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(); }
function pleiofile_generate_file_thumbs(ElggObject $file) { if ($file->simpletype != "image") { return null; } $file->icontime = time(); $sizes = array(60 => "thumb", 153 => "tinythumb", 153 => "smallthumb", 600 => "largethumb"); $filename = str_replace("file/", "", $file->getFilename()); foreach ($sizes as $size => $description) { if ($size < 600) { $upscale = true; } else { $upscale = false; } $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, $upscale); if ($thumbnail) { $path = "file/" . $description . "_" . $filename; $thumb = new ElggFile(); $thumb->setMimeType($_FILES['upload']['type']); $thumb->setFilename($path); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); if ($description == "thumb") { $file->thumbnail = $path; } else { $file->{$description} = $path; } unset($thumbnail); } } }
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; } }
/** * ban user if sending too many messages * * @param string $event * @param string $type * @param ElggObject $object * @return bool */ function community_spam_messages_throttle($event, $type, $object) { if ($object->getSubtype() !== 'messages') { return; } if (community_spam_is_new_user()) { $msg_limit = elgg_get_plugin_setting('new_user_msg_limit', 'community_spam_tools'); } else { $msg_limit = elgg_get_plugin_setting('msg_limit', 'community_spam_tools'); } if (!$msg_limit) { return; } // two message objects created per message but after they are saved, // both are set to private so we only have access to one later on $msg_limit = $msg_limit + 1; $params = array('type' => 'object', 'subtype' => 'messages', 'created_time_lower' => time() - 5 * 60, 'metadata_names' => 'fromId', 'metadata_values' => elgg_get_logged_in_user_guid(), 'count' => true); $num_msgs = elgg_get_entities_from_metadata($params); if ($num_msgs > $msg_limit) { $spammer = elgg_get_logged_in_user_entity(); $spammer->annotate('banned', 1); // this integrates with ban plugin $spammer->ban("Sent {$num_msgs} in 5 minutes"); return false; } }
/** * @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(); }
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; } }
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(); } }
/** * Change the tidypics_batch's access_id to container's access_id (album object) * * @param ElggObject $entity * @param string $getter * @param array $options */ function tidypics_2012111901($entity, $getter, $options) { $album = $entity->getContainerEntity(); if ($guid = tidypics_adjust_batch_access_id($entity, $album)) { return $guid; } }
/** * 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); }
/** * 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(); }
/** * After the question is updated in the databse make sure the answers have the same access_id * * @param string $event the name of the event * @param string $type the type of the event * @param \ElggObject $entity the affected object * * @return void */ public static function updateQuestion($event, $type, $entity) { if (!$entity instanceof \ElggQuestion) { return; } $org_attributes = $entity->getOriginalAttributes(); if (elgg_extract('access_id', $org_attributes) === null) { // access wasn't updated return; } // ignore access for this part $ia = elgg_set_ignore_access(true); // get all the answers for this question $answers = $entity->getAnswers(['limit' => false]); if (empty($answers)) { // restore access elgg_set_ignore_access($ia); return; } /* @var $answer \ElggAnswer */ foreach ($answers as $answer) { // update the access_id with the questions access_id $answer->access_id = $entity->access_id; $answer->save(); } // restore access elgg_set_ignore_access($ia); }
/** * 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(); } }
/** * Prepare the add/edit form variables * * @param ElggObject $page * @return array */ function pad_pages_object_actions_menu($colab, $page) { if (elgg_get_logged_in_user_guid() == $page->getOwnerGuid()) { $name = $colab ? 'collaborative' : 'non-collaborative'; $url = "action/pages/make-{$name}/?guid={$page->guid}"; $text = elgg_echo("pages:make:{$name}"); elgg_register_menu_item('title', array('name' => $name, 'href' => $url, 'text' => $text, 'link_class' => 'elgg-button elgg-button-action', 'is_action' => true)); } }
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; }
/** * Make sure we can autosubscribe the user to further updates * * @param string $event the name of the event * @param string $type the type of the event * @param ElggObject $object the created comment * * @return void */ public static function createObject($event, $type, \ElggObject $object) { if (!$object instanceof \ElggComment) { return; } $owner = $object->getOwnerEntity(); $entity = $object->getContainerEntity(); // add auto subscription for this user content_subscriptions_autosubscribe($entity->getGUID(), $owner->getGUID()); }
/** * 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(); }
/** * 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(); }
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(); }
/** * Format and return the URL for crud object. * * @param ElggObject $entity Assembly object * @return string URL of crud object. */ function crud_url_handler($entity) { if (!$entity->getOwnerEntity()) { // default to a standard view if no owner. return FALSE; } /*if (!$entity->testAssembly()) { return FALSE; }*/ //$friendly_title = elgg_get_friendly_title($entity->title); return $entity->getSubtype() . "/view/{$entity->guid}"; }
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(); } } }
function event_create_object($event, $type, \ElggObject $object) { if (!is_on_probation($object->getOwnerEntity())) { return true; } $object->{QUARANTINED} = '1'; if (elgg_get_plugin_setting(QUARANTINE_PRIVATE, PLUGIN_ID)) { system_message(elgg_echo('probation:moderated:private')); } else { system_message(elgg_echo('probation:moderated')); } State::$entities_quarantined[$object->guid] = $object; }
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'); } }
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()); }
/** * 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(); }
function homepaage_cms_action_hook($hook, $type, $returnvalue, $params) { $hpc_params = array("type" => "object", "subtype" => "hpcroles"); $allRoles = elgg_get_entities($hpc_params); if ($params["hpc_role_check"] == true) { if (!$allRoles) { $hpcRoleTitles = array("all" => array("title" => "all", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[all]"), "learner" => array("title" => "learner", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[learner]"), "instructor" => array("title" => "instructor", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[instructor]"), "developer" => array("title" => "learner", "subtype" => $hpc_params["subtype"], "desc" => "Basic home page cms role to refer page this[developer]")); foreach ($hpcRoleTitles as $roleTitle) { $tmpHpcRole = new ElggObject(); $tmpHpcRole->title = $roleTitle["title"]; $tmpHpcRole->subtype = $roleTitle["subtype"]; $tmpHpcRole->description = $roleTitle["desc"]; $tmpHpcRole->pagecontent = ''; $allRoles[$roleTitle] = $tmpHpcRole->save(); } //system_message('Created roles: '.count($allRoles)); } else { //please uncomment out the following foreach loop to delete all the roles with subtype "hpcroles" in elgg database foreach ($allRoles as $role) { $role->delete(); //system_message((string)$role->guid); } system_message('Available roles: ' . count($allRoles)); } } }
/** * Resets the menu cache for static pages on update and create of an entity * * @param string $event 'create|delete|update' * @param string $type 'object' * @param \ElggObject $entity the entity about to be removed * * @return void */ public static function resetMenuCache($event, $type, \ElggObject $entity) { if (!$entity instanceof \StaticPage) { return; } $root_entity = $entity->getRootPage(); if (empty($root_entity)) { return; } $file = new \ElggFile(); $file->owner_guid = $root_entity->guid; $file->setFilename('static_menu_item_cache'); if ($file->exists()) { $file->delete(); } }
protected function initializeAttributes() { parent::initializeAttributes(); $this->siteDomain = get_site_domain($CONFIG->site_guid); $this->site = elgg_get_site_entity(); $this->approvedDomains = ['forces.gc.ca', 'test.gc.ca']; }
/** * (non-PHPdoc) * @see ElggObject::canComment() */ public function canComment($user_guid = 0) { if ($this->comments_allowed !== 'yes') { return false; } return parent::canComment($user_guid); }
function initializeAttributes() { parent::initializeAttributes(); $this->userGuid = $this->getUserGuid(); $this->user = $this->getUser(); $this->userName = $this->getUserName(); }