/** * Filter a content item's content * * @return string */ function filter($item, $field = "content", $length = 0) { $nodefilters = array(); if (is_a($item, 'Zoo_Content_Interface')) { $txt = $item->{$field}; $nodefilters = Zoo::getService('content')->getFilters($item); } else { $txt = $item; } if ($length > 0) { $txt = substr($txt, 0, $length); } if (count($nodefilters)) { $ids = array(); foreach ($nodefilters as $nodefilter) { $ids[] = $nodefilter->filter_id; } $filters = Zoo::getService('filter')->getFilters($ids); foreach ($filters as $filter) { $txt = $filter->filter($txt); } if (extension_loaded('tidy')) { $config = array('indent' => TRUE, 'show-body-only' => TRUE, 'output-xhtml' => TRUE, 'wrap' => 0); $tidy = tidy_parse_string($txt, $config, 'UTF8'); $tidy->cleanRepair(); $txt = tidy_get_output($tidy); } } else { $txt = htmlspecialchars($txt); } return $txt; }
/** * Returns content menu container object * @return Zend_Navigation_Container */ function getContentMenu() { if (!$this->container) { $cacheid = "navigate_content_menu"; try { $this->container = Zoo::getService("cache")->load($cacheid); } catch (Zoo_Exception_Service $e) { // Cache unavailable } if (!$this->container) { // menu not loaded from cache $items = Zoo::getService('content')->getContent(array('group' => 'category', 'active' => true, 'order' => 'published', 'render' => false), 0, 0); $tree = new Zoo_Object_Tree($items, 'id', 'pid'); $this->container = $this->getRootPage(); $this->treeToPageContainer($tree, $this->container); $tags = array('menu'); try { Zoo::getService('cache')->save($this->container, $cacheid, $tags); } catch (Zoo_Exception_Service $e) { // Cache service not available, do nothing } } } return $this->container; }
/** * Render a File browser * * @param string $id * @param string $value * @param array $params * @param array $attribs * @return string */ public function fileBrowser($id, $value = '', array $params = array(), array $attribs = array()) { $attribs = $this->_prepareAttributes($id, $value, $attribs); if (strlen($value) >= 6) { $params['color'] = $value; } if (count($params) > 0) { $params = ZendX_JQuery::encodeJson($params); } else { $params = "{}"; } $js = sprintf('%s("#%s").click(function(){window.open("%s", "%s", "location=0,status=1,scrollbars=1,width=800,height=500");});', ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), $attribs['id'] . "_image", "/filemanager/file/browse?elementid=" . $attribs['id'], $attribs['id'] . "_window", $params); $this->jquery->addOnLoad($js); $js2 = sprintf("function callFunction(id, url, element_id) {\n \telement_id = '#' + element_id\n \tvar image_id = element_id + '_image';\n \t%s(image_id).attr('src', url);\n \t%s(element_id).attr('value', id);\n\t }", ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(), ZendX_JQuery_View_Helper_JQuery::getJQueryHandler()); $this->view->headScript()->appendScript($js2); // XHTML or HTML end tag? $endTag = ' />'; if ($this->view instanceof Zend_View_Abstract && !$this->view->doctype()->isXhtml()) { $endTag = '>'; } if ($value && ($file = Zoo::getService('filemanager')->find($value)->current())) { $xhtml = '<img id="' . $attribs['id'] . '_image" src="' . $file->getUrl(150, 150) . '" ' . $endTag; } else { $xhtml = '<img id="' . $attribs['id'] . '_image" src="/images/crystal_project/128x128/mimetypes/ascii.png" ' . $endTag; } $xhtml .= $this->view->formHidden($id, $value, $attribs); return $xhtml; }
/** * Fetch blocks that are visible on this page * * @return array */ public function getBlocks() { $ret = array(); $groups = array(0); try { $roles = Zoo::getService('user')->getCurrentUser()->getGroups(); $groups = array_keys($roles); } catch (Zoo_Exception_Service $e) { // Do nothing } $cacheid = str_replace(array("/", "?", "=", "&", "-", '.'), "_", "Flex_blocks_page" . Zend_Controller_Front::getInstance()->getRequest()->getRequestUri() . "_" . implode("_", $groups)); try { $ret = Zoo::getService("cache")->load($cacheid); } catch (Zoo_Exception_Service $e) { // @todo: Remove this comment: I'm beginning to tire of writing try-catch for services } if (!$ret) { $ret = $this->fetchFromDb(); try { Zoo::getService('cache')->save($ret, $cacheid, array(), null); } catch (Zoo_Exception_Service $e) { // No caching available } } // Return array ordered by block position return $ret; }
/** * Returns content menu container object * @return Zend_Navigation_Container */ function getContentMenu($root = 0) { if (!isset($this->container[$root])) { $cacheid = "navigate_content_menu"; try { $this->container = Zoo::getService("cache")->load($cacheid); } catch (Zoo_Exception_Service $e) { // Cache unavailable } if (!isset($this->container[$root])) { // menu not loaded from cache $items = $this->factory->fetchWithChildren($root); // Build menu tree $tree = new Zoo_Object_Tree($items, 'id', 'pid'); $this->container[$root] = $this->getRootPage(); $this->treeToPageContainer($tree, $this->container[$root], $root); // Cache the tree $tags = array('menu'); try { Zoo::getService('cache')->save($this->container, $cacheid, $tags); } catch (Zoo_Exception_Service $e) { // Cache service not available, do nothing } } } return $this->container[$root]; }
/** * Send debug information to view * */ public function dispatchLoopShutdown() { $profiler = Zoo::getService("db")->getDb()->getProfiler(); if ($profiler->getEnabled() && !$profiler instanceof Zend_Db_Profiler_Firebug && ($queryCount = $profiler->getTotalNumQueries()) > 0) { $longestTime = 0; $longestQuery = null; $totalTime = $profiler->getTotalElapsedSecs(); $queries = array(); foreach ($profiler->getQueryProfiles(null, true) as $query) { /* @var $query Zend_Db_Profiler_Query */ if ($query->getQueryType() != Zend_Db_Profiler::CONNECT && $query->getElapsedSecs() > $longestTime) { $longestTime = round($query->getElapsedSecs(), 4); $longestQuery = $query->getQuery(); } $queries[] = $query->getQuery() . " (" . round($query->getElapsedSecs(), 6) . ")"; } $debug = '<div class="query-execution-time">Executed ' . $queryCount . ' queries in ' . round($totalTime, 4) . ' seconds' . "</div>\n"; $debug .= '<div class="query-avg-time">Average query length: ' . round($totalTime / $queryCount, 6) . ' seconds' . "</div>\n"; $debug .= '<div class="queries-per-second">Queries per second: ' . round($queryCount / $totalTime, 2) . "</div>\n"; $debug .= '<div class="query-long-length">Longest query length: ' . round($longestTime, 6) . "</div>\n"; $debug .= '<div class="query-long">Longest query: ' . $longestQuery . "</div>\n"; $debug .= implode("<br />\n", $queries); $view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view; /* @var $view Zend_View_Abstract */ $view->assign('debug', $debug . "\n<div class='debugger'>" . get_class($profiler) . "</div>"); } }
/** * Retrieve service object instance * * @param Zend_Config $config * @return Zend_Translate */ public function &getService($config) { if (!$this->service) { Zend_Translate::setCache(Zoo::getService('cache')->getCache('translate')); /* * @todo Re-enable this with configuration options instead of hardcoding $writer = new Zend_Log_Writer_Firebug(); $logger = new Zend_Log($writer); $this->service = new Zend_Translate('gettext', ZfApplication::$_base_path."/app/Zoo/Language", null, array( 'scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true, 'log' => $logger, 'logUntranslated' => true) ); */ if ($config->language->default) { $locale = new Zend_Locale($config->language->default); Zend_Registry::set("Zend_Locale", $locale); } else { $locale = new Zend_Locale("en"); } $this->service = new Zend_Translate('gettext', ZfApplication::$_base_path . "/app/Zoo/Language", $locale, array('scan' => Zend_Translate::LOCALE_FILENAME, 'disableNotices' => true)); } return $this->service; }
/** * The default action - show the guestbook entries */ public function indexAction() { $method = __METHOD__; $cacheid = str_replace("::", "_", $method) . intval($this->getRequest()->getParam('page', 1)); $can_edit = false; if (Zoo::getService('acl')->checkAccess('edit')) { $cacheid .= "_edit"; $can_edit = true; } $content = $this->checkCache($cacheid); if (!$content) { $limit = 20; // Offset = items per page multiplied by the page number minus 1 $offset = ($this->getRequest()->getParam('page', 1) - 1) * $limit; $options = array('active' => true, 'nodetype' => 'guestbook_entry', 'order' => 'created DESC', 'render' => true); $select = Zoo::getService('content')->getContentSelect($options, $offset, $limit); $this->view->items = Zoo::getService('content')->getContent($options, $offset, $limit); // Pagination Zend_Paginator::setDefaultScrollingStyle('Elastic'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('pagination_control.phtml', 'zoo')); $adapter = new Zend_Paginator_Adapter_DbSelect($select); $paginator = new Zend_Paginator($adapter); $paginator->setItemCountPerPage($limit); $paginator->setCurrentPageNumber($this->getRequest()->getParam('page', 1)); $paginator->setView($this->view); $this->view->assign('paginator', $paginator); $this->view->can_edit = $can_edit; $content = $this->getContent(); $this->cache($content, $cacheid, array('nodelist', 'guestbook_list')); } $this->view->pagetitle = Zoo::_('Guestbook'); $this->renderContent($content); }
/** * Hook for node form, add extra fields * * @param Zend_Form $form * @param array $arguments */ public function nodeForm(Zend_Form &$form, &$arguments) { $item =& array_shift($arguments); $content_type = Zoo::getService('content')->getType($item->type); if ($content_type->has_parent_url == 0) { $path = new Zend_Form_Element_Text('rewrite_path', array('size' => 65)); $path->setLabel('URL'); $form->addElement($path); $options = array('legend' => Zoo::_("URL Rewriting")); $form->addDisplayGroup(array('rewrite_path'), 'rewrite_path_options', $options); if ($item->id > 0) { $factory = new Rewrite_Path_Factory(); $path = $factory->find($item->id)->current(); if ($path) { $form->populate(array('rewrite_path' => $path->path)); } else { // Find parent's path if ($item->pid && ($path = $factory->find($item->pid)->current())) { $form->populate(array('rewrite_path' => $path->path . "/" . $item->id)); } else { $form->populate(array('rewrite_path' => $item->url())); } } } } }
/** * Get hook action objects for a given event * * @param string $type * @param string $action * @return array * @throws Zend_Db_Exception if trouble with database or tables */ protected function getHooks($type, $action) { $cacheId = "flex_hooks_{$type}_{$action}"; $ret = array(); try { $ret = Zoo::getService("cache")->load($cacheId); if ($ret == array('none')) { return array(); } } catch (Zoo_Exception_Service $e) { // No cache service } if (!$ret) { $factory = new Utility_Hook_Factory(); $hooks = $factory->fetchAll(array('type = ?' => $type, 'action = ?' => $action), 'weight ASC'); if ($hooks->count() > 0) { foreach ($hooks as $hook) { $class = $hook->class . "_Hook_" . $type; $ret[] = new $class(); } } if (!$ret) { $ret = array('none'); } try { Zoo::getService("cache")->save($ret, $cacheId, array('hooks')); } catch (Zoo_Exception_Service $e) { // No cache service } } if ($ret == array('none')) { return array(); } return $ret; }
/** * Returns content escaped using the View's escape function with more parameters * * @return string */ public function filter($item, $field = "content", $length = 0) { try { return Zoo::getService("filter")->filter($item, $field, $length); } catch (Zoo_Exception_Service $e) { return $this->view->escape($item); } }
/** * Retrieve node listing * * @return array */ function getTemplateVars() { $menu = null; if (Zend_Registry::isRegistered('context')) { $menu = Zoo::getService('menu')->getBreadcrumbsFromNode(Zend_Registry::get('context')->node); } return array('menu' => $menu); }
function init() { if (is_numeric($this->destination)) { $this->_node = Zoo::getService('content')->load($this->destination, 'List'); $this->_resource = 'content.node'; $this->_privilege = 'index.' . $this->_node->type; } }
/** * Retrieve galleries listing * * @return array */ function getTemplateVars() { $menu = null; if (Zend_Registry::isRegistered('content_id')) { $node = Zoo::getService('content')->load(Zend_Registry::get('content_id'), 'Short'); $menu = Zoo::getService('menu')->getBreadcrumbsFromNode($node); } return array('menu' => $menu); }
/** * Retrieve node menu items * * @return array * * @uses Hook_Node::nodeMenu() */ function getTemplateVars() { if (Zend_Registry::getInstance()->isRegistered('content_id')) { $item = Zoo::getService('content')->load(Zend_Registry::get('content_id'), 'Menu'); $menu = new Zend_Navigation($item->hooks['menu']); return array('menu' => $menu); } return false; }
/** * Hook for node save - if type is Comments Node, save extra fields * * @param Zend_Form $form * @param array $arguments */ public function nodeSave(&$form, &$arguments) { $item = array_shift($arguments); $arguments = $form->getValues(); if ($item->type == "comments_node") { $item->pid = $arguments['pid']; $item->save(); Zoo::getService('cache')->remove("Comments_Block_List_" . $item->pid); } }
/** * Retrieve node menu items * * @return array * * @uses Hook_Node::nodeMenu() */ function getTemplateVars() { $context = Zend_Registry::get('context'); if (isset($context->node) && $context->node->id > 0) { $item = Zoo::getService('content')->load($context->node->id, 'Menu'); $menu = new Zend_Navigation($item->hooks['menu']); return array('menu' => $menu); } return false; }
/** * Clears all cache * */ function cleanAction() { if ($this->getRequest()->getParam('tag')) { Zoo::getService('cache')->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array($this->getRequest()->getParam('tag'))); } else { Zoo::getService('cache')->clean(); Zoo::getService('cache')->getCache('metadata')->clean(); Zoo::getService('cache')->getCache('acl')->clean(); } }
/** * Locate path alias node * @see library/Zend/Controller/Plugin/Zend_Controller_Plugin_Abstract#routeStartup($request) * * @param Zend_Controller_Request_Abstract $request * @return void */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { if ($request->getRequestUri() != "/" && ($path = Zoo::getService('path')->findPath($request->getRequestUri()))) { $content_service = Zoo::getService('content'); $request->setActionName($content_service->action); $request->setControllerName($content_service->controller); $request->setModuleName($content_service->module); $request->setParam('id', $path->nid); } }
/** * Return available region styles * @todo Make generic and load from other modules * @return array */ protected function getRegionStyles() { $ret = array('standard' => 'Standard', 'box' => 'Box'); try { Zoo::getService('hook')->trigger('panel', 'regionStyles', $ret); } catch (Zoo_Exception_Service $e) { // No hooks service available, do nothing } return $ret; }
/** * Check the cache for a cache ID - returns cached content if any * * @param string $cacheid * @return string */ function checkCache($cacheid) { try { $content = Zoo::getService("cache")->load($cacheid); } catch (Zoo_Exception_Service $e) { // Cache unavailable, set content to empty string $content = ""; } return $content; }
/** * Set default adapter and cache for Zend_Db_Table classes * * @param Zend_Controller_Request_Abstract $request */ public function routeStartup($request = null) { Zend_Db_Table_Abstract::setDefaultAdapter(Zoo::getService('db')->getDb()); $frontendOptions = new Zend_Config(array('lifetime' => 86400)); try { $metacache = Zoo::getService('cache')->getCache('metadata', 'Core', $frontendOptions); Zend_Db_Table_Abstract::setDefaultMetadataCache($metacache); } catch (Zoo_Exception_Service $e) { // No cache service available } }
/** * Get array of group names/role ids * * @return Array Acl_Role objects */ public function getGroups($update = false) { if (!$this->groups) { if (!$update && isset($_SESSION['user_groups'])) { $this->groups = $_SESSION['user_groups']; } else { $this->groups = Zoo::getService('acl')->getGroups($this->id); $_SESSION['user_groups'] = $this->groups; } } return $this->groups; }
/** * Set default adapter and cache for Zend_Db_Table classes * * @param Zend_Controller_Request_Abstract $request */ public function dispatchLoopStartup($request = null) { // Add translator $translate = Zoo::getService("translator"); Zend_Registry::set("Zend_Translate", $translate); // Language try { $translate->addTranslation(ZfApplication::$_base_path . "/app/" . $request->getModuleName() . "/Language", null, array('scan' => Zend_Translate::LOCALE_FILENAME)); } catch (Zend_Translate_Exception $e) { // Translation doesn't exist. } }
/** * Fetch IDs of blocks that are visible on this page * * @param Zend_Controller_Request_Abstract $request * @return array */ public function getVisibleBlocks(Zend_Controller_Request_Abstract $request) { $groups = array(0); try { $roles = Zoo::getService('user')->getCurrentUser()->getGroups(); $groups = array_keys($roles); } catch (Zoo_Exception_Service $e) { // Do nothing } $select = $this->select()->where('module IN (?)', array('', $request->getModuleName()))->where('controller IN (?)', array('', $request->getControllerName()))->where('action IN (?)', array('', $request->getActionName()))->where('id IN (?)', array(0, $request->getParam('id', 0)))->where('group_id IN (?)', $groups); return $this->fetchAll($select); }
/** * Returns the URL for the content node * * @return string Url for the link href attribute. */ public function url() { if ($this->id > 0) { try { $path_service = Zoo::getService('path'); return $path_service->getNodeUrl($this->id); } catch (Zend_Exception $e) { $router = Zend_Controller_Front::getInstance()->getRouter(); return $router->assemble(array('id' => $this->id), $this->type); } } return ""; }
/** * @return bool|Zend_Form_Subform */ function getOptions() { $menus = Zoo::getService('menu')->fetchAll(); // Build menu tree $tree = new Zoo_Object_Tree($menus, 'id', 'pid'); $options = $tree->getIndentedArray('title', 0, '-'); $form = new Zend_Form_SubForm(); $menu_select = new Zend_Form_Element_Select('menu'); $menu_select->setLabel('Menu'); $menu_select->addMultiOptions($options); $form->addElement($menu_select); return $form; }
/** * Display gallery front page * */ public function indexAction() { $method = __METHOD__; $cacheid = str_replace("::", "_", $method); $content = $this->checkCache($cacheid); if (!$content) { $items = Zoo::getService('content')->getContent(array('active' => true, 'nodetype' => 'gallery_node', 'render' => false)); $this->view->assign('items', $items); $content = $this->getContent(); $this->cache($content, $cacheid, array('nodelist', 'node_gallery_node'), 60); //60 Seconds set - should be dynamic? Should it invalidate, whenever a node is saved? } $this->renderContent($content); }
/** * Updates existing rows. * * @param array $data Column-value pairs. * @param array|string $where An SQL WHERE clause, or an array of SQL WHERE clauses. * @return int The number of rows updated. */ public function update(array $data, $where) { // add a timestamp $data['updated'] = time(); $data['updatedby'] = 0; try { $uid = Zoo::getService('user')->getCurrentUser()->id; if ($uid > 0) { $data['updatedby'] = $uid; } } catch (Exception $e) { } return parent::update($data, $where); }
/** * Display list of content nodes * */ public function indexAction() { $method = __METHOD__; $cacheid = str_replace("::", "_", $method); $content = $this->checkCache($cacheid); if (!$content) { $items = Zoo::getService('content')->getContent(array('active' => true, 'group' => 'content', 'render' => true)); $this->view->assign('items', $items); $content = $this->getContent(); $this->cache($content, $cacheid, array('nodelist'), 60); //60 Seconds set - should it be dynamic? } $this->renderContent($content); }