Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }