📄 general_functions.php
字号:
/*****************************************************
function dp_setcookie
-----DESCRIPTION: -----------------------------------
Set a cookie.
-----ARGUMENTS: -------------------------------------
name Cookie name
value Cookie value
length [Optional] Cookie lifetime (in seconds)
-----RETURNS: ---------------------------------------
Nothing; directly produces output
*****************************************************/
function dp_setcookie($name, $value, $length=NULL) {
global $settings; _a();
$time = (int)time();
if ($length == 'ever') {
$time += (int)(60 * 60 * 24 * 365 * 10); // 10 years
} elseif ($length > 0) {
if ($length > $time) {
$time = $length;
} else {
$time += (int)$length;
}
} elseif ($length == -1) {
$time = 1; $value = '';
} else {
$time = NULL;
}
if (!$settings['cookie_path']) {
$settings['cookie_path'] = '/';
}
setcookie($name, $value, $time, $settings['cookie_path'], '', 0);
}
/*****************************************************
function date_format
-----DESCRIPTION: -----------------------------------
Transform a timestamp into a formatted human-readable
date string as specified.
-----ARGUMENTS: -------------------------------------
date Date to convert
format [Default = 'day']
day Use the "date_day" format
full Use the "date_full" format
time Use the "date_time" format
-----RETURNS: ---------------------------------------
The formatted date string.
*****************************************************/
function date_format($date, $format='day') {
global $settings;
if ($format == 'day') {
return date($settings[date_day], $date);
} elseif ($format == 'full') {
return date($settings[date_full], $date);
} elseif ($format == 'time') {
return date($settings[date_time], $date);
}
}
/*****************************************************
function insert sql
-----DESCRIPTION: -----------------------------------
Generate the data subclause for MySQL's multiple-insert
query syntax from the given flat array.
-----ARGUMENTS: -------------------------------------
array Array of items to add (should be one-dimensional)
-----RETURNS: ---------------------------------------
The subclause, suitable for use in a query like
"INSERT INTO TABLE (col1, ... coln) VALUES $foo",
where $foo is the return value of this function.
*****************************************************/
function insertsql($array) {
if (!is_array($array)) {
return NULL;
}
foreach ($array AS $key => $var) {
$sql .= "(";
if (is_array($var)) { // multi column array
foreach ($var AS $key2 => $bit) {
$sql .= '\'' . mysql_escape_string($bit) . '\' ,';
}
} else { // only two column array
$sql .= "'" . mysql_escape_string($key) . '\',\'' . mysql_escape_string($var) . '\',';
}
$sql = substr($sql, 0, -1);
$sql .= '), ';
}
$sql = substr($sql,0,-2);
return $sql;
}
/*****************************************************
function doloop
-----DESCRIPTION: -----------------------------------
Perform the actual loop logic for a template.
*****************************************************/
function doloop($name, $data, $template, $GLOBALS) {
extract($GLOBALS, EXTR_SKIP);
unset($html, $loop_iteration);
$template = str_replace("loop-temp-section", "'", $template);
if (is_array($data)) {
foreach ($data AS $key => $var) {
${$name} = $var; // convert variable back into proper namespace
eval("\$html .= \"".$template."\";");
$loop_iteration ++;
}
}
return $html;
}
/*****************************************************
function getemailtemplate
-----DESCRIPTION: -----------------------------------
Retrieve the specified email template for the given
language.
-----ARGUMENTS: -------------------------------------
template_name Name of template to retrieve
language (integer) language to retrieve
-----RETURNS: ---------------------------------------
An associative array, containing:
'body' => the template body
'subject' => the e-mail's subject
if a template is found, or:
NULL, NULL
if the template is *not* found.
*****************************************************/
function getemailtemplate($template_name, $language = NULL) {
global $emailtemplate_cache, $session, $settings, $db;
if (!$language AND $settings['default_language']) {
$language = $settings['default_language'];
} elseif (!$language) {
$language = 1;
}
if (!isset($emailtemplate_cache[$language][$template_name])) {
// need a new sql class
global $db_user, $db_password, $host, $dbname;
$db3 = new_db_class(3);
// determine ordering method
if ($session['language'] > $settings['default_language']) {
$order = "DESC";
} else {
$order = "ASC";
}
if (defined('TEMPLATEFILES')) {
$db->query("SELECT id, name FROM languages WHERE id = '" . mysql_escape_string($language) . "'");
while ($res = $db->row_array()) {
$lang[$res['id']] = "/$res[name]";
}
// If we're grabbing a TECHBODY template, just grab from templates/email/
if (stristr($template_name, 'TECHBODY')) {
$lang[$language] = "";
}
require_once(INCLUDE_PATH . 'functions/conditional_functions.php');
if (defined('GATEWAYZONE')) {
$location = INCLUDE_PATH . '../admin/';
} elseif (defined('USERZONE')) {
$location = './admin/';
} elseif (defined('TECHZONE')) {
$location = './../../admin/';
} elseif (defined('ADMINZONE')) {
$location = './';
}
$template = @file($location . "templates/email" . $lang[$language] . "/$template_name.txt");
if (preg_match("/^Subject:(.*)$/i", $template[0], $matches)) {
$subject = trim($matches[1]);
array_shift($template);
}
if (preg_match("/^Description:(.*)$/i", $template[0], $matches)) {
$description = trim($matches[1]);
array_shift($template);
}
if (is_array($template)) {
$emailtemplate_cache[$language][$template_name]['body'] = parse_conditionals(join('', $template));
$emailtemplate_cache[$language][$template_name]['subject'] = $subject;
} else {
return array(NULL, NULL);
}
} else {
if (stristr($template_name, 'TECHBODY')) {
$language = "-1";
}
$result = $db3->query_return("
SELECT template, subject
FROM template_email
WHERE name = '" . mysql_escape_string($template_name) . "' AND
(
language = '$language' OR
language = '$settings[default_language]' OR
category = 'Tech Emails'
)
ORDER BY language $order, backup
");
if (is_array($result)) {
$emailtemplate_cache[$language][$template_name]['body'] = $result['template'];
$emailtemplate_cache[$language][$template_name]['subject'] = $result['subject'];
} else {
return array(NULL, NULL);
}
}
}
$template = $emailtemplate_cache[$language][$template_name]['body'];
$subject = $emailtemplate_cache[$language][$template_name]['subject'];
return array(
'body' => str_replace("\'", '\'', $template),
'subject' => $subject
);
}
/*****************************************************
function gettemplate
-----DESCRIPTION: -----------------------------------
Retrieve a HTML template.
-----ARGUMENTS: -------------------------------------
template_name Name of template to retrieve
htmlcomment [Optional] Add a comment to the template
-----RETURNS: ---------------------------------------
The template, ready for eval().
*****************************************************/
function gettemplate($template_name, $htmlcomment=1) {
global $template_cache, $template_group, $session, $settings;
// get template from cache or database
if ($template_name == 'log_out_') {
$template = get_log_out_template();
}
if (isset($template_cache[$template_name])) {
$template = $template_cache[$template_name];
$cached = "CACHED";
} else {
// need a new sql class
global $db_user,$db_password,$host,$dbname;
$db3 = new_db_class(3);
if (defined('TEMPLATEFILES')) {
require_once(INCLUDE_PATH . 'functions/conditional_functions.php');
$template = @implode('', @file("./admin/templates/$template_name.html"));
/*
$template = @file($location . "templates/email" . $lang[$language] . "/$template_name.txt");
if (preg_match("/^Subject:(.*)$/i", $template[0], $matches)) {
$subject = trim($matches[1]);
array_shift($template);
} else {
$subject = '';
}
if (is_array($template)) {
$emailtemplate_cache[$language][$template_name]['body'] = parse_conditionals(join('', $template));
if (preg_match("/^Subject:(.*)$/i", $template[0], $matches)) {
$subject = trim($matches[1]);
array_shift($template);
*/
$template = parse_conditionals($template);
} else {
$result = $db3->query_return("
SELECT *
FROM template
WHERE name = '" . mysql_escape_string($template_name) . "'
ORDER BY backup
");
$template = $result[template];
}
$template_cache[$template_name] = $template;
$cached = "NOT CACHED";
}
unset($htmlcomment);
// add template commenting
if ($htmlcomment) {
return "\n<!-- BEGIN TEMPLATE : $template_name {$cached} -->\n$template\n<!-- END TEMPLATE : $template_name -->\n";
}
return str_replace("\'", '\'', $template);
}
/*****************************************************
function templatecache
-----DESCRIPTION: -----------------------------------
Initialize and load the template cache.
-----ARGUMENTS: -------------------------------------
template_list List of templates to load
email If false, load HTML templates.
If true, load email templates.
-----RETURNS: ---------------------------------------
The initialized template cache.
*****************************************************/
function templatecache($template_list, $email = NULL) {
global $db, $template_group, $language, $settings;
if (defined('TEMPLATEFILES')) {
if (!$language AND $settings['default_language']) {
$language = $settings['default_language'];
} else {
$language = 1;
}
require_once(INCLUDE_PATH . 'functions/conditional_functions.php');
$templates_to_get = explode(',', $template_list);
if (!$email) {
foreach ($templates_to_get AS $key => $var) {
$template = @implode('', @file("./admin/templates/$var.html"));
$template = parse_conditionals($template);
$template_cache[$var] = $template;
}
} else {
$db->query("SELECT id, name FROM languages WHERE id = '" . mysql_escape_string($language) . "'");
while ($res = $db->row_array()) {
$lang[$res['id']] = $res['name'];
}
if (defined('USERZONE')) {
$location = './admin/';
} elseif (
defined('TECHZONE')) {
$location = './../../admin/';
} elseif (defined('ADMINZONE')) {
$loation = './';
}
foreach ($templates_to_get AS $key => $var) {
$template = @file($location . "templates/email/" . $lang[$language] . "/$var.txt");
if (preg_match("/^Subject:(.*)$/i", $template[0], $matches)) {
$subject = ", subject = '" . mysql_escape_string(trim($matches[1])) . "'";
array_shift($template);
} else {
$subject = NULL;
}
$template_cache[$var] = array(
'template' => parse_conditionals(join(NULL, $template)),
'subject' => $subject
);
}
}
return $template_cache;
}
// turn from comma list to SQL
$template_list = str_replace(',', "','", $template_list);
// determine ordering method
if ($language > $settings['default_language']) {
$order = "DESC";
} else {
$order = "ASC";
}
if ($email) {
$table = 'template_email';
} else {
$table = 'template';
}
// get templates from database
$db->query(" SELECT *
FROM $table
WHERE (name IN ('" . mysql_escape_string($template_list) . "'))
ORDER BY backup
");
while ($template = $db->row_array()) {
str_replace("###", "\"", $template);
// use correct language if template is avaliable
if ($array[$template['name']] != "done") {
if ($email) {
$template_cache[$template['name']] = array('template' => $template['template'], 'subject' => $template['subject']);
} else {
$template_cache[$template['name']] = $template['template'];
}
$array[$template['name']] = "done";
}
}
return $template_cache;
}
/*****************************************************
function makeeval
-----DESCRIPTION: -----------------------------------
This function is always called before sending an
email to a user. It updates the $user_details array
to manipulate the greeting
*****************************************************/
function update_user_details($user_details) {
$user_details['greeting'] = ifr($u
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -