Merge pull request #5261 from annando/and-again-abstraction
And again the item abstraction - and a fix for issue 5252
This commit is contained in:
commit
8a3cae686b
|
@ -1547,7 +1547,7 @@ function api_search($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$data['status'] = api_format_items(dba::inArray($statuses), $user_info);
|
$data['status'] = api_format_items(Item::inArray($statuses), $user_info);
|
||||||
|
|
||||||
return api_format_data("statuses", $type, $data);
|
return api_format_data("statuses", $type, $data);
|
||||||
}
|
}
|
||||||
|
@ -1614,7 +1614,7 @@ function api_statuses_home_timeline($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$items = dba::inArray($statuses);
|
$items = Item::inArray($statuses);
|
||||||
|
|
||||||
$ret = api_format_items($items, $user_info, false, $type);
|
$ret = api_format_items($items, $user_info, false, $type);
|
||||||
|
|
||||||
|
@ -1691,7 +1691,7 @@ function api_statuses_public_timeline($type)
|
||||||
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
|
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
|
||||||
|
|
||||||
$r = dba::inArray($statuses);
|
$r = Item::inArray($statuses);
|
||||||
} else {
|
} else {
|
||||||
$condition = ["`verb` = ? AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
|
$condition = ["`verb` = ? AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
|
||||||
ACTIVITY_POST, $since_id];
|
ACTIVITY_POST, $since_id];
|
||||||
|
@ -1708,7 +1708,7 @@ function api_statuses_public_timeline($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$r = dba::inArray($statuses);
|
$r = Item::inArray($statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = api_format_items($r, $user_info, false, $type);
|
$ret = api_format_items($r, $user_info, false, $type);
|
||||||
|
@ -1767,7 +1767,7 @@ function api_statuses_networkpublic_timeline($type)
|
||||||
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
|
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
|
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -1843,7 +1843,7 @@ function api_statuses_show($type)
|
||||||
throw new BadRequestException("There is no status with this id.");
|
throw new BadRequestException("There is no status with this id.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
|
|
||||||
if ($conversation) {
|
if ($conversation) {
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
|
@ -1923,7 +1923,7 @@ function api_conversation_show($type)
|
||||||
throw new BadRequestException("There is no status with id $id.");
|
throw new BadRequestException("There is no status with id $id.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
|
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
return api_format_data("statuses", $type, $data);
|
return api_format_data("statuses", $type, $data);
|
||||||
|
@ -2089,7 +2089,7 @@ function api_statuses_mentions($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
|
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -2169,7 +2169,7 @@ function api_statuses_user_timeline($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, true, $type);
|
||||||
|
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -2311,7 +2311,7 @@ function api_favorites($type)
|
||||||
|
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = ['status' => $ret];
|
$data = ['status' => $ret];
|
||||||
|
@ -2728,7 +2728,7 @@ function api_format_items_activities(&$item, $type = "json")
|
||||||
$condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
|
$condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri']];
|
||||||
$ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
|
$ret = Item::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
|
||||||
|
|
||||||
while ($item = dba::fetch($ret)) {
|
while ($item = Item::fetch($ret)) {
|
||||||
// not used as result should be structured like other user data
|
// not used as result should be structured like other user data
|
||||||
//builtin_activity_puller($i, $activities);
|
//builtin_activity_puller($i, $activities);
|
||||||
|
|
||||||
|
@ -3117,7 +3117,7 @@ function api_lists_statuses($type)
|
||||||
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
|
||||||
|
|
||||||
$items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$items = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
|
|
||||||
$data = ['status' => $items];
|
$data = ['status' => $items];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
@ -4636,7 +4636,7 @@ function prepare_photo_data($type, $scale, $photo_id)
|
||||||
$statuses = Item::selectForUser(api_user(), [], $condition);
|
$statuses = Item::selectForUser(api_user(), [], $condition);
|
||||||
|
|
||||||
// prepare output of comments
|
// prepare output of comments
|
||||||
$commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
|
$commentData = api_format_items(Item::inArray($statuses), $user_info, false, $type);
|
||||||
$comments = [];
|
$comments = [];
|
||||||
if ($type == "xml") {
|
if ($type == "xml") {
|
||||||
$k = 0;
|
$k = 0;
|
||||||
|
|
|
@ -779,7 +779,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
|
||||||
}
|
}
|
||||||
$thread_items = Item::selectForUser(local_user(), [], $condition, $params);
|
$thread_items = Item::selectForUser(local_user(), [], $condition, $params);
|
||||||
|
|
||||||
$comments = dba::inArray($thread_items);
|
$comments = Item::inArray($thread_items);
|
||||||
|
|
||||||
if (count($comments) != 0) {
|
if (count($comments) != 0) {
|
||||||
$items = array_merge($items, $comments);
|
$items = array_merge($items, $comments);
|
||||||
|
|
|
@ -474,7 +474,7 @@ function perms2str($p) {
|
||||||
*/
|
*/
|
||||||
function load_view_file($s) {
|
function load_view_file($s) {
|
||||||
global $lang, $a;
|
global $lang, $a;
|
||||||
if (! isset($lang)) {
|
if (!isset($lang)) {
|
||||||
$lang = 'en';
|
$lang = 'en';
|
||||||
}
|
}
|
||||||
$b = basename($s);
|
$b = basename($s);
|
||||||
|
@ -519,7 +519,7 @@ function get_intltext_template($s) {
|
||||||
$engine = "/smarty3";
|
$engine = "/smarty3";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($lang)) {
|
if (!isset($lang)) {
|
||||||
$lang = 'en';
|
$lang = 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,8 +621,8 @@ function logger($msg, $level = 0) {
|
||||||
$loglevel = intval(Config::get('system','loglevel'));
|
$loglevel = intval(Config::get('system','loglevel'));
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! $debugging
|
!$debugging
|
||||||
|| ! $logfile
|
|| !$logfile
|
||||||
|| $level > $loglevel
|
|| $level > $loglevel
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
|
@ -689,7 +689,7 @@ function dlogger($msg, $level = 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$logfile = Config::get('system', 'dlogfile');
|
$logfile = Config::get('system', 'dlogfile');
|
||||||
if (! $logfile) {
|
if (!$logfile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,7 +1253,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
|
||||||
$s = $hook_data['html'];
|
$s = $hook_data['html'];
|
||||||
unset($hook_data);
|
unset($hook_data);
|
||||||
|
|
||||||
if (! $attach) {
|
if (!$attach) {
|
||||||
// Replace the blockquotes with quotes that are used in mails.
|
// Replace the blockquotes with quotes that are used in mails.
|
||||||
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
|
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
|
||||||
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
||||||
|
@ -1553,7 +1553,7 @@ function generate_user_guid() {
|
||||||
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
|
$x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
|
||||||
dbesc($guid)
|
dbesc($guid)
|
||||||
);
|
);
|
||||||
if (! DBM::is_result($x)) {
|
if (!DBM::is_result($x)) {
|
||||||
$found = false;
|
$found = false;
|
||||||
}
|
}
|
||||||
} while ($found == true);
|
} while ($found == true);
|
||||||
|
@ -1595,7 +1595,7 @@ function base64url_decode($s) {
|
||||||
* // Uncomment if you find you need it.
|
* // Uncomment if you find you need it.
|
||||||
*
|
*
|
||||||
* $l = strlen($s);
|
* $l = strlen($s);
|
||||||
* if (! strpos($s,'=')) {
|
* if (!strpos($s,'=')) {
|
||||||
* $m = $l % 4;
|
* $m = $l % 4;
|
||||||
* if ($m == 2)
|
* if ($m == 2)
|
||||||
* $s .= '==';
|
* $s .= '==';
|
||||||
|
@ -1818,7 +1818,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
||||||
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
|
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
|
||||||
|
|
||||||
foreach ($check_new_tags as $tag) {
|
foreach ($check_new_tags as $tag) {
|
||||||
if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
if (!stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
||||||
$new_tags[] = $tag;
|
$new_tags[] = $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1830,7 +1830,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
||||||
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
|
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
|
||||||
|
|
||||||
foreach ($check_deleted_tags as $tag) {
|
foreach ($check_deleted_tags as $tag) {
|
||||||
if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
if (!stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
||||||
$deleted_tags[] = $tag;
|
$deleted_tags[] = $tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1859,20 +1859,17 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function file_tag_save_file($uid, $item, $file)
|
function file_tag_save_file($uid, $item_id, $file)
|
||||||
{
|
{
|
||||||
if (! intval($uid)) {
|
if (!intval($uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
$item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
|
||||||
intval($item),
|
if (DBM::is_result($item)) {
|
||||||
intval($uid)
|
if (!stristr($item['file'],'[' . file_tag_encode($file) . ']')) {
|
||||||
);
|
$fields = ['file' => $item['file'] . '[' . file_tag_encode($file) . ']'];
|
||||||
if (DBM::is_result($r)) {
|
Item::update($fields, ['id' => $item_id]);
|
||||||
if (!stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) {
|
|
||||||
$fields = ['file' => $r[0]['file'] . '[' . file_tag_encode($file) . ']'];
|
|
||||||
Item::update($fields, ['id' => $item]);
|
|
||||||
}
|
}
|
||||||
$saved = PConfig::get($uid, 'system', 'filetags');
|
$saved = PConfig::get($uid, 'system', 'filetags');
|
||||||
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
|
if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) {
|
||||||
|
@ -1883,9 +1880,9 @@ function file_tag_save_file($uid, $item, $file)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function file_tag_unsave_file($uid, $item, $file, $cat = false)
|
function file_tag_unsave_file($uid, $item_id, $file, $cat = false)
|
||||||
{
|
{
|
||||||
if (! intval($uid)) {
|
if (!intval($uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1897,16 +1894,13 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false)
|
||||||
$termtype = TERM_FILE;
|
$termtype = TERM_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
$item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
|
||||||
intval($item),
|
if (!DBM::is_result($item)) {
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
if (! DBM::is_result($r)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['file' => str_replace($pattern,'',$r[0]['file'])];
|
$fields = ['file' => str_replace($pattern,'',$item['file'])];
|
||||||
Item::update($fields, ['id' => $item]);
|
Item::update($fields, ['id' => $item_id]);
|
||||||
|
|
||||||
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
|
$r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
|
||||||
dbesc($file),
|
dbesc($file),
|
||||||
|
|
|
@ -21,7 +21,7 @@ function search_saved_searches() {
|
||||||
$o = '';
|
$o = '';
|
||||||
$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
|
$search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : '');
|
||||||
|
|
||||||
if (! Feature::isEnabled(local_user(),'savedsearch'))
|
if (!Feature::isEnabled(local_user(),'savedsearch'))
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
$r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
|
$r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d",
|
||||||
|
@ -184,7 +184,7 @@ function search_content(App $a) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $search)
|
if (!$search)
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
if (Config::get('system','only_tag_search'))
|
if (Config::get('system','only_tag_search'))
|
||||||
|
@ -211,8 +211,13 @@ function search_content(App $a) {
|
||||||
}
|
}
|
||||||
dba::close($terms);
|
dba::close($terms);
|
||||||
|
|
||||||
$items = Item::selectForUser(local_user(), [], ['id' => array_reverse($itemids)]);
|
if (!empty($itemids)) {
|
||||||
$r = dba::inArray($items);
|
$params = ['order' => ['id' => true]];
|
||||||
|
$items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
|
||||||
|
$r = dba::inArray($items);
|
||||||
|
} else {
|
||||||
|
$r = [];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
|
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
|
||||||
|
|
||||||
|
@ -250,4 +255,3 @@ function search_content(App $a) {
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,32 +11,29 @@ function starred_init(App $a) {
|
||||||
$starred = 0;
|
$starred = 0;
|
||||||
$message_id = null;
|
$message_id = null;
|
||||||
|
|
||||||
if (! local_user()) {
|
if (!local_user()) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
if ($a->argc > 1) {
|
if ($a->argc > 1) {
|
||||||
$message_id = intval($a->argv[1]);
|
$message_id = intval($a->argv[1]);
|
||||||
}
|
}
|
||||||
if (! $message_id) {
|
if (!$message_id) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `starred` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1",
|
$item = Item::selectForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
|
||||||
intval(local_user()),
|
if (!DBM::is_result($item)) {
|
||||||
intval($message_id)
|
|
||||||
);
|
|
||||||
if (! DBM::is_result($r)) {
|
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! intval($r[0]['starred'])) {
|
if (!intval($item['starred'])) {
|
||||||
$starred = 1;
|
$starred = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::update(['starred' => $starred], ['id' => $message_id]);
|
Item::update(['starred' => $starred], ['id' => $message_id]);
|
||||||
|
|
||||||
// See if we've been passed a return path to redirect to
|
// See if we've been passed a return path to redirect to
|
||||||
$return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : '');
|
$return_path = (x($_REQUEST,'return') ? $_REQUEST['return'] : '');
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
$rand = '_=' . time();
|
$rand = '_=' . time();
|
||||||
if (strpos($return_path, '?')) {
|
if (strpos($return_path, '?')) {
|
||||||
|
|
|
@ -175,23 +175,19 @@ EOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the original post is on this site, update it.
|
// if the original post is on this site, update it.
|
||||||
|
$original_item = Item::selectFirst(['tag', 'id', 'uid'], ['origin' => true, 'uri' => $item['uri']]);
|
||||||
$r = q("SELECT `tag`,`id`,`uid` FROM `item` WHERE `origin`=1 AND `uri`='%s' LIMIT 1",
|
if (DBM::is_result($original_item)) {
|
||||||
dbesc($item['uri'])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
|
$x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
|
||||||
intval($r[0]['uid'])
|
intval($original_item['uid'])
|
||||||
);
|
);
|
||||||
$t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
|
$t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
|
||||||
intval($r[0]['id']),
|
intval($original_item['id']),
|
||||||
dbesc($term)
|
dbesc($term)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
|
if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
|
||||||
q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
|
q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
|
||||||
intval($r[0]['id']),
|
intval($original_item['id']),
|
||||||
$term_objtype,
|
$term_objtype,
|
||||||
TERM_HASHTAG,
|
TERM_HASHTAG,
|
||||||
dbesc($term),
|
dbesc($term),
|
||||||
|
|
|
@ -56,6 +56,40 @@ class Item extends BaseObject
|
||||||
'author-id', 'author-link', 'owner-link', 'contact-uid',
|
'author-id', 'author-link', 'owner-link', 'contact-uid',
|
||||||
'signed_text', 'signature', 'signer'];
|
'signed_text', 'signature', 'signer'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fetch a single item row
|
||||||
|
*
|
||||||
|
* @param mixed $stmt statement object
|
||||||
|
* @return array current row
|
||||||
|
*/
|
||||||
|
public static function fetch($stmt)
|
||||||
|
{
|
||||||
|
$row = dba::fetch($stmt);
|
||||||
|
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fills an array with data from an item query
|
||||||
|
*
|
||||||
|
* @param object $stmt statement object
|
||||||
|
* @return array Data array
|
||||||
|
*/
|
||||||
|
public static function inArray($stmt, $do_close = true) {
|
||||||
|
if (is_bool($stmt)) {
|
||||||
|
return $stmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
while ($row = self::fetch($stmt)) {
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
if ($do_close) {
|
||||||
|
dba::close($stmt);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a single record from the item table for a given user and returns it in an associative array
|
* Retrieve a single record from the item table for a given user and returns it in an associative array
|
||||||
*
|
*
|
||||||
|
@ -118,7 +152,7 @@ class Item extends BaseObject
|
||||||
if (is_bool($result)) {
|
if (is_bool($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$row = dba::fetch($result);
|
$row = self::fetch($result);
|
||||||
dba::close($result);
|
dba::close($result);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
@ -225,7 +259,7 @@ class Item extends BaseObject
|
||||||
if (is_bool($result)) {
|
if (is_bool($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
$row = dba::fetch($result);
|
$row = self::fetch($result);
|
||||||
dba::close($result);
|
dba::close($result);
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ class DFRN
|
||||||
|
|
||||||
if (!empty($ids)) {
|
if (!empty($ids)) {
|
||||||
$ret = Item::select(Item::DELIVER_FIELDLIST, ['id' => $ids]);
|
$ret = Item::select(Item::DELIVER_FIELDLIST, ['id' => $ids]);
|
||||||
$items = dba::inArray($ret);
|
$items = Item::inArray($ret);
|
||||||
} else {
|
} else {
|
||||||
$items = [];
|
$items = [];
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ class DFRN
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = Item::select(Item::DELIVER_FIELDLIST, $condition);
|
$ret = Item::select(Item::DELIVER_FIELDLIST, $condition);
|
||||||
$items = dba::inArray($ret);
|
$items = Item::inArray($ret);
|
||||||
if (!DBM::is_result($items)) {
|
if (!DBM::is_result($items)) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
@ -938,10 +938,10 @@ class DFRN
|
||||||
|
|
||||||
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
|
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
|
||||||
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
|
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
|
||||||
$parent = q("SELECT `guid`,`plink` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($parent_item), intval($item['uid']));
|
$parent = Item::selectFirst(['guid', 'plink'], ['uri' => $parent_item, 'uid' => $item['uid']]);
|
||||||
$attributes = ["ref" => $parent_item, "type" => "text/html",
|
$attributes = ["ref" => $parent_item, "type" => "text/html",
|
||||||
"href" => $parent[0]['plink'],
|
"href" => $parent['plink'],
|
||||||
"dfrn:diaspora_guid" => $parent[0]['guid']];
|
"dfrn:diaspora_guid" => $parent['guid']];
|
||||||
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
|
XML::addElement($doc, $entry, "thr:in-reply-to", "", $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2161,13 +2161,8 @@ class DFRN
|
||||||
|
|
||||||
$is_a_remote_action = false;
|
$is_a_remote_action = false;
|
||||||
|
|
||||||
$r = q(
|
$parent = Item::selectFirst(['parent-uri'], ['uri' => $item["parent-uri"]]);
|
||||||
"SELECT `item`.`parent-uri` FROM `item`
|
if (DBM::is_result($parent)) {
|
||||||
WHERE `item`.`uri` = '%s'
|
|
||||||
LIMIT 1",
|
|
||||||
dbesc($item["parent-uri"])
|
|
||||||
);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
|
"SELECT `item`.`forum_mode`, `item`.`wall` FROM `item`
|
||||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||||
|
@ -2175,9 +2170,9 @@ class DFRN
|
||||||
AND `item`.`uid` = %d
|
AND `item`.`uid` = %d
|
||||||
$sql_extra
|
$sql_extra
|
||||||
LIMIT 1",
|
LIMIT 1",
|
||||||
dbesc($r[0]["parent-uri"]),
|
dbesc($parent["parent-uri"]),
|
||||||
dbesc($r[0]["parent-uri"]),
|
dbesc($parent["parent-uri"]),
|
||||||
dbesc($r[0]["parent-uri"]),
|
dbesc($parent["parent-uri"]),
|
||||||
intval($importer["importer_uid"])
|
intval($importer["importer_uid"])
|
||||||
);
|
);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
|
@ -2318,25 +2313,15 @@ class DFRN
|
||||||
$item["gravity"] = GRAVITY_LIKE;
|
$item["gravity"] = GRAVITY_LIKE;
|
||||||
// only one like or dislike per person
|
// only one like or dislike per person
|
||||||
// splitted into two queries for performance issues
|
// splitted into two queries for performance issues
|
||||||
$r = q(
|
$condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"],
|
||||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
|
'verb' => $item["verb"], 'parent-uri' => $item["parent-uri"]];
|
||||||
intval($item["uid"]),
|
if (dba::exists('item', $condition)) {
|
||||||
intval($item["author-id"]),
|
|
||||||
dbesc($item["verb"]),
|
|
||||||
dbesc($item["parent-uri"])
|
|
||||||
);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q(
|
$condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"],
|
||||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
|
'verb' => $item["verb"], 'thr-parent' => $item["parent-uri"]];
|
||||||
intval($item["uid"]),
|
if (dba::exists('item', $condition)) {
|
||||||
intval($item["author-id"]),
|
|
||||||
dbesc($item["verb"]),
|
|
||||||
dbesc($item["parent-uri"])
|
|
||||||
);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2348,22 +2333,17 @@ class DFRN
|
||||||
$xt = XML::parseString($item["target"], false);
|
$xt = XML::parseString($item["target"], false);
|
||||||
|
|
||||||
if ($xt->type == ACTIVITY_OBJ_NOTE) {
|
if ($xt->type == ACTIVITY_OBJ_NOTE) {
|
||||||
$r = q(
|
$item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
|
||||||
"SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
if (!DBM::is_result($item_tag)) {
|
||||||
dbesc($xt->id),
|
|
||||||
intval($importer["importer_uid"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
logger("Query failed to execute, no result returned in " . __FUNCTION__);
|
logger("Query failed to execute, no result returned in " . __FUNCTION__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract tag, if not duplicate, add to parent item
|
// extract tag, if not duplicate, add to parent item
|
||||||
if ($xo->content) {
|
if ($xo->content) {
|
||||||
if (!stristr($r[0]["tag"], trim($xo->content))) {
|
if (!stristr($item_tag["tag"], trim($xo->content))) {
|
||||||
$tag = $r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
|
$tag = $item_tag["tag"] . (strlen($item_tag["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
|
||||||
Item::update(['tag' => $tag], ['id' => $r[0]["id"]]);
|
Item::update(['tag' => $tag], ['id' => $item_tag["id"]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2218,7 +2218,7 @@ class Diaspora
|
||||||
|
|
||||||
// Send all existing comments and likes to the requesting server
|
// Send all existing comments and likes to the requesting server
|
||||||
$comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]);
|
$comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]);
|
||||||
while ($comment = dba::fetch($comments)) {
|
while ($comment = Item::fetch($comments)) {
|
||||||
if ($comment['id'] == $comment['parent']) {
|
if ($comment['id'] == $comment['parent']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2771,7 +2771,7 @@ class Diaspora
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($item = dba::fetch($r)) {
|
while ($item = Item::fetch($r)) {
|
||||||
// Fetch the parent item
|
// Fetch the parent item
|
||||||
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
|
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
|
||||||
|
|
||||||
|
|
|
@ -2152,7 +2152,7 @@ class OStatus
|
||||||
$ret = Item::select([], $condition, $params);
|
$ret = Item::select([], $condition, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = dba::inArray($ret);
|
$items = Item::inArray($ret);
|
||||||
|
|
||||||
$doc = new DOMDocument('1.0', 'utf-8');
|
$doc = new DOMDocument('1.0', 'utf-8');
|
||||||
$doc->formatOutput = true;
|
$doc->formatOutput = true;
|
||||||
|
|
|
@ -64,7 +64,7 @@ class Delivery extends BaseObject
|
||||||
$itemdata = Item::select([], $condition, $params);
|
$itemdata = Item::select([], $condition, $params);
|
||||||
|
|
||||||
$items = [];
|
$items = [];
|
||||||
while ($item = dba::fetch($itemdata)) {
|
while ($item = Item::fetch($itemdata)) {
|
||||||
if ($item['id'] == $parent_id) {
|
if ($item['id'] == $parent_id) {
|
||||||
$parent = $item;
|
$parent = $item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ class Notifier {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = dba::inArray($ret);
|
$items = Item::inArray($ret);
|
||||||
|
|
||||||
// avoid race condition with deleting entries
|
// avoid race condition with deleting entries
|
||||||
if ($items[0]['deleted']) {
|
if ($items[0]['deleted']) {
|
||||||
|
|
|
@ -438,12 +438,10 @@ class OnePoll
|
||||||
$refs_arr[$x] = "'" . Email::msgid2iri(str_replace(['<', '>', ' '],['', '', ''],dbesc($refs_arr[$x]))) . "'";
|
$refs_arr[$x] = "'" . Email::msgid2iri(str_replace(['<', '>', ' '],['', '', ''],dbesc($refs_arr[$x]))) . "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$qstr = implode(',', $refs_arr);
|
$condition = ['uri' => $refs_arr, 'uid' => $importer_uid];
|
||||||
$r = q("SELECT `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1",
|
$parent = Item::selectFirst(['parent-uri'], $condition);
|
||||||
intval($importer_uid)
|
if (DBM::is_result($parent)) {
|
||||||
);
|
$datarray['parent-uri'] = $parent['parent-uri']; // Set the parent as the top-level item
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,12 +470,11 @@ class OnePoll
|
||||||
|
|
||||||
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
||||||
if (empty($datarray['parent-uri']) && $reply) {
|
if (empty($datarray['parent-uri']) && $reply) {
|
||||||
$r = q("SELECT `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
|
$condition = ['title' => $datarray['title'], 'uid' => importer_uid, 'network' => NETWORK_MAIL];
|
||||||
dbesc(protect_sprintf($datarray['title'])),
|
$params = ['order' => ['created' => true]];
|
||||||
intval($importer_uid),
|
$parent = Item::selectFirst(['parent-uri'], $condition, $params);
|
||||||
dbesc(NETWORK_MAIL));
|
if (DBM::is_result($parent)) {
|
||||||
if (DBM::is_result($r)) {
|
$datarray['parent-uri'] = $parent['parent-uri'];
|
||||||
$datarray['parent-uri'] = $r[0]['parent-uri'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ class TagUpdate
|
||||||
|
|
||||||
dba::close($messages);
|
dba::close($messages);
|
||||||
|
|
||||||
$messages = dba::p("SELECT `guid` FROM `item` WHERE `uid` = 0");
|
$messages = dba::select('item', ['guid'], ['uid' => 0]);
|
||||||
|
|
||||||
logger('fetched messages: ' . dba::num_rows($messages));
|
logger('fetched messages: ' . dba::num_rows($messages));
|
||||||
while ($message = dba::fetch(messages)) {
|
while ($message = dba::fetch(messages)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user