/** * 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; }
/** * 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; // 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 = 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); } 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); }
/** * 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; }