SlideShare uma empresa Scribd logo
1 de 63
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 your content! Not only in your articles, but also in
sections, categories, modules, components, META
tags, etc.”
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.
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 “bridged”
Install Ubuntu
● Click “Start” for the newly defined virtual machine
● When prompted, select your saved .iso image for
Linux
Final Steps in Setting up development
Environment
Install
•Joomla
•Sourcerer
(directly or via Extension Manager)
•JCE (optional)
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
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
Starting to code
Open a terminal, become root
Create a directory to put your PHP code
Set ownership/permissions
Open Bluefish
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
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
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.
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
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.
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;
} ?>
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 );
};
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();
?>
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 />
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...

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php(report)
Php(report)Php(report)
Php(report)
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
Php Unit 1
Php Unit 1Php Unit 1
Php Unit 1
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php workshop L03 superglobals
Php workshop L03 superglobalsPhp workshop L03 superglobals
Php workshop L03 superglobals
 
Php workshop L04 database
Php workshop L04 databasePhp workshop L04 database
Php workshop L04 database
 
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCRDrupal7 Theming session on the occassion of  Drupal7 release party in Delhi NCR
Drupal7 Theming session on the occassion of Drupal7 release party in Delhi NCR
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Mustache
MustacheMustache
Mustache
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 

Semelhante a Sourcerer and Joomla! rev. 20130903

Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting languageElmer Concepcion Jr.
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/tutorialsruby
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeProf. Wim Van Criekinge
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessoradeel990
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Phpdrperl
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 

Semelhante a Sourcerer and Joomla! rev. 20130903 (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
 
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Day1
Day1Day1
Day1
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
 
Basic php 5
Basic php 5Basic php 5
Basic php 5
 
Php intro
Php introPhp intro
Php intro
 
Php
PhpPhp
Php
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
PHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERSPHP NOTES FOR BEGGINERS
PHP NOTES FOR BEGGINERS
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 

Último

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Sourcerer and Joomla! rev. 20130903

  • 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 http://www.nonumber.nl
  • 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.
  • 6. Platform Ubuntu 12.04LTS Either installed on a dedicated PC Or Virtual Machine
  • 8. Download platform & extension pack
  • 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.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. Final Steps in Setting up development Environment Install •Joomla •Sourcerer (directly or via Extension Manager) •JCE (optional)
  • 48. 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
  • 49. 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
  • 50. Starting to code Open a terminal, become root Create a directory to put your PHP code Set ownership/permissions Open Bluefish
  • 51. 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
  • 52. 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
  • 53. 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.
  • 54.
  • 55.
  • 56.
  • 57. 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
  • 58. 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.
  • 59. 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; } ?>
  • 60. 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 ); };
  • 61. 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(); ?>
  • 62. 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 />
  • 63. 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...