Sign up to create your own snipts, or login.

Public snipts » joomla The latest public joomla snipts.

showing 1-14 of 14 snipts for joomla
  • Replace Mootools in Joomla! with a compressed copy from Google AJAX Libraries API
    <!-- The following code goes into your template's index.php <head> tags, right before the <jdoc:include type="head" /> code block -->
    <?php
    // Replace Mootools in Joomla! with a compressed copy from Google AJAX Libraries API
    $document =& JFactory::getDocument();
    unset($document->_scripts[$this->baseurl . '/media/system/js/mootools.js']);
    ?>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">google.load("mootools", "1.1.2");</script>
    

    copy | embed

    0 comments - tagged in  posted by fevangelou on Feb 28, 2010 at 8:42 p.m. EST
  • Prevent ?tp=1 module position exposure on Joomla! sites using PHP only
    <?php
    // Properly prevent ?tp=1 module position exposure on Joomla! sites using PHP only
    $currentURL = explode('?',substr(JURI::base(),0,-1).$_SERVER['REQUEST_URI']);
    if($_GET['tp']) header('Location: '.$currentURL[0]);
    
    // Same thing using the Joomla! API
    JRequest::setVar('tp',0);
    ?>
    

    copy | embed

    0 comments - tagged in  posted by fevangelou on Feb 28, 2010 at 7:46 p.m. EST
  • How to handle sessions into Joomla Framework
    <?php
    // Set session var
    $session =& JFactory::getSession();
    $value = "paris";
    $session->set('siteshop', $value);
    
    // Get session var
    $session =& JFactory::getSession();
    $mainframe->addCustomHeadTag('<META name="'.$session->get('siteshop').'" content="test"/>');
    ?>
    

    copy | embed

    0 comments - tagged in  posted by bmrateb on Feb 23, 2010 at 5:27 a.m. EST
  • AJAX in Joomla 1.5
    <?php
    	/*
    	/com_mycomponent
    	|-/views
    	|  |-/response
    	|     |-/tmpl
    	|     |  |-default.php
    	|     |  |-index.html
    	|     |-view.raw.php
    	*/
    ?>
    
    <?php
    	//default.php
    	defined('_JEXEC') or die('Restricted access');
    	echo $this->response;
    ?>
    
    <?php
    	//view.raw.php
    	defined('_JEXEC') or die('Restricted access');
    
    	jimport( 'joomla.application.component.view');
    
    	class MycomponentViewResponse extends JView{
    		public function plain($tpl=null){
    			$this->setLayout('default');
    			parent::display($tpl);
    		}
    		public function json($tpl=null){
    			$this->response = json_encode($this->response);
    			$this->setLayout('default');
    			parent::display($tpl);
    		}
    	}
    ?>
    
    
    <?php
    	//somewhere in a controller
    	public function check(){
    		$view = &$this->getView('response','raw');
    		$view->response = 'OK';
    		$view->plain();
    	}
    ?>
    
    In your ajax call use the following base URL:
    
    index.php?option=com_mycomponent&format=raw&
    
    Then append the right controller & task parameters to the url, like:
    
    index.php?option=com_mycomponent&format=raw&controller=mycontroller&task=check
    

    copy | embed

    0 comments - tagged in  posted by dukeofgaming on Jan 18, 2010 at 5:07 p.m. EST
  • Fade Joomla! Message
    <script type="text/javascript" >
     var tmjmosmsg,fx;
     function pload(){
     tmjmosmsg=$$('div.message');
     if($type(tmjmosmsg[0])=='element'){
     var el=tmjmosmsg[0];
     el.setStyle('overflow','hidden');
     var h=el.getSize().size.y;
     fx = new Fx.Styles(el, {duration:900, wait:false});
     //scrol to message
     winScroller = new Fx.Scroll(window);
     winScroller.toElement($('header'));//name of header div
     //delayed start, then remove the html element upon completion
     
    (function(){
     
    fx.start({
     
    'margin-top':-1*h.toInt(),
     
    opacity:0
     
     
    }).chain(function(){el.remove();});
    }).delay(2500);
     
     }
     
     };
     
     window.addEvent('load',function(){
     pload();
     }
     
     );
     </script>
    

    copy | embed

    0 comments - tagged in  posted by jameshafner on Dec 03, 2009 at 11:13 a.m. EST
  • JAccess
    <?php
    /**
     * @version		$Id: access.php 13317 2009-10-24 07:41:26Z eddieajau $
     * @package		Joomla.Framework
     * @subpackage	Access
     * @copyright	Copyright (C) 2005 - 2009 Open Source Matters, Inc. All rights reserved.
     * @license		GNU General Public License version 2 or later; see LICENSE.txt
     */
    
    defined('JPATH_BASE') or die;
    
    jimport('joomla.access.rules');
    jimport('joomla.database.query');
    
    /**
     * Class that handles all access authorization routines.
     *
     * @package 	Joomla.Framework
     * @subpackage	User
     * @since		1.6
     */
    class JAccess
    {
    	protected static $isRoot = null;
    	protected static $viewLevels = array();
    	protected static $assetRules = array();
    
    	/**
    	 * Method to check if a user is authorised to perform an action, optionally on an asset.
    	 *
    	 * @param	integer	Id of the user for which to check authorisation.
    	 * @param	string	The name of the action to authorise.
    	 * @param	mixed	Integer asset id or the name of the asset as a string.  Defaults to the global asset node.
    	 * @return	boolean	True if authorised.
    	 * @since	1.6
    	 */
    	public static function check($userId, $action, $asset = null)
    	{
    		if (self::$isRoot) {
    			return true;
    		}
    		else
    		{
    			// Sanitize inputs.
    			$userId = (int) $userId;
    
    			$action = strtolower(preg_replace('#[\s\-]+#', '.', trim($action)));
    			$asset  = strtolower(preg_replace('#[\s\-]+#', '.', trim($asset)));
    
    			// Default to the root asset node.
    			if (empty($asset)) {
    				$asset = 1;
    			}
    
    			// Get the rules for the asset recursively to root if not already retrieved.
    			if (empty(self::$assetRules[$asset])) {
    				self::$assetRules[$asset] = self::getAssetRules($asset, true);
    			}
    
    			// Get all groups against which the user is mapped.
    			$identities = self::getGroupsByUser($userId);
    			array_unshift($identities, $userId * -1);
    
    			// Make sure we only check for core.admin once during the run.
    			if (self::$isRoot === null)
    			{
    				if (self::getAssetRules(1)->allow('core.admin', $identities)) {
    					self::$isRoot = true;
    					return true;
    				}
    				else {
    					self::$isRoot = false;
    				}
    			}
    
    			return self::$assetRules[$asset]->allow($action, $identities);
    		}
    	}
    
    	/**
    	 * Method to return the JRules object for an asset.  The returned object can optionally hold
    	 * only the rules explicitly set for the asset or the summation of all inherited rules from
    	 * parent assets and explicit rules.
    	 *
    	 * @param	mixed	Integer asset id or the name of the asset as a string.
    	 * @param	boolean	True to return the rules object with inherited rules.
    	 * @return	object	JRules object for the asset.
    	 * @since	1.6
    	 */
    	public static function getAssetRules($asset, $recursive = false)
    	{
    		// Get the database connection object.
    		$db = JFactory::getDbo();
    
    		// Build the database query to get the rules for the asset.
    		$query	= new JQuery;
    		$query->select($recursive ? 'b.rules' : 'a.rules');
    		$query->from('#__assets AS a');
    
    		// If the asset identifier is numeric assume it is a primary key, else lookup by name.
    		if (is_numeric($asset)) {
    			$query->where('a.id = '.(int) $asset);
    		}
    		else {
    			$query->where('a.name = '.$db->quote($asset));
    		}
    
    		// If we want the rules cascading up to the global asset node we need a self-join.
    		if ($recursive)
    		{
    			$query->leftJoin('#__assets AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
    			$query->order('b.lft');
    		}
    
    		// Execute the query and load the rules from the result.
    		$db->setQuery($query);
    		$result	= $db->loadResultArray();
    
    		// Instantiate and return the JRules object for the asset rules.
    		$rules	= new JRules;
    		$rules->mergeCollection($result);
    
    		return $rules;
    	}
    
    	/**
    	 * Method to return a list of user groups mapped to a user.  The returned list can optionally hold
    	 * only the groups explicitly mapped to the user or all groups both explicitly mapped and inherited
    	 * by the user.
    	 *
    	 * @param	integer	Id of the user for which to get the list of groups.
    	 * @param	boolean	True to include inherited user groups.
    	 * @return	array	List of user group ids to which the user is mapped.
    	 * @since	1.6
    	 */
    	public static function getGroupsByUser($userId, $recursive = true)
    	{
    		// Get the database connection object.
    		$db = JFactory::getDbo();
    
    		// Build the database query to get the rules for the asset.
    		$query	= new JQuery;
    		$query->select($recursive ? 'b.id' : 'a.id');
    		$query->from('#__user_usergroup_map AS map');
    		$query->where('map.user_id = '.(int) $userId);
    		$query->leftJoin('#__usergroups AS a ON a.id = map.group_id');
    
    		// If we want the rules cascading up to the global asset node we need a self-join.
    		if ($recursive) {
    			$query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
    		}
    
    		// Execute the query and load the rules from the result.
    		$db->setQuery($query);
    		$result	= $db->loadResultArray();
    
    		// Clean up any NULL or duplicate values, just in case
    		JArrayHelper::toInteger($result);
    		if (empty($result)) {
    			$result = array('1');
    		}
    		else {
    			$result = array_unique($result);
    		}
    
    		return $result;
    	}
    
    	/**
    	 * Method to return a list of view levels for which the user is authorised.
    	 *
    	 * @param	integer	Id of the user for which to get the list of authorised view levels.
    	 * @return	array	List of view levels for which the user is authorised.
    	 * @since	1.6
    	 */
    	public static function getAuthorisedViewLevels($userId)
    	{
    		// Get all groups that the user is mapped to recursively.
    		$groups = self::getGroupsByUser($userId);
    
    		// Only load the view levels once.
    		if (empty(self::$viewLevels))
    		{
    			// Get a database object.
    			$db	= JFactory::getDBO();
    
    			// Build the base query.
    			$query	= new JQuery;
    			$query->select('id, rules');
    			$query->from('`#__viewlevels`');
    
    			// Set the query for execution.
    			$db->setQuery((string) $query);
    
    			// Build the view levels array.
    			foreach ($db->loadAssocList() as $level)
    			{
    				self::$viewLevels[$level['id']] = (array) json_decode($level['rules']);
    			}
    		}
    
    		// Initialize the authorised array.
    		$authorised = array(1);
    		$config = new JConfig;
    
    		// Find the authorized levels.
    		foreach (self::$viewLevels as $level => $rule)
    		{
    			foreach ($rule as $id)
    			{
    				if (($id < 0) && (($id * -1) == $userId))
    				{
    					$authorised[] = $level;
    					break;
    				}
    				// Check to see if the group is mapped to the level.
    				elseif (($id >= 0) && in_array($id, $groups))
    				{
    					$authorised[] = $level;
    					break;
    				}
    			}
    		}
    
    		return $authorised;
    	}
    
    	/**
    	 * Method to return a list of actions for which permissions can be set given a component and section.
    	 *
    	 * @param	string	The component from which to retrieve the actions.
    	 * @param	string	The name of the section within the component from which to retrieve the actions.
    	 * @return	array	List of actions available for the given component and section.
    	 * @since	1.6
    	 */
    	public static function getActions($component, $section = 'component')
    	{
    		$actions = array();
    
    		if (is_file(JPATH_ADMINISTRATOR.'/components/'.$component.'/access.xml'))
    		{
    			$xml = simplexml_load_file(JPATH_ADMINISTRATOR.'/components/'.$component.'/access.xml');
    
    			foreach ($xml->children() as $child)
    			{
    				if ($section == (string) $child['name'])
    				{
    					foreach ($child->children() as $action)
    					{
    						$actions[] = (object) array('name' => (string) $action['name'], 'title' => (string) $action['title'], 'description' => (string) $action['description']);
    					}
    
    					break;
    				}
    			}
    		}
    
    		return $actions;
    	}
    }
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 26, 2009 at 9:44 a.m. EDT
  • Joomla 1.5 Parameters
    <param name="myradiovalue" type="radio" default="0" label="Select an option" description="">
      <option value="0">1</option>
      <option value="1">2</option>
    </param>
    
    <param name="myfile" type="filelist" default="" label="Select a file" description="" directory="administrator" filter="" exclude="" stripext="" />
    
    <param name="calendar" type="calendar" default="5-10-2008" label="Select a date" description="" format="%d-%m-%Y" />
    
    <param name="category" type="category" label="Select a category" description="" section="3" />
    
    <param name="editor" type="editors" default="none" label="Select an editor" />
    
    <param name="folder" type="folderlist" default="" label="Select a folder" directory="administrator" filter="" exclude="" stripext="" />
    
    <param name="helpsite" type="helpsites" default="" label="Select a help site" description="" />
    
    <param name="secretvariable" type="hidden" default="" />
    
    <param name="image" type="imagelist" default="" label="Select an image" description="" directory="" exclude="" stripext="" />
    
    <param name="language" type="languages" client="site" default="en-GB" label="Select a language" description="" />
    
    <param name="listvalue" type="list" default="" label="Select an option" description="">
      <option value="0">Option 1</option>
      <option value="1">Option 2</option>
    </param>
    
    <param name="menu" type="menu" default="mainmenu" label="Select a menu" description="Select a menu" />
    
    <param name="menuitem" type="menuitem" default="45" label="Select a menu item" description="Select a menu item" />
    
    <param name="password" type="password" default="secret" label="Enter a password" description="" size="5" />
    
    <param name="section" type="section" default="" label="Select a section" description="" />
    
    <param type="spacer" default="Advanced parameters" />
    
    <param name="field" type="sql" default="10" label="Select an article" query="SELECT id, title FROM #__table" key_field=”id” value_field=”title” />
    
    <param name="textvalue" type="text" default="Some text" label="Enter some text" description="" size="10" />
    
    <param name="textarea" type="textarea" default="default" label="Enter some text" description="" rows="10" cols="5" />
    
    <param name="timezone" type="timezones" default="-10" label="Select a timezone" description="" />
    
    <param name="usergroups" type="usergroup" default="" label="Select a user group" description="" />
    

    copy | embed

    0 comments - tagged in  posted by jameshafner on Oct 23, 2009 at 2:40 p.m. EDT
  • modal popup autoresize in joomla
    {handler:'iframe',size:{x:window.getSize().scrollSize.x-80, y: window.getSize().size.y-80}, onShow:$('sbox-window').setStyles({'padding': 0})}
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 09, 2009 at 12:30 p.m. EDT
  • INI formatted parameters
    enable_filter=1
    latest_post_hours=8,12
    latest_post_days=1,2,3
    latest_post_weeks=1
    latest_post_months=1,6
    latest_post_years=1
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 08, 2009 at 7:54 p.m. EDT
  • Joomla module params groups
    <params>
    <!--"Module Parameters"-->
    </params>
    <params group="advanced">
    <!--"Advanced Parameters"-->
    </params>
    <params group="other">
    <!--"Other Parameters"-->
    </params>
    <params group="legacy">
    <!--"Legacy Parameters"-->
    </params>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Sep 09, 2009 at 7:00 p.m. EDT
  • Logout URL w/ Return to Index.php
    <a href="index.php?option=com_user&task=logout&return=aW5kZXgucGhw" title="Sign Out">Sign Out</a>
    

    copy | embed

    0 comments - tagged in  posted by jameshafner on Sep 09, 2009 at 5:49 p.m. EDT
  • Unsetting Mootools in J! Head
    $headerjs = $this -> getHeadData ( ) ; headerjs $ = $ this -> getHeadData ();
    reset ( $headerjs [ 'scripts' ] ) ; reset ($ headerjs [ 'scripts']);
    foreach ( $headerjs [ 'scripts' ] as $script => $type ) { foreach ($ headerjs [ 'scripts'] as $ script => $ type) (
     if ( ( strpos ( $script , 'mootools.js' ) ) or ( strpos ( $script , 'caption.js' ) ) ) { if ((strpos ($ script, 'mootools.js')) or (strpos ($ script, 'caption.js'))) (
     unset ( $headerjs [ 'scripts' ] [ $script ] ) ; unset ($ headerjs [ 'scripts'] [$ script]);
      } )
     } )
    $this -> setHeadData ( $headerjs ) ; $ this -> setHeadData ($ headerjs); 
    

    copy | embed

    0 comments - tagged in  posted by jameshafner on Aug 24, 2009 at 11:10 a.m. EDT
  • Joomla, Plesk Permissions
    #!/bin/bash
    # This script makes it easier to get domain directory permissions to work well with Joomla
    
    # First check that this is a valid username
    grep "^${1}:" /etc/passwd > /dev/null 2>&1
    if [ "$?" -ne "0" ]; then
    echo "Sorry, cannot find user ${1} in /etc/passwd or you didn't supply a username"
    echo "Usage: ${0} "
    
    exit 1
    fi
    
    userdir=`grep "^${1}:" /etc/passwd | cut -d: -f6`
    
    if [ -d ${userdir} ] ; then
    echo "Changing to directory ${userdir}"
    cd ${userdir} && chown -R ${1}:psacln httpdocs && chmod -R g+w httpdocs && find httpdocs -type d -exec chmod g+s {} \; && /etc/init.d/httpd reload
    fi
    

    copy | embed

    0 comments - tagged in  posted by bhubbard on Mar 17, 2009 at 10:07 a.m. EDT
  • Resets all article hits to 0.
    update jos_content set hits=0
    

    copy | embed

    0 comments - tagged in  posted by ploughansen on Feb 15, 2009 at 1:11 p.m. EST
Sign up to create your own snipts, or login.