Exemple #1
0
 /**
  * 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');
 }
Exemple #2
0
 /**
  * get all categories for a user
  *
  */
 public function getusercategories($args)
 {
     $args['returnCategory'] = 1;
     $userRootCat = $this->getuserrootcat($args);
     if (!$userRootCat) {
         return LogUtil::registerError($this->__f('Error! The user root node seems to point towards an invalid category: %s.', $userRoot));
     }
     $relative = isset($args['relative']) ? $args['relative'] : false;
     return CategoryUtil::getCategoriesByParentID($userRootCat['id'], '', $relative);
 }
Exemple #3
0
    /**
     * 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');
    }
Exemple #4
0
 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');
 }
Exemple #5
0
 public function validatePostProcess($type = 'user', $data = null)
 {
     if (!$data) {
         $data = $this->_objData;
     }
     if (!$data) {
         return false;
     }
     // ensure that the name we want to use doesn't exist already on this level
     $name = $data['name'];
     $cats = CategoryUtil::getCategoriesByParentID($data['parent_id'], '', false, '', 'name');
     if (isset($cats[$name]) && $cats[$name] && $cats[$name]['id'] != (isset($data['id']) ? $data['id'] : null)) {
         $_SESSION['validationErrors'][$this->_objPath]['name'] = __f('Category %s must be unique under parent', $name);
         $_SESSION['validationFailedObjects'][$this->_objPath] = $data;
         return false;
     }
     return true;
 }
Exemple #6
0
    /**
     * Internal function to count categories including subcategories
     *
     * @author Erik Spaan [espaan]
     * @return array
     */
    private function _countcategories($category, $property, $catregistry, $uid)
    {
        // Get the number of articles in this category within this category property
        $news_articlecount = ModUtil::apiFunc('News', 'user', 'countitems', array('status' => 0,
                    'filterbydate' => true,
                    'category' => array($property => $category['id']),
                    'catregistry' => $catregistry));

        $news_totalarticlecount = $news_articlecount;

        // Get the number of articles by the current uid in this category within this category property
        if ($uid > 0) {
            $news_yourarticlecount = ModUtil::apiFunc('News', 'user', 'countitems', array('status' => 0,
                        'filterbydate' => true,
                        'uid' => $uid,
                        'category' => array($property => $category['id']),
                        'catregistry' => $catregistry));
        } else {
            $news_yourarticlecount = 0;
        }

        // Check if this category is a leaf/endnode
        $subcats = CategoryUtil::getCategoriesByParentID($category['id']);
        if (!$category['is_leaf'] && !empty($subcats)) {
            $subcategories = array();
            foreach ($subcats as $cat) {
                $count = $this->_countcategories($cat, $property, $catregistry, $uid);
                // Add the subcategories count to this category
                $news_totalarticlecount += $count['category']['news_totalarticlecount'];
                $news_yourarticlecount += $count['category']['news_yourarticlecount'];
                $subcategories[] = $count;
            }
        } else {
            $subcategories = null;
        }

        $category['news_articlecount'] = $news_articlecount;
        $category['news_totalarticlecount'] = $news_totalarticlecount;
        $category['news_yourarticlecount'] = $news_yourarticlecount;
        // if a category image is available, store it for easy reuse
        if (isset($category['__ATTRIBUTES__']) && isset($category['__ATTRIBUTES__']['topic_image'])) {
            $category['catimage'] = $category['__ATTRIBUTES__']['topic_image'];
        }

        $return = array('category' => $category,
            'subcategories' => $subcategories);

        return $return;
    }
Exemple #7
0
    /**
     * Load the intial data into the object
     */
    public function getDefaultData()
    {
        $defaultdata = array(
            'title' => '',
            'categories' => null,
            'status' => 0,
            'show' => 1,
            'limit' => 5,
            'orderoptions' => 0,
            'dayslimit' => 0,
            'maxtitlelength' => 0,
            'titlewraptext' => '...',
            'disphometext' => false,
            'maxhometextlength' => 300,
            'hometextwraptext' => '[' . $this->__('Read more...') . ']',
            'dispuname' => true,
            'dispdate' => true,
            'dateformat' => '%x',
            'dispreads' => false,
            'dispcomments' => false,
            'dispsplitchar' => ',',
            'dispnewimage' => false,
            'newimagelimit' => 3,
            'newimageset' => 'icons/extrasmall',
            'newimagesrc' => 'favorites.png',
            'linktosubmit' => true,
            'customtemplate' => '',
            'displayStoryImage' => false);
        
        // Get the registered categories for the News module
        $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'news');
        $properties = array_keys($catregistry);

        // set a default category based on page category
        foreach ($properties as $prop) {
            $subcats_fulldata = CategoryUtil::getCategoriesByParentID($catregistry[$prop]);
            $subcats = array();
            foreach ($subcats_fulldata as $subcat_fulldata) {
                $subcats[] = $subcat_fulldata['id'];
            }
            if (in_array($this->getPageCategoryId(), $subcats)) {
                // this awkward array format iswhat $this->loadData() interprets to set category
                $defaultdata['category__' . $prop] = $this->getPageCategoryId();
            }
        }

        return $defaultdata;
    }
Exemple #8
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');
    }
Exemple #9
0
    /**
     * 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', 'categories', '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);
            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;
    }