]> git.mxchange.org Git - friendica-addons.git/blobdiff - gpluspost/gpluspost.php
gpluspost: Showing a "recycle" sign when displaying repeated items.
[friendica-addons.git] / gpluspost / gpluspost.php
index 327f9f3244d238c64213109f993940c062023feb..76cf237bac0179f956835bac19132433f48117c9 100644 (file)
@@ -43,13 +43,14 @@ function gpluspost_settings(&$a,&$s) {
                return;
 
        $enabled = get_pconfig(local_user(),'gpluspost','post');
-
        $checked = (($enabled) ? ' checked="checked" ' : '');
 
        $def_enabled = get_pconfig(local_user(),'gpluspost','post_by_default');
-
        $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
 
+       $noloop_enabled = get_pconfig(local_user(),'gpluspost','no_loop_prevention');
+       $noloop_checked = (($noloop_enabled) ? ' checked="checked" ' : '');
+
        $s .= '<div class="settings-block">';
        $s .= '<h3>' . t('Google+ Post Settings') . '</h3>';
        $s .= '<div id="gpluspost-enable-wrapper">';
@@ -62,11 +63,15 @@ function gpluspost_settings(&$a,&$s) {
        $s .= '<input id="gpluspost-bydefault" type="checkbox" name="gpluspost_bydefault" value="1" ' . $def_checked . '/>';
        $s .= '</div><div class="clear"></div>';
 
+       $s .= '<div id="gpluspost-noloopprevention-wrapper">';
+       $s .= '<label id="gpluspost-noloopprevention-label" for="gpluspost-noloopprevention">' . t('Do not prevent posting loops') . '</label>';
+       $s .= '<input id="gpluspost-noloopprevention" type="checkbox" name="gpluspost_noloopprevention" value="1" ' . $noloop_checked . '/>';
+       $s .= '</div><div class="clear"></div>';
+
        /* provide a submit button */
 
        $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="gpluspost-submit" name="gpluspost-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
        $s .= 'Register an account at <a href="https://hootsuite.com">Hootsuite</a>, add your G+ page and add the feed-url there.<br />';
-       //$s .= 'Feed-url: '.$a->get_baseurl().'/gpluspost/'.$a->user["uid"].'</div>';
        $s .= 'Feed-url: '.$a->get_baseurl().'/gpluspost/'.urlencode($a->user["nickname"]).'</div>';
 }
 
@@ -75,6 +80,7 @@ function gpluspost_settings_post(&$a,&$b) {
        if(x($_POST,'gpluspost-submit')) {
                set_pconfig(local_user(),'gpluspost','post',intval($_POST['gpluspost']));
                set_pconfig(local_user(),'gpluspost','post_by_default',intval($_POST['gpluspost_bydefault']));
+               set_pconfig(local_user(),'gpluspost','no_loop_prevention',intval($_POST['gpluspost_noloopprevention']));
        }
 }
 
@@ -93,7 +99,7 @@ function gpluspost_post_local(&$a,&$b) {
 
        $enable = (($post && x($_REQUEST,'gpluspost_enable')) ? intval($_REQUEST['gpluspost_enable']) : 0);
 
-       if(intval(get_pconfig(local_user(),'gpluspost','post_by_default')))
+       if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'gpluspost','post_by_default')))
                $enable = 1;
 
        if(!$enable)
@@ -107,7 +113,7 @@ function gpluspost_post_local(&$a,&$b) {
 
 function gpluspost_send(&$a,&$b) {
 
-       logger('gpluspost_send: invoked for post '.$b['id']);
+       logger('gpluspost_send: invoked for post '.$b['id']." ".$b['app']);
 
        if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
                return;
@@ -119,7 +125,7 @@ function gpluspost_send(&$a,&$b) {
                return;
 
        // if post comes from Google+ don't send it back
-       if($b['app'] == "Google+")
+       if (!get_pconfig($b["uid"],'gpluspost','no_loop_prevention') and ($b['app'] == "Google+"))
                return;
 
        $itemlist = get_pconfig($b["uid"],'gpluspost','itemlist');
@@ -149,19 +155,25 @@ function gpluspost_init() {
                $uid = (int)$a->argv[1];
                if ($uid == 0) {
                        $contacts = q("SELECT `name`, `id` FROM contact WHERE `nick` = '%s' LIMIT 1", dbesc($a->argv[1]));
-                       if ($contacts)
+                       if ($contacts) {
                                $uid = $contacts[0]["id"];
-               } else
+                               $nick = $a->argv[1];
+                       }
+               } else {
                        $contacts = q("SELECT `name` FROM contact WHERE ID=%d LIMIT 1", intval($uid));
+                       $nick = $uid;
+               }
        }
 
        header("content-type: application/atom+xml");
        echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
        echo '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n";
        echo "\t".'<title type="html"><![CDATA['.$a->config['sitename'].']]></title>'."\n";
-       if ($uid != 0)
+       if ($uid != 0) {
                echo "\t".'<subtitle type="html"><![CDATA['.$contacts[0]["name"]."]]></subtitle>\n";
-       echo "\t".'<link rel="self" href="'.$a->get_baseurl().'/gpluspost"/>'."\n";
+               echo "\t".'<link rel="self" href="'.$a->get_baseurl().'/gpluspost/'.$nick.'"/>'."\n";
+       } else
+               echo "\t".'<link rel="self" href="'.$a->get_baseurl().'/gpluspost"/>'."\n";
        echo "\t<id>".$a->get_baseurl()."/</id>\n";
        echo "\t".'<link rel="alternate" type="text/html" href="'.$a->get_baseurl().'"/>'."\n";
        echo "\t<updated>".date("c")."</updated>\n"; // To-Do
@@ -169,8 +181,7 @@ function gpluspost_init() {
        echo "\t".'<generator uri="'.$a->get_baseurl().'">'.$a->config['sitename'].'</generator>'."\n";
 
        if ($uid != 0) {
-               $itemlist = get_pconfig(local_user(),'gpluspost','itemlist');
-               //$itemlist = "262568,262567,269154,271508,270121,273721,314735,312616,311570,308771,308247,306100,295372,291096,290390,290389,283242,283060,280465,273725";
+               $itemlist = get_pconfig($uid,'gpluspost','itemlist');
                $items = explode(",", $itemlist);
 
                foreach ($items AS $item)
@@ -205,7 +216,7 @@ function gpluspost_ShareAttributes($match) {
 
         //$text = "<br />".$headline."</strong><blockquote>".$match[2]."</blockquote>";
        //$text = "\n\t".$match[2].":\t";
-       $text = $author.": ".$match[2];
+       $text = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8').$author.": ".$match[2];
 
         return($text);
 }