Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Get theme key from active layout & active themes
  *
  * @return mixed   NULL if devmode or keycode string
  */
 public static function getThemeKey()
 {
     $t3cache = T3Cache::getT3Cache();
     if ($t3cache->_devmode) {
         return null;
     }
     //no cache in devmode
     $themes = T3Common::get_active_themes();
     $layout = T3Common::get_active_layout();
     $string = 'theme-infos-' . $layout;
     if (is_array($themes)) {
         $string .= serialize($themes);
     }
     return $string;
 }
Ejemplo n.º 3
0
 /**
  * Implement after route event
  *
  * @return null
  */
 function onAfterRoute()
 {
     // Load t3 language file for front-end & template admin.
     //$this->loadLanguage(null, JPATH_ADMINISTRATOR);
     //this language should be loaded by joomla
     $lang = JFactory::getLanguage();
     $lang->load('plg_system_jat3', JPATH_ADMINISTRATOR);
     t3import('core.framework');
     $app = JFactory::getApplication('administrator');
     if ($app->isAdmin()) {
         t3import('core.admin.util');
         // Clean cache if there's something changed backend
         if (JRequest::getCmd('jat3action') || in_array(JRequest::getCmd('task'), array('save', 'delete', 'remove', 'apply', 'publish', 'unpublish'))) {
             if (JRequest::getCmd('jat3action')) {
                 //if template parameter updated => clear cache
                 t3import('core.cache');
                 T3Cache::clean(2);
             } else {
                 $params = T3Common::get_template_based_params();
                 $cache = $params->get('cache');
                 if ($cache) {
                     //if other update: clear cache if cache is enabled
                     t3import('core.cache');
                     T3Cache::clean(1);
                 }
             }
         }
         if (JAT3_AdminUtil::checkPermission()) {
             if (JAT3_AdminUtil::checkCondition_for_Menu()) {
                 JHTML::stylesheet(JURI::root() . T3_CORE . '/element/assets/css/japaramhelper.css');
                 JHTML::script(JURI::root() . T3_CORE . '/element/assets/js/japaramhelper.js', true);
             }
             if (JRequest::getCmd('jat3type') == 'plugin') {
                 $action = JRequest::getCmd('jat3action');
                 t3import('core.ajax');
                 $obj = new JAT3_Ajax();
                 if ($action && method_exists($obj, $action)) {
                     jimport('joomla.filesystem.folder');
                     jimport('joomla.filesystem.file');
                     $obj->{$action}();
                 }
                 return;
             }
             //Load moontools library
             JHtml::_('behavior.framework');
             if (!T3Common::detect()) {
                 return;
             }
             JAT3_AdminUtil::loadStyle();
             JAT3_AdminUtil::loadScipt();
             return;
         } elseif (JRequest::getCmd('jat3type') == 'plugin') {
             $result['error'] = 'Session has expired. Please login before continuing.';
             echo json_encode($result);
             exit;
         }
         return;
     }
     if (!$app->isAdmin() && T3Common::detect()) {
         $action = JRequest::getCmd('jat3action');
         // Process request ajax like action - public
         if ($action) {
             t3import('core.ajaxsite');
             if (method_exists('T3AjaxSite', $action)) {
                 T3AjaxSite::$action();
                 $app->close();
                 //exit after finish action
             }
         }
         // Load core library
         T3Framework::t3_init($this->plgParams);
         // Init T3Engine
         // Get list templates
         $themes = T3Common::get_active_themes();
         $path = T3Path::getInstance();
         // Path in t3 engine
         // Active themes path
         if ($themes && count($themes)) {
             foreach ($themes as $theme) {
                 if ($theme[0] == 'engine') {
                     $path->addPath($theme[0] . '.' . $theme[1], T3Path::path(T3_BASE . '/base-themes/' . $theme[1]), T3Path::url(T3_BASE . '/base-themes/' . $theme[1]));
                 } elseif ($theme[0] == 'template') {
                     $path->addPath($theme[0] . '.' . $theme[1], T3Path::path(T3_TEMPLATE), T3Path::url(T3_TEMPLATE));
                 } else {
                     $themepath = T3Path::path(T3_TEMPLATE) . DS . 'themes';
                     // Check if template use newest folder structure or not
                     // If themes folder is exists in template folder, consider as template use newst folder structure
                     if (@is_dir($themepath)) {
                         $path->addPath($theme[0] . '.' . $theme[1], T3Path::path(T3_TEMPLATE) . DS . 'themes' . DS . $theme[1], T3Path::url(T3_TEMPLATE) . "/themes/{$theme[1]}");
                     } else {
                         // Compatible: if template use older folder structure, try to use it
                         $path->addPath($theme[0] . '.' . $theme[1], T3Path::path(T3_TEMPLATE) . DS . $theme[0] . DS . 'themes' . DS . $theme[1], T3Path::url(T3_TEMPLATE) . "/{$theme[0]}/themes/{$theme[1]}");
                     }
                 }
             }
         }
         // Disable editor if website is access by iphone & handheld
         $device = T3Common::mobile_device_detect();
         if ($device == 'iphone' || $device == 'handheld') {
             $config = JFactory::getConfig();
             $config->set('editor', 'none');
         }
         T3Framework::init_layout();
     }
 }
Ejemplo n.º 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());
     */
 }
Ejemplo n.º 5
0
 /**
  * Get active themes info
  *
  * @return array   Themes information
  */
 public static function get_active_themes_info()
 {
     $key = T3Cache::getThemeKey();
     $t3cache = T3Cache::getT3Cache();
     $themes_info = $t3cache->getObject($key);
     if ($themes_info && isset($themes_info['layout']) && $themes_info['layout']) {
         return $themes_info;
     }
     $themes = T3Common::get_active_themes();
     $themes[] = array('engine', 'default');
     $themes_info = null;
     foreach ($themes as $theme) {
         //$theme_info = T3Common::get_themes (implode('.', $theme));
         $theme_info = T3Common::get_theme_info($theme);
         if (!$theme_info) {
             continue;
         }
         if (!$themes_info) {
             $themes_info = $theme_info;
         } else {
             //merge info
             $themes_info = T3Common::merge_info($theme_info, $themes_info);
         }
     }
     //Get layout if tmpl is not component
     $themes_info['layout'] = null;
     $tmpl = JRequest::getCmd('tmpl');
     if ($tmpl != 'component') {
         $themes_info['layout'] = T3Common::get_layout_info();
     }
     $t3cache->storeObject($themes_info, $key);
     return $themes_info;
 }
Ejemplo n.º 6
0
 function clearCache()
 {
     //clean cache
     t3_import('core/cache');
     T3Cache::clean(10);
     //clear all cache
     echo JText::_('T3 Cache is cleaned!');
     exit;
 }
Ejemplo n.º 7
0
 function onAfterRoute()
 {
     t3import('core.framework');
     $app = JFactory::getApplication('administrator');
     if ($app->isAdmin()) {
         t3import('core.admin.util');
         //Clean cache if there's something changed backend
         if (JRequest::getCmd('jat3action') || in_array(JRequest::getCmd('task'), array('save', 'delete', 'remove', 'apply', 'publish', 'unpublish'))) {
             if (JRequest::getCmd('jat3action')) {
                 //if template parameter updated => clear cache
                 t3_import('core/cache');
                 T3Cache::clean(2);
             } else {
                 $params = T3Common::get_template_based_params();
                 $cache = $params->get('cache');
                 if ($cache) {
                     //if other update: clear cache if cache is enabled
                     t3_import('core/cache');
                     T3Cache::clean(1);
                 }
             }
         }
         if (JAT3_AdminUtil::checkPermission()) {
             if (JAT3_AdminUtil::checkCondition_for_Menu()) {
                 JHTML::stylesheet('', JURI::root() . T3_CORE . '/element/assets/css/japaramhelper.css');
                 JHTML::script('', JURI::root() . T3_CORE . '/element/assets/js/japaramhelper.js', true);
             }
             if (JRequest::getCmd('jat3type') == 'plugin') {
                 $action = JRequest::getCmd('jat3action');
                 t3import('core.ajax');
                 $obj = new JAT3_Ajax();
                 if ($action && method_exists($obj, $action)) {
                     $obj->{$action}();
                 }
                 return;
             }
             if (!T3Common::detect()) {
                 return;
             }
             JAT3_AdminUtil::loadStyle();
             JAT3_AdminUtil::loadScipt();
             return;
         } elseif (JRequest::getCmd('jat3type') == 'plugin') {
             $result['error'] = 'Session has expired. Please login before continuing.';
             echo json_encode($result);
             exit;
         }
         return;
     }
     if (!$app->isAdmin() && T3Common::detect()) {
         $action = JRequest::getCmd('jat3action');
         //process request ajax like action - public
         if ($action) {
             t3import('core.ajaxsite');
             if (method_exists('T3AjaxSite', $action)) {
                 T3AjaxSite::$action();
                 $app->close();
                 //exit after finish action
             }
         }
         //load core library
         T3Framework::t3_init($this->plgParams);
         //Init T3Engine
         //get list templates
         $themes = T3Common::get_active_themes();
         $path = T3Path::getInstance();
         //path in t3 engine
         //active themes path
         if ($themes && count($themes)) {
             foreach ($themes as $theme) {
                 $path->addPath($theme[0] . '.' . $theme[1], T3Path::path(T3_TEMPLATE) . DS . $theme[0] . DS . 'themes' . DS . $theme[1], T3Path::url(T3_TEMPLATE) . "/{$theme[0]}/themes/{$theme[1]}");
             }
         }
         //add default & base theme path
         //if isRTL, auto add rtl theme
         if (T3Common::isRTL() && is_dir(T3Path::path(T3_TEMPLATE_CORE . '/themes/default-rtl'))) {
             $path->addPath('core.default-rtl', T3Path::path(T3_TEMPLATE_CORE . '/themes/default-rtl'), T3Path::url(T3_TEMPLATE_CORE . '/themes/default-rtl'));
         }
         $path->addPath('template.default', T3Path::path(T3_TEMPLATE), T3Path::url(T3_TEMPLATE));
         if (T3Common::isRTL() && is_dir(T3Path::path(T3_BASETHEME . '-rtl'))) {
             $path->addPath('engine.default-rtl', T3Path::path(T3_BASETHEME . '-rtl'), T3Path::url(T3_BASETHEME . '-rtl'));
         }
         $path->addPath('engine.default', T3Path::path(T3_BASETHEME), T3Path::url(T3_BASETHEME));
         T3Framework::init_layout();
     }
 }
Ejemplo n.º 8
0
 /**
  * Set object
  *
  * @param string $name    Object name
  * @param string $object  Instance of object
  *
  * @return void
  */
 function setObject($name, $object)
 {
     $template = T3_ACTIVE_TEMPLATE;
     $preload = T3Preload::getInstance();
     $preload->data[$template][$name] = $object;
     //$key = T3Parameter::getKey ('preload-'.$template, 0);
     $key = T3Cache::getPreloadKey($template);
     $t3cache = T3Cache::getT3Cache();
     $t3cache->storeObject($preload->data[$template], $key);
 }
Ejemplo n.º 9
0
 function get_active_themes_info()
 {
     global $mainframe;
     //$key = T3Parameter::getKey ('themes-info',2);
     $key = T3Cache::getThemeKey();
     $themes_info = T3Cache::get_object($key);
     //force cache
     if ($themes_info && isset($themes_info['layout']) && $themes_info['layout']) {
         return $themes_info;
     }
     $themes = T3Common::get_active_themes();
     $themes[] = array('engine', 'default');
     $themes_info = null;
     foreach ($themes as $theme) {
         //$theme_info = T3Common::get_themes (implode('.', $theme));
         $theme_info = T3Common::get_theme_info($theme);
         if (!$theme_info) {
             continue;
         }
         if (!$themes_info) {
             $themes_info = $theme_info;
         } else {
             //merge info
             $themes_info = T3Common::merge_info($theme_info, $themes_info);
         }
     }
     //Get layout if tmpl is not component
     $themes_info['layout'] = null;
     $tmpl = JRequest::getCmd('tmpl');
     if ($tmpl != 'component') {
         $themes_info['layout'] = T3Common::get_layout_info();
     }
     T3Cache::store_object($themes_info, $key);
     return $themes_info;
 }
Ejemplo n.º 10
0
    /**
     *
     * 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;
    }
Ejemplo n.º 11
0
 function get_file($key)
 {
     if (!$key) {
         return null;
     }
     $t3cache = T3Cache::getInstance();
     $data = null;
     $path = $t3cache->cache_assets_path() . DS . $key;
     if (is_file($path)) {
         $data = @file_get_contents($path);
     }
     return $data;
 }
Ejemplo n.º 12
0
 function optimizecss($css_urls)
 {
     $content = '';
     $optimize_css = T3Parameter::get('optimize_css', 2);
     if (!$optimize_css) {
         return $css_urls;
     }
     //no optimize css
     $output = array();
     $optimize_exclude = trim(T3Parameter::get('optimize_exclude', ''));
     $optimize_exclude_regex = null;
     if ($optimize_exclude) {
         $optimize_exclude_regex = '#' . preg_replace('#[\\r\\n]+#', '|', preg_quote($optimize_exclude)) . '#';
     }
     $files = array();
     $t3cache = T3Cache::getInstance();
     $cachepath = T3Path::path(T3Parameter::get('optimize_folder', 't3-assets'));
     $needupdate = false;
     $filelimit = $optimize_css == 1 ? 20 : 999;
     //limit files import into a css file (in IE7, only first 30 css files are loaded). other case, load unlimited
     $filecount = 0;
     jimport('joomla.filesystem.file');
     foreach ($css_urls as $theme => $urls) {
         foreach ($urls as $url) {
             $ignore = false;
             $import = false;
             $importupdate = false;
             //check ignore to optimize
             // - not a local file
             // - not a css file
             // - in ignore list
             if (!$url[0]) {
                 $ignore = true;
             } else {
                 if (!preg_match('#\\.css$#', $url[0])) {
                     $ignore = true;
                 } else {
                     if ($optimize_exclude_regex && preg_match($optimize_exclude_regex, $url[1])) {
                         $ignore = true;
                     }
                 }
             }
             if (!$ignore && $optimize_css > 1) {
                 //check if need update. for css, the cache should be [filename] or [filename]-import
                 //[filename]-import - for the case there's @import inside
                 //in the ignore of @import, file still optimize but will be put into a sigle file
                 $cfile = $cachepath . DS . md5($url[0]) . '.' . basename($url[0]);
                 if (!(is_file($cfile) && @filemtime($url[0]) < @filemtime($cfile)) && !(is_file($cfile . '-import') && @filemtime($url[0]) < @filemtime($cfile . '-import'))) {
                     //Need update
                     $data = T3Head::compresscss(@JFile::read($url[0]), $url[1]);
                     //check if contain @import
                     if (preg_match('#@import\\s+.+#', $data)) {
                         $import = true;
                         $importupdate = true;
                         $cfile = $cfile . '-import';
                     }
                     //delete old file if exists
                     @JFile::delete($cfile);
                     @JFile::delete($cfile . '-import');
                     //write to cache file
                     @JFile::write($cfile, $data);
                     //make a flag for updating cache file
                     $needupdate = true;
                 } else {
                     if (is_file($cfile . '-import')) {
                         $import = true;
                         $importupdate = false;
                         $cfile = $cfile . '-import';
                     }
                 }
             }
             //match ignore file, or import file, or reach the limit: flush previous files out
             if ($ignore || $import || count($files) == $filelimit) {
                 if (count($files)) {
                     $ourl = T3Head::store_file2($files, 'css', $needupdate);
                     if (!$ourl) {
                         return $css_urls;
                     }
                     //put result into output
                     $output[] = array('', $ourl);
                 }
                 //reset the flag for file update
                 $needupdate = false;
                 $files = array();
             }
             //write out the @import file
             if ($import) {
                 $ourl = T3Head::store_file2(array(array($cfile, '')), 'css', $importupdate);
                 if (!$ourl) {
                     return $css_urls;
                 }
                 //put result into output
                 $output[] = array('', $ourl);
             } else {
                 if ($ignore) {
                     $output[] = $url;
                 } else {
                     if ($optimize_css > 1) {
                         $files[] = array($cfile, '');
                     } else {
                         $files[] = $url;
                     }
                 }
             }
         }
     }
     if (count($files)) {
         $ourl = T3Head::store_file2($files, 'css', $needupdate);
         if (!$ourl) {
             return $css_urls;
         }
         //put result into output
         $output[] = array('', $ourl);
     }
     return array($output);
 }
Ejemplo n.º 13
0
 /**
  * Clear cache
  *
  * @return void
  */
 function clearCache()
 {
     // Clean cache
     t3import('core.cache');
     T3Cache::clean(10);
     echo JText::_('T3 Cache is cleaned!');
     exit;
 }
Ejemplo n.º 14
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;
 }