Merge namespace development into master
This commit is contained in:
1015
www/lib/CoreLibs/ACL/Login.inc
Normal file
1015
www/lib/CoreLibs/ACL/Login.inc
Normal file
File diff suppressed because it is too large
Load Diff
362
www/lib/CoreLibs/Admin/Backend.inc
Normal file
362
www/lib/CoreLibs/Admin/Backend.inc
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2006/08/15
|
||||
* VERSION: 1.0.0
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* DESCRIPTION
|
||||
* Basic Admin interface backend
|
||||
* - sets action flags
|
||||
* - menu creation
|
||||
* - array vars for smarty
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
*
|
||||
* PRIVATE METHODS
|
||||
*
|
||||
* HISTORY:
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
namespace CoreLibs\Admin;
|
||||
|
||||
class Backend extends \CoreLibs\DB\IO
|
||||
{
|
||||
// page name
|
||||
public $page_name; // the name of the current page
|
||||
public $menu = array();
|
||||
public $menu_show_flag = 0; // top menu flag (mostly string)
|
||||
// action ids
|
||||
public $action_list = array ('action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag', 'action_menu', 'action_value', 'action_error', 'action_loaded');
|
||||
public $action;
|
||||
public $action_id;
|
||||
public $action_sub_id;
|
||||
public $action_yes;
|
||||
public $action_flag;
|
||||
public $action_menu;
|
||||
public $action_loaded;
|
||||
public $action_value;
|
||||
public $action_error;
|
||||
// ACL array variable if we want to set acl data from outisde
|
||||
public $acl = array ();
|
||||
// the current active edit access id
|
||||
public $edit_access_id;
|
||||
// error/warning/info messages
|
||||
public $messages = array ();
|
||||
public $error = 0;
|
||||
public $warning = 0;
|
||||
public $info = 0;
|
||||
// smarty publics
|
||||
public $DATA;
|
||||
public $HEADER;
|
||||
public $DEBUG_DATA;
|
||||
public $CONTENT_DATA;
|
||||
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
public function __construct($db_config, $lang, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
|
||||
{
|
||||
// get the language sub class & init it
|
||||
$this->l = new \CoreLibs\Language\L10n($lang);
|
||||
|
||||
// init the database class
|
||||
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
|
||||
|
||||
// internal
|
||||
$this->class_info["adbBackend"] = array(
|
||||
"class_name" => "Admin Interface Backend",
|
||||
"class_version" => "1.0.0",
|
||||
"class_created" => "2006/08/15",
|
||||
"class_author" => "Clemens Schwaighofer"
|
||||
);
|
||||
|
||||
// set page name
|
||||
$this->page_name = $this->getPageName();
|
||||
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
$this->$_action = (isset($_POST[$_action])) ? $_POST[$_action] : '';
|
||||
}
|
||||
|
||||
$this->default_acl = DEFAULT_ACL_LEVEL;
|
||||
|
||||
// random key generation
|
||||
$this->key_range = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
|
||||
$GLOBALS["_KEY_RANGE"] = $this->key_range;
|
||||
$this->one_key_length = count($this->key_range);
|
||||
$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)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// deconstructor
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// INTERNAL METHODS |===============================================>
|
||||
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
// METHOD: adbEditLog()
|
||||
// PARAMS: event -> any kind of event description, data -> any kind of data related to that event
|
||||
// RETURN: none
|
||||
// DESC : writes all action vars plus other info into edit_log table
|
||||
public function adbEditLog($event = '', $data = '', $write_type = 'STRING')
|
||||
{
|
||||
if ($write_type == 'BINARY') {
|
||||
$data_binary = $this->dbEscapeBytea(bzcompress(serialize($data)));
|
||||
$data = 'see bzip compressed data_binary field';
|
||||
}
|
||||
if ($write_type == 'STRING') {
|
||||
$data = $this->dbEscapeString(serialize($data));
|
||||
}
|
||||
|
||||
$q = "INSERT INTO ".LOGIN_DB_SCHEMA.".edit_log ";
|
||||
$q .= "(euid, event_date, event, 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 ";
|
||||
$q .= "(".@$_SESSION['EUID'].", NOW(), '".$this->dbEscapeString($event)."', '".$data."', '".$data_binary."', '".$this->page_name."', ";
|
||||
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->dbEscapeString(@$_SERVER['HTTP_USER_AGENT'])."', ";
|
||||
$q .= "'".$this->dbEscapeString(@$_SERVER['HTTP_REFERER'])."', '".$this->dbEscapeString(@$_SERVER['SCRIPT_FILENAME'])."', ";
|
||||
$q .= "'".$this->dbEscapeString(@$_SERVER['QUERY_STRING'])."', '".$this->dbEscapeString(@$_SERVER['SERVER_NAME'])."', ";
|
||||
$q .= "'".$this->dbEscapeString(@$_SERVER['HTTP_HOST'])."', '".$this->dbEscapeString(@$_SERVER['HTTP_ACCEPT'])."', ";
|
||||
$q .= "'".$this->dbEscapeString(@$_SERVER['HTTP_ACCEPT_CHARSET'])."', '".$this->dbEscapeString(@$_SERVER['HTTP_ACCEPT_ENCODING'])."', ";
|
||||
$q .= "'".session_id()."', ";
|
||||
$q .= "'".$this->dbEscapeString($this->action)."', '".$this->dbEscapeString($this->action_id)."', ";
|
||||
$q .= "'".$this->dbEscapeString($this->action_yes)."', '".$this->dbEscapeString($this->action_flag)."', ";
|
||||
$q .= "'".$this->dbEscapeString($this->action_menu)."', '".$this->dbEscapeString($this->action_loaded)."', ";
|
||||
$q .= "'".$this->dbEscapeString($this->action_value)."', '".$this->dbEscapeString($this->action_error)."')";
|
||||
$this->dbExec($q, 'NULL');
|
||||
}
|
||||
|
||||
// METHOD: adbTopMenu
|
||||
// PARAMS: level
|
||||
// RETURN: returns an array for the top menu with all correct settings
|
||||
// DESC : menu creater
|
||||
public function adbTopMenu($flag = 0)
|
||||
{
|
||||
if ($this->menu_show_flag) {
|
||||
$flag = $this->menu_show_flag;
|
||||
}
|
||||
|
||||
// get the session pages array
|
||||
$pages = $_SESSION["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, $iMax = count($pages); $i < $iMax; $i ++) {
|
||||
$show = 0;
|
||||
// is it visible in the menu & is it 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) {
|
||||
$show = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if no flag given, show all menu points
|
||||
$show = 1;
|
||||
}
|
||||
|
||||
if ($show) {
|
||||
// if it is popup, write popup arrayound
|
||||
if ($pages[$i]["popup"]) {
|
||||
$type = "popup";
|
||||
} else {
|
||||
$type = "normal";
|
||||
}
|
||||
$query_string = '';
|
||||
if (count($pages[$i]["query"])) {
|
||||
for ($j = 0, $jMax = count($pages[$i]["query"]); $j < $jMax; $j ++) {
|
||||
if (strlen($query_string)) {
|
||||
$query_string .= "&";
|
||||
}
|
||||
$query_string .= $pages[$i]["query"][$j]["name"]."=";
|
||||
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"]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$url = $pages[$i]["filename"];
|
||||
if (strlen($query_string)) {
|
||||
$url .= "?".$query_string;
|
||||
}
|
||||
$name = $pages[$i]["page_name"];
|
||||
// if page name matchs -> set selected flag
|
||||
$selected = 0;
|
||||
if ($this->getPageName() == $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"])) {
|
||||
$enabled = 1;
|
||||
}
|
||||
// write in to view menu array
|
||||
array_push($this->menu, array("name" => $this->l->__($name), "url" => $url, "selected" => $selected, "enabled" => $enabled, "type" => $type));
|
||||
} // show page
|
||||
} // online and in menu
|
||||
} // for each page
|
||||
return $this->menu;
|
||||
}
|
||||
|
||||
// METHOD: adbShowMenuPoint
|
||||
// PARAMS: filename
|
||||
// RETURN: returns boolean true/false
|
||||
// DESC : checks if this filename is in the current situation (user id, etc) available
|
||||
public function adbShowMenuPoint($filename)
|
||||
{
|
||||
$enabled = 0;
|
||||
switch ($filename) {
|
||||
default:
|
||||
$enabled = 1;
|
||||
break;
|
||||
};
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbAssocArray
|
||||
// PARAMS: db array, key, value part
|
||||
// RETURN: returns and associative array
|
||||
// DESC : creates out of a normal db_return array an assoc array
|
||||
public function adbAssocArray($db_array, $key, $value)
|
||||
{
|
||||
return $this->genAssocArray($db_array, $key, $value);
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbByteStringFormat
|
||||
// PARAMS: int
|
||||
// RETURN: string
|
||||
// DESC : converts bytes into formated string with KB, MB, etc
|
||||
public function adbByteStringFormat($number)
|
||||
{
|
||||
return $this->byteStringFormat($number);
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbCreateThumbnail
|
||||
// PARAMS: id from picture where from we create a thumbnail
|
||||
// x -> max x size of thumbnail
|
||||
// y -> max y size of thumbnail
|
||||
// dummy -> if set to true, then if no images was found we show a dummy image
|
||||
// path -> if source start is not ROOT path, if empty ROOT is choosen
|
||||
// cache -> cache path, if not given TMP is used
|
||||
// RETURN: thumbnail name
|
||||
// DESC : converts picture to a thumbnail with max x and max y size
|
||||
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "")
|
||||
{
|
||||
return $this->createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
|
||||
}
|
||||
|
||||
// METHOD: adbMsg
|
||||
// PARAMS: level -> info/warning/error
|
||||
// msg -> string, can be printf formated
|
||||
// var array -> optional data for a possible printf formated msg
|
||||
// RETURN: none
|
||||
// DESC : wrapper function to fill up the mssages array
|
||||
public function adbMsg($level, $msg, $vars = array ())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: adbLiveQueue
|
||||
// PARAMS: queue_key -> string to identfy the queue
|
||||
// type -> INSERT/UPDATE/DELETE
|
||||
// target -> target table to write to
|
||||
// data -> SQL part to write, this can include #KEY_VALUE#, #KEY_NAME# for delete sub queries
|
||||
// key_name -> key name, mostly used for update search
|
||||
// key_value -> data for the key
|
||||
// associate -> NULL for free, LOCK for first insert, group key for reference to first entry
|
||||
// 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)
|
||||
{
|
||||
$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->dbEscapeString($queue_key)."', '".$this->dbEscapeString($key_value)."', ";
|
||||
$q .= "'".$this->dbEscapeString($key_name)."', '".$this->dbEscapeString($type)."', ";
|
||||
$q .= "'".$this->dbEscapeString($target)."', '".$this->dbEscapeString($data)."', ";
|
||||
$q .= "'".$this->queue_key."', '".$this->action."', '".$this->dbEscapeString($associate)."', ";
|
||||
$q .= "'".$this->dbEscapeString($file)."')";
|
||||
$this->db_exec($q);
|
||||
}
|
||||
|
||||
// METHOD: adbPrintDateTime
|
||||
// PARAMS: year, month, day, hour, min: the date and time values
|
||||
// suffix: additional info printed after the date time variable in the drop down,
|
||||
// also used for ID in the on change JS call
|
||||
// minute steps: can be 1 (default), 5, 10, etc, if invalid (outside 1h range,
|
||||
// it falls back to 1min)
|
||||
// name pos back: default false, if set to true, the name will be printend
|
||||
// after the drop down and not before the drop down
|
||||
// RETURN: HTML formated strings for drop down lists of date and time
|
||||
// DESC : print the date/time drop downs, used in any queue/send/insert at date/time place
|
||||
// NOTE : Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||
// are translated in this call
|
||||
public function adbPrintDateTime($year, $month, $day, $hour, $min, $suffix = '', $min_steps = 1, $name_pos_back = false)
|
||||
{
|
||||
// get the build layout
|
||||
$html_time = $this->printDateTime($year, $month, $day, $hour, $min, $suffix, $min_steps, $name_pos_back);
|
||||
// translate the strings inside
|
||||
foreach (array('Year ', 'Month ', 'Day ', 'Hour ', 'Minute ') as $_time) {
|
||||
$html_time = str_replace($_time, $this->l->__(str_replace(' ', '', $_time)).' ', $html_time);
|
||||
}
|
||||
// replace week days in short
|
||||
foreach (array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') as $_date) {
|
||||
$html_time = str_replace('('.$_date.')', '('.$this->l->__($_date).')', $html_time);
|
||||
}
|
||||
// return the datetime select string with strings translated
|
||||
return $html_time;
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
2301
www/lib/CoreLibs/Basic.inc
Normal file
2301
www/lib/CoreLibs/Basic.inc
Normal file
File diff suppressed because it is too large
Load Diff
546
www/lib/CoreLibs/DB/Extended/ArrayIO.inc
Normal file
546
www/lib/CoreLibs/DB/Extended/ArrayIO.inc
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2002/12/17
|
||||
* VERSION: 1.0.0
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* SHORT DESC :RIPTION:
|
||||
* DB Array IO Class:
|
||||
* writes, reads or deletes a complete array (one data set) in/out a
|
||||
* table from the connected DB.
|
||||
* you don't have to write any SQL queries, worry over update/insert
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* PUBLIC METHOD:S
|
||||
*
|
||||
* PRIVATE METHOD:S
|
||||
*
|
||||
* HISTORY:
|
||||
* 2005/07/07 (cs) updated array class for postgres: set 0 & NULL if int field given, insert uses () values () syntax
|
||||
* 2005/03/31 (cs) fixed the class call with all debug vars
|
||||
* 2003-03-10: error_ids where still wrong chagned 11->21 and 12->22
|
||||
* 2003-02-26: db_array_io is no longer single class but extens db_io,
|
||||
* as it needs it anyway
|
||||
* moved the class info vars into class_info array into
|
||||
* the constructor, removed info function
|
||||
* 2003-02-24: in db_delete moved query build to top, or pk_name/value
|
||||
* will be reset before delete is done
|
||||
* 2002-12-20: just added info() method
|
||||
* 2002-12-17: splitted the class from other file (with main db wrapper)
|
||||
*********************************************************************/
|
||||
|
||||
// picture upload should be taken out from here and out in media_class
|
||||
// as it actually has nothing to do with this one here ? (or at least
|
||||
// put into separete function in this class)
|
||||
|
||||
namespace CoreLibs\DB\Extended;
|
||||
|
||||
// subclass for one array handling
|
||||
class ArrayIO extends \CoreLibs\DB\IO
|
||||
{
|
||||
// main calss variables
|
||||
public $table_array; // the array from the table to work on
|
||||
public $table_name; // the table_name
|
||||
public $pk_name; // the primary key from this table
|
||||
public $pk_id; // the PK id
|
||||
|
||||
// METHOD: db_array_io
|
||||
// PARAMS: db_config -> db_io class init vars
|
||||
// table_array -> the array from the table
|
||||
// table_name -> name of the table (for the array)
|
||||
// db_debug -> turn on db_io debug output (DB_DEBUG as global var does the same)
|
||||
// RETURN: none
|
||||
// DESC : constructor for the array io class, set the
|
||||
// primary key name automatically (from array)
|
||||
public function __construct($db_config, $table_array, $table_name, $debug = 0, $db_debug = 0, $echo = 1, $print = 0)
|
||||
{
|
||||
// instance db_io class
|
||||
parent::__construct($db_config, $debug, $db_debug, $echo, $print);
|
||||
// more error vars for this class
|
||||
$this->error_string["21"] = "No Primary Key given";
|
||||
$this->error_string["22"] = "Could not run Array Query";
|
||||
|
||||
$this->table_array = $table_array;
|
||||
$this->table_name = $table_name;
|
||||
|
||||
// set primary key for given table_array
|
||||
if ($this->table_array) {
|
||||
foreach ($table_array as $key => $value) {
|
||||
if ($value["pk"]) {
|
||||
$this->pk_name = $key;
|
||||
}
|
||||
}
|
||||
} // set pk_name IF table_array was given
|
||||
// internal
|
||||
$this->class_info["db_array_io"] = array(
|
||||
"class_name" => "DB Array IO",
|
||||
"class_version" => "1.0.0",
|
||||
"class_created" => "2002/12/17",
|
||||
"class_author" => "Clemens Schwaighofer"
|
||||
);
|
||||
}
|
||||
|
||||
// deconstruktor
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// METHOD: convertData
|
||||
// WAS : convert_data
|
||||
// PARAMS: string -> the string that should be changed
|
||||
// RETURN: string -> the altered string
|
||||
// DESC : changes all previously alterd HTML code into visible one,
|
||||
// works for <b>,<i>, and <a> (thought <a> can be / or should
|
||||
// be handled with the magic links functions
|
||||
// used with the read function
|
||||
public function convertData($text)
|
||||
{
|
||||
$text = str_replace('<b>', '<b>', $text);
|
||||
$text = str_replace('</b>', '</b>', $text);
|
||||
$text = str_replace('<i>', '<i>', $text);
|
||||
$text = str_replace('</i>', '</i>', $text);
|
||||
// my need a change
|
||||
$text = str_replace('<a href="', '<a target="_blank" href="', $text);
|
||||
$text = str_replace('">', '">', $text);
|
||||
$text = str_replace('</a>', '</a>', $text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
// METHOD: convertEntities
|
||||
// WAS : convert_entities
|
||||
// PARAMS: string -> string to be changed
|
||||
// RETURN: string -> altered string
|
||||
// DESC : changeds all HTML entities into non HTML ones
|
||||
public function convertEntities($text)
|
||||
{
|
||||
$text = str_replace('<', '<', $text);
|
||||
$text = str_replace('>', '>', $text);
|
||||
$text = str_replace('&', '&', $text);
|
||||
$text = str_replace('"', '"', $text);
|
||||
$text = str_replace(''', "'", $text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
// METHOD: dbDumpArray
|
||||
// WAS : db_dump_array
|
||||
// PARAMS: none
|
||||
// RETURN: returns the current array
|
||||
// DESC : dumps the current data
|
||||
public function dbDumpArray($write = 0)
|
||||
{
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
$string .= "<b>".$column."</b> -> ".$data_array["value"]."<br>";
|
||||
}
|
||||
// add output to internal error_msg
|
||||
if ($write) {
|
||||
$this->error_msg['db'] .= $string;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
// METHOD: dbCheckPkSet
|
||||
// WAS : db_check_pk_set
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : checks if pk is set and if not, set from pk_id and if this also not set return 0
|
||||
public function dbCheckPkSet()
|
||||
{
|
||||
// if pk_id is set, overrule ...
|
||||
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 no PK found, error ...
|
||||
$this->error_id = 21;
|
||||
$this->__dbError();
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: dbResetArray
|
||||
// WAS : db_reset_array
|
||||
// PARAMS: reset_pk -> if set reset the pk too
|
||||
// RETURN: none
|
||||
// DESC : resets the whole array
|
||||
public function dbResetArray($reset_pk = 0)
|
||||
{
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
if (!$this->table_array[$column]["pk"]) {
|
||||
unset($this->table_array[$column]["value"]);
|
||||
} elseif ($reset_pk) {
|
||||
unset($this->table_array[$column]["value"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: dbDelete
|
||||
// WAS : db_delete
|
||||
// PARAMS: optional the table_array, if not given uses class var
|
||||
// RETURN: 1 for successfull delete or 0 for error
|
||||
// DESC : deletes one dataset
|
||||
public function dbDelete($table_array = 0)
|
||||
{
|
||||
if (is_array($table_array)) {
|
||||
$this->table_array = $table_array;
|
||||
}
|
||||
if (!$this->dbCheckPkSet()) {
|
||||
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);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
// suchen nach bildern und lschen ...
|
||||
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)) {
|
||||
unlink($this->table_array[$column]["path"].$dateiname);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->table_array[$column]["fk"]) {
|
||||
// zusammenstellen der FKs
|
||||
if ($q_where) {
|
||||
$q_where .= " AND ";
|
||||
}
|
||||
$q_where .= $column." = ".$this->table_array[$column]["value"];
|
||||
}
|
||||
// allgemeines zurcksetzen des arrays
|
||||
unset($this->table_array[$column]["value"]);
|
||||
}
|
||||
|
||||
// attach fk row if there ...
|
||||
if ($q_where) {
|
||||
$q .= " AND ".$q_where;
|
||||
}
|
||||
// if 0, error
|
||||
unset($this->pk_id);
|
||||
if (!$this->dbExec($q)) {
|
||||
$this->error_id=22;
|
||||
$this->__dbError();
|
||||
}
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// METHOD: dbRead
|
||||
// WAS : db_read
|
||||
// PARAMS: edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var
|
||||
// RETURN: true or false for reading
|
||||
// DESC : reads one row into the array
|
||||
public function dbRead($edit = 0, $table_array = 0)
|
||||
{
|
||||
// if array give, overrules internal array
|
||||
if (is_array($table_array)) {
|
||||
$this->table_array = $table_array;
|
||||
}
|
||||
if (!$this->dbCheckPkSet()) {
|
||||
return $this->table_array;
|
||||
}
|
||||
reset($this->table_array);
|
||||
// create select part & addition FK part
|
||||
foreach ($this->table_array as $column => $data_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) {
|
||||
$q_where .= " AND ";
|
||||
}
|
||||
$q_where .= $column .= " = ".$this->table_array[$column]["value"];
|
||||
}
|
||||
}
|
||||
|
||||
$q = "SELECT ";
|
||||
$q .= $q_select;
|
||||
$q .= " FROM ".$this->table_name." WHERE ";
|
||||
$q .= $this->pk_name." = ".$this->table_array[$this->pk_name]["value"]." ";
|
||||
if ($q_where) {
|
||||
$q .= " AND ".$q_where;
|
||||
}
|
||||
|
||||
// if query was executed okay, else set error
|
||||
if ($this->dbExec($q)) {
|
||||
if ($res = $this->dbFetchArray()) {
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
// wenn "edit" dann gib daten wie in DB zurck, ansonten aufbereiten fr ausgabe
|
||||
// ?? sollte das nicht drauen ??? 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) {
|
||||
$this->table_array[$column]["value"] = $res[$column];
|
||||
// if password, also write to hidden
|
||||
if ($this->table_array[$column]["type"] == "password") {
|
||||
$this->table_array[$column]["HIDDEN_value"] = $res[$column];
|
||||
}
|
||||
} else {
|
||||
$this->table_array[$column]["value"] = $this->convertData(nl2br($res[$column]));
|
||||
// had to put out the htmlentities from the line above as it breaks japanese characters
|
||||
}
|
||||
}
|
||||
}
|
||||
// possible dbFetchArray errors ...
|
||||
$this->pk_id = $this->table_array[$this->pk_name]["value"];
|
||||
} else {
|
||||
$this->error_id = 22;
|
||||
$this->__dbError();
|
||||
}
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// METHOD: dbWrite
|
||||
// WAS : db_write
|
||||
// PARAMS: addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var
|
||||
// RETURN: true or false on write
|
||||
// DESC : writes on set into DB or updates one set (if PK exists)
|
||||
public function dbWrite($addslashes = 0, $table_array = 0)
|
||||
{
|
||||
if (is_array($table_array)) {
|
||||
$this->table_array = $table_array;
|
||||
}
|
||||
// PK ID check
|
||||
// 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"]) {
|
||||
$insert = 1;
|
||||
} else {
|
||||
$insert = 0;
|
||||
}
|
||||
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
/********************************* START FILE *************************************/
|
||||
// file upload
|
||||
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"]) {
|
||||
unset($this->table_array[$column]["delete"]);
|
||||
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 zusammenbasteln: org-name + _pkid liste + .ext
|
||||
list($name, $ext) = explode(".", $this->table_array[$column]["dn"]);
|
||||
|
||||
// mozilla, patch
|
||||
$fn_name = explode("/", $this->table_array[$column]["dn"]);
|
||||
$this->table_array[$column]["dn"] = $fn_name[count($fn_name)-1];
|
||||
$filename_parts = explode(".", $this->table_array[$column]["dn"]);
|
||||
$ext = end($filename_parts);
|
||||
array_splice($filename_parts, -1, 1);
|
||||
$name = str_replace(" ", "_", implode(".", $filename_parts));
|
||||
//echo "PK: $pk_ids_file<br>";
|
||||
$dateiname = $name.$pk_ids_file.".".$ext;
|
||||
//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") {
|
||||
$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 {
|
||||
$this->table_array[$column]["value"] = $dateiname;
|
||||
}
|
||||
} elseif (file_exists($this->table_array[$column]["path"].$this->table_array[$column]["value"])) {
|
||||
// mach gar nix, wenn bild schon da ???
|
||||
}
|
||||
} // delete or upload
|
||||
} // file IF
|
||||
/********************************* 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) {
|
||||
// for password use hidden value if main is not set
|
||||
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)) {
|
||||
$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"]) {
|
||||
$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"]) {
|
||||
$_value = 'NULL';
|
||||
} elseif (!isset($this->table_array[$column]["value"])) {
|
||||
$_value = 0;
|
||||
} else {
|
||||
$_value = $this->table_array[$column]["value"];
|
||||
}
|
||||
$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"]) {
|
||||
$_value = 'NULL';
|
||||
}
|
||||
$q_data .= $_value;
|
||||
} else {
|
||||
// normal string
|
||||
$q_data .= "'";
|
||||
// if add slashes do convert & add slashes else write AS is
|
||||
if ($addslashes) {
|
||||
$q_data .= $this->dbEscapeString($this->convertEntities($this->table_array[$column]["value"]));
|
||||
} else {
|
||||
$q_data .= $this->dbEscapeString($this->table_array[$column]["value"]);
|
||||
}
|
||||
$q_data .= "'";
|
||||
}
|
||||
}
|
||||
} // while ...
|
||||
|
||||
// NOW get PK, and FK settings (FK only for update query)
|
||||
// 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
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
// check FK ...
|
||||
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"]) {
|
||||
// max id, falls INSERT
|
||||
$q = "SELECT MAX(".$this->pk_name.") + 1 AS pk_id FROM ".$this->table_name;
|
||||
$res = $this->dbReturnRow($q);
|
||||
if (!$res["pk_id"]) {
|
||||
$res["pk_id"] = 1;
|
||||
}
|
||||
$this->table_array[$this->pk_name]["value"] = $res["pk_id"];
|
||||
}
|
||||
|
||||
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) {
|
||||
$q .= " AND ".$q_where;
|
||||
}
|
||||
// set pk_id ... if it has changed or so
|
||||
$this->pk_id = $this->table_array[$this->pk_name]["value"];
|
||||
} 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"];
|
||||
}
|
||||
// return success or not
|
||||
if (!$this->dbExec($q)) {
|
||||
$this->error_id = 22;
|
||||
$this->__dbError();
|
||||
}
|
||||
// set primary key
|
||||
if ($insert) {
|
||||
$this->table_array[$this->pk_name]["value"] = $this->insert_id;
|
||||
$this->ok = $this->insert_id;
|
||||
}
|
||||
// return the table if needed
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// COMPATIBILITY METHODS
|
||||
// those methods are deprecated function call names
|
||||
// they exist for backwards compatibility only
|
||||
// *************************************************************
|
||||
|
||||
public function convert_data($text)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->convertData($text);
|
||||
}
|
||||
|
||||
public function convert_entities($text)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->convertEntities($text);
|
||||
}
|
||||
|
||||
public function db_dump_array($write = 0)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbDumpArray($write);
|
||||
}
|
||||
|
||||
public function db_check_pk_set()
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbCheckPkSet();
|
||||
}
|
||||
|
||||
public function db_reset_array($reset_pk = 0)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbResetArray($reset_pk);
|
||||
}
|
||||
|
||||
public function db_delete($table_array = 0)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbDelete($table_array);
|
||||
}
|
||||
|
||||
public function db_read($edit = 0, $table_array = 0)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbRead($edit, $table_array);
|
||||
}
|
||||
|
||||
public function db_write($addslashes = 0, $table_array = 0)
|
||||
{
|
||||
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
|
||||
return $this->dbWrite($addslashes, $table_array);
|
||||
}
|
||||
} // end of class
|
||||
|
||||
# __END__
|
||||
2092
www/lib/CoreLibs/DB/IO.inc
Normal file
2092
www/lib/CoreLibs/DB/IO.inc
Normal file
File diff suppressed because it is too large
Load Diff
430
www/lib/CoreLibs/DB/SQL/PgSQL.inc
Normal file
430
www/lib/CoreLibs/DB/SQL/PgSQL.inc
Normal file
@@ -0,0 +1,430 @@
|
||||
<?php
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2003/04/09
|
||||
* SHORT DESCRIPTION:
|
||||
* 2018/3/23, the whole class system is transformed to namespaces
|
||||
* also all internal class calls are converted to camel case
|
||||
*
|
||||
* pgsql wrapper calls
|
||||
*
|
||||
* HISTORY:
|
||||
* 2008/04/16 (cs) wrapper for pg escape string
|
||||
* 2007/01/11 (cs) add prepare/execute for postgres
|
||||
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
|
||||
* 2006/06/26 (cs) added port for db connection
|
||||
* 2006/04/03 (cs) added meta data for table
|
||||
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
|
||||
* 2005/07/07 (cs) the default it is table_name _ id
|
||||
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
|
||||
* 2004/09/30 (cs) layout cleanup
|
||||
* /
|
||||
|
||||
* collection of PostgreSQL wrappers
|
||||
* REQUIRES 5.x PHP!!!
|
||||
*
|
||||
* pg_prepare
|
||||
* pg_execute
|
||||
* pg_num_rows
|
||||
* pg_num_fields
|
||||
* pg_field_name
|
||||
* pg_affected_rows (*)
|
||||
* pg_fetch_array
|
||||
* pg_query
|
||||
* pg_send_query
|
||||
* pg_get_result
|
||||
* pg_connection_busy
|
||||
* pg_close
|
||||
* pg_connect (*)
|
||||
* pg_meta_data
|
||||
* pg_escape_string
|
||||
*
|
||||
*/
|
||||
|
||||
namespace CoreLibs\DB\SQL;
|
||||
|
||||
class PgSQL
|
||||
{
|
||||
private $last_error_query;
|
||||
private $dbh;
|
||||
|
||||
// METHOD: __construct
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : class constructor
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
// METHOD: __dbLastErrorQuery
|
||||
// WAS : _db_last_error_query
|
||||
// PARAMS: none
|
||||
// RETURN: true/false if last error is set
|
||||
// DESC : queries last error query and returns true or false if error was set
|
||||
public function __dbLastErrorQuery()
|
||||
{
|
||||
if ($this->last_error_query) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbQuery
|
||||
// WAS : _db_query
|
||||
// PARAMS: query
|
||||
// RETURN: query result
|
||||
// DESC : wrapper for gp_query, catches error and stores it in class var
|
||||
public function __dbQuery($query)
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
// read out the query status and save the query if needed
|
||||
$result = pg_query($this->dbh, $query);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbSendQuery
|
||||
// WAS : _db_send_query
|
||||
// PARAMS: query
|
||||
// RETURN: true/false if query was sent successful
|
||||
// DESC : sends an async query to the server
|
||||
public function __dbSendQuery($query)
|
||||
{
|
||||
return pg_send_query($this->dbh, $query);
|
||||
}
|
||||
|
||||
// METHOD: __dbGetResult
|
||||
// WAS : _db_get_result
|
||||
// PARAMS: none
|
||||
// RETURN: resource handler
|
||||
// DESC : wrapper for pg_get_result
|
||||
public function __dbGetResult()
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
$result = pg_get_result($this->dbh);
|
||||
if ($error = pg_result_error($result)) {
|
||||
$this->last_error_query = $error;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbClose
|
||||
// WAS : _db_close
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : wrapper for pg_close
|
||||
public function __dbClose()
|
||||
{
|
||||
if (is_resource($this->dbh)) {
|
||||
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
|
||||
pg_close($this->dbh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbPrepare
|
||||
// WAS : _db_prepare
|
||||
// PARAMS: prepare name, query
|
||||
// RETURN: prepared statement handler
|
||||
// DESC : wrapper for pg_prepare
|
||||
public function __dbPrepare($name, $query)
|
||||
{
|
||||
$result = pg_prepare($this->dbh, $name, $query);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbExecute
|
||||
// WAS : _db_execute
|
||||
// PARAMS: prepare name, data for query
|
||||
// RETURN: returns status
|
||||
// DESC : wrapper for pg_execute for running a prepared statement
|
||||
public function __dbExecute($name, $data)
|
||||
{
|
||||
$result = pg_execute($this->dbh, $name, $data);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbNumRows
|
||||
// WAS : _db_num_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: rows
|
||||
// DESC : wrapper for pg_num_rows
|
||||
public function __dbNumRows($cursor)
|
||||
{
|
||||
return pg_num_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbNumFields
|
||||
// WAS : _db_num_fields
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for fields in query
|
||||
// DESC : wrapper for pg_num_fields
|
||||
public function __dbNumFields($cursor)
|
||||
{
|
||||
return pg_num_fields($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbFieldName
|
||||
// WAS : _db_field_name
|
||||
// PARAMS: cursor, field position
|
||||
// RETURN: name of field
|
||||
// DESC : wrapper for pg_field_name
|
||||
public function __dbFieldName($cursor, $i)
|
||||
{
|
||||
return pg_field_name($cursor, $i);
|
||||
}
|
||||
|
||||
// METHOD: __dbFetchArray
|
||||
// WAS : _db_fetch_array
|
||||
// PARAMS: cursor, opt result type
|
||||
// RETURN: row
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
public function __dbFetchArray($cursor, $result_type = '')
|
||||
{
|
||||
// result type is passed on as is [should be checked]
|
||||
if ($result_type) {
|
||||
return pg_fetch_array($cursor, null, $result_type);
|
||||
} else {
|
||||
return pg_fetch_array($cursor);
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbFetchAll
|
||||
// WAS : _db_fetch_all
|
||||
// PARAMS: cursor
|
||||
// RETURN: all rows as array
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
public function __dbFetchAll($cursor)
|
||||
{
|
||||
return pg_fetch_all($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbAffectedRows
|
||||
// WAS : _db_affected_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for rows
|
||||
// DESC : wrapper for pg_affected_rows
|
||||
public function __dbAffectedRows($cursor)
|
||||
{
|
||||
return pg_affected_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbInsertId
|
||||
// WAS : _db_insert_id
|
||||
// PARAMS: query, primary key name
|
||||
// RETURN: last insert primary key
|
||||
// DESC : reads the last inserted primary key for the query
|
||||
// if ther is no pk_name tries to auto built it from the table name
|
||||
// this only works if db schema is after "no plural names. and pk name is table name + _id
|
||||
// detects schema prefix in table name
|
||||
public function __dbInsertId($query, $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
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, '.')) {
|
||||
list($schema, $table) = explode('.', $_table);
|
||||
} else {
|
||||
$table = $_table;
|
||||
}
|
||||
// no PK name given at all
|
||||
if (!$pk_name) {
|
||||
// if name is plurar, make it singular
|
||||
// if (preg_match("/.*s$/i", $table))
|
||||
// $table = substr($table, 0, -1);
|
||||
// set pk_name to "id"
|
||||
$pk_name = $table."_id";
|
||||
}
|
||||
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
|
||||
$q = "SELECT CURRVAL('$seq') AS insert_id";
|
||||
// I have to do manually or I overwrite the original insert internal vars ...
|
||||
if ($q = $this->__dbQuery($q)) {
|
||||
list($id) = $this->__dbFetchArray($q);
|
||||
} else {
|
||||
$id = array(-1, $q);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbPrimaryKey
|
||||
// WAS : _db_primary_key
|
||||
// PARAMS: table and optional schema
|
||||
// RETURN: primary key name OR false if not possible
|
||||
// DESC : queries database for the primary key name to this table in the selected schema
|
||||
public function __dbPrimaryKey($table, $schema = '')
|
||||
{
|
||||
if ($table) {
|
||||
// check if schema set is different from schema given, only needed if schema is not empty
|
||||
$table_prefix = '';
|
||||
if ($schema) {
|
||||
$q = "SHOW search_path";
|
||||
$cursor = $this->__dbQuery($q);
|
||||
$search_path = $this->__dbFetchArray($cursor)['search_path'];
|
||||
if ($search_path != $schema) {
|
||||
$table_prefix = $schema.'.';
|
||||
}
|
||||
}
|
||||
// read from table the PK name
|
||||
// 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) {
|
||||
$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) {
|
||||
$q .= "nspname = '".$schema."' AND ";
|
||||
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
|
||||
}
|
||||
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
|
||||
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
|
||||
$q .= "AND indisprimary";
|
||||
$cursor = $this->__dbQuery($q);
|
||||
if ($cursor) {
|
||||
return $this->__dbFetchArray($cursor)['column_name'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbConnect
|
||||
// WAS : _db_connect
|
||||
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
|
||||
// RETURN: database handler
|
||||
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
public function __dbConnect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
|
||||
{
|
||||
// to avoid empty 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) {
|
||||
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
|
||||
}
|
||||
return $this->dbh;
|
||||
}
|
||||
|
||||
// METHOD: __dbPrintError
|
||||
// WAS : _db_print_error
|
||||
// PARAMS: database handler, cursor
|
||||
// RETURN: error string (HTML)
|
||||
// DESC : reads the last error for this cursor
|
||||
public function __dbPrintError($cursor = '')
|
||||
{
|
||||
// run the query again for the error result here
|
||||
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)) {
|
||||
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbMetaData
|
||||
// WAS : _db_meta_data
|
||||
// PARAMS: table name
|
||||
// RETURN: array with table data
|
||||
// DESC : wrapper for pg_emta_data
|
||||
public function __dbMetaData($table)
|
||||
{
|
||||
return pg_meta_data($this->dbh, $table);
|
||||
}
|
||||
|
||||
// METHOD: __dbEscapeString
|
||||
// WAS : _db_escape_string
|
||||
// PARAMS: string
|
||||
// RETURN: escaped string for postgres
|
||||
// DESC : wrapper for pg_escape_string
|
||||
public function __dbEscapeString($string)
|
||||
{
|
||||
return pg_escape_string($this->dbh, $string);
|
||||
}
|
||||
|
||||
// METHOD: __dbEscapeBytea
|
||||
// WAS : _db_escape_bytea
|
||||
// PARAMS: string
|
||||
// RETURN: escape bytes for postgres
|
||||
// DESC : wrapper for pg_escape_bytea
|
||||
public function __dbEscapeBytea($bytea)
|
||||
{
|
||||
return pg_escape_bytea($this->dbh, $bytea);
|
||||
}
|
||||
|
||||
// METHOD: __dbConnectionBusy
|
||||
// WAS : _db_connection_busy
|
||||
// PARAMS: none
|
||||
// RETURN: true/false for busy connection
|
||||
// DESC : wrapper for pg_connection_busy
|
||||
public function __dbConnectionBusy()
|
||||
{
|
||||
return pg_connection_busy($this->dbh);
|
||||
}
|
||||
|
||||
// METHOD: __dbVersion
|
||||
// WAS : _db_version
|
||||
// PARAMS: none
|
||||
// RETURN: databse version
|
||||
// DESC : wrapper for pg_version
|
||||
public function __dbVersion()
|
||||
{
|
||||
// array has client, protocol, server
|
||||
// we just need the server
|
||||
$v = pg_version($this->dbh);
|
||||
return $v['server'];
|
||||
}
|
||||
|
||||
// METHOD: __dbArrayParse
|
||||
// WAS : _db_array_parse
|
||||
// PARAMS: input text, output array [needed]
|
||||
// [internal] limit: are we at the end of the parse
|
||||
// [internal] offset: shift for {}
|
||||
// RETURN: array with the elements
|
||||
// DESC : postgresql array to php array
|
||||
public function __dbArrayParse($text, &$output, $limit = false, $offset = 1)
|
||||
{
|
||||
if (false === $limit) {
|
||||
$limit = strlen($text) - 1;
|
||||
$output = array();
|
||||
}
|
||||
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]) {
|
||||
return $offset;
|
||||
}
|
||||
} else {
|
||||
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
|
||||
}
|
||||
} while ($limit > $offset);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
48
www/lib/CoreLibs/Language/Core/CachedFileReader.inc
Executable file
48
www/lib/CoreLibs/Language/Core/CachedFileReader.inc
Executable file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
|
||||
This file is part of PHP-gettext.
|
||||
|
||||
PHP-gettext is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
PHP-gettext is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Language\Core;
|
||||
|
||||
// Preloads entire file in memory first, then creates a StringReader
|
||||
// over it (it assumes knowledge of StringReader internals)
|
||||
class CachedFileReader extends CoreLibs\Language\Core\StringReader
|
||||
{
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
$length = filesize($filename);
|
||||
$fd = fopen($filename, 'rb');
|
||||
|
||||
if (!$fd) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
return false;
|
||||
}
|
||||
$this->_str = fread($fd, $length);
|
||||
fclose($fd);
|
||||
} else {
|
||||
$this->error = 2; // File doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
91
www/lib/CoreLibs/Language/Core/FileReader.inc
Executable file
91
www/lib/CoreLibs/Language/Core/FileReader.inc
Executable file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
|
||||
This file is part of PHP-gettext.
|
||||
|
||||
PHP-gettext is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
PHP-gettext is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Language\Core;
|
||||
|
||||
class FileReader
|
||||
{
|
||||
public $fr_pos;
|
||||
public $fr_fd;
|
||||
public $fr_length;
|
||||
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
$this->fr_length = filesize($filename);
|
||||
$this->fr_pos = 0;
|
||||
$this->fr_fd = fopen($filename, 'rb');
|
||||
if (!$this->fr_fd) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = 2; // File doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function read($bytes)
|
||||
{
|
||||
if ($bytes) {
|
||||
fseek($this->fr_fd, $this->fr_pos);
|
||||
|
||||
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
|
||||
// the discussions at PHP Bugs suggest it's the intended behaviour
|
||||
$data = '';
|
||||
while ($bytes > 0) {
|
||||
$chunk = fread($this->fr_fd, $bytes);
|
||||
$data .= $chunk;
|
||||
$bytes -= strlen($chunk);
|
||||
}
|
||||
$this->fr_pos = ftell($this->fr_fd);
|
||||
|
||||
return $data;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function seekto($pos)
|
||||
{
|
||||
fseek($this->fr_fd, $pos);
|
||||
$this->fr_pos = ftell($this->fr_fd);
|
||||
return $this->fr_pos;
|
||||
}
|
||||
|
||||
public function currentpos()
|
||||
{
|
||||
return $this->fr_pos;
|
||||
}
|
||||
|
||||
public function length()
|
||||
{
|
||||
return $this->fr_length;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
fclose($this->fr_fd);
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
460
www/lib/CoreLibs/Language/Core/GetTextReader.inc
Executable file
460
www/lib/CoreLibs/Language/Core/GetTextReader.inc
Executable file
@@ -0,0 +1,460 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
Copyright (c) 2005 Nico Kaiser <nico@siriux.net>
|
||||
|
||||
This file is part of PHP-gettext.
|
||||
|
||||
PHP-gettext is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
PHP-gettext is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Language\Core;
|
||||
|
||||
/**
|
||||
* Provides a simple gettext replacement that works independently from
|
||||
* the system's gettext abilities.
|
||||
* It can read MO files and use them for translating strings.
|
||||
* The files are passed to gettext_reader as a Stream (see streams.php)
|
||||
*
|
||||
* This version has the ability to cache all strings and translations to
|
||||
* speed up the string lookup.
|
||||
* While the cache is enabled by default, it can be switched off with the
|
||||
* second parameter in the constructor (e.g. whenusing very large MO files
|
||||
* that you don't want to keep in memory)
|
||||
*/
|
||||
class GetTextReader
|
||||
{
|
||||
// public:
|
||||
public $error = 0; // public variable that holds error code (0 if no error)
|
||||
|
||||
//private:
|
||||
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 */
|
||||
|
||||
|
||||
/**
|
||||
* Reads a 32bit Integer from the Stream
|
||||
*
|
||||
* @access private
|
||||
* @return Integer from the Stream
|
||||
*/
|
||||
private function readint()
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
$input = unpack('V', $this->STREAM->read(4));
|
||||
return array_shift($input);
|
||||
} else {
|
||||
// big endian
|
||||
$input = unpack('N', $this->STREAM->read(4));
|
||||
return array_shift($input);
|
||||
}
|
||||
}
|
||||
|
||||
public function read($bytes)
|
||||
{
|
||||
return $this->STREAM->read($bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an array of Integers from the Stream
|
||||
*
|
||||
* @param int count How many elements should be read
|
||||
* @return Array of Integers
|
||||
*/
|
||||
public function readintarray($count)
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
return unpack('V'.$count, $this->STREAM->read(4 * $count));
|
||||
} else {
|
||||
// big endian
|
||||
return unpack('N'.$count, $this->STREAM->read(4 * $count));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object Reader the StreamReader object
|
||||
* @param boolean enable_cache Enable or disable caching of strings (default on)
|
||||
*/
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
||||
// Caching can be turned off
|
||||
$this->enable_cache = $enable_cache;
|
||||
|
||||
$MAGIC1 = "\x95\x04\x12\xde";
|
||||
$MAGIC2 = "\xde\x12\x04\x95";
|
||||
|
||||
$this->STREAM = $Reader;
|
||||
$magic = $this->read(4);
|
||||
if ($magic == $MAGIC1) {
|
||||
$this->BYTEORDER = 1;
|
||||
} elseif ($magic == $MAGIC2) {
|
||||
$this->BYTEORDER = 0;
|
||||
} else {
|
||||
$this->error = 1; // not MO file
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: Do we care about revision? We should.
|
||||
$revision = $this->readint();
|
||||
|
||||
$this->total = $this->readint();
|
||||
$this->originals = $this->readint();
|
||||
$this->translations = $this->readint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the translation tables from the MO file into the cache
|
||||
* If caching is enabled, also loads all strings into a cache
|
||||
* to speed up translation lookups
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function load_tables()
|
||||
{
|
||||
if (is_array($this->cache_translations) &&
|
||||
is_array($this->table_originals) &&
|
||||
is_array($this->table_translations)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* get original and translations tables */
|
||||
if (!is_array($this->table_originals)) {
|
||||
$this->STREAM->seekto($this->originals);
|
||||
$this->table_originals = $this->readintarray($this->total * 2);
|
||||
}
|
||||
if (!is_array($this->table_translations)) {
|
||||
$this->STREAM->seekto($this->translations);
|
||||
$this->table_translations = $this->readintarray($this->total * 2);
|
||||
}
|
||||
|
||||
if ($this->enable_cache) {
|
||||
$this->cache_translations = array ();
|
||||
/* read all strings in the cache */
|
||||
for ($i = 0; $i < $this->total; $i++) {
|
||||
$this->STREAM->seekto($this->table_originals[$i * 2 + 2]);
|
||||
$original = $this->STREAM->read($this->table_originals[$i * 2 + 1]);
|
||||
$this->STREAM->seekto($this->table_translations[$i * 2 + 2]);
|
||||
$translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]);
|
||||
$this->cache_translations[$original] = $translation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string from the "originals" table
|
||||
*
|
||||
* @access private
|
||||
* @param int num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function get_original_string($num)
|
||||
{
|
||||
$length = $this->table_originals[$num * 2 + 1];
|
||||
$offset = $this->table_originals[$num * 2 + 2];
|
||||
if (!$length) {
|
||||
return '';
|
||||
}
|
||||
$this->STREAM->seekto($offset);
|
||||
$data = $this->STREAM->read($length);
|
||||
return (string)$data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string from the "translations" table
|
||||
*
|
||||
* @access private
|
||||
* @param int num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function get_translation_string($num)
|
||||
{
|
||||
$length = $this->table_translations[$num * 2 + 1];
|
||||
$offset = $this->table_translations[$num * 2 + 2];
|
||||
if (!$length) {
|
||||
return '';
|
||||
}
|
||||
$this->STREAM->seekto($offset);
|
||||
$data = $this->STREAM->read($length);
|
||||
return (string)$data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binary search for string
|
||||
*
|
||||
* @access private
|
||||
* @param string string
|
||||
* @param int start (internally used in recursive function)
|
||||
* @param int end (internally used in recursive function)
|
||||
* @return int string number (offset in originals table)
|
||||
*/
|
||||
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;
|
||||
$end = $this->total;
|
||||
}
|
||||
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) {
|
||||
return $start;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} elseif ($start > $end) {
|
||||
// start > end -> turn around and start over
|
||||
return $this->find_string($string, $end, $start);
|
||||
} else {
|
||||
// Divide table in two parts
|
||||
$half = (int)(($start + $end) / 2);
|
||||
$cmp = strcmp($string, $this->get_original_string($half));
|
||||
if ($cmp == 0) {
|
||||
// string is exactly in the middle => return it
|
||||
return $half;
|
||||
} elseif ($cmp < 0) {
|
||||
// The string is in the upper half
|
||||
return $this->find_string($string, $start, $half);
|
||||
} else {
|
||||
// Translateshe string is in the lower half
|
||||
return $this->find_string($string, $half, $end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string
|
||||
*
|
||||
* @access public
|
||||
* @param string string to be translated
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
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)) {
|
||||
return $this->cache_translations[$string];
|
||||
} else {
|
||||
return $string;
|
||||
}
|
||||
} else {
|
||||
// Caching not enabled, try to find string
|
||||
$num = $this->find_string($string);
|
||||
if ($num == -1) {
|
||||
return $string;
|
||||
} else {
|
||||
return $this->get_translation_string($num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize plural form expression for use in PHP eval call.
|
||||
*
|
||||
* @access private
|
||||
* @return string sanitized plural form expression
|
||||
*/
|
||||
private function sanitize_plural_expression($expr)
|
||||
{
|
||||
// Get rid of disallowed characters.
|
||||
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
|
||||
|
||||
// Add parenthesis for tertiary '?' operator.
|
||||
$expr .= ';';
|
||||
$res = '';
|
||||
$p = 0;
|
||||
for ($i = 0; $i < strlen($expr); $i++) {
|
||||
$ch = $expr[$i];
|
||||
switch ($ch) {
|
||||
case '?':
|
||||
$res .= ' ? (';
|
||||
$p++;
|
||||
break;
|
||||
case ':':
|
||||
$res .= ') : (';
|
||||
break;
|
||||
case ';':
|
||||
$res .= str_repeat(')', $p).';';
|
||||
$p = 0;
|
||||
break;
|
||||
default:
|
||||
$res .= $ch;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse full PO header and extract only plural forms line.
|
||||
*
|
||||
* @access private
|
||||
* @return string verbatim plural form header field
|
||||
*/
|
||||
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 {
|
||||
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
|
||||
}
|
||||
return $expr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get possible plural forms from MO header
|
||||
*
|
||||
* @access private
|
||||
* @return string plural form header
|
||||
*/
|
||||
private function get_plural_forms()
|
||||
{
|
||||
// lets assume message number 0 is header
|
||||
// this is true, right?
|
||||
$this->load_tables();
|
||||
|
||||
// cache header field for plural forms
|
||||
if (! is_string($this->pluralheader)) {
|
||||
if ($this->enable_cache) {
|
||||
$header = $this->cache_translations[""];
|
||||
} else {
|
||||
$header = $this->get_translation_string(0);
|
||||
}
|
||||
$expr = $this->extract_plural_forms_header_from_po_header($header);
|
||||
$this->pluralheader = $this->sanitize_plural_expression($expr);
|
||||
}
|
||||
return $this->pluralheader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects which plural form to take
|
||||
*
|
||||
* @access private
|
||||
* @param n count
|
||||
* @return int array index of the right plural form
|
||||
*/
|
||||
private function select_string($n)
|
||||
{
|
||||
$string = $this->get_plural_forms();
|
||||
$string = str_replace('nplurals', "\$total", $string);
|
||||
$string = str_replace("n", $n, $string);
|
||||
$string = str_replace('plural', "\$plural", $string);
|
||||
|
||||
$total = 0;
|
||||
$plural = 0;
|
||||
|
||||
eval("$string");
|
||||
if ($plural >= $total) {
|
||||
$plural = $total - 1;
|
||||
}
|
||||
return $plural;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext
|
||||
*
|
||||
* @access public
|
||||
* @param string single
|
||||
* @param string plural
|
||||
* @param string number
|
||||
* @return translated plural form
|
||||
*/
|
||||
public function ngettext($single, $plural, $number)
|
||||
{
|
||||
if ($this->short_circuit) {
|
||||
if ($number != 1) {
|
||||
return $plural;
|
||||
} else {
|
||||
return $single;
|
||||
}
|
||||
}
|
||||
|
||||
// find out the appropriate form
|
||||
$select = $this->select_string($number);
|
||||
|
||||
// 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;
|
||||
} else {
|
||||
$result = $this->cache_translations[$key];
|
||||
$list = explode(chr(0), $result);
|
||||
return $list[$select];
|
||||
}
|
||||
} else {
|
||||
$num = $this->find_string($key);
|
||||
if ($num == -1) {
|
||||
return ($number != 1) ? $plural : $single;
|
||||
} else {
|
||||
$result = $this->get_translation_string($num);
|
||||
$list = explode(chr(0), $result);
|
||||
return $list[$select];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function pgettext($context, $msgid)
|
||||
{
|
||||
$key = $context.chr(4).$msgid;
|
||||
$ret = $this->translate($key);
|
||||
if (strpos($ret, "\004") !== false) {
|
||||
return $msgid;
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
public function npgettext($context, $singular, $plural, $number)
|
||||
{
|
||||
$key = $context.chr(4).$singular;
|
||||
$ret = $this->ngettext($key, $plural, $number);
|
||||
if (strpos($ret, "\004") !== false) {
|
||||
return $singular;
|
||||
} else {
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
54
www/lib/CoreLibs/Language/Core/StreamReader.inc
Executable file
54
www/lib/CoreLibs/Language/Core/StreamReader.inc
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
|
||||
This file is part of PHP-gettext.
|
||||
|
||||
PHP-gettext is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
PHP-gettext is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Language\Core;
|
||||
|
||||
// Simple class to wrap file streams, string streams, etc.
|
||||
// seek is essential, and it should be byte stream
|
||||
class StreamReader
|
||||
{
|
||||
// should return a string [FIXME: perhaps return array of bytes?]
|
||||
public function read($bytes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// should return new position
|
||||
public function seekto($position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns current position
|
||||
public function currentpos()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns length of entire stream (limit for seekto()s)
|
||||
public function length()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
67
www/lib/CoreLibs/Language/Core/StringReader.inc
Executable file
67
www/lib/CoreLibs/Language/Core/StringReader.inc
Executable file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
|
||||
|
||||
This file is part of PHP-gettext.
|
||||
|
||||
PHP-gettext is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
PHP-gettext is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Language\Core;
|
||||
|
||||
class StringReader
|
||||
{
|
||||
public $sr_pos;
|
||||
public $sr_str;
|
||||
|
||||
public function __construct($str = '')
|
||||
{
|
||||
$this->sr_str = $str;
|
||||
$this->sr_pos = 0;
|
||||
}
|
||||
|
||||
public function read($bytes)
|
||||
{
|
||||
$data = substr($this->sr_str, $this->sr_pos, $bytes);
|
||||
$this->sr_pos += $bytes;
|
||||
if (strlen($this->sr_str) < $this->sr_pos) {
|
||||
$this->sr_pos = strlen($this->sr_str);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function seekto($pos)
|
||||
{
|
||||
$this->sr_pos = $pos;
|
||||
if (strlen($this->sr_str) < $this->sr_pos) {
|
||||
$this->sr_pos = strlen($this->sr_str);
|
||||
}
|
||||
return $this->sr_pos;
|
||||
}
|
||||
|
||||
public function currentpos()
|
||||
{
|
||||
return $this->sr_pos;
|
||||
}
|
||||
|
||||
public function length()
|
||||
{
|
||||
return strlen($this->sr_str);
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
116
www/lib/CoreLibs/Language/L10n.inc
Normal file
116
www/lib/CoreLibs/Language/L10n.inc
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2004/11/18
|
||||
* VERSION: 1.0.0
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* SHORT DESCRIPTION:
|
||||
* init class for gettext. Original was just a function & var setting include for wordpress.
|
||||
* I changed that to a class to be more portable with my style of coding
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
* __: returns string (translated or original if not found)
|
||||
* __e: echos out string (translated or original if not found)
|
||||
* __ngettext: should return plural. never tested this.
|
||||
*
|
||||
* PRIVATE METHODS
|
||||
*
|
||||
* HISTORY:
|
||||
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||
*********************************************************************/
|
||||
|
||||
namespace CoreLibs\Language;
|
||||
|
||||
use \CoreLibs\Language\Core\FileReader;
|
||||
use \CoreLibs\Language\Core\GetTextReader;
|
||||
|
||||
class L10n extends \CoreLibs\Basic
|
||||
{
|
||||
private $lang = '';
|
||||
private $mofile = '';
|
||||
private $input;
|
||||
private $l10n;
|
||||
|
||||
public function __construct($lang = '', $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
if (!$lang) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
if (is_dir(LAYOUT.$path.LANG)) {
|
||||
$path = LAYOUT.$path.LANG;
|
||||
} elseif (!is_dir($path)) {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
$this->input = new FileReader($this->mofile);
|
||||
} else {
|
||||
$this->input = false;
|
||||
}
|
||||
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
}
|
||||
|
||||
// reloads the mofile, if the location of the lang file changes
|
||||
public function l10nReloadMOfile($lang, $path = DEFAULT_TEMPLATE)
|
||||
{
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->lang;
|
||||
|
||||
$this->lang = $lang;
|
||||
|
||||
if (is_dir(LAYOUT.$path.LANG)) {
|
||||
$path = LAYOUT.$path.LANG;
|
||||
} elseif (!is_dir($path)) {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
$this->mofile = $path.$this->lang.".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
$this->input = new FileReader($this->mofile);
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
} else {
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->lang = $old_lang;
|
||||
}
|
||||
}
|
||||
|
||||
public function __($text)
|
||||
{
|
||||
return $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
public function __e($text)
|
||||
{
|
||||
echo $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
// Return the plural form.
|
||||
public function __ngettext($single, $plural, $number)
|
||||
{
|
||||
return $this->l10n->ngettext($single, $plural, $number);
|
||||
}
|
||||
|
||||
public function __getLang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
public function __getMoFile()
|
||||
{
|
||||
return $this->mofile;
|
||||
}
|
||||
}
|
||||
1687
www/lib/CoreLibs/Output/Form/Generate.inc
Normal file
1687
www/lib/CoreLibs/Output/Form/Generate.inc
Normal file
File diff suppressed because it is too large
Load Diff
673
www/lib/CoreLibs/Output/Progressbar.inc
Normal file
673
www/lib/CoreLibs/Output/Progressbar.inc
Normal file
@@ -0,0 +1,673 @@
|
||||
<?php
|
||||
/*
|
||||
* Class ProgressBar
|
||||
*
|
||||
* Author: Gerd Weitenberg (hahnebuechen@web.de)
|
||||
* Date: 2005.03.09
|
||||
*
|
||||
* Update: Clemens Schwaighofer
|
||||
* Date: 2012.9.5 [stacked output]
|
||||
* Date: 2013.2.21 [proper class formatting]
|
||||
* Date: 2017.4.13 [no output fix with cache overload]
|
||||
* Date: 2018.3.28 [PHPCS + namespace]
|
||||
*
|
||||
*/
|
||||
|
||||
namespace CoreLibs\Output;
|
||||
|
||||
class ProgressBar
|
||||
{
|
||||
// private vars
|
||||
|
||||
public $code; // unique code
|
||||
public $status = 'new'; // current status (new,show,hide)
|
||||
public $step = 0; // current step
|
||||
public $position = array(); // current bar position
|
||||
|
||||
public $clear_buffer_size = 1; // we need to send this before the lfush to get browser output
|
||||
public $clear_buffer_size_init = 1024*1024; // if I don't send that junk, it won't send anything
|
||||
|
||||
// public vars
|
||||
|
||||
public $min = 0; // minimal steps
|
||||
public $max = 100; // maximal steps
|
||||
|
||||
public $left = 5; // bar position from left
|
||||
public $top = 5; // bar position from top
|
||||
public $width = 300; // bar width
|
||||
public $height = 25; // bar height
|
||||
public $pedding = 0; // bar pedding
|
||||
public $color = '#0033ff'; // bar color
|
||||
public $bgr_color = '#c0c0c0'; // bar background color
|
||||
public $bgr_color_master = '#ffffff'; // master div background color
|
||||
public $border = 1; // bar border width
|
||||
public $brd_color = '#000000'; // bar border color
|
||||
|
||||
public $direction = 'right'; // direction of motion (right,left,up,down)
|
||||
|
||||
public $frame = array('show' => false); // ProgressBar Frame
|
||||
/* 'show' => false, # frame show (true/false)
|
||||
'left' => 200, # frame position from left
|
||||
'top' => 100, # frame position from top
|
||||
'width' => 300, # frame width
|
||||
'height' => 75, # frame height
|
||||
'color' => '#c0c0c0', # frame color
|
||||
'border' => 2, # frame border
|
||||
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf' # frame border color
|
||||
*/
|
||||
|
||||
public $label = array(); // ProgressBar Labels
|
||||
/* 'name' => array( # label name
|
||||
'type' => 'text', # label type (text,button,step,percent,crossbar)
|
||||
'value' => 'Please wait ...', # label value
|
||||
'left' => 10, # label position from left
|
||||
'top' => 20, # label position from top
|
||||
'width' => 0, # label width
|
||||
'height' => 0, # label height
|
||||
'align' => 'left', # label align
|
||||
'font-size' => 11, # label font size
|
||||
'font-family' => 'Verdana, Tahoma, Arial', # label font family
|
||||
'font-weight' => '', # label font weight
|
||||
'color' => '#000000', # label font color
|
||||
'bgr_color' => '' # label background color
|
||||
)
|
||||
*/
|
||||
|
||||
// constructor
|
||||
public function __construct($width = 0, $height = 0)
|
||||
{
|
||||
$this->code = substr(md5(microtime()), 0, 6);
|
||||
if ($width > 0) {
|
||||
$this->width = $width;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// private functions
|
||||
|
||||
private function __flushCache($clear_buffer_size = 0)
|
||||
{
|
||||
if (!$clear_buffer_size) {
|
||||
$clear_buffer_size = $this->clear_buffer_size;
|
||||
}
|
||||
echo str_repeat(' ', $clear_buffer_size);
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
private function __calculatePercent($step)
|
||||
{
|
||||
// avoid divison through 0
|
||||
if ($this->max - $this->min == 0) {
|
||||
$this->max ++;
|
||||
}
|
||||
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
|
||||
if ($percent > 100) {
|
||||
$percent = 100;
|
||||
}
|
||||
return $percent;
|
||||
}
|
||||
|
||||
private function __calculatePosition($step)
|
||||
{
|
||||
switch ($this->direction) {
|
||||
case 'right':
|
||||
case 'left':
|
||||
$bar = $this->width;
|
||||
break;
|
||||
case 'down':
|
||||
case 'up':
|
||||
$bar = $this->height;
|
||||
break;
|
||||
}
|
||||
// avoid divison through 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) {
|
||||
$pixel = 0;
|
||||
}
|
||||
if ($step >= $this->max) {
|
||||
$pixel = $bar - ($this->pedding * 2);
|
||||
}
|
||||
|
||||
switch ($this->direction) {
|
||||
case 'right':
|
||||
$position['left'] = $this->pedding;
|
||||
$position['top'] = $this->pedding;
|
||||
$position['width'] = $pixel;
|
||||
$position['height'] = $this->height - ($this->pedding * 2);
|
||||
break;
|
||||
case 'left':
|
||||
$position['left'] = $this->width - $this->pedding - $pixel;
|
||||
$position['top'] = $this->pedding;
|
||||
$position['width'] = $pixel;
|
||||
$position['height'] = $this->height - ($this->pedding * 2);
|
||||
break;
|
||||
case 'down':
|
||||
$position['left'] = $this->pedding;
|
||||
$position['top'] = $this->pedding;
|
||||
$position['width'] = $this->width - ($this->pedding * 2);
|
||||
$position['height'] = $pixel;
|
||||
break;
|
||||
case 'up':
|
||||
$position['left'] = $this->pedding;
|
||||
$position['top'] = $this->height - $this->pedding - $pixel;
|
||||
$position['width'] = $this->width - ($this->pedding * 2);
|
||||
$position['height'] = $pixel;
|
||||
break;
|
||||
}
|
||||
return $position;
|
||||
}
|
||||
|
||||
private function __setStep($step)
|
||||
{
|
||||
if ($step > $this->max) {
|
||||
$step = $this->max;
|
||||
}
|
||||
if ($step < $this->min) {
|
||||
$step = $this->min;
|
||||
}
|
||||
$this->step = $step;
|
||||
}
|
||||
|
||||
// public functions
|
||||
public function setFrame($width = 0, $height = 0)
|
||||
{
|
||||
$this->frame = array (
|
||||
'show' => true,
|
||||
'left' => 20,
|
||||
'top' => 35,
|
||||
'width' => $this->width + 6,
|
||||
'height' => 'auto',
|
||||
'color' => '#c0c0c0',
|
||||
'border' => 2,
|
||||
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf'
|
||||
);
|
||||
|
||||
if ($width > 0) {
|
||||
$this->frame['width'] = $width;
|
||||
}
|
||||
if ($height > 0) {
|
||||
$this->frame['height'] = $height;
|
||||
}
|
||||
}
|
||||
|
||||
public function addLabel($type, $name, $value = ' ')
|
||||
{
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
$this->label[$name] = array(
|
||||
'type' => 'text',
|
||||
'value' => $value,
|
||||
'left' => 0, // keep all to the left in box
|
||||
'top' => 2, // default top is 2px
|
||||
'width' => $this->width,
|
||||
'height' => 0,
|
||||
'align' => 'left',
|
||||
'font-size' => 11,
|
||||
'font-family' => 'Verdana, Tahoma, Arial',
|
||||
'font-weight' => 'normal',
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
break;
|
||||
case 'button':
|
||||
$this->label[$name] = array(
|
||||
'type' => 'button',
|
||||
'value' => $value,
|
||||
'action' => '',
|
||||
'target' => 'self',
|
||||
'left' => 5,
|
||||
'top' => 5,
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'align' => 'center',
|
||||
'font-size' => 11,
|
||||
'font-family' => 'Verdana, Tahoma, Arial',
|
||||
'font-weight' => 'normal',
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
break;
|
||||
case 'step':
|
||||
$this->label[$name] = array(
|
||||
'type' => 'step',
|
||||
'value' => $value,
|
||||
'left' => $this->left + 5,
|
||||
'top' => $this->top + 5,
|
||||
'width' => 10,
|
||||
'height' => 0,
|
||||
'align' => 'right',
|
||||
'font-size' => 11,
|
||||
'font-family' => 'Verdana, Tahoma, Arial',
|
||||
'font-weight' => 'normal',
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
break;
|
||||
case 'percentlbl':
|
||||
case 'percent':
|
||||
// check font size
|
||||
if ($this->height <= 11) {
|
||||
$font_size = $this->height - 1;
|
||||
} else {
|
||||
$font_size = 11;
|
||||
}
|
||||
$this->label[$name] = array(
|
||||
'type' => $type, // either percent or percentlbl
|
||||
'value' => $value,
|
||||
'left' => false,
|
||||
'top' => round(($this->height - $font_size) / log($this->height - $font_size, 7), 0) - $this->pedding,
|
||||
'width' => $this->width,
|
||||
'height' => 0,
|
||||
'align' => 'center',
|
||||
'font-size' => $font_size,
|
||||
'font-family' => 'sans-serif',
|
||||
'font-weight' => 'normal',
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
// print "THIS[$name]: ".$this->label[$name]['left']." | ".$this->label[$name]['width']."<br>";
|
||||
break;
|
||||
case 'crossbar':
|
||||
$this->label[$name] = array(
|
||||
'type' => 'crossbar',
|
||||
'value' => $value,
|
||||
'left' => $this->left + ($this->width / 2),
|
||||
'top' => $this->top - 16,
|
||||
'width' => 10,
|
||||
'height' => 0,
|
||||
'align' => 'center',
|
||||
'font-size' => 11,
|
||||
'font-family' => 'Verdana, Tahoma, Arial',
|
||||
'font-weight' => 'normal',
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function addButton($name, $value, $action, $target = 'self')
|
||||
{
|
||||
$this->addLabel('button', $name, $value);
|
||||
$this->label[$name]['action'] = $action;
|
||||
$this->label[$name]['target'] = $target;
|
||||
}
|
||||
|
||||
public function setLabelPosition($name, $left, $top, $width, $height, $align = '')
|
||||
{
|
||||
// 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) {
|
||||
$this->label[$name][$pos_name] = intval($$pos_name);
|
||||
}
|
||||
}
|
||||
|
||||
if ($align != '') {
|
||||
$this->label[$name]['align'] = $align;
|
||||
}
|
||||
}
|
||||
// init
|
||||
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";';
|
||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.width="'.$this->label[$name]['width'].'px";';
|
||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.height="'.$this->label[$name]['height'].'px";';
|
||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";';
|
||||
$output .= '</script>'."\n";
|
||||
echo $output;
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setLabelColor($name, $color)
|
||||
{
|
||||
$this->label[$name]['color'] = $color;
|
||||
if ($this->status != 'new') {
|
||||
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setLabelBackground($name, $color)
|
||||
{
|
||||
$this->label[$name]['bgr_color'] = $color;
|
||||
if ($this->status != 'new') {
|
||||
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setLabelFont($name, $size, $family = '', $weight = '')
|
||||
{
|
||||
// just in case if it is too small
|
||||
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) {
|
||||
$size = $this->height - 1;
|
||||
}
|
||||
// position the label new if this is 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 != '') {
|
||||
$this->label[$name]['font-family'] = $family;
|
||||
}
|
||||
if ($weight != '') {
|
||||
$this->label[$name]['font-weight'] = $weight;
|
||||
}
|
||||
|
||||
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'].'";';
|
||||
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-weight="'.$this->label[$name]['font-weight'].'";';
|
||||
$output .= '</script>'."\n";
|
||||
echo $output;
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setLabelValue($name, $value)
|
||||
{
|
||||
$this->label[$name]['value'] = $value;
|
||||
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
|
||||
if ($this->status != 'new') {
|
||||
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setBarColor($color)
|
||||
{
|
||||
$this->color = $color;
|
||||
if ($this->status != 'new') {
|
||||
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setBarBackground($color)
|
||||
{
|
||||
$this->bgr_color = $color;
|
||||
if ($this->status != 'new') {
|
||||
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function setBarDirection($direction)
|
||||
{
|
||||
$this->direction = $direction;
|
||||
|
||||
if ($this->status != 'new') {
|
||||
$this->position = $this->__calculatePosition($this->step);
|
||||
|
||||
echo '<script type="text/JavaScript">';
|
||||
echo 'PBposition'.$this->code.'("left",'.$this->position['left'].');';
|
||||
echo 'PBposition'.$this->code.'("top",'.$this->position['top'].');';
|
||||
echo 'PBposition'.$this->code.'("width",'.$this->position['width'].');';
|
||||
echo 'PBposition'.$this->code.'("height",'.$this->position['height'].');';
|
||||
echo '</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function getHtml()
|
||||
{
|
||||
$html = '';
|
||||
$js = '';
|
||||
$html_button = '';
|
||||
|
||||
$this->__setStep($this->step);
|
||||
$this->position = $this->__calculatePosition($this->step);
|
||||
|
||||
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) {
|
||||
$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) {
|
||||
$style_bar .= 'top:'.$this->position['top'].'px;';
|
||||
}
|
||||
if ($this->position['left'] !== false) {
|
||||
$style_bar .= 'left:'.$this->position['left'].'px;';
|
||||
}
|
||||
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) {
|
||||
$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";
|
||||
}
|
||||
|
||||
// temp write the bar here, we add that later, below all the html + progress %
|
||||
$html_bar_top = '<div id="pbrd'.$this->code.'" style="'.$style_brd.($this->frame['show'] == true ? 'margin-left: 2px;margin-bottom:2px;' : '').'">'."\n";
|
||||
$html_bar_top .= '<div id="pbar'.$this->code.'" style="'.$style_bar.'">';
|
||||
// insert single percent there
|
||||
$html_bar_bottom = '</div></div>'."\n";
|
||||
|
||||
$js .= 'function PBposition'.$this->code.'(item,pixel) {'."\n";
|
||||
$js .= ' pixel = parseInt(pixel);'."\n";
|
||||
$js .= ' switch(item) {'."\n";
|
||||
$js .= ' case "left": document.getElementById("pbar'.$this->code.'").style.left=(pixel) + \'px\'; break;'."\n";
|
||||
$js .= ' case "top": document.getElementById("pbar'.$this->code.'").style.top=(pixel) + \'px\'; break;'."\n";
|
||||
$js .= ' case "width": document.getElementById("pbar'.$this->code.'").style.width=(pixel) + \'px\'; break;'."\n";
|
||||
$js .= ' case "height": document.getElementById("pbar'.$this->code.'").style.height=(pixel) + \'px\'; break;'."\n";
|
||||
$js .= ' }'."\n";
|
||||
$js .= '}'."\n";
|
||||
|
||||
// print "DUMP LABEL: <br><pre>".print_r($this->label, 1)."</pre><br>";
|
||||
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) {
|
||||
$style_lbl .= $move_prefix.'-top:'.$data['top'].'px;';
|
||||
}
|
||||
if ($data['left'] !== false) {
|
||||
$style_lbl .= $move_prefix.'-left:'.$data['left'].'px;';
|
||||
}
|
||||
$style_lbl .= 'text-align:'.$data['align'].';';
|
||||
if ($data['width'] > 0) {
|
||||
$style_lbl .= 'width:'.$data['width'].'px;';
|
||||
}
|
||||
if ($data['height'] > 0) {
|
||||
$style_lbl .= 'height:'.$data['height'].'px;';
|
||||
}
|
||||
|
||||
if (array_key_exists('font-size', $data)) {
|
||||
$style_lbl .= 'font-size:'.$data['font-size'].'px;';
|
||||
}
|
||||
if (array_key_exists('font-family', $data)) {
|
||||
$style_lbl .= 'font-family:'.$data['font-family'].';';
|
||||
}
|
||||
if (array_key_exists('font-weight', $data)) {
|
||||
$style_lbl .= 'font-weight:'.$data['font-weight'].';';
|
||||
}
|
||||
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']) {
|
||||
case 'text':
|
||||
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'margin-bottom:2px;">'.$data['value'].'</div>'."\n";
|
||||
break;
|
||||
case 'button':
|
||||
$html_button .= '<div><input id="plbl'.$name.$this->code.'" type="button" value="'.$data['value'].'" style="'.$style_lbl.'margin-bottom:5px;" onclick="'.$data['target'].'.location.href=\''.$data['action'].'\'" /></div>'."\n";
|
||||
break;
|
||||
case 'step':
|
||||
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'">'.$this->step.'</div>'."\n";
|
||||
break;
|
||||
case 'percent':
|
||||
// only one inner percent
|
||||
// print "STYLE[$name]: ".$style_lbl."<br>";
|
||||
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";
|
||||
break;
|
||||
case 'crossbar':
|
||||
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'">'.$data['value'].'</div>'."\n";
|
||||
|
||||
$js .= 'function PBrotaryCross'.$name.$this->code.'() {'."\n";
|
||||
$js .= ' cross = document.getElementById("plbl'.$name.$this->code.'").firstChild.nodeValue;'."\n";
|
||||
$js .= ' switch(cross) {'."\n";
|
||||
$js .= ' case "--": cross = "\\\\"; break;'."\n";
|
||||
$js .= ' case "\\\\": cross = "|"; break;'."\n";
|
||||
$js .= ' case "|": cross = "/"; break;'."\n";
|
||||
$js .= ' default: cross = "--"; break;'."\n";
|
||||
$js .= ' }'."\n";
|
||||
$js .= ' document.getElementById("plbl'.$name.$this->code.'").firstChild.nodeValue = cross;'."\n";
|
||||
$js .= '}'."\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write the progress bar + inner percent inside
|
||||
$html .= $html_bar_top;
|
||||
$html .= $html_percent;
|
||||
$html .= $html_bar_bottom;
|
||||
$html .= $html_button; // any buttons on bottom
|
||||
|
||||
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) {
|
||||
$html .= '</div>'."\n";
|
||||
}
|
||||
|
||||
$html .= '<script type="text/JavaScript">'."\n";
|
||||
$html .= $js;
|
||||
$html .= '</script>'."\n";
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$this->status = 'show';
|
||||
echo $this->getHtml();
|
||||
$this->__flushCache();
|
||||
}
|
||||
|
||||
public function moveStep($step)
|
||||
{
|
||||
$last_step = $this->step;
|
||||
$this->__setStep($step);
|
||||
|
||||
$js = '';
|
||||
$new_position = $this->__calculatePosition($this->step);
|
||||
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') {
|
||||
$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']) {
|
||||
case '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)) {
|
||||
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");';
|
||||
}
|
||||
break;
|
||||
case 'crossbar':
|
||||
$js .= 'PBrotaryCross'.$name.$this->code.'();';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($js != '') {
|
||||
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function moveNext()
|
||||
{
|
||||
$this->moveStep($this->step + 1);
|
||||
}
|
||||
|
||||
public function moveMin()
|
||||
{
|
||||
$this->moveStep($this->min);
|
||||
}
|
||||
|
||||
public function hide()
|
||||
{
|
||||
if ($this->status == 'show') {
|
||||
$this->status = 'hide';
|
||||
|
||||
$output = '<script type="text/JavaScript">';
|
||||
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="hidden";document.getElementById("pbm'.$this->code.'").style.display="none";';
|
||||
$output .= '</script>'."\n";
|
||||
echo $output;
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
public function unhide()
|
||||
{
|
||||
if ($this->status == 'hide') {
|
||||
$this->status = 'show';
|
||||
|
||||
$output = '<script type="text/JavaScript">';
|
||||
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="visible";document.getElementById("pbm'.$this->code.'").style.visibility="block";';
|
||||
$output .= '</script>'."\n";
|
||||
echo $output;
|
||||
$this->__flushCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
|
||||
32
www/lib/CoreLibs/Template/SmartyExtend.inc
Normal file
32
www/lib/CoreLibs/Template/SmartyExtend.inc
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2004/12/21
|
||||
* SHORT DESCRIPTION:
|
||||
* extends smarty with the l10n class so I can use __(, etc calls
|
||||
* HISTORY:
|
||||
* 2005/06/22 (cs) include smarty class here, so there is no need to include it in the main file
|
||||
*********************************************************************/
|
||||
|
||||
namespace CoreLibs\Template;
|
||||
|
||||
// I need to manually load Smarty BC here (it is not namespaced)
|
||||
require_once(BASE.LIB.SMARTY.'SmartyBC.class.php');
|
||||
// So it doesn't start looking around in the wrong naemspace as smarty doesn't have one
|
||||
use SmartyBC;
|
||||
|
||||
class SmartyExtend extends SmartyBC
|
||||
{
|
||||
public $l10n;
|
||||
|
||||
// constructor class, just sets the language stuff
|
||||
public function __construct($lang)
|
||||
{
|
||||
SmartyBC::__construct();
|
||||
$this->l10n = new \CoreLibs\Language\L10n($lang);
|
||||
// variable variable register
|
||||
$this->register_modifier('getvar', array(&$this, 'get_template_vars'));
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
31
www/lib/CoreLibs/Upload/Core/qqUploadedFileForm.inc
Executable file
31
www/lib/CoreLibs/Upload/Core/qqUploadedFileForm.inc
Executable file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace CoreLibs\Upload\Core;
|
||||
|
||||
/**
|
||||
* Handle file uploads via regular form post (uses the $_FILES array)
|
||||
*/
|
||||
class qqUploadedFileForm
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
public function save($path)
|
||||
{
|
||||
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
return $_FILES['qqfile']['name'];
|
||||
}
|
||||
public function getSize()
|
||||
{
|
||||
return $_FILES['qqfile']['size'];
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
46
www/lib/CoreLibs/Upload/Core/qqUploadedFileXhr.inc
Executable file
46
www/lib/CoreLibs/Upload/Core/qqUploadedFileXhr.inc
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace CoreLibs\Upload\Core;
|
||||
|
||||
/**
|
||||
* Handle file uploads via XMLHttpRequest
|
||||
*/
|
||||
class qqUploadedFileXhr
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
public function save($path)
|
||||
{
|
||||
$input = fopen("php://input", "r");
|
||||
$temp = tmpfile();
|
||||
$realSize = stream_copy_to_stream($input, $temp);
|
||||
fclose($input);
|
||||
|
||||
if ($realSize != $this->getSize()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$target = fopen($path, "w");
|
||||
fseek($temp, 0, SEEK_SET);
|
||||
stream_copy_to_stream($temp, $target);
|
||||
fclose($target);
|
||||
|
||||
return true;
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
return $_GET['qqfile'];
|
||||
}
|
||||
public function getSize()
|
||||
{
|
||||
if (isset($_SERVER["CONTENT_LENGTH"])) {
|
||||
return (int)$_SERVER["CONTENT_LENGTH"];
|
||||
} else {
|
||||
throw new Exception('Getting content length is not supported.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
112
www/lib/CoreLibs/Upload/qqFileUploader.inc
Executable file
112
www/lib/CoreLibs/Upload/qqFileUploader.inc
Executable file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace CoreLibs\Upload;
|
||||
|
||||
use \CoreLibs\Upload\Core\qqUploadedFileForm;
|
||||
use \CoreLibs\Upload\Core\qqUploadedFileXhr;
|
||||
|
||||
class qqFileUploader
|
||||
{
|
||||
private $allowedExtensions = array();
|
||||
private $sizeLimit = 10485760;
|
||||
private $file;
|
||||
|
||||
public function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760)
|
||||
{
|
||||
$allowedExtensions = array_map("strtolower", $allowedExtensions);
|
||||
|
||||
$this->allowedExtensions = $allowedExtensions;
|
||||
$this->sizeLimit = $sizeLimit;
|
||||
|
||||
$this->checkServerSettings();
|
||||
|
||||
if (isset($_GET['qqfile'])) {
|
||||
$this->file = new qqUploadedFileXhr();
|
||||
} elseif (isset($_FILES['qqfile'])) {
|
||||
$this->file = new qqUploadedFileForm();
|
||||
} else {
|
||||
$this->file = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkServerSettings()
|
||||
{
|
||||
$postSize = $this->toBytes(ini_get('post_max_size'));
|
||||
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
|
||||
|
||||
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
|
||||
$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
|
||||
die("{'error':'increase post_max_size and upload_max_filesize to $size'}");
|
||||
}
|
||||
}
|
||||
|
||||
private function toBytes($str)
|
||||
{
|
||||
$val = trim($str);
|
||||
$last = strtolower($str[strlen($str)-1]);
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$val *= 1024;
|
||||
// no break
|
||||
case 'm':
|
||||
$val *= 1024;
|
||||
// no break
|
||||
case 'k':
|
||||
$val *= 1024;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array('success'=>true) or array('error'=>'error message')
|
||||
*/
|
||||
public function handleUpload($uploadDirectory, $replaceOldFile = false)
|
||||
{
|
||||
if (!is_writable($uploadDirectory)) {
|
||||
return array('error' => "Server error. Upload directory isn't writable.");
|
||||
}
|
||||
|
||||
if (!$this->file) {
|
||||
return array('error' => 'No files were uploaded.');
|
||||
}
|
||||
|
||||
$size = $this->file->getSize();
|
||||
|
||||
if ($size == 0) {
|
||||
return array('error' => 'File is empty');
|
||||
}
|
||||
|
||||
if ($size > $this->sizeLimit) {
|
||||
return array('error' => 'File is too large');
|
||||
}
|
||||
|
||||
$pathinfo = pathinfo($this->file->getName());
|
||||
$filename = $pathinfo['filename'];
|
||||
//$filename = md5(uniqid());
|
||||
$ext = $pathinfo['extension'];
|
||||
|
||||
if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
|
||||
$these = implode(', ', $this->allowedExtensions);
|
||||
return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
|
||||
}
|
||||
|
||||
if (!$replaceOldFile) {
|
||||
/// don't overwrite previous files that were uploaded
|
||||
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
|
||||
$filename .= rand(10, 99);
|
||||
}
|
||||
}
|
||||
|
||||
$this->uploadFileName = $uploadDirectory . $filename . '.' . $ext;
|
||||
$this->uploadFileExt = $ext;
|
||||
|
||||
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
|
||||
return array('success'=>true);
|
||||
} else {
|
||||
return array('error'=> 'Could not save uploaded file.' .
|
||||
'The upload was cancelled, or server error encountered');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# __END__
|
||||
Reference in New Issue
Block a user