]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
a mostly completed port of JHU/APL wire plugin to 1.8
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 22:41:25 +0000 (22:41 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 12 Feb 2011 22:41:25 +0000 (22:41 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8183 36083f99-b078-4883-b0ff-0f9b5a30f544

29 files changed:
mod/thewire/actions/add.php
mod/thewire/actions/delete.php
mod/thewire/add.php [deleted file]
mod/thewire/everyone.php [deleted file]
mod/thewire/index.php [deleted file]
mod/thewire/languages/en.php
mod/thewire/manifest.xml
mod/thewire/pages/everyone.php [new file with mode: 0644]
mod/thewire/pages/friends.php [new file with mode: 0644]
mod/thewire/pages/previous.php [new file with mode: 0644]
mod/thewire/pages/reply.php [new file with mode: 0644]
mod/thewire/pages/tag.php [new file with mode: 0644]
mod/thewire/pages/thread.php [new file with mode: 0644]
mod/thewire/pages/user.php [new file with mode: 0644]
mod/thewire/readme.txt [deleted file]
mod/thewire/start.php
mod/thewire/tests/regex.php [new file with mode: 0644]
mod/thewire/views/default/forms/thewire/add.php [new file with mode: 0644]
mod/thewire/views/default/object/thewire.php
mod/thewire/views/default/river/object/thewire/create.php
mod/thewire/views/default/thewire/css.php
mod/thewire/views/default/thewire/forms/add.php [deleted file]
mod/thewire/views/default/thewire/metadata.php [new file with mode: 0644]
mod/thewire/views/default/thewire/notfound.php [deleted file]
mod/thewire/views/default/thewire/profile_status.php
mod/thewire/views/default/thewire/reply.php [new file with mode: 0644]
mod/thewire/views/default/thewire/view.php [deleted file]
mod/thewire/views/default/widgets/thewire/content.php
mod/thewire/views/default/widgets/thewire/edit.php

index 04aa2bc82076c5598f24d374d802c9eb42b84941..f32f7e555c5e1a110fe73f9f75a60a31a97d9268 100644 (file)
@@ -1,41 +1,33 @@
-<?php
-
-/**
- * Elgg thewire: add shout action
- *
- * @package Elggthewire
- */
-
-// Make sure we're logged in (send us to the front page if not)
-if (!elgg_is_logged_in()) forward();
-
-// Get input data
-$body = get_input('new_post_textarea');
-$access_id = (int)get_default_access();
-if ($access_id == ACCESS_PRIVATE) {
-       $access_id = ACCESS_LOGGED_IN; // Private wire messages are pointless
-}
-$method = get_input('method');
-$parent = (int)get_input('parent', 0);
-if (!$parent) {
-       $parent = 0;
-}
-// Make sure the body isn't blank
-if (empty($body)) {
-       register_error(elgg_echo("thewire:blank"));
-       forward("mod/thewire/add.php");
-}
-
-if (!thewire_save_post($body, $access_id, $parent, $method)) {
-       register_error(elgg_echo("thewire:error"));
-       forward("mod/thewire/add.php");
-}
-
-
-// Success message
-system_message(elgg_echo("thewire:posted"));
-
-// Forward
-forward("mod/thewire/everyone.php");
-
-?>
+<?php\r
+/**\r
+ * Action for adding a wire post\r
+ * \r
+ */\r
+\r
+// Get input data\r
+$body = get_input('body', '', false); // don't filter since we strip and filter escapes some characters\r
+$access_id = ACCESS_PUBLIC;\r
+$method = 'site';\r
+$parent_guid = (int) get_input('parent_guid');\r
+\r
+// make sure the post isn't blank\r
+if (empty($body)) {\r
+       register_error(elgg_echo("thewire:blank"));\r
+       forward(REFERER);\r
+}\r
+\r
+$guid = thewire_save_post($body, get_loggedin_userid(), $access_id, $parent_guid, $method);\r
+if (!$guid) {\r
+       register_error(elgg_echo("thewire:error"));\r
+       forward(REFERER);\r
+}\r
+\r
+// Send response to original poster if not already registered to receive notification\r
+if ($parent_guid) {\r
+       thewire_send_response_notification($guid, $parent_guid, $user);\r
+       $parent = get_entity($parent_guid);\r
+       forward("pg/thewire/thread/$parent->wire_thread");\r
+}\r
+\r
+system_message(elgg_echo("thewire:posted"));\r
+forward(REFERER);\r
index 849433e0f8537ba371162a4c5068bcbc473cb477..7758b4b03abd128f7571539585c1ae67746acd39 100644 (file)
@@ -1,34 +1,39 @@
-<?php
-
-       /**
-        * Elgg thewire: delete note action
-        * 
-        * @package ElggTheWire
-        */
-
-       // Make sure we're logged in (send us to the front page if not)
-               if (!elgg_is_logged_in()) forward();
-
-       // Get input data
-               $guid = (int) get_input('thewirepost');
-               
-       // Make sure we actually have permission to edit
-               $thewire = get_entity($guid);
-               if ($thewire->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
+<?php\r
+/**\r
+ * Action for deleting a wire post\r
+ * \r
+ */\r
+\r
+// Get input data\r
+$guid = (int) get_input('guid');\r
+\r
+// Make sure we actually have permission to edit\r
+$thewire = get_entity($guid);\r
+if ($thewire->getSubtype() == "thewire" && $thewire->canEdit()) {\r
+\r
+       // unset reply metadata on children\r
+       $children = elgg_get_entities_from_relationship(array(\r
+               'relationship' => 'parent',\r
+               'relationship_guid' => $post_guid,\r
+               'inverse_relationship' => true,\r
+       ));\r
+       if ($children) {\r
+               foreach ($children as $child) {\r
+                       $child->reply = false;\r
+               }\r
+       }\r
+\r
+       // Get owning user\r
+       $owner = get_entity($thewire->getOwner());\r
+\r
+       // Delete it\r
+       $rowsaffected = $thewire->delete();\r
+       if ($rowsaffected > 0) {\r
+               // Success message\r
+               system_message(elgg_echo("thewire:deleted"));\r
+       } else {\r
+               register_error(elgg_echo("thewire:notdeleted"));\r
+       }\r
+\r
+       forward("pg/thewire/owner/" . $owner->username);\r
+}\r
diff --git a/mod/thewire/add.php b/mod/thewire/add.php
deleted file mode 100644 (file)
index a63a101..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-
-       /**
-        * Elgg thewire add entry page
-        * 
-        * @package ElggTheWire
-        *
-        */
-
-       // Load Elgg engine
-               require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-               
-       // If we're not logged in, forward to the front page
-               if (!elgg_is_logged_in()) forward(); 
-               
-       // choose the required canvas layout and items to display
-           $area2 = elgg_view_title(elgg_echo('thewire:add'));
-           $area2 .= elgg_view("thewire/forms/add");
-           
-           $body = elgg_view_layout("one_sidebar", array('content' => $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 (file)
index 05793ed..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-       /**
-        * Elgg view all thewire posts from all users page
-        * 
-        * @package ElggTheWire
-        */
-
-       // Load Elgg engine
-               require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-               
-               $area2 = elgg_view_title(elgg_echo("thewire:everyone"));
-               
-               //add form
-               if (elgg_is_logged_in()) {
-                       $area2 .= elgg_view("thewire/forms/add");
-               }
-               $offset = (int)get_input('offset', 0);
-               $area2 .= elgg_list_entities(array('types' => '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 (file)
index 7ed43e3..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-       /**
-        * Elgg thewire index page
-        *
-        * @package Elggthewire
-        */
-
-       // Load Elgg engine
-               require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
-
-       // Get the current page's owner
-               $page_owner = elgg_get_page_owner_entity();
-               if ($page_owner === false || is_null($page_owner)) {
-                       $page_owner = elgg_get_logged_in_user_entity();
-                       set_page_owner($page_owner->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
index 581ac5506bd40da9ca0a43ea1e308a6ebe9bd677..8978c67398c49b9502dafb215b65aaa441682905 100644 (file)
@@ -1,82 +1,46 @@
 <?php
+/**
+ * The Wire English language file
+ */
 
-       $english = array(
-       
-               /**
-                * Menu items and titles
-                */
-       
-                       'thewire:title' => "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 <b>%s</b>",
-                       
-       );
-                                       
-       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);
index 563b28152e34b828acc81033b310f8daa8bcc7bc..47fc97846398926d5a50a298800f36c41d2bc4a3 100644 (file)
@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
        <name>The Wire</name>
-       <author>Curverider</author>
+       <author>Curverider and JHU/APL</author>
        <version>1.8</version>
-       <description>Provides a microblogging service for your Elgg site.</description>
+       <description>Microblogging for Elgg</description>
        <website>http://www.elgg.org/</website>
-       <copyright>(C) Curverider 2008-2010</copyright>
+       <copyright>(C) Curverider 2008-2010 JHU/APL 2011</copyright>
        <license>GNU Public License version 2</license>
-       <recommends>smsclient</recommends>
        <requires>
                <type>elgg_version</type>
                <version>2010030101</version>
diff --git a/mod/thewire/pages/everyone.php b/mod/thewire/pages/everyone.php
new file mode 100644 (file)
index 0000000..75abd28
--- /dev/null
@@ -0,0 +1,29 @@
+<?php\r
+/**\r
+ * All wire posts\r
+ * \r
+ */\r
+\r
+elgg_push_breadcrumb(elgg_echo('thewire'));\r
+\r
+$title = elgg_echo('thewire:everyone');\r
+\r
+if (elgg_is_logged_in()) {\r
+       $content .= elgg_view_form('thewire/add');\r
+       $content .= elgg_view('input/urlshortener');\r
+}\r
+\r
+$content .= elgg_list_entities(array(\r
+       'type' => 'object',\r
+       'subtype' => 'thewire',\r
+       'limit' => 15,\r
+));\r
+\r
+$body = elgg_view_layout('content', array(\r
+       'filter_context' => 'all',\r
+       'content' => $content,\r
+       'title' => $title,\r
+       'buttons' => false,\r
+));\r
+\r
+echo elgg_view_page($title, $body);\r
diff --git a/mod/thewire/pages/friends.php b/mod/thewire/pages/friends.php
new file mode 100644 (file)
index 0000000..239359e
--- /dev/null
@@ -0,0 +1,23 @@
+<?php\r
+/**\r
+ * Wire posts of your friends\r
+ */\r
+\r
+$owner = elgg_get_page_owner_entity();\r
+\r
+$title = elgg_echo('thewire:friends');\r
+\r
+elgg_push_breadcrumb(elgg_echo('thewire'), "pg/thewire/all/");\r
+elgg_push_breadcrumb($owner->name, "pg/thewire/owner/$owner->username");\r
+elgg_push_breadcrumb(elgg_echo('friends'));\r
+\r
+$content = list_user_friends_objects($owner->guid, 'thewire', 15, false);\r
+\r
+$body = elgg_view_layout('content', array(\r
+       'filter_context' => 'friends',\r
+       'content' => $content,\r
+       'title' => $title,\r
+       'buttons' => false,\r
+));\r
+\r
+echo elgg_view_page($title, $body);\r
diff --git a/mod/thewire/pages/previous.php b/mod/thewire/pages/previous.php
new file mode 100644 (file)
index 0000000..05fc326
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Server up html for a post
+ */
+
+$guid = (int) get_input('guid');
+
+$parent = thewire_get_parent($guid);
+if ($parent) {
+       echo elgg_view_entity($parent);
+}
\ No newline at end of file
diff --git a/mod/thewire/pages/reply.php b/mod/thewire/pages/reply.php
new file mode 100644 (file)
index 0000000..e349761
--- /dev/null
@@ -0,0 +1,28 @@
+<?php\r
+/**\r
+ * Reply page\r
+ * \r
+ */\r
+\r
+gatekeeper();\r
+\r
+$post = get_entity(get_input('guid'));\r
+\r
+$title = elgg_echo('thewire:reply');\r
+\r
+elgg_push_breadcrumb(elgg_echo('thewire'), 'pg/thewire/all');\r
+elgg_push_breadcrumb($title);\r
+\r
+$content = elgg_view('thewire/reply', array('post' => $post));\r
+$content .= elgg_view_form('thewire/add', array(), array('post' => $post));\r
+$content .= elgg_view('input/urlshortener');\r
+\r
+\r
+$body = elgg_view_layout('content', array(\r
+       'filter' => false,\r
+       'content' => $content,\r
+       'title' => $title,\r
+       'buttons' => false,\r
+));\r
+\r
+echo elgg_view_page($title, $body);\r
diff --git a/mod/thewire/pages/tag.php b/mod/thewire/pages/tag.php
new file mode 100644 (file)
index 0000000..7e62a33
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Wire posts tagged with <tag>
+ */
+
+$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 (file)
index 0000000..49ca3af
--- /dev/null
@@ -0,0 +1,28 @@
+<?php\r
+/**\r
+ * View conversation thread\r
+ */\r
+\r
+$thread_id = get_input('thread_id');\r
+\r
+$title = elgg_echo('thewire:thread');\r
+\r
+elgg_push_breadcrumb(elgg_echo('thewire'), 'pg/thewire/all');\r
+elgg_push_breadcrumb($title);\r
+\r
+$content = elgg_list_entities_from_metadata(array(\r
+       "metadata_name" => "wire_thread",\r
+       "metadata_value" => $thread_id,\r
+       "type" => "object",\r
+       "subtype" => "thewire",\r
+       "limit" => 20,\r
+));\r
+\r
+$body = elgg_view_layout('content', array(\r
+       'filter' => false,\r
+       'content' => $content,\r
+       'title' => $title,\r
+       'buttons' => false,\r
+));\r
+\r
+echo elgg_view_page($title, $body);\r
diff --git a/mod/thewire/pages/user.php b/mod/thewire/pages/user.php
new file mode 100644 (file)
index 0000000..cc96669
--- /dev/null
@@ -0,0 +1,33 @@
+<?php\r
+/**\r
+ * User's wire posts\r
+ * \r
+ */\r
+\r
+$owner = elgg_get_page_owner_entity();\r
+\r
+$title = elgg_echo('thewire:user', array($owner->name));\r
+\r
+elgg_push_breadcrumb(elgg_echo('thewire'), "pg/thewire/all/");\r
+elgg_push_breadcrumb($owner->name);\r
+\r
+if (get_loggedin_userid() == $owner->guid) {\r
+       $content = elgg_view_form('thewire/add');\r
+       $content .= elgg_view('input/urlshortener');\r
+}\r
+\r
+$content .= elgg_list_entities(array(\r
+       'type' => 'object',\r
+       'subtype' => 'thewire',\r
+       'owner_guid' => $owner->guid,\r
+       'limit' => 15,\r
+));\r
+\r
+$body = elgg_view_layout('content', array(\r
+       'filter_context' => 'mine',\r
+       'content' => $content,\r
+       'title' => $title,\r
+       'buttons' => false,\r
+));\r
+\r
+echo elgg_view_page($title, $body);\r
diff --git a/mod/thewire/readme.txt b/mod/thewire/readme.txt
deleted file mode 100644 (file)
index 0971ee4..0000000
+++ /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 <info@elgg.com>
-        * @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
index 2ae5c53e8263c81149e26ee09d0594bc22baf7fb..c2c0f491d92965b6e9882e06aa83a9c5ccd29feb 100644 (file)
-<?php
-
-function rest_wire_post($username, $text) {
-       login(get_user(2));
-       
-    $user = get_user_by_username($username);
-    if (!$user) {
-        throw new InvalidParameterException('Bad username');
-    }
-
-    $obj = new ElggObject();
-    $obj->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');
-               
-
-               
-?>
+<?php\r
+/**\r
+ * Elgg wire plugin\r
+ * \r
+ * Forked from Curverider's version\r
+ * \r
+ * JHU/APL Contributors:\r
+ * Cash Costello\r
+ * Clark Updike\r
+ * John Norton\r
+ * Nathan Koterba\r
+ */\r
+\r
+register_elgg_event_handler('init', 'system', 'thewire_init');\r
+\r
+function thewire_init() {\r
+       global $CONFIG;\r
+\r
+       // add a site navigation item\r
+       $item = new ElggMenuItem('thewire', elgg_echo('thewire'), 'pg/thewire/all');\r
+       elgg_register_menu_item('site', $item);\r
+       \r
+       // Extend system CSS with our own styles, which are defined in the thewire/css view\r
+       elgg_extend_view('css', 'thewire/css');\r
+\r
+       //extend views\r
+       elgg_extend_view('activity/thewire', 'thewire/activity_view');\r
+       elgg_extend_view('profile/status', 'thewire/profile_status');\r
+       elgg_extend_view('js/initialise_elgg', 'thewire/js/textcounter');\r
+\r
+       // Register a page handler, so we can have nice URLs\r
+       register_page_handler('thewire', 'thewire_page_handler');\r
+\r
+       // Register a URL handler for thewire posts\r
+       register_entity_url_handler('thewire_url', 'object', 'thewire');\r
+\r
+       // Your thewire widget\r
+       add_widget_type('thewire', elgg_echo('thewire'), elgg_echo("thewire:widget:desc"));\r
+\r
+       // Register entity type\r
+       register_entity_type('object', 'thewire');\r
+\r
+       // Register granular notification for this type\r
+       register_notification_object('object', 'thewire', elgg_echo('thewire:notify:subject'));\r
+\r
+       // Listen to notification events and supply a more useful message\r
+       register_plugin_hook('notify:entity:message', 'object', 'thewire_notify_message');\r
+\r
+       // Register actions\r
+       $action_base = $CONFIG->pluginspath . 'thewire/actions';\r
+       register_action("thewire/add", false, "$action_base/add.php");\r
+       register_action("thewire/delete", false, "$action_base/delete.php");\r
+\r
+       register_plugin_hook('unit_test', 'system', 'thewire_test');\r
+}\r
+\r
+/**\r
+ * The wire page handler\r
+ *\r
+ * Supports:\r
+ * pg/thewire/all                  View site wire posts\r
+ * pg/thewire/owner/<username>     View this user's wire posts\r
+ * pg/thewire/following/<username> View the posts of those this user follows\r
+ * pg/thewire/reply/<guid>         Reply to a post\r
+ * pg/thewire/view/<guid>          View a conversation thread\r
+ * pg/thewire/tag/<tag>            View wire posts tagged with <tag>\r
+ *\r
+ * @param array $page From the page_handler function\r
+ * @return true|false Depending on success\r
+ */\r
+function thewire_page_handler($page) {\r
+\r
+       // if just pg/thewire/ go to global view in the else statement\r
+       if (isset($page[0]) && $page[0]) {\r
+\r
+               switch ($page[0]) {\r
+                       case "all":\r
+                               include dirname(__FILE__) . "/pages/everyone.php";\r
+                               break;\r
+\r
+                       case "friends":\r
+                               if (isset($page[1])) {\r
+                                       set_input('username', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/friends.php";\r
+                               break;\r
+\r
+                       case "owner":\r
+                               if (isset($page[1])) {\r
+                                       set_input('username', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/user.php";\r
+                               break;\r
+\r
+                       case "thread":\r
+                               if (isset($page[1])) {\r
+                                       set_input('thread_id', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/thread.php";\r
+                               break;\r
+                       case "reply":\r
+                               if (isset($page[1])) {\r
+                                       set_input('guid', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/reply.php";\r
+                               break;\r
+                       case "tag":\r
+                               if (isset($page[1])) {\r
+                                       set_input('tag', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/tag.php";\r
+                               break;\r
+                       case "previous":\r
+                               if (isset($page[1])) {\r
+                                       set_input('guid', $page[1]);\r
+                               }\r
+                               include dirname(__FILE__) . "/pages/previous.php";\r
+                               break;\r
+               }\r
+       } else {\r
+               include dirname(__FILE__) . "/pages/everyone.php";\r
+       }\r
+\r
+       return true;\r
+}\r
+\r
+/**\r
+ * Override the url for a wire post to return the thread\r
+ * \r
+ * @param $thewirepost - wire post object\r
+ */\r
+function thewire_url($thewirepost) {\r
+       global $CONFIG;\r
+       return $CONFIG->url . "pg/thewire/view/" . $thewirepost->guid;\r
+}\r
+\r
+/**\r
+ * Returns the notification body\r
+ *\r
+ * @param string $hook\r
+ * @param string $entity_type\r
+ * @param string $returnvalue\r
+ * @param array  $params\r
+ * @return $string\r
+ */\r
+function thewire_notify_message($hook, $entity_type, $returnvalue, $params) {\r
+       global $CONFIG;\r
+       \r
+       $entity = $params['entity'];\r
+       if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'thewire')) {\r
+               $descr = $entity->description;\r
+               $owner = $entity->getOwnerEntity();\r
+               if ($entity->reply) {\r
+                       // have to do this because of poor design of Elgg notification system\r
+                       $parent_post = get_entity(get_input('parent_guid'));\r
+                       if ($parent_post) {\r
+                               $parent_owner = $parent_post->getOwnerEntity();\r
+                       }\r
+                       $body = sprintf(elgg_echo('thewire:notify:reply'), $owner->name, $parent_owner->name);\r
+               } else {\r
+                       $body = sprintf(elgg_echo('thewire:notify:post'), $owner->name);\r
+               }\r
+               $body .= "\n\n" . $descr . "\n\n";\r
+               $body .= elgg_echo('thewire') . ": {$CONFIG->url}pg/thewire/";\r
+               return $body;\r
+       }\r
+       return $returnvalue;\r
+}\r
+\r
+/**\r
+ * Get an array of hashtags from a text string\r
+ * \r
+ * @param string $text\r
+ * @return array\r
+ */\r
+function thewire_get_hashtags($text) {\r
+       // beginning of text or white space followed by hashtag\r
+       // hashtag must begin with # and contain at least one character not digit, space, or punctuation\r
+       $matches = array();\r
+       preg_match_all('/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', $text, $matches);\r
+       return $matches[2];\r
+}\r
+\r
+/**\r
+ * Replace urls, hash tags, and @'s by links\r
+ * \r
+ * @param $text\r
+ * @return string\r
+ */\r
+function thewire_filter($text) {\r
+       global $CONFIG;\r
+\r
+       $text = ' ' . $text;\r
+\r
+       // email addresses\r
+       $text = preg_replace(\r
+                               '/(^|[^\w])([\w\-\.]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})/i',\r
+                               '$1<a href="mailto:$2@$3">$2@$3</a>',\r
+                               $text);\r
+\r
+       // links\r
+       $text = parse_urls($text);\r
+\r
+       // usernames\r
+       $text = preg_replace(\r
+                               '/(^|[^\w])@([\w]+)/',\r
+                               '$1<a href="' . $CONFIG->wwwroot . 'pg/thewire/owner/$2">@$2</a>',\r
+                               $text);\r
+\r
+       // hashtags\r
+       $text = preg_replace(\r
+                               '/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/',\r
+                               '$1<a href="' . $CONFIG->wwwroot . 'pg/thewire/tag/$2">#$2</a>',\r
+                               $text);\r
+\r
+       $text = trim($text);\r
+\r
+       return $text;\r
+}\r
+\r
+/**\r
+ * Create a new wire post.\r
+ *\r
+ * @param string $text        The post text\r
+ * @param int    $userid      The user's guid\r
+ * @param int    $access_id   Public/private etc\r
+ * @param int    $parent_guid Parent post guid (if any)\r
+ * @param string $method      The method (default: 'site')\r
+ * @return guid or false if failure\r
+ */\r
+function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site") {\r
+       $post = new ElggObject();\r
+\r
+       $post->subtype = "thewire";\r
+       $post->owner_guid = $userid;\r
+       $post->access_id = $access_id;\r
+\r
+       // only 200 characters allowed\r
+       $text = elgg_substr($text, 0, 200);\r
+\r
+       // no html tags allowed so we escape\r
+       $post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');\r
+\r
+       $post->method = $method; //method: site, email, api, ...\r
+\r
+       $tags = thewire_get_hashtags($text);\r
+       if ($tags) {\r
+               $post->tags = $tags;\r
+       }\r
+\r
+       // must do this before saving so notifications pick up that this is a reply\r
+       if ($parent_guid) {\r
+               $post->reply = true;\r
+       }\r
+\r
+       $guid = $post->save();\r
+\r
+       // set thread guid\r
+       if ($parent_guid) {\r
+               $post->addRelationship($parent_guid, 'parent');\r
+               \r
+                // name conversation threads by guid of first post (works even if first post deleted)\r
+               $parent_post = get_entity($parent_guid);\r
+               $post->wire_thread = $parent_post->wire_thread;\r
+       } else {\r
+               // first post in this thread\r
+               $post->wire_thread = $guid;\r
+       }\r
+\r
+       if ($guid) {\r
+               add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);\r
+       }\r
+       \r
+       return $guid;\r
+}\r
+\r
+/**\r
+ * Send notification to poster of parent post if not notified already\r
+ *\r
+ * @param int      $guid\r
+ * @param int      $parent_guid\r
+ * @param ElggUser $user\r
+ */\r
+function thewire_send_response_notification($guid, $parent_guid, $user) {\r
+       $parent_owner = get_entity($parent_guid)->getOwnerEntity();\r
+       $user = get_loggedin_user();\r
+\r
+       // check to make sure user is not responding to self\r
+       if ($parent_owner->guid != $user->guid) {\r
+               // check if parent owner has notification for this user\r
+               $send_response = true;\r
+               global $NOTIFICATION_HANDLERS;\r
+               foreach ($NOTIFICATION_HANDLERS as $method => $foo) {\r
+                       if (check_entity_relationship($parent_owner->guid, 'notify' . $method, $user->guid)) {\r
+                               $send_response = false;\r
+                       }\r
+               }\r
+\r
+               // create the notification message\r
+               if ($send_response) {\r
+                       // grab same notification message that goes to everyone else\r
+                       $params = array(\r
+                               'entity' => get_entity($guid),\r
+                               'method' => "email",\r
+                       );\r
+                       $msg = thewire_notify_message("", "", "", $params);\r
+\r
+                       notify_user(\r
+                                       $parent_owner->guid,\r
+                                       $user->guid,\r
+                                       elgg_echo('thewire:notify:subject'),\r
+                                       $msg);\r
+               }\r
+       }\r
+}\r
+\r
+/**\r
+ * Get the latest wire guid - used for ajax update\r
+ * @return guid\r
+ */\r
+function thewire_latest_guid() {\r
+       $post = elgg_get_entities(array(\r
+               'type' => 'object',\r
+               'subtype' => 'thewire',\r
+               'limit' => 1,\r
+       ));\r
+       if ($post) {\r
+               return $post[0]->guid;\r
+       } else {\r
+               return 0;\r
+       }\r
+}\r
+\r
+/**\r
+ * Get the parent of a wire post\r
+ * \r
+ * @param ElggObject $post\r
+ * @return ElggObject or null \r
+ */\r
+function thewire_get_parent($post_guid) {\r
+       $parents = elgg_get_entities_from_relationship(array(\r
+               'relationship' => 'parent',\r
+               'relationship_guid' => $post_guid,\r
+       ));\r
+       if ($parents) {\r
+               return $parents[0];\r
+       }\r
+       return null;\r
+}\r
+\r
+/**\r
+ * Runs unit tests for the wire\r
+ */\r
+function thewire_test($hook, $type, $value, $params) {\r
+       global $CONFIG;\r
+       $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php';\r
+       return $value;\r
+}
\ No newline at end of file
diff --git a/mod/thewire/tests/regex.php b/mod/thewire/tests/regex.php
new file mode 100644 (file)
index 0000000..9e187cf
--- /dev/null
@@ -0,0 +1,271 @@
+<?php
+/**
+ * Regular expression tests for the wire
+ */
+class TheWireRegexTest extends ElggCoreUnitTest {
+
+       /**
+        * Called before each test object.
+        */
+       public function __construct() {
+               $this->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 "<a href=\"{$CONFIG->wwwroot}pg/thewire/owner/$username\">@$username</a>";
+       }
+
+       protected function getHashtagLink($tag) {
+               global $CONFIG;
+               return "<a href=\"{$CONFIG->wwwroot}pg/thewire/tag/$tag\">#$tag</a>";
+       }
+
+       protected function getEmailLink($address) {
+               return "<a href=\"mailto:$address\">$address</a>";
+       }
+
+       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 (file)
index 0000000..e34a8c0
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Wire add form body
+ *
+ * @uses $vars['post']
+ */
+
+$post = elgg_get_array_value('post', $vars);
+
+$text = elgg_echo('post');
+if ($post) {
+       $text = elgg_echo('thewire:reply');
+}
+
+if ($post) {
+       echo elgg_view('input/hidden', array(
+               'internalname' => 'parent_guid',
+               'value' => $post->guid,
+       ));
+}
+?>
+<textarea id="thewire-textarea" name="body" class="mtm"></textarea>
+<div id="thewire-characters-remaining">
+       <span>140</span> <?php echo elgg_echo('thewire:charleft'); ?>
+</div>
+<?php
+
+echo elgg_view('input/submit', array(
+       'value' => $text,
+       'internalid' => 'thewire-submit-button',
+));
+
+?>
+<script type="text/javascript">
+
+$(document).ready(function() {
+       $("#thewire-textarea").bind('keydown', function() {
+               textCounter(this, $("#thewire-characters-remaining span"), 140);
+       });
+       $("#thewire-textarea").bind('keyup', function() {
+               textCounter(this, $("#thewire-characters-remaining span"), 140);
+       });
+});
+
+function textCounter(textarea, status, limit) {
+
+       var remaining_chars = limit - textarea.value.length;
+       status.html(remaining_chars);
+
+       if (remaining_chars < 0) {
+               status.parent().css("color", "#D40D12");
+               $("#thewire-submit-button").attr('disabled', 'disabled');
+               $("#thewire-submit-button").css('background', '#999999');
+               $("#thewire-submit-button").css('border-color', '#999999');
+               $("#thewire-submit-button").css('cursor', 'default');
+       } else {
+               status.parent().css("color", "");
+               $("#thewire-submit-button").removeAttr('disabled', 'disabled');
+               $("#thewire-submit-button").css('background', '#4690d6');
+               $("#thewire-submit-button").css('border-color', '#4690d6');
+               $("#thewire-submit-button").css('cursor', 'pointer');
+       }
+}
+</script>
index d154548159c1f535063f005108fdaf5e3a376dd9..603870153221c12b52da71d82d29e0f47ffc2a32 100644 (file)
@@ -1,69 +1,53 @@
 <?php
+/**
+ * View a wire post
+ * 
+ * @uses $vars['entity']
+ */
 
-       /**
-        * Elgg Wire Posts Listings
-        *
-        * @package thewire
-        *
-        * @question - do we want users to be able to edit thewire?
-        *
-        * @uses $vars['entity'] Optionally, the note to view
-        */
 
-if (isset($vars['entity'])) {
-       $user_name = $vars['entity']->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");
-?>
-<div class="wire_post">
-       <div class="wire_post_contents clearfix radius8">
+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;
+}
 
-               <div class="wire_post_icon">
-               <?php
-                               echo elgg_view("profile/icon",array('entity' => $vars['entity']->getOwnerEntity(), 'size' => 'tiny'));
-               ?>
-               </div>
+$owner = $post->getOwnerEntity();
 
-               <div class="wire_post_options">
-               <?php
-                       if(elgg_is_logged_in()){
-               ?>
-                       <a href="<?php echo elgg_get_site_url(); ?>mod/thewire/add.php?wire_username=<?php echo $vars['entity']->getOwnerEntity()->username; ?>" class="elgg-button-action reply small"><?php echo elgg_echo('thewire:reply'); ?></a>
-                       <?php
-                       }//close reply if statement
-                       // if the user looking at thewire post can edit, show the delete link
-                       if ($vars['entity']->canEdit()) {
-                       echo "<span class='delete-button'>" . elgg_view("output/confirmlink",array(
-                                       'href' => "action/thewire/delete?thewirepost=" . $vars['entity']->getGUID(),
-                                       'text' => elgg_echo('delete'),
-                                       'confirm' => elgg_echo('deleteconfirm'),
-                               )) . "</span>";
-                       }
-               ?>
-               </div>
+$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);
 
-               <div class="wire_post_info">
-                       <a href="<?php echo elgg_get_site_url(); ?>pg/thewire/<?php echo $vars['entity']->getOwnerEntity()->username; ?>"><?php echo $user_name; ?></a>
-                       <?php
-                               $desc = $vars['entity']->description;
-                               //$desc = preg_replace('/\@([A-Za-z0-9\_\.\-]*)/i','@<a href="' . elgg_get_site_url() . 'pg/thewire/$1">$1</a>',$desc);
-                               echo parse_urls($desc);
-                       ?>
-                       <p class="entity-subtext">
-                       <?php
-                               echo elgg_echo("thewire:wired") . " " . elgg_echo("thewire:strapline",
-                                                               array(elgg_view_friendly_time($vars['entity']->time_created))
-                               );
-                               echo ' ';
-                               echo elgg_echo('thewire:via_method', array(elgg_echo($vars['entity']->method)));
-                               echo '.';
-                       ?>
-                       </p>
-               </div>
-       </div>
-</div>
-<?php
+$metadata = elgg_view('thewire/metadata', array(
+       'entity' => $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);
index b1142e0f48df929f2ee9bc0c8acdc5aaced74337..d4dac38eee865596e9be85c3a5c5e29a4ee4c4da 100644 (file)
@@ -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(),
index d7beac105f6f7548964d1bf7dde53f17512aed97..c1c7b5bcb5a445586c3f933dd653749007f2a9f2 100644 (file)
@@ -1,12 +1,36 @@
 <?php
+/**
+ * The Wire CSS
+ */
 
-       /**
-        * Elgg thewire CSS extender
-        * 
-        * @package ElggTheWire
-        */
-
 ?>
+/********************************
+ 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;
+}
+<?php
+return true;
+?>
+
 /* 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 (file)
index 3ad968b..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-
-       /**
-        * Elgg thewire edit/add page
-        * 
-        * @package ElggTheWire
-        * 
-        */
-
-               $wire_user = get_input('wire_username');
-               if (!empty($wire_user)) { $msg = '@' . $wire_user . ' '; } else { $msg = ''; }
-
-?>
-<div class="new_wire_post clearfix">
-<h3><?php echo elgg_echo("thewire:doing"); ?></h3>
-<?php //@todo JS 1.8: no ?>
-<script type="text/javascript" src="<?php echo elgg_get_site_url(); ?>mod/thewire/views/default/thewire/scripts/counter.js"></script>
-<form action="<?php echo elgg_get_site_url(); ?>action/thewire/add" method="post" name="new_post">
-       <?php
-               $action_txt = elgg_echo('post');
-               $display .= "<textarea name='new_post_textarea' value='' onKeyDown=\"textCounter(document.new_post.new_post_textarea,document.new_post.remLen1,140)\" onKeyUp=\"textCounter(document.new_post.new_post_textarea,document.new_post.remLen1,140)\">{$msg}</textarea>";
-               $display .= "<input type='submit' class='elgg-button-action' value='{$action_txt}' />";
-               $display .= "<div class='character_count'><input readonly type=\"text\" name=\"remLen1\" size=\"3\" maxlength=\"3\" value=\"140\">";
-               echo $display;
-               echo elgg_echo("thewire:charleft") . "</div>";
-               echo elgg_view('input/securitytoken');
-       ?>
-       <input type="hidden" name="method" value="site" />
-</form>
-</div>
-<?php echo elgg_view('input/urlshortener'); ?>
\ 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 (file)
index 0000000..f04345e
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ *
+ */
+
+$entity = $vars['entity'];
+$handler = elgg_get_array_value('handler', $vars, '');
+
+?>
+<ul class="elgg-list-metadata">
+<?php
+if (elgg_is_logged_in()) {
+       echo '<li>';
+       echo elgg_view('output/url', array(
+               'href' => "pg/thewire/reply/$entity->guid",
+               'text' => elgg_echo('thewire:reply'),
+       ));
+       echo '</li>';
+}
+
+if ($entity->reply) {
+       echo '<li>';
+       echo elgg_view('output/url', array(
+               'href' => "pg/thewire/previous/$entity->guid",
+               'text' => elgg_echo('thewire:previous'),
+       ));
+       echo '</li>';
+}
+
+echo '<li>';
+echo elgg_view('output/url', array(
+       'href' => 'pg/thewire/thread/' . $entity->wire_thread,
+       'text' => elgg_echo('thewire:thread'),
+));
+echo '</li>';
+
+
+// links to delete or edit.
+if ($entity->canEdit() && $handler) {
+
+       $delete_url = "action/$handler/delete?guid={$entity->getGUID()}";
+       $delete_link = elgg_view('output/confirmlink', array(
+               'href' => $delete_url,
+               'text' => '<span class="elgg-icon elgg-icon-delete"></span>',
+               'title' => elgg_echo('delete'),
+               'confirm' => elgg_echo('deleteconfirm'),
+               'text_encode' => false,
+       ));
+       echo "<li>$delete_link</li>";
+}
+
+$likes = elgg_view_likes($entity);
+echo "<li>$likes</li>";
+
+?>
+</ul>
\ 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 (file)
index a3d08fe..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-       /**
-        * Elgg shout not found page
-        * 
-        * @package ElggShouts
-        */
-
-?>
-
-       <p>
-               <?php
-
-                       echo elgg_echo("thewire:notfound");
-               
-               ?>
-       </p>
\ No newline at end of file
index 29dc69329430a1164d4a19eacb302a250bba3f01..9ff0c4d59e575c31cee4abaeaa90f6099a00b2c2 100644 (file)
@@ -1,12 +1,11 @@
 <?php
-
 /**
- * Latest wire post on profile activity page
+ * Latest wire post on profile page
  */
  
 $owner = $vars['entity']->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 = "<p class='entity-subtext'> (" . elgg_view_friendly_time($lw->time_created) . ")</p>";
-       }
+if ($latest_wire && count($latest_wire) > 0) {
+       $latest_wire = $latest_wire[0];
+       $content = thewire_filter($latest_wire->description);
+       $time = "<p class='entity-subtext'> (" . elgg_view_friendly_time($latest_wire->time_created) . ")</p>";
 
        echo "<div class='wire_post'><div class='wire_post_contents clearfix radius8'>";
        echo $content;
diff --git a/mod/thewire/views/default/thewire/reply.php b/mod/thewire/views/default/thewire/reply.php
new file mode 100644 (file)
index 0000000..3794e14
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Reply header
+ */
+
+$post = $vars['post'];
+$poster = $post->getOwnerEntity();
+
+?>
+<b><?php echo elgg_echo('thewire:replying', array($poster->name)); ?>: </b>
+<?php echo $post->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 (file)
index 725643c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-       /**
-        * Elgg thewire view page
-        * 
-        * @package ElggTheWire
-        * 
-        * @uses $vars['entity'] An array of wire notes to view
-        * 
-        */
-        
-       // If there are any wire notes to view, view them
-               if (is_array($vars['entity']) && sizeof($vars['entity']) > 0) {
-                       
-                       foreach($vars['entity'] as $shout) {
-                               
-                               echo elgg_view_entity($shout);
-                               
-                       }
-                       
-               }
-
-?>
\ No newline at end of file
index 6de5f1e649b6a36b1f1338b5438e8b43d01caef5..a8471a4b14a7fae6296968ea86ad5e0e5f410338 100644 (file)
@@ -1,15 +1,29 @@
 <?php
-               
+/**
+ * User wire post widget display view
+ */
+
 $num = $vars['entity']->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 "<div class=\"shares_widget_wrapper\"><a href=\"{$blogurl}\">".elgg_echo('thewire:moreposts')."</a></div>";
+       $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 "<span class=\"elgg-widget-more\">$more_link</span>";
+} else {
+       echo elgg_echo('thewire:noposts');
 }
index 969015ab8801aff483a5cd4c39b76ef197a70e90..8c93383ad961e3bfa8c09ad698eba5f49c8cc811 100644 (file)
@@ -1,22 +1,22 @@
 <?php
+/**
+ * User wire widget edit view
+ */
+
 // set default value
 if (!isset($vars['entity']->num_display)) {
        $vars['entity']->num_display = 4;
 }
-?>
-<p>
-       <?php echo elgg_echo("thewire:num"); ?>
-       <select name="params[num_display]">
-<?php
-$options = array(1,2,3,4,5,6);
-foreach ($options as $option)  {
-       $selected = '';
-       if ($vars['entity']->num_display == $option) {
-               $selected = "selected='selected'";
-       }
 
-       echo "  <option value='{$option}' $selected >{$option}</option>\n";
-}
+$params = array(
+       'internalname' => 'params[num_display]',
+       'value' => $vars['entity']->num_display,
+       'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
+);
+$dropdown = elgg_view('input/dropdown', $params);
+
 ?>
-       </select>
-</p>
\ No newline at end of file
+<div>
+       <?php echo elgg_echo('thewire:num'); ?>:
+       <?php echo $dropdown; ?>
+</div>