From becfa414b5b024ded4e094b1c113a72f39d8b763 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 25 Feb 2014 15:45:00 +0100 Subject: refactor detail.php to template.php - refactor detail en mediamanager link creation - refactor metadata listing --- inc/template.php | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 6 deletions(-) (limited to 'inc/template.php') diff --git a/inc/template.php b/inc/template.php index 0a6a9e4aa..aa3c658a8 100644 --- a/inc/template.php +++ b/inc/template.php @@ -548,6 +548,7 @@ function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = fals * @var string $method * @var bool $nofollow * @var array $params + * @var string $replacement */ extract($data); if(strpos($id, '#') === 0) { @@ -556,6 +557,9 @@ function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = fals $linktarget = wl($id, $params); } $caption = $lang['btn_'.$type]; + if(strpos($caption, '%s')){ + $caption = sprintf($caption, $replacement); + } $akey = $addTitle = ''; if($accesskey) { $akey = 'accesskey="'.$accesskey.'" '; @@ -609,11 +613,12 @@ function tpl_get_action($type) { if ($type == 'subscription') $type = 'subscribe'; if(!actionOK($type)) return false; - $accesskey = null; - $id = $ID; - $method = 'get'; - $params = array('do' => $type); - $nofollow = true; + $accesskey = null; + $id = $ID; + $method = 'get'; + $params = array('do' => $type); + $nofollow = true; + $replacement = ''; switch($type) { case 'edit': // most complicated type - we need to decide on current action @@ -670,6 +675,11 @@ function tpl_get_action($type) { $params = array(); $accesskey = 'b'; break; + case 'img_backto': + $params = array(); + $accesskey = 'b'; + $replacement = $ID; + break; case 'login': $params['sectok'] = getSecurityToken(); if(isset($_SERVER['REMOTE_USER'])) { @@ -717,11 +727,26 @@ function tpl_get_action($type) { case 'media': $params['ns'] = getNS($ID); break; + case 'mediaManager': + // View image in media manager + global $IMG; + $imgNS = getNS($IMG); + $authNS = auth_quickaclcheck("$imgNS:*"); + if ($authNS < AUTH_UPLOAD) { + return false; + } + $params = array( + 'ns' => $imgNS, + 'image' => $IMG, + 'do' => 'media' + ); + //$type = 'media'; + break; default: return '[unknown %s type]'; break; } - return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow'); + return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement'); } /** @@ -1016,6 +1041,67 @@ function tpl_img_getTag($tags, $alt = '', $src = null) { return $info; } +/** + * Returns a description list of the metatags of the current image + * + * @return string html of description list + */ +function tpl_img_meta() { + global $lang; + + $tags = tpl_get_img_meta(); + + echo '
'; + foreach($tags as $tag) { + $label = $lang[$tag['langkey']]; + if(!$label) $label = $tag['langkey']; + + echo '
'.$label.':
'; + if ($tag['type'] == 'date') { + echo dformat($tag['value']); + } else { + echo hsc($tag['value']); + } + echo '
'; + } + echo '
'; +} + +/** + * Returns metadata as configured in mediameta config file, ready for creating html + * + * @return array with arrays containing the entries: + * - string langkey key to lookup in the $lang var, if not found printed as is + * - string type type of value + * - string value tag value (unescaped) + */ +function tpl_get_img_meta() { + + $config_files = getConfigFiles('mediameta'); + foreach ($config_files as $config_file) { + if(@file_exists($config_file)) { + include($config_file); + } + } + /** @var array $fields the included array with metadata */ + + $tags = array(); + foreach($fields as $tag){ + $t = array(); + if (!empty($tag[0])) { + $t = array($tag[0]); + } + if(is_array($tag[3])) { + $t = array_merge($t,$tag[3]); + } + $value = tpl_img_getTag($t); + if ($value) { + $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value); + } + } + return $tags; +} + /** * Prints the image with a link to the full sized version * -- cgit v1.2.3