mighty_enable) && $config->mighty_enable && isset($config->mighty[0][0])) { // Remove legacy if ($config->dbtype == 'mightysites') { $config->dbtype = 'mysql'; } if (version_compare(JVERSION, '3.0', 'ge')) { require_once(JPATH_SITE.'/libraries/joomla/database/database.php'); require_once(JPATH_SITE.'/libraries/joomla/database/driver.php'); require_once(JPATH_SITE.'/libraries/joomla/database/driver/'.$config->dbtype.'.php'); class_alias('JDatabaseDriver'.ucfirst($config->dbtype), 'JDatabaseMightysitesBase'); } else { require_once(JPATH_SITE.'/libraries/joomla/database/database.php'); require_once(JPATH_SITE.'/libraries/joomla/database/database/'.$config->dbtype.'.php'); class_alias('JDatabase'.$config->dbtype, 'JDatabaseMightysitesBase'); } class JDatabaseMightysites extends JDatabaseMightysitesBase { public $count = null; public $log = null; public $mighty = null; public function __construct($options) { parent::__construct($options); $this->mighty = JFactory::getConfig()->get('mighty'); // stupid IIS uses \r\n if (PHP_EOL === "\r\n" && isset($this->mighty[0][0])) { foreach($this->mighty[0] as &$tmp) { $tmp = str_replace('\n', '\r\n', $tmp); } } } // Not here, baby! public function __destruct() {} public function replacePrefix($sql, $prefix = '#__') { // We need to allow parent usual method if (isset($GLOBALS['no_mightysharing'])) { return parent::replacePrefix($sql, $prefix); } // Initialize variables. $escaped = false; $startPos = 0; $quoteChar = ''; $literal = ''; $sql = trim($sql); $n = strlen($sql); while ($startPos < $n) { $ip = strpos($sql, $prefix, $startPos); if ($ip === false) { break; } $j = strpos($sql, "'", $startPos); $k = strpos($sql, '"', $startPos); if (($k !== false) && (($k < $j) || ($j === false))) { $quoteChar = '"'; $j = $k; } else { $quoteChar = "'"; } if ($j === false) { $j = $n; } $literal .= str_replace($prefix, $this->tablePrefix, preg_replace($this->mighty[0], $this->mighty[1], substr($sql, $startPos, $j - $startPos).' ')); $startPos = $j; $j = $startPos + 1; if ($j >= $n) { break; } // quote comes first, find end of quote while (true) { $k = strpos($sql, $quoteChar, $j); $escaped = false; if ($k === false) { break; } $l = $k - 1; while ($l >= 0 && $sql{$l} == '\\') { $l--; $escaped = !$escaped; } if ($escaped) { $j = $k + 1; continue; } break; } if ($k === false) { // error in the query - no end quote; ignore it break; } $literal .= substr($sql, $startPos, $k - $startPos + 1); $startPos = $k + 1; } if ($startPos < $n) { $literal .= substr($sql, $startPos, $n - $startPos); } return $literal; } public static function changeHandler() { $db = JFactory::getDBO(); $config = JFactory::getConfig(); $debug = $config->get('debug'); $debug ? $log = $db->getLog() : null; JFactory::$database = new JDatabaseMightysites(array( 'driver' => 'mightysites', 'host' => $config->get('host'), 'user' => $config->get('user'), 'password' => $config->get('password'), 'database' => $config->get('db'), 'prefix' => $config->get('dbprefix') )); if ($debug) { $db = JFactory::getDBO(); $db->setDebug(($debug == 0) ? false : true); $db->count = sizeof($log); $db->log = $log; } } } JDatabaseMightysites::changeHandler(); } // Overload format if (defined('JVERSION')) { if (version_compare(JVERSION, '3.3', 'ge')) { require_once(dirname(__FILE__).'/format_33.php'); } else if (version_compare(JVERSION, '3.0', 'ge')) { require_once(dirname(__FILE__).'/format_30.php'); } else { require_once(dirname(__FILE__).'/format_25.php'); } }