DirectPHP plugin
Written by kksou   
Monday, 24 March 2008

This plugin allows direct embedding of PHP commands right inside Joomla content page for dynamic contents.

Available for both Joomla 1.0.x and native 1.5.x!

Important: If you're using Joomla 1.5.8, please refer to the article:
How to enter HTML tags, javascript and PHP codes in Joomla 1.5.8?
Otherwise you might find that all your HTML tags, Javascript and PHP scripts will be removed the moment you click the Save or Apply button.

Key Features

  • Include PHP commands right inside your Jommla content page using the standard php construct:
  • <?php php_commands... ?>
  • Freely intermix static contents with php commands:
  • Now is: <?php echo date('Y-m-d H:i:s');?>
  • Leverage on all your PHP libraries right inside the content page:
  • <?php 
    require_once('fullpath/your_lib.php');
    your_php_func();
    ?>
  • You can edit the php code right inside the default TinyMCE WYSIWYG Editor!
  • Ability to block potentially "risky" commands, e.g. system, fopen, unlink, rmdir, etc. You can add and edit this list of commands-to-block yourself.

Latest version
Updated: April 8, 2009
DirectPHP for Joomla 1.0.x: DirectPHP_v1.06
DirectPHP for Joomla 1.5.x: DirectPHP_v1.56

Added one more parameter "Using No Editor". If you're not using any editor when editing content articles, select 'yes' for this parameter. This will allow you to freely use any HTML tags (such as <br /> or <p>).

Background

I've recently redesigned this website using Joomla. As you can see, there are more than 450 PHP-GTK sample codes. It's just too much a hassle to include each sample code into every article. Isn't it nice if I could do a simple

echo "<pre>".htmlentities('filename.php')."</pre>";

to automatically include the respective sample code?

I've tried two other plugins: Jumi and RunPHP .

  • Jumi allows you to call or include another .php file. However, it doesn't allow you to add php commands right inside the content. What this means is that if you want to display a sample code, say example1.php, you need to create an intermediate .php file. In that intermediate php file, you then load and display the sample code with echo "<pre>".htmlentities('filename.php')."</pre>". These intermediate files accumulate very fast and is becoming a bit cumbersome.
  • RunPHP allows you to embed php commands right inside the content page. However, using it is a bit troublesome. You need to use, for example, JCE Editor with Show HTML view. You cannot use the default TinyMCE WYSIWYG Editor.

So I decided to develop my own plugin, and the result is this plugin DirectPHP.

How to install (Joomla 1.0.x)

  1. Download the plugin and unzip it into a folder.
  2. From the Installers menu, select mambots. In the field "Install directory", enter the folder location (where you unzipped the file) and click Install.
  3. From the Mambots menu, select Site Mambots.
  4. Make sure the plugin "DirectPHP" is published. If you see a cross in the Published column, just click on it. It will turn into a green tick.
  5. To try if it works, go to Content Manager, and copy the following text into any static content page:
  6. Current date and time is: <?php echo date('Y-m-d H:i:s');?>
  7. Now load that content page. You should see the current date and time displayed.

To customize the block list (Joomla 1.0.x)

  • From the Mambots menu, select Site Mambots and then click on DirectPHP.
  • On the right-hand side, you will see the Plugin Parameters "PHP commands to block".
  • Edit this list and click Save.

How to install (Joomla 1.5.x)

  1. Download the plugin and unzip it into a folder.
  2. From the Extensions menu, select Install/Uninstall. In the field "Install directory", enter the folder location (where you unzipped the file) and click Install.
  3. From the Extensions menu, select Plugin Manager.
  4. Enable the plugin (DirectPHP) - make sure there is a green tick in the Enabled column.
  5. To try if it works, go to "Content - Article Manager", and copy the following text into any static content page:
  6. Current date and time is: <?php echo date('Y-m-d H:i:s');?>
  7. Very Important: If you're using Joomla 1.5.8 and above, please refer to the article:
    How to enter HTML tags, javascript and PHP codes in Joomla 1.5.8?. Otherwise you might find that all your HTML tags, Javascript and PHP scripts will be removed the moment you click the Save or Apply button.
  8. Now load that content page. You should see the current date and time displayed.

To customize the block list (Joomla 1.5.x)

  • From the Extensions menu, select Plugin Manager, and click on DirectPHP.
  • On the right-hand side, you will see the Plugin Parameters "PHP commands to block".
  • Edit this list and click Save.

Examples

Here are some examples:

  1. You can display the current date and time with:
  2.  Now is: <?php echo date('l j D, Y H:i:s');?> 


  3. You can use for or foreach loop:
  4. <?php
    for ($i=0; $i<10; ++$i) {
        echo "$i: ".$i*$i,"<br>"; 
    } 
    ?>

  5. You can include your own PHP library and call the functions within that library:
  6. <?php
    require_once('/fullpath/your_php_library.php');
    display_image('image123.jpg');
    ?>
  7. You can sprinkle as many PHP statements you want within your content page. Note that these PHP statements will be processed in sequential order, and it respects all scoping of variables. So if you have set a variable earlier, you can use it in your PHP statements later.
  8. <?php global $a;
    $a = 10;?>
    This is a test. variable $a = <?php echo $a;?>
    
    <?php
    function f1() {
        global $a;
        return $a*2;
    }
    $b = f1($a);
    ?>
    
    You can access variable $a from within the function with global.
    variable $b = <?php echo $b;?>
    
  9. You can add any HTML statements through PHP:
  10. <?php
    echo "<table border=4$gt;";
    echo "<tr><td>a11</td><td>a12</td></tr>";
    echo "<tr><td>a11</td><td>a12</td></tr>";
    echo "</table>";
    ?>
  11. You can easily serve different contents for registered and non-registered members:
  12. For Joomla 1.0:

    <?php
    global $my;
    if ($my->id==0) {
        // non-registered members
        print "Please register or login.";
    } else {
        // registered members
        print "Contents for registered members.";
    }
    ?>

    For Joomla 1.5:

    <?php
    $user =& JFactory::getUser();
    if ($user->id==0) {
        // non-registered members
        print "Please register or login.";
    } else {
        // registered members
        print "Contents for registered members.";
    }
    ?>

Important Note: Blocking of PHP commands

By default, I've blocked some of the potentially "risky" commands, e.g. system, fopen, unlink, rmdir, etc.

You can view the entire list of PHP commands that are blocked in the plugin's property page. In there, you can also add, edit or delete this list of commands to suit your needs.

If you need to use any of these commands (e.g. mkdir) from within the content page, put them in one of the library files on your server, do a include() and then call that function. This is a much safer method.

If you insist, you may choose to turn off the blocking in the property page. However, I would strongly advise that you do so only if you're the only one maintaining your Joomla site. If you're opening up the adding and editing of content pages to the public, DO NOT turn off the blocking. It's too dangerous.

Disclaimer

DirectPHP is a simple, yet flexible and powerful plugin. I'm using it on this website. I'm sharing with you here because I think it will be very useful to some of you.

Your use of this plugin is at your own risk. kksou.com makes no warranties or representations, express or implied, as to the functionality or usefulness of this plugin. kksou.com disclaims all warranties, express or implied, including without limitation warranties of merchantability and fitness for a particular purpose. kksou.com disclaims liability for any direct, indirect, incidental, consequential, special, exemplary, punitive or other damages, or lost profits, that may result, directly or indirectly, from your use of this plugin, including without limitation any damage to computer systems, hardware or software, loss of data, or any other performance failures, or any errors, bugs, viruses or other defects that result from or are associated with use of this plugin.

Download

Note: To upgrade to the newer version, simply uninstall the old version and install the new version of the plugin.

Version History

  1. Version 1.00: released March 24, 2008.
  2. Version 1.01: released March 27, 2008.
  3. In TinyMCE Editor, when you press Enter, internally it's stored as a <p>. If you press shift-Enter, internally it's stored as <br>. In v1.00, if the user presses Enter after "<?php", the php script will not be captured. I only preg_matched for <br>. Overlooked the case for <p>. Bug has been fixed.

  4. Version 1.02: released April 6, 2008.
  5. In some of the editors, tabs is internally stored as &160;. If you're using tabs for code indentation, please download this update.

  6. Version 1.03: released May 12, 2008.
  7. Encapsulate all functions used by DirectPHP within a class so that you can use DirectPHP with some other plugins such as the "DirectPHP for Category Description" plugin.

  8. Version 1.04: released June 21, 2008.
  9. Now supports both PHP5 and PHP4.

  10. Version 1.05: October 11, 2008
  11. Thanks to Salvatore who informed me about some "mysterious" double-byte characters that get inserted into the DirectPHP code by the content editor of some of the non-English Joomla. These double-byte characters will cause error when processing the PHP commands with eval(). Have fixed this in this version.



User reviews   Average user ratings:    4.0   (from 72 users)
  1. Rod
    March 26, 2008 10:46pm
    shows promise!

    I would kill for this to work - but everytime I save it, then re-edit the content item, the php has disappeared. I'm using fck2 for an editor...

  2. kksou
    March 26, 2008 11:01pm

    Hi Rod,

    I don't use fck2. The plugin has been tested on the default TinyMCE WYSIWYG Editor.

    But I'll install fck2 and test it out. Will get back to you as soon as I find out where's the problem.

    Regards,
    /kksou

  3. kksou
    March 27, 2008 1:36am
    using DirectPHP with JCK (was joomlafck2)

    Hi Rod,

    I supposed you're referring to JCK. The website said it was formerly called was joomlafck2.

    I installed the editor. True enough. Entering and saving the code was ok. But when you tried to reload the content, the php code "disappeared".

    I probed around and found a couple of things:
    1) The code is still there in the mysql db. If you go straight into jos_content, you can see the code there.

    2) Interestingly, if you do a view source, the code is also there! It's just not shown.

    This leads me to realize that the code was being parsed by one of its javascript functions. That's why you can see it in view source, but the code is not displayed.

    I believe the function is contained in the file:
    mambots/editors/joomlafck2/editor/js/fckeditorcode_gecko.js

    However, the author has "encrypted", or obfuscated, the code. So there's no easy way to change the code. I would suggest you contact the author to see if he's willing to add one more parameter so that user's can choose whether to view or not view the PHP codes.

    As a "quick fix", you can actually comment out the code that make the PHP code disappear.

    Open up the file: mambots/editors/joomlafck2.php. Scroll to the bottom. You will see the following statements:

    <pre>
    return <<<EOD
    <textarea name="$hiddenField" id="$hiddenField" cols="$col" rows="$row" style="width:{$WidthCSS}; height:{$HeightCSS};">$content</textarea>

    <script type="text/javascript">

    /*

    var oFCKeditor = new FCKeditor('$hiddenField');

    oFCKeditor.BasePath = '$mosConfig_live_site/mambots/editors/joomlafck2/' ;
    oFCKeditor.Width = '$wwidth' ;
    oFCKeditor.Height = '$hheight' ;
    oFCKeditor.ToolbarSet = '$toolbar' ;

    oFCKeditor.Config['EditorAreaCSS'] = '$mosConfig_live_site/$content_css';
    oFCKeditor.Config['StylesXmlPath']= '$mosConfig_live_site/mambots/editors/joomlafck2styles.xml.php?css_filename=$content_css' ;
    oFCKeditor.Config['CustomConfigurationsPath'] = '$mosConfig_live_site/mambots/editors/joomlafck2.js.php' ;

    oFCKeditor.ReplaceTextarea() ;

    function InsertHTML(field, value) {
    // Get the editor instance that we want to interact with.
    var oEditor = FCKeditorAPI.GetInstance(field) ;

    // Check the active editing mode.
    if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
    {
    // Insert the desired HTML.
    oEditor.InsertHtml( value ) ;
    }
    else
    alert( 'Please switch to WYSIWYG mode.' ) ;
    }
    */
    </script>
    <br />
    <p>$buttons</p>
    EOD;')
    </pre>

    Comment out the entire javascript code as shown above with /*...*/.

    Try the editor again. You will be able to see all your PHP codes right there!

    But of course, there's some problem with this approach. You will find that your editor has now become a pure HTML editor. If you need a line break, you have to manually enter a <br> or <p>.

    So I guess the best is still for you to contact the author of JCK for help.

    Regards,
    /kksou

  4. ssnobben
    March 27, 2008 2:34am
    Having a slideshow module in main page

    hmmm just want to know if this is possible for putting a slideshow module in the front main page mosbody easy?

    should be like using {loadmodule mod_fpslideshow} for having that in a content article page easy. Is this possible ?

  5. kksou
    March 27, 2008 7:52am

    Yes. You can actually easily create a module or component using this plugin.

    If you're using Joomla 1.0.x, go to Module Manager, click New, then scroll all the way down to the bottom. In the custom output, you can add any PHP code here. It will be processed by the DirectPHP plugin.

    So if you have written some PHP/javascript library that presents a slideshow of images, just create a module as described above and publish it in one of the module position in the front main page.

    As for Joomla 1.5.x, the HTML module (was Custom module in 1.0.x) is no longer processed by the content plugins. The solution is to install a module called "CustomContent" by Ian MacLennan first. Once you've installed this module, you can publish any article in any module position. In that article, you can place any PHP code there, which will be processed by the DirectPHP plugin.

    I will give more details and examples of creating modules and components using the DirectPHP plugin in the next one or two days.

    Regards,
    /kksou

  6. kksou
    March 27, 2008 8:53am

    Hi Rod,

    I spent a bit more time with JCK and found a solution which seems to work.

    Edit the file: mambots/editors/joomlafck2.php. Look for the function "function botEditorArea()". You will see the following 5 lines:

    <pre>
    $content = str_replace("<", "", $content);
    $content = str_replace("&", "&", $content);
    $content = str_replace(" ", " ", $content);
    $content = str_replace(""", "\"", $content);
    </pre>

    Comment out this 5 lines altogether.

    <pre>
    /*$content = str_replace("<", "", $content);
    $content = str_replace("&", "&", $content);
    $content = str_replace(" ", " ", $content);
    $content = str_replace(""", "\"", $content);*/
    </pre>

    Now edit an article and type in some fresh php commands (don't use the old one that you've typed before) and save it. Reload it. You should be able to see the php commands back in the editor.

    I tried quite a few sample codes and they all seem to work.

    Do give it a try. Hope it works on your machine too!

    Regards,
    /kksou

  7. Rod
    March 27, 2008 9:27am
    I'm impressed

    this is a great addition to Joomla! And amazing response from kksou... thanks for your work!

    Rod

  8. ssnobben
    March 28, 2008 2:41am
    Slideshow on frontpage

    "I will give more details and examples of creating modules and components using the DirectPHP plugin in the next one or two days."

    That would be great!

    I will try to use this with the Slideshow component that also have a module and it would be nice to have that module on front page by article...:-)

    http://extensions.joomla.org/component/option,com_mtree/task,viewlink/
    link_id,1664/Itemid,35/

  9. ssnobben
    March 28, 2008 3:00am
    Slideshow on frontpage

    What I mean is to publish it to mainpage mainbody.

    Publishing the slideshow module to frontpage article!

  10. JoyMonkey
    March 28, 2008 9:08am
    Small JoomlaFCK Editor problem

    This is a very nice plugin, but I've run into a problem similar to Rod's. I'm using the JoomlaFCK editor (available from www.joomlafckeditor.com) with Joomla 1.5 and when editing an article that includes PHP it replaces some essential characters for the plugin to work. I tried looking in the editor's php file (plugins/editors/fckeditor.php) but couldn't find any lines similar to the ones you mention above.
    Can you please take a look?

  11. kksou
    March 28, 2008 9:31am

    Hi JoyMonkey,

    From the filename you mentioned, looks like you're using JoomlaFCK v1. The one Rod used is v2.

    Let me look around to see if ver 1 is still available for download. Will try it out and get back to you if there's any possible solution.

    Regards,
    /kksou

  12. JoyMonkey
    March 28, 2008 9:41am

    No, it's not v1, it's a new branch of JoomlaFCK (it's a little confusing, I know). This is a new editor, but appears to be very popular.
    Here is a direct link to the editor I'm using:
    http://joomlacode.org/gf/download/frsrelease/6583/21437
    /mod_bot_JoomlaFCKeditor2.5.1.1bVersion1.5.zip

  13. kksou
    March 28, 2008 9:41am

    Hi Ssnobben,

    "What I mean is to publish it to mainpage mainbody."

    Sorry I misunderstood your question earlier.

    Yes, it's possible. You can actually "insert" a module into a content page. But this is a Joomla "feature" and you do not really need the DirectPHP plugin to enable this.

    Doing this on Joola 1.0 and Joola 1.5 is slightly different. Give me about one day. Will post the solution in the tutorial section near the top of this page.

    Regards,
    /kksou

  14. gp44
    March 28, 2008 1:36pm
    strip php for rss

    Excellent plugin

    Is there anyway to auto switch off the rss feed for any article that uses direct php - or strip the php out - at the moment the actual code shows in the feed.

  15. Greivin Britton
    March 28, 2008 4:46pm
    I can't get this to work

    When i do the test, only appear the text just like i put it. The plugin is enable and i'm set TinyMCE by default and i have joomla 1.5, could you please help with this...

  16. kksou
    March 29, 2008 12:15am

    Hi Greivin,

    If you're sure the plugin is enabled, then

    1) First let's try this one more time:
    now = <?php echo date('Y-m-d');?>
    Please enter everything in one line (or just copy and paste into the editor). Reload the page. Did you see the php code or the time? Or did you see any error message?

    2) If it still doesn't work, then may I know if yours is a fresh install of Joomla 1.5? Have you installed any other plugins? I know some plugins such as jReviews removes all modifications by other plugins. They simply load the original content straight from mysql db and rewrites the contents. So DirectPHP will not work if you have such a plugin installed.

    3) As a test, you might want to try installing a fresh Joomla 1.5 into another location (it takes only about 5 minutes). Then install DirectPHP and see if it works. If it does work, then you know the problem is with one of the plugins that you have installed in your original Joomla.

    Hope this helps...

    Regards,
    /kksou

  17. kksou
    March 29, 2008 2:28am

    Hi Gp44,

    Which rss generator are you using? Are you using the rss feed that comes with standard Joomla installation? If yes, I could modify that to suit your need. (But please let me know which version of Joomla are you using - J1.0.13, J1.0.15 or J1.5?)

    Regards,
    /kksou

  18. kksou
    March 29, 2008 3:15am

    Hi JoyMonkey,

    I tried all 3 versions of JoomlaFCK from
    http://www.joomlafckeditor.com/index.php?option=com_content&view=category
    &layout=blog&id=34&Itemid=61

    All 3 versions (v2.5.1, v2.5.1.1 and v2.5.1.1b) seem to work fine. Switching between standard view and code view works fine too.

    1. May I know if you're using any of these 3 versions, or an earlier version?

    2. If you're using an earlier version, would you want to try the latest version and see if it works on your machine?

    3. Also, may I know if the plugin is not working at all? Or only some of the php statements are not working? If it's only some, could you please show me some of these php codes that don't work? (need to know which of the characters get converted by the editor)

    4. Lastly, does the simple statement:
    now = <?php echo date('Y-m-d');?>
    work on your machine? When you save the above statement and reload it in the editor, what did you see? Just 'now =' or any other text?

    Regards,
    /kksou

  19. ssnobben
    March 29, 2008 1:20pm
    loadposition moduleposition J 1.5

    Hi got this info today:
    Re: v 1.5 Interface Changes

    New postby guysmiley on Sat Mar 29, 2008 7:57 pm
    Note:
    Code above is inaccurate. For calling modules in J1.5 use:

    Code: Select all
    {loadposition moduleposition

    }

    Example:

    Code: Select all
    {loadposition advert1

    }

  20. ssnobben
    March 30, 2008 2:03am
    Maybe not correct ?

    Seems to be problem with this loadposition moduleposition
    call.

    Here is a topic in Joomla forum http://forum.joomla.org/viewtopic.php?f=304&t=175613&p=1253384#p1253384

  21. JoyMonkey
    March 31, 2008 5:21am
    Re: problems with JoomlaFCK

    1. I'm running the latest version (v2.5.1.1b).
    2. I removed JoomlaFCK and re-installed it to make sure I'm using that version.
    3. I've only tried one piece of php (your example #6).
    4. Trying it now...
    Inserting the line "now = " into an article using JoomlaFCK's 'Source' button works fine.
    However, when I try to edit that article it removes the php code entirely, leaving it as "now ="

  22. kksou
    March 31, 2008 6:49am

    Hi JoyMonkey,

    Thanks for the detailed description of what you've tried. Guess I know what's happening.

    I followed what you did. Enter the php code in source mode. And then switch back to the editor mode. Yes, the codes are gone.

    In JoomlaFCK, you have to enter those PHP code right in the editor mode (i.e. not the source mode). Try it. Just type <?php echo date('Y-m-d');?> direct into the editor and save it. It should work.

    Regards,
    /kksou

  23. JoyMonkey
    April 01, 2008 7:32am
    Perfect!

    I just assumed that the php code would be best entered in source mode. Thanks for clearing this up kksou! It's working perfectly now!

  24. Paul
    April 03, 2008 11:10pm
    Doesnt work - TinyMCE

    Using Joomla 1.0.13, tiny MCE editor, Mambot is published, code is entered in editor (not in HTML box) and saved.

    The php code itself is displayed on the page, ie. Current date and time is:

    Anything else I can try ? Thanks !!

    Paul

  25. kksou
    April 08, 2008 1:15am

    Please try one more time. Enter the following into editor all in one line:
    Current date is: <?php echo date('Y-m-d');?>

    If it still doesn't work, then one possible reason could be that you have other plugins installed that do not follow the standard rules. I know some plugins do that by overwriting whatever modifications that have been done by other plugins.

    As a test, you might want to try installing a fresh of Joomla into another location (it takes only about 5 minutes). Then install DirectPHP and see if it works. If it does work, then you know the problem is with one of the plugins that you have installed in your original Joomla.

    Regards,
    /kksou

  26. Tim Davis
    April 22, 2008 6:26pm

    I installed directphp to a fresh joomla 1.5 install (using the installer and uploading the zip file, not unzipping and uploading as you described) and I am using the tinymce editor that is the default.

    Unfortunately, whenever I enter the "<" character before php, it gets changed to "<" in the html (as does ">" get changed to something else. But when I go into the html and change it back to a "<" and ">" the whole php line i have entered simply disappears after saving - as in it is not there when I look back in the html for it.

    Do you know the solution to my problem? I really hope to use your plugin!

  27. Tim Davis
    April 22, 2008 6:26pm
    < being changed to - < -

    Sorry for this repost - my first one had things dropped at certain points so I had to edit out quote marks that were throwing things off.

    -----------

    I installed directphp to a fresh joomla 1.5 install (using the installer and uploading the zip file, not unzipping and uploading as you described) and I am using the tinymce editor that is the default.

    Unfortunately, whenever I enter the < character before php, it gets changed to < in the html (as does > get changed to something else. But when I go into the html and change it back to a < and > the whole php line i have entered simply disappears after saving - as in it is not there when I look back in the html for it.

    Do you know the solution to my problem? I really hope to use your plugin!

  28. kksou
    April 22, 2008 6:27pm

    Hi Tim ,

    Yes, tinymce editor will change those < and > to some other characters. (In fact, it will change many other characters such as ' and ".)

    But don't worry. My plugin will change all these back. So just go ahead and type those PHP commands in the tinymce editor. It should work just like that.

    Note that if you change those htmlentities back to say '<' and '>' by directly editing the content in mysql, you will find that all your PHP commands will disappear. This is because the tinymce editor refuses to show any tags in the editor, even though all your codes are still there.

    Alternatively, you might want to try installing other editors (one good one is JoomlaFCK) that allows you to easily switch between WYSIWYG mode and Source Code mode.

    Regards,
    /kksou

  29. Tim Davis
    April 22, 2008 8:11pm
    Thanks

    Thanks for your answer - it helped me narrow down what was happening.

    I am working with a fresh joomla 1.5.2 install, but I did import the database from a an existing 1.0.13 site - so i guess that might not qualify as totally fresh.

    Once I actually typed in the code (instead of relying upon elements of whatever was already there) things took.

    It also helped greatly when I actually included the question mark in the opening php tag. Yes, I'm a php noob i guess.

    Your plugin is awesome and it's so great it is 1.5 native. If you haven't already put it up on the joomla extension site, you really should. There are lots who will enjoy using it.

  30. Filipe Torres
    April 23, 2008 8:51am
    Problems with JCE editor

    Hi Kksou, I'm using JCE Editor and installed DirectPHP plugin, pasted PHP your exemple code:
    now =
    but nothing happens. It's possible this plugin work together with JCE Editor?

  31. kksou
    April 23, 2008 6:00pm

    Hi Filipe,

    1) First double-check that the plugin is published.

    2) Next go to Site - Global Configuration, and set Default WYSIWYG Editor to "No WYSIWYG Editor". Now enter the following into editor all in one line:

    Current date is: <?php echo date('Y-m-d');?>

    Reload the page. Did you see the date and time? If yes, it means DirectPHP is running ok. We can then know that the problem is with the JCE Editor.

    3) I will try out the JCE Editor and see if I can find a fix.

    Regards,
    /kksou

  32. kksou
    May 02, 2008 2:43am

    Hi Filipe,

    I've installed the JCE Editor and tried it with DirectPHP. Yes, it does work.

    One possible reason it didn't work on your system might be that: In JCE Editor, I see there's one [show/hide] link that let's you see the underlying HTML tags associated with the intro and fulltext.

    I'll call the default view (the one with all the toolbars) the WYSIWYG mode, and the other view (with all the toolbars hidden) the source mode.

    I believe you have entered the PHP commands in the source mode (the view without any of the toolbars). When you do this, when you switch back to the WYSIWYG mode, you will find that all your PHP commands are gone!

    The "trick" is: you have to enter the PHP codes in the WYSIWYG mode.

    Please give it a try one more time. Just copy and paste this line into the editor in the WYSIWYG mode:


    Current date is: <?php echo date('Y-m-d');?>


    Save and reload the page. The current date should be displayed.

    Regards,
    /kksou

  33. Markus Sägesser
    May 08, 2008 12:17am
    $REMOTE_ADDR

    Hi kksou,

    First let me thank you for this great plugin.

    Almost everything I tried so far did work; maybe you can help
    me with the part that didn't?

    I wish to display the Users IP-Adress on my page (great for supporting
    via remote connection) with following code:

    Your IP:

    Unfortunately nothing seems to happen.

    Can you bring in some light?

    Thanks in advance
    Greetings from Switzerland
    pfnuesu

  34. Markus Sägesser
    May 08, 2008 5:38am
    Another try

    Thanks for getting back - it seems like the code was parsed... (with the same result as I get on my own page)
    <?php echo "$REMOTE_ADDR";?>

    Greetings
    pfnuesu

  35. kksou
    May 08, 2008 6:04am

    Hi Markus,

    Try this...

    <?php echo "ip = ".$_SERVER['REMOTE_ADDR'];?>


    Regards,
    /kksou

  36. Markus Sägesser
    May 08, 2008 6:15am
    Thanks!

    (just gained 1 Star ;-) )
    Guess I was too lazy in using the short form...

    Works flawlessly!

    Thanks,
    Markus

  37. rebecca
    May 18, 2008 7:11pm
    small problem

    I installed it and I tried your test codes and it worked flawlessly! I just need one simple script to work. It is a random code generator. I can get it to work on a non-joomla page. But it is still not working in joomla. this is all it is:




    Sorry for this code comment, any thoughts?

  38. rebecca
    May 18, 2008 7:40pm
    Darn

    I tried to leave you the code but it got stripped out. I am so frustrated.

  39. kksou
    May 18, 2008 7:50pm

    Hi Rebecca,

    You missed out a semicolon at the end of one of the PHP statements.

    eval() is more "strict" than running php from command line. You need a semicolon at the end of every PHP statement.

    Regards,
    /kksou

  40. rebecca
    May 18, 2008 7:50pm
    Thanks

    kksou is my hero. thanks for the email help, the problem was solved in a matter of seconds.

  41. qc454
    May 23, 2008 1:07pm
    DirectPHP with comments extension security question

    First I would say thank you very much for this handy extension!

    I'm using yvComment as a commenting extension in my Joomla site, I'm allowing guests to add comments. I want to use DirectPHP but I'm worried about the possibility of guests writing php in their comments, I've tried to write php in a comment, (tried this and also this <?php echo 'hello'; ?> ) it was just ignored by yvComment that's good news, but I need confirmation (if any) that it is safe to use DirectPHP while allowing guests to add comments. I really need both :(

    A second question:

    When I use the search feature in joomla, the php code is displayed in the search results! for example :
    6. php test
    ('Uncategorised Content')


    is there a way to prevent this

    Thanks again for this wonderful extension!

  42. qc454
    May 23, 2008 1:19pm

    your commenting system did not allow me to write this:
    & lt;?php echo 'hello'; ? & gt;

    on the previous comment, I added some spaces to accept it,

    insert that in (tried this ...) in the previous comment

    Best Regards

  43. iochrist
    June 17, 2008 9:59am
    How to connect to database;

    Hello. Great work!!

    I want to to this in a content of Joomla.
    and i geti this:

    Parse error: syntax error, unexpected T_STRING in C:\Program Files\xampp\htdocs\sitakis\mambots\content\DirectPHP.php(65) : eval()'d code on line 11

  44. kksou
    June 17, 2008 6:01pm

    The error message usually means that you're running PHP4. However, I just tried with PHP v4.4.8. It runs ok. I supposed you're running a version earlier than PHP4.4.8...

    Can you try changing line 67:
    eval($this->fix_str2($phpcode));
    to:
    eval($phpcode2);
    and see if it works?

    Regards,
    /kksou

  45. faber
    August 06, 2008 6:05am
    php dissapears, all standard

    Hi I use joomla 1.54
    and TinyMCE editor 2.0
    (all standard)

    Now I can't get it to work
    when posting your Current date and time is:
    and then saving,
    the editor window only shows :Current date and time is:

    Dunno what I am doing wrong.

    I would like to use your plugin to include my phpfiles with db acces, show list out of db and forms from my former site (completely php based programming)

    tnx

  46. kksou
    August 06, 2008 8:27am

    Hi Faber,

    When you enter the PHP codes in TinyMCE editor, make sure you enter the codes in the WYSIWYG mode.

    DO NOT click the "Enter HTML Source" button and enter the codes in the HTML Source mode. All your codes will be stripped away by the editor.

    Regards,
    /kksou

  47. faber
    August 06, 2008 11:45pm

    I am pretty new to joomla, how do I check wether I am in wysiwyg mode ? if found extentions-plugin- Editor - TinyMCE 2.0 and there are settings:(translated from dutch)
    Functionality advanced
    clean code at start off
    clean code at save always
    don't clean HTML. no
    save warning on
    Gecomprim version on

    but can't get it to work...

  48. faber
    August 07, 2008 12:16am

    oh forgot, the html button is not clicked...

  49. Larry
    August 18, 2008 3:15pm
    my first test was not positive

    I downloaded and installed this plugin into Joomla! 1.5.6 today. Joomla! was installed with the default data and I simply replaced the contents of the Stick to the Code! article with

  50. Larry
    August 18, 2008 3:35pm
    my first test was not positive (repeat)

    I downloaded and installed this plugin into Joomla! 1.5.6 today. Joomla! was installed with the default data and I simply replaced the contents of the Stick to the Code! article with
    . After I refreshed the Frontpage, I could see that the phpinfo() was rendered properly, albeit in very small type. There were other issues, however.

    The other text on my Frontpage was also somehow affected. It was smaller than before I changed the article. It also seems that all the DIV's on the page also now have a border. Maybe my first trial should have been simpler?!?

  51. Larry
    August 18, 2008 4:09pm
    more test results

    My last post should have showed that the php code I was executing was simply phpinfo(); inside standard php open/close tags.

    I tried the same the thing with jumi and it produced the same results as DirectPHP. So I guess this may just have been a bed one to try. Having said this, I do have some php code that renders tables and other graphics that I want to try. I'll let you know how it goes.

  52. Larry
    August 18, 2008 4:35pm
    unfair test

    After further review, I've concluded that my test was unfair. Since phpinfo() writes a complete html file, it is not fair to expect that my page would render correctly given the test that I did. A more appropriate application for what I wanted was to use the wrapper module. Having said this, I do see a lot of value with this plugin. I think that DirectPHP and jumi (and DirectPHP with the Custom Content module) all have value. I'll probably end up using some mix of the two (three).

  53. sofia
    September 01, 2008 1:02am
    Parse error

    Hi!This is a very interesting work and just what I needed!
    The problem is that I'm getting a parse error just like iochrist above. I tried the change you suggested changing the code to eval($phpcode2) but it didn't work.
    I use PHP5.What can I do?I really have to make it work!
    Thanks anyway!

  54. kksou
    September 01, 2008 3:23am

    If you're using PHP5, and you have "Parse error", it usually means there's some syntax error in your PHP codes.

    First, you need to make sure that DirectPHP works on your machine. Try the following:


    Now is: <?php echo date('Y-m-d H:i:s');?>

    Does it work? Did you see the date?

    If you see the date, it means DirectPHP works. So the next thing is to debug your PHP codes. As I've mentioned before, debugging PHP codes in eval() statement is extremely tough. So I usually test the codes on a standalone .php page. Once it works, I then copy and paste into the content item page.

    Hope this helps.

    Regards,
    /kksou

  55. sofia
    September 02, 2008 5:49am

    thanks but it didn't work..I just see exactly what I wrote..the php code..now what?

  56. Greg FitzPatrick
    September 02, 2008 8:40am
    more joomlafck disappearance

    Hi kksou, I read the help you were giving folks who lost their scripts upon saving content edited in joomlafck. My problem is slightly similar. I wanted to test an onload eventhandler and I put in body tags (I had jscript as well). After saving, both the body tags and the scripts were gone from sight, but both are still in there somewhere and causing havoc on my site.

    joomlafck 2.5.1 ver 1.5

  57. Derek Newbould
    September 03, 2008 4:19am

    Brilliant! Just updated to Joomla 1.5 and I wanted something to replace {kl_php}. This did it perfectly. Like some others here I had problems with code not showing in the editor. This is because I made a mistake with my update query when converting from {kl_php} to DirectPHP.

    The correct mySQL syntax is:
    update `jos_content` set `introtext` = replace(`introtext`,'{kl_php} ','<?php ');
    update `jos_content` set `introtext` = replace(`introtext`,'{/kl_php}',' ?>');


    update `jos_content` set `fulltext` = replace(`fulltext`,'{kl_php} ','<?php ');
    update `jos_content` set `fulltext` = replace(`fulltext`,'{/kl_php}',' ?>');

    I hope this helps anyone else having problems with the conversion.

    Many thanks for this plugin,

    Derek

  58. manuphi
    October 11, 2008 7:23am
    Doesn't work with a specific module

    Hi kksou,
    Sorry for my english langage, cause I'm french...
    I already use DirectPHP on the content of my Joomla websites and it works very well.
    Now, I would like to use it on a module named yoo_scroller for joomla 1.5, but it doesn't works.
    Could you try it and give me a solution, please ?

    Thanks for your answer,
    - Manuphi

  59. manuphi
    October 11, 2008 8:00am
    Manuphi problem again !

    I just want to precise my problem :
    if I want to post an article written with php language in a module it semms that it doesn't work.
    Or I made a mistake but I can't see where ?
    Thanks for your answer,
    - Manuphi

  60. moh3
    December 13, 2008 12:57pm
    hello the download link is not working

    hello the download link is not working

  61. Airport1
    January 21, 2009 6:21am
    Optional PHP Code also in HTML View?

    Hello, it would be nice if - at least optional - the editor could enter the php code in html view also. Currently I have to "transfer" pure mixed html+php content from Drupal to Joomla, and as it is not possible to throw it directly into the html view I have to cut out the php code, throw the html in, and add the php code later around again in wysiwyg.

  62. Airport1
    January 21, 2009 6:43am
    Optional PHP Code also in HTML View?

    Hello, it would be nice if - at least optional - the editor could enter the php code in html view also. Currently I have to "transfer" pure mixed html+php content from Drupal to Joomla, and as it is not possible to throw it directly into the html view I have to cut out the php code, throw the html in, and add the php code later around again in wysiwyg.

  63. Walter Stockheim
    February 12, 2009 6:30pm
    Very cool.

    I'm just learning php, but this works well for me so far and seems to have lots of awesome possibilities.

  64. seb
    February 24, 2009 9:07pm
    Was working but now it isnt

    Hi, I'm putting php code directly into the page (not through html source) however as soon as I click save, the php portion is disappearing. this is the code im putting in. Current date is:

    All that is left is the Current date is:

    I've seen other people have had this problem and seen the response, which was to put the code directly in without using the html source. That is what I am doing but to no avail. What is the next step to take because it seems like the

  65. seb
    February 24, 2009 9:19pm
    fix on top

    "Current date is: " seems like its parsing on this comment page too so just letting u know, im putting the php code and not only the text.

  66. seb
    February 26, 2009 2:37pm
    Fixed but wysiwyg problem

    So I followed the directions of the fix for versions 1.5.8 and on and the php code is parsing correctly. However, when I enable a wysiwyg editor in Joomla and click edit on an article, the code is gone. The code is gone but it's in the backend hidden somewhere because the php code still parses. When i turn off the wysiwyg editor I can once again see the php code. This is only a matter of convenience as I would like to not disable wysiwyg everytime I need to edit the php code. What can I do?

  67. richard
    March 04, 2009 1:53pm
    Issues with DirectPHP in Joomla 1.5

    I run without an editor because joomla's default editor (Tiny MC) strips form tags. when I add the php code via source it will only read one line. If it is more than that it loses track of what is going on. The tags are left in there but it prints the contents to the page instead of the result. i.e I put in a simple echo statement -
    and it couldn't printed out "echo "this is working"; after successfully printing out the date example I copied from up further on this page? So the complete code read" -
    Current date and time is:


    I have chronoforms plugin installed, if you were wondering about other plugins.

    Any suggestions. This would really be sweet if it works for us because we use php extensively on our server-side, would be sweet to be able to work it directly into articles and etc!

    Appreciate any time you take on this!

  68. richard
    March 04, 2009 2:14pm
    Found part of my problem

    Well figured out that my statements being overlooked were written with the php shortcut tags instead of . Once I changed that the statements were shown, except for an include statement? I included a file that simply had a png in a link like so -- logon here
    The include is being bypassed for some reason?
    I have an echo statement before and after it and both fire. So thinking it is probably my statement, but they are all contained in the same tags? and the echo statements both fire so it's going through it, just not loading it. I am pretty sure that's most likely some error on my behalf so wanted to let you know I had figured out the problem I posted above.

  69. Chris Arveson
    March 06, 2009 9:25pm
    EXACTLY What I Needed

    This plug-in is genius! I'm moving from an html website to Joomla! and could not see how to use my mySQL database in Joomla!.

    DirectPHP lets me put in the form elements I wanted, and pull the data out as I had originally programmed it. Thank you so much!

  70. Jez Reyes
    May 12, 2009 8:59pm
    HELP!!!!!

    excellent plugin!

    but i was just having trouble getting some php code to work, i dont know if the problem is with directphp or not.

    i tried to display this as a content item in Joomla 1.0

    heres the code:



    Personal INFO

  71. Jon
    May 27, 2009 11:34am

    This Worked for me with 1.5.7 and TinyMCE:
    The "trick" is: you have to enter the PHP codes in the WYSIWYG mode.

    Please give it a try one more time. Just copy and paste this line into the editor in the WYSIWYG mode:

  72. JustforTaty
    June 01, 2009 9:58pm
    Transferring php script

    Hi there
    I am very excited to have found this. Thak you so much for taking the time and effort to help others. I am trying to have certain php pages from a site transferred to Joomla. I installed DirectPHP and have attempted to copy and paste the pages after transferring the database to the joomla database, but when I view the pages I see the scripting as text on the page. Have I missed anything? should I have done anything before trying to copy the script to the joomla pages?

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2009. kksou.com. All Rights Reserved