Beispiel #1
0
function process_page(ElggObject $page)
{
    $tags_to_groups = array('ib' => 10113262, 'inkomstenbelasting' => 10113262, 'ob' => 12967492, 'btw' => 12967492, 'omzetbelasting' => 12967492, 'lh' => 10112672, 'loonheffingen' => 10112672, 'open forum' => 7746192, 'toeslagen' => 7746232, 'Toeslagen' => 7746232, 'vennootschapsbelasting' => 7746292);
    $container_guid = false;
    if (!$page->tags) {
        return;
    }
    if (!is_array($page->tags)) {
        $tags = array($page->tags);
    } else {
        $tags = $page->tags;
    }
    foreach ($tags_to_groups as $tag => $group_guid) {
        if (in_array($tag, $tags)) {
            $container_guid = $group_guid;
            continue;
        }
    }
    $news = new ElggObject();
    $news->subtype = "news";
    $news->title = $page->title;
    $news->description = $page->description;
    $news->tags = $page->tags;
    $news->owner_guid = $page->owner_guid;
    $news->container_guid = $container_guid;
    $news->access_id = get_default_access();
    $news->save();
    $news->time_created = $page->time_created;
    $news->time_updated = $page->time_updated;
    $news->save();
}
Beispiel #2
0
 /**
  * Called before each test method.
  */
 public function setUp()
 {
     $this->ignoreAccess = elgg_set_ignore_access(false);
     $this->cache = elgg_get_metadata_cache();
     $this->obj1 = new ElggObject();
     $this->obj1->save();
     $this->guid1 = $this->obj1->guid;
     $this->obj2 = new ElggObject();
     $this->obj2->save();
     $this->guid2 = $this->obj2->guid;
 }
 /**
  * Called before each test method.
  */
 public function setUp()
 {
     $this->ignoreAccess = elgg_set_ignore_access(false);
     $this->cache = _elgg_services()->metadataCache;
     $this->obj1 = new \ElggObject();
     $this->obj1->save();
     $this->guid1 = $this->obj1->guid;
     $this->obj2 = new \ElggObject();
     $this->obj2->save();
     $this->guid2 = $this->obj2->guid;
 }
Beispiel #4
0
 public function testCommentAccessSync()
 {
     _elgg_disable_caching_for_entity($this->comment->guid);
     _elgg_disable_caching_for_entity($this->container->guid);
     $this->assertEqual($this->comment->access_id, $this->container->access_id);
     // now change the access of the container
     $this->container->access_id = ACCESS_LOGGED_IN;
     $this->container->save();
     $updated_container = get_entity($this->container->guid);
     $updated_comment = get_entity($this->comment->guid);
     $this->assertEqual($updated_comment->access_id, $updated_container->access_id);
 }
Beispiel #5
0
function spam_login_filter_verify_action_hook($hook, $entity_type, $returnvalue, $params)
{
    //Check against stopforumspam and domain blacklist
    $email = get_input('email');
    $ip = spam_login_filter_get_ip();
    if (spam_login_filter_check_spammer($email, $ip)) {
        return true;
    } else {
        //Check if the ip exists
        $options = array("type" => "object", "subtype" => "spam_login_filter_ip", "metadata_name_value_pairs" => array("name" => "ip_address", "value" => $ip), "count" => TRUE);
        $ia = elgg_set_ignore_access(true);
        $spam_login_filter_ip_list = elgg_get_entities_from_metadata($options);
        if ($spam_login_filter_ip_list == 0) {
            //Create the banned ip
            $ip_obj = new ElggObject();
            $ip_obj->subtype = 'spam_login_filter_ip';
            $ip_obj->access_id = ACCESS_PRIVATE;
            $ip_obj->ip_address = $ip;
            $ip_obj->owner_guid = elgg_get_site_entity()->guid;
            $ip_obj->container_guid = elgg_get_site_entity()->guid;
            $ip_obj->save();
        }
        elgg_set_ignore_access($ia);
        //return false;
        forward();
    }
}
/**
 * Flag suspicious messages
 *
 * @param string     $event  "create"
 * @param string     $type   "object"
 * @param ElggObject $entity Message
 * @return void
 */
function hypeapps_inbox_monitor_flag_suspicious_messages($event, $type, $entity)
{
    if ($entity->getSubtype() != 'messages') {
        return;
    }
    $policy = elgg_get_plugin_setting('policy', 'hypeInboxMonitor', 'nothing');
    $blacklist = hypeapps_inbox_monitor_get_blacklist();
    $options = array('also_check' => $blacklist);
    $filter = new \JCrowe\BadWordFilter\BadWordFilter($options);
    $badWords = $filter->getDirtyWordsFromString("{$entity->title} {$entity->description}");
    $entity->badwords = $badWords;
    switch ($policy) {
        case 'mask':
            $entity->title = $filter->clean($entity->title);
            $entity->description = $filter->clean($entity->title);
            break;
        case 'silence':
            $replacement = '<span rel="bwsilent">$0</span>';
            $entity->title = $filter->clean($entity->title, $replacement);
            $entity->description = $filter->clean($entity->description, $replacement);
            break;
        case 'remove':
            $replacement = '<span rel="bwremoved">[' . elgg_echo('inbox:monitor:removed') . ']</span>';
            $entity->title = $filter->clean($entity->title, $replacement);
            $entity->description = $filter->clean($entity->description, $replacement);
            break;
    }
    $entity->save();
}
Beispiel #7
0
function current_dokuwiki_entity($create = true)
{
    $page_owner = elgg_get_page_owner_guid();
    $user = elgg_get_logged_in_user_entity();
    //error_log($page_owner->guid);
    //error_log($user->guid);
    if (!$page_owner) {
        $page_owner = 0;
    }
    $entities = elgg_get_entities(array('types' => 'object', 'subtypes' => 'dokuwiki', 'limit' => 1, 'owner_guid' => $page_owner));
    if ($entities) {
        $doku = $entities[0];
        return $doku;
    } elseif ($user && $create) {
        elgg_set_ignore_access(true);
        $newdoku = new ElggObject();
        $newdoku->access_id = ACCESS_PUBLIC;
        $newdoku->owner_guid = $page_owner;
        $newdoku->subtype = 'dokuwiki';
        $newdoku->container_guid = $page_owner;
        $newdoku->save();
        $acl = array();
        $acl[] = "# acl.auth.php";
        $acl[] = '# <?php exit()?\\>';
        $acl[] = "*               @ALL        0";
        $acl[] = "*               @user        1";
        $acl[] = "*               @member        8";
        $acl[] = "*               @admin        16";
        $acl[] = "*               @root        255";
        $newdoku->wiki_acl = implode("\n", $acl) . "\n";
        elgg_set_ignore_access(false);
        return $newdoku;
    }
}
Beispiel #8
0
function app2_blog_save($title, $text, $excerpt, $tags, $access, $container_guid)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->container_guid = $container_guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
    if ($guid) {
        return true;
    } else {
        return false;
    }
}
Beispiel #9
0
 function save()
 {
     $guid = parent::save();
     try {
         $sessionID = $this->startSession();
         $groupID = $this->groupID;
         // Create a pad if not exists
         if (!$this->pname) {
             $name = uniqid();
             $this->get_pad_client()->createGroupPad($groupID, $name, elgg_get_plugin_setting('new_pad_text', 'etherpad'));
             $this->setMetaData('pname', $groupID . "\$" . $name);
         }
         $padID = $this->getMetadata('pname');
         //set etherpad permissions
         if ($this->access_id == ACCESS_PUBLIC) {
             $this->get_pad_client()->setPublicStatus($padID, "true");
         } else {
             $this->get_pad_client()->setPublicStatus($padID, "false");
         }
         $this->get_pad_client()->deleteSession($sessionID);
     } catch (Exception $e) {
         register_error($e->getMessage());
         return false;
     }
     return $guid;
 }
Beispiel #10
0
 /**
  * @group current
  */
 public function testCanSaveNewObject()
 {
     $subtype = 'test_subtype';
     $subtype_id = add_subtype('object', $subtype);
     $user = $this->mocks()->getUser();
     _elgg_services()->session->setLoggedInUser($user);
     $object = new \ElggObject();
     $object->subtype = $subtype;
     $object->title = 'Foo';
     $object->description = 'Bar';
     $object->owner_guid = $user->guid;
     $object->container_guid = $user->guid;
     $object->access_id = ACCESS_LOGGED_IN;
     $object->time_created = time();
     $object->setCurrentTime();
     // We should be able to match timestamps
     $now = $object->getCurrentTime()->getTimestamp();
     $guid = $object->save();
     $this->assertNotFalse($guid);
     $object = get_entity($guid);
     $this->assertEquals('object', $object->type);
     $this->assertEquals($subtype_id, $object->subtype);
     $this->assertEquals('Foo', $object->title);
     $this->assertEquals('Foo', $object->getDisplayName());
     $this->assertEquals('Bar', $object->description);
     $this->assertEquals($user->guid, $object->getOwnerGUID());
     $this->assertEquals($user, $object->getOwnerEntity());
     $this->assertEquals($user->guid, $object->getContainerGUID());
     $this->assertEquals($user, $object->getContainerEntity());
     $this->assertEquals(ACCESS_LOGGED_IN, $object->access_id);
     _elgg_services()->session->removeLoggedInUser();
 }
Beispiel #11
0
/**
 * Clones the custom layout of a parent group, for a newly created subgroup
 * @param type $group
 * @param type $parent
 */
function au_subgroups_clone_layout($group, $parent)
{
    if (!elgg_is_active_plugin('group_custom_layout') || !group_custom_layout_allow($parent)) {
        return false;
    }
    // get the layout object for the parent
    if ($parent->countEntitiesFromRelationship(GROUP_CUSTOM_LAYOUT_RELATION) <= 0) {
        return false;
    }
    $parentlayout = $parent->getEntitiesFromRelationship(GROUP_CUSTOM_LAYOUT_RELATION);
    $parentlayout = $parentlayout[0];
    $layout = new ElggObject();
    $layout->subtype = GROUP_CUSTOM_LAYOUT_SUBTYPE;
    $layout->owner_guid = $group->getGUID();
    $layout->container_guid = $group->getGUID();
    $layout->access_id = ACCESS_PUBLIC;
    $layout->save();
    // background image
    $layout->enable_background = $parentlayout->enable_background;
    $parentimg = elgg_get_config('dataroot') . 'group_custom_layout/backgrounds/' . $parent->getGUID() . '.jpg';
    $groupimg = elgg_get_config('dataroot') . 'group_custom_layout/backgrounds/' . $group->getGUID() . '.jpg';
    if (file_exists($parentimg)) {
        copy($parentimg, $groupimg);
    }
    $layout->enable_colors = $parentlayout->enable_colors;
    $layout->background_color = $parentlayout->background_color;
    $layout->border_color = $parentlayout->border_color;
    $layout->title_color = $parentlayout->title_color;
    $group->addRelationship($layout->getGUID(), GROUP_CUSTOM_LAYOUT_RELATION);
}
 /**
  * Update container entity last action on successful save.
  *
  * @param bool $update_last_action Update the container entity's last_action field
  * @return bool|int
  */
 public function save($update_last_action = true)
 {
     $result = parent::save();
     if ($result && $update_last_action) {
         update_entity_last_action($this->container_guid, $this->time_updated);
     }
     return $result;
 }
 /**
  * Save the subscription to the database
  *
  * @return bool
  *
  * @see ElggObject::save()
  */
 public function save()
 {
     // ignore access restrictions
     $ia = elgg_set_ignore_access(true);
     $result = parent::save();
     // restore access
     elgg_set_ignore_access($ia);
     return $result;
 }
Beispiel #14
0
 function save()
 {
     if (!$this->guid) {
         $this->attributes["owner_guid"] = elgg_get_logged_in_user_guid();
         $this->attributes["container_guid"] = elgg_get_logged_in_user_guid();
         $this->attributes["access_id"] = ACCESS_PRIVATE;
     }
     return parent::save();
 }
function save_question($title, $body)
{
    $question = new ElggObject();
    $question->subtype = "question";
    $question->access_id = ACCESS_PUBLIC;
    $question->title = $title;
    $question->description = $body;
    $question->save();
    return $question;
}
Beispiel #16
0
/**
 * Condense annotation into object
 *
 * @param ElggObject $topic
 */
function groups_2011030101($topic)
{
    $annotation = $topic->getAnnotations('group_topic_post', 1);
    if (!$annotation) {
        // no text for this forum post so we delete (probably caused by #2624)
        return $topic->delete();
    }
    $topic->description = $annotation[0]->value;
    $topic->save();
    return $annotation[0]->delete();
}
Beispiel #17
0
 /**
  * Update container entity last action on successful save.
  *
  * @param bool $update_last_action Update the container entity's last_action field
  * @return bool|int
  */
 public function save($update_last_action = true)
 {
     $result = parent::save();
     if ($result && $update_last_action) {
         $container = $this->getContainerEntity();
         if ($container) {
             $container->updateLastAction($this->time_updated);
         }
     }
     return $result;
 }
Beispiel #18
0
 /**
  * Create the entities used for each test
  */
 protected function setUp()
 {
     $this->markTestSkipped("Skipped test as Elgg can not yet run PHP Unit tests that interact with the database");
     $this->guids = array();
     $obj1 = new \ElggObject();
     $obj1->save();
     $this->guids[] = $obj1->guid;
     $obj2 = new \ElggObject();
     $obj2->save();
     $this->guids[] = $obj2->guid;
 }
function elgg_modifications_generate_digischool_menu_page_handler($page)
{
    admin_gatekeeper();
    if (elgg_is_active_plugin("menu_builder")) {
        // remove current menu items
        $current_options = array("type" => "object", "subtype" => "menu_builder_menu_item", "limit" => false);
        if ($current_items = elgg_get_entities($current_options)) {
            foreach ($current_items as $current_item) {
                $current_item->delete();
            }
        }
        // 			var_dump($current_items);
        // 			exit();
        // add the new ones
        $site = elgg_get_site_entity();
        $site_acl = $site->getACL();
        $menu_items = array(array("title" => "Voorpagina", "url" => "[wwwroot]", "access_id" => ACCESS_PUBLIC, "children" => array(array("title" => "Alle blogs", "url" => "[wwwroot]blog/all", "access_id" => ACCESS_PUBLIC), array("title" => "Alle activiteiten", "url" => "[wwwroot]activity", "access_id" => ACCESS_LOGGED_IN))), array("title" => "Statische pagina's", "url" => "[wwwroot]lidworden", "access_id" => ACCESS_LOGGED_IN), array("title" => "Archief", "url" => "Zelf in te vullen", "access_id" => ACCESS_PUBLIC), array("title" => "Leermiddelen", "url" => "#", "access_id" => ACCESS_PUBLIC, "children" => array(array("title" => "Vakpagina", "url" => "hier de link naar uw vakp", "access_id" => ACCESS_PUBLIC), array("title" => "Leermiddelenbank Digischool", "url" => "[wwwroot]", "access_id" => ACCESS_PUBLIC), array("title" => "Leden keurmerkgroepen", "url" => "zelf te vullen", "access_id" => ACCESS_PUBLIC))), array("title" => "Leden", "url" => "#", "access_id" => ACCESS_LOGGED_IN, "children" => array(array("title" => "Mijn groepen", "url" => "[wwwroot]groups/member/[username]", "access_id" => $site_acl), array("title" => "Mijn profielpagina", "url" => "[wwwroot]profile/[username]", "access_id" => $site_acl), array("title" => "Alle groepen", "url" => "[wwwroot]groups/all/?filter=pop", "access_id" => $site_acl), array("title" => "Lid worden", "url" => "[wwwroot]lidworden", "access_id" => ACCESS_PUBLIC), array("title" => "Content toevoegen", "url" => "[wwwroot]add", "access_id" => $site_acl), array("title" => "Mijn dashboard", "url" => "[wwwroot]dashboard", "access_id" => $site_acl), array("title" => "Zoeken leden", "url" => "[wwwroot]members", "access_id" => $site_acl), array("title" => "Mijn contacten", "url" => "[wwwroot]friends/[username]", "access_id" => $site_acl), array("title" => "Contactverzoeken", "url" => "[wwwroot]friend_request/", "access_id" => $site_acl), array("title" => "Mijn instellingen", "url" => "[wwwroot]settings", "access_id" => $site_acl), array("title" => "Nieuwe groep maken", "url" => "[wwwroot]groups/add", "access_id" => $site_acl))), array("title" => "Beheer", "url" => "[wwwroot]admin", "access_id" => ACCESS_PRIVATE, "children" => array(array("title" => "Gebruikersbeheer", "url" => "[wwwroot]admin/users/newest", "access_id" => ACCESS_PRIVATE), array("title" => "Nodig leden uit", "url" => "[wwwroot]admin/users/invite", "access_id" => ACCESS_PRIVATE), array("title" => "Pluginbeheer", "url" => "[wwwroot]admin/plugins", "access_id" => ACCESS_PRIVATE), array("title" => "Beheer template", "url" => "[wwwroot]admin/appearance/template", "access_id" => ACCESS_PRIVATE))));
        $i = 0;
        foreach ($menu_items as $main_item) {
            $item = new ElggObject();
            $item->subtype = "menu_builder_menu_item";
            $item->owner_guid = $site->getGUID();
            $item->container_guid = $site->getGUID();
            $item->site_guid = $site->getGUID();
            $item->access_id = $main_item["access_id"];
            $item->parent_guid = 0;
            $item->title = $main_item["title"];
            $item->url = $main_item["url"];
            $item->order = $i;
            $i++;
            $item->save();
            if (array_key_exists("children", $main_item)) {
                foreach ($main_item["children"] as $sub_item) {
                    $submenu_item = new ElggObject();
                    $submenu_item->subtype = "menu_builder_menu_item";
                    $submenu_item->owner_guid = $site->getGUID();
                    $submenu_item->container_guid = $site->getGUID();
                    $submenu_item->site_guid = $site->getGUID();
                    $submenu_item->access_id = $sub_item["access_id"];
                    $submenu_item->parent_guid = $item->getGUID();
                    $submenu_item->title = $sub_item["title"];
                    $submenu_item->url = $sub_item["url"];
                    $submenu_item->order = $i;
                    $i++;
                    $submenu_item->save();
                }
            }
        }
        system_message("menu created");
    } else {
        register_error("plugin menu_builder not activated");
    }
    forward();
}
Beispiel #20
0
function hypefaker_add_page($owner, $container, $parent = null)
{
    $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
    $faker = Factory::create($locale);
    $access_array = get_write_access_array($owner->guid);
    $access_id = array_rand($access_array, 1);
    $write_access_array = get_write_access_array($owner->guid);
    unset($write_access_array[ACCESS_PUBLIC]);
    $write_access_id = array_rand($write_access_array, 1);
    $page = new ElggObject();
    $page->subtype = $parent ? 'page' : 'page_top';
    $page->owner_guid = $owner->guid;
    $page->container_guid = $container->guid;
    $page->title = $faker->sentence(6);
    $page->description = $faker->text(500);
    $page->tags = $faker->words(5);
    $page->access_id = $access_id;
    $page->write_access_id = $write_access_id;
    $page->__faker = true;
    if ($parent) {
        $page->parent_guid = $parent->guid;
    }
    if ($page->save()) {
        $page->annotate('page', $page->description, $page->access_id, $page->owner_guid);
        elgg_create_river_item(array('view' => 'river/object/page/create', 'action_type' => 'create', 'subject_guid' => $page->owner_guid, 'object_guid' => $page->getGUID()));
        // add some revisions
        $users = elgg_get_entities_from_metadata(array('types' => 'user', 'limit' => rand(1, 10), 'order_by' => 'RAND()', 'metadata_names' => '__faker'));
        foreach ($users as $user) {
            if ($page->canAnnotate($user->guid, 'page')) {
                $last_revision = $faker->text(500);
                $page->annotate('page', $last_annotation, $page->access_id, $user->guid);
            }
        }
        if (!empty($last_revision)) {
            $page->description = $last_revision;
            $page->save();
        }
        return $page;
    }
    return false;
}
Beispiel #21
0
 public function testElggUserLoad()
 {
     // new object
     $object = new ElggObject();
     $this->AssertEqual($object->getGUID(), 0);
     $guid = $object->save();
     $this->AssertNotEqual($guid, 0);
     // fail on wrong type
     $this->assertFalse(get_user($guid));
     // clean up
     $object->delete();
 }
 public function testElggApiGettersEntitiesFromPrivateSettings()
 {
     // create some test private settings
     $setting_name = 'test_setting_name_' . rand();
     $setting_value = rand(1000, 9999);
     $setting_name2 = 'test_setting_name_' . rand();
     $setting_value2 = rand(1000, 9999);
     $subtypes = $this->getRandomValidSubtypes(array('object'), 1);
     $subtype = $subtypes[0];
     $guids = array();
     // our targets
     $valid = new ElggObject();
     $valid->subtype = $subtype;
     $valid->save();
     $guids[] = $valid->getGUID();
     set_private_setting($valid->getGUID(), $setting_name, $setting_value);
     set_private_setting($valid->getGUID(), $setting_name2, $setting_value2);
     $valid2 = new ElggObject();
     $valid2->subtype = $subtype;
     $valid2->save();
     $guids[] = $valid2->getGUID();
     set_private_setting($valid2->getGUID(), $setting_name, $setting_value);
     set_private_setting($valid2->getGUID(), $setting_name2, $setting_value2);
     // simple test with name
     $options = array('private_setting_name' => $setting_name);
     $entities = elgg_get_entities_from_private_settings($options);
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
         $value = get_private_setting($entity->getGUID(), $setting_name);
         $this->assertEqual($value, $setting_value);
     }
     // simple test with value
     $options = array('private_setting_value' => $setting_value);
     $entities = elgg_get_entities_from_private_settings($options);
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
         $value = get_private_setting($entity->getGUID(), $setting_name);
         $this->assertEqual($value, $setting_value);
     }
     // test pairs
     $options = array('type' => 'object', 'subtype' => $subtype, 'private_setting_name_value_pairs' => array(array('name' => $setting_name, 'value' => $setting_value), array('name' => $setting_name2, 'value' => $setting_value2)));
     $entities = elgg_get_entities_from_private_settings($options);
     $this->assertEqual(2, count($entities));
     foreach ($entities as $entity) {
         $this->assertTrue(in_array($entity->getGUID(), $guids));
     }
     foreach ($guids as $guid) {
         if ($e = get_entity($guid)) {
             $e->delete();
         }
     }
 }
Beispiel #23
0
function hj_forum_1358206168()
{
    $subtypes = array('hjforum' => 'hjForum', 'hjforumcategory' => 'hjForumCategory', 'hjforumtopic' => 'hjForumTopic', 'hjforumpost' => 'hjForumPost');
    foreach ($subtypes as $subtype => $class) {
        if (get_subtype_id('object', $subtype)) {
            update_subtype('object', $subtype, $class);
        } else {
            add_subtype('object', $subtype, $class);
        }
    }
    $subtypeIdForum = get_subtype_id('object', 'hjforum');
    $subtypeIdForumTopic = get_subtype_id('object', 'hjforumtopic');
    $subtypeIdAnnotation = get_subtype_id('object', 'hjannotation');
    $dbprefix = elgg_get_config('dbprefix');
    $segments = elgg_get_entities_from_metadata(array('types' => 'object', 'subtypes' => 'hjsegment', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjforumtopic'), 'limit' => 0));
    /**
     * Upgrade :
     * 1. Convert segmented hjForumTopic objects to hjForum objects
     * 2. Remove segments
     * 3. Convert widgets to categories
     */
    foreach ($segments as $segment) {
        $forum = get_entity($segment->container_guid);
        $query = "UPDATE {$dbprefix}entities SET subtype = {$subtypeIdForum} WHERE subtype = {$subtypeIdForumTopic} AND guid = {$forum->guid}";
        update_data($query);
        $widgets = elgg_get_entities(array('types' => 'object', 'subtypes' => 'widget', 'container_guids' => array($segment->guid, $forum->guid), 'limit' => 0));
        if ($widgets) {
            $forum->enable_subcategories = true;
            foreach ($widgets as $widget) {
                $threads = elgg_get_entities_from_metadata(array('types' => 'object', 'subtypes' => 'hjforumtopic', 'metadata_name_value_pairs' => array(array('name' => 'widget', 'value' => $widget->guid)), 'limit' => 0));
                $cat = new ElggObject();
                $cat->subtype = 'hjforumcategory';
                $cat->owner_guid = elgg_get_logged_in_user_guid();
                $cat->container_guid = $forum->guid;
                $cat->title = $widget->title;
                $cat->description = '';
                $cat->access_id = ACCESS_PUBLIC;
                $cat->save();
                foreach ($threads as $thread) {
                    $query = "UPDATE {$dbprefix}entities SET container_guid = {$forum->guid} WHERE guid = {$thread->guid}";
                    update_data($query);
                    unset($thread->widget);
                    $thread->setCategory($cat->guid, true);
                }
                $widget->disable('plugin_version_upgrade');
            }
        }
        $segment->disable('plugin_version_upgrade');
    }
}
Beispiel #24
0
 /**
  * Save an album
  *
  * @return bool
  */
 public function save()
 {
     if (!isset($this->new_album)) {
         $this->new_album = true;
     }
     if (!isset($this->last_notified)) {
         $this->last_notified = 0;
     }
     if (!parent::save()) {
         return false;
     }
     mkdir(tp_get_img_dir($this->guid), 0755, true);
     return true;
 }
Beispiel #25
0
 public function testElggDeleteAnnotations()
 {
     $e = new ElggObject();
     $e->save();
     for ($i = 0; $i < 30; $i++) {
         $e->annotate('test_annotation', rand(0, 10000));
     }
     $options = array('guid' => $e->getGUID(), 'limit' => 0);
     $annotations = elgg_get_annotations($options);
     $this->assertIdentical(30, count($annotations));
     $this->assertTrue(elgg_delete_annotations($options));
     $annotations = elgg_get_annotations($options);
     $this->assertTrue(empty($annotations));
     $this->assertTrue($e->delete());
 }
Beispiel #26
0
 /**
  * Save an album
  *
  * @return bool
  */
 public function save()
 {
     if (!isset($this->new_album)) {
         $this->new_album = true;
     }
     if (!isset($this->last_notified)) {
         $this->last_notified = 0;
     }
     if (!parent::save()) {
         return false;
     }
     mkdir(tp_get_img_dir() . $this->guid, 0755, true);
     elgg_trigger_event('create', 'album', $this);
     return true;
 }
Beispiel #27
0
/**
 * Condense first annotation into object
 *
 * @param ElggObject $topic
 */
function groups_2011030101($topic)
{
    // do not upgrade topics that have already been upgraded
    if ($topic->description) {
        return true;
    }
    $annotation = $topic->getAnnotations(array('annotation_name' => 'group_topic_post', 'limit' => 1));
    if (!$annotation) {
        // no text for this forum post so we delete (probably caused by #2624)
        return $topic->delete();
    }
    $topic->description = $annotation[0]->value;
    $topic->save();
    return $annotation[0]->delete();
}
Beispiel #28
0
function polls_add_choices($poll, $choices)
{
    $i = 0;
    if ($choices) {
        foreach ($choices as $choice) {
            $poll_choice = new ElggObject();
            $poll_choice->subtype = "poll_choice";
            $poll_choice->text = $choice;
            $poll_choice->display_order = $i * 10;
            $poll_choice->access_id = $poll->access_id;
            $poll_choice->save();
            add_entity_relationship($poll_choice->guid, 'poll_choice', $poll->guid);
            $i += 1;
        }
    }
}
Beispiel #29
0
 /**
  * Test elgg_instanceof()
  * @return unknown_type
  */
 public function testElggInstanceOf()
 {
     $entity = new ElggObject();
     $entity->subtype = 'test_subtype';
     $entity->save();
     $this->assertTrue(elgg_instanceof($entity));
     $this->assertTrue(elgg_instanceof($entity, 'object'));
     $this->assertTrue(elgg_instanceof($entity, 'object', 'test_subtype'));
     $this->assertFalse(elgg_instanceof($entity, 'object', 'invalid_subtype'));
     $this->assertFalse(elgg_instanceof($entity, 'user', 'test_subtype'));
     $entity->delete();
     $bad_entity = FALSE;
     $this->assertFalse(elgg_instanceof($bad_entity));
     $this->assertFalse(elgg_instanceof($bad_entity, 'object'));
     $this->assertFalse(elgg_instanceof($bad_entity, 'object', 'test_subtype'));
 }
Beispiel #30
0
/**
 * Write a persistent message to the admin view.
 * Useful to alert the admin to take a certain action.
 * The id is a unique ID that can be cleared once the admin
 * completes the action.
 *
 * eg: add_admin_notice('twitter_services_no_api',
 * 	'Before your users can use Twitter services on this site, you must set up
 * 	the Twitter API key in the <a href="link">Twitter Services Settings</a>');
 *
 * @param string $id      A unique ID that your plugin can remember
 * @param string $message Body of the message
 *
 * @return bool
 * @since 1.8.0
 */
function elgg_add_admin_notice($id, $message)
{
    if ($id && $message) {
        if (elgg_admin_notice_exists($id)) {
            return false;
        }
        $admin_notice = new ElggObject();
        $admin_notice->subtype = 'admin_notice';
        // admins can see ACCESS_PRIVATE but no one else can.
        $admin_notice->access_id = ACCESS_PRIVATE;
        $admin_notice->admin_notice_id = $id;
        $admin_notice->description = $message;
        return $admin_notice->save();
    }
    return FALSE;
}