Commit 8a75e851 authored by lfagundes's avatar lfagundes

Refactor: moved object display logic related to Plugin Include relation...

Refactor: moved object display logic related to Plugin Include relation tracking from wikilib to objectlib and smarty functions.
Properly display an link comments in Plugin Include warning message.
parent 7b3e3c7b
......@@ -4090,6 +4090,7 @@ lib/smarty_tiki/function.object_score.php -text
lib/smarty_tiki/function.object_selector.php -text
lib/smarty_tiki/function.object_selector_multi.php -text
lib/smarty_tiki/function.object_title.php -text
lib/smarty_tiki/function.object_type.php -text
lib/smarty_tiki/function.page_alias.php -text
lib/smarty_tiki/function.page_in_structure.php -text
lib/smarty_tiki/function.payment.php -text
......
......@@ -529,7 +529,16 @@ class ObjectLib extends TikiLib
*/
function get_title($type, $id, $format = null)
{
$detail = '';
switch ($type) {
case 'trackeritemfield':
$type = 'trackeritem';
$ids = explode(':', $id);
$id = (int)$ids[0];
$fieldId = (int)$ids[1];
$trackerlib = TikiLib::lib('trk');
$info = $trackerlib->get_field_info($fieldId);
$extra = $info['name'];
case 'trackeritem':
if ($format) {
$lib = TikiLib::lib('unifiedsearch');
......@@ -556,6 +565,9 @@ class ObjectLib extends TikiLib
if( empty($title) ) {
$title = "$type:$id";
}
if ($extra) {
$title .= ' (' . $extra . ')';
}
return $title;
case 'category':
return TikiLib::lib('categ')->get_category_name($id);
......@@ -599,6 +611,81 @@ class ObjectLib extends TikiLib
}
}
/**
* Gets a wiki parsed content for an object. This is used in case an object can have wiki parsed
* content that generates relations (ex: Plugin Include).
*
* @param string $type
* @param $id
* @return void|string
*/
function get_wiki_content($type, $objectId)
{
if (substr($type, -7) == 'comment') {
$comment_info = TikiLib::lib('comments')->get_comment((int)$objectId);
return $comment_info['data'];
}
switch($type) {
case 'wiki':
$type = 'wiki page';
case 'wiki page':
$info = $this->get_page_info($objectId);
return $info['data'];
case 'forum post':
$comment_info = TikiLib::lib('comments')->get_comment((int)$objectId);
return $comment_info['data'];
case 'tracker':
$tracker_info = TikiLib::lib('trk')->get_tracker((int)$objectId);
return $tracker_info['description'];
case 'trackerfield':
$field_info = TikiLib::lib('trk')->get_field_info((int)$objectId);
return $field_info['description'];
case 'trackeritemfield':
$objectId = explode(':', $objectId);
$itemId = (int)$objectId[0];
$fieldId = (int)$objectId[1];
$trackerlib = TikiLib::lib('trk');
$item_info = $trackerlib->get_tracker_item($itemId);
return $item_info[$fieldId];
}
}
/**
* @param string $type
* @return string
*/
function get_verbose_type($type)
{
if (substr($type, -7) == 'comment') {
$isComment = true;
$type = substr($type, 0, strlen($type)-8);
} else {
$isComment = false;
}
switch ($type) {
case 'trackeritem':
$type = 'tracker item';
break;
case 'trackeritemfield':
$type = 'tracker item field';
break;
case 'trackerfield':
$type = 'tracker field';
break;
case 'wiki':
$type = 'wiki page';
break;
}
if ($isComment) {
$type .= " comment";
}
return tra(ucwords($type));
}
// Returns a hash indicating which permission is needed for viewing an object of desired type.
static function map_object_type_to_permission()
{
......
......@@ -69,6 +69,9 @@ function smarty_function_object_link( $params, $smarty )
case 'freetag':
$function = 'smarty_function_object_link_freetag';
break;
case 'trackeritemfield':
$type = 'trackeritem';
$object = (int)(explode(':', $object)[0]);
case 'trackeritem':
$function = 'smarty_function_object_link_trackeritem';
break;
......
<?php
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id: function.object_title.php 57964 2016-03-17 20:04:05Z jonnybradley $
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
}
function smarty_function_object_type( $params, $smarty )
{
if ( ! isset( $params['type'] ) && ! isset( $params['identifier'] ) ) {
return tra('No object information provided.');
}
if ( isset( $params['type'] ) ) {
$type = $params['type'];
} else {
list($type, $object) = explode(':', $params['identifier'], 2);
}
$smarty->loadPlugin('smarty_modifier_escape');
return smarty_modifier_escape(TikiLib::lib('object')->get_verbose_type($type));
}
......@@ -31,6 +31,13 @@ function smarty_modifier_sefurl($source, $type='wiki', $with_next = '', $all_lan
$type = 'blogpost';
break;
}
if (substr($type, -7) == 'comment') {
$type = substr($type, 0, strlen($type)-8);
$info = TikiLib::lib('comments')->get_comment((int)$source);
$source = $info['object'];
}
switch ($type) {
case 'wiki':
return TikiLib::tikiUrlOpt($wikilib->sefurl($source, $with_next, $all_langs));
......@@ -109,6 +116,11 @@ function smarty_modifier_sefurl($source, $type='wiki', $with_next = '', $all_lan
}
break;
case 'trackerfield':
$trklib = TikiLib::lib('trk');
$trackerId = TikiLib::lib('trk')->get_field_info((int)$source)['trackerId'];
$href = 'tiki-admin_tracker_fields.php?trackerId=' . $trackerId;
break;
case 'filegallery':
case 'file gallery':
$type = 'file gallery';
......
......@@ -614,69 +614,23 @@ class WikiLib extends TikiLib
$relationlib = TikiLib::lib('relation');
$relations = $relationlib->get_relations_to('wiki page', $page, 'tiki.wiki.include');
$objectlib = TikiLib::lib('object');
$result = array();
foreach ($relations as $relation) {
$type = $relation['type'];
$vtype = $type;
if ($type == 'wiki page') {
$page = $relation['itemId'];
$href = 'tiki-index.php?page=' . urlencode($page);
$info = $this->get_page_info($page);
$title = $info['pageName'];
$data = $info['data'];
} elseif ($type == 'forum post') {
$objectId = (int)$relation['itemId'];
$href = 'tiki-view_forum_thread.php?threadId=' . $objectId;
$comment_info = TikiLib::lib('comments')->get_comment($objectId);
$title = $comment_info['title'];
$data = $comment_info['data'];
} elseif ($type == 'tracker') {
$objectId = (int)$relation['itemId'];
$href = 'tiki-view_tracker.php?trackerId=' . $objectId;
$tracker_info = TikiLib::lib('trk')->get_tracker($objectId);
$title = $comment_info['name'];
$data = $tracker_info['description'];
} elseif ($type == 'trackerfield') {
$vtype = 'tracker field';
$objectId = (int)$relation['itemId'];
$field_info = TikiLib::lib('trk')->get_field_info($objectId);
$href = 'tiki-view_tracer_fields.php?trackerId=' . $field_info['trackerId'];
$title = $field_info['name'];
$data = $field_info['description'];
} elseif ($type == 'trackeritemfield') {
$vtype = 'tracker item field';
$objectId = explode(':', $relation['itemId']);
$itemId = (int)$objectId[0];
$fieldId = (int)$objectId[1];
$href = 'tiki-view_tracker_item.php?itemId=' . $itemId;
$trackerlib = TikiLib::lib('trk');
$item_info = $trackerlib->get_tracker_item($itemId);
$field_info = $trackerlib->get_field_info($fieldId);
$title = sprintf(tra("item %d field %s"), $itemId, $field_info['name']);
$data = $item_info[$fieldId];
} elseif (substr($type, -7) == 'comment') {
// TODO, depends on item type
continue;
} else {
continue;
}
$data = $objectlib->get_wiki_content($relation['type'], $relation['itemId']);
$matches = WikiParser_PluginMatcher::match($data);
$argParser = new WikiParser_PluginArgumentParser();
$objectlib = TikiLib::lib('object');
foreach ( $matches as $match ) {
$info = $objectlib->get_info($type, $relation['itemId']);
$arguments = $argParser->parse($match->getArguments());
if ( $match->getName() == 'include' ) {
$result[] = array(
'type' => $type,
'type' => $relation['type'],
'itemId' => $relation['itemId'],
'href' => $href,
'verboseType' => $vtype,
'title' => $title,
'start' => $arguments['start'],
'end' => $arguments['end']
);
......
<ul>
{foreach from=$included_by item=include}
<li>
{$include.verboseType|capitalize}:
<a href="{$include.href}" target="_blank">{$include.title}</a>
{object_type type=$include.type}:
{object_link type=$include.type objectId=$include.itemId}
{if $include.start || $include.end} - {/if}
{if $include.start}
{tr}from{/tr} "{$include.start}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment