Filed Under (Mootools) by khawaib on 30-03-2010
Operators used in Mootools:
‘=’ : is equal to
‘*=’: contains
‘^=’ : starts-with
‘$=’ : ends-with
‘!=’ : is not equal to
‘~=’ : contained in a space separated list
‘|=’ : contained in a ‘-’ separated list
Website Root path
<?php echo $this->baseurl ?>
Template name
<?php echo $this->template;?>
$this->baseurl;
$this->template;
$this->params; // Template specific params object -- defined in the params.ini file
// From JDocument:
$this->base; // Document base URL -- redundant, as far as I can tell
$this->description; // Document description
$this->direction; // Contains the document direction setting (default='ltr')
$this->language; // Contains the document language setting (default='en-gb')
$this->link; // Document full URL
$this->title; // Document title
$this->_generator; // Document generator (default='Joomla! 1.5 - Open Source Content Management')
Filed Under (Joomla! 1.5) by khawaib on 05-03-2010
By default Joomla module do not come with the functionality of creating table or running any queries with install. With a little bit of code and a parameters flag database queries can be run on first run of module when it is published.
Step 1:
Add a parameter flag in xml file.
<param name="flag_key" type="text" default="0" label="Flag Key" description="" />
and in your helper file you can add following code:
function getFanbox( $params ) {
if (!trim($params->get('flag_key'))) {
$database =& JFactory::getDBO();
$query = "CREATE TABLE example ( id INT, data VARCHAR(100) );";
$database->setQuery($query);
$result = $database->query();
$params->set('flag_key', 1);
}
}
Code basically checks if the flag is set or not, if its not set queries run and set the flag so next time condition fails. Please note parameter key is type text field. You must make a custom element and make the field read only to make sure user does not change it and may be also move the field to Advanced Parameters to get it out of the way.
Below is the complete code from helper.php and XML file.
mod_fbfanbox.xml:
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<name>Facebook FanBox</name>
<author>Khawaib Ahmed</author>
<creationDate>July 2009</creationDate>
<copyright>Copyright (C) 2009 - Present. www.Khawaib.co.uk. All rights reserved.</copyright>
<authorEmail>khawaib@khawaib.co.uk</authorEmail>
<authorUrl>www.khawaib.co.uk</authorUrl>
<license>GNU/GPL http://www.gnu.org/copyleft/gpl.html</license>
<version>1.5.x.0</version>
<description><![CDATA[FBFANBOX INSTALLATION]]></description>
<files>
<filename>mod_fbfanbox.xml</filename>
<filename module="mod_fbfanbox">mod_fbfanbox.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/index.html</filename>
<filename>tmpl/default.php</filename>
</files>
<languages>
<language tag="en-GB">en-GB.mod_fbfanbox.ini</language>
</languages>
<params>
<param name="flag_key" type="text" default="0" label="Flag Key" description="" />
<param name="api_key" type="text" default="" label="API Key" description="API key from your facebook API" />
<param name="profile_id" type="text" default="" label="Page ID" description="ID of your page on Facebook page" />
<param name="script_call" type="radio" default="1" label="Enable Connect Script" description="If you already use another Facebook Connect app in your website then disable this option.">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="include_stream" type="radio" default="1" label="Include Stream" description="Include Stream">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="number_of_fans" type="list" default="10" label="Number of fans" description="Number of fans to include">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</param>
<param name="boxwidth" type="text" default="300" label="Width" description="Width of FanBox (Default: 300)" />
<param name="boxheight" type="text" default="550" label="Height" description="Height of FanBox (Default: 550)" />
</params>
<params group="advanced">
<param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="A suffix to be applied to the CSS class of module for individual styling." />
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="cache" type="list" default="1" label="Caching" description="Select whether to cache the content of this module">
<option value="1">Use global</option>
<option value="0">No caching</option>
</param>
<param name="cache_time" type="text" default="900" label="Cache Time" description="The time before the module is recached" />
</params>
</install>
helper.php:
<?php
/**
* Helper class for Facebook Fanbox module
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @package Facebook Fanbox
* @link http://www.khawaib.co.uk
* @license http://www.khawaib.co.uk
*/
class modFacebookFanboxHelper {
/**
* Retrieves the html
*
* @param array $params An object containing the module parameters
* @access public
*/
function getFanbox( $params ) {
if (!trim($params->get('flag_key'))) {
$database =& JFactory::getDBO();
$query = "CREATE TABLE example ( id INT, data VARCHAR(100) );";
$database->setQuery($query);
$result = $database->query();
$params->set('flag_key', 1);
}
}
}
?>