コード例 #1
0
 /**
  * Return the list of all user-apps, in proper order
  *
  * @param	int		user id
  * @return	array	of objects
  */
 public function getUserApps($userid, $state = 0)
 {
     $db = $this->getDBO();
     $query = 'SELECT ' . $db->quoteName('element') . ' FROM ' . $db->quoteName(PLUGIN_TABLE_NAME) . ' WHERE ' . $db->quoteName(EXTENSION_ENABLE_COL_NAME) . '=' . $db->Quote(1) . ' ' . 'AND ' . $db->quoteName('folder') . '=' . $db->Quote('community');
     $db->setQuery($query);
     $elementsResult = $db->loadColumn();
     if ($elementsResult) {
         $elements = "'" . implode($elementsResult, "','") . "'";
     }
     $query = 'SELECT DISTINCT a.* FROM ' . $db->quoteName('#__community_apps') . ' AS a ' . 'WHERE a.' . $db->quoteName('userid') . '=' . $db->Quote($userid) . ' ' . 'AND a.' . $db->quoteName('apps') . '!=' . $db->Quote('news_feed') . 'AND a.' . $db->quoteName('apps') . '!=' . $db->Quote('profile') . 'AND a.' . $db->quoteName('apps') . '!=' . $db->Quote('friends');
     if (!empty($elements)) {
         $query .= 'AND a.' . $db->quoteName('apps') . ' IN (' . $elements . ') ';
     }
     $query .= 'ORDER BY a.' . $db->quoteName('ordering');
     $db->setQuery($query);
     $result = $db->loadObjectList();
     if ($db->getErrorNum()) {
         JError::raiseError(500, $db->stderr());
     }
     // If no data yet, we load default apps
     // and add them to db
     if (empty($result)) {
         $result = $this->getCoreApps();
         foreach ($result as $row) {
             $row->userid = $userid;
             // We need to load the positions based on plugins default config
             $dispatcher = CDispatcher::getInstanceStatic();
             $observers = $dispatcher->getObservers();
             for ($i = 0; $i < count($observers); $i++) {
                 $plgObj = $observers[$i];
                 if (is_object($plgObj)) {
                     $plgObjWrapper = new CPluginWrapper($plgObj);
                     if ($plgObjWrapper->getPluginType() == 'community' && $plgObj->params != null && $plgObjWrapper->getPluginName() == $row->apps) {
                         $row->position = $plgObj->params->get('position', 'content');
                         $row->privacy = $plgObj->params->get('privacy', 0);
                     }
                 }
             }
             $db->insertObject('#__community_apps', $row);
             if ($db->getErrorNum()) {
                 JError::raiseError(500, $db->stderr());
             }
         }
         // Reload the apps
         // @todo: potential duplicate code
         $sql = 'SELECT * FROM ' . $db->quoteName('#__community_apps') . ' WHERE ' . $db->quoteName('userid') . '=' . $db->Quote($userid) . ' AND ' . $db->quoteName('apps') . '!=' . $db->Quote('news_feed') . ' AND ' . $db->quoteName('apps') . '!=' . $db->Quote('profile') . ' AND ' . $db->quoteName('apps') . '!=' . $db->Quote('friends') . ' ORDER BY ' . $db->quoteName('ordering');
         $db->setQuery($sql);
         $result = $db->loadObjectList();
         if ($db->getErrorNum()) {
             JError::raiseError(500, $db->stderr());
         }
     }
     // For 2.2 onwards, wall apps WILL NOT be displayed in the profile page, we need
     // to splice the array out!
     $offset = null;
     for ($i = 0; $i < count($result); $i++) {
         if ($result[$i]->apps == 'walls') {
             $offset = $i;
         }
     }
     if (!is_null($offset)) {
         array_splice($result, $offset, 1);
     }
     return $result;
 }
コード例 #2
0
ファイル: apps.php プロジェクト: Simarpreet05/joomla
 /**
  * Used to trigger applications
  * @param	string	eventName
  * @param	array	params to pass to the function
  * @param	bool	do we need to use custom user ordering ?
  * 
  * returns	Array	An array of object that the caller can then manipulate later.	 	 	 	 
  **/
 public function triggerEvent($event, $arrayParams = null, $needOrdering = false)
 {
     $mainframe =& JFactory::getApplication();
     $dispatcher =& CDispatcher::getInstanceStatic();
     $content = array();
     // Avoid problem with php 5.3
     if (is_null($arrayParams)) {
         $arrayParams = array();
     }
     // @todo: Fix ordering so we only load according to user ordering or site wide plugin ordering.
     // as we cannot use the mainframe to trigger because all the data are already outputed, no way to manipulate it.
     switch ($event) {
         case 'onProfileDisplay':
             $content = $this->_triggerOnProfileDisplay($event);
             break;
         case 'onFormDisplay':
             // We need to merge the arrays
             $content = $this->_triggerOnFormDisplay($event, $arrayParams);
             break;
         default:
             // Trigger system events
             $systemObj = new CEventTrigger();
             call_user_func_array(array(&$systemObj, $event), $arrayParams);
             $observers =& $dispatcher->getObservers();
             //$dispatcher->trigger( $event , $arrayParams );
             for ($i = 0; $i < count($observers); $i++) {
                 $plgObj = $observers[$i];
                 if (is_object($plgObj)) {
                     $plgObjWrapper = new CPluginWrapper($plgObj);
                     if ($plgObjWrapper->getPluginType() == 'community' && method_exists($plgObj, $event) && $plgObjWrapper->getPluginName() != 'input') {
                         // Format the applications with proper heading
                         // Trigger external apps
                         $content[] = call_user_func_array(array(&$plgObj, $event), $arrayParams);
                     }
                 }
             }
             break;
     }
     $this->triggerCount++;
     return $content;
 }