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 page key from URI, browser (version), params (cookie params)
  *
  * @return mixed  NULL if devmode/noncache or string key code
  */
 public static function getPageKey()
 {
     static $key = null;
     if ($key) {
         return $key;
     }
     // No cache in devmode
     $t3cache = T3Cache::getT3Cache();
     if ($t3cache->_devmode) {
         return null;
     }
     // No cache when disable T3 cache
     $config = T3Common::get_template_based_params();
     if ($config->get('cache', 0) == 0) {
         return null;
     }
     // TODO: need to move in cache page code at the end of onAfterRender
     $mainframe = JFactory::getApplication();
     $messages = $mainframe->getMessageQueue();
     // Ignore cache when there're some message
     if (is_array($messages) && count($messages)) {
         return null;
     }
     // If user log-in, ignore cache
     $user = JFactory::getUser();
     if (!$user->get('guest') || $_SERVER['REQUEST_METHOD'] != 'GET') {
         return null;
     }
     // If ie6, ignore cache
     $isIE6 = T3Template::isIE6();
     if ($isIE6) {
         return null;
     }
     // Don't cache when offline
     $cfg = JFactory::getConfig();
     if ($cfg->get('offline')) {
         return null;
     }
     $uri = JRequest::getURI();
     //$browser = T3Common::getBrowserSortName() . "-" . T3Common::getBrowserMajorVersion();
     $mobile = T3Common::mobile_device_detect();
     $params = T3Parameter::getInstance();
     $cparams = '';
     foreach ($params->_params_cookie as $k => $v) {
         $cparams .= $k . "=" . $v . '&';
     }
     //$key = "page - URI: $uri; Browser: $browser; Params: $cparams";
     $key = "page - URI: {$uri}; Mobile: {$mobile}; Params: {$cparams}";
     //T3Common::log($key . '  ' . T3Common::getBrowserSortName() . "-" . T3Common::getBrowserMajorVersion());
     return $key;
 }
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 profile name
  *
  * @return string
  */
 public static function get_active_profile()
 {
     // @todo improve way to select profile
     static $profile = null;
     if ($profile) {
         return $profile;
     }
     $lang = JFactory::getLanguage();
     $lang = strtolower($lang->getTag());
     $params = T3Common::get_template_based_params();
     $pages_profile = strtolower($params->get('pages_profile'));
     $profile = '';
     //Get active profile by pages
     //$menu = JSite::getMenu();
     $menu = JFactory::getApplication()->getMenu();
     $menuid = T3Common::getItemid();
     while ($menuid && !$profile) {
         // Check there is assignment with current language and menu
         $regex = '/(^|,|\\>|\\n)\\s*' . $lang . '#' . $menuid . '(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
         // Check there is assignment with default language and menu
         $regex = '/(^|,|\\>|\\n)\\s*' . $menuid . '(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
         $menuitem = $menu->getItem($menuid);
         $menuid = $menuitem && isset($menuitem->parent) ? $menuitem->parent : 0;
     }
     //Get profile by component name(such as com_content)
     $comname = JRequest::getCmd('option');
     if ($comname) {
         // Check there is assignment with current language and component
         $regex = '/(^|,|\\>|\\n)\\s*' . $lang . '#' . $comname . '\\s*(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
         // Check there is assingment with default language and component
         $regex = '/(^|,|\\>|\\n)\\s*' . $comname . '\\s*(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
     }
     //Get profile by page name (such as home)
     if (JRequest::getCmd('view') == 'frontpage') {
         $regex = '/(^|,|\\>|\\n)\\s*home(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
     }
     // Check there is assingmnet for current language
     $regex = '/(^|,|\\>|\\n)\\s*' . $lang . '(,[^=]*)?=([^\\<\\n]*)/';
     if (preg_match($regex, $pages_profile, $matches)) {
         $profile = $matches[3];
         if (T3Common::profile_exists($profile)) {
             return $profile;
         }
     }
     //Get active profile from user setting
     $profile = T3Common::get_default_profile();
     return $profile;
 }
Ejemplo n.º 6
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.º 7
0
 function get_active_profile()
 {
     static $profile = null;
     if ($profile) {
         return $profile;
     }
     $params = T3Common::get_template_based_params();
     $pages_profile = strtolower($params->get('pages_profile'));
     $profile = '';
     //Get profile by component name(such as com_content)
     $comname = JRequest::getCmd('option');
     if ($comname) {
         $regex = '/(^|,|\\>|\\n)\\s*' . $comname . '\\s*(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
     }
     //Get active profile by pages
     $menu =& JSite::getMenu();
     $menuid = T3Common::getItemid();
     while ($menuid && !$profile) {
         $regex = '/(^|,|\\>|\\n)\\s*' . $menuid . '(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
         $menuitem = $menu->getItem($menuid);
         $menuid = $menuitem && isset($menuitem->parent) ? $menuitem->parent : 0;
     }
     //Get profile by page name (such as home)
     if (JRequest::getCmd('view') == 'frontpage') {
         $regex = '/(^|,|\\>|\\n)\\s*home(,[^=]*)?=([^\\<\\n]*)/';
         if (preg_match($regex, $pages_profile, $matches)) {
             $profile = $matches[3];
             if (T3Common::profile_exists($profile)) {
                 return $profile;
             }
         }
     }
     //Get active profile from user setting
     $profile = T3Common::get_default_profile();
     return $profile;
 }
Ejemplo n.º 8
0
 function clean($t3assets = false)
 {
     //clear T3 cache in cache folder
     $t3cache = T3Cache::getInstance();
     if (!$t3cache) {
         return false;
     }
     if ($t3assets > 0) {
         //clean content cache
         $cache = $t3cache->cache;
         $cache->clean();
     }
     //Clear css/js cached in t3-assets
     if ($t3assets > 1) {
         //Clear assets folder in cache
         $path = $t3cache->cache_assets_path();
         if (is_dir($path)) {
             @JFolder::delete($path);
         }
     }
     if ($t3assets > 2) {
         //clean t3-assets folder, the cache for js/css
         $params = T3Common::get_template_based_params();
         $cache_path = $params->get('optimize_folder', 't3-assets');
         $path = T3Path::path($cache_path);
         if (is_dir($path)) {
             @JFolder::delete($path);
         }
     }
 }