/** * 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; }
/** * 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; }
/** * 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; }
public function export() { if (!($this->_application = Zoo::getApplication())) { throw new ExportHelperException('No application selected.'); } // export frontpage $frontpage = new Category(); $frontpage->name = 'Root'; $frontpage->alias = '_root'; $frontpage->description = $this->_application->description; // export categories $categories = $this->_application->getCategories(); $categories[0] = $frontpage; foreach ($categories as $category) { $this->_addCategory($this->_categoryToXML($category, $categories)); } $this->categories = $categories; // export items $types = $this->_application->getTypes(); $item_table = YTable::getInstance('item'); foreach ($types as $type) { $items = $item_table->getByType($type->id, $this->_application->id); foreach ($items as $key => $item) { $this->_addItem($type->name, $this->_itemToXML($item)); $item->unsetElementData(); unset($items[$key]); } } return parent::export(); }
/** * 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); }
/** * 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; }
public static function getApplication() { // check if application object already exists if (isset(self::$_application)) { return self::$_application; } // get joomla and application table $joomla = JFactory::getApplication(); $table = YTable::getInstance('application'); // handle admin if ($joomla->isAdmin()) { // create application from user state, or search for default $id = $joomla->getUserState('com_zooapplication'); $apps = $table->all(array('order' => 'name')); if (isset($apps[$id])) { self::$_application = $apps[$id]; } else { if (!empty($apps)) { self::$_application = array_shift($apps); } } return self::$_application; } // handle site if ($joomla->isSite()) { // get component params $params = $joomla->getParams(); // create application from menu item params / request if ($item_id = YRequest::getInt('item_id')) { if ($item = YTable::getInstance('item')->get($item_id)) { self::$_application = $item->getApplication(); } } else { if ($category_id = YRequest::getInt('category_id')) { if ($category = YTable::getInstance('category')->get($category_id)) { self::$_application = $category->getApplication(); } } else { if ($id = YRequest::getInt('app_id')) { self::$_application = $table->get($id); } else { if ($id = $params->get('application')) { self::$_application = $table->get($id); } else { // try to get application from default menu item $menu = JSite::getMenu(true); $default = $menu->getDefault(); if (isset($default->component) && $default->component == 'com_zoo') { if ($app_id = $menu->getParams($default->id)->get('application')) { self::$_application = $table->get($app_id); } } } } } } return self::$_application; } return null; }
/** * 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; }
/** * Form initialization * * @return void */ public function init() { $url = Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => "flex", 'controller' => 'panel', 'action' => 'form'), 'default'); $this->setAction($url)->setMethod('post'); $this->setLegend(sprintf(Zoo::_('Edit %s'), $this->target->name)); $name = new Zend_Form_Element_Text('name'); $name->setLabel('Name')->setRequired(true); $name->setDescription('Administration-side identifier'); $title = new Zend_Form_Element_Text('title'); $title->setLabel('Title'); $title->setDescription('User-visible title of panel'); $layout = new Zend_Form_Element_Select('layout'); $layout->setLabel('Layout'); $layout->setMultiOptions($this->getLayouts()); $category = new Zend_Form_Element_Text('category'); $category->setLabel('Category'); $category->setDescription('Administration-side grouping'); $category->setRequired(true); $submit = new Zend_Form_Element_Submit('save'); $submit->setLabel('save')->setOrder(100); $this->addElements(array($name, $title, $layout, $category)); $legend = Zoo::_("Basic options"); $this->addDisplayGroup(array('name', 'title', 'layout', 'category'), 'block_form', array('legend' => $legend)); $this->addElement($submit); if ($this->target->id > 0) { $id_ele = new Zend_Form_Element_Hidden('id'); $id_ele->setValue(intval($this->target->id)); $this->addElement($id_ele); } $this->populate($this->target->toArray()); }
/** * 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())); } } } } }
public function __construct($default = array()) { parent::__construct($default); // get application $this->application = Zoo::getApplication(); // registers tasks $this->registerTask('frontpage', 'category'); }
/** * 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); }
/** * 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); } }
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 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; }
/** * 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() { $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(); } }
/** * 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; }
/** * 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); } }
/** * 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); } }
/** * 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; }
public function display() { // set toolbar items JToolBarHelper::title(JText::_('New App'), ZOO_ICON); ZooHelper::toolbarHelp(); // get applications $this->applications = Zoo::getApplicationGroups(); // display view $this->getView()->display(); }
public function __construct($default = array()) { parent::__construct($default); // get application $this->application = Zoo::getApplication(); // register tasks $this->registerTask('add', 'edit'); $this->registerTask('apply', 'save'); $this->registerTask('saveandnew', 'save'); }
/** * 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 } }
public function getProfiles($ids = array()) { $ret = array(0 => Zoo::_('Anonymous')); $users = $this->getFactory()->fetchAll($this->getFactory()->select()->where('uid IN (?)', $ids)); if ($users) { foreach ($users as $user) { $ret[$user->uid] = $user; } } return $ret; }
public function edit() { //init vars $multiselect = $this->_config->get('multiselect', array()); $options = array(); if (!$multiselect) { $options[] = JHTML::_('select.option', '', '-' . JText::_('Select Category') . '-'); } $attribs = $multiselect ? 'size="5" multiple="multiple"' : ''; return JHTML::_('zoo.categorylist', Zoo::getApplication(), $options, 'elements[' . $this->identifier . '][category][]', $attribs, 'value', 'text', $this->_data->get('category', array())); }
public function display() { // set toolbar items JToolBarHelper::title(JText::_('App Manager'), ZOO_ICON); JToolBar::getInstance('toolbar')->appendButton('Popup', 'config', 'Check Requirements', JRoute::_($this->baseurl . '&task=checkrequirements&tmpl=component'), 700, 700); ZooHelper::toolbarHelp(); // get applications $this->applications = Zoo::getApplicationGroups(); // display view $this->getView()->display(); }
function fetchElement($name, $value, &$node, $control_name) { $application = Zoo::getApplication(); // create html $options = array(); $options[] = JHTML::_('select.option', '', '- ' . JText::_('Select Category') . ' -'); $html[] = '<div id="' . $name . '" class="zoo-categories">'; $html[] = JHTML::_('zoo.categorylist', $application, $options, $control_name . '[' . $name . ']', 'size="10"', 'value', 'text', $value); $html[] = '</div>'; return implode("\n", $html); }