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

📄 devmode_functions.php

📁 本代码是为客户联系管理而做的系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:
				\'0\',
				\'0\',
				\'0\',
				\'0\',
				\''.mysql_escape_string($val[template_unparsed]).'\',
				\''.mysql_escape_string($val[displayorder]).'\',
				\'0\',
				\''.mysql_escape_string($val[language]).'\',
				\''.mysql_escape_string($val[subject]).'\'
				)');
		}
	}
}


/*****************************************************
	function dev_words_export()

-----DESCRIPTION: -----------------------------------
	Exports all language translations.

-----ARGUMENTS: -------------------------------------
	location	Directory to export to

-----RETURNS: ---------------------------------------
	Nothing.

*****************************************************/

function dev_words_export($location) {
	global $db;
	umask(0);

	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 template phrases: $php_errormsg";
	}

	// Fetch languages to process
	if (!count($errors)) {
		$catnames = $db->query_return_array_id("SELECT id, name FROM template_words_cat", 'name');

		if ($_REQUEST['languages']) {
			$db->query("SELECT id, name FROM languages WHERE id IN " . array2sql($_REQUEST['languages']));
			if (!$db->num_rows()) {
				$errors[] = "No languages were selected. Cannot export.";
			}
		} else {
			$db->query("SELECT id, name FROM languages");
			if (!$db->num_rows()) {
				$errors[] = "No languages are defined. Cannot export.";
			}
		}

		$languages = array();
		$legend = "# Format:\n#\n# Empty lines, and lines beginning with \"#\" are comments. Lines beginning with\n# \"%%\" specify a new (or continuing) category. Empty lines are ignored as\n# comments. When a category is specified, every wordref beneath it is added to\n# that category. The template file should begin with a category specification,\n# otherwise, wordrefs appearing prior to a category specifier will be assigned\n# no category.\n#\n# All other lines are expected to be in the format: \n# wordref: full phrase text\n#\n# To delete a wordref, specify it on a line by itself with no phrase \n# definition, as shown: \n# wordref:\n\n";

		if (!$_REQUEST['languages']) {
			echo "No languages selected";
			return;
		}

		while ($res = $db->row_array()) {
			if (!$res['id'] AND !@in_array('0', $_REQUEST['languages'])) {
				continue;
			}

			$languages[$res['id']]['name'] = $res['name'];
			$languages[$res['id']]['file'] = $location . '/' . str_replace('/', '_', $res['name']);
			$languages[$res['id']]['prev'] = 0;

			if (!$languages[$res['id']]['handle'] = @fopen($languages[$res['id']]['file'], 'wb')) {
				$errors[] = "Cannot open " . $languages[$res['id']]['file'] . "for writing $php_errormsg";
			}

			if (!@fwrite($languages[$res['id']]['handle'], $legend)) {
				$errors[] = "Couldn't write to " . $languages[$res['id']]['file'] . " for header: $php_errormsg";
			}
		}

		// Process data
		$data = $db->query_return_array("SELECT * FROM template_words ORDER BY language, category, wordref");

		if (!$db->num_rows()) {
			mistake("No template phrases are defined. Cannot export.");
		}
	
		foreach($data AS $val) {
			if ($val['category'] != $languages[$val['language']]['prev']) {
				$languages[$val['language']]['prev'] = $val['category'];
				$line = "\n%%{$catnames[$val['category']]}\n\n";
				if (!@fwrite($languages[$val['language']]['handle'], $line)) {
					$errors[] = "Couldn't write to " . $languages[$val['language']]['file'] . " for entry $val[wordref]: $php_errormsg";
				}
			}
			$line = "$val[wordref]: $val[text]\n";
			if (!@fwrite($languages[$val['language']]['handle'], $line)) {
				$errors[] = "Couldn't write to " . $languages[$val['language']]['file'] . " for entry $val[wordref]: $php_errormsg";
				$exported[$val['wordref']][$val['language']] = 1;
			}
			$exported[$val['wordref']][$val['language']] = -1;
		}

		$cols = array('Template Name');
		foreach ($languages as $lang) {
			$cols[] = $lang['name'];
			@fclose($lang['handle']);
		}

		foreach ($exported AS $template => $val) {
			$row = array($template);
			foreach ($languages AS $lang_id => $lang) {
				if ($val[$lang_id] == -1) {
					$result = '<FONT COLOR="green">Exported</FONT>';
				} elseif ($val[$lang_id] > 0) {
					$result = '<FONT COLOR="red">Error</FONT>';
				} else {
					$result = 'Not Defined';
				}
				$row[] = "<CENTER>$result</CENTER>";
				if (is_string($val[$lang_id])) {
					$errors[] = $val[$lang_id];
				}
			}
			$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_words_import()

-----DESCRIPTION: -----------------------------------
	Imports all language translations.

-----ARGUMENTS: -------------------------------------
	location	Directory to import from

-----RETURNS: ---------------------------------------
	Nothing.

*****************************************************/

function dev_words_import($location) {
	global $db, $_REQUEST;
	
	if (!file_exists($location)) {
		$errors[] = "[ERROR] $location doesn't exist; cannot import templates: $php_errormsg";
	}
	if (!@is_dir($location)) {
		$errors[] = "[ERROR] $location isn't a directory or can't be stat()'d; cannot import templates: $php_errormsg";
	}

	if (!count($errors)) {
		if ($_REQUEST['dryrun']) {
			$errors[] = "[NOTICE] Dry run; no changes were made.";
		}
	
		$catnames = $db->query_return_array_id("SELECT id, name FROM template_words_cat", 'name');
		$catnames[0] = '';

		$languages = array();

		if (@in_array('0', $_REQUEST['languages']) OR !$_REQUEST['languages']) {
			$languages[0] = array(
				'name' => 'Default',
				'file' => "$location/Default",
			);
		}

		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.";
		} else {
			while ($res = $db->row_array()) {
				$languages[$res['id']]['name'] = $res['name'];
				$languages[$res['id']]['file'] = $location . '/' . str_replace('/', '_', $res['name']);
			}

			foreach ($languages AS $langid => $lang) {
				if (!$_REQUEST['dryrun']) {
					if ($_REQUEST['replace_all'] AND $_REQUEST['replace_all_confirm']) {
						$db->query("DELETE FROM template_words WHERE language = '$langid'");
						$errors[] = "[NOTICE] Purged all existing words for the $lang[name] language.";
					}
				} else {
					if ($_REQUEST['replace_all'] AND $_REQUEST['replace_all_confirm']) {
						$errors[] = "[NOTICE] Would delete all existing words for the $lang[name] language.";
					}
				}
				if (!$handle = fopen($lang['file'], 'rb')) {
					$errors[] = "Cannot open " . $langid['file'] . "for reading $php_errormsg";
				} else {
					$data = array();
					while (!feof($handle)) {
						$data[] = fgets($handle, 4096);
					}
					@fclose($handle);
					$count = 0;
					$catid = 0;
					foreach ($data as $line) {
						$count++;
						$matches = array();
						$line = trim($line);
						if (!$line or (preg_match('/^#/', $line))) {
							continue;
						}
						if (preg_match("/^%%(.*)/", $line, $cat)) {
							$catname = $cat[1];
							$catid = array_search($catname, $catnames);
							if (!$catid) {
								if (!$_REQUEST['dryrun']) {
									$db->query("INSERT INTO template_words_cat (name) VALUES ('" . mysql_escape_string($catname) . "')");
									$catid = $db->last_id();
								}
								$errors[] = "Category $catname not found, created new category, ID #$catid";
								$catnames = $db->query_return_array_id("SELECT id, name FROM template_words_cat", 'name');
							}
							continue;
						}
						if (preg_match("/^([^:]*):(.*)$/", $line, $matches)) {
							$matches[1] = mysql_escape_string(trim($matches[1]));
							$matches[2] = mysql_escape_string(trim($matches[2]));
							$db->query("SELECT * FROM template_words WHERE
								wordref = '$matches[1]' AND
								language = '$langid'
							");
							if ($db->num_rows()) {
								if (!$matches[2]) {
									if (!$_REQUEST['dryrun']) {
										$db->query("DELETE FROM template_words
											WHERE wordref = '$matches[1]' AND
											language = '$landid'
										");
									}
									$imported[$matches[1]][$langid] = -4;
								}
								if (!$_REQUEST['dryrun'] AND !$_REQUEST['replace_all']) {
									$db->query("
										UPDATE template_words SET
											category = '$catid',
											text = '$matches[2]'
										WHERE
											wordref = '$matches[1]'
											AND language = '$langid'
									");
									if ($db->affected_rows()) {
										$imported[$matches[1]][$langid] = -1;
									} else {
										$imported[$matches[1]][$langid] = -2;
									}
								} else {
									if ($imported[$matches[1]][$langid] == 0) {
										$imported[$matches[1]][$langid] = -1;
									}
								}
							} else {
								if (!$_REQUEST['dryrun']) {
									$db->query("INSERT INTO template_words (wordref, category, text, language)
										VALUES ('$matches[1]', '$catid', '$matches[2]', '$langid')
									");
								}
								$imported[$matches[1]][$langid] = -3;
							}
						} else {
							$errors[] = "Error in file " . $languages[$langid]['file'] . " on line $count.";
						}
					}
				}
			}
		}
	
		$cols = array('Template Name');
		foreach ($languages as $lang) {
			$cols[] = $lang['name'];
		}

		foreach ($imported AS $template => $val) {
			$row = array($template);
			foreach ($languages AS $lang_id => $lang) {
				if ($val[$lang_id] == -1) {
					$result = iff($_REQUEST['dryrun'], '<FONT COLOR="green">Would Import</FONT>', '<FONT COLOR="green">Imported</FONT>');
				} elseif ($val[$lang_id] == -2) {
					$result = '<FONT COLOR="green">No Change</FONT>';
				} elseif ($val[$lang_id] == -3) {
					$result = iff($_REQUEST['dryrun'], '<FONT COLOR="green">Would Add</FONT>', '<FONT COLOR="green">Added</FONT>');
				} elseif ($val[$lang_id] == -4) {
					$result = iff($_REQUEST['dryrun'], '<FONT COLOR="red">Would Delete</FONT>', '<FONT COLOR="red">Deleted</FONT>');
				} elseif ($val[$lang_id] === FALSE) {
					$result = '<FONT COLOR="red">Error</FONT>';
				} else {
					$result = 'Not defined';
				}
				$row[] = "<CENTER>$result</CENTER>";
				if (is_string($val[$lang_id])) {
					$errors[] = $val[$lang_id];
				}
			}
			$rows[] = $row;
		}
	}	

	table_header('Import Results');
	table_content($cols, $rows);
	table_footer();

	if (count($errors)) {
		table_header('Import Errors');
		table_content(NULL, $errors);
		table_footer();
	}
	return;
}

/*****************************************************
	function dev_install_words_default()

-----DESCRIPTION: -----------------------------------
	Imports all language translations.

-----ARGUMENTS: -------------------------------------
	location	Directory to import from

-----RETURNS: ---------------------------------------
	Nothing.

*****************************************************/

function dev_install_words_default() {

	global $db;

	$db->query("SELECT * FROM template_words WHERE language = '1'");
	while ($result = $db->row_array()) {

		$data[] = array(
			$result['wordref'],
			0,
			$result['text'],
			$result['category'],
			0
		);

	}
	$db->query("
		INSERT INTO template_words 
		(wordref, language, text, category, cust) 
		VALUES " . multi_array2sql($data) . "
	");

}


⌨️ 快捷键说明

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