]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbsync/fbsync.php
Design improvements for importing posts from twitter, facebook and G+
[friendica-addons.git] / fbsync / fbsync.php
index 13a504dcf3e5162861ef8246df1d423edf2e8625..32f62a4a487903baceab9d45b9cf0ded7c84f269 100644 (file)
@@ -119,8 +119,13 @@ function fbsync_settings(&$a,&$s) {
 
        /* Add some HTML to the existing form */
 
-       $s .= '<div class="settings-block">';
+       $s .= '<span id="settings_fbsync_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fbsync_expanded\'); openClose(\'settings_fbsync_inflated\');">';
        $s .= '<h3>' . t('Facebook Import Settings') . '</h3>';
+       $s .= '</span>';
+       $s .= '<div id="settings_fbsync_expanded" class="settings-block" style="display: none;">';
+       $s .= '<span class="fakelink" onclick="openClose(\'settings_fbsync_expanded\'); openClose(\'settings_fbsync_inflated\');">';
+       $s .= '<h3>' . t('Facebook Import Settings') . '</h3>';
+       $s .= '</span>';
 
        $s .= '<div id="fbsync-enable-wrapper">';
        $s .= '<label id="fbsync-enable-label" for="fbsync-checkbox">' . t('Import Facebook newsfeed') . '</label>';
@@ -134,7 +139,7 @@ function fbsync_settings(&$a,&$s) {
 
        /* provide a submit button */
 
-       $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="fbsync-submit" name="fbsync-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
+       $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="fbsync-submit" name="fbsync-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
 
 }
 
@@ -179,6 +184,8 @@ function fbsync_cron($a,$b) {
 
 function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) {
 
+       require_once("include/oembed.php");
+
        // check if it was already imported
        $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
                intval($uid),
@@ -262,10 +269,15 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
        $postarray["body"] = $msgdata["body"];
        $postarray["tag"] = $msgdata["tags"];
 
-       if(isset($post->attachment->name) and isset($post->attachment->href))
-               $postarray["body"] .= "\n\n[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]";
-       elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
-               $postarray["body"] .= "\n\n[b]" . $post->attachment->name."[/b]";
+       $content = "";
+       $type = "";
+
+       if (isset($post->attachment->name) and isset($post->attachment->href)) {
+               $oembed_data = oembed_fetch_url($post->attachment->href);
+               $type = $oembed_data->type;
+               $content = "[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]";
+       } elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
+               $content = "[b]" . $post->attachment->name."[/b]";
 
        $quote = "";
        if(isset($post->attachment->description) and ($post->attachment->fb_object_type != "photo"))
@@ -274,12 +286,13 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
        if(isset($post->attachment->caption) and ($post->attachment->fb_object_type == "photo"))
                $quote = $post->attachment->caption;
 
-       if ($quote.$post->attachment->href.$postarray["body"] == "")
+       if ($quote.$post->attachment->href.$content.$postarray["body"] == "")
                return;
 
-       if (isset($post->attachment->media) AND !strstr($post->attachment->href, "://www.youtube.com/")
-               AND !strstr($post->attachment->href, "://youtu.be/")
-               AND !strstr($post->attachment->href, ".vimeo.com/")) {
+       if (isset($post->attachment->media) // AND !strstr($post->attachment->href, "://www.youtube.com/")
+               //AND !strstr($post->attachment->href, "://youtu.be/")
+               //AND !strstr($post->attachment->href, ".vimeo.com/"))
+               AND (($type == "") OR ($type == "link"))) {
                foreach ($post->attachment->media AS $media) {
                        //$media->photo->owner = number_format($media->photo->owner, 0, '', '');
                        //if ($media->photo->owner != '') {
@@ -288,21 +301,36 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
                        //      $postarray['author-avatar'] = $contacts[$media->photo->owner]->pic_square;
                        //}
 
+                       if (isset($media->type))
+                               $type = $media->type;
+
                        if(isset($media->src) && isset($media->href) AND ($media->src != "") AND ($media->href != ""))
-                               $postarray["body"] .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]';
+                               $content .= "\n".'[url='.$media->href.'][img]'.fpost_cleanpicture($media->src).'[/img][/url]';
                        else {
                                if (isset($media->src) AND ($media->src != ""))
-                                       $postarray["body"] .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]';
+                                       $content .= "\n".'[img]'.fpost_cleanpicture($media->src).'[/img]';
 
                                // if just a link, it may be a wall photo - check
                                if(isset($post->link))
-                                       $postarray["body"] .= fbpost_get_photo($media->href);
+                                       $content .= fbpost_get_photo($media->href);
                        }
                }
        }
 
+       if ($content)
+               $postarray["body"] .= "\n\n";
+
+       if ($type)
+               $postarray["body"] .= "[class=type-".$type."]";
+
+       if ($content)
+               $postarray["body"] .= $content;
+
        if ($quote)
-               $postarray["body"] .= "\n[quote]".$quote."[/quote]";
+               $postarray["body"] .= "\n[quote]".trim($quote)."[/quote]";
+
+       if ($type)
+               $postarray["body"] .= "[/class]";
 
        $postarray["body"] = trim($postarray["body"]);