2 require_once("statusnet.lib.php");
5 function html2bbcode($html) {
7 $bbcode = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
9 $bbcode = str_replace(array("\n"), array(""), $bbcode);
10 $bbcode = str_replace(array("<b>", "</b>"), array("[b]", "[/b]"), $bbcode);
11 $bbcode = str_replace(array("<i>", "</i>"), array("[i]", "[/i]"), $bbcode);
12 $bbcode = str_replace(array("<s>", "</s>"), array("[s]", "[/s]"), $bbcode);
13 $bbcode = str_replace(array("<br />"), array("\n"), $bbcode);
15 $bbcode = trim(strip_tags($bbcode));
19 function friendicapost($post) {
22 $api = new Statusnet($friendica["user"], $friendica["pw"], "GooglePlus", $friendica["server"]);
23 $ret = $api->updateStatus($post);
27 function handleattachments($item) {
30 foreach ($item->object->attachments as $attachment) {
31 switch($attachment->objectType) {
33 //$post .= "\n\n[url=".$attachment->url."]".
34 // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
35 $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
37 //if (strpos($attachment->embed->url, "youtube.com"))
38 // $post .= "[youtube]".$attachment->url."[/youtube]\n";
40 /// $post .= "[url=".$attachment->url."][img]".$attachment->image->url."[/img][/url]\n";
42 ///$post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
46 //$post .= "\n\n[url=".$attachment->url."]".
47 // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
48 $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
49 $post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
53 //$post .= "\n\n[url=".$attachment->fullImage->url."]".
54 // "[img]".$attachment->fullImage->url."[/img][/url]\n";
55 $post .= "\n\n[img]".$attachment->fullImage->url."[/img]\n";
56 if ($attachment->displayName != "")
57 $post .= html2bbcode($attachment->displayName)."\n";
61 $post .= "\n\n[url=".$attachment->url."]".
62 "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
74 $result = file_get_contents("https://www.googleapis.com/plus/v1/people/".$google["id"]."/activities/public?alt=json&pp=1&key=".$google["key"]."&maxResults=".$google["maxfetch"]);
75 $activities = json_decode($result);
77 $state = array("lastid"=>'');
78 if (file_exists($statefile))
79 $state = unserialize(file_get_contents($statefile));
83 foreach($activities->items as $item) {
84 if ($item->id == $state["lastid"])
90 switch($item->object->objectType) {
92 $post = html2bbcode($item->object->content);
94 if (is_array($item->object->attachments))
95 $post .= handleattachments($item);
100 $post = html2bbcode($item->annotation)."\n";
101 //$post .= html2bbcode("♲ ");
102 $post .= html2bbcode("♻ ");
103 $post .= "[url=".$item->object->actor->url."]".$item->object->actor->displayName."[/url]";
105 //$post .= "[quote]";
107 $post .= html2bbcode($item->object->content);
109 if (is_array($item->object->attachments))
110 $post .= "\n".trim(handleattachments($item));
112 //$post .= "[/quote]";
114 friendicapost($post);
125 $state['lastid'] = $lastid;
126 file_put_contents($statefile, serialize($state));