added spaces + some curly braces + some usage of dbm::is_result()

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-04-04 19:47:32 +02:00 committed by Roland Häder
parent 0c2c221e50
commit f66c5c6823
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
4 changed files with 63 additions and 58 deletions

View file

@ -14,18 +14,19 @@ $objDDDBLResultHandler = new DataObjectPool('Result-Handler');
* *
**/ **/
$cloPDOStatementResultHandler = function(Queue $objQueue) { $cloPDOStatementResultHandler = function(Queue $objQueue) {
$objPDO = $objQueue->getState()->get('PDOStatement'); $objPDO = $objQueue->getState()->get('PDOStatement');
$objQueue->getState()->update(array('result' => $objPDO)); $objQueue->getState()->update(array('result' => $objPDO));
# delete handler which closes the PDOStatement-cursor /*
# this will be done manual if using this handler * delete handler which closes the PDOStatement-cursor
* this will be done manual if using this handler
*/
$objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION); $objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION);
}; };
$objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementResultHandler)); $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementResultHandler));
if (! class_exists('dba')) {
/** /**
* *
* MySQL database class * MySQL database class
@ -36,8 +37,6 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR
* the debugging stream is safe to view within both terminals and web pages. * the debugging stream is safe to view within both terminals and web pages.
* *
*/ */
if (! class_exists('dba')) {
class dba { class dba {
private $debug = 0; private $debug = 0;
@ -147,8 +146,7 @@ class dba {
$a->save_timestamp($stamp1, "database"); $a->save_timestamp($stamp1, "database");
/// @TODO really check $a->config for 'system'? it is very generic and should be there /// @TODO really check $a->config for 'system'? it is very generic and should be there
if (x($a->config, 'system') && x($a->config['system'], 'db_log')) { if (x($a->config, 'system') && x($a->config['system'], 'db_log') && ($duration > $a->config["system"]["db_loglimit"])) {
if (($duration > $a->config["system"]["db_loglimit"])) {
$duration = round($duration, 3); $duration = round($duration, 3);
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
@file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t". @file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t".
@ -156,7 +154,6 @@ class dba {
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t". $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
substr($sql, 0, 2000)."\n", FILE_APPEND); substr($sql, 0, 2000)."\n", FILE_APPEND);
} }
}
if ($intErrorCode) { if ($intErrorCode) {
$this->error = $intErrorCode; $this->error = $intErrorCode;
@ -202,8 +199,11 @@ class dba {
} }
if ($onlyquery) { if ($onlyquery) {
$this->result = $r; # this will store an PDOStatement Object in result // this will store an PDOStatement Object in result
$this->result->execute(); # execute the Statement, to get its result $this->result = $r;
// execute the Statement, to get its result
$this->result->execute();
return true; return true;
} }
@ -262,7 +262,8 @@ function printable($s) {
return $s; return $s;
}} }}
// Procedural functions // --- Procedural functions ---
if (! function_exists('dbg')) { if (! function_exists('dbg')) {
function dbg($state) { function dbg($state) {
global $db; global $db;
@ -273,14 +274,16 @@ function dbg($state) {
if (! function_exists('dbesc')) { if (! function_exists('dbesc')) {
function dbesc($str) { function dbesc($str) {
global $db; global $db;
if ($db && $db->connected)
return($db->escape($str)); if ($db && $db->connected) {
else return $db->escape($str);
return(str_replace("'","\\'",$str)); } else {
return str_replace("'","\\'",$str);
}
}} }}
if (! function_exists('q')) { if (! function_exists('q')) {
/** /*
* Function: q($sql,$args); * Function: q($sql,$args);
* Description: execute SQL query with printf style args. * Description: execute SQL query with printf style args.
* Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", * Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
@ -301,23 +304,19 @@ function q($sql) {
return $db->q($stmt); return $db->q($stmt);
} }
/** /*
*
* This will happen occasionally trying to store the * This will happen occasionally trying to store the
* session data after abnormal program termination * session data after abnormal program termination
*
*/ */
logger('dba: no database: ' . print_r($args,true)); logger('dba: no database: ' . print_r($args,true));
return false; return false;
}} }}
if (! function_exists('dbq')) { if (! function_exists('dbq')) {
/** /*
* Raw db query, no arguments * Raw db query, no arguments
*/ */
function dbq($sql) { function dbq($sql) {
global $db; global $db;
if ($db && $db->connected) { if ($db && $db->connected) {
$ret = $db->q($sql); $ret = $db->q($sql);
@ -327,15 +326,14 @@ function dbq($sql) {
return $ret; return $ret;
}} }}
if (! function_exists('dbesc_array_cb')) {
function dbesc_array_cb(&$item, $key) {
/* /*
* Caller is responsible for ensuring that any integer arguments to * Caller is responsible for ensuring that any integer arguments to
* dbesc_array are actually integers and not malformed strings containing * dbesc_array are actually integers and not malformed strings containing
* SQL injection vectors. All integer array elements should be specifically * SQL injection vectors. All integer array elements should be specifically
* cast to int to avoid trouble. * cast to int to avoid trouble.
*/ */
if (! function_exists('dbesc_array_cb')) {
function dbesc_array_cb(&$item, $key) {
if (is_string($item)) { if (is_string($item)) {
$item = dbesc($item); $item = dbesc($item);
} }

View file

@ -26,7 +26,7 @@ function convert_to_innodb() {
$sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME'])); $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
echo $sql."\n"; echo $sql."\n";
$result = @$db->q($sql); $result = $db->q($sql);
if (!dbm::is_result($result)) { if (!dbm::is_result($result)) {
print_update_error($db, $sql); print_update_error($db, $sql);
} }
@ -81,6 +81,7 @@ function update_fail($update_id, $error_message) {
/* /*
@TODO deprecated code?
$email_tpl = get_intltext_template("update_fail_eml.tpl"); $email_tpl = get_intltext_template("update_fail_eml.tpl");
$email_msg = replace_macros($email_tpl, array( $email_msg = replace_macros($email_tpl, array(
'$sitename' => $a->config['sitename'], '$sitename' => $a->config['sitename'],
@ -1750,8 +1751,8 @@ function dbstructure_run(&$argv, &$argc) {
} }
if (is_null($db)) { if (is_null($db)) {
@include(".htconfig.php"); @include ".htconfig.php";
require_once("include/dba.php"); require_once "include/dba.php";
$db = new dba($db_host, $db_user, $db_pass, $db_data); $db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);
} }

View file

@ -932,18 +932,20 @@ class Diaspora {
logger("defining user ".$contact["nick"]." as friend"); logger("defining user ".$contact["nick"]." as friend");
} }
// We don't seem to like that person // Is this contact wanted?
if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) { if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) {
// Maybe blocked, don't accept.
return false; return false;
// We are following this person? Then it is okay // Is this person being followed?
} elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) { } elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) {
// Yes, then it is fine.
return true; return true;
// Is it a post to a community? That's good // Is it a post to a community?
} elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) { } elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) {
// That's good
return true; return true;
} } elseif (($importer["uid"] == 0) || $is_comment) {
// Messages for the global users and comments are always accepted // Messages for the global users and comments are always accepted
if (($importer["uid"] == 0) || $is_comment) {
return true; return true;
} }

View file

@ -853,18 +853,22 @@ function widget_events() {
return; return;
} }
// Cal logged in user (test permission at foreign profile page) /*
// If the $owner uid is available we know it is part of one of the profile pages (like /cal) * Cal logged in user (test permission at foreign profile page)
// So we have to test if if it's the own profile page of the logged in user * If the $owner uid is available we know it is part of one of the profile pages (like /cal)
// or a foreign one. For foreign profile pages we need to check if the feature * So we have to test if if it's the own profile page of the logged in user
// for exporting the cal is enabled (otherwise the widget would appear for logged in users * or a foreign one. For foreign profile pages we need to check if the feature
// on foreigen profile pages even if the widget is disabled) * for exporting the cal is enabled (otherwise the widget would appear for logged in users
* on foreigen profile pages even if the widget is disabled)
*/
if (intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) { if (intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) {
return; return;
} }
// If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and /*
// export feature isn't enabled * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
* export feature isn't enabled
*/
if (intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) { if (intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) {
return; return;
} }