Ejemplo n.º 1
0
 protected function exportSQLIfNeed($aConf = array())
 {
     foreach ($aConf as $aSQLConf) {
         if (!PluginLib_ModulePlugin::IsDBObjectExist($aSQLConf['table'], $aSQLConf['field'])) {
             $this->ExportSQL($aSQLConf['file']);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Активация плагина
  * Создание дополнительной колонки в таблицe _topic в базе.
  */
 public function Activate()
 {
     if (!PluginLib_ModulePlugin::IsDBObjectExist(Config::Get('db.table.blog'), 'blog_cat')) {
         $this->ExportSQL(dirname(__FILE__) . '/sql.sql');
     }
     $this->Cache_Clean();
     return true;
 }
Ejemplo n.º 3
0
    public function getTopicIDsForMyStuff($oUser, $aFilter = array())
    {
        $sql = 'SELECT 
						user_to 
						FROM ' . Config::Get('db.table.friend') . ' 
						WHERE 
							user_from = ?d 
							AND (status_from = 1
							OR status_from   = 2)
					UNION 
					SELECT 
						user_from 
						FROM ' . Config::Get('db.table.friend') . '
						WHERE 
							user_to = ?d
							AND (status_to = 1
							OR status_to = 2)';
        //first, get a list of all my friends
        $friends = $this->oDb->selectCol($sql, $oUser->getId(), $oUser->getId());
        dump('My friends are: ' . print_r($friends, true));
        //now get a list of topics my friends commented
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        $sAccessWhere = !$oUserCurrent->isAdministrator() && PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic') ? ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($oUserCurrent->getId()) : ' ';
        $sDateWhere = '';
        if (isset($aFilter['more']['topic_add_date']) && isset($aFilter['less']['topic_add_date'])) {
            $sDateWhere = ' AND tc.created >= "' . mysql_real_escape_string($aFilter['more']['topic_add_date']) . '" AND ' . 'tc.created <= "' . mysql_real_escape_string($aFilter['less']['topic_add_date']) . '"';
        }
        $sql = 'SELECT
						tc.topic_id 
					FROM 
						' . Config::Get('plugin.mystuff.table.topic_commented') . ' as tc,
						' . Config::Get('db.table.topic') . ' as t
					WHERE
						tc.user_id IN (?a)
						AND
						tc.topic_id = t.topic_id
						' . $sDateWhere . '
						' . $sAccessWhere . '
					';
        if ($topics = $this->oDb->selectCol($sql, $friends)) {
            $topics = array_unique($topics);
            dump('My Stuff Topics are: ' . print_r($topics, true));
            return $topics;
        }
        //fallback
        return array();
    }
Ejemplo n.º 4
0
    /**
     * Получаем массив id топиков удовлетворяющих фильтру
     * 
     * @param	array		параметры фильтра array(
     * 											'more' => array('fieldName' => 'value'),
     * 											'less' => ...,
     * 											'in' => ...
     * 										)
     * @param	bool		доступен ли плагин для проверки на доступ к топикам
     * @return	array		массив id
     */
    public function GetTopicsForBlogosphereByFilter($aFilter)
    {
        $sWhere = PluginLib_ModuleMapper::BuildFilter($aFilter, 't');
        //фильтрация по уровню доступа к топикам
        if (PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic') && !$aFilter['oUser']->isAdministrator()) {
            $sWhere .= ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($aFilter['oUser']->getId());
        }
        $sql = 'SELECT 
						t.topic_id
					FROM 
						' . Config::Get('db.table.topic') . ' as t
					WHERE 
						1 = 1
						' . $sWhere;
        $aTopics = array();
        if ($aRows = $this->oDb->select($sql)) {
            foreach ($aRows as $aTopic) {
                $aTopics[] = $aTopic['topic_id'];
            }
        }
        return $aTopics;
    }
Ejemplo n.º 5
0
    /**
     * Получаем массив id топиков удовлетворяющих фильтру
     * 
     * @param	array		параметры фильтра 'aUserFilter' array(
     * 												'more' => array('fieldName' => 'value'),
     * 												'less' => ...,
     * 												'in' => ...
     * 												...
     * 											),
     * 											'aTopicFilter' => (...)
     * @param	array		(поле=>направление для сортировки)
     * @param	array		параметры для браузера страниц ('iPage', 'iElementsPerPage')
     * @return	array		массив id
     */
    public function GetTopicsByFilters($aFilters, $aOrder, $aPaging)
    {
        if (isset($aFilters['aUserFilter'])) {
            $sUserWhere = PluginLib_ModuleMapper::BuildFilter($aFilters['aUserFilter'], 'u');
        } else {
            $sUserWhere = '';
        }
        if (isset($aFilters['aTopicFilter'])) {
            $sTopicWhere = PluginLib_ModuleMapper::BuildFilter($aFilters['aTopicFilter'], 't');
        } else {
            $sTopicWhere = '';
        }
        $oUserCurrent = PluginLib_ModuleUser::GetUserCurrent();
        if (!$oUserCurrent->isAdministrator() && PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic')) {
            $sTopicWhere .= ' AND ' . PluginAccesstotopic_ModuleAccess::GetAccessWhereStatment($oUserCurrent->getId());
        }
        $sOrder = PluginLib_ModuleMapper::BuildOrder($aOrder, 't');
        $sLimit = PluginLib_ModuleMapper::BuildLimit($aPaging);
        $sql = 'SELECT 
						t.topic_id
					FROM 
						' . Config::Get('db.table.user') . ' as u,
						' . Config::Get('db.table.topic') . ' as t
					WHERE t.user_id = u.user_id
						' . $sUserWhere . '
						' . $sTopicWhere . '
						' . $sOrder . '
						' . $sLimit;
        $aTopics = array();
        if ($aRows = $this->oDb->select($sql)) {
            foreach ($aRows as $aTopic) {
                $aTopics[] = $aTopic['topic_id'];
            }
        }
        return $aTopics;
    }
Ejemplo n.º 6
0
 /**
  * Высылаем уведомления подписчикам пользователя о новой записи сделанной им,
  * если они включили соответсвующую функцию и у них есть доступ к этой записи.
  * 
  * @param	oTopic		новый топик
  * @param	oBlog		блог в который добавляется запись
  * @param	array		список id пользователей, которым уведомления не высылаются
  * @return	array|null		список id пользователей, которым были высланы уведомления
  */
 public function SendNotificationsToAuthorFriends($oTopic, $oBlog, $aExceptUserId = array())
 {
     if (!is_array($aExceptUserId)) {
         $aExceptUserId = array($aExceptUserId);
     }
     $aSubscriberId = $this->oMapper->GetUserSubscribers($oTopic->getUserId());
     if (!$aSubscriberId) {
         return null;
     }
     $aSubscriberId = array_diff($aSubscriberId, $aExceptUserId);
     $aSubscriber = $this->User_GetUsersByArrayId($aSubscriberId);
     $aRecipientId = array();
     foreach ($aSubscriber as $oSubscriber) {
         if (PluginLib_ModulePlugin::IsPluginAvailable('accesstotopic')) {
             if (!$this->PluginAccesstotopic_Access_CheckUserAccess($oSubscriber, $oTopic, 'read')) {
                 continue;
             }
         }
         if ($this->sendNotificationToAuthorFriend($oSubscriber, $oTopic, $oBlog, $this->User_GetUserCurrent())) {
             $aRecipientId[] = $oSubscriber->getId();
         }
     }
     return $aRecipientId;
 }