Joomla 1.0 Articles
- How to create a module with DirectPHP plugin?
- How to include modules in Content item?
- How to include modules in Section/Content Description
- How to include PHP commands in Section/Content Description
- How to make plugins process Section/Category descriptions
- Include Code Listing plugin - More Tips and Techniques
Joomla 1.5 Articles
- How to create a module with DirectPHP plugin?
- How to include modules in Content item?
- How to include modules in Section/Content Description
- How to include PHP commands in Section/Content Description
- How to make plugins process Section/Category descriptions
- Include Code Listing plugin - More Tips and Techniques
|
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! Latest version:Updated: Apr 6, 2008 DirectPHP for Joomla 1.0.x: DirectPHP_v1.02 DirectPHP for Joomla 1.5.x: DirectPHP_v1.52 Note: if you downloaded a copy before Mar 28, please download this latest update. Please refer to the Version History for key changes. Key Features
<php php_commands... ?> Now is: <php echo date('Y-m-d H:i:s');?>
<php
require_once('fullpath/your_lib.php');
your_php_func();
?>
BackgroundI'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 .
So I decided to develop my own plugin, and the result is this plugin DirectPHP. How to install (Joomla 1.0.x)
Current date and time is: <?php echo date('Y-m-d H:i:s');?>
To customize the block list (Joomla 1.0.x)
How to install (Joomla 1.5.x)
Current date and time is: <?php echo date('Y-m-d H:i:s');?>
To customize the block list (Joomla 1.5.x)
ExamplesHere are some examples:
Now is: <?php echo date('l j D, Y H:i:s');?>
<?php
for ($i=0; $i<10; ++$i) {
echo "$i: ".$i*$i,"<br>";
}
?>
<?php
require_once('/fullpath/your_php_library.php');
display_image('image123.jpg');
?>
<?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;?>
<?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>"; ?> <?php
global $my;
if ($my->id==0) {
// non-registered members
print "Please register or login.";
} else {
// registered members
print "Contents for registered members.";
}
?>
Important Note: Blocking of PHP commandsBy 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 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. DisclaimerDirectPHP 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. DownloadDirectPHP for Joomla 1.0.x: DirectPHP_v1.02DirectPHP for Joomla 1.5.x: DirectPHP_v1.52 Note: To upgrade to the newer version, simply uninstall the old version and install the new version of the plugin. Version History
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. In some of the editors, tabs is internally stored as &160;. If you're using tabs for code indentation, please download this update. User reviews Average user ratings: 4.0 (from 36 users)Note: You have to be a registered member to leave a comment. Free registration here. |
|||
| < Prev |
|---|



March 26, 2008 11:46pm
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...
March 27, 2008 12:01am
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
March 27, 2008 2:36am
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
March 27, 2008 3:34am
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 ?
March 27, 2008 8: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
March 27, 2008 9: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
March 27, 2008 10:27am
this is a great addition to Joomla! And amazing response from kksou... thanks for your work!
Rod
March 28, 2008 3:41am
"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/
March 28, 2008 4:00am
What I mean is to publish it to mainpage mainbody.
Publishing the slideshow module to frontpage article!
March 28, 2008 10:08am
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?
March 28, 2008 10: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
March 28, 2008 10: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
March 28, 2008 10: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
March 28, 2008 2:36pm
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.
March 28, 2008 5:46pm
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...
March 29, 2008 1: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
March 29, 2008 3: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
March 29, 2008 4: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
March 29, 2008 2:20pm
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
}
March 30, 2008 3:03am
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
March 31, 2008 6:21am
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 ="
March 31, 2008 7: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
April 01, 2008 8:32am
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!
April 04, 2008 12:10am
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
April 08, 2008 2: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
April 22, 2008 7: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!
April 22, 2008 7:26pm
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!
April 22, 2008 7: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
April 22, 2008 9:11pm
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.
April 23, 2008 9:51am
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?
April 23, 2008 7: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
May 02, 2008 3: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:
Save and reload the page. The current date should be displayed.
Regards,
/kksou
May 08, 2008 1:17am
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
May 08, 2008 6:38am
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
May 08, 2008 7:04am
Hi Markus,
Try this...
<?php echo "ip = ".$_SERVER['REMOTE_ADDR'];?>
Regards,
/kksou
May 08, 2008 7:15am
(just gained 1 Star ;-) )
Guess I was too lazy in using the short form...
Works flawlessly!
Thanks,
Markus