function wikiplugin_listexecute($data, $params)
{
    $unifiedsearchlib = TikiLib::lib('unifiedsearch');
    $actions = array();
    $factory = new Search_Action_Factory();
    $factory->register(array('change_status' => 'Search_Action_ChangeStatusAction', 'delete' => 'Search_Action_Delete', 'email' => 'Search_Action_EmailAction', 'wiki_approval' => 'Search_Action_WikiApprovalAction', 'tracker_item_modify' => 'Search_Action_TrackerItemModify'));
    $query = new Search_Query();
    $unifiedsearchlib->initQuery($query);
    $matches = WikiParser_PluginMatcher::match($data);
    $builder = new Search_Query_WikiBuilder($query);
    $builder->apply($matches);
    foreach ($matches as $match) {
        $name = $match->getName();
        if ($name == 'action') {
            $action = $factory->fromMatch($match);
            if ($action && $action->isAllowed(Perms::get()->getGroups())) {
                $actions[$action->getName()] = $action;
            }
        }
    }
    if (!empty($_REQUEST['sort_mode'])) {
        $query->setOrder($_REQUEST['sort_mode']);
    }
    $index = $unifiedsearchlib->getIndex();
    $result = $query->search($index);
    $plugin = new Search_Formatter_Plugin_SmartyTemplate('templates/wiki-plugins/wikiplugin_listexecute.tpl');
    $paginationArguments = $builder->getPaginationArguments();
    $dataSource = $unifiedsearchlib->getDataSource();
    $builder = new Search_Formatter_Builder();
    $builder->setPaginationArguments($paginationArguments);
    $builder->apply($matches);
    $builder->setFormatterPlugin($plugin);
    $formatter = $builder->getFormatter();
    $reportSource = new Search_Action_ReportingTransform();
    if (isset($_POST['list_action'], $_POST['objects'])) {
        $action = $_POST['list_action'];
        $objects = (array) $_POST['objects'];
        if (isset($actions[$action])) {
            $tx = TikiDb::get()->begin();
            $action = $actions[$action];
            $plugin->setFields(array_fill_keys($action->getFields(), null));
            $list = $formatter->getPopulatedList($result);
            foreach ($list as $entry) {
                $identifier = "{$entry['object_type']}:{$entry['object_id']}";
                if (in_array($identifier, $objects) || in_array('ALL', $objects)) {
                    $success = $action->execute($entry);
                    $reportSource->setStatus($entry['object_type'], $entry['object_id'], $success);
                }
            }
            $tx->commit();
        }
    }
    $plugin = new Search_Formatter_Plugin_SmartyTemplate('templates/wiki-plugins/wikiplugin_listexecute.tpl');
    $plugin->setFields(array('report_status' => null));
    $plugin->setData(array('actions' => array_keys($actions)));
    $formatter = new Search_Formatter($plugin);
    $result->applyTransform($reportSource);
    return $formatter->format($result);
}
示例#2
0
 function testIndexProvidesHighlightHelper()
 {
     $query = new Search_Query('foobar or hello');
     $resultSet = $query->search($this->index);
     $plugin = new Search_Formatter_Plugin_WikiTemplate('{display name=highlight}');
     $formatter = new Search_Formatter($plugin);
     $output = $formatter->format($resultSet);
     $this->assertContains('<em>Hello</em>', $output);
     $this->assertNotContains('<body>', $output);
 }
示例#3
0
文件: Builder.php 项目: rjsmelo/tiki
 function getFormatter()
 {
     $plugin = $this->formatterPlugin;
     if (!$plugin) {
         $plugin = new Search_Formatter_Plugin_WikiTemplate("* {display name=title format=objectlink}\n");
     }
     $formatter = new Search_Formatter($plugin);
     if ($this->alternateOutput > '') {
         $formatter->setAlternateOutput($this->alternateOutput);
     } else {
         $formatter->setAlternateOutput('^' . tra('No results for query.') . '^');
     }
     foreach ($this->subFormatters as $name => $plugin) {
         $formatter->addSubFormatter($name, $plugin);
     }
     return $formatter;
 }
示例#4
0
 function action_render(JitFilter $request)
 {
     $encoded = $request->stream->none();
     $page = $request->page->int() ?: 1;
     if (!($baseQuery = Tiki_Security::get()->decode($encoded))) {
         throw new Services_Exception_Denied('Invalid request performed.');
     }
     $query = new Search_Query();
     $this->lib->initQuery($query);
     $query->filterType('activity');
     $matches = WikiParser_PluginMatcher::match($baseQuery['body']);
     $builder = new Search_Query_WikiBuilder($query);
     $builder->enableAggregate();
     $builder->apply($matches);
     if ($builder->isNextPossible()) {
         $query->setPage($page);
     }
     $query->setOrder('modification_date_desc');
     if (!($index = $this->lib->getIndex())) {
         throw new Services_Exception_NotAvailable(tr('Activity stream currently unavailable.'));
     }
     $result = $query->search($index);
     $paginationArguments = $builder->getPaginationArguments();
     $resultBuilder = new Search_ResultSet_WikiBuilder($result);
     $resultBuilder->setPaginationArguments($paginationArguments);
     $resultBuilder->apply($matches);
     try {
         $plugin = new Search_Formatter_Plugin_SmartyTemplate('templates/activity/activitystream.tpl');
         $plugin->setFields(array('like_list' => true, 'user_groups' => true, 'contributors' => true));
         $formatter = new Search_Formatter($plugin);
         $formatter->setDataSource($this->lib->getDataSource());
         $out = $formatter->format($result);
     } catch (SmartyException $e) {
         throw new Services_Exception_NotAvailable($e->getMessage());
     }
     return array('autoScroll' => $request->autoscroll->int(), 'pageNumber' => $page, 'nextPossible' => $builder->isNextPossible(), 'stream' => $encoded, 'body' => TikiLib::lib('parser')->parse_data($out, array('is_html' => true)));
 }
示例#5
0
 function testIndexProvidesHighlightHelper()
 {
     $query = new Search_Query('foobar or hello');
     $resultSet = $query->search($this->index);
     // Manually adding the content to avoid initializing the entire formatter
     foreach ($resultSet as &$entry) {
         $entry['content'] = 'Hello World';
     }
     $plugin = new Search_Formatter_Plugin_WikiTemplate('{display name=highlight}');
     $formatter = new Search_Formatter($plugin);
     $output = $formatter->format($resultSet);
     $this->assertContains('<b style="color:black;background-color:#ff66ff">Hello</b>', $output);
     $this->assertNotContains('<body>', $output);
 }
示例#6
0
 function testHighlightRequested()
 {
     $plugin = new Search_Formatter_Plugin_WikiTemplate('{display name=highlight}');
     $resultSet = new Search_ResultSet(array(array('object_type' => 'wiki page', 'object_id' => 'HomePage', 'content' => 'Hello World'), array('object_type' => 'wiki page', 'object_id' => 'SomePage', 'content' => 'Test')), 22, 20, 10);
     $resultSet->setHighlightHelper(new Search_FormatterTest_HighlightHelper());
     $formatter = new Search_Formatter($plugin);
     $output = $formatter->format($resultSet);
     $this->assertContains('<strong>Hello</strong>', $output);
 }
function wikiplugin_list($data, $params)
{
	$unifiedsearchlib = TikiLib::lib('unifiedsearch');

	$alternate = null;
	$output = null;
	$subPlugins = array();

	$query = new Search_Query;
	$query->setWeightCalculator($unifiedsearchlib->getWeightCalculator());

	if (isset($_REQUEST['maxRecords'])) {
		if (isset($_REQUEST['offset'])) {
			$query->setRange($_REQUEST['offset'], $_REQUEST['maxRecords']);
		} else {
			$query->setRange(0, $_REQUEST['maxRecords']);
		}
	} elseif (isset($_REQUEST['offset'])) {
		$query->setRange($_REQUEST['offset']);
	}

	$matches = WikiParser_PluginMatcher::match($data);
	$argumentParser = new WikiParser_PluginArgumentParser;

	$onclick = '';
	$offset_jsvar = '';

	foreach ($matches as $match) {
		$name = $match->getName();
		$arguments = $argumentParser->parse($match->getArguments());

		foreach ($arguments as $key => $value) {
			$function = "wpquery_{$name}_{$key}";

			if (function_exists($function)) {
				$function($query, $value, $arguments);
			}

			$function = "wpformat_{$name}_{$key}";

			if (function_exists($function)) {
				$function($subPlugins, $value, $match->getBody());
			}
		}

		if ($name == 'output') {
			$output = $match;
		}

		if ($name == 'alternate') {
			$alternate = $match->getBody();
		}

		if ($name == 'pagination' && isset($arguments['onclick'])) {
			$onclick = $arguments['onclick'];
		}
		if ($name == 'pagination' && isset($arguments['offset_jsvar'])) {
			$offset_jsvar = $arguments['offset_jsvar'];
		}
	}

	if (! Perms::get()->admin) {
		$query->filterPermissions(Perms::get()->getGroups());
	}

	if (!empty($_REQUEST['sort_mode'])) {
		$query->setOrder($_REQUEST['sort_mode']);
	}

	$index = $unifiedsearchlib->getIndex();

	$result = $query->search($index);

	if (count($result)) {
		if (!empty($output)) {
			$arguments = $argumentParser->parse($output->getArguments());

			if (isset($arguments['template'])) {
				if ($arguments['template'] == 'table') {
					$arguments['template'] = dirname(__FILE__) . '/../../templates/table.tpl';
				} else if (!file_exists($arguments['template'])) {
					TikiLib::lib('errorreport')->report(tr('Missing template "%0"', $arguments['template']));
					return '';
				}
				$builder = new Search_Formatter_ArrayBuilder;
				$templateData = $builder->getData($output->getBody());

				$plugin = new Search_Formatter_Plugin_SmartyTemplate($arguments['template']);
				$plugin->setData($templateData);
				$plugin->setFields(wp_list_findfields($templateData));
			} elseif (isset($arguments['wiki']) && TikiLib::lib('tiki')->page_exists($arguments['wiki'])) {	
				$wikitpl = "tplwiki:" . $arguments['wiki'];
				$wikicontent = TikiLib::lib('smarty')->fetch($wikitpl);
				$plugin = new Search_Formatter_Plugin_WikiTemplate($wikicontent);
			} else {
				$plugin = new Search_Formatter_Plugin_WikiTemplate($output->getBody());
			}

			if (isset($arguments['pagination'])) {
				$plugin = new WikiPlugin_List_AppendPagination($plugin, $onclick, $offset_jsvar);
			}
		} else {
			$plugin = new Search_Formatter_Plugin_WikiTemplate("* {display name=title format=objectlink}\n");
		}

		$formatter = new Search_Formatter($plugin);
		$formatter->setDataSource($unifiedsearchlib->getDataSource());

		foreach ($subPlugins as $key => $plugin) {
			$formatter->addSubFormatter($key, $plugin);
		}

		$out = $formatter->format($result);
	} elseif (!empty($alternate)) {
		$out = $alternate;
	} else {
		$out = '^' . tra('No results for query.') . '^';
	}

	return $out;
}
示例#8
0
 private function renderResults($resultset)
 {
     global $prefs;
     $unifiedsearchlib = TikiLib::lib('unifiedsearch');
     $dataSource = $unifiedsearchlib->getDataSource('formatting');
     $plugin = new Search_Formatter_Plugin_SmartyTemplate(realpath('templates/searchresults-plain.tpl'));
     $plugin->setData(array('prefs' => $prefs));
     $fields = array('title' => null, 'url' => null, 'modification_date' => null, 'highlight' => null);
     if ($prefs['feature_search_show_visit_count'] === 'y') {
         $fields['visits'] = null;
     }
     $plugin->setFields($fields);
     $formatter = new Search_Formatter($plugin);
     $wiki = $formatter->format($resultset);
     $tikilib = TikiLib::lib('tiki');
     $results = $tikilib->parse_data($wiki, array('is_html' => true));
     return $results;
 }
示例#9
0
                $isCached = true;
            }
        }
        if (!$isCached) {
            $results = tiki_searchindex_get_results($filter, $postfilter, $offset, $maxRecords);
            $facets = array_map(function ($facet) {
                return $facet->getName();
            }, $results->getFacets());
            $plugin = new Search_Formatter_Plugin_SmartyTemplate(realpath('templates/searchresults-plain.tpl'));
            $plugin->setData(array('prefs' => $prefs));
            $fields = array('title' => null, 'url' => null, 'modification_date' => null, 'highlight' => null);
            if ($prefs['feature_search_show_visit_count'] === 'y') {
                $fields['visits'] = null;
            }
            $plugin->setFields($fields);
            $formatter = new Search_Formatter($plugin);
            $wiki = $formatter->format($results);
            $html = $tikilib->parse_data($wiki, array('is_html' => true));
            if (!empty($prefs['unified_user_cache'])) {
                $cachelib->cacheItem($cacheName, serialize(array($tikilib->now, $html)), $cacheType);
            }
        }
        $smarty->assign('results', $html);
    }
}
$smarty->assign('filter', $filter);
$smarty->assign('postfilter', $postfilter);
$smarty->assign('facets', $facets);
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
if ($prefs['search_use_facets'] == 'y') {
示例#10
0
            }
        }
        if (!$isCached) {
            $results = tiki_searchindex_get_results($filter, $offset, $maxRecords);
            $facets = array_map(function ($facet) {
                return $facet->getName();
            }, $results->getFacets());
            $dataSource = $unifiedsearchlib->getDataSource('formatting');
            $plugin = new Search_Formatter_Plugin_SmartyTemplate(realpath('templates/searchresults-plain.tpl'));
            $plugin->setData(array('prefs' => $prefs));
            $fields = array('title' => null, 'url' => null, 'modification_date' => null, 'highlight' => null);
            if ($prefs['feature_search_show_visit_count'] === 'y') {
                $fields['visits'] = null;
            }
            $plugin->setFields($fields);
            $formatter = new Search_Formatter($plugin);
            $formatter->setDataSource($dataSource);
            $wiki = $formatter->format($results);
            $html = $tikilib->parse_data($wiki, array('is_html' => true));
            if (!empty($prefs['unified_user_cache'])) {
                $cachelib->cacheItem($cacheName, serialize(array($tikilib->now, $html)), $cacheType);
            }
        }
        $smarty->assign('results', $html);
    }
}
$smarty->assign('filter', $filter);
$smarty->assign('facets', $facets);
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
if ($prefs['search_use_facets'] == 'y') {