' . _("No bookmarks to display") . '
'; } return $html; } } trean-1.0.3/lib/Block/Mostclicked.php 0000664 0001750 0001750 00000004070 12171337642 015511 0 ustar jan jan */ class Trean_Block_Mostclicked extends Horde_Core_Block { /** */ public function __construct($app, $params = array()) { parent::__construct($app, $params); $this->_name = _("Most-clicked Bookmarks"); } /** */ protected function _params() { return array( 'rows' => array( 'name' => _("Number of bookmarks to show"), 'type' => 'enum', 'default' => '10', 'values' => array( '10' => _("10 rows"), '15' => _("15 rows"), '25' => _("25 rows") ) ), 'template' => array( 'name' => _("Template"), 'type' => 'enum', 'default' => '1line', 'values' => array( 'standard' => _("3 Line"), '2line' => _("2 Line"), '1line' => _("1 Line") ) ) ); } /** */ protected function _title() { return Horde::url($GLOBALS['registry']->getInitialPage(), true)->link() . $this->getName() . ''; } /** */ protected function _content() { $template = TREAN_TEMPLATES . '/block/' . $this->_params['template'] . '.inc'; $html = ''; $bookmarks = $GLOBALS['trean_gateway']->listBookmarks('clicks', 1, 0, $this->_params['rows']); foreach ($bookmarks as $bookmark) { ob_start(); require $template; $html .= '' . _("No bookmarks to display") . '
'; } return $html; } } trean-1.0.3/lib/Queue/Task/Crawl.php 0000664 0001750 0001750 00000007131 12171337642 015255 0 ustar jan jan _url = $url; $this->_userTitle = $userTitle; $this->_userDesc = $userDesc; $this->_bookmarkId = $bookmarkId; $this->_userId = $userId; } /** */ public function run() { $injector = $GLOBALS['injector']; // Get Horde_Http_Client $client = $injector->getInstance('Horde_Http_Client'); // Fetch full text of $url try { $page = $client->get($this->_url); $body = $page->getBody(); } catch (Horde_Http_Exception $e) { Horde::log($e, 'ERR'); return; } $gateway = $injector->getInstance('Trean_Bookmarks'); $bookmark = $gateway->getBookmark($this->_bookmarkId); $changed = false; // update URL if we were redirected if ($page->uri && ($page->uri != $this->_url)) { $bookmark->url = $page->uri; $this->_url = $page->uri; $changed = true; } // update bookmark_http_status if ($bookmark->http_status != $page->code) { $bookmark->http_status = $page->code; $changed = true; } // submit text to ElasticSearch, under $userId's index if ($body && $page->code == 200) { try { $indexer = $injector->getInstance('Content_Indexer'); $indexer->index('horde-user-' . $this->_userId, 'trean-bookmark', $this->_bookmarkId, json_encode(array( 'title' => $this->_userTitle, 'description' => $this->_userDesc, 'url' => $this->_url, 'headers' => $page->headers, 'body' => $body, ))); } catch (Exception $e) { Horde::log($e, 'INFO'); } } if ($changed) { $bookmark->save(false); } // @TODO: crawl resources from the page to make a fully local version // (http://bugs.horde.org/ticket/10753) // Favicon if ($body) { if ($type = $page->getHeader('Content-Type') && preg_match('/.*;\s*charset="?([^" ]*)/', $type, $match)) { $charset = $match[1]; } else { $charset = null; } try { $queue = $injector->getInstance('Horde_Queue_Storage'); $queue->add(new Trean_Queue_Task_Favicon( $this->_url, $this->_bookmarkId, $this->_userId, $body, $charset )); } catch (Exception $e) { Horde::log($e, 'INFO'); } } } } trean-1.0.3/lib/Queue/Task/Favicon.php 0000664 0001750 0001750 00000012561 12171337642 015575 0 ustar jan jan _url = $url; $this->_bookmarkId = $bookmarkId; $this->_userId = $userId; $this->_body = $body; $this->_charset = $charset; } /** */ public function run() { $injector = $GLOBALS['injector']; $client = $injector->getInstance('Horde_Http_Client'); if (!$this->_body) { // Fetch full text of $url try { $page = $client->get($this->_url); $this->_body = $page->getBody(); if ($type = $page->getHeader('Content-Type') && preg_match('/.*;\s*charset="?([^" ]*)/', $type, $match)) { $this->_charset = $match[1]; } } catch (Horde_Http_Exception $e) { } } $url = parse_url($this->_url); if ($favicon = $this->_findByRel($client, $url, $this->_body, $this->_charset)) { $this->_storeFavicon($favicon); } elseif ($favicon = $this->_findByRoot($client, $url)) { $this->_storeFavicon($favicon); } elseif ($favicon = $this->_findByPath($client, $url)) { $this->_storeFavicon($favicon); } } /** * @param Horde_Http_Response_Base $response HTTP response; body of this is the favicon */ protected function _storeFavicon(Horde_Http_Response_Base $response) { global $injector; $gateway = $injector->getInstance('Trean_Bookmarks'); $bookmark = $gateway->getBookmark($this->_bookmarkId); if ($bookmark) { $bookmark->favicon_url = $response->uri; $bookmark->save(false); } // Initialize VFS $vfs = $GLOBALS['injector'] ->getInstance('Horde_Core_Factory_Vfs') ->create(); $vfs->writeData('.horde/trean/favicons/', md5($bookmark->favicon_url), $response->getBody(), true); } protected function _findByRel($client, $url, $body, $charset) { try { $dom = new Horde_Domhtml($body, $charset); foreach ($dom as $node) { if ($node instanceof DOMElement && Horde_String::lower($node->tagName) == 'link' && ($rel = Horde_String::lower($node->getAttribute('rel'))) && ($rel == 'shortcut icon' || $rel == 'icon')) { $favicon = $node->getAttribute('href'); // Make sure $favicon is a full URL. $favicon_url = parse_url($favicon); if (empty($favicon_url['scheme'])) { if (substr($favicon, 0, 1) == '/') { $favicon = $url['scheme'] . '://' . $url['host'] . $favicon; } else { $path = pathinfo($url['path']); $favicon = $url['scheme'] . '://' . $url['host'] . $path['dirname'] . '/' . $favicon; } } try { $response = $client->get($favicon); if ($this->_isValidFavicon($response)) { return $response; } } catch (Horde_Http_Exception $e) { } } } } catch (Exception $e) { } } protected function _findByRoot($client, $url) { try { $response = $client->get($url['scheme'] . '://' . $url['host'] . '/favicon.ico'); if ($this->_isValidFavicon($response)) { return $response; } } catch (Horde_Http_Exception $e) { } } protected function _findByPath($client, $url) { if (isset($url['path'])) { $path = pathinfo($url['path']); if (strlen($path['dirname'])) { try { $response = $client->get($url['scheme'] . '://' . $url['host'] . $path['dirname'] . '/favicon.ico'); if ($this->_isValidFavicon($response)) { return $response; } } catch (Horde_Http_Exception $e) { } } } } protected function _isValidFavicon($response) { return ($response->code == 200) && (substr($response->getHeader('content-type'), 0, 5) == 'image') && (strlen($response->getBody()) > 0); } } trean-1.0.3/lib/View/BookmarkList.php 0000664 0001750 0001750 00000014747 12171337642 015545 0 ustar jan jan * @package Trean */ class Trean_View_BookmarkList { /** * Tag Browser * * @var Trean_TagBrowser */ protected $_browser; /** * The loaded bookmarks. * * @var array */ protected $_bookmarks; /** * Current page * * @var int */ protected $_page = 0; /** * Bookmarks to display per page * * @var int */ protected $_perPage = 999; /** * Flag to indicate we have an empty search. * * @var boolean */ protected $_noSearch = false; /** * Flag to indicate whether or not to show the tag browser * @var boolean */ protected $_showTagBrowser = true; /** * Const'r * */ public function __construct($bookmarks = null, $browser = null) { $this->_bookmarks = $bookmarks; if ($browser) { $this->_browser = $browser; } else { $this->_browser = new Trean_TagBrowser( $GLOBALS['injector']->getInstance('Trean_Tagger')); } $action = Horde_Util::getFormData('actionID', ''); switch ($action) { case 'remove': $tag = Horde_Util::getFormData('tag'); if (isset($tag)) { $this->_browser->removeTag($tag); $this->_browser->save(); } break; case 'add': default: // Add new tag to the stack, save to session. $tag = Horde_Util::getFormData('tag'); if (isset($tag)) { $this->_browser->addTag($tag); $this->_browser->save(); } } // Check for empty tag search.. then do what? $this->_noSearch = $this->_browser->tagCount() < 1; } /** * Toggle showing of the tag browser */ public function showTagBrowser($showTagBrowser) { $this->_showTagBrowser = $showTagBrowser; } /** * Returns whether bookmarks currently exist. * * @return boolean True if there exist any bookmarks in the backend. */ public function hasBookmarks() { $this->_getBookmarks(); return (bool)count($this->_bookmarks) || (bool)$this->_browser->tagCount(); } /** * Renders the view. */ public function render($title = null) { if (is_null($title)) { $title = _("Bookmarks"); } $this->_getBookmarks(); $browser = ''; if ($this->_showTagBrowser) { $browser = '* 'title' - The title for this resource. * 'desc' - A terse description of this resource. * 'view_url' - The URL to view this resource. * 'app' - The Horde application this resource belongs to. **/ public function searchTags($names, $max = 10, $from = 0, $resource_type = '', $user = null, $raw = false) { // TODO: $max, $from, $resource_type not honored $results = $GLOBALS['injector'] ->getInstance('Trean_Tagger') ->search( $names, array('type' => 'bookmark', 'user' => $user)); // Check for error or if we requested the raw data array. if ($raw) { return $results; } $return = array(); $redirectUrl = Horde::url('redirect.php'); foreach ($results as $bookmark_id) { try { $bookmark = $GLOBALS['trean_gateway']->getBookmark($bookmark_id); $return[] = array( 'title' => $bookmark->title, 'desc' => $bookmark->description, 'view_url' => $redirectUrl->add('b', $bookmark->id), 'app' => 'trean', ); } catch (Exception $e) { } } return $return; } /** * Returns a URL that can be used in other applications to add the currently * displayed page as a bookmark. If javascript and DOM is available, an overlay * is used, if javascript and no DOM, then a pop-up is used and if no javascript * is available a URL to Trean's add.php page is returned. * * @param array $params A hash of 'url' and 'title' properties of the requested * bookmark. * @return string The URL suitable for use in a tag. */ public function getAddUrl($params = array()) { $GLOBALS['no_compress'] = true; $browser = $GLOBALS['injector']->getInstance('Horde_Browser'); if ($browser->hasFeature('javascript')) { if ($browser->hasFeature('dom')) { $addurl = Horde::url('add.php', true, -1)->add('iframe', 1); $url = "javascript:(function(){o=document.createElement('div');o.id='overlay';o.style.background='#000';o.style.position='absolute';o.style.top=0;o.style.left=0;o.style.width='100%';o.style.height='100%';o.style.zIndex=5000;o.style.opacity=.8;document.body.appendChild(o);i=document.createElement('iframe');i.id='frame';i.style.zIndex=5001;i.style.border='thin solid #000';i.src='$addurl'+'&title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(location.href);i.style.position='absolute';i.style.width='350px';i.style.height='150px';i.style.left='100px';i.style.top='100px';document.body.appendChild(i);l=document.createElement('a');l.style.position='absolute';l.style.background='#ccc';l.style.color='#000';l.style.border='thin solid #000';l.style.display='block';l.style.top='250px';l.style.left='100px';l.style.zIndex=5001;l.style.padding='5px';l.appendChild(document.createTextNode('" . _("Close") . "'));l.onclick=function(){var o=document.getElementById('overlay');o.parentNode.removeChild(o);var i=document.getElementById('frame');i.parentNode.removeChild(i);this.parentNode.removeChild(this);};document.body.appendChild(l);})()"; } else { $addurl = Horde::url('add.php', true, -1)->add('popup', 1); $url = "javascript:d = new Date(); w = window.open('$addurl' + '&title=' + encodeURIComponent(document.title) + '&url=' + encodeURIComponent(location.href) + '&d=' + d.getTime(), d.getTime(), 'height=200,width=400'); w.focus();"; } } else { // Fallback to a regular URL $url = Horde::url('add.php', true)->add($params); } return $url; } } trean-1.0.3/lib/Application.php 0000664 0001750 0001750 00000007011 12171337643 014460 0 ustar jan jan */ /* Determine the base directories. */ if (!defined('TREAN_BASE')) { define('TREAN_BASE', __DIR__ . '/..'); } if (!defined('HORDE_BASE')) { /* If Horde does not live directly under the app directory, the HORDE_BASE * constant should be defined in config/horde.local.php. */ if (file_exists(TREAN_BASE . '/config/horde.local.php')) { include TREAN_BASE . '/config/horde.local.php'; } else { define('HORDE_BASE', TREAN_BASE . '/..'); } } /* Load the Horde Framework core (needed to autoload * Horde_Registry_Application::). */ require_once HORDE_BASE . '/lib/core.php'; class Trean_Application extends Horde_Registry_Application { /** */ public $version = 'H5 (1.0.3)'; /** * Global variables defined: * - $trean_db: Horde_Db object * - $trean_gateway: Trean_Bookmarks object */ protected function _init() { /* For now, autoloading the Content_* classes depend on there being a * registry entry for the 'content' application that contains at least * the fileroot entry. */ $GLOBALS['injector']->getInstance('Horde_Autoloader') ->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix( '/^Content_/', $GLOBALS['registry']->get('fileroot', 'content') . '/lib/' )); if (!class_exists('Content_Tagger')) { throw new Horde_Exception('The Content_Tagger class could not be found. Make sure the Content application is installed.'); } // Set the timezone variable. $GLOBALS['registry']->setTimeZone(); // Create db and gateway instances. $GLOBALS['trean_db'] = $GLOBALS['injector'] ->getInstance('Horde_Core_Factory_Db') ->create('trean', 'storage'); $GLOBALS['trean_gateway'] = $GLOBALS['injector'] ->getInstance('Trean_Bookmarks'); } /** */ public function perms() { return array( 'max_bookmarks' => array( 'title' => _("Maximum Number of Bookmarks"), 'type' => 'int' ), ); } /** */ public function menu($menu) { $menu->add(Horde::url('browse.php'), _("_Browse"), 'trean-browse', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null); } /** * Add additional items to the sidebar. * * @param Horde_View_Sidebar $sidebar The sidebar object. */ public function sidebar($sidebar) { $sidebar->addNewButton(_("_New Bookmark"), Horde::url('add.php')); $sidebar->containers['tags'] = array( 'header' => array( 'id' => 'trean-toggle-tags', 'label' => _("Tags"), 'collapsed' => false, ), ); $tagger = $GLOBALS['injector']->getInstance('Trean_Tagger'); $tags = $tagger->listBookmarkTags(); natcasesort($tags); foreach ($tags as $tag) { $url = Horde::url("tag/$tag"); $row = array( 'url' => $url, 'cssClass' => 'trean-tag', 'label' => $tag, ); $sidebar->addRow($row, 'tags'); } } } trean-1.0.3/lib/Bookmark.php 0000664 0001750 0001750 00000010660 12171337643 013766 0 ustar jan jan * @package Trean */ class Trean_Bookmark { public $id = null; public $userId = null; public $url = null; public $title = ''; public $description = ''; public $clicks = 0; public $http_status = null; public $favicon_url; public $dt; public $tags = array(); /** */ public function __construct($bookmark = array()) { if ($bookmark) { $this->userId = $bookmark['user_id']; $this->url = $bookmark['bookmark_url']; $this->title = $bookmark['bookmark_title']; $this->description = $bookmark['bookmark_description']; if (!empty($bookmark['bookmark_id'])) { $this->id = (int)$bookmark['bookmark_id']; } if (!empty($bookmark['bookmark_clicks'])) { $this->clicks = (int)$bookmark['bookmark_clicks']; } if (!empty($bookmark['bookmark_http_status'])) { $this->http_status = $bookmark['bookmark_http_status']; } if (!empty($bookmark['favicon_url'])) { $this->favicon_url = $bookmark['favicon_url']; } if (!empty($bookmark['bookmark_dt'])) { $this->dt = $bookmark['bookmark_dt']; } if (!empty($bookmark['bookmark_tags'])) { $this->tags = $bookmark['bookmark_tags']; } } } /** * Save bookmark. */ public function save($crawl = true) { if (!strlen($this->url)) { throw new Trean_Exception('Incomplete bookmark'); } $charset = $GLOBALS['trean_db']->getOption('charset'); $c_url = Horde_String::convertCharset($this->url, 'UTF-8', $charset); $c_title = Horde_String::convertCharset($this->title, 'UTF-8', $charset); $c_description = Horde_String::convertCharset($this->description, 'UTF-8', $charset); $c_favicon_url = Horde_String::convertCharset($this->favicon_url, 'UTF-8', $charset); if ($this->id) { // Update an existing bookmark. $GLOBALS['trean_db']->update(' UPDATE trean_bookmarks SET user_id = ?, bookmark_url = ?, bookmark_title = ?, bookmark_description = ?, bookmark_clicks = ?, bookmark_http_status = ?, favicon_url = ? WHERE bookmark_id = ?', array( $this->userId, $c_url, $c_title, $c_description, $this->clicks, $this->http_status, $c_favicon_url, $this->id, )); $GLOBALS['injector']->getInstance('Trean_Tagger')->replaceTags((string)$this->id, $this->tags, $GLOBALS['registry']->getAuth(), 'bookmark'); } else { // Saving a new bookmark. $bookmark_id = $GLOBALS['trean_db']->insert(' INSERT INTO trean_bookmarks ( user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', array( $this->userId, $c_url, $c_title, $c_description, $this->clicks, $this->http_status, $c_favicon_url, $this->dt, )); $this->id = (int)$bookmark_id; $GLOBALS['injector']->getInstance('Trean_Tagger')->tag((string)$this->id, $this->tags, $GLOBALS['registry']->getAuth(), 'bookmark'); } if ($crawl) { try { $queue = $GLOBALS['injector']->getInstance('Horde_Queue_Storage'); $queue->add(new Trean_Queue_Task_Crawl( $this->url, $this->title, $this->description, $this->id, $this->userId )); } catch (Exception $e) { Horde::log($e, 'INFO'); } } return $this->id; } } trean-1.0.3/lib/Bookmarks.php 0000664 0001750 0001750 00000014250 12171337643 014150 0 ustar jan jan * @package Trean */ class Trean_Bookmarks { /** * @var Content_Users_Manager */ protected $_userManager; /** * @var integer */ protected $_userId; /** * Constructor. */ public function __construct(Content_Users_Manager $userManager) { $this->_userManager = $userManager; try { $this->_userId = current($this->_userManager->ensureUsers($GLOBALS['registry']->getAuth())); } catch (Content_Exception $e) { throw new Trean_Exception($e); } } /** * Create a new bookmark for the current user * * @return Trean_Bookmark */ public function newBookmark(array $properties) { $properties['user_id'] = $this->_userId; $properties['bookmark_dt'] = new Horde_Date(time()); $bookmark = new Trean_Bookmark($properties); $bookmark->save(); return $bookmark; } /** * Search bookmarks. */ public function listBookmarks($sortby = 'title', $sortdir = 0, $from = 0, $count = 0) { $values = array($this->_userId); $sql = 'SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt FROM trean_bookmarks WHERE user_id = ? ORDER BY bookmark_' . $sortby . ($sortdir ? ' DESC' : ''); $sql = $GLOBALS['trean_db']->addLimitOffset($sql, array('limit' => $count, 'offset' => $from)); return $this->_resultSet($GLOBALS['trean_db']->selectAll($sql, $values)); } /** * Search bookmarks. */ public function searchBookmarks($q) { $indexer = $GLOBALS['injector']->getInstance('Content_Indexer'); try { $search = $indexer->search('horde-user-' . $this->_userId, 'trean-bookmark', $q); } catch (Content_Exception $e) { throw new Trean_Exception($e); } if (!$search->hits->total) { return array(); } $bookmarkIds = array(); foreach ($search->hits->hits as $bookmarkHit) { $bookmarkIds[] = (int)$bookmarkHit->_id; } $sql = 'SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt FROM trean_bookmarks WHERE user_id = ? AND bookmark_id IN (' . implode(',', $bookmarkIds) . ')'; $values = array($this->_userId); return $this->_resultSet($GLOBALS['trean_db']->selectAll($sql, $values)); } /** * Returns the number of bookmarks. * * @return integer The number of all bookmarks. */ public function countBookmarks() { $sql = 'SELECT COUNT(*) FROM trean_bookmarks WHERE user_id = ?'; return $GLOBALS['trean_db']->selectValue($sql, array($this->_userId)); } /** * Return counts on grouping bookmarks by a specific property. */ public function groupBookmarks($groupby) { switch ($groupby) { case 'status': $sql = 'SELECT bookmark_http_status AS status, COUNT(*) AS count FROM trean_bookmarks GROUP BY bookmark_http_status'; break; default: return array(); } return $GLOBALS['trean_db']->selectAll($sql); } /** * Returns the bookmark corresponding to the given id. * * @param integer $id The ID of the bookmark to retrieve. * * @return Trean_Bookmark The bookmark object corresponding to the given name. */ public function getBookmark($id) { $bookmark = $GLOBALS['trean_db']->selectOne(' SELECT bookmark_id, user_id, bookmark_url, bookmark_title, bookmark_description, bookmark_clicks, bookmark_http_status, favicon_url, bookmark_dt FROM trean_bookmarks WHERE bookmark_id = ' . (int)$id); if (is_null($bookmark)) { throw new Trean_Exception('not found'); } $bookmark = $this->_resultSet(array($bookmark)); return array_pop($bookmark); } /** * Removes a Trean_Bookmark from the backend. * * @param Trean_Bookmark $bookmark The bookmark to remove. */ public function removeBookmark(Trean_Bookmark $bookmark) { /* Check permissions. */ if ($bookmark->userId != $this->_userId) { throw new Trean_Exception('permission denied'); } /* Untag */ $tagger = $GLOBALS['injector']->getInstance('Trean_Tagger'); $tagger->replaceTags((string)$bookmark->id, array(), $GLOBALS['registry']->getAuth(), 'bookmark'); /* @TODO delete from content index? */ //$indexer->index('horde-user-' . $this->_userId, 'trean-bookmark', $this->_bookmarkId, json_encode(array( /* Delete from SQL. */ $GLOBALS['trean_db']->delete('DELETE FROM trean_bookmarks WHERE bookmark_id = ' . (int)$bookmark->id); return true; } /** * Creates Trean_Bookmark objects for each row in a SQL result. */ protected function _resultSet($bookmarks) { if (is_null($bookmarks)) { return array(); } $objects = array(); $tagger = $GLOBALS['injector']->getInstance('Trean_Tagger'); $charset = $GLOBALS['trean_db']->getOption('charset'); foreach ($bookmarks as $bookmark) { foreach ($bookmark as $key => $value) { if (!empty($value) && !is_numeric($value)) { $cvBookmarks[$key] = Horde_String::convertCharset($value, $charset, 'UTF-8'); } else { $cvBookmarks[$key] = $value; } } $cvBookmarks['bookmark_tags'] = $tagger->getTags((string)$cvBookmarks['bookmark_id'], 'bookmark'); $objects[] = new Trean_Bookmark($cvBookmarks); } return $objects; } } trean-1.0.3/lib/Exception.php 0000664 0001750 0001750 00000000070 12171337643 014151 0 ustar jan jan * @category Horde * @license http://www.horde.org/licenses/bsdl.php BSD * @package Trean */ class Trean_TagBrowser extends Horde_Core_TagBrowser { protected $_app = 'trean'; /** * Get breadcrumb style navigation html for choosen tags * * @return Return information useful for building a tag trail. */ public function getTagTrail() { } /** * Fetch the matching resources that should appear on the current page * * @return Array An array of Trean_Bookmark objects. */ public function getSlice($page = 0, $perpage = null) { global $injector; // Refresh the search $this->runSearch(); $totals = $this->count(); $start = $page * $perpage; $results = array_slice($this->_results, $start, $perpage); $bookmarks = array(); foreach ($results as $id) { try { $bookmarks[] = $injector ->getInstance('Trean_Bookmarks') ->getBookmark($id); } catch (Trean_Exception $e) { Horde::logMessage('Bookmark not found: ' . $id, 'ERR'); } } return $bookmarks; } } trean-1.0.3/lib/Tagger.php 0000664 0001750 0001750 00000003552 12171337643 013434 0 ustar jan jan * * @package Trean */ class Trean_Tagger extends Horde_Core_Tagger { protected $_app = 'trean'; protected $_types = array('bookmark'); /** * Searches for resources that are tagged with all of the requested tags. * * @param array $tags Either a tag_id, tag_name or an array. * @param array $filter Array of filter parameters. * - user (array) - only include objects owned by * these users. * * @return A hash of 'bookmark' that contains an array of bookmark ids */ public function search($tags, $filter = array()) { $args = array(); /* Add the tags to the search */ $args['tagId'] = $GLOBALS['injector'] ->getInstance('Content_Tagger') ->getTagIds($tags); $args['typeId'] = $this->_type_ids['bookmark']; $results = $GLOBALS['injector'] ->getInstance('Content_Tagger') ->getObjects($args); $results = array_values($results); return $results; } /** * Returns tags on bookmarks belonging to the current user. * * @param string $token The token to match the start of the tag with. * * @return A tag_id => tag_name hash * @throws Horde_Exception */ public function listBookmarkTags() { try { return $GLOBALS['injector']->getInstance('Content_Tagger') ->getTags(array( 'typeId' => $this->_type_ids['bookmark'], 'userId' => $GLOBALS['registry']->getAuth()) ); } catch (Content_Exception $e) { throw new Horde_Exception($e); } } } trean-1.0.3/lib/Trean.php 0000664 0001750 0001750 00000004710 12171337643 013271 0 ustar jan jan * @package Trean */ class Trean { /** * Returns the specified permission for the current user. * * @param string $permission A permission, currently only 'max_folders' * and 'max_bookmarks'. * * @return mixed The value of the specified permission. */ static function hasPermission($permission) { $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if (!$perms->exists('trean:' . $permission)) { return true; } $allowed = $perms->getPermissions( 'trean:' . $permission, $GLOBALS['registry']->getAuth()); if (is_array($allowed)) { switch ($permission) { case 'max_folders': case 'max_bookmarks': $allowed = max($allowed); break; } } return $allowed; } /** * Returns an apropriate icon for the given bookmark. * * @param Trean_Bookmark $bookmark The bookmark object. * * @return Horde_Url The URL for the image. */ static function getFavicon($bookmark) { if ($bookmark->favicon_url) { return Horde::url('favicon.php')->add('bookmark_id', $bookmark->id); } else { // Default to the protocol icon. $protocol = substr($bookmark->url, 0, strpos($bookmark->url, '://')); return Horde_Themes::img('protocol/' . (empty($protocol) ? 'http' : $protocol) . '.png'); } } static public function addFeedLink() { $rss = Horde::url('rss.php', true, -1); if ($label = Horde_Util::getFormData('label')) { $rss->add('label', $label); } $GLOBALS['page_output']->addLinkTag(array( 'href' => $rss, 'title' => _("Bookmarks Feed") )); } static public function bookmarkletLink() { $view = $GLOBALS['injector']->createInstance('Horde_View'); $view->url = Horde::url('add.php', true, array('append_session' => -1)) ->add('popup', 1); $view->image = Horde::img('add.png'); return $view->render('bookmarklet'); } } trean-1.0.3/lib/Url.php 0000664 0001750 0001750 00000000626 12171337643 012764 0 ustar jan jan _url = new Horde_Url($url); $this->_url->remove(array( 'utm_source', 'utm_medium', 'utm_term', 'utm_campaign', 'utm_content', )); } public function __toString() { return (string)$this->_url; } } trean-1.0.3/locale/de/LC_MESSAGES/trean.mo 0000664 0001750 0001750 00000211320 12171337643 016020 0 ustar jan jan ~ 7 J $ J ) J J &