Sourcerer
Create your own extensions for Joomla! Without
needing to learn the full MVC model or a complicated
IDE
Sourcerer
An extension for Joomla! 2.5 or 3.x from
Peter van Westen
http://www.nonumber.nl
What is it?
“Sourcerer enables you to place PHP and any kind of
HTML style code (including CSS and JavaScript) right
into ...
What does that mean?
Without needing to learn all that it takes to develop
your own components, you can add custom capabil...
Environment
● Platform
●Linux
●Apache/PHP/Joomla!
●Sourcerer
●Bluefish
●myphpadmin
Platform
Ubuntu 12.04LTS
Either installed on a dedicated PC
Or
Virtual Machine
Oracle VirtualBox
https://www.virtualbox.org/
Download platform & extension pack
Download Ubuntu Desktop
http://www.ubuntu.com/download/desktop
VirtualBox Install
● Run and accept the default
options.
(see video)
Create Ubuntu Virtual Machine
● Create New machine
Options:
● Ubuntu Linux
● 1G memory
● 32G disk
● Change network to “bri...
Install Ubuntu
● Click “Start” for the newly defined virtual machine
● When prompted, select your saved .iso image for
Lin...
Final Steps in Setting up development
Environment
Install
•Joomla
•Sourcerer
(directly or via Extension Manager)
•JCE (opt...
Advanced Configuration
Modify php.ini
Settings for apache: /etc/php5/apache2
Settings for CLI: /etc/php5/cli
Settings may ...
Code Resources
PHP site: www.php.net
great for syntax and code samples
Google
Your friend for finding PHP code,
and findin...
Starting to code
Open a terminal, become root
Create a directory to put your PHP code
Set ownership/permissions
Open Bluef...
PHP key points
● Variables always start with $
● Variables are automatically defined (mostly)
● Variable names are case se...
Error Messages
● When a Joomla! page ends up white, malformed, or
with an error message, check:
/var/log/apache2/error.log...
A simple code snippet
● Create new article
● Click on insert code
● Between the <?php and ?> tags, enter:
printf(“Today is...
The other way to insert source...
● Create a suitable directory (e.g. php under your
installation root). Don't forget to s...
Bluefish
●A simple but relatively useful editor, which is
language aware.
●You'll probably prefer to run it as root, so op...
Monospace text from file
<?php
function monofilter($filePath){
printf("%sn",'<style type="text/css"> textMonospace
{ font-...
Match a string in a text file
<!-- needs to be run by Sourcerer within Joomla -->
<?php
require_once("/usr/local/charts/ut...
Part 2
$printForm = JRequest::getVar( 'print' );
// print variable set to 1 by print icon
if ($printForm > 0) {
$searchStr...
Part 3
<BR>
<textChartMono>
<?php
// echo $searchStrForm;
// 2 is used since the variable includes ""
if (strlen($searchSt...
Summary
● Sourcerer allows you to develop your own
HTML/JavaScript/PHP code without needing to
learn how to create your ow...
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Sourcerer and Joomla! rev. 20130903
Upcoming SlideShare
Loading in …5
×

Sourcerer and Joomla! rev. 20130903

2,775 views

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 extension to create custom capabilities for the Joomla! CMS.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,775
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sourcerer and Joomla! rev. 20130903

  1. 1. Sourcerer Create your own extensions for Joomla! Without needing to learn the full MVC model or a complicated IDE
  2. 2. Sourcerer An extension for Joomla! 2.5 or 3.x from Peter van Westen http://www.nonumber.nl
  3. 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. 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. 5. Environment ● Platform ●Linux ●Apache/PHP/Joomla! ●Sourcerer ●Bluefish ●myphpadmin
  6. 6. Platform Ubuntu 12.04LTS Either installed on a dedicated PC Or Virtual Machine
  7. 7. Oracle VirtualBox https://www.virtualbox.org/
  8. 8. Download platform & extension pack
  9. 9. Download Ubuntu Desktop http://www.ubuntu.com/download/desktop
  10. 10. VirtualBox Install ● Run and accept the default options. (see video)
  11. 11. Create Ubuntu Virtual Machine ● Create New machine Options: ● Ubuntu Linux ● 1G memory ● 32G disk ● Change network to “bridged”
  12. 12. Install Ubuntu ● Click “Start” for the newly defined virtual machine ● When prompted, select your saved .iso image for Linux
  13. 13. Final Steps in Setting up development Environment Install •Joomla •Sourcerer (directly or via Extension Manager) •JCE (optional)
  14. 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. 15. Code Resources PHP site: www.php.net great for syntax and code samples Google Your friend for finding PHP code, and finding Joomla! API calls
  16. 16. Starting to code Open a terminal, become root Create a directory to put your PHP code Set ownership/permissions Open Bluefish
  17. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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...

×