예제 #1
0
 /**
  * Search
  *
  * do the actual search and display the results
  *
  * @return output the search results
  */
 public function search($args)
 {
     if (!SecurityUtil::checkPermission('EZComments::', '::', ACCESS_READ)) {
         return true;
     }
     $minlen = 3;
     $maxlen = 30;
     if (strlen($args['q']) < $minlen || strlen($args['q']) > $maxlen) {
         return LogUtil::registerStatus($this->__f('The comments can only be searched for words that are longer than %1$s and less than %2$s characters!', array($minlen, $maxlen)));
     }
     ModUtil::dbInfoLoad('Search');
     $tables = DBUtil::getTables();
     // ezcomments tables
     $ezcommentstable = $tables['EZComments'];
     $ezcommentscolumn = $tables['EZComments_column'];
     // our own tables
     $searchTable = $tables['search_result'];
     $searchColumn = $tables['search_result_column'];
     // where
     $where = Search_Api_User::construct_where($args, array($ezcommentscolumn['subject'], $ezcommentscolumn['comment']));
     $where .= " AND " . $ezcommentscolumn['url'] . " != ''";
     $sessionId = session_id();
     $insertSql = "INSERT INTO {$searchTable}\n              ({$searchColumn['title']},\n               {$searchColumn['text']},\n               {$searchColumn['extra']},\n               {$searchColumn['module']},\n               {$searchColumn['created']},\n               {$searchColumn['session']})\n            VALUES\n            ";
     $comments = DBUtil::selectObjectArray('EZComments', $where);
     foreach ($comments as $comment) {
         $sql = $insertSql . '(' . '\'' . DataUtil::formatForStore($comment['subject']) . '\', ' . '\'' . DataUtil::formatForStore($comment['comment']) . '\', ' . '\'' . DataUtil::formatForStore($comment['url']) . '\', ' . '\'' . 'EZComments' . '\', ' . '\'' . DataUtil::formatForStore($comment['date']) . '\', ' . '\'' . DataUtil::formatForStore($sessionId) . '\')';
         $insertResult = DBUtil::executeSQL($sql);
         if (!$insertResult) {
             return LogUtil::registerError($this->__('Error! Could not load items.'));
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Performs the actual search processing.
  */
 public function search($args)
 {
     ModUtil::dbInfoLoad('Search');
     $dbtables = DBUtil::getTables();
     $pageTable = $dbtables['content_page'];
     $pageColumn = $dbtables['content_page_column'];
     $contentTable = $dbtables['content_content'];
     $contentColumn = $dbtables['content_content_column'];
     $contentSearchTable = $dbtables['content_searchable'];
     $contentSearchColumn = $dbtables['content_searchable_column'];
     $translatedPageTable = $dbtables['content_translatedpage'];
     $translatedPageColumn = $dbtables['content_translatedpage_column'];
     $sessionId = session_id();
     // check whether we need to search also in translated content
     $multilingual = System::getVar('multilingual');
     $currentLanguage = ZLanguage::getLanguageCode();
     $searchWhereClauses = array();
     $searchWhereClauses[] = '(' . Search_Api_User::construct_where($args, array($pageColumn['title']), $pageColumn['language']) . ')';
     if ($multilingual) {
         $searchWhereClauses[] = '(' . Search_Api_User::construct_where($args, array($translatedPageColumn['title']), $translatedPageColumn['language']) . ')';
     }
     $searchWhereClauses[] = '(' . Search_Api_User::construct_where($args, array($contentSearchColumn['text']), $contentSearchColumn['language']) . ')';
     // add default filters
     $whereClauses = array();
     $whereClauses[] = '(' . implode(' OR ', $searchWhereClauses) . ')';
     $whereClauses[] = $pageColumn['active'] . ' = 1';
     $whereClauses[] = "({$pageColumn['activeFrom']} IS NULL OR {$pageColumn['activeFrom']} <= NOW())";
     $whereClauses[] = "({$pageColumn['activeTo']} IS NULL OR {$pageColumn['activeTo']} >= NOW())";
     $whereClauses[] = $contentColumn['active'] . ' = 1';
     $whereClauses[] = $contentColumn['visiblefor'] . (UserUtil::isLoggedIn() ? ' <= 1' : ' >= 1');
     $titleFields = $pageColumn['title'];
     $additionalJoins = '';
     if ($multilingual) {
         // if searching in non-default languages, we need the translated title
         $titleFields .= ', ' . $translatedPageColumn['title'] . ' AS translatedTitle';
         // join also the translation table if required
         $additionalJoins = "LEFT OUTER JOIN {$translatedPageTable} ON {$translatedPageColumn['pageId']} = {$pageColumn['id']} AND {$translatedPageColumn['language']} = '{$currentLanguage}'";
         // prevent content snippets in other languages
         $whereClauses[] = $contentSearchColumn['language'] . ' = \'' . $currentLanguage . '\'';
     }
     $where = implode(' AND ', $whereClauses);
     $sql = "\n            SELECT DISTINCT {$titleFields},\n            {$contentSearchColumn['text']} AS description,\n            {$pageColumn['id']} AS pageId,\n            {$pageColumn['cr_date']} AS createdDate\n            FROM {$pageTable}\n            JOIN {$contentTable}\n            ON {$contentColumn['pageId']} = {$pageColumn['id']}\n            JOIN {$contentSearchTable}\n            ON {$contentSearchColumn['contentId']} = {$contentColumn['id']}\n            {$additionalJoins}\n            WHERE {$where}\n        ";
     $result = DBUtil::executeSQL($sql);
     if (!$result) {
         return LogUtil::registerError($this->__('Error! Could not load items.'));
     }
     $objectArray = DBUtil::marshallObjects($result);
     foreach ($objectArray as $object) {
         $pageTitle = $object['page_title'];
         if ($object['translatedTitle'] != '') {
             $pageTitle = $object['translatedTitle'];
         }
         $searchItemData = array('title' => $pageTitle, 'text' => $object['description'], 'extra' => $object['pageId'], 'created' => $object['createdDate'], 'module' => 'Content', 'session' => $sessionId);
         if (!\DBUtil::insertObject($searchItemData, 'search_result')) {
             return \LogUtil::registerError($this->__('Error! Could not save the search results.'));
         }
     }
     return true;
 }
예제 #3
0
    /**
     * Search plugin main function
     **/
    public function search($args)
    {
        ModUtil::dbInfoLoad('Search');
        $dbtables = DBUtil::getTables();

        $searchTable = $dbtables['search_result'];
        $searchColumn = $dbtables['search_result_column'];
        $pageTable = $dbtables['content_page'];
        $pageColumn = $dbtables['content_page_column'];
        $contentTable = $dbtables['content_content'];
        $contentColumn = $dbtables['content_content_column'];
        $contentSearchTable = $dbtables['content_searchable'];
        $contentSearchColumn = $dbtables['content_searchable_column'];

        $sessionId = session_id();

        $where = Search_Api_User::construct_where($args, 
				array($contentSearchColumn['text']), null);
        $wheretitle = Search_Api_User::construct_where($args, 
				array($pageColumn['title']), $pageColumn['language']);

		// Direct SQL way of searching in titles and searchable content items 
		// for Pages and Content items that are visible/active
		// Optimization and conversion into DBUtil calls should be done
        $sql = "INSERT INTO $searchTable
            ($searchColumn[title],
            $searchColumn[text],
            $searchColumn[module],
            $searchColumn[extra],
            $searchColumn[created],
            $searchColumn[session])
            SELECT DISTINCT $pageColumn[title],
            $contentSearchColumn[text],
            'Content',
            $pageColumn[id],
            $pageColumn[cr_date] AS createdDate,
            '" . DataUtil::formatForStore($sessionId) . "'
            FROM $pageTable
            JOIN $contentTable
            ON $contentColumn[pageId] = $pageColumn[id]
            JOIN $contentSearchTable
            ON $contentSearchColumn[contentId] = $contentColumn[id]
            WHERE ($where or $wheretitle) AND $pageColumn[active] = 1 AND ($pageColumn[activeFrom] IS NULL OR $pageColumn[activeFrom] <= NOW()) AND ($pageColumn[activeTo] IS NULL OR $pageColumn[activeTo] >= NOW()) AND $contentColumn[active] = 1 AND $contentColumn[visiblefor] " . (UserUtil::isLoggedIn() ? '<=1' : '>=1');

        $dbresult = DBUtil::executeSQL($sql);
        if (!$dbresult) {
            return LogUtil::registerError($this->__('Error! Could not load any Content pages or items.'));
        }
        return true;
    }
예제 #4
0
    /**
     * Search plugin main function
     **/
    public function search($args)
    {
        if (!SecurityUtil::checkPermission('News::', '::', ACCESS_READ)) {
            return true;
        }

        ModUtil::dbInfoLoad('Search');
        $tables = DBUtil::getTables();
        $newsColumn = $tables['news_column'];

        $where = Search_Api_User::construct_where($args,
                array($newsColumn['title'],
                $newsColumn['hometext'],
                $newsColumn['bodytext']),
                $newsColumn['language']);
        // Only search in published articles that are currently visible
        $where .= " AND ({$newsColumn['published_status']} = '0')";
        $date = DateUtil::getDatetime();
        $where .= " AND ('$date' >= {$newsColumn['from']} AND ({$newsColumn['to']} IS NULL OR '$date' <= {$newsColumn['to']}))";

        $sessionId = session_id();

        ModUtil::loadApi('News', 'user');

        $permChecker = new News_ResultChecker($this->getVar('enablecategorization'), $this->getVar('enablecategorybasedpermissions'));
        $articles = DBUtil::selectObjectArrayFilter('news', $where, null, null, null, '', $permChecker, null);

        foreach ($articles as $article)
        {
            $item = array(
                'title' => $article['title'],
                'text'  => $article['hometext'],
                'extra' => $article['sid'],
                'created' => $article['from'],
                'module'  => 'News',
                'session' => $sessionId
            );
            $insertResult = DBUtil::insertObject($item, 'search_result');
            if (!$insertResult) {
                return LogUtil::registerError($this->__('Error! Could not load any articles.'));
            }
        }

        return true;
    }
예제 #5
0
파일: Search.php 프로젝트: rmaiwald/Reviews
 /**
  * Executes the actual search process.
  *
  * @param array $args List of arguments.
  *
  * @return boolean
  *
  * @throws RuntimeException Thrown if search results can not be saved
  */
 public function search(array $args = array())
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         return '';
     }
     // ensure that database information of Search module is loaded
     ModUtil::dbInfoLoad('Search');
     // save session id as it is used when inserting search results below
     $sessionId = session_id();
     // retrieve list of activated object types
     $searchTypes = isset($args['objectTypes']) ? (array) $args['objectTypes'] : (array) FormUtil::getPassedValue('reviewsSearchTypes', array(), 'GETPOST');
     $controllerHelper = new Reviews_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'search', 'action' => 'search');
     $allowedTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $entityManager = ServiceUtil::getService('doctrine.entitymanager');
     $currentPage = 1;
     $resultsPerPage = 50;
     foreach ($searchTypes as $objectType) {
         if (!in_array($objectType, $allowedTypes)) {
             continue;
         }
         $whereArray = array();
         $languageField = null;
         switch ($objectType) {
             case 'review':
                 $whereArray[] = 'tbl.workflowState';
                 $whereArray[] = 'tbl.title';
                 $whereArray[] = 'tbl.text';
                 $whereArray[] = 'tbl.zlanguage';
                 $whereArray[] = 'tbl.reviewer';
                 $whereArray[] = 'tbl.email';
                 $whereArray[] = 'tbl.score';
                 $whereArray[] = 'tbl.url';
                 $whereArray[] = 'tbl.url_title';
                 $whereArray[] = 'tbl.cover';
                 $whereArray[] = 'tbl.coverUpload';
                 $languageField = 'zlanguage';
                 break;
         }
         $where = Search_Api_User::construct_where($args, $whereArray);
         $entityClass = $this->name . '_Entity_' . ucwords($objectType);
         $repository = $entityManager->getRepository($entityClass);
         // get objects from database
         list($entities, $objectCount) = $repository->selectWherePaginated($where, '', $currentPage, $resultsPerPage, false);
         if ($objectCount == 0) {
             continue;
         }
         $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
         $descriptionField = $repository->getDescriptionFieldName();
         foreach ($entities as $entity) {
             $urlArgs = array('ot' => $objectType);
             // create identifier for permission check
             $instanceId = '';
             foreach ($idFields as $idField) {
                 $urlArgs[$idField] = $entity[$idField];
                 if (!empty($instanceId)) {
                     $instanceId .= '_';
                 }
                 $instanceId .= $entity[$idField];
             }
             $urlArgs['id'] = $instanceId;
             /* commented out as it could exceed the maximum length of the 'extra' field
                if (isset($entity['slug'])) {
                    $urlArgs['slug'] = $entity['slug'];
                }*/
             // perform permission check
             if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', $instanceId . '::', ACCESS_OVERVIEW)) {
                 continue;
             }
             $title = $entity->getTitleFromDisplayPattern();
             $description = !empty($descriptionField) ? $entity[$descriptionField] : '';
             $created = isset($entity['createdDate']) ? $entity['createdDate']->format('Y-m-d H:i:s') : '';
             $searchItemData = array('title' => $title, 'text' => $description, 'extra' => serialize($urlArgs), 'created' => $created, 'module' => $this->name, 'session' => $sessionId);
             if (!DBUtil::insertObject($searchItemData, 'search_result')) {
                 return LogUtil::registerError($this->__('Error! Could not save the search results.'));
             }
         }
     }
     return true;
 }
예제 #6
0
    /**
     * Perform a search.
     *
     * Parameters passed in the $args array:
     * -------------------------------------
     * ? $args['q'] ?.
     * ? $args[?]   ?.
     *
     * @param array $args All parameters passed to this function.
     *
     * @return bool True on success or null result, false on error.
     */
    public function search($args)
    {
        ModUtil::dbInfoLoad('Search');
        $table = DBUtil::getTables();
        $pagestable = $table['pages'];
        $pagescolumn = $table['pages_column'];
        $searchTable = $table['search_result'];
        $searchColumn = $table['search_result_column'];

        $where = Search_Api_User::construct_where(
            $args,
            array(
                $pagescolumn['title'],
                $pagescolumn['content']
            ),
            null
        );

        $sessionId = session_id();

        /*
          // define the permission filter to apply
          $permFilter = array(array('realm'           => 0,
          'component_left'  => 'Pages',
          'component_right' => 'Page',
          'instance_left'   => 'title',
          'instance_right'  => 'pageid',
          'level'           => ACCESS_READ));
         */

        // get the objects from the db
        $permChecker = new pages_result_checker();
        $objArray = DBUtil::selectObjectArrayFilter('pages', $where, 'pageid', 1, -1, '', $permChecker);
        if ($objArray === false) {
            return LogUtil::registerError($this->__('Error! Could not load any page.'));
        }

        $addcategorytitletopermalink = ModUtil::getVar('Pages', 'addcategorytitletopermalink');

        $insertSql =
                "INSERT INTO $searchTable
                ($searchColumn[title],
                $searchColumn[text],
                $searchColumn[extra],
                $searchColumn[created],
                $searchColumn[module],
                $searchColumn[session])
                VALUES ";

        // Process the result set and insert into search result table
        foreach ($objArray as $obj) {
            if ($addcategorytitletopermalink) {
                $extra = serialize(array(
                    'pageid' => $obj['pageid'],
                    'cat' => isset($obj['__CATEGORIES__']['Main']['name']) ? $obj['__CATEGORIES__']['Main']['name'] : null));
            } else {
                $extra = serialize(array('pageid' => $obj['pageid']));
            }
            $sql = $insertSql . '('
                    . '\'' . DataUtil::formatForStore($obj['title']) . '\', '
                    . '\'' . DataUtil::formatForStore($obj['content']) . '\', '
                    . '\'' . DataUtil::formatForStore($extra) . '\', '
                    . '\'' . DataUtil::formatForStore($obj['cr_date']) . '\', '
                    . '\'' . 'Pages' . '\', '
                    . '\'' . DataUtil::formatForStore($sessionId) . '\')';
            $insertResult = DBUtil::executeSQL($sql);
            if (!$insertResult) {
                return LogUtil::registerError($this->__('Error! Could not load any page.'));
            }
        }

        return true;
    }
예제 #7
0
function search_construct_where($args, $fields, $mlfield = null)
{
    LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array('search_construct_where()', 'Search_Api_User::construct_where()')), E_USER_DEPRECATED);
    return Search_Api_User::construct_where($args, $fields, $mlfield);

}
예제 #8
0
파일: Search.php 프로젝트: rmaiwald/MUBoard
 /**
  * Executes the actual search process.
  *
  * @param array $args List of arguments.
  *
  * @return boolean
  */
 public function search($args)
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         return '';
     }
     // ensure that database information of Search module is loaded
     ModUtil::dbInfoLoad('Search');
     // save session id as it is used when inserting search results below
     $sessionId = session_id();
     // retrieve list of activated object types
     //$searchTypes = isset($args['objectTypes']) ? (array)$args['objectTypes'] : (array)FormUtil::getPassedValue('search_mediarepository_types', array(), 'GETPOST');
     $searchTypes[] = 'posting';
     $controllerHelper = new MUBoard_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'search', 'action' => 'search');
     //$allowedTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $allowedTypes[] = 'posting';
     $entityManager = ServiceUtil::getService('doctrine.entitymanager');
     $currentPage = 1;
     $resultsPerPage = 50;
     //  foreach ($searchTypes as $objectType) {
     /* if (!in_array($objectType, $allowedTypes)) {
     		continue;
     		}*/
     $whereArray = array();
     $languageField = null;
     $whereArray[] = 'title';
     $whereArray[] = 'text';
     /*switch ($objectType) {
     		 case 'repository':
     		$whereArray[] = 'name';
     		$whereArray[] = 'workDirectory';
     		$whereArray[] = 'storageDirectory';
     		$whereArray[] = 'cacheDirectory';
     		$whereArray[] = 'uploadNamingPrefix';
     		$whereArray[] = 'mailRecipient';
     		break;
     		case 'mediaHandler':
     		$whereArray[] = 'mimeType';
     		$whereArray[] = 'fileType';
     		$whereArray[] = 'foundMimeType';
     		$whereArray[] = 'foundFileType';
     		$whereArray[] = 'handlerName';
     		$whereArray[] = 'title';
     		$whereArray[] = 'image';
     		break;
     		case 'medium':
     		$whereArray[] = 'title';
     		$whereArray[] = 'keywords';
     		$whereArray[] = 'description';
     		$whereArray[] = 'description2';
     		$whereArray[] = 'dateTaken';
     		$whereArray[] = 'placeTaken';
     		$whereArray[] = 'notes';
     		$whereArray[] = 'license';
     		$whereArray[] = 'areamap';
     		$whereArray[] = 'url';
     		$whereArray[] = 'mediaHandler';
     		$whereArray[] = 'fileUpload';
     		break;
     		case 'thumbSize':
     		$whereArray[] = 'name';
     		break;
     		}*/
     $where = Search_Api_User::construct_where($args, $whereArray, $languageField);
     $repository = $entityManager->getRepository($this->name . '_Entity_' . ucfirst($objectType));
     $repository = MUBoard_Util_Model::getPostingRepository();
     // get objects from database
     list($entities, $objectCount) = $repository->selectWherePaginated($where, '', $currentPage, $resultsPerPage, false);
     if ($objectCount == 0) {
         continue;
     }
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     $titleField = $repository->getTitleFieldName();
     $descriptionField = $repository->getDescriptionFieldName();
     foreach ($entities as $entity) {
         $urlArgs = array('ot' => $objectType);
         // create identifier for permission check
         $instanceId = '';
         foreach ($idFields as $idField) {
             $urlArgs[$idField] = $entity[$idField];
             if (!empty($instanceId)) {
                 $instanceId .= '_';
             }
             $instanceId .= $entity[$idField];
         }
         $urlArgs['id'] = $instanceId;
         if (isset($entity['slug'])) {
             $urlArgs['slug'] = $entity['slug'];
         }
         if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', $instanceId . '::', ACCESS_OVERVIEW)) {
             continue;
         }
         $title = $titleField != '' ? $entity[$titleField] : $this->__('Item');
         $description = $descriptionField != '' ? $entity[$descriptionField] : '';
         $created = isset($entity['createdDate']) ? $entity['createdDate'] : '';
         $searchItem = array('title' => $title, 'text' => $description, 'extra' => serialize($urlArgs), 'created' => $created, 'module' => $this->name, 'session' => $sessionId);
         if (!DBUtil::insertObject($searchItem, 'search_result')) {
             return LogUtil::registerError($this->__('Error! Could not save the search results.'));
         }
     }
     //  }
     return true;
 }
예제 #9
0
    /**
     * Perform a search.
     *
     * Parameters passed in the $args array:
     * -------------------------------------
     * ? $args['q'] ?.
     * ? $args[?]   ?.
     *
     * @param array $args All parameters passed to this function.
     *
     * @return bool True on success or null result, false on error.
     */
    public function search($args)
    {
        // Security check
        if (!SecurityUtil::checkPermission('Users::', '::', ACCESS_READ)) {
            return false;
        }

        if (!isset($args['q']) || empty($args['q'])) {
            return true;
        }

        // decide if we have to load the DUDs from the Profile module
        $profileModule = System::getVar('profilemodule', '');
        $useProfileMod = (!empty($profileModule) && ModUtil::available($profileModule));

        // get the db and table info
        $dbtable = DBUtil::getTables();
        $userscolumn = $dbtable['users_column'];

        $q = DataUtil::formatForStore($args['q']);
        $q = str_replace('%', '\\%', $q);  // Don't allow user input % as wildcard

        // build the where clause
        $where   = array();
        $where[] = "({$userscolumn['activated']} != " . Users_Constant::ACTIVATED_PENDING_REG . ')';

        $unameClause = Search_Api_User::construct_where($args, array($userscolumn['uname']));

        // invoke the current profilemodule search query
        if ($useProfileMod) {
            $uids = ModUtil::apiFunc($profileModule, 'user', 'searchDynadata',
                                 array('dynadata' => array('all' => $q)));

            $tmp = $unameClause;
            if (is_array($uids) && !empty($uids)) {
                $tmp .= " OR {$userscolumn['uid']} IN (" . implode(', ', $uids) . ')';
            }
            $where[] = "({$tmp}) ";
        } else {
            $where[] = $unameClause;
        }

        $where = implode(' AND ', $where);

        $users = DBUtil::selectObjectArray ('users', $where, '', -1, -1, 'uid');

        if (!$users) {
            return true;
        }

        $sessionId = session_id();

        foreach ($users as $user) {
            if ($user['uid'] != 1 && SecurityUtil::checkPermission('Users::', "$user[uname]::$user[uid]", ACCESS_READ)) {
                if ($useProfileMod) {
                     $qtext = $this->__("Click the user's name to view his/her complete profile.");
                } else {
                    $qtext = '';
                }
                $items = array('title' => $user['uname'],
                               'text' => $qtext,
                               'extra' => $user['uid'],
                               'module' => 'Users',
                               'created' => null,
                               'session' => $sessionId);
                $insertResult = DBUtil::insertObject($items, 'search_result');
                if (!$insertResult) {
                    $this->registerError($this->__("Error! Could not load the results of the user's search."));

                    return false;
                }
            }
        }

        return true;
    }