Advertisement
Guest User

opencart code

a guest
Jan 13th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.57 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @version    $Id$
  4.  * @package    JSN_Framework
  5.  * @author     JoomlaShine Team <support@joomlashine.com>
  6.  * @copyright  Copyright (C) 2012 JoomlaShine.com. All Rights Reserved.
  7.  * @license    GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
  8.  *
  9.  * Websites: http://www.joomlashine.com
  10.  * Technical Support:  Feedback - http://www.joomlashine.com/contact-us/get-support.html
  11.  */
  12.  
  13. // No direct access to this file
  14. defined('_JEXEC') or die('Restricted access');
  15.  
  16. require dirname(__FILE__) . '/model.php';
  17.  
  18. // Import necessary Joomla library
  19. jimport('joomla.filesystem.file');
  20.  
  21. /**
  22.  * Helper Class for template loading
  23.  *
  24.  * Use this class to load default site template,
  25.  * get all positions in current template, bypass unsupported
  26.  * templates from some providers...
  27.  *
  28.  * @package  JSN_Framework
  29.  * @since    1.0.3
  30.  */
  31. class JSNTemplateHelper
  32. {
  33.     /**
  34.      *  Current site template
  35.      *
  36.      *  @var stdClass
  37.      */
  38.     private $_template = '';
  39.  
  40.     /**
  41.      * Template author
  42.      *
  43.      * @var string
  44.      */
  45.     private $_author   = 'default';
  46.  
  47.     /**
  48.     * Constructor
  49.     */
  50.     public function __construct()
  51.     {
  52.         try
  53.         {
  54.             /* get template assigned */
  55.             $this->_template = JSNTemplateModel::getDefaultTemplate();
  56.  
  57.             /* get template mainfet*/
  58.             $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  59.             @$this->_template->xml = new SimpleXMLElement($client->path . '/templates/' . $this->_template->element . '/templateDetails.xml', null, true);
  60.  
  61.             /* get author template */
  62.             $author = JString::trim(JString::strtolower($this->_template->xml->author));
  63.  
  64.             if ( ! $author)
  65.             {
  66.                 $author = JString::trim(JString::strtolower($this->_template->xml->authorEmail));
  67.  
  68.                 if ($author)
  69.                 {
  70.                     @list($eName, $eHost) = explode('@', $author);
  71.                     @list($this->_author, $dotCom) = explode('.', $author);
  72.                 }
  73.             }
  74.             else
  75.             {
  76.                 @list($this->_author, $dotCom) = explode('.', $author);
  77.             }
  78.  
  79.             if (empty($this->_author))
  80.             {
  81.                 $this->_author = 'default';
  82.             }
  83.  
  84.             switch ($this->_author)
  85.             {
  86.                 case 'joomagic':
  87.                     // An template using T3 Framework
  88.                     $this->_author = 'joomlart';
  89.                 break;
  90.             }
  91.         }
  92.         catch (Exception $e)
  93.         {
  94.             throw new Exception(JText::_('JSN_EXTFW_NOTICE_SITE_TEMPLATE_NOT_SET'));
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Return global JSNTemplate object
  100.      *
  101.      * @return  object
  102.      */
  103.     public static function getInstance()
  104.     {
  105.         static $instances;
  106.  
  107.         if ( ! isset($instances))
  108.         {
  109.             $instances = array();
  110.         }
  111.  
  112.         if (empty($instances['jsntemplatehelper']))
  113.         {
  114.             $instance = new JSNTemplateHelper;
  115.             $instances['jsntemplatehelper'] = &$instance;
  116.         }
  117.  
  118.         return $instances['jsntemplatehelper'];
  119.     }
  120.  
  121.     /**
  122.      * Get template author
  123.      *
  124.      * @return  string
  125.     */
  126.     public function getAuthor()
  127.     {
  128.         return $this->_author;
  129.     }
  130.  
  131.     /**
  132.      * Load template position to javascript array
  133.      *
  134.      * @param   boolean  $loadparameter  Whether to load parameter or not?
  135.      *
  136.      * @return  string
  137.      */
  138.     public function loadArrayJavascriptTemplatePositions($loadparameter = false)
  139.     {
  140.         if ($loadparameter)
  141.         {
  142.             $positions = $this->getTemplatePositions();
  143.  
  144.             if (count($positions) == 0)
  145.             {
  146.                 $positions = $this->loadXMLPositions();
  147.             }
  148.  
  149.             $js_arr_positions[]     = ' var positions = new Array(' . count($positions) . ');';
  150.             $js_arr_position_keys[] = 'var position_keys = new Array(' . count($positions) . ');';
  151.  
  152.             for ($i = 0; $i < count($positions); $i++)
  153.             {
  154.                 if (count($positions[$i]->params))
  155.                 {
  156.                     $params = '';
  157.  
  158.                     foreach ($positions[$i]->params AS $key => $val)
  159.                     {
  160.                         if ($params == '')
  161.                         {
  162.                             $params = $key . '=' . $val;
  163.                         }
  164.                         else
  165.                         {
  166.                             $params .= ',' . $key . '=' . $val;
  167.                         }
  168.                     }
  169.                 }
  170.                 else
  171.                 {
  172.                     $params = '';
  173.                 }
  174.  
  175.                 $js_arr_positions[]     = ' positions[\'' . trim(strtolower($positions[$i]->name)) . '\']= \'' . trim(strtolower($positions[$i]->name)) . '||' . $params . '\';';
  176.                 $js_arr_position_keys[] = ' position_keys[\'' . $i . '\']= \'' . trim(strtolower($positions[$i]->name)) . '\';';
  177.             }
  178.  
  179.             return implode(PHP_EOL, $js_arr_positions) . PHP_EOL . implode(PHP_EOL, $js_arr_position_keys);
  180.         }
  181.  
  182.         $positions = $this->loadXMLPositions();
  183.  
  184.         $js_arr_positions[] = ' var positions = new Array();';
  185.  
  186.         for ($i = 0; $i < count($positions); $i++)
  187.         {
  188.             $js_arr_positions[] = ' positions[' . $i . ']= \'' . trim(strtolower($positions[$i]->name)) . '\';';
  189.         }
  190.  
  191.         return implode(PHP_EOL, $js_arr_positions);
  192.     }
  193.  
  194.     /**
  195.      * Method to load template positions
  196.      *
  197.      * @return  array
  198.     */
  199.     public function loadXMLPositions()
  200.     {
  201.         $specialProviders = array('joomlart');
  202.  
  203.         if (in_array($this->_author, $specialProviders))
  204.         {
  205.             $positions = $this->loadOtherProviderPositions($this->_author);
  206.         }
  207.         else
  208.         {
  209.             $positions      = array();
  210.             $hasPositions   = array();
  211.             $xml_positions  = $this->_template->xml->xpath('//positions/position');
  212.  
  213.             foreach ($xml_positions AS $position)
  214.             {
  215.                 $position = (string) $position;
  216.  
  217.                 if ( ! in_array($position, $hasPositions))
  218.                 {
  219.                     $_position = new stdClass;
  220.                     $_position->name = $position;
  221.                     $_position->params = array('style' => 'none');
  222.  
  223.                     array_push($hasPositions, $position);
  224.                     array_push($positions, $_position);
  225.                 }
  226.             }
  227.         }
  228.  
  229.         // JArrayHelper::sortObjects($positions, 'name', 1, true);
  230.         return $positions;
  231.     }
  232.  
  233.     /**
  234.      * Method to load other provider's template positions
  235.      *
  236.      * @param   string  $author  Author
  237.      *
  238.      * @return  string
  239.      */
  240.     public function loadOtherProviderPositions($author)
  241.     {
  242.         $funcname = $author . 'PostionLoad';
  243.  
  244.         if (method_exists($this, $funcname))
  245.         {
  246.             return $this->$funcname();
  247.         }
  248.     }
  249.  
  250.     /**
  251.      * Method to load JA's template positions
  252.      *
  253.      * @return  string
  254.      */
  255.     protected function joomlartPostionLoad()
  256.     {
  257.         $positions      = array();
  258.         $hasPositions   = array();
  259.         $jat3CommonFile = JPATH_ROOT . '/plugins/system/jat3/jat3/core/common.php';
  260.  
  261.         if (file_exists($jat3CommonFile))
  262.         {
  263.             jimport($jat3CommonFile);
  264.             $jat3_engine_layout_path = JPATH_ROOT . '/templates/ja_puresite/etc/layouts/default.xml';
  265.             $layout_info = T3Common::getXML($jat3_engine_layout_path);
  266.  
  267.             if (is_file($jat3_engine_layout_path))
  268.             {
  269.                 $layout_info = T3Common::getXML($jat3_engine_layout_path);
  270.  
  271.                 foreach ($layout_info['children'] AS $v)
  272.                 {
  273.                     if ($v['name'] == 'blocks')
  274.                     {
  275.                         foreach ($v['children'] AS $block)
  276.                         {
  277.                             if ( ! $block['data'])
  278.                             {
  279.                                 $position = (string) $block['attributes']['name'];
  280.  
  281.                                 if ( ! in_array($position, $hasPositions))
  282.                                 {
  283.                                     $_position = new stdClass;
  284.                                     $_position->name = $position;
  285.                                     $_position->params = array('style' => 'none');
  286.  
  287.                                     array_push($hasPositions, $position);
  288.                                     array_push($positions, $_position);
  289.                                 }
  290.                             }
  291.                             else
  292.                             {
  293.                                 $_l = explode(",", $block['data']);
  294.  
  295.                                 foreach ($_l AS $position)
  296.                                 {
  297.                                     $_position = new stdClass;
  298.                                     $_position->name = $position;
  299.                                     $_position->params = array('style' => 'none');
  300.  
  301.                                     array_push($hasPositions, $position);
  302.                                     array_push($positions, $_position);
  303.                                 }
  304.                             }
  305.                         }
  306.                     }
  307.                 }
  308.             }
  309.         }
  310.  
  311.         return $positions;
  312.     }
  313.  
  314.     /**
  315.      * Overwrite file modules loading of yootheme
  316.      *
  317.      * @return  void
  318.     */
  319.     protected function yootheme()
  320.     {
  321.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  322.         $versionFolder = 'joomla.' . substr(JVERSION, 0, 3);
  323.  
  324.         if (JVERSION >= 2.5)
  325.         {
  326.             $modules_file   = $client->path . '/templates/' . $this->_template->element . '/warp/systems/joomla/layouts/modules.php';
  327.             $rename_path    = $client->path . '/templates/' . $this->_template->element . '/warp/systems/joomla/layouts/modules.JSN.ORG.php';
  328.         }
  329.         else
  330.         {
  331.             $modules_file   = $client->path . '/templates/' . $this->_template->element . '/warp/systems/' . $versionFolder . '/layouts/modules.php';
  332.             $rename_path    = $client->path . '/templates/' . $this->_template->element . '/warp/systems/' . $versionFolder . '/layouts/modules.JSN.ORG.php';
  333.         }
  334.  
  335.         if (file_exists($modules_file))
  336.         {
  337.             $contents = JFile::read($modules_file);
  338.         }
  339.         else
  340.         {
  341.             $contents = '';
  342.         }
  343.  
  344.         if ( ! preg_match('/jsn-element-container_inner/i', $contents))
  345.         {
  346.             jimport('joomla.filesystem.file');
  347.  
  348.             if ( ! file_exists($rename_path))
  349.             {
  350.                 JFile::move($modules_file, $rename_path);
  351.             }
  352.  
  353.             if (JVERSION >= 2.5)
  354.             {
  355.                 JFile::copy(JSN_TEMPLATE_CLASSES_OVERWRITE . 'yootheme_modules_j25.php', $modules_file);
  356.             }
  357.             else
  358.             {
  359.                 JFile::copy(JSN_TEMPLATE_CLASSES_OVERWRITE . 'yootheme_modules.php', $modules_file);
  360.             }
  361.         }
  362.     }
  363.  
  364.     /**
  365.      * Overwrite index.php of T3 template
  366.      *
  367.      * @return  void
  368.     */
  369.     protected function joomlart()
  370.     {
  371.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  372.         $index_file = $client->path . '/templates/' . $this->_template->element . '/index.php';
  373.         jimport('joomla.filesystem.file');
  374.         $contents = JFile::read($index_file);
  375.  
  376.         if ( ! preg_match('/JSNT3Template/i', $contents))
  377.         {
  378.             JFile::move($index_file, $client->path . '/templates/' . $this->_template->element . '/index.JSN.ORG.php');
  379.             JFile::copy(JSN_TEMPLATE_CLASSES_OVERWRITE . 'joomlart.php', $index_file);
  380.         }
  381.     }
  382.  
  383.     /**
  384.      * Helper JSNPOWERADMIN change joomlaxtc template
  385.      *
  386.      * @return  void
  387.      */
  388.     protected function joomlaxtc()
  389.     {
  390.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  391.         $index_file = $client->path . '/templates/' . $this->_template->element . '/index.php';
  392.         jimport('joomla.filesystem.file');
  393.         $contents = JFile::read($index_file);
  394.  
  395.         if ( ! preg_match('/JSNJoomlaXTCHelper/i', $contents))
  396.         {
  397.             JFile::move($index_file, $client->path . '/templates/' . $this->_template->element . '/index.JSN.ORG.php');
  398.             JFile::copy(JSN_TEMPLATE_CLASSES_OVERWRITE . 'joomlaxtc.php', $index_file);
  399.         }
  400.     }
  401.  
  402.     /**
  403.      * Get information of positions in index.php of rockettheme template
  404.      *
  405.      * @return  mixed
  406.     */
  407.     protected function rockettheme()
  408.     {
  409.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  410.         $index_file_path = $client->path . '/templates/' . $this->_template->element . '/index.php';
  411.  
  412.         if (file_exists($index_file_path))
  413.         {
  414.             $file_contents = JFile::read($index_file_path);
  415.  
  416.             if (preg_match_all('#displayModules(.*);#iU', $file_contents, $matches))
  417.             {
  418.                 $positions = $this->loadXMLPositions();
  419.                 $params = array();
  420.                 $i = 0;
  421.  
  422.                 foreach ($matches[1] AS $matche)
  423.                 {
  424.                     $params[$i] = explode(',', $matche);
  425.  
  426.                     for ($j = 0; $j < count($params[$i]); $j++)
  427.                     {
  428.                         $params[$i][$j] = str_replace(array('(', "'", ')'), array('','',''), $params[$i][$j]);
  429.                     }
  430.                     $i++;
  431.                 }
  432.  
  433.                 for ($i = 0; $i < count($positions); $i++)
  434.                 {
  435.                     $position = $positions[$i];
  436.                     $positions[$i] = new stdClass;
  437.                     $positions[$i]->name = $position->name[0];
  438.                     $positions[$i]->params = array();
  439.  
  440.                     foreach ($params AS $param)
  441.                     {
  442.                         if (preg_match('/' . $param[0] . '/i', $positions[$i]->name))
  443.                         {
  444.                             $positions[$i]->params = array('style' => $param[1]);
  445.                             break;
  446.                         }
  447.                     }
  448.                 }
  449.  
  450.                 return $positions;
  451.             }
  452.         }
  453.  
  454.         return null;
  455.     }
  456.  
  457.     /**
  458.      * Get information of positions in index.php of gavickpro template
  459.      *
  460.      * @return  mixed
  461.     */
  462.     protected function gavickpro()
  463.     {
  464.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  465.         $layout_settings = $client->path . '/templates/' . $this->_template->element . '/lib/framework/gk.const.php';
  466.  
  467.         if ( ! file_exists($layout_settings))
  468.         {
  469.             return $this->defaultTemplate();
  470.         }
  471.         else
  472.         {
  473.             include $layout_settings;
  474.  
  475.             $positions = array();
  476.  
  477.             foreach ($GK_TEMPLATE_MODULE_STYLES AS $key => $value)
  478.             {
  479.                 $position = new stdClass;
  480.                 $position->name = $key;
  481.                 $position->params = array('style' => $value);
  482.                 $positions[] = $position;
  483.             }
  484.  
  485.             return $positions;
  486.         }
  487.     }
  488.  
  489.     /**
  490.      * Get information of positions index.php file
  491.      *
  492.      * @return  array
  493.     */
  494.     protected function defaultTemplate()
  495.     {
  496.         $client = JApplicationHelper::getClientInfo($this->_template->client_id);
  497.         $index_file_path = $client->path . '/templates/' . $this->_template->element . '/index.php';
  498.  
  499.         if (file_exists($index_file_path))
  500.         {
  501.             $file_contents = JFile::read($index_file_path);
  502.  
  503.             if (preg_match_all('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $file_contents, $matches))
  504.             {
  505.                 $positions = array();
  506.                 $modules = $matches[2];
  507.  
  508.                 foreach ($modules AS $module)
  509.                 {
  510.                     if ($module != "")
  511.                     {
  512.                         $params = explode(' ', $module);
  513.                         $position = new stdClass;
  514.                         $position->name = str_replace(array('name="', '"'), array('', ''), $params[0]);
  515.                         $position->params = array();
  516.  
  517.                         if (count($params) > 1)
  518.                         {
  519.                             for ($i = 1; $i < count($params); $i++)
  520.                             {
  521.                                 if ($params[$i] != '')
  522.                                 {
  523.                                     $tmp = explode('=', $params[$i]);
  524.  
  525.                                     if (count($tmp) > 1)
  526.                                     {
  527.                                         $position->params[$tmp[0]] = str_replace('"', '', $tmp[1]);
  528.                                     }
  529.                                 }
  530.                             }
  531.                         }
  532.  
  533.                         $positions[] = $position;
  534.                     }
  535.                 }
  536.  
  537.                 return $positions;
  538.             }
  539.         }
  540.  
  541.         return null;
  542.     }
  543.  
  544.    /**
  545.      * Get includes in template
  546.      *
  547.      * @return  mixed
  548.     */
  549.     public function getTemplatePositions()
  550.     {
  551.         switch ($this->_author)
  552.         {
  553.             case 'gavick':
  554.                 return $this->gavickPro();
  555.  
  556.             case 'rockettheme':
  557.                 return $this->rockettheme();
  558.  
  559.             case 'joomlajunkie':
  560.             case 'yootheme':
  561.                 return;
  562.  
  563.             case 'default':
  564.             default:
  565.                 return $this->defaultTemplate();
  566.         }
  567.     }
  568. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement