Index: trunk/core/kernel/application.php =================================================================== diff -u -r4576 -r4590 --- trunk/core/kernel/application.php (.../application.php) (revision 4576) +++ trunk/core/kernel/application.php (.../application.php) (revision 4590) @@ -85,13 +85,20 @@ var $ModuleInfo = Array(); /** - * Holds DBConnection + * Holds DBConnection (depricated, use Conn instead) * * @var kDBConnection */ var $DB; /** + * Holds DBConnection + * + * @var kDBConnection + */ + var $Conn = null; + + /** * Maintains list of user-defined error handlers * * @var Array @@ -187,22 +194,24 @@ if($error_handler) $this->errorHandlers[] = $error_handler; } - $this->DB = new kDBConnection(SQL_TYPE, Array(&$this,'handleSQLError') ); - $this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); - $this->DB->debugMode = $this->isDebugMode(); + $this->Conn = new kDBConnection(SQL_TYPE, Array(&$this, 'handleSQLError') ); + $this->Conn->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB); + $this->Conn->debugMode = $this->isDebugMode(); - $this->refreshModuleInfo(); - $this->ConfigHash = $this->DB->GetCol('SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'ConfigurationValues', 'VariableName'); +// $this->DB =& $this->Conn; // for backwards compatibility + + $this->ConfigHash = $this->Conn->GetCol('SELECT VariableValue, VariableName FROM '.TABLE_PREFIX.'ConfigurationValues', 'VariableName'); $rewrite_on = $this->ConfigValue('UseModRewrite'); $admin_on = getArrayValue($_REQUEST, 'admin') || $this->IsAdmin(); define('MOD_REWRITE', $rewrite_on && !$admin_on ? 1 : 0); $this->Factory = new kFactory(); - + $this->registerDefaultClasses(); + $this->refreshModuleInfo(); $this->SetDefaultConstants(); - + // 1. to read configs before doing any recallObject (called from "SetDefaultConstants" anyway) $config_reader =& $this->recallObject('kUnitConfigReader'); @@ -242,7 +251,27 @@ function refreshModuleInfo() { - $this->ModuleInfo = $this->DB->Query('SELECT * FROM '.TABLE_PREFIX.'Modules ORDER BY LoadOrder', 'Name'); + $where_clause = Array('Loaded = 1'); + + // admin only: filter licensed modules + if ($this->IsAdmin()) { + $modules_helper =& $this->recallObject('ModulesHelper'); + $modules = $modules_helper->checkLogin(); + if ($modules) { + foreach ($modules as $module_index => $module) { + $modules[$module_index] = $this->Conn->qstr($module); + } + $where_clause[] = 'Name IN ('.implode(',', $modules).')'; + } + } + + // front and admin: filter enabled modules + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'Modules + WHERE '.implode(' AND ', $where_clause).' + ORDER BY LoadOrder'; + + $this->ModuleInfo = $this->Conn->Query($sql, 'Name'); } /** @@ -258,7 +287,7 @@ $sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE Enabled = 1'; - $language_ids = $this->DB->GetCol($sql); + $language_ids = $this->Conn->GetCol($sql); } if (!$language_id || !in_array($language_id, $language_ids)) { @@ -280,7 +309,7 @@ $sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE Enabled = 1'; - $theme_ids = $this->DB->GetCol($sql); + $theme_ids = $this->Conn->GetCol($sql); } if (!$theme_id || !in_array($theme_id, $theme_ids)) { @@ -300,7 +329,7 @@ $sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE (PrimaryLang = 1) AND (Enabled = 1)'; - $language_id = $this->DB->GetOne($sql); + $language_id = $this->Conn->GetOne($sql); return $language_id; } @@ -320,7 +349,7 @@ $sql = 'SELECT '.$id_field.' FROM '.$table.' WHERE (PrimaryTheme = 1) AND (Enabled = 1)'; - $theme_id = $this->DB->GetOne($sql); + $theme_id = $this->Conn->GetOne($sql); } return $theme_id; } @@ -329,7 +358,7 @@ { if ($this->isModuleEnabled('In-Commerce')) { $table = $this->getUnitOption('curr', 'TableName'); - return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'); + return $this->Conn->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1'); } else { return 'USD'; @@ -423,17 +452,17 @@ // this allows to save 2 sql queries for each category $sql = 'SELECT NamedParentPath, CachedCategoryTemplate, CachedItemTemplate FROM '.$table.' - WHERE '.$id_field.' = '.$this->DB->qstr($id); - $category_data = $this->DB->GetRow($sql); + WHERE '.$id_field.' = '.$this->Conn->qstr($id); + $category_data = $this->Conn->GetRow($sql); $filename = $category_data['NamedParentPath']; $this->setCache('category_templates', $id, $category_data['CachedCategoryTemplate']); $this->setCache('item_templates', $id, $category_data['CachedItemTemplate']); } else { $sql = 'SELECT Filename FROM '.$table.' - WHERE '.$id_field.' = '.$this->DB->qstr($id); - $filename = $this->DB->GetOne($sql); + WHERE '.$id_field.' = '.$this->Conn->qstr($id); + $filename = $this->Conn->GetOne($sql); } $this->setCache('filenames', $prefix.'_'.$id, $filename); } @@ -611,7 +640,7 @@ /*if (constOn('EXPERIMENTAL_PRE_PARSE')) { $data = serialize($this->PreParsedCache); - $this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.adodb_mktime().')'); + $this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->Conn->qstr($data).', '.adodb_mktime().')'); }*/ } @@ -819,7 +848,7 @@ */ function &GetADODBConnection() { - return $this->DB; + return $this->Conn; } function ParseBlock($params,$pass_params=0,$as_template=false) @@ -1319,7 +1348,6 @@ function ConfigValue($name) { return getArrayValue($this->ConfigHash, $name); -// return $this->DB->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName = '.$this->DB->qstr($name) ); } /** @@ -1684,15 +1712,15 @@ { $table_name = TABLE_PREFIX.'IdGenerator'; - $this->DB->Query('LOCK TABLES '.$table_name.' WRITE'); - $this->DB->Query('UPDATE '.$table_name.' SET lastid = lastid + 1'); - $id = $this->DB->GetOne('SELECT lastid FROM '.$table_name); + $this->Conn->Query('LOCK TABLES '.$table_name.' WRITE'); + $this->Conn->Query('UPDATE '.$table_name.' SET lastid = lastid + 1'); + $id = $this->Conn->GetOne('SELECT lastid FROM '.$table_name); if($id === false) { - $this->DB->Query('INSERT INTO '.$table_name.' (lastid) VALUES (2)'); + $this->Conn->Query('INSERT INTO '.$table_name.' (lastid) VALUES (2)'); $id = 2; } - $this->DB->Query('UNLOCK TABLES'); + $this->Conn->Query('UNLOCK TABLES'); return $id - 1; } @@ -1764,7 +1792,7 @@ } else { $sql = 'SELECT ParentPath FROM '.$this->getUnitOption('c', 'TableName').' WHERE CategoryId = '.$cat_id; - $cat_hierarchy = $this->DB->GetOne($sql); + $cat_hierarchy = $this->Conn->GetOne($sql); $cat_hierarchy = explode('|', $cat_hierarchy); array_shift($cat_hierarchy); array_pop($cat_hierarchy); @@ -1779,7 +1807,7 @@ WHERE Permission = "'.$name.'" AND CatId = '.$category_id.' AND GroupId IN ('.$groups.')'; - $res = $this->DB->GetOne($sql); + $res = $this->Conn->GetOne($sql); if ($res !== false) { return $res; } @@ -1819,7 +1847,7 @@ */ function isModuleEnabled($module_name) { - return $this->findModule('Name', $module_name, 'Loaded'); + return $this->findModule('Name', $module_name); }