/** * 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; }
<?php /** * The wire's JavaScript */ $wire_length = thewire_tools_get_wire_length(); ?> //<script> elgg.provide('elgg.thewire'); elgg.thewire.init = function() { $("#thewire-textarea").live('keydown', function() { elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), <?php echo $wire_length; ?> ); }); $("#thewire-textarea").live('keyup', function() { elgg.thewire.textCounter(this, $("#thewire-characters-remaining span"), <?php echo $wire_length; ?> ); }); $(".thewire-previous").live('click', elgg.thewire.viewPrevious); }; /** * Update the number of characters left with every keystroke * * @param {Object} textarea
<?php /** * Wire add form body * * @uses $vars["post"] */ elgg_load_js("elgg.thewire"); $post = elgg_extract("post", $vars); $char_limit = thewire_tools_get_wire_length(); $reshare = elgg_extract("reshare", $vars); // for reshare functionality $text = elgg_echo("post"); if ($post) { $text = elgg_echo("reply"); } $chars_left = elgg_echo("thewire:charleft"); $parent_input = ""; if ($post) { $parent_input = elgg_view("input/hidden", array("name" => "parent_guid", "value" => $post->guid)); } $reshare_input = ""; $post_value = ""; if (!empty($reshare)) { $reshare_input = elgg_view("input/hidden", array("name" => "reshare_guid", "value" => $reshare->getGUID())); $reshare_input .= elgg_view("thewire_tools/reshare_source", array("entity" => $reshare)); if (!empty($reshare->title)) { $post_value = $reshare->title; } elseif (!empty($reshare->name)) { $post_value = $reshare->name; } elseif (!empty($reshare->description)) {
/** * 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; }