Esempio n. 1
0
function fb_photos_tab($link)
{
    ?>
	<style type="text/css">
	<?php 
    include FB_PLUGIN_PATH . 'styles/admin-styles.css';
    ?>
	</style>
	<form id="image-form">
	<?php 
    if (isset($_GET['aid'])) {
        $album = fb_get_album($_GET['aid']);
        $photos = fb_get_photos($_GET['aid']);
        ?>
	<script language="javascript">
	var fbThumb; var fbFull; var fbLink; var fbCaption;
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}
	function insertPopup(obj, thumb, full, link, caption) {
		fbThumb = thumb;	fbFull		= full;
		fbLink	= link;	 fbCaption = caption;
		var popup = document.getElementById('fb-insert-popup');
		popup.style.display = 'block';
		popup.style.left		= findPos(obj)[0]+'px';
		popup.style.top		 = findPos(obj)[1]+'px';
	}
	function insertPhoto(size) {
		var src;
		if (size == 'thumb')
			src = fbThumb;
		else
			src = fbFull;
		var html =
			'<a href="'+fbLink+'" class="fb-photo">' +
			'<img src="'+src+'" alt="'+fbCaption+'" />' +
			'</a> ';
		wpgallery.getWin().send_to_editor(html);
	}
	</script>
	<h3><?php 
        echo $album['name'];
        ?>
 <a href="<?php 
        echo $link;
        ?>
" style="font-size: 11px">&laquo; Back to Albums</a></small></h2>

	<div id="fb-insert-popup">
		Insert...<br />
		&nbsp; <a href="#" onclick="insertPhoto('thumb'); return false;">Thumbnail</a><br />
		&nbsp; <a href="#" onclick="insertPhoto('full'); return false;">Full</a><br />
		<br /><a href="#" onclick="this.parentNode.style.display = 'none'; return false;">[close]</a>
	</div>

	<ul id="fb-photos-tab">
		<?php 
        foreach ($photos as $photo) {
            ?>
		<li>
			<a href="#" onclick="insertPopup(this.parentNode, '<?php 
            echo $photo['src'];
            ?>
','<?php 
            echo $photo['src_big'];
            ?>
','<?php 
            echo fb_get_photo_link($photo['pid']);
            ?>
', '<?php 
            echo addslashes($photo['caption']);
            ?>
'); return false;">
				<img src="<?php 
            echo $photo['src'];
            ?>
" />
			</a>
		</li>
		<?php 
        }
        ?>
	</ul>
	<?php 
    } else {
        $albums = fb_get_album();
        ?>
	<h3>Select an Album</h3>
	<ul id="fb-manage-list">
		<?php 
        foreach ($albums as $album) {
            $thumb = fb_get_photo($album['cover_pid'], 'small');
            ?>
		<li id="album_<?php 
            echo $album['aid'];
            ?>
" style="cursor: default">
			<div class="thumb" style="background-image:url(<?php 
            echo $thumb;
            ?>
);"></div>
			<div>
				<h3><a href="<?php 
            echo $link;
            ?>
&amp;aid=<?php 
            echo $album['aid'];
            ?>
"><?php 
            echo $album['name'];
            ?>
</a></h3>
				<div class="description">
					<small style="font-weight: normal"><?php 
            echo $album['size'];
            ?>
 Photos</small><br />
				</div>
			</div>
			<div style="clear: both"></div>
		</li>
		<?php 
        }
        ?>
	</ul>
	<?php 
    }
    ?>
	</form>
	<?php 
}
Esempio n. 2
0
/**
 * @param int $uid
 * @param object $j
 * @param bool $wall
 */
function fb_consume_stream($uid, $j, $wall = false)
{
    $a = get_app();
    $user = q("SELECT * FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1", intval($uid));
    if (!count($user)) {
        return;
    }
    // $my_local_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
    $no_linking = get_pconfig($uid, 'facebook', 'no_linking');
    if ($no_linking) {
        return;
    }
    $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid));
    $blocked_apps = get_pconfig($uid, 'facebook', 'blocked_apps');
    $blocked_apps_arr = explode(',', $blocked_apps);
    $sync_comments = get_config('facebook', 'sync_comments');
    /** @var string $self_id  */
    $self_id = get_pconfig($uid, 'facebook', 'self_id');
    if (!count($j->data) || !strlen($self_id)) {
        return;
    }
    $top_item = 0;
    foreach ($j->data as $entry) {
        logger('fb_consume: entry: ' . print_r($entry, true), LOGGER_DATA);
        $datarray = array();
        $r = q("SELECT * FROM `item` WHERE ( `uri` = '%s' OR `extid` = '%s') AND `uid` = %d LIMIT 1", dbesc('fb::' . $entry->id), dbesc('fb::' . $entry->id), intval($uid));
        if (count($r)) {
            $orig_post = $r[0];
            $top_item = $r[0]['id'];
        } else {
            $orig_post = null;
        }
        if (!$orig_post) {
            $datarray['gravity'] = 0;
            $datarray['uid'] = $uid;
            $datarray['wall'] = $wall ? 1 : 0;
            $datarray['uri'] = $datarray['parent-uri'] = 'fb::' . $entry->id;
            $from = $entry->from;
            if ($from->id == $self_id) {
                $datarray['contact-id'] = $self[0]['id'];
            } else {
                // Looking if user is known - if not he is added
                $access_token = get_pconfig($uid, 'facebook', 'access_token');
                fb_get_friends_sync_new($uid, $access_token, array($from));
                $r = q("SELECT * FROM `contact` WHERE `notify` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", dbesc($from->id), intval($uid));
                if (count($r)) {
                    $datarray['contact-id'] = $r[0]['id'];
                }
            }
            // don't store post if we don't have a contact
            if (!x($datarray, 'contact-id')) {
                logger('facebook: no contact ' . $from->name . ' ' . $from->id . '. post ignored');
                continue;
            }
            $datarray['verb'] = ACTIVITY_POST;
            if ($wall) {
                $datarray['owner-name'] = $self[0]['name'];
                $datarray['owner-link'] = $self[0]['url'];
                $datarray['owner-avatar'] = $self[0]['thumb'];
            }
            if (isset($entry->application) && isset($entry->application->name) && strlen($entry->application->name)) {
                $datarray['app'] = strip_tags($entry->application->name);
            } else {
                $datarray['app'] = 'facebook';
            }
            $found_blocked = false;
            if (count($blocked_apps_arr)) {
                foreach ($blocked_apps_arr as $bad_appl) {
                    if (strlen(trim($bad_appl)) && stristr($datarray['app'], trim($bad_appl))) {
                        $found_blocked = true;
                    }
                }
            }
            if ($found_blocked) {
                logger('facebook: blocking application: ' . $datarray['app']);
                continue;
            }
            $datarray['author-name'] = $from->name;
            $datarray['author-link'] = 'http://facebook.com/profile.php?id=' . $from->id;
            $datarray['author-avatar'] = 'https://graph.facebook.com/' . $from->id . '/picture';
            $datarray['plink'] = $datarray['author-link'] . '&v=wall&story_fbid=' . substr($entry->id, strpos($entry->id, '_') + 1);
            logger('facebook: post ' . $entry->id . ' from ' . $from->name);
            $datarray['body'] = isset($entry->message) ? escape_tags($entry->message) : '';
            if (isset($entry->name) and isset($entry->link)) {
                $datarray['body'] .= "\n\n[bookmark=" . $entry->link . "]" . $entry->name . "[/bookmark]";
            } elseif (isset($entry->name)) {
                $datarray['body'] .= "\n\n[b]" . $entry->name . "[/b]";
            }
            if (isset($entry->caption)) {
                if (!isset($entry->name) and isset($entry->link)) {
                    $datarray['body'] .= "\n\n[bookmark=" . $entry->link . "]" . $entry->caption . "[/bookmark]";
                } else {
                    $datarray['body'] .= "[i]" . $entry->caption . "[/i]\n";
                }
            }
            if (!isset($entry->caption) and !isset($entry->name)) {
                if (isset($entry->link)) {
                    $datarray['body'] .= "\n[url]" . $entry->link . "[/url]\n";
                } else {
                    $datarray['body'] .= "\n";
                }
            }
            $quote = "";
            if (isset($entry->description)) {
                $quote = $entry->description;
            }
            if (isset($entry->properties)) {
                foreach ($entry->properties as $property) {
                    $quote .= "\n" . $property->name . ": [url=" . $property->href . "]" . $property->text . "[/url]";
                }
            }
            if ($quote) {
                $datarray['body'] .= "\n[quote]" . $quote . "[/quote]";
            }
            // Only import the picture when the message is no video
            // oembed display a picture of the video as well
            if ($entry->type != "video") {
                if (isset($entry->picture) && isset($entry->link)) {
                    $datarray['body'] .= "\n" . '[url=' . $entry->link . '][img]' . $entry->picture . '[/img][/url]';
                } else {
                    if (isset($entry->picture)) {
                        $datarray['body'] .= "\n" . '[img]' . $entry->picture . '[/img]';
                    }
                    // if just a link, it may be a wall photo - check
                    if (isset($entry->link)) {
                        $datarray['body'] .= fb_get_photo($uid, $entry->link);
                    }
                }
            }
            if ($datarray['app'] == "Events" and isset($entry->actions)) {
                foreach ($entry->actions as $action) {
                    if ($action->name == "View") {
                        $datarray['body'] .= " [url=" . $action->link . "]" . $entry->story . "[/url]";
                    }
                }
            }
            // Just as a test - to see if these are the missing entries
            //if(trim($datarray['body']) == '')
            //	$datarray['body'] = $entry->story;
            // Adding the "story" text to see if there are useful data in it (testing)
            //if (($datarray['app'] != "Events") and $entry->story)
            //	$datarray['body'] .= "\n".$entry->story;
            if (trim($datarray['body']) == '') {
                logger('facebook: empty body ' . $entry->id . ' ' . print_r($entry, true));
                continue;
            }
            $datarray['body'] .= "\n";
            if (isset($entry->icon)) {
                $datarray['body'] .= "[img]" . $entry->icon . "[/img] &nbsp; ";
            }
            if (isset($entry->actions)) {
                foreach ($entry->actions as $action) {
                    if ($action->name != "Comment" and $action->name != "Like") {
                        $datarray['body'] .= "[url=" . $action->link . "]" . $action->name . "[/url] &nbsp; ";
                    }
                }
            }
            $datarray['body'] = trim($datarray['body']);
            //if(($datarray['body'] != '') and ($uid == 1))
            //	$datarray['body'] .= "[noparse]".print_r($entry, true)."[/noparse]";
            if (isset($entry->place)) {
                if ($entry->place->name or $entry->place->location->street or $entry->place->location->city or $entry->place->location->Denmark) {
                    $datarray['coord'] = '';
                    if ($entry->place->name) {
                        $datarray['coord'] .= $entry->place->name;
                    }
                    if ($entry->place->location->street) {
                        $datarray['coord'] .= $entry->place->location->street;
                    }
                    if ($entry->place->location->city) {
                        $datarray['coord'] .= " " . $entry->place->location->city;
                    }
                    if ($entry->place->location->country) {
                        $datarray['coord'] .= " " . $entry->place->location->country;
                    }
                } else {
                    if ($entry->place->location->latitude and $entry->place->location->longitude) {
                        $datarray['coord'] = substr($entry->place->location->latitude, 0, 8) . ' ' . substr($entry->place->location->longitude, 0, 8);
                    }
                }
            }
            $datarray['created'] = datetime_convert('UTC', 'UTC', $entry->created_time);
            $datarray['edited'] = datetime_convert('UTC', 'UTC', $entry->updated_time);
            // If the entry has a privacy policy, we cannot assume who can or cannot see it,
            // as the identities are from a foreign system. Mark it as private to the owner.
            if (isset($entry->privacy) && $entry->privacy->value !== 'EVERYONE') {
                $datarray['private'] = 1;
                $datarray['allow_cid'] = '<' . $self[0]['id'] . '>';
            }
            $top_item = item_store($datarray);
            $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($top_item), intval($uid));
            if (count($r)) {
                $orig_post = $r[0];
                logger('fb: new top level item posted');
            }
        }
        /**  @var array $orig_post */
        $likers_num = isset($entry->likes) && isset($entry->likes->count) ? IntVal($entry->likes->count) : 0;
        if (isset($entry->likes) && isset($entry->likes->data)) {
            $likers = $entry->likes->data;
        } else {
            $likers = null;
        }
        $comments_num = isset($entry->comments) && isset($entry->comments->count) ? IntVal($entry->comments->count) : 0;
        if (isset($entry->comments) && isset($entry->comments->data)) {
            $comments = $entry->comments->data;
        } else {
            $comments = null;
        }
        $needs_sync = false;
        if (is_array($likers)) {
            foreach ($likers as $likes) {
                fb_consume_like($a, $user, $self, $self_id, $wall, $orig_post, $likes);
            }
            if ($sync_comments) {
                $r = q("SELECT COUNT(*) likes FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `verb` = '%s' AND `parent-uri` != `uri`", dbesc($orig_post['uri']), intval($uid), dbesc(ACTIVITY_LIKE));
                if ($r[0]['likes'] < $likers_num) {
                    logger('fb_consume_stream: missing likes found for ' . $orig_post['uri'] . ' (we have ' . $r[0]['likes'] . ' of ' . $likers_num . '). Synchronizing...', LOGGER_DEBUG);
                    $needs_sync = true;
                }
            }
        }
        if (is_array($comments)) {
            foreach ($comments as $cmnt) {
                fb_consume_comment($a, $user, $self, $self_id, $wall, $orig_post, $cmnt);
            }
            if ($sync_comments) {
                $r = q("SELECT COUNT(*) comments FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `verb` = '%s' AND `parent-uri` != `uri`", dbesc($orig_post['uri']), intval($uid), ACTIVITY_POST);
                if ($r[0]['comments'] < $comments_num) {
                    logger('fb_consume_stream: missing comments found for ' . $orig_post['uri'] . ' (we have ' . $r[0]['comments'] . ' of ' . $comments_num . '). Synchronizing...', LOGGER_DEBUG);
                    $needs_sync = true;
                }
            }
        }
        if ($needs_sync) {
            fb_consume_status($a, $user, $entry, $self, $self_id, $wall, $orig_post);
        }
    }
}