/** * 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'); }
public function handleCommand(Zikula_Form_View $view, &$args) { if ($args['commandName'] == 'save') { if (!$this->view->isValid()) { return false; } $data = $this->view->getValues(); if (!ModUtil::setVars('Content', $data['config'])) { return $this->view->setErrorMsg($this->__('Failed to set configuration variables')); } if ($data['config']['categoryUsage'] < 4) { // load the category registry util $mainCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $data['config']['categoryPropPrimary']); if (!$mainCategory) { return LogUtil::registerError($this->__('Main category property does not exist.')); } if ($data['config']['categoryUsage'] < 3) { $secondCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $data['config']['categoryPropSecondary']); if (!$secondCategory) { return LogUtil::registerError($this->__('Second category property does not exist.')); } } } LogUtil::registerStatus($this->__('Done! Saved module configuration.')); } else if ($args['commandName'] == 'cancel') { } $url = ModUtil::url('Content', 'admin', 'main'); return $this->view->redirect($url); }
public function initialize(Zikula_Form_View $view) { $this->pageId = (int) FormUtil::getPassedValue('pid', isset($this->args['pid']) ? $this->args['pid'] : -1); if ((bool) $this->getVar('inheritPermissions', false) === true) { if (!ModUtil::apiFunc('Content', 'page', 'checkPermissionForPageInheritance', array('pageId' => $this->pageId, 'level' => ACCESS_EDIT))) { throw new Zikula_Exception_Forbidden(LogUtil::getErrorMsgPermission()); } } else { if (!SecurityUtil::checkPermission('Content:page:', $this->pageId . '::', ACCESS_EDIT)) { throw new Zikula_Exception_Forbidden(LogUtil::getErrorMsgPermission()); } } $page = ModUtil::apiFunc('Content', 'Page', 'getPage', array('id' => $this->pageId, 'editing' => true, 'filter' => array('checkActive' => false), 'enableEscape' => false, 'translate' => false, 'includeContent' => true, 'includeCategories' => true)); if ($page === false) { return $this->view->registerError(null); } // load the category registry util $mainCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); $secondCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropSecondary')); $multilingual = ModUtil::getVar(ModUtil::CONFIG_MODULE, 'multilingual'); if ($page['language'] == ZLanguage::getLanguageCode()) { $multilingual = false; } PageUtil::setVar('title', $this->__("Edit page") . ' : ' . $page['title']); $pagelayout = ModUtil::apiFunc('Content', 'Layout', 'getLayout', array('layout' => $page['layout'])); if ($pagelayout === false) { return $this->view->registerError(null); } $layouts = ModUtil::apiFunc('Content', 'Layout', 'getLayouts'); if ($layouts === false) { return $this->view->registerError(null); } $layoutTemplate = $page['layoutEditTemplate']; $this->view->assign('layoutTemplate', $layoutTemplate); $this->view->assign('mainCategory', $mainCategory); $this->view->assign('secondCategory', $secondCategory); $this->view->assign('page', $page); $this->view->assign('multilingual', $multilingual); $this->view->assign('layouts', $layouts); $this->view->assign('pagelayout', $pagelayout); $this->view->assign('enableVersioning', $this->getVar('enableVersioning')); $this->view->assign('categoryUsage', $this->getVar('categoryUsage')); Content_Util::contentAddAccess($this->view, $this->pageId); if (!$this->view->isPostBack() && FormUtil::getPassedValue('back', 0)) { $this->backref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; } if ($this->backref != null) { $returnUrl = $this->backref; } else { $returnUrl = ModUtil::url('Content', 'admin', 'main'); } ModUtil::apiFunc('PageLock', 'user', 'pageLock', array('lockName' => "contentPage{$this->pageId}", 'returnUrl' => $returnUrl)); return true; }
/** * import the categories provided */ private function importCategories() { $rootCatId = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', ModUtil::getVar('Content', 'categoryPropPrimary')); $rootCatObj = CategoryUtil::getCategoryById($rootCatId); $this->categoryPathMap[$this->rootCategoryLocalId] = $rootCatObj['path']; $this->categoryMap[$this->rootCategoryLocalId] = (int) $rootCatId; $oldCategories = $this->getCategories(); foreach ($oldCategories as $oldCategory) { if (isset($this->categoryPathMap[$oldCategory['pid']])) { $id = CategoryUtil::createCategory($this->categoryPathMap[$oldCategory['pid']], $oldCategory['title'], null, $oldCategory['title'], $oldCategory['title']); $catObj = CategoryUtil::getCategoryById($id); $this->categoryPathMap[$oldCategory['id']] = $catObj['path']; $this->categoryMap[$oldCategory['id']] = (int) $id; } } }
/** * 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'); }
/** * 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; } }
/** * modify block settings * * @author The Zikula Development Team * @param array $blockinfo a blockinfo structure * @return output the bock form */ public function modify($blockinfo) { // Break out options from our content field $vars = BlockUtil::varsFromContent($blockinfo['content']); // Defaults if (empty($vars['storiestype'])) { $vars['storiestype'] = 2; } if (empty($vars['limit'])) { $vars['limit'] = 10; } if (empty($vars['category'])) { $vars['category'] = null; } // Create output object $this->view->setCaching(false); $mainCat = CategoryRegistryUtil::getRegisteredModuleCategory('News', 'news', 'Main', 30); // 30 == /__SYSTEM__/Modules/Global $this->view->assign('mainCategory', $mainCat); $this->view->assign('category', $vars['category']); $this->view->assign(ModUtil::getVar('News')); // assign the block vars $this->view->assign($vars); $this->view->assign('dom'); // Return the output that has been generated by this function return $this->view->fetch('block/stories_modify.tpl'); }
/** * decode custom url string * * @author Philipp Niethammer * @return bool true if succeded false otherwise */ public function decodeurl($args) { $suffix = $this->getVar('shorturlsuffix'); $supportedfunctions = array('main', 'list', 'view', 'subpages', 'sitemap', 'extlist', 'categoriesList', 'pagelist'); $argsnum = count($args['vars']); if (!isset($args['vars'][2]) || empty($args['vars'][2])) { System::queryStringSetVar('func', 'sitemap'); return true; } if (in_array($args['vars'][2], $supportedfunctions)) { return false; } $lastarg = end($args['vars']); $urlname = ''; if (substr($lastarg, strlen($lastarg) - strlen($suffix)) == $suffix) { for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } if (($suffixLen = strlen($suffix)) > 0) { $urlname = substr($urlname, 0, -$suffixLen); } System::queryStringSetVar('func', 'view'); System::queryStringSetVar('name', $urlname); return true; } if (!isset($args['vars'][3]) || empty($args['vars'][3])) { $mainCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); // 30 == /__SYSTEM__/Modules/Global //$cats = CategoryUtil::getCategoriesByParentID($mainCategory); $cats = CategoryUtil::getSubCategories($mainCategory); foreach ($cats as $cat) { if ($args['vars'][2] == $cat['name'] || $args['vars'][2] == DataUtil::formatForURL($cat['name'])) { System::queryStringSetVar('func', 'listpages'); System::queryStringSetVar('cat', $cat['id']); return true; } } } for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } System::queryStringSetVar('func', 'subpages'); System::queryStringSetVar('name', $urlname); return true; }
/** * Returns the main category id for a given object type and a certain property name. * * @param string $args['ot'] The object type to retrieve (optional) * @param string $args['property'] The property name (optional) * * @return integer The main category id of desired tree. */ public function getMainCatForProperty(array $args = array()) { $objectType = $this->determineObjectType($args, 'getMainCatForProperty'); $catId = CategoryRegistryUtil::getRegisteredModuleCategory($this->name, ucfirst($objectType), $args['property']); return $catId; }