Beispiel #1
0
 function t3_init()
 {
     t3import('core.parameter');
     t3import('core.extendable');
     t3import('core.template');
     t3import('core.basetemplate');
     t3import('core.cache');
     t3import('core.head');
     t3import('core.hook');
     t3import('core.joomla.view');
     if (!class_exists('JModuleHelper', false)) {
         t3import('core.joomla.modulehelper');
     }
     t3import('core.joomla.pagination');
     //Load template language
     $this->loadLanguage('tpl_' . T3_ACTIVE_TEMPLATE, JPATH_SITE);
     $params = T3Common::get_template_based_params();
     //instance cache object.
     $devmode = $params ? $params->get('devmode', '0') == '1' : false;
     T3Cache::getInstance($devmode);
     //Check if enable T3 info mode. Enable by default (if not set)
     if ($params->get('infomode', 1) == 1) {
         if (!JRequest::getCmd('t3info') && JRequest::getCmd('tp')) {
             JRequest::setVar('t3info', JRequest::getCmd('tp'));
         }
     }
     $key = T3Cache::getPageKey();
     $data = null;
     $user =& JFactory::getUser();
     if (!$devmode && JRequest::getCmd('cache') != 'no') {
         T3Cache::setCaching(true);
         JResponse::allowCache(true);
     }
     $data = T3Cache::get($key);
     if ($data) {
         if (!preg_match('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data)) {
             $mainframe = JFactory::getApplication();
             $token = JUtility::getToken();
             $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
             $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
             $data = preg_replace($search, $replacement, $data);
             JResponse::setBody($data);
             echo JResponse::toString($mainframe->getCfg('gzip'));
             if (JDEBUG) {
                 global $_PROFILER;
                 $_PROFILER->mark('afterCache');
                 echo implode('', $_PROFILER->getBuffer());
             }
             $mainframe->close();
         }
     }
     //Preload template
     t3import('core.preload');
     $preload = T3Preload::getInstance();
     $preload->load();
     $doc =& JFactory::getDocument();
     $t3 = T3Template::getInstance($doc);
     $t3->_html = $data;
 }
Beispiel #2
0
 function onAfterRender()
 {
     $app = JFactory::getApplication();
     t3import('core.admin.util');
     $util = new JAT3_AdminUtil();
     if ($app->isAdmin()) {
         ob_start();
         $util->show_button_clearCache();
         $content = ob_get_clean();
         $buffer = JResponse::getBody();
         $buffer = preg_replace('/<\\/body>/', $content . "\n</body>", $buffer);
         JResponse::setBody($buffer);
     }
     if ($util->checkPermission()) {
         if (JAT3_AdminUtil::checkCondition_for_Menu()) {
             // HTML= Parser lib
             require_once T3Path::path(T3_CORE) . DS . 'libs' . DS . "html_parser.php";
             $_body = JResponse::getBody();
             require_once T3Path::path(T3_CORE) . DS . 'admin' . DS . "util.php";
             // Replace content
             $jat3core = new JAT3_AdminUtil();
             $_body = $jat3core->replaceContent($_body);
             if ($_body) {
                 JResponse::setBody($_body);
             }
         }
     }
     if (!T3Common::detect()) {
         return;
     }
     if ($util->checkPermission()) {
         if ($util->checkCondition()) {
             $params = T3Path::path(T3_CORE) . DS . 'admin' . DS . 'index.php';
             if (file_exists($params)) {
                 ob_start();
                 include $params;
                 $content = ob_get_clean();
                 $buffer = JResponse::getBody();
                 $buffer = preg_replace('/<\\/body>/', $content . "\n</body>", $buffer);
                 JResponse::setBody($buffer);
             }
         }
         return;
     }
     if (!$app->isAdmin()) {
         //Expires date set to very long
         //JResponse::setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', time() + 3600000 ) . ' GMT', true );
         //JResponse::setHeader( 'Last-Modified', gmdate( 'D, d M Y H:i:s', time()) . ' GMT', true );
         JResponse::setHeader('Expires', '', true);
         JResponse::setHeader('Cache-Control', 'private', true);
         //Update cache in case of the whole page is cached
         $key = T3Cache::getPageKey();
         if (($data = T3Cache::get($key)) && !preg_match('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data)) {
             $buffer = JResponse::getBody();
             T3Cache::store($buffer, $key);
         }
     }
 }
Beispiel #3
0
 /**
  * Implement after render event
  *
  * @return null
  */
 function onAfterRender()
 {
     $app = JFactory::getApplication();
     t3import('core.admin.util');
     $util = new JAT3_AdminUtil();
     if ($app->isAdmin()) {
         ob_start();
         $util->show_button_clearCache();
         $content = ob_get_clean();
         $buffer = JResponse::getBody();
         $buffer = str_replace('</body>', $content . "\n</body>", $buffer);
         JResponse::setBody($buffer);
     }
     if ($util->checkPermission()) {
         if (JAT3_AdminUtil::checkCondition_for_Menu()) {
             // HTML= Parser lib
             include_once T3Path::path(T3_CORE) . DS . 'libs' . DS . "html_parser.php";
             include_once T3Path::path(T3_CORE) . DS . 'admin' . DS . "util.php";
             $_body = JResponse::getBody();
             // Replace content
             $jat3core = new JAT3_AdminUtil();
             $_body = $jat3core->replaceContent($_body);
             if ($_body) {
                 JResponse::setBody($_body);
             }
         }
     }
     if (!T3Common::detect()) {
         return;
     }
     if ($util->checkPermission()) {
         if ($util->checkCondition()) {
             // Load t3 language file for template admin to avoid to be override by other extensions language
             $extension = 'plg_' . $this->_type . '_' . $this->_name;
             $lang = JFactory::getLanguage();
             $lang->load(strtolower($extension), JPATH_ADMINISTRATOR, null, true, false);
             $params = T3Path::path(T3_CORE) . DS . 'admin' . DS . 'index.php';
             if (file_exists($params)) {
                 ob_start();
                 include $params;
                 $content = ob_get_clean();
                 $buffer = JResponse::getBody();
                 $buffer = preg_replace('/<\\/body>/', $content . "\n</body>", $buffer);
                 JResponse::setBody($buffer);
             }
         }
         return;
     }
     if (!$app->isAdmin()) {
         //Expires date set to very long
         //JResponse::setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', time() + 3600000 ) . ' GMT', true );
         //JResponse::setHeader( 'Last-Modified', gmdate( 'D, d M Y H:i:s', time()) . ' GMT', true );
         JResponse::setHeader('Expires', '', true);
         JResponse::setHeader('Cache-Control', 'private', true);
         //Update cache in case of the whole page is cached
         $t3template = T3Template::getInstance();
         $key = T3Cache::getPageKey();
         //if (($data = T3Cache::get ( $key )) && !preg_match('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $data)) {
         if ($key != null && $t3template->nonecache == false) {
             $time = time();
             JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $time) . ' GMT', true);
             JResponse::setHeader('ETag', md5($key), true);
             $time = sprintf('%20d', $time);
             $buffer = $time . JResponse::getBody();
             $t3cache = T3Cache::getT3Cache();
             $t3cache->store($buffer, $key);
         }
     }
 }
Beispiel #4
0
 function t3_init()
 {
     t3import('core.parameter');
     t3import('core.extendable');
     t3import('core.template');
     t3import('core.cache');
     t3import('core.head');
     t3import('core.hook');
     // Remove JDocumentHTML for compatible J1.6 & J1.7
     // if (!class_exists ('JDocumentHTML', false)) t3import ('core.joomla.documenthtml');
     if (!class_exists('JView', false)) {
         t3import('core.joomla.view');
     }
     if (!class_exists('JModuleHelper', false)) {
         t3import('core.joomla.modulehelper');
     }
     // if (! class_exists('JPagination', false)) t3import('core.joomla.pagination');
     //Load template language
     $this->loadLanguage('tpl_' . T3_ACTIVE_TEMPLATE, JPATH_SITE);
     $params = T3Common::get_template_based_params();
     //instance cache object.
     $devmode = $params ? $params->get('devmode', '0') == '1' : false;
     $t3cache = T3Cache::getT3Cache($devmode);
     //Check if enable T3 info mode. Enable by default (if not set)
     if ($params->get('infomode', 1) == 1) {
         if (!JRequest::getCmd('t3info') && JRequest::getCmd('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) {
             JRequest::setVar('t3info', JRequest::getCmd('tp'));
         }
     }
     $key = T3Cache::getPageKey();
     $user =& JFactory::getUser();
     $data = null;
     if ($devmode || JRequest::getCmd('cache') == 'no') {
         $t3cache->setCaching(false);
         JResponse::allowCache(false);
     } else {
         $t3cache->setCaching(true);
         JResponse::allowCache(true);
     }
     // Get cache
     $data = $t3cache->get($key);
     if ($data) {
         $mainframe = JFactory::getApplication();
         // Check HTTP header
         $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false;
         $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false;
         $cache_time = (int) substr($data, 0, 20);
         $etag = md5($key);
         if ($if_modified_since && $if_none_match && $if_modified_since == $cache_time && $if_none_match == $etag) {
             header('HTTP/1.x 304 Not Modified', true);
             $mainframe->close();
         }
         $data = substr($data, 20);
         // Check cached data
         if (!preg_match('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data)) {
             $token = JUtility::getToken();
             $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
             $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
             $data = preg_replace($search, $replacement, $data);
             JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $cache_time) . ' GMT', true);
             JResponse::setHeader('ETag', $etag, true);
             JResponse::setBody($data);
             echo JResponse::toString($mainframe->getCfg('gzip'));
             if (JDEBUG) {
                 global $_PROFILER;
                 $_PROFILER->mark('afterCache');
                 echo implode('', $_PROFILER->getBuffer());
             }
             $mainframe->close();
         }
     }
     //Preload template
     t3import('core.preload');
     $preload = T3Preload::getInstance();
     $preload->load();
     //$doc = JFactory::getDocument();
     //$t3 = T3Template::getInstance($doc);
     //$t3->_html = $data;
     // Disable joomla cache when browsing by device
     $device = T3Common::mobile_device_detect();
     if ($device !== 'false') {
         $conf = JFactory::getConfig();
         $conf->set('caching', 0);
     }
     // Separate cache when browsing in each device
     /*
     $app = JFactory::getApplication();
     $registeredurlparams = $app->get('registeredurlparams');
     if (empty($registeredurlparams)) {
         $registeredurlparams = new stdClass;
     }
     $registeredurlparams->device = 'CMD';
     $app->set('registeredurlparams', $registeredurlparams);
     JRequest::setVar('device', T3Common::mobile_device_detect());
     */
 }
    /**
     *
     * JT3 Framework render
     */
    public function render()
    {
        $replace = array();
        $matches = array();
        parent::loadLayout();
        $data = $this->_html;
        if (preg_match_all('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data, $matches)) {
            $cache_exclude = parent::getParam('cache_exclude');
            $cache_exclude = new JRegistry($cache_exclude);
            $nc_com = explode(',', $cache_exclude->get('component'));
            $nc_pos = explode(',', $cache_exclude->get('position'));
            $replace = array();
            $matches[0] = array_reverse($matches[0]);
            $matches[1] = array_reverse($matches[1]);
            $matches[2] = array_reverse($matches[2]);
            $count = count($matches[1]);
            $option = JRequest::getCmd('option');
            $headindex = -1;
            //for none cache items
            $nonecachesearch = array();
            $nonecachereplace = array();
            //search for item load in template (css, images, js)
            $regex = '/(href|src)=("|\')([^"\']*\\/templates\\/' . T3_ACTIVE_TEMPLATE . '\\/([^"\']*))\\2/';
            for ($i = 0; $i < $count; $i++) {
                $attribs = JUtility::parseAttributes($matches[2][$i]);
                $type = $matches[1][$i];
                $name = isset($attribs['name']) ? $attribs['name'] : null;
                //no cache => no cache for all jdoc include except head
                //cache: exclude modules positions & components listed in cache exclude param
                //check if head
                if ($type == 'head') {
                    $headindex = $i;
                } else {
                    $content = parent::getBuffer($type, $name, $attribs);
                    $renderer = $this->loadRenderer('module');
                    $poweradmin = JRequest::getCmd('poweradmin', 0);
                    $vsm_changeposition = JRequest::getCmd('vsm_changeposition', 0);
                    //Add a div wrapper for showing block information
                    if ($poweradmin == 1) {
                        //If the page requested to render position only
                        if ($vsm_changeposition == 1) {
                            if ($type == 'modules') {
                                $content = '<div class="jsn-element-container_inner">' . '<div class="jsn-poweradmin-position clearafter" id="' . $name . '-jsnposition">
												<p>' . $name . '</p>
											</div>
											</div>
										    ';
                            } else {
                                if ($type == 'module') {
                                    $key = "mod.{$name}";
                                } else {
                                    if ($type == 'component') {
                                        $content = '<div class="jsn-component-container" id="jsnrender-component"><div class="jsn-show-component-container"><p>' . parent::getTitle() . '</p></div></div>';
                                    } else {
                                        $key = "{$type}.{$name}";
                                    }
                                }
                            }
                        } else {
                            if ($type == 'modules') {
                                $buffer = '';
                                foreach (JModuleHelper::getModules($name) as $mod) {
                                    $buffer .= '<div class="poweradmin-module-item" id="' . $mod->id . '-jsnposition" ><div id="moduleid-' . $mod->id . '-content">' . $renderer->render($mod, $attribs) . '</div></div>';
                                }
                                $content = '<div class="jsn-element-container_inner">' . '<div class="jsn-poweradmin-position clearafter" id="' . $name . '-jsnposition">
											' . $buffer . '
											</div>
											</div>
										    ';
                            } else {
                                if ($type == 'module') {
                                    $key = "mod.{$name}";
                                } else {
                                    if ($type == 'component') {
                                        $app = JFactory::getApplication();
                                        $itemid = JRequest::getVar('itemid', '');
                                        $menu = $app->getMenu();
                                        if ($itemid) {
                                            $menuItem = $menu->getItem($itemid);
                                        } else {
                                            $menuItem = $menu->getActive();
                                        }
                                        $uri = JURI::getInstance();
                                        $route = JRouter::getInstance('site');
                                        $params = $route->parse($uri);
                                        if (empty($params['id']) && !empty($menuItem->id)) {
                                            $uri->parse($menuItem->link);
                                            $params = $route->parse($uri);
                                        }
                                        if (!empty($params['option'])) {
                                            $key = array_search($params['option'], array('', 'com_content', 'com_categories', 'com_banner', 'com_weblinks', 'com_contact', 'com_newsfeeds', 'com_search', 'com_redirect'));
                                            if ($key) {
                                                if (!empty($params['id'])) {
                                                    if ($params['view'] == 'category') {
                                                        $editLink = 'option=com_categories&task=category.edit&id=' . $params['id'] . '&extension=' . $params['option'] . '&tmpl=component';
                                                        $task = 'category.apply';
                                                    } else {
                                                        switch ($key) {
                                                            case 1:
                                                                //com_content
                                                                $editLink = 'option=com_content&task=article.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'article.apply';
                                                                break;
                                                            case 2:
                                                                //com_categories
                                                                $editLink = 'option=com_categories&task=category.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'category.apply';
                                                                break;
                                                            case 3:
                                                                if ($params['view'] == 'client') {
                                                                    $editLink = 'option=com_banners&task=client.edit&id=' . $params['id'] . '&tmpl=component';
                                                                    $task = 'client.apply';
                                                                } else {
                                                                    $editLink = 'option=com_banners&task=banner.edit&id=' . $params['id'] . '&tmpl=component';
                                                                    $task = 'bannber.apply';
                                                                }
                                                                break;
                                                            case 4:
                                                                $editLink = 'option=com_weblinks&task=weblink.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'weblink.apply';
                                                                break;
                                                            case 5:
                                                                $editLink = 'option=com_contact&task=contact.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'contact.apply';
                                                                break;
                                                            case 6:
                                                                $editLink = 'option=com_newsfeeds&task=newsfeed.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'newsfeed.apply';
                                                                break;
                                                            case 7:
                                                                $editLink = 'option=com_search&task=search.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'search.apply';
                                                                break;
                                                            case 8:
                                                                $editLink = 'option=com_redirect&task=link.edit&id=' . $params['id'] . '&tmpl=component';
                                                                $task = 'link.apply';
                                                                break;
                                                        }
                                                    }
                                                } else {
                                                    $editLink = 'option=com_menus&task=item.edit&id=' . $menuItem->id . '&tmpl=component';
                                                    $task = 'item.save';
                                                }
                                            } else {
                                                //in feature
                                                $editLink = '';
                                                $task = '';
                                            }
                                        } else {
                                            $editLink = '';
                                            $task = '';
                                        }
                                        $content = '<div class="jsn-component-container" id="jsnrender-component">' . '<div class="jsn-show-component-container">' . '<div class="jsn-show-component">' . '<span id="tableshow" itemid="' . $menuItem->id . '" editlink="' . base64_encode($editLink) . '" title="' . parent::getTitle() . '" task="' . $task . '"></span>' . '</div>' . '</div>' . $content . '</div>';
                                    } else {
                                        $key = "{$type}.{$name}";
                                    }
                                }
                            }
                        }
                    }
                    //process url
                    $content = preg_replace_callback($regex, array($this, 'processReplateURL'), $content);
                }
                if (!parent::getParam('cache') || $type == 'head' || $type == 'modules' && in_array($name, $nc_pos) || $type == 'component' && in_array($option, $nc_com)) {
                    $replace[$i] = $matches[0][$i];
                    $nonecachesearch[] = $replace[$i];
                    $nonecachereplace[] = $content;
                } else {
                    $replace[$i] = $content;
                }
            }
            //update head
            if ($headindex > -1) {
                T3Head::proccess();
                $head = parent::getBuffer('head');
                $replace[$headindex] = $head;
            }
            //replace all cache content
            $data = str_replace($matches[0], $replace, $data);
            //update cache
            $key = T3Cache::getPageKey();
            if ($key) {
                T3Cache::store($data, $key);
            }
            //replace none cache content
            $data = str_replace($nonecachesearch, $nonecachereplace, $data);
        } else {
            $token = JUtility::getToken();
            $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
            $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
            $data = preg_replace($search, $replacement, $data);
        }
        echo $data;
    }
Beispiel #6
0
 function render()
 {
     $replace = array();
     $matches = array();
     $data = $this->_html;
     if (preg_match_all('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data, $matches)) {
         $cache_exclude = $this->getParam('cache_exclude');
         $cache_exclude = new JParameter($cache_exclude);
         $nc_com = explode(',', $cache_exclude->get('component'));
         $nc_pos = explode(',', $cache_exclude->get('position'));
         $replace = array();
         $matches[0] = array_reverse($matches[0]);
         $matches[1] = array_reverse($matches[1]);
         $matches[2] = array_reverse($matches[2]);
         $count = count($matches[1]);
         $option = JRequest::getCmd('option');
         $headindex = -1;
         //for none cache items
         $nonecachesearch = array();
         $nonecachereplace = array();
         //search for item load in template (css, images, js)
         $regex = '/(href|src)=("|\')([^"\']*\\/templates\\/' . T3_ACTIVE_TEMPLATE . '\\/([^"\']*))\\2/';
         for ($i = 0; $i < $count; $i++) {
             $attribs = JUtility::parseAttributes($matches[2][$i]);
             $type = $matches[1][$i];
             $name = isset($attribs['name']) ? $attribs['name'] : null;
             //no cache => no cache for all jdoc include except head
             //cache: exclude modules positions & components listed in cache exclude param
             //check if head
             if ($type == 'head') {
                 $headindex = $i;
             } else {
                 $content = $this->getBuffer($type, $name, $attribs);
                 //Add a div wrapper for showing block information
                 if ($this->getParam('infomode', 1) == 1 && JRequest::getCmd('t3info')) {
                     if ($type == 'modules') {
                         $key = "pos.{$name}";
                     } else {
                         if ($type == 'module') {
                             $key = "mod.{$name}";
                         } else {
                             if ($type == 'component') {
                                 $key = "content";
                             } else {
                                 $key = "{$type}.{$name}";
                             }
                         }
                     }
                     $content = "<div id=\"jainfo-pos-{$key}\" class=\"jainfo-pos-{$type}\">{$content}</div>";
                 }
                 //process url
                 $content = preg_replace_callback($regex, array($this, 'processReplateURL'), $content);
             }
             if (!$this->getParam('cache') || $type == 'head' || $type == 'modules' && in_array($name, $nc_pos) || $type == 'component' && in_array($option, $nc_com)) {
                 $replace[$i] = $matches[0][$i];
                 $nonecachesearch[] = $replace[$i];
                 $nonecachereplace[] = $content;
             } else {
                 $replace[$i] = $content;
             }
         }
         //update head
         if ($headindex > -1) {
             T3Head::proccess();
             $head = $this->getBuffer('head');
             $replace[$headindex] = $head;
         }
         //replace all cache content
         $data = str_replace($matches[0], $replace, $data);
         //update cache
         $key = T3Cache::getPageKey();
         if ($key) {
             T3Cache::store($data, $key);
         }
         //replace none cache content
         $data = str_replace($nonecachesearch, $nonecachereplace, $data);
     } else {
         $token = JUtility::getToken();
         $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
         $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
         $data = preg_replace($search, $replacement, $data);
     }
     echo $data;
 }