Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Inline PHP in category description?


mattsc

Recommended Posts

Is it somehow possible to insert some inline PHP into a category description? I have a desire to be able to use a PHP function to serve different content based on a result of a test.

<?php
  if (CheckThing()) {
    DoThingX();
  } else {
    DoThingY();
  }
?>

but don't know if:

1) It's even possible

2) How I might go about doing it such that it wouldn't be obliterated by the categories.php upon subsequent edits

Link to comment
Share on other sites

Well, yes it should be possible to do something like that, but not easily. The most general case would be to allow embedding of PHP within the HTML of your text (out of the database). This would require that whatever is handling the category description text to look for "<?php", extract that part of the text, do some sort of "eval()" on it, and insert the resulting text back into the HTML text for output to the browser. Note that a browser is expecting pure HTML... it has no idea what to do with PHP code. Also note that you have to be very careful to do this only with trusted sources -- imagine what a hacker could do if they could insert PHP into a product review or something!

 

A more limited approach would be to modify the category description (or whatever) code to drop your code permanently into the middle of the PHP, and then the normal HTML text from the database is placed before, after, or around the output of your custom code. Either approach would still be vulnerable to being wiped out by updates to the osC code, especially if you're messing around in "core" code.

Link to comment
Share on other sites

Unfortunately my need is to call a PHP function from general.php. Which sounds then like, no... not really possible. Was just a hair brained idea that came to me this morning while mulling over a problem I've got, where I need to serve different content based on the result of the PHP function call.

 

Basically I have to show one thing if the function returns true, else show the other. Currently the desire is to be able to serve this content from inside of a category page so it fits in seamlessly with the menu and I don't have to then create a box for the left pane to serve just that content and become disjointed from the rest of the sites navigation methods. I'm running out of ideas on how to do that tho.

Link to comment
Share on other sites

wouldn't an ajax call for the extra/different content work better ?

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

wouldn't an ajax call for the extra/different content work better ?

 Possibly. I am not sure how I could implement that tho. Javascript and I don't exactly get along. ;)

 

If you have some sort of example you might point me at where I could call the PHP function in general.php that would be great.

Link to comment
Share on other sites

I once wrote something that did what you want. It's about 200 lines of messy PHP that's prone to failure if you don't do everything exactly right. That means that a misplaced apostrophe can cause the whole page to display blank. I don't really recommend it, but you can have it if you want. The code is here.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

@@mattsc I'm not sure I understand what you want but something like this will work:

 

- In the products description put some unique code at the end, like +@@abc@+

 

- In the product_info file, send the description to a function before displaying it like this,

echo MyFcn($product_info['products_description);

- In the function have something like this:

function MyFcn($desc) {
    if (strop($desc, '+@[member=abc]@+') !== FALSE) {
       $desc = str_replace('+@[member=abc]@+', '', $desc);
       do what ever you want...
    } else if (strop($desc, '+@[member=def]@+') !== FALSE) {
       $desc = str_replace('+@[member=def]@+', '', $desc);
       do something else...
    }
    return $desc;
|

You can use whatever codes you want. You may need to set an option in the function and then operate on it in the product_info code, depending upon what you are needing to do.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...