예제 #1
0
파일: app.php 프로젝트: Jougito/DynWeb
 /**
  * Laod the app given the username and appname
  * If it doesn't exist, check if it is a core apps and create an entry
  */
 public function loadUserApp($userid, $element)
 {
     $db = JFactory::getDBO();
     $query = 'SELECT * FROM ' . $db->quoteName('#__community_apps') . ' ' . 'WHERE ' . $db->quoteName('apps') . '=' . $db->Quote($element) . '	AND ' . $db->quoteName('userid') . '=' . $db->Quote($userid);
     //echo $strSQL;
     $db->setQuery($query);
     $result = $db->loadObject();
     if ($result) {
         $this->bind($result);
     } else {
         // if it doen's exist, it could be core apps. Look into current
         // dispatcher
         $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 && $plgObj->params->get('coreapp', 0) == 1 && method_exists($plgObj, 'onProfileDisplay')) {
                     // Ok, now we confirm that this plugin is valid
                     // The app should be displayed, just that it is not in the
                     // db yet.
                     // @todo: Get the position and privacy from backend
                     $this->apps = $element;
                     $this->userid = $userid;
                     $this->position = $plgObj->params->get('position', 'content');
                     $this->privacy = $plgObj->params->get('privacy', 0);
                     $this->store();
                 }
             }
         }
     }
     // If id still not loaded. Something is messed up and this object is no good
     return !empty($this->id);
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * 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;
 }
예제 #4
0
 public function _triggerAllFieldsLoad($event, $arrayParams)
 {
     $dispatcher = CDispatcher::getInstanceStatic();
     $observers = $dispatcher->getObservers();
     $result = $arrayParams[0];
     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)) {
                 $content = call_user_func_array(array(&$plgObj, $event), $arrayParams);
                 // Merge it to flatten the layers.
                 if (is_array($content)) {
                     $result = array_merge($result, $content);
                 }
             }
         }
     }
     return $result;
 }