From 1f3befaf97c2840dbd4ecadd8cc62bf838d32a45 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 26 Mar 2011 15:23:08 +0000 Subject: standardized thewire plugin git-svn-id: http://code.elgg.org/elgg/trunk@8841 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/thewire/actions/add.php | 67 +- mod/thewire/actions/delete.php | 78 +- mod/thewire/classes/ElggWire.php | 4 +- mod/thewire/languages/en.php | 4 +- mod/thewire/pages/thewire/everyone.php | 60 +- mod/thewire/pages/thewire/friends.php | 46 +- mod/thewire/pages/thewire/owner.php | 68 +- mod/thewire/pages/thewire/reply.php | 56 +- mod/thewire/pages/thewire/thread.php | 56 +- mod/thewire/start.php | 879 +++++++++++---------- mod/thewire/tests/regex.php | 24 + mod/thewire/views/default/object/thewire.php | 8 +- .../views/default/thewire/profile_status.php | 2 +- mod/thewire/views/rss/object/thewire.php | 39 +- 14 files changed, 711 insertions(+), 680 deletions(-) diff --git a/mod/thewire/actions/add.php b/mod/thewire/actions/add.php index 33936d5ee..97b630678 100644 --- a/mod/thewire/actions/add.php +++ b/mod/thewire/actions/add.php @@ -1,33 +1,34 @@ -wire_thread"); -} - -system_message(elgg_echo("thewire:posted")); -forward(REFERER); +wire_thread"); +} + +system_message(elgg_echo("thewire:posted")); +forward(REFERER); diff --git a/mod/thewire/actions/delete.php b/mod/thewire/actions/delete.php index 9d629325a..58502a7e7 100644 --- a/mod/thewire/actions/delete.php +++ b/mod/thewire/actions/delete.php @@ -1,39 +1,39 @@ -getSubtype() == "thewire" && $thewire->canEdit()) { - - // unset reply metadata on children - $children = elgg_get_entities_from_relationship(array( - 'relationship' => 'parent', - 'relationship_guid' => $post_guid, - 'inverse_relationship' => true, - )); - if ($children) { - foreach ($children as $child) { - $child->reply = false; - } - } - - // Get owning user - $owner = get_entity($thewire->getOwner()); - - // Delete it - $rowsaffected = $thewire->delete(); - if ($rowsaffected > 0) { - // Success message - system_message(elgg_echo("thewire:deleted")); - } else { - register_error(elgg_echo("thewire:notdeleted")); - } - - forward("thewire/owner/" . $owner->username); -} +getSubtype() == "thewire" && $thewire->canEdit()) { + + // unset reply metadata on children + $children = elgg_get_entities_from_relationship(array( + 'relationship' => 'parent', + 'relationship_guid' => $post_guid, + 'inverse_relationship' => true, + )); + if ($children) { + foreach ($children as $child) { + $child->reply = false; + } + } + + // Get owning user + $owner = get_entity($thewire->getOwner()); + + // Delete it + $rowsaffected = $thewire->delete(); + if ($rowsaffected > 0) { + // Success message + system_message(elgg_echo("thewire:deleted")); + } else { + register_error(elgg_echo("thewire:notdeleted")); + } + + forward("thewire/owner/" . $owner->username); +} diff --git a/mod/thewire/classes/ElggWire.php b/mod/thewire/classes/ElggWire.php index d864cc259..3242dd5cb 100644 --- a/mod/thewire/classes/ElggWire.php +++ b/mod/thewire/classes/ElggWire.php @@ -5,7 +5,9 @@ class ElggWire extends ElggObject { /** - * Set subtype to thewire. + * Set subtype to thewire + * + * @return void */ protected function initializeAttributes() { parent::initializeAttributes(); diff --git a/mod/thewire/languages/en.php b/mod/thewire/languages/en.php index 4143a40cb..0896ecf14 100644 --- a/mod/thewire/languages/en.php +++ b/mod/thewire/languages/en.php @@ -39,8 +39,8 @@ $english = array( */ 'thewire:posted' => "Your message was successfully posted to the wire.", 'thewire:deleted' => "The wire post was successfully deleted.", - 'thewire:blank' => "Sorry; you need to actually put something in the textbox before we can save it.", - 'thewire:notfound' => "Sorry; we could not find the specified wire post.", + 'thewire:blank' => "Sorry, you need to enter come text before we can post this.", + 'thewire:notfound' => "Sorry, we could not find the specified wire post.", 'thewire:notdeleted' => "Sorry. We could not delete this wire post.", ); diff --git a/mod/thewire/pages/thewire/everyone.php b/mod/thewire/pages/thewire/everyone.php index 6ccff11fd..e3d38ace5 100644 --- a/mod/thewire/pages/thewire/everyone.php +++ b/mod/thewire/pages/thewire/everyone.php @@ -1,30 +1,30 @@ - 'object', - 'subtype' => 'thewire', - 'limit' => 15, -)); - -$body = elgg_view_layout('content', array( - 'filter_context' => 'all', - 'content' => $content, - 'title' => $title, - 'buttons' => false, - 'sidebar' => elgg_view('thewire/sidebar'), -)); - -echo elgg_view_page($title, $body); + 'object', + 'subtype' => 'thewire', + 'limit' => 15, +)); + +$body = elgg_view_layout('content', array( + 'filter_context' => 'all', + 'content' => $content, + 'title' => $title, + 'buttons' => false, + 'sidebar' => elgg_view('thewire/sidebar'), +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/pages/thewire/friends.php b/mod/thewire/pages/thewire/friends.php index 6e8642544..ab452aa55 100644 --- a/mod/thewire/pages/thewire/friends.php +++ b/mod/thewire/pages/thewire/friends.php @@ -1,23 +1,23 @@ -name, "thewire/owner/$owner->username"); -elgg_push_breadcrumb(elgg_echo('friends')); - -$content = list_user_friends_objects($owner->guid, 'thewire', 15, false); - -$body = elgg_view_layout('content', array( - 'filter_context' => 'friends', - 'content' => $content, - 'title' => $title, - 'buttons' => false, -)); - -echo elgg_view_page($title, $body); +name, "thewire/owner/$owner->username"); +elgg_push_breadcrumb(elgg_echo('friends')); + +$content = list_user_friends_objects($owner->guid, 'thewire', 15, false); + +$body = elgg_view_layout('content', array( + 'filter_context' => 'friends', + 'content' => $content, + 'title' => $title, + 'buttons' => false, +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/pages/thewire/owner.php b/mod/thewire/pages/thewire/owner.php index e52b445ab..d61307990 100644 --- a/mod/thewire/pages/thewire/owner.php +++ b/mod/thewire/pages/thewire/owner.php @@ -1,34 +1,34 @@ -name)); - -elgg_push_breadcrumb(elgg_echo('thewire'), "thewire/all"); -elgg_push_breadcrumb($owner->name); - -if (get_loggedin_userid() == $owner->guid) { - $content = elgg_view_form('thewire/add'); - $content .= elgg_view('input/urlshortener'); -} - -$content .= elgg_list_entities(array( - 'type' => 'object', - 'subtype' => 'thewire', - 'owner_guid' => $owner->guid, - 'limit' => 15, -)); - -$body = elgg_view_layout('content', array( - 'filter_context' => 'mine', - 'content' => $content, - 'title' => $title, - 'buttons' => false, - 'sidebar' => elgg_view('thewire/sidebar'), -)); - -echo elgg_view_page($title, $body); +name)); + +elgg_push_breadcrumb(elgg_echo('thewire'), "thewire/all"); +elgg_push_breadcrumb($owner->name); + +if (get_loggedin_userid() == $owner->guid) { + $content = elgg_view_form('thewire/add'); + $content .= elgg_view('input/urlshortener'); +} + +$content .= elgg_list_entities(array( + 'type' => 'object', + 'subtype' => 'thewire', + 'owner_guid' => $owner->guid, + 'limit' => 15, +)); + +$body = elgg_view_layout('content', array( + 'filter_context' => 'mine', + 'content' => $content, + 'title' => $title, + 'buttons' => false, + 'sidebar' => elgg_view('thewire/sidebar'), +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/pages/thewire/reply.php b/mod/thewire/pages/thewire/reply.php index c29f81669..826d513b6 100644 --- a/mod/thewire/pages/thewire/reply.php +++ b/mod/thewire/pages/thewire/reply.php @@ -1,28 +1,28 @@ - $post)); -$content .= elgg_view_form('thewire/add', array(), array('post' => $post)); -$content .= elgg_view('input/urlshortener'); - - -$body = elgg_view_layout('content', array( - 'filter' => false, - 'content' => $content, - 'title' => $title, - 'buttons' => false, -)); - -echo elgg_view_page($title, $body); + $post)); +$content .= elgg_view_form('thewire/add', array(), array('post' => $post)); +$content .= elgg_view('input/urlshortener'); + + +$body = elgg_view_layout('content', array( + 'filter' => false, + 'content' => $content, + 'title' => $title, + 'buttons' => false, +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/pages/thewire/thread.php b/mod/thewire/pages/thewire/thread.php index 8b6ee4bd0..5c32a8400 100644 --- a/mod/thewire/pages/thewire/thread.php +++ b/mod/thewire/pages/thewire/thread.php @@ -1,28 +1,28 @@ - "wire_thread", - "metadata_value" => $thread_id, - "type" => "object", - "subtype" => "thewire", - "limit" => 20, -)); - -$body = elgg_view_layout('content', array( - 'filter' => false, - 'content' => $content, - 'title' => $title, - 'buttons' => false, -)); - -echo elgg_view_page($title, $body); + "wire_thread", + "metadata_value" => $thread_id, + "type" => "object", + "subtype" => "thewire", + "limit" => 20, +)); + +$body = elgg_view_layout('content', array( + 'filter' => false, + 'content' => $content, + 'title' => $title, + 'buttons' => false, +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/start.php b/mod/thewire/start.php index d10efb6ba..0c35b0231 100644 --- a/mod/thewire/start.php +++ b/mod/thewire/start.php @@ -1,437 +1,442 @@ -pluginspath . 'thewire/actions'; - register_action("thewire/add", false, "$action_base/add.php"); - register_action("thewire/delete", false, "$action_base/delete.php"); - - register_plugin_hook('unit_test', 'system', 'thewire_test'); -} - -/** - * The wire page handler - * - * Supports: - * thewire/all View site wire posts - * thewire/owner/ View this user's wire posts - * thewire/following/ View the posts of those this user follows - * thewire/reply/ Reply to a post - * thewire/view/ View a conversation thread - * thewire/tag/ View wire posts tagged with - * - * @param array $page From the page_handler function - * @return true|false Depending on success - */ -function thewire_page_handler($page) { - - $base_dir = elgg_get_plugins_path() . 'thewire/pages/thewire'; - - // if just /thewire go to global view in the else statement - if (isset($page[0]) && $page[0]) { - - switch ($page[0]) { - case "all": - include "$base_dir/everyone.php"; - break; - - case "friends": - include "$base_dir/friends.php"; - break; - - case "owner": - include "$base_dir/owner.php"; - break; - - case "thread": - if (isset($page[1])) { - set_input('thread_id', $page[1]); - } - include "$base_dir/thread.php"; - break; - case "reply": - if (isset($page[1])) { - set_input('guid', $page[1]); - } - include "$base_dir/reply.php"; - break; - case "tag": - if (isset($page[1])) { - set_input('tag', $page[1]); - } - include "$base_dir/tag.php"; - break; - case "previous": - if (isset($page[1])) { - set_input('guid', $page[1]); - } - include "$base_dir/previous.php"; - break; - } - } else { - include "$base_dir/everyone.php"; - } - - return true; -} - -/** - * Override the url for a wire post to return the thread - * - * @param $thewirepost - wire post object - */ -function thewire_url($thewirepost) { - global $CONFIG; - return $CONFIG->url . "thewire/view/" . $thewirepost->guid; -} - -/** - * Returns the notification body - * - * @param string $hook - * @param string $entity_type - * @param string $returnvalue - * @param array $params - * @return $string - */ -function thewire_notify_message($hook, $entity_type, $returnvalue, $params) { - global $CONFIG; - - $entity = $params['entity']; - if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'thewire')) { - $descr = $entity->description; - $owner = $entity->getOwnerEntity(); - if ($entity->reply) { - // have to do this because of poor design of Elgg notification system - $parent_post = get_entity(get_input('parent_guid')); - if ($parent_post) { - $parent_owner = $parent_post->getOwnerEntity(); - } - $body = sprintf(elgg_echo('thewire:notify:reply'), $owner->name, $parent_owner->name); - } else { - $body = sprintf(elgg_echo('thewire:notify:post'), $owner->name); - } - $body .= "\n\n" . $descr . "\n\n"; - $body .= elgg_echo('thewire') . ": {$CONFIG->url}thewire"; - return $body; - } - return $returnvalue; -} - -/** - * Get an array of hashtags from a text string - * - * @param string $text - * @return array - */ -function thewire_get_hashtags($text) { - // beginning of text or white space followed by hashtag - // hashtag must begin with # and contain at least one character not digit, space, or punctuation - $matches = array(); - preg_match_all('/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', $text, $matches); - return $matches[2]; -} - -/** - * Replace urls, hash tags, and @'s by links - * - * @param $text - * @return string - */ -function thewire_filter($text) { - global $CONFIG; - - $text = ' ' . $text; - - // email addresses - $text = preg_replace( - '/(^|[^\w])([\w\-\.]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})/i', - '$1$2@$3', - $text); - - // links - $text = parse_urls($text); - - // usernames - $text = preg_replace( - '/(^|[^\w])@([\w]+)/', - '$1@$2', - $text); - - // hashtags - $text = preg_replace( - '/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', - '$1#$2', - $text); - - $text = trim($text); - - return $text; -} - -/** - * 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; -} - -/** - * Send notification to poster of parent post if not notified already - * - * @param int $guid - * @param int $parent_guid - * @param ElggUser $user - */ -function thewire_send_response_notification($guid, $parent_guid, $user) { - $parent_owner = get_entity($parent_guid)->getOwnerEntity(); - $user = get_loggedin_user(); - - // check to make sure user is not responding to self - if ($parent_owner->guid != $user->guid) { - // check if parent owner has notification for this user - $send_response = true; - global $NOTIFICATION_HANDLERS; - foreach ($NOTIFICATION_HANDLERS as $method => $foo) { - if (check_entity_relationship($parent_owner->guid, 'notify' . $method, $user->guid)) { - $send_response = false; - } - } - - // create the notification message - if ($send_response) { - // grab same notification message that goes to everyone else - $params = array( - 'entity' => get_entity($guid), - 'method' => "email", - ); - $msg = thewire_notify_message("", "", "", $params); - - notify_user( - $parent_owner->guid, - $user->guid, - elgg_echo('thewire:notify:subject'), - $msg); - } - } -} - -/** - * Get the latest wire guid - used for ajax update - * @return guid - */ -function thewire_latest_guid() { - $post = elgg_get_entities(array( - 'type' => 'object', - 'subtype' => 'thewire', - 'limit' => 1, - )); - if ($post) { - return $post[0]->guid; - } else { - return 0; - } -} - -/** - * Get the parent of a wire post - * - * @param ElggObject $post - * @return ElggObject or null - */ -function thewire_get_parent($post_guid) { - $parents = elgg_get_entities_from_relationship(array( - 'relationship' => 'parent', - 'relationship_guid' => $post_guid, - )); - if ($parents) { - return $parents[0]; - } - return null; -} - -/** - * Sets up the entity menu for thewire - * - * Adds reply, thread, and view previous links. Removes edit and access. - * - * @param string $hook - * @param string $type - * @param array $value - * @param array $params - * @return array - */ -function thewire_setup_entity_menu_items($hook, $type, $value, $params) { - $handler = elgg_extract('handler', $params, false); - if ($handler != 'thewire') { - return $value; - } - - foreach ($value as $index => $item) { - $name = $item->getName(); - if ($name == 'access' || $name == 'edit') { - unset($value[$index]); - } - } - - $entity = $params['entity']; - - if (elgg_is_logged_in()) { - $options = array( - 'name' => 'reply', - 'text' => elgg_echo('thewire:reply'), - 'href' => "thewire/reply/$entity->guid", - 'priority' => 150, - ); - $value[] = ElggMenuItem::factory($options); - } - - if ($entity->reply) { - $options = array( - 'name' => 'previous', - 'text' => elgg_echo('thewire:previous'), - 'href' => "thewire/previous/$entity->guid", - 'priority' => 160, - ); - $value[] = ElggMenuItem::factory($options); - } - - $options = array( - 'name' => 'thread', - 'text' => elgg_echo('thewire:thread'), - 'href' => "thewire/thread/$entity->wire_thread", - 'priority' => 170, - ); - $value[] = ElggMenuItem::factory($options); - - return $value; -} - -/** - * Add a menu item to an ownerblock - */ -function thewire_owner_block_menu($hook, $type, $return, $params) { - if (elgg_instanceof($params['entity'], 'user')) { - $url = "thewire/owner/{$params['entity']->username}"; - $item = new ElggMenuItem('thewire', elgg_echo('item:object:thewire'), $url); - $return[] = $item; - } - - return $return; -} - -/** - * Runs unit tests for the wire - */ -function thewire_test($hook, $type, $value, $params) { - global $CONFIG; - $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php'; - return $value; -} +pluginspath . 'thewire/actions'; + register_action("thewire/add", false, "$action_base/add.php"); + register_action("thewire/delete", false, "$action_base/delete.php"); + + register_plugin_hook('unit_test', 'system', 'thewire_test'); +} + +/** + * The wire page handler + * + * Supports: + * thewire/all View site wire posts + * thewire/owner/ View this user's wire posts + * thewire/following/ View the posts of those this user follows + * thewire/reply/ Reply to a post + * thewire/view/ View a conversation thread + * thewire/tag/ View wire posts tagged with + * + * @param array $page From the page_handler function + * @return true|false Depending on success + */ +function thewire_page_handler($page) { + + $base_dir = elgg_get_plugins_path() . 'thewire/pages/thewire'; + + // if just /thewire go to global view in the else statement + if (isset($page[0]) && $page[0]) { + + switch ($page[0]) { + case "all": + include "$base_dir/everyone.php"; + break; + + case "friends": + include "$base_dir/friends.php"; + break; + + case "owner": + include "$base_dir/owner.php"; + break; + + case "thread": + if (isset($page[1])) { + set_input('thread_id', $page[1]); + } + include "$base_dir/thread.php"; + break; + case "reply": + if (isset($page[1])) { + set_input('guid', $page[1]); + } + include "$base_dir/reply.php"; + break; + case "tag": + if (isset($page[1])) { + set_input('tag', $page[1]); + } + include "$base_dir/tag.php"; + break; + case "previous": + if (isset($page[1])) { + set_input('guid', $page[1]); + } + include "$base_dir/previous.php"; + break; + } + } else { + include "$base_dir/everyone.php"; + } + + return true; +} + +/** + * Override the url for a wire post to return the thread + * + * @param ElggObject $thewirepost Wire post object + */ +function thewire_url($thewirepost) { + global $CONFIG; + return $CONFIG->url . "thewire/view/" . $thewirepost->guid; +} + +/** + * Returns the notification body + * + * @return $string + */ +function thewire_notify_message($hook, $entity_type, $returnvalue, $params) { + global $CONFIG; + + $entity = $params['entity']; + if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'thewire')) { + $descr = $entity->description; + $owner = $entity->getOwnerEntity(); + if ($entity->reply) { + // have to do this because of poor design of Elgg notification system + $parent_post = get_entity(get_input('parent_guid')); + if ($parent_post) { + $parent_owner = $parent_post->getOwnerEntity(); + } + $body = sprintf(elgg_echo('thewire:notify:reply'), $owner->name, $parent_owner->name); + } else { + $body = sprintf(elgg_echo('thewire:notify:post'), $owner->name); + } + $body .= "\n\n" . $descr . "\n\n"; + $body .= elgg_echo('thewire') . ": {$CONFIG->url}thewire"; + return $body; + } + return $returnvalue; +} + +/** + * Get an array of hashtags from a text string + * + * @param string $text The text of a post + * @return array + */ +function thewire_get_hashtags($text) { + // beginning of text or white space followed by hashtag + // hashtag must begin with # and contain at least one character not digit, space, or punctuation + $matches = array(); + preg_match_all('/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', $text, $matches); + return $matches[2]; +} + +/** + * Replace urls, hash tags, and @'s by links + * + * @param string $text The text of a post + * @return string + */ +function thewire_filter($text) { + global $CONFIG; + + $text = ' ' . $text; + + // email addresses + $text = preg_replace( + '/(^|[^\w])([\w\-\.]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})/i', + '$1$2@$3', + $text); + + // links + $text = parse_urls($text); + + // usernames + $text = preg_replace( + '/(^|[^\w])@([\w]+)/', + '$1@$2', + $text); + + // hashtags + $text = preg_replace( + '/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', + '$1#$2', + $text); + + $text = trim($text); + + return $text; +} + +/** + * 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; +} + +/** + * Send notification to poster of parent post if not notified already + * + * @param int $guid The guid of the reply wire post + * @param int $parent_guid The guid of the original wire post + * @param ElggUser $user The user who posted the reply + * @return void + */ +function thewire_send_response_notification($guid, $parent_guid, $user) { + $parent_owner = get_entity($parent_guid)->getOwnerEntity(); + $user = get_loggedin_user(); + + // check to make sure user is not responding to self + if ($parent_owner->guid != $user->guid) { + // check if parent owner has notification for this user + $send_response = true; + global $NOTIFICATION_HANDLERS; + foreach ($NOTIFICATION_HANDLERS as $method => $foo) { + if (check_entity_relationship($parent_owner->guid, 'notify' . $method, $user->guid)) { + $send_response = false; + } + } + + // create the notification message + if ($send_response) { + // grab same notification message that goes to everyone else + $params = array( + 'entity' => get_entity($guid), + 'method' => "email", + ); + $msg = thewire_notify_message("", "", "", $params); + + notify_user( + $parent_owner->guid, + $user->guid, + elgg_echo('thewire:notify:subject'), + $msg); + } + } +} + +/** + * Get the latest wire guid - used for ajax update + * + * @return guid + */ +function thewire_latest_guid() { + $post = elgg_get_entities(array( + 'type' => 'object', + 'subtype' => 'thewire', + 'limit' => 1, + )); + if ($post) { + return $post[0]->guid; + } else { + return 0; + } +} + +/** + * Get the parent of a wire post + * + * @param int $post_guid The guid of the reply + * @return ElggObject or null + */ +function thewire_get_parent($post_guid) { + $parents = elgg_get_entities_from_relationship(array( + 'relationship' => 'parent', + 'relationship_guid' => $post_guid, + )); + if ($parents) { + return $parents[0]; + } + return null; +} + +/** + * Sets up the entity menu for thewire + * + * Adds reply, thread, and view previous links. Removes edit and access. + * + * @param string $hook Hook name + * @param string $type Hook type + * @param array $value Array of menu items + * @param array $params Array with the entity + * @return array + */ +function thewire_setup_entity_menu_items($hook, $type, $value, $params) { + $handler = elgg_extract('handler', $params, false); + if ($handler != 'thewire') { + return $value; + } + + foreach ($value as $index => $item) { + $name = $item->getName(); + if ($name == 'access' || $name == 'edit') { + unset($value[$index]); + } + } + + $entity = $params['entity']; + + if (elgg_is_logged_in()) { + $options = array( + 'name' => 'reply', + 'text' => elgg_echo('thewire:reply'), + 'href' => "thewire/reply/$entity->guid", + 'priority' => 150, + ); + $value[] = ElggMenuItem::factory($options); + } + + if ($entity->reply) { + $options = array( + 'name' => 'previous', + 'text' => elgg_echo('thewire:previous'), + 'href' => "thewire/previous/$entity->guid", + 'priority' => 160, + ); + $value[] = ElggMenuItem::factory($options); + } + + $options = array( + 'name' => 'thread', + 'text' => elgg_echo('thewire:thread'), + 'href' => "thewire/thread/$entity->wire_thread", + 'priority' => 170, + ); + $value[] = ElggMenuItem::factory($options); + + return $value; +} + +/** + * Add a menu item to an ownerblock + * + * @return array + */ +function thewire_owner_block_menu($hook, $type, $return, $params) { + if (elgg_instanceof($params['entity'], 'user')) { + $url = "thewire/owner/{$params['entity']->username}"; + $item = new ElggMenuItem('thewire', elgg_echo('item:object:thewire'), $url); + $return[] = $item; + } + + return $return; +} + +/** + * Runs unit tests for the wire + * + * @return array + */ +function thewire_test($hook, $type, $value, $params) { + global $CONFIG; + $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php'; + return $value; +} diff --git a/mod/thewire/tests/regex.php b/mod/thewire/tests/regex.php index a1a432a20..f5487a422 100644 --- a/mod/thewire/tests/regex.php +++ b/mod/thewire/tests/regex.php @@ -38,22 +38,46 @@ class TheWireRegexTest extends ElggCoreUnitTest { parent::__destruct(); } + /** + * Get the link for a user's wire page + * + * @param string $username Username + * @return string + */ protected function getUserWireLink($username) { $url = "thewire/owner/$username"; $url = elgg_normalize_url($url); return "@$username"; } + /** + * Get the link for a hashtag page + * + * @param string $tag Tag string + * @return string + */ protected function getHashtagLink($tag) { $url = "thewire/tag/$tag"; $url = elgg_normalize_url($url); return "#$tag"; } + /** + * Get a link for an email address mailto + * + * @param string $address Email address + * @return string + */ protected function getEmailLink($address) { return "$address"; } + /** + * Get the html for a link + * + * @param string $address URL + * @return string + */ protected function getLink($address) { return parse_urls($address); } diff --git a/mod/thewire/views/default/object/thewire.php b/mod/thewire/views/default/object/thewire.php index 9ffde3eeb..ace290589 100644 --- a/mod/thewire/views/default/object/thewire.php +++ b/mod/thewire/views/default/object/thewire.php @@ -30,10 +30,10 @@ $author_text = elgg_echo('byline', array($owner_link)); $date = elgg_view_friendly_time($post->time_created); $metadata = elgg_view_menu('entity', array( - 'entity' => $post, - 'handler' => 'thewire', - 'sort_by' => 'priority', - 'class' => 'elgg-menu-hz', + 'entity' => $post, + 'handler' => 'thewire', + 'sort_by' => 'priority', + 'class' => 'elgg-menu-hz', )); $subtitle = "$author_text $date"; diff --git a/mod/thewire/views/default/thewire/profile_status.php b/mod/thewire/views/default/thewire/profile_status.php index 7b04cba50..6ab47bccb 100644 --- a/mod/thewire/views/default/thewire/profile_status.php +++ b/mod/thewire/views/default/thewire/profile_status.php @@ -23,7 +23,7 @@ if ($latest_wire && count($latest_wire) > 0) { $button = ''; if ($owner == elgg_get_logged_in_user_guid()) { - $url_to_wire = "thewire/owner/" . $vars['entity']->username; + $url_to_wire = "thewire/owner/" . $vars['entity']->username; $button = elgg_view('output/url', array( 'text' => elgg_echo('thewire:update'), 'href' => $url_to_wire, diff --git a/mod/thewire/views/rss/object/thewire.php b/mod/thewire/views/rss/object/thewire.php index fbbb670b7..8229f46f1 100644 --- a/mod/thewire/views/rss/object/thewire.php +++ b/mod/thewire/views/rss/object/thewire.php @@ -11,38 +11,37 @@ if ($owner) { $title = elgg_echo('thewire:by', array($owner->name)); } else { $subtitle = strip_tags($vars['entity']->description); - $title = substr($subtitle,0,32); - if (strlen($subtitle) > 32) { - $title .= " ..."; - } + $title = elgg_get_excerpt($subtitle, 32); } ?> getGUID(); ?> -time_created) ?> +time_created) ?> getURL()); ?> <![CDATA[<?php echo $title; ?>]]> description)); ?>]]> getOwnerEntity(); - if ($owner) { -?> -name; ?> -getOwnerEntity(); +if ($owner) { + ?> + name; ?> + getLongitude()) && - ($vars['entity']->getLatitude()) - ) { - ?> - getLatitude(); ?> getLongitude(); ?> - getLongitude()) && + ($vars['entity']->getLatitude()) +) { + ?> + + getLatitude(); ?> getLongitude(); ?> + + -- cgit v1.2.3