4 * Description: Imports posts from a Google+ account and repeats them - not working by now
6 * Author: Michael Vogel <ike@piratenpartei.de>
10 function fromgplus_install() {
11 register_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
12 register_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
15 function fromgplus_uninstall() {
16 unregister_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
17 unregister_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
20 function fromgplus_addon_settings(&$a,&$s) {
25 $enable_checked = (intval(get_pconfig(local_user(),'fromgplus','enable')) ? ' checked="checked"' : '');
26 $account = get_pconfig(local_user(),'fromgplus','account');
28 $s .= '<div class="settings-block">';
29 $s .= '<h3>' . t('Google+ Import Settings').'</h3>';
30 $s .= '<div id="fromgplus-wrapper">';
32 $s .= '<label id="fromgplus-enable-label" for="fromgplus-enable">'.t('Enable Google+ Import').'</label>';
33 $s .= '<input id="fromgplus-enable" type="checkbox" name="fromgplus-enable" value="1"'.$enable_checked.' />';
34 $s .= '<div class="clear"></div>';
35 $s .= '<label id="fromgplus-label" for="fromgplus-account">'.t('Google Account ID').' </label>';
36 $s .= '<input id="fromgplus-account" type="text" name="fromgplus-account" value="'.$account.'" />';
37 $s .= '</div><div class="clear"></div>';
39 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="fromgplus-submit" name="fromgplus-submit"
40 class="settings-submit" value="' . t('Submit') . '" /></div>';
46 function fromgplus_addon_settings_post(&$a,&$b) {
51 if($_POST['fromgplus-submit']) {
52 set_pconfig(local_user(),'fromgplus','account',trim($_POST['fromgplus-account']));
53 $enable = ((x($_POST,'fromgplus-enable')) ? intval($_POST['fromgplus-enable']) : 0);
54 set_pconfig(local_user(),'fromgplus','enable', $enable);
55 info( t('Google+ Import Settings saved.') . EOL);
59 function html2bbcode($html) {
61 $bbcode = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
63 $bbcode = str_replace(array("\n"), array(""), $bbcode);
64 $bbcode = str_replace(array("<b>", "</b>"), array("[b]", "[/b]"), $bbcode);
65 $bbcode = str_replace(array("<i>", "</i>"), array("[i]", "[/i]"), $bbcode);
66 $bbcode = str_replace(array("<s>", "</s>"), array("[s]", "[/s]"), $bbcode);
67 $bbcode = str_replace(array("<br />"), array("\n"), $bbcode);
69 $bbcode = trim(strip_tags($bbcode));
73 function friendicapost($post) {
76 $api = new Statusnet($friendica["user"], $friendica["pw"], "GooglePlus", $friendica["server"]);
77 $ret = $api->updateStatus($post);
81 function handleattachments($item) {
84 foreach ($item->object->attachments as $attachment) {
85 switch($attachment->objectType) {
87 //$post .= "\n\n[url=".$attachment->url."]".
88 // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
89 $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
91 //if (strpos($attachment->embed->url, "youtube.com"))
92 // $post .= "[youtube]".$attachment->url."[/youtube]\n";
94 /// $post .= "[url=".$attachment->url."][img]".$attachment->image->url."[/img][/url]\n";
96 ///$post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
100 //$post .= "\n\n[url=".$attachment->url."]".
101 // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
102 $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
103 $post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
107 //$post .= "\n\n[url=".$attachment->fullImage->url."]".
108 // "[img]".$attachment->fullImage->url."[/img][/url]\n";
109 $post .= "\n\n[img]".$attachment->fullImage->url."[/img]\n";
110 if ($attachment->displayName != "")
111 $post .= html2bbcode($attachment->displayName)."\n";
115 $post .= "\n\n[url=".$attachment->url."]".
116 "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
120 print_r($attachment);
129 file_get_contents("https://www.googleapis.com/plus/v1/people/".$google["id"]."/activities/public?alt=json&pp=1&key=".$google["key"]."&maxResults=".$google["maxfetch"]);
130 $activities = json_decode($result);
132 $state = array("lastid"=>'');
133 if (file_exists($statefile))
134 $state = unserialize(file_get_contents($statefile));
138 foreach($activities->items as $item) {
139 if ($item->id == $state["lastid"])
145 switch($item->object->objectType) {
147 $post = html2bbcode($item->object->content);
149 if (is_array($item->object->attachments))
150 $post .= handleattachments($item);
151 friendicapost($post);
155 $post = html2bbcode($item->annotation)."\n";
156 //$post .= html2bbcode("♲ ");
157 $post .= html2bbcode("♻ ");
158 $post .= "[url=".$item->object->actor->url."]".$item->object->actor->displayName."[/url]";
160 //$post .= "[quote]";
162 $post .= html2bbcode($item->object->content);
164 if (is_array($item->object->attachments))
165 $post .= "\n".trim(handleattachments($item));
167 //$post .= "[/quote]";
169 friendicapost($post);
180 $state['lastid'] = $lastid;
181 file_put_contents($statefile, serialize($state));