1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8function smarty_function_favorite($params, $smarty) 9{ 10 global $prefs, $user; 11 12 // Disabled, do nothing 13 if (empty($user) || $prefs['user_favorites'] != 'y') { 14 return; 15 } 16 17 $servicelib = TikiLib::lib('service'); 18 $smarty = TikiLib::lib('smarty'); 19 $smarty->loadPlugin('smarty_modifier_escape'); 20 21 $url = $servicelib->getUrl([ 22 'controller' => 'favorite', 23 'action' => 'toggle', 24 'type' => $params['type'], 25 'object' => $params['object'], 26 ]); 27 28 $url = smarty_modifier_escape($url); 29 $e_user = smarty_modifier_escape($user); 30 31 if (isset($params['label'])) { 32 $label = $params['label']; 33 } else { 34 $label = tr('Favorite'); 35 } 36 37 if (isset($params['button_classes'])) { 38 $button_classes = $params['button_classes']; 39 } else { 40 $button_classes = "btn btn-primary"; 41 } 42 43 return '<a class="' . $button_classes . ' favorite-toggle" href="' . $url . '" data-key="favorite_' . $e_user . '"> ' . $label . '</a>'; 44} 45