本文整理汇总了PHP中SqlUtility::splitMySqlFile方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlUtility::splitMySqlFile方法的具体用法?PHP SqlUtility::splitMySqlFile怎么用?PHP SqlUtility::splitMySqlFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlUtility
的用法示例。
在下文中一共展示了SqlUtility::splitMySqlFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queryFromFile
function queryFromFile($sql_file_path)
{
$tables = array();
if (!file_exists($sql_file_path)) {
return false;
}
$sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)));
SqlUtility::splitMySqlFile($pieces, $sql_query);
$this->db->connect();
foreach ($pieces as $piece) {
$piece = trim($piece);
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $this->db->prefix());
if ($prefixed_query != false) {
$table = $this->db->prefix($prefixed_query[4]);
if ($prefixed_query[1] == 'CREATE TABLE') {
if ($this->db->query($prefixed_query[0]) != false) {
if (!isset($this->s_tables['create'][$table])) {
$this->s_tables['create'][$table] = 1;
}
} else {
if (!isset($this->f_tables['create'][$table])) {
$this->f_tables['create'][$table] = 1;
}
}
} elseif ($prefixed_query[1] == 'INSERT INTO') {
if ($this->db->query($prefixed_query[0]) != false) {
if (!isset($this->s_tables['insert'][$table])) {
$this->s_tables['insert'][$table] = 1;
} else {
$this->s_tables['insert'][$table]++;
}
} else {
if (!isset($this->f_tables['insert'][$table])) {
$this->f_tables['insert'][$table] = 1;
} else {
$this->f_tables['insert'][$table]++;
}
}
} elseif ($prefixed_query[1] == 'ALTER TABLE') {
if ($this->db->query($prefixed_query[0]) != false) {
if (!isset($this->s_tables['alter'][$table])) {
$this->s_tables['alter'][$table] = 1;
}
} else {
if (!isset($this->s_tables['alter'][$table])) {
$this->f_tables['alter'][$table] = 1;
}
}
} elseif ($prefixed_query[1] == 'DROP TABLE') {
if ($this->db->query('DROP TABLE ' . $table) != false) {
if (!isset($this->s_tables['drop'][$table])) {
$this->s_tables['drop'][$table] = 1;
}
} else {
if (!isset($this->s_tables['drop'][$table])) {
$this->f_tables['drop'][$table] = 1;
}
}
}
}
}
return true;
}
示例2: queryFromFile
/**
* perform queries from SQL dump file in a batch
*
* @param string $file file path to an SQL dump file
*
* @return bool FALSE if failed reading SQL file or
* TRUE if the file has been read and queries executed
*/
public function queryFromFile($file)
{
if (false !== ($fp = fopen($file, 'r'))) {
$sql_queries = trim(fread($fp, filesize($file)));
\SqlUtility::splitMySqlFile($pieces, $sql_queries);
foreach ($pieces as $query) {
$prefixed_query = \SqlUtility::prefixQuery(trim($query), $this->prefix());
if ($prefixed_query != false) {
$this->query($prefixed_query[0]);
}
}
return true;
}
return false;
}
示例3: bulletin_oninstall_base
function bulletin_oninstall_base($module, $mydirname)
{
// transations on module install
global $ret;
$db =& Database::getInstance();
$mid = $module->getVar('mid');
// for Cube 2.1
if (defined('XOOPS_CUBE_LEGACY')) {
$isCube = true;
$root =& XCube_Root::getSingleton();
$root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'bulletin_message_append_oninstall');
$ret = array();
} else {
$isCube = false;
if (!is_array($ret)) {
$ret = array();
}
}
// transations on module installation
$bulletin_posting_permissions = array(1, 2, 3, 7);
$gperm_handler = xoops_gethandler('groupperm');
foreach ($bulletin_posting_permissions as $itemid) {
$gperm =& $gperm_handler->create();
$gperm->setVar('gperm_groupid', 1);
$gperm->setVar('gperm_name', 'bulletin_permit');
$gperm->setVar('gperm_modid', $mid);
$gperm->setVar('gperm_itemid', $itemid);
$gperm_handler->insert($gperm);
}
// TABLES (loading mysql.sql)
$sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
$prefix_mod = $db->prefix() . '_' . $mydirname;
if (file_exists($sql_file_path)) {
$ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...<br />";
if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
$sqlutil = new OldSqlUtility();
} else {
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sqlutil = new SqlUtility();
}
$sql_query = trim(file_get_contents($sql_file_path));
$sqlutil->splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
$prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
if (!$prefixed_query) {
$ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
return false;
}
if (!$db->query($prefixed_query[0])) {
$ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
var_dump($db->error());
return false;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$ret[] = ' Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
$created_tables[] = $prefixed_query[4];
} else {
$ret[] = ' Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
}
}
}
}
// TEMPLATES
$tplfile_handler =& xoops_gethandler('tplfile');
$tpl_path = dirname(__FILE__) . '/templates';
if ($handler = @opendir($tpl_path . '/')) {
while (($file = readdir($handler)) !== false) {
if (substr($file, 0, 1) == '.') {
continue;
}
$file_path = $tpl_path . '/' . $file;
if (is_file($file_path) && substr($file, -5) == '.html') {
$mtime = intval(@filemtime($file_path));
$tplfile =& $tplfile_handler->create();
$tplfile->setVar('tpl_source', file_get_contents($file_path), true);
$tplfile->setVar('tpl_refid', $mid);
$tplfile->setVar('tpl_tplset', 'default');
$tplfile->setVar('tpl_file', $mydirname . '_' . $file);
$tplfile->setVar('tpl_desc', '', true);
$tplfile->setVar('tpl_module', $mydirname);
$tplfile->setVar('tpl_lastmodified', $mtime);
$tplfile->setVar('tpl_lastimported', 0);
$tplfile->setVar('tpl_type', 'module');
if (!$tplfile_handler->insert($tplfile)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
} else {
$tplid = $tplfile->getVar('tpl_id');
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
// generate compiled file
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
include_once XOOPS_ROOT_PATH . '/class/template.php';
if (!xoops_template_touch($tplid)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
} else {
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
}
}
}
//.........这里部分代码省略.........
示例4: xoops_module_install
function xoops_module_install($dirname)
{
global $xoopsUser, $xoopsConfig;
$dirname = trim($dirname);
$db =& Database::getInstance();
$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
$module_handler =& xoops_gethandler('module');
if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
$module =& $module_handler->create();
$module->loadInfoAsVar($dirname);
$module->setVar('weight', 1);
$error = false;
$errs = array();
$sqlfile =& $module->getInfo('sqlfile');
$msgs = array();
$msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
$msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
}
$msgs[] = '<b>Version:</b> ' . $module->getInfo('version');
if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
$msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author'));
}
$msgs[] = '';
$errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>';
if ($sqlfile != false && is_array($sqlfile)) {
$sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE];
if (!file_exists($sql_file_path)) {
$errs[] = "SQL file not found at <b>{$sql_file_path}</b>";
$error = true;
} else {
$msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables...";
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
if (!$prefixed_query) {
$errs[] = "<b>{$piece}</b> is not a valid SQL!";
$error = true;
break;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $reservedTables)) {
// not reserved, so try to create one
if (!$db->query($prefixed_query[0])) {
$errs[] = $db->error();
$error = true;
break;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$msgs[] = ' Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.';
$created_tables[] = $prefixed_query[4];
} else {
$msgs[] = ' Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.';
}
}
} else {
// the table name is reserved, so halt the installation
$errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!";
$error = true;
break;
}
}
// if there was an error, delete the tables created so far, so the next installation will not fail
if ($error == true) {
foreach ($created_tables as $ct) {
//echo $ct;
$db->query("DROP TABLE " . $db->prefix($ct));
}
}
}
}
// if no error, save the module info and blocks info associated with it
if ($error == false) {
if (!$module_handler->insert($module)) {
$errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.';
foreach ($created_tables as $ct) {
$db->query("DROP TABLE " . $db->prefix($ct));
}
$ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . " " . _MD_AM_ERRORSC . "<br />";
foreach ($errs as $err) {
$ret .= " - " . $err . "<br />";
}
$ret .= "</p>";
unset($module);
unset($created_tables);
unset($errs);
unset($msgs);
return $ret;
} else {
$newmid = $module->getVar('mid');
unset($created_tables);
$msgs[] = 'Module data inserted successfully. Module ID: <b>' . $newmid . '</b>';
$tplfile_handler =& xoops_gethandler('tplfile');
$templates = $module->getInfo('templates');
//.........这里部分代码省略.........
示例5: executeSQL
/**
* Execute module's SQL file - if any
*
* @return bool
*/
function executeSQL()
{
$error = false;
$sqlfile =& $this->getInfo('sqlfile');
if ($sqlfile != false && is_array($sqlfile)) {
$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
$sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $this->getVar('dirname') . "/" . $sqlfile[XOOPS_DB_TYPE];
if (!file_exists($sql_file_path)) {
$this->setErrors("SQL file not found at <b>{$sql_file_path}</b>");
$error = true;
} else {
$this->setMessage("SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables...");
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $GLOBALS['xoopsDB']->prefix());
if (!$prefixed_query) {
$this->setErrors("<b>{$piece}</b> is not a valid SQL!");
$error = true;
break;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $reservedTables)) {
// not reserved, so try to create one
if (!$GLOBALS['xoopsDB']->query($prefixed_query[0])) {
$this->setErrors($GLOBALS['xoopsDB']->error());
$error = true;
break;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$this->setMessage(' Table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b> created.');
$created_tables[] = $prefixed_query[4];
} else {
$this->setMessage(' Data inserted to table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b>.');
}
}
} else {
// the table name is reserved, so halt the installation
$this->setErrors('<b>' . $prefixed_query[4] . "</b> is a reserved table!");
$error = true;
break;
}
}
// if there was an error, delete the tables created so far, so the next installation will not fail
if ($error == true) {
foreach ($created_tables as $ct) {
//echo $ct;
$GLOBALS['xoopsDB']->query("DROP TABLE " . $GLOBALS['xoopsDB']->prefix($ct));
}
}
}
}
return $error;
}
示例6: installSQLAutomatically
/**
* Executes SQL file which xoops_version of $module specifies. This
* function is usefull for installers, but it's impossible to control
* for detail.
*
* @static
* @param XoopsModule $module
* @param Legacy_ModuleInstallLog $log
* @note FOR THE CUSTOM-INSTALLER
*/
function installSQLAutomatically(&$module, &$log)
{
$sqlfileInfo =& $module->getInfo('sqlfile');
$dirname = $module->getVar('dirname');
if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) {
return;
}
$sqlfile = $sqlfileInfo[XOOPS_DB_TYPE];
$sqlfilepath = XOOPS_MODULE_PATH . "/{$dirname}/{$sqlfile}";
if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) {
require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
$scanner = new Legacy_SQLScanner();
$scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
$scanner->setDirname($module->get('dirname'));
if (!$scanner->loadFile($sqlfilepath)) {
$log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
return false;
}
$scanner->parse();
$sqls = $scanner->getSQL();
$root =& XCube_Root::getSingleton();
$db =& $root->mController->getDB();
//
// TODO The following variable exists for rollback, but it is not implemented.
//
foreach ($sqls as $sql) {
if (!$db->query($sql)) {
$log->addError($db->error());
return;
}
}
$log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
} else {
require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications');
$root =& XCube_Root::getSingleton();
$db =& $root->mController->mDB;
$sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
if (!$prefixed_query) {
$log->addError("{$piece} is not a valid SQL!");
return;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $reservedTables)) {
// not reserved, so try to create one
if (!$db->query($prefixed_query[0])) {
$log->addError($db->error());
return;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$log->addReport(' Table ' . $db->prefix($prefixed_query[4]) . ' created.');
$created_tables[] = $prefixed_query[4];
} else {
$log->addReport(' Data inserted to table ' . $db->prefix($prefixed_query[4]));
}
}
} else {
// the table name is reserved, so halt the installation
$log->addError($prefixed_query[4] . " is a reserved table!");
return;
}
}
}
}
示例7: xoops_module_install
function xoops_module_install($dirname)
{
global $xoopsUser, $xoopsConfig;
$dirname = trim($dirname);
$db =& $GLOBALS["xoopsDB"];
$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
$module_handler =& xoops_gethandler('module');
if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) {
$module =& $module_handler->create();
$module->loadInfoAsVar($dirname);
$module->setVar('weight', 1);
$error = false;
$errs = array();
$msgs = array();
$msgs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>';
if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
$msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />';
}
$msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version');
if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
$msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . trim($module->getInfo('author'));
}
$msgs[] = '';
$errs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>';
// Load module specific install script if any
$install_script = $module->getInfo('onInstall');
if ($install_script && trim($install_script) != '') {
include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script);
}
$func = "xoops_module_pre_install_{$dirname}";
// If pre install function is defined, execute
if (function_exists($func)) {
$result = $func($module);
if (!$result) {
$error = true;
$errs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>";
$errs = array_merge($errs, $module->getErrors());
} else {
$msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
$msgs += $module->getErrors();
}
}
if ($error == false) {
$sqlfile = $module->getInfo('sqlfile');
if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) {
$sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE];
if (!file_exists($sql_file_path)) {
$errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
$error = true;
} else {
$msgs[] = "<p>" . sprintf(_MD_AM_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br />" . _MD_AM_CREATE_TABLES;
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
if (!$prefixed_query) {
$errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_VALID, "<strong>" . $piece . "</strong>");
$error = true;
break;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $reservedTables)) {
// not reserved, so try to create one
if (!$db->query($prefixed_query[0])) {
$errs[] = $db->error();
$error = true;
break;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$msgs[] = " " . sprintf(_MD_AM_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
$created_tables[] = $prefixed_query[4];
} else {
$msgs[] = " " . sprintf(_MD_AM_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
}
}
} else {
// the table name is reserved, so halt the installation
$errs[] = " " . sprintf(_MD_AM_TABLE_RESERVED, "<strong>" . $prefixed_query[4] . "</strong>");
$error = true;
break;
}
}
// if there was an error, delete the tables created so far, so the next installation will not fail
if ($error == true) {
foreach ($created_tables as $ct) {
$db->query("DROP TABLE " . $db->prefix($ct));
}
}
}
}
}
// if no error, save the module info and blocks info associated with it
if ($error == false) {
if (!$module_handler->insert($module)) {
$errs[] = "<p>" . sprintf(_MD_AM_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>");
//.........这里部分代码省略.........
示例8: ucfirst
function xpwiki_oninstall_base($module, $mydirname)
{
// transations on module install
global $ret;
// TODO :-D
// for Cube 2.1
if (defined('XOOPS_CUBE_LEGACY')) {
$root =& XCube_Root::getSingleton();
$root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_oninstall');
$root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_oninstall');
$ret = array();
} else {
if (!is_array($ret)) {
$ret = array();
}
}
$db =& Database::getInstance();
$mid = $module->getVar('mid');
// TABLES (loading mysql.sql)
$sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
$prefix_mod = $db->prefix() . '_' . $mydirname;
if (file_exists($sql_file_path)) {
$ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path, ENT_COMPAT, _CHARSET) . "</b>.<br /> Creating tables...";
if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
$sqlutil = new OldSqlUtility();
} else {
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sqlutil = new SqlUtility();
}
$sql_query = trim(file_get_contents($sql_file_path));
// [ MySQL Version >= 5 ] BLOB and TEXT columns cannot be assigned a default value.
if (is_object($db->conn) && get_class($db->conn) === 'mysqli') {
$mysql_ver = mysqli_get_server_info($db->conn);
} else {
$mysql_ver = mysql_get_server_info();
}
if (@$mysql_ver[0] >= 5) {
$sql_query = str_replace(' default \'\'', '', $sql_query);
}
// [ MySQL Version >= 4 ] ENGINE is the preferred term from MySQL 4.0.18 on and TYPE is deprecated.
if (@$mysql_ver[0] >= 4) {
$sql_query = str_replace(' TYPE=MyISAM', ' ENGINE=MyISAM', $sql_query);
}
$sqlutil->splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
$prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
if (!$prefixed_query) {
$ret[] = "Invalid SQL <b>" . htmlspecialchars($piece, ENT_COMPAT, _CHARSET) . "</b><br />";
return false;
}
if (!$db->query($prefixed_query[0])) {
$ret[] = '<b>' . htmlspecialchars($db->error(), ENT_COMPAT, _CHARSET) . '</b><br />';
//var_dump( $db->error() ) ;
return false;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b> created.<br />';
$created_tables[] = $prefixed_query[4];
} else {
$ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b>.</br />';
}
}
}
}
// TEMPLATES
$tplfile_handler =& xoops_gethandler('tplfile');
$tpl_path = dirname(__FILE__) . '/templates';
if ($handler = @opendir($tpl_path . '/')) {
while (($file = readdir($handler)) !== false) {
if (substr($file, 0, 1) == '.') {
continue;
}
$file_path = $tpl_path . '/' . $file;
if (is_file($file_path) && substr($file, -5) == '.html') {
$mtime = intval(@filemtime($file_path));
$tplfile =& $tplfile_handler->create();
$tplfile->setVar('tpl_source', file_get_contents($file_path), true);
$tplfile->setVar('tpl_refid', $mid);
$tplfile->setVar('tpl_tplset', 'default');
$tplfile->setVar('tpl_file', $mydirname . '_' . $file);
$tplfile->setVar('tpl_desc', '', true);
$tplfile->setVar('tpl_module', $mydirname);
$tplfile->setVar('tpl_lastmodified', $mtime);
$tplfile->setVar('tpl_lastimported', 0);
$tplfile->setVar('tpl_type', 'module');
if (!$tplfile_handler->insert($tplfile)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span><br />';
} else {
$tplid = $tplfile->getVar('tpl_id');
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
// generate compiled file
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
include_once XOOPS_ROOT_PATH . '/class/template.php';
if (!xoops_template_touch($tplid)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span><br />';
} else {
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span><br />';
}
//.........这里部分代码省略.........
示例9: xoonips_sql_queries
/**
* @split $sqls to individual queries, add prefix to table, and query sqls
* output some informations to stdout.
*
* @param string $sqls string of sqls.
* @return boolean true if succeed
*
*/
function xoonips_sql_queries($sqls)
{
global $xoopsDB;
$textutil =& xoonips_getutility('text');
$pieces = array();
SqlUtility::splitMySqlFile($pieces, $sqls);
$created_tables = array();
$errs = array();
$msgs = array();
$error = false;
$ret = '';
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $xoopsDB->prefix());
if (!$prefixed_query) {
$errs[] = '<b>' . $piece . '</b> is not a valid SQL!';
$error = true;
break;
}
if (!$xoopsDB->query($prefixed_query[0])) {
$errs[] = $xoopsDB->error() . ' of SQL ' . $textutil->html_special_chars($prefixed_query[0]);
$error = true;
break;
}
if (strncmp('CREATE', strtoupper($prefixed_query[0]), 6) == 0 && !in_array($prefixed_query[4], $created_tables)) {
$msgs[] = ' Table <b>' . $xoopsDB->prefix($prefixed_query[4]) . '</b> created.';
$created_tables[] = $prefixed_query[4];
}
}
if ($error) {
// if there was an error, delete the tables created so far,
// so the next installation will not fail
foreach ($created_tables as $ct) {
$xoopsDB->query('DROP TABLE ' . $xoopsDB->prefix($ct));
}
// set error messages
foreach ($errs as $er) {
$ret .= ' ' . $er . '<br />';
}
unset($msgs);
unset($errs);
}
echo $ret;
return !$error;
}
示例10: _addTable
protected function _addTable()
{
$db =& Database::getInstance();
$sqlFilePath = $this->path . '/sql/mysql.sql';
$prefix = $db->prefix() . '_' . $this->dirname;
if (!file_exists($sqlFilePath)) {
return;
}
$this->_addMessage('SQL file found at <b>' . htmlspecialchars($sqlFilePath) . '</b>.<br /> Creating tables...');
if (file_exists($this->root->cms->rootPath . '/class/database/oldsqlutility.php')) {
require_once $this->root->cms->rootPath . '/class/database/oldsqlutility.php';
$sqlutil = new OldSqlUtility();
} else {
require_once $this->root->cms->rootPath . '/class/database/sqlutility.php';
$sqlutil = new SqlUtility();
}
$tables = array();
$createdTables = array();
$sqlQuery = trim(file_get_contents($sqlFilePath));
$sqlutil->splitMySqlFile($tables, $sqlQuery);
if (!is_array($tables) or count($tables) === 0) {
return;
}
foreach ($tables as $table) {
$prefixedQuery = $sqlutil->prefixQuery($table, $prefix);
if (!$prefixedQuery) {
$this->_addError('Invalid SQL <b>' . htmlspecialchars($table) . '</b>');
throw new Exception();
}
if (!$db->query($prefixedQuery[0])) {
$this->_addError('<b>' . htmlspecialchars($db->error()) . '</b>');
throw new Exception();
}
if (!in_array($prefixedQuery[4], $createdTables)) {
$this->_addMessage('Table <b>' . htmlspecialchars($prefix . '_' . $prefixedQuery[4]) . '</b> created.');
$createdTables[] = $prefixedQuery[4];
} else {
$this->_addMessage('Data inserted to table <b>' . htmlspecialchars($prefix . '_' . $prefixedQuery[4]) . '</b>.');
}
}
}
示例11: xsns_oninstall
function xsns_oninstall($module, $mydirname)
{
global $ret;
if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
$root =& XCube_Root::getSingleton();
$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'xsns_message_append_oninstall' ) ;
$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail' , 'xsns_message_append_oninstall' ) ;
$ret = array() ;
}
else{
if( !is_array($ret) ){
$ret = array() ;
}
}
$constpref = '_MI_'.strtoupper($mydirname);
if(strlen($mydirname) > 15){
$ret[] = constant($constpref.'_INSTERR').'<br />';
}
$db =& Database::getInstance() ;
$mid = $module->getVar('mid') ;
// Tables
$sql_ver = floatval(substr(mysql_get_server_info(), 0, 3));
if($sql_ver < 4){
$sql_file = 'mysql3.sql';
}
elseif($sql_ver == 4.0){
$sql_file = 'mysql40.sql';
}
else{
$sql_file = 'mysql.sql';
}
$sql_file_path = realpath(dirname(__FILE__).'/sql/'.$sql_file);
$prefix_mod = $db->prefix() . '_' . $mydirname ;
if( file_exists( $sql_file_path ) ) {
$ret[] = "SQL file found at <b>".htmlspecialchars($sql_file_path)."</b>.<br /> Creating tables...";
if( file_exists( XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ) ) {
include_once XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ;
$sqlutil = new OldSqlUtility ;
} else {
include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php' ;
$sqlutil = new SqlUtility ;
}
$sql_query = trim( file_get_contents( $sql_file_path ) ) ;
$sqlutil->splitMySqlFile( $pieces , $sql_query ) ;
$created_tables = array() ;
if( is_array( $pieces ) ) {
foreach( $pieces as $piece ) {
$prefixed_query = $sqlutil->prefixQuery( $piece , $prefix_mod ) ;
if( ! $prefixed_query ) {
$ret[] = "Invalid SQL <b>".htmlspecialchars($piece)."</b><br />";
return false ;
}
if( ! $db->query( $prefixed_query[0] ) ) {
$ret[] = '<b>'.htmlspecialchars( $db->error() ).'</b><br />' ;
return false ;
}
else {
if( ! in_array( $prefixed_query[4] , $created_tables ) ) {
$ret[] = 'Table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b> created.<br />'; $created_tables[] = $prefixed_query[4];
}
else {
$ret[] = 'Data inserted to table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b>.</br />';
}
}
}
}
}
// Templates
$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
$tpl_path = dirname(__FILE__).'/templates' ;
if( $handler = @opendir( $tpl_path . '/' ) ) {
while( ( $file = readdir( $handler ) ) !== false ) {
if( substr( $file , 0 , 1 ) == '.' || !preg_match('/(\.html$)|(\.css$)/i', $file)){
continue ;
}
$file_path = $tpl_path . '/' . $file ;
if( is_file( $file_path ) ) {
$mtime = intval( @filemtime( $file_path ) ) ;
$tplfile =& $tplfile_handler->create() ;
$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
$tplfile->setVar( 'tpl_refid' , $mid ) ;
$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
$tplfile->setVar( 'tpl_desc' , '' , true ) ;
$tplfile->setVar( 'tpl_module' , $mydirname ) ;
$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
$tplfile->setVar( 'tpl_type' , 'module' ) ;
if( ! $tplfile_handler->insert( $tplfile ) ) {
$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />';
} else {
$tplid = $tplfile->getVar( 'tpl_id' ) ;
$ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />';
//.........这里部分代码省略.........
示例12: install
/**
* install a module
*
* @param string $mod module dirname
* @param boolean $force force query
*
* @return bool|XoopsModule|XoopsObject
*/
public function install($mod = '', $force = false)
{
$xoops = Xoops::getInstance();
$module_handler = $xoops->getHandlerModule();
$mod = trim($mod);
try {
$cnt = $module_handler->getCount(new Criteria('dirname', $mod));
} catch (DBALException $e) {
$cnt = 0;
}
if ($cnt == 0) {
/* @var $module XoopsModule */
$module = $module_handler->create();
$module->loadInfoAsVar($mod);
$module->setVar('weight', 1);
$module->setVar('isactive', 1);
$module->setVar('last_update', time());
$install_script = $module->getInfo('onInstall');
if ($install_script && trim($install_script) != '') {
XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($install_script)));
}
$func = "xoops_module_pre_install_{$mod}";
// If pre install function is defined, execute
if (function_exists($func)) {
$result = $func($module);
if (!$result) {
$this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
$this->error = array_merge($this->error, $module->getErrors());
return false;
} else {
$this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
$this->trace = array_merge($this->trace, $module->getMessages());
}
}
// Create tables
$created_tables = array();
if (count($this->error) == 0) {
$schema_file = $module->getInfo('schema');
$sql_file = $module->getInfo('sqlfile');
if (!empty($schema_file)) {
$schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
if (!XoopsLoad::fileExists($schema_file_path)) {
$this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
return false;
}
$importer = new ImportSchema();
$importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
$synchronizer = new SingleDatabaseSynchronizer($xoops->db());
$synchronizer->updateSchema($importSchema, true);
} elseif (is_array($sql_file) && !empty($sql_file[\XoopsBaseConfig::get('db-type')])) {
$xoops->deprecated('Install SQL files are deprecated since 2.6.0. Convert to portable Schemas');
$sql_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $sql_file[\XoopsBaseConfig::get('db-type')];
if (!XoopsLoad::fileExists($sql_file_path)) {
$this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
return false;
} else {
$this->trace[] = sprintf(SystemLocale::SF_SQL_FILE_FOUND, "<strong>{$sql_file_path}</strong>");
$this->trace[] = SystemLocale::MANAGING_TABLES;
$sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $xoops->db()->prefix());
if (!$prefixed_query) {
$this->error[]['sub'] = '<span class="red">' . sprintf(XoopsLocale::EF_INVALID_SQL, '<strong>' . $piece . '</strong>') . '</span>';
break;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $this->reservedTables) || $mod == 'system') {
// not reserved, so try to create one
try {
$result = $xoops->db()->query($prefixed_query[0]);
} catch (Exception $e) {
$xoops->events()->triggerEvent('core.exception', $e);
$result = false;
}
if (!$result) {
$this->error[] = $xoops->db()->errorInfo();
break;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$this->trace[]['sub'] = sprintf(XoopsLocale::SF_TABLE_CREATED, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>');
$created_tables[] = $prefixed_query[4];
} else {
$this->trace[]['sub'] = sprintf(XoopsLocale::SF_DATA_INSERTED_TO_TABLE, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>');
}
}
} else {
// the table name is reserved, so halt the installation
$this->error[]['sub'] = sprintf(SystemLocale::EF_TABLE_IS_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>');
//.........这里部分代码省略.........
示例13: isset
$importfile = isset($_POST['importfile']) ? $_POST['importfile'] : 'nonselected';
$sql_file_path = XOOPS_ROOT_PATH . "/modules/smartsection/admin/import/" . $importfile . ".sql";
if (!file_exists($sql_file_path)) {
$errs[] = "SQL file not found at <b>{$sql_file_path}</b>";
$error = true;
} else {
xoops_cp_header();
ss_adminMenu(-1, _AM_SS_IMPORT);
$error = false;
$db =& Database::getInstance();
$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'comments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource');
$msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Importing Q&A";
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
$sql_query = trim($sql_query);
SqlUtility::splitMySqlFile($pieces, $sql_query);
$created_tables = array();
foreach ($pieces as $piece) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
if (!$prefixed_query) {
$errs[] = "<b>{$piece}</b> is not a valid SQL!";
$error = true;
break;
}
// check if the table name is reserved
if (!in_array($prefixed_query[4], $reservedTables)) {
// not reserved, so try to create one
if (!$db->query($prefixed_query[0])) {
$errs[] = $db->error();
示例14: queryFromFile
/**
* perform queries from SQL dump file in a batch
*
* @param string $file file path to an SQL dump file
*
* @return bool FALSE if failed reading SQL file or TRUE
* if the file has been read and queries executed
* @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector.
*/
public function queryFromFile($file)
{
$this->deprecated();
if (false !== ($fp = fopen($file, 'r'))) {
$sql_queries = trim(fread($fp, filesize($file)));
SqlUtility::splitMySqlFile($pieces, $sql_queries);
foreach ($pieces as $query) {
// [0] contains the prefixed query
// [4] contains unprefixed table name
$prefixed_query = SqlUtility::prefixQuery(trim($query), $this->prefix());
if ($prefixed_query != false) {
$this->query($prefixed_query[0]);
}
}
return true;
}
return false;
}
示例15: ucfirst
function pico_oninstall_base($module, $mydirname)
{
// transations on module install
global $ret;
// TODO :-D
// for Cube 2.1
if (defined('XOOPS_CUBE_LEGACY')) {
$root =& XCube_Root::getSingleton();
$root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'pico_message_append_oninstall');
$ret = array();
} else {
if (!is_array($ret)) {
$ret = array();
}
}
$db =& Database::getInstance();
$mid = $module->getVar('mid');
// TABLES (loading mysql.sql)
$sql_file_path = dirname(__FILE__) . '/sql/mysql.sql';
$prefix_mod = $db->prefix() . '_' . $mydirname;
if (file_exists($sql_file_path)) {
$ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...";
if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) {
include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php';
$sqlutil = new OldSqlUtility();
} else {
include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php';
$sqlutil = new SqlUtility();
}
$sql_query = trim(file_get_contents($sql_file_path));
$sqlutil->splitMySqlFile($pieces, $sql_query);
$created_tables = array();
if (is_array($pieces)) {
foreach ($pieces as $piece) {
$prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod);
if (!$prefixed_query) {
$ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />";
return false;
}
if (!$db->query($prefixed_query[0])) {
$ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />';
//var_dump( $db->error() ) ;
return false;
} else {
if (!in_array($prefixed_query[4], $created_tables)) {
$ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
$created_tables[] = $prefixed_query[4];
} else {
$ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />';
}
}
}
}
}
// TEMPLATES
$tplfile_handler =& xoops_gethandler('tplfile');
$tpl_path = dirname(__FILE__) . '/templates';
if ($handler = @opendir($tpl_path . '/')) {
while (($file = readdir($handler)) !== false) {
if (substr($file, 0, 1) == '.') {
continue;
}
$file_path = $tpl_path . '/' . $file;
if (is_file($file_path)) {
$mtime = intval(@filemtime($file_path));
$tplfile =& $tplfile_handler->create();
$tplfile->setVar('tpl_source', file_get_contents($file_path), true);
$tplfile->setVar('tpl_refid', $mid);
$tplfile->setVar('tpl_tplset', 'default');
$tplfile->setVar('tpl_file', $mydirname . '_' . $file);
$tplfile->setVar('tpl_desc', '', true);
$tplfile->setVar('tpl_module', $mydirname);
$tplfile->setVar('tpl_lastmodified', $mtime);
$tplfile->setVar('tpl_lastimported', 0);
$tplfile->setVar('tpl_type', 'module');
if (!$tplfile_handler->insert($tplfile)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />';
} else {
$tplid = $tplfile->getVar('tpl_id');
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />';
// generate compiled file
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
include_once XOOPS_ROOT_PATH . '/class/template.php';
if (!xoops_template_touch($tplid)) {
$ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />';
} else {
$ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />';
}
}
}
}
closedir($handler);
}
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
include_once XOOPS_ROOT_PATH . '/class/template.php';
xoops_template_clear_module_cache($mid);
return true;
}