Merge pull request #345 from tobiasd/20160312-degree
authorMichael Vogel <icarus@dabo.de>
Sun, 13 Mar 2016 10:54:29 +0000 (11:54 +0100)
committerMichael Vogel <icarus@dabo.de>
Sun, 13 Mar 2016 10:54:29 +0000 (11:54 +0100)
encode the degree for the translation

19 files changed:
appnet/appnet.php
defaultfeatures/defaultfeatures.php
jappixmini.tgz [new file with mode: 0644]
ldapauth/ldapauth.php
mailstream/mailstream.php
mailstream/templates/settings.tpl
pumpio/pumpio.php
rendertime/rendertime.php
retriever/database.sql
retriever/retriever.php
retriever/templates/extract.tpl
retriever/templates/fix-urls.tpl [new file with mode: 0644]
retriever/templates/help.tpl
retriever/templates/rule-config.tpl
retriever/templates/settings.tpl
smileybutton/smileybutton.php
statusnet/statusnet.php
twitter/twitter.php
xmpp/xmpp.php

index a672e065bbe2068930dc1f60ae0be86baac0ac81..bbcf9208ae835553b936e97c8290c29c378c8131 100644 (file)
@@ -15,6 +15,8 @@
  - https://alpha.app.net/opendev/post/34396399 - location data
 */
 
+require_once('include/enotify.php');
+
 define('APPNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
 function appnet_install() {
@@ -25,6 +27,7 @@ function appnet_install() {
        register_hook('connector_settings',     'addon/appnet/appnet.php', 'appnet_settings');
        register_hook('connector_settings_post','addon/appnet/appnet.php', 'appnet_settings_post');
        register_hook('prepare_body',           'addon/appnet/appnet.php', 'appnet_prepare_body');
+       register_hook('check_item_notification','addon/appnet/appnet.php', 'appnet_check_item_notification');
 }
 
 
@@ -36,6 +39,7 @@ function appnet_uninstall() {
        unregister_hook('connector_settings',   'addon/appnet/appnet.php', 'appnet_settings');
        unregister_hook('connector_settings_post', 'addon/appnet/appnet.php', 'appnet_settings_post');
        unregister_hook('prepare_body',         'addon/appnet/appnet.php', 'appnet_prepare_body');
+       unregister_hook('check_item_notification','addon/appnet/appnet.php', 'appnet_check_item_notification');
 }
 
 function appnet_module() {}
@@ -64,6 +68,18 @@ function appnet_content(&$a) {
        return $o;
 }
 
+function appnet_check_item_notification($a, &$notification_data) {
+        $own_id = get_pconfig($notification_data["uid"], 'appnet', 'ownid');
+
+        $own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
+                        intval($notification_data["uid"]),
+                        dbesc("adn::".$own_id)
+                );
+
+        if ($own_user)
+                $notification_data["profiles"][] = $own_user[0]["url"];
+}
+
 function appnet_plugin_admin(&$a, &$o){
         $t = get_markup_template( "admin.tpl", "addon/appnet/" );
 
@@ -707,7 +723,7 @@ function appnet_fetchstream($a, $uid) {
 
                $lastid = $post["id"];
 
-               if (($item != 0) AND ($postarray['contact-id'] != $me["id"])) {
+               if (($item != 0) AND ($postarray['contact-id'] != $me["id"]) AND !function_exists("check_item_notification")) {
                        $r = q("SELECT `thread`.`iid` AS `parent` FROM `thread`
                                INNER JOIN `item` ON `thread`.`iid` = `item`.`parent` AND `thread`.`uid` = `item`.`uid`
                                WHERE `item`.`id` = %d AND `thread`.`mention` LIMIT 1", dbesc($item));
@@ -769,6 +785,10 @@ function appnet_fetchstream($a, $uid) {
 
                        $parent_id = 0;
                        logger('appnet_fetchstream: User '.$uid.' posted mention item '.$item);
+
+                       if ($item AND function_exists("check_item_notification"))
+                               check_item_notification($item, $uid, NOTIFY_TAGSELF);
+
                } else {
                        $item = 0;
                        $parent_id = 0;
@@ -790,7 +810,7 @@ function appnet_fetchstream($a, $uid) {
                $lastid = $post["id"];
 
                //if (($item != 0) AND ($postarray['contact-id'] != $me["id"])) {
-               if ($item != 0) {
+               if (($item != 0) AND !function_exists("check_item_notification")) {
                        require_once('include/enotify.php');
                        notification(array(
                                'type'         => NOTIFY_TAGSELF,
index dfe4a067b45d1cdabe70d884e55e421859b3875e..c92547d8070e45c77f197d3cb6cd1a33ad5329ef 100755 (executable)
@@ -4,6 +4,7 @@
  * Description: Choose which Additional Features are on by default for new users on the site.
  * Version: 1.0
  * Author: Michael Johnston
+ * Status: Unsupported
  */
 
 function defaultfeatures_install() {
diff --git a/jappixmini.tgz b/jappixmini.tgz
new file mode 100644 (file)
index 0000000..676f147
Binary files /dev/null and b/jappixmini.tgz differ
index 55c855af99e839ccd3da4fd76e7b29cc7c8b8dce..60273c3b824d29398e10471f4e403d923368ee2f 100755 (executable)
@@ -47,7 +47,7 @@
  * //   attribute to get email - optional - default : 'mail'
  * $a->config['ldapauth']['ldap_autocreateaccount_emailattribute'] = 'mail';
  * //   attribute to get nickname - optional - default : 'givenName'
- * $a->config['ldapauth']['ldap_autocreateaccount_nameattribute'] = 'givenName';
+ * $a->config['ldapauth']['ldap_autocreateaccount_nameattribute'] = 'cn';
  *
  * ...etc.
  */
@@ -90,23 +90,29 @@ function ldapauth_authenticate($username,$password) {
        
     if(! ((strlen($password))
             && (function_exists('ldap_connect'))
-            && (strlen($ldap_server))))
+            && (strlen($ldap_server)))) {
+            logger("ldapauth: not configured or missing php-ldap module");
             return false;
+    }
 
     $connect = @ldap_connect($ldap_server);
 
-    if(! $connect)
+    if($connect === false) {
+        logger("ldapauth: could not connect to $ldap_server");
         return false;
+    }
 
     @ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION,3);
     @ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
     if((@ldap_bind($connect,$ldap_binddn,$ldap_bindpw)) === false) {
+        logger("ldapauth: could not bind $ldap_server as $ldap_binddn");
         return false;
     }
 
     $res = @ldap_search($connect,$ldap_searchdn, $ldap_userattr . '=' . $username);
 
     if(! $res) {
+        logger("ldapauth: $ldap_userattr=$username,$ldap_searchdn not found");
         return false;
     }
 
index 5e4767841ee87d710755cb9962c8cfb35b123a1c..02a1192b2b2b6c0a73bdf3138cfabe0fe12615a2 100644 (file)
@@ -2,46 +2,60 @@
 /**
  * Name: Mail Stream
  * Description: Mail all items coming into your network feed to an email address
- * Version: 0.2
+ * Version: 1.0
  * Author: Matthew Exon <http://mat.exon.name>
  */
 
 function mailstream_install() {
     register_hook('plugin_settings', 'addon/mailstream/mailstream.php', 'mailstream_plugin_settings');
     register_hook('plugin_settings_post', 'addon/mailstream/mailstream.php', 'mailstream_plugin_settings_post');
-    register_hook('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_remote_hook');
+    register_hook('post_local_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
+    register_hook('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
     register_hook('cron', 'addon/mailstream/mailstream.php', 'mailstream_cron');
 
-    $schema = file_get_contents(dirname(__file__).'/database.sql');
-    $arr = explode(';', $schema);
-    foreach ($arr as $a) {
-        $r = q($a);
-    }
-
     if (get_config('mailstream', 'dbversion') == '0.1') {
         q('ALTER TABLE `mailstream_item` DROP INDEX `uid`');
         q('ALTER TABLE `mailstream_item` DROP INDEX `contact-id`');
         q('ALTER TABLE `mailstream_item` DROP INDEX `plink`');
         q('ALTER TABLE `mailstream_item` CHANGE `plink` `uri` char(255) NOT NULL');
+        set_config('mailstream', 'dbversion', '0.2');
     }
     if (get_config('mailstream', 'dbversion') == '0.2') {
         q('DELETE FROM `pconfig` WHERE `cat` = "mailstream" AND `k` = "delay"');
+        set_config('mailstream', 'dbversion', '0.3');
     }
     if (get_config('mailstream', 'dbversion') == '0.3') {
         q('ALTER TABLE `mailstream_item` CHANGE `created` `created` timestamp NOT NULL DEFAULT now()');
         q('ALTER TABLE `mailstream_item` CHANGE `completed` `completed` timestamp NULL DEFAULT NULL');
+        set_config('mailstream', 'dbversion', '0.4');
     }
     if (get_config('mailstream', 'dbversion') == '0.4') {
         q('ALTER TABLE `mailstream_item` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
+        set_config('mailstream', 'dbversion', '0.5');
+    }
+    if (get_config('mailstream', 'dbversion') == '0.5') {
+        set_config('mailstream', 'dbversion', '1.0');
+    }
+
+    if (get_config('retriever', 'dbversion') != '1.0') {
+        $schema = file_get_contents(dirname(__file__).'/database.sql');
+        $arr = explode(';', $schema);
+        foreach ($arr as $a) {
+            $r = q($a);
+        }
+        set_config('mailstream', 'dbversion', '1.0');
     }
-    set_config('mailstream', 'dbversion', '0.5');
 }
 
 function mailstream_uninstall() {
     unregister_hook('plugin_settings', 'addon/mailstream/mailstream.php', 'mailstream_plugin_settings');
     unregister_hook('plugin_settings_post', 'addon/mailstream/mailstream.php', 'mailstream_plugin_settings_post');
+    unregister_hook('post_local', 'addon/mailstream/mailstream.php', 'mailstream_post_local_hook');
     unregister_hook('post_remote', 'addon/mailstream/mailstream.php', 'mailstream_post_remote_hook');
+    unregister_hook('post_local_end', 'addon/mailstream/mailstream.php', 'mailstream_post_local_hook');
     unregister_hook('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_remote_hook');
+    unregister_hook('post_local_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
+    unregister_hook('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
     unregister_hook('cron', 'addon/mailstream/mailstream.php', 'mailstream_cron');
     unregister_hook('incoming_mail', 'addon/mailstream/mailstream.php', 'mailstream_incoming_mail');
 }
@@ -70,10 +84,12 @@ function mailstream_generate_id($a, $uri) {
     // http://www.jwz.org/doc/mid.html
     $host = $a->get_hostname();
     $resource = hash('md5', $uri);
-    return "<" . $resource . "@" . $host . ">";
+    $message_id = "<" . $resource . "@" . $host . ">";
+    logger('mailstream: Generated message ID ' . $message_id . ' for URI ' . $uri, LOGGER_DEBUG);
+    return $message_id;
 }
 
-function mailstream_post_remote_hook(&$a, &$item) {
+function mailstream_post_hook(&$a, &$item) {
     if (!get_pconfig($item['uid'], 'mailstream', 'enabled')) {
         return;
     }
@@ -86,10 +102,16 @@ function mailstream_post_remote_hook(&$a, &$item) {
     if (!$item['uri']) {
         return;
     }
+    if (get_pconfig($item['uid'], 'mailstream', 'nolikes')) {
+        if ($item['verb'] == ACTIVITY_LIKE) {
+            return;
+        }
+    }
 
+    $message_id = mailstream_generate_id($a, $item['uri']);
     q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " .
       "VALUES (%d, '%s', '%s', '%s')", intval($item['uid']),
-      intval($item['contact-id']), dbesc($item['uri']), dbesc(mailstream_generate_id($a, $item['uri'])));
+      intval($item['contact-id']), dbesc($item['uri']), dbesc($message_id));
     $r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri']));
     if (count($r) != 1) {
         logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL);
@@ -104,7 +126,7 @@ function mailstream_post_remote_hook(&$a, &$item) {
         logger('mailstream_post_remote_hook: no user ' . $item['uid'], LOGGER_NORMAL);
         return;
     }
-    mailstream_send($a, $ms_item, $item, $user);
+    mailstream_send($a, $ms_item['message-id'], $item, $user);
 }
 
 function mailstream_get_user($uid) {
@@ -117,39 +139,67 @@ function mailstream_get_user($uid) {
 }
 
 function mailstream_do_images($a, &$item, &$attachments) {
+    if (!get_pconfig($item['uid'], 'mailstream', 'attachimg')) {
+        return;
+    }
+    $attachments = array();
     $baseurl = $a->get_baseurl();
-    $id = 1;
-    $matches = array();
-    preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches);
-    if (count($matches)) {
-        foreach ($matches[3] as $url) {
-            $attachments[$url] = array();
+    preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches1);
+    preg_match_all("/\[img\](.*?)\[\/img\]/ism", $item["body"], $matches2);
+    foreach (array_merge($matches1[3], $matches2[1]) as $url) {
+        $redirects;
+        $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
+        $attachments[$url] = array(
+            'data' => fetch_url($url, true, $redirects, 0, Null, $cookiejar),
+            'guid' => hash("crc32", $url),
+            'filename' => basename($url),
+            'type' => $a->get_curl_content_type());
+        if (strlen($attachments[$url]['data'])) {
+            $item['body'] = str_replace($url, 'cid:' . $attachments[$url]['guid'], $item['body']);
+            continue;
         }
     }
-    preg_match_all("/\[img\](.*?)\[\/img\]/ism", $item["body"], $matches);
-    if (count($matches)) {
-        foreach ($matches[1] as $url) {
-            $attachments[$url] = array();
+    return $attachments;
+}
+
+function mailstream_sender($item) {
+    $r = q('SELECT * FROM `contact` WHERE `id` = %d', $item['contact-id']);
+    if (count($r)) {
+        $contact = $r[0];
+        if ($contact['name'] != $item['author-name']) {
+            return $contact['name'] . ' - ' . $item['author-name'];
         }
     }
-    foreach ($attachments as $url=>$cid) {
-        if (strncmp($url, $baseurl, strlen($baseurl))) {
-            unset($attachments[$url]); // Not a local image, don't replace
-        }
-        else {
-            $attachments[$url]['guid'] = substr($url, strlen($baseurl) + strlen('/photo/'));
-            $r = q("SELECT `data`, `filename`, `type` FROM `photo` WHERE `resource-id` = '%s'", dbesc($attachments[$url]['guid']));
-            $attachments[$url]['data'] = $r[0]['data'];
-            $attachments[$url]['filename'] = $r[0]['filename'];
-            $attachments[$url]['type'] = $r[0]['type'];
-            $item['body'] = str_replace($url, 'cid:' . $attachments[$url]['guid'], $item['body']);
-        }
+    return $item['author-name'];
+}
+
+function mailstream_decode_subject($subject) {
+    $html = bbcode($subject);
+    if (!$html) {
+        return $subject;
+    }
+    $notags = strip_tags($html);
+    if (!$notags) {
+       return $subject;
+    }
+    $noentity = html_entity_decode($notags);
+    if (!$noentity) {
+        return $notags;
+    }
+    $nocodes = preg_replace_callback("/(&#[0-9]+;)/", function($m) { return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); }, $noentity);
+    if (!$nocodes) {
+        return $noentity;
     }
+    $trimmed = trim($nocodes);
+    if (!$trimmed) {
+        return $nocodes;
+    }
+    return $trimmed;
 }
 
 function mailstream_subject($item) {
     if ($item['title']) {
-        return $item['title'];
+        return mailstream_decode_subject($item['title']);
     }
     $parent = $item['thr-parent'];
     // Don't look more than 100 levels deep for a subject, in case of loops
@@ -162,7 +212,7 @@ function mailstream_subject($item) {
             break;
         }
         if ($r[0]['title']) {
-            return t('Re:') . ' ' . $r[0]['title'];
+            return t('Re:') . ' ' . mailstream_decode_subject($r[0]['title']);
         }
         $parent = $r[0]['thr-parent'];
     }
@@ -176,7 +226,10 @@ function mailstream_subject($item) {
         return t("Diaspora post");
     }
     if ($contact['network'] === 'face') {
-        $subject = (strlen($item['body']) > 150) ? (substr($item['body'], 0, 140) . '...') : $item['body'];
+        $text = mailstream_decode_subject($item['body']);
+        // For some reason these do show up in Facebook
+        $text = preg_replace('/\xA0$/', '', $text);
+        $subject = (strlen($text) > 150) ? (substr($text, 0, 140) . '...') : $text;
         return preg_replace('/\\s+/', ' ', $subject);
     }
     if ($contact['network'] === 'feed') {
@@ -188,10 +241,13 @@ function mailstream_subject($item) {
     return t("Friendica Item");
 }
 
-function mailstream_send($a, $ms_item, $item, $user) {
+function mailstream_send($a, $message_id, $item, $user) {
     if (!$item['visible']) {
         return;
     }
+    if (!$message_id) {
+        return;
+    }
     require_once(dirname(__file__).'/class.phpmailer.php');
     require_once('include/bbcode.php');
     $attachments = array();
@@ -207,9 +263,9 @@ function mailstream_send($a, $ms_item, $item, $user) {
     $mail = new PHPmailer;
     try {
         $mail->XMailer = 'Friendica Mailstream Plugin';
-        $mail->SetFrom($frommail, $item['author-name']);
+        $mail->SetFrom($frommail, mailstream_sender($item));
         $mail->AddAddress($address, $user['username']);
-        $mail->MessageID = $ms_item['message-id'];
+        $mail->MessageID = $message_id;
         $mail->Subject = mailstream_subject($item);
         if ($item['thr-parent'] != $item['uri']) {
             $mail->addCustomHeader('In-Reply-To: ' . mailstream_generate_id($a, $item['thr-parent']));
@@ -217,7 +273,7 @@ function mailstream_send($a, $ms_item, $item, $user) {
         $mail->addCustomHeader('X-Friendica-Mailstream-URI: ' . $item['uri']);
         $mail->addCustomHeader('X-Friendica-Mailstream-Plink: ' . $item['plink']);
         $encoding = 'base64';
-        foreach ($attachments as $url=>$image) {
+        foreach ($attachments as $url => $image) {
             $mail->AddStringEmbeddedImage($image['data'], $image['guid'], $image['filename'], $encoding, $image['type']);
         }
         $mail->IsHTML(true);
@@ -229,36 +285,59 @@ function mailstream_send($a, $ms_item, $item, $user) {
                                          '$upstream' => t('Upstream'),
                                          '$local' => t('Local'),
                                          '$item' => $item));
+        mailstream_html_wrap($mail->Body);
         if (!$mail->Send()) {
             throw new Exception($mail->ErrorInfo);
         }
         logger('mailstream_send sent message ' . $mail->MessageID . ' ' . $mail->Subject, LOGGER_DEBUG);
     } catch (phpmailerException $e) {
-        logger('mailstream_send PHPMailer exception sending message ' . $ms_item['message-id'] . ': ' . $e->errorMessage(), LOGGER_NORMAL);
+        logger('mailstream_send PHPMailer exception sending message ' . $message_id . ': ' . $e->errorMessage(), LOGGER_NORMAL);
     } catch (Exception $e) {
-        logger('mailstream_send exception sending message ' . $ms_item['message-id'] . ': ' . $e->getMessage(), LOGGER_NORMAL);
+        logger('mailstream_send exception sending message ' . $message_id . ': ' . $e->getMessage(), LOGGER_NORMAL);
     }
     // In case of failure, still set the item to completed.  Otherwise
     // we'll just try to send it over and over again and it'll fail
     // every time.
-    q("UPDATE `mailstream_item` SET `completed` = now() WHERE `id` = %d", intval($ms_item['id']));
+    q('UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = "%s"', dbesc($message_id));
+}
+
+/**
+ * Email tends to break if you send excessively long lines.  To make
+ * bbcode's output suitable for transmission, we try to break things
+ * up so that lines are about 200 characters.
+ */
+function mailstream_html_wrap(&$text)
+{
+    $lines = str_split($text, 200);
+    for ($i = 0; $i < count($lines); $i++)
+    {
+        $lines[$i] = preg_replace('/ /', "\n", $lines[$i], 1);
+    }
+    $text = implode($lines);
 }
 
 function mailstream_cron($a, $b) {
-    $ms_items = q("SELECT * FROM `mailstream_item` WHERE `completed` IS NULL LIMIT 100");
-    logger('mailstream_cron processing ' . count($ms_items) . ' items', LOGGER_DEBUG);
-    foreach ($ms_items as $ms_item) {
-        $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `contact-id` = %d",
-                   intval($ms_item['uid']), dbesc($ms_item['uri']), intval($ms_item['contact-id']));
+    // Only process items older than an hour in cron.  This is because
+    // we want to give mailstream_post_remote_hook a fair chance to
+    // send the email itself before cron jumps in.  Only if
+    // mailstream_post_remote_hook fails for some reason will this get
+    // used, and in that case it's worth holding off a bit anyway.
+    $ms_item_ids = q("SELECT `mailstream_item`.`message-id`, `mailstream_item`.`uri`, `item`.`id` FROM `mailstream_item` JOIN `item` ON (`mailstream_item`.`uid` = `item`.`uid` AND `mailstream_item`.`uri` = `item`.`uri` AND `mailstream_item`.`contact-id` = `item`.`contact-id`) WHERE `mailstream_item`.`completed` IS NULL AND `mailstream_item`.`created` < DATE_SUB(NOW(), INTERVAL 1 HOUR) AND `item`.`visible` = 1 ORDER BY `mailstream_item`.`created` LIMIT 100");
+    logger('mailstream_cron processing ' . count($ms_item_ids) . ' items', LOGGER_DEBUG);
+    foreach ($ms_item_ids as $ms_item_id) {
+        if (!$ms_item_id['message-id'] || !strlen($ms_item_id['message-id'])) {
+            logger('mailstream_cron: Item ' . $ms_item_id['id'] . ' URI ' . $ms_item_id['uri'] . ' has no message-id', LOGGER_NORMAL);
+        }
+        $items = q('SELECT * FROM `item` WHERE `id` = %d', $ms_item_id['id']);
         $item = $items[0];
-        $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($ms_item['uid']));
+        $users = q("SELECT * FROM `user` WHERE `uid` = %d", intval($item['uid']));
         $user = $users[0];
         if ($user && $item) {
-            mailstream_send($a, $ms_item, $item, $user);
+            mailstream_send($a, $ms_item_id['message-id'], $item, $user);
         }
         else {
-            logger('mailstream_cron: Unable to find item ' . $ms_item['uri'], LOGGER_NORMAL);
-            q("UPDATE `mailstream_item` SET `completed` = now() WHERE `id` = %d", intval($ms_item['id']));
+            logger('mailstream_cron: Unable to find item ' . $ms_item_id['id'], LOGGER_NORMAL);
+            q("UPDATE `mailstream_item` SET `completed` = now() WHERE `message-id` = %d", intval($ms_item['message-id']));
         }
     }
     mailstream_tidy();
@@ -267,17 +346,29 @@ function mailstream_cron($a, $b) {
 function mailstream_plugin_settings(&$a,&$s) {
     $enabled = get_pconfig(local_user(), 'mailstream', 'enabled');
     $address = get_pconfig(local_user(), 'mailstream', 'address');
+    $nolikes = get_pconfig(local_user(), 'mailstream', 'nolikes');
+    $attachimg= get_pconfig(local_user(), 'mailstream', 'attachimg');
     $template = get_markup_template('settings.tpl', 'addon/mailstream/');
     $s .= replace_macros($template, array(
+                             '$enabled' => array(
+                                 'mailstream_enabled',
+                                 t('Enabled'),
+                                 $enabled),
                              '$address' => array(
                                  'mailstream_address',
                                  t('Email Address'),
                                  $address,
                                  t("Leave blank to use your account email address")),
-                             '$enabled' => array(
-                                 'mailstream_enabled',
-                                 t('Enabled'),
-                                 $enabled),
+                             '$nolikes' => array(
+                                 'mailstream_nolikes',
+                                 t('Exclude Likes'),
+                                 $nolikes,
+                                 t("Check this to omit mailing \"Like\" notifications")),
+                             '$attachimg' => array(
+                                 'mailstream_attachimg',
+                                 t('Attach Images'),
+                                 $attachimg,
+                                 t("Download images in posts and attach them to the email.  Useful for reading email while offline.")),
                              '$title' => t('Mail Stream Settings'),
                              '$submit' => t('Save Settings')));
 }
@@ -289,12 +380,24 @@ function mailstream_plugin_settings_post($a,$post) {
     else {
         del_pconfig(local_user(), 'mailstream', 'address');
     }
+    if ($_POST['mailstream_nolikes']) {
+        set_pconfig(local_user(), 'mailstream', 'nolikes', $_POST['mailstream_enabled']);
+    }
+    else {
+        del_pconfig(local_user(), 'mailstream', 'nolikes');
+    }
     if ($_POST['mailstream_enabled']) {
         set_pconfig(local_user(), 'mailstream', 'enabled', $_POST['mailstream_enabled']);
     }
     else {
         del_pconfig(local_user(), 'mailstream', 'enabled');
     }
+    if ($_POST['mailstream_attachimg']) {
+        set_pconfig(local_user(), 'mailstream', 'attachimg', $_POST['mailstream_attachimg']);
+    }
+    else {
+        del_pconfig(local_user(), 'mailstream', 'attachimg');
+    }
 }
 
 function mailstream_tidy() {
index bd24e38fa9a168c7400dfdb2be3d94b727a6d5bc..376108285a770f2c60bc76758cb3aebe59098986 100644 (file)
@@ -1,11 +1,8 @@
-<span id="settings_mailstream_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_mailstream_expanded'); openClose('settings_mailstream_inflated');">
-<h3>{{$title}}</h3>
-</span>
-<div id="settings_mailstream_expanded" class="settings-block" style="display: none;">
-<span class="fakelink" onclick="openClose('settings_mailstream_expanded'); openClose('settings_mailstream_inflated');">
+<div class="settings-block">
   <h3>{{$title}}</h3>
-  </span>
-{{include file="field_input.tpl" field=$address}}
 {{include file="field_checkbox.tpl" field=$enabled}}
+{{include file="field_input.tpl" field=$address}}
+{{include file="field_checkbox.tpl" field=$nolikes}}
+{{include file="field_checkbox.tpl" field=$attachimg}}
   <input type="submit" value="{{$submit}}">
 </div>
index 0a5f50b967f9a2e66bac4c1ccdb504665be2f60c..1702971ce87dae29207a97e9bc7cc3cac2e30ffd 100644 (file)
@@ -7,6 +7,7 @@
  */
 require('addon/pumpio/oauth/http.php');
 require('addon/pumpio/oauth/oauth_client.php');
+require_once('include/enotify.php');
 
 define('PUMPIO_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
@@ -18,6 +19,7 @@ function pumpio_install() {
        register_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
        register_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
        register_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
+       register_hook('check_item_notification','addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
 }
 
 function pumpio_uninstall() {
@@ -28,6 +30,7 @@ function pumpio_uninstall() {
        unregister_hook('connector_settings_post', 'addon/pumpio/pumpio.php', 'pumpio_settings_post');
        unregister_hook('cron', 'addon/pumpio/pumpio.php', 'pumpio_cron');
        unregister_hook('queue_predeliver', 'addon/pumpio/pumpio.php', 'pumpio_queue_hook');
+       unregister_hook('check_item_notification','addon/pumpio/pumpio.php', 'pumpio_check_item_notification');
 }
 
 function pumpio_module() {}
@@ -57,6 +60,14 @@ function pumpio_content(&$a) {
        return $o;
 }
 
+function pumpio_check_item_notification($a, &$notification_data) {
+       $hostname = get_pconfig($notification_data["uid"], 'pumpio','host');
+       $username = get_pconfig($notification_data["uid"], "pumpio", "user");
+
+        $notification_data["profiles"][] = "https://".$hostname."/".$username;
+}
+
+
 function pumpio_registerclient(&$a, $host) {
 
        $url = "https://".$host."/api/client/register";
@@ -857,17 +868,19 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
 
        // Searching for the liked post
        // Two queries for speed issues
-       $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+       $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
                                dbesc($post->object->id),
-                               intval($uid)
+                               intval($uid),
+                               dbesc(NETWORK_PUMPIO)
                );
 
        if (count($r))
                $orig_post = $r[0];
        else {
-               $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
+               $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
                                        dbesc($post->object->id),
-                                       intval($uid)
+                                       intval($uid),
+                                       dbesc(NETWORK_PUMPIO)
                        );
 
                if (!count($r))
@@ -1306,42 +1319,44 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
                if (link_compare($own_id, $postarray['author-link']))
                        return $top_item;
 
-               $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
-                               dbesc($postarray['parent-uri']),
-                               intval($uid)
-                               );
-
-               if(count($myconv)) {
-
-                       foreach($myconv as $conv) {
-                               // now if we find a match, it means we're in this conversation
-
-                               if(!link_compare($conv['author-link'],$importer_url) AND !link_compare($conv['author-link'],$own_id))
-                                       continue;
+               if (!function_exists("check_item_notification")) {
+                       $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0",
+                                       dbesc($postarray['parent-uri']),
+                                       intval($uid)
+                                       );
 
-                               require_once('include/enotify.php');
-
-                               $conv_parent = $conv['parent'];
-
-                               notification(array(
-                                       'type'         => NOTIFY_COMMENT,
-                                       'notify_flags' => $user[0]['notify-flags'],
-                                       'language'     => $user[0]['language'],
-                                       'to_name'      => $user[0]['username'],
-                                       'to_email'     => $user[0]['email'],
-                                       'uid'          => $user[0]['uid'],
-                                       'item'         => $postarray,
-                                       'link'         => $a->get_baseurl().'/display/'.urlencode(get_item_guid($top_item)),
-                                       'source_name'  => $postarray['author-name'],
-                                       'source_link'  => $postarray['author-link'],
-                                       'source_photo' => $postarray['author-avatar'],
-                                       'verb'         => ACTIVITY_POST,
-                                       'otype'        => 'item',
-                                       'parent'       => $conv_parent,
-                                       ));
-
-                               // only send one notification
-                               break;
+                       if(count($myconv)) {
+
+                               foreach($myconv as $conv) {
+                                       // now if we find a match, it means we're in this conversation
+
+                                       if(!link_compare($conv['author-link'],$importer_url) AND !link_compare($conv['author-link'],$own_id))
+                                               continue;
+
+                                       require_once('include/enotify.php');
+
+                                       $conv_parent = $conv['parent'];
+
+                                       notification(array(
+                                               'type'         => NOTIFY_COMMENT,
+                                               'notify_flags' => $user[0]['notify-flags'],
+                                               'language'     => $user[0]['language'],
+                                               'to_name'      => $user[0]['username'],
+                                               'to_email'     => $user[0]['email'],
+                                               'uid'          => $user[0]['uid'],
+                                               'item'         => $postarray,
+                                               'link'         => $a->get_baseurl().'/display/'.urlencode(get_item_guid($top_item)),
+                                               'source_name'  => $postarray['author-name'],
+                                               'source_link'  => $postarray['author-link'],
+                                               'source_photo' => $postarray['author-avatar'],
+                                               'verb'         => ACTIVITY_POST,
+                                               'otype'        => 'item',
+                                               'parent'       => $conv_parent,
+                                               ));
+
+                                       // only send one notification
+                                       break;
+                               }
                        }
                }
        }
index b5e486c68a35cd1a770de56b81d8ed8d11877f71..22afa03980d04d28cdb6aaefafec0b3d75c9a769 100755 (executable)
@@ -26,7 +26,7 @@ function rendertime_page_end(&$a, &$o) {
 
        $duration = microtime(true)-$a->performance["start"];
 
-       if (is_site_admin() AND ($_GET["mode"] != "minimal") AND !$a->is_mobile AND !$a->is_tablet)
+       if (is_site_admin() AND ($_GET["mode"] != "minimal") AND !$a->is_mobile AND !$a->is_tablet) {
                $o = $o.'<div class="renderinfo">'.sprintf(t("Performance: Database: %s, Network: %s, Rendering: %s, Parser: %s, I/O: %s, Other: %s, Total: %s"),
                                                round($a->performance["database"], 3),
                                                round($a->performance["network"], 3),
@@ -41,4 +41,23 @@ function rendertime_page_end(&$a, &$o) {
                                                //round($a->performance["plugin"], 3)
                                                )."</div>";
 
+               if (get_config("rendertime", "callstack")) {
+                       $o .= "<pre>";
+                       $o .= "\nDatabase:\n";
+                       foreach ($a->callstack["database"] AS $func => $time) {
+                               $time = round($time, 3);
+                               if ($time > 0)
+                                       $o .= $func.": ".$time."\n";
+                       }
+
+                       $o .= "\nNetwork:\n";
+                       foreach ($a->callstack["network"] AS $func => $time) {
+                               $time = round($time, 3);
+                               if ($time > 0)
+                                       $o .= $func.": ".$time."\n";
+                       }
+
+                       $o .= "</pre>";
+               }
+       }
 }
index 2513dd281b130bd03ea13cc36ab7951bd58a1138..1661c1696ec6cda341c9a31a62168c4545dde360 100644 (file)
@@ -14,7 +14,6 @@ CREATE TABLE IF NOT EXISTS `retriever_item` (
        `item-uid` int(10) unsigned NOT NULL DEFAULT '0',
        `contact-id` int(10) unsigned NOT NULL DEFAULT '0',
        `resource` int(11) NOT NULL,
-       `parent` int(11) NOT NULL,
        `finished` tinyint(1) unsigned NOT NULL DEFAULT '0',
        KEY `resource` (`resource`),
        KEY `all` (`item-uri`, `item-uid`, `contact-id`),
@@ -31,5 +30,7 @@ CREATE TABLE IF NOT EXISTS `retriever_resource` (
        `last-try` timestamp NULL DEFAULT NULL,
        `num-tries` int(11) NOT NULL DEFAULT 0,
        `data` mediumtext NOT NULL,
+       `http-code` smallint(1) unsigned NULL DEFAULT NULL,
+       `redirect-url` varchar(800) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL,
        PRIMARY KEY (`id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
index 048340181351fe24b04fa9e4c2bab23c191e0779..a05e2e3fa927af9e659abac8e0ed691c37911d20 100644 (file)
@@ -2,10 +2,13 @@
 /**
  * Name: Retrieve Feed Content
  * Description: Follow the permalink of RSS/Atom feed items and replace the summary with the full content.
- * Version: 0.2
+ * Version: 1.0
  * Author: Matthew Exon <http://mat.exon.name>
  */
 
+require_once('include/html2bbcode.php');       
+require_once('include/Photo.php');     
+
 function retriever_install() {
     register_hook('plugin_settings', 'addon/retriever/retriever.php', 'retriever_plugin_settings');
     register_hook('plugin_settings_post', 'addon/retriever/retriever.php', 'retriever_plugin_settings_post');
@@ -13,12 +16,6 @@ function retriever_install() {
     register_hook('contact_photo_menu', 'addon/retriever/retriever.php', 'retriever_contact_photo_menu');
     register_hook('cron', 'addon/retriever/retriever.php', 'retriever_cron');
 
-    $schema = file_get_contents(dirname(__file__).'/database.sql');
-    $arr = explode(';', $schema);
-    foreach ($arr as $a) {
-        $r = q($a);
-    }
-
     $r = q("SELECT `id` FROM `pconfig` WHERE `cat` LIKE 'retriever_%%'");
     if (count($r) || (get_config('retriever', 'dbversion') == '0.1')) {
         $retrievers = array();
@@ -33,17 +30,21 @@ function retriever_install() {
             q("INSERT INTO `retriever_rule` (`uid`, `contact-id`, `data`) VALUES (%d, %d, '%s')",
               intval($uid), intval($k), dbesc(json_encode($v)));
         }
-        q("DELETE FROM `pconfig` WHERE `cat` LIKE 'retriever%%'");
+        q("DELETE FROM `pconfig` WHERE `cat` LIKE 'retriever_%%'");
+        set_config('retriever', 'dbversion', '0.2');
     }
     if (get_config('retriever', 'dbversion') == '0.2') {
         q("ALTER TABLE `retriever_resource` DROP COLUMN `retriever`");
+        set_config('retriever', 'dbversion', '0.3');
     }
     if (get_config('retriever', 'dbversion') == '0.3') {
         q("ALTER TABLE `retriever_item` MODIFY COLUMN `item-uri` varchar(800) CHARACTER SET ascii NOT NULL");
         q("ALTER TABLE `retriever_resource` MODIFY COLUMN `url` varchar(800) CHARACTER SET ascii NOT NULL");
+        set_config('retriever', 'dbversion', '0.4');
     }
     if (get_config('retriever', 'dbversion') == '0.4') {
         q("ALTER TABLE `retriever_item` ADD COLUMN `finished` tinyint(1) unsigned NOT NULL DEFAULT '0'");
+        set_config('retriever', 'dbversion', '0.5');
     }
     if (get_config('retriever', 'dbversion') == '0.5') {
         q('ALTER TABLE `retriever_resource` CHANGE `created` `created` timestamp NOT NULL DEFAULT now()');
@@ -51,6 +52,7 @@ function retriever_install() {
         q('ALTER TABLE `retriever_resource` CHANGE `last-try` `last-try` timestamp NULL DEFAULT NULL');
         q('ALTER TABLE `retriever_item` DROP KEY `all`');
         q('ALTER TABLE `retriever_item` ADD KEY `all` (`item-uri`, `item-uid`, `contact-id`)');
+        set_config('retriever', 'dbversion', '0.6');
     }
     if (get_config('retriever', 'dbversion') == '0.6') {
         q('ALTER TABLE `retriever_item` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
@@ -58,6 +60,7 @@ function retriever_install() {
         q('ALTER TABLE `retriever_resource` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
         q('ALTER TABLE `retriever_resource` CHANGE `url` `url`  varchar(800) CHARACTER SET ascii COLLATE ascii_bin NOT NULL');
         q('ALTER TABLE `retriever_rule` CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin');
+        set_config('retriever', 'dbversion', '0.7');
     }
     if (get_config('retriever', 'dbversion') == '0.7') {
         $r = q("SELECT `id`, `data` FROM `retriever_rule`");
@@ -113,8 +116,26 @@ function retriever_install() {
             $r = q('UPDATE `retriever_rule` SET `data` = "%s" WHERE `id` = %d', dbesc(json_encode($data)), $rr['id']);
             logger('retriever_install: retriever ' . $rr['id'] . ' new config ' . json_encode($data), LOGGER_DATA);
         }
+        set_config('retriever', 'dbversion', '0.8');
+    }
+    if (get_config('retriever', 'dbversion') == '0.8') {
+        q("ALTER TABLE `retriever_resource` ADD COLUMN `http-code` smallint(1) unsigned NULL DEFAULT NULL");
+        set_config('retriever', 'dbversion', '0.9');
+    }
+    if (get_config('retriever', 'dbversion') == '0.9') {
+        q("ALTER TABLE `retriever_item` DROP COLUMN `parent`");
+        q("ALTER TABLE `retriever_resource` ADD COLUMN `redirect-url` varchar(800) CHARACTER SET ascii COLLATE ascii_bin NULL DEFAULT NULL");
+        set_config('retriever', 'dbversion', '0.10');
+    }
+
+    if (get_config('retriever', 'dbversion') != '0.10') {
+        $schema = file_get_contents(dirname(__file__).'/database.sql');
+        $arr = explode(';', $schema);
+        foreach ($arr as $a) {
+            $r = q($a);
+        }
+        set_config('retriever', 'dbversion', '0.10');
     }
-    set_config('retriever', 'dbversion', '0.8');
 }
 
 function retriever_uninstall() {
@@ -158,13 +179,18 @@ function retriever_retrieve_items($max_items) {
     }
 
     $retrieve_items = $max_items - $retriever_item_count;
+    logger('retriever_retrieve_items: asked for maximum ' . $max_items . ', already retrieved ' . $retriever_item_count . ', retrieve ' . $retrieve_items, LOGGER_DEBUG);
     do {
         $r = q("SELECT * FROM `retriever_resource` WHERE `completed` IS NULL AND (`last-try` IS NULL OR %s) ORDER BY `last-try` ASC LIMIT %d",
                dbesc(implode($schedule_clauses, ' OR ')),
                intval($retrieve_items));
+        if (!is_array($r)) {
+            break;
+        }
         if (count($r) == 0) {
             break;
         }
+        logger('retriever_retrieve_items: found ' . count($r) . ' waiting resources in database', LOGGER_DEBUG);
         foreach ($r as $rr) {
             retrieve_resource($rr);
             $retriever_item_count++;
@@ -182,22 +208,24 @@ function retriever_retrieve_items($max_items) {
     if (!$r) {
         $r = array();
     }
+    logger('retriever_retrieve_items: items waiting even though resource has completed: ' . count($r), LOGGER_DEBUG);
     foreach ($r as $rr) {
         $resource = q("SELECT * FROM retriever_resource WHERE `id` = %d", $rr['resource']);
         $retriever_item = retriever_get_retriever_item($rr['item']);
         if (!$retriever_item) {
-            logger('retriever_retrieve_items: no retriever item with id ' . $rr['item']);
+            logger('retriever_retrieve_items: no retriever item with id ' . $rr['item'], LOGGER_NORMAL);
             continue;
         }
         $item = retriever_get_item($retriever_item);
         if (!$item) {
-            logger('retriever_retrieve_items: no item ' . $retriever_item['item-uri']);
+            logger('retriever_retrieve_items: no item ' . $retriever_item['item-uri'], LOGGER_NORMAL);
             continue;
         }
         $retriever = get_retriever($item['contact-id'], $item['uid']);
         if (!$retriever) {
             logger('retriever_retrieve_items: no retriever for item ' .
-                   $retriever_item['item-uri'] . ' ' . $retriever_item['uid'] . ' ' . $item['contact-id']);
+                   $retriever_item['item-uri'] . ' ' . $retriever_item['uid'] . ' ' . $item['contact-id'],
+                   LOGGER_NORMAL);
             continue;
         }
         retriever_apply_completed_resource_to_item($retriever, $item, $resource[0]);
@@ -212,22 +240,37 @@ function retriever_tidy() {
     q("DELETE FROM retriever_resource WHERE completed IS NULL AND created < DATE_SUB(now(), INTERVAL 3 MONTH)");
 
     $r = q("SELECT retriever_item.id FROM retriever_item LEFT OUTER JOIN retriever_resource ON (retriever_item.resource = retriever_resource.id) WHERE retriever_resource.id is null");
+    logger('retriever_tidy: found ' . count($r) . ' retriever_items with no retriever_resource');
     foreach ($r as $rr) {
         q('DELETE FROM retriever_item WHERE id = %d', intval($rr['id']));
     }
 }
 
 function retrieve_resource($resource) {
+    $a = get_app();
+
     logger('retrieve_resource: ' . ($resource['num-tries'] + 1) .
            ' attempt at resource ' . $resource['id'] . ' ' . $resource['url'], LOGGER_DEBUG);
-    q("UPDATE `retriever_resource` SET `last-try` = now(), `num-tries` = `num-tries` + 1 WHERE id = %d",
+    $redirects;
+    $cookiejar = tempnam(get_temppath(), 'cookiejar-retriever-');
+    $fetch_result = z_fetch_url($resource['url'], $resource['binary'], $redirects, array('cookiejar' => $cookiejar));
+    unlink($cookiejar);
+    $resource['data'] = $fetch_result['body'];
+    $resource['http-code'] = $a->get_curl_code();
+    $resource['type'] = $a->get_curl_content_type();
+    $resource['redirect-url'] = $fetch_result['redirect_url'];
+    logger('retrieve_resource: got code ' . $resource['http-code'] .
+           ' retrieving resource ' . $resource['id'] .
+           ' final url ' . $resource['redirect-url'], LOGGER_DEBUG);
+    q("UPDATE `retriever_resource` SET `last-try` = now(), `num-tries` = `num-tries` + 1, `http-code` = %d, `redirect-url` = '%s' WHERE id = %d",
+      intval($resource['http-code']),
+      dbesc($resource['redirect-url']),
       intval($resource['id']));
-    $data = fetch_url($resource['url'], $resource['binary'], $resource['type']);
-    $resource['type'] = get_app()->get_curl_content_type();
-    if ($data) {
-        $resource['data'] = $data;
+    if ($resource['data']) {
         q("UPDATE `retriever_resource` SET `completed` = now(), `data` = '%s', `type` = '%s' WHERE id = %d",
-          dbesc($data), dbesc($resource['type']), intval($resource['id']));
+          dbesc($resource['data']),
+          dbesc($resource['type']),
+          intval($resource['id']));
         retriever_resource_completed($resource);
     }
 }
@@ -304,6 +347,7 @@ function apply_retrospective($retriever, $num) {
            intval($retriever['contact-id']), intval($num));
     foreach ($r as $item) {
         q('UPDATE `item` SET `visible` = 0 WHERE `id` = %d', $item['id']);
+        q('UPDATE `thread` SET `visible` = 0 WHERE `iid` = %d', $item['id']);
         retriever_on_item_insert($retriever, $item);
     }
 }
@@ -330,18 +374,53 @@ function retriever_on_item_insert($retriever, &$item) {
 
 function add_retriever_resource($url, $binary = false) {
     logger('add_retriever_resource: ' . $url, LOGGER_DEBUG);
+
+    $scheme = parse_url($url, PHP_URL_SCHEME);
+    if ($scheme == 'data') {
+        $fp = fopen($url, 'r');
+        $meta = stream_get_meta_data($fp);
+        $type = $meta['mediatype'];
+        $data = stream_get_contents($fp);
+        fclose($fp);
+
+        $url = 'md5://' . hash('md5', $url);
+        $r = q("SELECT * FROM `retriever_resource` WHERE `url` = '%s'", dbesc($url));
+        $resource = $r[0];
+        if (count($r)) {
+            logger('add_retriever_resource: Resource ' . $url . ' already requested', LOGGER_DEBUG);
+            return $resource;
+        }
+
+        logger('retrieve_resource: got data URL type ' . $resource['type'], LOGGER_DEBUG);
+        q("INSERT INTO `retriever_resource` (`type`, `binary`, `url`, `completed`, `data`) " .
+          "VALUES ('%s', %d, '%s', now(), '%s')",
+          dbesc($type),
+          intval($binary ? 1 : 0),
+          dbesc($url),
+          dbesc($data));
+        $r = q("SELECT * FROM `retriever_resource` WHERE `url` = '%s'", dbesc($url));
+        $resource = $r[0];
+        if (count($r)) {
+            retriever_resource_completed($resource);
+        }
+        return $resource;
+    }
+
+    if (strlen($url) > 800) {
+        logger('add_retriever_resource: URL is longer than 800 characters', LOGGER_NORMAL);
+    }
+
     $r = q("SELECT * FROM `retriever_resource` WHERE `url` = '%s'", dbesc($url));
     $resource = $r[0];
     if (count($r)) {
         logger('add_retriever_resource: Resource ' . $url . ' already requested', LOGGER_DEBUG);
-        return $r[0];
-    }
-    else {
-        q("INSERT INTO `retriever_resource` (`binary`, `url`) " .
-          "VALUES (%d, '%s')", intval($binary ? 1 : 0), dbesc($url));
-        $r = q("SELECT * FROM `retriever_resource` WHERE `url` = '%s'", dbesc($url));
-        return $r[0];
+        return $resource;
     }
+
+    q("INSERT INTO `retriever_resource` (`binary`, `url`) " .
+      "VALUES (%d, '%s')", intval($binary ? 1 : 0), dbesc($url));
+    $r = q("SELECT * FROM `retriever_resource` WHERE `url` = '%s'", dbesc($url));
+    return $r[0];
 }
 
 function add_retriever_item(&$item, $resource) {
@@ -371,38 +450,26 @@ function retriever_get_encoding($resource) {
     return 'utf-8';
 }
 
-function retriever_construct_xpath($spec) {
-    if (gettype($spec) != "array") {
-        return;
+function retriever_apply_xslt_text($xslt_text, $doc) {
+    if (!$xslt_text) {
+        logger('retriever_apply_xslt_text: empty XSLT text', LOGGER_NORMAL);
+        return $doc;
     }
-    $components = array();
-    foreach ($spec as $clause) {
-        if (!$clause['attribute']) {
-            $components[] = $clause['element'];
-            continue;
-        }
-        if ($clause['attribute'] === 'class') {
-            $components[] =
-                $clause['element'] .
-                "[contains(concat(' ', normalize-space(@class), ' '), ' " .
-                $clause['value'] . " ')]";
-        }
-        else {
-            $components[] =
-                $clause['element'] . '[@' .
-                $clause['attribute'] . "='" .
-                $clause['value'] . "']";
-        }
+    $xslt_doc = new DOMDocument();
+    if (!$xslt_doc->loadXML($xslt_text)) {
+        logger('retriever_apply_xslt_text: could not load XML', LOGGER_NORMAL);
+        return $doc;
     }
-    // It would be better to do this in smarty3 in extract.tpl
-    return implode('|', $components);
+    $xp = new XsltProcessor();
+    $xp->importStylesheet($xslt_doc);
+    $result = $xp->transformToDoc($doc);
+    return $result;
 }
 
 function retriever_apply_dom_filter($retriever, &$item, $resource) {
-    logger('retriever_apply_dom_filter: applying XSLT to ' . $item['id'] . ' ' . $item['plink'], LOGGER_DEBUG);
-    require_once('include/html2bbcode.php');   
+    logger('retriever_apply_dom_filter: applying XSLT to ' . $item['id'] . ' ' . $item['uri'] . ' contact ' . $item['contact-id'], LOGGER_DEBUG);
 
-    if (!$retriever['data']['include']) {
+    if (!$retriever['data']['include'] && !$retriever['data']['customxslt']) {
         return;
     }
     if (!$resource['data']) {
@@ -411,33 +478,42 @@ function retriever_apply_dom_filter($retriever, &$item, $resource) {
     }
 
     $encoding = retriever_get_encoding($resource);
-    logger('@@@ item type ' . $resource['type'] . ' encoding ' . $encoding);
-    $extracter_template = get_markup_template('extract.tpl', 'addon/retriever/');
-    $doc = new DOMDocument('1.0', 'utf-8');
+    $content = mb_convert_encoding($resource['data'], 'HTML-ENTITIES', $encoding);
+    $doc = new DOMDocument('1.0', 'UTF-8');
     if (strpos($resource['type'], 'html') !== false) {
-        @$doc->loadHTML($resource['data']);
+        @$doc->loadHTML($content);
     }
     else {
-        $doc->loadXML($resource['data']);
+        $doc->loadXML($content);
     }
-    logger('@@@ actual encoding of document is ' . $doc->encoding);
 
-    $components = parse_url($item['plink']);
+    $params = array('$spec' => $retriever['data']);
+    $extract_template = get_markup_template('extract.tpl', 'addon/retriever/');
+    $extract_xslt = replace_macros($extract_template, $params);
+    if ($retriever['data']['include']) {
+        $doc = retriever_apply_xslt_text($extract_xslt, $doc);
+    }
+    if ($retriever['data']['customxslt']) {
+        $doc = retriever_apply_xslt_text($retriever['data']['customxslt'], $doc);
+    }
+    if (!$doc) {
+        logger('retriever_apply_dom_filter: failed to apply extract XSLT template', LOGGER_NORMAL);
+        return;
+    }
+
+    $components = parse_url($resource['redirect-url']);
     $rooturl = $components['scheme'] . "://" . $components['host'];
     $dirurl = $rooturl . dirname($components['path']) . "/";
+    $params = array('$dirurl' => $dirurl, '$rooturl' => $rooturl);
+    $fix_urls_template = get_markup_template('fix-urls.tpl', 'addon/retriever/');
+    $fix_urls_xslt = replace_macros($fix_urls_template, $params);
+    $doc = retriever_apply_xslt_text($fix_urls_xslt, $doc);
+    if (!$doc) {
+        logger('retriever_apply_dom_filter: failed to apply fix urls XSLT template', LOGGER_NORMAL);
+        return;
+    }
 
-    $params = array('$include' => retriever_construct_xpath($retriever['data']['include']),
-                    '$exclude' => retriever_construct_xpath($retriever['data']['exclude']),
-                    '$pageurl' => $item['plink'],
-                    '$dirurl' => $dirurl,
-                    '$rooturl' => $rooturl);
-    $xslt = replace_macros($extracter_template, $params);
-    $xmldoc = new DOMDocument();
-    $xmldoc->loadXML($xslt);
-    $xp = new XsltProcessor();
-    $xp->importStylesheet($xmldoc);
-    $transformed = $xp->transformToXML($doc);
-    $item['body'] = html2bbcode($transformed);
+    $item['body'] = html2bbcode($doc->saveXML());
     if (!strlen($item['body'])) {
         logger('retriever_apply_dom_filter retriever ' . $retriever['id'] . ' item ' . $item['id'] . ': output was empty', LOGGER_NORMAL);
         return;
@@ -485,8 +561,9 @@ function retriever_check_item_completed(&$item)
         q("UPDATE `item` SET `visible` = %d WHERE `id` = %d",
           intval($item['visible']),
           intval($item['id']));
-// disable due to possible security issue
-//        proc_run('php', "include/notifier.php", 'edit_post', $item['id']);
+        q("UPDATE `thread` SET `visible` = %d WHERE `iid` = %d",
+          intval($item['visible']),
+          intval($item['id']));
     }
 }
 
@@ -562,8 +639,6 @@ function retriever_store_photo($item, &$resource) {
 }
 
 function retriever_transform_images(&$item, $resource) {
-    require_once('include/Photo.php'); 
-
     if (!$resource["data"]) {
         logger('retriever_transform_images: no data available for '
                . $resource['id'] . ' ' . $resource['url'], LOGGER_NORMAL);
@@ -616,7 +691,7 @@ function retriever_content($a) {
         if (x($_POST["id"])) {
             $retriever = get_retriever($a->argv[1], local_user(), true);
             $retriever["data"] = array();
-            foreach (array('pattern', 'replace', 'enable', 'images') as $setting) {
+            foreach (array('pattern', 'replace', 'enable', 'images', 'customxslt') as $setting) {
                 if (x($_POST['retriever_' . $setting])) {
                     $retriever["data"][$setting] = $_POST['retriever_' . $setting];
                 }
@@ -672,8 +747,15 @@ function retriever_content($a) {
                                                       t('Retrospectively Apply'),
                                                       '0',
                                                       t('Reapply the rules to this number of posts')),
+                                                  '$customxslt' => array(
+                                                      'retriever_customxslt',
+                                                      t('Custom XSLT'),
+                                                      $retriever['data']['customxslt'],
+                                                      t("When standard rules aren't enough, apply custom XSLT to the article")),
                                                   '$title' => t('Retrieve Feed Content'),
                                                   '$help' => $a->get_baseurl() . '/retriever/help',
+                                                  '$help_t' => t('Get Help'),
+                                                  '$submit_t' => t('Submit'),
                                                   '$submit' => t('Save Settings'),
                                                   '$id' => ($retriever["id"] ? $retriever["id"] : "create"),
                                                   '$tag_t' => t('Tag'),
@@ -706,6 +788,13 @@ function retriever_post_remote_hook(&$a, &$item) {
         retriever_on_item_insert($retriever, $item);
     }
     else {
+        if (get_pconfig($item["uid"], 'retriever', 'oembed')) {
+            // Convert to HTML and back to take advantage of bbcode's resolution of oembeds.
+            $body = html2bbcode(bbcode($item['body']));
+            if ($body) {
+                $item['body'] = $body;
+            }
+        }
         if (get_pconfig($item["uid"], 'retriever', 'all_photos')) {
             retrieve_images($item, null);
         }
@@ -715,21 +804,35 @@ function retriever_post_remote_hook(&$a, &$item) {
 
 function retriever_plugin_settings(&$a,&$s) {
     $all_photos = get_pconfig(local_user(), 'retriever', 'all_photos');
-    $all_photos_mu = ($all_photos == 'on') ? ' checked="true"' : '';
+    $oembed = get_pconfig(local_user(), 'retriever', 'oembed');
     $template = get_markup_template('/settings.tpl', 'addon/retriever/');
     $s .= replace_macros($template, array(
+                             '$allphotos' => array(
+                                 'retriever_all_photos',
+                                 t('All Photos'),
+                                 $all_photos,
+                                 t('Check this to retrieve photos for all posts')),
+                             '$oembed' => array(
+                                 'retriever_oembed',
+                                 t('Resolve OEmbed'),
+                                 $oembed,
+                                 t('Check this to attempt to retrieve embedded content for all posts - useful e.g. for Facebook posts')),
                              '$submit' => t('Save Settings'),
                              '$title' => t('Retriever Settings'),
-                             '$help' => $a->get_baseurl() . '/retriever/help',
-                             '$all_photos' => $all_photos_mu,
-                             '$all_photos_t' => t('All Photos')));
+                             '$help' => $a->get_baseurl() . '/retriever/help'));
 }
 
 function retriever_plugin_settings_post($a,$post) {
-    if ($_POST['all_photos']) {
-        set_pconfig(local_user(), 'retriever', 'all_photos', $_POST['all_photos']);
+    if ($_POST['retriever_all_photos']) {
+        set_pconfig(local_user(), 'retriever', 'all_photos', $_POST['retriever_all_photos']);
     }
     else {
         del_pconfig(local_user(), 'retriever', 'all_photos');
     }
+    if ($_POST['retriever_oembed']) {
+        set_pconfig(local_user(), 'retriever', 'oembed', $_POST['retriever_oembed']);
+    }
+    else {
+        del_pconfig(local_user(), 'retriever', 'oembed');
+    }
 }
index 36b9181337f682bfed376b8bee77baa23c19e48d..fd38bde67642f6b7a0531c3607833032c5209b4e 100644 (file)
@@ -1,18 +1,26 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 <?xml version="1.0" encoding="utf-8"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 
   <xsl:template match="text()"/>
 
-  <xsl:template match="{{$include}}">
+{{function clause_xpath}}
+{{if !$clause.attribute}}
+{{$clause.element}}{{elseif $clause.attribute == 'class'}}
+{{$clause.element}}[contains(concat(' ', normalize-space(@class), ' '), '{{$clause.value}}')]{{else}}
+{{$clause.element}}[@{{$clause.attribute}}='{{$clause.value}}']{{/if}}
+{{/function}}
+
+{{foreach $spec.include as $clause}}
+  <xsl:template match="{{clause_xpath clause=$clause}}">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*" mode="remove"/>
     </xsl:copy>
   </xsl:template>
+{{/foreach}}
+
+{{foreach $spec.exclude as $clause}}
+  <xsl:template match="{{clause_xpath clause=$clause}}" mode="remove"/>
+{{/foreach}}
 
   <xsl:template match="node()|@*" mode="remove">
     <xsl:copy>
     </xsl:copy>
   </xsl:template>
 
-{{if $exclude}}
-  <xsl:template match="{{$exclude}}" mode="remove"/>
-{{/if}}
-
-  <!-- attempt to replace relative URLs with absolute URLs -->
-  <!-- http://stackoverflow.com/questions/3824631/replace-href-value-in-anchor-tags-of-html-using-xslt -->
-
-  <xsl:template match="*/@src[starts-with(.,'.')]" mode="remove">
-    <xsl:attribute name="src">
-      <xsl:value-of select="concat('{{$dirurl}}',.)"/>
-    </xsl:attribute>
-  </xsl:template>
-  <xsl:template match="*/@src[starts-with(.,'/')]" mode="remove">
-    <xsl:attribute name="src">
-      <xsl:value-of select="concat('{{$rooturl}}',.)"/>
-    </xsl:attribute>
-  </xsl:template>
-
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
diff --git a/retriever/templates/fix-urls.tpl b/retriever/templates/fix-urls.tpl
new file mode 100644 (file)
index 0000000..5bb665a
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- attempt to replace relative URLs with absolute URLs -->
+<!-- http://stackoverflow.com/questions/3824631/replace-href-value-in-anchor-tags-of-html-using-xslt -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+  <xsl:output method="xml"/>
+
+  <xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="node()|@*"/>
+    </xsl:copy>
+  </xsl:template>
+
+  <xsl:template match="*/@src[starts-with(.,'.')]">
+    <xsl:attribute name="src">
+      <xsl:value-of select="concat('{{$dirurl}}',.)"/>
+    </xsl:attribute>
+  </xsl:template>
+  <xsl:template match="*/@src[starts-with(.,'/')]">
+    <xsl:attribute name="src">
+      <xsl:value-of select="concat('{{$rooturl}}',.)"/>
+    </xsl:attribute>
+  </xsl:template>
+
+</xsl:stylesheet>
index 23ae297b7e080779883466702e159177f75cd2b1..10b421d051f724edb88ba000dd959390dc608b91 100644 (file)
@@ -1,8 +1,3 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 <h2>Retriever Plugin Help</h2>
 <p>
 This plugin replaces the short excerpts you normally get in RSS feeds
@@ -147,7 +142,7 @@ Photos" box in the "Retriever Settings" section and click "Submit".
 </p>
 <h2>Configure Feeds:</h2>
 <div>
-{{ for $feeds as $feed }}
-{{ inc contact_template.tpl with $contact=$feed }}{{ endinc }}
-{{ endfor }}
+{{foreach $feeds as $feed}}
+{{include file='contact_template.tpl' contact=$feed}}
+{{/foreach}}
 </div>
index 79add59aad07b34fc961b24d062104661bed6ae0..228d0326776e90eefefa3e8b909efa206d9a14db 100644 (file)
@@ -1,8 +1,3 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 <div class="settings-block">
   <script language="javascript">
 function retriever_add_row(id)
@@ -47,7 +42,7 @@ function retriever_remove_row(id, number)
 }
   </script>
   <h2>{{$title}}</h2>
-  <p><a href="{{$help}}">Get Help</a></p>
+  <p><a href="{{$help}}">{{$help_t}}</a></p>
   <form method="post">
     <input type="hidden" name="id" value="{{$id}}">
 {{include file="field_checkbox.tpl" field=$enable}}
@@ -111,6 +106,7 @@ function retriever_remove_row(id, number)
       </table>
       <input type="button" onclick="retriever_add_row('retriever-exclude')" value="{{$add_t}}">
     </div>
-    <input type="submit" size="70" value="{{$submit}}">
+{{include file="field_textarea.tpl" field=$customxslt}}
+    <input type="submit" size="70" value="{{$submit_t}}">
   </form>
 </div>
index 3bc71559f285f63a927c7493304263a7fa9d86ea..8bfe8db04096a57a291129083aec557a96ab8ff3 100644 (file)
@@ -1,22 +1,9 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 <div class="settings-block">
   <h3>{{$title}}</h3>
   <p>
     <a href="{{$help}}">Get Help</a>
   </p>
-  <table>
-    <tbody>
-      <tr>
-        <td>{{$all_photos_t}}:</td>
-        <td><input class="checkbox" type="checkbox" name="all_photos" {{$all_photos}}></td>
-      </tr>
-      <tr>
-        <td colspan="2"><input type="submit" value="{{$submit}}"></td>
-      </tr>
-    </tbody>
-  </table>
+{{include file="field_checkbox.tpl" field=$allphotos}}
+{{include file="field_checkbox.tpl" field=$oembed}}
+  <input type="submit" value="{{$submit}}">
 </div>
index 50a61606831f75da69d328846059c093c1edf9d0..d8c1533024704673b0ce5534d9d475e427912b4b 100755 (executable)
@@ -130,10 +130,9 @@ function show_button($a, &$b) {
        $b = <<< EOT
        <div id="profile-smiley-wrapper" style="display: block;" >
                <img src="$image_url" class="smiley_button" onclick="toggle_smileybutton()" alt="smiley">
-       </div>
-
-       <div id="smileybutton" style="display:none;">
-       $s
+               <div id="smileybutton" style="display:none;">
+               $s
+               </div>
        </div>
 
        <script>
index f92dde76c8e60012311aab25b9320ca3aec392bb..e030232f184fb42e5b01ea415e2774a6d53b49e7 100644 (file)
@@ -44,6 +44,7 @@
 define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
 require_once('library/twitteroauth.php');
+require_once('include/enotify.php');
 
 class StatusNetOAuth extends TwitterOAuth {
     function get_maxlength() {
@@ -119,6 +120,7 @@ function statusnet_install() {
        register_hook('jot_networks',    'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
        register_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
        register_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+       register_hook('check_item_notification','addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
        logger("installed GNU Social");
 }
 
@@ -131,6 +133,7 @@ function statusnet_uninstall() {
        unregister_hook('jot_networks',    'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
        unregister_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
        unregister_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+       unregister_hook('check_item_notification','addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
 
        // old setting - remove only
        unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
@@ -139,6 +142,10 @@ function statusnet_uninstall() {
 
 }
 
+function statusnet_check_item_notification($a, &$notification_data) {
+       $notification_data["profiles"][] = get_pconfig($notification_data["uid"], 'statusnet', 'own_url');
+}
+
 function statusnet_jot_nets(&$a,&$b) {
        if(! local_user())
                return;
@@ -1443,7 +1450,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted home timeline item '.$item);
 
-                                       if ($item != 0)
+                                       if ($item AND !function_exists("check_item_notification"))
                                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                                }
 
@@ -1493,6 +1500,9 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                        $postarray["id"] = $item;
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted mention timeline item '.$item);
+
+                                       if ($item AND function_exists("check_item_notification"))
+                                               check_item_notification($item, $uid, NOTIFY_TAGSELF);
                                }
                        }
 
@@ -1505,7 +1515,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                $parent_id = $r[0]['parent'];
                        }
 
-                       if ($item != 0) {
+                       if (($item != 0) AND !function_exists("check_item_notification")) {
                                require_once('include/enotify.php');
                                notification(array(
                                        'type'         => NOTIFY_TAGSELF,
@@ -1536,6 +1546,7 @@ function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $
        $api     = get_pconfig($uid, 'statusnet', 'baseapi');
        $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
        $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $own_url = get_pconfig($uid, 'statusnet', 'own_url');
 
        require_once('library/twitteroauth.php');
 
@@ -1559,7 +1570,7 @@ function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $
 
                        logger('statusnet_complete_conversation: User '.$self["nick"].' posted home timeline item '.$item);
 
-                       if ($item != 0)
+                       if ($item AND !function_exists("check_item_notification"))
                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                }
        }
index 3469cafc574e1aa7d11c06f62aec3d394777ba8c..e5b058cc8166025d07839dedc99610dae039cab7 100644 (file)
@@ -60,6 +60,8 @@
  *     Requirements: PHP5, curl [Slinky library]
  */
 
+require_once('include/enotify.php');
+
 define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
 function twitter_install() {
@@ -74,6 +76,7 @@ function twitter_install() {
        register_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
        register_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
        register_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+       register_hook('check_item_notification','addon/twitter/twitter.php', 'twitter_check_item_notification');
        logger("installed twitter");
 }
 
@@ -89,6 +92,7 @@ function twitter_uninstall() {
        unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
        unregister_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
        unregister_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+       unregister_hook('check_item_notification','addon/twitter/twitter.php', 'twitter_check_item_notification');
 
        // old setting - remove only
        unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
@@ -97,6 +101,18 @@ function twitter_uninstall() {
 
 }
 
+function twitter_check_item_notification($a, &$notification_data) {
+       $own_id = get_pconfig($notification_data["uid"], 'twitter', 'own_id');
+
+       $own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
+                       intval($notification_data["uid"]),
+                       dbesc("twitter::".$own_id)
+               );
+
+       if ($own_user)
+               $notification_data["profiles"][] = $own_user[0]["url"];
+}
+
 function twitter_follow($a, &$contact) {
 
        logger("twitter_follow: Check if contact is twitter contact. ".$contact["url"], LOGGER_DEBUG);
@@ -1580,7 +1596,7 @@ function twitter_fetchparentposts($a, $uid, $post, $connection, $self, $own_id)
 
                if (count($r))
                        break;
-               
+
                $posts[] = $post;
        }
 
@@ -1600,7 +1616,7 @@ function twitter_fetchparentposts($a, $uid, $post, $connection, $self, $own_id)
 
                        logger('twitter_fetchparentpost: User '.$self["nick"].' posted parent timeline item '.$item);
 
-                       if ($item != 0)
+                       if ($item AND !function_exists("check_item_notification"))
                                twitter_checknotification($a, $uid, $own_id, $item, $postarray);
                }
        }
@@ -1710,7 +1726,7 @@ function twitter_fetchhometimeline($a, $uid) {
 
                        logger('twitter_fetchhometimeline: User '.$self["nick"].' posted home timeline item '.$item);
 
-                       if ($item != 0)
+                       if ($item AND !function_exists("check_item_notification"))
                                twitter_checknotification($a, $uid, $own_id, $item, $postarray);
 
                }
@@ -1755,6 +1771,9 @@ function twitter_fetchhometimeline($a, $uid) {
                        $item = item_store($postarray);
                        $postarray["id"] = $item;
 
+                       if ($item AND function_exists("check_item_notification"))
+                               check_item_notification($item, $uid, NOTIFY_TAGSELF);
+
                        if (!isset($postarray["parent"]) OR ($postarray["parent"] == 0))
                                $postarray["parent"] = $item;
 
@@ -1772,7 +1791,7 @@ function twitter_fetchhometimeline($a, $uid) {
                        } else
                                $parent_id = $postarray['parent'];
 
-                       if ($item != 0) {
+                       if (($item != 0) AND !function_exists("check_item_notification")) {
                                require_once('include/enotify.php');
                                notification(array(
                                        'type'         => NOTIFY_TAGSELF,
index 21ac59cd2f800b95e50b898558caf4cab883aafc..753ea0a505735337692185e69bb3dd0b57fd332f 100644 (file)
@@ -125,6 +125,9 @@ function xmpp_converse(&$a,&$s) {
        if (!get_pconfig(local_user(),"xmpp","enabled"))
                return;
 
+       if (in_array($a->query_string, array("admin/federation/")))
+               return;
+
        $a->page['htmlhead'] .= '<link type="text/css" rel="stylesheet" media="screen" href="addon/xmpp/converse/css/converse.css" />'."\n";
        $a->page['htmlhead'] .= '<script src="addon/xmpp/converse/builds/converse.min.js"></script>'."\n";