Sign up to create your own snipts, or login.

Public snipts » stipsan's snipts The latest snipts from stipsan.

showing 1-17 of 17 snipts
  • Example component xml manifest
    <?xml version="1.0" encoding="utf-8"?>
    <install type="component" version="1.5.0" method="upgrade">
    	<name>Foo</name>
    	<author>John Doe</author>
    	<creationDate>2012-12-21 00:00</creationDate>
    	<copyright>(C) 2009-2010 ACME inc. All rights reserved.</copyright>
    	<license>GNU/GPL</license>
    	<authoremail>john@example.com</authoremail>
    	<authorurl>example.com</authorurl>
    	<version>1.0.0</version>
    	<revision>279</revision>
    	<description>Lorem ipsum dolor sit amet.</description>
    </install>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 24, 2010 at 9:59 a.m. EST
  • Ninjaboard basic xml manifest (only showing the metadata part)
    <?xml version="1.0" encoding="utf-8"?>
    <install type="component" version="1.5.0" method="upgrade" mootools="1.2">
    	<name>Ninjaboard</name>
    	<author>NinjaForge</author>
    	<creationDate>2009-02-21</creationDate>
    	<copyright>(C) 2007-2010 Ninja Media Group. All rights reserved.</copyright>
    	<license>GNU/GPL</license>
    	<csslicense>CC-BY</csslicense>
    	<jslicense>MIT</jslicense>
    	<authoremail>support@ninjaforge.com</authoremail>
    	<authorurl>ninjaforge.com</authorurl>
    	<version status="Alpha3" color="red">1.0.0</version>
    	<revision>279</revision>
    	<description>The sharpest user forum</description>
    </install>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 23, 2010 at 6:30 p.m. EST
  • SetRevisionTask for Phing
    <?php
    /*
     * $Id: SetRevisionTask.php 89 2010-01-27 14:33:53Z stian $
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     * This software consists of voluntary contributions made by many individuals
     * and is licensed under the LGPL. For more information please see
     * <http://phing.info>.
     */
    require_once 'phing/Task.php';
    
     /**
      * SetRevisionTask
      *
      * Updates an xml manifest with the revision number from the supplied property
      *
      * @author      Stian Didriksen <stian@ninjaforge.com>
      * @version     $Id: SetRevisionTask.php 89 2010-01-27 14:33:53Z stian $
      * @package     napi.phing.tasks
      */
    class SetRevisionTask extends Task
    {
        /**
         * Property for File
         * @var PhingFile file
         */
        private $file;
    
        /**
         * Property to be set
         * @var string $property
         */
        private $property;
    
        /**
         * Set Property for File containing versioninformation
         * @param PhingFile $file
         */
        public function setFile($file)
        {
            $this->file = $file;
        }
        
        /**
         * Set
         * @param $property
         * @return
         */
        public function setProperty($property)
        {
            $this->property = $property;
        }
    
        /**
         * Main-Method for the Task
         *
         * @return  void
         * @throws  BuildException
         */
        public function main()
        {
            // check supplied attributes
            $this->checkFile();
            $this->checkProperty();
    
            // load file
            $xml = simplexml_load_file($this->file);
    
            // set new version, overwriting the old one
            $xml = $this->setRevision($xml);
    
            // write the new xml to the old xml file
            $xml->asXML($this->file);
        }
    
        /**
         * Sets the new revision number
         *
         * @param SimpleXMLElement $xml
         * @return SimpleXMLElement
         */
        private function setRevision($xml)
        {
        	$xml->revision = $this->property;
    
            return $xml;
        }
    
        /**
         * checks file attribute
         * @return void
         * @throws BuildException
         */
        private function checkFile()
        {
            // check File
            if ($this->file === null ||
            strlen($this->file) == 0) {
                throw new BuildException('You must specify an xml file containing the <revision> tag.', $this->location);
            }
    
            $content = file_get_contents($this->file);
            if (strlen($content) == 0) {
                throw new BuildException(sprintf('Supplied file %s is empty', $this->file), $this->location);
            }
    
        }
    
        /**
         * checks property attribute
         * @return void
         * @throws BuildException
         */
        private function checkProperty()
        {
            if (is_null($this->property) ||
                strlen($this->property) === 0) {
                throw new BuildException('Property for revision number is not set', $this->location);
            }
        }
    }
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 23, 2010 at 6:28 p.m. EST
  • GetVersionTask for Phing
    <?php
    /*
     * $Id: GetVersionTask.php 88 2010-01-27 14:32:06Z stian $
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     * This software consists of voluntary contributions made by many individuals
     * and is licensed under the LGPL. For more information please see
     * <http://phing.info>.
     */
    require_once 'phing/Task.php';
    
     /**
      * GetVersionTask
      *
      * Reads an Xml manifest and retrieves the version string
      * Resulting version number is also published under supplied property.
      *
      * Based on VersionTask by Mike Wittje <mw@mike.wittje.de>
      *
      * @author      Stian Didriksen <stian@ninjaforge.com>
      * @version     $Id: GetVersionTask.php 88 2010-01-27 14:32:06Z stian $
      * @package     napi.phing.tasks
      */
    class GetVersionTask extends Task
    {
        /**
         * Property for File
         * @var PhingFile file
         */
        private $file;
    
        /**
         * Property to be set
         * @var string $property
         */
        private $property;
    
        /**
         * Set Property for File containing versioninformation
         * @param PhingFile $file
         */
        public function setFile($file)
        {
            $this->file = $file;
        }
    
        /**
         * Set
         * @param $property
         * @return
         */
        public function setProperty($property)
        {
            $this->property = $property;
        }
    
        /**
         * Main-Method for the Task
         *
         * @return  void
         * @throws  BuildException
         */
        public function main()
        {
            // check supplied attributes
            $this->checkFile();
            $this->checkProperty();
    
            // load file
            $xml = simplexml_load_file($this->file);
    
            // get new version
            $newVersion = $this->getVersion($xml);
    
            // publish new version number as property
            $this->project->setProperty($this->property, $newVersion);
    
        }
    
        /**
         * Returns new version number
         *
         * @param SimpleXMLElement $xml
         * @return string
         */
        private function getVersion($xml)
        {
            // Extract version
            $newVersion = (string) $xml->version;
            
            // Append status, if the status attribute exists
            if(isset($xml->version['status'])) $newVersion .= (string) $xml->version['status'];
    
            return $newVersion;
        }
    
        /**
         * checks file attribute
         * @return void
         * @throws BuildException
         */
        private function checkFile()
        {
            // check File
            if ($this->file === null ||
            strlen($this->file) == 0) {
                throw new BuildException('You must specify an xml file containing the version number', $this->location);
            }
    
            $content = file_get_contents($this->file);
            if (strlen($content) == 0) {
                throw new BuildException(sprintf('Supplied file %s is empty', $this->file), $this->location);
            }
    
        }
    
        /**
         * checks property attribute
         * @return void
         * @throws BuildException
         */
        private function checkProperty()
        {
            if (is_null($this->property) ||
                strlen($this->property) === 0) {
                throw new BuildException('Property for publishing version number is not set', $this->location);
            }
        }
    }
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 23, 2010 at 6:27 p.m. EST
  • Phing script using GetVersionTask and SetRevisionTask
    <?xml version="1.0" ?>  
    <project name="Example" basedir=".." default="build">
    
    	<taskdef name="getversion" classname="GetVersionTask" classpath="scripts/tasks" />
    	<taskdef name="setrevision" classname="SetRevisionTask" classpath="scripts/tasks" />
    
    	<target name="prepare">
    	
    		<svnlastrevision workingcopy="." propertyname="svn.lastrevision" />
    		<setrevision file="code/administrator/components/com_foo/foo.xml" property="${svn.lastrevision}" />
    	
    		<delete dir="tmp" includeemptydirs="true" />
    		
    		<copy todir="tmp" >
    		  <fileset dir="code">
    		  	<exclude name=".**" />
    		  </fileset>
    		</copy>
    		
    		<move file="tmp/administrator/components/com_foo/foo.xml" tofile="tmp/foo.xml" />
    		<copy todir="tmp/install">
    			<fileset dir="tmp/administrator/components/com_foo/install/">
    			    <exclude name=".**" />
    			  </fileset>
    		</copy>
    		
    	</target>
    	<target name="build">
    		<phingcall target="prepare" />
    		
    		<svnlastrevision workingcopy="." propertyname="svn.lastrevision" />
    		<getversion file="tmp/foo.xml" property="ext.version" />
    		
    		<mkdir dir="packages" /> 
    				
    		<tar destfile="packages/com_foo_v${ext.version}_rev${svn.lastrevision}.tar">
    			<fileset dir="tmp" />
    		</tar>
    		
    		<delete dir="tmp" includeemptydirs="true" />
    		
    	</target>
    	
    </project>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 23, 2010 at 6:26 p.m. EST
  • Phing script for updating koowa snapshot
    <?xml version="1.0" ?>  
    <project name="Update Koowa snapshot" basedir=".." default="build">
    
    	<target name="build">
    
    		<!-- Get the koowa plugin -->
    		<svnexport username="" password="" repositoryurl="https://nooku-framework.svn.sourceforge.net/svnroot/nooku-framework/trunk/code/" todir="code" nocache="true" force="true" />
    		<move file="code/koowa.xml" tofile="code/plugins/system/koowa.xml" overwrite="true"/>
    
    	</target>
    
    </project>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 23, 2010 at 6:01 p.m. EST
  • String.Extras.js and String.Slugify.js backported to M1.11
    /*
    ---
    
    script: String.Extras.js
    
    description: Extends the String native object with a couple of useful utilities; Like a slugify method, useful for url slugs.
    
    license: MIT-style license
    
    authors: Stian Didriksen
    
    requires:
    - core:1.11/String
    - core:1.11/Array
    
    provides: [String.Extras]
    
    ...
    */
    
    (function(){
    
    var special = ['À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','?','?','?','?','?','?','?','?','Ç','ç', '?','?','?','?', 'È','è','É','é','Ê','ê','Ë','ë','?','?','?','?', '?','?','Ì','ì','Í','í','Î','î','Ï','ï', '?','?','?','?','?','?', 'Ñ','ñ','?','?','?','?','Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø','?','?','?','?','?','Š','š','?','?','?','?', '?','?','?','?','?','?','Ù','ù','Ú','ú','Û','û','Ü','ü','?','?', 'Ÿ','ÿ','ý','Ý','Ž','ž','?','?','?','?', 'Þ','þ','Ð','ð','ß','Œ','œ','Æ','æ','µ'];
    
    var standard = ['A','a','A','a','A','a','A','a','Ae','ae','A','a','A','a','A','a','C','c','C','c','C','c','D','d','D','d', 'E','e','E','e','E','e','E','e','E','e','E','e','G','g','I','i','I','i','I','i','I','i','L','l','L','l','L','l', 'N','n','N','n','N','n', 'O','o','O','o','O','o','O','o','Oe','oe','O','o','o', 'R','r','R','r', 'S','s','S','s','S','s','T','t','T','t','T','t', 'U','u','U','u','U','u','Ue','ue','U','u','Y','y','Y','y','Z','z','Z','z','Z','z','TH','th','DH','dh','ss','OE','oe','AE','ae','u'];
    
    var tidymap = {
    	"[\xa0\u2002\u2003\u2009]": " ",
    	"\xb7": "*",
    	"[\u2018\u2019]": "'",
    	"[\u201c\u201d]": '"',
    	"\u2026": "...",
    	"\u2013": "-",
    	"\u2014": "--",
    	"\uFFFD": "&raquo;"
    };
    
    String.extend({
    
    	standardize: function(){
    		var text = this;
    		special.each(function(ch, i){
    			text = text.replace(new RegExp(ch, 'g'), standard[i]);
    		});
    		return text;
    	},
    
    	tidy: function(){
    		var txt = this.toString();
    		$each(tidymap, function(value, key){
    			txt = txt.replace(new RegExp(key, 'g'), value);
    		});
    		return txt;
    	},
    
    	slugify: function(){
    
    		var txt = this.toString().tidy().standardize().replace(/\s+/g,'-').toLowerCase().replace(/[^a-z0-9\-]/g,'');
    		
    		return txt;
    	}
    
    });
    
    })();
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 15, 2010 at 12:23 p.m. EST
  • alias generator mootools 1.2
    window.addEvent('domready', function(){
    		var aliasvalidator = function(){
    			this.value = this.value.replace(/&(.)[^;]*;/, '$1').replace(/ /g, '-').toLowerCase();
    		};
    		var titlevalidator = function(){
    			if(!$('alias').defaultValue) $('alias').value = this.value.replace(/&(.)[^;]*;/, '$1').replace(/ /g, '-').toLowerCase(); 
    		};
    		
    		$('title').addEvents({'keyup': titlevalidator, 'keydown': titlevalidator, 'blur': titlevalidator});
    		$('alias').addEvents({'blur': aliasvalidator});
    		
    	});
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 15, 2010 at 3:10 a.m. EST
  • using mamp in the os x terminal
    export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Feb 09, 2010 at 5:48 a.m. EST
  • Growl Mono style, tweaked
    /* Mono by Christopher Lobay is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. */
    
    body {
    	margin: 0;
    	padding: 0;
    	position: relative;
    	width: 300px;
    	word-wrap: break-word;
    }
    #outer {
    	background: -webkit-gradient(linear, left top, right top, from(rgba(0,0,0,.98)), to(rgba(0,0,0,0.9)));
    	border: 1px solid rgba(0,0,0,0.7); 
    	-webkit-border-radius: 5px;
    }
    #wrapper {
    	background: -webkit-gradient(linear, left top, left bottom, from(rgba(255,255,255,0.25)), to(rgba(255,255,255,0.0)));
    	border-left: 1px solid rgba(255,255,255,0.10);
    	-webkit-background-clip: border;
    	-webkit-background-origin: border;
    	/*border-left: 1px solid rgba(255,255,255,0.0);*/
    	/*border-top: 1px solid rgba(255,255,255,0.6);*/
    	margin-top: 1px;
    	/*margin-left: 1px;*/
    	/*-webkit-box-shadow: hsla(0, 0%, 100%, 0.6) 0px -1px 0, hsla(0, 0%, 100%, 0.1) -1px 0px 0;*/
    	-webkit-box-shadow: hsla(0, 0%, 100%, 0.6) 0px -1px 0;
    	overflow: hidden;
    	padding: 10px 20px 10px 53px;
    	position: relative;
    	-webkit-border-radius: 4px;
    	z-index: 1;
    	min-height: 34px;
    }
    #title, #text, #textwrapper, #icon { position: relative; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease; }
    #title, #text { text-align: left; text-shadow: 0px -1px 1px rgba(0,0,0,0.7); width: 223px; z-index: 3; }
    #title { color: rgba(255,255,255,0.99); font: bold 10pt "Helvetica Neue"; letter-spacing: 0.7pt; -webkit-animation-duration: 0.9s; -webkit-animation-name: 'titleIn'; line-height: 16px; }
    #text { color: rgba(255,255,255,.7); font: normal 8pt "Helvetica Neue"; margin: 2px 0 0 0; text-align: left; -webkit-animation-duration: 1.1s; -webkit-animation-name: 'textIn'; line-height: 15px; }
    #border { background: -webkit-gradient(linear, left top, left bottom, from(rgba(255,255,255,0.0)), to(rgba(255,255,255,0.0)), color-stop(0.5, rgba(255,255,255,0.2))); bottom: 0; left: 0; position: absolute; top: 0; width: 1px; }
    #textwrapper { padding: 0 0 0 11px; -webkit-animation-duration: 0.7s; -webkit-animation-name: 'wrapperIn'; min-height: 34px; }
    #icon { min-height: 32px; min-width: 32px; max-height: 34px; max-width: 34px; left: 10px; opacity: 1; position: absolute; top: 10px; -webkit-animation-duration: 0.5s; -webkit-animation-name: 'iconIn'; z-index: 2; }
    @-webkit-keyframes 'titleIn' { 
    	0% { color: rgba(255,255,255,0); text-shadow: hsla(0, 0%, 100%, 1) 0px -1px 10px; left: 10px; opacity: 0; } 
    	100% { color: rgba(255,255,255,1); text-shadow: 0px -1px 1px rgba(0,0,0,0.7); left: 0px; opacity: 1; } 
    }
    @-webkit-keyframes 'textIn' { 0% { color: rgba(255,255,255,0); text-shadow: hsla(0, 0%, 70%, 1) 0px -1px 10px; left: 30px; opacity: 0; } 100% { color: rgba(255,255,255,0.7); text-shadow: 0px -1px 1px rgba(0,0,0,0.7); left: 0px; opacity: 1; } }
    @-webkit-keyframes 'iconIn' { 0% { left: 30px; opacity: 0; } 100% { left: 10px; opacity: 1; } }
    @-webkit-keyframes 'wrapperIn' { 0% { margin-left: 20px; opacity: 0; } 100% { margin-left: 0px; opacity: 1; } }
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Dec 19, 2009 at 7:43 p.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
  • admin/com_content/access.xml
    <?xml version="1.0" encoding="utf-8" ?>
    <access component="com_content">
    	<section name="component">
    		<action name="core.admin" title="JAction_Admin" description="JAction_Admin_Component_Desc" />
    		<action name="core.manage" title="JAction_Manage" description="JAction_Manage_Component_Desc" />
    		<action name="core.create" title="JAction_Create" description="JAction_Create_Component_Desc" />
    		<action name="core.delete" title="JAction_Delete" description="JAction_Delete_Component_Desc" />
    		<action name="core.edit" title="JAction_Edit" description="JAction_Edit_Component_Desc" />
    		<action name="core.edit.state" title="JAction_Edit_State" description="JAction_Edit_State_Component_Desc" />
    	</section>
    	<section name="category">
    		<action name="core.create" title="CATEGORY_ACCESS_CREATE" description="CATEGORY_ACCESS_CREATE_DESC" />
    		<action name="core.delete" title="CATEGORY_ACCESS_DELETE" description="CATEGORY_ACCESS_DELETE_DESC" />
    		<action name="core.edit" title="CATEGORY_ACCESS_EDIT" description="CATEGORY_ACCESS_EDIT_DESC" />
    		<action name="core.edit.state" title="CATEGORY_ACCESS_EDITSTATE" description="CATEGORY_ACCESS_EDITSTATE_DESC" />
    	</section>
    	<section name="article">
    		<action name="core.delete" title="CONTENT_ACCESS_DELETE" description="CONTENT_ACCESS_DELETE_DESC" />
    		<action name="core.edit" title="CONTENT_ACCESS_EDIT" description="CONTENT_ACCESS_EDIT_DESC" />
    		<action name="core.edit.state" title="CONTENT_ACCESS_EDITSTATE" description="CONTENT_ACCESS_EDITSTATE_DESC" />
    	</section>
    </access>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 26, 2009 at 9:35 a.m. EDT
  • article picker used in NB
    <div class="page" style="float:none;"><a style="float:none;" href="index.php?option=com_content&amp;task=element&amp;tmpl=component&amp;object=term_id" title="Select an Article::Click to open a modal window and pick your content item." class="modal hasTip" rel="{handler:'iframe',size:{x:window.getSize().scrollSize.x-80, y: window.getSize().size.y-80}, onShow:$('sbox-window').setStyles({'padding': 0})}">Select an Article</a></div></div>
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 09, 2009 at 12:33 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
  • JSON formatted parameters
    {"latestpost_settings":{"filter":"1","hours":"8,12","days":"1,2,3","weeks":"1","months":"1,6","years":"1"}}
    

    copy | embed

    0 comments - tagged in  posted by stipsan on Oct 08, 2009 at 8:34 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
Sign up to create your own snipts, or login.