Skip to content

Commit

Permalink
Merge branch 'master' into feature/introduce-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mystralkk committed Nov 5, 2016
2 parents c57e5c6 + b6bfe49 commit d7af0ea
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
1 change: 1 addition & 0 deletions public_html/lib-common.php
Expand Up @@ -303,6 +303,7 @@
// Set template class default template variables option
$TEMPLATE_OPTIONS['default_vars']['layout_url'] = $_CONF['layout_url'];
$TEMPLATE_OPTIONS['default_vars']['anonymous_user'] = COM_isAnonUser();
$TEMPLATE_OPTIONS['default_vars']['device_mobile'] = $_DEVICE->is_mobile();

/**
* This provides the ability to set css and javascript.
Expand Down
20 changes: 10 additions & 10 deletions system/classes/template.class.php
Expand Up @@ -66,16 +66,16 @@
$_CONF['path'],
'/' // this entry must always exist and must always be last
),
'incl_phpself_header' => true, // set this to true if your template cache exists within your web server's docroot.
'cache_by_language' => true, // create cache directories for each language. Takes extra space but moves all $LANG variable text directly into the cached file
'cache_for_mobile' => $_CONF['cache_mobile'], // create cache directories for mobile devices. Non mobile devices uses regular directory. If disabled mobile uses regular cache files. Takes extra space
'default_vars' => array( // list of vars found in all templates.
'xhtml' => $xhtml, // Will be reset by lib-common
'site_url' => $_CONF['site_url'],
'site_admin_url' => $_CONF['site_admin_url'],
'layout_url' => $_CONF['layout_url'], // Can be set by lib-common on theme change
'anonymous_user' => true, // Set to false in lib-common if current visitor is logged in

'incl_phpself_header' => true, // set this to true if your template cache exists within your web server's docroot.
'cache_by_language' => true, // create cache directories for each language. Takes extra space but moves all $LANG variable text directly into the cached file
'cache_for_mobile' => $_CONF['cache_mobile'], // create cache directories for mobile devices. Non mobile devices uses regular directory. If disabled mobile uses regular cache files. Takes extra space
'default_vars' => array( // list of vars found in all templates.
'xhtml' => $xhtml, // Will be reset by lib-common
'site_url' => $_CONF['site_url'],
'site_admin_url' => $_CONF['site_admin_url'],
'layout_url' => $_CONF['layout_url'], // Can be set by lib-common on theme change
'anonymous_user' => true, // Set to false in lib-common if current visitor is logged in
'device_mobile' => false // Set to true in lib-common if device found to be considered mobile
),
'hook' => array(),
);
Expand Down
34 changes: 19 additions & 15 deletions system/databases/mysql.class.php
Expand Up @@ -119,9 +119,6 @@ private function _errorlog($msg)
/**
* Connects to the MySQL database server
* This function connects to the MySQL server and returns the connection object
*
* @return object Returns connection object
* @access private
*/
private function _connect()
{
Expand Down Expand Up @@ -158,9 +155,15 @@ private function _connect()
if (($this->_mysql_version >= 50007) &&
function_exists('mysql_set_charset')
) {
@mysql_set_charset('utf8', $this->_db);
$result = @mysql_set_charset('utf8mb4', $this->_db);

if (!$result) {
@mysql_set_charset('utf8', $this->_db);
}
} else {
@mysql_query("SET NAMES 'utf8'", $this->_db);
if (!@mysql_query("SET NAMES 'utf8mb4'", $this->_db)) {
@mysql_query("SET NAMES 'utf8'", $this->_db);
}
}
}

Expand Down Expand Up @@ -347,9 +350,8 @@ public function dbQuery($sql, $ignore_errors = 0)
}

return $result;

} else {
// callee may want to supress printing of errors
// callee may want to suppress printing of errors
if ($ignore_errors) {
return false;
}
Expand Down Expand Up @@ -452,7 +454,7 @@ public function dbDelete($table, $id, $value)
* @param array|string $id additional field name used in where clause
* @param array|string $value additional values used in where clause
* @param bool $suppress_quotes if false it will not use '<value>' in where clause
* @return bool Returns true on success otherwise false
* @return bool Returns true on success otherwise false
*/
public function dbChange($table, $item_to_set, $value_to_set, $id, $value, $suppress_quotes = false)
{
Expand Down Expand Up @@ -482,8 +484,7 @@ public function dbChange($table, $item_to_set, $value_to_set, $id, $value, $supp
next($value);
}
} else {
// error, they both have to be arrays and of the
// same size
// error, they both have to be arrays and of the same size
return false;
}
} else {
Expand All @@ -497,11 +498,13 @@ public function dbChange($table, $item_to_set, $value_to_set, $id, $value, $supp
$this->_errorlog("dbChange sql = $sql");
}

$this->dbQuery($sql);
$result = $this->dbQuery($sql);

if ($this->isVerbose()) {
$this->_errorlog("\n*** Leaving database->dbChange ***");
}

return $result;
}

/**
Expand Down Expand Up @@ -573,7 +576,7 @@ public function dbCount($table, $id = '', $value = '')
* @param string $tableFrom Table to get record from
* @param array|string $id field name(s) to use in where clause
* @param array|string $value Value(s) to use in where clause
* @return bool Returns true on success otherwise false
* @return bool Returns true on success otherwise false
*/
public function dbCopy($table, $fields, $values, $tableFrom, $id, $value)
{
Expand All @@ -600,8 +603,7 @@ public function dbCopy($table, $fields, $values, $tableFrom, $id, $value)
next($value);
}
} else {
// error, they both have to be arrays and of the
// same size
// error, they both have to be arrays and of the same size
return false;
}
} else {
Expand All @@ -610,12 +612,14 @@ public function dbCopy($table, $fields, $values, $tableFrom, $id, $value)
}
}

$this->dbQuery($sql);
$result = $this->dbQuery($sql);
$this->dbDelete($tableFrom, $id, $value);

if ($this->isVerbose()) {
$this->_errorlog("\n*** Leaving database->dbCopy ***");
}

return $result;
}

/**
Expand Down
37 changes: 25 additions & 12 deletions system/databases/mysqli.class.php
Expand Up @@ -49,7 +49,7 @@ class Database
private $_name = '';

/**
* @var sring|string
* @var string
*/
private $_user = '';

Expand Down Expand Up @@ -118,13 +118,14 @@ private function _errorlog($msg)
* Connects to the MySQL database server
* This function connects to the MySQL server and returns the connection object
*
* @return object Returns connection object
* @access private
* @return bool Returns connection object
*/
private function _connect()
{
global $_TABLES, $use_innodb;

$result = true;

if ($this->_verbose) {
$this->_errorlog("\n*** Inside database->_connect ***");
}
Expand All @@ -139,27 +140,38 @@ private function _connect()
$this->_mysql_version = $this->_db->server_version;

// Set the database
$this->_db->select_db($this->_name) || die('error selecting database');
if (!$this->_db->select_db($this->_name)) {
die('error selecting database');
}

if (!($this->_db)) {
if (!$this->_db) {
if ($this->_verbose) {
$this->_errorlog("\n*** Error in database->_connect ***");
}

// damn, got an error.
$this->dbError();
$result = false;
}

if ($this->_mysql_version >= 40100) {
if ($this->_charset === 'utf-8') {
$result = false;

if (method_exists($this->_db, 'set_charset')) {
$result = $this->_db->set_charset('utf8');
}
$result = $this->_db->set_charset('utf8mb4');

if (!$result) {
@$this->_db->query("SET NAMES 'utf8'");
if (!$result) {
$result = $this->_db->set_charset('utf8');
}
} else {
if (!$result) {
$result = @$this->_db->query("SET NAMES 'utf8mb4'");

if (!$result) {
$result = @$this->_db->query("SET NAMES 'utf8'");
}
}
}
}
}
Expand All @@ -182,6 +194,8 @@ private function _connect()
if ($this->_verbose) {
$this->_errorlog("\n***leaving database->_connect***");
}

return $result;
}

/**
Expand Down Expand Up @@ -213,8 +227,7 @@ public function dbTableExists($tableName, $ignoreErrors = 0)
* @param string $errorlogfn Name of the errorlog function
* @param string $charset Character set to use
*/
public function __construct($dbhost, $dbname, $dbuser, $dbpass, $tablePrefix, $errorlogfn = '',
$charset = '')
public function __construct($dbhost, $dbname, $dbuser, $dbpass, $tablePrefix, $errorlogfn = '', $charset = '')
{
$this->_host = $dbhost;
$this->_name = $dbname;
Expand Down Expand Up @@ -714,7 +727,7 @@ public function dbAffectedRows($recordSet)
*
* @param mysqli_result $recordSet The record set to operate on
* @param bool $both get both assoc and numeric indices
* @return array Returns data array of current row from record set
* @return array|false Returns data array of current row from record set
*/
public function dbFetchArray($recordSet, $both = false)
{
Expand Down

0 comments on commit d7af0ea

Please sign in to comment.