Esempio n. 1
0
 function testSkipPermissionChecks()
 {
     $perms = new Perms();
     $perms->setResolverFactories(array(new Perms_ResolverFactory_StaticFactory('root', new Perms_Resolver_Default(false))));
     Perms::set($perms);
     $manip = new Category_Manipulator('wiki page', 'Hello World');
     $manip->overrideChecks();
     $manip->setCurrentCategories(array(1, 2, 3, 7));
     $manip->setUnmanagedCategories(range(1, 5));
     $manip->setNewCategories(array(1, 2, 4, 6));
     $this->assertEquals(array(6), $manip->getAddedCategories());
     $this->assertEquals(array(7), $manip->getRemovedCategories());
 }
Esempio n. 2
0
 function update_object_categories($categories, $objId, $objType, $desc = NULL, $name = NULL, $href = NULL, $managedCategories = null, $override_perms = false)
 {
     global $prefs, $user;
     $userlib = TikiLib::lib('user');
     if (empty($categories)) {
         $forcedcat = $userlib->get_user_group_default_category($user);
         if (!empty($forcedcat)) {
             $categories[] = $forcedcat;
         }
     }
     $manip = new Category_Manipulator($objType, $objId);
     if ($override_perms) {
         $manip->overrideChecks();
     }
     $manip->setNewCategories($categories ? $categories : array());
     if (is_array($managedCategories) && !$override_perms) {
         $manip->setManagedCategories($managedCategories);
     }
     if ($prefs['category_defaults']) {
         foreach ($prefs['category_defaults'] as $constraint) {
             $manip->addRequiredSet($this->extentCategories($constraint['categories']), $constraint['default'], $constraint['filter'], $constraint['type']);
         }
     }
     $this->applyManipulator($manip, $objType, $objId, $desc, $name, $href);
     if ($prefs['category_i18n_sync'] != 'n' && $prefs['feature_multilingual'] == 'y') {
         $multilinguallib = TikiLib::lib('multilingual');
         $targetCategories = $this->get_object_categories($objType, $objId, -1, false);
         if ($objType == 'wiki page') {
             $translations = $multilinguallib->getTranslations($objType, $this->get_page_id_from_name($objId), $objId);
             $objectIdKey = 'objName';
         } else {
             if (in_array($objType, array('article'))) {
                 // only try on supported types
                 $translations = $multilinguallib->getTranslations($objType, $objId);
                 $objectIdKey = 'objId';
             } else {
                 $translations = array();
                 $objectIdKey = 'objId';
             }
         }
         $subset = $prefs['category_i18n_synced'];
         if (is_string($subset)) {
             $subset = unserialize($subset);
         }
         foreach ($translations as $tr) {
             if (!empty($tr[$objectIdKey]) && $tr[$objectIdKey] != $objId) {
                 $manip = new Category_Manipulator($objType, $tr[$objectIdKey]);
                 $manip->setNewCategories($targetCategories);
                 $manip->overrideChecks();
                 if ($prefs['category_i18n_sync'] == 'whitelist') {
                     $manip->setManagedCategories($subset);
                 } elseif ($prefs['category_i18n_sync'] == 'blacklist') {
                     $manip->setUnmanagedCategories($subset);
                 }
                 $this->applyManipulator($manip, $objType, $tr[$objectIdKey]);
             }
         }
     }
     $added = $manip->getAddedCategories();
     $removed = $manip->getRemovedCategories();
     TikiLib::events()->trigger('tiki.object.categorized', array('object' => $objId, 'type' => $objType, 'added' => $added, 'removed' => $removed));
     $this->notify_add($added, $name, $objType, $href);
     $this->notify_remove($removed, $name, $objType, $href);
 }
Esempio n. 3
0
 function update_object_categories($categories, $objId, $objType, $desc = NULL, $name = NULL, $href = NULL, $managedCategories = null, $override_perms = false)
 {
     global $prefs, $user, $userlib;
     if (empty($categories)) {
         $forcedcat = $userlib->get_user_group_default_category($user);
         if (!empty($forcedcat)) {
             $categories[] = $forcedcat;
         }
     }
     require_once 'lib/core/Category/Manipulator.php';
     $manip = new Category_Manipulator($objType, $objId);
     if ($override_perms) {
         $manip->overrideChecks();
     }
     $manip->setNewCategories($categories ? $categories : array());
     if (is_array($managedCategories)) {
         $manip->setManagedCategories($managedCategories);
     }
     if ($prefs['category_defaults']) {
         foreach ($prefs['category_defaults'] as $constraint) {
             $manip->addRequiredSet($this->extentCategories($constraint['categories']), $constraint['default'], $constraint['filter'], $constraint['type']);
         }
     }
     $this->applyManipulator($manip, $objType, $objId, $desc, $name, $href);
     if ($prefs['category_i18n_sync'] != 'n' && $prefs['feature_multilingual'] == 'y') {
         global $multilinguallib;
         require_once 'lib/multilingual/multilinguallib.php';
         $targetCategories = $this->get_object_categories($objType, $objId, -1, false);
         if ($objType == 'wiki page') {
             $translations = $multilinguallib->getTranslations($objType, $this->get_page_id_from_name($objId), $objId);
             $objectIdKey = 'objName';
         } else {
             $translations = $multilinguallib->getTranslations($objType, $objId);
             $objectIdKey = 'objId';
         }
         $subset = $prefs['category_i18n_synced'];
         if (is_string($subset)) {
             $subset = unserialize($subset);
         }
         foreach ($translations as $tr) {
             if (!empty($tr[$objectIdKey]) && $tr[$objectIdKey] != $objId) {
                 $manip = new Category_Manipulator($objType, $tr[$objectIdKey]);
                 $manip->setNewCategories($targetCategories);
                 $manip->overrideChecks();
                 if ($prefs['category_i18n_sync'] == 'whitelist') {
                     $manip->setManagedCategories($subset);
                 } elseif ($prefs['category_i18n_sync'] == 'blacklist') {
                     $manip->setUnmanagedCategories($subset);
                 }
                 $this->applyManipulator($manip, $objType, $tr[$objectIdKey]);
             }
         }
     }
     $this->notify_add($manip->getAddedCategories(), $name, $objType, $href);
     $this->notify_remove($manip->getRemovedCategories(), $name, $objType, $href);
 }