📄 devmode_functions.php
字号:
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_undo_changes() {
global $db;
$db->query("UPDATE template SET changed = '0', upgraded = '0'");
}
/*****************************************************
function dev_export_templates()
-----DESCRIPTION: -----------------------------------
Export HTML templates to files in the specified
directory.
-----ARGUMENTS: -------------------------------------
location Directory to place templates into
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_export_templates($location) {
global $db, $_REQUEST;
if (!file_exists($location)) {
mistake("[ERROR] $location doesn't exist; cannot export HTML templates");
}
if (!is_dir($location)) {
mistake("[ERROR] $location isn't a directory; cannot export HTML templates");
}
if ($_REQUEST['id']) {
$db->query("SELECT * FROM template WHERE !backup AND id = '$_REQUEST[id]'");
} elseif ($_REQUEST['search']) {
$db->query("SELECT * FROM template WHERE !backup AND template.name LIKE '%" . mysql_escape_string($_REQUEST['search']) . "%'");
} else {
$db->query("SELECT * FROM template WHERE !backup");
}
if (!$db->num_rows()) {
error('No templates exported');
}
while ($data = $db->row_array()) {
if ($handle = @fopen($location . '/' . $data['name'] . '.html', 'wb')) {
@fwrite($handle, $data['template_unparsed']);
@fclose($handle);
echo "[NOTICE] Exported $data[name].html<br />";
} else {
echo "[WARN] Couldn't open $location/$data[name] for writing.<br />";
}
}
}
/*****************************************************
function dev_export_mail_templates()
-----DESCRIPTION: -----------------------------------
Export e-mail templates to files in the specified
directory.
-----ARGUMENTS: -------------------------------------
location Directory to place templates into
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_export_mail_templates($location) {
global $db, $_REQUEST;
umask(0);
$orig_langs = $_REQUEST['languages'];
if (in_array('tech', $_REQUEST['languages'])) {
$get_tech = 1;
if (count($_REQUEST['languages']) > 1) {
foreach($_REQUEST['languages'] AS $val) {
if ($val != 'tech') {
$langs[] = $val;
}
$_REQUEST['languages'] = $langs;
}
$get_norm = 1;
} else {
$_REQUEST['languages'] = NULL;
}
} else {
$get_norm = 1;
}
if (!file_exists($location)) {
// Try to create the directory if it doesn't exist
if (!@mkdir($location, '0775')) {
// We couldn't create the directory, so we can't export this language
$errors[] = "[ERROR] $location doesn't exist and cannot be created: $php_errormsg";
} else {
$errors[] = "[NOTICE] Created directory $location<BR />\n";
}
}
if (!@is_dir($location)) {
$errors[] = "[ERROR] $location isn't a directory or can't be stat()'d; cannot export e-mail templates: $php_errormsg";
}
// Fetch languages to process
if (!count($errors)) {
if ($_REQUEST['languages']) {
$langs = ' where ID in ' . array2sql($_REQUEST['languages']);
}
$db->query("SELECT id, name FROM languages $langs");
if (!$db->num_rows()) {
$errors[] = "No languages are defined, or none were selected. Cannot export.";
}
while ($res = $db->row_array()) {
$languages[$res['id']]['name'] = $res['name'];
$languages[$res['id']]['dir'] = $location.'/'.$res['name'];
if (!@file_exists($languages[$res['id']]['dir'])) {
// First try to create the directory
if (!@mkdir($languages[$res['id']]['dir'], '0775')) {
$errors[] = "Directory " . $languages[$res['id']]['dir'] . " doesn't exist and couldn't be created: $php_errormsg";
} else {
$errors[] = "[NOTICE] Created directory " . $languages[$res['id']]['dir'];
}
}
if (!@is_dir($languages[$res['id']]['dir'])) {
// It's a plain file, not a directory. Can't export like this.
$errors[] = $languages[$res['id']]['dir'] . " exists but isn't a directory or can't be stat()'d: $php_errormsg";
}
}
// Process each language
$db->query("SELECT template_unparsed, subject, name, language FROM template_email WHERE language AND !backup ORDER BY language");
if (!$db->num_rows()) {
mistake("No e-mail templates are defined. Cannot export.");
}
while ($res = $db->row_array()) {
if (stristr($res['name'], 'TECHBODY')) {
if (!$get_tech) {
continue;
}
$name = "$location/$res[name].txt";
} else {
if (!$get_norm) {
continue;
}
$name = $languages[$res['language']]['dir'] . '/' . $res['name'] . '.txt';
}
if ($handle = @fopen($name, 'wb')) {
@fwrite($handle, "Subject: $res[subject]\n");
@fwrite($handle, $res['template_unparsed']);
@fclose($handle);
if(stristr($res['name'], 'TECHBODY')) {
$exported[$res['name']][-1] = -1;
} else {
$exported[$res['name']][$res['language']] = -1;
}
} else {
$exported[$res['name']][$res['language']] = "[WARNING] Couldn't export $res[name] to $name: $php_errormsg";
}
}
$cols = array('Template Name');
$languages['-1']['name'] = "Tech Mails";
foreach ($languages as $lang_id => $lang) {
if (in_array($lang_id, $orig_langs)) {
$cols[] = $lang['name'];
}
}
foreach ($exported AS $template => $val) {
$row = array($template);
foreach ($languages AS $lang_id => $lang) {
if (in_array($lang_id, $orig_langs)) {
if(stristr($template, 'TECHBODY')) {
if ($val[-1] == -1) {
$result = '<FONT COLOR="green">Tech E-mail Template Exported</FONT>';
} elseif ($val[-1]) {
$result = '<FONT COLOR="red">Error</FONT>';
}
} else {
if ($val[$lang_id] == -1) {
$result = '<FONT COLOR="green">Exported</FONT>';
} elseif ($val[$lang_id]) {
$result = '<FONT COLOR="red">Error</FONT>';
} else {
$result = 'Not Defined';
}
}
$row[] = "<CENTER>$result</CENTER>";
if (is_string($val[$lang_id])) {
$errors[] = $val[$lang_id];
}
if(stristr($template, 'TECHBODY')) {
break;
}
}
}
$rows[] = $row;
}
}
table_header('Export Results');
table_content($cols, $rows);
table_footer();
if (count($errors)) {
table_header('Export Errors');
table_content(NULL, $errors);
table_footer();
}
}
/*****************************************************
function dev_reset_backup_templates()
-----DESCRIPTION: -----------------------------------
Recreate backups from current templates for all
templates
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_reset_backup_templates() {
global $db;
$db->query("DELETE FROM template WHERE backup");
$data = $db->query_return_array("SELECT * FROM template");
if (@is_array($data)) {
foreach($data AS $val) {
$db->query('INSERT INTO template
(name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder, backup) VALUES (
\''.mysql_escape_string($val[name]).'\',
\''.mysql_escape_string($val[template]).'\',
\''.mysql_escape_string($val[category]).'\',
\''.mysql_escape_string($val[description]).'\',
\'0\',
\'0\',
\'0\',
\'0\',
\''.mysql_escape_string($val[template_unparsed]).'\',
\''.mysql_escape_string($val[displayorder]).'\',
\'1\'
)');
}
}
}
/*****************************************************
function dev_reset_backups()
-----DESCRIPTION: -----------------------------------
Makes copies of all current non-backup templates
as the system's backup templates, replacing
backup templates of the same name if they already
existed.
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_reset_backups() {
global $db;
$db->query('SELECT * FROM template_email');
while($res = $db->row_array()) {
if ($res['backup']) {
$ids[] = $res['name'];
} else {
$data[] = $res;
}
}
if (count($ids)) {
$db->query('DELETE FROM template_email WHERE backup AND name IN ' . array2sql($ids));
}
if (@is_array($data)) {
foreach($data AS $val) {
$db->query('INSERT INTO template_email
(name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder, backup, language, subject) VALUES (
\''.mysql_escape_string($val[name]).'\',
\''.mysql_escape_string($val[template]).'\',
\''.mysql_escape_string($val[category]).'\',
\''.mysql_escape_string($val[description]).'\',
\'0\',
\'0\',
\'0\',
\'0\',
\''.mysql_escape_string($val[template_unparsed]).'\',
\''.mysql_escape_string($val[displayorder]).'\',
1,
\''.mysql_escape_string($val[language]).'\',
\''.mysql_escape_string($val[subject]).'\'
)');
}
}
}
/*****************************************************
function dev_restore_norm_templates()
-----DESCRIPTION: -----------------------------------
Makes copies of all current backup templates
and makes non-backup templates from them.
Destroys non-backup templates.
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_restore_norm_templates() {
global $db;
$templates = $db->query_return_array('SELECT * FROM template WHERE backup');
$db->query("DELETE FROM template WHERE !backup");
if (@is_array($templates)) {
foreach($templates AS $val) {
$db->query('INSERT INTO template
(name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder, backup) VALUES (
\''.mysql_escape_string($val[name]).'\',
\''.mysql_escape_string($val[template]).'\',
\''.mysql_escape_string($val[category]).'\',
\''.mysql_escape_string($val[description]).'\',
\'0\',
\'0\',
\'0\',
\'0\',
\''.mysql_escape_string($val[template_unparsed]).'\',
\''.mysql_escape_string($val[displayorder]).'\',
\'0\'
)');
}
}
$templates = $db->query_return_array('SELECT * FROM template_email WHERE backup');
$db->query("DELETE FROM template_email WHERE !backup");
if (@is_array($templates)) {
foreach($templates AS $val) {
$db->query('INSERT INTO template_email
(name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder, backup, language, subject) VALUES (
\''.mysql_escape_string($val[name]).'\',
\''.mysql_escape_string($val[template]).'\',
\''.mysql_escape_string($val[category]).'\',
\''.mysql_escape_string($val[description]).'\',
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -