Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------
- Package/Module/Helper/Data.php
- ----------------------------------------------------------------------
- class Package_Module_Helper_Data extends Mage_Core_Helper_Abstract
- {
- /*
- * Inserts array at given position and shifts elements down
- *
- * @param integer $position
- * @param array $array
- * @param array $element
- */
- public function array_insert($position=null,&$array,$element) {
- if (count($array) == 0) {
- $array[] = $element;
- }
- elseif (is_numeric($position) && $position < 0) {
- if((count($array)+position) < 0) {
- $array = array_insert($array,$element,0);
- }
- else {
- $array[count($array)+$position] = $element;
- }
- }
- elseif (is_numeric($position) && isset($array[$position])) {
- $part1 = array_slice($array,0,$position,true);
- $part2 = array_slice($array,$position,null,true);
- $array = array_merge($part1,array($position=>$element),$part2);
- foreach($array as $key=>$item) {
- if (is_null($item)) {
- unset($array[$key]);
- }
- }
- }
- elseif (is_null($position)) {
- $array[] = $element;
- }
- elseif (!isset($array[$position])) {
- $array[$position] = $element;
- }
- $array = array_merge($array);
- return $array;
- }
- }
- ----------------------------------------------------------------------
- Package/Module/Block/Page/Html/Head.php
- ----------------------------------------------------------------------
- class Package_Module_Block_Page_Html_Head extends Mage_Page_Block_Html_Head
- {
- public function addJs($name, $params = "", $sort_order = null)
- {
- $this->addItem('js', $name, $params, null, null, $sort_order);
- return $this;
- }
- public function addItem($type, $name, $params=null, $if=null, $cond=null, $sort_order = null)
- {
- if ($type==='skin_css' && empty($params)) {
- $params = 'media="all"';
- }
- // If sort order is defined then do it
- if($sort_order>=0) {
- $helper = Mage::helper('jquerylib');
- $helper->array_insert($sort_order, $this->_data['items'],array(
- 'type' => $type,
- 'name' => $name,
- 'params' => $params,
- 'if' => $if,
- 'cond' => $cond
- ));
- // Or else append item
- } else {
- $this->_data['items'][$type.'/'.$name] = array(
- 'type' => $type,
- 'name' => $name,
- 'params' => $params,
- 'if' => $if,
- 'cond' => $cond,
- );
- }
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement