+ if (!get_pconfig($b["uid"],'gpluspost','no_loop_prevention') && (($b['app'] == "Google+") || ($b["extid"] == NETWORK_GPLUS)))
+ return;
+
+ if (!gpluspost_nextscripts()) {
+ // Posting via RSS-Feed and Hootsuite
+ $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);
+
+ } else {
+ // Posting via NextScripts
+ $username = get_pconfig($b['uid'],'gpluspost','username');
+ $password = get_pconfig($b['uid'],'gpluspost','password');
+ $page = get_pconfig($b['uid'],'gpluspost','page');
+
+ $success = false;
+
+ if($username && $password) {
+ require_once("addon/gpluspost/postToGooglePlus.php");
+ require_once("include/plaintext.php");
+
+ $item = $b;
+
+ // Markup for Google+
+ if ($item["title"] != "")
+ $item["title"] = "*".$item["title"]."*";
+
+ $item["body"] = preg_replace("(\[b\](.*?)\[\/b\])ism",'*$1*',$item["body"]);
+ $item["body"] = preg_replace("(\[i\](.*?)\[\/i\])ism",'_$1_',$item["body"]);
+ $item["body"] = preg_replace("(\[s\](.*?)\[\/s\])ism",'-$1-',$item["body"]);
+
+ $data = plaintext($a, $item, 0, false, 9);
+
+ logger('gpluspost_send: data: '.print_r($data, true), LOGGER_DEBUG);
+
+ $loginError = doConnectToGooglePlus2($username, $password);
+ if (!$loginError) {
+ if ($data["url"] != "")
+ $lnk = doGetGoogleUrlInfo2($data["url"]);
+ elseif ($data["image"] != "")
+ $lnk = array('img'=>$data["image"]);
+ else
+ $lnk = "";
+
+ // Send a special blank to identify the post through the "fromgplus" addon
+ $blank = html_entity_decode(" ", ENT_QUOTES, 'UTF-8');
+
+ doPostToGooglePlus2($data["text"].$blank, $lnk, $page);
+
+ $success = true;
+
+ logger('gpluspost_send: '.$b['uid'].' success', LOGGER_DEBUG);
+ } else
+ logger('gpluspost_send: '.$b['uid'].' failed '.$loginError, LOGGER_DEBUG);
+
+ if (!$success) {
+ logger('gpluspost_send: requeueing '.$b['uid'], LOGGER_DEBUG);
+
+ $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", $b['uid']);
+ if (count($r))
+ $a->contact = $r[0]["id"];
+
+ $s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $data));
+ require_once('include/queue_fn.php');
+ add_to_queue($a->contact,NETWORK_GPLUS,$s);
+ notice(t('Google+ post failed. Queued for retry.').EOL);
+ }
+ } else
+ logger('gpluspost_send: '.$b['uid'].' missing username or password', LOGGER_DEBUG);
+ }
+
+}
+
+function gpluspost_queue_hook(&$a,&$b) {
+
+ $qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
+ dbesc(NETWORK_GPLUS)
+ );
+ if(! count($qi))