+ $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))
+ return;
+
+ require_once('include/queue_fn.php');
+
+ foreach($qi as $x) {
+ if($x['network'] !== NETWORK_GPLUS)
+ continue;
+
+ logger('gpluspost_queue: run');
+
+ $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid`
+ WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
+ intval($x['cid'])
+ );
+ if(! count($r))
+ continue;
+
+ $userdata = $r[0];
+
+ //logger('gpluspost_queue: fetching userdata '.print_r($userdata, true));
+
+ $username = get_pconfig($userdata['uid'],'gpluspost','username');
+ $password = get_pconfig($userdata['uid'],'gpluspost','password');
+ $page = get_pconfig($userdata['uid'],'gpluspost','page');
+
+ $success = false;
+
+ if($username && $password) {
+ require_once("addon/gpluspost/postToGooglePlus.php");
+
+ logger('gpluspost_queue: able to post for user '.$username);
+
+ $z = unserialize($x['content']);
+
+ $data = $z['post'];
+ // $z['url']
+
+ logger('gpluspost_send: data: '.print_r($data, true), LOGGER_DATA);
+
+ $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);
+
+ logger('gpluspost_queue: send '.$userdata['uid'].' success', LOGGER_DEBUG);
+
+ $success = true;
+
+ remove_queue_item($x['id']);
+ } else
+ logger('gpluspost_queue: send '.$userdata['uid'].' failed '.$loginError, LOGGER_DEBUG);
+ } else
+ logger('gpluspost_queue: send '.$userdata['uid'].' missing username or password', LOGGER_DEBUG);
+
+ if (!$success) {
+ logger('gpluspost_queue: delayed');
+ update_queue_time($x['id']);
+ }
+ }