本文整理汇总了PHP中item_store函数的典型用法代码示例。如果您正苦于以下问题:PHP item_store函数的具体用法?PHP item_store怎么用?PHP item_store使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了item_store函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_shadow_entry
function add_shadow_entry($item)
{
// Is this a shadow entry?
if ($item['uid'] == 0) {
return;
}
// Is there a shadow parent?
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item['parent-uri']));
if (!count($r)) {
return;
}
// Is there already a shadow entry?
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item['uri']));
if (count($r)) {
return;
}
// Preparing public shadow (removing user specific data)
require_once "include/items.php";
require_once "include/Contact.php";
unset($item['id']);
$item['uid'] = 0;
$item['contact-id'] = get_contact($item['author-link'], 0);
$public_shadow = item_store($item, false, false, true);
logger("Stored public shadow for comment " . $item['uri'] . " under id " . $public_shadow, LOGGER_DEBUG);
}
示例2: get
function get()
{
if (!local_channel()) {
return;
}
$postid = $_REQUEST['postid'];
if (!$postid) {
return;
}
$emoji = $_REQUEST['emoji'];
if ($_REQUEST['emoji']) {
$i = q("select * from item where id = %d and uid = %d", intval($postid), intval(local_channel()));
if (!$i) {
return;
}
$channel = \App::get_channel();
$n = array();
$n['aid'] = $channel['channel_account_id'];
$n['uid'] = $channel['channel_id'];
$n['item_origin'] = true;
$n['parent'] = $postid;
$n['parent_mid'] = $i[0]['mid'];
$n['mid'] = item_message_id();
$n['verb'] = ACTIVITY_REACT . '#' . $emoji;
$n['body'] = "\n\n[zmg=32x32]" . z_root() . '/images/emoji/' . $emoji . '.png[/zmg]' . "\n\n";
$n['author_xchan'] = $channel['channel_hash'];
$x = item_store($n);
if ($x['success']) {
$nid = $x['item_id'];
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'like', $nid));
}
}
}
示例3: impel_init
function impel_init(&$a)
{
$ret = array('success' => false);
if (!local_channel()) {
json_return_and_die($ret);
}
logger('impel: ' . print_r($_REQUEST, true), LOGGER_DATA);
$elm = $_REQUEST['element'];
$x = base64url_decode($elm);
if (!$x) {
json_return_and_die($ret);
}
$j = json_decode($x, true);
if (!$j) {
json_return_and_die($ret);
}
$channel = $a->get_channel();
$arr = array();
switch ($j['type']) {
case 'webpage':
$arr['item_restrict'] = ITEM_WEBPAGE;
$namespace = 'WEBPAGE';
$installed_type = t('webpage');
break;
case 'block':
$arr['item_restrict'] = ITEM_BUILDBLOCK;
$namespace = 'BUILDBLOCK';
$installed_type = t('block');
break;
case 'layout':
$arr['item_restrict'] = ITEM_PDL;
$namespace = 'PDL';
$installed_type = t('layout');
break;
default:
logger('mod_impel: unrecognised element type' . print_r($j, true));
break;
}
$arr['uid'] = local_channel();
$arr['aid'] = $channel['channel_account_id'];
$arr['title'] = $j['title'];
$arr['body'] = $j['body'];
$arr['term'] = $j['term'];
$arr['created'] = datetime_convert('UTC', 'UTC', $j['created']);
$arr['edited'] = datetime_convert('UTC', 'UTC', $j['edited']);
$arr['owner_xchan'] = get_observer_hash();
$arr['author_xchan'] = $j['author_xchan'] ? $j['author_xchan'] : get_observer_hash();
$arr['mimetype'] = $j['mimetype'] ? $j['mimetype'] : 'text/bbcode';
if (!$j['mid']) {
$j['mid'] = item_message_id();
}
$arr['mid'] = $arr['parent_mid'] = $j['mid'];
if ($j['pagetitle']) {
require_once 'library/urlify/URLify.php';
$pagetitle = strtolower(URLify::transliterate($j['pagetitle']));
}
// Verify ability to use html or php!!!
$execflag = false;
if ($arr['mimetype'] === 'application/x-php') {
$z = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id where channel_id = %d limit 1", intval(local_channel()));
if ($z && ($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE || $z[0]['channel_pageflags'] & PAGE_ALLOWCODE)) {
$execflag = true;
}
}
$remote_id = 0;
$z = q("select * from item_id where sid = '%s' and service = '%s' and uid = %d limit 1", dbesc($pagetitle), dbesc($namespace), intval(local_channel()));
$i = q("select id from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel()));
if ($z && $i) {
$remote_id = $z[0]['id'];
$arr['id'] = $i[0]['id'];
// don't update if it has the same timestamp as the original
if ($arr['edited'] > $i[0]['edited']) {
$x = item_store_update($arr, $execflag);
}
} else {
$x = item_store($arr, $execflag);
}
if ($x['success']) {
$item_id = $x['item_id'];
}
update_remote_id($channel, $item_id, $arr['item_restrict'], $pagetitle, $namespace, $remote_id, $arr['mid']);
$ret['success'] = true;
info(sprintf(t('%s element installed'), $installed_type));
json_return_and_die(true);
}
示例4: randpost_fetch
function randpost_fetch(&$a, &$b)
{
$fort_server = get_config('fortunate', 'server');
if (!$fort_server) {
return;
}
$r = q("select * from pconfig where cat = 'randpost' and k = 'enable'");
if ($r) {
foreach ($r as $rr) {
if (!$rr['v']) {
continue;
}
// logger('randpost');
// cronhooks run every 10-15 minutes typically
// try to keep from posting frequently.
$test = mt_rand(0, 100);
if ($test == 25) {
$c = q("select * from channel where channel_id = %d limit 1", intval($rr['uid']));
if (!$c) {
continue;
}
$mention = '';
require_once 'include/html2bbcode.php';
$s = z_fetch_url('http://' . $fort_server . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand());
if (!$s['success']) {
continue;
}
$x = array();
$x['uid'] = $c[0]['channel_id'];
$x['aid'] = $c[0]['channel_account_id'];
$x['mid'] = $x['parent_mid'] = item_message_id();
$x['author_xchan'] = $x['owner_xchan'] = $c[0]['channel_hash'];
$x['item_thread_top'] = 1;
$x['item_origin'] = 1;
$x['item_verified'] = 1;
$x['item_wall'] = 1;
// if it might be a quote make it a quote
if (strpos($s['body'], '--')) {
$x['body'] = $mention . '[quote]' . html2bbcode($s['body']) . '[/quote]';
} else {
$x['body'] = $mention . html2bbcode($s['body']);
}
$x['sig'] = base64url_encode(rsa_sign($x['body'], $c[0]['channel_prvkey']));
$post = item_store($x);
$post_id = $post['item_id'];
$x['id'] = $post_id;
call_hooks('post_local_end', $x);
Zotlabs\Daemon\Master::Summon(array('Notifier', 'wall-new', $post_id));
}
}
}
}
示例5: delete_imported_item
/**
* @brief Deletes an imported item.
*
* @param array $sender
* * \e string \b hash a xchan_hash
* @param array $item
* @param int $uid
* @param boolean $relay
* @return boolean|int post_id
*/
function delete_imported_item($sender, $item, $uid, $relay)
{
logger('delete_imported_item invoked', LOGGER_DEBUG);
$ownership_valid = false;
$item_found = false;
$post_id = 0;
$r = q("select id, author_xchan, owner_xchan, source_xchan, item_deleted from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' )\n\t\tand mid = '%s' and uid = %d limit 1", dbesc($sender['hash']), dbesc($sender['hash']), dbesc($sender['hash']), dbesc($item['mid']), intval($uid));
if ($r) {
if ($r[0]['author_xchan'] === $sender['hash'] || $r[0]['owner_xchan'] === $sender['hash'] || $r[0]['source_xchan'] === $sender['hash']) {
$ownership_valid = true;
}
$post_id = $r[0]['id'];
$item_found = true;
} else {
// perhaps the item is still in transit and the delete notification got here before the actual item did. Store it with the deleted flag set.
// item_store() won't try to deliver any notifications or start delivery chains if this flag is set.
// This means we won't end up with potentially even more delivery threads trying to push this delete notification.
// But this will ensure that if the (undeleted) original post comes in at a later date, we'll reject it because it will have an older timestamp.
logger('delete received for non-existent item - storing item data.');
/** @BUG $arr is undefined here, so this is dead code */
if ($arr['author_xchan'] === $sender['hash'] || $arr['owner_xchan'] === $sender['hash'] || $arr['source_xchan'] === $sender['hash']) {
$ownership_valid = true;
$item_result = item_store($arr);
$post_id = $item_result['item_id'];
}
}
if ($ownership_valid === false) {
logger('delete_imported_item: failed: ownership issue');
return false;
}
require_once 'include/items.php';
if ($item_found) {
if (intval($r[0]['item_deleted'])) {
logger('delete_imported_item: item was already deleted');
if (!$relay) {
return false;
}
// This is a bit hackish, but may have to suffice until the notification/delivery loop is optimised
// a bit further. We're going to strip the ITEM_ORIGIN on this item if it's a comment, because
// it was already deleted, and we're already relaying, and this ensures that no other process or
// code path downstream can relay it again (causing a loop). Since it's already gone it's not coming
// back, and we aren't going to (or shouldn't at any rate) delete it again in the future - so losing
// this information from the metadata should have no other discernible impact.
if ($r[0]['id'] != $r[0]['parent'] && intval($r[0]['item_origin'])) {
q("update item set item_origin = 0 where id = %d and uid = %d", intval($r[0]['id']), intval($r[0]['uid']));
}
}
require_once 'include/items.php';
// Use phased deletion to set the deleted flag, call both tag_deliver and the notifier to notify downstream channels
// and then clean up after ourselves with a cron job after several days to do the delete_item_lowlevel() (DROPITEM_PHASE2).
drop_item($post_id, false, DROPITEM_PHASE1);
tag_deliver($uid, $post_id);
}
return $post_id;
}
示例6: consume_feed
//.........这里部分代码省略.........
$author = array();
$datarray = get_atom_elements($feed, $item, $author);
if (!x($author, 'author_name') || $author['author_is_feed']) {
$author['author_name'] = $contact['xchan_name'];
}
if (!x($author, 'author_link') || $author['author_is_feed']) {
$author['author_link'] = $contact['xchan_url'];
}
if (!x($author, 'author_photo') || $author['author_is_feed']) {
$author['author_photo'] = $contact['xchan_photo_m'];
}
$datarray['author_xchan'] = '';
if ($author['author_link'] != $contact['xchan_url']) {
$x = import_author_unknown(array('name' => $author['author_name'], 'url' => $author['author_link'], 'photo' => array('src' => $author['author_photo'])));
if ($x) {
$datarray['author_xchan'] = $x;
}
}
if (!$datarray['author_xchan']) {
$datarray['author_xchan'] = $contact['xchan_hash'];
}
$datarray['owner_xchan'] = $contact['xchan_hash'];
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($item_id), intval($importer['channel_id']));
// Update content if 'updated' changes
if ($r) {
if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
// do not accept (ignore) an earlier edit than one we currently have.
if (datetime_convert('UTC', 'UTC', $datarray['edited']) < $r[0]['edited']) {
continue;
}
update_feed_item($importer['channel_id'], $datarray);
}
continue;
}
$datarray['parent_mid'] = $parent_mid;
$datarray['uid'] = $importer['channel_id'];
logger('consume_feed: ' . print_r($datarray, true), LOGGER_DATA);
$xx = item_store($datarray);
$r = $xx['item_id'];
continue;
} else {
// Head post of a conversation. Have we seen it? If not, import it.
$item_id = base64url_encode($item->get_id());
$author = array();
$datarray = get_atom_elements($feed, $item, $author);
if (is_array($contact)) {
if (!x($author, 'author_name') || $author['author_is_feed']) {
$author['author_name'] = $contact['xchan_name'];
}
if (!x($author, 'author_link') || $author['author_is_feed']) {
$author['author_link'] = $contact['xchan_url'];
}
if (!x($author, 'author_photo') || $author['author_is_feed']) {
$author['author_photo'] = $contact['xchan_photo_m'];
}
}
if (!x($author, 'author_name') || !x($author, 'author_link')) {
logger('consume_feed: no author information! ' . print_r($author, true));
continue;
}
$datarray['author_xchan'] = '';
if ($author['author_link'] != $contact['xchan_url']) {
$x = import_author_unknown(array('name' => $author['author_name'], 'url' => $author['author_link'], 'photo' => array('src' => $author['author_photo'])));
if ($x) {
$datarray['author_xchan'] = $x;
}
}
if (!$datarray['author_xchan']) {
$datarray['author_xchan'] = $contact['xchan_hash'];
}
$datarray['owner_xchan'] = $contact['xchan_hash'];
$r = q("SELECT edited FROM item WHERE mid = '%s' AND uid = %d LIMIT 1", dbesc($item_id), intval($importer['channel_id']));
// Update content if 'updated' changes
if ($r) {
if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
// do not accept (ignore) an earlier edit than one we currently have.
if (datetime_convert('UTC', 'UTC', $datarray['edited']) < $r[0]['edited']) {
continue;
}
update_feed_item($importer['channel_id'], $datarray);
}
continue;
}
$datarray['parent_mid'] = $item_id;
$datarray['uid'] = $importer['channel_id'];
if (!link_compare($author['owner_link'], $contact['xchan_url'])) {
logger('consume_feed: Correcting item owner.', LOGGER_DEBUG);
$author['owner_name'] = $contact['name'];
$author['owner_link'] = $contact['url'];
$author['owner_avatar'] = $contact['thumb'];
}
logger('consume_feed: author ' . print_r($author, true), LOGGER_DEBUG);
logger('consume_feed: ' . print_r($datarray, true), LOGGER_DATA);
$xx = item_store($datarray);
$r = $xx['item_id'];
continue;
}
}
}
}
示例7: diaspora_like
//.........这里部分代码省略.........
logger('diaspora_like: received a like with positive set to "false"');
logger('diaspora_like: unlike received with no corresponding like...ignoring');
return;
}
/* How Diaspora performs "like" signature checking:
- If an item has been sent by the like author to the top-level post owner to relay on
to the rest of the contacts on the top-level post, the top-level post owner should check
the author_signature, then create a parent_author_signature before relaying the like on
- If an item has been relayed on by the top-level post owner, the contacts who receive it
check only the parent_author_signature. Basically, they trust that the top-level post
owner has already verified the authenticity of anything he/she sends out
- In either case, the signature that get checked is the signature created by the person
who sent the salmon
*/
// 2014-09-10 let's try this: signatures are failing. I'll try and make a signable string from
// the parameters in the order they were presented in the post. This is how D* creates the signable string.
$signed_data = $positive . ';' . $guid . ';' . $target_type . ';' . $parent_guid . ';' . $diaspora_handle;
$key = $msg['key'];
if ($parent_author_signature) {
// If a parent_author_signature exists, then we've received the like
// relayed from the top-level post owner. There's no need to check the
// author_signature if the parent_author_signature is valid
$parent_author_signature = base64_decode($parent_author_signature);
if (!rsa_verify($signed_data, $parent_author_signature, $key, 'sha256')) {
if (intval(get_config('system', 'ignore_diaspora_like_signature'))) {
logger('diaspora_like: top-level owner verification failed. Proceeding anyway.');
} else {
logger('diaspora_like: top-level owner verification failed.');
return;
}
}
} else {
// If there's no parent_author_signature, then we've received the like
// from the like creator. In that case, the person is "like"ing
// our post, so he/she must be a contact of ours and his/her public key
// should be in $msg['key']
$author_signature = base64_decode($author_signature);
if (!rsa_verify($signed_data, $author_signature, $key, 'sha256')) {
if (intval(get_config('system', 'ignore_diaspora_like_signature'))) {
logger('diaspora_like: like creator verification failed. Proceeding anyway');
} else {
logger('diaspora_like: like creator verification failed.');
return;
}
}
}
logger('diaspora_like: signature check complete.', LOGGER_DEBUG);
// Phew! Everything checks out. Now create an item.
// Find the original comment author information.
// We need this to make sure we display the comment author
// information (name and avatar) correctly.
if (strcasecmp($diaspora_handle, $msg['author']) == 0) {
$person = $contact;
} else {
$person = find_diaspora_person_by_handle($diaspora_handle);
if (!is_array($person)) {
logger('diaspora_like: unable to find author details');
return;
}
}
$uri = $diaspora_handle . ':' . $guid;
$activity = ACTIVITY_LIKE;
$post_type = $parent_item['resource_type'] === 'photo' ? t('photo') : t('status');
$links = array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $parent_item['plink']));
$objtype = $parent_item['resource_type'] === 'photo' ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE;
$body = $parent_item['body'];
$object = json_encode(array('type' => $post_type, 'id' => $parent_item['mid'], 'parent' => $parent_item['thr_parent'] ? $parent_item['thr_parent'] : $parent_item['parent_mid'], 'link' => $links, 'title' => $parent_item['title'], 'content' => $parent_item['body'], 'created' => $parent_item['created'], 'edited' => $parent_item['edited'], 'author' => array('name' => $item_author['xchan_name'], 'address' => $item_author['xchan_addr'], 'guid' => $item_author['xchan_guid'], 'guid_sig' => $item_author['xchan_guid_sig'], 'link' => array(array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item_author['xchan_url']), array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])))));
$bodyverb = t('%1$s likes %2$s\'s %3$s');
$arr = array();
$arr['uid'] = $importer['channel_id'];
$arr['aid'] = $importer['channel_account_id'];
$arr['mid'] = $guid;
$arr['parent_mid'] = $parent_item['mid'];
$arr['owner_xchan'] = $parent_item['owner_xchan'];
$arr['author_xchan'] = $person['xchan_hash'];
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$alink = '[url=' . $parent_item['author-link'] . ']' . $parent_item['author-name'] . '[/url]';
$plink = '[url=' . z_root() . '/display/' . $guid . ']' . $post_type . '[/url]';
$arr['body'] = sprintf($bodyverb, $ulink, $alink, $plink);
$arr['app'] = 'Diaspora';
$arr['item_private'] = $parent_item['item_private'];
$arr['verb'] = $activity;
$arr['object-type'] = $objtype;
$arr['object'] = $object;
if (!$parent_author_signature) {
$datarray['diaspora_meta'] = array('signer' => $diaspora_handle, 'body' => $text, 'signed_text' => $signed_data, 'signature' => base64_encode($author_signature));
}
$x = item_store($arr);
if ($x) {
$message_id = $x['item_id'];
}
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if ($parent_item['item_flags'] & ITEM_ORIGIN && !$parent_author_signature) {
proc_run('php', 'include/notifier.php', 'comment-import', $message_id);
}
return;
}
示例8: photos_post
//.........这里部分代码省略.........
}
/* Don't make the item visible if the only change was the album name */
$visibility = 0;
if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
$visibility = 1;
}
if (!$item_id) {
// Create item container
$title = '';
$uri = item_new_uri($a->get_hostname(), $page_owner_uid);
$arr = array();
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$arr['type'] = 'photo';
$arr['wall'] = 1;
$arr['resource-id'] = $p[0]['resource-id'];
$arr['contact-id'] = $owner_record['id'];
$arr['owner-name'] = $owner_record['name'];
$arr['owner-link'] = $owner_record['url'];
$arr['owner-avatar'] = $owner_record['thumb'];
$arr['author-name'] = $owner_record['name'];
$arr['author-link'] = $owner_record['url'];
$arr['author-avatar'] = $owner_record['thumb'];
$arr['title'] = $title;
$arr['allow_cid'] = $p[0]['allow_cid'];
$arr['allow_gid'] = $p[0]['allow_gid'];
$arr['deny_cid'] = $p[0]['deny_cid'];
$arr['deny_gid'] = $p[0]['deny_gid'];
$arr['last-child'] = 1;
$arr['visible'] = $visibility;
$arr['origin'] = 1;
$arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]' . '[/url]';
$item_id = item_store($arr);
}
if ($item_id) {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($page_owner_uid));
}
if (count($r)) {
$old_tag = $r[0]['tag'];
$old_inform = $r[0]['inform'];
}
if (strlen($rawtags)) {
$str_tags = '';
$inform = '';
// if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
$x = substr($rawtags, 0, 1);
if ($x !== '@' && $x !== '#') {
$rawtags = '#' . $rawtags;
}
$taginfo = array();
$tags = get_tags($rawtags);
if (count($tags)) {
foreach ($tags as $tag) {
if (isset($profile)) {
unset($profile);
}
if (strpos($tag, '@') === 0) {
$name = substr($tag, 1);
if (strpos($name, '@') || strpos($name, 'http://')) {
$newname = $name;
$links = @lrdd($name);
if (count($links)) {
foreach ($links as $link) {
if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
$profile = $link['@attributes']['href'];
示例9: import_items
function import_items($channel, $items)
{
if ($channel && $items) {
$allow_code = false;
$r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id \n\t\t\twhere channel_id = %d limit 1", intval($channel['channel_id']));
if ($r) {
if ($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE || $r[0]['channel_pageflags'] & PAGE_ALLOWCODE) {
$allow_code = true;
}
}
foreach ($items as $i) {
$item = get_item_elements($i, $allow_code);
if (!$item) {
continue;
}
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", dbesc($item['mid']), intval($channel['channel_id']));
if ($r) {
if ($item['edited'] > $r[0]['edited']) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
item_store_update($item);
continue;
}
} else {
$item['aid'] = $channel['channel_account_id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item);
}
}
}
}
示例10: pumpio_dopost
//.........这里部分代码省略.........
// Take an existing contact, the contact of the note or - as a fallback - the id of the user
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", dbesc($post->actor->url), intval($uid));
if (count($r)) {
$contact_id = $r[0]['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", dbesc($post->actor->url), intval($uid));
if (count($r)) {
$contact_id = $r[0]['id'];
} else {
$contact_id = $self[0]['id'];
}
}
}
$reply = new stdClass();
$reply->verb = "note";
$reply->cc = $post->cc;
$reply->to = $post->to;
$reply->object = new stdClass();
$reply->object->objectType = $post->object->inReplyTo->objectType;
$reply->object->content = $post->object->inReplyTo->content;
$reply->object->id = $post->object->inReplyTo->id;
$reply->actor = $post->object->inReplyTo->author;
$reply->url = $post->object->inReplyTo->url;
$reply->generator = new stdClass();
$reply->generator->displayName = "pumpio";
$reply->published = $post->object->inReplyTo->published;
$reply->received = $post->object->inReplyTo->updated;
$reply->url = $post->object->inReplyTo->url;
pumpio_dopost($a, $client, $uid, $self, $reply, $own_id, false);
$postarray['parent-uri'] = $post->object->inReplyTo->id;
}
if ($post->object->pump_io->proxyURL) {
$postarray['extid'] = $post->object->pump_io->proxyURL;
}
$postarray['contact-id'] = $contact_id;
$postarray['verb'] = ACTIVITY_POST;
$postarray['owner-name'] = $post->actor->displayName;
$postarray['owner-link'] = $post->actor->url;
$postarray['owner-avatar'] = $post->actor->image->url;
$postarray['author-name'] = $post->actor->displayName;
$postarray['author-link'] = $post->actor->url;
$postarray['author-avatar'] = $post->actor->image->url;
$postarray['plink'] = $post->object->url;
$postarray['app'] = $post->generator->displayName;
$postarray['body'] = html2bbcode($post->object->content);
if ($post->object->fullImage->url != "") {
$postarray["body"] = "[url=" . $post->object->fullImage->url . "][img]" . $post->object->image->url . "[/img][/url]\n" . $postarray["body"];
}
if ($post->object->displayName != "") {
$postarray['title'] = $post->object->displayName;
}
$postarray['created'] = datetime_convert('UTC', 'UTC', $post->published);
$postarray['edited'] = datetime_convert('UTC', 'UTC', $post->received);
if ($post->verb == "share") {
if (!intval(get_config('system', 'wall-to-wall_share'))) {
$postarray['body'] = "[share author='" . $post->object->author->displayName . "' profile='" . $post->object->author->url . "' avatar='" . $post->object->author->image->url . "' posted='" . datetime_convert('UTC', 'UTC', $post->object->created) . "' link='" . $post->links->self->href . "']" . $postarray['body'] . "[/share]";
} else {
// Let shares look like wall-to-wall posts
$postarray['author-name'] = $post->object->author->displayName;
$postarray['author-link'] = $post->object->author->url;
$postarray['author-avatar'] = $post->object->author->image->url;
}
}
if (trim($postarray['body']) == "") {
return false;
}
$top_item = item_store($postarray);
$postarray["id"] = $top_item;
if ($top_item == 0 and $post->verb == "update") {
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s' , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", dbesc($postarray["title"]), dbesc($postarray["body"]), dbesc($postarray["edited"]), dbesc($postarray["uri"]), intval($uid));
}
if ($post->object->objectType == "comment") {
if ($threadcompletion) {
pumpio_fetchallcomments($a, $uid, $postarray['parent-uri']);
}
$user = q("SELECT * FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1", intval($uid));
if (!count($user)) {
return $top_item;
}
$importer_url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
if (link_compare($own_id, $postarray['author-link'])) {
return $top_item;
}
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", dbesc($postarray['parent-uri']), intval($uid));
if (count($myconv)) {
foreach ($myconv as $conv) {
// now if we find a match, it means we're in this conversation
if (!link_compare($conv['author-link'], $importer_url) and !link_compare($conv['author-link'], $own_id)) {
continue;
}
require_once 'include/enotify.php';
$conv_parent = $conv['parent'];
notification(array('type' => NOTIFY_COMMENT, 'notify_flags' => $user[0]['notify-flags'], 'language' => $user[0]['language'], 'to_name' => $user[0]['username'], 'to_email' => $user[0]['email'], 'uid' => $user[0]['uid'], 'item' => $postarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($top_item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $conv_parent));
// only send one notification
break;
}
}
}
return $top_item;
}
示例11: profile_activity
/** @file */
function profile_activity($changed, $value)
{
$a = get_app();
if (!local_channel() || !is_array($changed) || !count($changed)) {
return;
}
if (!get_pconfig(local_channel(), 'system', 'post_profilechange')) {
return;
}
require_once 'include/items.php';
$self = $a->get_channel();
if (!count($self)) {
return;
}
$arr = array();
$arr['mid'] = $arr['parent_mid'] = item_message_id();
$arr['uid'] = local_channel();
$arr['aid'] = $self['channel_account_id'];
$arr['owner_xchan'] = $arr['author_xchan'] = $self['xchan_hash'];
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['verb'] = ACTIVITY_UPDATE;
$arr['obj_type'] = ACTIVITY_OBJ_PROFILE;
$arr['plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . $arr['mid'];
$A = '[url=' . z_root() . '/channel/' . $self['channel_address'] . ']' . $self['channel_name'] . '[/url]';
$changes = '';
$t = count($changed);
$z = 0;
foreach ($changed as $ch) {
if (strlen($changes)) {
if ($z == $t - 1) {
$changes .= t(' and ');
} else {
$changes .= ', ';
}
}
$z++;
$changes .= $ch;
}
$prof = '[url=' . z_root() . '/profile/' . $self['channel_address'] . ']' . t('public profile') . '[/url]';
if ($t == 1 && strlen($value)) {
// if it's a url, the HTML quotes will mess it up, so link it and don't try and zidify it because we don't know what it points to.
$value = preg_replace_callback("/([^\\]\\='" . '"' . "]|^|\\#\\^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\@\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", 'red_zrl_callback', $value);
// take out the bookmark indicator
if (substr($value, 0, 2) === '#^') {
$value = str_replace('#^', '', $value);
}
$message = sprintf(t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
$message .= "\n\n" . sprintf(t('Visit %1$s\'s %2$s'), $A, $prof);
} else {
$message = sprintf(t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
}
$arr['body'] = $message;
$links = array();
$links[] = array('rel' => 'alternate', 'type' => 'text/html', 'href' => z_root() . '/profile/' . $self['channel_address']);
$links[] = array('rel' => 'photo', 'type' => $self['xchan_photo_mimetype'], 'href' => $self['xchan_photo_l']);
$arr['object'] = json_encode(array('type' => ACTIVITY_OBJ_PROFILE, 'title' => $self['channel_name'], 'id' => $self['xchan_url'] . '/' . $self['xchan_hash'], 'link' => $links));
$arr['allow_cid'] = $self['channel_allow_cid'];
$arr['allow_gid'] = $self['channel_allow_gid'];
$arr['deny_cid'] = $self['channel_deny_cid'];
$arr['deny_gid'] = $self['channel_deny_gid'];
$res = item_store($arr);
$i = $res['item_id'];
if ($i) {
// FIXME - limit delivery in notifier.php to those specificed in the perms argument
proc_run('php', "include/notifier.php", "activity", "{$i}", 'PERMS_R_PROFILE');
}
}
示例12: diaspora_like
//.........这里部分代码省略.........
if ($positive === 'false') {
q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($r[0]['id']), intval($importer['uid']));
// FIXME
// send notification via proc_run()
return;
}
}
if ($positive === 'false') {
logger('diaspora_like: unlike received with no corresponding like');
return;
}
$author_signed_data = $guid . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $diaspora_handle;
$author_signature = base64_decode($author_signature);
if (strcasecmp($diaspora_handle, $msg['author']) == 0) {
$person = $contact;
$key = $msg['key'];
} else {
$person = find_diaspora_person_by_handle($diaspora_handle);
if (is_array($person) && x($person, 'pubkey')) {
$key = $person['pubkey'];
} else {
logger('diaspora_like: unable to find author details');
return;
}
}
if (!rsa_verify($author_signed_data, $author_signature, $key, 'sha256')) {
logger('diaspora_like: verification failed.');
return;
}
if ($parent_author_signature) {
$owner_signed_data = $guid . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $diaspora_handle;
$parent_author_signature = base64_decode($parent_author_signature);
$key = $msg['key'];
if (!rsa_verify($owner_signed_data, $parent_author_signature, $key, 'sha256')) {
logger('diaspora_like: owner verification failed.');
return;
}
}
// Phew! Everything checks out. Now create an item.
$uri = $diaspora_handle . ':' . $guid;
$activity = ACTIVITY_LIKE;
$post_type = $parent_item['resource-id'] ? t('photo') : t('status');
$objtype = $parent_item['resource-id'] ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE;
$link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . '" />' . "\n");
$body = $parent_item['body'];
$obj = <<<EOT
\t<object>
\t\t<type>{$objtype}</type>
\t\t<local>1</local>
\t\t<id>{$parent_item['uri']}</id>
\t\t<link>{$link}</link>
\t\t<title></title>
\t\t<content>{$body}</content>
\t</object>
EOT;
$bodyverb = t('%1$s likes %2$s\'s %3$s');
$arr = array();
$arr['uri'] = $uri;
$arr['uid'] = $importer['uid'];
$arr['guid'] = $guid;
$arr['contact-id'] = $contact['id'];
$arr['type'] = 'activity';
$arr['wall'] = $parent_item['wall'];
$arr['gravity'] = GRAVITY_LIKE;
$arr['parent'] = $parent_item['id'];
$arr['parent-uri'] = $parent_item['uri'];
$arr['owner-name'] = $parent_item['name'];
$arr['owner-link'] = $parent_item['url'];
$arr['owner-avatar'] = $parent_item['thumb'];
$arr['author-name'] = $person['name'];
$arr['author-link'] = $person['url'];
$arr['author-avatar'] = x($person, 'thumb') ? $person['thumb'] : $person['photo'];
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$alink = '[url=' . $parent_item['author-link'] . ']' . $parent_item['author-name'] . '[/url]';
$plink = '[url=' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . ']' . $post_type . '[/url]';
$arr['body'] = sprintf($bodyverb, $ulink, $alink, $plink);
$arr['app'] = 'Diaspora';
$arr['private'] = $parent_item['private'];
$arr['verb'] = $activity;
$arr['object-type'] = $objtype;
$arr['object'] = $obj;
$arr['visible'] = 1;
$arr['unseen'] = 1;
$arr['last-child'] = 0;
$message_id = item_store($arr);
if ($message_id) {
q("update item set plink = '%s' where id = %d limit 1", dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), intval($message_id));
}
if (!$parent_author_signature) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($message_id), dbesc($author_signed_data), dbesc(base64_encode($author_signature)), dbesc($diaspora_handle));
}
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if ($parent_item['origin'] && !$parent_author_signature) {
proc_run('php', 'include/notifier.php', 'comment', $message_id);
}
return;
}
示例13: ostatus_completion
function ostatus_completion($conversation_url, $uid, $item = array())
{
$a = get_app();
$item_stored = -1;
$conversation_url = ostatus_convert_href($conversation_url);
// If the thread shouldn't be completed then store the item and go away
if (intval(get_config('system', 'ostatus_poll_interval')) == -2 and count($item) > 0) {
//$arr["app"] .= " (OStatus-NoCompletion)";
$item_stored = item_store($item, true);
return $item_stored;
}
// Get the parent
$parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN\n\t\t\t(SELECT `parent` FROM `item` WHERE `id` IN\n\t\t\t\t(SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url));
if ($parents) {
$parent = $parents[0];
} elseif (count($item) > 0) {
$parent = $item;
$parent["type"] = "remote";
$parent["verb"] = ACTIVITY_POST;
$parent["visible"] = 1;
} else {
// Preset the parent
$r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid);
if (!$r) {
return -2;
}
$parent = array();
$parent["id"] = 0;
$parent["parent"] = 0;
$parent["uri"] = "";
$parent["contact-id"] = $r[0]["id"];
$parent["type"] = "remote";
$parent["verb"] = ACTIVITY_POST;
$parent["visible"] = 1;
}
$conv = str_replace("/conversation/", "/api/statusnet/conversation/", $conversation_url) . ".as";
$pageno = 1;
$items = array();
logger('fetching conversation url ' . $conv . ' for user ' . $uid);
do {
$conv_arr = z_fetch_url($conv . "?page=" . $pageno);
// If it is a non-ssl site and there is an error, then try ssl or vice versa
if (!$conv_arr["success"] and substr($conv, 0, 7) == "http://") {
$conv = str_replace("http://", "https://", $conv);
$conv_as = fetch_url($conv . "?page=" . $pageno);
} elseif (!$conv_arr["success"] and substr($conv, 0, 8) == "https://") {
$conv = str_replace("https://", "http://", $conv);
$conv_as = fetch_url($conv . "?page=" . $pageno);
} else {
$conv_as = $conv_arr["body"];
}
$conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as);
$conv_as = json_decode($conv_as);
if (@is_array($conv_as->items)) {
$items = array_merge($items, $conv_as->items);
} else {
break;
}
$pageno++;
} while (true);
logger('fetching conversation done. Found ' . count($items) . ' items');
if (!sizeof($items)) {
if (count($item) > 0) {
//$arr["app"] .= " (OStatus-NoConvFetched)";
$item_stored = item_store($item, true);
if ($item_stored) {
logger("Conversation " . $conversation_url . " couldn't be fetched. Item uri " . $item["uri"] . " stored: " . $item_stored, LOGGER_DEBUG);
ostatus_store_conversation($item_id, $conversation_url);
}
return $item_stored;
} else {
return -3;
}
}
$items = array_reverse($items);
$r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
$importer = $r[0];
foreach ($items as $single_conv) {
// Test - remove before flight
//$tempfile = tempnam(get_temppath(), "conversation");
//file_put_contents($tempfile, json_encode($single_conv));
$mention = false;
if (isset($single_conv->object->id)) {
$single_conv->id = $single_conv->object->id;
}
$plink = ostatus_convert_href($single_conv->id);
if (isset($single_conv->object->url)) {
$plink = ostatus_convert_href($single_conv->object->url);
}
if (@(!$single_conv->id)) {
continue;
}
logger("Got id " . $single_conv->id, LOGGER_DEBUG);
if ($first_id == "") {
$first_id = $single_conv->id;
// The first post of the conversation isn't our first post. There are three options:
// 1. Our conversation hasn't the "real" thread starter
// 2. This first post is a post inside our thread
// 3. This first post is a post inside another thread
if ($first_id != $parent["uri"] and $parent["uri"] != "") {
//.........这里部分代码省略.........
示例14: import_items
function import_items($channel, $items, $sync = false, $relocate = null)
{
if ($channel && $items) {
$allow_code = false;
$r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id \n\t\t\twhere channel_id = %d limit 1", intval($channel['channel_id']));
if ($r) {
if ($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE || $r[0]['channel_pageflags'] & PAGE_ALLOWCODE) {
$allow_code = true;
}
}
$deliver = false;
// Don't deliver any messages or notifications when importing
foreach ($items as $i) {
$item_result = false;
$item = get_item_elements($i, $allow_code);
if (!$item) {
continue;
}
if ($relocate && $item['mid'] === $item['parent_mid']) {
item_url_replace($channel, $item, $relocate['url'], z_root(), $relocate['channel_address']);
}
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", dbesc($item['mid']), intval($channel['channel_id']));
if ($r) {
// flags may have changed and we are probably relocating the post,
// so force an update even if we have the same timestamp
if ($item['edited'] >= $r[0]['edited']) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store_update($item, $allow_code, $deliver);
}
} else {
$item['aid'] = $channel['channel_account_id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item, $allow_code, $deliver);
}
if ($sync && $item['item_wall']) {
// deliver singletons if we have any
if ($item_result && $item_result['success']) {
Zotlabs\Daemon\Master::Summon(['Notifier', 'single_activity', $item_result['item_id']]);
}
}
}
}
}
示例15: subthread_content
//.........这里部分代码省略.........
}
$item = $r[0];
$owner_uid = $item['uid'];
if (!can_write_wall($a, $owner_uid)) {
return;
}
$remote_owner = null;
if (!$item['wall']) {
// The top level post may have been written by somebody on another system
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item['contact-id']), intval($item['uid']));
if (!count($r)) {
return;
}
if (!$r[0]['self']) {
$remote_owner = $r[0];
}
}
// this represents the post owner on this system.
$r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`\n\t\tWHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1", intval($owner_uid));
if (count($r)) {
$owner = $r[0];
}
if (!$owner) {
logger('like: no owner');
return;
}
if (!$remote_owner) {
$remote_owner = $owner;
}
// This represents the person posting
if (local_user() && local_user() == $owner_uid) {
$contact = $owner;
} else {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_SESSION['visitor_id']), intval($owner_uid));
if (count($r)) {
$contact = $r[0];
}
}
if (!$contact) {
return;
}
$uri = item_new_uri($a->get_hostname(), $owner_uid);
$post_type = $item['resource-id'] ? t('photo') : t('status');
$objtype = $item['resource-id'] ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE;
$link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
$body = $item['body'];
$obj = <<<EOT
\t<object>
\t\t<type>{$objtype}</type>
\t\t<local>1</local>
\t\t<id>{$item['uri']}</id>
\t\t<link>{$link}</link>
\t\t<title></title>
\t\t<content>{$body}</content>
\t</object>
EOT;
$bodyverb = t('%1$s is following %2$s\'s %3$s');
if (!isset($bodyverb)) {
return;
}
$arr = array();
$arr['uri'] = $uri;
$arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id'];
$arr['type'] = 'activity';
$arr['wall'] = $item['wall'];
$arr['origin'] = 1;
$arr['gravity'] = GRAVITY_LIKE;
$arr['parent'] = $item['id'];
$arr['parent-uri'] = $item['uri'];
$arr['thr-parent'] = $item['uri'];
$arr['owner-name'] = $remote_owner['name'];
$arr['owner-link'] = $remote_owner['url'];
$arr['owner-avatar'] = $remote_owner['thumb'];
$arr['author-name'] = $contact['name'];
$arr['author-link'] = $contact['url'];
$arr['author-avatar'] = $contact['thumb'];
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
$plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
$arr['body'] = sprintf($bodyverb, $ulink, $alink, $plink);
$arr['verb'] = $activity;
$arr['object-type'] = $objtype;
$arr['object'] = $obj;
$arr['allow_cid'] = $item['allow_cid'];
$arr['allow_gid'] = $item['allow_gid'];
$arr['deny_cid'] = $item['deny_cid'];
$arr['deny_gid'] = $item['deny_gid'];
$arr['visible'] = 1;
$arr['unseen'] = 1;
$arr['last-child'] = 0;
$post_id = item_store($arr);
if (!$item['visible']) {
$r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item['id']), intval($owner_uid));
}
$arr['id'] = $post_id;
call_hooks('post_local_end', $arr);
killme();
}