Your SlideShare is downloading. ×

Sourcerer and Joomla! rev. 20130903


Published on

Presented at the Joomla! User Group Toronto meeting of August 20, 2013. Covers setting up an environment under Linux, using Bluefish to create PHP code that can be executed using the Sourcerer …

Presented at the Joomla! User Group Toronto meeting of August 20, 2013. Covers setting up an environment under Linux, using Bluefish to create PHP code that can be executed using the Sourcerer extension to create custom capabilities for the Joomla! CMS.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Sourcerer Create your own extensions for Joomla! Without needing to learn the full MVC model or a complicated IDE
  • 2. Sourcerer An extension for Joomla! 2.5 or 3.x from Peter van Westen
  • 3. What is it? “Sourcerer enables you to place PHP and any kind of HTML style code (including CSS and JavaScript) right into your content! Not only in your articles, but also in sections, categories, modules, components, META tags, etc.”
  • 4. What does that mean? Without needing to learn all that it takes to develop your own components, you can add custom capabilities to your Joomla! sites.
  • 5. Environment ● Platform ●Linux ●Apache/PHP/Joomla! ●Sourcerer ●Bluefish ●myphpadmin
  • 6. Platform Ubuntu 12.04LTS Either installed on a dedicated PC Or Virtual Machine
  • 7. Oracle VirtualBox
  • 8. Download platform & extension pack
  • 9. Download Ubuntu Desktop
  • 10. VirtualBox Install ● Run and accept the default options. (see video)
  • 11. Create Ubuntu Virtual Machine ● Create New machine Options: ● Ubuntu Linux ● 1G memory ● 32G disk ● Change network to “bridged”
  • 12. Install Ubuntu ● Click “Start” for the newly defined virtual machine ● When prompted, select your saved .iso image for Linux
  • 13. Final Steps in Setting up development Environment Install •Joomla •Sourcerer (directly or via Extension Manager) •JCE (optional)
  • 14. Advanced Configuration Modify php.ini Settings for apache: /etc/php5/apache2 Settings for CLI: /etc/php5/cli Settings may need to be changed to increase memory, upload size, or execution time
  • 15. Code Resources PHP site: great for syntax and code samples Google Your friend for finding PHP code, and finding Joomla! API calls
  • 16. Starting to code Open a terminal, become root Create a directory to put your PHP code Set ownership/permissions Open Bluefish
  • 17. PHP key points ● Variables always start with $ ● Variables are automatically defined (mostly) ● Variable names are case sensitive ● If you mis-spell or mis-capitalize, it isn't the same variable ● =, == and === are not the same thing ● Error messages are cryptic ● Arrays use associative indexes, which can be very useful
  • 18. Error Messages ● When a Joomla! page ends up white, malformed, or with an error message, check: /var/log/apache2/error.log ● Go to the end of the file, and look back until you find the first of what is usually a bunch of messages. ● If you're lucky the message will be useful, but it will at least give you a line number
  • 19. A simple code snippet ● Create new article ● Click on insert code ● Between the <?php and ?> tags, enter: printf(“Today is %s<br>n”,date(“Y-m-d”)); ● Save article, add menu item, open page.
  • 20. The other way to insert source... ● Create a suitable directory (e.g. php under your installation root). Don't forget to set the ownership/permissions correctly. ● Reference your.php file by putting a require_once into your article between the {source}{/source} tags
  • 21. Bluefish ●A simple but relatively useful editor, which is language aware. ●You'll probably prefer to run it as root, so open a terminal window, then “sudo bash”, and then “bluefish&” ●Click on “New”, then “Save As”, and start writing. ●The file you've created should be the one you've put into the “require_once” statement.
  • 22. Monospace text from file <?php function monofilter($filePath){ printf("%sn",'<style type="text/css"> textMonospace { font-family: monospace, "Courier New", Courier } </style><textMonospace>'); $handle=@fopen($filePath, "r"); if($handle){while(($line=fgets($handle))!==false) {printf("%s%s",str_replace(" ","&nbsp;", $line),"<br>");};fclose($handle);}; printf("%s",'</textMonospace>'); return; } ?>
  • 23. Match a string in a text file <!-- needs to be run by Sourcerer within Joomla --> <?php require_once("/usr/local/charts/utilPHP/htmlUtil.php"); defineChartMono(); $session = JFactory::getSession(); $mainframe=& JFactory::getApplication(); $sessionID = $session->getID(); $submitForm = JRequest::getVar( 'submit' ); $searchStrForm = strip_tags(strtoupper(JRequest::getVar( 'searchStr' ))); // save values if needed for print if ($submitForm == "Display" ) { $mainframe->setUserState( $sessionID.".searchStr", $searchStrForm ); };
  • 24. Part 2 $printForm = JRequest::getVar( 'print' ); // print variable set to 1 by print icon if ($printForm > 0) { $searchStrForm=$mainframe->getUserState($sessionID.".searchStr"); } else { // don't put up input fields if printing ?> <form method="post" action="sourcerer"> <label for="searchStr">Look For: </label><input type="text" id="searchStr" name="searchStr" size=32 value= <?php printf(""%s"",$searchStrForm); ?> />&nbsp;&nbsp; <input type="submit" value="DISPLAY" name="submit" /> </form> <?php }; defineChartMono(); ?>
  • 25. Part 3 <BR> <textChartMono> <?php // echo $searchStrForm; // 2 is used since the variable includes "" if (strlen($searchStrForm)>0) { $cmd="/bin/fgrep -i -- " . $searchStrForm . " ./images/txt/names.txt" ; // var_dump($cmd); exec($cmd, &$answer); // var_dump($answer); $nlines=count($answer); for( $i=0; $i<$nlines; $i++) printf("%s", formatNBR($answer[$i])); } ?> </textchartmono> <br />
  • 26. Summary ● Sourcerer allows you to develop your own HTML/JavaScript/PHP code without needing to learn how to create your own component/plugin ● Using “require” to pull in an external PHP that is edited in Bluefish allows for rapid development without needing to learn a complicated IDE But you probably will want to, eventually...