More abstraction for the item access
This commit is contained in:
parent
d602da024f
commit
a4607f8d1c
5 changed files with 103 additions and 115 deletions
35
mod/acl.php
35
mod/acl.php
|
@ -8,6 +8,7 @@ use Friendica\Core\ACL;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\Item;
|
||||||
|
|
||||||
require_once 'include/dba.php';
|
require_once 'include/dba.php';
|
||||||
require_once 'mod/proxy.php';
|
require_once 'mod/proxy.php';
|
||||||
|
@ -250,25 +251,26 @@ function acl_content(App $a)
|
||||||
* but first get known contacts url to filter them out
|
* but first get known contacts url to filter them out
|
||||||
*/
|
*/
|
||||||
$known_contacts = array_map(function ($i) {
|
$known_contacts = array_map(function ($i) {
|
||||||
return dbesc($i['link']);
|
return $i['link'];
|
||||||
}, $contacts);
|
}, $contacts);
|
||||||
|
|
||||||
$unknown_contacts = [];
|
$unknown_contacts = [];
|
||||||
$r = q("SELECT `author-link`
|
|
||||||
FROM `item` WHERE `parent` = %d
|
$condition = ["`parent` = ?", $conv_id];
|
||||||
AND (`author-name` LIKE '%%%s%%' OR `author-link` LIKE '%%%s%%')
|
$params = ['order' => ['author-name' => true]];
|
||||||
AND `author-link` NOT IN ('%s')
|
$authors = Item::select(local_user(), ['author-link'], $condition, $params);
|
||||||
GROUP BY `author-link`, `author-avatar`, `author-name`
|
$item_authors = [];
|
||||||
ORDER BY `author-name` ASC
|
while ($author = dba::fetch($authors)) {
|
||||||
",
|
$item_authors[$author['author-link']] = $author['author-link'];
|
||||||
intval($conv_id),
|
}
|
||||||
dbesc($search),
|
dba::close($authors);
|
||||||
dbesc($search),
|
|
||||||
implode("', '", $known_contacts)
|
foreach ($item_authors as $author) {
|
||||||
);
|
if (in_array($author, $known_contacts)) {
|
||||||
if (DBM::is_result($r)) {
|
continue;
|
||||||
foreach ($r as $row) {
|
}
|
||||||
$contact = Contact::getDetailsByURL($row['author-link']);
|
|
||||||
|
$contact = Contact::getDetailsByURL($author);
|
||||||
|
|
||||||
if (count($contact) > 0) {
|
if (count($contact) > 0) {
|
||||||
$unknown_contacts[] = [
|
$unknown_contacts[] = [
|
||||||
|
@ -284,7 +286,6 @@ function acl_content(App $a)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$items = array_merge($items, $unknown_contacts);
|
$items = array_merge($items, $unknown_contacts);
|
||||||
$tot += count($unknown_contacts);
|
$tot += count($unknown_contacts);
|
||||||
|
|
56
mod/poke.php
56
mod/poke.php
|
@ -50,7 +50,7 @@ function poke_init(App $a) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
|
$parent = (x($_GET,'parent') ? intval($_GET['parent']) : 0);
|
||||||
|
|
||||||
|
|
||||||
logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
|
logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG);
|
||||||
|
@ -69,29 +69,25 @@ function poke_init(App $a) {
|
||||||
$target = $r[0];
|
$target = $r[0];
|
||||||
|
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
$r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`
|
$fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
|
||||||
FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1",
|
$condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
|
||||||
intval($parent),
|
$item = Item::selectFirst(local_user(), $fields, $condition);
|
||||||
intval($parent),
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$parent_uri = $r[0]['uri'];
|
|
||||||
$private = $r[0]['private'];
|
|
||||||
$allow_cid = $r[0]['allow_cid'];
|
|
||||||
$allow_gid = $r[0]['allow_gid'];
|
|
||||||
$deny_cid = $r[0]['deny_cid'];
|
|
||||||
$deny_gid = $r[0]['deny_gid'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
$private = ((x($_GET,'private')) ? intval($_GET['private']) : 0);
|
if (DBM::is_result($item)) {
|
||||||
|
$parent_uri = $item['uri'];
|
||||||
|
$private = $item['private'];
|
||||||
|
$allow_cid = $item['allow_cid'];
|
||||||
|
$allow_gid = $item['allow_gid'];
|
||||||
|
$deny_cid = $item['deny_cid'];
|
||||||
|
$deny_gid = $item['deny_gid'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$private = (x($_GET,'private') ? intval($_GET['private']) : 0);
|
||||||
|
|
||||||
$allow_cid = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']);
|
$allow_cid = ($private ? '<' . $target['id']. '>' : $a->user['allow_cid']);
|
||||||
$allow_gid = (($private) ? '' : $a->user['allow_gid']);
|
$allow_gid = ($private ? '' : $a->user['allow_gid']);
|
||||||
$deny_cid = (($private) ? '' : $a->user['deny_cid']);
|
$deny_cid = ($private ? '' : $a->user['deny_cid']);
|
||||||
$deny_gid = (($private) ? '' : $a->user['deny_gid']);
|
$deny_gid = ($private ? '' : $a->user['deny_gid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$poster = $a->contact;
|
$poster = $a->contact;
|
||||||
|
@ -103,7 +99,7 @@ function poke_init(App $a) {
|
||||||
$arr['guid'] = get_guid(32);
|
$arr['guid'] = get_guid(32);
|
||||||
$arr['uid'] = $uid;
|
$arr['uid'] = $uid;
|
||||||
$arr['uri'] = $uri;
|
$arr['uri'] = $uri;
|
||||||
$arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri);
|
$arr['parent-uri'] = ($parent_uri ? $parent_uri : $uri);
|
||||||
$arr['type'] = 'activity';
|
$arr['type'] = 'activity';
|
||||||
$arr['wall'] = 1;
|
$arr['wall'] = 1;
|
||||||
$arr['contact-id'] = $poster['id'];
|
$arr['contact-id'] = $poster['id'];
|
||||||
|
@ -160,8 +156,8 @@ function poke_content(App $a) {
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$name = $r[0]['name'];
|
$name = $item['name'];
|
||||||
$id = $r[0]['id'];
|
$id = $item['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,16 +171,17 @@ function poke_content(App $a) {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
|
$parent = (x($_GET,'parent') ? intval($_GET['parent']) : '0');
|
||||||
|
|
||||||
|
|
||||||
$verbs = get_poke_verbs();
|
$verbs = get_poke_verbs();
|
||||||
|
|
||||||
$shortlist = [];
|
$shortlist = [];
|
||||||
foreach($verbs as $k => $v)
|
foreach ($verbs as $k => $v) {
|
||||||
if($v[1] !== 'NOTRANSLATION')
|
if ($v[1] !== 'NOTRANSLATION') {
|
||||||
$shortlist[] = [$k, $v[1]];
|
$shortlist[] = [$k, $v[1]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$tpl = get_markup_template('poke_content.tpl');
|
$tpl = get_markup_template('poke_content.tpl');
|
||||||
|
|
||||||
|
@ -202,5 +199,4 @@ function poke_content(App $a) {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
|
use Friendica\Model\Item;
|
||||||
|
|
||||||
function share_init(App $a) {
|
function share_init(App $a) {
|
||||||
$post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
|
$post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
|
||||||
|
@ -10,27 +11,25 @@ function share_init(App $a) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT item.*, contact.network FROM `item`
|
$fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar',
|
||||||
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
|
'guid', 'created', 'plink', 'title'];
|
||||||
WHERE `item`.`id` = %d LIMIT 1",
|
$item = Item::selectFirst(local_user(), $fields, ['id' => $post_id]);
|
||||||
intval($post_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBM::is_result($r) || ($r[0]['private'] == 1)) {
|
if (!DBM::is_result($item) || $item['private']) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($r[0]['body'], "[/share]") !== false) {
|
if (strpos($item['body'], "[/share]") !== false) {
|
||||||
$pos = strpos($r[0]['body'], "[share");
|
$pos = strpos($item['body'], "[share");
|
||||||
$o = substr($r[0]['body'], $pos);
|
$o = substr($item['body'], $pos);
|
||||||
} else {
|
} else {
|
||||||
$o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
|
$o = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']);
|
||||||
|
|
||||||
if ($r[0]['title']) {
|
if ($item['title']) {
|
||||||
$o .= '[b]'.$r[0]['title'].'[/b]'."\n";
|
$o .= '[b]'.$item['title'].'[/b]'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$o .= $r[0]['body'];
|
$o .= $item['body'];
|
||||||
$o .= "[/share]";
|
$o .= "[/share]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,18 +22,14 @@ function subthread_content(App $a) {
|
||||||
|
|
||||||
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
|
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
|
||||||
|
|
||||||
$r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1",
|
$condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
|
||||||
dbesc($item_id),
|
$item = Item::selectFirst(local_user(), [], $condition);
|
||||||
dbesc($item_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(! $item_id || (! DBM::is_result($r))) {
|
if (empty($item_id) || !DBM::is_result($item)) {
|
||||||
logger('subthread: no item ' . $item_id);
|
logger('subthread: no item ' . $item_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = $r[0];
|
|
||||||
|
|
||||||
$owner_uid = $item['uid'];
|
$owner_uid = $item['uid'];
|
||||||
|
|
||||||
if (!can_write_wall($owner_uid)) {
|
if (!can_write_wall($owner_uid)) {
|
||||||
|
@ -80,7 +76,7 @@ function subthread_content(App $a) {
|
||||||
$contact = null;
|
$contact = null;
|
||||||
// This represents the person posting
|
// This represents the person posting
|
||||||
|
|
||||||
if ((local_user()) && (local_user() == $owner_uid)) {
|
if (local_user() && (local_user() == $owner_uid)) {
|
||||||
$contact = $owner;
|
$contact = $owner;
|
||||||
} else {
|
} else {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||||
|
@ -168,5 +164,3 @@ EOT;
|
||||||
killme();
|
killme();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,25 +23,22 @@ function tagger_content(App $a) {
|
||||||
// no commas allowed
|
// no commas allowed
|
||||||
$term = str_replace([',',' '],['','_'],$term);
|
$term = str_replace([',',' '],['','_'],$term);
|
||||||
|
|
||||||
if(! $term)
|
if (!$term) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
|
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
|
||||||
|
|
||||||
logger('tagger: tag ' . $term . ' item ' . $item_id);
|
logger('tagger: tag ' . $term . ' item ' . $item_id);
|
||||||
|
|
||||||
|
|
||||||
$r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
|
$item = Item::selectFirst(local_user(), [], ['id' => $item_id]);
|
||||||
dbesc($item_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(! $item_id || (! DBM::is_result($r))) {
|
if (!$item_id || !DBM::is_result($item)) {
|
||||||
logger('tagger: no item ' . $item_id);
|
logger('tagger: no item ' . $item_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = $r[0];
|
|
||||||
|
|
||||||
$owner_uid = $item['uid'];
|
$owner_uid = $item['uid'];
|
||||||
$owner_nick = '';
|
$owner_nick = '';
|
||||||
$blocktags = 0;
|
$blocktags = 0;
|
||||||
|
@ -54,15 +51,16 @@ function tagger_content(App $a) {
|
||||||
$blocktags = $r[0]['blocktags'];
|
$blocktags = $r[0]['blocktags'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(local_user() != $owner_uid)
|
if (local_user() != $owner_uid) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$r = q("select * from contact where self = 1 and uid = %d limit 1",
|
$r = q("select * from contact where self = 1 and uid = %d limit 1",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
if (DBM::is_result($r))
|
if (DBM::is_result($r)) {
|
||||||
$contact = $r[0];
|
$contact = $r[0];
|
||||||
else {
|
} else {
|
||||||
logger('tagger: no contact_id');
|
logger('tagger: no contact_id');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +163,7 @@ EOT;
|
||||||
dbesc($term)
|
dbesc($term)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((!$blocktags) && $t[0]['tcount'] == 0 ) {
|
if (!$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($item['id']),
|
intval($item['id']),
|
||||||
$term_objtype,
|
$term_objtype,
|
||||||
|
|
Loading…
Reference in a new issue