示例#1
0
 /**
  * get the roor category for a user
  *
  */
 public function getuserrootcat($args)
 {
     $returnCategory = isset($args['returnCategory']) ? $args['returnCategory'] : false;
     $returnField = isset($args['returnField']) ? $args['returnField'] : 'id';
     $userRoot = $this->getVar('userrootcat', 0);
     if (!$userRoot) {
         return LogUtil::registerError($this->__('Error! Could not determine the user root node.'));
     }
     $userRootCat = CategoryUtil::getCategoryByPath($userRoot);
     if (!$userRoot) {
         return LogUtil::registerError($this->__f('Error! The user root node seems to point towards an invalid category: %s.', $userRoot));
     }
     if ($userRootCat == 1) {
         return LogUtil::registerError($this->__("Error! The root directory cannot be modified in 'user' mode"));
     }
     $userCatName = $this->getusercategoryname();
     $thisUserRootCatPath = $userRoot . '/' . $userCatName;
     $thisUserRootCat = CategoryUtil::getCategoryByPath($thisUserRootCatPath);
     if (!$thisUserRootCat) {
         return false;
     }
     if ($returnCategory) {
         return $thisUserRootCat;
     }
     return $thisUserRootCat[$returnField];
 }
示例#2
0
 function __construct($registryId = null, $parentId = null)
 {
     if (!empty($parentId)) {
         $this->parentId = $parentId;
     } else {
         $parentIdCategory = \CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
         $this->parentId = $parentIdCategory['id'];
     }
     $this->registryId = $registryId;
     $this->lang = \ZLanguage::getLanguageCode();
 }
示例#3
0
 /**
  * Install the Reviews application.
  *
  * @return boolean True on success, or false.
  */
 public function install()
 {
     // Check if upload directories exist and if needed create them
     try {
         $controllerHelper = new Reviews_Util_Controller($this->serviceManager);
         $controllerHelper->checkAndCreateAllUploadFolders();
     } catch (\Exception $e) {
         return LogUtil::registerError($e->getMessage());
     }
     // create all tables from according entity definitions
     try {
         DoctrineHelper::createSchema($this->entityManager, $this->listEntityClasses());
     } catch (\Exception $e) {
         if (System::isDevelopmentMode()) {
             return LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
         }
         $returnMessage = $this->__f('An error was encountered while creating the tables for the %s extension.', array($this->name));
         if (!System::isDevelopmentMode()) {
             $returnMessage .= ' ' . $this->__('Please enable the development mode by editing the /config/config.php file in order to reveal the error details.');
         }
         return LogUtil::registerError($returnMessage);
     }
     // set up all our vars with initial values
     $this->setVar('enablecategorization', false);
     $this->setVar('pagesize', 10);
     $this->setVar('scoreForUsers', false);
     $this->setVar('addcategorytitletopermalink', false);
     $categoryRegistryIdsPerEntity = array();
     // add default entry for category registry (property named Main)
     include_once 'modules/Reviews/lib/Reviews/Api/Base/Category.php';
     include_once 'modules/Reviews/lib/Reviews/Api/Category.php';
     $categoryApi = new Reviews_Api_Category($this->serviceManager);
     $categoryGlobal = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
     $registryData = array();
     $registryData['modname'] = $this->name;
     $registryData['table'] = 'Review';
     $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Review'));
     $registryData['category_id'] = $categoryGlobal['id'];
     $registryData['id'] = false;
     if (!DBUtil::insertObject($registryData, 'categories_registry')) {
         LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('review')));
     }
     $categoryRegistryIdsPerEntity['review'] = $registryData['id'];
     // create the default data
     $this->createDefaultData($categoryRegistryIdsPerEntity);
     // register persistent event handlers
     $this->registerPersistentEventHandlers();
     // register hook subscriber bundles
     HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles());
     // initialisation successful
     return true;
 }
示例#4
0
 /**
  * Upgrade the MUVideo application from an older version.
  *
  * If the upgrade fails at some point, it returns the last upgraded version.
  *
  * @param integer $oldVersion Version to upgrade from.
  *
  * @return boolean True on success, false otherwise.
  */
 public function upgrade($oldVersion)
 {
     // Upgrade dependent on old version number
     switch ($oldVersion) {
         case '1.0.0':
             // update the database schema
             try {
                 DoctrineHelper::updateSchema($this->entityManager, $this->listEntityClasses());
             } catch (\Exception $e) {
                 if (System::isDevelopmentMode()) {
                     return LogUtil::registerError($this->__('Doctrine Exception: ') . $e->getMessage());
                 }
                 return LogUtil::registerError($this->__f('An error was encountered while updating tables for the %s extension.', array($this->getName())));
             }
             $categoryRegistryIdsPerEntity = array();
             // add default entry for category registry (property named Main)
             include_once 'modules/MUVideo/lib/MUVideo/Api/Base/Category.php';
             include_once 'modules/MUVideo/lib/MUVideo/Api/Category.php';
             $categoryApi = new MUVideo_Api_Category($this->serviceManager);
             $categoryGlobal = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
             $registryData = array();
             $registryData['modname'] = $this->name;
             $registryData['table'] = 'Collection';
             $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Collection'));
             $registryData['category_id'] = $categoryGlobal['id'];
             $registryData['id'] = false;
             if (!DBUtil::insertObject($registryData, 'categories_registry')) {
                 LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('collection')));
             }
             $categoryRegistryIdsPerEntity['collection'] = $registryData['id'];
             $registryData = array();
             $registryData['modname'] = $this->name;
             $registryData['table'] = 'Movie';
             $registryData['property'] = $categoryApi->getPrimaryProperty(array('ot' => 'Movie'));
             $registryData['category_id'] = $categoryGlobal['id'];
             $registryData['id'] = false;
             if (!DBUtil::insertObject($registryData, 'categories_registry')) {
                 LogUtil::registerError($this->__f('Error! Could not create a category registry for the %s entity.', array('movie')));
             }
             $categoryRegistryIdsPerEntity['movie'] = $registryData['id'];
             // unregister persistent event handlers
             EventUtil::unregisterPersistentModuleHandlers($this->name);
             // register persistent event handlers
             $this->registerPersistentEventHandlers();
         case '1.1.0':
             // for later updates
     }
     // update successful
     return true;
 }
示例#5
0
 private function _content_setCategoryRoot()
 {
     // load necessary classes
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Global');
     if ($rootcat) {
         // create an entry in the categories registry
         $registry = new Categories_DBObject_Registry();
         $registry->setDataField('modname', 'Content');
         $registry->setDataField('table', 'content_page');
         $registry->setDataField('property', 'Main');
         $registry->setDataField('category_id', $rootcat['id']);
         $registry->insert();
     }
     return true;
 }
/**
 * 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);
        }
    }
}
示例#7
0
    /**
     * Get registered category for module property.
     *
     * @param string $modname   The module we wish to get the property for.
     * @param string $tablename The tablename for which we wish to get the property for.
     * @param string $property  The property name.
     * @param string $default   The default value to return if the requested value is not set (optional) (default=null).
     *
     * @return array The associative field array of registered categories for the specified module.
     */
    public static function getRegisteredModuleCategory($modname, $tablename, $property, $default = null)
    {
        if (!$modname || !$property) {
            return $default;
        }

        $fArr = self::getRegisteredModuleCategories($modname, $tablename);

        if ($fArr && isset($fArr[$property]) && $fArr[$property]) {
            return $fArr[$property];
        }

        // if we have a path default, we get the ID
        if ($default && !is_integer($default)) {
            $cat = CategoryUtil::getCategoryByPath($default);
            if ($cat) {
                $default = $cat['id'];
            }
        }

        return $default;
    }
示例#8
0
    /**
     * view items
     *
     * @author Mark West
     * @param $args['prop']             category property
     * @param $args['cat']              category id
     * @param $args['page']             starting number for paged view
     * @param $args['itemsperpage']     the number of items on a page
     * @param $args['page']             starting number for paged view
     * @param $args['displayonindex']   show only newsitems marked for display on the index page
     * @param $args['giventemplate']    Template file to use
     * @return string HTML string
     */
    public function view($args = array())
    {
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('News::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission());

        // clean the session preview data
        SessionUtil::delVar('newsitem');

        // get all module vars for later use
        $modvars = $this->getVars();

        // Get parameters from whatever input we need
        $prop = isset($args['prop']) ? $args['prop'] : (string)FormUtil::getPassedValue('prop', null, 'GET');
        $cat = isset($args['cat']) ? $args['cat'] : (string)FormUtil::getPassedValue('cat', null, 'GET');
        $page = isset($args['page']) ? $args['page'] : (int)FormUtil::getPassedValue('page', 1, 'GET');
        $displayModule = FormUtil::getPassedValue('module', 'X', 'GET');
        // storyhome nrofitems is only used when News is the homepage module
        $defaultItemsPerPage = ($displayModule == 'X') ? $modvars['storyhome'] : $modvars['itemsperpage'];
        $itemsperpage = isset($args['itemsperpage']) ? $args['itemsperpage'] : (int)FormUtil::getPassedValue('itemsperpage', $defaultItemsPerPage, 'GET');
        $displayonindex = isset($args['displayonindex']) ? (int)$args['displayonindex'] : FormUtil::getPassedValue('displayonindex', null, 'GET');
        $giventemplate = isset($args['giventemplate']) ? $args['giventemplate'] : 'view.tpl';

        // pages start at 1
        if ($page < 1) {
            LogUtil::registerError($this->__('Error! Invalid page passed.'));
        }

        // work out page size from page number
        $startnum = (($page - 1) * $itemsperpage) + 1;

        $lang = ZLanguage::getLanguageCode();

        // check if categorization is enabled
        if ($modvars['enablecategorization']) {
            // get the categories registered for News
            $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
            $properties = array_keys($catregistry);

            // validate the property
            // and build the category filter - mateo
            if (!empty($prop) && in_array($prop, $properties) && !empty($cat)) {
                if (!is_numeric($cat)) {
                    $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]);
                    $cat = CategoryUtil::getCategoryByPath($rootCat['path'] . '/' . $cat);
                } else {
                    $cat = CategoryUtil::getCategoryByID($cat);
                }
                $catname = isset($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'];

                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->__('Error! Invalid category passed.'));
                }
            }
        }

        // get matching news articles
        $items = ModUtil::apiFunc('News', 'user', 'getall', array('startnum' => $startnum,
                    'numitems' => $itemsperpage,
                    'status' => News_Api_User::STATUS_PUBLISHED,
                    'displayonindex' => $displayonindex,
                    'filterbydate' => true,
                    'category' => isset($catFilter) ? $catFilter : null, // get all method doesn't appear to want a category arg
                    'catregistry' => isset($catregistry) ? $catregistry : null));

        if ($items == false) {
            if ($modvars['enablecategorization'] && isset($catFilter)) {
                LogUtil::registerStatus($this->__f('No articles currently published under the \'%s\' category.', $catname));
            } else {
                LogUtil::registerStatus($this->__('No articles currently published.'));
            }
        }

        // assign various useful template variables
        $this->view->assign('startnum', $startnum);
        $this->view->assign('lang', $lang);

        // assign the root category
        $this->view->assign('category', $cat);
        $this->view->assign('catname', isset($catname) ? $catname : '');
        $this->view->assign('catimagepath', $this->getVar('catimagepath'));

        $accesslevel = ACCESS_READ;
        if (SecurityUtil::checkPermission('News::', "::", ACCESS_COMMENT)) $accesslevel = ACCESS_COMMENT;
        if (SecurityUtil::checkPermission('News::', "::", ACCESS_EDIT)) $accesslevel = ACCESS_EDIT;
        $accesslevel = '|a'.$accesslevel;

        $newsitems = array();
        // Loop through each item and display it
        foreach ($items as $item) {
            // display if it's published and the displayonindex match (if set)
            if (($item['published_status'] == 0) &&
                    (!isset($displayonindex) || $item['displayonindex'] == $displayonindex)) {

                $template = 'user/index.tpl';
                if (!$this->view->is_cached($template, $item['sid'])) {
                    // $info is array holding raw information.
                    // Used below and also passed to the theme - jgm
                    $info = ModUtil::apiFunc('News', 'user', 'getArticleInfo', $item);

                    // $links is an array holding pure URLs to
                    // specific functions for this article.
                    // Used below and also passed to the theme - jgm
                    $links = ModUtil::apiFunc('News', 'user', 'getArticleLinks', $info);

                    // $preformat is an array holding chunks of
                    // preformatted text for this article.
                    // Used below and also passed to the theme - jgm
                    $preformat = ModUtil::apiFunc('News', 'user', 'getArticlePreformat', array('info' => $info,
                                'links' => $links));

                    $this->view->assign(array(
                        'info' => $info,
                        'links' => $links,
                        'preformat' => $preformat));
                }

                $newsitems[] = $this->view->fetch($template, $item['sid'].$accesslevel);
            }
        }

        // The items that are displayed on this overview page depend on the individual
        // user permissions. Therefor, we can not cache the whole page.
        // The single entries are cached, though.
        $this->view->setCaching(false);

        // Display the entries
        $this->view->assign('newsitems', $newsitems);

        // Assign the values for the smarty plugin to produce a pager
        $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('News', 'user', 'countitems', array('status' => 0,
                'filterbydate' => true,
                'displayonindex' => $displayonindex,
                'category' => isset($catFilter) ? $catFilter : null)),
            'itemsperpage' => $itemsperpage));

        // Return the output that has been generated by this function
        return $this->view->fetch('user/'.$giventemplate);
    }
示例#9
0
    /**
     * create the Topics category tree
     */
    private function _createtopicscategory($regpath = '/__SYSTEM__/Modules/Topics')
    {
        // get the language file
        $lang = ZLanguage::getLanguageCode();

        // get the category path for which we're going to insert our place holder category
        $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');

        // create placeholder for all the migrated topics
        $tCat    = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Topics');

        if (!$tCat) {
            // create placeholder for all our migrated categories
            $cat = new Categories_DBObject_Category();
            $cat->setDataField('parent_id', $rootcat['id']);
            $cat->setDataField('name', 'Topics');
            // pnModLangLoad doesn't handle type 1 modules
            //pnModLangLoad('Topics', 'version');
            $cat->setDataField('display_name', array($lang => $this->__('Topics')));
            $cat->setDataField('display_desc', array($lang => $this->__('Display and manage topics')));
            if (!$cat->validate('admin')) {
                return false;
            }
            $cat->insert();
            $cat->update();
        }

        // get the category path for which we're going to insert our upgraded News categories
        $rootcat = CategoryUtil::getCategoryByPath($regpath);
        if ($rootcat) {
            // create an entry in the categories registry to the Topic property
            $registry = new Categories_DBObject_Registry();
            $registry->setDataField('modname', 'News');
            $registry->setDataField('table', 'stories');
            $registry->setDataField('property', 'Topic');
            $registry->setDataField('category_id', $rootcat['id']);
            $registry->insert();
        } else {
            return false;
        }

        return true;
    }
示例#10
0
 /**
  * migrate old local categories to the categories module
  */
 private function _migratecategories()
 {
     // get the language file
     $lang = ZLanguage::getLanguageCode();
     $catPath = '/__SYSTEM__/Modules/Quotes';
     // create root category and entry in the categories registry
     $this->_createdefaultcategory($catPath);
     // get the category path for which we're going to insert our upgraded categories
     $rootcat = CategoryUtil::getCategoryByPath($catPath);
     // create placeholder for all our migrated quotes
     $cat = new Categories_DBObject_Category();
     $cat->setDataField('parent_id', $rootcat['id']);
     $cat->setDataField('name', 'Imported');
     $cat->setDataField('display_name', array($lang => $this->__('Imported quotes')));
     $cat->setDataField('display_desc', array($lang => $this->__('Quotes imported from .7x version')));
     if (!$cat->validate('admin')) {
         return false;
     }
     $cat->insert();
     $cat->update();
     $catid = $cat->getDataField('id');
     unset($cat);
     // migrate page category assignments
     $prefix = System::getVar('prefix');
     $sql = "SELECT pn_qid FROM {$prefix}_quotes";
     $result = DBUtil::executeSQL($sql);
     $quotes = array();
     for (; !$result->EOF; $result->MoveNext()) {
         $quotes[] = array('qid' => $result->fields[0], '__CATEGORIES__' => array('Main' => $catid), '__META__' => array('module' => 'Quotes'));
     }
     foreach ($quotes as $quote) {
         if (!DBUtil::updateObject($quote, 'quotes', '', 'qid')) {
             return LogUtil::registerError($this->__('Error! Update attempt failed.'));
         }
     }
     return true;
 }
 /**
  * create the category tree
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException If Root category not found.
  * @throws \Exception
  *
  * @return boolean
  */
 private function createCategoryTree()
 {
     // create category
     \CategoryUtil::createCategory('/__SYSTEM__/Modules', $this->bundle->getName(), null, $this->__('Gallery'), $this->__('Gallery categories'));
     // create subcategory
     \CategoryUtil::createCategory('/__SYSTEM__/Modules/KaikmediaGalleryModule', 'Category1', null, $this->__('Category 1'), $this->__('Initial sub-category created on install'), array('color' => '#99ccff'));
     \CategoryUtil::createCategory('/__SYSTEM__/Modules/KaikmediaGalleryModule', 'Category2', null, $this->__('Category 2'), $this->__('Initial sub-category created on install'), array('color' => '#cceecc'));
     // get the category path to insert Pages categories
     $rootcat = \CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/KaikmediaGalleryModule');
     if ($rootcat) {
         // create an entry in the categories registry to the Main property
         if (!\CategoryRegistryUtil::insertEntry($this->bundle->getName(), 'AlbumEntity', 'Main', $rootcat['id'])) {
             throw new \Exception('Cannot insert Category Registry entry.');
         }
     } else {
         throw new NotFoundHttpException('Root category not found.');
     }
     return true;
 }
示例#12
0
    /**
     * 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');
    }
示例#13
0
 /**
  * Provide default categories.
  *
  * @return void
  */
 protected function defaultcategories()
 {
     if (!($cat = CategoryUtil::createCategory('/__SYSTEM__/Modules', 'ExampleDoctrine', null, $this->__('ExampleDoctrine'), $this->__('ExampleDoctrine categories')))) {
         return false;
     }
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/ExampleDoctrine');
     CategoryRegistryUtil::insertEntry('ExampleDoctrine', 'User', 'Main', $rootcat['id']);
     CategoryUtil::createCategory('/__SYSTEM__/Modules/ExampleDoctrine', 'category1', null, $this->__('Category 1'), $this->__('Category 1'));
 }
示例#14
0
    /**
     * create placeholder for categories
     */
    private function _feeds_createdefaultcategory($regpath = '/__SYSTEM__/Modules/Global')
    {
        // load necessary classes
        Loader::loadClass('CategoryUtil');
        Loader::loadClassFromModule('Categories', 'Category');
        Loader::loadClassFromModule('Categories', 'CategoryRegistry');

        // get the language code
        $lang = ZLanguage::getLanguageCode();
        $dom  = ZLanguage::getModuleDomain('Feeds');

        // get the category path for which we're going to insert our place holder category
        $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
        $fCat    = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Feeds');

        if (!$fCat) {
            // create placeholder for all the module categories
            $cat = new Categories_DBObject_Category();
            $cat->setDataField('parent_id', $rootcat['id']);
            $cat->setDataField('name', 'Feeds');
            $cat->setDataField('display_name', array($lang => __('Feeds', $dom)));
            $cat->setDataField('display_desc', array($lang => __('Feed Reader.', $dom)));
            if (!$cat->validate('admin')) {
                return false;
            }
            $cat->insert();
            $cat->update();
        }

        // get the category path for which the feeds will be classified
        $rootcat = CategoryUtil::getCategoryByPath($regpath);
        if ($rootcat) {
            // create an entry in the categories registry
            $registry = new Categories_DBObject_Registry();
            $registry->setDataField('modname', 'Feeds');
            $registry->setDataField('table', 'feeds');
            $registry->setDataField('property', 'Main');
            $registry->setDataField('category_id', $rootcat['id']);
            $registry->insert();
        } else {
            return false;
        }

        return true;
    }
示例#15
0
 function _addressbook_createdefaultcategory()
 {
     $dom = ZLanguage::getModuleDomain('AddressBook');
     // get the language file
     $lang = ZLanguage::getLanguageCode();
     // get the category path for which we're going to insert our place holder category
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
     $adrCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook');
     if (!$adrCat) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'AddressBook');
         $cat->setDataField('display_name', array($lang => $this->__('AddressBook')));
         $cat->setDataField('display_desc', array($lang => $this->__('Adress administration.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // create the first 2 categories
     $adrCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook');
     $adrCat1 = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook/Business');
     if (!$adrCat1) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $adrCat['id']);
         $cat->setDataField('name', 'Business');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Business')));
         $cat->setDataField('display_desc', array($lang => $this->__('Business')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     $adrCat2 = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/AddressBook/Personal');
     if (!$adrCat2) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $adrCat['id']);
         $cat->setDataField('name', 'Personal');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Personal')));
         $cat->setDataField('display_desc', array($lang => $this->__('Personal')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     if ($adrCat) {
         // place category registry entry for products (key == Products)
         $registry = new Categories_DBObject_Registry();
         $registry->setDataField('modname', 'AddressBook');
         $registry->setDataField('table', 'addressbook_address');
         $registry->setDataField('property', 'AddressBook');
         $registry->setDataField('category_id', $adrCat['id']);
         $registry->insert();
     }
     // now the old prefix field
     // get the category path for which we're going to insert our place holder form of address
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General');
     $foaCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address');
     if (!$foaCat) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'Form of address');
         $cat->setDataField('display_name', array($lang => $this->__('Form of address')));
         $cat->setDataField('display_desc', array($lang => $this->__('Form of address')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // create the first 2 categories
     $foaCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address');
     $foaCat1 = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address/Mr');
     if (!$foaCat1) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $foaCat['id']);
         $cat->setDataField('name', 'Mr');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Mr.')));
         $cat->setDataField('display_desc', array($lang => $this->__('Mr.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     $foaCat2 = CategoryUtil::getCategoryByPath('/__SYSTEM__/General/Form of address/Mrs');
     if (!$foaCat2) {
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $foaCat['id']);
         $cat->setDataField('name', 'Mrs');
         $cat->setDataField('is_leaf', 1);
         $cat->setDataField('display_name', array($lang => $this->__('Mrs.')));
         $cat->setDataField('display_desc', array($lang => $this->__('Mrs.')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     return true;
 }
/**
 * 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 .= "&nbsp;&nbsp;<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;
    }
}
示例#17
0
文件: User.php 项目: rmaiwald/Reviews
 /**
  * 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);
             */
 }
示例#18
0
    /**
     * edit categories for the currently logged in user
     */
    public function edituser()
    {
        if (!SecurityUtil::checkPermission('Categories::category', '::', ACCESS_EDIT)) {
            return LogUtil::registerPermissionError();
        }

        if (!UserUtil::isLoggedIn()) {
            return LogUtil::registerError($this->__('Error! Editing mode for user-owned categories is only available to users who have logged-in.'));
        }

        $allowUserEdit = $this->getVar('allowusercatedit', 0);
        if (!$allowUserEdit) {
            return LogUtil::registerError($this->__('Error! User-owned category editing has not been enabled. This feature can be enabled by the site administrator.'));
        }

        $userRoot = $this->getVar('userrootcat', 0);
        if (!$userRoot) {
            return LogUtil::registerError($this->__('Error! Could not determine the user root node.'));
        }

        $userRootCat = CategoryUtil::getCategoryByPath($userRoot);
        if (!$userRoot) {
            return LogUtil::registerError($this->__f('Error! The user root node seems to point towards an invalid category: %s.', $userRoot));
        }

        if ($userRootCat == 1) {
            return LogUtil::registerError($this->__("Error! The root directory cannot be modified in 'user' mode"));
        }

        $userCatName = $this->getusercategoryname();
        if (!$userCatName) {
            return LogUtil::registerError($this->__('Error! Cannot determine user category root node name.'));
        }

        $thisUserRootCatPath = $userRoot . '/' . $userCatName;
        $thisUserRootCat = CategoryUtil::getCategoryByPath($thisUserRootCatPath);

        $dr = null;
        if (!$thisUserRootCat) {
            $autoCreate = $this->getVar('autocreateusercat', 0);
            if (!$autoCreate) {
                return LogUtil::registerError($this->__("Error! The user root category node for this user does not exist, and the automatic creation flag (autocreate) has not been set."));
            }

            $installer = new Categories_Installer(ServiceUtil::getManager());
            $cat = array('id' => '',
                    'parent_id' => $userRootCat['id'],
                    'name' => $userCatName,
                    'display_name' => unserialize($installer->makeDisplayName($userCatName)),
                    'display_desc' => unserialize($installer->makeDisplayDesc()),
                    'security_domain' => 'Categories::',
                    'path' => $thisUserRootCatPath,
                    'status' => 'A');

            $obj = new Categories_DBObject_Category();
            $obj->setData($cat);
            $obj->insert();
            // since the original insert can't construct the ipath (since
            // the insert id is not known yet) we update the object here
            $obj->update();
            $dr = $obj->getID();

            $autoCreateDefaultUserCat = $this->getVar('autocreateuserdefaultcat', 0);
            if ($autoCreateDefaultUserCat) {
                $userdefaultcatname = $this->getVar('userdefaultcatname', $this->__('Default'));
                $cat = array('id' => '',
                        'parent_id' => $dr,
                        'name' => $userdefaultcatname,
                        'display_name' => unserialize($installer->makeDisplayName($userdefaultcatname)),
                        'display_desc' => unserialize($installer->makeDisplayDesc()),
                        'security_domain' => 'Categories::',
                        'path' => $thisUserRootCatPath . '/' . $userdefaultcatname,
                        'status' => 'A');
                $obj->setData($cat);
                $obj->insert();
                // since the original insert can't construct the ipath (since
                // the insert id is not known yet) we update the object here
                $obj->update();
            }
        } else {
            $dr = $thisUserRootCat['id'];
        }

        $url = ModUtil::url('Categories', 'user', 'edit', array('dr' => $dr));
        $this->redirect($url);
    }
示例#19
0
 private function _createdefaultcategory($regpath = '/__SYSTEM__/Modules/Global')
 {
     // get the language
     $lang = ZLanguage::getLanguageCode();
     // get the category path for which we're going to insert our place holder category
     $rootcat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules');
     $qCat = CategoryUtil::getCategoryByPath('/__SYSTEM__/Modules/Ephemerides');
     if (!$qCat) {
         // create placeholder for all our migrated categories
         $cat = new Categories_DBObject_Category();
         $cat->setDataField('parent_id', $rootcat['id']);
         $cat->setDataField('name', 'Ephemerides');
         $cat->setDataField('display_name', array($lang => $this->__('Ephemerides')));
         $cat->setDataField('display_desc', array($lang => $this->__('Ephemerides')));
         if (!$cat->validate('admin')) {
             return false;
         }
         $cat->insert();
         $cat->update();
     }
     // get the category path for which we're going to insert our upgraded categories
     $rootcat = CategoryUtil::getCategoryByPath($regpath);
     if ($rootcat) {
         // create an entry in the categories registry
         $registry = new Categories_DBObject_Registry();
         $registry->setDataField('modname', 'Ephemerides');
         $registry->setDataField('table', 'ephem');
         $registry->setDataField('property', 'Main');
         $registry->setDataField('category_id', $rootcat['id']);
         $registry->insert();
     } else {
         return false;
     }
     return true;
 }
示例#20
0
 /**
  * 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']);
     }
 }