예제 #1
0
    /**
     * Return a category object by ID
     *
     * @param string $rootPath    The path of the parent category.
     * @param string $name        The name of the category.
     * @param string $value       The value of the category (optional) (default=null).
     * @param string $displayname The displayname of the category (optional) (default=null, uses $name).
     * @param string $description The description of the category (optional) (default=null, uses $name).
     * @param string $attributes  The attributes array to bind to the category (optional) (default=null).
     *
     * @return The resulting folder object
     */
    public static function createCategory($rootPath, $name, $value=null, $displayname=null, $description=null, $attributes=null)
    {
        if (!isset($rootPath) || !$rootPath) {
            return LogUtil::registerError(__f("Error! Received invalid parameter '%s'", 'rootPath'));
        }
        if (!isset($name) || !$name) {
            return LogUtil::registerError(__f("Error! Received invalid parameter '%s'", 'name'));
        }

        if (!$displayname) {
            $displayname = $name;
        }
        if (!$description) {
            $description = $name;
        }

        $lang = ZLanguage::getLanguageCode();

        $rootCat = self::getCategoryByPath($rootPath);
        if (!$rootCat) {
            return LogUtil::registerError(__f("Error! Non-existing root category '%s' received", $rootPath));
        }

        $checkCat = self::getCategoryByPath("$rootPath/$name");
        if (!$checkCat) {
            $cat = new Categories_DBObject_Category();
            $data = array();
            $data['parent_id'] = $rootCat['id'];
            $data['name'] = $name;
            $data['display_name'] = array($lang => $displayname);
            $data['display_desc'] = array($lang => $description);
            if ($value) {
                $data['value'] = $value;
            }
            if ($attributes && is_array($attributes)) {
                $data['__ATTRIBUTES__'] = $attributes;
            }
            $cat->setData($data);
            if (!$cat->validate('admin')) {
                return false;
            }
            $cat->insert();
            $cat->update();
            return $cat->getDataField('id');
        }

        return false;
    }
예제 #2
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;
 }
예제 #3
0
    /**
     * create category
     */
    public function newcat()
    {
        $this->checkCsrfToken();

        if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
            return LogUtil::registerPermissionError();
        }

        $dr = (int)FormUtil::getPassedValue('dr', 0, 'POST');
        $url = System::serverGetVar('HTTP_REFERER');

        if (!$dr) {
            return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url);
        }

        $cat = new Categories_DBObject_Category ();
        $data = $cat->getDataFromInput();

        if (!$cat->validate()) {
            $this->redirect(ModUtil::url('Categories', 'user', 'edit', $_POST) . '#top');
        }

        $cat->insert();
        // since the original insert can't construct the ipath (since
        // the insert id is not known yet) we update the object here.
        $cat->update();

        $msg = $this->__f('Done! Inserted the %s category.', $data['name']);
        LogUtil::registerStatus($msg);
        $this->redirect($url);
    }
예제 #4
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;
 }
예제 #5
0
 public function save()
 {
     $this->checkAjaxToken();
     $mode = $this->request->getPost()->get('mode', 'new');
     $accessLevel = $mode == 'edit' ? ACCESS_EDIT : ACCESS_ADD;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', $accessLevel));
     $result = array();
     $cat = new Categories_DBObject_Category();
     $cat->getDataFromInput();
     if (!$cat->validate()) {
         $args = array('cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'mode' => $mode);
         return $this->edit($args);
     }
     $attributes = array();
     $values = $this->request->getPost()->get('attribute_value');
     foreach ($this->request->getPost()->get('attribute_name') as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     $cat->setDataField('__ATTRIBUTES__', $attributes);
     if ($mode == 'edit') {
         // retrieve old category from DB
         $category = $this->request->getPost()->get('category');
         $oldCat = new Categories_DBObject_Category(DBObject::GET_FROM_DB, $category['id']);
         // update new category data
         $cat->update();
         // since a name change will change the object path, we must rebuild it here
         if ($oldCat->getDataField('name') != $cat->getDataField('name')) {
             CategoryUtil::rebuildPaths('path', 'name', $cat->getDataField('id'));
         }
     } else {
         $cat->insert();
         // update new category data
         $cat->update();
     }
     $categories = CategoryUtil::getSubCategories($cat->getDataField('id'), true, true, true, true, true);
     $options = array('nullParent' => $cat->getDataField('parent_id'), 'withWraper' => false);
     $node = CategoryUtil::getCategoryTreeJS((array) $categories, true, true, $options);
     $leafStatus = array('leaf' => array(), 'noleaf' => array());
     foreach ($categories as $c) {
         if ($c['is_leaf']) {
             $leafStatus['leaf'][] = $c['id'];
         } else {
             $leafStatus['noleaf'][] = $c['id'];
         }
     }
     $result = array('action' => $mode == 'edit' ? 'edit' : 'add', 'cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'node' => $node, 'leafstatus' => $leafStatus, 'result' => true);
     return new Zikula_Response_Ajax($result);
 }
예제 #6
0
 /**
  * create category
  */
 public function newcat()
 {
     $this->checkCsrfToken();
     if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_ADD)) {
         return LogUtil::registerPermissionError();
     }
     $cat = new Categories_DBObject_Category();
     $cat->getDataFromInput();
     // submit button wasn't pressed -> category was chosen from dropdown
     // we now get the parent (security) category domains so we can inherit them
     if (!FormUtil::getPassedValue('category_submit', null, 'POST')) {
         $newCat = $_POST['category'];
         $pcID = $newCat['parent_id'];
         $pCat = new Categories_DBObject_Category();
         $parentCat = $pCat->get($pcID);
         //$newCat['security_domain'] = $parentCat['security_domain'];
         //for ($i=1; $i<=5; $i++) {
         //    $name = 'data' . $i . '_domain';
         //    $newCat[$name] = $parentCat[$name];
         //}
         $_SESSION['newCategory'] = $newCat;
         return System::redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     if (!$cat->validate('admin')) {
         return System::redirect(ModUtil::url('Categories', 'admin', 'newcat') . '#top');
     }
     $attributes = array();
     $values = FormUtil::getPassedValue('attribute_value', array(), 'POST');
     foreach (FormUtil::getPassedValue('attribute_name', array(), 'POST') as $index => $name) {
         if (!empty($name)) {
             $attributes[$name] = $values[$index];
         }
     }
     if ($attributes) {
         $cat->setDataField('__ATTRIBUTES__', $attributes);
     }
     $cat->insert();
     // since the original insert can't construct the ipath (since
     // the insert id is not known yet) we update the object here.
     $cat->update();
     $msg = __f('Done! Inserted the %s category.', $cat->_objData['name']);
     LogUtil::registerStatus($msg);
     $this->redirect(ModUtil::url('Categories', 'admin', 'view') . '#top');
 }
예제 #7
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;
    }
예제 #8
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;
 }
예제 #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;
    }