本文整理汇总了PHP中item_store_update函数的典型用法代码示例。如果您正苦于以下问题:PHP item_store_update函数的具体用法?PHP item_store_update怎么用?PHP item_store_update使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了item_store_update函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
function get()
{
if (!local_channel()) {
goaway(z_root() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
// remove tag on the fly if item and tag are provided
if (argc() == 4 && argv(1) === 'drop' && intval(argv(2))) {
$item = intval(argv(2));
$tag = argv(3);
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval(local_channel()));
if (!$r) {
goaway(z_root() . '/' . $_SESSION['photo_return']);
}
$r = fetch_post_tags($r, true);
$item = $r[0];
$new_tags = array();
if ($item['term']) {
for ($x = 0; $x < count($item['term']); $x++) {
if ($item['term'][$x]['term'] !== hex2bin($tag)) {
$new_tags[] = $item['term'][$x];
}
}
}
if ($new_tags) {
$item['term'] = $new_tags;
} else {
unset($item['term']);
}
item_store_update($item);
info(t('Tag removed') . EOL);
goaway(z_root() . '/' . $_SESSION['photo_return']);
}
//if we got only the item print a list of tags to select
if (argc() == 3 && argv(1) === 'drop' && intval(argv(2))) {
$o = '';
$item = intval(argv(2));
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval(local_channel()));
if (!$r) {
goaway(z_root() . '/' . $_SESSION['photo_return']);
}
$r = fetch_post_tags($r, true);
if (!count($r[0]['term'])) {
goaway(z_root() . '/' . $_SESSION['photo_return']);
}
$o .= '<h3>' . t('Remove Item Tag') . '</h3>';
$o .= '<p id="tag-remove-desc">' . t('Select a tag to remove: ') . '</p>';
$o .= '<form id="tagrm" action="tagrm" method="post" >';
$o .= '<input type="hidden" name="item" value="' . $item . '" />';
$o .= '<ul>';
foreach ($r[0]['term'] as $x) {
$o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x['term']) . '" >' . bbcode($x['term']) . '</input></li>';
}
$o .= '</ul>';
$o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . t('Remove') . '" />';
$o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . t('Cancel') . '" />';
$o .= '</form>';
return $o;
}
}
示例2: 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']]);
}
}
}
}
}
示例3: update_imported_item
/**
* @brief Just calls item_store_update() and logs result.
*
* @see item_store_update()
* @param array $sender (unused)
* @param array $item
* @param int $uid (unused)
*/
function update_imported_item($sender, $item, $orig, $uid)
{
// If this is a comment being updated, remove any privacy information
// so that item_store_update will set it from the original.
if ($item['mid'] !== $item['parent_mid']) {
unset($item['allow_cid']);
unset($item['allow_gid']);
unset($item['deny_cid']);
unset($item['deny_gid']);
unset($item['item_private']);
}
$x = item_store_update($item);
// If we're updating an event that we've saved locally, we store the item info first
// because event_addtocal will parse the body to get the 'new' event details
if ($orig['resource_type'] === 'event') {
$res = event_addtocal($orig['id'], $uid);
if (!$res) {
logger('update event: failed');
}
}
if (!$x['item_id']) {
logger('update_imported_item: failed: ' . $x['message']);
} else {
logger('update_imported_item');
}
}
示例4: 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);
}
示例5: store_doc_file
function store_doc_file($s)
{
if (is_dir($s)) {
return;
}
$item = array();
$sys = get_sys_channel();
$item['aid'] = 0;
$item['uid'] = $sys['channel_id'];
if (strpos($s, '.md')) {
$mimetype = 'text/markdown';
} elseif (strpos($s, '.html')) {
$mimetype = 'text/html';
} else {
$mimetype = 'text/bbcode';
}
require_once 'include/html2plain.php';
$item['body'] = html2plain(prepare_text(file_get_contents($s), $mimetype, true));
$item['mimetype'] = 'text/plain';
$item['plink'] = z_root() . '/' . str_replace('doc', 'help', $s);
$item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash'];
$item['item_type'] = ITEM_TYPE_DOC;
$r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and\n\t\tsid = '%s' and item_type = %d limit 1", dbesc($s), intval(ITEM_TYPE_DOC));
if ($r) {
$item['id'] = $r[0]['id'];
$item['mid'] = $item['parent_mid'] = $r[0]['mid'];
$x = item_store_update($item);
} else {
$item['mid'] = $item['parent_mid'] = item_message_id();
$x = item_store($item);
}
if ($x['success']) {
update_remote_id($sys, $x['item_id'], ITEM_TYPE_DOC, $s, 'docfile', 0, $item['mid']);
}
}
示例6: update_imported_item
/**
* @brief Just calls item_store_update() and logs result.
*
* @see item_store_update()
* @param array $sender (unused)
* @param array $item
* @param int $uid (unused)
*/
function update_imported_item($sender, $item, $uid)
{
$x = item_store_update($item);
if (!$x['item_id']) {
logger('update_imported_item: failed: ' . $x['message']);
} else {
logger('update_imported_item');
}
}
示例7: impel_init
//.........这里部分代码省略.........
if ($j['edited']) {
$m['menu_edited'] = datetime_convert($j['edited']);
}
$m['menu_flags'] = 0;
if ($j['flags']) {
if (in_array('bookmark', $j['flags'])) {
$m['menu_flags'] |= MENU_BOOKMARK;
}
if (in_array('system', $j['flags'])) {
$m['menu_flags'] |= MENU_SYSTEM;
}
}
$menu_id = menu_create($m);
if ($menu_id) {
if (is_array($j['items'])) {
foreach ($j['items'] as $it) {
$mitem = array();
$mitem['mitem_link'] = str_replace('[baseurl]', z_root(), $it['link']);
$mitem['mitem_desc'] = escape_tags($it['desc']);
$mitem['mitem_order'] = intval($it['order']);
if (is_array($it['flags'])) {
$mitem['mitem_flags'] = 0;
if (in_array('zid', $it['flags'])) {
$mitem['mitem_flags'] |= MENU_ITEM_ZID;
}
if (in_array('new-window', $it['flags'])) {
$mitem['mitem_flags'] |= MENU_ITEM_NEWWIN;
}
if (in_array('chatroom', $it['flags'])) {
$mitem['mitem_flags'] |= MENU_ITEM_CHATROOM;
}
}
menu_add_item($menu_id, local_channel(), $mitem);
}
if ($j['edited']) {
$x = q("update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", dbesc(datetime_convert('UTC', 'UTC', $j['edited'])), intval($menu_id), intval(local_channel()));
}
}
$ret['success'] = true;
}
$x = $ret;
} else {
$arr['uid'] = local_channel();
$arr['aid'] = $channel['channel_account_id'];
$arr['title'] = $j['title'];
$arr['body'] = $j['body'];
$arr['term'] = $j['term'];
$arr['layout_mid'] = $j['layout_mid'];
$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, edited, item_deleted 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 {
if ($i && intval($i[0]['item_deleted'])) {
// was partially deleted already, finish it off
q("delete from item where mid = '%s' and uid = %d", dbesc($arr['mid']), intval(local_channel()));
}
$x = item_store($arr, $execflag);
}
if ($x['success']) {
$item_id = $x['item_id'];
update_remote_id($channel, $item_id, $arr['item_type'], $pagetitle, $namespace, $remote_id, $arr['mid']);
}
}
if ($x['success']) {
$ret['success'] = true;
info(sprintf(t('%s element installed'), $installed_type));
} else {
notice(sprintf(t('%s element installation failed'), $installed_type));
}
//??? should perhaps return ret?
json_return_and_die(true);
}
示例8: item_post
//.........这里部分代码省略.........
if ($return_path) {
goaway($a->get_baseurl() . "/" . $return_path);
}
$json = array('cancel' => 1);
if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) {
$json['reload'] = $a->get_baseurl() . '/' . $_REQUEST['jsreload'];
}
echo json_encode($json);
killme();
}
if (mb_strlen($datarray['title']) > 255) {
$datarray['title'] = mb_substr($datarray['title'], 0, 255);
}
if (array_key_exists('item_private', $datarray) && $datarray['item_private']) {
$datarray['body'] = trim(z_input_filter($datarray['uid'], $datarray['body'], $datarray['mimetype']));
if ($uid) {
if ($channel['channel_hash'] === $datarray['author_xchan']) {
$datarray['sig'] = base64url_encode(rsa_sign($datarray['body'], $channel['channel_prvkey']));
$datarray['item_flags'] = $datarray['item_flags'] | ITEM_VERIFIED;
}
}
logger('Encrypting local storage');
$key = get_config('system', 'pubkey');
$datarray['item_flags'] = $datarray['item_flags'] | ITEM_OBSCURED;
if ($datarray['title']) {
$datarray['title'] = json_encode(crypto_encapsulate($datarray['title'], $key));
}
if ($datarray['body']) {
$datarray['body'] = json_encode(crypto_encapsulate($datarray['body'], $key));
}
}
if ($orig_post) {
$datarray['id'] = $post_id;
item_store_update($datarray, $execflag);
update_remote_id($channel, $post_id, $webpage, $pagetitle, $namespace, $remote_id, $mid);
if (!$nopush) {
proc_run('php', "include/notifier.php", 'edit_post', $post_id);
}
if (x($_REQUEST, 'return') && strlen($return_path)) {
logger('return: ' . $return_path);
goaway($a->get_baseurl() . "/" . $return_path);
}
killme();
} else {
$post_id = 0;
}
$post = item_store($datarray, $execflag);
$post_id = $post['item_id'];
if ($post_id) {
logger('mod_item: saved item ' . $post_id);
if ($parent) {
// only send comment notification if this is a wall-to-wall comment,
// otherwise it will happen during delivery
if ($datarray['owner_xchan'] != $datarray['author_xchan'] && $parent_item['item_flags'] & ITEM_WALL) {
notification(array('type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . $datarray['mid'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $parent, 'parent_mid' => $parent_item['mid']));
}
} else {
$parent = $post_id;
if ($datarray['owner_xchan'] != $datarray['author_xchan']) {
notification(array('type' => NOTIFY_WALL, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . $datarray['mid'], 'verb' => ACTIVITY_POST, 'otype' => 'item'));
}
if ($uid && $uid == $profile_uid && !$datarray['item_restrict']) {
q("update channel set channel_lastpost = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($uid));
}
}
// photo comments turn the corresponding item visible to the profile wall
示例9: photos_post
//.........这里部分代码省略.........
$height = $ph->getHeight();
$x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 1 limit 1", dbesc($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
}
if ($width > 320 || $height > 320) {
$ph->scaleImage(320);
$width = $ph->getWidth();
$height = $ph->getHeight();
$x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 2 limit 1", dbesc($ph->imageString()), intval($height), intval($width), dbesc($resource_id), intval($page_owner_uid));
}
}
}
}
$p = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `uid` = %d and ( photo_flags = %d or photo_flags = %d ) ORDER BY `scale` DESC", dbesc($resource_id), intval($page_owner_uid), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE));
if (count($p)) {
$ext = $phototypes[$p[0]['type']];
$r = q("UPDATE `photo` SET `description` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", dbesc($desc), dbesc($albname), dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), dbesc($resource_id), intval($page_owner_uid));
}
$item_private = $str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny ? true : false;
/* Don't make the item visible if the only change was the album name */
$visibility = 0;
if ($p[0]['description'] !== $desc || strlen($rawtags)) {
$visibility = 1;
}
if (!$item_id) {
$item_id = photos_create_item($a->data['channel'], get_observer_hash(), $p[0], $visibility);
}
if ($item_id) {
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($page_owner_uid));
}
if ($r) {
$old_tag = $r[0]['tag'];
$old_inform = $r[0]['inform'];
}
// make sure the linked item has the same permissions as the photo regardless of any other changes
$x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d\n\t\t\twhere id = %d limit 1", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($item_private), intval($item_id));
if (strlen($rawtags)) {
$str_tags = '';
$inform = '';
// if the new tag doesn't have a namespace specifier (@foo or #foo) give it a mention
$x = substr($rawtags, 0, 1);
if ($x !== '@' && $x !== '#') {
$rawtags = '@' . $rawtags;
}
$taginfo = array();
$tags = get_tags($rawtags);
if (count($tags)) {
foreach ($tags as $tag) {
// If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
// Robert Johnson should be first in the $tags array
$fullnametagged = false;
for ($x = 0; $x < count($tagged); $x++) {
if (stristr($tagged[$x], $tag . ' ')) {
$fullnametagged = true;
break;
}
}
if ($fullnametagged) {
continue;
}
require_once 'mod/item.php';
$body = $access_tag = '';
$success = handle_tag($a, $body, $access_tag, $str_tags, local_user() ? local_user() : $a->profile['profile_uid'], $tag);
logger('handle_tag: ' . print_r($success, tue), LOGGER_DEBUG);
if ($access_tag) {
logger('access_tag: ' . $tag . ' ' . print_r($access_tag, true), LOGGER_DEBUG);
if (strpos($access_tag, 'cid:') === 0) {
$str_contact_allow .= '<' . substr($access_tag, 4) . '>';
$access_tag = '';
} elseif (strpos($access_tag, 'gid:') === 0) {
$str_group_allow .= '<' . substr($access_tag, 4) . '>';
$access_tag = '';
}
}
if ($success['replaced']) {
$tagged[] = $tag;
$post_tags[] = array('uid' => $a->profile['profile_uid'], 'type' => $success['termtype'], 'otype' => TERM_OBJ_POST, 'term' => $success['term'], 'url' => $success['url']);
}
}
}
$r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($page_owner_uid));
if ($r) {
$datarray = $r[0];
$datarray['term'] = $post_tags;
item_store_update($datarray, $execflag);
}
}
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
return;
// NOTREACHED
}
/**
* default post action - upload a photo
*/
$_REQUEST['source'] = 'photos';
$r = photo_upload($a->channel, $a->get_observer(), $_REQUEST);
if (!$r['success']) {
notice($r['message'] . EOL);
}
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
示例10: photo_upload
//.........这里部分代码省略.........
$height = $link[2]['height'];
$tag = $r2 ? '[zmg=' . $width . 'x' . $height . ']' : '[zmg]';
}
$author_link = '[zrl=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $channel['channel_name'] . '[/zrl]';
$photo_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . t('a new photo') . '[/zrl]';
$album_link = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album) . ']' . (strlen($album) ? $album : '/') . '[/zrl]';
$activity_format = sprintf(t('%1$s posted %2$s to %3$s', 'photo_upload'), $author_link, $photo_link, $album_link);
$summary = ($args['body'] ? $args['body'] : '') . '[footer]' . $activity_format . '[/footer]';
$obj_body = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]' . '[/zrl]';
// Create item object
$object = array('type' => ACTIVITY_OBJ_PHOTO, 'title' => $title, 'created' => $p['created'], 'edited' => $p['edited'], 'id' => z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash, 'link' => $link, 'body' => $obj_body);
$target = array('type' => ACTIVITY_OBJ_ALBUM, 'title' => $album ? $album : '/', 'id' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album));
// Create item container
if ($args['item']) {
foreach ($args['item'] as $i) {
$item = get_item_elements($i);
$force = false;
if ($item['mid'] === $item['parent_mid']) {
$item['body'] = $summary;
$item['obj_type'] = ACTIVITY_OBJ_PHOTO;
$item['obj'] = json_encode($object);
$item['tgt_type'] = ACTIVITY_OBJ_ALBUM;
$item['target'] = json_encode($target);
if ($item['author_xchan'] === $channel['channel_hash']) {
$item['sig'] = base64url_encode(rsa_sign($item['body'], $channel['channel_prvkey']));
$item['item_verified'] = 1;
} else {
$item['sig'] = '';
}
$force = true;
}
$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'] || $force) {
$item['id'] = $r[0]['id'];
$item['uid'] = $channel['channel_id'];
item_store_update($item, false, $deliver);
continue;
}
} else {
$item['aid'] = $channel['channel_account_id'];
$item['uid'] = $channel['channel_id'];
$item_result = item_store($item, false, $deliver);
}
}
} else {
$mid = item_message_id();
$arr = array();
if ($lat && $lon) {
$arr['coord'] = $lat . ' ' . $lon;
}
$arr['aid'] = $account_id;
$arr['uid'] = $channel_id;
$arr['mid'] = $mid;
$arr['parent_mid'] = $mid;
$arr['item_hidden'] = $item_hidden;
$arr['resource_type'] = 'photo';
$arr['resource_id'] = $photo_hash;
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $observer['xchan_hash'];
$arr['title'] = $title;
$arr['allow_cid'] = $ac['allow_cid'];
$arr['allow_gid'] = $ac['allow_gid'];
$arr['deny_cid'] = $ac['deny_cid'];
$arr['deny_gid'] = $ac['deny_gid'];
$arr['verb'] = ACTIVITY_POST;
$arr['obj_type'] = ACTIVITY_OBJ_PHOTO;
$arr['obj'] = json_encode($object);
$arr['tgt_type'] = ACTIVITY_OBJ_ALBUM;
$arr['target'] = json_encode($target);
$arr['item_wall'] = 1;
$arr['item_origin'] = 1;
$arr['item_thread_top'] = 1;
$arr['item_private'] = intval($acl->is_private());
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
$arr['body'] = $summary;
// this one is tricky because the item and the photo have the same permissions, those of the photo.
// Use the channel read_stream permissions to get the correct public_policy for the item and recalculate the
// private flag accordingly. This may cause subtle bugs due to custom permissions roles. We want to use
// public policy when federating items to other sites, but should probably ignore them when accessing the item
// in the photos pages - using the photos permissions instead. We need the public policy to keep the photo
// linked item from leaking into the feed when somebody has a channel with read_stream restrictions.
$arr['public_policy'] = map_scope($channel['channel_r_stream'], true);
if ($arr['public_policy']) {
$arr['item_private'] = 1;
}
$result = item_store($arr, false, $deliver);
$item_id = $result['item_id'];
if ($visible && $deliver) {
Zotlabs\Daemon\Master::Summon(array('Notifier', 'wall-new', $item_id));
}
}
$ret['success'] = true;
$ret['item'] = $arr;
$ret['body'] = $obj_body;
$ret['resource_id'] = $photo_hash;
$ret['photoitem_id'] = $item_id;
call_hooks('photo_upload_end', $ret);
return $ret;
}
示例11: import_webpage_element
//.........这里部分代码省略.........
$liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'", dbesc($element['layout']));
if ($liid) {
$linfo = q("select mid from item where id = %d", intval($liid[0]['iid']));
$arr['layout_mid'] = $linfo[0]['mid'];
}
}
break;
//
// LAYOUTS
//
//
// LAYOUTS
//
case 'layout':
$arr['item_type'] = ITEM_TYPE_PDL;
$namespace = 'PDL';
$name = $element['name'];
$arr['title'] = $element['description'];
$arr['term'] = $element['term'];
break;
//
// BLOCKS
//
//
// BLOCKS
//
case 'block':
$arr['item_type'] = ITEM_TYPE_BLOCK;
$namespace = 'BUILDBLOCK';
$name = $element['name'];
$arr['title'] = $element['title'];
break;
default:
return null;
// return null if invalid element type
}
$arr['uid'] = $channel['channel_id'];
$arr['aid'] = $channel['channel_account_id'];
// Check if an item already exists based on the name
$iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'", dbesc($name));
if ($iid) {
// If the item does exist, get the item metadata
$iteminfo = q("select mid,created,edited from item where id = %d", intval($iid[0]['iid']));
$arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid'];
$arr['created'] = $iteminfo[0]['created'];
$arr['edited'] = $element['edited'] ? datetime_convert('UTC', 'UTC', $element['edited']) : datetime_convert();
} else {
// otherwise, generate the creation times and unique id
$arr['created'] = $element['created'] ? datetime_convert('UTC', 'UTC', $element['created']) : datetime_convert();
$arr['edited'] = datetime_convert('UTC', 'UTC', '0000-00-00 00:00:00');
$arr['mid'] = $arr['parent_mid'] = item_message_id();
}
// Import the actual element content
$arr['body'] = file_get_contents($element['path']);
// The element owner is the channel importing the elements
$arr['owner_xchan'] = get_observer_hash();
// The author is either the owner or whomever was specified
$arr['author_xchan'] = $element['author_xchan'] ? $element['author_xchan'] : get_observer_hash();
// Import mimetype if it is a valid mimetype for the element
$mimetypes = ['text/bbcode', 'text/html', 'text/markdown', 'text/plain', 'application/x-pdl', 'application/x-php'];
// Blocks and pages can have any mimetype, but layouts must be text/bbcode
if (in_array($element['mimetype'], $mimetypes) && ($type === 'page' || $type === 'block')) {
$arr['mimetype'] = $element['mimetype'];
} else {
$arr['mimetype'] = 'text/bbcode';
}
// 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;
}
}
$z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'service' limit 1", dbesc($name), dbesc($namespace));
$i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel()));
$remote_id = 0;
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 {
if ($i && intval($i[0]['item_deleted'])) {
// was partially deleted already, finish it off
q("delete from item where mid = '%s' and uid = %d", dbesc($arr['mid']), intval(local_channel()));
}
$x = item_store($arr, $execflag);
}
if ($x['success']) {
$item_id = $x['item_id'];
update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']);
$element['import_success'] = 1;
} else {
$element['import_success'] = 0;
}
return $element;
}
示例12: post
//.........这里部分代码省略.........
logger('Duplicate post. Faking plugin cancel.');
}
}
call_hooks('post_local', $datarray);
if (x($datarray, 'cancel')) {
logger('mod_item: post cancelled by plugin or duplicate suppressed.');
if ($return_path) {
goaway(z_root() . "/" . $return_path);
}
$json = array('cancel' => 1);
$json['reload'] = z_root() . '/' . $_REQUEST['jsreload'];
echo json_encode($json);
killme();
}
if (mb_strlen($datarray['title']) > 255) {
$datarray['title'] = mb_substr($datarray['title'], 0, 255);
}
if (array_key_exists('item_private', $datarray) && $datarray['item_private']) {
$datarray['body'] = trim(z_input_filter($datarray['uid'], $datarray['body'], $datarray['mimetype']));
if ($uid) {
if ($channel['channel_hash'] === $datarray['author_xchan']) {
$datarray['sig'] = base64url_encode(rsa_sign($datarray['body'], $channel['channel_prvkey']));
$datarray['item_verified'] = 1;
}
}
}
if ($webpage) {
Zlib\IConfig::Set($datarray, 'system', webpage_to_namespace($webpage), $pagetitle ? $pagetitle : substr($datarray['mid'], 0, 16), true);
} elseif ($namespace) {
Zlib\IConfig::Set($datarray, 'system', $namespace, $remote_id ? $remote_id : substr($datarray['mid'], 0, 16), true);
}
if ($orig_post) {
$datarray['id'] = $post_id;
$x = item_store_update($datarray, $execflag);
if (!$parent) {
$r = q("select * from item where id = %d", intval($post_id));
if ($r) {
xchan_query($r);
$sync_item = fetch_post_tags($r);
build_sync_packet($profile_uid, array('item' => array(encode_item($sync_item[0], true))));
}
}
if (!$nopush) {
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_post', $post_id));
}
if (x($_REQUEST, 'return') && strlen($return_path)) {
logger('return: ' . $return_path);
goaway(z_root() . "/" . $return_path);
}
killme();
} else {
$post_id = 0;
}
$post = item_store($datarray, $execflag);
$post_id = $post['item_id'];
$datarray = $post['item'];
if ($post_id) {
logger('mod_item: saved item ' . $post_id);
if ($parent) {
// only send comment notification if this is a wall-to-wall comment,
// otherwise it will happen during delivery
if ($datarray['owner_xchan'] != $datarray['author_xchan'] && intval($parent_item['item_wall'])) {
Zlib\Enotify::submit(array('type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], 'item' => $datarray, 'link' => z_root() . '/display/' . $datarray['mid'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $parent, 'parent_mid' => $parent_item['mid']));
}
} else {
$parent = $post_id;
示例13: import_items
function import_items($channel, $items, $sync = false)
{
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;
}
$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_result = item_store_update($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(array('Notifier', 'single_activity', $item_result['item_id']));
}
}
continue;
}
} 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(array('Notifier', 'single_activity', $item_result['item_id']));
}
}
}
}
}
示例14: 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);
}
}
}
}
示例15: reflect_comment_store
function reflect_comment_store($channel, $post, $comment, $user)
{
// if the commenter was the channel owner, use their hubzilla xchan
if ($comment['author'] === REFLECT_EXPORTUSERNAME && $comment['registered']) {
$hash = $channel['xchan_hash'];
} else {
// we need a unique hash for the commenter. We don't know how many may have supplied
// http://yahoo.com as their URL, so we'll use their avatar guid if they have one.
// anonymous folks may get more than one xchan_hash if they commented more than once.
$hash = $comment['registered'] && $user ? $user['avatar'] : '';
if (!$hash) {
$hash = random_string() . '.unknown';
}
// create an xchan for them which will also import their profile photo
// they will have a network type 'unknown'.
$x = array('hash' => $hash, 'guid' => $hash, 'url' => $comment['url'] ? $comment['url'] : z_root(), 'photo' => $user ? REFLECT_BASEURL . $user['avatar'] : z_root() . '/' . get_default_profile_photo(), 'name' => $comment['author']);
xchan_store($x);
}
$arr = array();
$r = q("select * from item where mid = '%s' and uid = %d limit 1", dbesc($comment['guid']), intval($channel['channel_id']));
if ($r) {
if (REFLECT_OVERWRITE) {
$arr['id'] = $r[0]['id'];
} else {
return;
}
}
// this is a lot like storing the post except for subtle differences, like parent_mid, flags, author_xchan,
// and we don't have a comment edited field so use creation date
$arr['uid'] = $channel['channel_account_id'];
$arr['aid'] = $channel['channel_id'];
$arr['mid'] = $comment['guid'];
$arr['parent_mid'] = $post['mid'];
$arr['created'] = $comment['created'];
$arr['edited'] = $comment['created'];
$arr['author_xchan'] = $hash;
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['item_origin'] = 1;
$arr['item_wall'] = 1;
$arr['verb'] = ACTIVITY_POST;
$arr['comment_policy'] = 'contacts';
$arr['title'] = html2bbcode($comment['title']);
$arr['title'] = htmlspecialchars($arr['title'], ENT_COMPAT, 'UTF-8', false);
$arr['body'] = html2bbcode($comment['body']);
$arr['body'] = htmlspecialchars($arr['body'], ENT_COMPAT, 'UTF-8', false);
$arr['body'] = preg_replace_callback("/\\[url\\=\\/+article\\/(.*?)\\](.*?)\\[url\\]/", 'reflect_article_callback', $arr['body']);
$arr['body'] = preg_replace_callback("/\\[img(.*?)\\](.*?)\\[\\/img\\]/", 'reflect_photo_callback', $arr['body']);
// logger('comment: ' . print_r($arr,true));
if ($arr['id']) {
item_store_update($arr);
} else {
item_store($arr);
}
}