123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- <?php
- elgg_register_event_handler('init', 'system', 'thewire_init');
- function thewire_init() {
-
- $thewire_js = elgg_get_simplecache_url('js', 'thewire');
- elgg_register_simplecache_view('js/thewire');
- elgg_register_js('elgg.thewire', $thewire_js, 'footer');
-
- elgg_register_ajax_view('thewire/previous');
-
- $item = new ElggMenuItem('thewire', elgg_echo('thewire'), 'thewire/all');
- elgg_register_menu_item('site', $item);
-
- elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'thewire_owner_block_menu');
-
- elgg_register_plugin_hook_handler('register', 'menu:entity', 'thewire_setup_entity_menu_items');
-
-
- elgg_extend_view('css/elgg', 'thewire/css');
-
- elgg_extend_view('activity/thewire', 'thewire/activity_view');
- elgg_extend_view('profile/status', 'thewire/profile_status');
- elgg_extend_view('js/initialise_elgg', 'thewire/js/textcounter');
-
- elgg_register_page_handler('thewire', 'thewire_page_handler');
-
- elgg_register_entity_url_handler('object', 'thewire', 'thewire_url');
- elgg_register_widget_type('thewire', elgg_echo('thewire'), elgg_echo("thewire:widget:desc"));
-
- elgg_register_entity_type('object', 'thewire');
-
- register_notification_object('object', 'thewire', elgg_echo('thewire:notify:subject'));
-
- elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'thewire_notify_message');
-
- $action_base = elgg_get_plugins_path() . 'thewire/actions';
- elgg_register_action("thewire/add", "$action_base/add.php");
- elgg_register_action("thewire/delete", "$action_base/delete.php");
- elgg_register_action("thewire/get_smiley", "$action_base/get_smiley.php");
- elgg_register_plugin_hook_handler('unit_test', 'system', 'thewire_test');
- }
- function thewire_page_handler($page) {
- $base_dir = elgg_get_plugins_path() . 'thewire/pages/thewire';
- if (!isset($page[0])) {
- $page = array('all');
- }
- switch ($page[0]) {
- case "all":
- include "$base_dir/everyone.php";
- break;
- case "friends":
- include "$base_dir/friends.php";
- break;
- case "owner":
- include "$base_dir/owner.php";
- break;
- case "view":
- if (isset($page[1])) {
- set_input('guid', $page[1]);
- }
- include "$base_dir/view.php";
- break;
- case "thread":
- if (isset($page[1])) {
- set_input('thread_id', $page[1]);
- }
- include "$base_dir/thread.php";
- break;
- case "reply":
- if (isset($page[1])) {
- set_input('guid', $page[1]);
- }
- include "$base_dir/reply.php";
- break;
- case "tag":
- if (isset($page[1])) {
- set_input('tag', $page[1]);
- }
- include "$base_dir/tag.php";
- break;
- case "previous":
- if (isset($page[1])) {
- set_input('guid', $page[1]);
- }
- include "$base_dir/previous.php";
- break;
- default:
- return false;
- }
- return true;
- }
- function thewire_url($thewirepost) {
- global $CONFIG;
- return $CONFIG->url . "thewire/view/" . $thewirepost->guid;
- }
- 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) {
-
- $parent_post = get_entity(get_input('parent_guid'));
- if ($parent_post) {
- $parent_owner = $parent_post->getOwnerEntity();
- }
- $body = sprintf(elgg_echo('thewire:notify:reply'), $owner->name, $parent_owner->name);
- } else {
- $body = sprintf(elgg_echo('thewire:notify:post'), $owner->name);
- }
- $body .= "\n\n" . $descr . "\n\n";
- $body .= elgg_echo('thewire') . ": {$CONFIG->url}thewire";
- return $body;
- }
- return $returnvalue;
- }
- function thewire_get_hashtags($text) {
-
-
- $matches = array();
- preg_match_all('/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/', $text, $matches);
- return $matches[2];
- }
- function thewire_filter($text) {
- global $CONFIG;
- $text = ' ' . $text;
-
- $text = preg_replace(
- '/(^|[^\w])([\w\-\.]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})/i',
- '$1<a href="mailto:$2@$3">$2@$3</a>',
- $text);
-
- $text = parse_urls($text);
-
- $text = preg_replace(
- '/(^|[^\w])@([\p{L}\p{Nd}._]+)/u',
- '$1<a href="' . $CONFIG->wwwroot . 'thewire/owner/$2">@$2</a>',
- $text);
-
- $text = preg_replace(
- '/(^|[^\w])#(\w*[^\s\d!-\/:-@]+\w*)/',
- '$1<a href="' . $CONFIG->wwwroot . 'thewire/tag/$2">#$2</a>',
- $text);
- $text = trim($text);
- return $text;
- }
- 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;
-
- $text = elgg_substr($text, 0, 200);
-
- $post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
- $post->method = $method;
- $tags = thewire_get_hashtags($text);
- if ($tags) {
- $post->tags = $tags;
- }
-
- if ($parent_guid) {
- $post->reply = true;
- }
- $guid = $post->save();
-
- if ($parent_guid) {
- $post->addRelationship($parent_guid, 'parent');
-
-
- $parent_post = get_entity($parent_guid);
- $post->wire_thread = $parent_post->wire_thread;
- } else {
-
- $post->wire_thread = $guid;
- }
- if ($guid) {
- add_to_river('river/object/thewire/create', 'create', $post->owner_guid, $post->guid);
-
- $params = array(
- 'entity' => $post,
- 'user' => $post->getOwnerEntity(),
- 'message' => $post->description,
- 'url' => $post->getURL(),
- 'origin' => 'thewire',
- );
- elgg_trigger_plugin_hook('status', 'user', $params);
- }
-
- return $guid;
- }
- function thewire_send_response_notification($guid, $parent_guid, $user) {
- $parent_owner = get_entity($parent_guid)->getOwnerEntity();
- $user = elgg_get_logged_in_user_entity();
-
- if ($parent_owner->guid != $user->guid) {
-
- $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;
- }
- }
-
- if ($send_response) {
-
- $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);
- }
- }
- }
- function thewire_latest_guid() {
- $post = elgg_get_entities(array(
- 'type' => 'object',
- 'subtype' => 'thewire',
- 'limit' => 1,
- ));
- if ($post) {
- return $post[0]->guid;
- } else {
- return 0;
- }
- }
- 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;
- }
- function thewire_setup_entity_menu_items($hook, $type, $value, $params) {
- $handler = elgg_extract('handler', $params, false);
- if ($handler != 'thewire') {
- return $value;
- }
- foreach ($value as $index => $item) {
- $name = $item->getName();
- if ($name == 'access' || $name == 'edit') {
- unset($value[$index]);
- }
- }
- $entity = $params['entity'];
- if (elgg_is_logged_in()) {
- $options = array(
- 'name' => 'reply',
- 'text' => elgg_echo('thewire:reply'),
- 'href' => "thewire/reply/$entity->guid",
- 'priority' => 150,
- );
- $value[] = ElggMenuItem::factory($options);
- }
- if ($entity->reply) {
- $options = array(
- 'name' => 'previous',
- 'text' => elgg_echo('thewire:previous'),
- 'href' => "thewire/previous/$entity->guid",
- 'priority' => 160,
- 'link_class' => 'thewire-previous',
- 'title' => elgg_echo('thewire:previous:help'),
- );
- $value[] = ElggMenuItem::factory($options);
- }
- $options = array(
- 'name' => 'thread',
- 'text' => elgg_echo('thewire:thread'),
- 'href' => "thewire/thread/$entity->wire_thread",
- 'priority' => 170,
- );
- $value[] = ElggMenuItem::factory($options);
- return $value;
- }
- function thewire_owner_block_menu($hook, $type, $return, $params) {
- if (elgg_instanceof($params['entity'], 'user')) {
- $url = "thewire/owner/{$params['entity']->username}";
- $item = new ElggMenuItem('thewire', elgg_echo('item:object:thewire'), $url);
- $return[] = $item;
- }
- return $return;
- }
- function thewire_test($hook, $type, $value, $params) {
- global $CONFIG;
- $value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php';
- return $value;
- }
|