Example #1
0
 /**
  * Get an appropriate editor profile
  * @access public
  * @return $profile Object
  */
 public function getProfile($plugin = null)
 {
     if (!isset(self::$profile)) {
         $mainframe = JFactory::getApplication();
         $db = JFactory::getDBO();
         $user = JFactory::getUser();
         $option = $this->getComponentOption();
         $query = $db->getQuery(true);
         if (is_object($query)) {
             $query->select('*')->from('#__wf_profiles')->where('published = 1')->order('ordering ASC');
         } else {
             $query = 'SELECT * FROM #__wf_profiles' . ' WHERE published = 1' . ' ORDER BY ordering ASC';
         }
         $db->setQuery($query);
         $profiles = $db->loadObjectList();
         if ($option == 'com_jce') {
             $component_id = JRequest::getInt('component_id');
             if ($component_id) {
                 $component = WFExtensionHelper::getComponent($component_id);
                 $option = isset($component->element) ? $component->element : $component->option;
             }
         }
         // get the Joomla! area (admin or site)
         $area = $mainframe->isAdmin() ? 2 : 1;
         if (!class_exists('Wf_Mobile_Detect')) {
             // load mobile detect class
             require_once dirname(__FILE__) . '/mobile.php';
         }
         $mobile = new Wf_Mobile_Detect();
         // set device values
         if ($mobile->isMobile()) {
             $device = 'phone';
         } else {
             if ($mobile->isTablet()) {
                 $device = 'tablet';
             } else {
                 $device = 'desktop';
             }
         }
         // Joomla! 1.6+
         if (method_exists('JUser', 'getAuthorisedGroups')) {
             $keys = $user->getAuthorisedGroups();
         } else {
             $keys = array($user->gid);
         }
         foreach ($profiles as $item) {
             // at least one user group or user must be set
             if (empty($item->types) && empty($item->users)) {
                 continue;
             }
             // check user groups - a value should always be set
             $groups = array_intersect($keys, explode(',', $item->types));
             // user not in the current group...
             if (empty($groups)) {
                 // no additional users set or no user match
                 if (empty($item->users) || in_array($user->id, explode(',', $item->users)) === false) {
                     continue;
                 }
             }
             // check component
             if ($option !== 'com_jce' && $item->components && in_array($option, explode(',', $item->components)) === false) {
                 continue;
             }
             // set device default as 'desktop,tablet,mobile'
             if (!isset($item->device) || empty($item->device)) {
                 $item->device = 'desktop,tablet,phone';
             }
             // check device
             if (in_array($device, explode(',', $item->device)) === false) {
                 continue;
             }
             // check area
             if (!empty($item->area) && (int) $item->area != $area) {
                 continue;
             }
             // check for individual plugin - use Editor Model as it adds "core" plugins to profile set
             if ($plugin) {
                 wfimport('admin.models.editor');
                 $model = new WFModelEditor();
                 $plugins = (array) $model->getPlugins();
                 if (in_array($plugin, $plugins) === false) {
                     continue;
                 }
             }
             // decrypt params
             if (!empty($item->params)) {
                 wfimport('admin.helpers.encrypt');
                 $item->params = WFEncryptHelper::decrypt($item->params);
             }
             // assign item to profile
             self::$profile = $item;
             // return
             return self::$profile;
         }
         return null;
     }
     return self::$profile;
 }
 private function getProfileVars($plugin = "")
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $option = $this->getComponentOption();
     if ($option == 'com_jce') {
         $component_id = JRequest::getInt('component_id');
         if ($component_id) {
             $component = WFExtensionHelper::getComponent($component_id);
             $option = isset($component->element) ? $component->element : $component->option;
         }
     }
     // get the Joomla! area (admin or site)
     $area = $app->isAdmin() ? 2 : 1;
     if (!class_exists('Wf_Mobile_Detect')) {
         // load mobile detect class
         require_once dirname(__FILE__) . '/mobile.php';
     }
     $mobile = new Wf_Mobile_Detect();
     // desktop - default
     $device = 'desktop';
     // phone
     if ($mobile->isMobile()) {
         $device = 'phone';
     }
     // tablet
     if ($mobile->isTablet()) {
         $device = 'tablet';
     }
     // Joomla! 1.6+
     if (method_exists('JUser', 'getAuthorisedGroups')) {
         $groups = $user->getAuthorisedGroups();
     } else {
         $groups = array($user->gid);
     }
     return array("option" => $option, "area" => $area, "device" => $device, "groups" => $groups, "plugin" => $plugin);
 }