/** * form custom url string * * @author Philipp Niethammer <*****@*****.**> * @return custom url string */ public function encodeurl($args) { //check we have the required input if (!isset($args['modname']) || !isset($args['func']) || !isset($args['args'])) { return LogUtil::registerArgsError(); } $supportedfunctions = array('list', 'view', 'subpages', 'sitemap', 'extlist', 'categoriesList', 'pagelist'); if (!in_array($args['func'], $supportedfunctions)) { return ''; } if (isset($args['args']['preview']) || isset($args['args']['editmode'])) { return false; } if (isset($args['args']['cat']) && !empty($args['args']['cat'])) { $cat = CategoryUtil::getCategoryByID($args['args']['cat']); unset($args['args']['cat']); if (count($args['args']) > 0) { return ''; } return $args['modname'] . '/' . DataUtil::formatForURL($cat['name']); } if (isset($args['args']['pid']) && !empty($args['args']['pid'])) { $url = ModUtil::apiFunc('Content', 'page', 'getURLPath', array('pageId' => $args['args']['pid'])); if (strtolower($args['func']) == 'view') { $url .= $this->getVar('shorturlsuffix'); } return $args['modname'] . '/' . $url; } return ''; }
/** * delete category */ public function deleteAction() { if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_DELETE)) { throw new \Zikula\Framework\Exception\ForbiddenException(); } $cid = (int) $this->request->get('cid', 0); $dr = (int) $this->request->get('dr', 0); $url = System::serverGetVar('HTTP_REFERER'); if (!$dr) { return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url); } if (!$cid) { return LogUtil::registerError($this->__('Error! The category ID is invalid.'), null, $url); } $category = \CategoryUtil::getCategoryByID($cid); if (!$category) { $msg = $this->__f('Error! Cannot retrieve category with ID %s.', $cid); return LogUtil::registerError($msg, null, $url); } if ($category['is_locked']) { //! %1$s is the id, %2$s is the name return LogUtil::registerError($this->__f('Notice: The administrator has locked the category \'%2$s\' (ID \'%$1s\'). You cannot edit or delete it.', array($cid, $category['name'])), null, $url); } CategoryUtil::deleteCategoryByID($cid); return $this->redirect($url); }
/** * View list of categories * * @return Renderer */ public function categoriesList($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Content:page:', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $mainCategoryId = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); // 30 == /__SYSTEM__/Modules/Global $categories = CategoryUtil::getCategoriesByParentID($mainCategoryId); $rootCategory = CategoryUtil::getCategoryByID($mainCategoryId); $this->view->assign('rootCategory', $rootCategory); $this->view->assign('categories', $categories); $this->view->assign('lang', ZLanguage::getLanguageCode()); // Count the numer of pages in a specific category $pagecount = array(); foreach ($categories as $category) { $pagecount[$category['id']] = ModUtil::apiFunc('Content', 'Page', 'getPageCount', array('filter' => array('category' => $category['id']))); } $this->view->assign('pagecount', $pagecount); // Register a page variable breadcrumbs with the Content page hierarchy as array of array(url, title) if ((bool) $this->getVar('registerBreadcrumbs', false) === true) { // first include self, then loop over parents until root is reached $modInfo = $this->getModInfo(); $breadcrumbs[] = array('url' => ModUtil::url('Content', 'user', 'sitemap'), 'title' => $modInfo['displayname'] . ' ' . $this->__('Categories')); PageUtil::registerVar('breadcrumbs', false, $breadcrumbs); } return $this->view->fetch('user/main.tpl'); }
/** * Retrieve and display the value of a category field (by default, the category's path). * * Available attributes: * - id (numeric|string) if a numeric value is specified, then the * category id, if a string is specified, then * the category's path. * - idcolumn (string) field to use as the unique ID, either 'id', * 'path', or 'ipath' (optional, * default: 'id' if the id attribute is numeric, * 'path' if the id attribute is not numeric) * - field (string) category field to return (optional, default: path) * - html (boolean) if set, return HTML (optional, default: false) * - assign (string) the name of a template variable to assign the * output to, instead of returning it to the template. (optional) * * Examples: * * Get the path of category #1 and assign it to the template variable $category: * * <samp>{category_path id='1' assign='category'}</samp> * * Get the path of the category with an ipath of '/1/3/28/30' and display it. * * <samp>{category_path id='/1/3/28/30' idcolumn='ipath' field='path'}</samp> * * Get the parent_id of the category with a path of * '/__SYSTEM__/General/ActiveStatus/Active' and assign it to the template * variable $parentid. Then use that template variable to retrieve and display * the parent's path. * * <samp>{category_path id='/__SYSTEM__/General/ActiveStatus/Active' field='parent_id' assign='parentid'}</samp> * <samp>{category_path id=$parentid}</samp> * * Example from a Content module template: get the sort value of the current * page's category and assign it to the template variable $catsortvalue: * * <samp>{category_path id=$page.categoryId field='sort_value' assign='catsortvalue'}</samp> * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return void|string The value of the specified category field. */ function smarty_function_category_path($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $id = isset($params['id']) ? $params['id'] : 0; $idcolumn = isset($params['idcolumn']) ? $params['idcolumn'] : (is_numeric($id) ? 'id' : 'path'); $field = isset($params['field']) ? $params['field'] : 'path'; $html = isset($params['html']) ? $params['html'] : false; if (!$id) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'id'))); } if (!$idcolumn) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'idcolumn'))); } elseif ($idcolumn != 'id' && $idcolumn != 'path' && $idcolumn != 'ipath') { $view->trigger_error(__f('Error! in %1$s: invalid value for the %2$s parameter (%3$s).', array('category_path', 'idcolumn', $idcolumn))); } if (!$field) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('category_path', 'field'))); } $result = null; if ($idcolumn == 'id') { $cat = CategoryUtil::getCategoryByID($id); } elseif ($idcolumn == 'path' || $idcolumn == 'ipath') { $cat = CategoryUtil::getCategoryByPath($id, $idcolumn); } if ($cat) { if (isset($cat[$field])) { $result = $cat[$field]; } else { $view->trigger_error(__f('Error! Category [%1$s] does not have the field [%2$s] set.', array($id, $field))); return; } } else { $view->trigger_error(__f('Error! Cannot retrieve category with ID %s.', DataUtil::formatForDisplay($id))); return; } if ($assign) { $view->assign($params['assign'], $result); } else { if (isset($html) && is_bool($html) && $html) { return DataUtil::formatForDisplayHTML($result); } else { return DataUtil::formatForDisplay($result); } } }
/** * View list of categories * * @return Renderer */ public function categories($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Content:page:', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $mainCategoryId = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); // 30 == /__SYSTEM__/Modules/Global $categories = CategoryUtil::getCategoriesByParentID($mainCategoryId); $rootCategory = CategoryUtil::getCategoryByID($mainCategoryId); $this->view->assign('rootCategory', $rootCategory); $this->view->assign('categories', $categories); $this->view->assign('lang', ZLanguage::getLanguageCode()); // Count the numer of pages in a specific category $pagecount = array(); foreach ($categories as $category) { $pagecount[$category['id']] = ModUtil::apiFunc('Content', 'Page', 'getPageCount', array ('filter' => array('category' => $category['id']))); } $this->view->assign('pagecount', $pagecount); return $this->view->fetch('user/main.tpl'); }
public function initialize(Zikula_Form_View $view) { if (!SecurityUtil::checkPermission('Content:page:', '::', ACCESS_EDIT)) { throw new Zikula_Exception_Forbidden(LogUtil::getErrorMsgPermission()); } // Include categories only when 2nd category enabled in settings $pages = ModUtil::apiFunc('Content', 'Page', 'getPages', array('editing' => true, 'filter' => array('checkActive' => false, 'expandedPageIds' => SessionUtil::getVar('contentExpandedPageIds', array())), 'enableEscape' => true, 'translate' => false, 'includeLanguages' => true, 'includeCategories' => $this->getVar('categoryUsage') < 3, 'orderBy' => 'setLeft')); if ($pages === false) { return $this->view->registerError(null); } // Get categories names if enabled if ($this->getVar('$categoryUsage') < 4) { $lang = ZLanguage::getLanguageCode(); $categories = array(); foreach ($pages as $page) { $cat = CategoryUtil::getCategoryByID($page['categoryId']); $categories[$page['id']] = array(); $categories[$page['id']][] = isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']; if (isset($page['categories']) && is_array($page['categories'])) { foreach ($page['categories'] as $pageCat) { $cat = CategoryUtil::getCategoryByID($pageCat['categoryId']); $categories[$page['id']][] = isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']; } } } $this->view->assign('categories', $categories); } PageUtil::setVar('title', $this->__('Page list and content structure')); $csssrc = ThemeUtil::getModuleStylesheet('admin', 'admin.css'); PageUtil::addVar('stylesheet', $csssrc); $this->view->assign('pages', $pages); $this->view->assign('multilingual', ModUtil::getVar(ModUtil::CONFIG_MODULE, 'multilingual')); $this->view->assign('enableVersioning', $this->getVar('enableVersioning')); $this->view->assign('language', ZLanguage::getLanguageCode()); Content_Util::contentAddAccess($this->view, null); return true; }
/** * display available categories in News * * @author Erik Spaan [espaan] * @return string HTML string */ public function categorylist($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission()); $enablecategorization = $this->getVar('enablecategorization'); if (UserUtil::isLoggedIn()) { $uid = UserUtil::getVar('uid'); } else { $uid = 0; } if ($enablecategorization) { // Get the categories registered for News $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news'); $properties = array_keys($catregistry); $propertiesdata = array(); foreach ($properties as $property) { $rootcat = CategoryUtil::getCategoryByID($catregistry[$property]); if (!empty($rootcat)) { $rootcat['path'] .= '/'; // Get all categories in this category property $catcount = $this->_countcategories($rootcat, $property, $catregistry, $uid); $rootcat['news_articlecount'] = $catcount['category']['news_articlecount']; $rootcat['news_totalarticlecount'] = $catcount['category']['news_totalarticlecount']; $rootcat['news_yourarticlecount'] = $catcount['category']['news_yourarticlecount']; $rootcat['subcategories'] = $catcount['subcategories']; // Store data per property for listing in the overview $propertiesdata[] = array('name' => $property, 'category' => $rootcat); } } // Assign property & category related vars $this->view->assign('propertiesdata', $propertiesdata); } // Assign the config vars $this->view->assign('enablecategorization', $enablecategorization); $this->view->assign('shorturls', System::getVar('shorturls', false)); $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign('catimagepath', $this->getVar('catimagepath')); // Return the output that has been generated by this function return $this->view->fetch('user/categorylist.tpl'); }
public function updatePreProcess($objArray = null) { if (!$objArray) { $objArray =& $this->_objData; } if (!$objArray) { return $objArray; } foreach ($objArray as $k => $obj) { $pid = $obj['parent_id']; $parent = CategoryUtil::getCategoryByID((int) $pid); $this->insertPreProcess(); $objArray[$k]['path'] = "{$parent['path']}/{$obj['name']}"; $objArray[$k]['ipath'] = "{$parent['ipath']}/{$obj['id']}"; } return $objArray; }
/** * Load the parameters. * * This method is static because it is also called by the * CategoryCheckboxList plugin * * @param object &$list The list object (here: $this). * @param boolean $includeEmptyElement Whether or not to include an empty null item. * @param array $params The parameters passed from the Smarty plugin. * * @return void */ static function loadParameters(&$list, $includeEmptyElement, $params) { $all = isset($params['all']) ? $params['all'] : false; $lang = isset($params['lang']) ? $params['lang'] : ZLanguage::getLanguageCode(); $list->category = isset($params['category']) ? $params['category'] : 0; $list->editLink = isset($params['editLink']) ? $params['editLink'] : true; $includeLeaf = isset($params['includeLeaf']) ? $params['includeLeaf'] : true; $includeRoot = isset($params['includeRoot']) ? $params['includeRoot'] : false; $path = isset($params['path']) ? $params['path'] : ''; $pathfield = isset($params['pathfield']) ? $params['pathfield'] : 'path'; $recurse = isset($params['recurse']) ? $params['recurse'] : true; $relative = isset($params['relative']) ? $params['relative'] : true; $sortField = isset($params['sortField']) ? $params['sortField'] : 'sort_value'; $catField = isset($params['catField']) ? $params['catField'] : 'id'; $allCats = array(); // if we don't have a category-id we see if we can get a category by path if (!$list->category && $path) { $list->category = CategoryUtil::getCategoryByPath($path, $pathfield); $allCats = CategoryUtil::getSubCategoriesForCategory($list->category, $recurse, $relative, $includeRoot, $includeLeaf, $all, null, '', null, $sortField); } elseif (is_array($list->category) && isset($list->category['id']) && is_integer($list->category['id'])) { // check if we have an actual category object with a numeric ID set $allCats = CategoryUtil::getSubCategoriesForCategory($list->category, $recurse, $relative, $includeRoot, $includeLeaf, $all, null, '', null, $sortField); } elseif (is_numeric($list->category)) { // check if we have a numeric category $list->category = CategoryUtil::getCategoryByID($list->category); $allCats = CategoryUtil::getSubCategoriesForCategory($list->category, $recurse, $relative, $includeRoot, $includeLeaf, $all, null, '', null, $sortField); } elseif (is_string($list->category) && strpos($list->category, '/') === 0) { // check if we have a string/path category $list->category = CategoryUtil::getCategoryByPath($list->category, $pathfield); $allCats = CategoryUtil::getSubCategoriesForCategory($list->category, $recurse, $relative, $includeRoot, $includeLeaf, $all, null, '', null, $sortField); } if (!$allCats) { $allCats = array(); } if ($list->mandatory) { $list->addItem(__('Choose one'), null); } $line = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'; if ($includeEmptyElement) { $list->addItem('', null); } foreach ($allCats as $cat) { $cslash = StringUtil::countInstances(isset($cat['ipath_relative']) ? $cat['ipath_relative'] : $cat['ipath'], '/'); $indent = ''; if ($cslash > 0) { $indent = '| ' . substr($line, 0, $cslash * 2); } $catName = html_entity_decode(isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']); $list->addItem($indent . ' ' . $catName, isset($cat[$catField]) ? $cat[$catField] : $cat['id']); } }
/** * In Content editing mode this shows the Content plugin contents */ public function displayEditing() { $properties = array_keys($this->categories); $lang = ZLanguage::getLanguageCode(); // Construct the selected categories array $catnames = array(); foreach ($properties as $prop) { foreach ($this->categories[$prop] as $catid) { $cat = CategoryUtil::getCategoryByID($catid); $catnames[] = isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']; } } $catname = implode(' | ', $catnames); if (empty($catname)) { $catname = 'all'; } $output = '<h4>' . DataUtil::formatForDisplayHTML($this->title) . '</h4>'; $output .= '<p>' . $this->__f("News articles listed under <strong>%s</strong> category", $catname) . '</p>'; return $output; }
/** * view items * * @return string HTML output */ public function view() { // Security check if (!SecurityUtil::checkPermission('Reviews::', '::', ACCESS_OVERVIEW)) { return LogUtil::registerPermissionError(); } $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'view'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $entityClass = $this->name . '_Entity_' . ucwords($objectType); $repository = $this->entityManager->getRepository($entityClass); $repository->setControllerArguments(array()); $viewHelper = new Reviews_Util_View($this->serviceManager); // parameter for used sorting field $sort = $this->request->query->filter('sort', '', FILTER_SANITIZE_STRING); if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) { $sort = $repository->getDefaultSortingField(); } // parameter for used sort order $sdir = $this->request->query->filter('sortdir', '', FILTER_SANITIZE_STRING); $sdir = strtolower($sdir); if ($sdir != 'asc' && $sdir != 'desc') { $sdir = 'asc'; } // convenience vars to make code clearer $currentUrlArgs = array('ot' => $objectType); $where = ''; // we check for letter $letter = $this->request->query->filter('letter', NULL); if ($letter != NULL) { $where = 'tbl.title LIKE \'' . DataUtil::formatForStore($letter) . '%\''; } $selectionArgs = array('ot' => $objectType, 'where' => $where, 'orderBy' => $sort . ' ' . $sdir); $showOwnEntries = (int) $this->request->query->filter('own', $this->getVar('showOnlyOwnEntries', 0), FILTER_VALIDATE_INT); $showAllEntries = (int) $this->request->query->filter('all', 0, FILTER_VALIDATE_INT); if (!$showAllEntries) { $csv = (int) $this->request->query->filter('usecsvext', 0, FILTER_VALIDATE_INT); if ($csv == 1) { $showAllEntries = 1; } } $this->view->assign('showOwnEntries', $showOwnEntries)->assign('showAllEntries', $showAllEntries); if ($showOwnEntries == 1) { $currentUrlArgs['own'] = 1; } if ($showAllEntries == 1) { $currentUrlArgs['all'] = 1; } // prepare access level for cache id $accessLevel = ACCESS_READ; $component = 'Reviews:' . ucwords($objectType) . ':'; $instance = '::'; if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) { $accessLevel = ACCESS_COMMENT; } if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) { $accessLevel = ACCESS_EDIT; } $templateFile = $viewHelper->getViewTemplate($this->view, 'user', $objectType, 'view', array()); $cacheId = 'view|ot_' . $objectType . '_sort_' . $sort . '_' . $sdir; $resultsPerPage = 0; if ($showAllEntries == 1) { // set cache id $this->view->setCacheId($cacheId . '_all_1_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list without pagination $entities = ModUtil::apiFunc($this->name, 'selection', 'getEntities', $selectionArgs); } else { // the current offset which is used to calculate the pagination $currentPage = (int) $this->request->query->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) $this->request->query->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $resultsPerPage = $this->getVar('pagesize', 10); } // set cache id $this->view->setCacheId($cacheId . '_amount_' . $resultsPerPage . '_page_' . $currentPage . '_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list with pagination $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage)); } foreach ($entities as $k => $entity) { $entity->initWorkflow(); } // build ModUrl instance for display hooks $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'view', ZLanguage::getLanguageCode(), $currentUrlArgs); // assign the object data, sorting information and details for creating the pager $this->view->assign('items', $entities)->assign('sort', $sort)->assign('sdir', $sdir)->assign('pageSize', $resultsPerPage)->assign('currentUrlObject', $currentUrlObject)->assign('shorturls', System::getVar('shorturls'))->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); $modelHelper = new Reviews_Util_Model($this->serviceManager); $this->view->assign('canBeCreated', $modelHelper->canBeCreated($objectType)); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); ///////////////////////Alter Code // Get parameters from whatever input we need $cat = (string) FormUtil::getPassedValue('cat', isset($args['cat']) ? $args['cat'] : null, 'GET'); $prop = (string) FormUtil::getPassedValue('prop', isset($args['prop']) ? $args['prop'] : null, 'GET'); $letter = (string) FormUtil::getPassedValue('letter', null, 'REQUEST'); $page = (int) FormUtil::getPassedValue('page', isset($args['page']) ? $args['page'] : 1, 'GET'); // get all module vars for later use $modvars = ModUtil::getVar('Reviews'); // defaults and input validation if (!is_numeric($page) || $page < 0) { $page = 1; } $startnum = ($page - 1) * $modvars['itemsperpage'] + 1; // check if categorisation is enabled if ($modvars['enablecategorization']) { // get the categories registered for Reviews $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Reviews', 'reviews'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($properties) && in_array($prop, $properties)) { // if the property and the category are specified // means that we'll list the reviews that belongs to that category if (!empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'] . '/' . $cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } if (!empty($cat) && isset($cat['path'])) { // include all it's subcategories and build the filter $categories = categoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $catFilter = array($prop => $catstofilter); } else { LogUtil::registerError($this->__('Invalid category passed.')); } } } } // Get all matching reviews /*$items = ModUtil::apiFunc('Reviews', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); // assign all the necessary template variables $this->view->assign('items', $items); $this->view->assign('category', $cat); $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign($modvars); $this->view->assign('shorturls', System::getVar('shorturls')); $this->view->assign('shorturlstype', System::getVar('shorturlstype')); // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Reviews', 'user', 'countitems', array('letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); */ }
/** * Displays all available events. * * @return string HTML Code */ public function view() { // check object type $objectType = FormUtil::getPassedValue('ot', 'event', 'GET'); $this->throwNotFoundUnless(in_array($objectType, TimeIt_Util::getObjectTypes('view')), $this->__f('Unkown object type %s.', DataUtil::formatForDisplay($objectType))); // load filter $filter = TimeIt_Filter_Container::getFilterFormGETPOST($objectType); $this->view->assign('modvars', ModUtil::getVar('TimeIt')); // vars $tpl = null; $theme = null; $domain = $this->serviceManager->getService('timeit.manager.' . $objectType); // load the data if ($objectType == 'event') { $calendarId = (int) FormUtil::getPassedValue('cid', ModUtil::getVar('TimeIt', 'defaultCalendar'), 'GETPOST'); $calendar = $this->serviceManager->getService('timeit.manager.calendar')->getObject($calendarId); $this->throwNotFoundIf(empty($calendar), $this->__f('Calendar [%s] not found.', $calendarId)); $year = (int) FormUtil::getPassedValue('year', date("Y"), 'GETPOST'); $month = (int) FormUtil::getPassedValue('month', date("n"), 'GETPOST'); $day = (int) FormUtil::getPassedValue('day', date("j"), 'GETPOST'); $tpl = FormUtil::getPassedValue('viewType', FormUtil::getPassedValue('viewtype', $calendar['config']['defaultView'], 'GETPOST'), 'GETPOST'); $firstDayOfWeek = (int) FormUtil::getPassedValue('firstDayOfWeek', -1, 'GETPOST'); $theme = FormUtil::getPassedValue('template', $calendar['config']['defaultTemplate'], 'GETPOST'); // backward compatibility if ($theme == 'default') { $theme = 'table'; } // check for a valid $tpl if ($tpl != 'year' && $tpl != 'month' && $tpl != 'week' && $tpl != 'day') { $tpl = $calendar['config']['defaultView']; } $tpl = 'month'; $theme = 'table'; $this->view->assign('template', $theme); $this->view->assign('viewed_day', $day); $this->view->assign('viewed_month', $month); $this->view->assign('viewed_year', $year); $this->view->assign('viewType', $tpl); $this->view->assign('calendar', $calendar); $this->view->assign('viewed_date', DateUtil::getDatetime(mktime(0, 0, 0, $month, $day, $year), DATEONLYFORMAT_FIXED)); $this->view->assign('date_today', DateUtil::getDatetime(null, DATEONLYFORMAT_FIXED)); $this->view->assign('month_startDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, 1, $year), DATEONLYFORMAT_FIXED)); $this->view->assign('month_endDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, DateUtil::getDaysInMonth($month, $year), $year), DATEONLYFORMAT_FIXED)); $this->view->assign('filter_obj_url', $filter->toURL()); $this->view->assign('firstDayOfWeek', $firstDayOfWeek); $this->view->assign('selectedCats', array()); $categories = CategoryRegistryUtil::getRegisteredModuleCategories('TimeIt', 'TimeIt_events'); foreach ($categories as $property => $cid) { $cat = CategoryUtil::getCategoryByID($cid); if (isset($cat['__ATTRIBUTES__']['calendarid']) && !empty($cat['__ATTRIBUTES__']['calendarid'])) { if ($cat['__ATTRIBUTES__']['calendarid'] != $calendar['id']) { unset($categories[$property]); } } } $this->view->assign('categories', $categories); // load event data switch ($tpl) { case 'year': $objectData = $domain->getYearEvents($year, $calendar['id'], $firstDayOfWeek); break; case 'month': $objectData = $domain->getMonthEvents($year, $month, $day, $calendar['id'], $firstDayOfWeek, $filter); break; case 'week': $objectData = $domain->getWeekEvents($year, $month, $day, $calendar['id'], $filter); break; case 'day': $objectData = $domain->getDayEvents($year, $month, $day, $calendar['id'], $filter); break; } } // assign the data $this->view->assign('objectArray', $objectData); // render the html return $this->_renderTemplate($this->view, $objectType, 'user', 'view', $theme, $tpl, 'table'); }
/** * display block * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the rendered bock */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Slideshowblock::', $blockinfo['bid'].'::', ACCESS_OVERVIEW)) { return; } // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['limit'])) { $vars['limit'] = 4; } // work out the parameters for the api all $apiargs = array(); $apiargs['numitems'] = $vars['limit']; $apiargs['status'] = News_Api_User::STATUS_PUBLISHED; $apiargs['ignorecats'] = true; if (isset($vars['category']) && !empty($vars['category'])) { $cat = CategoryUtil::getCategoryByID($vars['category']); $categories = CategoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $apiargs['category'] = array('Main' => $catstofilter); } $apiargs['filterbydate'] = true; // call the api $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs); // check for an empty return if (empty($items)) { return; } // create the output object $this->view->setCaching(false); // loop through the items $picupload_uploaddir = ModUtil::getVar('News', 'picupload_uploaddir'); $picupload_maxpictures = ModUtil::getVar('News', 'picupload_maxpictures'); $slideshowoutput = array(); $count = 0; foreach ($items as $item) { $count++; if ($item['pictures'] > 0) { $this->view->assign('readperm', SecurityUtil::checkPermission('News::', "$item[cr_uid]::$item[sid]", ACCESS_READ)); $this->view->assign('count', $count); $this->view->assign('picupload_uploaddir', $picupload_uploaddir); $this->view->assign($item); $slideshowoutput[] = $this->view->fetch('block/slideshow_row.tpl', $item['sid'], null, false, false); } } // assign the results $this->view->assign('slideshow', $slideshowoutput); $blockinfo['content'] = $this->view->fetch('block/slideshow.tpl'); return BlockUtil::themeBlock($blockinfo); }
/** * Zikula_View function to display the current date and time * * Example * {getCategotyNameByID id=123123} * * * @return string */ function smarty_function_getCategotyNameByID($params, Zikula_View $view) { $piID = isset($params['id']) ? $params['id'] : 0; $laCategory = CategoryUtil::getCategoryByID($piID); return $laCategory["name"]; }
/** * view items * * @return string html string */ public function view($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Pages::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission()); $lang = ZLanguage::getLanguageCode(); $startnum = (int)FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : 1, 'GET'); $prop = (string)FormUtil::getPassedValue('prop', isset($args['prop']) ? $args['prop'] : null, 'GET'); $cat = (string)FormUtil::getPassedValue('cat', isset($args['cat']) ? $args['cat'] : null, 'GET'); $catparam = $cat; // defaults and input validation if (!is_numeric($startnum) || $startnum < 0) { $startnum = 1; } // get all module vars for later use $modvars = $this->getVars(); // check if categorization is enabled if ($modvars['enablecategorization']) { // get the categories registered for the Pages $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Pages', 'pages'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($prop) && in_array($prop, $properties)) { // TODO [Perform a category permission check here] // if the property and the category are specified // means that we'll list the pages that belongs to that category if (!empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'].'/'.$cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } if (!empty($cat) && isset($cat['path'])) { // include all it's subcategories and build the filter $categories = categoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $catFilter = array($prop => $catstofilter); } else { LogUtil::registerError($this->__('Invalid category passed.')); } } } // if nothing or only property is specified // means that we'll list the subcategories available on a property - mateo if (!isset($catFilter)) { $listproperties = array(); // list all the available properties if (empty($prop) || !in_array($prop, $properties)) { $listproperties = $properties; } else { $listproperties[] = $prop; } $listrootcats = array(); $listcategories = array(); $categorylisted = array(); foreach (array_keys($listproperties) as $i) { $listrootcats[$i] = CategoryUtil::getCategoryByID($catregistry[$listproperties[$i]]); if (in_array($listrootcats[$i]['id'], $categorylisted)) { continue; } // mark the root category as already listed $categorylisted[] = $listrootcats[$i]['id']; // add a final / to make the easy the relative paths build in the template - mateo $listrootcats[$i]['path'] .= '/'; // gets all the subcategories to list $listcategories[$i] = CategoryUtil::getCategoriesByParentID($listrootcats[$i]['id']); } unset($categorylisted); } } // assign various useful template variables $this->view->assign('startnum', $startnum); $this->view->assign('lang', $lang); // If categorization is enabled, show a // list of subcategories of an specific property if ($modvars['enablecategorization'] && !isset($catFilter)) { // Assign the current action to the template $this->view->assign('action', 'subcatslist'); $this->view->assign('listrootcats', $listrootcats); $this->view->assign('listproperties', $listproperties); $this->view->assign('listcategories', $listcategories); // List of Pages // of an specific category if categorization is enabled } else { // Assign the current action to the template $this->view->assign('action', 'pageslist'); // Assign the categories information if ($modvars['enablecategorization']) { $this->view->assign('properties', $properties); $this->view->assign('category', $cat); } // Get all matching pages $items = ModUtil::apiFunc('Pages', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null, 'language' => $lang)); if ($items == false) { LogUtil::registerStatus($this->__('No pages found.')); } // Loop through each item and display it. $pages = array(); foreach ($items as $item) { if (SecurityUtil::checkPermission('Pages::', "{$item['title']}::{$item['pageid']}", ACCESS_OVERVIEW)) { $this->view->assign('item', $item); if (SecurityUtil::checkPermission('Pages::', "{$item['title']}::{$item['pageid']}", ACCESS_READ)) { $pages[] = $this->view->fetch('user/rowread.tpl', $item['pageid']); } else { $pages[] = $this->view->fetch('user/rowoverview.tpl', $item['pageid']); } } } unset($items); // assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Pages', 'user', 'countitems', array('category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // assign the item output to the template $this->view->assign('pages', $pages); } // Return the output that has been generated by this function // is not practical to check for is_cached earlier in this method. $this->view->setCacheId('view|prop_'.$prop.'_cat_'.$catparam . '|stnum_'.$startnum.'_'.$modvars['itemsperpage']); return $this->view->fetch('user/view.tpl'); }
public function updatePreProcess($data = null) { if (!$data) { $data =& $this->_objData; } if (!$data) { return $data; } $pid = (int) $data['parent_id']; $parent = CategoryUtil::getCategoryByID($pid); $this->insertPreProcess(); $data = $this->_objData; $data['path'] = "{$parent['path']}/{$data['name']}"; $data['ipath'] = "{$parent['ipath']}/{$data['id']}"; // encode slash $data['name'] = str_replace('/', '/', $data['name']); $this->_objData = $data; return $data; }
/** * display block * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the rendered bock */ public function display($blockinfo) { // security check if (!SecurityUtil::checkPermission('Storiesblock::', $blockinfo['bid'].'::', ACCESS_OVERVIEW)) { return; } // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (!isset($vars['storiestype'])) { $vars['storiestype'] = 2; } if (!isset($vars['limit'])) { $vars['limit'] = 10; } // work out the paraemters for the api all $apiargs = array(); switch ($vars['storiestype']) { case 1: // non index page articles $apiargs['displayonindex'] = 0; break; case 3: // index page articles $apiargs['displayonindex'] = 1; break; // all - doesn't need displayonindex } $apiargs['numitems'] = $vars['limit']; $apiargs['status'] = News_Api_User::STATUS_PUBLISHED; $apiargs['ignorecats'] = true; if (isset($vars['category']) && !empty($vars['category'])) { $cat = CategoryUtil::getCategoryByID($vars['category']); $categories = CategoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $apiargs['category'] = array('Main' => $catstofilter); } $apiargs['filterbydate'] = true; // call the api $items = ModUtil::apiFunc('News', 'user', 'getall', $apiargs); // check for an empty return if (empty($items)) { return; } // create the output object $this->view->setCaching(false); // loop through the items $storiesoutput = array(); foreach ($items as $item) { $storyreadperm = false; if (SecurityUtil::checkPermission('News::', "$item[cr_uid]::$item[sid]", ACCESS_READ)) { $storyreadperm = true; } $this->view->assign('readperm', $storyreadperm); $this->view->assign($item); $storiesoutput[] = $this->view->fetch('block/stories_row.tpl', $item['sid'], null, false, false); } // assign the results $this->view->assign('stories', $storiesoutput); $blockinfo['content'] = $this->view->fetch('block/stories.tpl'); return BlockUtil::themeBlock($blockinfo); }
/** * Category selector. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string */ function smarty_function_selector_category($params, Zikula_View $view) { $categoryRegistryModule = isset($params['categoryRegistryModule']) ? $params['categoryRegistryModule'] : ''; $categoryRegistryTable = isset($params['categoryRegistryTable']) ? $params['categoryRegistryTable'] : ''; $categoryRegistryProperty = isset($params['categoryRegistryProperty']) ? $params['categoryRegistryProperty'] : ''; $category = isset($params['category']) ? $params['category'] : 0; $path = isset($params['path']) ? $params['path'] : ''; $pathfield = isset($params['pathfield']) ? $params['pathfield'] : 'path'; $field = isset($params['field']) ? $params['field'] : 'id'; $fieldIsAttribute = isset($params['fieldIsAttribute']) ? $params['fieldIsAttribute'] : null; $selectedValue = isset($params['selectedValue']) ? $params['selectedValue'] : 0; $defaultValue = isset($params['defaultValue']) ? $params['defaultValue'] : 0; $defaultText = isset($params['defaultText']) ? $params['defaultText'] : ''; $allValue = isset($params['allValue']) ? $params['allValue'] : 0; $allText = isset($params['allText']) ? $params['allText'] : ''; $name = isset($params['name']) ? $params['name'] : 'defaultselectorname'; $submit = isset($params['submit']) ? $params['submit'] : false; $recurse = isset($params['recurse']) ? $params['recurse'] : true; $relative = isset($params['relative']) ? $params['relative'] : true; $includeRoot = isset($params['includeRoot']) ? $params['includeRoot'] : false; $includeLeaf = isset($params['includeLeaf']) ? $params['includeLeaf'] : true; $all = isset($params['all']) ? $params['all'] : false; $displayPath = isset($params['displayPath']) ? $params['displayPath'] : false; $attributes = isset($params['attributes']) ? $params['attributes'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; $editLink = isset($params['editLink']) ? $params['editLink'] : true; $multipleSize = isset($params['multipleSize']) ? $params['multipleSize'] : 1; $sortField = isset($params['sortField']) ? $params['sortField'] : 'sort_value'; $doReplaceRootCat = isset($params['doReplaceRootCat']) ? $params['doReplaceRootCat'] : null; $cssClass = isset($params['cssClass']) ? $params['cssClass'] : ''; if (isset($params['lang'])) { $lang = $params['lang']; $oldLocale = ZLanguage::getLocale(); ZLanguage::setLocale($lang); } else { $lang = ZLanguage::getLanguageCode(); } if (!$category && !$path && $categoryRegistryModule && $categoryRegistryTable && $categoryRegistryProperty) { $category = CategoryRegistryUtil::getRegisteredModuleCategory($categoryRegistryModule, $categoryRegistryTable, $categoryRegistryProperty); } // if we don't have a category-id we see if we can get a category by path if (!$category && $path) { $category = CategoryUtil::getCategoryByPath($path, $pathfield); } elseif (is_numeric($category)) { // check if we have a numeric category $category = CategoryUtil::getCategoryByID($category); } elseif (is_string($category) && strpos($category, '/') === 0) { // check if we have a string/path category $category = CategoryUtil::getCategoryByPath($category, $pathfield); } static $catCache; if (!$catCache) { $catCache = array(); } $cacheKey = "{$category['id']}||{$recurse}|{$relative}|{$includeRoot}|{$includeLeaf}|{$all}|||{$attributes}|{$sortField}"; if (!isset($catCache[$cacheKey])) { $catCache[$cacheKey] = CategoryUtil::getSubCategoriesForCategory($category, $recurse, $relative, $includeRoot, $includeLeaf, $all, '', '', $attributes, $sortField); } $html = CategoryUtil::getSelector_Categories($catCache[$cacheKey], $field, $selectedValue, $name, $defaultValue, $defaultText, $allValue, $allText, $submit, $displayPath, $doReplaceRootCat, $multipleSize, $fieldIsAttribute, $cssClass, $lang); if ($editLink && !empty($category) && SecurityUtil::checkPermission('ZikulaCategoriesModule::', "{$category['id']}::", ACCESS_EDIT)) { $url = DataUtil::formatForDisplay(ModUtil::url('ZikulaCategoriesModule', 'user', 'edit', array('dr' => $category['id']))); $html .= " <a href=\"{$url}\"><img src=\"" . System::getBaseUrl() . "images/icons/extrasmall/xedit.png\" title=\"" . __('Edit sub-category') . '" alt="' . __('Edit sub-category') . '" /></a>'; } if (isset($params['lang'])) { // Reset language again. ZLanguage::setLocale($oldLocale); } if ($assign) { $view->assign($assign, $html); } else { return $html; } }
/** * edit category for a simple, non-recursive set of categories */ public function edit() { $docroot = FormUtil::getPassedValue('dr', 0); $cid = FormUtil::getPassedValue('cid', 0); $url = ModUtil::url('Categories', 'user', 'edit', array('dr' => $docroot)); if (!SecurityUtil::checkPermission('Categories::category', "ID::$docroot", ACCESS_EDIT)) { return LogUtil::registerPermissionError($url); } $referer = System::serverGetVar('HTTP_REFERER'); if (strpos($referer, 'module=Categories') === false) { SessionUtil::setVar('categories_referer', $referer); } $rootCat = array(); $allCats = array(); $editCat = array(); if (!$docroot) { return LogUtil::registerError($this->__("Error! The URL contains an invalid 'document root' parameter."), null, $url); } if ($docroot == 1) { return LogUtil::registerError($this->__("Error! The root directory cannot be modified in 'user' mode"), null, $url); } if (is_int((int)$docroot) && $docroot > 0) { $rootCat = CategoryUtil::getCategoryByID($docroot); } else { $rootCat = CategoryUtil::getCategoryByPath($docroot); if (!$rootCat) { $rootCat = CategoryUtil::getCategoryByPath($docroot, 'ipath'); } } // now check if someone is trying edit another user's categories $userRoot = $this->getVar('userrootcat', 0); if ($userRoot) { $userRootCat = CategoryUtil::getCategoryByPath($userRoot); if ($userRootCat) { $userRootCatIPath = $userRootCat['ipath']; $rootCatIPath = $rootCat['ipath']; if (strpos($rootCatIPath, $userRootCatIPath) !== false) { if (!SecurityUtil::checkPermission('Categories::category', "ID::$docroot", ACCESS_ADMIN)) { $thisUserRootCategoryName = ModUtil::apiFunc('Categories', 'user', 'getusercategoryname'); $thisUserRootCatPath = $userRootCat['path'] . '/' . $thisUserRootCategoryName; $userRootCatPath = $userRootCat['path']; $rootCatPath = $rootCat['path']; if (strpos($rootCatPath, $userRootCatPath) === false) { //! %s represents the root path (id), passed in the url return LogUtil::registerError($this->__f("Error! It looks like you are trying to edit another user's categories. Only site administrators can do that (%s).", $docroot), null, $url); } } } } } if ($cid) { $editCat = CategoryUtil::getCategoryByID($cid); if ($editCat['is_locked']) { //! %1$s is the id, %2$s is the name return LogUtil::registerError($this->__f('Notice: The administrator has locked the category \'%2$s\' (ID \'%$1s\'). You cannot edit or delete it.', array($cid, $editCat['name'])), null, $url); } } if (!$rootCat) { return LogUtil::registerError($this->__f("Error! Cannot access root directory (%s).", $docroot), null, $url); } if ($editCat && !$editCat['is_leaf']) { return LogUtil::registerError($this->__f('Error! The specified category is not a leaf-level category (%s).', $cid), null, $url); } if ($editCat && !CategoryUtil::isDirectSubCategory($rootCat, $editCat)) { return LogUtil::registerError($this->__f('Error! The specified category is not a child of the document root (%1$s; %2$s).', array($docroot, $cid)), null, $url); } $allCats = CategoryUtil::getSubCategoriesForCategory($rootCat, false, false, false, true, true); $attributes = isset($editCat['__ATTRIBUTES__']) ? $editCat['__ATTRIBUTES__'] : array(); $languages = ZLanguage::getInstalledLanguages(); $this->view->setCaching(Zikula_View::CACHE_DISABLED); return $this->view->assign('rootCat', $rootCat) ->assign('category', $editCat) ->assign('attributes', $attributes) ->assign('allCats', $allCats) ->assign('languages', $languages) ->assign('userlanguage', ZLanguage::getLanguageCode()) ->assign('referer', SessionUtil::getVar('categories_referer')) ->fetch('categories_user_edit.tpl'); }
public function categories() { $this->throwForbiddenUnless(SecurityUtil::checkPermission('AddressBook::', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $this->view->setCacheId('main'); if ($this->view->is_cached('user/main.tpl')) { return $this->view->fetch('user/main.tpl'); } // Create output object $enablecategorization = ModUtil::getVar('AddressBook', 'enablecategorization'); if ($enablecategorization) { // get the categories registered for the AddressBook $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('AddressBook', 'addressbook_address'); $properties = array_keys($catregistry); $propertiesdata = array(); foreach ($properties as $property) { $rootcat = CategoryUtil::getCategoryByID($catregistry[$property]); if (!empty($rootcat)) { $rootcat['path'] .= '/'; // add this to make the relative paths of the subcategories with ease - mateo $subcategories = CategoryUtil::getCategoriesByParentID($rootcat['id']); $propertiesdata[] = array('name' => $property, 'rootcat' => $rootcat, 'subcategories' => $subcategories); } } // Assign some useful vars to customize the main $this->view->assign('properties', $properties); $this->view->assign('propertiesdata', $propertiesdata); } return $this->view->fetch('user_categories.tpl'); }
/** * Return some useful News links * * Syntax used in menutree * {ext:Blocks:news:[flat=BOOL&links=view,add,cat,arch|ALL]} * Params in [] are optional and * flat - true or false, if set to true links are ungrouped (default is false) * links - list of elements, default is ALL, avaiable items: * - view - link to main News view * - add - link do Submit News form * - cat - list of News categories * - arch - link to News archive * Items are displayed in order provided in menutree * * @param array $args['item'] menu node to be replaced * @param string $args['lang'] current menu language * @param string $args['extrainfo'] additional params * @return mixed array of links if successful, false otherwise */ public function news($args) { $dom = ZLanguage::getModuleDomain('menutree'); $item = isset($args['item']) && !empty($args['item']) ? $args['item'] : null; $lang = isset($args['lang']) && !empty($args['lang']) ? $args['lang'] : null; $bid = isset($args['bid']) && !empty($args['bid']) ? $args['bid'] : null; $extrainfo = isset($args['extrainfo']) && !empty($args['extrainfo']) ? $args['extrainfo'] : null; // $item ang lang params are required if (!$item || !$lang) { return false; } // is there is extrainfo - convert it into array, parse_str is quite handy if ($extrainfo) { parse_str($extrainfo, $extrainfo); } $extrainfo['flat'] = isset($extrainfo['flat']) ? (bool) $extrainfo['flat'] : false; $extrainfo['links'] = isset($extrainfo['links']) ? explode(',', $extrainfo['links']) : array('all'); // get id for first element, use api func to aviod id conflicts inside menu $idoffset = Blocks_MenutreeUtil::getIdOffset($item['id']); $lineno = 0; // load plugin language file $modinfo = ModUtil::getInfo(ModUtil::getIdFromName('News')); $links = array(); // build some link // you may use associative array keys if (!$extrainfo['flat']) { $links['news'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => ModUtil::url('News'), 'title' => $item['title'], 'className' => $item['className'], 'state' => $item['state'], 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $item['parent'])); } $parentNode = !$extrainfo['flat'] ? $links['news'][$lang]['id'] : $item['parent']; if (in_array('all', $extrainfo['links']) || in_array('view', $extrainfo['links'])) { $links['view'] = array($lang => array('id' => $idoffset++, 'name' => $modinfo['displayname'], 'href' => ModUtil::url('News'), 'title' => __('View news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('arch', $extrainfo['links'])) { $links['arch'] = array($lang => array('id' => $idoffset++, 'name' => __('Archive', $dom), 'href' => ModUtil::url('News', 'user', 'archives'), 'title' => __('Archive', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('add', $extrainfo['links'])) { $links['add'] = array($lang => array('id' => $idoffset++, 'name' => __('Submit news', $dom), 'href' => ModUtil::url('News', 'user', 'new'), 'title' => __('Submit news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('cat', $extrainfo['links'])) { if (!$extrainfo['flat']) { $links['cat'] = array($lang => array('id' => $idoffset++, 'name' => __('Categories', $dom), 'href' => ModUtil::url('News'), 'title' => __('Categories', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } $catParentNode = !$extrainfo['flat'] ? $links['cat'][$lang]['id'] : $item['parent']; Loader::loadClass('CategoryRegistryUtil'); Loader::loadClass('CategoryUtil'); $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'stories'); if (!empty($catregistry)) { $multicategory = count($catregistry) > 1; $catLinks = array(); foreach ($catregistry as $prop => $catid) { if ($multicategory && !$extrainfo['flat']) { $parentCategory = CategoryUtil::getCategoryByID($catid); $catLinks[$catid] = array($lang => array('id' => $idoffset++, 'name' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'href' => '', 'title' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $catParentNode)); } $categories = CategoryUtil::getSubCategories($catid); foreach ($categories as $cat) { $catLinks[$cat['id']] = array($lang => array('id' => $idoffset++, 'name' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'href' => ModUtil::url('News', 'user', 'view', array('prop' => $prop, 'cat' => $cat['name'])), 'title' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => isset($catLinks[$cat['parent_id']]) ? $catLinks[$cat['parent_id']][$lang]['id'] : $catParentNode)); } } } elseif (!$extrainfo['flat']) { unset($links['cat']); } } // sort links in order provided in menutree if (!in_array('all', $extrainfo['links'])) { $sortedLinks = array(); if (!$extrainfo['flat']) { $sortedLinks[] = $links['news']; } foreach ($extrainfo['links'] as $l) { if (isset($links[$l]) && !empty($links[$l])) { $sortedLinks[] = $links[$l]; } if ($l == 'cat') { $sortedLinks = array_merge((array) $sortedLinks, (array) $catLinks); } } $links = $sortedLinks; } return $links; }