⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templates.php

📁 jsp程序开发系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		$db->query("
			UPDATE template SET 
			template = '" . mysql_escape_string($template_backup[template]) . "',
			template_unparsed = '" . mysql_escape_string($template_backup[template_unparsed]) . "',
			upgraded = 0,
			changed = 0,
			backup = 0
			WHERE id = '$id'
		");

		jump("templates.php?do=view&category=$_REQUEST[category]", "Template restored from backup");
	} else {
		mistake('Backup template not found');
	}

}

########################################################################################
############################### SEARCH / REPLACE  ######################################
########################################################################################

############################### PREG REPLACE (!) ###############################

if ($_REQUEST['do'] == "preg_replace") {

	admin_header('Styles', 'Template Search Results');

	$table[] = array('<b>Search For</b><br />Enter your search keyword', form_input('keyword'));
	$table[] = array('<b>Replace With</b><br />Text to replace with', form_input('replace'));
	$table[] = array('<b>Treat replace as PHP code</b>', '<input type="checkbox" name="phpcode" value="1">');


	table_header("Search for templates", 'templates.php', array('do' => 'preg_replace2'));
	table_content($columns, $table);
	table_footer('Search');

}

############################### PREG REPLACE (2) ###############################

if ($_REQUEST['do'] == "preg_replace2") {

	$db2 = new DB_Sql;
	$db2->User=constant('DATABASE_USER');
	$db2->Password=constant('DATABASE_PASSWORD');
	$db2->Host=constant('DATABASE_HOST');
	$db2->Database=constant('DATABASE_NAME');

	$db->query("SELECT id, name, template_unparsed FROM template");
	while ($result = $db->row_array()) {

	if ($_REQUEST[phpcode] == "1") {
		$newtemplate = preg_replace("/$_REQUEST[keyword]/siUe", $_REQUEST['replace'], $result['template_unparsed']);
	} else {
		$newtemplate = preg_replace("/$_REQUEST[keyword]/siU", $_REQUEST['replace'], $result['template_unparsed']);
		echo $newtemplate;
	}

	if ($newtemplate != $result[template_unparsed]) { 
		echo $result['template_unparsed'];
		echo $newtemplate;
			exit();
	}



		if ($newtemplate != $result[template_unparsed]) { 

			$parsed = parse_conditionals($newtemplate);
/*
			$db2->query("UPDATE template 
						SET template_unparsed = '" . mysql_escape_string($newtemplate) . "',
							template = '" . mysql_escape_string($parsed) . "'
						WHERE id = '$result[id]'
					");
*/
			echo $result[name] . '<br />';
		}	
	}
}

############################### FIND TEMPLATES ###############################

if ($_REQUEST['do'] == "find") {

	admin_header('Styles', 'Find In Templates');

	$table[] = array('<b>Search For</b><br />Enter your search keyword', form_input('keyword'));
	$table[] = table_midheader('Replace');
	$table[] = array('<b>Run replacements</b>', '<input type="checkbox" name="doreplace" value="1">');
	$table[] = array('<b>Replace With</b><br />Text to replace with', form_input('replace'));

	table_header("Search for templates", 'templates.php', array('do' => 'find2'));
	table_content($columns, $table);
	table_footer('Search');
	unset($table);

}

############################### FIND TEMPLATES ###############################

if ($_REQUEST['do'] == "find2") {

	admin_header('Styles', 'Search Results');

	$db->query("SELECT * FROM template WHERE template_unparsed LIKE '%" . mysql_escape_string($_REQUEST[keyword]) . "%' $where");

	while ($template = $db->row_array()) {

		$template[template_unparsed] = str_replace($_REQUEST['keyword'], $_REQUEST['replace'], $template[template_unparsed]);

		$template[template] = parse_conditionals($template[template_unparsed]);

		$update_templates[] = array($template[id], $template[name], $template[template], $template[category], $template[description], $template[upgraded], $template[changed], $template[custom], $template[version_upgrade], $template[template_unparsed], $template[displayorder]);

		$table[] = array($template[name], $template[category]);
		$secondrow[] = "<textarea cols=\"100\" rows=\"15\">" . htmlspecialchars($template[template_unparsed]) . "</textarea>";

	}

	// echo multi_array2sql($update_templates);

	if ($_REQUEST['doreplace']) {

		$db->query("
			REPLACE INTO template (id, name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder) 
			VALUES " . multi_array2sql($update_templates) . "");

	} else {
	
		table_header("Search for templates", 'templates.php', array('do' => 'find2'));
		table_content($columns, $table, '', '', '', $secondrow);
		table_footer('Search');
		unset($table);

	}
}



########################################################################################
###############################   DEVELOPER ONLY SECTION    ###############################
########################################################################################

############################### EXPORT TEMPLATES TO FILES ###############################

if ($_REQUEST['do'] == "dev_export") {

	developer_check();

	admin_header('Styles', 'Export To Files');

	$location = dirname(__FILE__);
	$location .= '/templates/';

	dev_export_templates($location);

	echo "<P>Export completed.</P>\n";
}

############################# EXPORT MAIL TEMPLATES TO FILES #############################

if ($_REQUEST['do'] == 'dev_export_mail') {
	developer_check();
	admin_header('Styles, Export Mail To Files');

	$languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
	echo "<FORM METHOD=\"POST\" ACTION=\"templates.php\">";
	echo form_hidden('do', 'do_dev_export_mail');
	$languages['tech'] = "Tech Mails";
	$rows[] = array('<B>Languages to Export</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
	table_header("Select Languages to Export to /admin/templates/email/*");
	table_content(NULL, $rows);
	table_footer('Export Languages');
	exit;
}

if ($_REQUEST['do'] == 'do_dev_export_mail') {

	developer_check();

	admin_header('Styles', 'Export Mail To Files');
	if (ini_set('track_errors', 1) === FALSE) {
		$errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
		$php_errormsg = 'Unknown error.';
	}
	
	$location = dirname(__FILE__) . '/templates/email';

	dev_export_mail_templates($location);

}

############################### IMPORT TEMPLATES FROM FILES ###############################

if ($_REQUEST['do'] == 'dev_import') {

	admin_header('Styles', 'Import From Files');
	$location = dirname(__FILE__);
	$location .= '/templates/';

	dev_import_templates($location);

	echo "Import completed.<BR />";
}

############################### IMPORT MAIL TEMPLATES FROM FILES ###############################

if ($_REQUEST['do'] == 'dev_import_mail') {
	developer_check();
	admin_header('Styles', 'Import Mail From Files');

	$languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
	$languages['tech'] = "Tech Mails";
	echo "<FORM METHOD=\"POST\" ACTION=\"templates.php\">";
	echo form_hidden('do', 'do_dev_import_mail');
	$rows[] = array('<B>Languages to Import</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
	table_header("Select Languages to Import to /admin/templates/email/*");
	table_content(NULL, $rows);
	table_footer('Import Languages');
	exit;
}

if ($_REQUEST['do'] == 'do_dev_import_mail') {
	developer_check();
	
	admin_header('Styles', 'Import Mail From Files');
	if (ini_set('track_errors', 1) === FALSE) {
		$errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
		$php_errormsg = 'Unknown error.';
	}
	
	$location = dirname(__FILE__) . '/templates/email';

	dev_import_mail_templates($location);
}

############################### TEMPLATE MAINTENANCE ###############################

if ($_REQUEST['do'] == "search_images") {

	developer_check();

	admin_header('Styles', 'Image Usage');

	if (is_win()) {
		echo "<B>Error:</B> This function is not currently supported on Windows platforms.";
		admin_footer();
		exit;
	}

	if (!chdir('../images')) {
		echo "<B>Error:</B> Couldn't chdir() to ../images/";
		admin_footer();
		exit;
	}

	$images = exec("find . -type f -name '*gif'", $output, $retval);

	if (!chdir('../')) {
		echo "<B>Error:</B> Couldn't chdir() to base of installation";
		admin_footer();
		exit;
	}

	if ($retval) {
		echo "<B>Error:</B> Find failed.";
		print_rr($output);
		admin_footer();
		exit;
	}

	if (is_array($output)) {
		$not_used = array();
		foreach ($output AS $image) {
			$image = substr($image, 2);
			unset($messages);
			exec('grep -onri "' . $image . '" *', $messages, $return);
			if (count($messages)) {
				foreach ($messages AS $message) {
					if (stristr($message, 'js') or stristr($message, 'php')) {
						$message = split(':', $message);
						$used[$image]['files'][$message[0]][] = array($message[1], $message[2]);
						$used[$image]['count']++;
					} elseif (stristr($message, 'html')) {
						$message = split(':', $message);
						$used[$image]['templates'][$message[0]][] = array($message[1], $message[2]);
						$used[$image]['count']++;
					}
				}
			}

			if (!$used[$image]['count']) {
				$not_used[] = $image;
				unset ($used[$image]);
			}
		}
	}

	if (is_array($used)) {
		print "<TABLE CELLPADDING=\"2\" CELLSPACING=\"0\">";
		$rowscount = 0;
		foreach($used AS $image => $use) {
			if ($rowscount % 2) {
				$bgcolor="#EEEEFF";
			} else {
				$bgcolor="white";
			}
			echo "<TR VALIGN=\"top\" BGCOLOR=\"$bgcolor\"><TD WIDTH=\"33%\">$image (use count: $use[count])</TD>\n";
			echo "<TD ROWSPAN=\"2\" WIDTH=\"33%\">";
			if (is_array($use['templates'])) {
				foreach ($use['templates'] AS $filename => $file) {
					echo "<TABLE><TR><TD COLSPAN=\"2\">$filename</TD></TR>\n";
					$lines = array();
					foreach ($file AS $linenum) {
						$lines[] = $linenum[0];
					}
					$lines = join(', ', $lines);
					echo "<TD>&nbsp;</TD><TD>Line number(s): $lines</TD></TR>\n";
					echo "</TABLE>\n";
				}
			} else {
				echo "Not used in any template.\n";
			}
			echo "</TD>\n";
			echo "<TD ROWSPAN=\"2\" WIDTH=\"34%\">";
			if (is_array($use['files'])) {
				foreach ($use['files'] AS $filename => $file) {
					echo "<TABLE><TR><TD COLSPAN=\"2\">$filename</TD></TR>\n";
					$lines = array();
					foreach ($file AS $linenum) {
						$lines[] = $linenum[0];
					}
					$lines = join(', ', $lines);
					echo "<TD>&nbsp;</TD><TD>Line number(s): $lines</TD></TR>\n";
					echo "</TABLE>\n";
				}
			} else {
				echo "Not used in any files.\n";
			}
			echo "</TD>\n";

			echo "</TR><TR VALIGN=\"top\" BGCOLOR=\"$bgcolor\"><TD>";
			$tmpimage = html_image($image);
			echo "<TABLE CELLPADDING=\"4\"><TR VALIGN=\"top\"><TD BGCOLOR=\"white\">$tmpimage</TD><TD BGCOLOR=\"black\">$tmpimage</TD></TR></TABLE>";
			echo "</TD></TR>\n";
			$rowscount++;

		}
		echo "</TABLE>\n";
	}

	print "<P><B>Unused Images:</B><BR>";
	if (is_array($not_used)) {
		if (count($not_used)) {
			print "<TABLE>";
			foreach($not_used AS $image) {
				$tmpimage = html_image($image);
				echo "<TR VALIGN=\"top\"><TD VALIGN=\"top\" ALIGN=\"right\">$image</TD><TD><TABLE CELLPADDING=\"4\"><TR><TD BGCOLOR=\"white\">$tmpimage</TD><TD BGCOLOR=\"black\">$tmpimage</TD></TR></TABLE></TD></TR>";
			}
			print "</TABLE>";
		} else {
			print "None";
		}
	} else {
		print "None";
	}

	print "</P>";
	exit;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -