]> git.mxchange.org Git - friendica-addons.git/blobdiff - fromgplus/fromgplus.php
Addon class
[friendica-addons.git] / fromgplus / fromgplus.php
index 0627b026af45fa2a34a2bafdded985f7975d3d22..b8910d5df98aff349ea80971b7db672a38c66dff 100644 (file)
@@ -9,27 +9,29 @@
 
 define('FROMGPLUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
 
+use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Object\Image;
 
-require_once('mod/share.php');
-require_once('mod/parse_url.php');
-require_once('include/text.php');
+require_once 'mod/share.php';
+require_once 'mod/parse_url.php';
+require_once 'include/text.php';
 
 function fromgplus_install() {
-       register_hook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
-       register_hook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
-       register_hook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
+       Addon::registerHook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+       Addon::registerHook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+       Addon::registerHook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
 }
 
 function fromgplus_uninstall() {
-       unregister_hook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
-       unregister_hook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
-       unregister_hook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
+       Addon::unregisterHook('connector_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+       Addon::unregisterHook('connector_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+       Addon::unregisterHook('cron', 'addon/fromgplus/fromgplus.php', 'fromgplus_cron');
 
        // Old hooks
-       unregister_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
-       unregister_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+       Addon::unregisterHook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+       Addon::unregisterHook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
 }
 
 function fromgplus_addon_settings(&$a,&$s) {
@@ -95,10 +97,10 @@ function fromgplus_addon_settings_post(&$a,&$b) {
 function fromgplus_plugin_admin(&$a, &$o){
         $t = get_markup_template("admin.tpl", "addon/fromgplus/");
 
-        $o = replace_macros($t, array(
+        $o = replace_macros($t, [
                 '$submit' => t('Save Settings'),
-                '$key' => array('key', t('Key'), trim(Config::get('fromgplus', 'key')), t('')),
-        ));
+                '$key' => ['key', t('Key'), trim(Config::get('fromgplus', 'key')), t('')],
+        ]);
 }
 
 function fromgplus_plugin_admin_post(&$a){
@@ -197,13 +199,13 @@ function fromgplus_html2bbcode($html) {
 
        $bbcode = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
 
-       $bbcode = str_ireplace(array("\n"), array(""), $bbcode);
-       $bbcode = str_ireplace(array("<b>", "</b>"), array("[b]", "[/b]"), $bbcode);
-       $bbcode = str_ireplace(array("<i>", "</i>"), array("[i]", "[/i]"), $bbcode);
-       $bbcode = str_ireplace(array("<s>", "</s>"), array("[s]", "[/s]"), $bbcode);
-       $bbcode = str_ireplace(array("<br />"), array("\n"), $bbcode);
-       $bbcode = str_ireplace(array("<br/>"), array("\n"), $bbcode);
-       $bbcode = str_ireplace(array("<br>"), array("\n"), $bbcode);
+       $bbcode = str_ireplace(["\n"], [""], $bbcode);
+       $bbcode = str_ireplace(["<b>", "</b>"], ["[b]", "[/b]"], $bbcode);
+       $bbcode = str_ireplace(["<i>", "</i>"], ["[i]", "[/i]"], $bbcode);
+       $bbcode = str_ireplace(["<s>", "</s>"], ["[s]", "[/s]"], $bbcode);
+       $bbcode = str_ireplace(["<br />"], ["\n"], $bbcode);
+       $bbcode = str_ireplace(["<br/>"], ["\n"], $bbcode);
+       $bbcode = str_ireplace(["<br>"], ["\n"], $bbcode);
 
        $bbcode = trim(strip_tags($bbcode));
        return($bbcode);
@@ -218,7 +220,7 @@ function fromgplus_parse_query($var)
        $var  = parse_url($var, PHP_URL_QUERY);
        $var  = html_entity_decode($var);
        $var  = explode('&', $var);
-       $arr  = array();
+       $arr  = [];
 
        foreach($var as $val) {
                $x          = explode('=', $val);
@@ -239,7 +241,7 @@ function fromgplus_cleanupgoogleproxy($fullImage, $image) {
        //$image = str_replace(array($preview, $preview2), array("/", "/"), $image->url);
        $image = $image->url;
 
-               $cleaned = array();
+               $cleaned = [];
 
        $queryvar = fromgplus_parse_query($fullImage);
        if ($queryvar['url'] != "")
@@ -263,14 +265,14 @@ function fromgplus_cleanupgoogleproxy($fullImage, $image) {
        }
 
        if ($cleaned["full"] != "")
-               $infoFull = get_photo_info($cleaned["full"]);
+               $infoFull = Image::getInfoFromURL($cleaned["full"]);
        else
-               $infoFull = array("0" => 0, "1" => 0);
+               $infoFull = ["0" => 0, "1" => 0];
 
        if ($cleaned["preview"] != "")
-               $infoPreview = get_photo_info($cleaned["preview"]);
+               $infoPreview = Image::getInfoFromURL($cleaned["preview"]);
        else
-               $infoFull = array("0" => 0, "1" => 0);
+               $infoFull = ["0" => 0, "1" => 0];
 
        if (($infoPreview[0] >= $infoFull[0]) && ($infoPreview[1] >= $infoFull[1])) {
                $temp = $cleaned["full"];
@@ -303,18 +305,17 @@ function fromgplus_cleantext($text) {
        $text = strip_tags($text);
        $text = html_entity_decode($text, ENT_QUOTES);
        $text = trim($text);
-       $text = str_replace(array("\n", "\r", " ", $trash), array("", "", "", ""), $text);
+       $text = str_replace(["\n", "\r", " ", $trash], ["", "", "", ""], $text);
        return($text);
 }
 
 function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
-       require_once("include/Photo.php");
        require_once("include/items.php");
        require_once("include/network.php");
 
        $post = "";
        $quote = "";
-       $pagedata = array();
+       $pagedata = [];
        $pagedata["type"] = "";
 
        foreach ($item->object->attachments as $attachment) {
@@ -348,13 +349,14 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
 
                        case "photo":
                                // Don't store shared pictures in your wall photos (to prevent a possible violating of licenses)
-                               if ($shared)
+                               if ($shared) {
                                        $images = fromgplus_cleanupgoogleproxy($attachment->fullImage, $attachment->image);
-                               else {
-                                       if ($attachment->fullImage->url != "")
-                                               $images = store_photo($a, $uid, "", $attachment->fullImage->url);
-                                       elseif ($attachment->image->url != "")
-                                               $images = store_photo($a, $uid, "", $attachment->image->url);
+                               } else {
+                                       if ($attachment->fullImage->url != "") {
+                                               $images = Image::storePhoto($a, $uid, "", $attachment->fullImage->url);
+                                       } elseif ($attachment->image->url != "") {
+                                               $images = Image::storePhoto($a, $uid, "", $attachment->image->url);
+                                       }
                                }
 
                                if ($images["preview"] != "") {
@@ -365,8 +367,9 @@ function fromgplus_handleattachments($a, $uid, $item, $displaytext, $shared) {
                                        $post .= "\n[img]".$images["full"]."[/img]\n";
                                        $pagedata["images"][0]["src"] = $images["full"];
 
-                                       if ($images["preview"] != "")
+                                       if ($images["preview"] != "") {
                                                $pagedata["images"][1]["src"] = $images["preview"];
+                                       }
                                }
 
                                if (($attachment->displayName != "") && (fromgplus_cleantext($attachment->displayName) != fromgplus_cleantext($displaytext))) {