Cleanups:

- made SQL keywords all uper-case
- put all SQL columns in back-ticks
- added curly braces
- added/removed spaces

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-04-08 19:30:35 +02:00
parent f6c667ef45
commit a69f3017fb
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78

View file

@ -6,31 +6,33 @@
use \Friendica\ParseUrl;
require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/salmon.php');
require_once('include/crypto.php');
require_once('include/Photo.php');
require_once('include/tags.php');
require_once('include/files.php');
require_once('include/text.php');
require_once('include/email.php');
require_once('include/threads.php');
require_once('include/socgraph.php');
require_once('include/plaintext.php');
require_once('include/ostatus.php');
require_once('include/feed.php');
require_once('include/Contact.php');
require_once('mod/share.php');
require_once('include/enotify.php');
require_once('include/dfrn.php');
require_once('include/group.php');
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
require_once 'include/salmon.php';
require_once 'include/crypto.php';
require_once 'include/Photo.php';
require_once 'include/tags.php';
require_once 'include/files.php';
require_once 'include/text.php';
require_once 'include/email.php';
require_once 'include/threads.php';
require_once 'include/socgraph.php';
require_once 'include/plaintext.php';
require_once 'include/ostatus.php';
require_once 'include/feed.php';
require_once 'include/Contact.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
require_once 'include/dfrn.php';
require_once 'include/group.php';
require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
/// @TODO one day with composer autploader no more needed
require_once 'library/defuse/php-encryption-1.2.1/Crypto.php';
function construct_verb($item) {
if ($item['verb'])
if ($item['verb']) {
return $item['verb'];
}
return ACTIVITY_POST;
}
@ -96,8 +98,10 @@ function limit_body_size($body) {
}
$orig_body = substr($orig_body, $img_end);
if ($orig_body === false) // in case the body ends on a closing image tag
if ($orig_body === false) {
// in case the body ends on a closing image tag
$orig_body = '';
}
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
@ -117,8 +121,9 @@ function limit_body_size($body) {
}
return $new_body;
} else
} else {
return $body;
}
}}
function title_is_body($title, $body) {
@ -224,23 +229,26 @@ function query_page_info($url, $no_photos = false, $photo = "", $keywords = fals
$data = ParseUrl::getSiteinfoCached($url, true);
if ($photo != "")
if ($photo != "") {
$data["images"][0]["src"] = $photo;
}
logger('fetch page info for '.$url.' '.print_r($data, true), LOGGER_DEBUG);
if (!$keywords AND isset($data["keywords"]))
if (!$keywords AND isset($data["keywords"])) {
unset($data["keywords"]);
}
if (($keyword_blacklist != "") AND isset($data["keywords"])) {
$list = explode(", ", $keyword_blacklist);
foreach ($list AS $keyword) {
$keyword = trim($keyword);
$index = array_search($keyword, $data["keywords"]);
if ($index !== false)
if ($index !== false) {
unset($data["keywords"][$index]);
}
}
}
return($data);
}
@ -254,8 +262,9 @@ function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = fa
$hashtag = str_replace(array(" ", "+", "/", ".", "#", "'"),
array("", "", "", "", "", ""), $keyword);
if ($tags != "")
if ($tags != "") {
$tags .= ", ";
}
$tags .= "#[url=" . App::get_baseurl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
}
@ -1195,7 +1204,7 @@ function tag_deliver($uid,$item_id) {
$mention = false;
$u = q("select * from user where uid = %d limit 1",
$u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
@ -1261,8 +1270,9 @@ function tag_deliver($uid,$item_id) {
// prevent delivery looping - only proceed
// if the message originated elsewhere and is a top-level post
if (($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent']))
if (($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent'])) {
return;
}
// now change this copy of the post to a forum head message and deliver to all the tgroup members
@ -1307,8 +1317,9 @@ function tgroup_check($uid,$item) {
// check that the message originated elsewhere and is a top-level post
if (($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri']))
if (($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri'])) {
return false;
}
/// @TODO Encapsulate this or find it encapsulated and replace all occurrances
$u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
@ -1757,8 +1768,9 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
$new_body = $new_body . substr($orig_body, 0, $img_start + $img_st_close) . $image . '[/img]';
$orig_body = substr($orig_body, $img_start + $img_st_close + $img_len + strlen('[/img]'));
if ($orig_body === false)
if ($orig_body === false) {
$orig_body = '';
}
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
@ -1921,9 +1933,10 @@ function drop_items($items) {
// multiple threads may have been deleted, send an expire notification
if ($uid)
if ($uid) {
proc_run(PRIORITY_HIGH, "include/notifier.php", "expire", $uid);
}
}
function drop_item($id, $interactive = true) {
@ -1937,8 +1950,9 @@ function drop_item($id,$interactive = true) {
);
if (! dbm::is_result($r)) {
if (! $interactive)
if (! $interactive) {
return 0;
}
notice( t('Item not found.') . EOL);
goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
}
@ -2076,7 +2090,7 @@ function drop_item($id,$interactive = true) {
// The new code splits the queries since the mysql optimizer really has bad problems with subqueries
// Creating list of parents
$r = q("select id from item where parent = %d and uid = %d",
$r = q("SELECT `id` FROM `item` WHERE `parent` = %d AND `uid` = %d",
intval($item['id']),
intval($item['uid'])
);
@ -2092,13 +2106,11 @@ function drop_item($id,$interactive = true) {
// Now delete them
if ($parentid != "") {
$r = q("DELETE FROM item_id where iid in (%s)", dbesc($parentid));
$r = q("DELETE FROM sign where iid in (%s)", dbesc($parentid));
$r = q("DELETE FROM `item_id` WHERE `iid` IN (%s)", dbesc($parentid));
$r = q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
}
// If it's the parent of a comment thread, kill all the kids
if ($item['uri'] == $item['parent-uri']) {
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = ''
WHERE `parent-uri` = '%s' AND `uid` = %d ",
@ -2136,13 +2148,15 @@ function drop_item($id,$interactive = true) {
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
if (! $interactive)
if (! $interactive) {
return $owner;
}
goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
//NOTREACHED
} else {
if (! $interactive)
if (! $interactive) {
return 0;
}
notice( t('Permission denied.') . EOL);
goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
//NOTREACHED
@ -2152,10 +2166,10 @@ function drop_item($id,$interactive = true) {
function first_post_date($uid, $wall = false) {
$r = q("select id, created from item
where uid = %d and wall = %d and deleted = 0 and visible = 1 AND moderated = 0
and id = parent
order by created asc limit 1",
$r = q("SELECT `id`, `created` FROM `item`
WHERE `uid` = %d AND `wall` = %d AND `deleted` = 0 AND `visible` = 1 AND `moderated` = 0
AND `id` = `parent`
ORDER BY `created` ASC LIMIT 1",
intval($uid),
intval($wall ? 1 : 0)
);
@ -2171,8 +2185,9 @@ function list_post_dates($uid, $wall) {
$dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d');
$dthen = first_post_date($uid, $wall);
if (! $dthen)
if (! $dthen) {
return array();
}
// Set the start and end date to the beginning of the month
$dnow = substr($dnow,0,8).'01';
@ -2180,8 +2195,10 @@ function list_post_dates($uid, $wall) {
$ret = array();
// Starting with the current month, get the first and last days of every
// month down to and including the month of the first post
/*
* Starting with the current month, get the first and last days of every
* month down to and including the month of the first post
*/
while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
$dyear = intval(substr($dnow,0,4));
$dstart = substr($dnow,0,8) . '01';
@ -2189,8 +2206,9 @@ function list_post_dates($uid, $wall) {
$start_month = datetime_convert('', '', $dstart,'Y-m-d');
$end_month = datetime_convert('', '', $dend,'Y-m-d');
$str = day_translate(datetime_convert('', '', $dnow,'F'));
if (! $ret[$dyear])
if (!$ret[$dyear]) {
$ret[$dyear] = array();
}
$ret[$dyear][] = array($str, $end_month, $start_month);
$dnow = datetime_convert('', '', $dnow . ' -1 month', 'Y-m-d');
}
@ -2201,8 +2219,9 @@ function posted_dates($uid,$wall) {
$dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d');
$dthen = first_post_date($uid, $wall);
if (! $dthen)
if (! $dthen) {
return array();
}
// Set the start and end date to the beginning of the month
$dnow = substr($dnow,0,8).'01';
@ -2227,8 +2246,9 @@ function posted_dates($uid,$wall) {
function posted_date_widget($url, $uid, $wall) {
$o = '';
if (! feature_enabled($uid,'archives'))
if (! feature_enabled($uid, 'archives')) {
return $o;
}
// For former Facebook folks that left because of "timeline"
@ -2236,13 +2256,15 @@ function posted_date_widget($url,$uid,$wall) {
return $o;*/
$visible_years = get_pconfig($uid,'system','archive_visible_years');
if (! $visible_years)
if (! $visible_years) {
$visible_years = 5;
}
$ret = list_post_dates($uid, $wall);
if (! dbm::is_result($ret))
if (! dbm::is_result($ret)) {
return $o;
}
$cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years;
$cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);