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(); } } }
public function testElggEntityRecursiveDisableAndEnable() { global $CONFIG; $obj1 = new \ElggObject(); $obj1->container_guid = $this->entity->getGUID(); $obj1->save(); $obj2 = new \ElggObject(); $obj2->container_guid = $this->entity->getGUID(); $obj2->save(); // disable $obj2 before disabling the container $this->assertTrue($obj2->disable()); // disable entities container by $this->entity $this->assertTrue($this->entity->disable()); $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'"); $this->assertIdentical($entity->enabled, 'no'); // enable entities that were disabled with the container (but not $obj2) $this->assertTrue($this->entity->enable()); $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj1->guid}'"); $this->assertIdentical($entity->enabled, 'yes'); $entity = get_data_row("SELECT * FROM {$CONFIG->dbprefix}entities WHERE guid = '{$obj2->guid}'"); $this->assertIdentical($entity->enabled, 'no'); // cleanup $this->assertTrue($obj2->enable()); $this->assertTrue($obj2->delete()); $this->assertTrue($obj1->delete()); }
/** * 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); }
/** * Remove all the files in this folder * * @param \ElggObject $entity the folder to removed the file from * * @return void */ protected static function removeFolderContents(\ElggObject $entity) { $batch = new \ElggBatch('elgg_get_entities_from_relationship', ['type' => 'object', 'subtype' => 'file', 'container_guid' => $entity->getContainerGUID(), 'limit' => false, 'relationship' => FILE_TOOLS_RELATIONSHIP, 'relationship_guid' => $entity->getGUID()]); $batch->setIncrementOffset(false); foreach ($batch as $file) { $file->delete(); } }
function save_answer($elgg_question, $answer_body) { $answer = new ElggObject(); $answer->subtype = "answer"; $answer->description = $answer_body; $answer->question_guid = $elgg_question->getGUID(); $answer->save(); add_entity_relationship($elgg_question->getGUID(), "answer", $answer->getGUID()); return $answer; }
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(); }
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 testElggApiGettersEntitiesFromAnnotation() { // grab a few different users to annotation // there will always be at least 2 here because of the construct. $users = elgg_get_entities(array('type' => 'user', 'limit' => 2)); // create some test annotations $subtypes = $this->getRandomValidSubtypes(array('object'), 1); $subtype = $subtypes[0]; $annotation_name = 'test_annotation_name_' . rand(); $annotation_value = rand(1000, 9999); $annotation_name2 = 'test_annotation_name_' . rand(); $annotation_value2 = rand(1000, 9999); $guids = array(); // our targets $valid = new \ElggObject(); $valid->subtype = $subtype; $valid->save(); $guids[] = $valid->getGUID(); create_annotation($valid->getGUID(), $annotation_name, $annotation_value, 'integer', $users[0]->getGUID()); $valid2 = new \ElggObject(); $valid2->subtype = $subtype; $valid2->save(); $guids[] = $valid2->getGUID(); create_annotation($valid2->getGUID(), $annotation_name2, $annotation_value2, 'integer', $users[1]->getGUID()); $options = array('annotation_owner_guid' => $users[0]->getGUID(), 'annotation_name' => $annotation_name); $entities = elgg_get_entities_from_annotations($options); foreach ($entities as $entity) { $this->assertTrue(in_array($entity->getGUID(), $guids)); $annotations = $entity->getAnnotations(array('annotation_name' => $annotation_name)); $this->assertEqual(count($annotations), 1); $this->assertEqual($annotations[0]->name, $annotation_name); $this->assertEqual($annotations[0]->value, $annotation_value); $this->assertEqual($annotations[0]->owner_guid, $users[0]->getGUID()); } foreach ($guids as $guid) { if ($e = get_entity($guid)) { $e->delete(); } } }
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()); }
public function testElggDeleteMetadata() { $e = new \ElggObject(); $e->save(); for ($i = 0; $i < 30; $i++) { $name = "test_metadata{$i}"; $e->{$name} = rand(0, 10000); } $options = array('guid' => $e->getGUID(), 'limit' => 0); $md = elgg_get_metadata($options); $this->assertIdentical(30, count($md)); $this->assertTrue(elgg_delete_metadata($options)); $md = elgg_get_metadata($options); $this->assertTrue(empty($md)); $e->delete(); }
public function testElggUserLoad() { // new object $object = new ElggObject(); $this->AssertEqual($object->getGUID(), 0); $guid = $object->save(); $this->AssertNotEqual($guid, 0); // fail on wrong type try { $error = new ElggUserTest($guid); $this->assertTrue(FALSE); } catch (Exception $e) { $this->assertIsA($e, 'InvalidClassException'); $message = sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, 'ElggUser'); $this->assertIdentical($e->getMessage(), $message); } // clean up $object->delete(); }
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; }
/** * Read a folder structure for a zip file * * @param ElggObject $folder the folder to read * @param string $prepend current prefix * * @return array */ function file_tools_get_zip_structure($folder, $prepend) { $entries = []; if (!empty($prepend)) { $prepend = ltrim(sanitise_filepath($prepend), '/'); } if (empty($folder)) { $parent_guid = 0; } else { $parent_guid = $folder->getGUID(); } // get subfolder of this folder $entities = new ElggBatch('elgg_get_entities_from_metadata', ['type' => 'object', 'subtype' => FILE_TOOLS_SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => ['parent_guid' => $parent_guid]]); /* @var $subfolder ElggObject */ foreach ($entities as $subfolder) { $path = $prepend . $subfolder->title; $entries[] = ['directory' => $path, 'files' => file_tools_has_files($subfolder->getGUID())]; $entries = array_merge($entries, file_tools_get_zip_structure($subfolder, $path)); } return $entries; }
/** * Prepare the add/edit form variables * * @param ElggObject $page * @param int $parent_guid * @param ElggAnnotation $revision * @return array */ function pages_prepare_form_vars($page = null, $parent_guid = 0, $revision = null) { // input names => defaults $values = array('title' => '', 'description' => '', 'access_id' => ACCESS_DEFAULT, 'write_access_id' => ACCESS_DEFAULT, 'tags' => '', 'container_guid' => elgg_get_page_owner_guid(), 'guid' => null, 'entity' => $page, 'parent_guid' => $parent_guid); if ($page) { foreach (array_keys($values) as $field) { if (isset($page->{$field})) { $values[$field] = $page->{$field}; } } } if (elgg_is_sticky_form('page')) { $sticky_values = elgg_get_sticky_values('page'); foreach ($sticky_values as $key => $value) { $values[$key] = $value; } } elgg_clear_sticky_form('page'); // load the revision annotation if requested if ($revision instanceof ElggAnnotation && $revision->entity_guid == $page->getGUID()) { $values['description'] = $revision->value; } return $values; }
} if (!empty($border_color)) { $layout->border_color = $border_color; system_message(elgg_echo("group_custom_layout:action:save:success:border_color")); } else { register_error(elgg_echo("group_custom_layout:action:save:error:border_color")); } if (!empty($title_color)) { $layout->title_color = $title_color; system_message(elgg_echo("group_custom_layout:action:save:success:title_color")); } else { register_error(elgg_echo("group_custom_layout:action:save:error:title_color")); } } $last_save = $layout->save(); if ($existing && $last_save) { system_message(elgg_echo("group_custom_layout:action:save:success:existing")); } elseif ($existing && !$last_save) { register_error(elgg_echo("group_custom_layout:action:save:error:last_save")); } elseif (!$existing && $group->addRelationship($layout->getGUID(), GROUP_CUSTOM_LAYOUT_RELATION)) { system_message(elgg_echo("group_custom_layout:action:save:success:group")); } else { register_error(elgg_echo("group_custom_layout:action:save:error:add_to_group")); } } else { register_error(elgg_echo("group_custom_layout:action:save:error:no_group")); } } else { register_error(elgg_echo("group_custom_layout:action:save:error:input")); } forward($group->getURL());
$img_river_view = elgg_get_plugin_setting('img_river_view', 'tidypics'); $album = get_entity($album_guid); if (!elgg_instanceof($album, 'object', 'album')) { exit; } $params = array('type' => 'object', 'subtype' => 'image', 'metadata_names' => 'batch', 'metadata_values' => $batch, 'limit' => 0); $images = elgg_get_entities_from_metadata($params); if ($images) { // Create a new batch object to contain these photos $batch = new ElggObject(); $batch->subtype = "tidypics_batch"; $batch->access_id = ACCESS_PUBLIC; $batch->container_guid = $album->guid; if ($batch->save()) { foreach ($images as $image) { add_entity_relationship($image->guid, "belongs_to_batch", $batch->getGUID()); } } } else { // @todo some sort of message to edit them manually. exit; } // "added images to album" river if ($img_river_view == "batch" && $album->new_album == false) { add_to_river('river/object/tidypics_batch/create', 'create', $batch->getOwnerGUID(), $batch->getGUID()); } // "created album" river if ($album->new_album) { $album->new_album = false; $album->first_upload = true; add_to_river('river/object/album/create', 'create', $album->getOwnerGUID(), $album->getGUID());
// we have to delete everything or the times are wrong. // don't save if nothing changed if ($auto_save_annotations = $blog->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { $auto_save == FALSE; } if (!$auto_save) { $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value != $description) { $blog->clearAnnotations('blog_auto_save'); $annotation_id = $blog->annotate('blog_auto_save', $description); } elseif ($auto_save instanceof ElggAnnotation && $auto_save->value == $description) { // this isn't an error because we have an up to date annotation. $annotation_id = $auto_save->id; } if (!$annotation_id) { $error = elgg_echo('blog:error:cannot_auto_save'); } } } else { $error = elgg_echo('blog:error:missing:description'); } if ($error) { $json = array('success' => FALSE, 'message' => $error); echo json_encode($json); } else { $msg = elgg_echo('blog:message:saved'); $json = array('success' => TRUE, 'message' => $msg, 'guid' => $blog->getGUID()); echo json_encode($json); }
/** * Save a wire post, overrules the default function because we need to support groups * * @param string $text the text of the post * @param int $userid the owner of the post * @param int $access_id the access level of the post * @param int $parent_guid is this a reply on another post * @param string $method which method was used * * @return bool|int the GUID of the new wire post or false */ function thewire_tools_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site") { // set correct container $container_guid = $userid; // check the access id if ($access_id == ACCESS_PRIVATE) { // private wire posts aren"t allowed $access_id = ACCESS_LOGGED_IN; } elseif (thewire_tools_groups_enabled()) { // allow the saving of a wire post in a group (if enabled) if (!in_array($access_id, array(ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC))) { // try to find a group with access_id $group_options = array("type" => "group", "limit" => 1, "metadata_name_value_pairs" => array("group_acl" => $access_id)); $groups = elgg_get_entities_from_metadata($group_options); if (!empty($groups)) { $group = $groups[0]; if ($group->thewire_enable == "no") { // not allowed to post in this group register_error(elgg_echo("thewire_tools:groups:error:not_enabled")); // let creation of object fail return false; } else { $container_guid = $group->getGUID(); } } } } // create the new post $post = new ElggObject(); $post->subtype = "thewire"; $post->owner_guid = $userid; $post->container_guid = $container_guid; $post->access_id = $access_id; // only xxx characters allowed (see plugin setting) $text = elgg_substr($text, 0, thewire_tools_get_wire_length()); // no html tags allowed so we escape $post->description = htmlspecialchars($text, ENT_NOQUOTES, "UTF-8"); $post->method = $method; //method: site, email, api, ... $tags = thewire_get_hashtags($text); if (!empty($tags)) { $post->tags = $tags; } // must do this before saving so notifications pick up that this is a reply if ($parent_guid) { $post->reply = true; } $guid = $post->save(); // set thread guid if ($parent_guid) { $post->addRelationship($parent_guid, "parent"); // name conversation threads by guid of first post (works even if first post deleted) $parent_post = get_entity($parent_guid); $post->wire_thread = $parent_post->wire_thread; } else { // first post in this thread $post->wire_thread = $guid; } if ($guid) { add_to_river("river/object/thewire/create", "create", $post->getOwnerGUID(), $post->getGUID()); // let other plugins know we are setting a user status $params = array("entity" => $post, "user" => $post->getOwnerEntity(), "message" => $post->description, "url" => $post->getURL(), "origin" => "thewire"); elgg_trigger_plugin_hook("status", "user", $params); } return $guid; }
} } else { unset($template); register_error(elgg_echo("InvalidParameterException:NoEntityFound")); } } elseif (!empty($newsletter_guid)) { $newsletter = get_entity($newsletter_guid); if (!empty($newsletter) && $newsletter->canEdit()) { if (elgg_instanceof($newsletter, "object", Newsletter::SUBTYPE)) { $template = new ElggObject(); $template->subtype = NEWSLETTER_TEMPLATE; $template->owner_guid = $newsletter->owner_guid; $template->container_guid = $newsletter->container_guid; $template->access_id = ACCESS_PUBLIC; if ($template->save()) { $newsletter->template = $template->getGUID(); } else { unset($template); register_error(elgg_echo("IOException:UnableToSaveNew", array(elgg_echo("item:object:" . NEWSLETTER_TEMPLATE)))); } } else { register_error(elgg_echo("ClassException:ClassnameNotClass", array($guid, elgg_echo("item:object:" . Newsletter::SUBTYPE)))); } } else { register_error(elgg_echo("InvalidParameterException:NoEntityFound")); } } if (!empty($template)) { $template->title = $name; if (!empty($html)) { $template->html = $html;
/** * Add an ElggObject to this group. * * @param ElggObject $object The object. * * @return bool */ public function addObjectToGroup(ElggObject $object) { return add_object_to_group($this->getGUID(), $object->getGUID()); }
public function testElggAnnotationExists() { $e = new ElggObject(); $e->save(); $guid = $e->getGUID(); $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation')); $e->annotate('test_annotation', rand(0, 10000)); $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation')); // this metastring should always exist but an annotation of this name should not $this->assertFalse(elgg_annotation_exists($guid, 'email')); $options = array('guid' => $guid, 'limit' => 0); $this->assertTrue(elgg_disable_annotations($options)); $this->assertTrue(elgg_annotation_exists($guid, 'test_annotation')); $this->assertTrue($e->delete()); $this->assertFalse(elgg_annotation_exists($guid, 'test_annotation')); }
/** * Change the access of all file in a folder * * @param ElggObject $folder the folder to change the file access for * * @return void */ function file_tools_change_files_access($folder) { if (!empty($folder) && $folder instanceof ElggObject) { if ($folder->getSubtype() == FILE_TOOLS_SUBTYPE) { // change access on files in this folder $options = array("type" => "object", "subtype" => "file", "container_guid" => $folder->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $folder->getGUID()); if ($files = elgg_get_entities_from_relationship($options)) { // need to unregister an event listener elgg_unregister_event_handler("update", "object", "file_tools_object_handler"); foreach ($files as $file) { $file->access_id = $folder->access_id; $file->save(); } } } } }
/** * Message URL override * * @param ElggObject $message * @return string */ function messages_url($message) { $url = elgg_get_site_url() . 'messages/read/' . $message->getGUID(); return $url; }
$topic->title = $entity->title; $topic->description = $entity->description; $topic->tags = $entity->tags; $topic->status = 'open'; if ($topic->save()) { // cleanup sticky form elgg_clear_sticky_form('question'); // make sure we can copy all annotations $ia = elgg_set_ignore_access(true); $comment_options = ['type' => 'object', 'subtype' => 'comment', 'container_guid' => $entity->getGUID(), 'limit' => false]; $comments = new ElggBatch('elgg_get_entities', $comment_options); // copy all comments on the question to topic replies foreach ($comments as $comment) { $reply = new ElggDiscussionReply(); $reply->owner_guid = $comment->getOwnerGUID(); $reply->container_guid = $topic->getGUID(); $reply->access_id = $topic->access_id; $reply->description = $comment->description; if ($reply->save()) { questions_backdate_entity($reply->getGUID(), $comment->time_created); } $comment->delete(); } $answer_options = ['type' => 'object', 'subtype' => 'answer', 'container_guid' => $entity->getGUID(), 'limit' => false]; $answers = new ElggBatch('elgg_get_entities', $answer_options); // copy all answers on the question to topic replies foreach ($answers as $answer) { // move awnser to reply $reply = new ElggDiscussionReply(); $reply->owner_guid = $answer->getOwnerGUID(); $reply->container_guid = $topic->getGUID();
register_error(elgg_echo("publication:error")); forward($_SERVER['HTTP_REFERER']); } if (is_array($tagarray)) { $publication->tags = $tagarray; } $publication->comments_on = $comments_on; $publication->uri = $uri; foreach ($CONFIG->publication as $shortname => $valuetype) { $publication->{$shortname} = $params_value[$shortname]; } $publication->clearRelationships(); if (is_array($pauthors) && sizeof($pauthors) > 0) { foreach ($pauthors as $author) { if (is_int($author)) { add_entity_relationship($publication->getGUID(), 'author', $author); } } } $pauthors = implode(',', $pauthors); $publication->authors = $pauthors; $publication->attachment = $attachment; system_message(elgg_echo("publication:posted")); add_to_river('river/object/publication/create', 'create', $_SESSION['user']->guid, $publication->guid); remove_metadata($_SESSION['user']->guid, 'publicationtitle'); remove_metadata($_SESSION['user']->guid, 'publicationabstract'); remove_metadata($_SESSION['user']->guid, 'publicationkeywords'); remove_metadata($_SESSION['user']->guid, 'publicationauthors'); remove_metadata($_SESSION['user']->guid, 'publicationexauthors'); remove_metadata($_SESSION['user']->guid, 'publicationuri'); remove_metadata($_SESSION['user']->guid, 'publicationsource');
public function testElggEntityRecursiveDisableWhenLoggedOut() { $e1 = new \ElggObject(); $e1->access_id = ACCESS_PUBLIC; $e1->owner_guid = 0; $e1->container_guid = 0; $e1->save(); $guid1 = $e1->getGUID(); $e2 = new \ElggObject(); $e2->container_guid = $guid1; $e2->access_id = ACCESS_PUBLIC; $e2->owner_guid = 0; $e2->save(); $guid2 = $e2->getGUID(); // fake being logged out $old_user = $this->replaceSession(); $ia = elgg_set_ignore_access(true); $this->assertTrue($e1->disable(null, true)); // "log in" original user $this->replaceSession($old_user); elgg_set_ignore_access($ia); $this->assertFalse(get_entity($guid1)); $this->assertFalse(get_entity($guid2)); $db_prefix = elgg_get_config('dbprefix'); $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$guid1}"; $r = get_data_row($q); $this->assertEqual('no', $r->enabled); $q = "SELECT * FROM {$db_prefix}entities WHERE guid = {$guid2}"; $r = get_data_row($q); $this->assertEqual('no', $r->enabled); access_show_hidden_entities(true); $e1->delete(); $e2->delete(); access_show_hidden_entities(false); }
$page->{$name} = $value; } } // need to add check to make sure user can write to container $page->container_guid = $container_guid; if ($parent_guid && $parent_guid != $page_guid) { // Check if parent isn't below the page in the tree if ($page_guid) { $tree_page = get_entity($parent_guid); while ($tree_page->parent_guid > 0 && $page_guid != $tree_page->guid) { $tree_page = get_entity($tree_page->parent_guid); } // If is below, bring all child elements forward if ($page_guid == $tree_page->guid) { $previous_parent = $page->parent_guid; $children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID())); if ($children) { foreach ($children as $child) { $child->parent_guid = $previous_parent; } } } } $page->parent_guid = $parent_guid; } if ($page->save()) { //check in the page becaused the user just saved it if ($page->deleteMetadata("checkedOut")) { system_message(elgg_echo('pages:checked_in')); } else { system_message('Page could not be checked in. It is still locked for editing');
if ($groups) { $containers = array_merge($containers, $groups); } foreach ($containers as $container) { elgg_set_page_owner_guid($container->guid); $access_array = get_write_access_array($owner->guid); $access_id = array_rand($access_array, 1); $bookmark = new ElggObject(); $bookmark->subtype = 'bookmarks'; $bookmark->owner_guid = $owner->guid; $bookmark->container_guid = $container->guid; $bookmark->title = $faker->sentence(6); $bookmark->description = $faker->text(500); $bookmark->tags = $faker->words(5); $bookmark->address = $faker->url; $bookmark->access_id = $access_id; $bookmark->__faker = true; if ($bookmark->save()) { $success++; elgg_create_river_item(array('view' => 'river/object/bookmarks/create', 'action_type' => 'create', 'subject_guid' => $owner->guid, 'object_guid' => $bookmark->getGUID())); } else { $error++; } } } if ($error) { system_message(elgg_echo('faker:gen_bookmarks:error', array($success, $error))); } else { system_message(elgg_echo('faker:gen_bookmarks:success', array($success))); } forward(REFERER);
if ($result) { array_push($uploaded_images, $image->getGUID()); if ($img_river_view == "all") { add_to_river('river/object/image/create', 'create', $image->getOwnerGUID(), $image->getGUID()); } } } if (count($uploaded_images)) { // Create a new batch object to contain these photos $batch = new ElggObject(); $batch->subtype = "tidypics_batch"; $batch->access_id = $album->access_id; $batch->container_guid = $album->getGUID(); if ($batch->save()) { foreach ($uploaded_images as $uploaded_guid) { add_entity_relationship($uploaded_guid, "belongs_to_batch", $batch->getGUID()); } } $album->prependImageList($uploaded_images); // "added images to album" river if ($img_river_view == "batch" && $album->new_album == false) { add_to_river('river/object/tidypics_batch/create', 'create', $batch->getOwnerGUID(), $batch->getGUID()); } // "created album" river if ($album->new_album) { $album->new_album = false; $album->first_upload = true; add_to_river('river/object/album/create', 'create', $album->getOwnerGUID(), $album->getGUID()); // "created album" notifications // we throw the notification manually here so users are not told about the new album until // there are at least a few photos in it
function testElggApiGettersEntityMetadataNVPInvalidDouble() { $subtypes = $this->getRandomValidSubtypes(array('object'), 1); $subtype = $subtypes[0]; $md_name = 'test_metadata_name_' . rand(); $guids = array(); $valid_guids = array(); $value = '052e866869'; // our targets $valid = new ElggObject(); $valid->subtype = $subtype; $valid->{$md_name} = $value; $valid->save(); $guids[] = $valid->getGUID(); $valid_guids[] = $valid->getGUID(); $options = array('type' => 'object', 'subtype' => $subtype, 'metadata_name_value_pairs' => array('name' => $md_name, 'value' => $value)); $entities = elgg_get_entities_from_metadata($options); $this->assertIsA($entities, 'array'); $this->assertEqual(count($entities), 1); foreach ($entities as $entity) { $this->assertTrue(in_array($entity->getGUID(), $valid_guids)); $this->assertEqual($entity->{$md_name}, $value); $entity->delete(); } foreach ($guids as $guid) { if ($e = get_entity($guid)) { $e->delete(); } } }