From: <lph...@us...> - 2010-02-24 18:19:06
|
Revision: 25677 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=25677&view=rev Author: lphuberdeau Date: 2010-02-24 18:18:59 +0000 (Wed, 24 Feb 2010) Log Message: ----------- [MOD] Add support for relation_source and relation_target to display custom labels set as attributes Modified Paths: -------------- trunk/lib/attributes/relationlib.php trunk/lib/smarty_tiki/function.object_link.php Modified: trunk/lib/attributes/relationlib.php =================================================================== --- trunk/lib/attributes/relationlib.php 2010-02-24 17:53:29 UTC (rev 25676) +++ trunk/lib/attributes/relationlib.php 2010-02-24 18:18:59 UTC (rev 25677) @@ -45,6 +45,11 @@ } } + function get_relation( $id ) { + $result = $this->fetchAll( 'SELECT * FROM `tiki_object_relations` WHERE `relationId` = ?', array( $id ) ); + return reset( $result ); + } + private function apply_relation_condition( $relation, & $cond, & $vars ) { $relation = TikiFilter::get( 'attribute_type' ) ->filter( $relation ); Modified: trunk/lib/smarty_tiki/function.object_link.php =================================================================== --- trunk/lib/smarty_tiki/function.object_link.php 2010-02-24 17:53:29 UTC (rev 25676) +++ trunk/lib/smarty_tiki/function.object_link.php 2010-02-24 18:18:59 UTC (rev 25677) @@ -8,6 +8,7 @@ $type = $params['type']; $object = $params['id']; + $title = isset( $params['title'] ) ? $params['title'] : null; switch( $type ) { case 'wiki page': @@ -21,49 +22,104 @@ case 'external': $function = 'smarty_function_object_link_external'; break; + case 'relation_source': + $function = 'smarty_function_object_link_relation_source'; + break; + case 'relation_target': + $function = 'smarty_function_object_link_relation_target'; + break; default: return tr('No rules to display object %1 of type %0.', $type, $object ); } - return $function( $object ); + return $function( $object, $title ); } -function smarty_function_object_link_wiki( $page ) { +function smarty_function_object_link_wiki( $page, $title = null ) { require_once 'lib/smarty_tiki/modifier.sefurl.php'; require_once 'lib/smarty_tiki/modifier.escape.php'; - $escapedPage = smarty_modifier_escape( $page ); + $escapedPage = smarty_modifier_escape( $title ? $title : $page ); $escapedHref = smarty_modifier_escape( smarty_modifier_sefurl( $page, 'wiki' ) ); return '<a href="' . $escapedHref . '">' . $escapedPage . '</a>'; } -function smarty_function_object_link_user( $user ) { +function smarty_function_object_link_user( $user, $title = null ) { require_once 'lib/smarty_tiki/modifier.userlink.php'; - return smarty_modifier_userlink( $user ); + return smarty_modifier_userlink( $user, 'link', 'not_set', $title ? $title : '' ); } -function smarty_function_object_link_external( $link ) { +function smarty_function_object_link_external( $link, $title = null ) { global $cachelib; require_once 'lib/cache/cachelib.php'; global $tikilib; - if( ! $data = $cachelib->getCached( $link, 'object_link_ext' ) ) { - $body = $tikilib->httprequest( $link ); - if( preg_match( '|<title>(.+)</title>|', $body, $parts ) ) { - $title = TikiFilter::get('text')->filter($parts[1]); - } else { - $title = $link; + if( ! $title ) { + if( ! $title = $cachelib->getCached( $link, 'object_link_ext_title' ) ) { + $body = $tikilib->httprequest( $link ); + if( preg_match( '|<title>(.+)</title>|', $body, $parts ) ) { + $title = TikiFilter::get('text')->filter($parts[1]); + } else { + $title = $link; + } + + $cachelib->cacheItem( $link, $title, 'object_link_ext_title' ); } + } - require_once 'lib/smarty_tiki/modifier.escape.php'; - $escapedHref = smarty_modifier_escape( $link ); - $escapedTitle = smarty_modifier_escape( $title ); - $data = '<a href="' . $escapedHref . '">' . $escapedTitle . '</a>'; + require_once 'lib/smarty_tiki/modifier.escape.php'; + $escapedHref = smarty_modifier_escape( $link ); + $escapedTitle = smarty_modifier_escape( $title ); + $data = '<a href="' . $escapedHref . '">' . $escapedTitle . '</a>'; - $cachelib->cacheItem( $link, $data, 'object_link_ext' ); + return $data; +} + +function smarty_function_object_link_relation_source( $relationId, $title = null ) { + return smarty_function_object_link_relation_end( 'source', $relationId, $title ); +} + +function smarty_function_object_link_relation_target( $relationId, $title = null ) { + return smarty_function_object_link_relation_end( 'target', $relationId, $title ); +} + +function smarty_function_object_link_relation_end( $end, $relationId, $title = null ) { + global $relationlib; require_once 'lib/attributes/relationlib.php'; + global $attributelib; require_once 'lib/attributes/attributelib.php'; + global $cachelib; require_once 'lib/cache/cachelib.php'; + + $cacheKey = "$relationId:$end:$title"; + + if( ! $out = $cachelib->getCached( $cacheKey, 'relation_link' ) ) { + $relation = $relationlib->get_relation( $relationId ); + + if( $relation ) { + if( ! $title ) { + $attributes = $attributelib->get_attributes( 'relation', $relationId ); + $key = 'tiki.relation.' . $end; + + if( isset( $attributes[$key] ) && ! empty( $attributes[$key] ) ) { + $title = $attributes[$key]; + } + } + + $type = $relation[ $end . '_type' ]; + $object = $relation[ $end . '_itemId' ]; + + global $smarty; + $out = smarty_function_object_link( array( + 'type' => $type, + 'id' => $object, + 'title' => $title, + ), $smarty ); + + $cachelib->cacheItem( $cacheKey, $out, 'relation_link' ); + } else { + $out = tra('Relation not found.'); + } } - return $data; + return $out; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |