/** * 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']); } }
/** * 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'); }