本文整理汇总了PHP中add_to_queue函数的典型用法代码示例。如果您正苦于以下问题:PHP add_to_queue函数的具体用法?PHP add_to_queue怎么用?PHP add_to_queue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_to_queue函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: die
if (!isset($command)) {
die("No command!");
}
if ($link = mysqli_connect("localhost", "queue", "password", "queue")) {
echo "connected to mysql<br>";
$cmd = mysqli_real_escape_string($link, $command);
$q = mysqli_query($link, "INSERT into queue VALUES (NULL, 0, '{$cmd}')") or die(mysqli_error($link));
mysqli_close($link);
echo "Command {$command} added to the queue!";
} else {
echo "cannot connect to database!";
}
}
if (isset($_GET['a'])) {
$add = $_GET['a'];
add_to_queue($add);
//add this event to the queue
} else {
//run something from the queue
if ($link = mysqli_connect("localhost", "queue", "password", "queue")) {
$q = mysqli_query($link, "SELECT * from queue.queue where status = 0 ORDER BY id asc limit 1");
if ($q) {
$rows = mysqli_num_rows($q);
if ($rows > 0) {
$row = mysqli_fetch_row($q);
$id = $row[0];
$html = $row[2];
$u_q = mysqli_query($link, "UPDATE queue.queue SET status = 1 where id = {$id} limit 1");
}
}
}
示例2: gpluspost_send
function gpluspost_send(&$a, &$b)
{
logger('gpluspost_send: invoked for post ' . $b['id'] . " " . $b['app']);
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 (!get_pconfig($b["uid"], 'gpluspost', 'no_loop_prevention') and ($b['app'] == "Google+" or $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);
}
}
}
示例3: diaspora_transmit
function diaspora_transmit($owner, $contact, $slap, $public_batch, $queue_run = false)
{
$enabled = intval(get_config('system', 'diaspora_enabled'));
if (!$enabled) {
return 200;
}
$a = get_app();
$logid = random_string(4);
$dest_url = $public_batch ? $contact['batch'] : $contact['notify'];
if (!$dest_url) {
logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch);
return 0;
}
logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
if (!$queue_run && was_recently_delayed($contact['id'])) {
$return_code = 0;
} else {
if (!intval(get_config('system', 'diaspora_test'))) {
post_url($dest_url . '/', $slap);
$return_code = $a->get_curl_code();
} else {
logger('diaspora_transmit: test_mode');
return 200;
}
}
logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
if (!$return_code || $return_code == 503 && stristr($a->get_curl_headers(), 'retry-after')) {
logger('diaspora_transmit: queue message');
$r = q("SELECT id from queue where cid = %d and network = '%s' and content = '%s' and batch = %d limit 1", intval($contact['id']), dbesc(NETWORK_DIASPORA), dbesc($slap), intval($public_batch));
if (count($r)) {
logger('diaspora_transmit: add_to_queue ignored - identical item already in queue');
} else {
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_DIASPORA, $slap, $public_batch);
}
}
return $return_code ? $return_code : -1;
}
示例4: delivery_run
//.........这里部分代码省略.........
$nickname = basename($contact['url']);
if ($contact['issued-id']) {
$sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
} else {
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
}
$x = q("SELECT\t`contact`.*, `contact`.`uid` AS `importer_uid`,\n\t\t\t\t\t\t`contact`.`pubkey` AS `cpubkey`,\n\t\t\t\t\t\t`contact`.`prvkey` AS `cprvkey`,\n\t\t\t\t\t\t`contact`.`thumb` AS `thumb`,\n\t\t\t\t\t\t`contact`.`url` as `url`,\n\t\t\t\t\t\t`contact`.`name` as `senderName`,\n\t\t\t\t\t\t`user`.*\n\t\t\t\t\t\tFROM `contact`\n\t\t\t\t\t\tINNER JOIN `user` ON `contact`.`uid` = `user`.`uid`\n\t\t\t\t\t\tWHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\t\t\tAND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'\n\t\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t\tAND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1", dbesc(NETWORK_DFRN), dbesc($nickname));
if ($x && count($x)) {
$write_flag = $x[0]['rel'] && $x[0]['rel'] != CONTACT_IS_SHARING ? true : false;
if (($owner['page-flags'] == PAGE_COMMUNITY || $write_flag) && !$x[0]['writable']) {
q("update contact set writable = 1 where id = %d", intval($x[0]['id']));
$x[0]['writable'] = 1;
}
$ssl_policy = get_config('system', 'ssl_policy');
fix_contact_ssl_policy($x[0], $ssl_policy);
// If we are setup as a soapbox we aren't accepting input from this person
if ($x[0]['page-flags'] == PAGE_SOAPBOX) {
break;
}
require_once 'library/simplepie/simplepie.inc';
logger('mod-delivery: local delivery');
local_delivery($x[0], $atom);
break;
}
}
if (!was_recently_delayed($contact['id'])) {
$deliver_status = dfrn_deliver($owner, $contact, $atom);
} else {
$deliver_status = -1;
}
logger('notifier: dfrn_delivery returns ' . $deliver_status);
if ($deliver_status == -1) {
logger('notifier: delivery failed: queuing message');
add_to_queue($contact['id'], NETWORK_DFRN, $atom);
}
break;
case NETWORK_OSTATUS:
// Do not send to otatus if we are not configured to send to public networks
if ($owner['prvnets']) {
break;
}
if (get_config('system', 'ostatus_disabled') || get_config('system', 'dfrn_only')) {
break;
}
// only send salmon if public - e.g. if it's ok to notify
// a public hub, it's ok to send a salmon
if ($public_message && !$expire) {
$slaps = array();
foreach ($items as $item) {
if (!$item['parent']) {
continue;
}
// private emails may be in included in public conversations. Filter them.
if ($public_message && $item['private'] == 1) {
continue;
}
$item_contact = get_item_contact($item, $icontacts);
if (!$item_contact) {
continue;
}
if ($top_level && $public_message && $item['author-link'] === $item['owner-link'] && !$expire) {
$slaps[] = atom_entry($item, 'html', null, $owner, true);
}
}
logger('notifier: slapdelivery: ' . $contact['name']);
foreach ($slaps as $slappy) {
示例5: notifier_run
//.........这里部分代码省略.........
proc_run('php', 'include/delivery.php', $cmd, $item_id, $contact['id']);
if ($interval) {
@time_sleep_until(microtime(true) + (double) $interval);
}
continue;
}
$deliver_status = 0;
logger("main delivery by notifier: followup={$followup} mail={$mail} fsuggest={$fsuggest}");
switch ($contact['network']) {
case NETWORK_DFRN:
// perform local delivery if we are on the same site
$basepath = implode('/', array_slice(explode('/', $contact['url']), 0, 3));
if (link_compare($basepath, $a->get_baseurl())) {
$nickname = basename($contact['url']);
if ($contact['issued-id']) {
$sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
} else {
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
}
$x = q("SELECT\t`contact`.*, `contact`.`uid` AS `importer_uid`, \n\t\t\t\t\t\t\t`contact`.`pubkey` AS `cpubkey`, \n\t\t\t\t\t\t\t`contact`.`prvkey` AS `cprvkey`, \n\t\t\t\t\t\t\t`contact`.`thumb` AS `thumb`, \n\t\t\t\t\t\t\t`contact`.`url` as `url`,\n\t\t\t\t\t\t\t`contact`.`name` as `senderName`,\n\t\t\t\t\t\t\t`user`.* \n\t\t\t\t\t\t\tFROM `contact` \n\t\t\t\t\t\t\tLEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` \n\t\t\t\t\t\t\tWHERE `contact`.`blocked` = 0 AND `contact`.`pending` = 0\n\t\t\t\t\t\t\tAND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'\n\t\t\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t\t\tAND `user`.`account_expired` = 0 LIMIT 1", dbesc(NETWORK_DFRN), dbesc($nickname));
if (count($x)) {
require_once 'library/simplepie/simplepie.inc';
logger('mod-delivery: local delivery');
local_delivery($x[0], $atom);
break;
}
}
logger('notifier: dfrndelivery: ' . $contact['name']);
$deliver_status = dfrn_deliver($owner, $contact, $atom);
logger('notifier: dfrn_delivery returns ' . $deliver_status);
if ($deliver_status == -1) {
logger('notifier: delivery failed: queuing message');
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_DFRN, $atom);
}
break;
case NETWORK_OSTATUS:
// Do not send to otatus if we are not configured to send to public networks
if ($owner['prvnets']) {
break;
}
if (get_config('system', 'ostatus_disabled') || get_config('system', 'dfrn_only')) {
break;
}
if ($followup && $contact['notify']) {
logger('notifier: slapdelivery: ' . $contact['name']);
$deliver_status = slapper($owner, $contact['notify'], $slap);
if ($deliver_status == -1) {
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_OSTATUS, $slap);
}
} else {
// only send salmon if public - e.g. if it's ok to notify
// a public hub, it's ok to send a salmon
if (count($slaps) && $public_message && !$expire) {
logger('notifier: slapdelivery: ' . $contact['name']);
foreach ($slaps as $slappy) {
if ($contact['notify']) {
$deliver_status = slapper($owner, $contact['notify'], $slappy);
if ($deliver_status == -1) {
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_OSTATUS, $slappy);
}
}
}
}
示例6: twitter_post_hook
//.........这里部分代码省略.........
if ($b['extid'] == NETWORK_TWITTER) {
return;
}
if ($b['app'] == "Twitter") {
return;
}
logger('twitter post invoked');
load_pconfig($b['uid'], 'twitter');
$ckey = get_config('twitter', 'consumerkey');
$csecret = get_config('twitter', 'consumersecret');
$otoken = get_pconfig($b['uid'], 'twitter', 'oauthtoken');
$osecret = get_pconfig($b['uid'], 'twitter', 'oauthsecret');
if ($ckey && $csecret && $otoken && $osecret) {
logger('twitter: we have customer key and oauth stuff, going to send.', LOGGER_DEBUG);
// If it's a repeated message from twitter then do a native retweet and exit
if (twitter_is_retweet($a, $b['uid'], $b['body'])) {
return;
}
require_once 'library/twitteroauth.php';
require_once 'include/bbcode.php';
$tweet = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
$max_char = 140;
require_once "include/plaintext.php";
$msgarr = plaintext($a, $b, $max_char, true, 8);
$msg = $msgarr["text"];
if ($msg == "" and isset($msgarr["title"])) {
$msg = shortenmsg($msgarr["title"], $max_char - 50);
}
$image = "";
if (isset($msgarr["url"]) and $msgarr["type"] != "photo") {
$msg .= "\n" . $msgarr["url"];
} elseif (isset($msgarr["image"]) and $msgarr["type"] != "video") {
$image = $msgarr["image"];
}
// and now tweet it :-)
if (strlen($msg) and $image != "") {
$img_str = fetch_url($image);
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);
// Twitter had changed something so that the old library doesn't work anymore
// so we are using a new library for twitter
// To-Do:
// Switching completely to this library with all functions
require_once "addon/twitter/codebird.php";
$cb = \Codebird\Codebird::getInstance();
$cb->setConsumerKey($ckey, $csecret);
$cb->setToken($otoken, $osecret);
$post = array('status' => $msg, 'media[]' => $tempfile);
if ($iscomment) {
$post["in_reply_to_status_id"] = substr($orig_post["uri"], 9);
}
$result = $cb->statuses_updateWithMedia($post);
unlink($tempfile);
logger('twitter_post_with_media send, result: ' . print_r($result, true), LOGGER_DEBUG);
if ($result->source) {
set_config("twitter", "application_name", strip_tags($result->source));
}
if ($result->errors or $result->error) {
logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"');
// Workaround: Remove the picture link so that the post can be reposted without it
$msg .= " " . $image;
$image = "";
} elseif ($iscomment) {
logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']);
q("UPDATE `item` SET `extid` = '%s', `body` = '%s' WHERE `id` = %d", dbesc("twitter::" . $result->id_str), dbesc($result->text), intval($b['id']));
}
}
if (strlen($msg) and $image == "") {
$url = 'statuses/update';
$post = array('status' => $msg);
if ($iscomment) {
$post["in_reply_to_status_id"] = substr($orig_post["uri"], 9);
}
$result = $tweet->post($url, $post);
logger('twitter_post send, result: ' . print_r($result, true), LOGGER_DEBUG);
if ($result->source) {
set_config("twitter", "application_name", strip_tags($result->source));
}
if ($result->errors) {
logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"');
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid']));
if (count($r)) {
$a->contact = $r[0]["id"];
}
$s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $post));
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_TWITTER, $s);
notice(t('Twitter post failed. Queued for retry.') . EOL);
} elseif ($iscomment) {
logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']);
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d", dbesc("twitter::" . $result->id_str), intval($b['id']));
//q("UPDATE `item` SET `extid` = '%s', `body` = '%s' WHERE `id` = %d",
// dbesc("twitter::".$result->id_str),
// dbesc($result->text),
// intval($b['id'])
//);
}
}
}
}
示例7: pumpio_action
function pumpio_action(&$a, $uid, $uri, $action, $content = "")
{
// Don't do likes and other stuff if you don't import the timeline
if (!get_pconfig($uid, 'pumpio', 'import')) {
return;
}
$ckey = get_pconfig($uid, 'pumpio', 'consumer_key');
$csecret = get_pconfig($uid, 'pumpio', 'consumer_secret');
$otoken = get_pconfig($uid, 'pumpio', 'oauth_token');
$osecret = get_pconfig($uid, 'pumpio', 'oauth_token_secret');
$hostname = get_pconfig($uid, 'pumpio', 'host');
$username = get_pconfig($uid, "pumpio", "user");
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($uri), intval($uid));
if (!count($r)) {
return;
}
$orig_post = $r[0];
if ($orig_post["extid"] and !strstr($orig_post["extid"], "/proxy/")) {
$uri = $orig_post["extid"];
} else {
$uri = $orig_post["uri"];
}
if ($orig_post["object-type"] != "" and strstr($orig_post["object-type"], NAMESPACE_ACTIVITY_SCHEMA)) {
$objectType = str_replace(NAMESPACE_ACTIVITY_SCHEMA, '', $orig_post["object-type"]);
} elseif (strstr($uri, "/api/comment/")) {
$objectType = "comment";
} elseif (strstr($uri, "/api/note/")) {
$objectType = "note";
} elseif (strstr($uri, "/api/image/")) {
$objectType = "image";
}
$params["verb"] = $action;
$params["object"] = array('id' => $uri, "objectType" => $objectType, "content" => $content);
$client = new oauth_client_class();
$client->oauth_version = '1.0a';
$client->authorization_header = true;
$client->url_parameters = false;
$client->client_id = $ckey;
$client->client_secret = $csecret;
$client->access_token = $otoken;
$client->access_token_secret = $osecret;
$url = 'https://' . $hostname . '/api/user/' . $username . '/feed';
if (pumpio_reachable($url)) {
$success = $client->CallAPI($url, 'POST', $params, array('FailOnAccessError' => true, 'RequestContentType' => 'application/json'), $user);
} else {
$success = false;
}
if ($success) {
logger('pumpio_action ' . $username . ' ' . $action . ': success ' . $uri);
} else {
logger('pumpio_action ' . $username . ' ' . $action . ': general error: ' . $uri . ' ' . print_r($user, true));
$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' => $orig_post["id"], 'post' => $params));
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_PUMPIO, $s);
notice(t('Pump.io like failed. Queued for retry.') . EOL);
}
}
示例8: fbpost_post_hook
//.........这里部分代码省略.........
if (count($deny_arr)) {
$postvars['privacy'] .= ',"deny": "' . implode(',', $deny_arr) . '"';
}
$postvars['privacy'] .= '}';
}
$post_to_page = get_pconfig($b['uid'], 'facebook', 'post_to_page');
$page_access_token = get_pconfig($b['uid'], 'facebook', 'page_access_token');
if (intval($post_to_page) != 0 and $page_access_token != "") {
$target = $post_to_page;
} else {
$target = "me";
}
if ($reply) {
$url = 'https://graph.facebook.com/' . $reply . '/' . ($likes ? 'likes' : 'comments');
} else {
if ($video != "" or $image == "" and $link != "") {
// If it is a link to a video or a link without a preview picture then post it as a link
if ($video != "") {
$link = $video;
}
$postvars = array('access_token' => $fb_token, 'link' => $link);
if ($msg != $video) {
$postvars['message'] = $msg;
}
$url = 'https://graph.facebook.com/' . $target . '/links';
} else {
if ($link == "" and $image != "") {
// If it is only an image without a page link then post this image as a photo
$postvars = array('access_token' => $fb_token, 'url' => $image);
if ($msg != $image) {
$postvars['message'] = $msg;
}
$url = 'https://graph.facebook.com/' . $target . '/photos';
//} else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) {
} else {
$url = 'https://graph.facebook.com/' . $target . '/feed';
if (!get_pconfig($b['uid'], 'facebook', 'suppress_view_on_friendica') and $b['plink']) {
$postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}';
}
}
}
}
/* } else {
// if its only a message and a subject and the message is larger than 500 characters then post it as note
$postvars = array(
'access_token' => $fb_token,
'message' => bbcode($b['body'], false, false),
'subject' => $b['title'],
);
$url = 'https://graph.facebook.com/'.$target.'/notes';
} */
// Post to page?
if (!$reply and $target != "me" and $page_access_token) {
$postvars['access_token'] = $page_access_token;
}
logger('fbpost_post_hook: post to ' . $url);
logger('fbpost_post_hook: postvars: ' . print_r($postvars, true));
// "test_mode" prevents anything from actually being posted.
// Otherwise, let's do it.
if (!get_config('facebook', 'test_mode')) {
$x = post_url($url, $postvars);
logger('fbpost_post_hook: post returns: ' . $x, LOGGER_DEBUG);
$retj = json_decode($x);
if ($retj->id) {
// Only set the extid when it isn't the toplevel post
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d AND `parent` != %d", dbesc('fb::' . $retj->id), intval($b['id']), intval($b['id']));
} else {
// Sometimes posts are accepted from facebook although it telling an error
// This leads to endless comment flooding.
// If it is a special kind of failure the post was receiced
// Although facebook said it wasn't received ...
if (!$likes and ($retj->error->type != "OAuthException" or $retj->error->code != 2) and $x != "") {
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid']));
if (count($r)) {
$a->contact = $r[0]["id"];
}
$s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars));
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_FACEBOOK, $s);
logger('fbpost_post_hook: Post failed, requeued.', LOGGER_DEBUG);
notice(t('Facebook post failed. Queued for retry.') . EOL);
}
if (isset($retj->error) && $retj->error->type == "OAuthException" && $retj->error->code == 190) {
logger('fbpost_post_hook: Facebook session has expired due to changed password.', LOGGER_DEBUG);
$last_notification = get_pconfig($b['uid'], 'facebook', 'session_expired_mailsent');
if (!$last_notification || $last_notification < time() - FACEBOOK_SESSION_ERR_NOTIFICATION_INTERVAL) {
require_once 'include/enotify.php';
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($b['uid']));
notification(array('uid' => $b['uid'], 'type' => NOTIFY_SYSTEM, 'system_type' => 'facebook_connection_invalid', 'language' => $r[0]['language'], 'to_name' => $r[0]['username'], 'to_email' => $r[0]['email'], 'source_name' => t('Administrator'), 'source_link' => $a->config["system"]["url"], 'source_photo' => $a->config["system"]["url"] . '/images/person-80.jpg'));
set_pconfig($b['uid'], 'facebook', 'session_expired_mailsent', time());
} else {
logger('fbpost_post_hook: No notification, as the last one was sent on ' . $last_notification, LOGGER_DEBUG);
}
}
}
}
}
}
}
}
示例9: profile_change
function profile_change()
{
$a = get_app();
if (!local_user()) {
return;
}
// $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
// if($url && strlen(get_config('system','directory_submit_url')))
// proc_run('php',"include/directory.php","$url");
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'\n\t\tAND `uid` = %d AND `rel` != %d ", dbesc(NETWORK_DIASPORA), intval(local_user()), intval(CONTACT_IS_SHARING));
if (!count($recips)) {
return;
}
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`\n\t\tINNER JOIN `user` ON `profile`.`uid` = `user`.`uid`\n\t\tWHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1", intval(local_user()));
if (!count($r)) {
return;
}
$profile = $r[0];
$handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3));
$first = xmlify(strpos($profile['name'], ' ') ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name']);
$last = xmlify($first === $profile['name'] ? '' : trim(substr($profile['name'], strlen($first))));
$large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
$medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
$small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg');
$searchable = xmlify($profile['publish'] && $profile['net-publish'] ? 'true' : 'false');
// $searchable = 'true';
if ($searchable === 'true') {
$dob = '1000-00-00';
if ($profile['dob'] && $profile['dob'] != '0000-00-00') {
$dob = (intval($profile['dob']) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC', 'UTC', $profile['dob'], 'm-d');
}
$gender = xmlify($profile['gender']);
$about = xmlify($profile['about']);
require_once 'include/bbcode.php';
$about = xmlify(strip_tags(bbcode($about)));
$location = '';
if ($profile['locality']) {
$location .= $profile['locality'];
}
if ($profile['region']) {
if ($location) {
$location .= ', ';
}
$location .= $profile['region'];
}
if ($profile['country-name']) {
if ($location) {
$location .= ', ';
}
$location .= $profile['country-name'];
}
$location = xmlify($location);
$tags = '';
if ($profile['pub_keywords']) {
$kw = str_replace(',', ' ', $profile['pub_keywords']);
$kw = str_replace(' ', ' ', $kw);
$arr = explode(' ', $profile['pub_keywords']);
if (count($arr)) {
for ($x = 0; $x < 5; $x++) {
if (trim($arr[$x])) {
$tags .= '#' . trim($arr[$x]) . ' ';
}
}
}
}
$tags = xmlify(trim($tags));
}
$tpl = get_markup_template('diaspora_profile.tpl');
$msg = replace_macros($tpl, array('$handle' => $handle, '$first' => $first, '$last' => $last, '$large' => $large, '$medium' => $medium, '$small' => $small, '$dob' => $dob, '$gender' => $gender, '$about' => $about, '$location' => $location, '$searchable' => $searchable, '$tags' => $tags));
logger('profile_change: ' . $msg, LOGGER_ALL);
foreach ($recips as $recip) {
$msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $a->user, $recip, $a->user['prvkey'], $recip['pubkey'], false)));
add_to_queue($recip['id'], NETWORK_DIASPORA, $msgtosend, false);
}
}
示例10: notifier_run
//.........这里部分代码省略.........
$nickname = basename($contact['url']);
if ($contact['issued-id']) {
$sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
} else {
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
}
$x = q("SELECT\t`contact`.*, `contact`.`uid` AS `importer_uid`,\n\t\t\t\t\t\t\t`contact`.`pubkey` AS `cpubkey`,\n\t\t\t\t\t\t\t`contact`.`prvkey` AS `cprvkey`,\n\t\t\t\t\t\t\t`contact`.`thumb` AS `thumb`,\n\t\t\t\t\t\t\t`contact`.`url` as `url`,\n\t\t\t\t\t\t\t`contact`.`name` as `senderName`,\n\t\t\t\t\t\t\t`user`.*\n\t\t\t\t\t\t\tFROM `contact`\n\t\t\t\t\t\t\tINNER JOIN `user` ON `contact`.`uid` = `user`.`uid`\n\t\t\t\t\t\t\tWHERE `contact`.`blocked` = 0 AND `contact`.`archive` = 0\n\t\t\t\t\t\t\tAND `contact`.`pending` = 0\n\t\t\t\t\t\t\tAND `contact`.`network` = '%s' AND `user`.`nickname` = '%s'\n\t\t\t\t\t\t\t{$sql_extra}\n\t\t\t\t\t\t\tAND `user`.`account_expired` = 0 AND `user`.`account_removed` = 0 LIMIT 1", dbesc(NETWORK_DFRN), dbesc($nickname));
if ($x && count($x)) {
$write_flag = $x[0]['rel'] && $x[0]['rel'] != CONTACT_IS_SHARING ? true : false;
if (($owner['page-flags'] == PAGE_COMMUNITY || $write_flag) && !$x[0]['writable']) {
q("update contact set writable = 1 where id = %d", intval($x[0]['id']));
$x[0]['writable'] = 1;
}
// if contact's ssl policy changed, which we just determined
// is on our own server, update our contact links
$ssl_policy = get_config('system', 'ssl_policy');
fix_contact_ssl_policy($x[0], $ssl_policy);
// If we are setup as a soapbox we aren't accepting top level posts from this person
if ($x[0]['page-flags'] == PAGE_SOAPBOX and $top_level) {
break;
}
require_once 'library/simplepie/simplepie.inc';
logger('mod-delivery: local delivery');
local_delivery($x[0], $atom);
break;
}
}
logger('notifier: dfrndelivery: ' . $contact['name']);
$deliver_status = dfrn_deliver($owner, $contact, $atom);
logger('notifier: dfrn_delivery returns ' . $deliver_status);
if ($deliver_status == -1) {
logger('notifier: delivery failed: queuing message');
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_DFRN, $atom);
}
break;
case NETWORK_OSTATUS:
// Do not send to ostatus if we are not configured to send to public networks
if ($owner['prvnets']) {
break;
}
if (get_config('system', 'ostatus_disabled') || get_config('system', 'dfrn_only')) {
break;
}
if ($followup && $contact['notify']) {
logger('slapdelivery followup item ' . $item_id . ' to ' . $contact['name']);
$deliver_status = slapper($owner, $contact['notify'], $slap);
if ($deliver_status == -1) {
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_OSTATUS, $slap);
}
} else {
// only send salmon if public - e.g. if it's ok to notify
// a public hub, it's ok to send a salmon
if (count($slaps) && $public_message && !$expire) {
logger('slapdelivery item ' . $item_id . ' to ' . $contact['name']);
foreach ($slaps as $slappy) {
if ($contact['notify']) {
$deliver_status = slapper($owner, $contact['notify'], $slappy);
if ($deliver_status == -1) {
// queue message for redelivery
add_to_queue($contact['id'], NETWORK_OSTATUS, $slappy);
}
}
}
}
示例11: diaspora_send
function diaspora_send(&$a, &$b)
{
$hostname = $a->get_hostname();
logger('diaspora_send: invoked');
if ($b['deleted'] || $b['private'] || $b['created'] !== $b['edited']) {
return;
}
if (!strstr($b['postopts'], 'diaspora')) {
return;
}
if ($b['parent'] != $b['id']) {
return;
}
logger('diaspora_send: prepare posting', LOGGER_DEBUG);
$diaspora_username = get_pconfig($b['uid'], 'diaspora', 'diaspora_username');
$diaspora_password = get_pconfig($b['uid'], 'diaspora', 'diaspora_password');
$diaspora_url = get_pconfig($b['uid'], 'diaspora', 'diaspora_url');
if ($diaspora_url && $diaspora_username && $diaspora_password) {
logger('diaspora_send: all values seem to be okay', LOGGER_DEBUG);
require_once 'include/bb2diaspora.php';
$tag_arr = array();
$tags = '';
$x = preg_match_all('/\\#\\[(.*?)\\](.*?)\\[/', $b['tag'], $matches, PREG_SET_ORDER);
if ($x) {
foreach ($matches as $mtch) {
$tag_arr[] = $mtch[2];
}
}
if (count($tag_arr)) {
$tags = implode(',', $tag_arr);
}
$title = $b['title'];
$body = $b['body'];
// Insert a newline before and after a quote
$body = str_ireplace("[quote", "\n\n[quote", $body);
$body = str_ireplace("[/quote]", "[/quote]\n\n", $body);
// Removal of tags and mentions
// #-tags
$body = preg_replace('/#\\[url\\=(\\w+.*?)\\](\\w+.*?)\\[\\/url\\]/i', '#$2', $body);
// @-mentions
$body = preg_replace('/@\\[url\\=(\\w+.*?)\\](\\w+.*?)\\[\\/url\\]/i', '@$2', $body);
// remove multiple newlines
do {
$oldbody = $body;
$body = str_replace("\n\n\n", "\n\n", $body);
} while ($oldbody != $body);
// convert to markdown
$body = bb2diaspora($body, false, true);
// Adding the title
if (strlen($title)) {
$body = "## " . html_entity_decode($title) . "\n\n" . $body;
}
require_once "addon/diaspora/diasphp.php";
try {
logger('diaspora_send: prepare', LOGGER_DEBUG);
$conn = new Diasphp($diaspora_url);
logger('diaspora_send: try to log in ' . $diaspora_username, LOGGER_DEBUG);
$conn->login($diaspora_username, $diaspora_password);
logger('diaspora_send: try to send ' . $body, LOGGER_DEBUG);
//throw new Exception('Test');
$conn->post($body, $hostname);
logger('diaspora_send: success');
} catch (Exception $e) {
logger("diaspora_send: Error submitting the post: " . $e->getMessage());
logger('diaspora_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' => $body));
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_DIASPORA2, $s);
notice(t('Diaspora post failed. Queued for retry.') . EOL);
}
}
}
示例12: facebook_post_hook
//.........这里部分代码省略.........
// setup a cascade of shortening services
// try to get a short link from these services
// in the order ur1.ca, trim, id.gd, tinyurl
$slinky->set_cascade(array(new Slinky_UR1ca(), new Slinky_Trim(), new Slinky_IsGd(), new Slinky_TinyURL()));
$shortlink = $slinky->short();
// the new message will be shortened such that "... $shortlink"
// will fit into the character limit
$msg = substr($msg, 0, FACEBOOK_MAXPOSTLEN - strlen($shortlink) - 4);
$msg .= '... ' . $shortlink;
}
// Fallback - if message is empty
if (!strlen($msg)) {
$msg = $link;
}
if (!strlen($msg)) {
$msg = $image;
}
if (!strlen($msg)) {
$msg = $linkname;
}
// If there is nothing to post then exit
if (!strlen($msg)) {
return;
}
logger('Facebook post: msg=' . $msg, LOGGER_DATA);
if ($likes) {
$postvars = array('access_token' => $fb_token);
} else {
$postvars = array('access_token' => $fb_token, 'message' => $msg);
if (isset($image)) {
$postvars['picture'] = $image;
//$postvars['type'] = "photo";
}
if (isset($link)) {
$postvars['link'] = $link;
//$postvars['type'] = "link";
}
if (isset($linkname)) {
$postvars['name'] = $linkname;
}
}
if ($b['private'] && $toplevel) {
$postvars['privacy'] = '{"value": "CUSTOM", "friends": "SOME_FRIENDS"';
if (count($allow_arr)) {
$postvars['privacy'] .= ',"allow": "' . implode(',', $allow_arr) . '"';
}
if (count($deny_arr)) {
$postvars['privacy'] .= ',"deny": "' . implode(',', $deny_arr) . '"';
}
$postvars['privacy'] .= '}';
}
if ($reply) {
$url = 'https://graph.facebook.com/' . $reply . '/' . ($likes ? 'likes' : 'comments');
} else {
if ($link != "" or $image != "" or $b['title'] == '' or strlen($msg) < 500) {
$url = 'https://graph.facebook.com/me/feed';
if ($b['plink']) {
$postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}';
}
} else {
// if its only a message and a subject and the message is larger than 500 characters then post it as note
$postvars = array('access_token' => $fb_token, 'message' => bbcode($b['body']), 'subject' => $b['title']);
$url = 'https://graph.facebook.com/me/notes';
}
}
logger('facebook: post to ' . $url);
logger('facebook: postvars: ' . print_r($postvars, true));
// "test_mode" prevents anything from actually being posted.
// Otherwise, let's do it.
if (!get_config('facebook', 'test_mode')) {
$x = post_url($url, $postvars);
logger('Facebook post returns: ' . $x, LOGGER_DEBUG);
$retj = json_decode($x);
if ($retj->id) {
q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1", dbesc('fb::' . $retj->id), intval($b['id']));
} else {
if (!$likes) {
$s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars));
require_once 'include/queue_fn.php';
add_to_queue($a->contact, NETWORK_FACEBOOK, $s);
notice(t('Facebook post failed. Queued for retry.') . EOL);
}
if (isset($retj->error) && $retj->error->type == "OAuthException" && $retj->error->code == 190) {
logger('Facebook session has expired due to changed password.', LOGGER_DEBUG);
$last_notification = get_pconfig($b['uid'], 'facebook', 'session_expired_mailsent');
if (!$last_notification || $last_notification < time() - FACEBOOK_SESSION_ERR_NOTIFICATION_INTERVAL) {
require_once 'include/enotify.php';
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($b['uid']));
notification(array('uid' => $b['uid'], 'type' => NOTIFY_SYSTEM, 'system_type' => 'facebook_connection_invalid', 'language' => $r[0]['language'], 'to_name' => $r[0]['username'], 'to_email' => $r[0]['email'], 'source_name' => t('Administrator'), 'source_link' => $a->config["system"]["url"], 'source_photo' => $a->config["system"]["url"] . '/images/person-80.jpg'));
set_pconfig($b['uid'], 'facebook', 'session_expired_mailsent', time());
} else {
logger('Facebook: No notification, as the last one was sent on ' . $last_notification, LOGGER_DEBUG);
}
}
}
}
}
}
}
}