+ unregister_hook('post_local', 'addon/gpluspost/gpluspost.php', 'gpluspost_post_local');
+ unregister_hook('notifier_normal', 'addon/gpluspost/gpluspost.php', 'gpluspost_send');
+ unregister_hook('jot_networks', 'addon/gpluspost/gpluspost.php', 'gpluspost_jot_nets');
+ unregister_hook('connector_settings', 'addon/gpluspost/gpluspost.php', 'gpluspost_settings');
+ unregister_hook('connector_settings_post', 'addon/gpluspost/gpluspost.php', 'gpluspost_settings_post');
+}
+
+function gpluspost_jot_nets(&$a,&$b) {
+ if(! local_user())
+ return;
+
+ $post = get_pconfig(local_user(),'gpluspost','post');
+ if(intval($post) == 1) {
+ $defpost = get_pconfig(local_user(),'gpluspost','post_by_default');
+ $selected = ((intval($defpost) == 1) ? ' checked="checked" ' : '');
+ $b .= '<div class="profile-jot-net"><input type="checkbox" name="gpluspost_enable"' . $selected . ' value="1" /> '
+ . t('Post to Google+') . '</div>';
+ }
+}
+
+function gpluspost_settings(&$a,&$s) {
+
+ if(! local_user())
+ return;
+
+ $enabled = get_pconfig(local_user(),'gpluspost','post');
+
+ $checked = (($enabled) ? ' checked="checked" ' : '');
+
+ $def_enabled = get_pconfig(local_user(),'gpluspost','post_by_default');
+
+ $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
+
+ $s .= '<div class="settings-block">';
+ $s .= '<h3>' . t('Google+ Post Settings') . '</h3>';
+ $s .= '<div id="gpluspost-enable-wrapper">';
+ $s .= '<label id="gpluspost-enable-label" for="gpluspost-checkbox">' . t('Enable Google+ Post Plugin') . '</label>';
+ $s .= '<input id="gpluspost-checkbox" type="checkbox" name="gpluspost" value="1" ' . $checked . '/>';
+ $s .= '</div><div class="clear"></div>';
+
+ $s .= '<div id="gpluspost-bydefault-wrapper">';
+ $s .= '<label id="gpluspost-bydefault-label" for="gpluspost-bydefault">' . t('Post to Google+ by default') . '</label>';
+ $s .= '<input id="gpluspost-bydefault" type="checkbox" name="gpluspost_bydefault" value="1" ' . $def_checked . '/>';
+ $s .= '</div><div class="clear"></div>';
+
+ /* provide a submit button */
+
+ $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="gpluspost-submit" name="gpluspost-submit" class="settings-submit" value="' . t('Submit') . '" /></div>';
+ $s .= 'Register an account at <a href="https://hootsuite.com">Hootsuite</a>, add your G+ page and add the feed-url there.<br />';
+ //$s .= 'Feed-url: '.$a->get_baseurl().'/gpluspost/'.$a->user["uid"].'</div>';
+ $s .= 'Feed-url: '.$a->get_baseurl().'/gpluspost/'.urlencode($a->user["nickname"]).'</div>';
+}
+
+function gpluspost_settings_post(&$a,&$b) {
+
+ if(x($_POST,'gpluspost-submit')) {
+ set_pconfig(local_user(),'gpluspost','post',intval($_POST['gpluspost']));
+ set_pconfig(local_user(),'gpluspost','post_by_default',intval($_POST['gpluspost_bydefault']));
+ }
+}
+
+function gpluspost_post_local(&$a,&$b) {
+
+ if($b['edit'])
+ return;
+
+ if((! local_user()) || (local_user() != $b['uid']))
+ return;
+
+ if($b['private'] || $b['parent'])
+ return;
+
+ $post = intval(get_pconfig(local_user(),'gpluspost','post'));
+
+ $enable = (($post && x($_REQUEST,'gpluspost_enable')) ? intval($_REQUEST['gpluspost_enable']) : 0);
+
+ if(intval(get_pconfig(local_user(),'gpluspost','post_by_default')))
+ $enable = 1;
+
+ if(!$enable)
+ return;
+
+ if(strlen($b['postopts']))
+ $b['postopts'] .= ',';
+
+ $b['postopts'] .= 'gplus';
+}
+
+function gpluspost_send(&$a,&$b) {
+
+ logger('gpluspost_send: invoked for post '.$b['id']);
+
+ if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited']))
+ return;
+
+ if(! strstr($b['postopts'],'gplus'))
+ return;
+
+ if($b['parent'] != $b['id'])
+ return;
+
+ // if post comes from Google+ don't send it back
+ if($b['app'] == "Google+")
+ return;
+
+ $itemlist = get_pconfig($b["uid"],'gpluspost','itemlist');
+ $items = explode(",", $itemlist);
+
+ $i = 0;
+ $newitems = array($b['id']);
+ foreach ($items AS $item)
+ if ($i++ < 9)
+ $newitems[] = $item;
+
+ $itemlist = implode(",", $newitems);
+
+ logger('gpluspost_send: new itemlist: '.$itemlist." for uid ".$b["uid"]);
+
+ set_pconfig($b["uid"],'gpluspost','itemlist', $itemlist);