예제 #1
0
 /**
  * search - search
  *
  * @param string[] $queryArray search terms
  * @param string   $andor      and/or how to treat search terms
  * @param integer  $limit      max number to return
  * @param integer  $offset     offset of first row to return
  * @param integer  $userid     a specific user id to limit the query
  *
  * @return array of result items
  *           'title' => the item title
  *           'content' => brief content or summary
  *           'link' => link to visit item
  *           'time' => time modified (unix timestamp)
  *           'uid' => author uid
  *           'image' => icon for search display
  *
  */
 public function search($queryArray, $andor, $limit, $offset, $userid)
 {
     $andor = strtolower($andor) == 'and' ? 'and' : 'or';
     $qb = \Xoops::getInstance()->db()->createXoopsQueryBuilder();
     $eb = $qb->expr();
     $qb->select('DISTINCT *')->fromPrefix('page_content')->where($eb->neq('content_status', '0'))->orderBy('content_create', 'DESC')->setFirstResult($offset)->setMaxResults($limit);
     if (is_array($queryArray) && !empty($queryArray)) {
         $queryParts = array();
         foreach ($queryArray as $i => $q) {
             $qterm = ':qterm' . $i;
             $qb->setParameter($qterm, '%' . $q . '%', \PDO::PARAM_STR);
             $queryParts[] = $eb->orX($eb->like('content_title', $qterm), $eb->like('content_text', $qterm), $eb->like('content_shorttext', $qterm));
         }
         if ($andor == 'and') {
             $qb->andWhere(call_user_func_array(array($eb, "andX"), $queryParts));
         } else {
             $qb->andWhere(call_user_func_array(array($eb, "orX"), $queryParts));
         }
     } else {
         $qb->setParameter(':uid', (int) $userid, \PDO::PARAM_INT);
         $qb->andWhere($eb->eq('content_author', ':uid'));
     }
     $myts = MyTextSanitizer::getInstance();
     $items = array();
     $result = $qb->execute();
     while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
         $content = $myrow["content_shorttext"] . "<br /><br />" . $myrow["content_text"];
         $content = $myts->xoopsCodeDecode($content);
         $items[] = array('title' => $myrow['content_title'], 'content' => Metagen::getSearchSummary($content, $queryArray), 'link' => "viewpage.php?id=" . $myrow["content_id"], 'time' => $myrow['content_create'], 'uid' => $myrow['content_author'], 'image' => 'images/logo_small.png');
     }
     return $items;
 }
예제 #2
0
 public function searchAdvanced($queryarray, $andor, $limit, $offset, $userid, $categories = array(), $sortby = 0, $searchin = "", $extra = "")
 {
     $publisher = Publisher::getInstance();
     $ret = array();
     if ($queryarray == '' || count($queryarray) == 0) {
         $hightlight_key = '';
     } else {
         $keywords = implode('+', $queryarray);
         $hightlight_key = "&amp;keywords=" . $keywords;
     }
     $itemsObjs = $publisher->getItemHandler()->getItemsFromSearch($queryarray, $andor, $limit, $offset, $userid, $categories, $sortby, $searchin, $extra);
     $withCategoryPath = $publisher->getConfig('search_cat_path');
     $usersIds = array();
     /* @var $obj PublisherItem */
     foreach ($itemsObjs as $obj) {
         $item['image'] = "images/item_icon.gif";
         $item['link'] = $obj->getItemUrl();
         $item['link'] .= !empty($hightlight_key) && strpos($item['link'], '.php?') === false ? "?" . ltrim($hightlight_key, '&amp;') : $hightlight_key;
         if ($withCategoryPath) {
             $item['title'] = $obj->getCategoryPath(false) . " > " . $obj->title();
         } else {
             $item['title'] = $obj->title();
         }
         $item['time'] = $obj->getVar('datesub');
         //must go has unix timestamp
         $item['uid'] = $obj->getVar('uid');
         $item['content'] = Metagen::getSearchSummary($obj->body(), $queryarray);
         $item['author'] = $obj->getVar('author_alias');
         $item['datesub'] = $obj->datesub($publisher->getConfig('format_date'));
         $usersIds[$obj->getVar('uid')] = $obj->getVar('uid');
         $ret[] = $item;
         unset($item, $sanitized_text);
     }
     $usersNames = XoopsUserUtility::getUnameFromIds($usersIds, $publisher->getConfig('format_realname'), true);
     foreach ($ret as $key => $item) {
         if ($item["author"] == '') {
             $ret[$key]["author"] = @$usersNames[$item["uid"]];
         }
     }
     unset($usersNames, $usersIds);
     return $ret;
 }
예제 #3
0
파일: xmf.php 프로젝트: ming-hai/XoopsCore
You should have received a copy of the GNU General Public License,
and the GNU Lesser General Public License along with this program.
If not, see http://www.gnu.org/licenses/.

You may contact the copyright holder through XOOPS Project:
http://xoops.org
EOT;
echo '<h4>Extracted Description</h4>';
// get the intro of the article to use as the description
$description = Metagen::generateDescription($article, 50);
echo '<p>' . $description . '</p>';
echo '<h4>SEO Slug</h4>';
// turn title into a slug
echo '<p>' . Metagen::generateSeoTitle($title) . '</p>';
// highlight keywords in article
echo '<h4>Article with Top 25 Keywords Highlighted</h4>';
// get important words from title
$title_keywords = Metagen::generateKeywords($title, 25, 3);
//Debug::dump($title_keywords);
// get top 25 keywords, but always keep keywords from title
$keywords = Metagen::generateKeywords($article, 25, 4, $title_keywords);
Debug::dump($keywords, true);
echo Highlighter::apply($keywords, $article);
// add to the page
Metagen::assignTitle($title);
Metagen::assignKeywords($keywords);
Metagen::assignDescription($description);
// dump our source
echo '<br /><h2>Source code</h2>';
\Xoops\Utils::dumpFile(__FILE__);
$xoops->footer();