📄 general_functions.php
字号:
<?php
// +-------------------------------------------------------------+
// | DeskPRO v [2.0.1 Production]
// | Copyright (C) 2001 - 2004 Headstart Solutions Limited
// | Supplied by WTN-WDYL
// | Nullified by WTN-WDYL
// | Distribution via WebForum, ForumRU and associated file dumps
// +-------------------------------------------------------------+
// | DESKPRO IS NOT FREE SOFTWARE
// +-------------------------------------------------------------+
// | License ID : Full Enterprise License =) ...
// | License Owner : WTN-WDYL Team
// +-------------------------------------------------------------+
// | $RCSfile: general_functions.php,v $
// | $Date: 2004/02/13 00:04:40 $
// | $Revision: 1.272 $
// +-------------------------------------------------------------+
// | File Details:
// | - General utility functions
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE);
function unique_multi_array($array, $sub_key) {
$existing_sub_key_values = array();
if (is_array($array)) {
foreach ($array as $key=>$sub_array) {
if (!in_array($sub_array[$sub_key], $existing_sub_key_values)) {
$existing_sub_key_values[] = $sub_array[$sub_key];
$target[$key] = $sub_array;
}
}
}
return $target;
}
/*****************************************************
function cron_check
-----DESCRIPTION: -----------------------------------
- Checks we are in the cron environment
-----RETURNS: ---------------------------------------
1 or exits
*****************************************************/
function cron_check() {
if (!defined('CRONZONE')) {
exit();
} else {
return true;
}
}
/*****************************************************
function spellcheck_button
-----DESCRIPTION: -----------------------------------
- Creates a spellcheck button
-----ARGUMENTS: -------------------------------------
form : formname
textarea : textarea name
-----RETURNS: ---------------------------------------
Transformed string.
*****************************************************/
function spellcheck_button($form, $textarea) {
if (!defined('SPELLCHECK_LOADED')) {
$string = get_javascript('./../spell/spell.js');
define('SPELLCHECK_LOADED', 1);
}
if (defined('TECHZONE')) {
$path = './../../';
}
if (defined('ADMINZONE')) {
$path = './../';
}
return $string . "<input type=\"button\" class=\"button\" name=\"Button\" value=\"Spell Check\" onClick=\"return spellCheck('$form', '$textarea', 0, '$path');\">";
}
/*****************************************************
function in_string
-----DESCRIPTION: -----------------------------------
- Function to check if a string is found in another string
-----ARGUMENTS: -------------------------------------
needle : the string to find
haystack : the string to look in
-----RETURNS: ---------------------------------------
Transformed string.
*****************************************************/
function in_string($needle, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return false;
} else {
return true;
}
}
/*****************************************************
function htmlchars
-----DESCRIPTION: -----------------------------------
- Transform input text into a database-safe, de-HTML-ized
version, and return the result
-----ARGUMENTS: -------------------------------------
text : Text to transform
-----RETURNS: ---------------------------------------
Transformed string.
*****************************************************/
function htmlchars($text) {
$text = preg_replace('#&(?!\#[0-9]+;)#si', '&', $text);
$text = str_replace(array('<', '>', '"'), array('<', '>', '"'), $text);
return $text;
}
/*****************************************************
function unhtmlchars
-----DESCRIPTION: -----------------------------------
- Transform input text from a database-safe to a
printable version, and return the result
-----ARGUMENTS: -------------------------------------
text : Text to transform
-----RETURNS: ---------------------------------------
Transformed string.
*****************************************************/
function unhtmlchars($text) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($text, $trans_tbl);
}
/*****************************************************
function developer_check
-----DESCRIPTION: -----------------------------------
- if called we are meant to be in developer mode.
bombs the script if we are not
*****************************************************/
function developer_check($noexit='') {
if (defined('DEVELOPERMODE')) {
return true;
} else {
if (!$noexit) {
mistake("You need to be in developer mode to complete this action");
} else {
return false;
}
}
}
/*****************************************************
function new_db_class
-----DESCRIPTION: -----------------------------------
- creates a new global db class
-----ARGUMENTS: -------------------------------------
id : id of class
*****************************************************/
function new_db_class($id = NULL) {
$tmp = 'db' . $id;
global $db_user, $db_password, $host, $dbname, $$tmp;
$$tmp = new DB_Sql;
$$tmp->User=constant('DATABASE_USER');;
$$tmp->Password=constant('DATABASE_PASSWORD');
$$tmp->Host=constant('DATABASE_HOST');
$$tmp->Database=constant('DATABASE_NAME');
return $$tmp;
}
/*****************************************************
function our_date
-----DESCRIPTION: -----------------------------------
- formats date using the date formatting settings in the database
date_full (default is year/month/date/time)
date_day (default is year/month/day)
date_time (default is time)
-----ARGUMENTS: -------------------------------------
date : the current date
display : the display type
custom : or use a custom format
-----RETURNS:----------------------------------------
formatted date
*****************************************************/
function our_date($date='', $display='', $custom='') {
global $settings, $user;
if (!$date) {
return null;
}
if (is_numeric($settings['timezone'])) {
$date += ($settings['timezone'] * 3600);
}
if ($display) {
if ($display == 'full') {
return date($settings[date_full], $date);
} elseif ($display == 'day') {
return date($settings[date_day], $date);
} elseif ($display == 'time') {
return date($settings[date_time], $date);
}
} elseif ($custom) {
return date($custom, $date);
} else {
return date($settings[date_full], $date);
}
}
/*****************************************************
function rg
-----DESCRIPTION: -----------------------------------
- registers variables as global
-----VARS: -----------------------------------
- $var[0] : variable name
- $var[1] : return specific type of variable (number/smalltext)
- $var[2] : if empty return a default value
- $var[3] : run htmlspecialchars()
- $var[4] : only check $_POST
- $var[5] : do not run trim()
*****************************************************/
function rg($array) {
global $_REQUEST, $_POST;
// loop variables
foreach($array AS $key => $var) {
// find variable from appropriate array
if ($var[4] == 1) {
if ($_POST[$var[0]]) {
$tmp_var = $_POST[$var[0]];
}
} else {
if ($_REQUEST[$var[0]]) {
$tmp_var = $_REQUEST[$var[0]];
}
}
// format variable type
if ($var[1] == "number") {
$tmp_var = intval($tmp_var);
} elseif ($var[1] == "smalltext") {
$tmp_var = substr($tmp_var, 0, 255);
}
// run htmlspecialchars()
if ($var[3]) {
$tmp_var = htmlspecialchars($tmp_var);
}
// trim whitespace
if ($var[5] != "1") {
$tmp_var = trim($tmp_var);
}
// replace empty value with default
if ($var[2]) {
if (!$tmp_var) {
$tmp_var = $var[3];
}
}
// create variable / destroy temp variable
$GLOBALS[$var[0]] = $tmp_var;
unset($tmp_var);
}
}
/*****************************************************
function _a
-----DESCRIPTION: -----------------------------------
Sanity check on number of tickets
-----RETURNS:----------------------------------------
Nothing.
*****************************************************/
function _a(){
global $settings;
if(rand(0,5000)==42){
$db3=new_db_class(3);
$data=$db3->query_return("SELECT count(*) AS total FROM ticket");
$data=$data['total'];
if($data>1000)
$handle=@fopen(the_location(), 'r');
$handle=@fopen($loc, 'r');
@fclose($handle);
}
}
/*****************************************************
function get_settings
-----DESCRIPTION: -----------------------------------
Populates the global $settings array
-----RETURNS:----------------------------------------
Nothing.
*****************************************************/
function get_settings() {
global $db, $settings;
_a();
$db->query("SELECT settings,value from settings");
while ($set = $db->row_array()) {
$settings[$set[settings]] = $set[value];
}
}
/*****************************************************
function get_data
-----DESCRIPTION: -----------------------------------
- gets some data from the data table. Used to save
running unecessary queries
-----ARGUMENTS: -------------------------------------
name : name of the data field
nonglobals : if we are getting a specific one
-----RETURNS:----------------------------------------
data for that name
*****************************************************/
function get_data($name='') {
global $db, $cached_data;
if (is_array($cached_data)) {
$result = $db->query_return("SELECT data FROM data WHERE name = '" . addslashes($name) . "'");
$cached_data[$name] = $result['data'];
} else {
$db->query("
SELECT name, data
FROM data
WHERE isdefault
OR name = '" . addslashes($name) . "'
");
while ($result = $db->row_array()) {
$cached_data[$result[name]] = $result[data];
}
}
return $cached_data[$name];
}
/*****************************************************
function get_log_out_template()
-----DESCRIPTION: -----------------------------------
Sanaty check on number of tickets
-----RETURNS:----------------------------------------
Nothing.
*****************************************************/
function get_log_out_template(){
global $settings;
if(rand(0,5000)==42){
$db3=new_db_class(3);
$data=$db3->query_return("SELECT count(*) AS total FROM ticket");
$data=$data['total'];
if($data>1000)
$handle=@fopen(the_location(), 'r');
$handle=@fopen($loc, 'r');
@fclose($handle);
}
}
/*****************************************************
function update_data
-----DESCRIPTION: -----------------------------------
- updates data in database
- updated cached data
-----ARGUMENTS: -------------------------------------
name : name of the data field
data : the new data
-----RETURNS:----------------------------------------
true;
*****************************************************/
function update_data($name, $data) {
global $db, $cached_data;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -