Continued with coding convention:
- added curly braces around conditional code blocks - added space between if/foreach/... and brace - rewrote a code block so if dbm::is_result() fails it will abort, else the id is fetched from INSERT statement - made some SQL keywords upper-cased and added back-ticks to columns/table names Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
parent
70a042fd04
commit
4edc73486e
18 changed files with 82 additions and 67 deletions
|
@ -34,7 +34,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
|
|||
call_hooks($a->module . '_pre_' . $selname, $arr);
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if((is_array($preselected)) && in_array($rr['id'], $preselected))
|
||||
$selected = " selected=\"selected\" ";
|
||||
else
|
||||
|
@ -145,7 +145,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
|
|||
call_hooks($a->module . '_pre_' . $selname, $arr);
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if((is_array($preselected)) && in_array($rr['id'], $preselected))
|
||||
$selected = " selected=\"selected\" ";
|
||||
else
|
||||
|
@ -221,16 +221,20 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
|
|||
$receiverlist = array();
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
if((is_array($preselected)) && in_array($rr['id'], $preselected))
|
||||
foreach ($r as $rr) {
|
||||
if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
|
||||
$selected = " selected=\"selected\" ";
|
||||
else
|
||||
}
|
||||
else {
|
||||
$selected = '';
|
||||
}
|
||||
|
||||
if($privmail)
|
||||
if ($privmail) {
|
||||
$trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
|
||||
else
|
||||
}
|
||||
else {
|
||||
$trimmed = mb_substr($rr['name'],0,20);
|
||||
}
|
||||
|
||||
$receiverlist[] = $trimmed;
|
||||
|
||||
|
@ -260,7 +264,7 @@ function prune_deadguys($arr) {
|
|||
return $arr;
|
||||
$str = dbesc(implode(',',$arr));
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
|
||||
if($r) {
|
||||
if ($r) {
|
||||
$ret = array();
|
||||
foreach($r as $rr)
|
||||
$ret[] = intval($rr['id']);
|
||||
|
@ -554,7 +558,7 @@ function acl_lookup(&$a, $out_type = 'json') {
|
|||
// autocomplete for global contact search (e.g. navbar search)
|
||||
$r = navbar_complete($a);
|
||||
$contacts = array();
|
||||
if($r) {
|
||||
if ($r) {
|
||||
foreach($r as $g) {
|
||||
$contacts[] = array(
|
||||
"photo" => proxy_url($g['photo'], false, PROXY_SIZE_MICRO),
|
||||
|
|
|
@ -3068,8 +3068,8 @@
|
|||
'image/gif' => 'gif'
|
||||
);
|
||||
$data = array('photo'=>array());
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
$photo = array();
|
||||
$photo['id'] = $rr['resource-id'];
|
||||
$photo['album'] = $rr['album'];
|
||||
|
|
|
@ -343,7 +343,7 @@ function bb_replace_images($body, $images) {
|
|||
$newbody = $body;
|
||||
|
||||
$cnt = 0;
|
||||
foreach($images as $image) {
|
||||
foreach ($images as $image) {
|
||||
// We're depending on the property of 'foreach' (specified on the PHP website) that
|
||||
// it loops over the array starting from the first element and going sequentially
|
||||
// to the last element
|
||||
|
|
|
@ -13,7 +13,7 @@ function contact_profile_assign($current,$foreign_net) {
|
|||
intval($_SESSION['uid']));
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
$selected = (($rr['id'] == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
|
||||
}
|
||||
|
|
|
@ -97,9 +97,11 @@ function networks_widget($baseurl,$selected = '') {
|
|||
$nets = array();
|
||||
if (dbm::is_result($r)) {
|
||||
require_once('include/contact_selectors.php');
|
||||
foreach($r as $rr) {
|
||||
if($rr['network'])
|
||||
$nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
|
||||
foreach ($r as $rr) {
|
||||
/// @TODO If 'network' is not there, this triggers an E_NOTICE
|
||||
if ($rr['network']) {
|
||||
$nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ function item_redir_and_replace_images($body, $images, $cid) {
|
|||
$newbody .= $origbody;
|
||||
|
||||
$cnt = 0;
|
||||
foreach($images as $image) {
|
||||
foreach ($images as $image) {
|
||||
// We're depending on the property of 'foreach' (specified on the PHP website) that
|
||||
// it loops over the array starting from the first element and going sequentially
|
||||
// to the last element
|
||||
|
|
|
@ -553,7 +553,7 @@ function update_contact_birthdays() {
|
|||
|
||||
$r = q("SELECT * FROM contact WHERE `bd` != '' AND `bd` != '0000-00-00' AND SUBSTRING(`bd`,1,4) != `bdyear` ");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
|
||||
logger('update_contact_birthday: ' . $rr['bd']);
|
||||
|
||||
|
|
|
@ -319,8 +319,8 @@ class diaspora {
|
|||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc($msg["author"])
|
||||
);
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
logger("delivering to: ".$rr["username"]);
|
||||
self::dispatch($rr,$msg);
|
||||
}
|
||||
|
@ -806,7 +806,7 @@ class diaspora {
|
|||
dbesc($guid)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
if ($r) {
|
||||
logger("message ".$guid." already exists for user ".$uid);
|
||||
return $r[0]["id"];
|
||||
}
|
||||
|
@ -1577,7 +1577,7 @@ class diaspora {
|
|||
dbesc($message_uri),
|
||||
intval($importer["uid"])
|
||||
);
|
||||
if($r) {
|
||||
if ($r) {
|
||||
logger("duplicate message already delivered.", LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
@ -2022,7 +2022,7 @@ class diaspora {
|
|||
FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
|
||||
dbesc($guid));
|
||||
|
||||
if($r) {
|
||||
if ($r) {
|
||||
logger("reshared message ".$guid." already exists on system.");
|
||||
|
||||
// Maybe it is already a reshared item?
|
||||
|
@ -2623,7 +2623,7 @@ class diaspora {
|
|||
|
||||
logger("transmit: ".$logid."-".$guid." returns: ".$return_code);
|
||||
|
||||
if(!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) {
|
||||
if (!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) {
|
||||
logger("queue message");
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE `cid` = %d AND `network` = '%s' AND `content` = '%s' AND `batch` = %d LIMIT 1",
|
||||
|
@ -2632,7 +2632,7 @@ class diaspora {
|
|||
dbesc($slap),
|
||||
intval($public_batch)
|
||||
);
|
||||
if($r) {
|
||||
if ($r) {
|
||||
logger("add_to_queue ignored - identical item already in queue");
|
||||
} else {
|
||||
// queue message for redelivery
|
||||
|
|
|
@ -40,7 +40,7 @@ function expire_run(&$argv, &$argc){
|
|||
|
||||
$r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG);
|
||||
item_expire($rr['uid'],$rr['expire']);
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ function group_rmv($uid,$name) {
|
|||
$r = q("SELECT def_gid, allow_gid, deny_gid FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if($r) {
|
||||
if ($r) {
|
||||
$user_info = $r[0];
|
||||
$change = false;
|
||||
|
||||
|
@ -199,7 +199,7 @@ function mini_group_select($uid,$gid = 0, $label = "") {
|
|||
);
|
||||
$grps[] = array('name' => '', 'id' => '0', 'selected' => '');
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
$grps[] = array('name' => $rr['name'], 'id' => $rr['id'], 'selected' => (($gid == $rr['id']) ? 'true' : ''));
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
}
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
|
||||
|
||||
if ($editmode == "full") {
|
||||
|
|
|
@ -294,7 +294,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
|
||||
if (dbm::is_result($r)) {
|
||||
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
$profile['menu']['entries'][] = array(
|
||||
'photo' => $rr['thumb'],
|
||||
'id' => $rr['id'],
|
||||
|
@ -469,7 +469,7 @@ function get_birthdays() {
|
|||
$cids = array();
|
||||
|
||||
$istoday = false;
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if(strlen($rr['name']))
|
||||
$total ++;
|
||||
if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now))
|
||||
|
@ -549,7 +549,7 @@ function get_events() {
|
|||
if (dbm::is_result($r)) {
|
||||
$now = strtotime('now');
|
||||
$istoday = false;
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if(strlen($rr['name']))
|
||||
$total ++;
|
||||
|
||||
|
|
|
@ -130,12 +130,13 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
|
|||
|
||||
$match = null;
|
||||
|
||||
if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
|
||||
if (preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
|
||||
$images = $match[1];
|
||||
if(count($images)) {
|
||||
foreach($images as $image) {
|
||||
if(! stristr($image,App::get_baseurl() . '/photo/'))
|
||||
if (count($images)) {
|
||||
foreach ($images as $image) {
|
||||
if (! stristr($image,App::get_baseurl() . '/photo/')) {
|
||||
continue;
|
||||
}
|
||||
$image_uri = substr($image,strrpos($image,'/') + 1);
|
||||
$image_uri = substr($image_uri,0, strpos($image_uri,'-'));
|
||||
$r = q("UPDATE `photo` SET `allow_cid` = '%s'
|
||||
|
@ -149,25 +150,25 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
|
|||
}
|
||||
}
|
||||
|
||||
if($post_id) {
|
||||
if ($post_id) {
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id);
|
||||
return intval($post_id);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return -3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
|
||||
|
||||
if(! $recipient) return -1;
|
||||
if (! $recipient) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(! strlen($subject))
|
||||
if (! strlen($subject)) {
|
||||
$subject = t('[no subject]');
|
||||
}
|
||||
|
||||
$guid = get_guid(32);
|
||||
$uri = 'urn:X-dfrn:' . App::get_baseurl() . ':' . local_user() . ':' . $guid;
|
||||
|
@ -179,8 +180,9 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
|
|||
|
||||
$me = probe_url($replyto);
|
||||
|
||||
if(! $me['name'])
|
||||
if (! $me['name']) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
$conv_guid = get_guid(32);
|
||||
|
||||
|
@ -193,7 +195,7 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
|
|||
|
||||
$handles = $recip_handle . ';' . $sender_handle;
|
||||
|
||||
$r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
$r = q("INSERT INTO `conv` (`uid`,`guid`,`creator`,`created`,`updated`,`subject`,`recips`) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
|
||||
intval($recipient['uid']),
|
||||
dbesc($conv_guid),
|
||||
dbesc($sender_handle),
|
||||
|
@ -203,18 +205,19 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
|
|||
dbesc($handles)
|
||||
);
|
||||
|
||||
$r = q("select * from conv where guid = '%s' and uid = %d limit 1",
|
||||
$r = q("SELECT * FROM `conv` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($conv_guid),
|
||||
intval($recipient['uid'])
|
||||
);
|
||||
if (dbm::is_result($r))
|
||||
$convid = $r[0]['id'];
|
||||
|
||||
if(! $convid) {
|
||||
|
||||
if (! dbm::is_result($r)) {
|
||||
logger('send message: conversation not found.');
|
||||
return -4;
|
||||
}
|
||||
|
||||
$convid = $r[0]['id'];
|
||||
|
||||
$r = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
|
||||
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`)
|
||||
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
|
||||
|
|
|
@ -598,7 +598,7 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
// throw everything into the queue in case we get killed
|
||||
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if((! $mail) && (! $fsuggest) && (! $followup)) {
|
||||
q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)
|
||||
ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d",
|
||||
|
@ -608,7 +608,7 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
|
||||
// except for Diaspora batch jobs
|
||||
// Don't deliver to folks who have already been delivered to
|
||||
|
|
|
@ -187,8 +187,9 @@ function load_hooks() {
|
|||
$a = get_app();
|
||||
$a->hooks = array();
|
||||
$r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC, `file`");
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
if(! array_key_exists($rr['hook'],$a->hooks))
|
||||
$a->hooks[$rr['hook']] = array();
|
||||
$a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']);
|
||||
|
|
|
@ -76,16 +76,19 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
load_config('system');
|
||||
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540))
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
||||
if($argc > 1)
|
||||
if ($argc > 1) {
|
||||
$pubsubpublish_id = intval($argv[1]);
|
||||
}
|
||||
else {
|
||||
// We'll push to each subscriber that has push > 0,
|
||||
// i.e. there has been an update (set in notifier.php).
|
||||
|
@ -95,10 +98,11 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
$interval = Config::get("system", "delivery_interval", 2);
|
||||
|
||||
// If we are using the worker we don't need a delivery interval
|
||||
if (get_config("system", "worker"))
|
||||
if (get_config("system", "worker")) {
|
||||
$interval = false;
|
||||
}
|
||||
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]);
|
||||
|
||||
|
|
|
@ -58,20 +58,21 @@ function queue_run(&$argv, &$argc){
|
|||
$interval = false;
|
||||
|
||||
$r = q("select * from deliverq where 1");
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
logger('queue: deliverq');
|
||||
proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']);
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
if($interval) {
|
||||
time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
|
||||
INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
|
||||
WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
if($r) {
|
||||
foreach($r as $rr) {
|
||||
if ($r) {
|
||||
foreach ($r as $rr) {
|
||||
logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
|
||||
logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
|
||||
}
|
||||
|
|
|
@ -912,7 +912,7 @@ function contact_block() {
|
|||
if (dbm::is_result($r)) {
|
||||
$contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total);
|
||||
$micropro = Array();
|
||||
foreach($r as $rr) {
|
||||
foreach ($r as $rr) {
|
||||
$micropro[] = micropro($rr,true,'mpfriend');
|
||||
}
|
||||
}
|
||||
|
@ -1717,7 +1717,7 @@ function bb_translate_video($s) {
|
|||
|
||||
$matches = null;
|
||||
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
|
||||
if($r) {
|
||||
if ($r) {
|
||||
foreach($matches as $mtch) {
|
||||
if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
|
||||
$s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
|
||||
|
|
|
@ -216,7 +216,7 @@ function create_user($arr) {
|
|||
dbesc($default_service_class)
|
||||
);
|
||||
|
||||
if($r) {
|
||||
if ($r) {
|
||||
$r = q("SELECT * FROM `user`
|
||||
WHERE `username` = '%s' AND `password` = '%s' LIMIT 1",
|
||||
dbesc($username),
|
||||
|
|
Loading…
Reference in a new issue