X-Git-Url: https://git.mxchange.org/?p=friendica-addons.git;a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=9158052a528bc0e43149fe9aaac6415565b78d00;hp=a9e309cff2f30f24813d3c332cc9e7f26b8b482b;hb=27b60e003f92dd9f3aebbeddb34ebb905488ca82;hpb=31823eb729d4a7c14d40d632ff592cd1805e9ca8 diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index a9e309cf..9158052a 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -46,10 +46,13 @@ require_once 'library/twitteroauth.php'; require_once 'include/enotify.php'; use Friendica\App; +use Friendica\Content\OEmbed; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Model\GContact; +use Friendica\Model\Group; use Friendica\Model\Photo; +use Friendica\Model\User; class StatusNetOAuth extends TwitterOAuth { @@ -94,7 +97,7 @@ class StatusNetOAuth extends TwitterOAuth */ function http($url, $method, $postfields = NULL) { - $this->http_info = array(); + $this->http_info = []; $ci = curl_init(); /* Curl settings */ $prx = Config::get('system', 'proxy'); @@ -110,9 +113,9 @@ class StatusNetOAuth extends TwitterOAuth curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout); curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout); curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:')); + curl_setopt($ci, CURLOPT_HTTPHEADER, ['Expect:']); curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer); - curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader')); + curl_setopt($ci, CURLOPT_HEADERFUNCTION, [$this, 'getHeader']); curl_setopt($ci, CURLOPT_HEADER, FALSE); switch ($method) { @@ -238,7 +241,7 @@ function statusnet_settings_post(App $a, $post) } } } - goaway($a->get_baseurl() . '/settings/connectors'); + goaway('settings/connectors'); } else { if (isset($_POST['statusnet-consumersecret'])) { // check if we can reach the API of the GNU Social server @@ -266,7 +269,7 @@ function statusnet_settings_post(App $a, $post) notice(t('We could not contact the GNU Social API with the Path you entered.') . EOL); } } - goaway($a->get_baseurl() . '/settings/connectors'); + goaway('settings/connectors'); } else { if (isset($_POST['statusnet-pin'])) { // if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen @@ -284,7 +287,7 @@ function statusnet_settings_post(App $a, $post) 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'); + goaway('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 @@ -328,7 +331,7 @@ function statusnet_settings(App $a, &$s) $mirrorenabled = PConfig::get(local_user(), 'statusnet', 'mirror_posts'); $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : ''); $import = PConfig::get(local_user(), 'statusnet', 'import'); - $importselected = array("", "", ""); + $importselected = ["", "", ""]; $importselected[$import] = ' selected="selected"'; //$importenabled = PConfig::get(local_user(),'statusnet','import'); //$importchecked = (($importenabled) ? ' checked="checked" ' : ''); @@ -565,19 +568,21 @@ function statusnet_post_hook(App $a, &$b) $nicknameplain = "@" . $nick; logger("statusnet_post_hook: comparing " . $nickname . " and " . $nicknameplain . " with " . $b["body"], LOGGER_DEBUG); - if ((strpos($b["body"], $nickname) === false) && (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'] || !strstr($b['postopts'], 'statusnet')) + if ($b['private'] || !strstr($b['postopts'], 'statusnet')) { return; + } // Dont't post if the post doesn't belong to us. // This is a check for forum postings - $self = dba::select('contact', array('id'), array('uid' => $b['uid'], 'self' => true), array('limit' => 1)); + $self = dba::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]); if ($b['contact-id'] != $self['id']) { return; } @@ -634,7 +639,7 @@ function statusnet_post_hook(App $a, &$b) $tempfile = ""; require_once "include/plaintext.php"; require_once "include/network.php"; - $msgarr = plaintext($a, $b, $max_char, true, 7); + $msgarr = plaintext($b, $max_char, true, 7); $msg = $msgarr["text"]; if (($msg == "") && isset($msgarr["title"])) @@ -657,9 +662,9 @@ function statusnet_post_hook(App $a, &$b) $img_str = fetch_url($image); $tempfile = tempnam(get_temppath(), "cache"); file_put_contents($tempfile, $img_str); - $postdata = array("status" => $msg, "media[]" => $tempfile); + $postdata = ["status" => $msg, "media[]" => $tempfile]; } else { - $postdata = array("status" => $msg); + $postdata = ["status" => $msg]; } // and now dent it :-) @@ -703,7 +708,7 @@ function statusnet_post_hook(App $a, &$b) function statusnet_plugin_admin_post(App $a) { - $sites = array(); + $sites = []; foreach ($_POST['sitename'] as $id => $sitename) { $sitename = trim($sitename); @@ -720,13 +725,13 @@ function statusnet_plugin_admin_post(App $a) $key != "" && !x($_POST['delete'][$id])) { - $sites[] = Array( + $sites[] = [ 'sitename' => $sitename, 'apiurl' => $apiurl, 'consumersecret' => $secret, 'consumerkey' => $key, //'applicationname' => $applicationname - ); + ]; } } @@ -736,34 +741,34 @@ function statusnet_plugin_admin_post(App $a) function statusnet_plugin_admin(App $a, &$o) { $sites = Config::get('statusnet', 'sites'); - $sitesform = array(); + $sitesform = []; if (is_array($sites)) { foreach ($sites as $id => $s) { - $sitesform[] = Array( - 'sitename' => Array("sitename[$id]", "Site name", $s['sitename'], ""), - 'apiurl' => Array("apiurl[$id]", "Api url", $s['apiurl'], t("Base API Path \x28remember the trailing /\x29")), - 'secret' => Array("secret[$id]", "Secret", $s['consumersecret'], ""), - 'key' => Array("key[$id]", "Key", $s['consumerkey'], ""), + $sitesform[] = [ + 'sitename' => ["sitename[$id]", "Site name", $s['sitename'], ""], + 'apiurl' => ["apiurl[$id]", "Api url", $s['apiurl'], t("Base API Path \x28remember the trailing /\x29")], + 'secret' => ["secret[$id]", "Secret", $s['consumersecret'], ""], + 'key' => ["key[$id]", "Key", $s['consumerkey'], ""], //'applicationname' => Array("applicationname[$id]", "Application name", $s['applicationname'], ""), - 'delete' => Array("delete[$id]", "Delete", False, "Check to delete this preset"), - ); + 'delete' => ["delete[$id]", "Delete", False, "Check to delete this preset"], + ]; } } /* empty form to add new site */ $id++; - $sitesform[] = Array( - 'sitename' => Array("sitename[$id]", t("Site name"), "", ""), - 'apiurl' => Array("apiurl[$id]", "Api url", "", t("Base API Path \x28remember the trailing /\x29")), - 'secret' => Array("secret[$id]", t("Consumer Secret"), "", ""), - 'key' => Array("key[$id]", t("Consumer Key"), "", ""), + $sitesform[] = [ + 'sitename' => ["sitename[$id]", t("Site name"), "", ""], + 'apiurl' => ["apiurl[$id]", "Api url", "", t("Base API Path \x28remember the trailing /\x29")], + 'secret' => ["secret[$id]", t("Consumer Secret"), "", ""], + 'key' => ["key[$id]", t("Consumer Key"), "", ""], //'applicationname' => Array("applicationname[$id]", t("Application name"), "", ""), - ); + ]; $t = get_markup_template("admin.tpl", "addon/statusnet/"); - $o = replace_macros($t, array( + $o = replace_macros($t, [ '$submit' => t('Save Settings'), '$sites' => $sitesform, - )); + ]); } function statusnet_prepare_body(App $a, &$b) @@ -803,7 +808,7 @@ function statusnet_prepare_body(App $a, &$b) } } - $msgarr = plaintext($a, $item, $max_char, true, 7); + $msgarr = plaintext($item, $max_char, true, 7); $msg = $msgarr["text"]; if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) { @@ -897,7 +902,7 @@ function statusnet_fetchtimeline(App $a, $uid) $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); - $parameters = array("exclude_replies" => true, "trim_user" => true, "contributor_details" => false, "include_rts" => false); + $parameters = ["exclude_replies" => true, "trim_user" => true, "contributor_details" => false, "include_rts" => false]; $first_time = ($lastid == ""); @@ -1001,11 +1006,11 @@ function statusnet_fetch_contact($uid, $contact, $create_user) return -1; } - GContact::update(array("url" => $contact->statusnet_profile_url, + GContact::update(["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)); + "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)); @@ -1054,14 +1059,7 @@ function statusnet_fetch_contact($uid, $contact, $create_user) $contact_id = $r[0]['id']; - $g = q("SELECT def_gid FROM user WHERE uid = %d LIMIT 1", - intval($uid) - ); - - if ($g && intval($g[0]['def_gid'])) { - require_once 'include/group.php'; - group_add_member($uid, '', $contact_id, $g[0]['def_gid']); - } + Group::addMember(User::getDefaultGroup($uid), $contact_id); $photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_id); @@ -1145,7 +1143,7 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "") return; } - $parameters = array(); + $parameters = []; if ($screen_name != "") { $parameters["screen_name"] = $screen_name; @@ -1176,7 +1174,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $api = PConfig::get($uid, 'statusnet', 'baseapi'); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); - $postarray = array(); + $postarray = []; $postarray['network'] = NETWORK_STATUSNET; $postarray['gravity'] = 0; $postarray['uid'] = $uid; @@ -1197,7 +1195,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex ); if (count($r)) { - return array(); + return []; } $contactid = 0; @@ -1246,7 +1244,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex $postarray['owner-link'] = $r[0]["url"]; $postarray['owner-avatar'] = $r[0]["photo"]; } else { - return array(); + return []; } } // Don't create accounts of people who just comment something @@ -1265,7 +1263,7 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex if (($contactid == 0) && !$only_existing_contact) { $contactid = $self['id']; } elseif ($contactid <= 0) { - return array(); + return []; } $postarray['contact-id'] = $contactid; @@ -1363,7 +1361,7 @@ function statusnet_checknotification(App $a, $uid, $own_url, $top_item, $postarr $conv_parent = $conv['parent']; - notification(array( + notification([ 'type' => NOTIFY_COMMENT, 'notify_flags' => $user[0]['notify-flags'], 'language' => $user[0]['language'], @@ -1378,7 +1376,7 @@ function statusnet_checknotification(App $a, $uid, $own_url, $top_item, $postarr 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $conv_parent, - )); + ]); // only send one notification break; @@ -1388,7 +1386,7 @@ function statusnet_checknotification(App $a, $uid, $own_url, $top_item, $postarr function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) { - $conversations = array(); + $conversations = []; $ckey = PConfig::get($uid, 'statusnet', 'consumerkey'); $csecret = PConfig::get($uid, 'statusnet', 'consumersecret'); @@ -1437,7 +1435,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) return; } - $parameters = array("exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true); + $parameters = ["exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true]; //$parameters["count"] = 200; if ($mode == 1) { @@ -1571,7 +1569,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) if (($item != 0) && !function_exists("check_item_notification")) { require_once 'include/enotify.php'; - notification(array( + notification([ 'type' => NOTIFY_TAGSELF, 'notify_flags' => $u[0]['notify-flags'], 'language' => $u[0]['language'], @@ -1586,7 +1584,7 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1) 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $parent_id, - )); + ]); } } } @@ -1634,7 +1632,6 @@ function statusnet_complete_conversation(App $a, $uid, $self, $create_user, $nic function statusnet_convertmsg(App $a, $body, $no_tags = false) { - require_once "include/oembed.php"; require_once "include/items.php"; require_once "include/network.php"; @@ -1658,7 +1655,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) logger("statusnet_convertmsg: fetching data for " . $expanded_url, LOGGER_DEBUG); - $oembed_data = oembed_fetch_url($expanded_url, true); + $oembed_data = OEmbed::fetchURL($expanded_url, true); logger("statusnet_convertmsg: fetching data: done", LOGGER_DEBUG); @@ -1714,7 +1711,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } if ($no_tags) { - return array("body" => $body, "tags" => ""); + return ["body" => $body, "tags" => ""]; } $str_tags = ''; @@ -1742,7 +1739,7 @@ function statusnet_convertmsg(App $a, $body, $no_tags = false) } } - return array("body" => $body, "tags" => $str_tags); + return ["body" => $body, "tags" => $str_tags]; } function statusnet_fetch_own_contact(App $a, $uid)