Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
    function testBasicSmartyFormatter()
    {
        $plugin = new Search_Formatter_Plugin_SmartyTemplate(dirname(__FILE__) . '/basic.tpl');
        $plugin->setData(array('foo' => array('bar' => 'baz')));
        $formatter = new Search_Formatter($plugin);
        $output = $formatter->format(array(array('object_type' => 'wiki page', 'object_id' => 'HomePage'), array('object_type' => 'wiki page', 'object_id' => 'SomePage')));
        $expect = <<<OUT
<div>~np~<table>
\t<caption>baz: 2</caption>
\t<tr><th>Object</th><th>Type</th></tr>
\t<tr><td>HomePage</td><td>wiki page</td></tr>
\t<tr><td>SomePage</td><td>wiki page</td></tr>
</table>
~/np~</div>
OUT;
        $this->assertXmlStringEqualsXmlString($expect, "<div>{$output}</div>");
    }
Exemplo n.º 3
0
 private function handleOutput($output)
 {
     $smarty = TikiLib::lib('smarty');
     $arguments = $this->parser->parse($output->getArguments());
     if (isset($arguments['template'])) {
         if ($arguments['template'] == 'table') {
             $arguments['template'] = dirname(__FILE__) . '/../../../../templates/search/list/table.tpl';
             $arguments['pagination'] = true;
         } elseif ($arguments['template'] == 'medialist') {
             $arguments['template'] = dirname(__FILE__) . '/../../../../templates/search/list/medialist.tpl';
         } elseif ($arguments['template'] == 'carousel') {
             $arguments['template'] = dirname(__FILE__) . '/../../../../templates/search/list/carousel.tpl';
         } elseif ($arguments['template'] == 'count') {
             $arguments['template'] = dirname(__FILE__) . '/../../../../templates/search/list/count.tpl';
         } elseif (!file_exists($arguments['template'])) {
             $temp = $smarty->get_filename($arguments['template']);
             if (empty($temp)) {
                 //if get_filename cannot find template, return error
                 TikiLib::lib('errorreport')->report(tr('Missing template "%0"', $arguments['template']));
                 return '';
             }
             $arguments['template'] = $temp;
         }
         $abuilder = new Search_Formatter_ArrayBuilder();
         $outputData = $abuilder->getData($output->getBody());
         foreach ($this->paginationArguments as $k => $v) {
             $outputData[$k] = $this->paginationArguments[$k];
         }
         $templateData = file_get_contents($arguments['template']);
         $plugin = new Search_Formatter_Plugin_SmartyTemplate($arguments['template']);
         $plugin->setData($outputData);
         $plugin->setFields($this->findFields($outputData, $templateData));
     } elseif (isset($arguments['wiki']) && TikiLib::lib('tiki')->page_exists($arguments['wiki'])) {
         $wikitpl = "tplwiki:" . $arguments['wiki'];
         $wikicontent = $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 Search_Formatter_AppendPagination($plugin, $this->paginationArguments);
     }
     $this->formatterPlugin = $plugin;
 }
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 private function handleOutput($output)
 {
     $arguments = $this->parser->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 '';
             }
         }
         $abuilder = new Search_Formatter_ArrayBuilder();
         $templateData = $abuilder->getData($output->getBody());
         $plugin = new Search_Formatter_Plugin_SmartyTemplate($arguments['template']);
         $plugin->setData($templateData);
         $plugin->setFields($this->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, $this->paginationArguments);
     }
     $this->formatterPlugin = $plugin;
 }
Exemplo n.º 7
0
        $cacheType = 'search';
        $cacheName = $user . '/' . $offset . '/' . $maxRecords . '/' . serialize($filter);
        $isCached = false;
        if (!empty($prefs['unified_user_cache']) && $cachelib->isCached($cacheName, $cacheType)) {
            list($date, $html) = $cachelib->getSerialized($cacheName, $cacheType);
            if ($date > $tikilib->now - $prefs['unified_user_cache'] * 60) {
                $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);
    }
}