1<?php 2/** 3 * Trean Base Class. 4 * 5 * Copyright 2002-2017 Horde LLC (http://www.horde.org/) 6 * 7 * See the enclosed file LICENSE for license information (BSD). If you did not 8 * did not receive this file, see http://www.horde.org/licenses/bsdl.php. 9 * 10 * @author Mike Cochrane <mike@graftonhall.co.nz> 11 * @package Trean 12 */ 13class Trean 14{ 15 /** 16 * Returns the specified permission for the current user. 17 * 18 * @param string $permission A permission, currently only 'max_folders' 19 * and 'max_bookmarks'. 20 * 21 * @return mixed The value of the specified permission. 22 */ 23 static function hasPermission($permission) 24 { 25 $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); 26 if (!$perms->exists('trean:' . $permission)) { 27 return true; 28 } 29 30 $allowed = $perms->getPermissions( 31 'trean:' . $permission, $GLOBALS['registry']->getAuth()); 32 if (is_array($allowed)) { 33 switch ($permission) { 34 case 'max_folders': 35 case 'max_bookmarks': 36 $allowed = max($allowed); 37 break; 38 } 39 } 40 41 return $allowed; 42 } 43 44 /** 45 * Returns an apropriate icon for the given bookmark. 46 * 47 * @param Trean_Bookmark $bookmark The bookmark object. 48 * 49 * @return Horde_Url The URL for the image. 50 */ 51 static function getFavicon($bookmark) 52 { 53 if ($bookmark->favicon_url) { 54 return Horde::url('favicon.php')->add('bookmark_id', $bookmark->id); 55 } else { 56 // Default to the protocol icon. 57 $protocol = substr($bookmark->url, 0, strpos($bookmark->url, '://')); 58 return Horde_Themes::img('protocol/' . (empty($protocol) ? 'http' : $protocol) . '.png'); 59 } 60 } 61 62 static public function addFeedLink() 63 { 64 $rss = Horde::url('rss.php', true, -1); 65 if ($label = Horde_Util::getFormData('label')) { 66 $rss->add('label', $label); 67 } 68 69 $GLOBALS['page_output']->addLinkTag(array( 70 'href' => $rss, 71 'title' => _("Bookmarks Feed") 72 )); 73 } 74 75 static public function bookmarkletLink() 76 { 77 $view = $GLOBALS['injector']->createInstance('Horde_View'); 78 $view->url = Horde::url('add.php', true, array('append_session' => -1)) 79 ->add('popup', 1); 80 $view->image = Horde::img('add.png'); 81 return $view->render('bookmarklet'); 82 } 83 84} 85