]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbpost/fbpost.php
Reduce the opacity of the network settings icon when disabled.
[friendica-addons.git] / fbpost / fbpost.php
index db905a1573d8d6a4f8a81fb457eeb54400b3a638..93a31e2b4d6ac640fa9e81dfc1465fc520472872 100644 (file)
@@ -96,7 +96,7 @@ function fbpost_init(&$a) {
 
                if(strpos($x,'access_token=') !== false) {
                        $token = str_replace('access_token=', '', $x);
-                       if(strpos($token,'&') !== false)
+                       if(strpos($token,'&') !== false)
                                $token = substr($token,0,strpos($token,'&'));
                        set_pconfig($uid,'facebook','access_token',$token);
                        set_pconfig($uid,'facebook','post','1');
@@ -152,6 +152,12 @@ function fbpost_post(&$a) {
                set_pconfig($uid,'facebook','post_to_page', $values[0]);
                set_pconfig($uid,'facebook','page_access_token', $values[1]);
 
+               $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`");
+               if (count($result) > 0) {
+                       set_pconfig(local_user(),'fbsync','sync',intval($_POST['fbsync']));
+                       set_pconfig(local_user(),'fbsync','create_user',intval($_POST['create_user']));
+               }
+
                info( t('Settings updated.') . EOL);
        }
 
@@ -183,6 +189,9 @@ function fbpost_content(&$a) {
                info( t('Facebook Post disabled') . EOL);
        }
 
+       require_once("mod/settings.php");
+       settings_init($a);
+
        $o = '';
 
        $fb_installed = false;
@@ -207,7 +216,15 @@ function fbpost_content(&$a) {
        $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="'
                . $a->get_baseurl() . '/addon/fbpost/fbpost.css' . '" media="all" />' . "\r\n";
 
-       $o .= '<h3>' . t('Facebook') . '</h3>';
+       $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`");
+       $fbsync = (count($result) > 0);
+
+       if($fbsync)
+               $title = t('Facebook Import/Export/Mirror');
+       else
+               $title = t('Facebook Export/Mirror');
+
+       $o .= '<img class="connector" src="images/facebook.png" /><h3 class="connector">'.$title.'</h3>';
 
        if(! $fb_installed) {
                $o .= '<div id="fbpost-enable-wrapper">';
@@ -279,8 +296,20 @@ function fbpost_content(&$a) {
 
                $o .= "</select>";
 
-               $o .= '<p><input type="submit" name="submit" value="' . t('Save Settings') . '" /></form></div>';
+               if ($fbsync) {
+
+                       $o .= '<div class="clear"></div>';
+
+                       $sync_enabled = get_pconfig(local_user(),'fbsync','sync');
+                       $checked = (($sync_enabled) ? ' checked="checked" ' : '');
+                       $o .= '<input type="checkbox" name="fbsync" value="1"' . $checked . '/>' . ' ' . t('Import Facebook newsfeed.') . EOL;
 
+                       $create_user = get_pconfig(local_user(),'fbsync','create_user');
+                       $checked = (($create_user) ? ' checked="checked" ' : '');
+                       $o .= '<input type="checkbox" name="create_user" value="1"' . $checked . '/>' . ' ' . t('Automatically create contacts.') . EOL;
+
+               }
+               $o .= '<p><input type="submit" name="submit" value="' . t('Save Settings') . '" /></form></div>';
        }
 
        return $o;
@@ -292,10 +321,18 @@ function fbpost_content(&$a) {
  */
 function fbpost_plugin_settings(&$a,&$b) {
 
+       $enabled = get_pconfig(local_user(),'facebook','post');
+       $css = (($enabled) ? '' : '-disabled');
+
+       $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`");
+       if(count($result) > 0)
+               $title = t('Facebook Import/Export/Mirror');
+       else
+               $title = t('Facebook Export/Mirror');
+
        $b .= '<div class="settings-block">';
-       $b .= '<a href="fbpost"><h3>' . t('Facebook') . '</a></h3>';
+       $b .= '<a href="fbpost"><img class="connector'.$css.'" src="images/facebook.png" /><h3 class="connector">'.$title.'</h3></a>';
        $b .= '</div>';
-
 }
 
 
@@ -571,7 +608,8 @@ function fbpost_post_hook(&$a,&$b) {
 
                        $allow_str = dbesc(implode(', ',$recipients));
                        if($allow_str) {
-                               $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'"); 
+                               logger("fbpost_post_hook: private post to: ".$allow_str, LOGGER_DEBUG);
+                               $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'");
                                if(count($r))
                                        foreach($r as $rr)
                                                $allow_arr[] = $rr['notify'];
@@ -579,7 +617,7 @@ function fbpost_post_hook(&$a,&$b) {
 
                        $deny_str = dbesc(implode(', ',$deny));
                        if($deny_str) {
-                               $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $deny_str ) AND `network` = 'face'"); 
+                               $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $deny_str ) AND `network` = 'face'");
                                if(count($r))
                                        foreach($r as $rr)
                                                $deny_arr[] = $rr['notify'];
@@ -633,22 +671,32 @@ function fbpost_post_hook(&$a,&$b) {
 
                                logger('fbpost_post_hook: original msg=' . $msg, LOGGER_DATA);
 
-                               // To-Do: if it is a reply, then only do a simple bbcode2plain conversion
-                               $msgarr = fbpost_createmsg($b);
-                               $msg = $msgarr["msg"];
-                               $link = $msgarr["link"];
-                               $image = $msgarr["image"];
-                               $linkname = $msgarr["linkname"];
+                               if ($toplevel) {
+                                       $msgarr = fbpost_createmsg($b);
+                                       $msg = $msgarr["msg"];
+                                       $link = $msgarr["link"];
+                                       $image = $msgarr["image"];
+                                       $linkname = $msgarr["linkname"];
 
-                               // Fallback - if message is empty
-                               if(!strlen($msg))
-                                       $msg = $linkname;
+                                       // Fallback - if message is empty
+                                       if(!strlen($msg))
+                                               $msg = $linkname;
 
-                               if(!strlen($msg))
-                                       $msg = $link;
+                                       if(!strlen($msg))
+                                               $msg = $link;
 
-                               if(!strlen($msg))
-                                       $msg = $image;
+                                       if(!strlen($msg))
+                                               $msg = $image;
+                               } else {
+                                       require_once("include/bbcode.php");
+                                       require_once("include/html2plain.php");
+                                       $msg = bb_CleanPictureLinks($msg);
+                                       $msg = bbcode($msg, false, false, 2, true);
+                                       $msg = trim(html2plain($msg, 0));
+                                       $link = "";
+                                       $image = "";
+                                       $linkname = "";
+                               }
 
                                // If there is nothing to post then exit
                                if(!strlen($msg))
@@ -962,7 +1010,7 @@ function fbpost_get_app_access_token() {
                logger('fb_get_app_access_token: returned access token: ' . $x, LOGGER_DATA);
 
                $token = str_replace('access_token=', '', $x);
-               if(strpos($token,'&') !== false)
+               if(strpos($token,'&') !== false)
                        $token = substr($token,0,strpos($token,'&'));
 
                if ($token == "") {
@@ -1105,7 +1153,7 @@ function fbpost_fetchwall($a, $uid) {
                }
 
                if ($content)
-                       $_REQUEST["body"] .= "\n\n";
+                       $_REQUEST["body"] .= "\n";
 
                if ($type)
                        $_REQUEST["body"] .= "[class=type-".$type."]";