]> git.mxchange.org Git - friendica-addons.git/blobdiff - statusnet/statusnet.php
Issue 3873
[friendica-addons.git] / statusnet / statusnet.php
index f92dde76c8e60012311aab25b9320ca3aec392bb..ba119abea6f7d61a42e6dc175eb5ba63be33bdc8 100644 (file)
 define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
 require_once('library/twitteroauth.php');
+require_once('include/enotify.php');
+require_once("include/socgraph.php");
+
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
 
 class StatusNetOAuth extends TwitterOAuth {
     function get_maxlength() {
@@ -69,11 +74,11 @@ class StatusNetOAuth extends TwitterOAuth {
     $this->http_info = array();
     $ci = curl_init();
     /* Curl settings */
-    $prx = get_config('system','proxy');
+    $prx = Config::get('system','proxy');
     if(strlen($prx)) {
        curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1);
        curl_setopt($ci, CURLOPT_PROXY, $prx);
-       $prxusr = get_config('system','proxyuser');
+       $prxusr = Config::get('system','proxyuser');
        if(strlen($prxusr))
            curl_setopt($ci, CURLOPT_PROXYUSERPWD, $prxusr);
     }
@@ -119,6 +124,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 +137,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,15 +146,19 @@ function statusnet_uninstall() {
 
 }
 
+function statusnet_check_item_notification($a, &$notification_data) {
+       $notification_data["profiles"][] = PConfig::get($notification_data["uid"], 'statusnet', 'own_url');
+}
+
 function statusnet_jot_nets(&$a,&$b) {
        if(! local_user())
                return;
 
-       $statusnet_post = get_pconfig(local_user(),'statusnet','post');
+       $statusnet_post = PConfig::get(local_user(),'statusnet','post');
        if(intval($statusnet_post) == 1) {
-               $statusnet_defpost = get_pconfig(local_user(),'statusnet','post_by_default');
+               $statusnet_defpost = PConfig::get(local_user(),'statusnet','post_by_default');
                $selected = ((intval($statusnet_defpost) == 1) ? ' checked="checked" ' : '');
-               $b .= '<div class="profile-jot-net"><input type="checkbox" name="statusnet_enable"' . $selected . ' value="1" /> ' 
+               $b .= '<div class="profile-jot-net"><input type="checkbox" name="statusnet_enable"' . $selected . ' value="1" /> '
                        . t('Post to GNU Social') . '</div>';
        }
 }
@@ -182,16 +193,16 @@ function statusnet_settings_post ($a,$post) {
                 * use them. All the data are available in the global config.
                 * Check the API Url never the less and blame the admin if it's not working ^^
                 */
-               $globalsn = get_config('statusnet', 'sites');
+               $globalsn = Config::get('statusnet', 'sites');
                foreach ( $globalsn as $asn) {
                        if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl'] ) {
                                $apibase = $asn['apiurl'];
                                $c = fetch_url( $apibase . 'statusnet/version.xml' );
                                if (strlen($c) > 0) {
-                                       set_pconfig(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey'] );
-                                       set_pconfig(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret'] );
-                                       set_pconfig(local_user(), 'statusnet', 'baseapi', $asn['apiurl'] );
-                                       //set_pconfig(local_user(), 'statusnet', 'application_name', $asn['applicationname'] );
+                                       PConfig::set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey'] );
+                                       PConfig::set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret'] );
+                                       PConfig::set(local_user(), 'statusnet', 'baseapi', $asn['apiurl'] );
+                                       //PConfig::set(local_user(), 'statusnet', 'application_name', $asn['applicationname'] );
                                } else {
                                        notice( t('Please contact your site administrator.<br />The provided API URL is not valid.').EOL.$asn['apiurl'].EOL );
                                }
@@ -207,19 +218,19 @@ function statusnet_settings_post ($a,$post) {
                $c = fetch_url( $apibase . 'statusnet/version.xml' );
                if (strlen($c) > 0) {
                        //  ok the API path is correct, let's save the settings
-                       set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
-                       set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
-                       set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase );
-                       //set_pconfig(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] );
+                       PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
+                       PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
+                       PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase );
+                       //PConfig::set(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] );
                } else {
                        //  the API path is not correct, maybe missing trailing / ?
                        $apibase = $apibase . '/';
                        $c = fetch_url( $apibase . 'statusnet/version.xml' );
                        if (strlen($c) > 0) {
                                //  ok the API path is now correct, let's save the settings
-                               set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
-                               set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
-                               set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase );
+                               PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
+                               PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']);
+                               PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase );
                        } else {
                                //  still not the correct API base, let's do noting
                                notice( t('We could not contact the GNU Social API with the Path you entered.').EOL );
@@ -229,29 +240,29 @@ function statusnet_settings_post ($a,$post) {
        } else {
        if (isset($_POST['statusnet-pin'])) {
                //  if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen
-               $api     = get_pconfig(local_user(), 'statusnet', 'baseapi');
-               $ckey    = get_pconfig(local_user(), 'statusnet', 'consumerkey'  );
-               $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' );
+               $api     = PConfig::get(local_user(), 'statusnet', 'baseapi');
+               $ckey    = PConfig::get(local_user(), 'statusnet', 'consumerkey'  );
+               $csecret = PConfig::get(local_user(), 'statusnet', 'consumersecret' );
                //  the token and secret for which the PIN was generated were hidden in the settings
                //  form as token and token2, we need a new connection to GNU Social using these token
                //  and secret to request a Access Token with the PIN
                $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']);
                $token   = $connection->getAccessToken( $_POST['statusnet-pin'] );
                //  ok, now that we have the Access Token, save them in the user config
-               set_pconfig(local_user(),'statusnet', 'oauthtoken',  $token['oauth_token']);
-               set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']);
-               set_pconfig(local_user(),'statusnet', 'post', 1);
-               set_pconfig(local_user(),'statusnet', 'post_taglinks', 1);
+               PConfig::set(local_user(),'statusnet', 'oauthtoken',  $token['oauth_token']);
+               PConfig::set(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']);
+               PConfig::set(local_user(),'statusnet', 'post', 1);
+               PConfig::set(local_user(),'statusnet', 'post_taglinks', 1);
                //  reload the Addon Settings page, if we don't do it see Bug #42
                goaway($a->get_baseurl().'/settings/connectors');
        } else {
                //  if no PIN is supplied in the POST variables, the user has changed the setting
                //  to post a dent for every new __public__ posting to the wall
-               set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable']));
-               set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default']));
-               set_pconfig(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror']));
-               set_pconfig(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import']));
-               set_pconfig(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user']));
+               PConfig::set(local_user(),'statusnet','post',intval($_POST['statusnet-enable']));
+               PConfig::set(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default']));
+               PConfig::set(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror']));
+               PConfig::set(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import']));
+               PConfig::set(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user']));
 
                if (!intval($_POST['statusnet-mirror']))
                        del_pconfig(local_user(),'statusnet','lastid');
@@ -269,23 +280,23 @@ function statusnet_settings(&$a,&$s) {
         *    allow the user to cancel the connection process at this step
         * 3) Checkbox for "Send public notices (respect size limitation)
         */
-       $api     = get_pconfig(local_user(), 'statusnet', 'baseapi');
-       $ckey    = get_pconfig(local_user(), 'statusnet', 'consumerkey');
-       $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret');
-       $otoken  = get_pconfig(local_user(), 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret');
-       $enabled = get_pconfig(local_user(), 'statusnet', 'post');
+       $api     = PConfig::get(local_user(), 'statusnet', 'baseapi');
+       $ckey    = PConfig::get(local_user(), 'statusnet', 'consumerkey');
+       $csecret = PConfig::get(local_user(), 'statusnet', 'consumersecret');
+       $otoken  = PConfig::get(local_user(), 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get(local_user(), 'statusnet', 'oauthsecret');
+       $enabled = PConfig::get(local_user(), 'statusnet', 'post');
        $checked = (($enabled) ? ' checked="checked" ' : '');
-       $defenabled = get_pconfig(local_user(),'statusnet','post_by_default');
+       $defenabled = PConfig::get(local_user(),'statusnet','post_by_default');
        $defchecked = (($defenabled) ? ' checked="checked" ' : '');
-       $mirrorenabled = get_pconfig(local_user(),'statusnet','mirror_posts');
+       $mirrorenabled = PConfig::get(local_user(),'statusnet','mirror_posts');
        $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
-       $import = get_pconfig(local_user(),'statusnet','import');
+       $import = PConfig::get(local_user(),'statusnet','import');
        $importselected = array("", "", "");
        $importselected[$import] = ' selected="selected"';
-       //$importenabled = get_pconfig(local_user(),'statusnet','import');
+       //$importenabled = PConfig::get(local_user(),'statusnet','import');
        //$importchecked = (($importenabled) ? ' checked="checked" ' : '');
-       $create_userenabled = get_pconfig(local_user(),'statusnet','create_user');
+       $create_userenabled = PConfig::get(local_user(),'statusnet','create_user');
        $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
 
        $css = (($enabled) ? '' : '-disabled');
@@ -302,7 +313,7 @@ function statusnet_settings(&$a,&$s) {
                /***
                 * no consumer keys
                 */
-               $globalsn = get_config('statusnet', 'sites');
+               $globalsn = Config::get('statusnet', 'sites');
                /***
                 * lets check if we have one or more globally configured GNU Social
                 * server OAuth credentials in the configuration. If so offer them
@@ -413,41 +424,47 @@ function statusnet_settings(&$a,&$s) {
                        $s .= '<label id="statusnet-disconnect-label" for="statusnet-disconnect">'. t('Clear OAuth configuration') .'</label>';
                        $s .= '<input id="statusnet-disconnect" type="checkbox" name="statusnet-disconnect" value="1" />';
                        $s .= '</div><div class="clear"></div>';
-                       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>'; 
+                       $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
                }
        }
        $s .= '</div><div class="clear"></div>';
 }
 
 
-function statusnet_post_local(&$a,&$b) {
-       if($b['edit'])
+function statusnet_post_local(&$a, &$b) {
+       if ($b['edit']) {
                return;
+       }
 
-       if((local_user()) && (local_user() == $b['uid']) && (! $b['private'])) {
+       if (!local_user() || (local_user() != $b['uid'])) {
+               return;
+       }
 
-               $statusnet_post = get_pconfig(local_user(),'statusnet','post');
-               $statusnet_enable = (($statusnet_post && x($_REQUEST,'statusnet_enable')) ? intval($_REQUEST['statusnet_enable']) : 0);
+       $statusnet_post = PConfig::get(local_user(),'statusnet','post');
+       $statusnet_enable = (($statusnet_post && x($_REQUEST,'statusnet_enable')) ? intval($_REQUEST['statusnet_enable']) : 0);
 
-               // if API is used, default to the chosen settings
-               if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'statusnet','post_by_default')))
-                       $statusnet_enable = 1;
+       // if API is used, default to the chosen settings
+       if ($b['api_source'] && intval(PConfig::get(local_user(),'statusnet','post_by_default'))) {
+               $statusnet_enable = 1;
+       }
 
-               if(! $statusnet_enable)
-                       return;
+       if (!$statusnet_enable) {
+               return;
+       }
 
-               if(strlen($b['postopts']))
-                       $b['postopts'] .= ',';
-               $b['postopts'] .= 'statusnet';
+       if (strlen($b['postopts'])) {
+               $b['postopts'] .= ',';
        }
+
+       $b['postopts'] .= 'statusnet';
 }
 
 function statusnet_action($a, $uid, $pid, $action) {
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
 
        $connection = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret);
 
@@ -473,12 +490,12 @@ function statusnet_post_hook(&$a,&$b) {
         * Post to GNU Social
         */
 
-       if (!get_pconfig($b["uid"],'statusnet','import')) {
+       if (!PConfig::get($b["uid"],'statusnet','import')) {
                if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
                        return;
        }
 
-       $api = get_pconfig($b["uid"], 'statusnet', 'baseapi');
+       $api = PConfig::get($b["uid"], 'statusnet', 'baseapi');
        $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
 
        if($b['parent'] != $b['id']) {
@@ -486,8 +503,8 @@ function statusnet_post_hook(&$a,&$b) {
 
                // Looking if its a reply to a GNU Social post
                $hostlength = strlen($hostname) + 2;
-               if ((substr($b["parent-uri"], 0, $hostlength) != $hostname."::") AND (substr($b["extid"], 0, $hostlength) != $hostname."::")
-                       AND (substr($b["thr-parent"], 0, $hostlength) != $hostname."::")) {
+               if ((substr($b["parent-uri"], 0, $hostlength) != $hostname."::") && (substr($b["extid"], 0, $hostlength) != $hostname."::")
+                       && (substr($b["thr-parent"], 0, $hostlength) != $hostname."::")) {
                        logger("statusnet_post_hook: no GNU Social post ".$b["parent"]);
                        return;
                }
@@ -515,18 +532,18 @@ function statusnet_post_hook(&$a,&$b) {
                $nicknameplain = "@".$nick;
 
                logger("statusnet_post_hook: comparing ".$nickname." and ".$nicknameplain." with ".$b["body"], LOGGER_DEBUG);
-               if ((strpos($b["body"], $nickname) === false) AND (strpos($b["body"], $nicknameplain) === false))
+               if ((strpos($b["body"], $nickname) === false) && (strpos($b["body"], $nicknameplain) === false))
                        $b["body"] = $nickname." ".$b["body"];
 
                logger("statusnet_post_hook: parent found ".print_r($orig_post, true), LOGGER_DEBUG);
        } else {
                $iscomment = false;
 
-               if($b['private'] OR !strstr($b['postopts'],'statusnet'))
+               if($b['private'] || !strstr($b['postopts'],'statusnet'))
                        return;
        }
 
-       if (($b['verb'] == ACTIVITY_POST) AND $b['deleted'])
+       if (($b['verb'] == ACTIVITY_POST) && $b['deleted'])
                statusnet_action($a, $b["uid"], substr($orig_post["uri"], $hostlength), "delete");
 
        if($b['verb'] == ACTIVITY_LIKE) {
@@ -552,11 +569,11 @@ function statusnet_post_hook(&$a,&$b) {
 
        load_pconfig($b['uid'], 'statusnet');
 
-       $api     = get_pconfig($b['uid'], 'statusnet', 'baseapi');
-       $ckey    = get_pconfig($b['uid'], 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($b['uid'], 'statusnet', 'consumersecret');
-       $otoken  = get_pconfig($b['uid'], 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($b['uid'], 'statusnet', 'oauthsecret');
+       $api     = PConfig::get($b['uid'], 'statusnet', 'baseapi');
+       $ckey    = PConfig::get($b['uid'], 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($b['uid'], 'statusnet', 'consumersecret');
+       $otoken  = PConfig::get($b['uid'], 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($b['uid'], 'statusnet', 'oauthsecret');
 
        if($ckey && $csecret && $otoken && $osecret) {
 
@@ -568,7 +585,7 @@ function statusnet_post_hook(&$a,&$b) {
                $dent = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret);
                $max_char = $dent->get_maxlength(); // max. length for a dent
 
-               set_pconfig($b['uid'], 'statusnet', 'max_char', $max_char);
+               PConfig::set($b['uid'], 'statusnet', 'max_char', $max_char);
 
                $tempfile = "";
                require_once("include/plaintext.php");
@@ -576,18 +593,18 @@ function statusnet_post_hook(&$a,&$b) {
                $msgarr = plaintext($a, $b, $max_char, true, 7);
                $msg = $msgarr["text"];
 
-               if (($msg == "") AND isset($msgarr["title"]))
+               if (($msg == "") && isset($msgarr["title"]))
                        $msg = shortenmsg($msgarr["title"], $max_char - 50);
 
                $image = "";
 
-               if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo")) {
-                       if ((strlen($msgarr["url"]) > 20) AND
+               if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) {
+                       if ((strlen($msgarr["url"]) > 20) &&
                                ((strlen($msg." \n".$msgarr["url"]) > $max_char)))
                                $msg .= " \n".short_link($msgarr["url"]);
                        else
                                $msg .= " \n".$msgarr["url"];
-               } elseif (isset($msgarr["image"]) AND ($msgarr["type"] != "video"))
+               } elseif (isset($msgarr["image"]) && ($msgarr["type"] != "video"))
                        $image = $msgarr["image"];
 
                if ($image != "") {
@@ -618,7 +635,7 @@ function statusnet_post_hook(&$a,&$b) {
                                "\nmessage: ".$msg, LOGGER_DEBUG."\nOriginal post: ".print_r($b, true)."\nPost Data: ".print_r($postdata, true));
 
                        if ($result->source)
-                               set_pconfig($b["uid"], "statusnet", "application_name", strip_tags($result->source));
+                               PConfig::set($b["uid"], "statusnet", "application_name", strip_tags($result->source));
 
                        if ($result->error) {
                                logger('Send to GNU Social failed: "'.$result->error.'"');
@@ -664,13 +681,13 @@ function statusnet_plugin_admin_post(&$a){
                }
        }
 
-       $sites = set_config('statusnet','sites', $sites);
+       $sites = Config::set('statusnet','sites', $sites);
 
 }
 
 function statusnet_plugin_admin(&$a, &$o){
 
-       $sites = get_config('statusnet','sites');
+       $sites = Config::get('statusnet','sites');
        $sitesform=array();
        if (is_array($sites)){
                foreach($sites as $id=>$s){
@@ -706,7 +723,7 @@ function statusnet_prepare_body(&$a,&$b) {
                 return;
 
         if ($b["preview"]) {
-               $max_char = get_pconfig(local_user(),'statusnet','max_char');
+               $max_char = PConfig::get(local_user(),'statusnet','max_char');
                if (intval($max_char) == 0)
                        $max_char = 140;
 
@@ -730,7 +747,7 @@ function statusnet_prepare_body(&$a,&$b) {
                        $nickname = "@[url=".$orig_post["author-link"]."]".$nick."[/url]";
                        $nicknameplain = "@".$nick;
 
-                       if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false))
+                       if ((strpos($item["body"], $nickname) === false) && (strpos($item["body"], $nicknameplain) === false))
                                $item["body"] = $nickname." ".$item["body"];
                 }
 
@@ -738,7 +755,7 @@ function statusnet_prepare_body(&$a,&$b) {
                 $msgarr = plaintext($a, $item, $max_char, true, 7);
                 $msg = $msgarr["text"];
 
-                if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo"))
+                if (isset($msgarr["url"]) && ($msgarr["type"] != "photo"))
                         $msg .= " ".$msgarr["url"];
 
                 if (isset($msgarr["image"]))
@@ -749,9 +766,9 @@ function statusnet_prepare_body(&$a,&$b) {
 }
 
 function statusnet_cron($a,$b) {
-       $last = get_config('statusnet','last_poll');
+       $last = Config::get('statusnet','last_poll');
 
-       $poll_interval = intval(get_config('statusnet','poll_interval'));
+       $poll_interval = intval(Config::get('statusnet','poll_interval'));
        if(! $poll_interval)
                $poll_interval = STATUSNET_DEFAULT_POLL_INTERVAL;
 
@@ -772,7 +789,7 @@ function statusnet_cron($a,$b) {
                }
        }
 
-       $abandon_days = intval(get_config('system','account_abandon_days'));
+       $abandon_days = intval(Config::get('system','account_abandon_days'));
        if ($abandon_days < 1)
                $abandon_days = 0;
 
@@ -796,16 +813,16 @@ function statusnet_cron($a,$b) {
 
        logger('statusnet: cron_end');
 
-       set_config('statusnet','last_poll', time());
+       Config::set('statusnet','last_poll', time());
 }
 
 function statusnet_fetchtimeline($a, $uid) {
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
-       $lastid  = get_pconfig($uid, 'statusnet', 'lastid');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
+       $lastid  = PConfig::get($uid, 'statusnet', 'lastid');
 
        require_once('mod/item.php');
        require_once('include/items.php');
@@ -813,9 +830,9 @@ function statusnet_fetchtimeline($a, $uid) {
        //  get the application name for the SN app
        //  1st try personal config, then system config and fallback to the
        //  hostname of the node if neither one is set.
-       $application_name  = get_pconfig( $uid, 'statusnet', 'application_name');
+       $application_name  = PConfig::get( $uid, 'statusnet', 'application_name');
        if ($application_name == "")
-               $application_name  = get_config('statusnet', 'application_name');
+               $application_name  = Config::get('statusnet', 'application_name');
        if ($application_name == "")
                $application_name = $a->get_hostname();
 
@@ -864,6 +881,10 @@ function statusnet_fetchtimeline($a, $uid) {
                        $_REQUEST["source"] = $post->source;
                        $_REQUEST["extid"] = NETWORK_STATUSNET;
 
+                       if (isset($post->id)) {
+                               $_REQUEST['message_id'] = item_new_uri($a->get_hostname(), $uid, NETWORK_STATUSNET.":".$post->id);
+                       }
+
                        //$_REQUEST["date"] = $post->created_at;
 
                        $_REQUEST["title"] = "";
@@ -890,7 +911,7 @@ function statusnet_fetchtimeline($a, $uid) {
                }
            }
        }
-       set_pconfig($uid, 'statusnet', 'lastid', $lastid);
+       PConfig::set($uid, 'statusnet', 'lastid', $lastid);
 }
 
 function statusnet_address($contact) {
@@ -908,44 +929,19 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
        if ($contact->statusnet_profile_url == "")
                return(-1);
 
-       if (function_exists("update_gcontact"))
-               update_gcontact(array("url" => $contact->statusnet_profile_url,
-                               "network" => NETWORK_STATUSNET, "photo" => $contact->profile_image_url,
-                               "name" => $contact->name, "nick" => $contact->screen_name,
-                               "location" => $contact->location, "about" => $contact->description,
-                               "addr" => statusnet_address($contact), "generation" => 3));
-       else {
-               // Old Code
-                $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
-                               dbesc(normalise_link($contact->statusnet_profile_url)));
-
-               if (count($r) == 0)
-                       q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
-                               dbesc(normalise_link($contact->statusnet_profile_url)),
-                               dbesc($contact->name),
-                               dbesc($contact->screen_name),
-                               dbesc($contact->profile_image_url));
-               else
-                       q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
-                               dbesc($contact->name),
-                               dbesc($contact->screen_name),
-                               dbesc($contact->profile_image_url),
-                               dbesc(normalise_link($contact->statusnet_profile_url)));
-
-               if (DB_UPDATE_VERSION >= "1177")
-                       q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
-                               dbesc($contact->location),
-                               dbesc($contact->description),
-                               dbesc(normalise_link($contact->statusnet_profile_url)));
-       }
+       update_gcontact(array("url" => $contact->statusnet_profile_url,
+                       "network" => NETWORK_STATUSNET, "photo" => $contact->profile_image_url,
+                       "name" => $contact->name, "nick" => $contact->screen_name,
+                       "location" => $contact->location, "about" => $contact->description,
+                       "addr" => statusnet_address($contact), "generation" => 3));
 
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1",
                intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET));
 
-       if(!count($r) AND !$create_user)
+       if(!count($r) && !$create_user)
                return(0);
 
-       if (count($r) AND ($r[0]["readonly"] OR $r[0]["blocked"])) {
+       if (count($r) && ($r[0]["readonly"] || $r[0]["blocked"])) {
                logger("statusnet_fetch_contact: Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG);
                return(-1);
        }
@@ -954,8 +950,8 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
                // create contact record
                q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
                                        `name`, `nick`, `photo`, `network`, `rel`, `priority`,
-                                       `writable`, `blocked`, `readonly`, `pending` )
-                                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
+                                       `location`, `about`, `writable`, `blocked`, `readonly`, `pending` )
+                                       VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0 ) ",
                        intval($uid),
                        dbesc(datetime_convert()),
                        dbesc($contact->statusnet_profile_url),
@@ -970,6 +966,8 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
                        dbesc(NETWORK_STATUSNET),
                        intval(CONTACT_IS_FRIEND),
                        intval(1),
+                       dbesc($contact->location),
+                       dbesc($contact->description),
                        intval(1)
                );
 
@@ -1007,16 +1005,6 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
                        dbesc(datetime_convert()),
                        intval($contact_id)
                );
-
-               if (DB_UPDATE_VERSION >= "1177")
-                       q("UPDATE `contact` SET `location` = '%s',
-                                               `about` = '%s'
-                                       WHERE `id` = %d",
-                               dbesc($contact->location),
-                               dbesc($contact->description),
-                               intval($contact_id)
-                       );
-
        } else {
                // update profile photos once every two weeks as we have no notification of when they change.
 
@@ -1043,7 +1031,9 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
                                                `nurl` = '%s',
                                                `addr` = '%s',
                                                `name` = '%s',
-                                               `nick` = '%s'
+                                               `nick` = '%s',
+                                               `location` = '%s',
+                                               `about` = '%s'
                                        WHERE `id` = %d",
                                dbesc($photos[0]),
                                dbesc($photos[1]),
@@ -1056,17 +1046,10 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
                                dbesc(statusnet_address($contact)),
                                dbesc($contact->name),
                                dbesc($contact->screen_name),
+                               dbesc($contact->location),
+                               dbesc($contact->description),
                                intval($r[0]['id'])
                        );
-
-                       if (DB_UPDATE_VERSION >= "1177")
-                               q("UPDATE `contact` SET `location` = '%s',
-                                                       `about` = '%s'
-                                               WHERE `id` = %d",
-                                       dbesc($contact->location),
-                                       dbesc($contact->description),
-                                       intval($r[0]['id'])
-                               );
                }
        }
 
@@ -1074,11 +1057,11 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
 }
 
 function statusnet_fetchuser($a, $uid, $screen_name = "", $user_id = "") {
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
 
        require_once("addon/statusnet/codebird.php");
 
@@ -1119,7 +1102,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
 
        logger("statusnet_createpost: start", LOGGER_DEBUG);
 
-       $api = get_pconfig($uid, 'statusnet', 'baseapi');
+       $api = PConfig::get($uid, 'statusnet', 'baseapi');
        $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
 
        $postarray = array();
@@ -1177,7 +1160,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
                }
 
                // Is it me?
-               $own_url = get_pconfig($uid, 'statusnet', 'own_url');
+               $own_url = PConfig::get($uid, 'statusnet', 'own_url');
 
                if ($content->user->id == $own_url) {
                        $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
@@ -1205,7 +1188,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
                $postarray['owner-link'] = $post->user->statusnet_profile_url;
                $postarray['owner-avatar'] = $post->user->profile_image_url;
        }
-       if(($contactid == 0) AND !$only_existing_contact)
+       if(($contactid == 0) && !$only_existing_contact)
                $contactid = $self['id'];
        elseif ($contactid <= 0)
                return(array());
@@ -1219,7 +1202,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi
        $postarray['author-avatar'] = $content->user->profile_image_url;
 
        // To-Do: Maybe unreliable? Can the api be entered without trailing "/"?
-       $hostname = str_replace("/api/", "/notice/", get_pconfig($uid, 'statusnet', 'baseapi'));
+       $hostname = str_replace("/api/", "/notice/", PConfig::get($uid, 'statusnet', 'baseapi'));
 
        $postarray['plink'] = $hostname.$content->id;
        $postarray['app'] = strip_tags($content->source);
@@ -1305,7 +1288,7 @@ function statusnet_checknotification($a, $uid, $own_url, $top_item, $postarray)
                foreach($myconv as $conv) {
                        // now if we find a match, it means we're in this conversation
 
-                       if(!link_compare($conv['author-link'],$user[0]["url"]) AND !link_compare($conv['author-link'],$own_user[0]["url"]))
+                       if(!link_compare($conv['author-link'],$user[0]["url"]) && !link_compare($conv['author-link'],$own_user[0]["url"]))
                                continue;
 
                        require_once('include/enotify.php');
@@ -1338,12 +1321,12 @@ function statusnet_checknotification($a, $uid, $own_url, $top_item, $postarray)
 function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
        $conversations = array();
 
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
-       $create_user = get_pconfig($uid, 'statusnet', 'create_user');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
+       $create_user = PConfig::get($uid, 'statusnet', 'create_user');
 
        // "create_user" is deactivated, since currently you cannot add users manually by now
        $create_user = true;
@@ -1390,7 +1373,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
 
        if ($mode == 1) {
                // Fetching timeline
-               $lastid  = get_pconfig($uid, 'statusnet', 'lasthometimelineid');
+               $lastid  = PConfig::get($uid, 'statusnet', 'lasthometimelineid');
                //$lastid = 1;
 
                $first_time = ($lastid == "");
@@ -1401,11 +1384,11 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                $items = $connection->get('statuses/home_timeline', $parameters);
 
                if (!is_array($items)) {
-                       if (is_object($items) AND isset($items->error))
+                       if (is_object($items) && isset($items->error))
                                $errormsg = $items->error;
                        elseif (is_object($items))
                                $errormsg = print_r($items, true);
-                       elseif (is_string($items) OR is_float($items) OR is_int($items))
+                       elseif (is_string($items) || is_float($items) || is_int($items))
                                $errormsg = $items;
                        else
                                $errormsg = "Unknown error";
@@ -1443,17 +1426,17 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted home timeline item '.$item);
 
-                                       if ($item != 0)
+                                       if ($item && !function_exists("check_item_notification"))
                                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                                }
 
                        }
                }
-               set_pconfig($uid, 'statusnet', 'lasthometimelineid', $lastid);
+               PConfig::set($uid, 'statusnet', 'lasthometimelineid', $lastid);
        }
 
        // Fetching mentions
-       $lastid  = get_pconfig($uid, 'statusnet', 'lastmentionid');
+       $lastid  = PConfig::get($uid, 'statusnet', 'lastmentionid');
        $first_time = ($lastid == "");
 
        if ($lastid <> "")
@@ -1493,6 +1476,9 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                        $postarray["id"] = $item;
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted mention timeline item '.$item);
+
+                                       if ($item && function_exists("check_item_notification"))
+                                               check_item_notification($item, $uid, NOTIFY_TAGSELF);
                                }
                        }
 
@@ -1505,7 +1491,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                $parent_id = $r[0]['parent'];
                        }
 
-                       if ($item != 0) {
+                       if (($item != 0) && !function_exists("check_item_notification")) {
                                require_once('include/enotify.php');
                                notification(array(
                                        'type'         => NOTIFY_TAGSELF,
@@ -1527,15 +1513,16 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                }
        }
 
-       set_pconfig($uid, 'statusnet', 'lastmentionid', $lastid);
+       PConfig::set($uid, 'statusnet', 'lastmentionid', $lastid);
 }
 
 function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $conversation) {
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
+       $own_url = PConfig::get($uid, 'statusnet', 'own_url');
 
        require_once('library/twitteroauth.php');
 
@@ -1559,7 +1546,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 && !function_exists("check_item_notification"))
                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                }
        }
@@ -1604,7 +1591,7 @@ function statusnet_convertmsg($a, $body, $no_tags = false) {
                                $footerlink = "[url=".$expanded_url."]".$expanded_url."[/url]";
 
                                $body = str_replace($search, $footerlink, $body);
-                       } elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia)
+                       } elseif (($oembed_data->type == "photo") && isset($oembed_data->url) && !$dontincludemedia)
                                $body = str_replace($search, "[url=".$expanded_url."][img]".$oembed_data->url."[/img][/url]", $body);
                        elseif ($oembed_data->type != "link")
                                $body = str_replace($search,  "[url=".$expanded_url."]".$expanded_url."[/url]", $body);
@@ -1632,10 +1619,10 @@ function statusnet_convertmsg($a, $body, $no_tags = false) {
                if ($footerurl != "")
                        $footer = add_page_info($footerurl);
 
-               if (($footerlink != "") AND (trim($footer) != "")) {
+               if (($footerlink != "") && (trim($footer) != "")) {
                        $removedlink = trim(str_replace($footerlink, "", $body));
 
-                       if (($removedlink == "") OR strstr($body, $removedlink))
+                       if (($removedlink == "") || strstr($body, $removedlink))
                                $body = $removedlink;
 
                        $body .= $footer;
@@ -1673,12 +1660,12 @@ function statusnet_convertmsg($a, $body, $no_tags = false) {
 }
 
 function statusnet_fetch_own_contact($a, $uid) {
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $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');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
+       $own_url = PConfig::get($uid, 'statusnet', 'own_url');
 
        $contact_id = 0;
 
@@ -1690,7 +1677,7 @@ function statusnet_fetch_own_contact($a, $uid) {
                // Fetching user data
                $user = $connection->get('account/verify_credentials');
 
-               set_pconfig($uid, 'statusnet', 'own_url', normalise_link($user->statusnet_profile_url));
+               PConfig::set($uid, 'statusnet', 'own_url', normalise_link($user->statusnet_profile_url));
 
                $contact_id = statusnet_fetch_contact($uid, $user, true);
 
@@ -1732,11 +1719,11 @@ function statusnet_is_retweet($a, $uid, $body) {
        if ($matches[1] != "")
                $link = $matches[1];
 
-       $ckey    = get_pconfig($uid, 'statusnet', 'consumerkey');
-       $csecret = get_pconfig($uid, 'statusnet', 'consumersecret');
-       $api     = get_pconfig($uid, 'statusnet', 'baseapi');
-       $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
-       $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $ckey    = PConfig::get($uid, 'statusnet', 'consumerkey');
+       $csecret = PConfig::get($uid, 'statusnet', 'consumersecret');
+       $api     = PConfig::get($uid, 'statusnet', 'baseapi');
+       $otoken  = PConfig::get($uid, 'statusnet', 'oauthtoken');
+       $osecret = PConfig::get($uid, 'statusnet', 'oauthsecret');
        $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api);
 
        $id = preg_replace("=https?://".$hostname."/notice/(.*)=ism", "$1", $link);