PHP CodeStandard update

- all if/while/for/etc blocks have brackets on same line
- functions have brackets on new line
- no blocks without brackets
- all code starts on col 0 and there are no tab intends anymore

off: came case for classes and class methods
ignore: _ prefix functions (we can't change that anymore)
This commit is contained in:
2018-03-15 17:38:33 +09:00
parent 5226fbcfc3
commit 7d42256a30
42 changed files with 11623 additions and 12013 deletions
+8 -7
View File
@@ -4,8 +4,9 @@
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL)
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
define('USE_DATABASE', true);
// sample config
@@ -15,8 +16,9 @@
// session_name(EDIT_SESSION_NAME);
// session_start();
// basic class test file
foreach (array ('Login', 'Admin.Backend') as $class)
foreach (array ('Login', 'Admin.Backend') as $class) {
_spl_autoload('Class.'.$class.'.inc');
}
$lang = 'en_utf8';
@@ -31,10 +33,11 @@
$edit_access_id = 3;
print "ACL UNIT: ".print_r(array_keys($login->acl['unit']), 1)."<br>";
print "ACCESS CHECK: ".$login->login_check_edit_access($edit_access_id)."<br>";
if ($login->login_check_edit_access($edit_access_id))
if ($login->login_check_edit_access($edit_access_id)) {
$basic->edit_access_id = $edit_access_id;
else
} else {
$basic->edit_access_id = $login->acl['unit_id'];
}
// $basic->debug('SESSION', $basic->print_ar($_SESSION));
@@ -69,8 +72,7 @@
// DEPRICATED CALL
// $basic->adbSetACL($login->acl);
while ($res = $basic->db_return("SELECT * FROM max_test"))
{
while ($res = $basic->db_return("SELECT * FROM max_test")) {
print "TIME: ".$res['time']."<br>";
}
@@ -191,4 +193,3 @@
print $basic->print_error_msg();
print "</body></html>";
?>
+29 -50
View File
@@ -29,8 +29,7 @@
ob_start();
include("config.inc");
// overrride debug flags
if (!DEBUG)
{
if (!DEBUG) {
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
$DB_DEBUG = 0;
@@ -47,8 +46,9 @@
require(LIBS.'Class.Smarty.Extend.inc');
// set default lang if not set otherwise
if (!$lang)
if (!$lang) {
$lang = DEFAULT_LANG;
}
// should be utf8
header("Content-type: text/html; charset=".DEFAULT_ENCODING);
ob_end_flush();
@@ -57,16 +57,14 @@
// create form class
$form = new form($DB_CONFIG[MAIN_DB], $lang);
$form->db_exec("SET search_path TO ".LOGIN_DB_SCHEMA);
if ($form->mobile_phone)
{
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new SmartyML($lang);
if (TARGET == 'live' || TARGET == 'remote')
{
if (TARGET == 'live' || TARGET == 'remote') {
// login
$login->debug_output_all = DEBUG ? 1 : 0;
$login->echo_output_all = 0;
@@ -78,14 +76,11 @@
}
// set the template dir
// WARNING: this has a special check for the mailing tool layout (old layout)
if (defined('LAYOUT'))
{
if (defined('LAYOUT')) {
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$DATA['css'] = LAYOUT.DEFAULT_TEMPLATE.CSS;
$DATA['js'] = LAYOUT.DEFAULT_TEMPLATE.JS;
}
else
{
} else {
$smarty->setTemplateDir(TEMPLATES.DEFAULT_TEMPLATE);
$DATA['css'] = CSS.DEFAULT_TEMPLATE;
$DATA['js'] = JS.DEFAULT_TEMPLATE;
@@ -138,10 +133,11 @@
// MENU START
// request some session vars
if (!$HEADER_COLOR)
if (!$HEADER_COLOR) {
$DATA['HEADER_COLOR'] = "#E0E2FF";
else
} else {
$DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
}
$DATA['USER_NAME'] = $_SESSION["USER_NAME"];
$DATA['EUID'] = $_SESSION["EUID"];
$DATA['GROUP_NAME'] = $_SESSION["GROUP_NAME"];
@@ -151,10 +147,8 @@
//$form->debug('menu', $form->print_ar($PAGES));
// baue nav aus $PAGES ...
for ($i = 0; $i < count($PAGES); $i ++)
{
if ($PAGES[$i]["menu"] && $PAGES[$i]["online"])
{
for ($i = 0; $i < count($PAGES); $i ++) {
if ($PAGES[$i]["menu"] && $PAGES[$i]["online"]) {
$menuarray[] = $PAGES[$i];
}
}
@@ -164,42 +158,35 @@
$SPLIT_FACTOR = 3;
$START_SPLIT_COUNT = 3;
// WTF ?? I dunno what I am doing here ...
for ($i = 9; $i < $COUNT_NAV_POINTS; $i += $START_SPLIT_COUNT)
{
if ($COUNT_NAV_POINTS > $i)
for ($i = 9; $i < $COUNT_NAV_POINTS; $i += $START_SPLIT_COUNT) {
if ($COUNT_NAV_POINTS > $i) {
$SPLIT_FACTOR += 1;
}
}
for ($i = 1; $i <= count($menuarray); $i ++)
{
for ($i = 1; $i <= count($menuarray); $i ++) {
// do that for new array
$j = $i - 1;
$menu_data[$j]['pagename'] = htmlentities($menuarray[($i-1)]["page_name"]);
$menu_data[$j]['filename'] = $menuarray[($i-1)]["filename"].$menuarray[($i-1)]["query_string"];
if ($i == 1 || !(($i - 1) % $SPLIT_FACTOR))
{
if ($i == 1 || !(($i - 1) % $SPLIT_FACTOR)) {
$menu_data[$j]['splitfactor_in'] = 1;
}
if ($menuarray[($i - 1)]["filename"] == $form->get_page_name())
{
if ($menuarray[($i - 1)]["filename"] == $form->get_page_name()) {
$position = $i - 1;
$menu_data[$j]['position'] = 1;
}
else
{
} else {
// add query stuff
// HAS TO DONE LATER ... set urlencode, etc ...
// check if popup needed
if ($menuarray[($i - 1)]["popup"])
{
if ($menuarray[($i - 1)]["popup"]) {
$menu_data[$j]['popup'] = 1;
$menu_data[$j]['rand'] = uniqid(rand());
$menu_data[$j]['width'] = $menuarray[($i-1)]["popup_x"];
$menu_data[$j]['height'] = $menuarray[($i-1)]["popup_y"];
} // popup or not
} // highlight or not
if (!($i % $SPLIT_FACTOR) || (($i + 1) > count($menuarray)))
{
if (!($i % $SPLIT_FACTOR) || (($i + 1) > count($menuarray))) {
$menu_data[$j]['splitfactor_out'] = 1;
} // split
} // for
@@ -213,14 +200,12 @@
$DATA['load'] = $form->form_create_load();
$DATA['new'] = $form->form_create_new();
// SHOW DATA PART
if ($form->yes)
{
if ($form->yes) {
$DATA['form_yes'] = $form->yes;
$DATA['form_my_page_name'] = $form->my_page_name;
// depending on the "get_page_name()" I show different stuff
switch ($form->my_page_name)
{
switch ($form->my_page_name) {
case "edit_users":
$elements[] = $form->form_create_element("login_error_count");
$elements[] = $form->form_create_element("login_error_date_last");
@@ -250,23 +235,20 @@
$elements[] = $form->form_create_element("template");
break;
case "edit_pages":
if (!$form->table_array["edit_page_id"]["value"])
{
if (!$form->table_array["edit_page_id"]["value"]) {
$q = "DELETE FROM temp_files";
$form->db_exec($q);
// gets all files in the current dir ending with .php
$crap = exec("ls *.php", $output, $status);
// now get all that are NOT in de DB
$q = "INSERT INTO temp_files VALUES ";
for ($i = 0; $i < count($output); $i ++)
{
for ($i = 0; $i < count($output); $i ++) {
$t_q = "('".$form->db_escape_string($output[$i])."')";
$form->db_exec($q.$t_q, 'NULL');
}
$elements[] = $form->form_create_element("filename");
}
else // show file menu
{
} else {
// show file menu
// just show name of file ...
$DATA['filename_exist'] = 1;
$DATA['filename'] = $form->table_array["filename"]["value"];
@@ -313,9 +295,8 @@
// add name/value list here
$elements[] = $form->form_show_list_table("edit_access_data");
break;
break;
default:
print "NO NO NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!";
print "[No valid page definition given]";
break;
}
// $form->debug('edit', "Elements: <pre>".$form->print_ar($elements));
@@ -330,8 +311,7 @@
// create main data array
$CONTENT_DATA = array_merge($HEADER, $DATA, $DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($CONTENT_DATA))
{
while (list($key, $value) = each($CONTENT_DATA)) {
$smarty->assign($key, $value);
}
@@ -342,4 +322,3 @@
// debug output
echo $login->print_error_msg();
echo $form->print_error_msg();
?>
+2 -2
View File
@@ -5,8 +5,9 @@
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL)
if ($DEBUG_ALL) {
error_reporting(E_ALL);
}
// sample config
require("config.inc");
@@ -15,4 +16,3 @@
if ($var) {
echo "OUT<br>";
}
?>
+101 -131
View File
@@ -28,23 +28,29 @@
$show_type = $_GET['type']; // P (pic), F (flash), V (video), D (document: word), A (document: pdf), B (binary); , separated string
// default view is list
if (!$view && !$data_id)
if (!$view && !$data_id) {
$view = 'list';
elseif (!$view && $data_id)
} elseif (!$view && $data_id) {
$view = 'list';
}
// default is online
if (!isset($online))
if (!isset($online)) {
$online = 't';
}
// if not set, it is a fresh load
if (!$show_amount)
if (!$show_amount) {
$fresh_load = 1;
}
// the next two are for page view
if (!$start_row)
if (!$start_row) {
$start_row = 0;
if (!$show_amount)
}
if (!$show_amount) {
$show_amount = 12;
if (!$show_type)
}
if (!$show_type) {
$show_type = 'P';
}
// yes no list (online)
$yesno_list['f'] = 'No';
@@ -57,105 +63,92 @@
$sort_order_list['name_en'] = 'Alt Name English';
$sort_order_list['name_ja'] = 'Alt Name Japanese';
$sort_order_list['date_updated'] = 'Updated';
if (!$sort_order)
if (!$sort_order) {
$sort_order = 'date_created';
}
$sort_direction_list['ASC'] = 'Normal';
$sort_direction_list['DESC'] = 'Reverse';
if (!$sort_direction)
if (!$sort_direction) {
$sort_direction = 'ASC';
}
// set if we need to write to any of the set live queues
// a) on page save with set_live
// b) global page with live_queue
// set via QUEUE variable
// create 0 entries for: templates, menu, data_group?
if ($cms->action == 'new' && $cms->action_yes == 'true')
{
if ($cms->action == 'new' && $cms->action_yes == 'true') {
unset($file_uid);
unset($file_id);
unset($file_type);
$new_okay = 1;
}
// file type: P picture, M mouse over picutre, F flash, V video, B binary
if ($cms->action == 'save')
{
if (!$file_type)
if ($cms->action == 'save') {
if (!$file_type) {
$file_type = 'B';
}
$file_ok = false;
if (!$_FILES['file_up']['name'] && !$file_uid)
{
if (!$_FILES['file_up']['name'] && !$file_uid) {
$cms->messages[] = array('msg' => 'No file name given', 'class' => 'error');
$error = 1;
}
if (!$_FILES['file_up']['name'] && $file_uid)
if (!$_FILES['file_up']['name'] && $file_uid) {
$file_ok = true;
}
// echo "FILE TYPE: ".$_FILES['file_up']['type']."<br>";
foreach (split(',', $show_type) as $_show_type)
{
foreach (split(',', $show_type) as $_show_type) {
// check if the uploaded filename matches to the given type
if ($_FILES['file_up']['name'] && preg_match("/jpeg|png|gif/", $_FILES['file_up']['type']) && preg_match("/P/", $show_type))
{
if ($_FILES['file_up']['name'] && preg_match("/jpeg|png|gif/", $_FILES['file_up']['type']) && preg_match("/P/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/swf/", $_FILES['file_up']['type']) && preg_match("/F/", $show_type))
{
if ($_FILES['file_up']['name'] && preg_match("/swf/", $_FILES['file_up']['type']) && preg_match("/F/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/video/", $_FILES['file_up']['type']) && preg_match("/V/", $show_type))
{
if ($_FILES['file_up']['name'] && preg_match("/video/", $_FILES['file_up']['type']) && preg_match("/V/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/msword|vnd.oasis.opendocument.text/", $_FILES['file_up']['type']) && preg_match("/D/", $show_type))
{
if ($_FILES['file_up']['name'] && preg_match("/msword|vnd.oasis.opendocument.text/", $_FILES['file_up']['type']) && preg_match("/D/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/pdf/", $_FILES['file_up']['type']) && preg_match("/A/", $show_type))
{
if ($_FILES['file_up']['name'] && preg_match("/pdf/", $_FILES['file_up']['type']) && preg_match("/A/", $show_type)) {
$file_ok = true;
}
if ($_FILES['file_up']['name'] && preg_match("/B/", $show_type))
if ($_FILES['file_up']['name'] && preg_match("/B/", $show_type)) {
$file_ok = true;
}
}
// write out error messages according to show type
if (!$file_ok)
{
if (preg_match("/P/", $show_type))
{
if (!$file_ok) {
if (preg_match("/P/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a JPEG/PNG/GIF file', 'class' => 'error');
$error = 1;
}
if (preg_match("/F/", $show_type))
{
if (preg_match("/F/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a Flash File', 'class' => 'error');
$error = 1;
}
if (preg_match("/V/", $show_type))
{
if (preg_match("/V/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a Video', 'class' => 'error');
$error = 1;
}
if (preg_match("/D/", $show_type))
{
if (preg_match("/D/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a DOC/ODT file', 'class' => 'error');
$error = 1;
}
if (preg_match("/A/", $show_type))
{
if (preg_match("/A/", $show_type)) {
$cms->messages[] = array('msg' => 'File is not a PDF file', 'class' => 'error');
$error = 1;
}
if (preg_match("/B/", $show_type))
{
if (preg_match("/B/", $show_type)) {
$cms->messages[] = array('msg' => 'No valid file was given', 'class' => 'error');
$error = 1;
}
}
// binary: all okay
// if no error, save data
if (!$error)
{
if ($_FILES['file_up']['name'])
{
if (!$error) {
if ($_FILES['file_up']['name']) {
$mime_type = $_FILES['file_up']['type'];
$file_size = $_FILES['file_up']['size'];
$file_name = $_FILES['file_up']['name'];
@@ -163,46 +156,43 @@
list($width, $height) = getimagesize($_FILES['file_up']['tmp_name']);
$cms->debug('upload', "Width: $width X Height: $height");
// set the file type and the target folder
if (preg_match("/jpeg|png|gif/", $mime_type))
if (preg_match("/jpeg|png|gif/", $mime_type)) {
$file_type = 'P';
elseif (preg_match("/swf/", $mime_type))
} elseif (preg_match("/swf/", $mime_type)) {
$file_type = 'F';
elseif (preg_match("/video/", $mime_type))
} elseif (preg_match("/video/", $mime_type)) {
$file_type = 'V';
elseif (preg_match("/msword|vnd.oasis.opendocument.text/", $mime_type))
} elseif (preg_match("/msword|vnd.oasis.opendocument.text/", $mime_type)) {
$file_type = 'D';
elseif (preg_match("/pdf/", $mime_type))
} elseif (preg_match("/pdf/", $mime_type)) {
$file_type = 'A';
elseif ($mime_type)
} elseif ($mime_type) {
$file_type = 'B';
}
}
// if we have an id -> updated
if ($file_uid)
{
if ($file_uid) {
$q = "UPDATE file SET";
$q_set = " name_en = '".addslashes($name_en)."', name_ja = '".addslashes($name_ja)."', file_name = '".addslashes($file_name)."', online = '".$online."' ";
if ($_FILES['file_up']['name'])
{
if ($_FILES['file_up']['name']) {
$q_set .= ", type = '".$file_type."', mime_type = '$mime_type', file_size = $file_size, size_x = $width, size_y = $height ";
}
$q .= $q_set."WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'live_queue')
{
if (QUEUE == 'live_queue') {
$sql_action = 'UPDATE';
$sql_data = $q_set;
}
}
} else {
// insert new data
else
{
$file_uid = md5(uniqid(rand(), true));
$q = "INSERT INTO file (name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type) VALUES ('".addslashes($name_en)."', '".addslashes($name_ja)."', '".addslashes($file_name)."', '".$online."', '".$mime_type."', $file_size, ".(($width) ? $width : 'NULL').", ".(($height) ? $height : 'NULL').", '".$file_uid."', '".$file_type."')";
$q = "INSERT INTO file (name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type) VALUES (";
$q .= "'".addslashes($name_en)."', '".addslashes($name_ja)."', '".addslashes($file_name)."', '".$online."', '".$mime_type."', ";
$q .= "$file_size, ".(($width) ? $width : 'NULL').", ".(($height) ? $height : 'NULL').", '".$file_uid."', '".$file_type."')";
$cms->db_exec($q);
$file_id = $cms->insert_id;
// if queue
if (QUEUE == 'live_queue')
{
if (QUEUE == 'live_queue') {
$sql_data = $q;
$sql_action = 'INSERT';
}
@@ -211,15 +201,14 @@ $cms->debug('upload', "Width: $width X Height: $height");
$size_y = $height;
$file = DEV_SCHEMA."_".$file_uid;
// now upload the file
if ($_FILES['file_up']['name'])
{
if ($_FILES['file_up']['name']) {
$upload_file = ROOT.MEDIA.$cms->data_path[$file_type].$file;
// wipe out any old tmp data for this new upload
if (is_array(glob(ROOT.TMP."thumb_".$file."*")))
{
foreach (glob(ROOT.TMP."thumb_".$file."*") AS $filename)
if (is_array(glob(ROOT.TMP."thumb_".$file."*"))) {
foreach (glob(ROOT.TMP."thumb_".$file."*") as $filename) {
@unlink($filename);
}
}
# copy file to correct path
$error = move_uploaded_file($_FILES['file_up']['tmp_name'], $upload_file);
@@ -228,8 +217,7 @@ $cms->debug('file_upload', "Orig: ".$cms->print_ar($_FILES['file_up']));
// because I get bogus error info from move_uploaded_file ...
$error = 0;
if ($error)
{
if ($error) {
$cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_filesize"));
$cms->messages[] = array('msg' => 'File upload failed', 'class' => 'error');
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
@@ -237,11 +225,9 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
unset($file_id);
unset($file_uid);
$view = 'list';
}
else
{
} else {
$cms->messages[] = array('msg' => 'File upload successful', 'class' => 'warning');
// $vew = 'list';
// $view = 'list';
}
} // if file upload
// create thumbs + file size
@@ -249,35 +235,34 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
$picture_small = $cms->cache_pictures.$cms->adbCreateThumbnail($file, 80, 60, $file_type, '', $cms->cache_pictures_root);
$file_size = $cms->adbByteStringFormat($file_size);
// for live queue this is here needed
if (QUEUE == 'live_queue')
{
if (QUEUE == 'live_queue') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action";
if ($_FILES['file_up']['name'])
if ($_FILES['file_up']['name']) {
$q .= ", file";
}
$q .= ") VALUES ('".$cms->queue_name."', '".$file_uid."', 'file_uid', '".$sql_action."', 'file', '".$cms->db_escape_string($sql_data)."', '".$cms->queue_key."', '".$cms->action."'";
if ($_FILES['file_up']['name'])
if ($_FILES['file_up']['name']) {
$q .= ", '".ROOT.MEDIA.$cms->data_path[$file_type].$file."#".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."'";
}
$q .= ")";
$cms->db_exec($q);
}
} // if not error
}
if ($cms->action == 'delete' && $cms->action_yes == 'true')
{
if ($cms->action == 'delete' && $cms->action_yes == 'true') {
$file_uid = $cms->action_id;
$q = "SELECT type FROM file WHERE file_uid = '".$file_uid."'";
list ($file_type) = $cms->db_return_row($q);
// get the file type for the file path
$q = "DELETE FROM file WHERE file_uid = '".$file_uid."'";
$cms->db_exec($q);
if (QUEUE == 'set_live')
{
if (QUEUE == 'set_live') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".set_live (table_name, pkid, delete_flag) VALUES ('".$cms->page_name."', ".$file_uid.", 't')";
$cms->db_exec($q);
}
if (QUEUE == 'live_queue')
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES ('".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')";
if (QUEUE == 'live_queue') {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (queue_key, key_value, key_name, type, target, data, group_key, action, file) VALUES (";
$q .= "'".$cms->queue_name."', '".$file_uid."', 'file_uid', 'DELETE', 'file', '', '".$cms->queue_key."', '".$cms->action."', '".ROOT.MEDIA.$cms->data_path[$file_type].PUBLIC_SCHEMA."_".$file_uid."')";
}
@unlink(ROOT.MEDIA.$cms->data_path[$file_type].DEV_SCHEMA."_".$file_uid);
unset($file_uid);
@@ -285,8 +270,7 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
$delete_done = 1;
$view = 'list';
}
if ($cms->action == 'load')
{
if ($cms->action == 'load') {
$file_uid = $cms->action_id;
// load the data
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, type FROM file WHERE file_uid = '".$file_uid."'";
@@ -300,20 +284,16 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
// view to edit
$view = 'edit';
}
if ($cms->action == 'add_new')
{
if ($cms->action == 'add_new') {
$view = 'edit';
}
if ($cms->action == 'view_files' && $cms->action_yes == 'true')
{
if ($cms->action == 'view_files' && $cms->action_yes == 'true') {
$view = 'list';
}
// set delete live
if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete')
{
if ($cms->action_flag == 'set_live' && $cms->action = 'set_delete') {
$q = "SELECT file_uid, pkid, type FROM ".LOGIN_DB_SCHEMA.".set_live sl, file f WHERE sl.pkid = f.file_uid table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q))
{
while ($res = $cms->db_return($q)) {
$q_del = "DELETE FROM ".PUBLIC_SCHEMA.".file WHERE file_uid = '".$res['pkid'].'"';
$cms->db_exec($q_del);
@unlink(ROOT.MEDIA.$cms->data_path[$res['type']].PUBLIC_SCHEMA."_".$res['file_uid']);
@@ -321,31 +301,26 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
$q = "DELETE FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
$cms->db_exec($q);
}
if (DEV_SCHEMA != PUBLIC_SCHEMA)
{
if (DEV_SCHEMA != PUBLIC_SCHEMA) {
// read out possible deleted, to add "delete from live"
$q = "SELECT pkid FROM ".LOGIN_DB_SCHEMA.".set_live WHERE table_name = '".$cms->page_name."' AND delete_flag = 't'";
while ($res = $cms->db_return($q, 3))
{
while ($res = $cms->db_return($q, 3)) {
$cms->DATA['set_delete'][]['pkid'] = $res['pkid'];
}
}
// get th max entries
$q = "SELECT COUNT(file_uid) FROM file ";
$q_search_where = "WHERE type in ('".str_replace(',', "','", $show_type)."') ";
if ($search_what)
{
if ($search_what) {
$q_search_where .= "AND LOWER(name_en) LIKE '%".addslashes(strtolower($search_what))."%' OR name_ja LIKE '%".addslashes($search_what)."%' OR LOWER(file_name) LIKE '%".addslashes(strtolower($search_what))."%' ";
}
$q .= $q_search_where;
// get selection from show_type
list ($file_count) = $cms->db_return_row($q);
if ($cms->action == 'browse')
{
if ($cms->action == 'browse') {
// browse in the list of data
switch ($cms->action_id)
{
switch ($cms->action_id) {
case "<<<<":
$start_row = 0;
break;
@@ -367,24 +342,24 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
}
// check overflow
if ($start_row < 0)
if ($start_row < 0) {
$start_row = 0;
if ($start_row > $file_count)
}
if ($start_row > $file_count) {
$start_row = $file_count - $show_amount;
}
// if we have a "fresh_load"
if ($fresh_load)
{
if ($fresh_load) {
$count = 1;
$q = "SELECT file_uid FROM file ";
if ($q_search_where)
if ($q_search_where) {
$q .= $q_search_where;
}
$q .= "ORDER BY ".$sort_order." ".$sort_direction." ";
while ($res = $cms->db_return($q))
{
while ($res = $cms->db_return($q)) {
// if data_id is set and not file_id, go to the page where the current highlight is, but only if this is a "virgin" load of the page
if ($data_id && ($data_id == $res['file_uid']))
{
if ($data_id && ($data_id == $res['file_uid'])) {
$current_page = floor(($count / $show_amount));
$start_row = $current_page * $show_amount;
$current_page ++;
@@ -394,29 +369,26 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
}
// page forward/back buttons settings
if ($start_row > 0)
{
if ($start_row > 0) {
$cms->DATA['show_back'] = 1;
}
$cms->DATA['page_number'] = ceil($start_row / $show_amount) + 1;
$cms->DATA['page_count'] = ceil($file_count / $show_amount);
if ($cms->DATA['page_count'] > 2 && !$current_page)
{
if ($cms->DATA['page_count'] > 2 && !$current_page) {
$current_page = 1;
}
if (($start_row + $show_amount) < $file_count)
{
if (($start_row + $show_amount) < $file_count) {
$cms->DATA['show_forward'] = 1;
}
$q = "SELECT file_id, name_en, name_ja, file_name, online, mime_type, file_size, size_x, size_y, file_uid, type FROM file ";
// if search what, search in name_en, name_ja, file_name for the string
if ($q_search_where)
if ($q_search_where) {
$q .= $q_search_where;
}
$q .= "ORDER BY ".$sort_order." ".$sort_direction." ";
$q .= "LIMIT ".$show_amount." OFFSET ".$start_row;
while ($res = $cms->db_return($q))
{
while ($res = $cms->db_return($q)) {
$data_files[] = array (
'id' => $res['file_id'],
'name_en' => $res['name_en'],
@@ -444,8 +416,7 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
$cms->DATA['file_uid'] = $file_uid;
// write back all the other vars
if (!($delete_done || $new_okay))
{
if (!($delete_done || $new_okay)) {
// data name
$cms->DATA['file_name'] = $file_name;
$cms->DATA['name_en'] = $name_en;
@@ -468,8 +439,9 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
$cms->DATA['yesno_list'] = $yesno_list;
$cms->DATA['start_row'] = $start_row;
$cms->DATA['show_amount'] = $show_amount;
if ($data_id)
if ($data_id) {
$cms->DATA['data_id'] = $data_id;
}
$cms->DATA['top'] = 0;
$cms->DATA['left'] = 0;
@@ -482,5 +454,3 @@ $cms->debug('file_upload', "ERROR: $error | INI FSize: ".ini_get("upload_max_fil
//------------------------------ footer
require("footer.inc");
//------------------------------ footer
?>
-1
View File
@@ -10,4 +10,3 @@
// print debug messages
echo $login->print_error_msg();
echo $cms->print_error_msg();
?>
+16 -14
View File
@@ -9,8 +9,9 @@
//------------------------------ variable init start
// for dev test we set full error reporting; writes everything, except E_ERROR into logs/php_error-<day>.log
if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING)
if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING) {
include("libs/Error.Handling.inc");
}
// predefine vars
$lang = '';
$messages = array ();
@@ -22,25 +23,26 @@
// set output to quiet for load of classes & session settings
ob_start();
require("config.inc");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
// login class, DB connections & Admin class, Smarty extension
foreach (array ('Login', 'Admin.Backend', 'Smarty.Extend') as $class)
foreach (array ('Login', 'Admin.Backend', 'Smarty.Extend') as $class) {
_spl_autoload('Class.'.$class.'.inc');
}
//------------------------------ library include end
//------------------------------ basic variable settings start
// set encoding
if (!isset($encoding))
if (!isset($encoding)) {
$encoding = DEFAULT_ENCODING;
}
// set the default lang, if not given
if (session_id() && $_SESSION['DEFAULT_LANG'])
if (session_id() && $_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
elseif (!$lang)
} elseif (!$lang) {
$lang = DEFAULT_LANG;
}
// end the stop of the output flow, but only if we didn't request a csv file download
if (array_key_exists('action', $_POST) && $_POST['action'] != 'download_csv')
{
if (array_key_exists('action', $_POST) && $_POST['action'] != 'download_csv') {
header("Content-type: text/html; charset=".$encoding);
ob_end_flush();
}
@@ -50,8 +52,9 @@
// login & page access check
$login = new login($DB_CONFIG[LOGIN_DB], $lang);
// post login lang check
if ($_SESSION['DEFAULT_LANG'])
if ($_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
}
// create smarty object
$smarty = new SmartyML($lang);
// create new DB class
@@ -77,8 +80,9 @@
);
// log action
// no log if login
if (!$login->login)
if (!$login->login) {
$cms->adbEditLog('Submit', $data, 'BINARY');
}
//------------------------------ logging end
//------------------------------ page rights start
@@ -89,8 +93,7 @@
// automatic hide for DEBUG messages on live server
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE)
{
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) {
$login->debug_output_all = 0;
$login->echo_output_all = 0;
$login->print_output_all = 0;
@@ -99,4 +102,3 @@
$cms->print_output_all = 0;
}
$cms->DATA['JS_DEBUG'] = DEBUG;
?>
-2
View File
@@ -49,5 +49,3 @@
$month_short[10] = "Oct";
$month_short[11] = "Nov";
$month_short[12] = "Dec";
?>
+31 -25
View File
@@ -8,28 +8,32 @@
*********************************************************************/
// template path
if ($_SESSION['TEMPLATE'])
if ($_SESSION['TEMPLATE']) {
$TEMPLATE = $_SESSION['TEMPLATE'];
elseif ($LOCAL_TEMPLATE)
} elseif ($LOCAL_TEMPLATE) {
$TEMPLATE = $LOCAL_TEMPLATE;
else
} else {
$TEMPLATE = DEFAULT_TEMPLATE;
}
$TEMPLATE_DIR = $TEMPLATE.'/';
// master template
if (!$MASTER_TEMPLATE_NAME)
if (!$MASTER_TEMPLATE_NAME) {
$MASTER_TEMPLATE_NAME = MASTER_TEMPLATE_NAME;
}
// just emergency fallback for language
// set encoding
if ($_SESSION['DEFAULT_CHARSET'])
if ($_SESSION['DEFAULT_CHARSET']) {
$encoding = $_SESSION['DEFAULT_CHARSET'];
elseif (!$encoding)
} elseif (!$encoding) {
$encoding = DEFAULT_ENCODING;
}
// just emergency fallback for language
if ($_SESSION['DEFAULT_LANG'])
if ($_SESSION['DEFAULT_LANG']) {
$lang = $_SESSION['DEFAULT_LANG'];
elseif (!$lang)
} elseif (!$lang) {
$lang = DEFAULT_LANG;
}
// create the char lang encoding
$lang_short = substr($lang, 0, 2);
@@ -59,21 +63,20 @@
$cms->pictures = LAYOUT.$TEMPLATE_DIR.IMAGES."/";
$cms->cache_pictures = LAYOUT.$TEMPLATE_DIR.CACHE.IMAGES.'/';
$cms->cache_pictures_root = ROOT.$cms->cache_pictures;
if (!is_dir($cms->cache_pictures_root))
if (!is_dir($cms->cache_pictures_root)) {
mkdir($cms->cache_pictures_root);
}
$template_set = $TEMPLATE;
// if we don't find the master template, set the template path back AND set the insert template as absolute path
if (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".MASTER_TEMPLATE_NAME))
{
if (file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME))
if (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".MASTER_TEMPLATE_NAME)) {
if (file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME)) {
$TEMPLATE_NAME = ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME;
}
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
}
} elseif (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME)) {
// check if the template exists in the template path, if not, set path to to default
elseif (!file_exists(ROOT.$smarty->getTemplateDir()[0]."/".$TEMPLATE_NAME))
{
$smarty->setTemplateDir(LAYOUT.DEFAULT_TEMPLATE.TEMPLATES);
$template_set = DEFAULT_TEMPLATE;
}
@@ -81,26 +84,31 @@
// check if file exists, if not reset to default path
// check if the javascript folder exists in the template path, if not fall back to default
if (!is_dir($cms->javascript))
if (!is_dir($cms->javascript)) {
$cms->javascript = LAYOUT.DEFAULT_TEMPLATE.JS."/";
}
// check if lang_dir folder exists in the template path, if not fall back to default
if (!is_dir($cms->lang_dir))
if (!is_dir($cms->lang_dir)) {
$cms->lang_dir = LAYOUT.DEFAULT_TEMPLATE.LANG."/";
}
// check if include folder exists in the template path, if not fall back to default
if (!is_dir($cms->includes))
if (!is_dir($cms->includes)) {
$cms->includes = LAYOUT.DEFAULT_TEMPLATE.INCLUDES."/";
}
// check if css folder exists in the template path, if not fall back to default
if (!is_dir($cms->css))
if (!is_dir($cms->css)) {
$cms->css = LAYOUT.DEFAULT_TEMPLATE.CSS."/";
if (!is_dir($cms->pictures))
}
if (!is_dir($cms->pictures)) {
$cms->pictures = LAYOUT.DEFAULT_TEMPLATE.PICTURES.'/';
if (!is_dir($cms->cache_pictures))
}
if (!is_dir($cms->cache_pictures)) {
$cms->cache_pictures = LAYOUT.DEFAULT_TEMPLATE.CACHE.IMAGES.'/';
}
// if the template_dir is != DEFAULT_TEMPLATE, then try to make a lang switch
// if the default lang is not like the lang given, switch lang
if (false === strstr(LAYOUT.DEFAULT_TEMPLATE.LANG, $cms->lang_dir) || strcasecmp(DEFAULT_LANG, $lang))
{
if (false === strstr(LAYOUT.DEFAULT_TEMPLATE.LANG, $cms->lang_dir) || strcasecmp(DEFAULT_LANG, $lang)) {
$cms->debug('LANG', 'Orig: '.LAYOUT.DEFAULT_TEMPLATE.LANG.', New: '.$cms->lang_dir.' | Orig Lang: '.DEFAULT_LANG.', New Lang: '.$lang);
$cms->l->l10nReloadMOfile($lang, $cms->lang_dir);
$smarty->l10n->l10nReloadMOfile($lang, $cms->lang_dir);
@@ -109,5 +117,3 @@
// $cms->debug("LANGUAGE", "L: $lang | ".$cms->lang_dir." | MO File: ".$cms->l->mofile);
$cms->debug("LANGUAGE", "SL: ".$_SESSION['DEFAULT_CHARSET']." | ".$_SESSION['LANG']." | ".$_SESSION['DEFAULT_LANG']);
$cms->debug("TEMPLATE", "P: ".$smarty->getTemplateDir()[0]);
?>
+8 -15
View File
@@ -10,8 +10,9 @@
// trigger flags
$cms->HEADER['USE_PROTOTYPE'] = USE_PROTOTYPE;
// scriptacolous, can only be used with prototype
if (USE_PROTOTYPE)
if (USE_PROTOTYPE) {
$cms->HEADER['USE_SCRIPTACULOUS'] = USE_SCRIPTACULOUS;
}
// jquery and prototype should not be used together
$cms->HEADER['USE_JQUERY'] = USE_JQUERY; // don't use either of those two toger
@@ -19,32 +20,27 @@
// paths are set in the 'set_paths.inc' file
// check if we have an external file with the template name
if (file_exists($cms->includes.$cms->INC_TEMPLATE_NAME) && is_file($cms->includes.$cms->INC_TEMPLATE_NAME))
{
if (file_exists($cms->includes.$cms->INC_TEMPLATE_NAME) && is_file($cms->includes.$cms->INC_TEMPLATE_NAME)) {
include($cms->includes.$cms->INC_TEMPLATE_NAME);
}
// additional per page Javascript include
$cms->JS_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_TEMPLATE_NAME))
{
if (file_exists($cms->javascript.$cms->JS_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_TEMPLATE_NAME)) {
$cms->JS_INCLUDE = $cms->javascript.$cms->JS_TEMPLATE_NAME;
}
// per page css file
$cms->CSS_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_TEMPLATE_NAME))
{
if (file_exists($cms->css.$cms->CSS_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_TEMPLATE_NAME)) {
$cms->CSS_INCLUDE = $cms->css.$cms->CSS_TEMPLATE_NAME;
}
// optional CSS file
$cms->CSS_SPECIAL_INCLUDE = '';
if (file_exists($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME))
{
if (file_exists($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME) && is_file($cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME)) {
$cms->CSS_SPECIAL_INCLUDE = $cms->css.$cms->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$cms->JS_SPECIAL_INCLUDE = '';
if (file_exists($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME))
{
if (file_exists($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME) && is_file($cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME)) {
$cms->JS_SPECIAL_INCLUDE = $cms->javascript.$cms->JS_SPECIAL_TEMPLATE_NAME;
}
@@ -94,10 +90,7 @@
// create main data array
$cms->CONTENT_DATA = array_merge($cms->HEADER, $cms->DATA, $cms->DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)
while (list($key, $value) = each($cms->CONTENT_DATA))
{
while (list($key, $value) = each($cms->CONTENT_DATA)) {
$smarty->assign($key, $value);
}
$smarty->display($MASTER_TEMPLATE_NAME, $TEMPLATE.$lang, $TEMPLATE.$lang);
?>
-1
View File
@@ -18,4 +18,3 @@
require("smarty.inc");
require("footer.inc");
?>
@@ -74,4 +74,3 @@
)
)
);
?>
@@ -97,4 +97,3 @@
) // edit pages ggroup
)
);
?>
@@ -70,4 +70,3 @@
),
"table_name" => "edit_language"
);
?>
@@ -35,4 +35,3 @@
)
)
);
?>
@@ -175,4 +175,3 @@
) // query_string element list
) // element list
);
?>
@@ -52,4 +52,4 @@
)
)
); // main array
?>
@@ -251,4 +251,3 @@
) // edit pages ggroup
)
);
?>
@@ -28,4 +28,3 @@
)
)
);
?>
+9 -14
View File
@@ -12,6 +12,8 @@
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
@@ -186,9 +188,8 @@
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME) = explode(":", $_SERVER['HTTP_HOST']);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE)
{
list($HOST_NAME, $PORT) = array_pad(explode(":", $_SERVER['HTTP_HOST'], 2), 2, null);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE) {
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
@@ -229,18 +230,15 @@
'/usr/local/bin'
);
// find convert
foreach ($paths as $path)
{
if (file_exists($path."/convert") && is_file($path."/convert"))
{
foreach ($paths as $path) {
if (file_exists($path."/convert") && is_file($path."/convert")) {
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
}
// turn off debug if debug flag is OFF
if (DEBUG == false)
{
if (DEBUG == false) {
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
@@ -267,14 +265,11 @@
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder)
{
if (file_exists($folder.$include_file))
{
foreach ($dirs as $folder) {
if (file_exists($folder.$include_file)) {
require_once($folder.$include_file);
return true;
}
}
return false;
}
?>
+9 -14
View File
@@ -12,6 +12,8 @@
DEFINE('EDIT_SESSION_NAME', "<ADMIN SESSION NAME>");
// frontend
DEFINE('SESSION_NAME', "<SESSION NAME>");
// set the session name
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
/************* LANGUAGE / ENCODING *******/
DEFINE('DEFAULT_LANG', "en_utf8");
@@ -186,9 +188,8 @@
// live frontend pages
// ** missing live domains **
// get the name without the port
list($HOST_NAME) = explode(":", $_SERVER['HTTP_HOST']);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE)
{
list($HOST_NAME, $PORT) = array_pad(explode(":", $_SERVER['HTTP_HOST'], 2), 2, null);
if (!$DB_HOST[$HOST_NAME] && $USE_DATABASE) {
echo "No matching DB config found. Contact Admin<br>";
exit -1;
}
@@ -229,18 +230,15 @@
'/usr/local/bin'
);
// find convert
foreach ($paths as $path)
{
if (file_exists($path."/convert") && is_file($path."/convert"))
{
foreach ($paths as $path) {
if (file_exists($path."/convert") && is_file($path."/convert")) {
// image magick convert location
DEFINE('CONVERT', $path."/convert");
}
}
// turn off debug if debug flag is OFF
if (DEBUG == false)
{
if (DEBUG == false) {
$ECHO_ALL = 0;
$DEBUG_ALL = 0;
$PRINT_ALL = 0;
@@ -267,14 +265,11 @@
__DIR__.'/'.SMARTY
);
// try to find and load the class ifle
foreach ($dirs as $folder)
{
if (file_exists($folder.$include_file))
{
foreach ($dirs as $folder) {
if (file_exists($folder.$include_file)) {
require_once($folder.$include_file);
return true;
}
}
return false;
}
?>
+133 -211
View File
@@ -15,416 +15,353 @@
padding: 0;
} */
body
{
body {
background-color: white;
color: black;
font-size : 8pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
}
.large
{
.large {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 16pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.big
{
.big {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 12pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.normal
{
.normal {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 9pt;
font-family: Verdana,Arial,Helvetica,sans-serif;
}
.small
{
font-size : 8pt;
.small {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
}
.smallbold
{
font-size : 8pt;
.smallbold {
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size : 8pt;
font-weight: bold;
}
a:link
{
a:link {
color: #FF0000;
text-decoration: none;
}
a:active
{
a:active {
color: #FFFF00;
text-decoration: none;
}
a:visited
{
a:visited {
color: #550000;
text-decoration: none;
}
a:hover, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover
{
color: #FF0000;
a:hover, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover {
background-color: #e5e5e5;
border-bottom: 1px dotted red;
color: #FF0000;
}
a:focus, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover
{
color: #ff0000;
a:focus, a.item_loaded:hover, a.item_deleted:hover, a.item_loaded_deleted:hover {
background-color: #b3b3b3;
border-top: 1px dotted red;
border-bottom: 1px dotted red;
border-top: 1px dotted red;
color: #ff0000;
}
/* link highlight */
a.item_loaded
{
font-weight: bold;
color: #451010;
a.item_loaded {
background-color: #d5d6d6;
color: #451010;
font-weight: bold;
}
a.item_deleted
{
a.item_deleted {
text-decoration: line-through;
}
a.item_loaded_deleted
{
text-decoration: line-through;
font-weight: bold;
color: #451010;
a.item_loaded_deleted {
background-color: #d5d6d6;
color: #451010;
font-weight: bold;
text-decoration: line-through;
}
/* experimental */
input[type="text"]
{
border: 1px solid #999999;
input[type="text"] {
background-color: #efefef;
}
input[type="password"]
{
border: 1px solid #999999;
}
input[type="submit"]
{
input[type="password"] {
border: 1px solid #999999;
}
input[type="submit"] {
border: 1px solid #666666;
}
input[type="checkbox"]
{
input[type="checkbox"] {
border: 1px solid #999999;
}
input[type="radio"]
{
input[type="radio"] {
border: 1px solid #999999;
}
input[type="file"]
{
input[type="file"] {
border: 1px solid #999999;
}
input[type="button"]
{
input[type="button"] {
border: 1px solid #999999;
}
textarea
{
border: 1px solid #999999;
textarea {
background-color: #efefef;
border: 1px solid #999999;
}
select
{
border: 1px solid #999999;
select {
background-color: #efefef;
border: 1px solid #999999;
}
/* mouse over */
input[type=submit]:hover, input[type=button]:hover, input[type="text"]:hover, input[type="password"]:hover, input[type="checkbox"]:hover, input[type="radio"]:hover, input[type="file"]:hover, textarea:hover, select:hover
{
input[type=submit]:hover, input[type=button]:hover, input[type="text"]:hover, input[type="password"]:hover, input[type="checkbox"]:hover, input[type="radio"]:hover, input[type="file"]:hover, textarea:hover, select:hover {
border: 1px dashed red;
}
/* selected */
input[type=submit]:focus, input[type=button]:focus, input[type="password"]:focus, input[type="checkbox"]:focus, input[type="radio"]:focus, input[type="file"]:focus
{
border: 1px solid red;
input[type=submit]:focus, input[type=button]:focus, input[type="password"]:focus, input[type="checkbox"]:focus, input[type="radio"]:focus, input[type="file"]:focus {
background-color: #ffffff;
border: 1px solid red;
}
input[type="text"]:focus, textarea:focus, select:focus
{
border: 1px solid red;
input[type="text"]:focus, textarea:focus, select:focus {
background-color: #ffffff;
border: 1px solid red;
}
/* error & status layouts for messges */
.error
{
.error {
border: 1px solid red;
margin: 5px;
padding: 2px;
color: red;
margin: 5px;
padding: 2px;
text-align: center;
}
.warning
{
.warning {
border: 1px solid #df7700;
margin: 5px;
padding: 2px;
color: #d57200;
text-align: center;
}
.info
{
border: 1px solid #72C47E;
margin: 5px;
padding: 2px;
color: #1D731A;
text-align: center;
}
.div_error
{
border: 1px solid red;
margin-top: 1px;
margin-bottom: 1px;
.info {
border: 1px solid #72C47E;
color: #1D731A;
margin: 5px;
padding: 2px;
text-align: center;
}
.div_warning
{
.div_error {
border: 1px solid red;
margin-bottom: 1px;
margin-top: 1px;
}
.div_warning {
border: 1px solid #df7700;
}
/* borders */
.border_all
{
.border_all {
border: 1px solid black;
}
.border_bottom_title
{
font-weight: bold;
.border_bottom_title {
border-bottom: 1px solid black;
font-weight: bold;
}
.border_top
{
.border_top {
border-top: 1px solid #DCDCCC;
}
.border_all_error
{
.border_all_error {
border: 1px solid red;
}
.border_group
{
.border_group {
border: 1px solid #a89c5a;
}
.border_master
{
.border_master {
border: 1px solid white;
}
.border_sub
{
.border_sub {
border: 1px solid gray;
}
.border_sub_sub
{
.border_sub_sub {
border: 1px solid #e5ddba;
}
/* employee hardware/software borders */
.border_hardware
{
.border_hardware {
background-color: #e9e9e9;
border: 2px solid black;
background-color: #e9e9e9;
}
.border_hardware_usage_end
{
.border_hardware_usage_end {
background-color: #e9e9e9;
border: 2px solid red;
background-color: #e9e9e9;
}
.border_hardware_line
{
border-left: 2px solid black;
.border_hardware_line {
border-bottom: 2px solid black;
border-left: 2px solid black;
}
.border_software
{
border: 2px solid #a89c5a;
.border_software {
background-color: #d5d4c8;
border: 2px solid #a89c5a;
}
.border_software_line
{
border-left: 2px solid #a89c5a;
.border_software_line {
border-bottom: 2px solid #a89c5a;
border-left: 2px solid #a89c5a;
}
.border_software_line_left
{
.border_software_line_left {
border-left: 2px solid #a89c5a;
padding-bottom: 10px;
}
.border_software_line_bottom
{
.border_software_line_bottom {
border-bottom: 2px solid #a89c5a;
padding-left: 2px;
}
/* highlight */
.highlight
{
.highlight {
background-color: #e7e7e7;
font-weight: bold;
}
/* hide & show */
.visible
{
.visible {
visibility: visible;
}
.hidden
{
visibility: hidden;
.hidden {
display: none;
visibility: hidden;
}
/* spacer for line break in float elements */
div.spacer
{
.spacer {
clear: both;
}
/* unique definitions */
/* main body */
/* menu on top */
.menu
{
.menu {
border-bottom: 1px solid #a4a4a4;
font-size: 10px;
}
.pagename
{
text-align: center; font-size: 15px;
.pagename {
background-color: #e7e7e7;
font-size: 15px;
font-weight: bold;
padding: 5px;
text-align: center;
}
/* overlay side menu */
.sidemenu
{
border: 1px solid black;
.sidemenu {
background-color: white;
border: 1px solid black;
}
.buttongroup
{
.buttongroup {
border: 1px solid #e5ddba;
}
/* input group field */
/* normal */
.input_group
{
.input_group {
border: 1px solid #e5ddba;
}
/* loaded with id */
.input_group_id
{
.input_group_id {
border: 1px solid #8a7d3a;
}
/* deleted */
.input_group_deleted
{
border: 1px solid #8a7d3a;
.input_group_deleted {
background-color: #d5d4c8;
border: 1px solid #8a7d3a;
}
/* header part */
/* normal */
.input_group_header
{
.input_group_header {
background-color: #e9e9e9;
}
/* loaded with id */
.input_group_header_id
{
.input_group_header_id {
background-color: #d5d5d5;
}
/* deleted */
.input_group_header_deleted
{
.input_group_header_deleted {
background-color: #bfb59d;
}
/* error & warning messages */
.top_error_message
{
.top_error_message {
border: 2px solid red;
color: red;
font-size: 18px;
margin: 5px;
padding: 10px;
border: 2px solid red;
font-size: 18px;
text-align: center;
color: red;
}
.top_inventory_number
{
margin: 5px;
padding: 10px;
.top_inventory_number {
border: 2px solid orange;
font-size: 18px;
text-align: center;
}
.top_info_message
{
border: 2px solid green;
margin: 5px;
padding: 10px;
text-align: center;
font-size: 12px;
}
.debug_message
{
.top_info_message {
border: 2px solid green;
font-size: 12px;
margin: 5px;
padding: 10px;
text-align: center;
}
.debug_message {
border-top: 1px solid #a4a4a4;
color: #a4a4a4;
font-size: 8px;
@@ -434,78 +371,63 @@ div.spacer
/* set all colors here and not in the config file */
/* for edit interface */
.menu_bgcolor
{
.menu_bgcolor {
background-color: #666666;
}
.menu_fgcolor
{
.menu_fgcolor {
background-color: #DDDDDD;
}
.menu_fgcolor_na
{
.menu_fgcolor_na {
background-color: #CCCCCC;
}
.menu_fgcolor_a
{
.menu_fgcolor_a {
background-color: #EEEEEE;
}
.edit_bgcolor
{
.edit_bgcolor {
background-color: #666666;
}
.edit_fgcolor
{
.edit_fgcolor {
background-color: #FFFFDF;
}
.edit_fgcolor_mod_a
{
.edit_fgcolor_mod_a {
background-color: #CECEB5;
}
.edit_fgcolor_mod_b
{
.edit_fgcolor_mod_b {
background-color: #DEDEC3;
}
.edit_fgcolor_2
{
.edit_fgcolor_2 {
background-color: #AADAA2;
}
.edit_fgcolor_no
{
.edit_fgcolor_no {
background-color: #CECEB5;
}
.edit_fgcolor_alt
{
.edit_fgcolor_alt {
background-color: #CCCCCC;
}
.edit_fgcolor_delete
{
.edit_fgcolor_delete {
background-color: red;
}
.font_error
{
.font_error {
color: red;
}
.edit_fgcolor_special
{
.edit_fgcolor_special {
background-color: #EEEEEE;
}
.edit_temp
{
.edit_temp {
background-color: #FFDF6F;
}
+2 -3
View File
@@ -9,9 +9,8 @@
*/
// if debug is set to true, console log messages are printed
if (!DEBUG)
{
if (!DEBUG) {
$($H(window.console)).each(function(w) {
window.console[w.key] = function() {}
window.console[w.key] = function() {};
});
}
+38 -42
View File
@@ -6,50 +6,43 @@
* Some browser detection
*/
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var is_gecko = ((clientPC.indexOf('gecko') != -1) && (clientPC.indexOf('spoofer') == -1)
&& (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0') == -1));
var is_gecko = ((clientPC.indexOf('gecko') != -1) && (clientPC.indexOf('spoofer') == -1) &&
(clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0') == -1));
var is_safari = ((clientPC.indexOf('AppleWebKit') != -1) && (clientPC.indexOf('spoofer') == -1));
var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
if (clientPC.indexOf('opera') != -1)
{
if (clientPC.indexOf('opera') != -1) {
var is_opera = true;
var is_opera_preseven = (window.opera && !document.childNodes);
var is_opera_seven = (window.opera && document.childNodes);
}
function pop(theURL, winName, features)
{
function pop(theURL, winName, features) {
winName = window.open(theURL, winName, features);
winName.focus();
}
function emd_check_checkbox()
{
for (i = 0; i < document.manage_emails.length; i ++)
{
if (document.manage_emails.elements[i].checked == false && document.manage_emails.elements[i].type == 'checkbox')
{
function emd_check_checkbox() {
for (i = 0; i < document.manage_emails.length; i ++) {
if (document.manage_emails.elements[i].checked == false && document.manage_emails.elements[i].type == 'checkbox') {
document.manage_emails.elements[i].checked = true;
}
}
}
function expandTA(ta_id)
{
function expandTA(ta_id) {
var ta;
// if a string comes, its a get by id, else use it as an element pass on
if (!ta_id.length)
if (!ta_id.length) {
ta = ta_id;
else
} else {
ta = document.getElementById(ta_id);
}
var maxChars = ta.cols;
var theRows = ta.value.split("\n");
var numNewRows = 0;
for ( var i = 0; i < theRows.length; i++ )
{
if ((theRows[i].length+2) > maxChars)
{
for ( var i = 0; i < theRows.length; i++ ) {
if ((theRows[i].length+2) > maxChars) {
numNewRows += Math.ceil( (theRows[i].length+2) / maxChars ) ;
}
}
@@ -62,27 +55,27 @@ function expandTA(ta_id)
// DESC: shows or hides the menu
function ShowHideMenu(status, id)
{
if (status == 'show')
{
if (status == 'show') {
document.getElementById(id).style.visibility = 'visible';
if (document.getElementById('search_results').innerHTML)
if (document.getElementById('search_results').innerHTML) {
document.getElementById('search_results').style.visibility = 'visible';
}
else if (status == 'hide')
{
} else if (status == 'hide') {
document.getElementById(id).style.visibility = 'hidden';
if (document.getElementById('search_results').style.visibility == 'visible')
if (document.getElementById('search_results').style.visibility == 'visible') {
document.getElementById('search_results').style.visibility = 'hidden';
}
}
}
function ShowHideDiv(id)
{
element = document.getElementById(id);
if (element.className == 'visible' || !element.className)
if (element.className == 'visible' || !element.className) {
element.className = 'hidden';
else
} else {
element.className = 'visible';
}
// alert('E: ' + element.className + ' -- ' + element.style.visibility);
}
@@ -100,15 +93,17 @@ function mv(id, direction)
function le(id)
{
document.forms[form_name].action.value = 'load';
if (load_id)
if (load_id) {
document.forms[form_name].action_yes.value = confirm('Do you want to load this data?');
else
} else {
document.forms[form_name].action_yes.value = 'true';
}
document.forms[form_name].action_id.value = id;
document.forms[form_name].action_menu.value = id;
if (document.forms[form_name].action_yes.value == 'true')
if (document.forms[form_name].action_yes.value == 'true') {
document.forms[form_name].submit();
}
}
// METHOD: getWindowSize
// PARAMS: none
@@ -119,7 +114,10 @@ function getWindowSize()
var width, height;
width = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
height = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
return {width: width, height: height};
return {
width: width,
height: height
};
}
// METHOD: getScrollOffset
@@ -131,7 +129,10 @@ function getScrollOffset()
var left, top;
left = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
top = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
return {left: left, top: top};
return {
left: left,
top: top
};
}
// METHOD: setCenter
@@ -149,14 +150,12 @@ function setCenter(id, left, top)
// console.log('Id %s, type: %s, dimensions %s x %s, viewport %s x %s', id, $(id).getStyle('position'), dimensions.width, dimensions.height, viewport.width, viewport.height);
// console.log('Scrolloffset left: %s, top: %s', offset.left, offset.top);
// console.log('Left: %s, Top: %s (%s)', parseInt((viewport.width / 2) - (dimensions.width / 2) + offset.left), parseInt((viewport.height / 2) - (dimensions.height / 2) + offset.top), parseInt((viewport.height / 2) - (dimensions.height / 2)));
if (left)
{
if (left) {
$(id).setStyle ({
left: parseInt((viewport.width / 2) - (dimensions.width / 2) + offset.left) + 'px'
});
}
if (top)
{
if (top) {
// if we have fixed, we do not add the offset, else it moves out of the screen
var top_pos = type == 'fixed' ? parseInt((viewport.height / 2) - (dimensions.height / 2)) : parseInt((viewport.height / 2) - (dimensions.height / 2) + offset.top);
$(id).setStyle ({
@@ -178,15 +177,12 @@ function sh(id, showText, hideText)
// get status from element (hidden or visible)
divStatus = $(id).visible();
//console.log('Set flag %s for element %s', divStatus, id);
if (divStatus)
{
if (divStatus) {
// hide the element
Effect.BlindUp(id, {duration:0.3});
$(flag).value = 0;
$(btn).innerHTML = showText;
}
else if (!divStatus)
{
} else if (!divStatus) {
// show the element
Effect.BlindDown(id, {duration:0.3});
$(flag).value = 1;
@@ -10,7 +10,7 @@ var ConsoleSetup = function() {
for (var i = 0; i < names.length; ++i) {
if (!window.console[names[i]]) {
window.console[names[i]] = function() {}
window.console[names[i]] = function() {};
}
}
}();
+1 -2
View File
@@ -1,5 +1,4 @@
.debug_message
{
.debug_message {
border-top: 1px solid #a4a4a4;
color: #a4a4a4;
font-size: 8px;
@@ -8,10 +8,10 @@
// PARAMS: front/back -> what image to show
// RETURN: none
// DESC: ajax call to switch the main image in the detail view
function SwitchImage(image)
{
if (image != 'front' || image != 'back')
function SwitchImage(image) {
if (image != 'front' || image != 'back') {
image = 'front';
}
// disable / enable the href for the other side
x_ajax_afSwitchImage(image, OutputSwitchImage);
}
@@ -20,7 +20,6 @@ function SwitchImage(image)
// PARAMS: data -> the image full path for the new image
// RETURN: none
// DESC: replace the image in the product detail with the back image
function OutputSwitchImage(data)
{
function OutputSwitchImage(data) {
}
+77 -67
View File
@@ -81,8 +81,7 @@
$this->page_name = $this->get_page_name();
// set the action ids
foreach ($this->action_list as $_action)
{
foreach ($this->action_list as $_action) {
$this->$_action = (isset($_POST[$_action])) ? $_POST[$_action] : '';
}
@@ -95,9 +94,17 @@
$this->key_length = 4; // pow($this->one_key_length, 4); // hardcoded, should be more than enought (62*62*62*62)
// queue key
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action))
{
$this->queue_key = join('', array_map(function () { $range = $GLOBALS['_KEY_RANGE']; return $range[rand(0, (count($range) - 1))]; }, range(1, 3)));
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
$this->queue_key = join(
'',
array_map(
function () {
$range = $GLOBALS['_KEY_RANGE'];
return $range[rand(0, (count($range) - 1))];
},
range(1, 3)
)
);
}
}
@@ -118,13 +125,11 @@
// DESC: writes all action vars plus other info into edit_log table
public function adbEditLog($event = '', $data = '', $write_type = 'STRING')
{
if ($write_type == 'BINARY')
{
if ($write_type == 'BINARY') {
$data_binary = $this->db_escape_bytea(bzcompress(serialize($data)));
$data = 'see bzip compressed data_binary field';
}
if ($write_type == 'STRING')
{
if ($write_type == 'STRING') {
$data = $this->db_escape_string(serialize($data));
}
@@ -134,8 +139,16 @@
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ";
$q .= "(".@$_SESSION['EUID'].", NOW(), '".$this->db_escape_string($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string(@$_SERVER['HTTP_USER_AGENT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string(@$_SERVER['SCRIPT_FILENAME'])."', '".$this->db_escape_string(@$_SERVER['QUERY_STRING'])."', '".$this->db_escape_string(@$_SERVER['SERVER_NAME'])."', '".$this->db_escape_string(@$_SERVER['HTTP_HOST'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', '".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->action_id)."', '".$this->db_escape_string($this->action_yes)."', '".$this->db_escape_string($this->action_flag)."', '".$this->db_escape_string($this->action_menu)."', '".$this->db_escape_string($this->action_loaded)."', '".$this->db_escape_string($this->action_value)."', '".$this->db_escape_string($this->action_error)."')";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->db_escape_string(@$_SERVER['HTTP_USER_AGENT'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_REFERER'])."', '".$this->db_escape_string(@$_SERVER['SCRIPT_FILENAME'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['QUERY_STRING'])."', '".$this->db_escape_string(@$_SERVER['SERVER_NAME'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_HOST'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT'])."', ";
$q .= "'".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->db_escape_string(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', ";
$q .= "'".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->action_id)."', ";
$q .= "'".$this->db_escape_string($this->action_yes)."', '".$this->db_escape_string($this->action_flag)."', ";
$q .= "'".$this->db_escape_string($this->action_menu)."', '".$this->db_escape_string($this->action_loaded)."', ";
$q .= "'".$this->db_escape_string($this->action_value)."', '".$this->db_escape_string($this->action_error)."')";
$this->db_exec($q, 'NULL');
}
@@ -152,80 +165,72 @@
// DESC: menu creater
public function adbTopMenu($flag = 0)
{
if ($this->menu_show_flag)
if ($this->menu_show_flag) {
$flag = $this->menu_show_flag;
}
// get the session pages array
$pages = $_SESSION["PAGES"];
if (!is_array($pages))
if (!is_array($pages)) {
$pages = array ();
}
//$this->debug('pages', $this->print_ar($pages));
// if flag is 0, then we show all, else, we show only the matching flagges array points
// array is already sorted after correct order
reset($pages);
for ($i = 0; $i < count($pages); $i ++)
{
for ($i = 0; $i < count($pages); $i ++) {
$show = 0;
// is it visible in the menu & is it online
if ($pages[$i]["menu"] && $pages[$i]["online"])
{
if ($pages[$i]["menu"] && $pages[$i]["online"]) {
// check if it falls into our flag if we have a flag
if ($flag)
{
foreach ($pages[$i]["visible"] AS $name => $key)
{
if ($key == $flag)
if ($flag) {
foreach ($pages[$i]["visible"] as $name => $key) {
if ($key == $flag) {
$show = 1;
}
}
else
{
} else {
// if no flag given, show all menu points
$show = 1;
}
if ($show)
{
if ($show) {
// if it is popup, write popup arrayound
if ($pages[$i]["popup"])
{
if ($pages[$i]["popup"]) {
$type = "popup";
}
else
{
} else {
$type = "normal";
}
$query_string = '';
if (count($pages[$i]["query"]))
{
for ($j = 0; $j < count($pages[$i]["query"]); $j ++)
{
if (strlen($query_string))
if (count($pages[$i]["query"])) {
for ($j = 0; $j < count($pages[$i]["query"]); $j ++) {
if (strlen($query_string)) {
$query_string .= "&";
}
$query_string .= $pages[$i]["query"][$j]["name"]."=";
if (!$pages[$i]["query"][$j]["dynamic"])
if (!$pages[$i]["query"][$j]["dynamic"]) {
$query_string .= urlencode($pages[$i]["query"][$j]["value"]);
else
$query_string .= (($_GET[$pages[$i]["query"][$j]["value"]]) ? urlencode($_GET[$pages[$i]["query"][$j]["value"]]) : urlencode($_POST[$pages[$i]["query"][$j]["value"]]));
} else {
$query_string .= $_GET[$pages[$i]["query"][$j]["value"]] ? urlencode($_GET[$pages[$i]["query"][$j]["value"]]) : urlencode($_POST[$pages[$i]["query"][$j]["value"]]);
}
}
}
$url = $pages[$i]["filename"];
if (strlen($query_string))
if (strlen($query_string)) {
$url .= "?".$query_string;
}
$name = $pages[$i]["page_name"];
// if page name matchs -> set selected flag
$selected = 0;
if ($this->get_page_name() == $pages[$i]["filename"])
{
if ($this->get_page_name() == $pages[$i]["filename"]) {
$selected = 1;
$this->page_name = $name;
}
// last check, is this menu point okay to show
$enabled = 0;
if ($this->adbShowMenuPoint($pages[$i]["filename"]))
{
if ($this->adbShowMenuPoint($pages[$i]["filename"])) {
$enabled = 1;
}
// write in to view menu array
@@ -243,8 +248,7 @@
public function adbShowMenuPoint($filename)
{
$enabled = 0;
switch ($filename)
{
switch ($filename) {
default:
$enabled = 1;
break;
@@ -295,17 +299,23 @@
// DESC: wrapper function to fill up the mssages array
public function adbMsg($level, $msg, $vars = array ())
{
if (!preg_match("/^info|warning|error$/", $level))
if (!preg_match("/^info|warning|error$/", $level)) {
$level = "info";
}
$this->messages[] = array (
'msg' => sprintf($this->l->__($msg), $vars),
'class' => $level
);
switch ($level)
{
case 'info': $this->info = 1; break;
case 'warning': $this->warning = 1; break;
case 'error': $this->error = 1; break;
switch ($level) {
case 'info':
$this->info = 1;
break;
case 'warning':
$this->warning = 1;
break;
case 'error':
$this->error = 1;
break;
}
}
@@ -320,12 +330,16 @@
// file -> string for special file copy actions; mostyle "test#live;..."
// RETURN: none
// DESC: writes live queue
public function adbLiveQueue($queue_key, $type, $target, $data, $key_name, $key_value, $associate = NULL, $file = NULL)
public function adbLiveQueue($queue_key, $type, $target, $data, $key_name, $key_value, $associate = null, $file = null)
{
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (";
$q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file";
$q .= ") VALUES (";
$q .= "'".$this->db_escape_string($queue_key)."', '".$this->db_escape_string($key_value)."', '".$this->db_escape_string($key_name)."', '".$this->db_escape_string($type)."', '".$this->db_escape_string($target)."', '".$this->db_escape_string($data)."', '".$this->queue_key."', '".$this->action."', '".$this->db_escape_string($associate)."', '".$this->db_escape_string($file)."')";
$q .= "'".$this->db_escape_string($queue_key)."', '".$this->db_escape_string($key_value)."', ";
$q .= "'".$this->db_escape_string($key_name)."', '".$this->db_escape_string($type)."', ";
$q .= "'".$this->db_escape_string($target)."', '".$this->db_escape_string($data)."', ";
$q .= "'".$this->queue_key."', '".$this->action."', '".$this->db_escape_string($associate)."', ";
$q .= "'".$this->db_escape_string($file)."')";
$this->db_exec($q);
}
@@ -338,10 +352,12 @@
public function adbPrintDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1)
{
// if suffix given, add _ before
if ($suffix)
if ($suffix) {
$suffix = '_'.$suffix;
if ($min_steps < 1 || $min_steps > 59)
}
if ($min_steps < 1 || $min_steps > 59) {
$min_steps = 1;
}
$on_change_call = 'dt_list(\''.$suffix.'\');';
@@ -363,33 +379,28 @@
// from now to ?
$string = $this->l->__('Year').' ';
$string .= '<select id="year'.$suffix.'" name="year'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = date("Y"); $i <= $max_year; $i ++)
{
for ($i = date("Y"); $i <= $max_year; $i ++) {
$string .= '<option value="'.$i.'" '.(($year == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Month').' ';
$string .= '<select id="month'.$suffix.'" name="month'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= 12; $i ++)
{
for ($i = 1; $i <= 12; $i ++) {
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($month == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Day').' ';
$string .= '<select id="day'.$suffix.'" name="day'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= $days_in_month; $i ++)
{
for ($i = 1; $i <= $days_in_month; $i ++) {
// set weekday text based on current month ($month) and year ($year)
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($day == $i) ? 'selected' : '').'>'.$i.' ('.$this->l->__(date('D', mktime(0, 0, 0, $month, $i, $year))).')</option>';
}
$string .= '</select> '.$this->l->__('Hour').' ';
$string .= '<select id="hour'.$suffix.'" name="hour'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 0; $i <= 23; $i ++)
{
for ($i = 0; $i <= 23; $i ++) {
$string .= '<option value="'.(($i < 10) ? '0'.$i : $i).'" '.(($hour == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select> '.$this->l->__('Minute').' ';
$string .= '<select id="min'.$suffix.'" name="min'.$suffix.'" onChange="'.$on_change_call.'">';
for ( $i = 0; $i <= 59; $i += $min_steps)
{
for ($i = 0; $i <= 59; $i += $min_steps) {
$string .= '<option value="'.(( $i < 10) ? '0'.$i : $i).'" '.(($min == $i) ? 'selected' : '').'>'.$i.'</option>';
}
$string .= '</select>';
@@ -397,4 +408,3 @@
return $string;
}
}
?>
+411 -412
View File
File diff suppressed because it is too large Load Diff
+121 -139
View File
@@ -68,13 +68,12 @@
$this->table_name = $table_name;
// set primary key for given table_array
if ($this->table_array)
{
while (list($key, $value) = each($table_array))
{
if ($value["pk"])
if ($this->table_array) {
while (list($key, $value) = each($table_array)) {
if ($value["pk"]) {
$this->pk_name = $key;
}
}
} // set pk_name IF table_array was given
// internal
$this->class_info["db_array_io"] = array(
@@ -100,14 +99,14 @@
// used with the read function
public function convert_data($text)
{
$text = eregi_replace ('&lt;b&gt;', '<B>', $text);
$text = eregi_replace ('&lt;/b&gt;', '</B>', $text);
$text = eregi_replace ('&lt;i&gt;', '<I>', $text);
$text = eregi_replace ('&lt;/i&gt;', '</I>', $text);
$text = str_replace('&lt;b&gt;', '<b>', $text);
$text = str_replace('&lt;/b&gt;', '</b>', $text);
$text = str_replace('&lt;i&gt;', '<i>', $text);
$text = str_replace('&lt;/i&gt;', '</i>', $text);
// my need a change
$text = eregi_replace ('&lt;a href=&quot;', '<A TARGET="_blank" HREF="', $text);
$text = eregi_replace ('&quot;&gt;', '">', $text);
$text = eregi_replace ('&lt;/a&gt;', '</A>', $text);
$text = str_replace('&lt;a href=&quot;', '<a target="_blank" href="', $text);
$text = str_replace('&quot;&gt;', '">', $text);
$text = str_replace('&lt;/a&gt;', '</a>', $text);
return $text;
}
@@ -132,13 +131,13 @@
public function db_dump_array($write = 0)
{
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
while (list($column, $data_array) = each($this->table_array)) {
$string .= "<b>".$column."</b> -> ".$data_array["value"]."<br>";
}
// add output to internal error_msg
if ($write)
if ($write) {
$this->error_msg['db'] .= $string;
}
return $string;
}
@@ -162,19 +161,19 @@
public function db_check_pk_set()
{
// if pk_id is set, overrule ...
if ($this->pk_id)
if ($this->pk_id) {
$this->table_array[$this->pk_name]["value"] = $this->pk_id;
}
// if not set ... produce error
if (!$this->table_array[$this->pk_name]["value"])
{
if (!$this->table_array[$this->pk_name]["value"]) {
// if no PK found, error ...
$this->error_id = 21;
$this->_db_error();
return 0;
}
else
} else {
return 1;
}
}
// METHOD db_reset_array
// PARAMS reset_pk -> if set reset the pk too
@@ -183,14 +182,14 @@
public function db_reset_array($reset_pk = 0)
{
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
if (!$this->table_array[$column]["pk"])
while (list($column, $data_array) = each($this->table_array)) {
if (!$this->table_array[$column]["pk"]) {
unset($this->table_array[$column]["value"]);
else if ($reset_pk)
} elseif ($reset_pk) {
unset($this->table_array[$column]["value"]);
}
}
}
// METHOD db_delete
// PARAMS optional the table_array, if not given uses class var
@@ -198,32 +197,34 @@
// DESC deletes one dataset
public function db_delete($table_array = 0)
{
if (is_array($table_array))
if (is_array($table_array)) {
$this->table_array = $table_array;
if (!$this->db_check_pk_set())
}
if (!$this->db_check_pk_set()) {
return $this->table_array;
}
// delete query
$q = "DELETE FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
// delete files and build FK query
reset($this->table_array);
while(list($column, $data_array) = each($this->table_array))
{
while (list($column, $data_array) = each($this->table_array)) {
// suchen nach bildern und löschen ...
if ($this->table_array[$column]["file"] && file_exists($this->table_array[$column]["url"].$this->table_array[$column]["value"]))
{
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
if ($this->table_array[$column]["file"] && file_exists($this->table_array[$column]["url"].$this->table_array[$column]["value"])) {
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
}
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname))
if (file_exists($this->table_array[$column]["path"].$dateiname)) {
unlink($this->table_array[$column]["path"].$dateiname);
}
}
if ($this->table_array[$column]["fk"])
{
if ($this->table_array[$column]["fk"]) {
// zusammenstellen der FKs
if ($q_where)
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column." = ".$this->table_array[$column]["value"];
}
// allgemeines zurücksetzen des arrays
@@ -231,12 +232,12 @@
}
// attach fk row if there ...
if ($q_where)
if ($q_where) {
$q .= " AND ".$q_where;
}
// if 0, error
unset($this->pk_id);
if (!$this->db_exec($q))
{
if (!$this->db_exec($q)) {
$this->error_id=22;
$this->_db_error();
}
@@ -250,23 +251,25 @@
public function db_read($edit = 0, $table_array = 0)
{
// if array give, overrules internal array
if (is_array($table_array))
if (is_array($table_array)) {
$this->table_array = $table_array;
if (!$this->db_check_pk_set())
}
if (!$this->db_check_pk_set()) {
return $this->table_array;
}
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array)=each($this->table_array))
{
if ($q_select)
while (list($column, $data_array)=each($this->table_array)) {
if ($q_select) {
$q_select .= ", ";
}
$q_select .= $column;
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"])
{
if ($q_where)
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"]) {
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
}
}
@@ -275,31 +278,25 @@
$q .= $q_select;
$q .= " FROM ".$this->table_name." WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where)
if ($q_where) {
$q .= " AND ".$q_where;
}
// if query was executed okay, else set error
if ($this->db_exec($q))
{
if ($res = $this->db_fetch_array())
{
if ($this->db_exec($q)) {
if ($res = $this->db_fetch_array()) {
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array))
{
while (list($column, $data_array) = each($this->table_array)) {
// wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten für ausgabe
// ?? sollte das nicht draußen ??? man weis ja net was da drin steht --> is noch zu überlegen
// echo "EDIT: $edit | Spalte: $column | type: ".$this->table_array[$column]["type"]." | Res: ".$res[$column]."<br>";
if ($edit)
{
if ($edit) {
$this->table_array[$column]["value"] = $res[$column];
// if password, also write to hidden
if ($this->table_array[$column]["type"] == "password")
{
if ($this->table_array[$column]["type"] == "password") {
$this->table_array[$column]["HIDDEN_value"] = $res[$column];
}
}
else
{
} else {
$this->table_array[$column]["value"] = $this->convert_data(nl2br($res[$column]));
// had to put out the htmlentities from the line above as it breaks japanese characters
}
@@ -307,9 +304,7 @@
}
// possible db_fetch_array errors ...
$this->pk_id = $this->table_array[$this->pk_name]["value"];
}
else
{
} else {
$this->error_id = 22;
$this->_db_error();
}
@@ -322,42 +317,41 @@
// DESC writes on set into DB or updates one set (if PK exists)
public function db_write($addslashes = 0, $table_array = 0)
{
if (is_array($table_array))
if (is_array($table_array)) {
$this->table_array = $table_array;
}
// PK ID check
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"])
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"]) {
// $this->table_array[$this->pk_name]["value"]=$this->pk_id;
// }
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
if (!$this->table_array[$this->pk_name]["value"])
if (!$this->table_array[$this->pk_name]["value"]) {
$insert = 1;
else
} else {
$insert = 0;
}
reset($this->table_array);
while (list($column, $data_array) = each($this->table_array))
{
while (list($column, $data_array) = each($this->table_array)) {
/********************************* START FILE *************************************/
// file upload
if ($this->table_array[$column]["file"])
{
if ($this->table_array[$column]["file"]) {
// falls was im tmp drinnen, sprich ein upload, datei kopieren, Dateinamen in db schreiben
// falls datei schon am server (physischer pfad), dann einfach url in db schreiben (update)
// falls in "delete" "ja" dann loeschen (und gibts eh nur beim update)
if ($this->table_array[$column]["delete"])
{
if ($this->table_array[$column]["delete"]) {
unset($this->table_array[$column]["delete"]);
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
unlink($this->table_array[$column]["path"].$this->table_array[$column]["value"]);
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname))
unlink($this->table_array[$column]["path"].$dateiname);
$this->table_array[$column]["value"] = "";
}
else
{
if ($this->table_array[$column]["tmp"] != "none" && $this->table_array[$column]["tmp"])
{
$dateiname = str_replace("_tn", "", $this->table_array[$column]["value"]);
if (file_exists($this->table_array[$column]["path"].$dateiname)) {
unlink($this->table_array[$column]["path"].$dateiname);
}
$this->table_array[$column]["value"] = "";
} else {
if ($this->table_array[$column]["tmp"] != "none" && $this->table_array[$column]["tmp"]) {
// Dateiname zusammenbasteln: org-name + _pkid liste + .ext
list($name, $ext) = explode(".", $this->table_array[$column]["dn"]);
@@ -373,20 +367,17 @@
//echo "Dn: $dateiname";
copy($this->table_array[$column]["tmp"], $this->table_array[$column]["path"].$dateiname);
// automatisch thumbnail generieren, geht nur mit convert (ImageMagic!!!), aber nur bei bild ..
if (strtolower($ext) == "jpeg" || strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png")
{
if (strtolower($ext) == "jpeg" || strtolower($ext) == "jpg" || strtolower($ext) == "gif" || strtolower($ext) == "png") {
$dateiname_tn = $name.$pk_ids_file."_tn.".$ext;
$eingang = $this->table_array[$column]["path"].$dateiname;
$ausgang = $this->table_array[$column]["path"].$dateiname_tn;
$com = "convert -geometry 115 $eingang $ausgang";
exec($com);
$this->table_array[$column]["value"] = $dateiname_tn;
}
else
} else {
$this->table_array[$column]["value"] = $dateiname;
}
else if (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"]))
{
} elseif (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
// mach gar nix, wenn bild schon da ???
}
} // delete or upload
@@ -394,54 +385,52 @@
/********************************* END FILE **************************************/
// do not write 'pk' (primary key) or 'view' values
if (!$this->table_array[$column]["pk"] && $this->table_array[$column]['type'] != 'view' && strlen($column) > 0 )
{
if (!$this->table_array[$column]["pk"] && $this->table_array[$column]['type'] != 'view' && strlen($column) > 0) {
// for password use hidden value if main is not set
if ($this->table_array[$column]["type"] == "password" && !$this->table_array[$column]["value"])
if ($this->table_array[$column]["type"] == "password" && !$this->table_array[$column]["value"]) {
$this->table_array[$column]["value"] = $this->table_array[$column]["HIDDEN_value"];
if (!$insert)
{
if (strlen($q_data))
$q_data .= ", ";
$q_data .= $column." = ";
}
else
// this is insert
{
if (strlen($q_data))
if (!$insert) {
if (strlen($q_data)) {
$q_data .= ", ";
if ($q_vars)
}
$q_data .= $column." = ";
} else {
// this is insert
if (strlen($q_data)) {
$q_data .= ", ";
}
if ($q_vars) {
$q_vars .= ", ";
}
$q_vars .= $column;
}
// integer is different
if ($this->table_array[$column]["int"] || $this->table_array[$column]["int_null"])
{
if ($this->table_array[$column]["int"] || $this->table_array[$column]["int_null"]) {
$this->debug('write_check', "[$column][".$this->table_array[$column]["value"]."] Foo: ".isset($this->table_array[$column]["value"])." | ".$this->table_array[$column]["int_null"]);
if (!$this->table_array[$column]["value"] && $this->table_array[$column]["int_null"])
if (!$this->table_array[$column]["value"] && $this->table_array[$column]["int_null"]) {
$_value = 'NULL';
elseif (!isset($this->table_array[$column]["value"]))
} elseif (!isset($this->table_array[$column]["value"])) {
$_value = 0;
else
} else {
$_value = $this->table_array[$column]["value"];
$q_data .= $_value;
}
elseif ($this->table_array[$column]["interval"])
{
$q_data .= $_value;
} elseif ($this->table_array[$column]["interval"]) {
// for interval we check if no value, then we set null
if (!$this->table_array[$column]["value"])
if (!$this->table_array[$column]["value"]) {
$_value = 'NULL';
$q_data .= $_value;
}
else
$q_data .= $_value;
} else {
// normal string
{
$q_data .= "'";
// if add slashes do convert & add slashes else write AS is
if ($addslashes)
if ($addslashes) {
$q_data .= $this->db_escape_string($this->convert_entities($this->table_array[$column]["value"]));
else
} else {
$q_data .= $this->db_escape_string($this->table_array[$column]["value"]);
}
$q_data .= "'";
}
}
@@ -451,60 +440,54 @@ $this->debug('write_check', "[$column][".$this->table_array[$column]["value"]."]
// get it at the end, cause now we can be more sure of no double IDs, etc
reset($this->table_array);
// create select part & addition FK part
while (list($column, $data_array) = each($this->table_array))
{
while (list($column, $data_array) = each($this->table_array)) {
// check FK ...
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"])
{
if ($q_where)
if ($this->table_array[$column]["fk"] && $this->table_array[$column]["value"]) {
if ($q_where) {
$q_where .= " AND ";
}
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
}
}
// if no PK set, then get max ID from DB
if (!$this->table_array[$this->pk_name]["value"])
{
if (!$this->table_array[$this->pk_name]["value"]) {
// max id, falls INSERT
$q = "SELECT MAX(".$this->pk_name.") + 1 AS pk_id FROM ".$this->table_name;
$res = $this->db_return_row($q);
if (!$res["pk_id"])
if (!$res["pk_id"]) {
$res["pk_id"] = 1;
}
$this->table_array[$this->pk_name]["value"] = $res["pk_id"];
}
if (!$insert)
{
if (!$insert) {
$q = "UPDATE ".$this->table_name." SET ";
$q .= $q_data;
$q .= " WHERE ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
if ($q_where)
if ($q_where) {
$q .= " AND ".$q_where;
}
// set pk_id ... if it has changed or so
$this->pk_id = $this->table_array[$this->pk_name]["value"];
}
else
{
} else {
$q = "INSERT INTO ".$this->table_name." ";
$q .= "(".$q_vars.") ";
$q .= "VALUES (".$q_data.")";
// write primary key too
/* if ($q_data)
$q .= ", ";
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
$this->pk_id = $this->table_array[$this->pk_name]["value"];
*/
// if ($q_data)
// $q .= ", ";
// $q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
// $this->pk_id = $this->table_array[$this->pk_name]["value"];
}
// return success or not
if (!$this->db_exec($q))
{
if (!$this->db_exec($q)) {
$this->error_id = 22;
$this->_db_error();
}
// set primary key
if ($insert)
{
if ($insert) {
$this->table_array[$this->pk_name]["value"] = $this->insert_id;
$this->ok = $this->insert_id;
}
@@ -512,4 +495,3 @@ $this->debug('write_check', "[$column][".$this->table_array[$column]["value"]."]
return $this->table_array;
}
} // end of class
?>
+264 -355
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+142 -206
View File
@@ -95,8 +95,7 @@
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
// no session could be found at all
if (!session_id())
{
if (!session_id()) {
echo "<b>Session not started!</b><br>Use 'session_start();'.<br>For less problems with other session, you can set a session name with 'session_name(\"name\");'.<br>";
exit;
}
@@ -112,24 +111,33 @@
$this->euid = array_key_exists('EUID', $_SESSION) ? $_SESSION['EUID'] : 0; // if there is none, there is none, saves me POST/GET check
// get login vars, are so, can't be changed
// prepare
if (!isset($_POST['login_login']))
if (!isset($_POST['login_login'])) {
$_POST['login_login'] = '';
if (!isset($_POST['login_username']))
}
if (!isset($_POST['login_username'])) {
$_POST['login_username'] = '';
if (!isset($_POST['login_password']))
}
if (!isset($_POST['login_password'])) {
$_POST['login_password'] = '';
if (!isset($_POST['login_logout']))
}
if (!isset($_POST['login_logout'])) {
$_POST['login_logout'] = '';
if (!isset($_POST['change_password']))
}
if (!isset($_POST['change_password'])) {
$_POST['change_password'] = '';
if (!isset($_POST['pw_username']))
}
if (!isset($_POST['pw_username'])) {
$_POST['pw_username'] = '';
if (!isset($_POST['pw_old_password']))
}
if (!isset($_POST['pw_old_password'])) {
$_POST['pw_old_password'] = '';
if (!isset($_POST['pw_new_password']))
}
if (!isset($_POST['pw_new_password'])) {
$_POST['pw_new_password'] = '';
if (!isset($_POST['pw_new_password_confirm']))
}
if (!isset($_POST['pw_new_password_confirm'])) {
$_POST['pw_new_password_confirm'] = '';
}
// pass on vars to Object vars
$this->login = $_POST["login_login"];
$this->username = $_POST["login_username"];
@@ -146,8 +154,9 @@
// disallow user list for password change
$this->pw_change_deny_users = array ('admin');
// set flag if password change is okay
if (defined('PASSWORD_CHANGE'))
if (defined('PASSWORD_CHANGE')) {
$this->password_change = PASSWORD_CHANGE;
}
// max login counts before error reporting
$this->max_login_error_count = 10;
// users that never get locked, even if they are set strict
@@ -165,8 +174,7 @@
$_SESSION['DEFAULT_ACL_LIST'] = array ();
// read the current edit_access_right list into an array
$q = "SELECT level, type, name FROM edit_access_right WHERE level >= 0 ORDER BY level";
while ($res = $this->db_return($q))
{
while ($res = $this->db_return($q)) {
// level to description format (numeric)
$this->default_acl_list[$res['level']] = array (
'type' => $res['type'],
@@ -183,25 +191,25 @@
// logsout user
$this->login_logout_user();
// if the password change flag is okay, run the password change method
if ($this->password_change)
if ($this->password_change) {
$this->login_password_change();
}
// if !$euid || permission not okay, print login screan
echo $this->login_print_login();
// closing all connections, depending on error status, exit
if (!$this->login_close_class())
{
if (!$this->login_close_class()) {
// do not go anywhere, quit processing here
// do something with possible debug data?
if (TARGET == 'live' || TARGET == 'remote')
{
if (TARGET == 'live' || TARGET == 'remote') {
// login
$this->debug_output_all = DEBUG ? 1 : 0;
$this->echo_output_all = 0;
$this->print_output_all = DEBUG ? 1 : 0;
}
$status_msg = $this->print_error_msg();
if ($this->echo_output_all)
if ($this->echo_output_all) {
echo $status_msg;
}
exit;
}
// set acls for this user/group and this page
@@ -224,14 +232,10 @@
private function login_login_user()
{
// have to get the global stuff here for setting it later
if (!$this->euid && $this->login)
{
if (!($this->password && $this->username))
{
if (!$this->euid && $this->login) {
if (!($this->password && $this->username)) {
$this->login_error = 102;
}
else
{
} else {
// we have to get the themes in here too
$q = "SELECT eu.edit_user_id, username, password, eu.edit_group_id, eg.name AS edit_group_name, admin, eu.login_error_count, eu.login_error_date_last, eu.login_error_date_first, eu.strict, eu.locked, ";
$q .= "debug, db_debug, ";
@@ -251,12 +255,9 @@
$q .= "(LOWER(username) = '".strtolower($this->username)."') ";
$res = $this->db_return($q);
// username is wrong, but we throw for wrong username and wrong password the same error
if (!$this->cursor_ext[md5($q)]["num_rows"])
{
if (!$this->cursor_ext[md5($q)]["num_rows"]) {
$this->login_error = 1010;
}
else
{
} else {
// if login errors is half of max errors and the last login error was less than 10s ago, forbid any new login try
// check with what kind of prefix the password begins:
@@ -273,39 +274,28 @@
// - encrypted password matches
// - plain password matches
if (!$res["enabled"]) {
// user is enabled
if (!$res["enabled"])
{
$this->login_error = 104;
}
} elseif ($res['locked']) {
// user is locked, either set or auto set
elseif ($res['locked'])
{
$this->login_error = 105;
}
elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) && CRYPT_BLOWFISH != 1) || (preg_match("/^\\$1\\$/", $res['password']) && CRYPT_MD5 != 1) || (preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && CRYPT_STD_DES != 1))
{
$this->login_error = 9999; // this means password cannot be decrypted because of missing crypt methods
}
} elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) && CRYPT_BLOWFISH != 1) || (preg_match("/^\\$1\\$/", $res['password']) && CRYPT_MD5 != 1) || (preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && CRYPT_STD_DES != 1)) {
// this means password cannot be decrypted because of missing crypt methods
$this->login_error = 9999;
} elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) || preg_match("/^\\$1\\$/", $res['password']) || preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password'])) && !$this->verifyCryptString($this->password, $res['password'])) {
// check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES
elseif ((preg_match("/^\\$2(a|y)\\$/", $res['password']) || preg_match("/^\\$1\\$/", $res['password']) || preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password'])) && !$this->verifyCryptString($this->password, $res['password']))
{
$this->login_error = 1011;
}
} elseif (!preg_match("/^\\$2(a|y)\\$/", $res['password']) && !preg_match("/^\\$1\\$/", $res['password']) && !preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && $res['password'] != $this->password) {
// check old plain password, non case sensitive
elseif (!preg_match("/^\\$2(a|y)\\$/", $res['password']) && !preg_match("/^\\$1\\$/", $res['password']) && !preg_match("/^\\$[0-9A-Za-z.]{12}$/", $res['password']) && $res['password'] != $this->password)
{
$this->login_error = 1012;
}
// nromal user processing
else
{
} else {
// normal user processing
// set class var and session var
$_SESSION["EUID"] = $this->euid = $res["edit_user_id"];
// check if user is okay
$this->login_check_permissions();
if (!$this->login_error)
{
if (!$this->login_error) {
// now set all session vars and read page permissions
$GLOBALS["DEBUG_ALL"] = $_SESSION["DEBUG_ALL"] = $res["debug"];
$GLOBALS["DB_DEBUG"] = $_SESSION["DB_DEBUG"] = $res["db_debug"];
@@ -322,8 +312,7 @@
$_SESSION["DEFAULT_CHARSET"] = $res["lang_iso"];
$_SESSION["DEFAULT_LANG"] = $res["lang_short"].'_'.strtolower(str_replace('-', '', $res["lang_iso"]));
// reset any login error count for this user
if ($res['login_error_count'] > 0)
{
if ($res['login_error_count'] > 0) {
$q = "UPDATE edit_user SET login_error_count = 0, login_error_date_last = NULL, login_error_date_first = NULL WHERE edit_user_id = ".$res['edit_user_id'];
$this->db_exec($q);
}
@@ -335,8 +324,7 @@
$q .= "WHERE ep.edit_page_id = epa.edit_page_id AND ear.edit_access_right_id = epa.edit_access_right_id ";
$q .= "AND epa.enabled = 1 AND epa.edit_group_id = ".$res["edit_group_id"]." ";
$q .= "ORDER BY ep.order_number";
while ($res = $this->db_return($q))
{
while ($res = $this->db_return($q)) {
// page id array for sub data readout
$edit_page_ids[] = $res['edit_page_id'];
// create the array for pages
@@ -357,15 +345,12 @@
));
// make reference filename -> level
$pages_acl[$res["filename"]] = $res["level"];
} // for each page
// get the visible groups for all pages and write them to the pages
$_edit_page_id = 0;
$q = "SELECT epvg.edit_page_id, name, flag FROM edit_visible_group evp, edit_page_visible_group epvg WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id AND epvg.edit_page_id IN (".join(', ', $edit_page_ids).") ORDER BY epvg.edit_page_id";
while ($res = $this->db_return($q))
{
if ($res['edit_page_id'] != $_edit_page_id)
{
while ($res = $this->db_return($q)) {
if ($res['edit_page_id'] != $_edit_page_id) {
// search the pos in the array push
$pos = $this->array_search_recursive($res['edit_page_id'], $pages, 'edit_page_id');
$_edit_page_id = $res['edit_page_id'];
@@ -375,10 +360,8 @@
// get the same for the query strings
$_edit_page_id = 0;
$q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs WHERE enabled = 1 AND edit_page_id IN (".join(', ', $edit_page_ids).") ORDER BY eqs.edit_page_id";
while ($res = $this->db_return($q))
{
if ($res['edit_page_id'] != $_edit_page_id)
{
while ($res = $this->db_return($q)) {
if ($res['edit_page_id'] != $_edit_page_id) {
// search the pos in the array push
$pos = $this->array_search_recursive($res['edit_page_id'], $pages, 'edit_page_id');
$_edit_page_id = $res['edit_page_id'];
@@ -400,13 +383,11 @@
$unit_access = array();
$eauid = array();
$unit_acl = array();
while ($res = $this->db_return($q))
{
while ($res = $this->db_return($q)) {
// read edit access data fields and drop them into the unit access array
$q_sub ="SELECT name, value FROM edit_access_data WHERE enabled = 1 AND edit_access_id = ".$res['edit_access_id'];
$ea_data = array ();
while ($res_sub = $this->db_return($q_sub))
{
while ($res_sub = $this->db_return($q_sub)) {
$ea_data[$res_sub['name']] = $res_sub['value'];
}
// build master unit array
@@ -421,8 +402,9 @@
'data' => $ea_data
);
// set the default unit
if ($res['edit_default'])
if ($res['edit_default']) {
$_SESSION["UNIT_DEFAULT"] = $res['edit_access_id'];
}
// sub arrays for simple access
array_push($eauid, $res['edit_access_id']);
$unit_acl[$res['edit_access_id']] = $res['level'];
@@ -432,21 +414,19 @@
$_SESSION['EAID'] = $eauid;
} // user has permission to THIS page
} // user was not enabled or other login error
if ($this->login_error)
{
if ($res['login_error_count'] == 0)
if ($this->login_error) {
if ($res['login_error_count'] == 0) {
$login_error_date_first = ', login_error_date_first = NOW()';
}
// update login error count for this user
$q = "UPDATE edit_user SET login_error_count = login_error_count + 1, login_error_date_last = NOW() $login_error_date_first WHERE edit_user_id = ".$res['edit_user_id'];
$this->db_exec($q);
// totally lock the user if error max is reached
if ($res['login_error_count'] + 1 > $this->max_login_error_count)
{
if ($res['login_error_count'] + 1 > $this->max_login_error_count) {
// do some alert reporting in case this error is too big
// if strict is set, lock this user
// this needs manual unlocking by an admin user
if ($res['strict'] && !in_array($this->username, $this->lock_deny_users))
{
if ($res['strict'] && !in_array($this->username, $this->lock_deny_users)) {
$q = "UPDATE edit_user SET locked = 1 WHERE edit_user_id = ".$res['edit_user_id'];
}
}
@@ -454,8 +434,7 @@
} // user was not found
} // if not username AND password where given
// if there was an login error, show login screen
if ($this->login_error)
{
if ($this->login_error) {
// reset the perm var, to confirm logout
$this->permission_okay = 0;
}
@@ -468,8 +447,7 @@
// DESC : for every page the user access this script checks if he is allowed to do so
public function login_check_permissions()
{
if ($this->euid && $this->login_error != 103)
{
if ($this->euid && $this->login_error != 103) {
$q = "SELECT filename ";
$q .= "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu ";
$q .= "WHERE ep.edit_page_id = epa.edit_page_id AND eg.edit_group_id = epa.edit_group_id AND eg.edit_group_id = eu.edit_group_id ";
@@ -478,12 +456,9 @@
// unset mem limit if debug is set to 1
// if (($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] || $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) && ini_get('memory_limit') != -1)
// ini_set('memory_limit', -1);
if ($res["filename"] == $this->page_name)
{
if ($res["filename"] == $this->page_name) {
$this->permission_okay = 1;
}
else
{
} else {
$this->login_error = 103;
$this->permission_okay = 0;
}
@@ -498,8 +473,7 @@
// DESC : if a user pressed on logout, destroyes session and unsets all global vars
public function login_logout_user()
{
if ($this->logout || $this->login_error)
{
if ($this->logout || $this->login_error) {
// unregister and destroy session vars
unset($_SESSION["EUID"]);
unset($_SESSION["GROUP_LEVEL"]);
@@ -544,28 +518,22 @@
$this->acl['base'] = DEFAULT_ACL_LEVEL;
// set admin flag and base to 100
if ($_SESSION['ADMIN'])
{
if ($_SESSION['ADMIN']) {
$this->acl['admin'] = 1;
$this->acl['base'] = 100;
}
else
{
} else {
// now go throw the flow and set the correct ACL
// user > page > group
// group ACL 0
if ($_SESSION['GROUP_ACL_LEVEL'] != -1)
{
if ($_SESSION['GROUP_ACL_LEVEL'] != -1) {
$this->acl['base'] = $_SESSION['GROUP_ACL_LEVEL'];
}
// page ACL 1
if ($_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1)
{
if ($_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1) {
$this->acl['base'] = $_SESSION['PAGES_ACL_LEVEL'][$this->page_name];
}
// user ACL 2
if ($_SESSION['USER_ACL_LEVEL'] != -1)
{
if ($_SESSION['USER_ACL_LEVEL'] != -1) {
$this->acl['base'] = $_SESSION['USER_ACL_LEVEL'];
}
}
@@ -575,29 +543,24 @@
// set group if not -1, overrides default
// set page if not -1, overrides group set
$this->acl['page'] = DEFAULT_ACL_LEVEL;
if ($_SESSION['GROUP_ACL_LEVEL'] != -1)
{
if ($_SESSION['GROUP_ACL_LEVEL'] != -1) {
$this->acl['page'] = $_SESSION['GROUP_ACL_LEVEL'];
}
if (isset($_SESSION['PAGES_ACL_LEVEL'][$this->page_name]) && $_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1)
{
if (isset($_SESSION['PAGES_ACL_LEVEL'][$this->page_name]) && $_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1) {
$this->acl['page'] = $_SESSION['PAGES_ACL_LEVEL'][$this->page_name];
}
// PER ACCOUNT (UNIT/edit access)->
foreach ($_SESSION['UNIT'] as $ea_id => $unit)
{
foreach ($_SESSION['UNIT'] as $ea_id => $unit) {
// if admin flag is set, all units are set to 100
if ($this->acl['admin'])
{
if ($this->acl['admin']) {
$this->acl['unit'][$ea_id] = $this->acl['base'];
} else {
if ($unit['acl_level'] != -1) {
$this->acl['unit'][$ea_id] = $unit['acl_level'];
} else {
$this->acl['unit'][$ea_id] = $this->acl['base'];
}
else
{
if ($unit['acl_level'] != -1)
$this->acl['unit'][$ea_id] = $unit['acl_level'];
else
$this->acl['unit'][$ea_id] = $this->acl['base'];
}
// detail name/level set
$this->acl['unit_detail'][$ea_id] = array (
@@ -608,23 +571,22 @@
'data' => $unit['data']
);
// set default
if ($unit['default'])
{
if ($unit['default']) {
$this->acl['unit_id'] = $unit['id'];
$this->acl['unit_name'] = $unit['name'];
$this->acl['unit_uid'] = $unit['uid'];
}
}
// flag if to show extra edit access drop downs (because user has multiple groups assigned)
if (count($_SESSION['UNIT']) > 1)
if (count($_SESSION['UNIT']) > 1) {
$this->acl['show_ea_extra'] = 1;
else
} else {
$this->acl['show_ea_extra'] = 0;
}
// set the default edit access
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'];
// integrate the type acl list, but only for the keyword -> level
foreach ($this->default_acl_list as $level => $data)
{
foreach ($this->default_acl_list as $level => $data) {
$this->acl['min'][$data['type']] = $level;
}
// set the full acl list too
@@ -639,11 +601,12 @@
// DESC : checks if this edit access id is valid
public function login_check_edit_access($edit_access_id)
{
if (array_key_exists($edit_access_id, $this->acl['unit']))
if (array_key_exists($edit_access_id, $this->acl['unit'])) {
return true;
else
} else {
return false;
}
}
// METHOD: login_password_change
// PARAMS: none
@@ -651,70 +614,56 @@
// DESC : changes a user password
private function login_password_change()
{
if ($this->change_password)
{
if ($this->change_password) {
$event = 'Password Change';
// check that given username is NOT in the deny list, else silent skip (with error log)
if (!in_array($this->pw_username, $this->pw_change_deny_users))
{
if (!$this->pw_username || !$this->pw_password)
{
if (!in_array($this->pw_username, $this->pw_change_deny_users)) {
if (!$this->pw_username || !$this->pw_password) {
$this->login_error = 200;
$data = 'Missing username or old password.';
}
// check user exist, if not -> error
if (!$this->login_error)
{
if (!$this->login_error) {
$q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->db_escape_string($this->pw_username)."'";
list ($edit_user_id) = $this->db_return_row($q);
if (!$edit_user_id)
{
if (!$edit_user_id) {
// username wrong
$this->login_error = 201;
$data = 'User could not be found';
}
}
// check old passwords match -> error
if (!$this->login_error)
{
if (!$this->login_error) {
$q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->db_escape_string($this->pw_username)."' AND password = '".$this->db_escape_string($this->pw_old_password)."'";
list ($edit_user_id) = $this->db_return_row($q);
if (!$edit_user_id)
{
if (!$edit_user_id) {
// old password wrong
$this->login_error = 202;
$data = 'The old password does not match';
}
}
// check if new passwords were filled out -> error
if (!$this->login_error)
{
if (!$this->pw_new_password || !$this->pw_new_password_confirm)
{
if (!$this->login_error) {
if (!$this->pw_new_password || !$this->pw_new_password_confirm) {
$this->login_error = 203;
$data = 'Missing new password or new password confirm.';
}
}
// check new passwords both match -> error
if (!$this->login_error)
{
if ($this->pw_new_password != $this->pw_new_password_confirm)
{
if (!$this->login_error) {
if ($this->pw_new_password != $this->pw_new_password_confirm) {
$this->login_error = 204;
$data = 'The new passwords do not match: '.$this->pw_new_password.' == '.$this->pw_new_password_confirm;
}
}
// no error change this users password
if (!$this->login_error)
{
if (!$this->login_error) {
// update the user (edit_user_id) with the new password
$q = "UPDATE edit_user SET password = '".$this->db_escape_string($this->cryptString($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id;
$this->db_exec($q);
$data = 'Password change for user "'.$this->pw_username.'" from "'.$this->pw_old_password.'" to "'.$this->pw_new_password.'"';
}
}
else
{
} else {
// illegal user error
$this->login_error = '220';
$data = 'Illegal user for password change: '.$this->pw_username;
@@ -730,50 +679,47 @@
// DESC : prints out login html part if no permission (error) is set
private function login_print_login()
{
if (!$this->permission_okay)
{
if (!$this->permission_okay) {
// set the templates now
$this->login_set_templates();
// if there is a global logout target ...
if (file_exists($this->logout_target) && $this->logout_target)
{
if (file_exists($this->logout_target) && $this->logout_target) {
$LOGOUT_TARGET = $this->logout_target;
} else
{
} else {
$LOGOUT_TARGET = "";
}
$html_string = $this->login_template['template'];
// if password change is okay
if ($this->password_change)
{
if ($this->password_change) {
$html_string_password_change = $this->login_template['password_change'];
// pre change the data in the PASSWORD_CHANGE_DIV first
foreach ($this->login_template['strings'] as $string => $data)
{
if ($data)
foreach ($this->login_template['strings'] as $string => $data) {
if ($data) {
$html_string_password_change = str_replace("{".$string."}", $data, $html_string_password_change);
}
}
$this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change;
}
// put in the logout redirect string
if ($this->logout && $LOGOUT_TARGET)
if ($this->logout && $LOGOUT_TARGET) {
$html_string = str_replace("{LOGOUT_TARGET}", '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string);
else
} else {
$html_string = str_replace("{LOGOUT_TARGET}", '', $html_string);
}
// print error messagae
if ($this->login_error)
if ($this->login_error) {
$html_string = str_replace("{ERROR_MSG}", $this->login_error_msg[$this->login_error]."<br>", $html_string);
else
} else {
$html_string = str_replace("{ERROR_MSG}", "<br>", $html_string);
}
// create the replace array context
foreach ($this->login_template['strings'] as $string => $data)
{
foreach ($this->login_template['strings'] as $string => $data) {
$html_string = str_replace("{".$string."}", $data, $html_string);
}
@@ -789,20 +735,19 @@
private function login_close_class()
{
// write to LOG table ...
if ($this->login_error || $this->login || $this->logout)
{
if ($this->login_error || $this->login || $this->logout) {
$username = '';
$password = '';
// set event
if ($this->login)
if ($this->login) {
$event = "Login";
else if ($this->logout)
} elseif ($this->logout) {
$event = "Logout";
else
} else {
$event = "No Permission";
}
// prepare for log
if ($this->euid)
{
if ($this->euid) {
// get user from user table
$q = "SELECT username, password FROM edit_user WHERE edit_user_id = ".$this->euid;
list($username, $password) = $this->db_return_row($q);
@@ -811,12 +756,9 @@
} // write log under certain settings
// now close DB connection
// $this->error_msg = $this->_login();
if (!$this->permission_okay)
{
if (!$this->permission_okay) {
return false;
}
else
{
} else {
return true;
}
}
@@ -857,8 +799,7 @@
);
// if password change is okay
if ($this->password_change)
{
if ($this->password_change) {
$strings = array_merge($strings, array (
'TITLE_PASSWORD_CHANGE' => 'Change Password for User',
'OLD_PASSWORD' => $this->l->__("Old Password"),
@@ -881,9 +822,7 @@
</table>
</div>
EOM;
}
else
{
} else {
$strings = array_merge($strings, array (
'JS_SHOW_HIDE' => '',
'PASSWORD_CHANGE_BUTTON' => '',
@@ -892,26 +831,21 @@ EOM;
}
// first check if all strings are set from outside, if not, set with default ones
while (list($string, $data) = each($strings))
{
if (!array_key_exists($string, $this->login_template['strings']))
{
while (list($string, $data) = each($strings)) {
if (!array_key_exists($string, $this->login_template['strings'])) {
$this->login_template['strings'][$string] = $data;
}
}
// error msgs the same
while (list($code, $data) = each($error_msgs))
{
if (!array_key_exists($code, $this->login_error_msg))
{
while (list($code, $data) = each($error_msgs)) {
if (!array_key_exists($code, $this->login_error_msg)) {
$this->login_error_msg[$code] = $data;
}
}
// now check templates
if (!$this->login_template['template'])
{
if (!$this->login_template['template']) {
$this->login_template['template'] = <<<EOM
<html>
<head>
@@ -985,10 +919,11 @@ EOM;
// DESC : writes detailed data into the edit user log table (keep log what user does)
private function write_log($event, $data, $error = "", $username = "", $password = "")
{
if ($this->login)
if ($this->login) {
$this->action = 'Login';
elseif ($this->logout)
} elseif ($this->logout) {
$this->action = 'Logout';
}
$_data_binary = array (
'_SESSION' => $_SESSION,
'_GET' => $_GET,
@@ -1002,14 +937,15 @@ EOM;
$q .= "(username, password, euid, event_date, event, error, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ('".$this->db_escape_string($username)."', '".$this->db_escape_string($password)."', ".(($this->euid) ? $this->euid : 'NULL').", NOW(), '".$this->db_escape_string($event)."', '".$this->db_escape_string($error)."', '".$this->db_escape_string($data)."', '".$data_binary."', '".$this->page_name."', ";
foreach (array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING') as $server_code)
{
if (array_key_exists($server_code, $_SERVER))
$q .= "VALUES ('".$this->db_escape_string($username)."', '".$this->db_escape_string($password)."', ".(($this->euid) ? $this->euid : 'NULL').", ";
$q .= "NOW(), '".$this->db_escape_string($event)."', '".$this->db_escape_string($error)."', '".$this->db_escape_string($data)."', '".$data_binary."', '".$this->page_name."', ";
foreach (array('REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING') as $server_code) {
if (array_key_exists($server_code, $_SERVER)) {
$q .= "'".$this->db_escape_string($_SERVER[$server_code])."', ";
else
} else {
$q .= "NULL, ";
}
}
$q .= "'".session_id()."', ";
$q .= "'".$this->db_escape_string($this->action)."', '".$this->db_escape_string($this->username)."', NULL, '".$this->db_escape_string($this->login_error)."', NULL, NULL, '".$this->db_escape_string($this->permission_okay)."', NULL)";
$this->db_exec($q, 'NULL');
@@ -1021,11 +957,12 @@ EOM;
// DESC : checks that the given edit access id is valid for this user
public function login_check_edit_access_id($edit_access_id)
{
if (!array_key_exists($edit_access_id, $_SESSION["UNIT"]))
if (!array_key_exists($edit_access_id, $_SESSION["UNIT"])) {
return $_SESSION["UNIT_DEFAULT"];
else
} else {
return $edit_access_id;
}
}
// METHOD: login_set_edit_access_data
// PARAMS: edit access id, key value to search for
@@ -1033,11 +970,10 @@ EOM;
// DESC : searchs in the data set for the unit for the data key and returns the value asociated with it
public function login_set_edit_access_data($edit_access_id, $data_key)
{
if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key])
if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key]) {
return false;
else
} else {
return $_SESSION['UNIT'][$edit_access_id]['data'][$data_key];
}
}
} // close class
?>
+103 -101
View File
@@ -73,10 +73,12 @@ class ProgressBar
public function __construct($width = 0, $height = 0)
{
$this->code = substr(md5(microtime()), 0, 6);
if ($width > 0)
if ($width > 0) {
$this->width = $width;
if ($height > 0)
}
if ($height > 0) {
$this->height = $height;
}
// needs to be called twice or I do not get any output
$this->_flushCache($this->clear_buffer_size_init);
$this->_flushCache($this->clear_buffer_size_init);
@@ -86,8 +88,9 @@ class ProgressBar
private function _flushCache($clear_buffer_size = 0)
{
if (!$clear_buffer_size)
if (!$clear_buffer_size) {
$clear_buffer_size = $this->clear_buffer_size;
}
echo str_repeat(' ', $clear_buffer_size);
ob_flush();
flush();
@@ -96,18 +99,19 @@ class ProgressBar
private function _calculatePercent($step)
{
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
if ($percent > 100)
if ($percent > 100) {
$percent = 100;
}
return $percent;
}
private function _calculatePosition($step)
{
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
case 'left':
$bar = $this->width;
@@ -118,16 +122,18 @@ class ProgressBar
break;
}
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$pixel = round(($step - $this->min) * ($bar - ($this->pedding * 2)) / ($this->max - $this->min));
if ($step <= $this->min)
if ($step <= $this->min) {
$pixel = 0;
if ($step >= $this->max)
}
if ($step >= $this->max) {
$pixel = $bar - ($this->pedding * 2);
}
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
$position['left'] = $this->pedding;
$position['top'] = $this->pedding;
@@ -158,10 +164,12 @@ class ProgressBar
private function _setStep($step)
{
if ($step > $this->max)
if ($step > $this->max) {
$step = $this->max;
if ($step < $this->min)
}
if ($step < $this->min) {
$step = $this->min;
}
$this->step = $step;
}
@@ -179,16 +187,17 @@ class ProgressBar
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf'
);
if ($width > 0)
if ($width > 0) {
$this->frame['width'] = $width;
if ($height > 0)
}
if ($height > 0) {
$this->frame['height'] = $height;
}
}
public function addLabel($type, $name, $value = '&nbsp;')
{
switch($type)
{
switch ($type) {
case 'text':
$this->label[$name] = array(
'type' => 'text',
@@ -242,10 +251,11 @@ class ProgressBar
case 'percentlbl':
case 'percent':
// check font size
if ($this->height <= 11)
if ($this->height <= 11) {
$font_size = $this->height - 1;
else
} else {
$font_size = 11;
}
$this->label[$name] = array(
'type' => $type, // either percent or percentlbl
'value' => $value,
@@ -292,19 +302,19 @@ class ProgressBar
{
// print "SET POSITION[$name]: $left<br>";
// if this is percent, we ignore anything, it is auto positioned
if ($this->label[$name]['type'] != 'percent')
{
foreach (array('top', 'left', 'width', 'height') as $pos_name)
if ($$pos_name !== false)
if ($this->label[$name]['type'] != 'percent') {
foreach (array('top', 'left', 'width', 'height') as $pos_name) {
if ($$pos_name !== false) {
$this->label[$name][$pos_name] = intval($$pos_name);
}
}
if ($align != '')
if ($align != '') {
$this->label[$name]['align'] = $align;
}
}
// init
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.top="'.$this->label[$name]['top'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.left="'.$this->label[$name]['left'].'px";';
@@ -320,8 +330,7 @@ class ProgressBar
public function setLabelColor($name, $color)
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -330,8 +339,7 @@ class ProgressBar
public function setLabelBackground($name, $color)
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -340,24 +348,28 @@ class ProgressBar
public function setLabelFont($name, $size, $family = '', $weight = '')
{
// just in case if it is too small
if (intval($size) < 0)
if (intval($size) < 0) {
$size = 11;
}
// if this is percent, the size is not allowed to be bigger than the bar size - 5px
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height)
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height) {
$size = $this->height - 1;
}
// position the label new if this is percent
if ($this->label[$name]['type'] == 'percent')
if ($this->label[$name]['type'] == 'percent') {
$this->label[$name]['top'] = round(($this->height - intval($size)) / log($this->height - intval($size), 7), 0) - $this->pedding;
}
// print "HEIGHT: ".$this->height.", Size: ".intval($size).", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size)).", Log: ".log($this->height - intval($size), 7)."<br>";
// then set like usual
$this->label[$name]['font-size'] = intval($size);
if ($family != '')
if ($family != '') {
$this->label[$name]['font-family'] = $family;
if ($weight != '')
}
if ($weight != '') {
$this->label[$name]['font-weight'] = $weight;
}
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-size="'.$this->label[$name]['font-size'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-family="'.$this->label[$name]['font-family'].'";';
@@ -372,8 +384,7 @@ class ProgressBar
{
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
$this->_flushCache();
}
@@ -382,8 +393,7 @@ class ProgressBar
public function setBarColor($color)
{
$this->color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -392,8 +402,7 @@ class ProgressBar
public function setBarBackground($color)
{
$this->bgr_color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -403,8 +412,7 @@ class ProgressBar
{
$this->direction = $direction;
if ($this->status != 'new')
{
if ($this->status != 'new') {
$this->position = $this->_calculatePosition($this->step);
echo '<script type="text/JavaScript">';
@@ -426,25 +434,30 @@ class ProgressBar
$this->_setStep($this->step);
$this->position = $this->_calculatePosition($this->step);
if ($this->top || $this->left)
if ($this->top || $this->left) {
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
}
$html = '<div id="pbm'.$this->code.'" style="'.$style_master.'background:'.$this->bgr_color_master.';">';
$style_brd = 'width:'.$this->width.'px;height:'.$this->height.'px;background:'.$this->bgr_color.';';
if ($this->border > 0)
if ($this->border > 0) {
$style_brd .= 'border:'.$this->border.'px solid; border-color:'.$this->brd_color.'; -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
$style_bar = 'position:relative;width:'.$this->position['width'].'px;height:'.$this->position['height'].'px;background:'.$this->color.';';
if ($this->position['top'] !== false)
if ($this->position['top'] !== false) {
$style_bar .= 'top:'.$this->position['top'].'px;';
if ($this->position['left'] !== false)
}
if ($this->position['left'] !== false) {
$style_bar .= 'left:'.$this->position['left'].'px;';
if ($this->border > 0)
}
if ($this->border > 0) {
$style_bar .= '-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
if ($this->frame['show'] == true)
{
if ($this->frame['border'] > 0)
if ($this->frame['show'] == true) {
if ($this->frame['border'] > 0) {
$border = 'border:'.$this->frame['border'].'px solid;border-color:'.$this->frame['brd_color'].';margin-top:2px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
}
$html .= '<div id="pfrm'.$this->code.'" style="width:'.$this->frame['width'].'px;height:'.$this->frame['height'].'px;'.$border.'background:'.$this->frame['color'].';">'."\n";
}
@@ -465,34 +478,39 @@ class ProgressBar
$js .= '}'."\n";
//print "DUMP LABEL: <br><pre>".print_r($this->label, 1)."</pre><br>";
foreach ($this->label as $name => $data)
{
foreach ($this->label as $name => $data) {
// set what type of move we do
$move_prefix = $data['type'] == 'button' ? 'margin' : 'padding';
$style_lbl = 'position:relative;';
if ($data['top'] !== false)
if ($data['top'] !== false) {
$style_lbl .= $move_prefix.'-top:'.$data['top'].'px;';
if ($data['left'] !== false)
}
if ($data['left'] !== false) {
$style_lbl .= $move_prefix.'-left:'.$data['left'].'px;';
}
$style_lbl .= 'text-align:'.$data['align'].';';
if ($data['width'] > 0)
if ($data['width'] > 0) {
$style_lbl .= 'width:'.$data['width'].'px;';
if ($data['height'] > 0)
}
if ($data['height'] > 0) {
$style_lbl .= 'height:'.$data['height'].'px;';
}
if (array_key_exists('font-size', $data))
if (array_key_exists('font-size', $data)) {
$style_lbl .= 'font-size:'.$data['font-size'].'px;';
if (array_key_exists('font-family', $data))
}
if (array_key_exists('font-family', $data)) {
$style_lbl .= 'font-family:'.$data['font-family'].';';
if (array_key_exists('font-weight', $data))
}
if (array_key_exists('font-weight', $data)) {
$style_lbl .= 'font-weight:'.$data['font-weight'].';';
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != ''))
}
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != '')) {
$style_lbl .= 'background:'.$data['bgr_color'].';';
}
if (array_key_exists('type', $data))
{
switch ($data['type'])
{
if (array_key_exists('type', $data)) {
switch ($data['type']) {
case 'text':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'margin-bottom:2px;">'.$data['value'].'</div>'."\n";
break;
@@ -505,8 +523,9 @@ class ProgressBar
case 'percent':
// only one inner percent
// print "STYLE[$name]: ".$style_lbl."<br>";
if (!$html_percent)
if (!$html_percent) {
$html_percent = '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;line-height:1;text-shadow: 0 0 .2em white, 0 0 .5em white;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
}
break;
case 'percentlbl':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
@@ -535,17 +554,14 @@ class ProgressBar
$html .= $html_bar_bottom;
$html .= $html_button; // any buttons on bottom
if (count($this->label) > 0)
{
if (count($this->label) > 0) {
$js .= 'function PBlabelText'.$this->code.'(name,text) {'."\n";
$js .= ' name = "plbl" + name + "'.$this->code.'";'."\n";
$js .= ' document.getElementById(name).innerHTML=text;'."\n";
$js .= '}'."\n";
}
if ($this->frame['show'] == true)
{
if ($this->frame['show'] == true) {
$html .= '</div>'."\n";
}
@@ -572,40 +588,31 @@ class ProgressBar
$js = '';
$new_position = $this->_calculatePosition($this->step);
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left'))
{
if ($this->direction=='left')
{
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left')) {
if ($this->direction=='left') {
$js .= 'PBposition'.$this->code.'("left",'.$new_position['left'].');';
}
$js .= 'PBposition'.$this->code.'("width",'.$new_position['width'].');';
}
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down'))
{
if ($this->direction=='up')
{
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down')) {
if ($this->direction=='up') {
$js .= 'PBposition'.$this->code.'("top",'.$new_position['top'].');';
}
$js .= 'PBposition'.$this->code.'("height",'.$new_position['height'].');';
}
$this->position = $new_position;
foreach($this->label as $name => $data)
{
if (array_key_exists('type', $data))
{
switch($data['type'])
{
foreach ($this->label as $name => $data) {
if (array_key_exists('type', $data)) {
switch($data['type']) {
case 'step':
if ($this->step != $last_step)
{
if ($this->step != $last_step) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$this->step.'/'.$this->max.'");';
}
break;
case 'percentlbl':
case 'percent':
$percent = $this->_calculatePercent($this->step);
if ($percent != $this->_calculatePercent($last_step))
{
if ($percent != $this->_calculatePercent($last_step)) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");';
}
break;
@@ -615,8 +622,7 @@ class ProgressBar
}
}
}
if ($js != '')
{
if ($js != '') {
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
$this->_flushCache();
}
@@ -634,8 +640,7 @@ class ProgressBar
public function hide()
{
if ($this->status == 'show')
{
if ($this->status == 'show') {
$this->status = 'hide';
$output = '<script type="text/JavaScript">';
@@ -648,8 +653,7 @@ class ProgressBar
public function unhide()
{
if ($this->status == 'hide')
{
if ($this->status == 'hide') {
$this->status = 'show';
$output = '<script type="text/JavaScript">';
@@ -659,6 +663,4 @@ class ProgressBar
$this->_flushCache();
}
}
}
?>
-2
View File
@@ -26,6 +26,4 @@
// variable variable register
$this->register_modifier('getvar', array(&$this, 'get_template_vars'));
}
}
?>
+16 -15
View File
@@ -35,26 +35,30 @@
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
{
foreach (array('streams.php', 'gettext.php') as $include_file)
foreach (array('streams.php', 'gettext.php') as $include_file) {
_spl_autoload($include_file);
}
if (!$lang)
if (!$lang) {
$this->lang = 'en';
else
} else {
$this->lang = $lang;
}
if (is_dir(LAYOUT.$path.LANG))
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
elseif (!is_dir($path))
} elseif (!is_dir($path)) {
$path = '';
}
$this->mofile = $path.$this->lang.".mo";
// check if get a readable mofile
if (is_readable($this->mofile))
if (is_readable($this->mofile)) {
$this->input = new FileReader($this->mofile);
else
} else {
$this->input = false;
}
$this->l10n = new gettext_reader($this->input);
}
@@ -67,21 +71,19 @@
$this->lang = $lang;
if (is_dir(LAYOUT.$path.LANG))
if (is_dir(LAYOUT.$path.LANG)) {
$path = LAYOUT.$path.LANG;
elseif (!is_dir($path))
} elseif (!is_dir($path)) {
$path = '';
}
$this->mofile = $path.$this->lang.".mo";
// check if get a readable mofile
if (is_readable($this->mofile))
{
if (is_readable($this->mofile)) {
$this->input = new FileReader($this->mofile);
$this->l10n = new gettext_reader($this->input);
}
else
{
} else {
// else fall back to the old ones
$this->mofile = $old_mofile;
$this->lang = $old_lang;
@@ -114,4 +116,3 @@
return $this->mofile;
}
}
?>
+11 -14
View File
@@ -59,34 +59,31 @@
$ROOT = CURRENT_WORKING_DIR;
$LOG = 'log/';
// if the log folder is not found, try to create it
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG))
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG)) {
$ok = mkdir($ROOT.$LOG);
}
$error = 0;
// again, if the folder now exists, else set error flag
if (is_dir($ROOT.$LOG))
{
if (is_dir($ROOT.$LOG)) {
$fn = $ROOT.$LOG.'php_errors-'.date('Y-m-d').'.log';
// when opening, surpress the warning so we can catch the no file pointer below without throwing a warning for this
$fp = @fopen($fn, 'a');
// write if we have a file pointer, else set error flag
if ($fp)
{
if ($fp) {
fwrite($fp, $output."\n");
fclose($fp);
}
else
} else {
$error = 1;
}
else
} else {
$error = 1;
}
// if the above writing failed
if ($error)
{
if ($error) {
// if the display errors is on
// pretty print output for HTML
if (ini_get("display_errors"))
{
if (ini_get("display_errors")) {
echo "<div style='border: 1px dotted red; background-color: #ffffe5; color: #000000; padding: 5px; margin-bottom: 2px;'>";
echo "<div style='color: orange; font-weight: bold;'>".$error_level[$type].":</div>";
echo "<b>$message</b> on line <b>$line</b> in <b>$file</b>";
@@ -94,9 +91,10 @@
}
// if write to log is on
// simplified, remove datetime for log file
if (ini_get('log_errors'))
if (ini_get('log_errors')) {
error_log('{'.$page_temp.'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message);
}
}
// return true, to avoid that php calls its own error stuff
// if E_ERROR, the php one gets called anyway
return true;
@@ -104,4 +102,3 @@
// init the error handler
set_error_handler("MyErrorHandler");
?>
+34 -19
View File
@@ -3,12 +3,14 @@
/**
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
class qqUploadedFileXhr
{
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
public function save($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
@@ -25,10 +27,12 @@ class qqUploadedFileXhr {
return true;
}
function getName() {
public function getName()
{
return $_GET['qqfile'];
}
function getSize() {
public function getSize()
{
if (isset($_SERVER["CONTENT_LENGTH"])) {
return (int)$_SERVER["CONTENT_LENGTH"];
} else {
@@ -40,31 +44,37 @@ class qqUploadedFileXhr {
/**
* Handle file uploads via regular form post (uses the $_FILES array)
*/
class qqUploadedFileForm {
class qqUploadedFileForm
{
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
public function save($path)
{
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
return false;
}
return true;
}
function getName() {
public function getName()
{
return $_FILES['qqfile']['name'];
}
function getSize() {
public function getSize()
{
return $_FILES['qqfile']['size'];
}
}
class qqFileUploader {
class qqFileUploader
{
private $allowedExtensions = array();
private $sizeLimit = 10485760;
private $file;
function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760){
public function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760)
{
$allowedExtensions = array_map("strtolower", $allowedExtensions);
$this->allowedExtensions = $allowedExtensions;
@@ -81,7 +91,8 @@ class qqFileUploader {
}
}
private function checkServerSettings(){
private function checkServerSettings()
{
$postSize = $this->toBytes(ini_get('post_max_size'));
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
@@ -91,13 +102,19 @@ class qqFileUploader {
}
}
private function toBytes($str){
private function toBytes($str)
{
$val = trim($str);
$last = strtolower($str[strlen($str)-1]);
switch ($last) {
case 'g': $val *= 1024;
case 'm': $val *= 1024;
case 'k': $val *= 1024;
case 'g':
$val *= 1024;
// no break
case 'm':
$val *= 1024;
// no break
case 'k':
$val *= 1024;
}
return $val;
}
@@ -105,7 +122,8 @@ class qqFileUploader {
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
public function handleUpload($uploadDirectory, $replaceOldFile = false)
{
if (!is_writable($uploadDirectory)) {
return array('error' => "Server error. Upload directory isn't writable.");
}
@@ -150,8 +168,5 @@ class qqFileUploader {
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
}
}
?>
+21 -31
View File
@@ -47,8 +47,7 @@
{
// read out the query status and save the query if needed
$result = @pg_query($dbh, $query);
if (!$result)
{
if (!$result) {
$this->last_error_query = $query;
}
return $result;
@@ -136,19 +135,18 @@
private function _db_insert_id($dbh, $query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
if (preg_match("/^insert /i", $query)) {
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
if (strstr($_table, '.')) {
list ($schema, $table) = explode('.', $_table);
else
} else {
$table = $_table;
}
// no PK name given at all
if (!$pk_name)
{
if (!$pk_name) {
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
@@ -160,12 +158,9 @@
$this->currval_query = $q;
//echo "Q: $q<Br>";
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = @pg_query($dbh, $q))
{
if ($q = @pg_query($dbh, $q)) {
list($id) = pg_fetch_array($q);
}
else
{
} else {
$id = array(-1, $q);
}
return $id;
@@ -179,13 +174,11 @@
private function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
if (!$db_port) {
$db_port = 5432;
}
$this->dbh = @pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh)
{
if (!$this->dbh) {
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
@@ -198,15 +191,15 @@
private function _db_print_error($dbh, $cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
if (!$cursor && $this->last_error_query) {
pg_send_query($dbh, $this->last_error_query);
$this->last_error_query = "";
$cursor = pg_get_result($dbh);
}
if (pg_result_error($cursor))
if (pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
}
// METHOD: _db_meta_data
// PARAMS: database handler, table name
@@ -243,27 +236,24 @@
// DESC : postgresql array to php array
private function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
if ('},' == $match[3]) {
return $offset;
}
else
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
} while ($limit > $offset);
}
return $output;
}
}
?>
+47 -52
View File
@@ -53,11 +53,12 @@
public function _db_last_error_query()
{
if ($this->last_error_query)
if ($this->last_error_query) {
return true;
else
} else {
return false;
}
}
// METHOD: _db_query
// PARAMS: query
@@ -68,8 +69,9 @@
$this->last_error_query = '';
// read out the query status and save the query if needed
$result = pg_query($this->dbh, $query);
if (!$result)
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
@@ -90,8 +92,9 @@
{
$this->last_error_query = '';
$result = pg_get_result($this->dbh);
if ($error = pg_result_error($result))
if ($error = pg_result_error($result)) {
$this->last_error_query = $error;
}
return $result;
}
@@ -101,10 +104,12 @@
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_resource($this->dbh))
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK)
if (is_resource($this->dbh)) {
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
pg_close($this->dbh);
}
}
}
// METHOD: _db_prepare
// PARAMS: prepare name, query
@@ -113,8 +118,9 @@
public function _db_prepare($name, $query)
{
$result = pg_prepare($this->dbh, $name, $query);
if (!$result)
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
@@ -125,8 +131,9 @@
public function _db_execute($name, $data)
{
$result = pg_execute($this->dbh, $name, $data);
if (!$result)
if (!$result) {
$this->last_error_query = $query;
}
return $result;
}
@@ -164,11 +171,12 @@
public function _db_fetch_array($cursor, $result_type = '')
{
// result type is passed on as is [should be checked]
if ($result_type)
if ($result_type) {
return pg_fetch_array($cursor, NULL, $result_type);
else
} else {
return pg_fetch_array($cursor);
}
}
// METHOD: _db_fetch_all
// PARAMS: cursor
@@ -198,20 +206,19 @@
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
if (preg_match("/^insert /i", $query)) {
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
if (strstr($_table, '.')) {
list($schema, $table) = explode('.', $_table);
else
} else {
$table = $_table;
}
// no PK name given at all
if (!$pk_name)
{
if (!$pk_name) {
// if name is plurar, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
@@ -222,12 +229,9 @@
$q = "SELECT CURRVAL('$seq') AS insert_id";
// $this->currval_query = $q;
// I have to do manually or I overwrite the original insert internal vars ...
if ($q = $this->_db_query($q))
{
if ($q = $this->_db_query($q)) {
list($id) = $this->_db_fetch_array($q);
}
else
{
} else {
$id = array(-1, $q);
}
return $id;
@@ -240,17 +244,14 @@
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table)
{
if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema)
{
if ($schema) {
$q = "SHOW search_path";
$cursor = $this->_db_query($q);
$search_path = $this->_db_fetch_array($cursor)['search_path'];
if ($search_path != $schema)
{
if ($search_path != $schema) {
$table_prefix = $schema.'.';
}
}
@@ -258,14 +259,14 @@
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema)
if ($schema) {
$q .= ", pg_namespace ";
}
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema)
{
if ($schema) {
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
@@ -273,13 +274,12 @@
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$cursor = $this->_db_query($q);
if ($cursor)
if ($cursor) {
return $this->_db_fetch_array($cursor)['column_name'];
else
} else {
return false;
}
else
{
} else {
return false;
}
}
@@ -291,13 +291,11 @@
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
if (!$db_port) {
$db_port = 5432;
}
$this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh)
{
if (!$this->dbh) {
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
}
return $this->dbh;
@@ -310,15 +308,15 @@
public function _db_print_error($cursor = '')
{
// run the query again for the error result here
if (!$cursor && $this->last_error_query)
{
if (!$cursor && $this->last_error_query) {
pg_send_query($this->dbh, $this->last_error_query);
$this->last_error_query = '';
$cursor = pg_get_result($this->dbh);
}
if (pg_result_error($cursor))
if (pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
}
}
// METHOD: _db_meta_data
// PARAMS: table name
@@ -376,27 +374,24 @@
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
if ('},' == $match[3]) {
return $offset;
}
else
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
} while ($limit > $offset);
}
return $output;
}
}
?>
+37 -51
View File
@@ -28,11 +28,12 @@
public function _db_last_error_query()
{
if ($this->last_error_query)
if ($this->last_error_query) {
return true;
else
} else {
return false;
}
}
// METHOD: _db_query
// PARAMS: query
@@ -47,8 +48,9 @@
$this->last_error_query = $query; */
$cursor = $this->_db_prepare(md5($query), $query);
$result = $this->_db_execute(md5($query), array ());
if (!$result)
if (!$result) {
$this->last_error_query = $query;
}
return $cursor;
}
@@ -78,8 +80,9 @@
{
$this->last_error_query = '';
/* $result = pg_get_result($this->dbh);
if ($error = pg_result_error($result))
$this->last_error_query = $error; */
if ($error = pg_result_error($result)) {
$this->last_error_query = $error;
}*/
return $result;
}
@@ -89,10 +92,8 @@
// DESC : wrapper for pg_close
public function _db_close()
{
if (is_array($this->cursor))
{
foreach ($this->cursor as $key => $data)
{
if (is_array($this->cursor)) {
foreach ($this->cursor as $key => $data) {
$this->cursor[$key]->closeCursor;
$this->cursor[$key] = null;
}
@@ -180,20 +181,19 @@
public function _db_insert_id($query, $pk_name)
{
// only if an insert has been done
if (preg_match("/^insert /i", $query))
{
if (preg_match("/^insert /i", $query)) {
$schema = '';
// get table name from insert
$array = explode(' ', $query);
$_table = $array[2];
// if there is a dot inside, we need to split
if (strstr($_table, '.'))
if (strstr($_table, '.')) {
list($schema, $table) = explode('.', $_table);
else
} else {
$table = $_table;
}
// no PK name given at all
if (!$pk_name)
{
if (!$pk_name) {
// if name is plural, make it singular
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
@@ -204,12 +204,9 @@
$q = "SELECT CURRVAL('$seq') AS insert_id";
// I have to do manually or I overwrite the original insert internal vars ...
$row = $this->_db_query_result($q);
if ($row['insert_id'])
{
if ($row['insert_id']) {
$id = $row['insert_id'];
}
else
{
} else {
$id = array(-1, $q);
}
return $id;
@@ -222,18 +219,15 @@
// DESC : queries database for the primary key name to this table in the selected schema
public function _db_primary_key($table, $schema = '')
{
if ($table)
{
if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty
$table_prefix = '';
if ($schema)
{
if ($schema) {
$q = "SHOW search_path";
// $cursor = $this->_db_query($q);
// $search_path = $this->_db_fetch_array($cursor)['search_path'];
$search_path = $this->_db_query_result($q)['search_path'];
if ($search_path != $schema)
{
if ($search_path != $schema) {
$table_prefix = $schema.'.';
}
}
@@ -241,14 +235,14 @@
// faster primary key get
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
$q .= "FROM pg_index, pg_class, pg_attribute ";
if ($schema)
if ($schema) {
$q .= ", pg_namespace ";
}
$q .= "WHERE ";
// regclass translates the OID to the name
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
$q .= "indrelid = pg_class.oid AND ";
if ($schema)
{
if ($schema) {
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
}
@@ -256,13 +250,12 @@
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
$q .= "AND indisprimary";
$row = $this->_db_query_result($q);
if ($row === FALSE)
if ($row === false) {
return false;
else
} else {
return $row['column_name'];
}
else
{
} else {
return false;
}
}
@@ -274,16 +267,12 @@
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
{
// to avoid empty db_port
if (!$db_port)
{
if (!$db_port) {
$db_port = 5432;
}
try
{
try {
$this->dbh = new PDO('pgsql:host='.$db_host.';dbname='.$db_name.';port='.$db_port.';sslmode='.$db_ssl, $db_user, $db_pass);
}
catch (PDOException $e)
{
} catch (PDOException $e) {
print "Error!: ".$e->getMessage()."\n";
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."]: ".$e->getMEssage()."//-->");
}
@@ -363,27 +352,24 @@
// DESC : postgresql array to php array
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
{
if (false === $limit)
{
if (false === $limit) {
$limit = strlen($text) - 1;
$output = array();
}
if ('{}' != $text)
do
{
if ('{' != $text{$offset})
{
if ('{}' != $text) {
do {
if ('{' != $text{$offset}) {
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
$offset += strlen($match[0]);
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
if ('},' == $match[3])
if ('},' == $match[3]) {
return $offset;
}
else
} else {
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
}
while ($limit > $offset);
} while ($limit > $offset);
}
return $output;
}
}
?>
+79 -55
View File
@@ -18,7 +18,6 @@
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@@ -33,22 +32,23 @@
* second parameter in the constructor (e.g. whenusing very large MO files
* that you don't want to keep in memory)
*/
class gettext_reader {
class gettext_reader
{
// public:
var $error = 0; // public variable that holds error code (0 if no error)
public $error = 0; // public variable that holds error code (0 if no error)
//private:
var $BYTEORDER = 0; // 0: low endian, 1: big endian
var $STREAM = NULL;
var $short_circuit = false;
var $enable_cache = false;
var $originals = NULL; // offset of original table
var $translations = NULL; // offset of translation table
var $pluralheader = NULL; // cache header field for plural forms
var $total = 0; // total string count
var $table_originals = NULL; // table for original strings (offsets)
var $table_translations = NULL; // table for translated strings (offsets)
var $cache_translations = NULL; // original -> translation mapping
private $BYTEORDER = 0; // 0: low endian, 1: big endian
private $STREAM = null;
private $short_circuit = false;
private $enable_cache = false;
private $originals = null; // offset of original table
private $translations = null; // offset of translation table
private $pluralheader = null; // cache header field for plural forms
private $total = 0; // total string count
private $table_originals = null; // table for original strings (offsets)
private $table_translations = null; // table for translated strings (offsets)
private $cache_translations = null; // original -> translation mapping
/* Methods */
@@ -60,7 +60,8 @@ class gettext_reader {
* @access private
* @return Integer from the Stream
*/
function readint() {
private function readint()
{
if ($this->BYTEORDER == 0) {
// low endian
$input = unpack('V', $this->STREAM->read(4));
@@ -72,7 +73,8 @@ class gettext_reader {
}
}
function read($bytes) {
public function read($bytes)
{
return $this->STREAM->read($bytes);
}
@@ -82,7 +84,8 @@ class gettext_reader {
* @param int count How many elements should be read
* @return Array of Integers
*/
function readintarray($count) {
public function readintarray($count)
{
if ($this->BYTEORDER == 0) {
// low endian
return unpack('V'.$count, $this->STREAM->read(4 * $count));
@@ -98,7 +101,8 @@ class gettext_reader {
* @param object Reader the StreamReader object
* @param boolean enable_cache Enable or disable caching of strings (default on)
*/
function __construct($Reader, $enable_cache = true) {
public function __construct($Reader, $enable_cache = true)
{
// If there isn't a StreamReader, turn on short circuit mode.
if (!$Reader || isset($Reader->error)) {
$this->short_circuit = true;
@@ -137,11 +141,13 @@ class gettext_reader {
*
* @access private
*/
function load_tables() {
private function load_tables()
{
if (is_array($this->cache_translations) &&
is_array($this->table_originals) &&
is_array($this->table_translations))
is_array($this->table_translations)) {
return;
}
/* get original and translations tables */
if (!is_array($this->table_originals)) {
@@ -173,11 +179,13 @@ class gettext_reader {
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
function get_original_string($num) {
private function get_original_string($num)
{
$length = $this->table_originals[$num * 2 + 1];
$offset = $this->table_originals[$num * 2 + 2];
if (! $length)
if (!$length) {
return '';
}
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
@@ -190,11 +198,13 @@ class gettext_reader {
* @param int num Offset number of original string
* @return string Requested string if found, otherwise ''
*/
function get_translation_string($num) {
private function get_translation_string($num)
{
$length = $this->table_translations[$num * 2 + 1];
$offset = $this->table_translations[$num * 2 + 2];
if (! $length)
if (!$length) {
return '';
}
$this->STREAM->seekto($offset);
$data = $this->STREAM->read($length);
return (string)$data;
@@ -209,7 +219,8 @@ class gettext_reader {
* @param int end (internally used in recursive function)
* @return int string number (offset in originals table)
*/
function find_string($string, $start = -1, $end = -1) {
private function find_string($string, $start = -1, $end = -1)
{
if (($start == -1) or ($end == -1)) {
// find_string is called with only one parameter, set start end end
$start = 0;
@@ -218,10 +229,11 @@ class gettext_reader {
if (abs($start - $end) <= 1) {
// We're done, now we either found the string, or it doesn't exist
$txt = $this->get_original_string($start);
if ($string == $txt)
if ($string == $txt) {
return $start;
else
} else {
return -1;
}
} elseif ($start > $end) {
// start > end -> turn around and start over
return $this->find_string($string, $end, $start);
@@ -229,17 +241,18 @@ class gettext_reader {
// Divide table in two parts
$half = (int)(($start + $end) / 2);
$cmp = strcmp($string, $this->get_original_string($half));
if ($cmp == 0)
if ($cmp == 0) {
// string is exactly in the middle => return it
return $half;
else if ($cmp < 0)
} else if ($cmp < 0) {
// The string is in the upper half
return $this->find_string($string, $start, $half);
else
// The string is in the lower half
} else {
// Translateshe string is in the lower half
return $this->find_string($string, $half, $end);
}
}
}
/**
* Translates a string
@@ -248,26 +261,30 @@ class gettext_reader {
* @param string string to be translated
* @return string translated string (or original, if not found)
*/
function translate($string) {
if ($this->short_circuit)
public function translate($string)
{
if ($this->short_circuit) {
return $string;
}
$this->load_tables();
if ($this->enable_cache) {
// Caching enabled, get translated string from cache
if (array_key_exists($string, $this->cache_translations))
if (array_key_exists($string, $this->cache_translations)) {
return $this->cache_translations[$string];
else
} else {
return $string;
}
} else {
// Caching not enabled, try to find string
$num = $this->find_string($string);
if ($num == -1)
if ($num == -1) {
return $string;
else
} else {
return $this->get_translation_string($num);
}
}
}
/**
* Sanitize plural form expression for use in PHP eval call.
@@ -275,7 +292,8 @@ class gettext_reader {
* @access private
* @return string sanitized plural form expression
*/
function sanitize_plural_expression($expr) {
private function sanitize_plural_expression($expr)
{
// Get rid of disallowed characters.
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
@@ -310,11 +328,13 @@ class gettext_reader {
* @access private
* @return string verbatim plural form header field
*/
function extract_plural_forms_header_from_po_header($header) {
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
private function extract_plural_forms_header_from_po_header($header)
{
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
$expr = $regs[2];
else
} else {
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
}
return $expr;
}
@@ -324,7 +344,8 @@ class gettext_reader {
* @access private
* @return string plural form header
*/
function get_plural_forms() {
private function get_plural_forms()
{
// lets assume message number 0 is header
// this is true, right?
$this->load_tables();
@@ -349,7 +370,8 @@ class gettext_reader {
* @param n count
* @return int array index of the right plural form
*/
function select_string($n) {
private function select_string($n)
{
$string = $this->get_plural_forms();
$string = str_replace('nplurals', "\$total", $string);
$string = str_replace("n", $n, $string);
@@ -359,7 +381,9 @@ class gettext_reader {
$plural = 0;
eval("$string");
if ($plural >= $total) $plural = $total - 1;
if ($plural >= $total) {
$plural = $total - 1;
}
return $plural;
}
@@ -372,13 +396,15 @@ class gettext_reader {
* @param string number
* @return translated plural form
*/
function ngettext($single, $plural, $number) {
public function ngettext($single, $plural, $number)
{
if ($this->short_circuit) {
if ($number != 1)
if ($number != 1) {
return $plural;
else
} else {
return $single;
}
}
// find out the appropriate form
$select = $this->select_string($number);
@@ -386,7 +412,6 @@ class gettext_reader {
// this should contains all strings separated by NULLs
$key = $single . chr(0) . $plural;
if ($this->enable_cache) {
if (! array_key_exists($key, $this->cache_translations)) {
return ($number != 1) ? $plural : $single;
@@ -407,26 +432,25 @@ class gettext_reader {
}
}
function pgettext($context, $msgid) {
public function pgettext($context, $msgid)
{
$key = $context.chr(4).$msgid;
$ret = $this->translate($key);
if (strpos($ret, "\004") !== FALSE) {
if (strpos($ret, "\004") !== false) {
return $msgid;
} else {
return $ret;
}
}
function npgettext($context, $singular, $plural, $number) {
public function npgettext($context, $singular, $plural, $number)
{
$key = $context.chr(4).$singular;
$ret = $this->ngettext($key, $plural, $number);
if (strpos($ret, "\004") !== FALSE) {
if (strpos($ret, "\004") !== false) {
return $singular;
} else {
return $ret;
}
}
}
?>
+56 -41
View File
@@ -17,78 +17,90 @@
You should have received a copy of the GNU General Public License
along with PHP-gettext; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Simple class to wrap file streams, string streams, etc.
// seek is essential, and it should be byte stream
class StreamReader {
class StreamReader
{
// should return a string [FIXME: perhaps return array of bytes?]
function read($bytes) {
public function read($bytes)
{
return false;
}
// should return new position
function seekto($position) {
public function seekto($position)
{
return false;
}
// returns current position
function currentpos() {
public function currentpos()
{
return false;
}
// returns length of entire stream (limit for seekto()s)
function length() {
public function length()
{
return false;
}
};
}
class StringReader {
var $_pos;
var $_str;
class StringReader
{
public $_pos;
public $_str;
function __construct($str='') {
public function __construct($str = '')
{
$this->_str = $str;
$this->_pos = 0;
}
function read($bytes) {
public function read($bytes)
{
$data = substr($this->_str, $this->_pos, $bytes);
$this->_pos += $bytes;
if (strlen($this->_str)<$this->_pos)
if (strlen($this->_str)<$this->_pos) {
$this->_pos = strlen($this->_str);
}
return $data;
}
function seekto($pos) {
public function seekto($pos)
{
$this->_pos = $pos;
if (strlen($this->_str)<$this->_pos)
if (strlen($this->_str)<$this->_pos) {
$this->_pos = strlen($this->_str);
}
return $this->_pos;
}
function currentpos() {
public function currentpos()
{
return $this->_pos;
}
function length() {
public function length()
{
return strlen($this->_str);
}
};
}
class FileReader {
var $_pos;
var $_fd;
var $_length;
class FileReader
{
public $_pos;
public $_fd;
public $_length;
function __construct($filename) {
public function __construct($filename)
{
if (file_exists($filename)) {
$this->_length=filesize($filename);
$this->_pos = 0;
$this->_fd = fopen($filename, 'rb');
@@ -102,7 +114,8 @@ class FileReader {
}
}
function read($bytes) {
public function read($bytes)
{
if ($bytes) {
fseek($this->_fd, $this->_pos);
@@ -117,35 +130,41 @@ class FileReader {
$this->_pos = ftell($this->_fd);
return $data;
} else return '';
} else {
return '';
}
}
function seekto($pos) {
public function seekto($pos)
{
fseek($this->_fd, $pos);
$this->_pos = ftell($this->_fd);
return $this->_pos;
}
function currentpos() {
public function currentpos()
{
return $this->_pos;
}
function length() {
public function length()
{
return $this->_length;
}
function close() {
public function close()
{
fclose($this->_fd);
}
};
}
// Preloads entire file in memory first, then creates a StringReader
// over it (it assumes knowledge of StringReader internals)
class CachedFileReader extends StringReader {
function __construct($filename) {
class CachedFileReader extends StringReader
{
public function __construct($filename)
{
if (file_exists($filename)) {
$length=filesize($filename);
$fd = fopen($filename, 'rb');
@@ -155,13 +174,9 @@ class CachedFileReader extends StringReader {
}
$this->_str = fread($fd, $length);
fclose($fd);
} else {
$this->error = 2; // File doesn't exist
return false;
}
}
};
?>
}