From: <tr...@us...> - 2012-12-18 00:41:04
|
Revision: 10434 http://sourceforge.net/p/xoops/svn/10434 Author: trabis Date: 2012-12-18 00:41:00 +0000 (Tue, 18 Dec 2012) Log Message: ----------- Fixing some search functions Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/codex/class/plugin/search.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/news/include/search.inc.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/userinfo.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/xoops_version.php Added Paths: ----------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/search.php Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/codex/class/plugin/search.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/codex/class/plugin/search.php 2012-12-17 22:06:02 UTC (rev 10433) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/codex/class/plugin/search.php 2012-12-18 00:41:00 UTC (rev 10434) @@ -22,7 +22,8 @@ { public function search($queries, $andor, $limit, $start, $uid) { - $queries = implode(' ', $queries); + $queries = implode(' ', (array) $queries); + $files = XoopsLists::getFileListAsArray(dirname(dirname(dirname(__FILE__)))); $res = array(); $i = 0; Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/news/include/search.inc.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/news/include/search.inc.php 2012-12-17 22:06:02 UTC (rev 10433) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/news/include/search.inc.php 2012-12-18 00:41:00 UTC (rev 10434) @@ -30,6 +30,7 @@ function news_search($queryarray, $andor, $limit, $offset, $userid){ global $xoopsDB, $xoopsUser; + $xoops = Xoops::getInstance(); include_once XOOPS_ROOT_PATH.'/modules/news/include/functions.php'; $restricted=news_getmoduleoption('restrictindex'); $highlight = false; Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/userinfo.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/userinfo.php 2012-12-17 22:06:02 UTC (rev 10433) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/profile/userinfo.php 2012-12-18 00:41:00 UTC (rev 10434) @@ -188,10 +188,10 @@ $xoops->tpl()->assign('categories', $categories); // Dynamic user profiles end -if ($xoops->getModuleConfig('profile_search')) { - $criteria = new CriteriaCompo(new Criteria('hassearch', 1)); - $criteria->add(new Criteria('isactive', 1)); - $modules = $xoops->getHandlerModule()->getObjectsArray($criteria, true); +if ($xoops->isActiveModule('search') && $xoops->getModuleConfig('profile_search') && $xoops->getModuleConfig('enable_search', 'search')) { + $available_plugins = Xoops_Plugin::getAvailablePlugins('search'); + $criteria = new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)) . "')", 'IN'); + $modules = $module_handler->getObjectsArray($criteria, true); $mids = array_keys($modules); $myts = MyTextSanitizer::getInstance(); @@ -201,7 +201,9 @@ if (in_array($mid, $allowed_mids)) { /* @var XoopsModule $module */ $module = $modules[$mid]; - $results = $module->search('', '', 5, 0, $thisUser->getVar('uid')); + $plugin = Xoops_Plugin::getPlugin($module->getVar('dirname'), 'search'); + /* @var $plugin SearchPluginInterface */ + $results = $plugin->search('', '', 5, 0, $thisUser->getVar('uid')); $count = count($results); if (is_array($results) && $count > 0) { for ($i = 0; $i < $count; $i++) { Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/index.html =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/index.html (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/index.html 2012-12-18 00:41:00 UTC (rev 10434) @@ -0,0 +1 @@ +<script>history.go(-1);</script> \ No newline at end of file Added: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/search.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/search.php (rev 0) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/search.php 2012-12-18 00:41:00 UTC (rev 10434) @@ -0,0 +1,97 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * Publisher class + * + * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ + * @license http://www.fsf.org/copyleft/gpl.html GNU public license + * @package Class + * @subpackage Utils + * @since 1.0 + * @author trabis <lus...@gm...> + * @version $Id$ + */ + +defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined"); + +class PublisherSearchPlugin extends Xoops_Plugin_Abstract implements SearchPluginInterface +{ + public function search($queryarray, $andor, $limit, $offset, $userid) + { + $categories = array(); + $sortby = 0; + $searchin = ""; + $extra = ""; + return self::searchAdvanced($queryarray, $andor, $limit, $offset, $userid, $categories, $sortby, $searchin, $extra); + } + + 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 = "&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, '&') : $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'); + //"Fulltext search/highlight + $text = $obj->body(); + $sanitized_text = ""; + $text_i = strtolower($text); + $queryarray = is_array($queryarray) ? $queryarray : array($queryarray); + + //@todo look into xoopslocal + if ($hightlight_key != '') { + foreach ($queryarray as $query) { + $pos = strpos($text_i, strtolower($query)); //xoops_local("strpos", $text_i, strtolower($query)); + $start = max(($pos - 100), 0); + $length = strlen($query) + 200; //xoops_local("strlen", $query) + 200; + $context = $obj->highlight(XoopsLocal::substr($text, $start, $length, " [...]"), $query); + $sanitized_text .= "<p>[...] " . $context . "</p>"; + } + } + + //End of highlight + $item['text'] = $sanitized_text; + $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; + } +} Property changes on: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/class/plugin/search.php ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Date Id Rev URL Added: svn:eol-style + native Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/xoops_version.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/xoops_version.php 2012-12-17 22:06:02 UTC (rev 10433) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/publisher/xoops_version.php 2012-12-18 00:41:00 UTC (rev 10434) @@ -202,77 +202,6 @@ $modversion['blocks'][$i]['options'] = "0|datesub|5|65"; $modversion['blocks'][$i]['template'] = "publisher_category_items_sel.html"; -// Templates -$i = 0; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_header.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_HEADER_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_footer.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_FOOTER_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_singleitem.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_SINGLEITEM_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_categories_table.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_CATEGORIES_TABLE_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_display_list.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_DISPLAY_LIST_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_display_summary.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_DISPLAY_SUMMARY_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_display_full.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_DISPLAY_FULL_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_display_wfsection.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_DISPLAY_WFSECTION_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_item.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_ITEM_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_submit.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_SUBMIT_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_singleitem_block.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_SINGLEITEM_BLOCK_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_print.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_PRINT_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_rss.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_RSS_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_addfile.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_ADDFILE_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_search.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_SEARCH_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_author_items.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_AUTHOR_ITEMS_DSC; - -$i++; -$modversion['templates'][$i]['file'] = 'publisher_archive.html'; -$modversion['templates'][$i]['description'] = _MI_PUBLISHER_ARCHIVE__DSC; - // Config categories $i = 0; $modversion['configcat']['seo']['name'] = _MI_PUBLISHER_CONFCAT_SEO; |