Some more direct SQL calls had been replaced
This commit is contained in:
parent
82d55f120f
commit
ab5669e091
2 changed files with 36 additions and 41 deletions
|
@ -110,14 +110,21 @@ function item_redir_and_replace_images($body, $images, $cid) {
|
||||||
/**
|
/**
|
||||||
* Render actions localized
|
* Render actions localized
|
||||||
*/
|
*/
|
||||||
function localize_item(&$item) {
|
function localize_item(&$item)
|
||||||
|
{
|
||||||
$extracted = item_extract_images($item['body']);
|
$extracted = item_extract_images($item['body']);
|
||||||
if ($extracted['images']) {
|
if ($extracted['images']) {
|
||||||
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
|
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @TODO Separted ???
|
/*
|
||||||
|
heluecht 2018-06-19: from my point of view this whole code part is useless.
|
||||||
|
It just renders the body message of technical posts (Like, dislike, ...).
|
||||||
|
But: The body isn't visible at all. So we do this stuff just because we can.
|
||||||
|
Even if these messages were visible, this would only mean that something went wrong.
|
||||||
|
During the further steps of the database restructuring I would like to address this issue.
|
||||||
|
*/
|
||||||
|
|
||||||
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||||
if (activity_match($item['verb'], ACTIVITY_LIKE)
|
if (activity_match($item['verb'], ACTIVITY_LIKE)
|
||||||
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
|
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
|
||||||
|
@ -125,15 +132,11 @@ function localize_item(&$item) {
|
||||||
|| activity_match($item['verb'], ACTIVITY_ATTENDNO)
|
|| activity_match($item['verb'], ACTIVITY_ATTENDNO)
|
||||||
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
||||||
|
|
||||||
/// @TODO may hurt performance
|
$fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
|
||||||
$r = q("SELECT * FROM `item`, `contact`
|
$obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
|
||||||
WHERE `item`.`contact-id`=`contact`.`id`
|
if (!DBM::is_result($obj)) {
|
||||||
AND `item`.`uri`='%s'",
|
|
||||||
dbesc($item['parent-uri']));
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$obj = $r[0];
|
|
||||||
|
|
||||||
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
|
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
|
||||||
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
|
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
|
||||||
|
@ -189,7 +192,8 @@ function localize_item(&$item) {
|
||||||
$links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
|
$links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
|
||||||
|
|
||||||
$Bname = $obj->title;
|
$Bname = $obj->title;
|
||||||
$Blink = ""; $Bphoto = "";
|
$Blink = "";
|
||||||
|
$Bphoto = "";
|
||||||
foreach ($links->link as $l) {
|
foreach ($links->link as $l) {
|
||||||
$atts = $l->attributes();
|
$atts = $l->attributes();
|
||||||
switch ($atts['rel']) {
|
switch ($atts['rel']) {
|
||||||
|
@ -249,7 +253,7 @@ function localize_item(&$item) {
|
||||||
|
|
||||||
// now translate the verb
|
// now translate the verb
|
||||||
$poked_t = trim(sprintf($txt, "", ""));
|
$poked_t = trim(sprintf($txt, "", ""));
|
||||||
$txt = str_replace( $poked_t, L10n::t($verb), $txt);
|
$txt = str_replace($poked_t, L10n::t($verb), $txt);
|
||||||
|
|
||||||
// then do the sprintf on the translation string
|
// then do the sprintf on the translation string
|
||||||
|
|
||||||
|
@ -258,18 +262,12 @@ function localize_item(&$item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity_match($item['verb'], ACTIVITY_TAG)) {
|
if (activity_match($item['verb'], ACTIVITY_TAG)) {
|
||||||
/// @TODO may hurt performance "joining" two tables + asterisk
|
$fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink'];
|
||||||
$r = q("SELECT * FROM `item`, `contact`
|
$obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
|
||||||
WHERE `item`.`contact-id`=`contact`.`id`
|
if (!DBM::is_result($obj)) {
|
||||||
AND `item`.`uri`='%s'",
|
|
||||||
dbesc($item['parent-uri']));
|
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj = $r[0];
|
|
||||||
|
|
||||||
$author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
|
$author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
|
||||||
$objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
|
$objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
|
||||||
|
|
||||||
|
@ -299,8 +297,7 @@ function localize_item(&$item) {
|
||||||
$parsedobj = XML::parseString($xmlhead.$item['object']);
|
$parsedobj = XML::parseString($xmlhead.$item['object']);
|
||||||
|
|
||||||
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
|
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
|
||||||
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
|
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
|
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
|
||||||
|
@ -315,13 +312,9 @@ function localize_item(&$item) {
|
||||||
|
|
||||||
$obj = XML::parseString($xmlhead.$item['object']);
|
$obj = XML::parseString($xmlhead.$item['object']);
|
||||||
if (strlen($obj->id)) {
|
if (strlen($obj->id)) {
|
||||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
$fields = ['author-link', 'author-name', 'plink'];
|
||||||
dbesc($obj->id),
|
$target = Item::selectFirst($fields, ['uri' => $obj->id, 'uid' => $item['uid']]);
|
||||||
intval($item['uid'])
|
if (DBM::is_result($target) && $target['plink']) {
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($r) && $r[0]['plink']) {
|
|
||||||
$target = $r[0];
|
|
||||||
$Bname = $target['author-name'];
|
$Bname = $target['author-name'];
|
||||||
$Blink = $target['author-link'];
|
$Blink = $target['author-link'];
|
||||||
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
|
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
|
||||||
|
@ -1009,7 +1002,7 @@ function format_like($cnt, array $arr, $type, $id) {
|
||||||
}
|
}
|
||||||
if ($total >= MAX_LIKERS) {
|
if ($total >= MAX_LIKERS) {
|
||||||
$str = implode(', ', $arr);
|
$str = implode(', ', $arr);
|
||||||
$str .= L10n::t('and %d other people', $total - MAX_LIKERS );
|
$str .= L10n::t('and %d other people', $total - MAX_LIKERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
$likers = $str;
|
$likers = $str;
|
||||||
|
|
|
@ -172,7 +172,7 @@ function photos_post(App $a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$can_post) {
|
if (!$can_post) {
|
||||||
notice(L10n::t('Permission denied.') . EOL );
|
notice(L10n::t('Permission denied.') . EOL);
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ function photos_post(App $a)
|
||||||
$str_res = implode(',', $res);
|
$str_res = implode(',', $res);
|
||||||
|
|
||||||
// remove the associated photos
|
// remove the associated photos
|
||||||
q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
|
q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
|
||||||
intval($page_owner_uid)
|
intval($page_owner_uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ function photos_post(App $a)
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$Image = new Image($r[0]['data'], $r[0]['type']);
|
$Image = new Image($r[0]['data'], $r[0]['type']);
|
||||||
if ($Image->isValid()) {
|
if ($Image->isValid()) {
|
||||||
$rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
|
$rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
|
||||||
$Image->rotate($rotate_deg);
|
$Image->rotate($rotate_deg);
|
||||||
|
|
||||||
$width = $Image->getWidth();
|
$width = $Image->getWidth();
|
||||||
|
@ -918,7 +918,7 @@ function photos_content(App $a)
|
||||||
require_once 'include/conversation.php';
|
require_once 'include/conversation.php';
|
||||||
|
|
||||||
if (!x($a->data,'user')) {
|
if (!x($a->data,'user')) {
|
||||||
notice(L10n::t('No photos selected') . EOL );
|
notice(L10n::t('No photos selected') . EOL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1216,7 +1216,7 @@ function photos_content(App $a)
|
||||||
if (DBM::is_result($ph)) {
|
if (DBM::is_result($ph)) {
|
||||||
notice(L10n::t('Permission denied. Access to this item may be restricted.'));
|
notice(L10n::t('Permission denied. Access to this item may be restricted.'));
|
||||||
} else {
|
} else {
|
||||||
notice(L10n::t('Photo not available') . EOL );
|
notice(L10n::t('Photo not available') . EOL);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1289,15 +1289,15 @@ function photos_content(App $a)
|
||||||
];
|
];
|
||||||
|
|
||||||
// lock
|
// lock
|
||||||
$lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
|
$lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
|
||||||
|| strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
|
|| strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
|
||||||
? L10n::t('Private Message')
|
? L10n::t('Private Message')
|
||||||
: Null);
|
: Null);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $cmd === 'edit') {
|
if ($cmd === 'edit') {
|
||||||
$tpl = get_markup_template('photo_edit_head.tpl');
|
$tpl = get_markup_template('photo_edit_head.tpl');
|
||||||
$a->page['htmlhead'] .= replace_macros($tpl,[
|
$a->page['htmlhead'] .= replace_macros($tpl,[
|
||||||
'$prevlink' => $prevlink,
|
'$prevlink' => $prevlink,
|
||||||
|
@ -1332,7 +1332,8 @@ function photos_content(App $a)
|
||||||
// The difference is that we won't be displaying the conversation head item
|
// The difference is that we won't be displaying the conversation head item
|
||||||
// as a "post" but displaying instead the photo it is linked to
|
// as a "post" but displaying instead the photo it is linked to
|
||||||
|
|
||||||
$linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
|
/// @todo Rewrite this query. To do so, $sql_extra must be changed
|
||||||
|
$linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
|
||||||
dbesc($datum)
|
dbesc($datum)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1340,7 +1341,8 @@ function photos_content(App $a)
|
||||||
$link_item = [];
|
$link_item = [];
|
||||||
|
|
||||||
if (DBM::is_result($linked_items)) {
|
if (DBM::is_result($linked_items)) {
|
||||||
$link_item = $linked_items[0];
|
// This is a workaround to not being forced to rewrite the while $sql_extra handling
|
||||||
|
$link_item = Item::selectFirstForUser(local_user(), [], ['id' => $linked_items[0]['id']]);
|
||||||
|
|
||||||
$r = q("SELECT COUNT(*) AS `total`
|
$r = q("SELECT COUNT(*) AS `total`
|
||||||
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||||
|
|
Loading…
Reference in a new issue