/** * Create a new wire post, the TGS way * * @param string $text The post text * @param int $userid The user's guid * @param int $access_id Public/private etc * @param int $parent_guid Parent post guid (if any) * @param string $method The method (default: 'site') * @param int $container_guid Container guid (for group wire posts) * @return guid or false if failure */ function tgswire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $container_guid = NULL) { $post = new ElggObject(); $post->subtype = "thewire"; $post->owner_guid = $userid; $post->access_id = $access_id; // Check if we're removing the limit if (elgg_get_plugin_setting('limit_wire_chars', 'wire-extender') == 'yes') { // only 200 characters allowed $text = elgg_substr($text, 0, 200); } // If supplied with a container_guid, use it if ($container_guid) { $post->container_guid = $container_guid; } // 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 ($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->owner_guid, $post->guid); // 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; }
function hypefaker_add_wire($owner, $parent = null) { $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US'); $faker = Factory::create($locale); $wire = new ElggObject(); $wire->subtype = 'thewire'; $wire->owner_guid = $owner->guid; $tags = $faker->words(5); $text = $faker->text(80); foreach ($tags as $tag) { $text .= " #{$tag}"; } if ($parent) { $wire->reply = true; $username = $parent->getOwnerEntity()->username; $text = "@{$username} {$text}"; } $limit = elgg_get_plugin_setting('limit', 'thewire'); if ($limit > 0) { $text = elgg_substr($text, 0, $limit); } $wire->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); $wire->tags = $tags; $wire->method = 'faker'; $wire->access_id = ACCESS_PUBLIC; $wire->__faker = true; if ($wire->save()) { if ($parent) { $wire->addRelationship($parent->guid, 'parent'); $wire->wire_thread = $parent->wire_thread; } else { $wire->wire_thread = $wire->guid; } elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $wire->owner_guid, 'object_guid' => $wire->guid)); $params = array('entity' => $wire, 'user' => $owner, 'message' => $wire->description, 'url' => $wire->getURL(), 'origin' => 'thewire'); elgg_trigger_plugin_hook('status', 'user', $params); return $wire; } return false; }
/** * @SWG\Definition( * definition="Event", * required={"guid","title"}, * @SWG\Property(property="guid", type="integer"), * @SWG\Property(property="title", type="string"), * @SWG\Property(property="description", type="string"), * @SWG\Property(property="start_time", type="string"), * @SWG\Property(property="end_time", type="string"), * @SWG\Property(property="url", type="string"), * @SWG\Property(property="icon_url", type="string"), * @SWG\Property(property="time_created", type="string") * ) */ private function parseEvent(\ElggObject $event) { $start_time = mktime(date("H", $event->start_time), date("i", $event->start_time), 0, date("n", $event->start_day), date("j", $event->start_day), date("Y", $event->start_day)); if ($event->end_ts) { $end_time = date('c', $event->end_ts); } else { $end_time = null; } return array('guid' => $event->guid, 'title' => html_entity_decode($event->title, ENT_QUOTES), 'description' => html_entity_decode($event->description, ENT_QUOTES), 'start_time' => date('c', $start_time), 'end_time' => $end_time, 'url' => $event->getURL(), 'icon_url' => $event->getIconURL(), 'time_created' => date('c', $event->time_created)); }
<?php // only logged in users can add blog posts gatekeeper(); // get the form input $title = get_input('title'); $body = get_input('body'); $tags = string_to_tag_array(get_input('tags')); // create a new blog object $blogpost = new ElggObject(); $blogpost->title = $title; $blogpost->description = $body; $blogpost->subtype = "blog"; // for now make all blog posts public $blogpost->access_id = ACCESS_PUBLIC; // owner is logged in user $blogpost->owner_guid = get_loggedin_userid(); // save tags as metadata $blogpost->tags = $tags; // save to database $blogpost->save(); // forward user to a page that displays the post forward($blogpost->getURL());
if (sizeof($input) > 0) { foreach ($input as $name => $value) { $markdown_wiki->{$name} = $value; } } if ($markdown_wiki->save()) { elgg_clear_sticky_form('markdown_wiki'); elgg_load_library('markdown_wiki:fineDiff'); // set diff $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::wordDelimiters)); $compared['word'] = calc_diff_markdown_wiki($compare->renderDiffToHTML()); $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::sentenceDelimiters)); $compared['sentence'] = calc_diff_markdown_wiki($compare->renderDiffToHTML()); $compare = new FineDiff($old_description, $markdown_wiki->description, array(FineDiff::paragraphDelimiters)); $compared['paragraph'] = calc_diff_markdown_wiki($compare->renderDiffToHTML()); $array_change = array('text' => $markdown_wiki->description, 'diff' => $compared, 'summary' => get_input('summary')); // Now save description as an annotation $annotation_id = create_annotation($markdown_wiki->guid, 'markdown_wiki', serialize($array_change), '', 0, $markdown_wiki->access_id); system_message(elgg_echo('markdown_wiki:saved')); if ($new_markdown_wiki) { add_to_river('river/object/markdown_wiki/create', 'create', $user_guid, $markdown_wiki->guid); } else { if (!get_input('minorchange', false)) { add_to_river('river/object/markdown_wiki/update', 'update', $user_guid, $markdown_wiki->guid, '', 0, $annotation_id); } } forward($markdown_wiki->getURL()); } else { register_error(elgg_echo('markdown_wiki:error:no_save')); forward(REFERER); }
<?php // only logged in users can add blog posts gatekeeper(); // get the form input $title = get_input('title'); $body = get_input('id'); $keyword = get_input('keyword'); // create a new search object $search_obj = new ElggObject(); $search_obj->title = $title; $search_obj->id = $id; $search_obj->keyword = $keyword; $search_obj->subtype = "mmsearch"; // for now make all blog posts public $search_obj->access_id = ACCESS_PUBLIC; // owner is logged in user $search_obj->owner_guid = get_loggedin_userid(); // save to database $search_obj->save(); // forward user to a page that displays the post forward($search_obj->getURL());
/** * 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; }
/** * Create a new wire post. * * @param string $text The post text * @param int $userid The user's guid * @param int $access_id Public/private etc * @param int $parent_guid Parent post guid (if any) * @param string $method The method (default: 'site') * @return guid or false if failure */ function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site") { $post = new ElggObject(); $post->subtype = "thewire"; $post->owner_guid = $userid; $post->access_id = $access_id; // Character limit is now from config $limit = elgg_get_plugin_setting('limit', 'thewire'); if ($limit > 0) { $text = elgg_substr($text, 0, $limit); } // 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 ($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) { elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->owner_guid, 'object_guid' => $post->guid)); // 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; }
function golfscore_post($user, $score, $golf_course) { $body = elgg_view('output/url', array('href' => "profile/{$user->username}", 'text' => $user->name, 'is_trusted' => true)); $body .= ' shot an '; $body .= elgg_view('output/url', array('href' => "golfscore/view?golf_score_id={$score->golf_score_id}", 'text' => $score->total_score, 'is_trusted' => true)); $body .= " at "; $body .= elgg_view('output/url', array('href' => "golfscore/all?golf_course_id={$golf_course->golf_course_id}", 'text' => $golf_course->course_name, 'is_trusted' => true)); $body .= " Course"; $access_id = ACCESS_PUBLIC; $method = 'site'; $post = new ElggObject(); $post->subtype = "thewire"; $post->owner_guid = $user->guid; $post->access_id = $access_id; // only 200 characters allowed // $text = elgg_substr($body, 0, 200); $text = $body; // no html tags allowed so we escape $post->description = $text; //htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); $post->method = $method; //method: site, email, api, ... $tags = thewire_get_hashtags($text); if ($tags) { $post->tags = $tags; } $guid = $post->save(); // first post in this thread $post->wire_thread = $guid; if ($guid) { add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid); // 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); } //elgg_trigger_plugin_hook('thewire','post', array('body' => $body), false); }
$reply = get_entity($guid); $original_topic = $reply->getContainerEntity(); $user_guid = $reply->getOwnerGUID(); $group_guid = $original_topic->getContainerGUID(); $grouptopic = new ElggObject(); $grouptopic->subtype = "discussion"; $grouptopic->owner_guid = $user_guid; $grouptopic->container_guid = $group_guid; $grouptopic->access_id = $original_topic->access_id; $grouptopic->title = $title; $grouptopic->description = $reply->description; $grouptopic->status = 'open'; if (!$grouptopic->save()) { register_error(elgg_echo('discussion:error:notsaved')); forward(REFERER); } elgg_delete_river(array('object_guid' => $reply->guid)); elgg_create_river_item(array('view' => 'river/object/discussion/create', 'action_type' => 'create', 'subject_guid' => $user_guid, 'object_guid' => $grouptopic->guid, 'posted' => $reply->time_created)); // Replace the original content with a note and add a link that takes to the new topic $link = elgg_view('output/url', array('href' => $grouptopic->getURL(), 'text' => elgg_echo('cg:form:offtopic:warning:link'))); $warning_text = elgg_echo('cg:form:offtopic:warning'); $reply->description = "[{$warning_text} {$link}]"; $reply->save(); $user = get_user($user_guid); $site = elgg_get_site_entity(); $subject = elgg_echo('cg:forum:offtopic:notify:title', array(), $user->language); $message = elgg_echo('cg:forum:offtopic:notify:body', array($user->name, $site->name, elgg_get_excerpt($grouptopic->description, 80), $grouptopic->getURL()), $user->language); // Let the user know that the comment was moved notify_user($user_guid, $site->guid, $subject, $message, array('action' => 'move', 'object' => $grouptopic)); system_message(elgg_echo('cg:forum:offtopic:success')); forward($grouptopic->getURL());
// don't change access if not an owner/admin $user = elgg_get_logged_in_user_entity(); foreach ($input as $name => $value) { $publication->{$name} = $value; } } // need to add check to make sure user can write to container $publication->container_guid = $container_guid; if ($publication->save()) { if (($icon_file = get_resized_image_from_uploaded_file("image", 100, 100)) && ($icon_sizes = elgg_get_config("icon_sizes"))) { // create icon $prefix = "publications/" . $publication->getGUID(); $fh = new ElggFile(); $fh->owner_guid = $publication->getOwnerGUID(); foreach ($icon_sizes as $icon_name => $icon_info) { if ($icon_file = get_resized_image_from_uploaded_file("image", $icon_info["w"], $icon_info["h"], $icon_info["square"], $icon_info["upscale"])) { $fh->setFilename($prefix . $icon_name . ".jpg"); if ($fh->open("write")) { $fh->write($icon_file); $fh->close(); } } } $publication->icontime = time(); } system_message(elgg_echo('publications:saved')); forward($publication->getURL()); } else { register_error(elgg_echo('publications:error:notsaved')); forward(REFERER); }
if ($parent_guid) { $task->subtype = 'task'; } else { $task->subtype = 'task_top'; } $new_task = true; } if (sizeof($input) > 0) { foreach ($input as $name => $value) { $task->{$name} = $value; echo $name . ','; } } // need to add check to make sure user can write to container $task->container_guid = $container_guid; if ($parent_guid) { $task->parent_guid = $parent_guid; } if ($task->save()) { elgg_clear_sticky_form('task'); // Now save description as an annotation $task->annotate('task', $task->description, $task->access_id); system_message(elgg_echo('tasks:saved')); if ($new_task) { add_to_river('river/object/task/create', 'create', elgg_get_logged_in_user_guid(), $task->guid); } forward($task->getURL()); } else { register_error(elgg_echo('tasks:notsaved')); forward(REFERER); }
/** * 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 * @param int $reshare_guid is the a (re)share of some content item * * @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", $reshare_guid = 0) { // 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, [ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC])) { // try to find a group with access_id $group_options = ['type' => 'group', 'limit' => 1, 'metadata_name_value_pairs' => ['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 of thewire, 0 is unlimited) $max_length = thewire_tools_get_wire_length(); if ($max_length) { $text = elgg_substr($text, 0, $max_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(); if ($guid) { // 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; } // add reshare if ($reshare_guid) { $post->addRelationship($reshare_guid, 'reshare'); } // add to river elgg_create_river_item(['view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->getOwnerGUID(), 'object_guid' => $post->getGUID()]); // let other plugins know we are setting a user status $params = ['entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire']; elgg_trigger_plugin_hook('status', 'user', $params); } return $guid; }
/** * @SWG\Definition( * definition="FileFolder", * required={"guid","subtype","title"}, * @SWG\Property(property="guid", type="integer"), * @SWG\Property(property="subtype", type="string", enum={"file", "folder"}), * @SWG\Property(property="title", type="string"), * @SWG\Property(property="time_created", type="string") * ) */ private function parseObject(\ElggObject $object) { $subtype = $object->getSubtype(); $data = array('guid' => $object->guid, 'subtype' => $subtype, 'title' => html_entity_decode($object->title, ENT_QUOTES), 'time_created' => date('c', $object->time_created)); if ($subtype == "file") { $data['url'] = elgg_normalize_url('file/download/' . $object->guid); } else { $data['url'] = $object->getURL(); } return $data; }
<?php // only logged in users can add blog posts gatekeeper(); // get the form input $title = get_input('title'); $body = get_input('body'); $tags = string_to_tag_array(get_input('tags')); $container_guid = get_input('container'); // create a new blog object $groupfeed = new ElggObject(); $groupfeed->title = $title; $groupfeed->description = $body; $groupfeed->subtype = "groupfeed"; // for now make all blog posts public $groupfeed->access_id = ACCESS_PUBLIC; // owner is logged in user $groupfeed->owner_guid = get_loggedin_userid(); // save tags as metadata $groupfeed->tags = $tags; // adds to group $groupfeed->container_guid = $container_guid; // save to database $groupfeed->save(); // forward user to a page that displays the post forward($groupfeed->getURL());
} $list_guid = $input['list_guid']; if ($list_guid) { $task->list_guid = $list_guid; } else { $task->list_guid = 0; } $task->container_guid = $container_guid; if ($task->save()) { elgg_clear_sticky_form('task'); // Now save description as an annotation $task->annotate('task', $task->description, $task->access_id); system_message(elgg_echo('tasks:saved')); if ($new_task) { add_to_river('river/object/task/create', 'create', elgg_get_logged_in_user_guid(), $task->guid); } if ($new_task && $referer_guid && ($referer_entity = get_entity($referer_guid))) { $link = elgg_view('output/url', array('href' => $task->getURL(), 'text' => $task->title)); $annotation = create_annotation($referer_entity->guid, 'generic_comment', elgg_echo('tasks:this:referer:comment', array($link)), "", elgg_get_logged_in_user_guid(), $referer_entity->access_id); } $task_json = array(); foreach ($task->getExportableValues() as $v) { $task_json[$v] = $task->{$v}; } $task_json['list_guid'] = $task->list_guid; echo json_encode($task_json); forward($task->getURL()); } else { register_error(elgg_echo('tasks:error:no_save')); forward(REFERER); }
$entity = get_entity($guid); $is_new = true; if (elgg_instanceof($entity, 'object', 'scheduling_poll')) { if (!$entity->canEdit()) { register_error(elgg_echo('scheduling:error:cannot_edit')); forward(REFERER); } $is_new = false; } else { $entity = new ElggObject(); $entity->subtype = 'scheduling_poll'; $entity->container_guid = get_input('container_guid'); } $title = get_input('title'); $description = get_input('description'); $access_id = get_input('access_id'); $entity->access_id = $access_id; $entity->title = $title; $entity->description = $description; if ($entity->save()) { system_message(elgg_echo('scheduling:save:success')); } else { register_error(elgg_echo('scheduling:save:error')); forward(REFERER); } if ($is_new) { $forward_url = "scheduling/days/{$entity->guid}"; } else { $forward_url = $entity->getURL(); } forward($forward_url);
} else { // not embedded $entity->{$name} = $value; } } } // set parent if set if (!empty($parent_guid)) { $entity->parent_guid = $parent_guid; } // need to add check to make sure user can write to container $entity->container_guid = $container_guid; if ($entity->save()) { if ($embedded_child) { $embedded_child->parent_guid = $entity->guid; $embedded_child->access_id = $entity->access_id; $embedded_child->container_guid = $container_guid; $embedded_child->save(); } elgg_clear_sticky_form($crud_type); system_message(elgg_echo($msg_prefix . ':saved')); if ($new_entity) { add_to_river('river/object/crud/create', 'create', elgg_get_logged_in_user_guid(), $entity->guid); } else { add_to_river('river/object/crud/create', 'edited', elgg_get_logged_in_user_guid(), $entity->guid); } forward($entity->getURL()); } else { register_error(elgg_echo($msg_prefix . ':error:no_save')); forward(REFERER); }
if ($entry->save()) { $entry->addRelationship($survey->guid, 'hearSelection'); } } } if ($reason) { foreach ($reason as $selection) { $entry = new ElggObject(); $entry->access_id = 2; $entry->title = $selection; if ($entry->save()) { $entry->addRelationship($survey->guid, 'reasonSelection'); } } } if ($final8) { foreach ($final8 as $selection) { $entry = new ElggObject(); $entry->access_id = 2; $entry->title = $selection; if ($entry->save()) { $entry->addRelationship($survey->guid, 'final8Selection'); } } } system_message("Survey Submitted"); forward($survey->getURL()); } else { register_error("Error submitting survey"); forward(REFERER); }
} else { if (strtotime($expiration_date) < time()) { $page->unpublished = true; } } } // save the page 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'); } elgg_clear_sticky_form("page"); // Now save description as an annotation $page->annotate("page", $page->description, $page->access_id); system_message(elgg_echo("pages:saved")); if ($new_page && !$page->unpublished) { add_to_river("river/object/page/create", "create", $user->getGUID(), $page->getGUID()); } elseif ($page->getOwnerGUID() != $user->getGUID()) { // not the owner edited the page, notify the owner $subject = elgg_echo("pages_tools:notify:edit:subject", array($page->title)); $msg = elgg_echo("pages_tools:notify:edit:message", array($page->title, $user->name, $page->getURL())); notify_user($page->getOwnerGUID(), $user->getGUID(), $subject, $msg); } forward($page->getURL()); } else { register_error(elgg_echo("pages:error:no_save")); forward(REFERER); }
// get the form inputs $title = get_input('title'); $body = get_input('body'); $tags = string_to_tag_array(get_input('tags')); // create a new agnaret_hflts object $entry = new ElggObject(); $entry->subtype = "hflts"; $entry->title = $title; $entry->description = $body; // access_id possibilities //ACCESS_PRIVATE (value: 0) Private. //ACCESS_LOGGED_IN (value: 1) Logged in users. //ACCESS_PUBLIC (value: 2) Public data. //ACCESS_FRIENDS (value: -2) Owner and his/her friends. $entry->access_id = ACCESS_PRIVATE; // owner is logged in user $entry->owner_guid = elgg_get_logged_in_user_guid(); // save tags as metadata $entry->tags = $tags; // save to database and get id of the new agnaret_hflts $entry_guid = $entry->save(); // if the my_entry was saved, we want to display the new post // otherwise, we want to register an error and forward back to the form if ($entry_guid) { system_message(elgg_echo("hflts:msgOk")); forward($entry->getURL()); } else { register_error(elgg_echo("hflts:msgWrong")); forward(REFERER); // REFERER is a global variable that defines the previous page }
/** * Create a new wire post. * * @param string $text The post text * @param int $userid The user's guid * @param int $access_id Public/private etc * @param int $parent_guid Parent post guid (if any) * @param string $method The method (default: 'site') * @return guid or false if failure */ function wire_save_post($text, $userid, $entity_guid, $access_id, $parent_guid = 0, $method = "site") { $post = new ElggObject(); $post->subtype = "wire"; $post->owner_guid = $userid; $post->access_id = $access_id; $post->entity_guid = $entity_guid; // only 200 characters allowed $text = elgg_substr($text, 0, 200); // no html tags allowed so we escape $post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8'); $post->method = $method; //method: site, email, api, ... $tags = wire_get_hashtags($text); if ($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/wire/create', 'create', $post->owner_guid, $post->guid); // let other plugins know we are setting a user status $params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'wire'); elgg_trigger_plugin_hook('status', 'user', $params); } //fordebug register_error("in save entity_guid {$post->entity_guid}"); return $guid; }
if ($project_guid) { $project = get_entity($project_guid); if (!$project || !$project->canEdit()) { register_error(elgg_echo('gvprojects:error:no_save')); forward(REFERER); } $new_project = false; } else { $project = new ElggObject(); $project->subtype = 'project'; $new_project = true; } $project->title = $title; $project->short_desc = $short_desc; $project->description = $description; $project->tags = explode(",", $tags); $project->owner_guid = $container_guid; $project->container_guid = $container_guid; $project->access_id = ACCESS_LOGGED_IN; $project->competencies = $competencies; if ($project->save()) { elgg_clear_sticky_form('project'); system_message(elgg_echo('gvprojects:saved')); if ($new_project) { add_to_river('river/object/project/create', 'create', elgg_get_logged_in_user_guid(), $project->guid); } forward($project->getURL()); } else { register_error(elgg_echo('gvprojects:error:notsaved')); forward(REFERER); }
$question->description = $body; // check if user can add question to group if ($container_guid && $container_guid != $_SESSION['guid']) { $question->container_guid = $container_guid; $group = get_entity($container_guid); if (!$group instanceof ElggGroup) { forward(); } if (!can_write_to_container($_SESSION['guid'], $container_guid)) { forward(); } if ($group->content_access == ACCESS_PRIVATE) { $question->access_id = $group->group_acl; } } if (!$question->save()) { register_error(elgg_echo("answers:question:saveerror")); forward("mod/answers/add.php"); } if (is_array($tagarray)) { $question->tags = $tagarray; } // Success message system_message(elgg_echo("answers:question:posted")); // add to river add_to_river('river/object/question/create', 'create', $_SESSION['user']->guid, $question->guid); //notify user(s) if they were tagged $calloutUsers = new UserCallout(get_entity(elgg_get_logged_in_user_guid()), $callout_user_guids, "a question", $question->getURL()); $calloutUsers->sendUserNotifications(); forward($question->getURL()); }
// Make sure the title / description aren't blank if (empty($title)) { register_error(elgg_echo('answers:question:blank')); forward(REFERER); } // Otherwise, save the question if ($guid) { $question = get_entity($guid); $new = false; } else { $question = new ElggObject(); $question->subtype = 'question'; $new = true; } $question->access_id = $access_id; $question->title = $title; $question->description = $description; $question->tags = string_to_tag_array($tags); $question->container_guid = $container_guid; if ($question->save()) { elgg_clear_sticky_form('question'); system_message(elgg_echo('answers:question:posted') . $sysmsg); if ($new) { // only add river item when this is a new question add_to_river('river/object/question/create', 'create', $user_guid, $question->guid); } forward($question->getURL()); } else { register_error(elgg_echo('answers:error')); forward(REFERER); }
<?php // get the form inputs $cname = get_input('cat_name'); $cdesc = get_input('cat_desc'); // create a new my_blog object $category = new ElggObject(); $category->subtype = "create_category"; $category->cat_name = $cname; $category->cat_desc = $cdesc; // for now make all my_blog posts public $category->access_id = ACCESS_PRIVATE; // owner is logged in user $category->owner_guid = elgg_get_logged_in_user_guid(); // save tags as metadata $category->tags = $tags; // save to database and get id of the new my_blog $category_guid = $category->save(); // if the my_blog was saved, we want to display the new post // otherwise, we want to register an error and forward back to the form if ($category_guid) { system_message("Category Saved"); forward($category->getURL()); } else { register_error("Error saving Category!"); forward(REFERER); // REFERER is a global variable that defines the previous page }
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'); } elgg_clear_sticky_form('page'); // Now save description as an annotation $page->annotate('page', $page->description, $page->access_id); system_message(elgg_echo('pages:saved')); if ($new_page) { add_to_river('river/object/page/create', 'create', elgg_get_logged_in_user_guid(), $page->guid); } forward($page->getURL()); } else { register_error(elgg_echo('pages:error:notsaved')); forward(REFERER); }
if (sizeof($input) > 0) { foreach ($input as $name => $value) { $video->{$name} = $value; } } $video->container_guid = $container_guid; if ($video->save()) { elgg_clear_sticky_form('videolist'); // Let's save the thumbnail in the data folder $thumb_url = $video->thumbnail; if ($thumb_url) { $thumbnail = file_get_contents($thumb_url); if ($thumbnail) { $prefix = "videolist/" . $video->guid; $filehandler = new ElggFile(); $filehandler->owner_guid = $video->owner_guid; $filehandler->setFilename($prefix . ".jpg"); $filehandler->open("write"); $filehandler->write($thumbnail); $filehandler->close(); } } system_message(elgg_echo('videolist:saved')); if ($new_video) { elgg_create_river_item(array('view' => 'river/object/videolist_item/create', 'action_type' => 'create', 'subject_guid' => elgg_get_logged_in_user_guid(), 'object_guid' => $video->guid)); } forward($video->getURL()); } else { register_error(elgg_echo('videolist:error:no_save')); forward(REFERER); }
} else { // load original file object $topic = new ElggObject($guid); if (!$topic || !$topic->canEdit()) { register_error(elgg_echo('discussion:topic:notfound')); forward(REFERER); } } $topic->title = $title; $topic->description = $desc; $topic->status = $status; $topic->access_id = $access_id; $topic->container_guid = $container_guid; $tags = explode(",", $tags); $topic->tags = $tags; $result = $topic->save(); if (!$result) { register_error(elgg_echo('discussion:error:notsaved')); forward(REFERER); } // topic saved so clear sticky form elgg_clear_sticky_form('topic'); // handle results differently for new topics and topic edits if ($new_topic) { system_message(elgg_echo('discussion:topic:created')); add_to_river('river/object/groupforumtopic/create', 'create', elgg_get_logged_in_user_guid(), $topic->guid); } else { system_message(elgg_echo('discussion:topic:updated')); } forward($topic->getURL());
$email = get_input('email'); $categories = get_input('categories'); // create a new my_blog object $contact = new ElggObject(); $contact->subtype = "create_contact"; $contact->fname = $fname; $contact->lname = $lname; $contact->email = $email; $contact->categories = $categories; // for now make all contacts private $contact->access_id = ACCESS_PRIVATE; // owner is logged in user $contact->owner_guid = elgg_get_logged_in_user_guid(); // save tags as metadata $contact->tags = $tags; // save to database and get id of the new my_blog $contact_guid = $contact->save(); // Adding the page to activity stream - here we call river add_to_river('river/object/create_contact/create', 'create', elgg_get_logged_in_user_guid(), $contact->getGUID()); // if the Create Contact was saved, we want to display the new contact // otherwise, we want to register an error and forward back to the form if ($contact_guid) { // Printingout the Success Message system_message("Your contact saved"); // Forwarding the Page forward($contact->getURL()); } else { register_error("Your contact could not be saved!"); forward(REFERER); // REFERER is a global variable that defines the previous page }