From da90ff55725a9118ce6111ab2b6371650bf78ade Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 12 Feb 2011 22:41:25 +0000 Subject: a mostly completed port of JHU/APL wire plugin to 1.8 git-svn-id: http://code.elgg.org/elgg/trunk@8183 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/thewire/actions/add.php | 74 ++- mod/thewire/actions/delete.php | 73 +-- mod/thewire/add.php | 25 - mod/thewire/everyone.php | 26 - mod/thewire/index.php | 43 -- mod/thewire/languages/en.php | 120 ++--- mod/thewire/manifest.xml | 7 +- mod/thewire/pages/everyone.php | 29 + mod/thewire/pages/friends.php | 23 + mod/thewire/pages/previous.php | 11 + mod/thewire/pages/reply.php | 28 + mod/thewire/pages/tag.php | 36 ++ mod/thewire/pages/thread.php | 28 + mod/thewire/pages/user.php | 33 ++ mod/thewire/readme.txt | 13 - mod/thewire/start.php | 600 ++++++++++++--------- mod/thewire/tests/regex.php | 271 ++++++++++ mod/thewire/views/default/forms/thewire/add.php | 64 +++ mod/thewire/views/default/object/thewire.php | 106 ++-- .../views/default/river/object/thewire/create.php | 2 +- mod/thewire/views/default/thewire/css.php | 36 +- mod/thewire/views/default/thewire/forms/add.php | 31 -- mod/thewire/views/default/thewire/metadata.php | 56 ++ mod/thewire/views/default/thewire/notfound.php | 17 - .../views/default/thewire/profile_status.php | 16 +- mod/thewire/views/default/thewire/reply.php | 11 + mod/thewire/views/default/thewire/view.php | 23 - .../views/default/widgets/thewire/content.php | 28 +- mod/thewire/views/default/widgets/thewire/edit.php | 30 +- 29 files changed, 1184 insertions(+), 676 deletions(-) delete mode 100644 mod/thewire/add.php delete mode 100644 mod/thewire/everyone.php delete mode 100644 mod/thewire/index.php create mode 100644 mod/thewire/pages/everyone.php create mode 100644 mod/thewire/pages/friends.php create mode 100644 mod/thewire/pages/previous.php create mode 100644 mod/thewire/pages/reply.php create mode 100644 mod/thewire/pages/tag.php create mode 100644 mod/thewire/pages/thread.php create mode 100644 mod/thewire/pages/user.php delete mode 100644 mod/thewire/readme.txt create mode 100644 mod/thewire/tests/regex.php create mode 100644 mod/thewire/views/default/forms/thewire/add.php delete mode 100644 mod/thewire/views/default/thewire/forms/add.php create mode 100644 mod/thewire/views/default/thewire/metadata.php delete mode 100644 mod/thewire/views/default/thewire/notfound.php create mode 100644 mod/thewire/views/default/thewire/reply.php delete mode 100644 mod/thewire/views/default/thewire/view.php (limited to 'mod/thewire') diff --git a/mod/thewire/actions/add.php b/mod/thewire/actions/add.php index 04aa2bc82..f32f7e555 100644 --- a/mod/thewire/actions/add.php +++ b/mod/thewire/actions/add.php @@ -1,41 +1,33 @@ - +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 849433e0f..7758b4b03 100644 --- a/mod/thewire/actions/delete.php +++ b/mod/thewire/actions/delete.php @@ -1,34 +1,39 @@ -getSubtype() == "thewire" && $thewire->canEdit()) { - - // Get owning user - $owner = $thewire->getOwnerEntity(); - // Delete it! - $rowsaffected = $thewire->delete(); - if ($rowsaffected > 0) { - // Success message - system_message(elgg_echo("thewire:deleted")); - } else { - register_error(elgg_echo("thewire:notdeleted")); - } - // Forward to the main wire page - forward("mod/thewire/?username=" . $owner->username); - - } - -?> \ No newline at end of file +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("pg/thewire/owner/" . $owner->username); +} diff --git a/mod/thewire/add.php b/mod/thewire/add.php deleted file mode 100644 index a63a10190..000000000 --- a/mod/thewire/add.php +++ /dev/null @@ -1,25 +0,0 @@ - $area2)); - - // Display page - echo elgg_view_page(elgg_echo('thewire:addpost'),$body); - -?> \ No newline at end of file diff --git a/mod/thewire/everyone.php b/mod/thewire/everyone.php deleted file mode 100644 index 05793ed03..000000000 --- a/mod/thewire/everyone.php +++ /dev/null @@ -1,26 +0,0 @@ - 'object', 'subtypes' => 'thewire', 'offset' => $offset)); - - $body = elgg_view_layout("one_sidebar", array('content' => $area2)); - - // Display page - echo elgg_view_page(elgg_echo('thewire:everyone'),$body); - -?> diff --git a/mod/thewire/index.php b/mod/thewire/index.php deleted file mode 100644 index 7ed43e3bc..000000000 --- a/mod/thewire/index.php +++ /dev/null @@ -1,43 +0,0 @@ -getGUID()); - } - - // title - if (elgg_get_page_owner_guid() == elgg_get_logged_in_user_guid()) { - $area2 = elgg_view_title(elgg_echo("thewire:read")); - } else { - $area2 = elgg_view_title(elgg_echo("thewire:user",array($page_owner->name))); - } - - //add form - $area2 .= elgg_view("thewire/forms/add"); - - // Display the user's wire - $options = array( - 'type' => 'object', - 'subtype' => 'thewire', - 'owner_guid' => $page_owner->getGUID() - ); - $area2 .= elgg_list_entities($options); - - //select the correct canvas area - $body = elgg_view_layout("one_sidebar", array('content' => $area2)); - - // Display page - echo elgg_view_page(elgg_echo('thewire:user', array($page_owner->name)), $body); - -?> \ No newline at end of file diff --git a/mod/thewire/languages/en.php b/mod/thewire/languages/en.php index 581ac5506..8978c6739 100644 --- a/mod/thewire/languages/en.php +++ b/mod/thewire/languages/en.php @@ -1,82 +1,46 @@ "The Wire", - 'thewire:my_posts' => "My wire posts", - 'thewire:user' => "%s's wire posts", - 'thewire:posttitle' => "%s's notes on the wire: %s", - 'thewire:everyone' => "All wire posts", - - 'thewire:read' => "My wire posts", - - 'thewire:strapline' => "%s", - - 'thewire:add' => "Post to the wire", - 'thewire:text' => "A note on the wire", - 'thewire:reply' => "Reply", - 'thewire:via_method' => "via %s", - 'thewire:wired' => "Posted to the wire", - 'thewire:charleft' => "characters remaining", - 'item:object:thewire' => "Wire posts", - 'thewire:notedeleted' => "note deleted", - 'thewire:doing' => "What are you doing? Tell everyone on the wire:", - 'thewire:newpost' => 'New wire post', - 'thewire:addpost' => 'Post to the wire', - 'thewire:by' => "Wire post by %s", - 'thewire:update' => 'update', +$english = array( - - /** - * The wire river - **/ - - //generic terms to use - 'thewire:river:created' => "%s posted", - - //these get inserted into the river links to take the user to the entity - 'thewire:river:create' => "posted to the wire", - - /** - * Wire widget - **/ - - 'thewire:sitedesc' => 'This widget shows the latest site notes posted to the wire', - 'thewire:yourdesc' => 'This widget displays your latest wire posts', - 'thewire:friendsdesc' => 'This widget will show the latest from your friends on the wire', - 'thewire:friends' => 'Your friends on the wire', - 'thewire:num' => 'Number of items to display', - 'thewire:moreposts' => 'More wire posts', - - - /** - * Status messages - */ - - 'thewire:posted' => "Your message was successfully posted to the wire.", - 'thewire:deleted' => "Your wire post was successfully deleted.", - - /** - * Error messages - */ - - '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:notdeleted' => "Sorry; we could not delete this wire post.", - - - /** - * Settings - */ - 'thewire:smsnumber' => "Your SMS number if different from your mobile number (mobile number must be set to public for the wire to be able to use it). All phone numbers must be in international format.", - 'thewire:channelsms' => "The number to send SMS messages to is %s", - - ); - - add_translation("en",$english); + /** + * Menu items and titles + */ + 'thewire' => "The Wire", + 'thewire:everyone' => "All wire posts", + 'thewire:user' => "%s's wire posts", + 'thewire:friends' => "Friends' wire posts", + 'thewire:reply' => "Reply", + 'thewire:replying' => "Replying to %s who wrote", + 'thewire:thread' => "Thread", + 'thewire:previous' => "Previous", + 'thewire:charleft' => "characters remaining", + 'thewire:tags' => "Wire posts tagged with '%s'", + 'thewire:noposts' => "No wire posts yet", -?> + /** + * The wire river + */ + 'thewire:river:create' => "posted to the wire", + + /** + * Wire widget + */ + 'thewire:widget:desc' => 'Display your latest wire posts', + 'thewire:num' => 'Number of posts to display', + 'thewire:moreposts' => 'More wire posts', + + /** + * Status messages + */ + '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:notdeleted' => "Sorry. We could not delete this wire post.", + +); + +add_translation("en", $english); diff --git a/mod/thewire/manifest.xml b/mod/thewire/manifest.xml index 563b28152..47fc97846 100644 --- a/mod/thewire/manifest.xml +++ b/mod/thewire/manifest.xml @@ -1,13 +1,12 @@ The Wire - Curverider + Curverider and JHU/APL 1.8 - Provides a microblogging service for your Elgg site. + Microblogging for Elgg http://www.elgg.org/ - (C) Curverider 2008-2010 + (C) Curverider 2008-2010 JHU/APL 2011 GNU Public License version 2 - smsclient elgg_version 2010030101 diff --git a/mod/thewire/pages/everyone.php b/mod/thewire/pages/everyone.php new file mode 100644 index 000000000..75abd282d --- /dev/null +++ b/mod/thewire/pages/everyone.php @@ -0,0 +1,29 @@ + 'object', + 'subtype' => 'thewire', + 'limit' => 15, +)); + +$body = elgg_view_layout('content', array( + 'filter_context' => 'all', + 'content' => $content, + 'title' => $title, + 'buttons' => false, +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/pages/friends.php b/mod/thewire/pages/friends.php new file mode 100644 index 000000000..239359ec2 --- /dev/null +++ b/mod/thewire/pages/friends.php @@ -0,0 +1,23 @@ +name, "pg/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/previous.php b/mod/thewire/pages/previous.php new file mode 100644 index 000000000..05fc3267e --- /dev/null +++ b/mod/thewire/pages/previous.php @@ -0,0 +1,11 @@ + $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/tag.php b/mod/thewire/pages/tag.php new file mode 100644 index 000000000..7e62a33de --- /dev/null +++ b/mod/thewire/pages/tag.php @@ -0,0 +1,36 @@ + + */ + +$tag = get_input('tag'); +if (!$tag) { + forward('pg/thewire/all'); +} + +elgg_push_breadcrumb(elgg_echo('thewire'), 'pg/thewire/all'); +elgg_push_breadcrumb('#' . $tag); + +// remove # from tag +$tag = trim($tag, '# '); + +$title = elgg_echo('thewire:tags', array($tag)); + + +$content = elgg_list_entities_from_metadata(array( + 'metadata_name' => 'tags', + 'metadata_value' => $tag, + 'metadata_case_sensitive' => false, + 'type' => 'object', + 'subtype' => 'thewire', + 'limit' => 15, +)); + +$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/thread.php b/mod/thewire/pages/thread.php new file mode 100644 index 000000000..49ca3afd1 --- /dev/null +++ b/mod/thewire/pages/thread.php @@ -0,0 +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); diff --git a/mod/thewire/pages/user.php b/mod/thewire/pages/user.php new file mode 100644 index 000000000..cc966697f --- /dev/null +++ b/mod/thewire/pages/user.php @@ -0,0 +1,33 @@ +name)); + +elgg_push_breadcrumb(elgg_echo('thewire'), "pg/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, +)); + +echo elgg_view_page($title, $body); diff --git a/mod/thewire/readme.txt b/mod/thewire/readme.txt deleted file mode 100644 index 0971ee4a8..000000000 --- a/mod/thewire/readme.txt +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Elgg the wire - * - * @package ElggTheWire - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 - * @author Curverider - * @copyright Curverider Ltd 2008-2009 - * @link http://elgg.com/ -*/ - -This is a twitter style, short message service that allows users to post notes to the wire. - -Install: Just drop it into the mod directory and that should be it. \ No newline at end of file diff --git a/mod/thewire/start.php b/mod/thewire/start.php index 2ae5c53e8..c2c0f491d 100644 --- a/mod/thewire/start.php +++ b/mod/thewire/start.php @@ -1,242 +1,358 @@ -subtype = 'thewire'; - $obj->owner_guid = $user->guid; - $obj->access_id = ACCESS_PUBLIC; - $obj->method = 'api'; - $obj->description = elgg_substr(strip_tags($text), 0, 140); - - $guid = $obj->save(); - - add_to_river('river/object/thewire/create', - 'create', - $user->guid, - $obj->guid - ); - - return 'success'; -} - - - - - /** - * Elgg wire plugin - * The wire is simple twitter like plugin that allows users to post notes to the wire - * - * @package ElggTheWire - */ - - /** - * thewire initialisation - * - * These parameters are required for the event API, but we won't use them: - * - * @param unknown_type $event - * @param unknown_type $object_type - * @param unknown_type $object - */ - - function thewire_init() { - - expose_function('wire.post', - 'rest_wire_post', - array( 'username' => array ('type' => 'string'), - 'text' => array ('type' => 'string'), - ), - 'Post a status update to the wire', - 'POST', - false, - false); - -// Set up menu for logged in users - $item = new ElggMenuItem('thewire', elgg_echo('thewire:title'), 'pg/thewire'); - elgg_register_menu_item('site', $item); - - // Extend system CSS with our own styles, which are defined in the thewire/css view - elgg_extend_view('css/screen', 'thewire/css'); - - //extend views - elgg_extend_view('profile/status', 'thewire/profile_status'); - - // Register a page handler, so we can have nice URLs - register_page_handler('thewire','thewire_page_handler'); - - // Register a URL handler for thewire posts - register_entity_url_handler('thewire_url','object','thewire'); - - // Your thewire widget - elgg_register_widget_type('thewire',elgg_echo("thewire:read"),elgg_echo("thewire:yourdesc")); - - // Register entity type - register_entity_type('object','thewire'); - - // Listen for SMS create event - elgg_register_event_handler('create','object','thewire_incoming_sms'); - - // Register granular notification for this type - if (is_callable('register_notification_object')) - register_notification_object('object', 'thewire', elgg_echo('thewire:newpost')); - - // Listen to notification events and supply a more useful message for SMS' - elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'thewire_notify_message'); - - $action_path = elgg_get_plugins_path() . 'thewire/actions'; - elgg_register_action("thewire/add", "$action_path/add.php"); - elgg_register_action("thewire/delete", "$action_path/delete.php"); - } - - function thewire_pagesetup() { - - $base_url = elgg_get_site_url(); - - //add submenu options - if (elgg_get_context() == "thewire") { - if ((elgg_get_page_owner_guid() == elgg_get_logged_in_user_guid() || !elgg_get_page_owner_guid()) && elgg_is_logged_in()) { - add_submenu_item(elgg_echo('thewire:read'),"{$base_url}pg/thewire/" . elgg_get_logged_in_user_entity()->username); - add_submenu_item(elgg_echo('thewire:everyone'),"{$base_url}mod/thewire/everyone.php"); - } - } - - } - - /** - * thewire page handler; allows the use of fancy URLs - * - * @param array $page From the page_handler function - * @return true|false Depending on success - */ - function thewire_page_handler($page) { - - // The first component of a thewire URL is the username - if (isset($page[0])) { - set_input('username',$page[0]); - } - - // The second part dictates what we're doing - if (isset($page[1])) { - switch($page[1]) { - case "friends": // TODO: add friends thewire page here - break; - } - // If the URL is just 'thewire/username', or just 'thewire/', load the standard thewire index - } else { - require(dirname(__FILE__) . "/index.php"); - return true; - } - - return false; - - } - - function thewire_url($thewirepost) { - return "pg/thewire/" . $thewirepost->getOwnerEntity()->username; - } - - /** - * Returns a more meaningful message for SMS messages. - * - * @param unknown_type $hook - * @param unknown_type $entity_type - * @param unknown_type $returnvalue - * @param unknown_type $params - */ - function thewire_notify_message($hook, $entity_type, $returnvalue, $params) - { - $entity = $params['entity']; - $to_entity = $params['to_entity']; - $method = $params['method']; - if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'thewire')) - { - $descr = $entity->description; - if ($method == 'sms') { - $owner = $entity->getOwnerEntity(); - return $owner->username . ': ' . $descr; - } - if ($method == 'email') { - $owner = $entity->getOwnerEntity(); - return $owner->username . ': ' . $descr . "\n\n" . $entity->getURL(); - } - } - return null; - } - - /** - * Create a new wire post. - * - * @param string $post The post - * @param int $access_id Public/private etc - * @param int $parent Parent post (if any) - * @param string $method The method (default: 'site') - * @return bool - */ - function thewire_save_post($post, $access_id, $parent=0, $method = "site") - { - - global $SESSION; - - // Initialise a new ElggObject - $thewire = new ElggObject(); - - // Tell the system it's a thewire post - $thewire->subtype = "thewire"; - - // Set its owner to the current user - $thewire->owner_guid = elgg_get_logged_in_user_guid(); - - // For now, set its access to public (we'll add an access dropdown shortly) - $thewire->access_id = $access_id; - - // Set its description appropriately - $thewire->description = elgg_substr(strip_tags($post), 0, 160); - - // add some metadata - $thewire->method = $method; //method, e.g. via site, sms etc - $thewire->parent = $parent; //used if the note is a reply - - //save - $save = $thewire->save(); - - if($save) - add_to_river('river/object/thewire/create','create',$SESSION['user']->guid,$thewire->guid); - - return $save; - - } - - /** - * Listen and process incoming SMS' - */ - function thewire_incoming_sms($event, $object_type, $object) - { - if (($object) && ($object->subtype == get_subtype_id('object', 'sms'))) - { - // Get user from phone number - if ((elgg_is_active_plugin('smsclient')) && (elgg_is_active_plugin('smslogin'))) - { - // By this stage the owner should be logged in (requires SMS Login) - if (thewire_save_post($object->description, get_default_access(), 0, 'sms')) - return false; - - } - } - - return true; // always create the shout even if it can't be sent - } - - // Make sure the thewire initialisation function is called on initialisation - elgg_register_event_handler('init','system','thewire_init'); - elgg_register_event_handler('pagesetup','system','thewire_pagesetup'); - - - -?> +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: + * pg/thewire/all View site wire posts + * pg/thewire/owner/ View this user's wire posts + * pg/thewire/following/ View the posts of those this user follows + * pg/thewire/reply/ Reply to a post + * pg/thewire/view/ View a conversation thread + * pg/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) { + + // if just pg/thewire/ go to global view in the else statement + if (isset($page[0]) && $page[0]) { + + switch ($page[0]) { + case "all": + include dirname(__FILE__) . "/pages/everyone.php"; + break; + + case "friends": + if (isset($page[1])) { + set_input('username', $page[1]); + } + include dirname(__FILE__) . "/pages/friends.php"; + break; + + case "owner": + if (isset($page[1])) { + set_input('username', $page[1]); + } + include dirname(__FILE__) . "/pages/user.php"; + break; + + case "thread": + if (isset($page[1])) { + set_input('thread_id', $page[1]); + } + include dirname(__FILE__) . "/pages/thread.php"; + break; + case "reply": + if (isset($page[1])) { + set_input('guid', $page[1]); + } + include dirname(__FILE__) . "/pages/reply.php"; + break; + case "tag": + if (isset($page[1])) { + set_input('tag', $page[1]); + } + include dirname(__FILE__) . "/pages/tag.php"; + break; + case "previous": + if (isset($page[1])) { + set_input('guid', $page[1]); + } + include dirname(__FILE__) . "/pages/previous.php"; + break; + } + } else { + include dirname(__FILE__) . "/pages/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 . "pg/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}pg/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; +} + +/** + * Runs unit tests for the wire + */ +function thewire_test($hook, $type, $value, $params) { + global $CONFIG; + $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php'; + return $value; +} \ No newline at end of file diff --git a/mod/thewire/tests/regex.php b/mod/thewire/tests/regex.php new file mode 100644 index 000000000..9e187cf29 --- /dev/null +++ b/mod/thewire/tests/regex.php @@ -0,0 +1,271 @@ +ia = elgg_set_ignore_access(TRUE); + parent::__construct(); + + // all __construct() code should come after here + } + + /** + * Called before each test method. + */ + public function setUp() { + + } + + /** + * Called after each test method. + */ + public function tearDown() { + // do not allow SimpleTest to interpret Elgg notices as exceptions + $this->swallowErrors(); + } + + /** + * Called after each test object. + */ + public function __destruct() { + elgg_set_ignore_access($this->ia); + // all __destruct() code should go above here + parent::__destruct(); + } + + protected function getUserWireLink($username) { + global $CONFIG; + return "wwwroot}pg/thewire/owner/$username\">@$username"; + } + + protected function getHashtagLink($tag) { + global $CONFIG; + return "wwwroot}pg/thewire/tag/$tag\">#$tag"; + } + + protected function getEmailLink($address) { + return "$address"; + } + + protected function getLink($address) { + return parse_urls($address); + } + + /** + * Usernames: @user + */ + public function testReplaceUsernames() { + // beginning of text + $text = "@user test"; + $expected = $this->getUserWireLink('user') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // after space + $text = "test @user test"; + $expected = "test " . $this->getUserWireLink('user') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by comma + $text = "test @user, test"; + $expected = "test " . $this->getUserWireLink('user') . ", test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // preceded by comma + $text = "test ,@user test"; + $expected = "test ," . $this->getUserWireLink('user') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // include digit + $text = "@3user test"; + $expected = $this->getUserWireLink('3user') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // include underscore + $text = "@user_name test"; + $expected = $this->getUserWireLink('user_name') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // parentheses + $text = "test (@user) test"; + $expected = "test (" . $this->getUserWireLink('user') . ") test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + } + + /** + * Hashtags: #tag + */ + public function testReplaceHashtags() { + // tag at beginning + $text = "#tag test"; + $expected = $this->getHashtagLink('tag') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // tag not at beginning + $text = "test #tag test"; + $expected = "test " . $this->getHashtagLink('tag') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by comma + $text = "test #tag, test"; + $expected = "test " . $this->getHashtagLink('tag') . ", test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // preceded by comma + $text = "test,#tag test"; + $expected = "test," . $this->getHashtagLink('tag') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by period + $text = "test #tag. test"; + $expected = "test " . $this->getHashtagLink('tag') . ". test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // parentheses + $text = "test (#tag) test"; + $expected = "test (" . $this->getHashtagLink('tag') . ") test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // include number + $text = "test #tag2000 test"; + $expected = "test " . $this->getHashtagLink('tag2000') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // cannot be just a number + $text = "test #1 test"; + $expected = $text; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); +} + + /** + * Email: johndoe@gmail.com + */ + public function testReplaceEmailAddress() { + // email at beginning of text + $text = "test@test.com test"; + $expected = $this->getEmailLink('test@test.com') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // after space + $text = "test test@test.com test"; + $expected = "test " . $this->getEmailLink('test@test.com') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by comma + $text = "test test@test.com, test"; + $expected = "test " . $this->getEmailLink('test@test.com') . ", test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // preceded by comma + $text = "test,test@test.com test"; + $expected = "test," . $this->getEmailLink('test@test.com') . " test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by period + $text = "test test@test.com. test"; + $expected = "test " . $this->getEmailLink('test@test.com') . ". test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // parentheses + $text = "test (test@test.com) test"; + $expected = "test (" . $this->getEmailLink('test@test.com') . ") test"; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // includes digits + $text = "user1@domain1.com"; + $expected = $this->getEmailLink('user1@domain1.com'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // includes underscore + $text = "user_name@domain.com"; + $expected = $this->getEmailLink('user_name@domain.com'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // includes period + $text = "user.name@domain.com"; + $expected = $this->getEmailLink('user.name@domain.com'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // includes subdomains + $text = "user.name@domain.com.uk"; + $expected = $this->getEmailLink('user.name@domain.com.uk'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + } + + /** + * Links: http://www.example.org/ + */ + public function testReplaceLinks() { + // beginning of text + $text = "http://www.test.org"; + $expected = $this->getLink('http://www.test.org'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // not at beginning of text + $text = "test http://www.test.org"; + $expected = 'test ' . $this->getLink('http://www.test.org'); + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by comma + $text = "test http://www.test.org, test"; + $expected = 'test ' . $this->getLink('http://www.test.org') . ', test'; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // preceeded by comma + $text = "test,http://www.test.org test"; + $expected = 'test,' . $this->getLink('http://www.test.org') . ' test'; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // followed by period + $text = "test http://www.test.org. test"; + $expected = 'test ' . $this->getLink('http://www.test.org') . '. test'; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // surrounded by parentheses + $text = "test (http://www.test.org) test"; + $expected = 'test (' . $this->getLink('http://www.test.org') . ') test'; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + + // no http:// + $text = "test www.test.org test"; + $expected = 'test ' . $this->getLink('www.test.org') . ' test'; + $result = thewire_filter($text); + $this->assertEqual($result, $expected); + } + +} diff --git a/mod/thewire/views/default/forms/thewire/add.php b/mod/thewire/views/default/forms/thewire/add.php new file mode 100644 index 000000000..e34a8c0e5 --- /dev/null +++ b/mod/thewire/views/default/forms/thewire/add.php @@ -0,0 +1,64 @@ + 'parent_guid', + 'value' => $post->guid, + )); +} +?> + +
+ 140 +
+ $text, + 'internalid' => 'thewire-submit-button', +)); + +?> + diff --git a/mod/thewire/views/default/object/thewire.php b/mod/thewire/views/default/object/thewire.php index d15454815..603870153 100644 --- a/mod/thewire/views/default/object/thewire.php +++ b/mod/thewire/views/default/object/thewire.php @@ -1,69 +1,53 @@ getOwnerEntity()->name; +$full = elgg_get_array_value('full', $vars, FALSE); +$post = elgg_get_array_value('entity', $vars, FALSE); - //if the note is a reply, we need some more info - $note_url = ''; - $note_owner = elgg_echo("thewire:notedeleted"); -?> -
-
+if (!$post) { + return true; +} + +// make compatible with posts created with original Curverider plugin +$thread_id = $post->wire_thread; +if (!$thread_id) { + $post->wire_thread = $post->guid; +} -
- $vars['entity']->getOwnerEntity(), 'size' => 'tiny')); - ?> -
+$owner = $post->getOwnerEntity(); -
- - - canEdit()) { - echo "" . elgg_view("output/confirmlink",array( - 'href' => "action/thewire/delete?thewirepost=" . $vars['entity']->getGUID(), - 'text' => elgg_echo('delete'), - 'confirm' => elgg_echo('deleteconfirm'), - )) . ""; - } - ?> -
+$owner_icon = elgg_view_entity_icon($owner, 'tiny'); +$owner_link = elgg_view('output/url', array( + 'href' => "pg/thewire/owner/$owner->username", + 'text' => $owner->name, +)); +$author_text = elgg_echo('blog:author_by_line', array($owner_link)); +$date = elgg_view_friendly_time($post->time_created); - -
-
- $post, + 'handler' => 'thewire', +)); + +$subtitle = "$author_text $date"; + +// do not show the metadata and controls in widget view +if (elgg_in_context('widgets')) { + $metadata = ''; } -?> \ No newline at end of file + +$params = array( + 'entity' => $post, + 'metadata' => $metadata, + 'subtitle' => $subtitle, + 'content' => thewire_filter($post->description), + 'tags' => false, +); +$list_body = elgg_view('layout/objects/list/body', $params); + +echo elgg_view_image_block($owner_icon, $list_body); diff --git a/mod/thewire/views/default/river/object/thewire/create.php b/mod/thewire/views/default/river/object/thewire/create.php index b1142e0f4..d4dac38ee 100644 --- a/mod/thewire/views/default/river/object/thewire/create.php +++ b/mod/thewire/views/default/river/object/thewire/create.php @@ -5,7 +5,7 @@ $object = $vars['item']->getObjectEntity(); $excerpt = strip_tags($object->description); -$excerpt = elgg_get_excerpt($excerpt); +$excerpt = thewire_filter($excerpt); $params = array( 'href' => $object->getURL(), diff --git a/mod/thewire/views/default/thewire/css.php b/mod/thewire/views/default/thewire/css.php index d7beac105..c1c7b5bcb 100644 --- a/mod/thewire/views/default/thewire/css.php +++ b/mod/thewire/views/default/thewire/css.php @@ -1,12 +1,36 @@ +/******************************** + The Wire +*********************************/ +#thewire-textarea { + height: 40px; + padding: 6px; +} +#thewire-characters-remaining { + text-align: right; + float: right; + font-weight: bold; + color: #333333; +} +.thewire-characters-remaining { + color:#333333; + border:none; + font-size: 100%; + font-weight: bold; + padding:0 2px 0 0; + margin:0; + text-align: right; + background: white; +} + + /* new wire post form */ .new_wire_post { margin:10px 0 15px 0; diff --git a/mod/thewire/views/default/thewire/forms/add.php b/mod/thewire/views/default/thewire/forms/add.php deleted file mode 100644 index 3ad968b3b..000000000 --- a/mod/thewire/views/default/thewire/forms/add.php +++ /dev/null @@ -1,31 +0,0 @@ - -
-

- - -
- {$msg}"; - $display .= ""; - $display .= "
"; - echo $display; - echo elgg_echo("thewire:charleft") . "
"; - echo elgg_view('input/securitytoken'); - ?> - -
-
- \ No newline at end of file diff --git a/mod/thewire/views/default/thewire/metadata.php b/mod/thewire/views/default/thewire/metadata.php new file mode 100644 index 000000000..f04345ed2 --- /dev/null +++ b/mod/thewire/views/default/thewire/metadata.php @@ -0,0 +1,56 @@ + + \ No newline at end of file diff --git a/mod/thewire/views/default/thewire/notfound.php b/mod/thewire/views/default/thewire/notfound.php deleted file mode 100644 index a3d08fe18..000000000 --- a/mod/thewire/views/default/thewire/notfound.php +++ /dev/null @@ -1,17 +0,0 @@ - - -

- -

\ No newline at end of file diff --git a/mod/thewire/views/default/thewire/profile_status.php b/mod/thewire/views/default/thewire/profile_status.php index 29dc69329..9ff0c4d59 100644 --- a/mod/thewire/views/default/thewire/profile_status.php +++ b/mod/thewire/views/default/thewire/profile_status.php @@ -1,12 +1,11 @@ guid; -$url_to_wire = elgg_get_site_url() . "pg/thewire/" . $vars['entity']->username; - +$url_to_wire = elgg_get_site_url() . "pg/thewire/owner/" . $vars['entity']->username; + //grab the user's latest from the wire $params = array( 'types' => 'object', @@ -16,11 +15,10 @@ $params = array( ); $latest_wire = elgg_get_entities($params); -if ($latest_wire) { - foreach ($latest_wire as $lw) { - $content = $lw->description; - $time = "

(" . elgg_view_friendly_time($lw->time_created) . ")

"; - } +if ($latest_wire && count($latest_wire) > 0) { + $latest_wire = $latest_wire[0]; + $content = thewire_filter($latest_wire->description); + $time = "

(" . elgg_view_friendly_time($latest_wire->time_created) . ")

"; echo "
"; echo $content; diff --git a/mod/thewire/views/default/thewire/reply.php b/mod/thewire/views/default/thewire/reply.php new file mode 100644 index 000000000..3794e1454 --- /dev/null +++ b/mod/thewire/views/default/thewire/reply.php @@ -0,0 +1,11 @@ +getOwnerEntity(); + +?> +name)); ?>: +description; \ No newline at end of file diff --git a/mod/thewire/views/default/thewire/view.php b/mod/thewire/views/default/thewire/view.php deleted file mode 100644 index 725643cd1..000000000 --- a/mod/thewire/views/default/thewire/view.php +++ /dev/null @@ -1,23 +0,0 @@ - 0) { - - foreach($vars['entity'] as $shout) { - - echo elgg_view_entity($shout); - - } - - } - -?> \ No newline at end of file diff --git a/mod/thewire/views/default/widgets/thewire/content.php b/mod/thewire/views/default/widgets/thewire/content.php index 6de5f1e64..a8471a4b1 100644 --- a/mod/thewire/views/default/widgets/thewire/content.php +++ b/mod/thewire/views/default/widgets/thewire/content.php @@ -1,15 +1,29 @@ num_display; -if (!$num) { - $num = 4; -} -$content = elgg_list_entities(array('types' => 'object', 'subtypes' => 'thewire', 'container_guid' => $vars['entity']->owner_guid, 'limit' => $num, 'full_view' => FALSE, 'pagination' => FALSE)); +$options = array( + 'type' => 'object', + 'subtype' => 'thewire', + 'container_guid' => $vars['entity']->owner_guid, + 'limit' => $num, + 'full_view' => FALSE, + 'pagination' => FALSE, +); +$content = elgg_list_entities($options); echo $content; if ($content) { - $blogurl = elgg_get_site_url() . "pg/thewire/" . elgg_get_page_owner_entity()->username; - echo ""; + $owner_url = "pg/thewire/owner/" . elgg_get_page_owner_entity()->username; + $more_link = elgg_view('output/url', array( + 'href' => $owner_url, + 'text' => elgg_echo('thewire:moreposts'), + )); + echo "$more_link"; +} else { + echo elgg_echo('thewire:noposts'); } diff --git a/mod/thewire/views/default/widgets/thewire/edit.php b/mod/thewire/views/default/widgets/thewire/edit.php index 969015ab8..8c93383ad 100644 --- a/mod/thewire/views/default/widgets/thewire/edit.php +++ b/mod/thewire/views/default/widgets/thewire/edit.php @@ -1,22 +1,22 @@ num_display)) { $vars['entity']->num_display = 4; } -?> -

- - -

\ No newline at end of file +
+ : + +
-- cgit v1.2.3