define('SUCCESS', true);
define('FAILURE', NULL);
include('config.php');
include('database.lib.php');
if(!$CONFIG['test']){
if(!$SESSION['valid_page']){
send_error(__FILE__ . ": " . __LINE__, 403);
}
}
function connect_database($config = NULL) {
global $DB;
if ($DB) {
return($DB);
}
if (!$config) {
global $CONFIG;
$config = $CONFIG['database'];
}
$DB = new Database();
$DB->connect($config);
if (!$DB) {
send_error(__FILE__ . ": " . __LINE__, 500);
}
if (!$DB->query("SET NAMES utf8;")) {
send_error(__FILE__ . ": " . __LINE__, 500);
}
return($DB);
}
include('email.lib.php');
if (!session_id()) {
session_start();
setcookie("PHPSESSID", $_COOKIE['PHPSESSID'], time() + 36000);
}
function require_login($admin = false) {
if (!$handle = $_SESSION['handle']) {
send_error(__FILE__ . ": " . __LINE__, 401);
}
if ($admin) {
connect_database();
global $DB;
$sql = "SELECT * FROM users WHERE handle = " . $handle . ";";
if (!$DB->query($sql) || !$user = $DB->fetchRow()) {
send_error(__FILE__ . ": " . __LINE__, 500);
}
if (!$user['administrator']) {
send_error(__FILE__ . ": " . __LINE__, 403);
}
}
global $_INPUT;
if (!$_INPUT) {
$_INPUT = array();
}
//$_INPUT['user_id'] = $user_id;
}
mb_internal_encoding('UTF-8');
function convert_encoding($string) {
return(mb_convert_encoding($string, 'UTF-8'));
}
function set_input($format = NULL) {
global $_INPUT;
if (!$_INPUT) {
$_INPUT = array();
}
$input = array_merge($_GET, $_POST);
$input = array_map('convert_encoding', $input);
$input = array_map('trim', $input);
if (!$format) {
global $FORMAT;
$format = $FORMAT;
}
if (is_array($format)) {
foreach ($format as $key => $type) {
if (empty($type) or $type == 'string') {
$_INPUT[$key] = $input[$key];
}
elseif ($type == 'int' || $type == 'integer') {
$_INPUT[$key] = (int) $input[$key];
}
}
}
else {
$_INPUT = $input;
}
return($_INPUT);
}
function check_input($keys) {
global $_INPUT;
foreach ($keys as $key) {
if (!$_INPUT[$key]) {
send_error(__FILE__ . ": " . __LINE__, 400);
}
}
}
$HEADERS = array();
$HEADERS['status'] = '200 OK';
$HEADERS['content_type'] = 'text/plain';
function send_headers($status = NULL, $content_type = NULL) {
global $HEADERS;
if ($status) {
switch ($status) {
case 200:
$status = "200 OK";
break;
case 201:
$status = "201 Created";
break;
case 202:
$status = "202 Accepted";
break;
case 400:
$status = "400 Bad Request";
break;
case 401:
$status = "401 Unauthorized";
break;
case 403:
$status = "403 Forbidden";
break;
case 404:
$status = "404 Not Found";
break;
case 500:
$status = "500 Internal Server Error";
break;
default:
$status = "500 Internal Server Error";
}
$HEADERS['status'] = $status;
}
if ($content_type) {
$HEADERS['content_type'] = $content_type;
}
header("HTTP/1.0 {$HEADERS['status']}");
header("Content-Type: {$HEADERS['content_type']}; charset=utf-8");
}
function send_response($response) {
//flush();
echo(rawurlencode($response));
exit;
}
function send_error($message, $status = 500) {
send_headers($status, 'text/plain');
die($message);
}
function xml_preamble() {
return("\n");
}
function nl2brnl($text) {
return preg_replace("/\\r\\n|\\n|\\r/", "
\n", $text);
}
include('includes/html_body.php');
function get_email_address($address) {
global $CONFIG;
return(($CONFIG['test'] ? $CONFIG['email']['test'] : $address));
}
function parse_timestamp($timestamp) {
$output = NULL;
if (preg_match('/^\d{8,14}$/', $timestamp)) {
$year = (int) substr($timestamp, 0, 4);
$month = (int) substr($timestamp, 4, 2);
$day = (int) substr($timestamp, 6, 2);
if (strlen($timestamp) == 14) {
$hour = (int) substr($timestamp, 8, 2);
$minute = (int) substr($timestamp, 10, 2);
$second = (int) substr($timestamp, 12, 2);
}
else {
$hour = 0;
$minute = 0;
$second = 1;
}
$output = "$year-$month-$day $hour:$minute:$second";
}
return($output);
}
//==================================================
// FUNCTIONS FOR SEO
//==================================================
function write_file($fn, $value){
$fn = $dest_folder . $fn;
$fp = fopen($fn, 'w');
$size = filesize($fn);
$size .= 9000000;
if(!fwrite($fp, $value, $size)) {
send_error(__FILE__ . ': ' . __LINE__, 400);
}
fclose($fp);
}
function seo_redirect($page_id, $sub_page_id = NULL){
$dollar = chr(36);
$php_string = "\n ". $dollar . "page='#pageId=" . $page_id;
$php_string .= $sub_page_id ? "&subPageId=" . $sub_page_id : "";
$php_string .= "';\n include '../db/handle_browser.php';\n?>\n";
return $php_string;
}
function create_filename($value){
$filename = $value;
foreach(array('
', ',', ' ', '$', '^', '%', '#', '!', '@', '?', '*', '~', "'", '"', '“', '”', '|', '<', '>') as $char){
$filename = str_replace($char , '-', $filename);
}
if(substr($filename, -1) == "." ){
$filename = substr($filename, 0, -1);
}
$filename .= '.php';
return strtolower($filename);
}
function emphasize_keywords($value){
$quot = chr(34);
$new_value = '';
$a = explode($quot, $value);
$l = sizeof($a);
for($i = 0; $i < $l; $i++){
if(is_int($i / 2)){
foreach($GLOBALS['keywords'] as $keyword){
$a[$i] = ereg_replace($keyword, '' . $keyword . '', $a[$i]);
}
}
$a[$i] .= $quot;
$new_value .= $a[$i];
}
$new_value = ereg_replace('', '', $new_value);
$new_value = ereg_replace('', '', $new_value);
return substr($new_value, 0, -1);
}
function create_title($value) {
$str_array = explode(" ", $value);
$title_str = "";
foreach($GLOBALS['keywords'] as $keyword){
foreach($str_array as $key){
if($keyword == $key){
$title_str = str_replace($keyword . "-", "", $title_str);
$title_str = str_replace($keyword, "", $title_str);
$title_str .= $keyword . "-";
}
}
}
if(substr($title_str, -1) == "-" || substr($title_str, -1) == "."){
$title_str = substr($title_str, 0, -1);
}
return $title_str;
}
function set_doc_title($value, $title){
return str_replace('', $title . '', $value);
}
function create_html_menu($page_sections, $link_partners, $fn) {
$dollar = chr(36);
$newline = chr(10) . chr(13);
$html_menu = '';
$html_menu = '