selectQueryBuild($K,$Z,$pd,$Cf,$z,$D);if(!$F)$F="SELECT".limit(($_GET["page"]!="last"&&$z!=""&&$pd&&$ae&&$x=="sql"?"SQL_CALC_FOUND_ROWS ":"").implode(", ",$K)."\nFROM ".table($Q),($Z?"\nWHERE ".implode(" AND ",$Z):"").($pd&&$ae?"\nGROUP BY ".implode(", ",$pd):"").($Cf?"\nORDER BY ".implode(", ",$Cf):""),($z!=""?+$z:null),($D?$z*$D:0),"\n");$Gh=microtime(true);$H=$this->_conn->query($F);if($pg)echo$b->selectQuery($F,$Gh,!$H);return$H;}function
+delete($Q,$zg,$z=0){$F="FROM ".table($Q);return
+queries("DELETE".($z?limit1($Q,$F,$zg):" $F$zg"));}function
+update($Q,$N,$zg,$z=0,$L="\n"){$Yi=array();foreach($N
+as$y=>$X)$Yi[]="$y = $X";$F=table($Q)." SET$L".implode(",$L",$Yi);return
+queries("UPDATE".($z?limit1($Q,$F,$zg,$L):" $F$zg"));}function
+insert($Q,$N){return
+queries("INSERT INTO ".table($Q).($N?" (".implode(", ",array_keys($N)).")\nVALUES (".implode(", ",$N).")":" DEFAULT VALUES"));}function
+insertUpdate($Q,$J,$ng){return
+false;}function
+begin(){return
+queries("BEGIN");}function
+commit(){return
+queries("COMMIT");}function
+rollback(){return
+queries("ROLLBACK");}function
+slowQuery($F,$ii){}function
+convertSearch($u,$X,$o){return$u;}function
+value($X,$o){return(method_exists($this->_conn,'value')?$this->_conn->value($X,$o):(is_resource($X)?stream_get_contents($X):$X));}function
+quoteBinary($bh){return
+q($bh);}function
+warnings(){return'';}function
+tableHelp($B){}}$gc["sqlite"]="SQLite 3";$gc["sqlite2"]="SQLite 2";if(isset($_GET["sqlite"])||isset($_GET["sqlite2"])){$kg=array((isset($_GET["sqlite"])?"SQLite3":"SQLite"),"PDO_SQLite");define("DRIVER",(isset($_GET["sqlite"])?"sqlite":"sqlite2"));if(class_exists(isset($_GET["sqlite"])?"SQLite3":"SQLiteDatabase")){if(isset($_GET["sqlite"])){class
+Min_SQLite{var$extension="SQLite3",$server_info,$affected_rows,$errno,$error,$_link;function
+__construct($Wc){$this->_link=new
+SQLite3($Wc);$bj=$this->_link->version();$this->server_info=$bj["versionString"];}function
+query($F){$G=@$this->_link->query($F);$this->error="";if(!$G){$this->errno=$this->_link->lastErrorCode();$this->error=$this->_link->lastErrorMsg();return
+false;}elseif($G->numColumns())return
+new
+Min_Result($G);$this->affected_rows=$this->_link->changes();return
+true;}function
+quote($P){return(is_utf8($P)?"'".$this->_link->escapeString($P)."'":"x'".reset(unpack('H*',$P))."'");}function
+store_result(){return$this->_result;}function
+result($F,$o=0){$G=$this->query($F);if(!is_object($G))return
+false;$I=$G->_result->fetchArray();return$I[$o];}}class
+Min_Result{var$_result,$_offset=0,$num_rows;function
+__construct($G){$this->_result=$G;}function
+fetch_assoc(){return$this->_result->fetchArray(SQLITE3_ASSOC);}function
+fetch_row(){return$this->_result->fetchArray(SQLITE3_NUM);}function
+fetch_field(){$e=$this->_offset++;$T=$this->_result->columnType($e);return(object)array("name"=>$this->_result->columnName($e),"type"=>$T,"charsetnr"=>($T==SQLITE3_BLOB?63:0),);}function
+__desctruct(){return$this->_result->finalize();}}}else{class
+Min_SQLite{var$extension="SQLite",$server_info,$affected_rows,$error,$_link;function
+__construct($Wc){$this->server_info=sqlite_libversion();$this->_link=new
+SQLiteDatabase($Wc);}function
+query($F,$Fi=false){$Ue=($Fi?"unbufferedQuery":"query");$G=@$this->_link->$Ue($F,SQLITE_BOTH,$n);$this->error="";if(!$G){$this->error=$n;return
+false;}elseif($G===true){$this->affected_rows=$this->changes();return
+true;}return
+new
+Min_Result($G);}function
+quote($P){return"'".sqlite_escape_string($P)."'";}function
+store_result(){return$this->_result;}function
+result($F,$o=0){$G=$this->query($F);if(!is_object($G))return
+false;$I=$G->_result->fetch();return$I[$o];}}class
+Min_Result{var$_result,$_offset=0,$num_rows;function
+__construct($G){$this->_result=$G;if(method_exists($G,'numRows'))$this->num_rows=$G->numRows();}function
+fetch_assoc(){$I=$this->_result->fetch(SQLITE_ASSOC);if(!$I)return
+false;$H=array();foreach($I
+as$y=>$X)$H[($y[0]=='"'?idf_unescape($y):$y)]=$X;return$H;}function
+fetch_row(){return$this->_result->fetch(SQLITE_NUM);}function
+fetch_field(){$B=$this->_result->fieldName($this->_offset++);$dg='(\[.*]|"(?:[^"]|"")*"|(.+))';if(preg_match("~^($dg\\.)?$dg\$~",$B,$A)){$Q=($A[3]!=""?$A[3]:idf_unescape($A[2]));$B=($A[5]!=""?$A[5]:idf_unescape($A[4]));}return(object)array("name"=>$B,"orgname"=>$B,"orgtable"=>$Q,);}}}}elseif(extension_loaded("pdo_sqlite")){class
+Min_SQLite
+extends
+Min_PDO{var$extension="PDO_SQLite";function
+__construct($Wc){$this->dsn(DRIVER.":$Wc","","");}}}if(class_exists("Min_SQLite")){class
+Min_DB
+extends
+Min_SQLite{function
+__construct(){parent::__construct(":memory:");$this->query("PRAGMA foreign_keys = 1");}function
+select_db($Wc){if(is_readable($Wc)&&$this->query("ATTACH ".$this->quote(preg_match("~(^[/\\\\]|:)~",$Wc)?$Wc:dirname($_SERVER["SCRIPT_FILENAME"])."/$Wc")." AS a")){parent::__construct($Wc);$this->query("PRAGMA foreign_keys = 1");return
+true;}return
+false;}function
+multi_query($F){return$this->_result=$this->query($F);}function
+next_result(){return
+false;}}}class
+Min_Driver
+extends
+Min_SQL{function
+insertUpdate($Q,$J,$ng){$Yi=array();foreach($J
+as$N)$Yi[]="(".implode(", ",$N).")";return
+queries("REPLACE INTO ".table($Q)." (".implode(", ",array_keys(reset($J))).") VALUES\n".implode(",\n",$Yi));}function
+tableHelp($B){if($B=="sqlite_sequence")return"fileformat2.html#seqtab";if($B=="sqlite_master")return"fileformat2.html#$B";}}function
+idf_escape($u){return'"'.str_replace('"','""',$u).'"';}function
+table($u){return
+idf_escape($u);}function
+connect(){global$b;list(,,$E)=$b->credentials();if($E!="")return
+lang(22);return
+new
+Min_DB;}function
+get_databases(){return
+array();}function
+limit($F,$Z,$z,$C=0,$L=" "){return" $F$Z".($z!==null?$L."LIMIT $z".($C?" OFFSET $C":""):"");}function
+limit1($Q,$F,$Z,$L="\n"){global$h;return(preg_match('~^INTO~',$F)||$h->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')")?limit($F,$Z,1,0,$L):" $F WHERE rowid = (SELECT rowid FROM ".table($Q).$Z.$L."LIMIT 1)");}function
+db_collation($l,$qb){global$h;return$h->result("PRAGMA encoding");}function
+engines(){return
+array();}function
+logged_user(){return
+get_current_user();}function
+tables_list(){return
+get_key_vals("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') ORDER BY (name = 'sqlite_sequence'), name");}function
+count_tables($k){return
+array();}function
+table_status($B=""){global$h;$H=array();foreach(get_rows("SELECT name AS Name, type AS Engine, 'rowid' AS Oid, '' AS Auto_increment FROM sqlite_master WHERE type IN ('table', 'view') ".($B!=""?"AND name = ".q($B):"ORDER BY name"))as$I){$I["Rows"]=$h->result("SELECT COUNT(*) FROM ".idf_escape($I["Name"]));$H[$I["Name"]]=$I;}foreach(get_rows("SELECT * FROM sqlite_sequence",null,"")as$I)$H[$I["name"]]["Auto_increment"]=$I["seq"];return($B!=""?$H[$B]:$H);}function
+is_view($R){return$R["Engine"]=="view";}function
+fk_support($R){global$h;return!$h->result("SELECT sqlite_compileoption_used('OMIT_FOREIGN_KEY')");}function
+fields($Q){global$h;$H=array();$ng="";foreach(get_rows("PRAGMA table_info(".table($Q).")")as$I){$B=$I["name"];$T=strtolower($I["type"]);$Vb=$I["dflt_value"];$H[$B]=array("field"=>$B,"type"=>(preg_match('~int~i',$T)?"integer":(preg_match('~char|clob|text~i',$T)?"text":(preg_match('~blob~i',$T)?"blob":(preg_match('~real|floa|doub~i',$T)?"real":"numeric")))),"full_type"=>$T,"default"=>(preg_match("~'(.*)'~",$Vb,$A)?str_replace("''","'",$A[1]):($Vb=="NULL"?null:$Vb)),"null"=>!$I["notnull"],"privileges"=>array("select"=>1,"insert"=>1,"update"=>1),"primary"=>$I["pk"],);if($I["pk"]){if($ng!="")$H[$ng]["auto_increment"]=false;elseif(preg_match('~^integer$~i',$T))$H[$B]["auto_increment"]=true;$ng=$B;}}$Bh=$h->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ".q($Q));preg_match_all('~(("[^"]*+")+|[a-z0-9_]+)\s+text\s+COLLATE\s+(\'[^\']+\'|\S+)~i',$Bh,$Ge,PREG_SET_ORDER);foreach($Ge
+as$A){$B=str_replace('""','"',preg_replace('~^"|"$~','',$A[1]));if($H[$B])$H[$B]["collation"]=trim($A[3],"'");}return$H;}function
+indexes($Q,$i=null){global$h;if(!is_object($i))$i=$h;$H=array();$Bh=$i->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ".q($Q));if(preg_match('~\bPRIMARY\s+KEY\s*\((([^)"]+|"[^"]*"|`[^`]*`)++)~i',$Bh,$A)){$H[""]=array("type"=>"PRIMARY","columns"=>array(),"lengths"=>array(),"descs"=>array());preg_match_all('~((("[^"]*+")+|(?:`[^`]*+`)+)|(\S+))(\s+(ASC|DESC))?(,\s*|$)~i',$A[1],$Ge,PREG_SET_ORDER);foreach($Ge
+as$A){$H[""]["columns"][]=idf_unescape($A[2]).$A[4];$H[""]["descs"][]=(preg_match('~DESC~i',$A[5])?'1':null);}}if(!$H){foreach(fields($Q)as$B=>$o){if($o["primary"])$H[""]=array("type"=>"PRIMARY","columns"=>array($B),"lengths"=>array(),"descs"=>array(null));}}$Eh=get_key_vals("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ".q($Q),$i);foreach(get_rows("PRAGMA index_list(".table($Q).")",$i)as$I){$B=$I["name"];$v=array("type"=>($I["unique"]?"UNIQUE":"INDEX"));$v["lengths"]=array();$v["descs"]=array();foreach(get_rows("PRAGMA index_info(".idf_escape($B).")",$i)as$ah){$v["columns"][]=$ah["name"];$v["descs"][]=null;}if(preg_match('~^CREATE( UNIQUE)? INDEX '.preg_quote(idf_escape($B).' ON '.idf_escape($Q),'~').' \((.*)\)$~i',$Eh[$B],$Kg)){preg_match_all('/("[^"]*+")+( DESC)?/',$Kg[2],$Ge);foreach($Ge[2]as$y=>$X){if($X)$v["descs"][$y]='1';}}if(!$H[""]||$v["type"]!="UNIQUE"||$v["columns"]!=$H[""]["columns"]||$v["descs"]!=$H[""]["descs"]||!preg_match("~^sqlite_~",$B))$H[$B]=$v;}return$H;}function
+foreign_keys($Q){$H=array();foreach(get_rows("PRAGMA foreign_key_list(".table($Q).")")as$I){$q=&$H[$I["id"]];if(!$q)$q=$I;$q["source"][]=$I["from"];$q["target"][]=$I["to"];}return$H;}function
+view($B){global$h;return
+array("select"=>preg_replace('~^(?:[^`"[]+|`[^`]*`|"[^"]*")* AS\s+~iU','',$h->result("SELECT sql FROM sqlite_master WHERE name = ".q($B))));}function
+collations(){return(isset($_GET["create"])?get_vals("PRAGMA collation_list",1):array());}function
+information_schema($l){return
+false;}function
+error(){global$h;return
+h($h->error);}function
+check_sqlite_name($B){global$h;$Mc="db|sdb|sqlite";if(!preg_match("~^[^\\0]*\\.($Mc)\$~",$B)){$h->error=lang(23,str_replace("|",", ",$Mc));return
+false;}return
+true;}function
+create_database($l,$d){global$h;if(file_exists($l)){$h->error=lang(24);return
+false;}if(!check_sqlite_name($l))return
+false;try{$_=new
+Min_SQLite($l);}catch(Exception$Cc){$h->error=$Cc->getMessage();return
+false;}$_->query('PRAGMA encoding = "UTF-8"');$_->query('CREATE TABLE adminer (i)');$_->query('DROP TABLE adminer');return
+true;}function
+drop_databases($k){global$h;$h->__construct(":memory:");foreach($k
+as$l){if(!@unlink($l)){$h->error=lang(24);return
+false;}}return
+true;}function
+rename_database($B,$d){global$h;if(!check_sqlite_name($B))return
+false;$h->__construct(":memory:");$h->error=lang(24);return@rename(DB,$B);}function
+auto_increment(){return" PRIMARY KEY".(DRIVER=="sqlite"?" AUTOINCREMENT":"");}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){global$h;$Ri=($Q==""||$ed);foreach($p
+as$o){if($o[0]!=""||!$o[1]||$o[2]){$Ri=true;break;}}$c=array();$Lf=array();foreach($p
+as$o){if($o[1]){$c[]=($Ri?$o[1]:"ADD ".implode($o[1]));if($o[0]!="")$Lf[$o[0]]=$o[1][0];}}if(!$Ri){foreach($c
+as$X){if(!queries("ALTER TABLE ".table($Q)." $X"))return
+false;}if($Q!=$B&&!queries("ALTER TABLE ".table($Q)." RENAME TO ".table($B)))return
+false;}elseif(!recreate_table($Q,$B,$c,$Lf,$ed,$Na))return
+false;if($Na){queries("BEGIN");queries("UPDATE sqlite_sequence SET seq = $Na WHERE name = ".q($B));if(!$h->affected_rows)queries("INSERT INTO sqlite_sequence (name, seq) VALUES (".q($B).", $Na)");queries("COMMIT");}return
+true;}function
+recreate_table($Q,$B,$p,$Lf,$ed,$Na,$w=array()){global$h;if($Q!=""){if(!$p){foreach(fields($Q)as$y=>$o){if($w)$o["auto_increment"]=0;$p[]=process_field($o,$o);$Lf[$y]=idf_escape($y);}}$og=false;foreach($p
+as$o){if($o[6])$og=true;}$jc=array();foreach($w
+as$y=>$X){if($X[2]=="DROP"){$jc[$X[1]]=true;unset($w[$y]);}}foreach(indexes($Q)as$ie=>$v){$f=array();foreach($v["columns"]as$y=>$e){if(!$Lf[$e])continue
+2;$f[]=$Lf[$e].($v["descs"][$y]?" DESC":"");}if(!$jc[$ie]){if($v["type"]!="PRIMARY"||!$og)$w[]=array($v["type"],$ie,$f);}}foreach($w
+as$y=>$X){if($X[0]=="PRIMARY"){unset($w[$y]);$ed[]=" PRIMARY KEY (".implode(", ",$X[2]).")";}}foreach(foreign_keys($Q)as$ie=>$q){foreach($q["source"]as$y=>$e){if(!$Lf[$e])continue
+2;$q["source"][$y]=idf_unescape($Lf[$e]);}if(!isset($ed[" $ie"]))$ed[]=" ".format_foreign_key($q);}queries("BEGIN");}foreach($p
+as$y=>$o)$p[$y]=" ".implode($o);$p=array_merge($p,array_filter($ed));$ci=($Q==$B?"adminer_$B":$B);if(!queries("CREATE TABLE ".table($ci)." (\n".implode(",\n",$p)."\n)"))return
+false;if($Q!=""){if($Lf&&!queries("INSERT INTO ".table($ci)." (".implode(", ",$Lf).") SELECT ".implode(", ",array_map('idf_escape',array_keys($Lf)))." FROM ".table($Q)))return
+false;$Ci=array();foreach(triggers($Q)as$Ai=>$ji){$_i=trigger($Ai);$Ci[]="CREATE TRIGGER ".idf_escape($Ai)." ".implode(" ",$ji)." ON ".table($B)."\n$_i[Statement]";}$Na=$Na?0:$h->result("SELECT seq FROM sqlite_sequence WHERE name = ".q($Q));if(!queries("DROP TABLE ".table($Q))||($Q==$B&&!queries("ALTER TABLE ".table($ci)." RENAME TO ".table($B)))||!alter_indexes($B,$w))return
+false;if($Na)queries("UPDATE sqlite_sequence SET seq = $Na WHERE name = ".q($B));foreach($Ci
+as$_i){if(!queries($_i))return
+false;}queries("COMMIT");}return
+true;}function
+index_sql($Q,$T,$B,$f){return"CREATE $T ".($T!="INDEX"?"INDEX ":"").idf_escape($B!=""?$B:uniqid($Q."_"))." ON ".table($Q)." $f";}function
+alter_indexes($Q,$c){foreach($c
+as$ng){if($ng[0]=="PRIMARY")return
+recreate_table($Q,$Q,array(),array(),array(),0,$c);}foreach(array_reverse($c)as$X){if(!queries($X[2]=="DROP"?"DROP INDEX ".idf_escape($X[1]):index_sql($Q,$X[0],$X[1],"(".implode(", ",$X[2]).")")))return
+false;}return
+true;}function
+truncate_tables($S){return
+apply_queries("DELETE FROM",$S);}function
+drop_views($dj){return
+apply_queries("DROP VIEW",$dj);}function
+drop_tables($S){return
+apply_queries("DROP TABLE",$S);}function
+move_tables($S,$dj,$ai){return
+false;}function
+trigger($B){global$h;if($B=="")return
+array("Statement"=>"BEGIN\n\t;\nEND");$u='(?:[^`"\s]+|`[^`]*`|"[^"]*")+';$Bi=trigger_options();preg_match("~^CREATE\\s+TRIGGER\\s*$u\\s*(".implode("|",$Bi["Timing"]).")\\s+([a-z]+)(?:\\s+OF\\s+($u))?\\s+ON\\s*$u\\s*(?:FOR\\s+EACH\\s+ROW\\s)?(.*)~is",$h->result("SELECT sql FROM sqlite_master WHERE type = 'trigger' AND name = ".q($B)),$A);$mf=$A[3];return
+array("Timing"=>strtoupper($A[1]),"Event"=>strtoupper($A[2]).($mf?" OF":""),"Of"=>($mf[0]=='`'||$mf[0]=='"'?idf_unescape($mf):$mf),"Trigger"=>$B,"Statement"=>$A[4],);}function
+triggers($Q){$H=array();$Bi=trigger_options();foreach(get_rows("SELECT * FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ".q($Q))as$I){preg_match('~^CREATE\s+TRIGGER\s*(?:[^`"\s]+|`[^`]*`|"[^"]*")+\s*('.implode("|",$Bi["Timing"]).')\s*(.*?)\s+ON\b~i',$I["sql"],$A);$H[$I["name"]]=array($A[1],$A[2]);}return$H;}function
+trigger_options(){return
+array("Timing"=>array("BEFORE","AFTER","INSTEAD OF"),"Event"=>array("INSERT","UPDATE","UPDATE OF","DELETE"),"Type"=>array("FOR EACH ROW"),);}function
+begin(){return
+queries("BEGIN");}function
+last_id(){global$h;return$h->result("SELECT LAST_INSERT_ROWID()");}function
+explain($h,$F){return$h->query("EXPLAIN QUERY PLAN $F");}function
+found_rows($R,$Z){}function
+types(){return
+array();}function
+schemas(){return
+array();}function
+get_schema(){return"";}function
+set_schema($eh){return
+true;}function
+create_sql($Q,$Na,$Lh){global$h;$H=$h->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = ".q($Q));foreach(indexes($Q)as$B=>$v){if($B=='')continue;$H.=";\n\n".index_sql($Q,$v['type'],$B,"(".implode(", ",array_map('idf_escape',$v['columns'])).")");}return$H;}function
+truncate_sql($Q){return"DELETE FROM ".table($Q);}function
+use_sql($j){}function
+trigger_sql($Q){return
+implode(get_vals("SELECT sql || ';;\n' FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ".q($Q)));}function
+show_variables(){global$h;$H=array();foreach(array("auto_vacuum","cache_size","count_changes","default_cache_size","empty_result_callbacks","encoding","foreign_keys","full_column_names","fullfsync","journal_mode","journal_size_limit","legacy_file_format","locking_mode","page_size","max_page_count","read_uncommitted","recursive_triggers","reverse_unordered_selects","secure_delete","short_column_names","synchronous","temp_store","temp_store_directory","schema_version","integrity_check","quick_check")as$y)$H[$y]=$h->result("PRAGMA $y");return$H;}function
+show_status(){$H=array();foreach(get_vals("PRAGMA compile_options")as$_f){list($y,$X)=explode("=",$_f,2);$H[$y]=$X;}return$H;}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+support($Rc){return
+preg_match('~^(columns|database|drop_col|dump|indexes|descidx|move_col|sql|status|table|trigger|variables|view|view_trigger)$~',$Rc);}$x="sqlite";$U=array("integer"=>0,"real"=>0,"numeric"=>0,"text"=>0,"blob"=>0);$Kh=array_keys($U);$Li=array();$yf=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL","SQL");$md=array("hex","length","lower","round","unixepoch","upper");$sd=array("avg","count","count distinct","group_concat","max","min","sum");$oc=array(array(),array("integer|real|numeric"=>"+/-","text"=>"||",));}$gc["pgsql"]="PostgreSQL";if(isset($_GET["pgsql"])){$kg=array("PgSQL","PDO_PgSQL");define("DRIVER","pgsql");if(extension_loaded("pgsql")){class
+Min_DB{var$extension="PgSQL",$_link,$_result,$_string,$_database=true,$server_info,$affected_rows,$error,$timeout;function
+_error($zc,$n){if(ini_bool("html_errors"))$n=html_entity_decode(strip_tags($n));$n=preg_replace('~^[^:]*: ~','',$n);$this->error=$n;}function
+connect($M,$V,$E){global$b;$l=$b->database();set_error_handler(array($this,'_error'));$this->_string="host='".str_replace(":","' port='",addcslashes($M,"'\\"))."' user='".addcslashes($V,"'\\")."' password='".addcslashes($E,"'\\")."'";$this->_link=@pg_connect("$this->_string dbname='".($l!=""?addcslashes($l,"'\\"):"postgres")."'",PGSQL_CONNECT_FORCE_NEW);if(!$this->_link&&$l!=""){$this->_database=false;$this->_link=@pg_connect("$this->_string dbname='postgres'",PGSQL_CONNECT_FORCE_NEW);}restore_error_handler();if($this->_link){$bj=pg_version($this->_link);$this->server_info=$bj["server"];pg_set_client_encoding($this->_link,"UTF8");}return(bool)$this->_link;}function
+quote($P){return"'".pg_escape_string($this->_link,$P)."'";}function
+value($X,$o){return($o["type"]=="bytea"?pg_unescape_bytea($X):$X);}function
+quoteBinary($P){return"'".pg_escape_bytea($this->_link,$P)."'";}function
+select_db($j){global$b;if($j==$b->database())return$this->_database;$H=@pg_connect("$this->_string dbname='".addcslashes($j,"'\\")."'",PGSQL_CONNECT_FORCE_NEW);if($H)$this->_link=$H;return$H;}function
+close(){$this->_link=@pg_connect("$this->_string dbname='postgres'");}function
+query($F,$Fi=false){$G=@pg_query($this->_link,$F);$this->error="";if(!$G){$this->error=pg_last_error($this->_link);$H=false;}elseif(!pg_num_fields($G)){$this->affected_rows=pg_affected_rows($G);$H=true;}else$H=new
+Min_Result($G);if($this->timeout){$this->timeout=0;$this->query("RESET statement_timeout");}return$H;}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+result($F,$o=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
+false;return
+pg_fetch_result($G->_result,0,$o);}function
+warnings(){return
+h(pg_last_notice($this->_link));}}class
+Min_Result{var$_result,$_offset=0,$num_rows;function
+__construct($G){$this->_result=$G;$this->num_rows=pg_num_rows($G);}function
+fetch_assoc(){return
+pg_fetch_assoc($this->_result);}function
+fetch_row(){return
+pg_fetch_row($this->_result);}function
+fetch_field(){$e=$this->_offset++;$H=new
+stdClass;if(function_exists('pg_field_table'))$H->orgtable=pg_field_table($this->_result,$e);$H->name=pg_field_name($this->_result,$e);$H->orgname=$H->name;$H->type=pg_field_type($this->_result,$e);$H->charsetnr=($H->type=="bytea"?63:0);return$H;}function
+__destruct(){pg_free_result($this->_result);}}}elseif(extension_loaded("pdo_pgsql")){class
+Min_DB
+extends
+Min_PDO{var$extension="PDO_PgSQL",$timeout;function
+connect($M,$V,$E){global$b;$l=$b->database();$P="pgsql:host='".str_replace(":","' port='",addcslashes($M,"'\\"))."' options='-c client_encoding=utf8'";$this->dsn("$P dbname='".($l!=""?addcslashes($l,"'\\"):"postgres")."'",$V,$E);return
+true;}function
+select_db($j){global$b;return($b->database()==$j);}function
+quoteBinary($bh){return
+q($bh);}function
+query($F,$Fi=false){$H=parent::query($F,$Fi);if($this->timeout){$this->timeout=0;parent::query("RESET statement_timeout");}return$H;}function
+warnings(){return'';}function
+close(){}}}class
+Min_Driver
+extends
+Min_SQL{function
+insertUpdate($Q,$J,$ng){global$h;foreach($J
+as$N){$Mi=array();$Z=array();foreach($N
+as$y=>$X){$Mi[]="$y = $X";if(isset($ng[idf_unescape($y)]))$Z[]="$y = $X";}if(!(($Z&&queries("UPDATE ".table($Q)." SET ".implode(", ",$Mi)." WHERE ".implode(" AND ",$Z))&&$h->affected_rows)||queries("INSERT INTO ".table($Q)." (".implode(", ",array_keys($N)).") VALUES (".implode(", ",$N).")")))return
+false;}return
+true;}function
+slowQuery($F,$ii){$this->_conn->query("SET statement_timeout = ".(1000*$ii));$this->_conn->timeout=1000*$ii;return$F;}function
+convertSearch($u,$X,$o){return(preg_match('~char|text'.(!preg_match('~LIKE~',$X["op"])?'|date|time(stamp)?|boolean|uuid|'.number_type():'').'~',$o["type"])?$u:"CAST($u AS text)");}function
+quoteBinary($bh){return$this->_conn->quoteBinary($bh);}function
+warnings(){return$this->_conn->warnings();}function
+tableHelp($B){$ze=array("information_schema"=>"infoschema","pg_catalog"=>"catalog",);$_=$ze[$_GET["ns"]];if($_)return"$_-".str_replace("_","-",$B).".html";}}function
+idf_escape($u){return'"'.str_replace('"','""',$u).'"';}function
+table($u){return
+idf_escape($u);}function
+connect(){global$b,$U,$Kh;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2])){if(min_version(9,0,$h)){$h->query("SET application_name = 'Adminer'");if(min_version(9.2,0,$h)){$Kh[lang(25)][]="json";$U["json"]=4294967295;if(min_version(9.4,0,$h)){$Kh[lang(25)][]="jsonb";$U["jsonb"]=4294967295;}}}return$h;}return$h->error;}function
+get_databases(){return
+get_vals("SELECT datname FROM pg_database WHERE has_database_privilege(datname, 'CONNECT') ORDER BY datname");}function
+limit($F,$Z,$z,$C=0,$L=" "){return" $F$Z".($z!==null?$L."LIMIT $z".($C?" OFFSET $C":""):"");}function
+limit1($Q,$F,$Z,$L="\n"){return(preg_match('~^INTO~',$F)?limit($F,$Z,1,0,$L):" $F".(is_view(table_status1($Q))?$Z:" WHERE ctid = (SELECT ctid FROM ".table($Q).$Z.$L."LIMIT 1)"));}function
+db_collation($l,$qb){global$h;return$h->result("SHOW LC_COLLATE");}function
+engines(){return
+array();}function
+logged_user(){global$h;return$h->result("SELECT user");}function
+tables_list(){$F="SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema()";if(support('materializedview'))$F.="
+UNION ALL
+SELECT matviewname, 'MATERIALIZED VIEW'
+FROM pg_matviews
+WHERE schemaname = current_schema()";$F.="
+ORDER BY 1";return
+get_key_vals($F);}function
+count_tables($k){return
+array();}function
+table_status($B=""){$H=array();foreach(get_rows("SELECT c.relname AS \"Name\", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(c.oid) AS \"Data_length\", pg_total_relation_size(c.oid) - pg_relation_size(c.oid) AS \"Index_length\", obj_description(c.oid, 'pg_class') AS \"Comment\", ".(min_version(12)?"''":"CASE WHEN c.relhasoids THEN 'oid' ELSE '' END")." AS \"Oid\", c.reltuples as \"Rows\", n.nspname
+FROM pg_class c
+JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
+WHERE relkind IN ('r', 'm', 'v', 'f')
+".($B!=""?"AND relname = ".q($B):"ORDER BY relname"))as$I)$H[$I["Name"]]=$I;return($B!=""?$H[$B]:$H);}function
+is_view($R){return
+in_array($R["Engine"],array("view","materialized view"));}function
+fk_support($R){return
+true;}function
+fields($Q){$H=array();$Da=array('timestamp without time zone'=>'timestamp','timestamp with time zone'=>'timestamptz',);$Fd=min_version(10)?"(a.attidentity = 'd')::int":'0';foreach(get_rows("SELECT a.attname AS field, format_type(a.atttypid, a.atttypmod) AS full_type, pg_get_expr(d.adbin, d.adrelid) AS default, a.attnotnull::int, col_description(c.oid, a.attnum) AS comment, $Fd AS identity
+FROM pg_class c
+JOIN pg_namespace n ON c.relnamespace = n.oid
+JOIN pg_attribute a ON c.oid = a.attrelid
+LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum
+WHERE c.relname = ".q($Q)."
+AND n.nspname = current_schema()
+AND NOT a.attisdropped
+AND a.attnum > 0
+ORDER BY a.attnum")as$I){preg_match('~([^([]+)(\((.*)\))?([a-z ]+)?((\[[0-9]*])*)$~',$I["full_type"],$A);list(,$T,$we,$I["length"],$xa,$Ga)=$A;$I["length"].=$Ga;$fb=$T.$xa;if(isset($Da[$fb])){$I["type"]=$Da[$fb];$I["full_type"]=$I["type"].$we.$Ga;}else{$I["type"]=$T;$I["full_type"]=$I["type"].$we.$xa.$Ga;}if($I['identity'])$I['default']='GENERATED BY DEFAULT AS IDENTITY';$I["null"]=!$I["attnotnull"];$I["auto_increment"]=$I['identity']||preg_match('~^nextval\(~i',$I["default"]);$I["privileges"]=array("insert"=>1,"select"=>1,"update"=>1);if(preg_match('~(.+)::[^)]+(.*)~',$I["default"],$A))$I["default"]=($A[1]=="NULL"?null:(($A[1][0]=="'"?idf_unescape($A[1]):$A[1]).$A[2]));$H[$I["field"]]=$I;}return$H;}function
+indexes($Q,$i=null){global$h;if(!is_object($i))$i=$h;$H=array();$Th=$i->result("SELECT oid FROM pg_class WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema()) AND relname = ".q($Q));$f=get_key_vals("SELECT attnum, attname FROM pg_attribute WHERE attrelid = $Th AND attnum > 0",$i);foreach(get_rows("SELECT relname, indisunique::int, indisprimary::int, indkey, indoption , (indpred IS NOT NULL)::int as indispartial FROM pg_index i, pg_class ci WHERE i.indrelid = $Th AND ci.oid = i.indexrelid",$i)as$I){$Lg=$I["relname"];$H[$Lg]["type"]=($I["indispartial"]?"INDEX":($I["indisprimary"]?"PRIMARY":($I["indisunique"]?"UNIQUE":"INDEX")));$H[$Lg]["columns"]=array();foreach(explode(" ",$I["indkey"])as$Pd)$H[$Lg]["columns"][]=$f[$Pd];$H[$Lg]["descs"]=array();foreach(explode(" ",$I["indoption"])as$Qd)$H[$Lg]["descs"][]=($Qd&1?'1':null);$H[$Lg]["lengths"]=array();}return$H;}function
+foreign_keys($Q){global$tf;$H=array();foreach(get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition
+FROM pg_constraint
+WHERE conrelid = (SELECT pc.oid FROM pg_class AS pc INNER JOIN pg_namespace AS pn ON (pn.oid = pc.relnamespace) WHERE pc.relname = ".q($Q)." AND pn.nspname = current_schema())
+AND contype = 'f'::char
+ORDER BY conkey, conname")as$I){if(preg_match('~FOREIGN KEY\s*\((.+)\)\s*REFERENCES (.+)\((.+)\)(.*)$~iA',$I['definition'],$A)){$I['source']=array_map('trim',explode(',',$A[1]));if(preg_match('~^(("([^"]|"")+"|[^"]+)\.)?"?("([^"]|"")+"|[^"]+)$~',$A[2],$Fe)){$I['ns']=str_replace('""','"',preg_replace('~^"(.+)"$~','\1',$Fe[2]));$I['table']=str_replace('""','"',preg_replace('~^"(.+)"$~','\1',$Fe[4]));}$I['target']=array_map('trim',explode(',',$A[3]));$I['on_delete']=(preg_match("~ON DELETE ($tf)~",$A[4],$Fe)?$Fe[1]:'NO ACTION');$I['on_update']=(preg_match("~ON UPDATE ($tf)~",$A[4],$Fe)?$Fe[1]:'NO ACTION');$H[$I['conname']]=$I;}}return$H;}function
+view($B){global$h;return
+array("select"=>trim($h->result("SELECT pg_get_viewdef(".$h->result("SELECT oid FROM pg_class WHERE relname = ".q($B)).")")));}function
+collations(){return
+array();}function
+information_schema($l){return($l=="information_schema");}function
+error(){global$h;$H=h($h->error);if(preg_match('~^(.*\n)?([^\n]*)\n( *)\^(\n.*)?$~s',$H,$A))$H=$A[1].preg_replace('~((?:[^&]|&[^;]*;){'.strlen($A[3]).'})(.*)~','\1\2',$A[2]).$A[4];return
+nl_br($H);}function
+create_database($l,$d){return
+queries("CREATE DATABASE ".idf_escape($l).($d?" ENCODING ".idf_escape($d):""));}function
+drop_databases($k){global$h;$h->close();return
+apply_queries("DROP DATABASE",$k,'idf_escape');}function
+rename_database($B,$d){return
+queries("ALTER DATABASE ".idf_escape(DB)." RENAME TO ".idf_escape($B));}function
+auto_increment(){return"";}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){$c=array();$yg=array();if($Q!=""&&$Q!=$B)$yg[]="ALTER TABLE ".table($Q)." RENAME TO ".table($B);foreach($p
+as$o){$e=idf_escape($o[0]);$X=$o[1];if(!$X)$c[]="DROP $e";else{$Xi=$X[5];unset($X[5]);if(isset($X[6])&&$o[0]=="")$X[1]=($X[1]=="bigint"?" big":" ")."serial";if($o[0]=="")$c[]=($Q!=""?"ADD ":" ").implode($X);else{if($e!=$X[0])$yg[]="ALTER TABLE ".table($B)." RENAME $e TO $X[0]";$c[]="ALTER $e TYPE$X[1]";if(!$X[6]){$c[]="ALTER $e ".($X[3]?"SET$X[3]":"DROP DEFAULT");$c[]="ALTER $e ".($X[2]==" NULL"?"DROP NOT":"SET").$X[2];}}if($o[0]!=""||$Xi!="")$yg[]="COMMENT ON COLUMN ".table($B).".$X[0] IS ".($Xi!=""?substr($Xi,9):"''");}}$c=array_merge($c,$ed);if($Q=="")array_unshift($yg,"CREATE TABLE ".table($B)." (\n".implode(",\n",$c)."\n)");elseif($c)array_unshift($yg,"ALTER TABLE ".table($Q)."\n".implode(",\n",$c));if($Q!=""||$vb!="")$yg[]="COMMENT ON TABLE ".table($B)." IS ".q($vb);if($Na!=""){}foreach($yg
+as$F){if(!queries($F))return
+false;}return
+true;}function
+alter_indexes($Q,$c){$Gb=array();$hc=array();$yg=array();foreach($c
+as$X){if($X[0]!="INDEX")$Gb[]=($X[2]=="DROP"?"\nDROP CONSTRAINT ".idf_escape($X[1]):"\nADD".($X[1]!=""?" CONSTRAINT ".idf_escape($X[1]):"")." $X[0] ".($X[0]=="PRIMARY"?"KEY ":"")."(".implode(", ",$X[2]).")");elseif($X[2]=="DROP")$hc[]=idf_escape($X[1]);else$yg[]="CREATE INDEX ".idf_escape($X[1]!=""?$X[1]:uniqid($Q."_"))." ON ".table($Q)." (".implode(", ",$X[2]).")";}if($Gb)array_unshift($yg,"ALTER TABLE ".table($Q).implode(",",$Gb));if($hc)array_unshift($yg,"DROP INDEX ".implode(", ",$hc));foreach($yg
+as$F){if(!queries($F))return
+false;}return
+true;}function
+truncate_tables($S){return
+queries("TRUNCATE ".implode(", ",array_map('table',$S)));return
+true;}function
+drop_views($dj){return
+drop_tables($dj);}function
+drop_tables($S){foreach($S
+as$Q){$O=table_status($Q);if(!queries("DROP ".strtoupper($O["Engine"])." ".table($Q)))return
+false;}return
+true;}function
+move_tables($S,$dj,$ai){foreach(array_merge($S,$dj)as$Q){$O=table_status($Q);if(!queries("ALTER ".strtoupper($O["Engine"])." ".table($Q)." SET SCHEMA ".idf_escape($ai)))return
+false;}return
+true;}function
+trigger($B,$Q=null){if($B=="")return
+array("Statement"=>"EXECUTE PROCEDURE ()");if($Q===null)$Q=$_GET['trigger'];$J=get_rows('SELECT t.trigger_name AS "Trigger", t.action_timing AS "Timing", (SELECT STRING_AGG(event_manipulation, \' OR \') FROM information_schema.triggers WHERE event_object_table = t.event_object_table AND trigger_name = t.trigger_name ) AS "Events", t.event_manipulation AS "Event", \'FOR EACH \' || t.action_orientation AS "Type", t.action_statement AS "Statement" FROM information_schema.triggers t WHERE t.event_object_table = '.q($Q).' AND t.trigger_name = '.q($B));return
+reset($J);}function
+triggers($Q){$H=array();foreach(get_rows("SELECT * FROM information_schema.triggers WHERE event_object_table = ".q($Q))as$I)$H[$I["trigger_name"]]=array($I["action_timing"],$I["event_manipulation"]);return$H;}function
+trigger_options(){return
+array("Timing"=>array("BEFORE","AFTER"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("FOR EACH ROW","FOR EACH STATEMENT"),);}function
+routine($B,$T){$J=get_rows('SELECT routine_definition AS definition, LOWER(external_language) AS language, *
+FROM information_schema.routines
+WHERE routine_schema = current_schema() AND specific_name = '.q($B));$H=$J[0];$H["returns"]=array("type"=>$H["type_udt_name"]);$H["fields"]=get_rows('SELECT parameter_name AS field, data_type AS type, character_maximum_length AS length, parameter_mode AS inout
+FROM information_schema.parameters
+WHERE specific_schema = current_schema() AND specific_name = '.q($B).'
+ORDER BY ordinal_position');return$H;}function
+routines(){return
+get_rows('SELECT specific_name AS "SPECIFIC_NAME", routine_type AS "ROUTINE_TYPE", routine_name AS "ROUTINE_NAME", type_udt_name AS "DTD_IDENTIFIER"
+FROM information_schema.routines
+WHERE routine_schema = current_schema()
+ORDER BY SPECIFIC_NAME');}function
+routine_languages(){return
+get_vals("SELECT LOWER(lanname) FROM pg_catalog.pg_language");}function
+routine_id($B,$I){$H=array();foreach($I["fields"]as$o)$H[]=$o["type"];return
+idf_escape($B)."(".implode(", ",$H).")";}function
+last_id(){return
+0;}function
+explain($h,$F){return$h->query("EXPLAIN $F");}function
+found_rows($R,$Z){global$h;if(preg_match("~ rows=([0-9]+)~",$h->result("EXPLAIN SELECT * FROM ".idf_escape($R["Name"]).($Z?" WHERE ".implode(" AND ",$Z):"")),$Kg))return$Kg[1];return
+false;}function
+types(){return
+get_vals("SELECT typname
+FROM pg_type
+WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
+AND typtype IN ('b','d','e')
+AND typelem = 0");}function
+schemas(){return
+get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");}function
+get_schema(){global$h;return$h->result("SELECT current_schema()");}function
+set_schema($dh,$i=null){global$h,$U,$Kh;if(!$i)$i=$h;$H=$i->query("SET search_path TO ".idf_escape($dh));foreach(types()as$T){if(!isset($U[$T])){$U[$T]=0;$Kh[lang(26)][]=$T;}}return$H;}function
+create_sql($Q,$Na,$Lh){global$h;$H='';$Tg=array();$nh=array();$O=table_status($Q);$p=fields($Q);$w=indexes($Q);ksort($w);$bd=foreign_keys($Q);ksort($bd);if(!$O||empty($p))return
+false;$H="CREATE TABLE ".idf_escape($O['nspname']).".".idf_escape($O['Name'])." (\n ";foreach($p
+as$Tc=>$o){$Uf=idf_escape($o['field']).' '.$o['full_type'].default_value($o).($o['attnotnull']?" NOT NULL":"");$Tg[]=$Uf;if(preg_match('~nextval\(\'([^\']+)\'\)~',$o['default'],$Ge)){$mh=$Ge[1];$Ah=reset(get_rows(min_version(10)?"SELECT *, cache_size AS cache_value FROM pg_sequences WHERE schemaname = current_schema() AND sequencename = ".q($mh):"SELECT * FROM $mh"));$nh[]=($Lh=="DROP+CREATE"?"DROP SEQUENCE IF EXISTS $mh;\n":"")."CREATE SEQUENCE $mh INCREMENT $Ah[increment_by] MINVALUE $Ah[min_value] MAXVALUE $Ah[max_value] START ".($Na?$Ah['last_value']:1)." CACHE $Ah[cache_value];";}}if(!empty($nh))$H=implode("\n\n",$nh)."\n\n$H";foreach($w
+as$Kd=>$v){switch($v['type']){case'UNIQUE':$Tg[]="CONSTRAINT ".idf_escape($Kd)." UNIQUE (".implode(', ',array_map('idf_escape',$v['columns'])).")";break;case'PRIMARY':$Tg[]="CONSTRAINT ".idf_escape($Kd)." PRIMARY KEY (".implode(', ',array_map('idf_escape',$v['columns'])).")";break;}}foreach($bd
+as$ad=>$Zc)$Tg[]="CONSTRAINT ".idf_escape($ad)." $Zc[definition] ".($Zc['deferrable']?'DEFERRABLE':'NOT DEFERRABLE');$H.=implode(",\n ",$Tg)."\n) WITH (oids = ".($O['Oid']?'true':'false').");";foreach($w
+as$Kd=>$v){if($v['type']=='INDEX'){$f=array();foreach($v['columns']as$y=>$X)$f[]=idf_escape($X).($v['descs'][$y]?" DESC":"");$H.="\n\nCREATE INDEX ".idf_escape($Kd)." ON ".idf_escape($O['nspname']).".".idf_escape($O['Name'])." USING btree (".implode(', ',$f).");";}}if($O['Comment'])$H.="\n\nCOMMENT ON TABLE ".idf_escape($O['nspname']).".".idf_escape($O['Name'])." IS ".q($O['Comment']).";";foreach($p
+as$Tc=>$o){if($o['comment'])$H.="\n\nCOMMENT ON COLUMN ".idf_escape($O['nspname']).".".idf_escape($O['Name']).".".idf_escape($Tc)." IS ".q($o['comment']).";";}return
+rtrim($H,';');}function
+truncate_sql($Q){return"TRUNCATE ".table($Q);}function
+trigger_sql($Q){$O=table_status($Q);$H="";foreach(triggers($Q)as$zi=>$yi){$_i=trigger($zi,$O['Name']);$H.="\nCREATE TRIGGER ".idf_escape($_i['Trigger'])." $_i[Timing] $_i[Events] ON ".idf_escape($O["nspname"]).".".idf_escape($O['Name'])." $_i[Type] $_i[Statement];;\n";}return$H;}function
+use_sql($j){return"\connect ".idf_escape($j);}function
+show_variables(){return
+get_key_vals("SHOW ALL");}function
+process_list(){return
+get_rows("SELECT * FROM pg_stat_activity ORDER BY ".(min_version(9.2)?"pid":"procpid"));}function
+show_status(){}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+support($Rc){return
+preg_match('~^(database|table|columns|sql|indexes|descidx|comment|view|'.(min_version(9.3)?'materializedview|':'').'scheme|routine|processlist|sequence|trigger|type|variables|drop_col|kill|dump)$~',$Rc);}function
+kill_process($X){return
+queries("SELECT pg_terminate_backend(".number($X).")");}function
+connection_id(){return"SELECT pg_backend_pid()";}function
+max_connections(){global$h;return$h->result("SHOW max_connections");}$x="pgsql";$U=array();$Kh=array();foreach(array(lang(27)=>array("smallint"=>5,"integer"=>10,"bigint"=>19,"boolean"=>1,"numeric"=>0,"real"=>7,"double precision"=>16,"money"=>20),lang(28)=>array("date"=>13,"time"=>17,"timestamp"=>20,"timestamptz"=>21,"interval"=>0),lang(25)=>array("character"=>0,"character varying"=>0,"text"=>0,"tsquery"=>0,"tsvector"=>0,"uuid"=>0,"xml"=>0),lang(29)=>array("bit"=>0,"bit varying"=>0,"bytea"=>0),lang(30)=>array("cidr"=>43,"inet"=>43,"macaddr"=>17,"txid_snapshot"=>0),lang(31)=>array("box"=>0,"circle"=>0,"line"=>0,"lseg"=>0,"path"=>0,"point"=>0,"polygon"=>0),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}$Li=array();$yf=array("=","<",">","<=",">=","!=","~","!~","LIKE","LIKE %%","ILIKE","ILIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL");$md=array("char_length","lower","round","to_hex","to_timestamp","upper");$sd=array("avg","count","count distinct","max","min","sum");$oc=array(array("char"=>"md5","date|time"=>"now",),array(number_type()=>"+/-","date|time"=>"+ interval/- interval","char|text"=>"||",));}$gc["oracle"]="Oracle (beta)";if(isset($_GET["oracle"])){$kg=array("OCI8","PDO_OCI");define("DRIVER","oracle");if(extension_loaded("oci8")){class
+Min_DB{var$extension="oci8",$_link,$_result,$server_info,$affected_rows,$errno,$error;function
+_error($zc,$n){if(ini_bool("html_errors"))$n=html_entity_decode(strip_tags($n));$n=preg_replace('~^[^:]*: ~','',$n);$this->error=$n;}function
+connect($M,$V,$E){$this->_link=@oci_new_connect($V,$E,$M,"AL32UTF8");if($this->_link){$this->server_info=oci_server_version($this->_link);return
+true;}$n=oci_error();$this->error=$n["message"];return
+false;}function
+quote($P){return"'".str_replace("'","''",$P)."'";}function
+select_db($j){return
+true;}function
+query($F,$Fi=false){$G=oci_parse($this->_link,$F);$this->error="";if(!$G){$n=oci_error($this->_link);$this->errno=$n["code"];$this->error=$n["message"];return
+false;}set_error_handler(array($this,'_error'));$H=@oci_execute($G);restore_error_handler();if($H){if(oci_num_fields($G))return
+new
+Min_Result($G);$this->affected_rows=oci_num_rows($G);}return$H;}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+result($F,$o=1){$G=$this->query($F);if(!is_object($G)||!oci_fetch($G->_result))return
+false;return
+oci_result($G->_result,$o);}}class
+Min_Result{var$_result,$_offset=1,$num_rows;function
+__construct($G){$this->_result=$G;}function
+_convert($I){foreach((array)$I
+as$y=>$X){if(is_a($X,'OCI-Lob'))$I[$y]=$X->load();}return$I;}function
+fetch_assoc(){return$this->_convert(oci_fetch_assoc($this->_result));}function
+fetch_row(){return$this->_convert(oci_fetch_row($this->_result));}function
+fetch_field(){$e=$this->_offset++;$H=new
+stdClass;$H->name=oci_field_name($this->_result,$e);$H->orgname=$H->name;$H->type=oci_field_type($this->_result,$e);$H->charsetnr=(preg_match("~raw|blob|bfile~",$H->type)?63:0);return$H;}function
+__destruct(){oci_free_statement($this->_result);}}}elseif(extension_loaded("pdo_oci")){class
+Min_DB
+extends
+Min_PDO{var$extension="PDO_OCI";function
+connect($M,$V,$E){$this->dsn("oci:dbname=//$M;charset=AL32UTF8",$V,$E);return
+true;}function
+select_db($j){return
+true;}}}class
+Min_Driver
+extends
+Min_SQL{function
+begin(){return
+true;}}function
+idf_escape($u){return'"'.str_replace('"','""',$u).'"';}function
+table($u){return
+idf_escape($u);}function
+connect(){global$b;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2]))return$h;return$h->error;}function
+get_databases(){return
+get_vals("SELECT tablespace_name FROM user_tablespaces");}function
+limit($F,$Z,$z,$C=0,$L=" "){return($C?" * FROM (SELECT t.*, rownum AS rnum FROM (SELECT $F$Z) t WHERE rownum <= ".($z+$C).") WHERE rnum > $C":($z!==null?" * FROM (SELECT $F$Z) WHERE rownum <= ".($z+$C):" $F$Z"));}function
+limit1($Q,$F,$Z,$L="\n"){return" $F$Z";}function
+db_collation($l,$qb){global$h;return$h->result("SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET'");}function
+engines(){return
+array();}function
+logged_user(){global$h;return$h->result("SELECT USER FROM DUAL");}function
+tables_list(){return
+get_key_vals("SELECT table_name, 'table' FROM all_tables WHERE tablespace_name = ".q(DB)."
+UNION SELECT view_name, 'view' FROM user_views
+ORDER BY 1");}function
+count_tables($k){return
+array();}function
+table_status($B=""){$H=array();$fh=q($B);foreach(get_rows('SELECT table_name "Name", \'table\' "Engine", avg_row_len * num_rows "Data_length", num_rows "Rows" FROM all_tables WHERE tablespace_name = '.q(DB).($B!=""?" AND table_name = $fh":"")."
+UNION SELECT view_name, 'view', 0, 0 FROM user_views".($B!=""?" WHERE view_name = $fh":"")."
+ORDER BY 1")as$I){if($B!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
+is_view($R){return$R["Engine"]=="view";}function
+fk_support($R){return
+true;}function
+fields($Q){$H=array();foreach(get_rows("SELECT * FROM all_tab_columns WHERE table_name = ".q($Q)." ORDER BY column_id")as$I){$T=$I["DATA_TYPE"];$we="$I[DATA_PRECISION],$I[DATA_SCALE]";if($we==",")$we=$I["DATA_LENGTH"];$H[$I["COLUMN_NAME"]]=array("field"=>$I["COLUMN_NAME"],"full_type"=>$T.($we?"($we)":""),"type"=>strtolower($T),"length"=>$we,"default"=>$I["DATA_DEFAULT"],"null"=>($I["NULLABLE"]=="Y"),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),);}return$H;}function
+indexes($Q,$i=null){$H=array();foreach(get_rows("SELECT uic.*, uc.constraint_type
+FROM user_ind_columns uic
+LEFT JOIN user_constraints uc ON uic.index_name = uc.constraint_name AND uic.table_name = uc.table_name
+WHERE uic.table_name = ".q($Q)."
+ORDER BY uc.constraint_type, uic.column_position",$i)as$I){$Kd=$I["INDEX_NAME"];$H[$Kd]["type"]=($I["CONSTRAINT_TYPE"]=="P"?"PRIMARY":($I["CONSTRAINT_TYPE"]=="U"?"UNIQUE":"INDEX"));$H[$Kd]["columns"][]=$I["COLUMN_NAME"];$H[$Kd]["lengths"][]=($I["CHAR_LENGTH"]&&$I["CHAR_LENGTH"]!=$I["COLUMN_LENGTH"]?$I["CHAR_LENGTH"]:null);$H[$Kd]["descs"][]=($I["DESCEND"]?'1':null);}return$H;}function
+view($B){$J=get_rows('SELECT text "select" FROM user_views WHERE view_name = '.q($B));return
+reset($J);}function
+collations(){return
+array();}function
+information_schema($l){return
+false;}function
+error(){global$h;return
+h($h->error);}function
+explain($h,$F){$h->query("EXPLAIN PLAN FOR $F");return$h->query("SELECT * FROM plan_table");}function
+found_rows($R,$Z){}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){$c=$hc=array();foreach($p
+as$o){$X=$o[1];if($X&&$o[0]!=""&&idf_escape($o[0])!=$X[0])queries("ALTER TABLE ".table($Q)." RENAME COLUMN ".idf_escape($o[0])." TO $X[0]");if($X)$c[]=($Q!=""?($o[0]!=""?"MODIFY (":"ADD ("):" ").implode($X).($Q!=""?")":"");else$hc[]=idf_escape($o[0]);}if($Q=="")return
+queries("CREATE TABLE ".table($B)." (\n".implode(",\n",$c)."\n)");return(!$c||queries("ALTER TABLE ".table($Q)."\n".implode("\n",$c)))&&(!$hc||queries("ALTER TABLE ".table($Q)." DROP (".implode(", ",$hc).")"))&&($Q==$B||queries("ALTER TABLE ".table($Q)." RENAME TO ".table($B)));}function
+foreign_keys($Q){$H=array();$F="SELECT c_list.CONSTRAINT_NAME as NAME,
+c_src.COLUMN_NAME as SRC_COLUMN,
+c_dest.OWNER as DEST_DB,
+c_dest.TABLE_NAME as DEST_TABLE,
+c_dest.COLUMN_NAME as DEST_COLUMN,
+c_list.DELETE_RULE as ON_DELETE
+FROM ALL_CONSTRAINTS c_list, ALL_CONS_COLUMNS c_src, ALL_CONS_COLUMNS c_dest
+WHERE c_list.CONSTRAINT_NAME = c_src.CONSTRAINT_NAME
+AND c_list.R_CONSTRAINT_NAME = c_dest.CONSTRAINT_NAME
+AND c_list.CONSTRAINT_TYPE = 'R'
+AND c_src.TABLE_NAME = ".q($Q);foreach(get_rows($F)as$I)$H[$I['NAME']]=array("db"=>$I['DEST_DB'],"table"=>$I['DEST_TABLE'],"source"=>array($I['SRC_COLUMN']),"target"=>array($I['DEST_COLUMN']),"on_delete"=>$I['ON_DELETE'],"on_update"=>null,);return$H;}function
+truncate_tables($S){return
+apply_queries("TRUNCATE TABLE",$S);}function
+drop_views($dj){return
+apply_queries("DROP VIEW",$dj);}function
+drop_tables($S){return
+apply_queries("DROP TABLE",$S);}function
+last_id(){return
+0;}function
+schemas(){return
+get_vals("SELECT DISTINCT owner FROM dba_segments WHERE owner IN (SELECT username FROM dba_users WHERE default_tablespace NOT IN ('SYSTEM','SYSAUX'))");}function
+get_schema(){global$h;return$h->result("SELECT sys_context('USERENV', 'SESSION_USER') FROM dual");}function
+set_schema($eh,$i=null){global$h;if(!$i)$i=$h;return$i->query("ALTER SESSION SET CURRENT_SCHEMA = ".idf_escape($eh));}function
+show_variables(){return
+get_key_vals('SELECT name, display_value FROM v$parameter');}function
+process_list(){return
+get_rows('SELECT sess.process AS "process", sess.username AS "user", sess.schemaname AS "schema", sess.status AS "status", sess.wait_class AS "wait_class", sess.seconds_in_wait AS "seconds_in_wait", sql.sql_text AS "sql_text", sess.machine AS "machine", sess.port AS "port"
+FROM v$session sess LEFT OUTER JOIN v$sql sql
+ON sql.sql_id = sess.sql_id
+WHERE sess.type = \'USER\'
+ORDER BY PROCESS
+');}function
+show_status(){$J=get_rows('SELECT * FROM v$instance');return
+reset($J);}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+support($Rc){return
+preg_match('~^(columns|database|drop_col|indexes|descidx|processlist|scheme|sql|status|table|variables|view|view_trigger)$~',$Rc);}$x="oracle";$U=array();$Kh=array();foreach(array(lang(27)=>array("number"=>38,"binary_float"=>12,"binary_double"=>21),lang(28)=>array("date"=>10,"timestamp"=>29,"interval year"=>12,"interval day"=>28),lang(25)=>array("char"=>2000,"varchar2"=>4000,"nchar"=>2000,"nvarchar2"=>4000,"clob"=>4294967295,"nclob"=>4294967295),lang(29)=>array("raw"=>2000,"long raw"=>2147483648,"blob"=>4294967295,"bfile"=>4294967296),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}$Li=array();$yf=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT REGEXP","NOT IN","IS NOT NULL","SQL");$md=array("length","lower","round","upper");$sd=array("avg","count","count distinct","max","min","sum");$oc=array(array("date"=>"current_date","timestamp"=>"current_timestamp",),array("number|float|double"=>"+/-","date|timestamp"=>"+ interval/- interval","char|clob"=>"||",));}$gc["mssql"]="MS SQL (beta)";if(isset($_GET["mssql"])){$kg=array("SQLSRV","MSSQL","PDO_DBLIB");define("DRIVER","mssql");if(extension_loaded("sqlsrv")){class
+Min_DB{var$extension="sqlsrv",$_link,$_result,$server_info,$affected_rows,$errno,$error;function
+_get_error(){$this->error="";foreach(sqlsrv_errors()as$n){$this->errno=$n["code"];$this->error.="$n[message]\n";}$this->error=rtrim($this->error);}function
+connect($M,$V,$E){global$b;$l=$b->database();$zb=array("UID"=>$V,"PWD"=>$E,"CharacterSet"=>"UTF-8");if($l!="")$zb["Database"]=$l;$this->_link=@sqlsrv_connect(preg_replace('~:~',',',$M),$zb);if($this->_link){$Rd=sqlsrv_server_info($this->_link);$this->server_info=$Rd['SQLServerVersion'];}else$this->_get_error();return(bool)$this->_link;}function
+quote($P){return"'".str_replace("'","''",$P)."'";}function
+select_db($j){return$this->query("USE ".idf_escape($j));}function
+query($F,$Fi=false){$G=sqlsrv_query($this->_link,$F);$this->error="";if(!$G){$this->_get_error();return
+false;}return$this->store_result($G);}function
+multi_query($F){$this->_result=sqlsrv_query($this->_link,$F);$this->error="";if(!$this->_result){$this->_get_error();return
+false;}return
+true;}function
+store_result($G=null){if(!$G)$G=$this->_result;if(!$G)return
+false;if(sqlsrv_field_metadata($G))return
+new
+Min_Result($G);$this->affected_rows=sqlsrv_rows_affected($G);return
+true;}function
+next_result(){return$this->_result?sqlsrv_next_result($this->_result):null;}function
+result($F,$o=0){$G=$this->query($F);if(!is_object($G))return
+false;$I=$G->fetch_row();return$I[$o];}}class
+Min_Result{var$_result,$_offset=0,$_fields,$num_rows;function
+__construct($G){$this->_result=$G;}function
+_convert($I){foreach((array)$I
+as$y=>$X){if(is_a($X,'DateTime'))$I[$y]=$X->format("Y-m-d H:i:s");}return$I;}function
+fetch_assoc(){return$this->_convert(sqlsrv_fetch_array($this->_result,SQLSRV_FETCH_ASSOC));}function
+fetch_row(){return$this->_convert(sqlsrv_fetch_array($this->_result,SQLSRV_FETCH_NUMERIC));}function
+fetch_field(){if(!$this->_fields)$this->_fields=sqlsrv_field_metadata($this->_result);$o=$this->_fields[$this->_offset++];$H=new
+stdClass;$H->name=$o["Name"];$H->orgname=$o["Name"];$H->type=($o["Type"]==1?254:0);return$H;}function
+seek($C){for($s=0;$s<$C;$s++)sqlsrv_fetch($this->_result);}function
+__destruct(){sqlsrv_free_stmt($this->_result);}}}elseif(extension_loaded("mssql")){class
+Min_DB{var$extension="MSSQL",$_link,$_result,$server_info,$affected_rows,$error;function
+connect($M,$V,$E){$this->_link=@mssql_connect($M,$V,$E);if($this->_link){$G=$this->query("SELECT SERVERPROPERTY('ProductLevel'), SERVERPROPERTY('Edition')");if($G){$I=$G->fetch_row();$this->server_info=$this->result("sp_server_info 2",2)." [$I[0]] $I[1]";}}else$this->error=mssql_get_last_message();return(bool)$this->_link;}function
+quote($P){return"'".str_replace("'","''",$P)."'";}function
+select_db($j){return
+mssql_select_db($j);}function
+query($F,$Fi=false){$G=@mssql_query($F,$this->_link);$this->error="";if(!$G){$this->error=mssql_get_last_message();return
+false;}if($G===true){$this->affected_rows=mssql_rows_affected($this->_link);return
+true;}return
+new
+Min_Result($G);}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+mssql_next_result($this->_result->_result);}function
+result($F,$o=0){$G=$this->query($F);if(!is_object($G))return
+false;return
+mssql_result($G->_result,0,$o);}}class
+Min_Result{var$_result,$_offset=0,$_fields,$num_rows;function
+__construct($G){$this->_result=$G;$this->num_rows=mssql_num_rows($G);}function
+fetch_assoc(){return
+mssql_fetch_assoc($this->_result);}function
+fetch_row(){return
+mssql_fetch_row($this->_result);}function
+num_rows(){return
+mssql_num_rows($this->_result);}function
+fetch_field(){$H=mssql_fetch_field($this->_result);$H->orgtable=$H->table;$H->orgname=$H->name;return$H;}function
+seek($C){mssql_data_seek($this->_result,$C);}function
+__destruct(){mssql_free_result($this->_result);}}}elseif(extension_loaded("pdo_dblib")){class
+Min_DB
+extends
+Min_PDO{var$extension="PDO_DBLIB";function
+connect($M,$V,$E){$this->dsn("dblib:charset=utf8;host=".str_replace(":",";unix_socket=",preg_replace('~:(\d)~',';port=\1',$M)),$V,$E);return
+true;}function
+select_db($j){return$this->query("USE ".idf_escape($j));}}}class
+Min_Driver
+extends
+Min_SQL{function
+insertUpdate($Q,$J,$ng){foreach($J
+as$N){$Mi=array();$Z=array();foreach($N
+as$y=>$X){$Mi[]="$y = $X";if(isset($ng[idf_unescape($y)]))$Z[]="$y = $X";}if(!queries("MERGE ".table($Q)." USING (VALUES(".implode(", ",$N).")) AS source (c".implode(", c",range(1,count($N))).") ON ".implode(" AND ",$Z)." WHEN MATCHED THEN UPDATE SET ".implode(", ",$Mi)." WHEN NOT MATCHED THEN INSERT (".implode(", ",array_keys($N)).") VALUES (".implode(", ",$N).");"))return
+false;}return
+true;}function
+begin(){return
+queries("BEGIN TRANSACTION");}}function
+idf_escape($u){return"[".str_replace("]","]]",$u)."]";}function
+table($u){return($_GET["ns"]!=""?idf_escape($_GET["ns"]).".":"").idf_escape($u);}function
+connect(){global$b;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2]))return$h;return$h->error;}function
+get_databases(){return
+get_vals("SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')");}function
+limit($F,$Z,$z,$C=0,$L=" "){return($z!==null?" TOP (".($z+$C).")":"")." $F$Z";}function
+limit1($Q,$F,$Z,$L="\n"){return
+limit($F,$Z,1,0,$L);}function
+db_collation($l,$qb){global$h;return$h->result("SELECT collation_name FROM sys.databases WHERE name = ".q($l));}function
+engines(){return
+array();}function
+logged_user(){global$h;return$h->result("SELECT SUSER_NAME()");}function
+tables_list(){return
+get_key_vals("SELECT name, type_desc FROM sys.all_objects WHERE schema_id = SCHEMA_ID(".q(get_schema()).") AND type IN ('S', 'U', 'V') ORDER BY name");}function
+count_tables($k){global$h;$H=array();foreach($k
+as$l){$h->select_db($l);$H[$l]=$h->result("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES");}return$H;}function
+table_status($B=""){$H=array();foreach(get_rows("SELECT ao.name AS Name, ao.type_desc AS Engine, (SELECT value FROM fn_listextendedproperty(default, 'SCHEMA', schema_name(schema_id), 'TABLE', ao.name, null, null)) AS Comment FROM sys.all_objects AS ao WHERE schema_id = SCHEMA_ID(".q(get_schema()).") AND type IN ('S', 'U', 'V') ".($B!=""?"AND name = ".q($B):"ORDER BY name"))as$I){if($B!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
+is_view($R){return$R["Engine"]=="VIEW";}function
+fk_support($R){return
+true;}function
+fields($Q){$wb=get_key_vals("SELECT objname, cast(value as varchar) FROM fn_listextendedproperty('MS_DESCRIPTION', 'schema', ".q(get_schema()).", 'table', ".q($Q).", 'column', NULL)");$H=array();foreach(get_rows("SELECT c.max_length, c.precision, c.scale, c.name, c.is_nullable, c.is_identity, c.collation_name, t.name type, CAST(d.definition as text) [default]
+FROM sys.all_columns c
+JOIN sys.all_objects o ON c.object_id = o.object_id
+JOIN sys.types t ON c.user_type_id = t.user_type_id
+LEFT JOIN sys.default_constraints d ON c.default_object_id = d.parent_column_id
+WHERE o.schema_id = SCHEMA_ID(".q(get_schema()).") AND o.type IN ('S', 'U', 'V') AND o.name = ".q($Q))as$I){$T=$I["type"];$we=(preg_match("~char|binary~",$T)?$I["max_length"]:($T=="decimal"?"$I[precision],$I[scale]":""));$H[$I["name"]]=array("field"=>$I["name"],"full_type"=>$T.($we?"($we)":""),"type"=>$T,"length"=>$we,"default"=>$I["default"],"null"=>$I["is_nullable"],"auto_increment"=>$I["is_identity"],"collation"=>$I["collation_name"],"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),"primary"=>$I["is_identity"],"comment"=>$wb[$I["name"]],);}return$H;}function
+indexes($Q,$i=null){$H=array();foreach(get_rows("SELECT i.name, key_ordinal, is_unique, is_primary_key, c.name AS column_name, is_descending_key
+FROM sys.indexes i
+INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
+INNER JOIN sys.columns c ON ic.object_id = c.object_id AND ic.column_id = c.column_id
+WHERE OBJECT_NAME(i.object_id) = ".q($Q),$i)as$I){$B=$I["name"];$H[$B]["type"]=($I["is_primary_key"]?"PRIMARY":($I["is_unique"]?"UNIQUE":"INDEX"));$H[$B]["lengths"]=array();$H[$B]["columns"][$I["key_ordinal"]]=$I["column_name"];$H[$B]["descs"][$I["key_ordinal"]]=($I["is_descending_key"]?'1':null);}return$H;}function
+view($B){global$h;return
+array("select"=>preg_replace('~^(?:[^[]|\[[^]]*])*\s+AS\s+~isU','',$h->result("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = SCHEMA_NAME() AND TABLE_NAME = ".q($B))));}function
+collations(){$H=array();foreach(get_vals("SELECT name FROM fn_helpcollations()")as$d)$H[preg_replace('~_.*~','',$d)][]=$d;return$H;}function
+information_schema($l){return
+false;}function
+error(){global$h;return
+nl_br(h(preg_replace('~^(\[[^]]*])+~m','',$h->error)));}function
+create_database($l,$d){return
+queries("CREATE DATABASE ".idf_escape($l).(preg_match('~^[a-z0-9_]+$~i',$d)?" COLLATE $d":""));}function
+drop_databases($k){return
+queries("DROP DATABASE ".implode(", ",array_map('idf_escape',$k)));}function
+rename_database($B,$d){if(preg_match('~^[a-z0-9_]+$~i',$d))queries("ALTER DATABASE ".idf_escape(DB)." COLLATE $d");queries("ALTER DATABASE ".idf_escape(DB)." MODIFY NAME = ".idf_escape($B));return
+true;}function
+auto_increment(){return" IDENTITY".($_POST["Auto_increment"]!=""?"(".number($_POST["Auto_increment"]).",1)":"")." PRIMARY KEY";}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){$c=array();$wb=array();foreach($p
+as$o){$e=idf_escape($o[0]);$X=$o[1];if(!$X)$c["DROP"][]=" COLUMN $e";else{$X[1]=preg_replace("~( COLLATE )'(\\w+)'~",'\1\2',$X[1]);$wb[$o[0]]=$X[5];unset($X[5]);if($o[0]=="")$c["ADD"][]="\n ".implode("",$X).($Q==""?substr($ed[$X[0]],16+strlen($X[0])):"");else{unset($X[6]);if($e!=$X[0])queries("EXEC sp_rename ".q(table($Q).".$e").", ".q(idf_unescape($X[0])).", 'COLUMN'");$c["ALTER COLUMN ".implode("",$X)][]="";}}}if($Q=="")return
+queries("CREATE TABLE ".table($B)." (".implode(",",(array)$c["ADD"])."\n)");if($Q!=$B)queries("EXEC sp_rename ".q(table($Q)).", ".q($B));if($ed)$c[""]=$ed;foreach($c
+as$y=>$X){if(!queries("ALTER TABLE ".idf_escape($B)." $y".implode(",",$X)))return
+false;}foreach($wb
+as$y=>$X){$vb=substr($X,9);queries("EXEC sp_dropextendedproperty @name = N'MS_Description', @level0type = N'Schema', @level0name = ".q(get_schema()).", @level1type = N'Table', @level1name = ".q($B).", @level2type = N'Column', @level2name = ".q($y));queries("EXEC sp_addextendedproperty @name = N'MS_Description', @value = ".$vb.", @level0type = N'Schema', @level0name = ".q(get_schema()).", @level1type = N'Table', @level1name = ".q($B).", @level2type = N'Column', @level2name = ".q($y));}return
+true;}function
+alter_indexes($Q,$c){$v=array();$hc=array();foreach($c
+as$X){if($X[2]=="DROP"){if($X[0]=="PRIMARY")$hc[]=idf_escape($X[1]);else$v[]=idf_escape($X[1])." ON ".table($Q);}elseif(!queries(($X[0]!="PRIMARY"?"CREATE $X[0] ".($X[0]!="INDEX"?"INDEX ":"").idf_escape($X[1]!=""?$X[1]:uniqid($Q."_"))." ON ".table($Q):"ALTER TABLE ".table($Q)." ADD PRIMARY KEY")." (".implode(", ",$X[2]).")"))return
+false;}return(!$v||queries("DROP INDEX ".implode(", ",$v)))&&(!$hc||queries("ALTER TABLE ".table($Q)." DROP ".implode(", ",$hc)));}function
+last_id(){global$h;return$h->result("SELECT SCOPE_IDENTITY()");}function
+explain($h,$F){$h->query("SET SHOWPLAN_ALL ON");$H=$h->query($F);$h->query("SET SHOWPLAN_ALL OFF");return$H;}function
+found_rows($R,$Z){}function
+foreign_keys($Q){$H=array();foreach(get_rows("EXEC sp_fkeys @fktable_name = ".q($Q))as$I){$q=&$H[$I["FK_NAME"]];$q["db"]=$I["PKTABLE_QUALIFIER"];$q["table"]=$I["PKTABLE_NAME"];$q["source"][]=$I["FKCOLUMN_NAME"];$q["target"][]=$I["PKCOLUMN_NAME"];}return$H;}function
+truncate_tables($S){return
+apply_queries("TRUNCATE TABLE",$S);}function
+drop_views($dj){return
+queries("DROP VIEW ".implode(", ",array_map('table',$dj)));}function
+drop_tables($S){return
+queries("DROP TABLE ".implode(", ",array_map('table',$S)));}function
+move_tables($S,$dj,$ai){return
+apply_queries("ALTER SCHEMA ".idf_escape($ai)." TRANSFER",array_merge($S,$dj));}function
+trigger($B){if($B=="")return
+array();$J=get_rows("SELECT s.name [Trigger],
+CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(s.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(s.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
+CASE WHEN OBJECTPROPERTY(s.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing],
+c.text
+FROM sysobjects s
+JOIN syscomments c ON s.id = c.id
+WHERE s.xtype = 'TR' AND s.name = ".q($B));$H=reset($J);if($H)$H["Statement"]=preg_replace('~^.+\s+AS\s+~isU','',$H["text"]);return$H;}function
+triggers($Q){$H=array();foreach(get_rows("SELECT sys1.name,
+CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsertTrigger') = 1 THEN 'INSERT' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsUpdateTrigger') = 1 THEN 'UPDATE' WHEN OBJECTPROPERTY(sys1.id, 'ExecIsDeleteTrigger') = 1 THEN 'DELETE' END [Event],
+CASE WHEN OBJECTPROPERTY(sys1.id, 'ExecIsInsteadOfTrigger') = 1 THEN 'INSTEAD OF' ELSE 'AFTER' END [Timing]
+FROM sysobjects sys1
+JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
+WHERE sys1.xtype = 'TR' AND sys2.name = ".q($Q))as$I)$H[$I["name"]]=array($I["Timing"],$I["Event"]);return$H;}function
+trigger_options(){return
+array("Timing"=>array("AFTER","INSTEAD OF"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("AS"),);}function
+schemas(){return
+get_vals("SELECT name FROM sys.schemas");}function
+get_schema(){global$h;if($_GET["ns"]!="")return$_GET["ns"];return$h->result("SELECT SCHEMA_NAME()");}function
+set_schema($dh){return
+true;}function
+use_sql($j){return"USE ".idf_escape($j);}function
+show_variables(){return
+array();}function
+show_status(){return
+array();}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+support($Rc){return
+preg_match('~^(comment|columns|database|drop_col|indexes|descidx|scheme|sql|table|trigger|view|view_trigger)$~',$Rc);}$x="mssql";$U=array();$Kh=array();foreach(array(lang(27)=>array("tinyint"=>3,"smallint"=>5,"int"=>10,"bigint"=>20,"bit"=>1,"decimal"=>0,"real"=>12,"float"=>53,"smallmoney"=>10,"money"=>20),lang(28)=>array("date"=>10,"smalldatetime"=>19,"datetime"=>19,"datetime2"=>19,"time"=>8,"datetimeoffset"=>10),lang(25)=>array("char"=>8000,"varchar"=>8000,"text"=>2147483647,"nchar"=>4000,"nvarchar"=>4000,"ntext"=>1073741823),lang(29)=>array("binary"=>8000,"varbinary"=>8000,"image"=>2147483647),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}$Li=array();$yf=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL");$md=array("len","lower","round","upper");$sd=array("avg","count","count distinct","max","min","sum");$oc=array(array("date|time"=>"getdate",),array("int|decimal|real|float|money|datetime"=>"+/-","char|text"=>"+",));}$gc['firebird']='Firebird (alpha)';if(isset($_GET["firebird"])){$kg=array("interbase");define("DRIVER","firebird");if(extension_loaded("interbase")){class
+Min_DB{var$extension="Firebird",$server_info,$affected_rows,$errno,$error,$_link,$_result;function
+connect($M,$V,$E){$this->_link=ibase_connect($M,$V,$E);if($this->_link){$Pi=explode(':',$M);$this->service_link=ibase_service_attach($Pi[0],$V,$E);$this->server_info=ibase_server_info($this->service_link,IBASE_SVC_SERVER_VERSION);}else{$this->errno=ibase_errcode();$this->error=ibase_errmsg();}return(bool)$this->_link;}function
+quote($P){return"'".str_replace("'","''",$P)."'";}function
+select_db($j){return($j=="domain");}function
+query($F,$Fi=false){$G=ibase_query($F,$this->_link);if(!$G){$this->errno=ibase_errcode();$this->error=ibase_errmsg();return
+false;}$this->error="";if($G===true){$this->affected_rows=ibase_affected_rows($this->_link);return
+true;}return
+new
+Min_Result($G);}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+result($F,$o=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
+false;$I=$G->fetch_row();return$I[$o];}}class
+Min_Result{var$num_rows,$_result,$_offset=0;function
+__construct($G){$this->_result=$G;}function
+fetch_assoc(){return
+ibase_fetch_assoc($this->_result);}function
+fetch_row(){return
+ibase_fetch_row($this->_result);}function
+fetch_field(){$o=ibase_field_info($this->_result,$this->_offset++);return(object)array('name'=>$o['name'],'orgname'=>$o['name'],'type'=>$o['type'],'charsetnr'=>$o['length'],);}function
+__destruct(){ibase_free_result($this->_result);}}}class
+Min_Driver
+extends
+Min_SQL{}function
+idf_escape($u){return'"'.str_replace('"','""',$u).'"';}function
+table($u){return
+idf_escape($u);}function
+connect(){global$b;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2]))return$h;return$h->error;}function
+get_databases($cd){return
+array("domain");}function
+limit($F,$Z,$z,$C=0,$L=" "){$H='';$H.=($z!==null?$L."FIRST $z".($C?" SKIP $C":""):"");$H.=" $F$Z";return$H;}function
+limit1($Q,$F,$Z,$L="\n"){return
+limit($F,$Z,1,0,$L);}function
+db_collation($l,$qb){}function
+engines(){return
+array();}function
+logged_user(){global$b;$Jb=$b->credentials();return$Jb[1];}function
+tables_list(){global$h;$F='SELECT RDB$RELATION_NAME FROM rdb$relations WHERE rdb$system_flag = 0';$G=ibase_query($h->_link,$F);$H=array();while($I=ibase_fetch_assoc($G))$H[$I['RDB$RELATION_NAME']]='table';ksort($H);return$H;}function
+count_tables($k){return
+array();}function
+table_status($B="",$Qc=false){global$h;$H=array();$Ob=tables_list();foreach($Ob
+as$v=>$X){$v=trim($v);$H[$v]=array('Name'=>$v,'Engine'=>'standard',);if($B==$v)return$H[$v];}return$H;}function
+is_view($R){return
+false;}function
+fk_support($R){return
+preg_match('~InnoDB|IBMDB2I~i',$R["Engine"]);}function
+fields($Q){global$h;$H=array();$F='SELECT r.RDB$FIELD_NAME AS field_name,
+r.RDB$DESCRIPTION AS field_description,
+r.RDB$DEFAULT_VALUE AS field_default_value,
+r.RDB$NULL_FLAG AS field_not_null_constraint,
+f.RDB$FIELD_LENGTH AS field_length,
+f.RDB$FIELD_PRECISION AS field_precision,
+f.RDB$FIELD_SCALE AS field_scale,
+CASE f.RDB$FIELD_TYPE
+WHEN 261 THEN \'BLOB\'
+WHEN 14 THEN \'CHAR\'
+WHEN 40 THEN \'CSTRING\'
+WHEN 11 THEN \'D_FLOAT\'
+WHEN 27 THEN \'DOUBLE\'
+WHEN 10 THEN \'FLOAT\'
+WHEN 16 THEN \'INT64\'
+WHEN 8 THEN \'INTEGER\'
+WHEN 9 THEN \'QUAD\'
+WHEN 7 THEN \'SMALLINT\'
+WHEN 12 THEN \'DATE\'
+WHEN 13 THEN \'TIME\'
+WHEN 35 THEN \'TIMESTAMP\'
+WHEN 37 THEN \'VARCHAR\'
+ELSE \'UNKNOWN\'
+END AS field_type,
+f.RDB$FIELD_SUB_TYPE AS field_subtype,
+coll.RDB$COLLATION_NAME AS field_collation,
+cset.RDB$CHARACTER_SET_NAME AS field_charset
+FROM RDB$RELATION_FIELDS r
+LEFT JOIN RDB$FIELDS f ON r.RDB$FIELD_SOURCE = f.RDB$FIELD_NAME
+LEFT JOIN RDB$COLLATIONS coll ON f.RDB$COLLATION_ID = coll.RDB$COLLATION_ID
+LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID
+WHERE r.RDB$RELATION_NAME = '.q($Q).'
+ORDER BY r.RDB$FIELD_POSITION';$G=ibase_query($h->_link,$F);while($I=ibase_fetch_assoc($G))$H[trim($I['FIELD_NAME'])]=array("field"=>trim($I["FIELD_NAME"]),"full_type"=>trim($I["FIELD_TYPE"]),"type"=>trim($I["FIELD_SUB_TYPE"]),"default"=>trim($I['FIELD_DEFAULT_VALUE']),"null"=>(trim($I["FIELD_NOT_NULL_CONSTRAINT"])=="YES"),"auto_increment"=>'0',"collation"=>trim($I["FIELD_COLLATION"]),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),"comment"=>trim($I["FIELD_DESCRIPTION"]),);return$H;}function
+indexes($Q,$i=null){$H=array();return$H;}function
+foreign_keys($Q){return
+array();}function
+collations(){return
+array();}function
+information_schema($l){return
+false;}function
+error(){global$h;return
+h($h->error);}function
+types(){return
+array();}function
+schemas(){return
+array();}function
+get_schema(){return"";}function
+set_schema($dh){return
+true;}function
+support($Rc){return
+preg_match("~^(columns|sql|status|table)$~",$Rc);}$x="firebird";$yf=array("=");$md=array();$sd=array();$oc=array();}$gc["simpledb"]="SimpleDB";if(isset($_GET["simpledb"])){$kg=array("SimpleXML + allow_url_fopen");define("DRIVER","simpledb");if(class_exists('SimpleXMLElement')&&ini_bool('allow_url_fopen')){class
+Min_DB{var$extension="SimpleXML",$server_info='2009-04-15',$error,$timeout,$next,$affected_rows,$_result;function
+select_db($j){return($j=="domain");}function
+query($F,$Fi=false){$Rf=array('SelectExpression'=>$F,'ConsistentRead'=>'true');if($this->next)$Rf['NextToken']=$this->next;$G=sdb_request_all('Select','Item',$Rf,$this->timeout);$this->timeout=0;if($G===false)return$G;if(preg_match('~^\s*SELECT\s+COUNT\(~i',$F)){$Oh=0;foreach($G
+as$de)$Oh+=$de->Attribute->Value;$G=array((object)array('Attribute'=>array((object)array('Name'=>'Count','Value'=>$Oh,))));}return
+new
+Min_Result($G);}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+quote($P){return"'".str_replace("'","''",$P)."'";}}class
+Min_Result{var$num_rows,$_rows=array(),$_offset=0;function
+__construct($G){foreach($G
+as$de){$I=array();if($de->Name!='')$I['itemName()']=(string)$de->Name;foreach($de->Attribute
+as$Ja){$B=$this->_processValue($Ja->Name);$Y=$this->_processValue($Ja->Value);if(isset($I[$B])){$I[$B]=(array)$I[$B];$I[$B][]=$Y;}else$I[$B]=$Y;}$this->_rows[]=$I;foreach($I
+as$y=>$X){if(!isset($this->_rows[0][$y]))$this->_rows[0][$y]=null;}}$this->num_rows=count($this->_rows);}function
+_processValue($rc){return(is_object($rc)&&$rc['encoding']=='base64'?base64_decode($rc):(string)$rc);}function
+fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$y=>$X)$H[$y]=$I[$y];next($this->_rows);return$H;}function
+fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
+array_values($H);}function
+fetch_field(){$je=array_keys($this->_rows[0]);return(object)array('name'=>$je[$this->_offset++]);}}}class
+Min_Driver
+extends
+Min_SQL{public$ng="itemName()";function
+_chunkRequest($Gd,$wa,$Rf,$Gc=array()){global$h;foreach(array_chunk($Gd,25)as$jb){$Sf=$Rf;foreach($jb
+as$s=>$t){$Sf["Item.$s.ItemName"]=$t;foreach($Gc
+as$y=>$X)$Sf["Item.$s.$y"]=$X;}if(!sdb_request($wa,$Sf))return
+false;}$h->affected_rows=count($Gd);return
+true;}function
+_extractIds($Q,$zg,$z){$H=array();if(preg_match_all("~itemName\(\) = (('[^']*+')+)~",$zg,$Ge))$H=array_map('idf_unescape',$Ge[1]);else{foreach(sdb_request_all('Select','Item',array('SelectExpression'=>'SELECT itemName() FROM '.table($Q).$zg.($z?" LIMIT 1":"")))as$de)$H[]=$de->Name;}return$H;}function
+select($Q,$K,$Z,$pd,$Cf=array(),$z=1,$D=0,$pg=false){global$h;$h->next=$_GET["next"];$H=parent::select($Q,$K,$Z,$pd,$Cf,$z,$D,$pg);$h->next=0;return$H;}function
+delete($Q,$zg,$z=0){return$this->_chunkRequest($this->_extractIds($Q,$zg,$z),'BatchDeleteAttributes',array('DomainName'=>$Q));}function
+update($Q,$N,$zg,$z=0,$L="\n"){$Xb=array();$Vd=array();$s=0;$Gd=$this->_extractIds($Q,$zg,$z);$t=idf_unescape($N["`itemName()`"]);unset($N["`itemName()`"]);foreach($N
+as$y=>$X){$y=idf_unescape($y);if($X=="NULL"||($t!=""&&array($t)!=$Gd))$Xb["Attribute.".count($Xb).".Name"]=$y;if($X!="NULL"){foreach((array)$X
+as$fe=>$W){$Vd["Attribute.$s.Name"]=$y;$Vd["Attribute.$s.Value"]=(is_array($X)?$W:idf_unescape($W));if(!$fe)$Vd["Attribute.$s.Replace"]="true";$s++;}}}$Rf=array('DomainName'=>$Q);return(!$Vd||$this->_chunkRequest(($t!=""?array($t):$Gd),'BatchPutAttributes',$Rf,$Vd))&&(!$Xb||$this->_chunkRequest($Gd,'BatchDeleteAttributes',$Rf,$Xb));}function
+insert($Q,$N){$Rf=array("DomainName"=>$Q);$s=0;foreach($N
+as$B=>$Y){if($Y!="NULL"){$B=idf_unescape($B);if($B=="itemName()")$Rf["ItemName"]=idf_unescape($Y);else{foreach((array)$Y
+as$X){$Rf["Attribute.$s.Name"]=$B;$Rf["Attribute.$s.Value"]=(is_array($Y)?$X:idf_unescape($Y));$s++;}}}}return
+sdb_request('PutAttributes',$Rf);}function
+insertUpdate($Q,$J,$ng){foreach($J
+as$N){if(!$this->update($Q,$N,"WHERE `itemName()` = ".q($N["`itemName()`"])))return
+false;}return
+true;}function
+begin(){return
+false;}function
+commit(){return
+false;}function
+rollback(){return
+false;}function
+slowQuery($F,$ii){$this->_conn->timeout=$ii;return$F;}}function
+connect(){global$b;list(,,$E)=$b->credentials();if($E!="")return
+lang(22);return
+new
+Min_DB;}function
+support($Rc){return
+preg_match('~sql~',$Rc);}function
+logged_user(){global$b;$Jb=$b->credentials();return$Jb[1];}function
+get_databases(){return
+array("domain");}function
+collations(){return
+array();}function
+db_collation($l,$qb){}function
+tables_list(){global$h;$H=array();foreach(sdb_request_all('ListDomains','DomainName')as$Q)$H[(string)$Q]='table';if($h->error&&defined("PAGE_HEADER"))echo"".error()."\n";return$H;}function
+table_status($B="",$Qc=false){$H=array();foreach(($B!=""?array($B=>true):tables_list())as$Q=>$T){$I=array("Name"=>$Q,"Auto_increment"=>"");if(!$Qc){$Te=sdb_request('DomainMetadata',array('DomainName'=>$Q));if($Te){foreach(array("Rows"=>"ItemCount","Data_length"=>"ItemNamesSizeBytes","Index_length"=>"AttributeValuesSizeBytes","Data_free"=>"AttributeNamesSizeBytes",)as$y=>$X)$I[$y]=(string)$Te->$X;}}if($B!="")return$I;$H[$Q]=$I;}return$H;}function
+explain($h,$F){}function
+error(){global$h;return
+h($h->error);}function
+information_schema(){}function
+is_view($R){}function
+indexes($Q,$i=null){return
+array(array("type"=>"PRIMARY","columns"=>array("itemName()")),);}function
+fields($Q){return
+fields_from_edit();}function
+foreign_keys($Q){return
+array();}function
+table($u){return
+idf_escape($u);}function
+idf_escape($u){return"`".str_replace("`","``",$u)."`";}function
+limit($F,$Z,$z,$C=0,$L=" "){return" $F$Z".($z!==null?$L."LIMIT $z":"");}function
+unconvert_field($o,$H){return$H;}function
+fk_support($R){}function
+engines(){return
+array();}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){return($Q==""&&sdb_request('CreateDomain',array('DomainName'=>$B)));}function
+drop_tables($S){foreach($S
+as$Q){if(!sdb_request('DeleteDomain',array('DomainName'=>$Q)))return
+false;}return
+true;}function
+count_tables($k){foreach($k
+as$l)return
+array($l=>count(tables_list()));}function
+found_rows($R,$Z){return($Z?null:$R["Rows"]);}function
+last_id(){}function
+hmac($Ca,$Ob,$y,$Cg=false){$Wa=64;if(strlen($y)>$Wa)$y=pack("H*",$Ca($y));$y=str_pad($y,$Wa,"\0");$ge=$y^str_repeat("\x36",$Wa);$he=$y^str_repeat("\x5C",$Wa);$H=$Ca($he.pack("H*",$Ca($ge.$Ob)));if($Cg)$H=pack("H*",$H);return$H;}function
+sdb_request($wa,$Rf=array()){global$b,$h;list($Cd,$Rf['AWSAccessKeyId'],$gh)=$b->credentials();$Rf['Action']=$wa;$Rf['Timestamp']=gmdate('Y-m-d\TH:i:s+00:00');$Rf['Version']='2009-04-15';$Rf['SignatureVersion']=2;$Rf['SignatureMethod']='HmacSHA1';ksort($Rf);$F='';foreach($Rf
+as$y=>$X)$F.='&'.rawurlencode($y).'='.rawurlencode($X);$F=str_replace('%7E','~',substr($F,1));$F.="&Signature=".urlencode(base64_encode(hmac('sha1',"POST\n".preg_replace('~^https?://~','',$Cd)."\n/\n$F",$gh,true)));@ini_set('track_errors',1);$Vc=@file_get_contents((preg_match('~^https?://~',$Cd)?$Cd:"http://$Cd"),false,stream_context_create(array('http'=>array('method'=>'POST','content'=>$F,'ignore_errors'=>1,))));if(!$Vc){$h->error=$php_errormsg;return
+false;}libxml_use_internal_errors(true);$qj=simplexml_load_string($Vc);if(!$qj){$n=libxml_get_last_error();$h->error=$n->message;return
+false;}if($qj->Errors){$n=$qj->Errors->Error;$h->error="$n->Message ($n->Code)";return
+false;}$h->error='';$Zh=$wa."Result";return($qj->$Zh?$qj->$Zh:true);}function
+sdb_request_all($wa,$Zh,$Rf=array(),$ii=0){$H=array();$Gh=($ii?microtime(true):0);$z=(preg_match('~LIMIT\s+(\d+)\s*$~i',$Rf['SelectExpression'],$A)?$A[1]:0);do{$qj=sdb_request($wa,$Rf);if(!$qj)break;foreach($qj->$Zh
+as$rc)$H[]=$rc;if($z&&count($H)>=$z){$_GET["next"]=$qj->NextToken;break;}if($ii&µtime(true)-$Gh>$ii)return
+false;$Rf['NextToken']=$qj->NextToken;if($z)$Rf['SelectExpression']=preg_replace('~\d+\s*$~',$z-count($H),$Rf['SelectExpression']);}while($qj->NextToken);return$H;}$x="simpledb";$yf=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","IS NOT NULL");$md=array();$sd=array("count");$oc=array(array("json"));}$gc["mongo"]="MongoDB";if(isset($_GET["mongo"])){$kg=array("mongo","mongodb");define("DRIVER","mongo");if(class_exists('MongoDB')){class
+Min_DB{var$extension="Mongo",$server_info=MongoClient::VERSION,$error,$last_id,$_link,$_db;function
+connect($Ni,$Af){return@new
+MongoClient($Ni,$Af);}function
+query($F){return
+false;}function
+select_db($j){try{$this->_db=$this->_link->selectDB($j);return
+true;}catch(Exception$Cc){$this->error=$Cc->getMessage();return
+false;}}function
+quote($P){return$P;}}class
+Min_Result{var$num_rows,$_rows=array(),$_offset=0,$_charset=array();function
+__construct($G){foreach($G
+as$de){$I=array();foreach($de
+as$y=>$X){if(is_a($X,'MongoBinData'))$this->_charset[$y]=63;$I[$y]=(is_a($X,'MongoId')?'ObjectId("'.strval($X).'")':(is_a($X,'MongoDate')?gmdate("Y-m-d H:i:s",$X->sec)." GMT":(is_a($X,'MongoBinData')?$X->bin:(is_a($X,'MongoRegex')?strval($X):(is_object($X)?get_class($X):$X)))));}$this->_rows[]=$I;foreach($I
+as$y=>$X){if(!isset($this->_rows[0][$y]))$this->_rows[0][$y]=null;}}$this->num_rows=count($this->_rows);}function
+fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$y=>$X)$H[$y]=$I[$y];next($this->_rows);return$H;}function
+fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
+array_values($H);}function
+fetch_field(){$je=array_keys($this->_rows[0]);$B=$je[$this->_offset++];return(object)array('name'=>$B,'charsetnr'=>$this->_charset[$B],);}}class
+Min_Driver
+extends
+Min_SQL{public$ng="_id";function
+select($Q,$K,$Z,$pd,$Cf=array(),$z=1,$D=0,$pg=false){$K=($K==array("*")?array():array_fill_keys($K,true));$yh=array();foreach($Cf
+as$X){$X=preg_replace('~ DESC$~','',$X,1,$Fb);$yh[$X]=($Fb?-1:1);}return
+new
+Min_Result($this->_conn->_db->selectCollection($Q)->find(array(),$K)->sort($yh)->limit($z!=""?+$z:0)->skip($D*$z));}function
+insert($Q,$N){try{$H=$this->_conn->_db->selectCollection($Q)->insert($N);$this->_conn->errno=$H['code'];$this->_conn->error=$H['err'];$this->_conn->last_id=$N['_id'];return!$H['err'];}catch(Exception$Cc){$this->_conn->error=$Cc->getMessage();return
+false;}}}function
+get_databases($cd){global$h;$H=array();$Tb=$h->_link->listDBs();foreach($Tb['databases']as$l)$H[]=$l['name'];return$H;}function
+count_tables($k){global$h;$H=array();foreach($k
+as$l)$H[$l]=count($h->_link->selectDB($l)->getCollectionNames(true));return$H;}function
+tables_list(){global$h;return
+array_fill_keys($h->_db->getCollectionNames(true),'table');}function
+drop_databases($k){global$h;foreach($k
+as$l){$Pg=$h->_link->selectDB($l)->drop();if(!$Pg['ok'])return
+false;}return
+true;}function
+indexes($Q,$i=null){global$h;$H=array();foreach($h->_db->selectCollection($Q)->getIndexInfo()as$v){$ac=array();foreach($v["key"]as$e=>$T)$ac[]=($T==-1?'1':null);$H[$v["name"]]=array("type"=>($v["name"]=="_id_"?"PRIMARY":($v["unique"]?"UNIQUE":"INDEX")),"columns"=>array_keys($v["key"]),"lengths"=>array(),"descs"=>$ac,);}return$H;}function
+fields($Q){return
+fields_from_edit();}function
+found_rows($R,$Z){global$h;return$h->_db->selectCollection($_GET["select"])->count($Z);}$yf=array("=");}elseif(class_exists('MongoDB\Driver\Manager')){class
+Min_DB{var$extension="MongoDB",$server_info=MONGODB_VERSION,$error,$last_id;var$_link;var$_db,$_db_name;function
+connect($Ni,$Af){$lb='MongoDB\Driver\Manager';return
+new$lb($Ni,$Af);}function
+query($F){return
+false;}function
+select_db($j){$this->_db_name=$j;return
+true;}function
+quote($P){return$P;}}class
+Min_Result{var$num_rows,$_rows=array(),$_offset=0,$_charset=array();function
+__construct($G){foreach($G
+as$de){$I=array();foreach($de
+as$y=>$X){if(is_a($X,'MongoDB\BSON\Binary'))$this->_charset[$y]=63;$I[$y]=(is_a($X,'MongoDB\BSON\ObjectID')?'MongoDB\BSON\ObjectID("'.strval($X).'")':(is_a($X,'MongoDB\BSON\UTCDatetime')?$X->toDateTime()->format('Y-m-d H:i:s'):(is_a($X,'MongoDB\BSON\Binary')?$X->bin:(is_a($X,'MongoDB\BSON\Regex')?strval($X):(is_object($X)?json_encode($X,256):$X)))));}$this->_rows[]=$I;foreach($I
+as$y=>$X){if(!isset($this->_rows[0][$y]))$this->_rows[0][$y]=null;}}$this->num_rows=$G->count;}function
+fetch_assoc(){$I=current($this->_rows);if(!$I)return$I;$H=array();foreach($this->_rows[0]as$y=>$X)$H[$y]=$I[$y];next($this->_rows);return$H;}function
+fetch_row(){$H=$this->fetch_assoc();if(!$H)return$H;return
+array_values($H);}function
+fetch_field(){$je=array_keys($this->_rows[0]);$B=$je[$this->_offset++];return(object)array('name'=>$B,'charsetnr'=>$this->_charset[$B],);}}class
+Min_Driver
+extends
+Min_SQL{public$ng="_id";function
+select($Q,$K,$Z,$pd,$Cf=array(),$z=1,$D=0,$pg=false){global$h;$K=($K==array("*")?array():array_fill_keys($K,1));if(count($K)&&!isset($K['_id']))$K['_id']=0;$Z=where_to_query($Z);$yh=array();foreach($Cf
+as$X){$X=preg_replace('~ DESC$~','',$X,1,$Fb);$yh[$X]=($Fb?-1:1);}if(isset($_GET['limit'])&&is_numeric($_GET['limit'])&&$_GET['limit']>0)$z=$_GET['limit'];$z=min(200,max(1,(int)$z));$vh=$D*$z;$lb='MongoDB\Driver\Query';$F=new$lb($Z,array('projection'=>$K,'limit'=>$z,'skip'=>$vh,'sort'=>$yh));$Sg=$h->_link->executeQuery("$h->_db_name.$Q",$F);return
+new
+Min_Result($Sg);}function
+update($Q,$N,$zg,$z=0,$L="\n"){global$h;$l=$h->_db_name;$Z=sql_query_where_parser($zg);$lb='MongoDB\Driver\BulkWrite';$ab=new$lb(array());if(isset($N['_id']))unset($N['_id']);$Mg=array();foreach($N
+as$y=>$Y){if($Y=='NULL'){$Mg[$y]=1;unset($N[$y]);}}$Mi=array('$set'=>$N);if(count($Mg))$Mi['$unset']=$Mg;$ab->update($Z,$Mi,array('upsert'=>false));$Sg=$h->_link->executeBulkWrite("$l.$Q",$ab);$h->affected_rows=$Sg->getModifiedCount();return
+true;}function
+delete($Q,$zg,$z=0){global$h;$l=$h->_db_name;$Z=sql_query_where_parser($zg);$lb='MongoDB\Driver\BulkWrite';$ab=new$lb(array());$ab->delete($Z,array('limit'=>$z));$Sg=$h->_link->executeBulkWrite("$l.$Q",$ab);$h->affected_rows=$Sg->getDeletedCount();return
+true;}function
+insert($Q,$N){global$h;$l=$h->_db_name;$lb='MongoDB\Driver\BulkWrite';$ab=new$lb(array());if(isset($N['_id'])&&empty($N['_id']))unset($N['_id']);$ab->insert($N);$Sg=$h->_link->executeBulkWrite("$l.$Q",$ab);$h->affected_rows=$Sg->getInsertedCount();return
+true;}}function
+get_databases($cd){global$h;$H=array();$lb='MongoDB\Driver\Command';$tb=new$lb(array('listDatabases'=>1));$Sg=$h->_link->executeCommand('admin',$tb);foreach($Sg
+as$Tb){foreach($Tb->databases
+as$l)$H[]=$l->name;}return$H;}function
+count_tables($k){$H=array();return$H;}function
+tables_list(){global$h;$lb='MongoDB\Driver\Command';$tb=new$lb(array('listCollections'=>1));$Sg=$h->_link->executeCommand($h->_db_name,$tb);$rb=array();foreach($Sg
+as$G)$rb[$G->name]='table';return$rb;}function
+drop_databases($k){return
+false;}function
+indexes($Q,$i=null){global$h;$H=array();$lb='MongoDB\Driver\Command';$tb=new$lb(array('listIndexes'=>$Q));$Sg=$h->_link->executeCommand($h->_db_name,$tb);foreach($Sg
+as$v){$ac=array();$f=array();foreach(get_object_vars($v->key)as$e=>$T){$ac[]=($T==-1?'1':null);$f[]=$e;}$H[$v->name]=array("type"=>($v->name=="_id_"?"PRIMARY":(isset($v->unique)?"UNIQUE":"INDEX")),"columns"=>$f,"lengths"=>array(),"descs"=>$ac,);}return$H;}function
+fields($Q){$p=fields_from_edit();if(!count($p)){global$m;$G=$m->select($Q,array("*"),null,null,array(),10);while($I=$G->fetch_assoc()){foreach($I
+as$y=>$X){$I[$y]=null;$p[$y]=array("field"=>$y,"type"=>"string","null"=>($y!=$m->primary),"auto_increment"=>($y==$m->primary),"privileges"=>array("insert"=>1,"select"=>1,"update"=>1,),);}}}return$p;}function
+found_rows($R,$Z){global$h;$Z=where_to_query($Z);$lb='MongoDB\Driver\Command';$tb=new$lb(array('count'=>$R['Name'],'query'=>$Z));$Sg=$h->_link->executeCommand($h->_db_name,$tb);$qi=$Sg->toArray();return$qi[0]->n;}function
+sql_query_where_parser($zg){$zg=trim(preg_replace('/WHERE[\s]?[(]?\(?/','',$zg));$zg=preg_replace('/\)\)\)$/',')',$zg);$nj=explode(' AND ',$zg);$oj=explode(') OR (',$zg);$Z=array();foreach($nj
+as$lj)$Z[]=trim($lj);if(count($oj)==1)$oj=array();elseif(count($oj)>1)$Z=array();return
+where_to_query($Z,$oj);}function
+where_to_query($jj=array(),$kj=array()){global$b;$Ob=array();foreach(array('and'=>$jj,'or'=>$kj)as$T=>$Z){if(is_array($Z)){foreach($Z
+as$Jc){list($ob,$wf,$X)=explode(" ",$Jc,3);if($ob=="_id"){$X=str_replace('MongoDB\BSON\ObjectID("',"",$X);$X=str_replace('")',"",$X);$lb='MongoDB\BSON\ObjectID';$X=new$lb($X);}if(!in_array($wf,$b->operators))continue;if(preg_match('~^\(f\)(.+)~',$wf,$A)){$X=(float)$X;$wf=$A[1];}elseif(preg_match('~^\(date\)(.+)~',$wf,$A)){$Qb=new
+DateTime($X);$lb='MongoDB\BSON\UTCDatetime';$X=new$lb($Qb->getTimestamp()*1000);$wf=$A[1];}switch($wf){case'=':$wf='$eq';break;case'!=':$wf='$ne';break;case'>':$wf='$gt';break;case'<':$wf='$lt';break;case'>=':$wf='$gte';break;case'<=':$wf='$lte';break;case'regex':$wf='$regex';break;default:continue
+2;}if($T=='and')$Ob['$and'][]=array($ob=>array($wf=>$X));elseif($T=='or')$Ob['$or'][]=array($ob=>array($wf=>$X));}}}return$Ob;}$yf=array("=","!=",">","<",">=","<=","regex","(f)=","(f)!=","(f)>","(f)<","(f)>=","(f)<=","(date)=","(date)!=","(date)>","(date)<","(date)>=","(date)<=",);}function
+table($u){return$u;}function
+idf_escape($u){return$u;}function
+table_status($B="",$Qc=false){$H=array();foreach(tables_list()as$Q=>$T){$H[$Q]=array("Name"=>$Q);if($B==$Q)return$H[$Q];}return$H;}function
+create_database($l,$d){return
+true;}function
+last_id(){global$h;return$h->last_id;}function
+error(){global$h;return
+h($h->error);}function
+collations(){return
+array();}function
+logged_user(){global$b;$Jb=$b->credentials();return$Jb[1];}function
+connect(){global$b;$h=new
+Min_DB;list($M,$V,$E)=$b->credentials();$Af=array();if($V.$E!=""){$Af["username"]=$V;$Af["password"]=$E;}$l=$b->database();if($l!="")$Af["db"]=$l;if(($Ma=getenv("MONGO_AUTH_SOURCE")))$Af["authSource"]=$Ma;try{$h->_link=$h->connect("mongodb://$M",$Af);if($E!=""){$Af["password"]="";try{$h->connect("mongodb://$M",$Af);return
+lang(22);}catch(Exception$Cc){}}return$h;}catch(Exception$Cc){return$Cc->getMessage();}}function
+alter_indexes($Q,$c){global$h;foreach($c
+as$X){list($T,$B,$N)=$X;if($N=="DROP")$H=$h->_db->command(array("deleteIndexes"=>$Q,"index"=>$B));else{$f=array();foreach($N
+as$e){$e=preg_replace('~ DESC$~','',$e,1,$Fb);$f[$e]=($Fb?-1:1);}$H=$h->_db->selectCollection($Q)->ensureIndex($f,array("unique"=>($T=="UNIQUE"),"name"=>$B,));}if($H['errmsg']){$h->error=$H['errmsg'];return
+false;}}return
+true;}function
+support($Rc){return
+preg_match("~database|indexes|descidx~",$Rc);}function
+db_collation($l,$qb){}function
+information_schema(){}function
+is_view($R){}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+foreign_keys($Q){return
+array();}function
+fk_support($R){}function
+engines(){return
+array();}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){global$h;if($Q==""){$h->_db->createCollection($B);return
+true;}}function
+drop_tables($S){global$h;foreach($S
+as$Q){$Pg=$h->_db->selectCollection($Q)->drop();if(!$Pg['ok'])return
+false;}return
+true;}function
+truncate_tables($S){global$h;foreach($S
+as$Q){$Pg=$h->_db->selectCollection($Q)->remove();if(!$Pg['ok'])return
+false;}return
+true;}$x="mongo";$md=array();$sd=array();$oc=array(array("json"));}$gc["elastic"]="Elasticsearch (beta)";if(isset($_GET["elastic"])){$kg=array("json + allow_url_fopen");define("DRIVER","elastic");if(function_exists('json_decode')&&ini_bool('allow_url_fopen')){class
+Min_DB{var$extension="JSON",$server_info,$errno,$error,$_url;function
+rootQuery($bg,$Ab=array(),$Ue='GET'){@ini_set('track_errors',1);$Vc=@file_get_contents("$this->_url/".ltrim($bg,'/'),false,stream_context_create(array('http'=>array('method'=>$Ue,'content'=>$Ab===null?$Ab:json_encode($Ab),'header'=>'Content-Type: application/json','ignore_errors'=>1,))));if(!$Vc){$this->error=$php_errormsg;return$Vc;}if(!preg_match('~^HTTP/[0-9.]+ 2~i',$http_response_header[0])){$this->error=$Vc;return
+false;}$H=json_decode($Vc,true);if($H===null){$this->errno=json_last_error();if(function_exists('json_last_error_msg'))$this->error=json_last_error_msg();else{$_b=get_defined_constants(true);foreach($_b['json']as$B=>$Y){if($Y==$this->errno&&preg_match('~^JSON_ERROR_~',$B)){$this->error=$B;break;}}}}return$H;}function
+query($bg,$Ab=array(),$Ue='GET'){return$this->rootQuery(($this->_db!=""?"$this->_db/":"/").ltrim($bg,'/'),$Ab,$Ue);}function
+connect($M,$V,$E){preg_match('~^(https?://)?(.*)~',$M,$A);$this->_url=($A[1]?$A[1]:"http://")."$V:$E@$A[2]";$H=$this->query('');if($H)$this->server_info=$H['version']['number'];return(bool)$H;}function
+select_db($j){$this->_db=$j;return
+true;}function
+quote($P){return$P;}}class
+Min_Result{var$num_rows,$_rows;function
+__construct($J){$this->num_rows=count($J);$this->_rows=$J;reset($this->_rows);}function
+fetch_assoc(){$H=current($this->_rows);next($this->_rows);return$H;}function
+fetch_row(){return
+array_values($this->fetch_assoc());}}}class
+Min_Driver
+extends
+Min_SQL{function
+select($Q,$K,$Z,$pd,$Cf=array(),$z=1,$D=0,$pg=false){global$b;$Ob=array();$F="$Q/_search";if($K!=array("*"))$Ob["fields"]=$K;if($Cf){$yh=array();foreach($Cf
+as$ob){$ob=preg_replace('~ DESC$~','',$ob,1,$Fb);$yh[]=($Fb?array($ob=>"desc"):$ob);}$Ob["sort"]=$yh;}if($z){$Ob["size"]=+$z;if($D)$Ob["from"]=($D*$z);}foreach($Z
+as$X){list($ob,$wf,$X)=explode(" ",$X,3);if($ob=="_id")$Ob["query"]["ids"]["values"][]=$X;elseif($ob.$X!=""){$di=array("term"=>array(($ob!=""?$ob:"_all")=>$X));if($wf=="=")$Ob["query"]["filtered"]["filter"]["and"][]=$di;else$Ob["query"]["filtered"]["query"]["bool"]["must"][]=$di;}}if($Ob["query"]&&!$Ob["query"]["filtered"]["query"]&&!$Ob["query"]["ids"])$Ob["query"]["filtered"]["query"]=array("match_all"=>array());$Gh=microtime(true);$fh=$this->_conn->query($F,$Ob);if($pg)echo$b->selectQuery("$F: ".json_encode($Ob),$Gh,!$fh);if(!$fh)return
+false;$H=array();foreach($fh['hits']['hits']as$Bd){$I=array();if($K==array("*"))$I["_id"]=$Bd["_id"];$p=$Bd['_source'];if($K!=array("*")){$p=array();foreach($K
+as$y)$p[$y]=$Bd['fields'][$y];}foreach($p
+as$y=>$X){if($Ob["fields"])$X=$X[0];$I[$y]=(is_array($X)?json_encode($X):$X);}$H[]=$I;}return
+new
+Min_Result($H);}function
+update($T,$Dg,$zg,$z=0,$L="\n"){$Zf=preg_split('~ *= *~',$zg);if(count($Zf)==2){$t=trim($Zf[1]);$F="$T/$t";return$this->_conn->query($F,$Dg,'POST');}return
+false;}function
+insert($T,$Dg){$t="";$F="$T/$t";$Pg=$this->_conn->query($F,$Dg,'POST');$this->_conn->last_id=$Pg['_id'];return$Pg['created'];}function
+delete($T,$zg,$z=0){$Gd=array();if(is_array($_GET["where"])&&$_GET["where"]["_id"])$Gd[]=$_GET["where"]["_id"];if(is_array($_POST['check'])){foreach($_POST['check']as$eb){$Zf=preg_split('~ *= *~',$eb);if(count($Zf)==2)$Gd[]=trim($Zf[1]);}}$this->_conn->affected_rows=0;foreach($Gd
+as$t){$F="{$T}/{$t}";$Pg=$this->_conn->query($F,'{}','DELETE');if(is_array($Pg)&&$Pg['found']==true)$this->_conn->affected_rows++;}return$this->_conn->affected_rows;}}function
+connect(){global$b;$h=new
+Min_DB;list($M,$V,$E)=$b->credentials();if($E!=""&&$h->connect($M,$V,""))return
+lang(22);if($h->connect($M,$V,$E))return$h;return$h->error;}function
+support($Rc){return
+preg_match("~database|table|columns~",$Rc);}function
+logged_user(){global$b;$Jb=$b->credentials();return$Jb[1];}function
+get_databases(){global$h;$H=$h->rootQuery('_aliases');if($H){$H=array_keys($H);sort($H,SORT_STRING);}return$H;}function
+collations(){return
+array();}function
+db_collation($l,$qb){}function
+engines(){return
+array();}function
+count_tables($k){global$h;$H=array();$G=$h->query('_stats');if($G&&$G['indices']){$Od=$G['indices'];foreach($Od
+as$Nd=>$Hh){$Md=$Hh['total']['indexing'];$H[$Nd]=$Md['index_total'];}}return$H;}function
+tables_list(){global$h;$H=$h->query('_mapping');if($H)$H=array_fill_keys(array_keys($H[$h->_db]["mappings"]),'table');return$H;}function
+table_status($B="",$Qc=false){global$h;$fh=$h->query("_search",array("size"=>0,"aggregations"=>array("count_by_type"=>array("terms"=>array("field"=>"_type")))),"POST");$H=array();if($fh){$S=$fh["aggregations"]["count_by_type"]["buckets"];foreach($S
+as$Q){$H[$Q["key"]]=array("Name"=>$Q["key"],"Engine"=>"table","Rows"=>$Q["doc_count"],);if($B!=""&&$B==$Q["key"])return$H[$B];}}return$H;}function
+error(){global$h;return
+h($h->error);}function
+information_schema(){}function
+is_view($R){}function
+indexes($Q,$i=null){return
+array(array("type"=>"PRIMARY","columns"=>array("_id")),);}function
+fields($Q){global$h;$G=$h->query("$Q/_mapping");$H=array();if($G){$Ce=$G[$Q]['properties'];if(!$Ce)$Ce=$G[$h->_db]['mappings'][$Q]['properties'];if($Ce){foreach($Ce
+as$B=>$o){$H[$B]=array("field"=>$B,"full_type"=>$o["type"],"type"=>$o["type"],"privileges"=>array("insert"=>1,"select"=>1,"update"=>1),);if($o["properties"]){unset($H[$B]["privileges"]["insert"]);unset($H[$B]["privileges"]["update"]);}}}}return$H;}function
+foreign_keys($Q){return
+array();}function
+table($u){return$u;}function
+idf_escape($u){return$u;}function
+convert_field($o){}function
+unconvert_field($o,$H){return$H;}function
+fk_support($R){}function
+found_rows($R,$Z){return
+null;}function
+create_database($l){global$h;return$h->rootQuery(urlencode($l),null,'PUT');}function
+drop_databases($k){global$h;return$h->rootQuery(urlencode(implode(',',$k)),array(),'DELETE');}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){global$h;$vg=array();foreach($p
+as$Oc){$Tc=trim($Oc[1][0]);$Uc=trim($Oc[1][1]?$Oc[1][1]:"text");$vg[$Tc]=array('type'=>$Uc);}if(!empty($vg))$vg=array('properties'=>$vg);return$h->query("_mapping/{$B}",$vg,'PUT');}function
+drop_tables($S){global$h;$H=true;foreach($S
+as$Q)$H=$H&&$h->query(urlencode($Q),array(),'DELETE');return$H;}function
+last_id(){global$h;return$h->last_id;}$x="elastic";$yf=array("=","query");$md=array();$sd=array();$oc=array(array("json"));$U=array();$Kh=array();foreach(array(lang(27)=>array("long"=>3,"integer"=>5,"short"=>8,"byte"=>10,"double"=>20,"float"=>66,"half_float"=>12,"scaled_float"=>21),lang(28)=>array("date"=>10),lang(25)=>array("string"=>65535,"text"=>65535),lang(29)=>array("binary"=>255),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}}$gc["clickhouse"]="ClickHouse (alpha)";if(isset($_GET["clickhouse"])){define("DRIVER","clickhouse");class
+Min_DB{var$extension="JSON",$server_info,$errno,$_result,$error,$_url;var$_db='default';function
+rootQuery($l,$F){@ini_set('track_errors',1);$Vc=@file_get_contents("$this->_url/?database=$l",false,stream_context_create(array('http'=>array('method'=>'POST','content'=>$this->isQuerySelectLike($F)?"$F FORMAT JSONCompact":$F,'header'=>'Content-type: application/x-www-form-urlencoded','ignore_errors'=>1,))));if($Vc===false){$this->error=$php_errormsg;return$Vc;}if(!preg_match('~^HTTP/[0-9.]+ 2~i',$http_response_header[0])){$this->error=$Vc;return
+false;}$H=json_decode($Vc,true);if($H===null){if(!$this->isQuerySelectLike($F)&&$Vc==='')return
+true;$this->errno=json_last_error();if(function_exists('json_last_error_msg'))$this->error=json_last_error_msg();else{$_b=get_defined_constants(true);foreach($_b['json']as$B=>$Y){if($Y==$this->errno&&preg_match('~^JSON_ERROR_~',$B)){$this->error=$B;break;}}}}return
+new
+Min_Result($H);}function
+isQuerySelectLike($F){return(bool)preg_match('~^(select|show)~i',$F);}function
+query($F){return$this->rootQuery($this->_db,$F);}function
+connect($M,$V,$E){preg_match('~^(https?://)?(.*)~',$M,$A);$this->_url=($A[1]?$A[1]:"http://")."$V:$E@$A[2]";$H=$this->query('SELECT 1');return(bool)$H;}function
+select_db($j){$this->_db=$j;return
+true;}function
+quote($P){return"'".addcslashes($P,"\\'")."'";}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+result($F,$o=0){$G=$this->query($F);return$G['data'];}}class
+Min_Result{var$num_rows,$_rows,$columns,$meta,$_offset=0;function
+__construct($G){$this->num_rows=$G['rows'];$this->_rows=$G['data'];$this->meta=$G['meta'];$this->columns=array_column($this->meta,'name');reset($this->_rows);}function
+fetch_assoc(){$I=current($this->_rows);next($this->_rows);return$I===false?false:array_combine($this->columns,$I);}function
+fetch_row(){$I=current($this->_rows);next($this->_rows);return$I;}function
+fetch_field(){$e=$this->_offset++;$H=new
+stdClass;if($ecolumns)){$H->name=$this->meta[$e]['name'];$H->orgname=$H->name;$H->type=$this->meta[$e]['type'];}return$H;}}class
+Min_Driver
+extends
+Min_SQL{function
+delete($Q,$zg,$z=0){if($zg==='')$zg='WHERE 1=1';return
+queries("ALTER TABLE ".table($Q)." DELETE $zg");}function
+update($Q,$N,$zg,$z=0,$L="\n"){$Yi=array();foreach($N
+as$y=>$X)$Yi[]="$y = $X";$F=$L.implode(",$L",$Yi);return
+queries("ALTER TABLE ".table($Q)." UPDATE $F$zg");}}function
+idf_escape($u){return"`".str_replace("`","``",$u)."`";}function
+table($u){return
+idf_escape($u);}function
+explain($h,$F){return'';}function
+found_rows($R,$Z){$J=get_vals("SELECT COUNT(*) FROM ".idf_escape($R["Name"]).($Z?" WHERE ".implode(" AND ",$Z):""));return
+empty($J)?false:$J[0];}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){$c=$Cf=array();foreach($p
+as$o){if($o[1][2]===" NULL")$o[1][1]=" Nullable({$o[1][1]})";elseif($o[1][2]===' NOT NULL')$o[1][2]='';if($o[1][3])$o[1][3]='';$c[]=($o[1]?($Q!=""?($o[0]!=""?"MODIFY COLUMN ":"ADD COLUMN "):" ").implode($o[1]):"DROP COLUMN ".idf_escape($o[0]));$Cf[]=$o[1][0];}$c=array_merge($c,$ed);$O=($wc?" ENGINE ".$wc:"");if($Q=="")return
+queries("CREATE TABLE ".table($B)." (\n".implode(",\n",$c)."\n)$O$Xf".' ORDER BY ('.implode(',',$Cf).')');if($Q!=$B){$G=queries("RENAME TABLE ".table($Q)." TO ".table($B));if($c)$Q=$B;else
+return$G;}if($O)$c[]=ltrim($O);return($c||$Xf?queries("ALTER TABLE ".table($Q)."\n".implode(",\n",$c).$Xf):true);}function
+truncate_tables($S){return
+apply_queries("TRUNCATE TABLE",$S);}function
+drop_views($dj){return
+drop_tables($dj);}function
+drop_tables($S){return
+apply_queries("DROP TABLE",$S);}function
+connect(){global$b;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2]))return$h;return$h->error;}function
+get_databases($cd){global$h;$G=get_rows('SHOW DATABASES');$H=array();foreach($G
+as$I)$H[]=$I['name'];sort($H);return$H;}function
+limit($F,$Z,$z,$C=0,$L=" "){return" $F$Z".($z!==null?$L."LIMIT $z".($C?", $C":""):"");}function
+limit1($Q,$F,$Z,$L="\n"){return
+limit($F,$Z,1,0,$L);}function
+db_collation($l,$qb){}function
+engines(){return
+array('MergeTree');}function
+logged_user(){global$b;$Jb=$b->credentials();return$Jb[1];}function
+tables_list(){$G=get_rows('SHOW TABLES');$H=array();foreach($G
+as$I)$H[$I['name']]='table';ksort($H);return$H;}function
+count_tables($k){return
+array();}function
+table_status($B="",$Qc=false){global$h;$H=array();$S=get_rows("SELECT name, engine FROM system.tables WHERE database = ".q($h->_db));foreach($S
+as$Q){$H[$Q['name']]=array('Name'=>$Q['name'],'Engine'=>$Q['engine'],);if($B===$Q['name'])return$H[$Q['name']];}return$H;}function
+is_view($R){return
+false;}function
+fk_support($R){return
+false;}function
+convert_field($o){}function
+unconvert_field($o,$H){if(in_array($o['type'],array("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64","Float32","Float64")))return"to$o[type]($H)";return$H;}function
+fields($Q){$H=array();$G=get_rows("SELECT name, type, default_expression FROM system.columns WHERE ".idf_escape('table')." = ".q($Q));foreach($G
+as$I){$T=trim($I['type']);$if=strpos($T,'Nullable(')===0;$H[trim($I['name'])]=array("field"=>trim($I['name']),"full_type"=>$T,"type"=>$T,"default"=>trim($I['default_expression']),"null"=>$if,"auto_increment"=>'0',"privileges"=>array("insert"=>1,"select"=>1,"update"=>0),);}return$H;}function
+indexes($Q,$i=null){return
+array();}function
+foreign_keys($Q){return
+array();}function
+collations(){return
+array();}function
+information_schema($l){return
+false;}function
+error(){global$h;return
+h($h->error);}function
+types(){return
+array();}function
+schemas(){return
+array();}function
+get_schema(){return"";}function
+set_schema($dh){return
+true;}function
+auto_increment(){return'';}function
+last_id(){return
+0;}function
+support($Rc){return
+preg_match("~^(columns|sql|status|table|drop_col)$~",$Rc);}$x="clickhouse";$U=array();$Kh=array();foreach(array(lang(27)=>array("Int8"=>3,"Int16"=>5,"Int32"=>10,"Int64"=>19,"UInt8"=>3,"UInt16"=>5,"UInt32"=>10,"UInt64"=>20,"Float32"=>7,"Float64"=>16,'Decimal'=>38,'Decimal32'=>9,'Decimal64'=>18,'Decimal128'=>38),lang(28)=>array("Date"=>13,"DateTime"=>20),lang(25)=>array("String"=>0),lang(29)=>array("FixedString"=>0),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}$Li=array();$yf=array("=","<",">","<=",">=","!=","~","!~","LIKE","LIKE %%","IN","IS NULL","NOT LIKE","NOT IN","IS NOT NULL","SQL");$md=array();$sd=array("avg","count","count distinct","max","min","sum");$oc=array();}$gc=array("server"=>"MySQL")+$gc;if(!defined("DRIVER")){$kg=array("MySQLi","MySQL","PDO_MySQL");define("DRIVER","server");if(extension_loaded("mysqli")){class
+Min_DB
+extends
+MySQLi{var$extension="MySQLi";function
+__construct(){parent::init();}function
+connect($M="",$V="",$E="",$j=null,$gg=null,$xh=null){global$b;mysqli_report(MYSQLI_REPORT_OFF);list($Cd,$gg)=explode(":",$M,2);$Fh=$b->connectSsl();if($Fh)$this->ssl_set($Fh['key'],$Fh['cert'],$Fh['ca'],'','');$H=@$this->real_connect(($M!=""?$Cd:ini_get("mysqli.default_host")),($M.$V!=""?$V:ini_get("mysqli.default_user")),($M.$V.$E!=""?$E:ini_get("mysqli.default_pw")),$j,(is_numeric($gg)?$gg:ini_get("mysqli.default_port")),(!is_numeric($gg)?$gg:$xh),($Fh?64:0));$this->options(MYSQLI_OPT_LOCAL_INFILE,false);return$H;}function
+set_charset($db){if(parent::set_charset($db))return
+true;parent::set_charset('utf8');return$this->query("SET NAMES $db");}function
+result($F,$o=0){$G=$this->query($F);if(!$G)return
+false;$I=$G->fetch_array();return$I[$o];}function
+quote($P){return"'".$this->escape_string($P)."'";}}}elseif(extension_loaded("mysql")&&!((ini_bool("sql.safe_mode")||ini_bool("mysql.allow_local_infile"))&&extension_loaded("pdo_mysql"))){class
+Min_DB{var$extension="MySQL",$server_info,$affected_rows,$errno,$error,$_link,$_result;function
+connect($M,$V,$E){if(ini_bool("mysql.allow_local_infile")){$this->error=lang(32,"'mysql.allow_local_infile'","MySQLi","PDO_MySQL");return
+false;}$this->_link=@mysql_connect(($M!=""?$M:ini_get("mysql.default_host")),("$M$V"!=""?$V:ini_get("mysql.default_user")),("$M$V$E"!=""?$E:ini_get("mysql.default_password")),true,131072);if($this->_link)$this->server_info=mysql_get_server_info($this->_link);else$this->error=mysql_error();return(bool)$this->_link;}function
+set_charset($db){if(function_exists('mysql_set_charset')){if(mysql_set_charset($db,$this->_link))return
+true;mysql_set_charset('utf8',$this->_link);}return$this->query("SET NAMES $db");}function
+quote($P){return"'".mysql_real_escape_string($P,$this->_link)."'";}function
+select_db($j){return
+mysql_select_db($j,$this->_link);}function
+query($F,$Fi=false){$G=@($Fi?mysql_unbuffered_query($F,$this->_link):mysql_query($F,$this->_link));$this->error="";if(!$G){$this->errno=mysql_errno($this->_link);$this->error=mysql_error($this->_link);return
+false;}if($G===true){$this->affected_rows=mysql_affected_rows($this->_link);$this->info=mysql_info($this->_link);return
+true;}return
+new
+Min_Result($G);}function
+multi_query($F){return$this->_result=$this->query($F);}function
+store_result(){return$this->_result;}function
+next_result(){return
+false;}function
+result($F,$o=0){$G=$this->query($F);if(!$G||!$G->num_rows)return
+false;return
+mysql_result($G->_result,0,$o);}}class
+Min_Result{var$num_rows,$_result,$_offset=0;function
+__construct($G){$this->_result=$G;$this->num_rows=mysql_num_rows($G);}function
+fetch_assoc(){return
+mysql_fetch_assoc($this->_result);}function
+fetch_row(){return
+mysql_fetch_row($this->_result);}function
+fetch_field(){$H=mysql_fetch_field($this->_result,$this->_offset++);$H->orgtable=$H->table;$H->orgname=$H->name;$H->charsetnr=($H->blob?63:0);return$H;}function
+__destruct(){mysql_free_result($this->_result);}}}elseif(extension_loaded("pdo_mysql")){class
+Min_DB
+extends
+Min_PDO{var$extension="PDO_MySQL";function
+connect($M,$V,$E){global$b;$Af=array(PDO::MYSQL_ATTR_LOCAL_INFILE=>false);$Fh=$b->connectSsl();if($Fh){if(!empty($Fh['key']))$Af[PDO::MYSQL_ATTR_SSL_KEY]=$Fh['key'];if(!empty($Fh['cert']))$Af[PDO::MYSQL_ATTR_SSL_CERT]=$Fh['cert'];if(!empty($Fh['ca']))$Af[PDO::MYSQL_ATTR_SSL_CA]=$Fh['ca'];}$this->dsn("mysql:charset=utf8;host=".str_replace(":",";unix_socket=",preg_replace('~:(\d)~',';port=\1',$M)),$V,$E,$Af);return
+true;}function
+set_charset($db){$this->query("SET NAMES $db");}function
+select_db($j){return$this->query("USE ".idf_escape($j));}function
+query($F,$Fi=false){$this->setAttribute(1000,!$Fi);return
+parent::query($F,$Fi);}}}class
+Min_Driver
+extends
+Min_SQL{function
+insert($Q,$N){return($N?parent::insert($Q,$N):queries("INSERT INTO ".table($Q)." ()\nVALUES ()"));}function
+insertUpdate($Q,$J,$ng){$f=array_keys(reset($J));$lg="INSERT INTO ".table($Q)." (".implode(", ",$f).") VALUES\n";$Yi=array();foreach($f
+as$y)$Yi[$y]="$y = VALUES($y)";$Nh="\nON DUPLICATE KEY UPDATE ".implode(", ",$Yi);$Yi=array();$we=0;foreach($J
+as$N){$Y="(".implode(", ",$N).")";if($Yi&&(strlen($lg)+$we+strlen($Y)+strlen($Nh)>1e6)){if(!queries($lg.implode(",\n",$Yi).$Nh))return
+false;$Yi=array();$we=0;}$Yi[]=$Y;$we+=strlen($Y)+2;}return
+queries($lg.implode(",\n",$Yi).$Nh);}function
+slowQuery($F,$ii){if(min_version('5.7.8','10.1.2')){if(preg_match('~MariaDB~',$this->_conn->server_info))return"SET STATEMENT max_statement_time=$ii FOR $F";elseif(preg_match('~^(SELECT\b)(.+)~is',$F,$A))return"$A[1] /*+ MAX_EXECUTION_TIME(".($ii*1000).") */ $A[2]";}}function
+convertSearch($u,$X,$o){return(preg_match('~char|text|enum|set~',$o["type"])&&!preg_match("~^utf8~",$o["collation"])&&preg_match('~[\x80-\xFF]~',$X['val'])?"CONVERT($u USING ".charset($this->_conn).")":$u);}function
+warnings(){$G=$this->_conn->query("SHOW WARNINGS");if($G&&$G->num_rows){ob_start();select($G);return
+ob_get_clean();}}function
+tableHelp($B){$De=preg_match('~MariaDB~',$this->_conn->server_info);if(information_schema(DB))return
+strtolower(($De?"information-schema-$B-table/":str_replace("_","-",$B)."-table.html"));if(DB=="mysql")return($De?"mysql$B-table/":"system-database.html");}}function
+idf_escape($u){return"`".str_replace("`","``",$u)."`";}function
+table($u){return
+idf_escape($u);}function
+connect(){global$b,$U,$Kh;$h=new
+Min_DB;$Jb=$b->credentials();if($h->connect($Jb[0],$Jb[1],$Jb[2])){$h->set_charset(charset($h));$h->query("SET sql_quote_show_create = 1, autocommit = 1");if(min_version('5.7.8',10.2,$h)){$Kh[lang(25)][]="json";$U["json"]=4294967295;}return$h;}$H=$h->error;if(function_exists('iconv')&&!is_utf8($H)&&strlen($bh=iconv("windows-1250","utf-8",$H))>strlen($H))$H=$bh;return$H;}function
+get_databases($cd){$H=get_session("dbs");if($H===null){$F=(min_version(5)?"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA ORDER BY SCHEMA_NAME":"SHOW DATABASES");$H=($cd?slow_query($F):get_vals($F));restart_session();set_session("dbs",$H);stop_session();}return$H;}function
+limit($F,$Z,$z,$C=0,$L=" "){return" $F$Z".($z!==null?$L."LIMIT $z".($C?" OFFSET $C":""):"");}function
+limit1($Q,$F,$Z,$L="\n"){return
+limit($F,$Z,1,0,$L);}function
+db_collation($l,$qb){global$h;$H=null;$Gb=$h->result("SHOW CREATE DATABASE ".idf_escape($l),1);if(preg_match('~ COLLATE ([^ ]+)~',$Gb,$A))$H=$A[1];elseif(preg_match('~ CHARACTER SET ([^ ]+)~',$Gb,$A))$H=$qb[$A[1]][-1];return$H;}function
+engines(){$H=array();foreach(get_rows("SHOW ENGINES")as$I){if(preg_match("~YES|DEFAULT~",$I["Support"]))$H[]=$I["Engine"];}return$H;}function
+logged_user(){global$h;return$h->result("SELECT USER()");}function
+tables_list(){return
+get_key_vals(min_version(5)?"SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ORDER BY TABLE_NAME":"SHOW TABLES");}function
+count_tables($k){$H=array();foreach($k
+as$l)$H[$l]=count(get_vals("SHOW TABLES IN ".idf_escape($l)));return$H;}function
+table_status($B="",$Qc=false){$H=array();foreach(get_rows($Qc&&min_version(5)?"SELECT TABLE_NAME AS Name, ENGINE AS Engine, TABLE_COMMENT AS Comment FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ".($B!=""?"AND TABLE_NAME = ".q($B):"ORDER BY Name"):"SHOW TABLE STATUS".($B!=""?" LIKE ".q(addcslashes($B,"%_\\")):""))as$I){if($I["Engine"]=="InnoDB")$I["Comment"]=preg_replace('~(?:(.+); )?InnoDB free: .*~','\1',$I["Comment"]);if(!isset($I["Engine"]))$I["Comment"]="";if($B!="")return$I;$H[$I["Name"]]=$I;}return$H;}function
+is_view($R){return$R["Engine"]===null;}function
+fk_support($R){return
+preg_match('~InnoDB|IBMDB2I~i',$R["Engine"])||(preg_match('~NDB~i',$R["Engine"])&&min_version(5.6));}function
+fields($Q){$H=array();foreach(get_rows("SHOW FULL COLUMNS FROM ".table($Q))as$I){preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~',$I["Type"],$A);$H[$I["Field"]]=array("field"=>$I["Field"],"full_type"=>$I["Type"],"type"=>$A[1],"length"=>$A[2],"unsigned"=>ltrim($A[3].$A[4]),"default"=>($I["Default"]!=""||preg_match("~char|set~",$A[1])?$I["Default"]:null),"null"=>($I["Null"]=="YES"),"auto_increment"=>($I["Extra"]=="auto_increment"),"on_update"=>(preg_match('~^on update (.+)~i',$I["Extra"],$A)?$A[1]:""),"collation"=>$I["Collation"],"privileges"=>array_flip(preg_split('~, *~',$I["Privileges"])),"comment"=>$I["Comment"],"primary"=>($I["Key"]=="PRI"),"generated"=>preg_match('~^(VIRTUAL|PERSISTENT|STORED)~',$I["Extra"]),);}return$H;}function
+indexes($Q,$i=null){$H=array();foreach(get_rows("SHOW INDEX FROM ".table($Q),$i)as$I){$B=$I["Key_name"];$H[$B]["type"]=($B=="PRIMARY"?"PRIMARY":($I["Index_type"]=="FULLTEXT"?"FULLTEXT":($I["Non_unique"]?($I["Index_type"]=="SPATIAL"?"SPATIAL":"INDEX"):"UNIQUE")));$H[$B]["columns"][]=$I["Column_name"];$H[$B]["lengths"][]=($I["Index_type"]=="SPATIAL"?null:$I["Sub_part"]);$H[$B]["descs"][]=null;}return$H;}function
+foreign_keys($Q){global$h,$tf;static$dg='(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';$H=array();$Hb=$h->result("SHOW CREATE TABLE ".table($Q),1);if($Hb){preg_match_all("~CONSTRAINT ($dg) FOREIGN KEY ?\\(((?:$dg,? ?)+)\\) REFERENCES ($dg)(?:\\.($dg))? \\(((?:$dg,? ?)+)\\)(?: ON DELETE ($tf))?(?: ON UPDATE ($tf))?~",$Hb,$Ge,PREG_SET_ORDER);foreach($Ge
+as$A){preg_match_all("~$dg~",$A[2],$zh);preg_match_all("~$dg~",$A[5],$ai);$H[idf_unescape($A[1])]=array("db"=>idf_unescape($A[4]!=""?$A[3]:$A[4]),"table"=>idf_unescape($A[4]!=""?$A[4]:$A[3]),"source"=>array_map('idf_unescape',$zh[0]),"target"=>array_map('idf_unescape',$ai[0]),"on_delete"=>($A[6]?$A[6]:"RESTRICT"),"on_update"=>($A[7]?$A[7]:"RESTRICT"),);}}return$H;}function
+view($B){global$h;return
+array("select"=>preg_replace('~^(?:[^`]|`[^`]*`)*\s+AS\s+~isU','',$h->result("SHOW CREATE VIEW ".table($B),1)));}function
+collations(){$H=array();foreach(get_rows("SHOW COLLATION")as$I){if($I["Default"])$H[$I["Charset"]][-1]=$I["Collation"];else$H[$I["Charset"]][]=$I["Collation"];}ksort($H);foreach($H
+as$y=>$X)asort($H[$y]);return$H;}function
+information_schema($l){return(min_version(5)&&$l=="information_schema")||(min_version(5.5)&&$l=="performance_schema");}function
+error(){global$h;return
+h(preg_replace('~^You have an error.*syntax to use~U',"Syntax error",$h->error));}function
+create_database($l,$d){return
+queries("CREATE DATABASE ".idf_escape($l).($d?" COLLATE ".q($d):""));}function
+drop_databases($k){$H=apply_queries("DROP DATABASE",$k,'idf_escape');restart_session();set_session("dbs",null);return$H;}function
+rename_database($B,$d){$H=false;if(create_database($B,$d)){$Ng=array();foreach(tables_list()as$Q=>$T)$Ng[]=table($Q)." TO ".idf_escape($B).".".table($Q);$H=(!$Ng||queries("RENAME TABLE ".implode(", ",$Ng)));if($H)queries("DROP DATABASE ".idf_escape(DB));restart_session();set_session("dbs",null);}return$H;}function
+auto_increment(){$Oa=" PRIMARY KEY";if($_GET["create"]!=""&&$_POST["auto_increment_col"]){foreach(indexes($_GET["create"])as$v){if(in_array($_POST["fields"][$_POST["auto_increment_col"]]["orig"],$v["columns"],true)){$Oa="";break;}if($v["type"]=="PRIMARY")$Oa=" UNIQUE";}}return" AUTO_INCREMENT$Oa";}function
+alter_table($Q,$B,$p,$ed,$vb,$wc,$d,$Na,$Xf){$c=array();foreach($p
+as$o)$c[]=($o[1]?($Q!=""?($o[0]!=""?"CHANGE ".idf_escape($o[0]):"ADD"):" ")." ".implode($o[1]).($Q!=""?$o[2]:""):"DROP ".idf_escape($o[0]));$c=array_merge($c,$ed);$O=($vb!==null?" COMMENT=".q($vb):"").($wc?" ENGINE=".q($wc):"").($d?" COLLATE ".q($d):"").($Na!=""?" AUTO_INCREMENT=$Na":"");if($Q=="")return
+queries("CREATE TABLE ".table($B)." (\n".implode(",\n",$c)."\n)$O$Xf");if($Q!=$B)$c[]="RENAME TO ".table($B);if($O)$c[]=ltrim($O);return($c||$Xf?queries("ALTER TABLE ".table($Q)."\n".implode(",\n",$c).$Xf):true);}function
+alter_indexes($Q,$c){foreach($c
+as$y=>$X)$c[$y]=($X[2]=="DROP"?"\nDROP INDEX ".idf_escape($X[1]):"\nADD $X[0] ".($X[0]=="PRIMARY"?"KEY ":"").($X[1]!=""?idf_escape($X[1])." ":"")."(".implode(", ",$X[2]).")");return
+queries("ALTER TABLE ".table($Q).implode(",",$c));}function
+truncate_tables($S){return
+apply_queries("TRUNCATE TABLE",$S);}function
+drop_views($dj){return
+queries("DROP VIEW ".implode(", ",array_map('table',$dj)));}function
+drop_tables($S){return
+queries("DROP TABLE ".implode(", ",array_map('table',$S)));}function
+move_tables($S,$dj,$ai){$Ng=array();foreach(array_merge($S,$dj)as$Q)$Ng[]=table($Q)." TO ".idf_escape($ai).".".table($Q);return
+queries("RENAME TABLE ".implode(", ",$Ng));}function
+copy_tables($S,$dj,$ai){queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'");foreach($S
+as$Q){$B=($ai==DB?table("copy_$Q"):idf_escape($ai).".".table($Q));if(($_POST["overwrite"]&&!queries("\nDROP TABLE IF EXISTS $B"))||!queries("CREATE TABLE $B LIKE ".table($Q))||!queries("INSERT INTO $B SELECT * FROM ".table($Q)))return
+false;foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($Q,"%_\\")))as$I){$_i=$I["Trigger"];if(!queries("CREATE TRIGGER ".($ai==DB?idf_escape("copy_$_i"):idf_escape($ai).".".idf_escape($_i))." $I[Timing] $I[Event] ON $B FOR EACH ROW\n$I[Statement];"))return
+false;}}foreach($dj
+as$Q){$B=($ai==DB?table("copy_$Q"):idf_escape($ai).".".table($Q));$cj=view($Q);if(($_POST["overwrite"]&&!queries("DROP VIEW IF EXISTS $B"))||!queries("CREATE VIEW $B AS $cj[select]"))return
+false;}return
+true;}function
+trigger($B){if($B=="")return
+array();$J=get_rows("SHOW TRIGGERS WHERE `Trigger` = ".q($B));return
+reset($J);}function
+triggers($Q){$H=array();foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($Q,"%_\\")))as$I)$H[$I["Trigger"]]=array($I["Timing"],$I["Event"]);return$H;}function
+trigger_options(){return
+array("Timing"=>array("BEFORE","AFTER"),"Event"=>array("INSERT","UPDATE","DELETE"),"Type"=>array("FOR EACH ROW"),);}function
+routine($B,$T){global$h,$yc,$Td,$U;$Da=array("bool","boolean","integer","double precision","real","dec","numeric","fixed","national char","national varchar");$_h="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$Ei="((".implode("|",array_merge(array_keys($U),$Da)).")\\b(?:\\s*\\(((?:[^'\")]|$yc)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?";$dg="$_h*(".($T=="FUNCTION"?"":$Td).")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$Ei";$Gb=$h->result("SHOW CREATE $T ".idf_escape($B),2);preg_match("~\\(((?:$dg\\s*,?)*)\\)\\s*".($T=="FUNCTION"?"RETURNS\\s+$Ei\\s+":"")."(.*)~is",$Gb,$A);$p=array();preg_match_all("~$dg\\s*,?~is",$A[1],$Ge,PREG_SET_ORDER);foreach($Ge
+as$Qf)$p[]=array("field"=>str_replace("``","`",$Qf[2]).$Qf[3],"type"=>strtolower($Qf[5]),"length"=>preg_replace_callback("~$yc~s",'normalize_enum',$Qf[6]),"unsigned"=>strtolower(preg_replace('~\s+~',' ',trim("$Qf[8] $Qf[7]"))),"null"=>1,"full_type"=>$Qf[4],"inout"=>strtoupper($Qf[1]),"collation"=>strtolower($Qf[9]),);if($T!="FUNCTION")return
+array("fields"=>$p,"definition"=>$A[11]);return
+array("fields"=>$p,"returns"=>array("type"=>$A[12],"length"=>$A[13],"unsigned"=>$A[15],"collation"=>$A[16]),"definition"=>$A[17],"language"=>"SQL",);}function
+routines(){return
+get_rows("SELECT ROUTINE_NAME AS SPECIFIC_NAME, ROUTINE_NAME, ROUTINE_TYPE, DTD_IDENTIFIER FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = ".q(DB));}function
+routine_languages(){return
+array();}function
+routine_id($B,$I){return
+idf_escape($B);}function
+last_id(){global$h;return$h->result("SELECT LAST_INSERT_ID()");}function
+explain($h,$F){return$h->query("EXPLAIN ".(min_version(5.1)?"PARTITIONS ":"").$F);}function
+found_rows($R,$Z){return($Z||$R["Engine"]!="InnoDB"?null:$R["Rows"]);}function
+types(){return
+array();}function
+schemas(){return
+array();}function
+get_schema(){return"";}function
+set_schema($dh,$i=null){return
+true;}function
+create_sql($Q,$Na,$Lh){global$h;$H=$h->result("SHOW CREATE TABLE ".table($Q),1);if(!$Na)$H=preg_replace('~ AUTO_INCREMENT=\d+~','',$H);return$H;}function
+truncate_sql($Q){return"TRUNCATE ".table($Q);}function
+use_sql($j){return"USE ".idf_escape($j);}function
+trigger_sql($Q){$H="";foreach(get_rows("SHOW TRIGGERS LIKE ".q(addcslashes($Q,"%_\\")),null,"-- ")as$I)$H.="\nCREATE TRIGGER ".idf_escape($I["Trigger"])." $I[Timing] $I[Event] ON ".table($I["Table"])." FOR EACH ROW\n$I[Statement];;\n";return$H;}function
+show_variables(){return
+get_key_vals("SHOW VARIABLES");}function
+process_list(){return
+get_rows("SHOW FULL PROCESSLIST");}function
+show_status(){return
+get_key_vals("SHOW STATUS");}function
+convert_field($o){if(preg_match("~binary~",$o["type"]))return"HEX(".idf_escape($o["field"]).")";if($o["type"]=="bit")return"BIN(".idf_escape($o["field"])." + 0)";if(preg_match("~geometry|point|linestring|polygon~",$o["type"]))return(min_version(8)?"ST_":"")."AsWKT(".idf_escape($o["field"]).")";}function
+unconvert_field($o,$H){if(preg_match("~binary~",$o["type"]))$H="UNHEX($H)";if($o["type"]=="bit")$H="CONV($H, 2, 10) + 0";if(preg_match("~geometry|point|linestring|polygon~",$o["type"]))$H=(min_version(8)?"ST_":"")."GeomFromText($H, SRID($o[field]))";return$H;}function
+support($Rc){return!preg_match("~scheme|sequence|type|view_trigger|materializedview".(min_version(8)?"":"|descidx".(min_version(5.1)?"":"|event|partitioning".(min_version(5)?"":"|routine|trigger|view")))."~",$Rc);}function
+kill_process($X){return
+queries("KILL ".number($X));}function
+connection_id(){return"SELECT CONNECTION_ID()";}function
+max_connections(){global$h;return$h->result("SELECT @@max_connections");}$x="sql";$U=array();$Kh=array();foreach(array(lang(27)=>array("tinyint"=>3,"smallint"=>5,"mediumint"=>8,"int"=>10,"bigint"=>20,"decimal"=>66,"float"=>12,"double"=>21),lang(28)=>array("date"=>10,"datetime"=>19,"timestamp"=>19,"time"=>10,"year"=>4),lang(25)=>array("char"=>255,"varchar"=>65535,"tinytext"=>255,"text"=>65535,"mediumtext"=>16777215,"longtext"=>4294967295),lang(33)=>array("enum"=>65535,"set"=>64),lang(29)=>array("bit"=>20,"binary"=>255,"varbinary"=>65535,"tinyblob"=>255,"blob"=>65535,"mediumblob"=>16777215,"longblob"=>4294967295),lang(31)=>array("geometry"=>0,"point"=>0,"linestring"=>0,"polygon"=>0,"multipoint"=>0,"multilinestring"=>0,"multipolygon"=>0,"geometrycollection"=>0),)as$y=>$X){$U+=$X;$Kh[$y]=array_keys($X);}$Li=array("unsigned","zerofill","unsigned zerofill");$yf=array("=","<",">","<=",">=","!=","LIKE","LIKE %%","REGEXP","IN","FIND_IN_SET","IS NULL","NOT LIKE","NOT REGEXP","NOT IN","IS NOT NULL","SQL");$md=array("char_length","date","from_unixtime","lower","round","floor","ceil","sec_to_time","time_to_sec","upper");$sd=array("avg","count","count distinct","group_concat","max","min","sum");$oc=array(array("char"=>"md5/sha1/password/encrypt/uuid","binary"=>"md5/sha1","date|time"=>"now",),array(number_type()=>"+/-","date"=>"+ interval/- interval","time"=>"addtime/subtime","char|text"=>"concat",));}define("SERVER",$_GET[DRIVER]);define("DB",$_GET["db"]);define("ME",str_replace(":","%3a",preg_replace('~^[^?]*/([^?]*).*~','\1',$_SERVER["REQUEST_URI"])).'?'.(sid()?SID.'&':'').(SERVER!==null?DRIVER."=".urlencode(SERVER).'&':'').(isset($_GET["username"])?"username=".urlencode($_GET["username"]).'&':'').(DB!=""?'db='.urlencode(DB).'&'.(isset($_GET["ns"])?"ns=".urlencode($_GET["ns"])."&":""):''));$ia="4.7.5";class
+Adminer{var$operators;function
+name(){return"Adminer";}function
+credentials(){return
+array(SERVER,$_GET["username"],get_password());}function
+connectSsl(){}function
+permanentLogin($Gb=false){return
+password_file($Gb);}function
+bruteForceKey(){return$_SERVER["REMOTE_ADDR"];}function
+serverName($M){return
+h($M);}function
+database(){return
+DB;}function
+databases($cd=true){return
+get_databases($cd);}function
+schemas(){return
+schemas();}function
+queryTimeout(){return
+2;}function
+headers(){}function
+csp(){return
+csp();}function
+head(){return
+true;}function
+css(){$H=array();$Wc="adminer.css";if(file_exists($Wc))$H[]="$Wc?v=".crc32(file_get_contents($Wc));return$H;}function
+loginForm(){global$gc;echo"\n",$this->loginFormField('driver',''.lang(34).' | ',html_select("auth[driver]",$gc,DRIVER,"loginDriver(this);")."\n"),$this->loginFormField('server',' |
---|
'.lang(35).' | ',''."\n"),$this->loginFormField('username',' |
---|
'.lang(36).' | ',''.script("focus(qs('#username')); qs('#username').form['auth[driver]'].onchange();")),$this->loginFormField('password',' |
---|
'.lang(37).' | ',''."\n"),$this->loginFormField('db',' |
---|
'.lang(38).' | ',''."\n")," |
---|
\n","\n",checkbox("auth[permanent]",1,$_COOKIE["adminer_permanent"],lang(40))."\n";}function
+loginFormField($B,$zd,$Y){return$zd.$Y;}function
+login($Ae,$E){if($E=="")return
+lang(41,target_blank());return
+true;}function
+tableName($Rh){return
+h($Rh["Name"]);}function
+fieldName($o,$Cf=0){return''.h($o["field"]).'';}function
+selectLinks($Rh,$N=""){global$x,$m;echo'
';$ze=array("select"=>lang(42));if(support("table")||support("indexes"))$ze["table"]=lang(43);if(support("table")){if(is_view($Rh))$ze["view"]=lang(44);else$ze["create"]=lang(45);}if($N!==null)$ze["edit"]=lang(46);$B=$Rh["Name"];foreach($ze
+as$y=>$X)echo" $X";echo
+doc_link(array($x=>$m->tableHelp($B)),"?"),"\n";}function
+foreignKeys($Q){return
+foreign_keys($Q);}function
+backwardKeys($Q,$Qh){return
+array();}function
+backwardKeysPrint($Qa,$I){}function
+selectQuery($F,$Gh,$Pc=false){global$x,$m;$H="
\n";if(!$Pc&&($gj=$m->warnings())){$t="warnings";$H=", ".lang(47)."".script("qsl('a').onclick = partial(toggle, '$t');","")."$H\n$gj
\n";}return"".h(str_replace("\n"," ",$F))."
(".format_time($Gh).")".(support("sql")?" ".lang(10)."":"").$H;}function
+sqlCommandQuery($F){return
+shorten_utf8(trim($F),1000);}function
+rowDescription($Q){return"";}function
+rowDescriptions($J,$fd){return$J;}function
+selectLink($X,$o){}function
+selectVal($X,$_,$o,$Kf){$H=($X===null?"NULL":(preg_match("~char|binary|boolean~",$o["type"])&&!preg_match("~var~",$o["type"])?"$X
":$X));if(preg_match('~blob|bytea|raw|file~',$o["type"])&&!is_utf8($X))$H="".lang(48,strlen($Kf))."";if(preg_match('~json~',$o["type"]))$H="$H
";return($_?"$H":$H);}function
+editVal($X,$o){return$X;}function
+tableStructurePrint($p){echo"
\n";}function
+tableIndexesPrint($w){echo"\n";foreach($w
+as$B=>$v){ksort($v["columns"]);$pg=array();foreach($v["columns"]as$y=>$X)$pg[]="".h($X)."".($v["lengths"][$y]?"(".$v["lengths"][$y].")":"").($v["descs"][$y]?" DESC":"");echo"$v[type] | ".implode(", ",$pg)."\n";}echo" |
---|
\n";}function
+selectColumnsPrint($K,$f){global$md,$sd;print_fieldset("select",lang(54),$K);$s=0;$K[""]=array();foreach($K
+as$y=>$X){$X=$_GET["columns"][$y];$e=select_input(" name='columns[$s][col]'",$f,$X["col"],($y!==""?"selectFieldChange":"selectAddRow"));echo"".($md||$sd?"".on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'",1).script("qsl('select').onchange = function () { helpClose();".($y!==""?"":" qsl('select, input', this.parentNode).onchange();")." };","")."($e)":$e)."
\n";$s++;}echo"\n";}function
+selectSearchPrint($Z,$f,$w){print_fieldset("search",lang(57),$Z);foreach($w
+as$s=>$v){if($v["type"]=="FULLTEXT"){echo"(".implode(", ",array_map('h',$v["columns"])).") AGAINST"," ",script("qsl('input').oninput = selectFieldChange;",""),checkbox("boolean[$s]",1,isset($_GET["boolean"][$s]),"BOOL"),"
\n";}}$cb="this.parentNode.firstChild.onchange();";foreach(array_merge((array)$_GET["where"],array(array()))as$s=>$X){if(!$X||("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators))){echo"".select_input(" name='where[$s][col]'",$f,$X["col"],($X?"selectFieldChange":"selectAddRow"),"(".lang(58).")"),html_select("where[$s][op]",$this->operators,$X["op"],$cb),"",script("mixin(qsl('input'), {oninput: function () { $cb }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});",""),"
\n";}}echo"\n";}function
+selectOrderPrint($Cf,$f,$w){print_fieldset("sort",lang(59),$Cf);$s=0;foreach((array)$_GET["order"]as$y=>$X){if($X!=""){echo"".select_input(" name='order[$s]'",$f,$X,"selectFieldChange"),checkbox("desc[$s]",1,isset($_GET["desc"][$y]),lang(60))."
\n";$s++;}}echo"".select_input(" name='order[$s]'",$f,"","selectAddRow"),checkbox("desc[$s]",1,false,lang(60))."
\n","\n";}function
+selectLimitPrint($z){echo"\n";}function
+selectLengthPrint($gi){if($gi!==null){echo"\n";}}function
+selectActionPrint($w){echo"\n";}function
+selectCommandPrint(){return!information_schema(DB);}function
+selectImportPrint(){return!information_schema(DB);}function
+selectEmailPrint($tc,$f){}function
+selectColumnsProcess($f,$w){global$md,$sd;$K=array();$pd=array();foreach((array)$_GET["columns"]as$y=>$X){if($X["fun"]=="count"||($X["col"]!=""&&(!$X["fun"]||in_array($X["fun"],$md)||in_array($X["fun"],$sd)))){$K[$y]=apply_sql_function($X["fun"],($X["col"]!=""?idf_escape($X["col"]):"*"));if(!in_array($X["fun"],$sd))$pd[]=$K[$y];}}return
+array($K,$pd);}function
+selectSearchProcess($p,$w){global$h,$m;$H=array();foreach($w
+as$s=>$v){if($v["type"]=="FULLTEXT"&&$_GET["fulltext"][$s]!="")$H[]="MATCH (".implode(", ",array_map('idf_escape',$v["columns"])).") AGAINST (".q($_GET["fulltext"][$s]).(isset($_GET["boolean"][$s])?" IN BOOLEAN MODE":"").")";}foreach((array)$_GET["where"]as$y=>$X){if("$X[col]$X[val]"!=""&&in_array($X["op"],$this->operators)){$lg="";$xb=" $X[op]";if(preg_match('~IN$~',$X["op"])){$Jd=process_length($X["val"]);$xb.=" ".($Jd!=""?$Jd:"(NULL)");}elseif($X["op"]=="SQL")$xb=" $X[val]";elseif($X["op"]=="LIKE %%")$xb=" LIKE ".$this->processInput($p[$X["col"]],"%$X[val]%");elseif($X["op"]=="ILIKE %%")$xb=" ILIKE ".$this->processInput($p[$X["col"]],"%$X[val]%");elseif($X["op"]=="FIND_IN_SET"){$lg="$X[op](".q($X["val"]).", ";$xb=")";}elseif(!preg_match('~NULL$~',$X["op"]))$xb.=" ".$this->processInput($p[$X["col"]],$X["val"]);if($X["col"]!="")$H[]=$lg.$m->convertSearch(idf_escape($X["col"]),$X,$p[$X["col"]]).$xb;else{$sb=array();foreach($p
+as$B=>$o){if((preg_match('~^[-\d.'.(preg_match('~IN$~',$X["op"])?',':'').']+$~',$X["val"])||!preg_match('~'.number_type().'|bit~',$o["type"]))&&(!preg_match("~[\x80-\xFF]~",$X["val"])||preg_match('~char|text|enum|set~',$o["type"])))$sb[]=$lg.$m->convertSearch(idf_escape($B),$X,$o).$xb;}$H[]=($sb?"(".implode(" OR ",$sb).")":"1 = 0");}}}return$H;}function
+selectOrderProcess($p,$w){$H=array();foreach((array)$_GET["order"]as$y=>$X){if($X!="")$H[]=(preg_match('~^((COUNT\(DISTINCT |[A-Z0-9_]+\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\)|COUNT\(\*\))$~',$X)?$X:idf_escape($X)).(isset($_GET["desc"][$y])?" DESC":"");}return$H;}function
+selectLimitProcess(){return(isset($_GET["limit"])?$_GET["limit"]:"50");}function
+selectLengthProcess(){return(isset($_GET["text_length"])?$_GET["text_length"]:"100");}function
+selectEmailProcess($Z,$fd){return
+false;}function
+selectQueryBuild($K,$Z,$pd,$Cf,$z,$D){return"";}function
+messageQuery($F,$hi,$Pc=false){global$x,$m;restart_session();$_d=&get_session("queries");if(!$_d[$_GET["db"]])$_d[$_GET["db"]]=array();if(strlen($F)>1e6)$F=preg_replace('~[\x80-\xFF]+$~','',substr($F,0,1e6))."\n…";$_d[$_GET["db"]][]=array($F,time(),$hi);$Dh="sql-".count($_d[$_GET["db"]]);$H="".lang(65)."\n";if(!$Pc&&($gj=$m->warnings())){$t="warnings-".count($_d[$_GET["db"]]);$H="".lang(47).", $H\n$gj
\n";}return" ".@date("H:i:s").""." $H".shorten_utf8($F,1000)."
".($hi?"
($hi)":'').(support("sql")?'
'.lang(10).'':'').'
';}function
+editFunctions($o){global$oc;$H=($o["null"]?"NULL/":"");foreach($oc
+as$y=>$md){if(!$y||(!isset($_GET["call"])&&(isset($_GET["select"])||where($_GET)))){foreach($md
+as$dg=>$X){if(!$dg||preg_match("~$dg~",$o["type"]))$H.="/$X";}if($y&&!preg_match('~set|blob|bytea|raw|file~',$o["type"]))$H.="/SQL";}}if($o["auto_increment"]&&!isset($_GET["select"])&&!where($_GET))$H=lang(52);return
+explode("/",$H);}function
+editInput($Q,$o,$Ka,$Y){if($o["type"]=="enum")return(isset($_GET["select"])?" ":"").($o["null"]?" ":"").enum_input("radio",$Ka,$o,$Y,0);return"";}function
+editHint($Q,$o,$Y){return"";}function
+processInput($o,$Y,$r=""){if($r=="SQL")return$Y;$B=$o["field"];$H=q($Y);if(preg_match('~^(now|getdate|uuid)$~',$r))$H="$r()";elseif(preg_match('~^current_(date|timestamp)$~',$r))$H=$r;elseif(preg_match('~^([+-]|\|\|)$~',$r))$H=idf_escape($B)." $r $H";elseif(preg_match('~^[+-] interval$~',$r))$H=idf_escape($B)." $r ".(preg_match("~^(\\d+|'[0-9.: -]') [A-Z_]+\$~i",$Y)?$Y:$H);elseif(preg_match('~^(addtime|subtime|concat)$~',$r))$H="$r(".idf_escape($B).", $H)";elseif(preg_match('~^(md5|sha1|password|encrypt)$~',$r))$H="$r($H)";return
+unconvert_field($o,$H);}function
+dumpOutput(){$H=array('text'=>lang(66),'file'=>lang(67));if(function_exists('gzencode'))$H['gz']='gzip';return$H;}function
+dumpFormat(){return
+array('sql'=>'SQL','csv'=>'CSV,','csv;'=>'CSV;','tsv'=>'TSV');}function
+dumpDatabase($l){}function
+dumpTable($Q,$Lh,$ce=0){if($_POST["format"]!="sql"){echo"\xef\xbb\xbf";if($Lh)dump_csv(array_keys(fields($Q)));}else{if($ce==2){$p=array();foreach(fields($Q)as$B=>$o)$p[]=idf_escape($B)." $o[full_type]";$Gb="CREATE TABLE ".table($Q)." (".implode(", ",$p).")";}else$Gb=create_sql($Q,$_POST["auto_increment"],$Lh);set_utf8mb4($Gb);if($Lh&&$Gb){if($Lh=="DROP+CREATE"||$ce==1)echo"DROP ".($ce==2?"VIEW":"TABLE")." IF EXISTS ".table($Q).";\n";if($ce==1)$Gb=remove_definer($Gb);echo"$Gb;\n\n";}}}function
+dumpData($Q,$Lh,$F){global$h,$x;$Ie=($x=="sqlite"?0:1048576);if($Lh){if($_POST["format"]=="sql"){if($Lh=="TRUNCATE+INSERT")echo
+truncate_sql($Q).";\n";$p=fields($Q);}$G=$h->query($F,1);if($G){$Vd="";$Za="";$je=array();$Nh="";$Sc=($Q!=''?'fetch_assoc':'fetch_row');while($I=$G->$Sc()){if(!$je){$Yi=array();foreach($I
+as$X){$o=$G->fetch_field();$je[]=$o->name;$y=idf_escape($o->name);$Yi[]="$y = VALUES($y)";}$Nh=($Lh=="INSERT+UPDATE"?"\nON DUPLICATE KEY UPDATE ".implode(", ",$Yi):"").";\n";}if($_POST["format"]!="sql"){if($Lh=="table"){dump_csv($je);$Lh="INSERT";}dump_csv($I);}else{if(!$Vd)$Vd="INSERT INTO ".table($Q)." (".implode(", ",array_map('idf_escape',$je)).") VALUES";foreach($I
+as$y=>$X){$o=$p[$y];$I[$y]=($X!==null?unconvert_field($o,preg_match(number_type(),$o["type"])&&!preg_match('~\[~',$o["full_type"])&&is_numeric($X)?$X:q(($X===false?0:$X))):"NULL");}$bh=($Ie?"\n":" ")."(".implode(",\t",$I).")";if(!$Za)$Za=$Vd.$bh;elseif(strlen($Za)+4+strlen($bh)+strlen($Nh)<$Ie)$Za.=",$bh";else{echo$Za.$Nh;$Za=$Vd.$bh;}}}if($Za)echo$Za.$Nh;}elseif($_POST["format"]=="sql")echo"-- ".str_replace("\n"," ",$h->error)."\n";}}function
+dumpFilename($Ed){return
+friendly_url($Ed!=""?$Ed:(SERVER!=""?SERVER:"localhost"));}function
+dumpHeaders($Ed,$Xe=false){$Nf=$_POST["output"];$Kc=(preg_match('~sql~',$_POST["format"])?"sql":($Xe?"tar":"csv"));header("Content-Type: ".($Nf=="gz"?"application/x-gzip":($Kc=="tar"?"application/x-tar":($Kc=="sql"||$Nf!="file"?"text/plain":"text/csv")."; charset=utf-8")));if($Nf=="gz")ob_start('ob_gzencode',1e6);return$Kc;}function
+importServerPath(){return"adminer.sql";}function
+homepage(){echo''.($_GET["ns"]==""&&support("database")?''.lang(68)."\n":""),(support("scheme")?"".($_GET["ns"]!=""?lang(69):lang(70))."\n":""),($_GET["ns"]!==""?''.lang(71)."\n":""),(support("privileges")?"".lang(72)."\n":"");return
+true;}function
+navigation($We){global$ia,$x,$gc,$h;echo'
+';if($We=="auth"){$Nf="";foreach((array)$_SESSION["pwds"]as$aj=>$ph){foreach($ph
+as$M=>$Vi){foreach($Vi
+as$V=>$E){if($E!==null){$Tb=$_SESSION["db"][$aj][$M][$V];foreach(($Tb?array_keys($Tb):array(""))as$l)$Nf.="($gc[$aj]) ".h($V.($M!=""?"@".$this->serverName($M):"").($l!=""?" - $l":""))."\n";}}}}if($Nf)echo"\n".script("mixin(qs('#logins'), {onmouseover: menuOver, onmouseout: menuOut});");}else{if($_GET["ns"]!==""&&!$We&&DB!=""){$h->select_db(DB);$S=table_status('',true);}echo
+script_src(preg_replace("~\\?.*~","",ME)."?file=jush.js&version=4.7.5");if(support("sql")){echo'
+';}$this->databasesPrint($We);if(DB==""||!$We){echo"".(support("sql")?"".lang(65)."\n".lang(73)."\n":"")."";if(support("dump"))echo"".lang(74)."\n";}if($_GET["ns"]!==""&&!$We&&DB!=""){echo'".lang(75)."\n";if(!$S)echo"
".lang(9)."\n";else$this->tablesPrint($S);}}}function
+databasesPrint($We){global$b,$h;$k=$this->databases();if($k&&!in_array(DB,$k))array_unshift($k,DB);echo'
\n";}function
+tablesPrint($S){echo"".script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");foreach($S
+as$Q=>$O){$B=$this->tableName($O);if($B!=""){echo'- ".lang(79)." ",(support("table")||support("indexes")?'$B":"$B")."\n";}}echo"
\n";}}$b=(function_exists('adminer_object')?adminer_object():new
+Adminer);if($b->operators===null)$b->operators=$yf;function
+page_header($ki,$n="",$Ya=array(),$li=""){global$ca,$ia,$b,$gc,$x;page_headers();if(is_ajax()&&$n){page_messages($n);exit;}$mi=$ki.($li!=""?": $li":"");$ni=strip_tags($mi.(SERVER!=""&&SERVER!="localhost"?h(" - ".SERVER):"")." - ".$b->name());echo'
+
+
+
+',$ni,'
+
+',script_src(preg_replace("~\\?.*~","",ME)."?file=functions.js&version=4.7.5");if($b->head()){echo'
+
+';foreach($b->css()as$Lb){echo'
+';}}echo'
+
+';$Wc=get_temp_dir()."/adminer.version";if(!$_COOKIE["adminer_version"]&&function_exists('openssl_verify')&&file_exists($Wc)&&filemtime($Wc)+86400>time()){$bj=unserialize(file_get_contents($Wc));$wg="-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwqWOVuF5uw7/+Z70djoK
+RlHIZFZPO0uYRezq90+7Amk+FDNd7KkL5eDve+vHRJBLAszF/7XKXe11xwliIsFs
+DFWQlsABVZB3oisKCBEuI71J4kPH8dKGEWR9jDHFw3cWmoH3PmqImX6FISWbG3B8
+h7FIx3jEaw5ckVPVTeo5JRm/1DZzJxjyDenXvBQ/6o9DgZKeNDgxwKzH+sw9/YCO
+jHnq1cFpOIISzARlrHMa/43YfeNRAm/tsBXjSxembBPo7aQZLAWHmaj5+K19H10B
+nCpz9Y++cipkVEiKRGih4ZEvjoFysEOdRLj6WiD/uUNky4xGeA6LaJqh5XpkFkcQ
+fQIDAQAB
+-----END PUBLIC KEY-----
+";if(openssl_verify($bj["version"],base64_decode($bj["signature"]),$wg)==1)$_COOKIE["adminer_version"]=$bj["version"];}echo'
+
+
+',script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});"),'
+
+';if($Ya!==null){$_=substr(preg_replace('~\b(username|db|ns)=[^&]*&~','',ME),0,-1);echo'
'.$gc[DRIVER].' » ';$_=substr(preg_replace('~\b(db|ns)=[^&]*&~','',ME),0,-1);$M=$b->serverName(SERVER);$M=($M!=""?$M:lang(35));if($Ya===false)echo"$M\n";else{echo"$M » ";if($_GET["ns"]!=""||(DB!=""&&is_array($Ya)))echo''.h(DB).' » ';if(is_array($Ya)){if($_GET["ns"]!="")echo''.h($_GET["ns"]).' » ';foreach($Ya
+as$y=>$X){$Zb=(is_array($X)?$X[1]:h($X));if($Zb!="")echo"$Zb » ";}}echo"$ki\n";}}echo"
$mi
\n","
\n";restart_session();page_messages($n);$k=&get_session("dbs");if(DB!=""&&$k&&!in_array(DB,$k,true))$k=null;stop_session();define("PAGE_HEADER",1);}function
+page_headers(){global$b;header("Content-Type: text/html; charset=utf-8");header("Cache-Control: no-cache");header("X-Frame-Options: deny");header("X-XSS-Protection: 0");header("X-Content-Type-Options: nosniff");header("Referrer-Policy: origin-when-cross-origin");foreach($b->csp()as$Kb){$yd=array();foreach($Kb
+as$y=>$X)$yd[]="$y $X";header("Content-Security-Policy: ".implode("; ",$yd));}$b->headers();}function
+csp(){return
+array(array("script-src"=>"'self' 'unsafe-inline' 'nonce-".get_nonce()."' 'strict-dynamic'","connect-src"=>"'self'","frame-src"=>"https://www.adminer.org","object-src"=>"'none'","base-uri"=>"'none'","form-action"=>"'self'",),);}function
+get_nonce(){static$gf;if(!$gf)$gf=base64_encode(rand_string());return$gf;}function
+page_messages($n){$Ni=preg_replace('~^[^?]*~','',$_SERVER["REQUEST_URI"]);$Se=$_SESSION["messages"][$Ni];if($Se){echo"
".implode("
\n
",$Se)."
".script("messagesPrint();");unset($_SESSION["messages"][$Ni]);}if($n)echo"
$n
\n";}function
+page_footer($We=""){global$b,$ri;echo'
+
+';switch_lang();if($We!="auth"){echo'
+';}echo'
+',script("setupSubmitHighlight(document);");}function
+int32($Ze){while($Ze>=2147483648)$Ze-=4294967296;while($Ze<=-2147483649)$Ze+=4294967296;return(int)$Ze;}function
+long2str($W,$fj){$bh='';foreach($W
+as$X)$bh.=pack('V',$X);if($fj)return
+substr($bh,0,end($W));return$bh;}function
+str2long($bh,$fj){$W=array_values(unpack('V*',str_pad($bh,4*ceil(strlen($bh)/4),"\0")));if($fj)$W[]=strlen($bh);return$W;}function
+xxtea_mx($sj,$rj,$Oh,$fe){return
+int32((($sj>>5&0x7FFFFFF)^$rj<<2)+(($rj>>3&0x1FFFFFFF)^$sj<<4))^int32(($Oh^$rj)+($fe^$sj));}function
+encrypt_string($Jh,$y){if($Jh=="")return"";$y=array_values(unpack("V*",pack("H*",md5($y))));$W=str2long($Jh,true);$Ze=count($W)-1;$sj=$W[$Ze];$rj=$W[0];$xg=floor(6+52/($Ze+1));$Oh=0;while($xg-->0){$Oh=int32($Oh+0x9E3779B9);$nc=$Oh>>2&3;for($Of=0;$Of<$Ze;$Of++){$rj=$W[$Of+1];$Ye=xxtea_mx($sj,$rj,$Oh,$y[$Of&3^$nc]);$sj=int32($W[$Of]+$Ye);$W[$Of]=$sj;}$rj=$W[0];$Ye=xxtea_mx($sj,$rj,$Oh,$y[$Of&3^$nc]);$sj=int32($W[$Ze]+$Ye);$W[$Ze]=$sj;}return
+long2str($W,false);}function
+decrypt_string($Jh,$y){if($Jh=="")return"";if(!$y)return
+false;$y=array_values(unpack("V*",pack("H*",md5($y))));$W=str2long($Jh,false);$Ze=count($W)-1;$sj=$W[$Ze];$rj=$W[0];$xg=floor(6+52/($Ze+1));$Oh=int32($xg*0x9E3779B9);while($Oh){$nc=$Oh>>2&3;for($Of=$Ze;$Of>0;$Of--){$sj=$W[$Of-1];$Ye=xxtea_mx($sj,$rj,$Oh,$y[$Of&3^$nc]);$rj=int32($W[$Of]-$Ye);$W[$Of]=$rj;}$sj=$W[$Ze];$Ye=xxtea_mx($sj,$rj,$Oh,$y[$Of&3^$nc]);$rj=int32($W[0]-$Ye);$W[0]=$rj;$Oh=int32($Oh-0x9E3779B9);}return
+long2str($W,true);}$h='';$xd=$_SESSION["token"];if(!$xd)$_SESSION["token"]=rand(1,1e6);$ri=get_token();$eg=array();if($_COOKIE["adminer_permanent"]){foreach(explode(" ",$_COOKIE["adminer_permanent"])as$X){list($y)=explode(":",$X);$eg[$y]=$X;}}function
+add_invalid_login(){global$b;$kd=file_open_lock(get_temp_dir()."/adminer.invalid");if(!$kd)return;$Yd=unserialize(stream_get_contents($kd));$hi=time();if($Yd){foreach($Yd
+as$Zd=>$X){if($X[0]<$hi)unset($Yd[$Zd]);}}$Xd=&$Yd[$b->bruteForceKey()];if(!$Xd)$Xd=array($hi+30*60,0);$Xd[1]++;file_write_unlock($kd,serialize($Yd));}function
+check_invalid_login(){global$b;$Yd=unserialize(@file_get_contents(get_temp_dir()."/adminer.invalid"));$Xd=$Yd[$b->bruteForceKey()];$ff=($Xd[1]>29?$Xd[0]-time():0);if($ff>0)auth_error(lang(83,ceil($ff/60)));}$La=$_POST["auth"];if($La){session_regenerate_id();$aj=$La["driver"];$M=$La["server"];$V=$La["username"];$E=(string)$La["password"];$l=$La["db"];set_password($aj,$M,$V,$E);$_SESSION["db"][$aj][$M][$V][$l]=true;if($La["permanent"]){$y=base64_encode($aj)."-".base64_encode($M)."-".base64_encode($V)."-".base64_encode($l);$qg=$b->permanentLogin(true);$eg[$y]="$y:".base64_encode($qg?encrypt_string($E,$qg):"");cookie("adminer_permanent",implode(" ",$eg));}if(count($_POST)==1||DRIVER!=$aj||SERVER!=$M||$_GET["username"]!==$V||DB!=$l)redirect(auth_url($aj,$M,$V,$l));}elseif($_POST["logout"]){if($xd&&!verify_token()){page_header(lang(82),lang(84));page_footer("db");exit;}else{foreach(array("pwds","db","dbs","queries")as$y)set_session($y,null);unset_permanent();redirect(substr(preg_replace('~\b(username|db|ns)=[^&]*&~','',ME),0,-1),lang(85).' '.lang(86));}}elseif($eg&&!$_SESSION["pwds"]){session_regenerate_id();$qg=$b->permanentLogin();foreach($eg
+as$y=>$X){list(,$kb)=explode(":",$X);list($aj,$M,$V,$l)=array_map('base64_decode',explode("-",$y));set_password($aj,$M,$V,decrypt_string(base64_decode($kb),$qg));$_SESSION["db"][$aj][$M][$V][$l]=true;}}function
+unset_permanent(){global$eg;foreach($eg
+as$y=>$X){list($aj,$M,$V,$l)=array_map('base64_decode',explode("-",$y));if($aj==DRIVER&&$M==SERVER&&$V==$_GET["username"]&&$l==DB)unset($eg[$y]);}cookie("adminer_permanent",implode(" ",$eg));}function
+auth_error($n){global$b,$xd;$qh=session_name();if(isset($_GET["username"])){header("HTTP/1.1 403 Forbidden");if(($_COOKIE[$qh]||$_GET[$qh])&&!$xd)$n=lang(87);else{restart_session();add_invalid_login();$E=get_password();if($E!==null){if($E===false)$n.='
'.lang(88,target_blank(),'permanentLogin()
');set_password(DRIVER,SERVER,$_GET["username"],null);}unset_permanent();}}if(!$_COOKIE[$qh]&&$_GET[$qh]&&ini_bool("session.use_only_cookies"))$n=lang(89);$Rf=session_get_cookie_params();cookie("adminer_key",($_COOKIE["adminer_key"]?$_COOKIE["adminer_key"]:rand_string()),$Rf["lifetime"]);page_header(lang(39),$n,null);echo"\n";page_footer("auth");exit;}if(isset($_GET["username"])&&!class_exists("Min_DB")){unset($_SESSION["pwds"][DRIVER]);unset_permanent();page_header(lang(91),lang(92,implode(", ",$kg)),false);page_footer("auth");exit;}stop_session(true);if(isset($_GET["username"])&&is_string(get_password())){list($Cd,$gg)=explode(":",SERVER,2);if(is_numeric($gg)&&$gg<1024)auth_error(lang(93));check_invalid_login();$h=connect();$m=new
+Min_Driver($h);}$Ae=null;if(!is_object($h)||($Ae=$b->login($_GET["username"],get_password()))!==true){$n=(is_string($h)?h($h):(is_string($Ae)?$Ae:lang(94)));auth_error($n.(preg_match('~^ | $~',get_password())?'
'.lang(95):''));}if($La&&$_POST["token"])$_POST["token"]=$ri;$n='';if($_POST){if(!verify_token()){$Sd="max_input_vars";$Me=ini_get($Sd);if(extension_loaded("suhosin")){foreach(array("suhosin.request.max_vars","suhosin.post.max_vars")as$y){$X=ini_get($y);if($X&&(!$Me||$X<$Me)){$Sd=$y;$Me=$X;}}}$n=(!$_POST["token"]&&$Me?lang(96,"'$Sd'"):lang(84).' '.lang(97));}}elseif($_SERVER["REQUEST_METHOD"]=="POST"){$n=lang(98,"'post_max_size'");if(isset($_GET["sql"]))$n.=' '.lang(99);}function
+select($G,$i=null,$Ff=array(),$z=0){global$x;$ze=array();$w=array();$f=array();$Va=array();$U=array();$H=array();odd('');for($s=0;(!$z||$s<$z)&&($I=$G->fetch_row());$s++){if(!$s){echo"":"".lang(12))."\n";return$H;}function
+referencable_primary($kh){$H=array();foreach(table_status('',true)as$Sh=>$Q){if($Sh!=$kh&&fk_support($Q)){foreach(fields($Sh)as$o){if($o["primary"]){if($H[$Sh]){unset($H[$Sh]);break;}$H[$Sh]=$o;}}}}return$H;}function
+adminer_settings(){parse_str($_COOKIE["adminer_settings"],$sh);return$sh;}function
+adminer_setting($y){$sh=adminer_settings();return$sh[$y];}function
+set_adminer_settings($sh){return
+cookie("adminer_settings",http_build_query($sh+adminer_settings()));}function
+textarea($B,$Y,$J=10,$sb=80){global$x;echo"";}function
+edit_type($y,$o,$qb,$gd=array(),$Nc=array()){global$Kh,$U,$Li,$tf;$T=$o["type"];echo'
',on_help("getTarget(event).value",1),script("mixin(qsl('select'), {onfocus: function () { lastType = selectValue(this); }, onchange: editingTypeChange});",""),' | ',script("mixin(qsl('input'), {onfocus: editingLengthFocus, oninput: editingLengthChange});",""),' | ',"',($Li?"':''),(isset($o['on_update'])?"':''),($gd?" ":" ");}function
+process_length($we){global$yc;return(preg_match("~^\\s*\\(?\\s*$yc(?:\\s*,\\s*$yc)*+\\s*\\)?\\s*\$~",$we)&&preg_match_all("~$yc~",$we,$Ge)?"(".implode(",",$Ge[0]).")":preg_replace('~^[0-9].*~','(\0)',preg_replace('~[^-0-9,+()[\]]~','',$we)));}function
+process_type($o,$pb="COLLATE"){global$Li;return" $o[type]".process_length($o["length"]).(preg_match(number_type(),$o["type"])&&in_array($o["unsigned"],$Li)?" $o[unsigned]":"").(preg_match('~char|text|enum|set~',$o["type"])&&$o["collation"]?" $pb ".q($o["collation"]):"");}function
+process_field($o,$Di){return
+array(idf_escape(trim($o["field"])),process_type($Di),($o["null"]?" NULL":" NOT NULL"),default_value($o),(preg_match('~timestamp|datetime~',$o["type"])&&$o["on_update"]?" ON UPDATE $o[on_update]":""),(support("comment")&&$o["comment"]!=""?" COMMENT ".q($o["comment"]):""),($o["auto_increment"]?auto_increment():null),);}function
+default_value($o){$Vb=$o["default"];return($Vb===null?"":" DEFAULT ".(preg_match('~char|binary|text|enum|set~',$o["type"])||preg_match('~^(?![a-z])~i',$Vb)?q($Vb):$Vb));}function
+type_class($T){foreach(array('char'=>'text','date'=>'time|year','binary'=>'blob','enum'=>'set',)as$y=>$X){if(preg_match("~$y|$X~",$T))return" class='$y'";}}function
+edit_fields($p,$qb,$T="TABLE",$gd=array()){global$Td;$p=array_values($p);echo'
+';if($T=="PROCEDURE"){echo'';}echo' | ',($T=="TABLE"?lang(104):lang(105)),' | ',lang(50),'',script("qs('#enum-edit').onblur = editingLengthBlur;"),' | ',lang(106),' | ',lang(107);if($T=="TABLE"){echo' | NULL
+ | AI',doc_link(array('sql'=>"example-auto-increment.html",'mariadb'=>"auto_increment/",'sqlite'=>"autoinc.html",'pgsql'=>"datatype.html#DATATYPE-SERIAL",'mssql'=>"ms186775.aspx",)),' | ',lang(53),(support("comment")?" | ',"".script("row_count = ".count($p).";"),' |
+ |
+',script("mixin(qsl('tbody'), {onclick: editingClick, onkeydown: editingKeydown, oninput: editingInput});");foreach($p
+as$s=>$o){$s++;$Gf=$o[($_POST?"orig":"field")];$dc=(isset($_POST["add"][$s-1])||(isset($o["field"])&&!$_POST["drop_col"][$s]))&&(support("drop_col")||$Gf=="");echo'
+',($T=="PROCEDURE"?"".html_select("fields[$s][inout]",explode("|",$Td),$o["inout"]):""),' | ';if($dc){echo'',script("qsl('input').oninput = function () { editingNameChange.call(this);".($o["field"]!=""||count($p)>1?"":" editingAddRow.call(this);")." };","");}echo'';edit_type("fields[$s]",$o,$qb,$gd);if($T=="TABLE"){echo' | ',checkbox("fields[$s][null]",1,$o["null"],"","","block","label-null"),' | | ',checkbox("fields[$s][has_default]",1,$o["has_default"],"","","","label-default"),'',(support("comment")?" | ":"");}echo" | ",(support("move_col")?" "." "." ":""),($Gf==""||support("drop_col")?"":"");}}function
+process_fields(&$p){$C=0;if($_POST["up"]){$qe=0;foreach($p
+as$y=>$o){if(key($_POST["up"])==$y){unset($p[$y]);array_splice($p,$qe,0,array($o));break;}if(isset($o["field"]))$qe=$C;$C++;}}elseif($_POST["down"]){$id=false;foreach($p
+as$y=>$o){if(isset($o["field"])&&$id){unset($p[key($_POST["down"])]);array_splice($p,$C,0,array($id));break;}if(key($_POST["down"])==$y)$id=$o;$C++;}}elseif($_POST["add"]){$p=array_values($p);array_splice($p,key($_POST["add"]),0,array(array()));}elseif(!$_POST["drop_col"])return
+false;return
+true;}function
+normalize_enum($A){return"'".str_replace("'","''",addcslashes(stripcslashes(str_replace($A[0][0].$A[0][0],$A[0][0],substr($A[0],1,-1))),'\\'))."'";}function
+grant($nd,$sg,$f,$sf){if(!$sg)return
+true;if($sg==array("ALL PRIVILEGES","GRANT OPTION"))return($nd=="GRANT"?queries("$nd ALL PRIVILEGES$sf WITH GRANT OPTION"):queries("$nd ALL PRIVILEGES$sf")&&queries("$nd GRANT OPTION$sf"));return
+queries("$nd ".preg_replace('~(GRANT OPTION)\([^)]*\)~','\1',implode("$f, ",$sg).$f).$sf);}function
+drop_create($hc,$Gb,$ic,$ei,$kc,$_e,$Re,$Pe,$Qe,$pf,$cf){if($_POST["drop"])query_redirect($hc,$_e,$Re);elseif($pf=="")query_redirect($Gb,$_e,$Qe);elseif($pf!=$cf){$Ib=queries($Gb);queries_redirect($_e,$Pe,$Ib&&queries($hc));if($Ib)queries($ic);}else
+queries_redirect($_e,$Pe,queries($ei)&&queries($kc)&&queries($hc)&&queries($Gb));}function
+create_trigger($sf,$I){global$x;$ji=" $I[Timing] $I[Event]".($I["Event"]=="UPDATE OF"?" ".idf_escape($I["Of"]):"");return"CREATE TRIGGER ".idf_escape($I["Trigger"]).($x=="mssql"?$sf.$ji:$ji.$sf).rtrim(" $I[Type]\n$I[Statement]",";").";";}function
+create_routine($Xg,$I){global$Td,$x;$N=array();$p=(array)$I["fields"];ksort($p);foreach($p
+as$o){if($o["field"]!="")$N[]=(preg_match("~^($Td)\$~",$o["inout"])?"$o[inout] ":"").idf_escape($o["field"]).process_type($o,"CHARACTER SET");}$Wb=rtrim("\n$I[definition]",";");return"CREATE $Xg ".idf_escape(trim($I["name"]))." (".implode(", ",$N).")".(isset($_GET["function"])?" RETURNS".process_type($I["returns"],"CHARACTER SET"):"").($I["language"]?" LANGUAGE $I[language]":"").($x=="pgsql"?" AS ".q($Wb):"$Wb;");}function
+remove_definer($F){return
+preg_replace('~^([A-Z =]+) DEFINER=`'.preg_replace('~@(.*)~','`@`(%|\1)',logged_user()).'`~','\1',$F);}function
+format_foreign_key($q){global$tf;$l=$q["db"];$hf=$q["ns"];return" FOREIGN KEY (".implode(", ",array_map('idf_escape',$q["source"])).") REFERENCES ".($l!=""&&$l!=$_GET["db"]?idf_escape($l).".":"").($hf!=""&&$hf!=$_GET["ns"]?idf_escape($hf).".":"").table($q["table"])." (".implode(", ",array_map('idf_escape',$q["target"])).")".(preg_match("~^($tf)\$~",$q["on_delete"])?" ON DELETE $q[on_delete]":"").(preg_match("~^($tf)\$~",$q["on_update"])?" ON UPDATE $q[on_update]":"");}function
+tar_file($Wc,$oi){$H=pack("a100a8a8a8a12a12",$Wc,644,0,0,decoct($oi->size),decoct(time()));$ib=8*32;for($s=0;$ssend();echo
+str_repeat("\0",511-($oi->size+511)%512);}function
+ini_bytes($Sd){$X=ini_get($Sd);switch(strtolower(substr($X,-1))){case'g':$X*=1024;case'm':$X*=1024;case'k':$X*=1024;}return$X;}function
+doc_link($cg,$fi="?"){global$x,$h;$oh=$h->server_info;$bj=preg_replace('~^(\d\.?\d).*~s','\1',$oh);$Qi=array('sql'=>"https://dev.mysql.com/doc/refman/$bj/en/",'sqlite'=>"https://www.sqlite.org/",'pgsql'=>"https://www.postgresql.org/docs/$bj/",'mssql'=>"https://msdn.microsoft.com/library/",'oracle'=>"https://www.oracle.com/pls/topic/lookup?ctx=db".preg_replace('~^.* (\d+)\.(\d+)\.\d+\.\d+\.\d+.*~s','\1\2',$oh)."&id=",);if(preg_match('~MariaDB~',$oh)){$Qi['sql']="https://mariadb.com/kb/en/library/";$cg['sql']=(isset($cg['mariadb'])?$cg['mariadb']:str_replace(".html","/",$cg['sql']));}return($cg[$x]?"$fi":"");}function
+ob_gzencode($P){return
+gzencode($P);}function
+db_size($l){global$h;if(!$h->select_db($l))return"?";$H=0;foreach(table_status()as$R)$H+=$R["Data_length"]+$R["Index_length"];return
+format_number($H);}function
+set_utf8mb4($Gb){global$h;static$N=false;if(!$N&&preg_match('~\butf8mb4~i',$Gb)){$N=true;echo"SET NAMES ".charset($h).";\n\n";}}function
+connect_error(){global$b,$h,$ri,$n,$gc;if(DB!=""){header("HTTP/1.1 404 Not Found");page_header(lang(38).": ".h(DB),lang(112),true);}else{if($_POST["db"]&&!$n)queries_redirect(substr(ME,0,-1),lang(113),drop_databases($_POST["db"]));page_header(lang(114),$n,false);echo" \n";foreach(array('database'=>lang(115),'privileges'=>lang(72),'processlist'=>lang(116),'variables'=>lang(117),'status'=>lang(118),)as$y=>$X){if(support($y))echo"$X\n";}echo" ".lang(119,$gc[DRIVER],"".h($h->server_info)."","$h->extension")."\n"," ".lang(120,"".h(logged_user())."")."\n";$k=$b->databases();if($k){$eh=support("scheme");$qb=collations();echo" \n",script("tableCheck();");}}page_footer("db");}if(isset($_GET["status"]))$_GET["variables"]=$_GET["status"];if(isset($_GET["import"]))$_GET["sql"]=$_GET["import"];if(!(DB!=""?$h->select_db(DB):isset($_GET["sql"])||isset($_GET["dump"])||isset($_GET["database"])||isset($_GET["processlist"])||isset($_GET["privileges"])||isset($_GET["user"])||isset($_GET["variables"])||$_GET["script"]=="connect"||$_GET["script"]=="kill")){if(DB!=""||$_GET["refresh"]){restart_session();set_session("dbs",null);}connect_error();exit;}if(support("scheme")&&DB!=""&&$_GET["ns"]!==""){if(!isset($_GET["ns"]))redirect(preg_replace('~ns=[^&]*&~','',ME)."ns=".get_schema());if(!set_schema($_GET["ns"])){header("HTTP/1.1 404 Not Found");page_header(lang(78).": ".h($_GET["ns"]),lang(128),true);page_footer("ns");exit;}}$tf="RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT";class
+TmpFile{var$handler;var$size;function
+__construct(){$this->handler=tmpfile();}function
+write($Bb){$this->size+=strlen($Bb);fwrite($this->handler,$Bb);}function
+send(){fseek($this->handler,0);fpassthru($this->handler);fclose($this->handler);}}$yc="'(?:''|[^'\\\\]|\\\\.)*'";$Td="IN|OUT|INOUT";if(isset($_GET["select"])&&($_POST["edit"]||$_POST["clone"])&&!$_POST["save"])$_GET["edit"]=$_GET["select"];if(isset($_GET["callf"]))$_GET["call"]=$_GET["callf"];if(isset($_GET["function"]))$_GET["procedure"]=$_GET["function"];if(isset($_GET["download"])){$a=$_GET["download"];$p=fields($a);header("Content-Type: application/octet-stream");header("Content-Disposition: attachment; filename=".friendly_url("$a-".implode("_",$_GET["where"])).".".friendly_url($_GET["field"]));$K=array(idf_escape($_GET["field"]));$G=$m->select($a,$K,array(where($_GET,$p)),$K);$I=($G?$G->fetch_row():array());echo$m->value($I[0],$p[$_GET["field"]]);exit;}elseif(isset($_GET["table"])){$a=$_GET["table"];$p=fields($a);if(!$p)$n=error();$R=table_status1($a,true);$B=$b->tableName($R);page_header(($p&&is_view($R)?$R['Engine']=='materialized view'?lang(129):lang(130):lang(131)).": ".($B!=""?$B:h($a)),$n);$b->selectLinks($R);$vb=$R["Comment"];if($vb!="")echo"".lang(51).": ".h($vb)."\n";if($p)$b->tableStructurePrint($p);if(!is_view($R)){if(support("indexes")){echo" ".lang(132)."\n";$w=indexes($a);if($w)$b->tableIndexesPrint($w);echo''.lang(133)."\n";}if(fk_support($R)){echo" ".lang(100)."\n";$gd=foreign_keys($a);if($gd){echo"\n","".lang(134)." | ".lang(135)." | ".lang(103)." | ".lang(102)." | | \n";foreach($gd
+as$B=>$q){echo"","".implode(", ",array_map('h',$q["source"])).""," | ".($q["db"]!=""?"".h($q["db"]).".":"").($q["ns"]!=""?"".h($q["ns"]).".":"").h($q["table"])."","(".implode(", ",array_map('h',$q["target"])).")"," | ".h($q["on_delete"])."\n"," | ".h($q["on_update"])."\n",' | '.lang(136).'';}echo" | \n";}echo''.lang(137)."\n";}}if(support(is_view($R)?"view_trigger":"trigger")){echo" ".lang(138)."\n";$Ci=triggers($a);if($Ci){echo"\n";foreach($Ci
+as$y=>$X)echo"".h($X[0])." | ".h($X[1])." | ".h($y)." | ".lang(136)."\n";echo" |
---|
\n";}echo''.lang(139)."\n";}}elseif(isset($_GET["schema"])){page_header(lang(71),"",array(),h(DB.($_GET["ns"]?".$_GET[ns]":"")));$Uh=array();$Vh=array();$ea=($_GET["schema"]?$_GET["schema"]:$_COOKIE["adminer_schema-".str_replace(".","_",DB)]);preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~',$ea,$Ge,PREG_SET_ORDER);foreach($Ge
+as$s=>$A){$Uh[$A[1]]=array($A[2],$A[3]);$Vh[]="\n\t'".js_escape($A[1])."': [ $A[2], $A[3] ]";}$si=0;$Sa=-1;$dh=array();$Ig=array();$ue=array();foreach(table_status('',true)as$Q=>$R){if(is_view($R))continue;$hg=0;$dh[$Q]["fields"]=array();foreach(fields($Q)as$B=>$o){$hg+=1.25;$o["pos"]=$hg;$dh[$Q]["fields"][$B]=$o;}$dh[$Q]["pos"]=($Uh[$Q]?$Uh[$Q]:array($si,0));foreach($b->foreignKeys($Q)as$X){if(!$X["db"]){$se=$Sa;if($Uh[$Q][1]||$Uh[$X["table"]][1])$se=min(floatval($Uh[$Q][1]),floatval($Uh[$X["table"]][1]))-1;else$Sa-=.1;while($ue[(string)$se])$se-=.0001;$dh[$Q]["references"][$X["table"]][(string)$se]=array($X["source"],$X["target"]);$Ig[$X["table"]][$Q][(string)$se]=$X["target"];$ue[(string)$se]=true;}}$si=max($si,$dh[$Q]["pos"][0]+2.5+$hg);}echo'
+
+';foreach($dh
+as$B=>$Q){echo" ",' '.h($B)."",script("qsl('div').onmousedown = schemaMousedown;");foreach($Q["fields"]as$o){$X=' '.h($o["field"]).'';echo" ".($o["primary"]?" $X":$X);}foreach((array)$Q["references"]as$bi=>$Jg){foreach($Jg
+as$se=>$Fg){$te=$se-$Uh[$B][1];$s=0;foreach($Fg[0]as$zh)echo"\n ";}}foreach((array)$Ig[$B]as$bi=>$Jg){foreach($Jg
+as$se=>$f){$te=$se-$Uh[$B][1];$s=0;foreach($f
+as$ai)echo"\n ";}}echo"\n \n";}foreach($dh
+as$B=>$Q){foreach((array)$Q["references"]as$bi=>$Jg){foreach($Jg
+as$se=>$Fg){$Ve=$si;$Ke=-10;foreach($Fg[0]as$y=>$zh){$ig=$Q["pos"][0]+$Q["fields"][$zh]["pos"];$jg=$dh[$bi]["pos"][0]+$dh[$bi]["fields"][$Fg[1][$y]]["pos"];$Ve=min($Ve,$ig,$jg);$Ke=max($Ke,$ig,$jg);}echo" \n";}}}echo'
+',lang(140),'
+';}elseif(isset($_GET["dump"])){$a=$_GET["dump"];if($_POST&&!$n){$Eb="";foreach(array("output","format","db_style","routines","events","table_style","auto_increment","triggers","data_style")as$y)$Eb.="&$y=".urlencode($_POST[$y]);cookie("adminer_export",substr($Eb,1));$S=array_flip((array)$_POST["tables"])+array_flip((array)$_POST["data"]);$Kc=dump_headers((count($S)==1?key($S):DB),(DB==""||count($S)>1));$be=preg_match('~sql~',$_POST["format"]);if($be){echo"-- Adminer $ia ".$gc[DRIVER]." dump\n\n";if($x=="sql"){echo"SET NAMES utf8;
+SET time_zone = '+00:00';
+".($_POST["data_style"]?"SET foreign_key_checks = 0;
+SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
+":"")."
+";$h->query("SET time_zone = '+00:00';");}}$Lh=$_POST["db_style"];$k=array(DB);if(DB==""){$k=$_POST["databases"];if(is_string($k))$k=explode("\n",rtrim(str_replace("\r","",$k),"\n"));}foreach((array)$k
+as$l){$b->dumpDatabase($l);if($h->select_db($l)){if($be&&preg_match('~CREATE~',$Lh)&&($Gb=$h->result("SHOW CREATE DATABASE ".idf_escape($l),1))){set_utf8mb4($Gb);if($Lh=="DROP+CREATE")echo"DROP DATABASE IF EXISTS ".idf_escape($l).";\n";echo"$Gb;\n";}if($be){if($Lh)echo
+use_sql($l).";\n\n";$Mf="";if($_POST["routines"]){foreach(array("FUNCTION","PROCEDURE")as$Xg){foreach(get_rows("SHOW $Xg STATUS WHERE Db = ".q($l),null,"-- ")as$I){$Gb=remove_definer($h->result("SHOW CREATE $Xg ".idf_escape($I["Name"]),2));set_utf8mb4($Gb);$Mf.=($Lh!='DROP+CREATE'?"DROP $Xg IF EXISTS ".idf_escape($I["Name"]).";;\n":"")."$Gb;;\n\n";}}}if($_POST["events"]){foreach(get_rows("SHOW EVENTS",null,"-- ")as$I){$Gb=remove_definer($h->result("SHOW CREATE EVENT ".idf_escape($I["Name"]),3));set_utf8mb4($Gb);$Mf.=($Lh!='DROP+CREATE'?"DROP EVENT IF EXISTS ".idf_escape($I["Name"]).";;\n":"")."$Gb;;\n\n";}}if($Mf)echo"DELIMITER ;;\n\n$Mf"."DELIMITER ;\n\n";}if($_POST["table_style"]||$_POST["data_style"]){$dj=array();foreach(table_status('',true)as$B=>$R){$Q=(DB==""||in_array($B,(array)$_POST["tables"]));$Ob=(DB==""||in_array($B,(array)$_POST["data"]));if($Q||$Ob){if($Kc=="tar"){$oi=new
+TmpFile;ob_start(array($oi,'write'),1e5);}$b->dumpTable($B,($Q?$_POST["table_style"]:""),(is_view($R)?2:0));if(is_view($R))$dj[]=$B;elseif($Ob){$p=fields($B);$b->dumpData($B,$_POST["data_style"],"SELECT *".convert_fields($p,$p)." FROM ".table($B));}if($be&&$_POST["triggers"]&&$Q&&($Ci=trigger_sql($B)))echo"\nDELIMITER ;;\n$Ci\nDELIMITER ;\n";if($Kc=="tar"){ob_end_flush();tar_file((DB!=""?"":"$l/")."$B.csv",$oi);}elseif($be)echo"\n";}}foreach($dj
+as$cj)$b->dumpTable($cj,$_POST["table_style"],1);if($Kc=="tar")echo
+pack("x512");}}}if($be)echo"-- ".$h->result("SELECT NOW()")."\n";exit;}page_header(lang(74),$n,($_GET["export"]!=""?array("table"=>$_GET["export"]):array()),h(DB));echo'
+
+';$Yc=true;foreach($mg
+as$y=>$X){if($y!=""&&$X>1){echo($Yc?"":" ")."".h($y)."";$Yc=false;}}}elseif(isset($_GET["privileges"])){page_header(lang(72));echo' '.lang(146)."";$G=$h->query("SELECT User, Host FROM mysql.".(DB==""?"user":"db WHERE ".q(DB)." LIKE Db")." ORDER BY Host, User");$nd=$G;if(!$G)$G=$h->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host");echo" \n";}elseif(isset($_GET["sql"])){if(!$n&&$_POST["export"]){dump_headers("sql");$b->dumpTable("","");$b->dumpData("","table",$_POST["query"]);exit;}restart_session();$Ad=&get_session("queries");$_d=&$Ad[DB];if(!$n&&$_POST["clear"]){$_d=array();redirect(remove_from_uri("history"));}page_header((isset($_GET["import"])?lang(73):lang(65)),$n);if(!$n&&$_POST){$kd=false;if(!isset($_GET["import"]))$F=$_POST["query"];elseif($_POST["webfile"]){$Ch=$b->importServerPath();$kd=@fopen((file_exists($Ch)?$Ch:"compress.zlib://$Ch.gz"),"rb");$F=($kd?fread($kd,1e6):false);}else$F=get_file("sql_file",true);if(is_string($F)){if(function_exists('memory_get_usage'))@ini_set("memory_limit",max(ini_bytes("memory_limit"),2*strlen($F)+memory_get_usage()+8e6));if($F!=""&&strlen($F)<1e6){$xg=$F.(preg_match("~;[ \t\r\n]*\$~",$F)?"":";");if(!$_d||reset(end($_d))!=$xg){restart_session();$_d[]=array($xg,time());set_session("queries",$Ad);stop_session();}}$_h="(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)";$Yb=";";$C=0;$vc=true;$i=connect();if(is_object($i)&&DB!=""){$i->select_db(DB);if($_GET["ns"]!="")set_schema($_GET["ns"],$i);}$ub=0;$_c=array();$Tf='[\'"'.($x=="sql"?'`#':($x=="sqlite"?'`[':($x=="mssql"?'[':''))).']|/\*|-- |$'.($x=="pgsql"?'|\$[^$]*\$':'');$ti=microtime(true);parse_str($_COOKIE["adminer_export"],$ya);$mc=$b->dumpFormat();unset($mc["sql"]);while($F!=""){if(!$C&&preg_match("~^$_h*+DELIMITER\\s+(\\S+)~i",$F,$A)){$Yb=$A[1];$F=substr($F,strlen($A[0]));}else{preg_match('('.preg_quote($Yb)."\\s*|$Tf)",$F,$A,PREG_OFFSET_CAPTURE,$C);list($id,$hg)=$A[0];if(!$id&&$kd&&!feof($kd))$F.=fread($kd,1e5);else{if(!$id&&rtrim($F)=="")break;$C=$hg+strlen($id);if($id&&rtrim($id)!=$Yb){while(preg_match('('.($id=='/*'?'\*/':($id=='['?']':(preg_match('~^-- |^#~',$id)?"\n":preg_quote($id)."|\\\\."))).'|$)s',$F,$A,PREG_OFFSET_CAPTURE,$C)){$bh=$A[0][0];if(!$bh&&$kd&&!feof($kd))$F.=fread($kd,1e5);else{$C=$A[0][1]+strlen($bh);if($bh[0]!="\\")break;}}}else{$vc=false;$xg=substr($F,0,$hg);$ub++;$pg="".$b->sqlCommandQuery($xg)." \n";if($x=="sqlite"&&preg_match("~^$_h*+ATTACH\\b~i",$xg,$A)){echo$pg,"".lang(147)."\n";$_c[]=" $ub";if($_POST["error_stops"])break;}else{if(!$_POST["only_errors"]){echo$pg;ob_flush();flush();}$Gh=microtime(true);if($h->multi_query($xg)&&is_object($i)&&preg_match("~^$_h*+USE\\b~i",$xg))$i->query($xg);do{$G=$h->store_result();if($h->error){echo($_POST["only_errors"]?$pg:"")," ".lang(148).($h->errno?" ($h->errno)":"").": ".error()."\n";$_c[]=" $ub";if($_POST["error_stops"])break
+2;}else{$hi=" (".format_time($Gh).")".(strlen($xg)<1000?" ".lang(10)."":"");$_a=$h->affected_rows;$gj=($_POST["only_errors"]?"":$m->warnings());$hj="warnings-$ub";if($gj)$hi.=", ".lang(47)."".script("qsl('a').onclick = partial(toggle, '$hj');","");$Hc=null;$Ic="explain-$ub";if(is_object($G)){$z=$_POST["limit"];$Ff=select($G,$i,array(),$z);if(!$_POST["only_errors"]){echo" \n";}}else{if(preg_match("~^$_h*+(CREATE|DROP|ALTER)$_h++(DATABASE|SCHEMA)\\b~i",$xg)){restart_session();set_session("dbs",null);stop_session();}if(!$_POST["only_errors"])echo"".lang(151,$_a)."$hi\n";}echo($gj?" \n$gj \n":"");if($Hc){echo"\n";select($Hc,$i,$Ff);echo" \n";}}$Gh=microtime(true);}while($h->next_result());}$F=substr($F,$C);$C=0;}}}}if($vc)echo"".lang(152)."\n";elseif($_POST["only_errors"]){echo" ".lang(153,$ub-count($_c))," (".format_time($ti).")\n";}elseif($_c&&$ub>1)echo" ".lang(148).": ".implode("",$_c)."\n";}else
+echo" ".upload_error($F)."\n";}echo'
+
+';}elseif(isset($_GET["edit"])){$a=$_GET["edit"];$p=fields($a);$Z=(isset($_GET["select"])?($_POST["check"]&&count($_POST["check"])==1?where_check($_POST["check"][0],$p):""):where($_GET,$p));$Mi=(isset($_GET["select"])?$_POST["edit"]:$Z);foreach($p
+as$B=>$o){if(!isset($o["privileges"][$Mi?"update":"insert"])||$b->fieldName($o)==""||$o["generated"])unset($p[$B]);}if($_POST&&!$n&&!isset($_GET["select"])){$_e=$_POST["referer"];if($_POST["insert"])$_e=($Mi?null:$_SERVER["REQUEST_URI"]);elseif(!preg_match('~^.+&select=.+$~',$_e))$_e=ME."select=".urlencode($a);$w=indexes($a);$Hi=unique_array($_GET["where"],$w);$_g="\nWHERE $Z";if(isset($_POST["delete"]))queries_redirect($_e,lang(166),$m->delete($a,$_g,!$Hi));else{$N=array();foreach($p
+as$B=>$o){$X=process_input($o);if($X!==false&&$X!==null)$N[idf_escape($B)]=$X;}if($Mi){if(!$N)redirect($_e);queries_redirect($_e,lang(167),$m->update($a,$N,$_g,!$Hi));if(is_ajax()){page_headers();page_messages($n);exit;}}else{$G=$m->insert($a,$N);$re=($G?last_id():0);queries_redirect($_e,lang(168,($re?" $re":"")),$G);}}}$I=null;if($_POST["save"])$I=(array)$_POST["fields"];elseif($Z){$K=array();foreach($p
+as$B=>$o){if(isset($o["privileges"]["select"])){$Ha=convert_field($o);if($_POST["clone"]&&$o["auto_increment"])$Ha="''";if($x=="sql"&&preg_match("~enum|set~",$o["type"]))$Ha="1*".idf_escape($B);$K[]=($Ha?"$Ha AS ":"").idf_escape($B);}}$I=array();if(!support("table"))$K=array("*");if($K){$G=$m->select($a,$K,array($Z),$K,array(),(isset($_GET["select"])?2:1));if(!$G)$n=error();else{$I=$G->fetch_assoc();if(!$I)$I=false;}if(isset($_GET["select"])&&(!$I||$G->fetch_assoc()))$I=null;}}if(!support("table")&&!$p){if(!$Z){$G=$m->select($a,array("*"),$Z,array("*"));$I=($G?$G->fetch_assoc():false);if(!$I)$I=array($m->primary=>"");}if($I){foreach($I
+as$y=>$X){if(!$Z)$I[$y]=null;$p[$y]=array("field"=>$y,"null"=>($y!=$m->primary),"auto_increment"=>($y==$m->primary));}}}edit_form($a,$p,$I,$Mi);}elseif(isset($_GET["create"])){$a=$_GET["create"];$Vf=array();foreach(array('HASH','LINEAR HASH','KEY','LINEAR KEY','RANGE','LIST')as$y)$Vf[$y]=$y;$Hg=referencable_primary($a);$gd=array();foreach($Hg
+as$Sh=>$o)$gd[str_replace("`","``",$Sh)."`".str_replace("`","``",$o["field"])]=$Sh;$If=array();$R=array();if($a!=""){$If=fields($a);$R=table_status($a);if(!$R)$n=lang(9);}$I=$_POST;$I["fields"]=(array)$I["fields"];if($I["auto_increment_col"])$I["fields"][$I["auto_increment_col"]]["auto_increment"]=true;if($_POST)set_adminer_settings(array("comments"=>$_POST["comments"],"defaults"=>$_POST["defaults"]));if($_POST&&!process_fields($I["fields"])&&!$n){if($_POST["drop"])queries_redirect(substr(ME,0,-1),lang(169),drop_tables(array($a)));else{$p=array();$Ea=array();$Ri=false;$ed=array();$Hf=reset($If);$Ba=" FIRST";foreach($I["fields"]as$y=>$o){$q=$gd[$o["type"]];$Di=($q!==null?$Hg[$q]:$o);if($o["field"]!=""){if(!$o["has_default"])$o["default"]=null;if($y==$I["auto_increment_col"])$o["auto_increment"]=true;$ug=process_field($o,$Di);$Ea[]=array($o["orig"],$ug,$Ba);if($ug!=process_field($Hf,$Hf)){$p[]=array($o["orig"],$ug,$Ba);if($o["orig"]!=""||$Ba)$Ri=true;}if($q!==null)$ed[idf_escape($o["field"])]=($a!=""&&$x!="sqlite"?"ADD":" ").format_foreign_key(array('table'=>$gd[$o["type"]],'source'=>array($o["field"]),'target'=>array($Di["field"]),'on_delete'=>$o["on_delete"],));$Ba=" AFTER ".idf_escape($o["field"]);}elseif($o["orig"]!=""){$Ri=true;$p[]=array($o["orig"]);}if($o["orig"]!=""){$Hf=next($If);if(!$Hf)$Ba="";}}$Xf="";if($Vf[$I["partition_by"]]){$Yf=array();if($I["partition_by"]=='RANGE'||$I["partition_by"]=='LIST'){foreach(array_filter($I["partition_names"])as$y=>$X){$Y=$I["partition_values"][$y];$Yf[]="\n PARTITION ".idf_escape($X)." VALUES ".($I["partition_by"]=='RANGE'?"LESS THAN":"IN").($Y!=""?" ($Y)":" MAXVALUE");}}$Xf.="\nPARTITION BY $I[partition_by]($I[partition])".($Yf?" (".implode(",",$Yf)."\n)":($I["partitions"]?" PARTITIONS ".(+$I["partitions"]):""));}elseif(support("partitioning")&&preg_match("~partitioned~",$R["Create_options"]))$Xf.="\nREMOVE PARTITIONING";$Oe=lang(170);if($a==""){cookie("adminer_engine",$I["Engine"]);$Oe=lang(171);}$B=trim($I["name"]);queries_redirect(ME.(support("table")?"table=":"select=").urlencode($B),$Oe,alter_table($a,$B,($x=="sqlite"&&($Ri||$ed)?$Ea:$p),$ed,($I["Comment"]!=$R["Comment"]?$I["Comment"]:null),($I["Engine"]&&$I["Engine"]!=$R["Engine"]?$I["Engine"]:""),($I["Collation"]&&$I["Collation"]!=$R["Collation"]?$I["Collation"]:""),($I["Auto_increment"]!=""?number($I["Auto_increment"]):""),$Xf));}}page_header(($a!=""?lang(45):lang(75)),$n,array("table"=>$a),h($a));if(!$_POST){$I=array("Engine"=>$_COOKIE["adminer_engine"],"fields"=>array(array("field"=>"","type"=>(isset($U["int"])?"int":(isset($U["integer"])?"integer":"")),"on_update"=>"")),"partition_names"=>array(""),);if($a!=""){$I=$R;$I["name"]=$a;$I["fields"]=array();if(!$_GET["auto_increment"])$I["Auto_increment"]="";foreach($If
+as$o){$o["has_default"]=isset($o["default"]);$I["fields"][]=$o;}if(support("partitioning")){$ld="FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = ".q(DB)." AND TABLE_NAME = ".q($a);$G=$h->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $ld ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");list($I["partition_by"],$I["partitions"],$I["partition"])=$G->fetch_row();$Yf=get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $ld AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");$Yf[""]="";$I["partition_names"]=array_keys($Yf);$I["partition_values"]=array_values($Yf);}}}$qb=collations();$xc=engines();foreach($xc
+as$wc){if(!strcasecmp($wc,$I["Engine"])){$I["Engine"]=$wc;break;}}echo'
+
+',script("qs('#form')['defaults'].onclick();".(support("comment")?" editingCommentsClick(qs('#form')['comments']);":""));}elseif(isset($_GET["indexes"])){$a=$_GET["indexes"];$Ld=array("PRIMARY","UNIQUE","INDEX");$R=table_status($a,true);if(preg_match('~MyISAM|M?aria'.(min_version(5.6,'10.0.5')?'|InnoDB':'').'~i',$R["Engine"]))$Ld[]="FULLTEXT";if(preg_match('~MyISAM|M?aria'.(min_version(5.7,'10.2.2')?'|InnoDB':'').'~i',$R["Engine"]))$Ld[]="SPATIAL";$w=indexes($a);$ng=array();if($x=="mongo"){$ng=$w["_id_"];unset($Ld[0]);unset($w["_id_"]);}$I=$_POST;if($_POST&&!$n&&!$_POST["add"]&&!$_POST["drop_col"]){$c=array();foreach($I["indexes"]as$v){$B=$v["name"];if(in_array($v["type"],$Ld)){$f=array();$xe=array();$ac=array();$N=array();ksort($v["columns"]);foreach($v["columns"]as$y=>$e){if($e!=""){$we=$v["lengths"][$y];$Zb=$v["descs"][$y];$N[]=idf_escape($e).($we?"(".(+$we).")":"").($Zb?" DESC":"");$f[]=$e;$xe[]=($we?$we:null);$ac[]=$Zb;}}if($f){$Fc=$w[$B];if($Fc){ksort($Fc["columns"]);ksort($Fc["lengths"]);ksort($Fc["descs"]);if($v["type"]==$Fc["type"]&&array_values($Fc["columns"])===$f&&(!$Fc["lengths"]||array_values($Fc["lengths"])===$xe)&&array_values($Fc["descs"])===$ac){unset($w[$B]);continue;}}$c[]=array($v["type"],$B,$N);}}}foreach($w
+as$B=>$Fc)$c[]=array($Fc["type"],$B,"DROP");if(!$c)redirect(ME."table=".urlencode($a));queries_redirect(ME."table=".urlencode($a),lang(180),alter_indexes($a,$c));}page_header(lang(132),$n,array("table"=>$a),h($a));$p=array_keys(fields($a));if($_POST["add"]){foreach($I["indexes"]as$y=>$v){if($v["columns"][count($v["columns"])]!="")$I["indexes"][$y]["columns"][]="";}$v=end($I["indexes"]);if($v["type"]||array_filter($v["columns"],'strlen'))$I["indexes"][]=array("columns"=>array(1=>""));}if(!$I){foreach($w
+as$y=>$v){$w[$y]["name"]=$y;$w[$y]["columns"][]="";}$w[]=array("columns"=>array(1=>""));$I["indexes"]=$w;}echo'
+
+';}elseif(isset($_GET["database"])){$I=$_POST;if($_POST&&!$n&&!isset($_POST["add_x"])){$B=trim($I["name"]);if($_POST["drop"]){$_GET["db"]="";queries_redirect(remove_from_uri("db|database"),lang(184),drop_databases(array(DB)));}elseif(DB!==$B){if(DB!=""){$_GET["db"]=$B;queries_redirect(preg_replace('~\bdb=[^&]*&~','',ME)."db=".urlencode($B),lang(185),rename_database($B,$I["collation"]));}else{$k=explode("\n",str_replace("\r","",$B));$Mh=true;$qe="";foreach($k
+as$l){if(count($k)==1||$l!=""){if(!create_database($l,$I["collation"]))$Mh=false;$qe=$l;}}restart_session();set_session("dbs",null);queries_redirect(ME."db=".urlencode($qe),lang(186),$Mh);}}else{if(!$I["collation"])redirect(substr(ME,0,-1));query_redirect("ALTER DATABASE ".idf_escape($B).(preg_match('~^[a-z0-9_]+$~i',$I["collation"])?" COLLATE $I[collation]":""),substr(ME,0,-1),lang(187));}}page_header(DB!=""?lang(68):lang(115),$n,array(),h(DB));$qb=collations();$B=DB;if($_POST)$B=$I["name"];elseif(DB!="")$I["collation"]=db_collation(DB,$qb);elseif($x=="sql"){foreach(get_vals("SHOW GRANTS")as$nd){if(preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\.\*)?~',$nd,$A)&&$A[1]){$B=stripcslashes(idf_unescape("`$A[2]`"));break;}}}echo'
+
+';}elseif(isset($_GET["scheme"])){$I=$_POST;if($_POST&&!$n){$_=preg_replace('~ns=[^&]*&~','',ME)."ns=";if($_POST["drop"])query_redirect("DROP SCHEMA ".idf_escape($_GET["ns"]),$_,lang(188));else{$B=trim($I["name"]);$_.=urlencode($B);if($_GET["ns"]=="")query_redirect("CREATE SCHEMA ".idf_escape($B),$_,lang(189));elseif($_GET["ns"]!=$B)query_redirect("ALTER SCHEMA ".idf_escape($_GET["ns"])." RENAME TO ".idf_escape($B),$_,lang(190));else
+redirect($_);}}page_header($_GET["ns"]!=""?lang(69):lang(70),$n);if(!$I)$I["name"]=$_GET["ns"];echo'
+
+';}elseif(isset($_GET["call"])){$da=($_GET["name"]?$_GET["name"]:$_GET["call"]);page_header(lang(191).": ".h($da),$n);$Xg=routine($_GET["call"],(isset($_GET["callf"])?"FUNCTION":"PROCEDURE"));$Jd=array();$Mf=array();foreach($Xg["fields"]as$s=>$o){if(substr($o["inout"],-3)=="OUT")$Mf[$s]="@".idf_escape($o["field"])." AS ".idf_escape($o["field"]);if(!$o["inout"]||substr($o["inout"],0,2)=="IN")$Jd[]=$s;}if(!$n&&$_POST){$bb=array();foreach($Xg["fields"]as$y=>$o){if(in_array($y,$Jd)){$X=process_input($o);if($X===false)$X="''";if(isset($Mf[$y]))$h->query("SET @".idf_escape($o["field"])." = $X");}$bb[]=(isset($Mf[$y])?"@".idf_escape($o["field"]):$X);}$F=(isset($_GET["callf"])?"SELECT":"CALL")." ".table($da)."(".implode(", ",$bb).")";$Gh=microtime(true);$G=$h->multi_query($F);$_a=$h->affected_rows;echo$b->selectQuery($F,$Gh,!$G);if(!$G)echo"".error()."\n";else{$i=connect();if(is_object($i))$i->select_db(DB);do{$G=$h->store_result();if(is_object($G))select($G,$i);else
+echo" ".lang(192,$_a)."\n";}while($h->next_result());if($Mf)select($h->query("SELECT ".implode(", ",$Mf)));}}echo'
+
+';}elseif(isset($_GET["foreign"])){$a=$_GET["foreign"];$B=$_GET["name"];$I=$_POST;if($_POST&&!$n&&!$_POST["add"]&&!$_POST["change"]&&!$_POST["change-js"]){$Oe=($_POST["drop"]?lang(193):($B!=""?lang(194):lang(195)));$_e=ME."table=".urlencode($a);if(!$_POST["drop"]){$I["source"]=array_filter($I["source"],'strlen');ksort($I["source"]);$ai=array();foreach($I["source"]as$y=>$X)$ai[$y]=$I["target"][$y];$I["target"]=$ai;}if($x=="sqlite")queries_redirect($_e,$Oe,recreate_table($a,$a,array(),array(),array(" $B"=>($_POST["drop"]?"":" ".format_foreign_key($I)))));else{$c="ALTER TABLE ".table($a);$hc="\nDROP ".($x=="sql"?"FOREIGN KEY ":"CONSTRAINT ").idf_escape($B);if($_POST["drop"])query_redirect($c.$hc,$_e,$Oe);else{query_redirect($c.($B!=""?"$hc,":"")."\nADD".format_foreign_key($I),$_e,$Oe);$n=lang(196)." $n";}}}page_header(lang(197),$n,array("table"=>$a),h($a));if($_POST){ksort($I["source"]);if($_POST["add"])$I["source"][]="";elseif($_POST["change"]||$_POST["change-js"])$I["target"]=array();}elseif($B!=""){$gd=foreign_keys($a);$I=$gd[$B];$I["source"][]="";}else{$I["table"]=$a;$I["source"]=array("");}echo'
+
+';}elseif(isset($_GET["view"])){$a=$_GET["view"];$I=$_POST;$Jf="VIEW";if($x=="pgsql"&&$a!=""){$O=table_status($a);$Jf=strtoupper($O["Engine"]);}if($_POST&&!$n){$B=trim($I["name"]);$Ha=" AS\n$I[select]";$_e=ME."table=".urlencode($B);$Oe=lang(201);$T=($_POST["materialized"]?"MATERIALIZED VIEW":"VIEW");if(!$_POST["drop"]&&$a==$B&&$x!="sqlite"&&$T=="VIEW"&&$Jf=="VIEW")query_redirect(($x=="mssql"?"ALTER":"CREATE OR REPLACE")." VIEW ".table($B).$Ha,$_e,$Oe);else{$ci=$B."_adminer_".uniqid();drop_create("DROP $Jf ".table($a),"CREATE $T ".table($B).$Ha,"DROP $T ".table($B),"CREATE $T ".table($ci).$Ha,"DROP $T ".table($ci),($_POST["drop"]?substr(ME,0,-1):$_e),lang(202),$Oe,lang(203),$a,$B);}}if(!$_POST&&$a!=""){$I=view($a);$I["name"]=$a;$I["materialized"]=($Jf!="VIEW");if(!$n)$n=error();}page_header(($a!=""?lang(44):lang(204)),$n,array("table"=>$a),h($a));echo'
+
+';}elseif(isset($_GET["event"])){$aa=$_GET["event"];$Wd=array("YEAR","QUARTER","MONTH","DAY","HOUR","MINUTE","WEEK","SECOND","YEAR_MONTH","DAY_HOUR","DAY_MINUTE","DAY_SECOND","HOUR_MINUTE","HOUR_SECOND","MINUTE_SECOND");$Ih=array("ENABLED"=>"ENABLE","DISABLED"=>"DISABLE","SLAVESIDE_DISABLED"=>"DISABLE ON SLAVE");$I=$_POST;if($_POST&&!$n){if($_POST["drop"])query_redirect("DROP EVENT ".idf_escape($aa),substr(ME,0,-1),lang(205));elseif(in_array($I["INTERVAL_FIELD"],$Wd)&&isset($Ih[$I["STATUS"]])){$ch="\nON SCHEDULE ".($I["INTERVAL_VALUE"]?"EVERY ".q($I["INTERVAL_VALUE"])." $I[INTERVAL_FIELD]".($I["STARTS"]?" STARTS ".q($I["STARTS"]):"").($I["ENDS"]?" ENDS ".q($I["ENDS"]):""):"AT ".q($I["STARTS"]))." ON COMPLETION".($I["ON_COMPLETION"]?"":" NOT")." PRESERVE";queries_redirect(substr(ME,0,-1),($aa!=""?lang(206):lang(207)),queries(($aa!=""?"ALTER EVENT ".idf_escape($aa).$ch.($aa!=$I["EVENT_NAME"]?"\nRENAME TO ".idf_escape($I["EVENT_NAME"]):""):"CREATE EVENT ".idf_escape($I["EVENT_NAME"]).$ch)."\n".$Ih[$I["STATUS"]]." COMMENT ".q($I["EVENT_COMMENT"]).rtrim(" DO\n$I[EVENT_DEFINITION]",";").";"));}}page_header(($aa!=""?lang(208).": ".h($aa):lang(209)),$n);if(!$I&&$aa!=""){$J=get_rows("SELECT * FROM information_schema.EVENTS WHERE EVENT_SCHEMA = ".q(DB)." AND EVENT_NAME = ".q($aa));$I=reset($J);}echo'
+
+';}elseif(isset($_GET["procedure"])){$da=($_GET["name"]?$_GET["name"]:$_GET["procedure"]);$Xg=(isset($_GET["function"])?"FUNCTION":"PROCEDURE");$I=$_POST;$I["fields"]=(array)$I["fields"];if($_POST&&!process_fields($I["fields"])&&!$n){$Gf=routine($_GET["procedure"],$Xg);$ci="$I[name]_adminer_".uniqid();drop_create("DROP $Xg ".routine_id($da,$Gf),create_routine($Xg,$I),"DROP $Xg ".routine_id($I["name"],$I),create_routine($Xg,array("name"=>$ci)+$I),"DROP $Xg ".routine_id($ci,$I),substr(ME,0,-1),lang(214),lang(215),lang(216),$da,$I["name"]);}page_header(($da!=""?(isset($_GET["function"])?lang(217):lang(218)).": ".h($da):(isset($_GET["function"])?lang(219):lang(220))),$n);if(!$_POST&&$da!=""){$I=routine($_GET["procedure"],$Xg);$I["name"]=$da;}$qb=get_vals("SHOW CHARACTER SET");sort($qb);$Yg=routine_languages();echo'
+
+';}elseif(isset($_GET["sequence"])){$fa=$_GET["sequence"];$I=$_POST;if($_POST&&!$n){$_=substr(ME,0,-1);$B=trim($I["name"]);if($_POST["drop"])query_redirect("DROP SEQUENCE ".idf_escape($fa),$_,lang(222));elseif($fa=="")query_redirect("CREATE SEQUENCE ".idf_escape($B),$_,lang(223));elseif($fa!=$B)query_redirect("ALTER SEQUENCE ".idf_escape($fa)." RENAME TO ".idf_escape($B),$_,lang(224));else
+redirect($_);}page_header($fa!=""?lang(225).": ".h($fa):lang(226),$n);if(!$I)$I["name"]=$fa;echo'
+
+';}elseif(isset($_GET["type"])){$ga=$_GET["type"];$I=$_POST;if($_POST&&!$n){$_=substr(ME,0,-1);if($_POST["drop"])query_redirect("DROP TYPE ".idf_escape($ga),$_,lang(227));else
+query_redirect("CREATE TYPE ".idf_escape(trim($I["name"]))." $I[as]",$_,lang(228));}page_header($ga!=""?lang(229).": ".h($ga):lang(230),$n);if(!$I)$I["as"]="AS ";echo'
+
+';}elseif(isset($_GET["trigger"])){$a=$_GET["trigger"];$B=$_GET["name"];$Bi=trigger_options();$I=(array)trigger($B)+array("Trigger"=>$a."_bi");if($_POST){if(!$n&&in_array($_POST["Timing"],$Bi["Timing"])&&in_array($_POST["Event"],$Bi["Event"])&&in_array($_POST["Type"],$Bi["Type"])){$sf=" ON ".table($a);$hc="DROP TRIGGER ".idf_escape($B).($x=="pgsql"?$sf:"");$_e=ME."table=".urlencode($a);if($_POST["drop"])query_redirect($hc,$_e,lang(231));else{if($B!="")queries($hc);queries_redirect($_e,($B!=""?lang(232):lang(233)),queries(create_trigger($sf,$_POST)));if($B!="")queries(create_trigger($sf,$I+array("Type"=>reset($Bi["Type"]))));}}$I=$_POST;}page_header(($B!=""?lang(234).": ".h($B):lang(235)),$n,array("table"=>$a));echo'
+
+';}elseif(isset($_GET["user"])){$ha=$_GET["user"];$sg=array(""=>array("All privileges"=>""));foreach(get_rows("SHOW PRIVILEGES")as$I){foreach(explode(",",($I["Privilege"]=="Grant option"?"":$I["Context"]))as$Cb)$sg[$Cb][$I["Privilege"]]=$I["Comment"];}$sg["Server Admin"]+=$sg["File access on server"];$sg["Databases"]["Create routine"]=$sg["Procedures"]["Create routine"];unset($sg["Procedures"]["Create routine"]);$sg["Columns"]=array();foreach(array("Select","Insert","Update","References")as$X)$sg["Columns"][$X]=$sg["Tables"][$X];unset($sg["Server Admin"]["Usage"]);foreach($sg["Tables"]as$y=>$X)unset($sg["Databases"][$y]);$bf=array();if($_POST){foreach($_POST["objects"]as$y=>$X)$bf[$X]=(array)$bf[$X]+(array)$_POST["grants"][$y];}$od=array();$qf="";if(isset($_GET["host"])&&($G=$h->query("SHOW GRANTS FOR ".q($ha)."@".q($_GET["host"])))){while($I=$G->fetch_row()){if(preg_match('~GRANT (.*) ON (.*) TO ~',$I[0],$A)&&preg_match_all('~ *([^(,]*[^ ,(])( *\([^)]+\))?~',$A[1],$Ge,PREG_SET_ORDER)){foreach($Ge
+as$X){if($X[1]!="USAGE")$od["$A[2]$X[2]"][$X[1]]=true;if(preg_match('~ WITH GRANT OPTION~',$I[0]))$od["$A[2]$X[2]"]["GRANT OPTION"]=true;}}if(preg_match("~ IDENTIFIED BY PASSWORD '([^']+)~",$I[0],$A))$qf=$A[1];}}if($_POST&&!$n){$rf=(isset($_GET["host"])?q($ha)."@".q($_GET["host"]):"''");if($_POST["drop"])query_redirect("DROP USER $rf",ME."privileges=",lang(238));else{$df=q($_POST["user"])."@".q($_POST["host"]);$ag=$_POST["pass"];if($ag!=''&&!$_POST["hashed"]&&!min_version(8)){$ag=$h->result("SELECT PASSWORD(".q($ag).")");$n=!$ag;}$Ib=false;if(!$n){if($rf!=$df){$Ib=queries((min_version(5)?"CREATE USER":"GRANT USAGE ON *.* TO")." $df IDENTIFIED BY ".(min_version(8)?"":"PASSWORD ").q($ag));$n=!$Ib;}elseif($ag!=$qf)queries("SET PASSWORD FOR $df = ".q($ag));}if(!$n){$Ug=array();foreach($bf
+as$lf=>$nd){if(isset($_GET["grant"]))$nd=array_filter($nd);$nd=array_keys($nd);if(isset($_GET["grant"]))$Ug=array_diff(array_keys(array_filter($bf[$lf],'strlen')),$nd);elseif($rf==$df){$of=array_keys((array)$od[$lf]);$Ug=array_diff($of,$nd);$nd=array_diff($nd,$of);unset($od[$lf]);}if(preg_match('~^(.+)\s*(\(.*\))?$~U',$lf,$A)&&(!grant("REVOKE",$Ug,$A[2]," ON $A[1] FROM $df")||!grant("GRANT",$nd,$A[2]," ON $A[1] TO $df"))){$n=true;break;}}}if(!$n&&isset($_GET["host"])){if($rf!=$df)queries("DROP USER $rf");elseif(!isset($_GET["grant"])){foreach($od
+as$lf=>$Ug){if(preg_match('~^(.+)(\(.*\))?$~U',$lf,$A))grant("REVOKE",array_keys($Ug),$A[2]," ON $A[1] FROM $df");}}}queries_redirect(ME."privileges=",(isset($_GET["host"])?lang(239):lang(240)),!$n);if($Ib)$h->query("DROP USER $df");}}page_header((isset($_GET["host"])?lang(36).": ".h("$ha@$_GET[host]"):lang(146)),$n,array("privileges"=>array('',lang(72))));if($_POST){$I=$_POST;$od=$bf;}else{$I=$_GET+array("host"=>$h->result("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', -1)"));$I["pass"]=$qf;if($qf!="")$I["hashed"]=true;$od[(DB==""||$od?"":idf_escape(addcslashes(DB,"%_\\"))).".*"]=array();}echo'
+';}elseif(isset($_GET["processlist"])){if(support("kill")&&$_POST&&!$n){$le=0;foreach((array)$_POST["kill"]as$X){if(kill_process($X))$le++;}queries_redirect(ME."processlist=",lang(245,$le),$le||!$_POST["kill"]);}page_header(lang(116),$n);echo'
+
+',script("tableCheck();");}elseif(isset($_GET["select"])){$a=$_GET["select"];$R=table_status1($a);$w=indexes($a);$p=fields($a);$gd=column_foreign_keys($a);$nf=$R["Oid"];parse_str($_COOKIE["adminer_import"],$za);$Vg=array();$f=array();$gi=null;foreach($p
+as$y=>$o){$B=$b->fieldName($o);if(isset($o["privileges"]["select"])&&$B!=""){$f[$y]=html_entity_decode(strip_tags($B),ENT_QUOTES);if(is_shortable($o))$gi=$b->selectLengthProcess();}$Vg+=$o["privileges"];}list($K,$pd)=$b->selectColumnsProcess($f,$w);$ae=count($pd)selectSearchProcess($p,$w);$Cf=$b->selectOrderProcess($p,$w);$z=$b->selectLimitProcess();if($_GET["val"]&&is_ajax()){header("Content-Type: text/plain; charset=utf-8");foreach($_GET["val"]as$Ii=>$I){$Ha=convert_field($p[key($I)]);$K=array($Ha?$Ha:idf_escape(key($I)));$Z[]=where_check($Ii,$p);$H=$m->select($a,$K,$Z,$K);if($H)echo
+reset($H->fetch_row());}exit;}$ng=$Ki=null;foreach($w
+as$v){if($v["type"]=="PRIMARY"){$ng=array_flip($v["columns"]);$Ki=($K?$ng:array());foreach($Ki
+as$y=>$X){if(in_array(idf_escape($y),$K))unset($Ki[$y]);}break;}}if($nf&&!$ng){$ng=$Ki=array($nf=>0);$w[]=array("type"=>"PRIMARY","columns"=>array($nf));}if($_POST&&!$n){$mj=$Z;if(!$_POST["all"]&&is_array($_POST["check"])){$hb=array();foreach($_POST["check"]as$eb)$hb[]=where_check($eb,$p);$mj[]="((".implode(") OR (",$hb)."))";}$mj=($mj?"\nWHERE ".implode(" AND ",$mj):"");if($_POST["export"]){cookie("adminer_import","output=".urlencode($_POST["output"])."&format=".urlencode($_POST["format"]));dump_headers($a);$b->dumpTable($a,"");$ld=($K?implode(", ",$K):"*").convert_fields($f,$p,$K)."\nFROM ".table($a);$rd=($pd&&$ae?"\nGROUP BY ".implode(", ",$pd):"").($Cf?"\nORDER BY ".implode(", ",$Cf):"");if(!is_array($_POST["check"])||$ng)$F="SELECT $ld$mj$rd";else{$Gi=array();foreach($_POST["check"]as$X)$Gi[]="(SELECT".limit($ld,"\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$p).$rd,1).")";$F=implode(" UNION ALL ",$Gi);}$b->dumpData($a,"table",$F);exit;}if(!$b->selectEmailProcess($Z,$gd)){if($_POST["save"]||$_POST["delete"]){$G=true;$_a=0;$N=array();if(!$_POST["delete"]){foreach($f
+as$B=>$X){$X=process_input($p[$B]);if($X!==null&&($_POST["clone"]||$X!==false))$N[idf_escape($B)]=($X!==false?$X:idf_escape($B));}}if($_POST["delete"]||$N){if($_POST["clone"])$F="INTO ".table($a)." (".implode(", ",array_keys($N)).")\nSELECT ".implode(", ",$N)."\nFROM ".table($a);if($_POST["all"]||($ng&&is_array($_POST["check"]))||$ae){$G=($_POST["delete"]?$m->delete($a,$mj):($_POST["clone"]?queries("INSERT $F$mj"):$m->update($a,$N,$mj)));$_a=$h->affected_rows;}else{foreach((array)$_POST["check"]as$X){$ij="\nWHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($X,$p);$G=($_POST["delete"]?$m->delete($a,$ij,1):($_POST["clone"]?queries("INSERT".limit1($a,$F,$ij)):$m->update($a,$N,$ij,1)));if(!$G)break;$_a+=$h->affected_rows;}}}$Oe=lang(249,$_a);if($_POST["clone"]&&$G&&$_a==1){$re=last_id();if($re)$Oe=lang(168," $re");}queries_redirect(remove_from_uri($_POST["all"]&&$_POST["delete"]?"page":""),$Oe,$G);if(!$_POST["delete"]){edit_form($a,$p,(array)$_POST["fields"],!$_POST["clone"]);page_footer();exit;}}elseif(!$_POST["import"]){if(!$_POST["val"])$n=lang(250);else{$G=true;$_a=0;foreach($_POST["val"]as$Ii=>$I){$N=array();foreach($I
+as$y=>$X){$y=bracket_escape($y,1);$N[idf_escape($y)]=(preg_match('~char|text~',$p[$y]["type"])||$X!=""?$b->processInput($p[$y],$X):"NULL");}$G=$m->update($a,$N," WHERE ".($Z?implode(" AND ",$Z)." AND ":"").where_check($Ii,$p),!$ae&&!$ng," ");if(!$G)break;$_a+=$h->affected_rows;}queries_redirect(remove_from_uri(),lang(249,$_a),$G);}}elseif(!is_string($Vc=get_file("csv_file",true)))$n=upload_error($Vc);elseif(!preg_match('~~u',$Vc))$n=lang(251);else{cookie("adminer_import","output=".urlencode($za["output"])."&format=".urlencode($_POST["separator"]));$G=true;$sb=array_keys($p);preg_match_all('~(?>"[^"]*"|[^"\r\n]+)+~',$Vc,$Ge);$_a=count($Ge[0]);$m->begin();$L=($_POST["separator"]=="csv"?",":($_POST["separator"]=="tsv"?"\t":";"));$J=array();foreach($Ge[0]as$y=>$X){preg_match_all("~((?>\"[^\"]*\")+|[^$L]*)$L~",$X.$L,$He);if(!$y&&!array_diff($He[1],$sb)){$sb=$He[1];$_a--;}else{$N=array();foreach($He[1]as$s=>$ob)$N[idf_escape($sb[$s])]=($ob==""&&$p[$sb[$s]]["null"]?"NULL":q(str_replace('""','"',preg_replace('~^"|"$~','',$ob))));$J[]=$N;}}$G=(!$J||$m->insertUpdate($a,$J,$ng));if($G)$G=$m->commit();queries_redirect(remove_from_uri("page"),lang(252,$_a),$G);$m->rollback();}}}$Sh=$b->tableName($R);if(is_ajax()){page_headers();ob_start();}else
+page_header(lang(54).": $Sh",$n);$N=null;if(isset($Vg["insert"])||!support("table")){$N="";foreach((array)$_GET["where"]as$X){if($gd[$X["col"]]&&count($gd[$X["col"]])==1&&($X["op"]=="="||(!$X["op"]&&!preg_match('~[_%]~',$X["val"]))))$N.="&set".urlencode("[".bracket_escape($X["col"])."]")."=".urlencode($X["val"]);}}$b->selectLinks($R,$N);if(!$f&&support("table"))echo"".lang(253).($p?".":": ".error())."\n";else{echo" \n";$D=$_GET["page"];if($D=="last"){$jd=$h->result(count_rows($a,$Z,$ae,$pd));$D=floor(max(0,$jd-1)/$z);}$hh=$K;$qd=$pd;if(!$hh){$hh[]="*";$Db=convert_fields($f,$p,$K);if($Db)$hh[]=substr($Db,2);}foreach($K
+as$y=>$X){$o=$p[idf_unescape($X)];if($o&&($Ha=convert_field($o)))$hh[$y]="$Ha AS $X";}if(!$ae&&$Ki){foreach($Ki
+as$y=>$X){$hh[]=idf_escape($y);if($qd)$qd[]=idf_escape($y);}}$G=$m->select($a,$hh,$Z,$qd,$Cf,$z,$D,true);if(!$G)echo"".error()."\n";else{if($x=="mssql"&&$D)$G->seek($z*$D);$uc=array();echo" \n",(!$pd&&$K?"":script("tableCheck();"));}}}if(is_ajax()){ob_end_clean();exit;}}elseif(isset($_GET["variables"])){$O=isset($_GET["status"]);page_header($O?lang(118):lang(117));$Zi=($O?show_status():show_variables());if(!$Zi)echo"".lang(12)."\n";else{echo" \n";foreach($Zi
+as$y=>$X){echo"","".h($y)." "," | ".h($X);}echo" | \n";}}elseif(isset($_GET["script"])){header("Content-Type: text/javascript; charset=utf-8");if($_GET["script"]=="db"){$Ph=array("Data_length"=>0,"Index_length"=>0,"Data_free"=>0);foreach(table_status()as$B=>$R){json_row("Comment-$B",h($R["Comment"]));if(!is_view($R)){foreach(array("Engine","Collation")as$y)json_row("$y-$B",h($R[$y]));foreach($Ph+array("Auto_increment"=>0,"Rows"=>0)as$y=>$X){if($R[$y]!=""){$X=format_number($R[$y]);json_row("$y-$B",($y=="Rows"&&$X&&$R["Engine"]==($Bh=="pgsql"?"table":"InnoDB")?"~ $X":$X));if(isset($Ph[$y]))$Ph[$y]+=($R["Engine"]!="InnoDB"||$y!="Data_free"?$R[$y]:0);}elseif(array_key_exists($y,$R))json_row("$y-$B");}}}foreach($Ph
+as$y=>$X)json_row("sum-$y",format_number($X));json_row("");}elseif($_GET["script"]=="kill")$h->query("KILL ".number($_POST["kill"]));else{foreach(count_tables($b->databases())as$l=>$X){json_row("tables-$l",$X);json_row("size-$l",db_size($l));}json_row("");}exit;}else{$Yh=array_merge((array)$_POST["tables"],(array)$_POST["views"]);if($Yh&&!$n&&!$_POST["search"]){$G=true;$Oe="";if($x=="sql"&&$_POST["tables"]&&count($_POST["tables"])>1&&($_POST["drop"]||$_POST["truncate"]||$_POST["copy"]))queries("SET foreign_key_checks = 0");if($_POST["truncate"]){if($_POST["tables"])$G=truncate_tables($_POST["tables"]);$Oe=lang(263);}elseif($_POST["move"]){$G=move_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Oe=lang(264);}elseif($_POST["copy"]){$G=copy_tables((array)$_POST["tables"],(array)$_POST["views"],$_POST["target"]);$Oe=lang(265);}elseif($_POST["drop"]){if($_POST["views"])$G=drop_views($_POST["views"]);if($G&&$_POST["tables"])$G=drop_tables($_POST["tables"]);$Oe=lang(266);}elseif($x!="sql"){$G=($x=="sqlite"?queries("VACUUM"):apply_queries("VACUUM".($_POST["optimize"]?"":" ANALYZE"),$_POST["tables"]));$Oe=lang(267);}elseif(!$_POST["tables"])$Oe=lang(9);elseif($G=queries(($_POST["optimize"]?"OPTIMIZE":($_POST["check"]?"CHECK":($_POST["repair"]?"REPAIR":"ANALYZE")))." TABLE ".implode(", ",array_map('idf_escape',$_POST["tables"])))){while($I=$G->fetch_assoc())$Oe.="".h($I["Table"]).": ".h($I["Msg_text"])." ";}queries_redirect(substr(ME,0,-1),$Oe,$G);}page_header(($_GET["ns"]==""?lang(38).": ".h(DB):lang(78).": ".h($_GET["ns"])),$n,true);if($b->homepage()){if($_GET["ns"]!==""){echo"".lang(268)."\n";$Xh=tables_list();if(!$Xh)echo"".lang(9)."\n";else{echo" \n",script("tableCheck();");}echo''.lang(75)."\n",(support("view")?''.lang(204)."\n":"");if(support("routine")){echo" ".lang(143)."\n";$Zg=routines();if($Zg){echo"\n",''.lang(183).' | '.lang(50).' | '.lang(221)." | | \n";odd('');foreach($Zg
+as$I){$B=($I["SPECIFIC_NAME"]==$I["ROUTINE_NAME"]?"":"&name=".urlencode($I["ROUTINE_NAME"]));echo'',''.h($I["ROUTINE_NAME"]).'',' | '.h($I["ROUTINE_TYPE"]),' | '.h($I["DTD_IDENTIFIER"]),' | '.lang(136)."";}echo" | \n";}echo''.(support("procedure")?''.lang(220).'':'').''.lang(219)."\n";}if(support("sequence")){echo" ".lang(285)."\n";$nh=get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema() ORDER BY sequence_name");if($nh){echo"\n","".lang(183)." | \n";odd('');foreach($nh
+as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(226)."\n";}if(support("type")){echo" ".lang(26)."\n";$Ui=types();if($Ui){echo"\n","".lang(183)." | \n";odd('');foreach($Ui
+as$X)echo"".h($X)."\n";echo" |
---|
\n";}echo"".lang(230)."\n";}if(support("event")){echo" ".lang(144)."\n";$J=get_rows("SHOW EVENTS");if($J){echo"\n","".lang(183)." | ".lang(286)." | ".lang(210)." | ".lang(211)." | | \n";foreach($J
+as$I){echo"","".h($I["Name"])," | ".($I["Execute at"]?lang(287)." | ".$I["Execute at"]:lang(212)." ".$I["Interval value"]." ".$I["Interval field"]." | $I[Starts]")," | $I[Ends]",' | '.lang(136).'';}echo" | \n";$Bc=$h->result("SELECT @@event_scheduler");if($Bc&&$Bc!="ON")echo"event_scheduler : ".h($Bc)."\n";}echo'
'.lang(209)."\n";}if($Xh)echo
+script("ajaxSetHtml('".js_escape(ME)."script=db');");}}}page_footer();
\ No newline at end of file
diff --git a/android-chrome-192x192.png b/android-chrome-192x192.png
new file mode 100644
index 0000000..644fcb0
Binary files /dev/null and b/android-chrome-192x192.png differ
diff --git a/android-chrome-512x512.png b/android-chrome-512x512.png
new file mode 100644
index 0000000..f101920
Binary files /dev/null and b/android-chrome-512x512.png differ
diff --git a/app.php b/app.php
new file mode 100644
index 0000000..694a23b
--- /dev/null
+++ b/app.php
@@ -0,0 +1,754 @@
+'POST']);
+ $form->field('username', ['required'=>true, 'label'=>'Jméno']);
+ $form->field('password', ['type'=>'password', 'required'=>true, 'label'=>'Heslo']);
+ $form->field('_login', ['type'=>'submit', 'label'=>'Přihlásit se']);
+
+ if ($req->getMethod()=='POST') {
+ $form->fill($req->getParsedBody());
+ if ($form->validate()) {
+ $uz = $rows->one('users', ['username'=>$form->values['username'], 'is_active'=>1]);
+ if (!$uz) {
+ $form->error('username', 'Uživatel nenalezen');
+ } elseif (password_verify($form->values['password'], $uz['password'])) {
+ unset($uz['password']);
+ $_SESSION['user'] = $uz;
+ return redirect('/');
+ } else {
+ $form->error('password', 'Špatné heslo.');
+ }
+ }
+ }
+ return render('form', ['form'=>$form]);
+});
+
+route('', '/logout/', function ($req){
+ unset($_SESSION['user']);
+ unset($_SESSION['flashes']);
+ return redirect('/');
+});
+
+route('', '/zmena-hesla/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $form = new form(['method'=>'post']);
+ $form->field('password_current', ['required'=>true, 'type'=>'password', 'label'=>'Stávající heslo']);
+ $form->field('password', ['required'=>true, 'type'=>'password', 'label'=>'Nové heslo']);
+ $form->field('password_again', ['required'=>true, 'type'=>'password', 'label'=>'Nové heslo znovu']);
+ $form->field('_sbt', ['label'=>'Změnit heslo', 'type'=>'submit']);
+
+ $form->rule('password_again', function ($v, $o){
+ return $v==$o['password'];
+ }, 'Hesla se neshodují!');
+
+ $uz = $rows->one('users', $user['id']);
+
+ $form->rule('password_current', function ($v, $o) use ($uz) {
+ return password_verify($v, $uz['password']);
+ }, 'Špatné zadané současné heslo!');
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody()) && $form->validate()) {
+ $rows->update('users', [
+ 'password'=>password_hash($form->values['password'], PASSWORD_DEFAULT)
+ ], [
+ 'id'=>$user['id']
+ ]);
+ flash('Heslo změněno.');
+ return redirect('/');
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Změnit heslo']);
+});
+
+// SKLAD
+
+route('GET', '/sklad/', function ($req){
+ if (!user()) return redirect('/login/');
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ $items = $rows->page('items', ['is_active'=>1], ['ord'=>'asc']);
+
+ return render('items', ['items'=>$items]);
+});
+
+$singletons['nabidka_form'] = function (){
+ $form = new severak\forms\form(['method'=>'POST']);
+ $form->field('name', ['required'=>true, 'label'=>'Název']);
+ $form->field('price', ['type'=>'number', 'label'=>'Cena']);
+ $form->field('note', ['type'=>'textarea', 'label'=>'Poznámka']);
+ $form->field('ord', ['type'=>'number', 'label'=>'Pořadí']);
+ $form->field('is_amount_tracked', ['type'=>'checkbox', 'label'=>'Hlídat počet na skladě?']);
+ $form->field('amount', ['type'=>'number', 'label'=>'Počet na skladě']);
+ $form->field('_save', ['type'=>'submit', 'label'=>'Přidat']);
+
+ $form->rule('price', function ($f){
+ return $f > 0 || $f < 0;
+ }, 'Cena nemůže být nulová.');
+
+ return $form;
+};
+
+route('', '/sklad/pridat/', function ($req){
+ if (!user()) return redirect('/login/');
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ /** @var severak\forms\form $form */
+ $form = di('nabidka_form');
+
+ if ($req->getMethod()=='POST') {
+ $form->fill($req->getParsedBody());
+ if ($form->validate()) {
+ $rows->insert('items', [
+ 'name'=>$form->values['name'],
+ 'price'=>$form->values['price'],
+ 'note'=>$form->values['note'],
+ 'ord'=>$form->values['ord'],
+ 'amount'=>$form->values['amount'],
+ 'is_amount_tracked'=>$form->values['is_amount_tracked'],
+ ]);
+ return redirect('/sklad/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Přidat položku']);
+});
+
+route('', '/sklad/upravit/{id}/', function ($req, $params){
+ if (!user()) return redirect('/login/');
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ /** @var severak\forms\form $form */
+ $form = di('nabidka_form');
+
+ $item = $rows->one('items', $params['id']);
+ if (!$item) return notFound();
+ $form->fill($item);
+
+ if ($req->getMethod()=='POST') {
+ $form->fill($req->getParsedBody());
+ if ($form->validate()) {
+ $rows->update('items', [
+ 'name'=>$form->values['name'],
+ 'price'=>$form->values['price'],
+ 'note'=>$form->values['note'],
+ 'ord'=>$form->values['ord'],
+ 'amount'=>$form->values['amount'],
+ 'is_amount_tracked'=>$form->values['is_amount_tracked'],
+ ], $params['id']);
+ return redirect('/sklad/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Upravit položku']);
+});
+
+// TODO - tohle nechceme přes GET
+route('', '/sklad/smazat/{id}/', function ($req, $params){
+ if (!user()) return redirect('/login/');
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ $rows->update('items', ['is_active'=>0], ['id'=>$params['id'] ]);
+ return redirect('/sklad/');
+});
+
+// ČLENOVÉ
+route('', '/clenove/', function ($req){
+ if (!user()) return redirect('/login/');
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ if ($_POST['qrcode']) {
+ $card = $rows->one('cards', ['id'=>$_POST['qrcode']]);
+ if ($card) {
+ return redirect('/clenove/detail/'. $card['member_id'] . '/');
+ } else {
+ flash('Karta není registrována.', 'error');
+ return redirect('/clenove/');
+ }
+ }
+
+ $searchFor = $_GET['searchFor'] ?? null;
+ $page = $_GET['page'] ?? 1;
+
+ if ($searchFor) {
+ $searchSql = '%' . $searchFor . '%';
+ $members = $rows->more('members', $rows->fragment('name LIKE ? OR email LIKE ? OR phone LIKE ?', [$searchSql, $searchSql, $searchSql]));
+ $pages = 1;
+ } else {
+ $members = $rows->page('members', [], ['name'=>'asc'], $page, 30);
+ $pages = $rows->pages;
+ }
+
+ return render('members', ['members'=>$members, 'page'=>$page, 'pages'=>$pages, 'searchFor'=>$searchFor]);
+});
+
+function items_sold(rows $rows, $od, $do) {
+ $tsOd = strtotime($od);
+ $tsDo = strtotime($do);
+
+ return $rows->execute($rows->query('SELECT item_id, SUM(amount) AS amount FROM sold_items WHERE date>? AND date', [$tsOd, $tsDo]))->fetchAll(PDO::FETCH_KEY_PAIR);
+}
+
+route('', '/sklad/prodano/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $this_week = items_sold($rows, 'monday this week', 'now');
+ $last_week = items_sold($rows, 'monday last week', 'sunday last week +24 hours -1 sec');
+ $this_month = items_sold($rows, 'first day of this month midnight', 'last day of this month midnight +24 hours -1 sec');
+ $last_month = items_sold($rows, 'first day of last month midnight', 'last day of last month midnight +24 hours -1 sec');
+
+ $items = $rows->page('items', ['is_active'=>1, 'is_amount_tracked'=>1], ['ord'=>'asc']);
+ return render('items_sold', ['items'=>$items, 'this_week'=>$this_week, 'last_week'=>$last_week, 'this_month'=>$this_month, 'last_month'=>$last_month]);
+});
+
+
+route('', '/clenove/pridat/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $form = new severak\forms\form(['method'=>'POST']);
+ $form->field('card_id', ['required'=>true, 'type'=>'number', 'label'=>'Číslo karty', 'id'=>'qrcode']);
+ $form->field('name', ['required'=>true, 'label'=>'Jméno']);
+ $form->field('email', ['type'=>'email', 'label'=>'E-mail']);
+ $form->field('phone', ['type'=>'phone', 'label'=>'Telefon']);
+ $form->field('date_of_birth', ['type'=>'date', 'label'=>'Datum narození']);
+
+ $form->field('_save', ['type'=>'submit', 'label'=>'Přidat']);
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody()) && $form->validate()) {
+
+ $card = $rows->one('cards', $form->values['card_id']);
+ if ($card) {
+ $form->error('card_id', 'Karta již je registrovaná v systému!');
+ }
+
+ // TODO - tyhle duplikáty řešit jinak
+ if ($rows->one('members', ['name'=>$form->values['name']])) {
+ $form->error('name', 'Tento člen již kartičku má!');
+ }
+
+ if (!empty($form->values['email']) && $rows->one('members', ['email'=>$form->values['email']])) {
+ $form->error('email', 'Tento email již má některý člen.');
+ }
+
+ if (!empty($form->values['phone']) && $rows->one('members', ['phone'=>$form->values['phone']])) {
+ $form->error('phone', 'Tento telefon již má některý člen.!');
+ }
+
+ if ($form->isValid) {
+ $memberId = $rows->insert('members', [
+ 'name'=>$form->values['name'],
+ 'email'=>$form->values['email'],
+ 'phone'=>$form->values['phone'],
+ 'date_of_birth'=>$form->values['date_of_birth'],
+ ]);
+
+ $rows->insert('cards', [
+ 'id'=>$form->values['card_id'],
+ 'member_id'=>$memberId,
+ 'issued_by'=>$user['id'],
+ 'issued_at'=>time(),
+ 'is_active'=>1
+ ]);
+
+ flash('Člen byl úspěšně registrován.');
+ return redirect('/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Přidat člena']);
+});
+
+route('', '/clenove/detail/{id}/', function ($req, $params) {
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $member = $rows->one('members', $params['id']);
+ if (!$member) return notFound();
+
+ $page = $_GET['page'] ?? 1;
+
+ $transactions = $rows->page('transactions', ['member_id'=>$params['id']], ['issued_at'=>'desc'], $page, 30);
+ $cards = $rows->more('cards', ['member_id'=>$params['id']], ['issued_at'=>'desc']);
+ $pages = $rows->pages;
+
+ return render('member_detail', ['member'=>$member, 'page'=>$page, 'pages'=>$pages, 'transactions'=>$transactions, 'cards'=>$cards]);
+});
+
+route('', '/clenove/upravit/{id}/', function ($req, $params) {
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $member = $rows->one('members', $params['id']);
+ if (!$member) return notFound();
+
+ $form = new severak\forms\form(['method'=>'POST']);
+ $form->field('name', ['required'=>true, 'label'=>'Jméno']);
+ $form->field('email', ['type'=>'email', 'label'=>'E-mail']);
+ $form->field('phone', ['type'=>'phone', 'label'=>'Telefon']);
+ $form->field('date_of_birth', ['type'=>'date', 'label'=>'Datum narození']);
+ $form->field('note', ['type'=>'textarea', 'rows'=>3, 'label'=>'Poznámka']);
+ $form->field('is_active', ['type'=>'checkbox', 'label'=>'Je aktivní?']);
+
+ $form->field('_save', ['type'=>'submit', 'label'=>'Upravit']);
+
+ $form->fill($member);
+
+ if ($req->getMethod()=='POST') {
+ $form->fill($req->getParsedBody());
+
+ // TODO - zde nějak ošetřovat duplicity
+
+ if ($form->validate()) {
+ $rows->update('members', [
+ 'name'=>$form->values['name'],
+ 'email'=>$form->values['email'],
+ 'phone'=>$form->values['phone'],
+ 'date_of_birth'=>$form->values['date_of_birth'],
+ 'note'=>$form->values['note'],
+ 'is_active'=>$form->values['is_active'] ?? 0,
+ ], $params['id']);
+
+ if (!$form->values['is_active']) {
+ // deaktivujeme kartičku
+ $rows->update('cards', ['is_active'=>0, 'note'=>'deaktivována s uživatelem'], ['is_active'=>'1', 'member_id'=>$params['id']]);
+ }
+
+ if (!$member['is_active'] && $form->values['is_active']) {
+ flash('Nyní musíte vystavit novou kartičku.', 'warning');
+ }
+
+ return redirect('/clenove/detail/'. $params['id'].'/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Upravit člena']);
+});
+
+route('', '/clenove/nova_karta/{id}/', function ($req, $params) {
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $member = $rows->one('members', $params['id']);
+ if (!$member) return notFound();
+
+ $reasons = [
+ 'ztracená' => 'karta byla ztracená',
+ 'ukradená' => 'karta byla ukradená',
+ 'obnovení členství' => 'obnovení členství'
+ ];
+
+ $form = new severak\forms\form(['method'=>'POST']);
+ $form->field('card_id', ['required'=>true, 'type'=>'number', 'label'=>'Číslo karty', 'id'=>'qrcode']);
+ $form->field('reason', ['type'=>'select', 'label'=>'Důvod vydání nové karty', 'options'=>$reasons]);
+ $form->field('block_original', ['type'=>'checkbox', 'label'=>'zablokovat původní kartu']);
+
+ $form->field('_save', ['type'=>'submit', 'label'=>'Vystavit novou kartu']);
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody()) && $form->validate()) {
+
+ $card = $rows->one('cards', $form->values['card_id']);
+ if ($card) {
+ $form->error('card_id', 'Karta již je registrovaná v systému!');
+ }
+ $form->fill($req->getParsedBody());
+
+ if ($form->validate()) {
+ // deaktivujeme původní kartu
+ $rows->update('cards', [
+ 'is_active' => 0,
+ 'is_blocked' => $form->values['block_original'] ?? 0,
+ 'note' => $form->values['reason']
+ ], ['is_active' => '1', 'member_id' => $params['id']]);
+
+ // přidáváme novou
+ $rows->insert('cards', [
+ 'id'=>$form->values['card_id'],
+ 'member_id'=>$params['id'],
+ 'issued_by'=>$user['id'],
+ 'issued_at'=>time(),
+ 'is_active'=>1
+ ]);
+
+ return redirect('/clenove/detail/'. $params['id'].'/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Nová karta']);
+});
+
+// POKLADNA:
+route('','/pokladna/', function(){
+ return render('pokladna', ['title'=>'pokladna']);
+});
+
+route('', '/pokladna/dobit/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $form = new form(['method'=>'post']);
+ $form->field('card_id', ['required'=>true, 'type'=>'number', 'label'=>'Číslo karty', 'id'=>'qrcode']);
+ $form->field('amount', ['required'=>true, 'type'=>'number', 'label'=>'Částka']);
+ $form->field('_sbt', ['label'=>'Vložit', 'type'=>'submit']);
+
+ // TODO - zde kontrolovat maxmální a minimální výši nabití
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody()) && $form->validate()) {
+ $card = $rows->one('cards', ['id'=>$form->values['card_id']]);
+
+ if (!$card || !$card['is_active']) {
+ $form->error('card_id', 'Neznámá/neplatná karta!');
+ }
+
+ if ($card && $card['is_blocked']) {
+ $form->error('card_id', 'Karta je zablokovaná.');
+ }
+
+ if ($card) {
+ $member = $rows->one('members', $card['member_id']);
+ }
+
+ if ($form->isValid) {
+ // BIG TODO - tohle dělat v databázové transakci
+ $rows->insert('transactions', [
+ 'member_id' => $member['id'],
+ 'card_id' => $card['id'],
+ 'issued_by'=>$user['id'],
+ 'issued_at'=>time(),
+ 'amount'=>$form->values['amount'],
+ 'is_cash'=>1
+ ]);
+
+ $rows->execute($rows->query('UPDATE members SET balance = balance + ? WHERE id=?', [$form->values['amount'], $member['id']]));
+
+ flash('Kredit úspěšně dobit!', 'success');
+
+ return redirect('/');
+ }
+ }
+ return render('form', ['form'=>$form, 'title'=>'Dobít kartu']);
+});
+
+// TODO - zůstatek, vybrat
+
+// BAR:
+
+route('GET', '/bar/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ $nabidka = $rows->more('items', ['is_active'=>1], ['ord'=>'asc']);
+
+ return render('bar', ['items'=>$nabidka]);
+});
+
+route('POST', '/bar/userinfo/', function ($req){
+ if (!user()) return jsonResponse(['error'=>'Unauthorized.'], 403);
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $Q = $req->getParsedBody();
+
+ if (empty($Q['card_id'])) {
+ return jsonResponse(['error'=>'Špatný formát čísla karty.']);
+ }
+
+ $card = $rows->one('cards', $Q['card_id']);
+
+ if ($card && $card['is_blocked']) {
+ return jsonResponse(['error'=>'Karta je zablokovaná.']);
+ }
+
+ if (!$card || !$card['is_active']) {
+ return jsonResponse(['error'=>'Karta není aktivní.']);
+ }
+
+ $member = $rows->one('members', $card['member_id']);
+
+ if ($member['balance']==0) {
+ return jsonResponse(['error'=>'Karta není nabitá.']);
+ }
+
+ $dobMember = date_create($member['date_of_birth']);
+ $before18Years = date_create('now - 18 years');
+
+ $canBuyAlcohol = $dobMember && ($dobMember < $before18Years);
+
+ return jsonResponse([
+ 'name' => $member['name'],
+ 'balance' => $member['balance'],
+ 'can_buy_alcohol' => $canBuyAlcohol,
+ ]);
+});
+
+route('POST', '/bar/buy/', function ($req){
+ if (!user()) return jsonResponse(['error'=>'Vypršelo přihlášení.']);
+ $user = user();
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $Q = $req->getParsedBody();
+
+ if (empty($Q['card_id'])) {
+ return jsonResponse(['error'=>'Špatný formát čísla karty.']);
+ }
+
+ $card = $rows->one('cards', $Q['card_id']);
+
+ if ($card && $card['is_blocked']) {
+ return jsonResponse(['error'=>'Karta je zablokovaná.']);
+ }
+
+ if (!$card || !$card['is_active']) {
+ return jsonResponse(['error'=>'Karta není aktivní.']);
+ }
+
+ $member = $rows->one('members', $card['member_id']);
+
+ if ($member['balance']<1) {
+ return jsonResponse(['error'=>'Karta není nabitá.']);
+ }
+
+ $totalSum = 0;
+ foreach ($Q['items'] as $item) {
+ $totalSum = $totalSum + ($item['price'] * $item['amount']);
+ }
+
+ if ($member['balance']<$totalSum) {
+ return jsonResponse(['error'=>'Na kartě není dostatek peněz.', 'balance'=>$member['balance']]);
+ }
+
+ $transcactionId = $rows->insert('transactions', [
+ 'member_id' => $member['id'],
+ 'card_id' => $card['id'],
+ 'issued_by'=>$user['id'],
+ 'issued_at'=>time(),
+ 'amount'=>$totalSum * -1,
+ 'items' => json_encode($Q['items']),
+ 'is_cash'=>0
+ ]);
+
+ $rows->execute($rows->query('UPDATE members SET balance = balance - ? WHERE id=?', [$totalSum, $member['id']]));
+
+ $isAmountTracked = array_column($rows->more('items'), 'is_amount_tracked', 'id');
+
+ foreach ($Q['items'] as $item) {
+ if ($item['id'] && $isAmountTracked[$item['id']]) {
+ $rows->insert('sold_items', [
+ 'item_id' => $item['id'],
+ 'transaction_id' => $transcactionId,
+ 'amount' => $item['amount'],
+ 'date'=>time()
+ ]);
+ $rows->execute($rows->query('UPDATE items SET amount=amount-1 WHERE id=?', [$item['id']]));
+ }
+ }
+
+ return jsonResponse(['success'=>true]);
+});
+
+// OBSLUHA
+
+route('GET', '/obsluha/', function ($req){
+ if (!user()) return redirect('/login/');
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+ $items = $rows->page('users', [], ['is_active'=>'desc', 'name'=>'asc']);
+
+ return render('users', ['users'=>$items]);
+});
+
+route('', '/obsluha/pridat/', function ($req){
+ if (!user()) return redirect('/login/');
+ $user = user();
+ if (!$user['is_superuser']) {
+ flash('Obsluhu může přidávat jen admin.', 'warning');
+ return redirect('/');
+ }
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $form = new form(['method'=>'post']);
+ $form->field('username', ['label'=>'Uživatelské jméno']);
+ $form->field('password', ['required'=>true, 'type'=>'password', 'label'=>'Heslo']);
+ $form->field('password_again', ['required'=>true, 'type'=>'password', 'label'=>'Heslo znovu']);
+ $form->field('name', ['required'=>true, 'type'=>'text', 'label'=>'Jméno']);
+ $form->field('card_id', ['type'=>'number', 'label'=>'Číslo členské karty', 'id'=>'qrcode']);
+ $form->field('_sbt', ['label'=>'Přidat', 'type'=>'submit']);
+
+ $form->rule('password_again', function ($v, $o){
+ return $v==$o['password'];
+ }, 'Hesla se neshodují!');
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody()) && $form->validate()) {
+ $duplicateUser = $rows->one('users', ['username'=>$form->values['username'] ]);
+ if ($duplicateUser) {
+ $form->error('username', 'Uživatel tohoto jména již v systému je.');
+ }
+
+ $memberId = null;
+ if ($form->values['card_id']) {
+ $card = $rows->one('cards', ['id'=>$form->values['card_id'], 'is_active'=>1]);
+ $memberId = $card['member_id'];
+ }
+
+ if ($form->isValid) {
+ $rows->insert('users', [
+ 'username' => $form->values['username'],
+ 'name' => $form->values['name'],
+ 'password' => password_hash($form->values['password'], PASSWORD_DEFAULT),
+ 'member_id'=> $memberId
+ ]);
+
+ flash('Uživatel přidán.', 'success');
+ return redirect('/obsluha/');
+ }
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Přidat obsluhu']);
+});
+
+route('', '/obsluha/upravit/{id}/', function ($req, $params){
+ if (!user()) return redirect('/login/');
+ $user = user();
+
+ if (!$user['is_superuser']) {
+ flash('Obsluhu může upravovat jen admin.', 'warning');
+ return redirect('/');
+ }
+
+ $id = $params['id'];
+
+ /** @var Psr\Http\Message\ServerRequestInterface $req */
+ /** @var severak\database\rows $rows */
+ $rows = di('rows');
+
+ $form = new form(['method'=>'post']);
+ $form->field('username', ['label'=>'Uživatelské jméno']);
+ $form->field('password', ['type'=>'password', 'label'=>'Heslo']);
+ $form->field('password_again', ['type'=>'password', 'label'=>'Heslo znovu']);
+ $form->field('name', ['required'=>true, 'type'=>'text', 'label'=>'Jméno']);
+ $form->field('card_id', ['type'=>'number', 'label'=>'Číslo členské karty', 'id'=>'qrcode']);
+ $form->field('is_active', ['type'=>'checkbox', 'label'=>'Aktivní?']);
+ $form->field('is_superuser', ['type'=>'checkbox', 'label'=>'Je admin?']);
+ $form->field('note', ['type'=>'textarea', 'label'=>'Poznámka']);
+ $form->field('_sbt', ['label'=>'Uložit', 'type'=>'submit']);
+
+ $form->rule('password_again', function ($v, $o){
+ return $v==$o['password'];
+ }, 'Hesla se neshodují!');
+
+ if ($req->getMethod()=='POST' && $form->fill($req->getParsedBody())) {
+ $form->validate();
+
+ $duplicateUser = $rows->one('users', ['username'=>$form->values['username'] ]);
+ if ($duplicateUser && $duplicateUser['id']!=$id) {
+ $form->error('username', 'Uživatel tohoto jména již v systému je.');
+ }
+
+ if ($form->values['password'] && $form->values['password']!=$form->values['password_again']) {
+ $form->error('password', 'Hesla se musí shodovat!');
+ }
+
+ if ($form->isValid) {
+ $update = $form->values; // TODO tohle je prasárna
+ unset($update['id'], $update['password'], $update['password_again'], $update['card_id'], $update['_sbt']);
+ if ($form->values['password'] && $form->values['password']!=$form->values['password_again']) {
+ $update['password'] = password_hash($form->values['password'], PASSWORD_DEFAULT);
+ }
+
+ if ($form->values['card_id']) {
+ $card = $rows->one('cards', ['id'=>$form->values['card_id'], 'is_active'=>1]);
+ $update['member_id'] = $card['member_id'];
+ }
+
+ $rows->update('users', $update, $id);
+
+ flash('Uživatel upraven.', 'success');
+ return redirect('/obsluha/');
+ }
+
+ } else {
+ $editedUser = $rows->one('users', $id);
+
+ unset($editedUser['password']);
+
+ if ($editedUser['member_id']) {
+ $card = $rows->one('cards', ['member_id'=>$editedUser['member_id'], 'is_active'=>1]);
+ if ($card) {
+ $editedUser['card_id'] = $card['id'];
+ }
+ }
+
+ $form->fill($editedUser);
+ }
+
+ return render('form', ['form'=>$form, 'title'=>'Upravit obsluhu']);
+});
diff --git a/apple-touch-icon.png b/apple-touch-icon.png
new file mode 100644
index 0000000..77174b4
Binary files /dev/null and b/apple-touch-icon.png differ
diff --git a/config.example.php b/config.example.php
new file mode 100644
index 0000000..4c1ee37
--- /dev/null
+++ b/config.example.php
@@ -0,0 +1,8 @@
+$url]);
+}
+
+function render($view, $data=[])
+{
+ $tplFile = __DIR__ . '/tpl/' . $view . '.php';
+ if (file_exists($tplFile)) {
+ extract($data, EXTR_SKIP);
+ ob_start();
+ include $tplFile;
+ $output = ob_get_contents();
+ ob_end_clean();
+ return $output;
+ } else {
+ throw new Exception('Template '.$view.' not found in file '.$tplFile);
+ }
+
+}
+
+function response($body, $status=200, $headers=[])
+{
+ return new Nyholm\Psr7\Response($status, $headers, $body);
+}
+
+function jsonResponse($data, $status=200)
+{
+ return response(json_encode($data), $status, ['Content-type'=>'application/json']);
+}
+
+function notFound()
+{
+ $err404 = file_get_contents(__DIR__ . '/tpl/404.html');
+ return response($err404, 404);
+}
+
+function route($method, $url, $callback)
+{
+ global $routeCollector;
+ if (empty($method)) $method = ['GET', 'POST'];
+ $routeCollector->addRoute($method, $url, $callback);
+}
+
+
+
+// ROUTES
+require 'app.php';
+
+// finally running the APP
+
+session_start(); // TODO - nakonfit session
+
+$routeDispatcher = new FastRoute\Dispatcher\GroupCountBased($routeCollector->getData());
+$request = new Nyholm\Psr7\ServerRequest($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), getallheaders());
+if ($request->getMethod()=='POST') {
+ $request = $request->withParsedBody($_POST);
+}
+if ($request->getMethod()=='POST' && in_array('application/json', $request->getHeader('Content-Type'))) {
+ $rawPostData = file_get_contents('php://input');
+ $request = $request->withParsedBody(json_decode($rawPostData, true));
+}
+
+$routeInfo = $routeDispatcher->dispatch($request->getMethod(), $request->getUri());
+switch ($routeInfo[0]) {
+ case FastRoute\Dispatcher::NOT_FOUND:
+ http_response_code(404);
+ require __DIR__ . '/tpl/404.html';
+ break;
+ case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
+ $allowedMethods = $routeInfo[1];
+ throw new Exception('Method Not Allowed');
+ break;
+ case FastRoute\Dispatcher::FOUND:
+ $handler = $routeInfo[1];
+ $vars = $routeInfo[2];
+ // todo - zde přidat atributy
+ ob_start();
+ $response = $handler($request, $vars);
+ $output = ob_get_clean();
+ if (empty($response) && !empty($output)) $response = $output;
+ if (is_string($response)) $response = response($response);
+
+ $emmitter = new Narrowspark\HttpEmitter\SapiEmitter();
+ $emmitter->emit($response);
+
+ break;
+}
\ No newline at end of file
diff --git a/lib/FastRoute/BadRouteException.php b/lib/FastRoute/BadRouteException.php
new file mode 100644
index 0000000..ff350ee
--- /dev/null
+++ b/lib/FastRoute/BadRouteException.php
@@ -0,0 +1,10 @@
+ $route) {
+ $suffixLen++;
+ $suffix .= "\t";
+
+ $regexes[] = '(?:' . $regex . '/(\t{' . $suffixLen . '})\t{' . ($count - $suffixLen) . '})';
+ $routeMap[$suffix] = [$route->handler, $route->variables];
+ }
+
+ $regex = '~^(?|' . implode('|', $regexes) . ')$~';
+
+ return ['regex' => $regex, 'suffix' => '/' . $suffix, 'routeMap' => $routeMap];
+ }
+}
diff --git a/lib/FastRoute/DataGenerator/GroupCountBased.php b/lib/FastRoute/DataGenerator/GroupCountBased.php
new file mode 100644
index 0000000..ac2dbac
--- /dev/null
+++ b/lib/FastRoute/DataGenerator/GroupCountBased.php
@@ -0,0 +1,40 @@
+ $route) {
+ $numVariables = count($route->variables);
+ $numGroups = max($numGroups, $numVariables);
+
+ $regexes[] = $regex . str_repeat('()', $numGroups - $numVariables);
+ $routeMap[$numGroups + 1] = [$route->handler, $route->variables];
+
+ ++$numGroups;
+ }
+
+ $regex = '~^(?|' . implode('|', $regexes) . ')$~';
+
+ return ['regex' => $regex, 'routeMap' => $routeMap];
+ }
+}
diff --git a/lib/FastRoute/DataGenerator/GroupPosBased.php b/lib/FastRoute/DataGenerator/GroupPosBased.php
new file mode 100644
index 0000000..75cf68e
--- /dev/null
+++ b/lib/FastRoute/DataGenerator/GroupPosBased.php
@@ -0,0 +1,35 @@
+ $route) {
+ $regexes[] = $regex;
+ $routeMap[$offset] = [$route->handler, $route->variables];
+
+ $offset += count($route->variables);
+ }
+
+ $regex = '~^(?:' . implode('|', $regexes) . ')$~';
+
+ return ['regex' => $regex, 'routeMap' => $routeMap];
+ }
+}
diff --git a/lib/FastRoute/DataGenerator/MarkBased.php b/lib/FastRoute/DataGenerator/MarkBased.php
new file mode 100644
index 0000000..4e8e406
--- /dev/null
+++ b/lib/FastRoute/DataGenerator/MarkBased.php
@@ -0,0 +1,35 @@
+ $route) {
+ $regexes[] = $regex . '(*MARK:' . $markName . ')';
+ $routeMap[$markName] = [$route->handler, $route->variables];
+
+ ++$markName;
+ }
+
+ $regex = '~^(?|' . implode('|', $regexes) . ')$~';
+
+ return ['regex' => $regex, 'routeMap' => $routeMap];
+ }
+}
diff --git a/lib/FastRoute/DataGenerator/RegexBasedAbstract.php b/lib/FastRoute/DataGenerator/RegexBasedAbstract.php
new file mode 100644
index 0000000..57bc777
--- /dev/null
+++ b/lib/FastRoute/DataGenerator/RegexBasedAbstract.php
@@ -0,0 +1,211 @@
+ $regexToRoutesMap
+ *
+ * @return mixed[]
+ */
+ abstract protected function processChunk(array $regexToRoutesMap): array;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function addRoute(string $httpMethod, array $routeData, $handler): void
+ {
+ if ($this->isStaticRoute($routeData)) {
+ $this->addStaticRoute($httpMethod, $routeData, $handler);
+ } else {
+ $this->addVariableRoute($httpMethod, $routeData, $handler);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getData(): array
+ {
+ if ($this->methodToRegexToRoutesMap === []) {
+ return [$this->staticRoutes, []];
+ }
+
+ return [$this->staticRoutes, $this->generateVariableRouteData()];
+ }
+
+ /**
+ * @return mixed[]
+ */
+ private function generateVariableRouteData(): array
+ {
+ $data = [];
+ foreach ($this->methodToRegexToRoutesMap as $method => $regexToRoutesMap) {
+ $chunkSize = $this->computeChunkSize(count($regexToRoutesMap));
+ $chunks = array_chunk($regexToRoutesMap, $chunkSize, true);
+ $data[$method] = array_map([$this, 'processChunk'], $chunks);
+ }
+
+ return $data;
+ }
+
+ private function computeChunkSize(int $count): int
+ {
+ $numParts = max(1, round($count / $this->getApproxChunkSize()));
+
+ return (int) ceil($count / $numParts);
+ }
+
+ /**
+ * @param array $routeData
+ */
+ private function isStaticRoute(array $routeData): bool
+ {
+ return count($routeData) === 1 && is_string($routeData[0]);
+ }
+
+ /**
+ * @param array $routeData
+ * @param mixed $handler
+ */
+ private function addStaticRoute(string $httpMethod, array $routeData, $handler): void
+ {
+ $routeStr = $routeData[0];
+
+ if (isset($this->staticRoutes[$httpMethod][$routeStr])) {
+ throw new BadRouteException(sprintf(
+ 'Cannot register two routes matching "%s" for method "%s"',
+ $routeStr,
+ $httpMethod
+ ));
+ }
+
+ if (isset($this->methodToRegexToRoutesMap[$httpMethod])) {
+ foreach ($this->methodToRegexToRoutesMap[$httpMethod] as $route) {
+ if ($route->matches($routeStr)) {
+ throw new BadRouteException(sprintf(
+ 'Static route "%s" is shadowed by previously defined variable route "%s" for method "%s"',
+ $routeStr,
+ $route->regex,
+ $httpMethod
+ ));
+ }
+ }
+ }
+
+ $this->staticRoutes[$httpMethod][$routeStr] = $handler;
+ }
+
+ /**
+ * @param array $routeData
+ * @param mixed $handler
+ */
+ private function addVariableRoute(string $httpMethod, array $routeData, $handler): void
+ {
+ [$regex, $variables] = $this->buildRegexForRoute($routeData);
+
+ if (isset($this->methodToRegexToRoutesMap[$httpMethod][$regex])) {
+ throw new BadRouteException(sprintf(
+ 'Cannot register two routes matching "%s" for method "%s"',
+ $regex,
+ $httpMethod
+ ));
+ }
+
+ $this->methodToRegexToRoutesMap[$httpMethod][$regex] = new Route(
+ $httpMethod,
+ $handler,
+ $regex,
+ $variables
+ );
+ }
+
+ /**
+ * @param mixed[] $routeData
+ *
+ * @return mixed[]
+ */
+ private function buildRegexForRoute(array $routeData): array
+ {
+ $regex = '';
+ $variables = [];
+ foreach ($routeData as $part) {
+ if (is_string($part)) {
+ $regex .= preg_quote($part, '~');
+ continue;
+ }
+
+ [$varName, $regexPart] = $part;
+
+ if (isset($variables[$varName])) {
+ throw new BadRouteException(sprintf(
+ 'Cannot use the same placeholder "%s" twice',
+ $varName
+ ));
+ }
+
+ if ($this->regexHasCapturingGroups($regexPart)) {
+ throw new BadRouteException(sprintf(
+ 'Regex "%s" for parameter "%s" contains a capturing group',
+ $regexPart,
+ $varName
+ ));
+ }
+
+ $variables[$varName] = $varName;
+ $regex .= '(' . $regexPart . ')';
+ }
+
+ return [$regex, $variables];
+ }
+
+ private function regexHasCapturingGroups(string $regex): bool
+ {
+ if (strpos($regex, '(') === false) {
+ // Needs to have at least a ( to contain a capturing group
+ return false;
+ }
+
+ // Semi-accurate detection for capturing groups
+ return (bool) preg_match(
+ '~
+ (?:
+ \(\?\(
+ | \[ [^\]\\\\]* (?: \\\\ . [^\]\\\\]* )* \]
+ | \\\\ .
+ ) (*SKIP)(*FAIL) |
+ \(
+ (?!
+ \? (?! <(?![!=]) | P< | \' )
+ | \*
+ )
+ ~x',
+ $regex
+ );
+ }
+}
diff --git a/lib/FastRoute/Dispatcher.php b/lib/FastRoute/Dispatcher.php
new file mode 100644
index 0000000..cfd8f1a
--- /dev/null
+++ b/lib/FastRoute/Dispatcher.php
@@ -0,0 +1,24 @@
+ 'value', ...]]
+ *
+ * @return array
+ */
+ public function dispatch(string $httpMethod, string $uri): array;
+}
diff --git a/lib/FastRoute/Dispatcher/CharCountBased.php b/lib/FastRoute/Dispatcher/CharCountBased.php
new file mode 100644
index 0000000..2f79dbb
--- /dev/null
+++ b/lib/FastRoute/Dispatcher/CharCountBased.php
@@ -0,0 +1,34 @@
+staticRouteMap, $this->variableRouteData] = $data;
+ }
+
+ /**
+ * @param mixed[] $routeData
+ *
+ * @return mixed[]
+ */
+ abstract protected function dispatchVariableRoute(array $routeData, string $uri): array;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function dispatch(string $httpMethod, string $uri): array
+ {
+ if (isset($this->staticRouteMap[$httpMethod][$uri])) {
+ $handler = $this->staticRouteMap[$httpMethod][$uri];
+
+ return [self::FOUND, $handler, []];
+ }
+
+ $varRouteData = $this->variableRouteData;
+ if (isset($varRouteData[$httpMethod])) {
+ $result = $this->dispatchVariableRoute($varRouteData[$httpMethod], $uri);
+ if ($result[0] === self::FOUND) {
+ return $result;
+ }
+ }
+
+ // For HEAD requests, attempt fallback to GET
+ if ($httpMethod === 'HEAD') {
+ if (isset($this->staticRouteMap['GET'][$uri])) {
+ $handler = $this->staticRouteMap['GET'][$uri];
+
+ return [self::FOUND, $handler, []];
+ }
+
+ if (isset($varRouteData['GET'])) {
+ $result = $this->dispatchVariableRoute($varRouteData['GET'], $uri);
+ if ($result[0] === self::FOUND) {
+ return $result;
+ }
+ }
+ }
+
+ // If nothing else matches, try fallback routes
+ if (isset($this->staticRouteMap['*'][$uri])) {
+ $handler = $this->staticRouteMap['*'][$uri];
+
+ return [self::FOUND, $handler, []];
+ }
+
+ if (isset($varRouteData['*'])) {
+ $result = $this->dispatchVariableRoute($varRouteData['*'], $uri);
+ if ($result[0] === self::FOUND) {
+ return $result;
+ }
+ }
+
+ // Find allowed methods for this URI by matching against all other HTTP methods as well
+ $allowedMethods = [];
+
+ foreach ($this->staticRouteMap as $method => $uriMap) {
+ if ($method === $httpMethod || ! isset($uriMap[$uri])) {
+ continue;
+ }
+
+ $allowedMethods[] = $method;
+ }
+
+ foreach ($varRouteData as $method => $routeData) {
+ if ($method === $httpMethod) {
+ continue;
+ }
+
+ $result = $this->dispatchVariableRoute($routeData, $uri);
+ if ($result[0] !== self::FOUND) {
+ continue;
+ }
+
+ $allowedMethods[] = $method;
+ }
+
+ // If there are no allowed methods the route simply does not exist
+ if ($allowedMethods !== []) {
+ return [self::METHOD_NOT_ALLOWED, $allowedMethods];
+ }
+
+ return [self::NOT_FOUND];
+ }
+}
diff --git a/lib/FastRoute/Route.php b/lib/FastRoute/Route.php
new file mode 100644
index 0000000..129bed4
--- /dev/null
+++ b/lib/FastRoute/Route.php
@@ -0,0 +1,43 @@
+httpMethod = $httpMethod;
+ $this->handler = $handler;
+ $this->regex = $regex;
+ $this->variables = $variables;
+ }
+
+ /**
+ * Tests whether this route matches the given string.
+ */
+ public function matches(string $str): bool
+ {
+ $regex = '~^' . $this->regex . '$~';
+
+ return (bool) preg_match($regex, $str);
+ }
+}
diff --git a/lib/FastRoute/RouteCollector.php b/lib/FastRoute/RouteCollector.php
new file mode 100644
index 0000000..4186b56
--- /dev/null
+++ b/lib/FastRoute/RouteCollector.php
@@ -0,0 +1,148 @@
+routeParser = $routeParser;
+ $this->dataGenerator = $dataGenerator;
+ }
+
+ /**
+ * Adds a route to the collection.
+ *
+ * The syntax used in the $route string depends on the used route parser.
+ *
+ * @param string|string[] $httpMethod
+ * @param mixed $handler
+ */
+ public function addRoute($httpMethod, string $route, $handler): void
+ {
+ $route = $this->currentGroupPrefix . $route;
+ $routeDatas = $this->routeParser->parse($route);
+ foreach ((array) $httpMethod as $method) {
+ foreach ($routeDatas as $routeData) {
+ $this->dataGenerator->addRoute($method, $routeData, $handler);
+ }
+ }
+ }
+
+ /**
+ * Create a route group with a common prefix.
+ *
+ * All routes created in the passed callback will have the given group prefix prepended.
+ */
+ public function addGroup(string $prefix, callable $callback): void
+ {
+ $previousGroupPrefix = $this->currentGroupPrefix;
+ $this->currentGroupPrefix = $previousGroupPrefix . $prefix;
+ $callback($this);
+ $this->currentGroupPrefix = $previousGroupPrefix;
+ }
+
+ /**
+ * Adds a GET route to the collection
+ *
+ * This is simply an alias of $this->addRoute('GET', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function get(string $route, $handler): void
+ {
+ $this->addRoute('GET', $route, $handler);
+ }
+
+ /**
+ * Adds a POST route to the collection
+ *
+ * This is simply an alias of $this->addRoute('POST', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function post(string $route, $handler): void
+ {
+ $this->addRoute('POST', $route, $handler);
+ }
+
+ /**
+ * Adds a PUT route to the collection
+ *
+ * This is simply an alias of $this->addRoute('PUT', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function put(string $route, $handler): void
+ {
+ $this->addRoute('PUT', $route, $handler);
+ }
+
+ /**
+ * Adds a DELETE route to the collection
+ *
+ * This is simply an alias of $this->addRoute('DELETE', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function delete(string $route, $handler): void
+ {
+ $this->addRoute('DELETE', $route, $handler);
+ }
+
+ /**
+ * Adds a PATCH route to the collection
+ *
+ * This is simply an alias of $this->addRoute('PATCH', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function patch(string $route, $handler): void
+ {
+ $this->addRoute('PATCH', $route, $handler);
+ }
+
+ /**
+ * Adds a HEAD route to the collection
+ *
+ * This is simply an alias of $this->addRoute('HEAD', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function head(string $route, $handler): void
+ {
+ $this->addRoute('HEAD', $route, $handler);
+ }
+
+ /**
+ * Adds an OPTIONS route to the collection
+ *
+ * This is simply an alias of $this->addRoute('OPTIONS', $route, $handler)
+ *
+ * @param mixed $handler
+ */
+ public function options(string $route, $handler): void
+ {
+ $this->addRoute('OPTIONS', $route, $handler);
+ }
+
+ /**
+ * Returns the collected route data, as provided by the data generator.
+ *
+ * @return mixed[]
+ */
+ public function getData(): array
+ {
+ return $this->dataGenerator->getData();
+ }
+}
diff --git a/lib/FastRoute/RouteParser.php b/lib/FastRoute/RouteParser.php
new file mode 100644
index 0000000..6446321
--- /dev/null
+++ b/lib/FastRoute/RouteParser.php
@@ -0,0 +1,38 @@
+ $segment) {
+ if ($segment === '' && $n !== 0) {
+ throw new BadRouteException('Empty optional part');
+ }
+
+ $currentRoute .= $segment;
+ $routeDatas[] = $this->parsePlaceholders($currentRoute);
+ }
+
+ return $routeDatas;
+ }
+
+ /**
+ * Parses a route string that does not contain optional segments.
+ *
+ * @return mixed[]
+ */
+ private function parsePlaceholders(string $route): array
+ {
+ if (! preg_match_all('~' . self::VARIABLE_REGEX . '~x', $route, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
+ return [$route];
+ }
+
+ $offset = 0;
+ $routeData = [];
+
+ foreach ($matches as $set) {
+ if ($set[0][1] > $offset) {
+ $routeData[] = substr($route, $offset, $set[0][1] - $offset);
+ }
+
+ $routeData[] = [
+ $set[1][0],
+ isset($set[2]) ? trim($set[2][0]) : self::DEFAULT_DISPATCH_REGEX,
+ ];
+
+ $offset = $set[0][1] + strlen($set[0][0]);
+ }
+
+ if ($offset !== strlen($route)) {
+ $routeData[] = substr($route, $offset);
+ }
+
+ return $routeData;
+ }
+}
diff --git a/lib/FastRoute/functions.php b/lib/FastRoute/functions.php
new file mode 100644
index 0000000..9641f57
--- /dev/null
+++ b/lib/FastRoute/functions.php
@@ -0,0 +1,79 @@
+ $options
+ */
+ function simpleDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher
+ {
+ $options += [
+ 'routeParser' => RouteParser\Std::class,
+ 'dataGenerator' => DataGenerator\GroupCountBased::class,
+ 'dispatcher' => Dispatcher\GroupCountBased::class,
+ 'routeCollector' => RouteCollector::class,
+ ];
+
+ $routeCollector = new $options['routeCollector'](
+ new $options['routeParser'](), new $options['dataGenerator']()
+ );
+ assert($routeCollector instanceof RouteCollector);
+ $routeDefinitionCallback($routeCollector);
+
+ return new $options['dispatcher']($routeCollector->getData());
+ }
+
+ /**
+ * @param array $options
+ */
+ function cachedDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher
+ {
+ $options += [
+ 'routeParser' => RouteParser\Std::class,
+ 'dataGenerator' => DataGenerator\GroupCountBased::class,
+ 'dispatcher' => Dispatcher\GroupCountBased::class,
+ 'routeCollector' => RouteCollector::class,
+ 'cacheDisabled' => false,
+ ];
+
+ if (! isset($options['cacheFile'])) {
+ throw new LogicException('Must specify "cacheFile" option');
+ }
+
+ if (! $options['cacheDisabled'] && file_exists($options['cacheFile'])) {
+ $dispatchData = require $options['cacheFile'];
+ if (! is_array($dispatchData)) {
+ throw new RuntimeException('Invalid cache file "' . $options['cacheFile'] . '"');
+ }
+
+ return new $options['dispatcher']($dispatchData);
+ }
+
+ $routeCollector = new $options['routeCollector'](
+ new $options['routeParser'](), new $options['dataGenerator']()
+ );
+ assert($routeCollector instanceof RouteCollector);
+ $routeDefinitionCallback($routeCollector);
+
+ $dispatchData = $routeCollector->getData();
+ if (! $options['cacheDisabled']) {
+ file_put_contents(
+ $options['cacheFile'],
+ '
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Narrowspark\HttpEmitter;
+
+use Narrowspark\HttpEmitter\Contract\RuntimeException;
+use Psr\Http\Message\ResponseInterface;
+
+abstract class AbstractSapiEmitter
+{
+ /**
+ * Emit a response.
+ *
+ * Emits a response, including status line, headers, and the message body,
+ * according to the environment.
+ *
+ * Implementations of this method may be written in such a way as to have
+ * side effects, such as usage of header() or pushing output to the
+ * output buffer.
+ *
+ * Implementations MAY raise exceptions if they are unable to emit the
+ * response; e.g., if headers have already been sent.
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ *
+ * @return void
+ */
+ abstract public function emit(ResponseInterface $response): void;
+
+ /**
+ * Assert either that no headers been sent or the output buffer contains no content.
+ *
+ * @throws \Narrowspark\HttpEmitter\Contract\RuntimeException
+ *
+ * @return void
+ */
+ protected function assertNoPreviousOutput(): void
+ {
+ $file = $line = null;
+
+ if (headers_sent($file, $line)) {
+ throw new RuntimeException(\sprintf(
+ 'Unable to emit response: Headers already sent in file %s on line %s. '
+ . 'This happens if echo, print, printf, print_r, var_dump, var_export or similar statement that writes to the output buffer are used.',
+ $file,
+ (string) $line
+ ));
+ }
+
+ if (\ob_get_level() > 0 && \ob_get_length() > 0) {
+ throw new RuntimeException('Output has been emitted previously; cannot emit response.');
+ }
+ }
+
+ /**
+ * Emit the status line.
+ *
+ * Emits the status line using the protocol version and status code from
+ * the response; if a reason phrase is availble, it, too, is emitted.
+ *
+ * It's important to mention that, in order to prevent PHP from changing
+ * the status code of the emitted response, this method should be called
+ * after `emitBody()`
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ *
+ * @return void
+ */
+ protected function emitStatusLine(ResponseInterface $response): void
+ {
+ $statusCode = $response->getStatusCode();
+
+ header(
+ \vsprintf(
+ 'HTTP/%s %d%s',
+ [
+ $response->getProtocolVersion(),
+ $statusCode,
+ \rtrim(' ' . $response->getReasonPhrase()),
+ ]
+ ),
+ true,
+ $statusCode
+ );
+ }
+
+ /**
+ * Emit response headers.
+ *
+ * Loops through each header, emitting each; if the header value
+ * is an array with multiple values, ensures that each is sent
+ * in such a way as to create aggregate headers (instead of replace
+ * the previous).
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ *
+ * @return void
+ */
+ protected function emitHeaders(ResponseInterface $response): void
+ {
+ $statusCode = $response->getStatusCode();
+
+ foreach ($response->getHeaders() as $header => $values) {
+ $name = $this->toWordCase($header);
+ $first = $name !== 'Set-Cookie';
+
+ foreach ($values as $value) {
+ header(
+ \sprintf(
+ '%s: %s',
+ $name,
+ $value
+ ),
+ $first,
+ $statusCode
+ );
+
+ $first = false;
+ }
+ }
+ }
+
+ /**
+ * Converts header names to wordcase.
+ *
+ * @param string $header
+ *
+ * @return string
+ */
+ protected function toWordCase(string $header): string
+ {
+ $filtered = \str_replace('-', ' ', $header);
+ $filtered = \ucwords($filtered);
+
+ return \str_replace(' ', '-', $filtered);
+ }
+
+ /**
+ * Flushes output buffers and closes the connection to the client,
+ * which ensures that no further output can be sent.
+ *
+ * @return void
+ */
+ protected function closeConnection(): void
+ {
+ if (! \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
+ Util::closeOutputBuffers(0, true);
+ }
+
+ if (\function_exists('fastcgi_finish_request')) {
+ \fastcgi_finish_request();
+ }
+ }
+}
diff --git a/lib/Narrowspark/HttpEmitter/Contract/RuntimeException.php b/lib/Narrowspark/HttpEmitter/Contract/RuntimeException.php
new file mode 100644
index 0000000..bc03b98
--- /dev/null
+++ b/lib/Narrowspark/HttpEmitter/Contract/RuntimeException.php
@@ -0,0 +1,20 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Narrowspark\HttpEmitter\Contract;
+
+use RuntimeException as BaseRuntimeException;
+
+final class RuntimeException extends BaseRuntimeException
+{
+}
diff --git a/lib/Narrowspark/HttpEmitter/SapiEmitter.php b/lib/Narrowspark/HttpEmitter/SapiEmitter.php
new file mode 100644
index 0000000..aa543ae
--- /dev/null
+++ b/lib/Narrowspark/HttpEmitter/SapiEmitter.php
@@ -0,0 +1,46 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Narrowspark\HttpEmitter;
+
+use Psr\Http\Message\ResponseInterface;
+
+final class SapiEmitter extends AbstractSapiEmitter
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function emit(ResponseInterface $response): void
+ {
+ $this->assertNoPreviousOutput();
+
+ $this->emitHeaders($response);
+
+ // Set the status _after_ the headers, because of PHP's "helpful" behavior with location headers.
+ $this->emitStatusLine($response);
+
+ $this->emitBody($response);
+
+ $this->closeConnection();
+ }
+
+ /**
+ * Sends the message body of the response.
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ */
+ private function emitBody(ResponseInterface $response): void
+ {
+ echo $response->getBody();
+ }
+}
diff --git a/lib/Narrowspark/HttpEmitter/SapiStreamEmitter.php b/lib/Narrowspark/HttpEmitter/SapiStreamEmitter.php
new file mode 100644
index 0000000..6723717
--- /dev/null
+++ b/lib/Narrowspark/HttpEmitter/SapiStreamEmitter.php
@@ -0,0 +1,159 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Narrowspark\HttpEmitter;
+
+use Psr\Http\Message\ResponseInterface;
+
+final class SapiStreamEmitter extends AbstractSapiEmitter
+{
+ /**
+ * Maximum output buffering size for each iteration.
+ *
+ * @var int
+ */
+ protected $maxBufferLength = 8192;
+
+ /**
+ * Set the maximum output buffering level.
+ *
+ * @param int $maxBufferLength
+ *
+ * @return self
+ */
+ public function setMaxBufferLength(int $maxBufferLength): self
+ {
+ $this->maxBufferLength = $maxBufferLength;
+
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function emit(ResponseInterface $response): void
+ {
+ $this->assertNoPreviousOutput();
+
+ $this->emitHeaders($response);
+
+ // Set the status _after_ the headers, because of PHP's "helpful" behavior with location headers.
+ $this->emitStatusLine($response);
+
+ $range = $this->parseContentRange($response->getHeaderLine('Content-Range'));
+
+ if (\is_array($range) && $range[0] === 'bytes') {
+ $this->emitBodyRange($range, $response, $this->maxBufferLength);
+ } else {
+ $this->emitBody($response, $this->maxBufferLength);
+ }
+
+ $this->closeConnection();
+ }
+
+ /**
+ * Sends the message body of the response.
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ * @param int $maxBufferLength
+ */
+ private function emitBody(ResponseInterface $response, int $maxBufferLength): void
+ {
+ $body = $response->getBody();
+
+ if ($body->isSeekable()) {
+ $body->rewind();
+ }
+
+ if (! $body->isReadable()) {
+ echo $body;
+
+ return;
+ }
+
+ while (! $body->eof()) {
+ echo $body->read($maxBufferLength);
+
+ if (\connection_status() !== \CONNECTION_NORMAL) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Emit a range of the message body.
+ *
+ * @param array $range
+ * @param \Psr\Http\Message\ResponseInterface $response
+ * @param int $maxBufferLength
+ */
+ private function emitBodyRange(array $range, ResponseInterface $response, int $maxBufferLength): void
+ {
+ [$unit, $first, $last, $length] = $range;
+
+ $body = $response->getBody();
+
+ $length = $last - $first + 1;
+
+ if ($body->isSeekable()) {
+ $body->seek($first);
+ $first = 0;
+ }
+
+ if (! $body->isReadable()) {
+ echo \substr($body->getContents(), $first, (int) $length);
+
+ return;
+ }
+
+ $remaining = $length;
+
+ while ($remaining >= $maxBufferLength && ! $body->eof()) {
+ $contents = $body->read($maxBufferLength);
+ $remaining -= \strlen($contents);
+
+ echo $contents;
+
+ if (\connection_status() !== \CONNECTION_NORMAL) {
+ break;
+ }
+ }
+
+ if ($remaining > 0 && ! $body->eof()) {
+ echo $body->read((int) $remaining);
+ }
+ }
+
+ /**
+ * Parse content-range header
+ * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16.
+ *
+ * @param string $header
+ *
+ * @return null|array [unit, first, last, length]; returns false if no
+ * content range or an invalid content range is provided
+ */
+ private function parseContentRange($header): ?array
+ {
+ if (\preg_match('/(?P[\w]+)\s+(?P\d+)-(?P\d+)\/(?P\d+|\*)/', $header, $matches) === 1) {
+ return [
+ $matches['unit'],
+ (int) $matches['first'],
+ (int) $matches['last'],
+ $matches['length'] === '*' ? '*' : (int) $matches['length'],
+ ];
+ }
+
+ return null;
+ }
+}
diff --git a/lib/Narrowspark/HttpEmitter/Util.php b/lib/Narrowspark/HttpEmitter/Util.php
new file mode 100644
index 0000000..8fe2c7f
--- /dev/null
+++ b/lib/Narrowspark/HttpEmitter/Util.php
@@ -0,0 +1,73 @@
+
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Narrowspark\HttpEmitter;
+
+use Psr\Http\Message\ResponseInterface;
+
+final class Util
+{
+ /**
+ * Private constructor; non-instantiable.
+ *
+ * @codeCoverageIgnore
+ */
+ private function __construct()
+ {
+ }
+
+ /**
+ * Inject the Content-Length header if is not already present.
+ *
+ * @param \Psr\Http\Message\ResponseInterface $response
+ *
+ * @return \Psr\Http\Message\ResponseInterface
+ */
+ public static function injectContentLength(ResponseInterface $response): ResponseInterface
+ {
+ // PSR-7 indicates int OR null for the stream size; for null values,
+ // we will not auto-inject the Content-Length.
+ if (! $response->hasHeader('Content-Length')
+ && $response->getBody()->getSize() !== null
+ ) {
+ $response = $response->withHeader('Content-Length', (string) $response->getBody()->getSize());
+ }
+
+ return $response;
+ }
+
+ /**
+ * Cleans or flushes output buffers up to target level.
+ *
+ * Resulting level can be greater than target level if a non-removable buffer has been encountered.
+ *
+ * @param int $maxBufferLevel The target output buffering level
+ * @param bool $flush Whether to flush or clean the buffers
+ *
+ * @return void
+ */
+ public static function closeOutputBuffers(int $maxBufferLevel, bool $flush): void
+ {
+ $status = \ob_get_status(true);
+ $level = \count($status);
+ $flags = \PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? \PHP_OUTPUT_HANDLER_FLUSHABLE : \PHP_OUTPUT_HANDLER_CLEANABLE);
+
+ while ($level-- > $maxBufferLevel && (bool) ($s = $status[$level]) && ($s['del'] ?? ! isset($s['flags']) || $flags === ($s['flags'] & $flags))) {
+ if ($flush) {
+ \ob_end_flush();
+ } else {
+ \ob_end_clean();
+ }
+ }
+ }
+}
diff --git a/lib/Nyholm/Factory/HttplugFactory.php b/lib/Nyholm/Factory/HttplugFactory.php
new file mode 100644
index 0000000..a296541
--- /dev/null
+++ b/lib/Nyholm/Factory/HttplugFactory.php
@@ -0,0 +1,40 @@
+
+ * @author Martijn van der Ven
+ */
+final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
+{
+ public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
+ {
+ return new Request($method, $uri, $headers, $body, $protocolVersion);
+ }
+
+ public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1')
+ {
+ return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
+ }
+
+ public function createStream($body = null)
+ {
+ return Stream::create($body ?? '');
+ }
+
+ public function createUri($uri = ''): UriInterface
+ {
+ if ($uri instanceof UriInterface) {
+ return $uri;
+ }
+
+ return new Uri($uri);
+ }
+}
diff --git a/lib/Nyholm/Factory/Psr17Factory.php b/lib/Nyholm/Factory/Psr17Factory.php
new file mode 100644
index 0000000..08caf85
--- /dev/null
+++ b/lib/Nyholm/Factory/Psr17Factory.php
@@ -0,0 +1,73 @@
+
+ * @author Martijn van der Ven
+ */
+final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
+{
+ public function createRequest(string $method, $uri): RequestInterface
+ {
+ return new Request($method, $uri);
+ }
+
+ public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
+ {
+ if (2 > \func_num_args()) {
+ // This will make the Response class to use a custom reasonPhrase
+ $reasonPhrase = null;
+ }
+
+ return new Response($code, [], null, '1.1', $reasonPhrase);
+ }
+
+ public function createStream(string $content = ''): StreamInterface
+ {
+ return Stream::create($content);
+ }
+
+ public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
+ {
+ $resource = @\fopen($filename, $mode);
+ if (false === $resource) {
+ if ('' === $mode || false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'])) {
+ throw new \InvalidArgumentException('The mode ' . $mode . ' is invalid.');
+ }
+
+ throw new \RuntimeException('The file ' . $filename . ' cannot be opened.');
+ }
+
+ return Stream::create($resource);
+ }
+
+ public function createStreamFromResource($resource): StreamInterface
+ {
+ return Stream::create($resource);
+ }
+
+ public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
+ {
+ if (null === $size) {
+ $size = $stream->getSize();
+ }
+
+ return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
+ }
+
+ public function createUri(string $uri = ''): UriInterface
+ {
+ return new Uri($uri);
+ }
+
+ public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
+ {
+ return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
+ }
+}
diff --git a/lib/Nyholm/Psr7/MessageTrait.php b/lib/Nyholm/Psr7/MessageTrait.php
new file mode 100644
index 0000000..d1e93cc
--- /dev/null
+++ b/lib/Nyholm/Psr7/MessageTrait.php
@@ -0,0 +1,202 @@
+
+ * @author Martijn van der Ven
+ *
+ * @internal should not be used outside of Nyholm/Psr7 as it does not fall under our BC promise
+ */
+trait MessageTrait
+{
+ /** @var array Map of all registered headers, as original name => array of values */
+ private $headers = [];
+
+ /** @var array Map of lowercase header name => original name at registration */
+ private $headerNames = [];
+
+ /** @var string */
+ private $protocol = '1.1';
+
+ /** @var StreamInterface|null */
+ private $stream;
+
+ public function getProtocolVersion(): string
+ {
+ return $this->protocol;
+ }
+
+ public function withProtocolVersion($version): self
+ {
+ if ($this->protocol === $version) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->protocol = $version;
+
+ return $new;
+ }
+
+ public function getHeaders(): array
+ {
+ return $this->headers;
+ }
+
+ public function hasHeader($header): bool
+ {
+ return isset($this->headerNames[\strtolower($header)]);
+ }
+
+ public function getHeader($header): array
+ {
+ $header = \strtolower($header);
+ if (!isset($this->headerNames[$header])) {
+ return [];
+ }
+
+ $header = $this->headerNames[$header];
+
+ return $this->headers[$header];
+ }
+
+ public function getHeaderLine($header): string
+ {
+ return \implode(', ', $this->getHeader($header));
+ }
+
+ public function withHeader($header, $value): self
+ {
+ $value = $this->validateAndTrimHeader($header, $value);
+ $normalized = \strtolower($header);
+
+ $new = clone $this;
+ if (isset($new->headerNames[$normalized])) {
+ unset($new->headers[$new->headerNames[$normalized]]);
+ }
+ $new->headerNames[$normalized] = $header;
+ $new->headers[$header] = $value;
+
+ return $new;
+ }
+
+ public function withAddedHeader($header, $value): self
+ {
+ if (!\is_string($header) || '' === $header) {
+ throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string.');
+ }
+
+ $new = clone $this;
+ $new->setHeaders([$header => $value]);
+
+ return $new;
+ }
+
+ public function withoutHeader($header): self
+ {
+ $normalized = \strtolower($header);
+ if (!isset($this->headerNames[$normalized])) {
+ return $this;
+ }
+
+ $header = $this->headerNames[$normalized];
+ $new = clone $this;
+ unset($new->headers[$header], $new->headerNames[$normalized]);
+
+ return $new;
+ }
+
+ public function getBody(): StreamInterface
+ {
+ if (null === $this->stream) {
+ $this->stream = Stream::create('');
+ }
+
+ return $this->stream;
+ }
+
+ public function withBody(StreamInterface $body): self
+ {
+ if ($body === $this->stream) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->stream = $body;
+
+ return $new;
+ }
+
+ private function setHeaders(array $headers): void
+ {
+ foreach ($headers as $header => $value) {
+ $value = $this->validateAndTrimHeader($header, $value);
+ $normalized = \strtolower($header);
+ if (isset($this->headerNames[$normalized])) {
+ $header = $this->headerNames[$normalized];
+ $this->headers[$header] = \array_merge($this->headers[$header], $value);
+ } else {
+ $this->headerNames[$normalized] = $header;
+ $this->headers[$header] = $value;
+ }
+ }
+ }
+
+ /**
+ * Make sure the header complies with RFC 7230.
+ *
+ * Header names must be a non-empty string consisting of token characters.
+ *
+ * Header values must be strings consisting of visible characters with all optional
+ * leading and trailing whitespace stripped. This method will always strip such
+ * optional whitespace. Note that the method does not allow folding whitespace within
+ * the values as this was deprecated for almost all instances by the RFC.
+ *
+ * header-field = field-name ":" OWS field-value OWS
+ * field-name = 1*( "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^"
+ * / "_" / "`" / "|" / "~" / %x30-39 / ( %x41-5A / %x61-7A ) )
+ * OWS = *( SP / HTAB )
+ * field-value = *( ( %x21-7E / %x80-FF ) [ 1*( SP / HTAB ) ( %x21-7E / %x80-FF ) ] )
+ *
+ * @see https://tools.ietf.org/html/rfc7230#section-3.2.4
+ */
+ private function validateAndTrimHeader($header, $values): array
+ {
+ if (!\is_string($header) || 1 !== \preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@", $header)) {
+ throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string.');
+ }
+
+ if (!\is_array($values)) {
+ // This is simple, just one value.
+ if ((!\is_numeric($values) && !\is_string($values)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $values)) {
+ throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings.');
+ }
+
+ return [\trim((string) $values, " \t")];
+ }
+
+ if (empty($values)) {
+ throw new \InvalidArgumentException('Header values must be a string or an array of strings, empty array given.');
+ }
+
+ // Assert Non empty array
+ $returnValues = [];
+ foreach ($values as $v) {
+ if ((!\is_numeric($v) && !\is_string($v)) || 1 !== \preg_match("@^[ \t\x21-\x7E\x80-\xFF]*$@", (string) $v)) {
+ throw new \InvalidArgumentException('Header values must be RFC 7230 compatible strings.');
+ }
+
+ $returnValues[] = \trim((string) $v, " \t");
+ }
+
+ return $returnValues;
+ }
+}
diff --git a/lib/Nyholm/Psr7/Request.php b/lib/Nyholm/Psr7/Request.php
new file mode 100644
index 0000000..84a9f2a
--- /dev/null
+++ b/lib/Nyholm/Psr7/Request.php
@@ -0,0 +1,45 @@
+
+ * @author Martijn van der Ven
+ */
+final class Request implements RequestInterface
+{
+ use MessageTrait;
+ use RequestTrait;
+
+ /**
+ * @param string $method HTTP method
+ * @param string|UriInterface $uri URI
+ * @param array $headers Request headers
+ * @param string|resource|StreamInterface|null $body Request body
+ * @param string $version Protocol version
+ */
+ public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
+ {
+ if (!($uri instanceof UriInterface)) {
+ $uri = new Uri($uri);
+ }
+
+ $this->method = $method;
+ $this->uri = $uri;
+ $this->setHeaders($headers);
+ $this->protocol = $version;
+
+ if (!$this->hasHeader('Host')) {
+ $this->updateHostFromUri();
+ }
+
+ // If we got no body, defer initialization of the stream until Request::getBody()
+ if ('' !== $body && null !== $body) {
+ $this->stream = Stream::create($body);
+ }
+ }
+}
diff --git a/lib/Nyholm/Psr7/RequestTrait.php b/lib/Nyholm/Psr7/RequestTrait.php
new file mode 100644
index 0000000..f39993a
--- /dev/null
+++ b/lib/Nyholm/Psr7/RequestTrait.php
@@ -0,0 +1,113 @@
+
+ * @author Martijn van der Ven
+ *
+ * @internal should not be used outside of Nyholm/Psr7 as it does not fall under our BC promise
+ */
+trait RequestTrait
+{
+ /** @var string */
+ private $method;
+
+ /** @var string|null */
+ private $requestTarget;
+
+ /** @var UriInterface|null */
+ private $uri;
+
+ public function getRequestTarget(): string
+ {
+ if (null !== $this->requestTarget) {
+ return $this->requestTarget;
+ }
+
+ if ('' === $target = $this->uri->getPath()) {
+ $target = '/';
+ }
+ if ('' !== $this->uri->getQuery()) {
+ $target .= '?' . $this->uri->getQuery();
+ }
+
+ return $target;
+ }
+
+ public function withRequestTarget($requestTarget): self
+ {
+ if (\preg_match('#\s#', $requestTarget)) {
+ throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
+ }
+
+ $new = clone $this;
+ $new->requestTarget = $requestTarget;
+
+ return $new;
+ }
+
+ public function getMethod(): string
+ {
+ return $this->method;
+ }
+
+ public function withMethod($method): self
+ {
+ if (!\is_string($method)) {
+ throw new \InvalidArgumentException('Method must be a string');
+ }
+
+ $new = clone $this;
+ $new->method = $method;
+
+ return $new;
+ }
+
+ public function getUri(): UriInterface
+ {
+ return $this->uri;
+ }
+
+ public function withUri(UriInterface $uri, $preserveHost = false): self
+ {
+ if ($uri === $this->uri) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->uri = $uri;
+
+ if (!$preserveHost || !$this->hasHeader('Host')) {
+ $new->updateHostFromUri();
+ }
+
+ return $new;
+ }
+
+ private function updateHostFromUri(): void
+ {
+ if ('' === $host = $this->uri->getHost()) {
+ return;
+ }
+
+ if (null !== ($port = $this->uri->getPort())) {
+ $host .= ':' . $port;
+ }
+
+ if (isset($this->headerNames['host'])) {
+ $header = $this->headerNames['host'];
+ } else {
+ $this->headerNames['host'] = $header = 'Host';
+ }
+
+ // Ensure Host is the first header.
+ // See: http://tools.ietf.org/html/rfc7230#section-5.4
+ $this->headers = [$header => [$host]] + $this->headers;
+ }
+}
diff --git a/lib/Nyholm/Psr7/Response.php b/lib/Nyholm/Psr7/Response.php
new file mode 100644
index 0000000..a75e93c
--- /dev/null
+++ b/lib/Nyholm/Psr7/Response.php
@@ -0,0 +1,88 @@
+
+ * @author Martijn van der Ven
+ */
+final class Response implements ResponseInterface
+{
+ use MessageTrait;
+
+ /** @var array Map of standard HTTP status code/reason phrases */
+ private const PHRASES = [
+ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing',
+ 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-status', 208 => 'Already Reported',
+ 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Switch Proxy', 307 => 'Temporary Redirect',
+ 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 422 => 'Unprocessable Entity', 423 => 'Locked', 424 => 'Failed Dependency', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 451 => 'Unavailable For Legal Reasons',
+ 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 506 => 'Variant Also Negotiates', 507 => 'Insufficient Storage', 508 => 'Loop Detected', 511 => 'Network Authentication Required',
+ ];
+
+ /** @var string */
+ private $reasonPhrase = '';
+
+ /** @var int */
+ private $statusCode;
+
+ /**
+ * @param int $status Status code
+ * @param array $headers Response headers
+ * @param string|resource|StreamInterface|null $body Response body
+ * @param string $version Protocol version
+ * @param string|null $reason Reason phrase (when empty a default will be used based on the status code)
+ */
+ public function __construct(int $status = 200, array $headers = [], $body = null, string $version = '1.1', string $reason = null)
+ {
+ // If we got no body, defer initialization of the stream until Response::getBody()
+ if ('' !== $body && null !== $body) {
+ $this->stream = Stream::create($body);
+ }
+
+ $this->statusCode = $status;
+ $this->setHeaders($headers);
+ if (null === $reason && isset(self::PHRASES[$this->statusCode])) {
+ $this->reasonPhrase = self::PHRASES[$status];
+ } else {
+ $this->reasonPhrase = $reason ?? '';
+ }
+
+ $this->protocol = $version;
+ }
+
+ public function getStatusCode(): int
+ {
+ return $this->statusCode;
+ }
+
+ public function getReasonPhrase(): string
+ {
+ return $this->reasonPhrase;
+ }
+
+ public function withStatus($code, $reasonPhrase = ''): self
+ {
+ if (!\is_int($code) && !\is_string($code)) {
+ throw new \InvalidArgumentException('Status code has to be an integer');
+ }
+
+ $code = (int) $code;
+ if ($code < 100 || $code > 599) {
+ throw new \InvalidArgumentException('Status code has to be an integer between 100 and 599');
+ }
+
+ $new = clone $this;
+ $new->statusCode = $code;
+ if ((null === $reasonPhrase || '' === $reasonPhrase) && isset(self::PHRASES[$new->statusCode])) {
+ $reasonPhrase = self::PHRASES[$new->statusCode];
+ }
+ $new->reasonPhrase = $reasonPhrase;
+
+ return $new;
+ }
+}
diff --git a/lib/Nyholm/Psr7/ServerRequest.php b/lib/Nyholm/Psr7/ServerRequest.php
new file mode 100644
index 0000000..aff8721
--- /dev/null
+++ b/lib/Nyholm/Psr7/ServerRequest.php
@@ -0,0 +1,162 @@
+
+ * @author Martijn van der Ven
+ */
+final class ServerRequest implements ServerRequestInterface
+{
+ use MessageTrait;
+ use RequestTrait;
+
+ /** @var array */
+ private $attributes = [];
+
+ /** @var array */
+ private $cookieParams = [];
+
+ /** @var array|object|null */
+ private $parsedBody;
+
+ /** @var array */
+ private $queryParams = [];
+
+ /** @var array */
+ private $serverParams;
+
+ /** @var UploadedFileInterface[] */
+ private $uploadedFiles = [];
+
+ /**
+ * @param string $method HTTP method
+ * @param string|UriInterface $uri URI
+ * @param array $headers Request headers
+ * @param string|resource|StreamInterface|null $body Request body
+ * @param string $version Protocol version
+ * @param array $serverParams Typically the $_SERVER superglobal
+ */
+ public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1', array $serverParams = [])
+ {
+ $this->serverParams = $serverParams;
+
+ if (!($uri instanceof UriInterface)) {
+ $uri = new Uri($uri);
+ }
+
+ $this->method = $method;
+ $this->uri = $uri;
+ $this->setHeaders($headers);
+ $this->protocol = $version;
+
+ if (!$this->hasHeader('Host')) {
+ $this->updateHostFromUri();
+ }
+
+ // If we got no body, defer initialization of the stream until ServerRequest::getBody()
+ if ('' !== $body && null !== $body) {
+ $this->stream = Stream::create($body);
+ }
+ }
+
+ public function getServerParams(): array
+ {
+ return $this->serverParams;
+ }
+
+ public function getUploadedFiles(): array
+ {
+ return $this->uploadedFiles;
+ }
+
+ public function withUploadedFiles(array $uploadedFiles)
+ {
+ $new = clone $this;
+ $new->uploadedFiles = $uploadedFiles;
+
+ return $new;
+ }
+
+ public function getCookieParams(): array
+ {
+ return $this->cookieParams;
+ }
+
+ public function withCookieParams(array $cookies)
+ {
+ $new = clone $this;
+ $new->cookieParams = $cookies;
+
+ return $new;
+ }
+
+ public function getQueryParams(): array
+ {
+ return $this->queryParams;
+ }
+
+ public function withQueryParams(array $query)
+ {
+ $new = clone $this;
+ $new->queryParams = $query;
+
+ return $new;
+ }
+
+ public function getParsedBody()
+ {
+ return $this->parsedBody;
+ }
+
+ public function withParsedBody($data)
+ {
+ if (!\is_array($data) && !\is_object($data) && null !== $data) {
+ throw new \InvalidArgumentException('First parameter to withParsedBody MUST be object, array or null');
+ }
+
+ $new = clone $this;
+ $new->parsedBody = $data;
+
+ return $new;
+ }
+
+ public function getAttributes(): array
+ {
+ return $this->attributes;
+ }
+
+ public function getAttribute($attribute, $default = null)
+ {
+ if (false === \array_key_exists($attribute, $this->attributes)) {
+ return $default;
+ }
+
+ return $this->attributes[$attribute];
+ }
+
+ public function withAttribute($attribute, $value): self
+ {
+ $new = clone $this;
+ $new->attributes[$attribute] = $value;
+
+ return $new;
+ }
+
+ public function withoutAttribute($attribute): self
+ {
+ if (false === \array_key_exists($attribute, $this->attributes)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ unset($new->attributes[$attribute]);
+
+ return $new;
+ }
+}
diff --git a/lib/Nyholm/Psr7/Stream.php b/lib/Nyholm/Psr7/Stream.php
new file mode 100644
index 0000000..a72ce0a
--- /dev/null
+++ b/lib/Nyholm/Psr7/Stream.php
@@ -0,0 +1,257 @@
+
+ * @author Martijn van der Ven
+ */
+final class Stream implements StreamInterface
+{
+ /** @var resource|null A resource reference */
+ private $stream;
+
+ /** @var bool */
+ private $seekable;
+
+ /** @var bool */
+ private $readable;
+
+ /** @var bool */
+ private $writable;
+
+ /** @var array|mixed|void|null */
+ private $uri;
+
+ /** @var int|null */
+ private $size;
+
+ /** @var array Hash of readable and writable stream types */
+ private const READ_WRITE_HASH = [
+ 'read' => [
+ 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
+ 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
+ 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
+ 'x+t' => true, 'c+t' => true, 'a+' => true,
+ ],
+ 'write' => [
+ 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
+ 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
+ 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
+ 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true,
+ ],
+ ];
+
+ private function __construct()
+ {
+ }
+
+ /**
+ * Creates a new PSR-7 stream.
+ *
+ * @param string|resource|StreamInterface $body
+ *
+ * @return StreamInterface
+ *
+ * @throws \InvalidArgumentException
+ */
+ public static function create($body = ''): StreamInterface
+ {
+ if ($body instanceof StreamInterface) {
+ return $body;
+ }
+
+ if (\is_string($body)) {
+ $resource = \fopen('php://temp', 'rw+');
+ \fwrite($resource, $body);
+ $body = $resource;
+ }
+
+ if (\is_resource($body)) {
+ $new = new self();
+ $new->stream = $body;
+ $meta = \stream_get_meta_data($new->stream);
+ $new->seekable = $meta['seekable'] && 0 === \fseek($new->stream, 0, \SEEK_CUR);
+ $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
+ $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
+ $new->uri = $new->getMetadata('uri');
+
+ return $new;
+ }
+
+ throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
+ }
+
+ /**
+ * Closes the stream when the destructed.
+ */
+ public function __destruct()
+ {
+ $this->close();
+ }
+
+ public function __toString(): string
+ {
+ try {
+ if ($this->isSeekable()) {
+ $this->seek(0);
+ }
+
+ return $this->getContents();
+ } catch (\Exception $e) {
+ return '';
+ }
+ }
+
+ public function close(): void
+ {
+ if (isset($this->stream)) {
+ if (\is_resource($this->stream)) {
+ \fclose($this->stream);
+ }
+ $this->detach();
+ }
+ }
+
+ public function detach()
+ {
+ if (!isset($this->stream)) {
+ return null;
+ }
+
+ $result = $this->stream;
+ unset($this->stream);
+ $this->size = $this->uri = null;
+ $this->readable = $this->writable = $this->seekable = false;
+
+ return $result;
+ }
+
+ public function getSize(): ?int
+ {
+ if (null !== $this->size) {
+ return $this->size;
+ }
+
+ if (!isset($this->stream)) {
+ return null;
+ }
+
+ // Clear the stat cache if the stream has a URI
+ if ($this->uri) {
+ \clearstatcache(true, $this->uri);
+ }
+
+ $stats = \fstat($this->stream);
+ if (isset($stats['size'])) {
+ $this->size = $stats['size'];
+
+ return $this->size;
+ }
+
+ return null;
+ }
+
+ public function tell(): int
+ {
+ if (false === $result = \ftell($this->stream)) {
+ throw new \RuntimeException('Unable to determine stream position');
+ }
+
+ return $result;
+ }
+
+ public function eof(): bool
+ {
+ return !$this->stream || \feof($this->stream);
+ }
+
+ public function isSeekable(): bool
+ {
+ return $this->seekable;
+ }
+
+ public function seek($offset, $whence = \SEEK_SET): void
+ {
+ if (!$this->seekable) {
+ throw new \RuntimeException('Stream is not seekable');
+ }
+
+ if (-1 === \fseek($this->stream, $offset, $whence)) {
+ throw new \RuntimeException('Unable to seek to stream position ' . $offset . ' with whence ' . \var_export($whence, true));
+ }
+ }
+
+ public function rewind(): void
+ {
+ $this->seek(0);
+ }
+
+ public function isWritable(): bool
+ {
+ return $this->writable;
+ }
+
+ public function write($string): int
+ {
+ if (!$this->writable) {
+ throw new \RuntimeException('Cannot write to a non-writable stream');
+ }
+
+ // We can't know the size after writing anything
+ $this->size = null;
+
+ if (false === $result = \fwrite($this->stream, $string)) {
+ throw new \RuntimeException('Unable to write to stream');
+ }
+
+ return $result;
+ }
+
+ public function isReadable(): bool
+ {
+ return $this->readable;
+ }
+
+ public function read($length): string
+ {
+ if (!$this->readable) {
+ throw new \RuntimeException('Cannot read from non-readable stream');
+ }
+
+ return \fread($this->stream, $length);
+ }
+
+ public function getContents(): string
+ {
+ if (!isset($this->stream)) {
+ throw new \RuntimeException('Unable to read stream contents');
+ }
+
+ if (false === $contents = \stream_get_contents($this->stream)) {
+ throw new \RuntimeException('Unable to read stream contents');
+ }
+
+ return $contents;
+ }
+
+ public function getMetadata($key = null)
+ {
+ if (!isset($this->stream)) {
+ return $key ? null : [];
+ }
+
+ $meta = \stream_get_meta_data($this->stream);
+
+ if (null === $key) {
+ return $meta;
+ }
+
+ return $meta[$key] ?? null;
+ }
+}
diff --git a/lib/Nyholm/Psr7/UploadedFile.php b/lib/Nyholm/Psr7/UploadedFile.php
new file mode 100644
index 0000000..757e70e
--- /dev/null
+++ b/lib/Nyholm/Psr7/UploadedFile.php
@@ -0,0 +1,171 @@
+
+ * @author Martijn van der Ven
+ */
+final class UploadedFile implements UploadedFileInterface
+{
+ /** @var array */
+ private const ERRORS = [
+ \UPLOAD_ERR_OK => 1,
+ \UPLOAD_ERR_INI_SIZE => 1,
+ \UPLOAD_ERR_FORM_SIZE => 1,
+ \UPLOAD_ERR_PARTIAL => 1,
+ \UPLOAD_ERR_NO_FILE => 1,
+ \UPLOAD_ERR_NO_TMP_DIR => 1,
+ \UPLOAD_ERR_CANT_WRITE => 1,
+ \UPLOAD_ERR_EXTENSION => 1,
+ ];
+
+ /** @var string */
+ private $clientFilename;
+
+ /** @var string */
+ private $clientMediaType;
+
+ /** @var int */
+ private $error;
+
+ /** @var string|null */
+ private $file;
+
+ /** @var bool */
+ private $moved = false;
+
+ /** @var int */
+ private $size;
+
+ /** @var StreamInterface|null */
+ private $stream;
+
+ /**
+ * @param StreamInterface|string|resource $streamOrFile
+ * @param int $size
+ * @param int $errorStatus
+ * @param string|null $clientFilename
+ * @param string|null $clientMediaType
+ */
+ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename = null, $clientMediaType = null)
+ {
+ if (false === \is_int($errorStatus) || !isset(self::ERRORS[$errorStatus])) {
+ throw new \InvalidArgumentException('Upload file error status must be an integer value and one of the "UPLOAD_ERR_*" constants.');
+ }
+
+ if (false === \is_int($size)) {
+ throw new \InvalidArgumentException('Upload file size must be an integer');
+ }
+
+ if (null !== $clientFilename && !\is_string($clientFilename)) {
+ throw new \InvalidArgumentException('Upload file client filename must be a string or null');
+ }
+
+ if (null !== $clientMediaType && !\is_string($clientMediaType)) {
+ throw new \InvalidArgumentException('Upload file client media type must be a string or null');
+ }
+
+ $this->error = $errorStatus;
+ $this->size = $size;
+ $this->clientFilename = $clientFilename;
+ $this->clientMediaType = $clientMediaType;
+
+ if (\UPLOAD_ERR_OK === $this->error) {
+ // Depending on the value set file or stream variable.
+ if (\is_string($streamOrFile)) {
+ $this->file = $streamOrFile;
+ } elseif (\is_resource($streamOrFile)) {
+ $this->stream = Stream::create($streamOrFile);
+ } elseif ($streamOrFile instanceof StreamInterface) {
+ $this->stream = $streamOrFile;
+ } else {
+ throw new \InvalidArgumentException('Invalid stream or file provided for UploadedFile');
+ }
+ }
+ }
+
+ /**
+ * @throws \RuntimeException if is moved or not ok
+ */
+ private function validateActive(): void
+ {
+ if (\UPLOAD_ERR_OK !== $this->error) {
+ throw new \RuntimeException('Cannot retrieve stream due to upload error');
+ }
+
+ if ($this->moved) {
+ throw new \RuntimeException('Cannot retrieve stream after it has already been moved');
+ }
+ }
+
+ public function getStream(): StreamInterface
+ {
+ $this->validateActive();
+
+ if ($this->stream instanceof StreamInterface) {
+ return $this->stream;
+ }
+
+ $resource = \fopen($this->file, 'r');
+
+ return Stream::create($resource);
+ }
+
+ public function moveTo($targetPath): void
+ {
+ $this->validateActive();
+
+ if (!\is_string($targetPath) || '' === $targetPath) {
+ throw new \InvalidArgumentException('Invalid path provided for move operation; must be a non-empty string');
+ }
+
+ if (null !== $this->file) {
+ $this->moved = 'cli' === \PHP_SAPI ? \rename($this->file, $targetPath) : \move_uploaded_file($this->file, $targetPath);
+ } else {
+ $stream = $this->getStream();
+ if ($stream->isSeekable()) {
+ $stream->rewind();
+ }
+
+ // Copy the contents of a stream into another stream until end-of-file.
+ $dest = Stream::create(\fopen($targetPath, 'w'));
+ while (!$stream->eof()) {
+ if (!$dest->write($stream->read(1048576))) {
+ break;
+ }
+ }
+
+ $this->moved = true;
+ }
+
+ if (false === $this->moved) {
+ throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
+ }
+ }
+
+ public function getSize(): int
+ {
+ return $this->size;
+ }
+
+ public function getError(): int
+ {
+ return $this->error;
+ }
+
+ public function getClientFilename(): ?string
+ {
+ return $this->clientFilename;
+ }
+
+ public function getClientMediaType(): ?string
+ {
+ return $this->clientMediaType;
+ }
+}
diff --git a/lib/Nyholm/Psr7/Uri.php b/lib/Nyholm/Psr7/Uri.php
new file mode 100644
index 0000000..d67c078
--- /dev/null
+++ b/lib/Nyholm/Psr7/Uri.php
@@ -0,0 +1,310 @@
+
+ * @author Martijn van der Ven
+ */
+final class Uri implements UriInterface
+{
+ private const SCHEMES = ['http' => 80, 'https' => 443];
+
+ private const CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~';
+
+ private const CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;=';
+
+ /** @var string Uri scheme. */
+ private $scheme = '';
+
+ /** @var string Uri user info. */
+ private $userInfo = '';
+
+ /** @var string Uri host. */
+ private $host = '';
+
+ /** @var int|null Uri port. */
+ private $port;
+
+ /** @var string Uri path. */
+ private $path = '';
+
+ /** @var string Uri query string. */
+ private $query = '';
+
+ /** @var string Uri fragment. */
+ private $fragment = '';
+
+ public function __construct(string $uri = '')
+ {
+ if ('' !== $uri) {
+ if (false === $parts = \parse_url($uri)) {
+ throw new \InvalidArgumentException("Unable to parse URI: $uri");
+ }
+
+ // Apply parse_url parts to a URI.
+ $this->scheme = isset($parts['scheme']) ? \strtolower($parts['scheme']) : '';
+ $this->userInfo = $parts['user'] ?? '';
+ $this->host = isset($parts['host']) ? \strtolower($parts['host']) : '';
+ $this->port = isset($parts['port']) ? $this->filterPort($parts['port']) : null;
+ $this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : '';
+ $this->query = isset($parts['query']) ? $this->filterQueryAndFragment($parts['query']) : '';
+ $this->fragment = isset($parts['fragment']) ? $this->filterQueryAndFragment($parts['fragment']) : '';
+ if (isset($parts['pass'])) {
+ $this->userInfo .= ':' . $parts['pass'];
+ }
+ }
+ }
+
+ public function __toString(): string
+ {
+ return self::createUriString($this->scheme, $this->getAuthority(), $this->path, $this->query, $this->fragment);
+ }
+
+ public function getScheme(): string
+ {
+ return $this->scheme;
+ }
+
+ public function getAuthority(): string
+ {
+ if ('' === $this->host) {
+ return '';
+ }
+
+ $authority = $this->host;
+ if ('' !== $this->userInfo) {
+ $authority = $this->userInfo . '@' . $authority;
+ }
+
+ if (null !== $this->port) {
+ $authority .= ':' . $this->port;
+ }
+
+ return $authority;
+ }
+
+ public function getUserInfo(): string
+ {
+ return $this->userInfo;
+ }
+
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ public function getPort(): ?int
+ {
+ return $this->port;
+ }
+
+ public function getPath(): string
+ {
+ return $this->path;
+ }
+
+ public function getQuery(): string
+ {
+ return $this->query;
+ }
+
+ public function getFragment(): string
+ {
+ return $this->fragment;
+ }
+
+ public function withScheme($scheme): self
+ {
+ if (!\is_string($scheme)) {
+ throw new \InvalidArgumentException('Scheme must be a string');
+ }
+
+ if ($this->scheme === $scheme = \strtolower($scheme)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->scheme = $scheme;
+ $new->port = $new->filterPort($new->port);
+
+ return $new;
+ }
+
+ public function withUserInfo($user, $password = null): self
+ {
+ $info = $user;
+ if (null !== $password && '' !== $password) {
+ $info .= ':' . $password;
+ }
+
+ if ($this->userInfo === $info) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->userInfo = $info;
+
+ return $new;
+ }
+
+ public function withHost($host): self
+ {
+ if (!\is_string($host)) {
+ throw new \InvalidArgumentException('Host must be a string');
+ }
+
+ if ($this->host === $host = \strtolower($host)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->host = $host;
+
+ return $new;
+ }
+
+ public function withPort($port): self
+ {
+ if ($this->port === $port = $this->filterPort($port)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->port = $port;
+
+ return $new;
+ }
+
+ public function withPath($path): self
+ {
+ if ($this->path === $path = $this->filterPath($path)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->path = $path;
+
+ return $new;
+ }
+
+ public function withQuery($query): self
+ {
+ if ($this->query === $query = $this->filterQueryAndFragment($query)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->query = $query;
+
+ return $new;
+ }
+
+ public function withFragment($fragment): self
+ {
+ if ($this->fragment === $fragment = $this->filterQueryAndFragment($fragment)) {
+ return $this;
+ }
+
+ $new = clone $this;
+ $new->fragment = $fragment;
+
+ return $new;
+ }
+
+ /**
+ * Create a URI string from its various parts.
+ */
+ private static function createUriString(string $scheme, string $authority, string $path, string $query, string $fragment): string
+ {
+ $uri = '';
+ if ('' !== $scheme) {
+ $uri .= $scheme . ':';
+ }
+
+ if ('' !== $authority) {
+ $uri .= '//' . $authority;
+ }
+
+ if ('' !== $path) {
+ if ('/' !== $path[0]) {
+ if ('' !== $authority) {
+ // If the path is rootless and an authority is present, the path MUST be prefixed by "/"
+ $path = '/' . $path;
+ }
+ } elseif (isset($path[1]) && '/' === $path[1]) {
+ if ('' === $authority) {
+ // If the path is starting with more than one "/" and no authority is present, the
+ // starting slashes MUST be reduced to one.
+ $path = '/' . \ltrim($path, '/');
+ }
+ }
+
+ $uri .= $path;
+ }
+
+ if ('' !== $query) {
+ $uri .= '?' . $query;
+ }
+
+ if ('' !== $fragment) {
+ $uri .= '#' . $fragment;
+ }
+
+ return $uri;
+ }
+
+ /**
+ * Is a given port non-standard for the current scheme?
+ */
+ private static function isNonStandardPort(string $scheme, int $port): bool
+ {
+ return !isset(self::SCHEMES[$scheme]) || $port !== self::SCHEMES[$scheme];
+ }
+
+ private function filterPort($port): ?int
+ {
+ if (null === $port) {
+ return null;
+ }
+
+ $port = (int) $port;
+ if (0 > $port || 0xffff < $port) {
+ throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 0 and 65535', $port));
+ }
+
+ return self::isNonStandardPort($this->scheme, $port) ? $port : null;
+ }
+
+ private function filterPath($path): string
+ {
+ if (!\is_string($path)) {
+ throw new \InvalidArgumentException('Path must be a string');
+ }
+
+ return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path);
+ }
+
+ private function filterQueryAndFragment($str): string
+ {
+ if (!\is_string($str)) {
+ throw new \InvalidArgumentException('Query and fragment must be a string');
+ }
+
+ return \preg_replace_callback('/(?:[^' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str);
+ }
+
+ private static function rawurlencodeMatchZero(array $match): string
+ {
+ return \rawurlencode($match[0]);
+ }
+}
diff --git a/lib/Psr/Http/Message/MessageInterface.php b/lib/Psr/Http/Message/MessageInterface.php
new file mode 100644
index 0000000..dd46e5e
--- /dev/null
+++ b/lib/Psr/Http/Message/MessageInterface.php
@@ -0,0 +1,187 @@
+getHeaders() as $name => $values) {
+ * echo $name . ": " . implode(", ", $values);
+ * }
+ *
+ * // Emit headers iteratively:
+ * foreach ($message->getHeaders() as $name => $values) {
+ * foreach ($values as $value) {
+ * header(sprintf('%s: %s', $name, $value), false);
+ * }
+ * }
+ *
+ * While header names are not case-sensitive, getHeaders() will preserve the
+ * exact case in which headers were originally specified.
+ *
+ * @return string[][] Returns an associative array of the message's headers. Each
+ * key MUST be a header name, and each value MUST be an array of strings
+ * for that header.
+ */
+ public function getHeaders();
+
+ /**
+ * Checks if a header exists by the given case-insensitive name.
+ *
+ * @param string $name Case-insensitive header field name.
+ * @return bool Returns true if any header names match the given header
+ * name using a case-insensitive string comparison. Returns false if
+ * no matching header name is found in the message.
+ */
+ public function hasHeader($name);
+
+ /**
+ * Retrieves a message header value by the given case-insensitive name.
+ *
+ * This method returns an array of all the header values of the given
+ * case-insensitive header name.
+ *
+ * If the header does not appear in the message, this method MUST return an
+ * empty array.
+ *
+ * @param string $name Case-insensitive header field name.
+ * @return string[] An array of string values as provided for the given
+ * header. If the header does not appear in the message, this method MUST
+ * return an empty array.
+ */
+ public function getHeader($name);
+
+ /**
+ * Retrieves a comma-separated string of the values for a single header.
+ *
+ * This method returns all of the header values of the given
+ * case-insensitive header name as a string concatenated together using
+ * a comma.
+ *
+ * NOTE: Not all header values may be appropriately represented using
+ * comma concatenation. For such headers, use getHeader() instead
+ * and supply your own delimiter when concatenating.
+ *
+ * If the header does not appear in the message, this method MUST return
+ * an empty string.
+ *
+ * @param string $name Case-insensitive header field name.
+ * @return string A string of values as provided for the given header
+ * concatenated together using a comma. If the header does not appear in
+ * the message, this method MUST return an empty string.
+ */
+ public function getHeaderLine($name);
+
+ /**
+ * Return an instance with the provided value replacing the specified header.
+ *
+ * While header names are case-insensitive, the casing of the header will
+ * be preserved by this function, and returned from getHeaders().
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * new and/or updated header and value.
+ *
+ * @param string $name Case-insensitive header field name.
+ * @param string|string[] $value Header value(s).
+ * @return static
+ * @throws \InvalidArgumentException for invalid header names or values.
+ */
+ public function withHeader($name, $value);
+
+ /**
+ * Return an instance with the specified header appended with the given value.
+ *
+ * Existing values for the specified header will be maintained. The new
+ * value(s) will be appended to the existing list. If the header did not
+ * exist previously, it will be added.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * new header and/or value.
+ *
+ * @param string $name Case-insensitive header field name to add.
+ * @param string|string[] $value Header value(s).
+ * @return static
+ * @throws \InvalidArgumentException for invalid header names or values.
+ */
+ public function withAddedHeader($name, $value);
+
+ /**
+ * Return an instance without the specified header.
+ *
+ * Header resolution MUST be done without case-sensitivity.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that removes
+ * the named header.
+ *
+ * @param string $name Case-insensitive header field name to remove.
+ * @return static
+ */
+ public function withoutHeader($name);
+
+ /**
+ * Gets the body of the message.
+ *
+ * @return StreamInterface Returns the body as a stream.
+ */
+ public function getBody();
+
+ /**
+ * Return an instance with the specified message body.
+ *
+ * The body MUST be a StreamInterface object.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return a new instance that has the
+ * new body stream.
+ *
+ * @param StreamInterface $body Body.
+ * @return static
+ * @throws \InvalidArgumentException When the body is not valid.
+ */
+ public function withBody(StreamInterface $body);
+}
diff --git a/lib/Psr/Http/Message/RequestInterface.php b/lib/Psr/Http/Message/RequestInterface.php
new file mode 100644
index 0000000..a96d4fd
--- /dev/null
+++ b/lib/Psr/Http/Message/RequestInterface.php
@@ -0,0 +1,129 @@
+getQuery()`
+ * or from the `QUERY_STRING` server param.
+ *
+ * @return array
+ */
+ public function getQueryParams();
+
+ /**
+ * Return an instance with the specified query string arguments.
+ *
+ * These values SHOULD remain immutable over the course of the incoming
+ * request. They MAY be injected during instantiation, such as from PHP's
+ * $_GET superglobal, or MAY be derived from some other value such as the
+ * URI. In cases where the arguments are parsed from the URI, the data
+ * MUST be compatible with what PHP's parse_str() would return for
+ * purposes of how duplicate query parameters are handled, and how nested
+ * sets are handled.
+ *
+ * Setting query string arguments MUST NOT change the URI stored by the
+ * request, nor the values in the server params.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * updated query string arguments.
+ *
+ * @param array $query Array of query string arguments, typically from
+ * $_GET.
+ * @return static
+ */
+ public function withQueryParams(array $query);
+
+ /**
+ * Retrieve normalized file upload data.
+ *
+ * This method returns upload metadata in a normalized tree, with each leaf
+ * an instance of Psr\Http\Message\UploadedFileInterface.
+ *
+ * These values MAY be prepared from $_FILES or the message body during
+ * instantiation, or MAY be injected via withUploadedFiles().
+ *
+ * @return array An array tree of UploadedFileInterface instances; an empty
+ * array MUST be returned if no data is present.
+ */
+ public function getUploadedFiles();
+
+ /**
+ * Create a new instance with the specified uploaded files.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * updated body parameters.
+ *
+ * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
+ * @return static
+ * @throws \InvalidArgumentException if an invalid structure is provided.
+ */
+ public function withUploadedFiles(array $uploadedFiles);
+
+ /**
+ * Retrieve any parameters provided in the request body.
+ *
+ * If the request Content-Type is either application/x-www-form-urlencoded
+ * or multipart/form-data, and the request method is POST, this method MUST
+ * return the contents of $_POST.
+ *
+ * Otherwise, this method may return any results of deserializing
+ * the request body content; as parsing returns structured content, the
+ * potential types MUST be arrays or objects only. A null value indicates
+ * the absence of body content.
+ *
+ * @return null|array|object The deserialized body parameters, if any.
+ * These will typically be an array or object.
+ */
+ public function getParsedBody();
+
+ /**
+ * Return an instance with the specified body parameters.
+ *
+ * These MAY be injected during instantiation.
+ *
+ * If the request Content-Type is either application/x-www-form-urlencoded
+ * or multipart/form-data, and the request method is POST, use this method
+ * ONLY to inject the contents of $_POST.
+ *
+ * The data IS NOT REQUIRED to come from $_POST, but MUST be the results of
+ * deserializing the request body content. Deserialization/parsing returns
+ * structured data, and, as such, this method ONLY accepts arrays or objects,
+ * or a null value if nothing was available to parse.
+ *
+ * As an example, if content negotiation determines that the request data
+ * is a JSON payload, this method could be used to create a request
+ * instance with the deserialized parameters.
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * updated body parameters.
+ *
+ * @param null|array|object $data The deserialized body data. This will
+ * typically be in an array or object.
+ * @return static
+ * @throws \InvalidArgumentException if an unsupported argument type is
+ * provided.
+ */
+ public function withParsedBody($data);
+
+ /**
+ * Retrieve attributes derived from the request.
+ *
+ * The request "attributes" may be used to allow injection of any
+ * parameters derived from the request: e.g., the results of path
+ * match operations; the results of decrypting cookies; the results of
+ * deserializing non-form-encoded message bodies; etc. Attributes
+ * will be application and request specific, and CAN be mutable.
+ *
+ * @return array Attributes derived from the request.
+ */
+ public function getAttributes();
+
+ /**
+ * Retrieve a single derived request attribute.
+ *
+ * Retrieves a single derived request attribute as described in
+ * getAttributes(). If the attribute has not been previously set, returns
+ * the default value as provided.
+ *
+ * This method obviates the need for a hasAttribute() method, as it allows
+ * specifying a default value to return if the attribute is not found.
+ *
+ * @see getAttributes()
+ * @param string $name The attribute name.
+ * @param mixed $default Default value to return if the attribute does not exist.
+ * @return mixed
+ */
+ public function getAttribute($name, $default = null);
+
+ /**
+ * Return an instance with the specified derived request attribute.
+ *
+ * This method allows setting a single derived request attribute as
+ * described in getAttributes().
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that has the
+ * updated attribute.
+ *
+ * @see getAttributes()
+ * @param string $name The attribute name.
+ * @param mixed $value The value of the attribute.
+ * @return static
+ */
+ public function withAttribute($name, $value);
+
+ /**
+ * Return an instance that removes the specified derived request attribute.
+ *
+ * This method allows removing a single derived request attribute as
+ * described in getAttributes().
+ *
+ * This method MUST be implemented in such a way as to retain the
+ * immutability of the message, and MUST return an instance that removes
+ * the attribute.
+ *
+ * @see getAttributes()
+ * @param string $name The attribute name.
+ * @return static
+ */
+ public function withoutAttribute($name);
+}
diff --git a/lib/Psr/Http/Message/StreamInterface.php b/lib/Psr/Http/Message/StreamInterface.php
new file mode 100644
index 0000000..f68f391
--- /dev/null
+++ b/lib/Psr/Http/Message/StreamInterface.php
@@ -0,0 +1,158 @@
+
+ * [user-info@]host[:port]
+ *
+ *
+ * If the port component is not set or is the standard port for the current
+ * scheme, it SHOULD NOT be included.
+ *
+ * @see https://tools.ietf.org/html/rfc3986#section-3.2
+ * @return string The URI authority, in "[user-info@]host[:port]" format.
+ */
+ public function getAuthority();
+
+ /**
+ * Retrieve the user information component of the URI.
+ *
+ * If no user information is present, this method MUST return an empty
+ * string.
+ *
+ * If a user is present in the URI, this will return that value;
+ * additionally, if the password is also present, it will be appended to the
+ * user value, with a colon (":") separating the values.
+ *
+ * The trailing "@" character is not part of the user information and MUST
+ * NOT be added.
+ *
+ * @return string The URI user information, in "username[:password]" format.
+ */
+ public function getUserInfo();
+
+ /**
+ * Retrieve the host component of the URI.
+ *
+ * If no host is present, this method MUST return an empty string.
+ *
+ * The value returned MUST be normalized to lowercase, per RFC 3986
+ * Section 3.2.2.
+ *
+ * @see http://tools.ietf.org/html/rfc3986#section-3.2.2
+ * @return string The URI host.
+ */
+ public function getHost();
+
+ /**
+ * Retrieve the port component of the URI.
+ *
+ * If a port is present, and it is non-standard for the current scheme,
+ * this method MUST return it as an integer. If the port is the standard port
+ * used with the current scheme, this method SHOULD return null.
+ *
+ * If no port is present, and no scheme is present, this method MUST return
+ * a null value.
+ *
+ * If no port is present, but a scheme is present, this method MAY return
+ * the standard port for that scheme, but SHOULD return null.
+ *
+ * @return null|int The URI port.
+ */
+ public function getPort();
+
+ /**
+ * Retrieve the path component of the URI.
+ *
+ * The path can either be empty or absolute (starting with a slash) or
+ * rootless (not starting with a slash). Implementations MUST support all
+ * three syntaxes.
+ *
+ * Normally, the empty path "" and absolute path "/" are considered equal as
+ * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
+ * do this normalization because in contexts with a trimmed base path, e.g.
+ * the front controller, this difference becomes significant. It's the task
+ * of the user to handle both "" and "/".
+ *
+ * The value returned MUST be percent-encoded, but MUST NOT double-encode
+ * any characters. To determine what characters to encode, please refer to
+ * RFC 3986, Sections 2 and 3.3.
+ *
+ * As an example, if the value should include a slash ("/") not intended as
+ * delimiter between path segments, that value MUST be passed in encoded
+ * form (e.g., "%2F") to the instance.
+ *
+ * @see https://tools.ietf.org/html/rfc3986#section-2
+ * @see https://tools.ietf.org/html/rfc3986#section-3.3
+ * @return string The URI path.
+ */
+ public function getPath();
+
+ /**
+ * Retrieve the query string of the URI.
+ *
+ * If no query string is present, this method MUST return an empty string.
+ *
+ * The leading "?" character is not part of the query and MUST NOT be
+ * added.
+ *
+ * The value returned MUST be percent-encoded, but MUST NOT double-encode
+ * any characters. To determine what characters to encode, please refer to
+ * RFC 3986, Sections 2 and 3.4.
+ *
+ * As an example, if a value in a key/value pair of the query string should
+ * include an ampersand ("&") not intended as a delimiter between values,
+ * that value MUST be passed in encoded form (e.g., "%26") to the instance.
+ *
+ * @see https://tools.ietf.org/html/rfc3986#section-2
+ * @see https://tools.ietf.org/html/rfc3986#section-3.4
+ * @return string The URI query string.
+ */
+ public function getQuery();
+
+ /**
+ * Retrieve the fragment component of the URI.
+ *
+ * If no fragment is present, this method MUST return an empty string.
+ *
+ * The leading "#" character is not part of the fragment and MUST NOT be
+ * added.
+ *
+ * The value returned MUST be percent-encoded, but MUST NOT double-encode
+ * any characters. To determine what characters to encode, please refer to
+ * RFC 3986, Sections 2 and 3.5.
+ *
+ * @see https://tools.ietf.org/html/rfc3986#section-2
+ * @see https://tools.ietf.org/html/rfc3986#section-3.5
+ * @return string The URI fragment.
+ */
+ public function getFragment();
+
+ /**
+ * Return an instance with the specified scheme.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified scheme.
+ *
+ * Implementations MUST support the schemes "http" and "https" case
+ * insensitively, and MAY accommodate other schemes if required.
+ *
+ * An empty scheme is equivalent to removing the scheme.
+ *
+ * @param string $scheme The scheme to use with the new instance.
+ * @return static A new instance with the specified scheme.
+ * @throws \InvalidArgumentException for invalid or unsupported schemes.
+ */
+ public function withScheme($scheme);
+
+ /**
+ * Return an instance with the specified user information.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified user information.
+ *
+ * Password is optional, but the user information MUST include the
+ * user; an empty string for the user is equivalent to removing user
+ * information.
+ *
+ * @param string $user The user name to use for authority.
+ * @param null|string $password The password associated with $user.
+ * @return static A new instance with the specified user information.
+ */
+ public function withUserInfo($user, $password = null);
+
+ /**
+ * Return an instance with the specified host.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified host.
+ *
+ * An empty host value is equivalent to removing the host.
+ *
+ * @param string $host The hostname to use with the new instance.
+ * @return static A new instance with the specified host.
+ * @throws \InvalidArgumentException for invalid hostnames.
+ */
+ public function withHost($host);
+
+ /**
+ * Return an instance with the specified port.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified port.
+ *
+ * Implementations MUST raise an exception for ports outside the
+ * established TCP and UDP port ranges.
+ *
+ * A null value provided for the port is equivalent to removing the port
+ * information.
+ *
+ * @param null|int $port The port to use with the new instance; a null value
+ * removes the port information.
+ * @return static A new instance with the specified port.
+ * @throws \InvalidArgumentException for invalid ports.
+ */
+ public function withPort($port);
+
+ /**
+ * Return an instance with the specified path.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified path.
+ *
+ * The path can either be empty or absolute (starting with a slash) or
+ * rootless (not starting with a slash). Implementations MUST support all
+ * three syntaxes.
+ *
+ * If the path is intended to be domain-relative rather than path relative then
+ * it must begin with a slash ("/"). Paths not starting with a slash ("/")
+ * are assumed to be relative to some base path known to the application or
+ * consumer.
+ *
+ * Users can provide both encoded and decoded path characters.
+ * Implementations ensure the correct encoding as outlined in getPath().
+ *
+ * @param string $path The path to use with the new instance.
+ * @return static A new instance with the specified path.
+ * @throws \InvalidArgumentException for invalid paths.
+ */
+ public function withPath($path);
+
+ /**
+ * Return an instance with the specified query string.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified query string.
+ *
+ * Users can provide both encoded and decoded query characters.
+ * Implementations ensure the correct encoding as outlined in getQuery().
+ *
+ * An empty query string value is equivalent to removing the query string.
+ *
+ * @param string $query The query string to use with the new instance.
+ * @return static A new instance with the specified query string.
+ * @throws \InvalidArgumentException for invalid query strings.
+ */
+ public function withQuery($query);
+
+ /**
+ * Return an instance with the specified URI fragment.
+ *
+ * This method MUST retain the state of the current instance, and return
+ * an instance that contains the specified URI fragment.
+ *
+ * Users can provide both encoded and decoded fragment characters.
+ * Implementations ensure the correct encoding as outlined in getFragment().
+ *
+ * An empty fragment value is equivalent to removing the fragment.
+ *
+ * @param string $fragment The fragment to use with the new instance.
+ * @return static A new instance with the specified fragment.
+ */
+ public function withFragment($fragment);
+
+ /**
+ * Return the string representation as a URI reference.
+ *
+ * Depending on which components of the URI are present, the resulting
+ * string is either a full URI or relative reference according to RFC 3986,
+ * Section 4.1. The method concatenates the various components of the URI,
+ * using the appropriate delimiters:
+ *
+ * - If a scheme is present, it MUST be suffixed by ":".
+ * - If an authority is present, it MUST be prefixed by "//".
+ * - The path can be concatenated without delimiters. But there are two
+ * cases where the path has to be adjusted to make the URI reference
+ * valid as PHP does not allow to throw an exception in __toString():
+ * - If the path is rootless and an authority is present, the path MUST
+ * be prefixed by "/".
+ * - If the path is starting with more than one "/" and no authority is
+ * present, the starting slashes MUST be reduced to one.
+ * - If a query is present, it MUST be prefixed by "?".
+ * - If a fragment is present, it MUST be prefixed by "#".
+ *
+ * @see http://tools.ietf.org/html/rfc3986#section-4.1
+ * @return string
+ */
+ public function __toString();
+}
diff --git a/lib/Tracy/Bar/Bar.php b/lib/Tracy/Bar/Bar.php
new file mode 100644
index 0000000..867072b
--- /dev/null
+++ b/lib/Tracy/Bar/Bar.php
@@ -0,0 +1,242 @@
+panels[$id]));
+ }
+ $this->panels[$id] = $panel;
+ return $this;
+ }
+
+
+ /**
+ * Returns panel with given id
+ */
+ public function getPanel(string $id): ?IBarPanel
+ {
+ return $this->panels[$id] ?? null;
+ }
+
+
+ /**
+ * Renders loading '
+ + ''
+ );
+ doc.body.innerHTML = '' + this.elem.innerHTML + ' ';
+ evalScripts(doc.body);
+ if (this.elem.querySelector('h1')) {
+ doc.title = this.elem.querySelector('h1').textContent;
+ }
+
+ win.addEventListener('beforeunload', () => {
+ this.toPeek();
+ win.close(); // forces closing, can be invoked by F5
+ });
+
+ doc.addEventListener('keyup', (e) => {
+ if (e.keyCode === 27 && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
+ win.close();
+ }
+ });
+
+ this.elem.classList.remove(Panel.FLOAT);
+ this.elem.classList.remove(Panel.PEEK);
+ this.elem.classList.remove(Panel.FOCUSED);
+ this.elem.classList.remove(Panel.RESIZED);
+ this.elem.classList.add(Panel.WINDOW);
+ this.elem.Tracy.window = win;
+ return true;
+ }
+
+
+ reposition(deltaX, deltaY) {
+ let pos = getPosition(this.elem);
+ if (pos.width) { // is visible?
+ setPosition(this.elem, {left: pos.left + (deltaX || 0), top: pos.top + (deltaY || 0)});
+ if (this.is(Panel.RESIZED)) {
+ let size = getWindowSize();
+ this.elem.style.width = Math.min(size.width, pos.width) + 'px';
+ this.elem.style.height = Math.min(size.height, pos.height) + 'px';
+ }
+ }
+ }
+
+
+ savePosition() {
+ let key = this.id.split(':')[0]; // remove :contentId part
+ let pos = getPosition(this.elem);
+ if (this.is(Panel.WINDOW)) {
+ localStorage.setItem(key, JSON.stringify({window: true}));
+ } else if (pos.width) { // is visible?
+ localStorage.setItem(key, JSON.stringify({right: pos.right, bottom: pos.bottom, width: pos.width, height: pos.height, zIndex: this.elem.style.zIndex - Tracy.panelZIndex, resized: this.is(Panel.RESIZED)}));
+ } else {
+ localStorage.removeItem(key);
+ }
+ }
+
+
+ restorePosition() {
+ let key = this.id.split(':')[0];
+ let pos = JSON.parse(localStorage.getItem(key));
+ if (!pos) {
+ this.elem.classList.add(Panel.PEEK);
+ } else if (pos.window) {
+ this.init();
+ this.toWindow() || this.toFloat();
+ } else if (this.elem.dataset.tracyContent) {
+ this.init();
+ this.toFloat();
+ if (pos.resized) {
+ this.elem.classList.add(Panel.RESIZED);
+ this.elem.style.width = pos.width + 'px';
+ this.elem.style.height = pos.height + 'px';
+ }
+ setPosition(this.elem, pos);
+ this.elem.style.zIndex = Tracy.panelZIndex + (pos.zIndex || 1);
+ Panel.zIndexCounter = Math.max(Panel.zIndexCounter, (pos.zIndex || 1)) + 1;
+ }
+ }
+ }
+
+ Panel.PEEK = 'tracy-mode-peek';
+ Panel.FLOAT = 'tracy-mode-float';
+ Panel.WINDOW = 'tracy-mode-window';
+ Panel.FOCUSED = 'tracy-focused';
+ Panel.RESIZED = 'tracy-panel-resized';
+ Panel.zIndexCounter = 1;
+
+
+ class Bar
+ {
+ init() {
+ this.id = 'tracy-debug-bar';
+ this.elem = document.getElementById(this.id);
+
+ draggable(this.elem, {
+ handles: this.elem.querySelectorAll('li:first-child'),
+ draggedClass: 'tracy-dragged',
+ stop: () => {
+ this.savePosition();
+ }
+ });
+
+ this.elem.addEventListener('mousedown', (e) => {
+ e.preventDefault();
+ });
+
+ this.initTabs(this.elem);
+ this.restorePosition();
+
+ (new MutationObserver(() => {
+ this.restorePosition();
+ })).observe(this.elem, {childList: true, characterData: true, subtree: true});
+ }
+
+
+ initTabs(elem) {
+ elem.querySelectorAll('a').forEach((link) => {
+ link.addEventListener('click', (e) => {
+ if (link.dataset.tracyAction === 'close') {
+ this.close();
+
+ } else if (link.rel) {
+ let panel = Debug.panels[link.rel];
+ panel.init();
+
+ if (e.shiftKey) {
+ panel.toFloat();
+ panel.toWindow();
+
+ } else if (panel.is(Panel.FLOAT)) {
+ panel.toPeek();
+
+ } else {
+ panel.toFloat();
+ if (panel.peekPosition) {
+ panel.reposition(-Math.round(Math.random() * 100) - 20, (Math.round(Math.random() * 100) + 20) * (this.isAtTop() ? 1 : -1));
+ panel.peekPosition = false;
+ }
+ }
+ }
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ });
+
+ link.addEventListener('mouseenter', (e) => {
+ if (e.buttons || !link.rel || elem.classList.contains('tracy-dragged')) {
+ return;
+ }
+
+ clearTimeout(this.displayTimeout);
+ this.displayTimeout = setTimeout(() => {
+ let panel = Debug.panels[link.rel];
+ panel.focus();
+
+ if (panel.is(Panel.PEEK)) {
+ panel.init();
+
+ let pos = getPosition(panel.elem);
+ setPosition(panel.elem, {
+ left: getOffset(link).left + getPosition(link).width + 4 - pos.width,
+ top: this.isAtTop()
+ ? getOffset(this.elem).top + getPosition(this.elem).height + 4
+ : getOffset(this.elem).top - pos.height - 4
+ });
+ panel.peekPosition = true;
+ }
+ }, 50);
+ });
+
+ link.addEventListener('mouseleave', () => {
+ clearTimeout(this.displayTimeout);
+
+ if (link.rel && !elem.classList.contains('tracy-dragged')) {
+ Debug.panels[link.rel].blur();
+ }
+ });
+ });
+ this.autoHideLabels();
+ }
+
+
+ autoHideLabels() {
+ let width = getWindowSize().width;
+ this.elem.querySelectorAll('.tracy-row').forEach((row) => {
+ let i, labels = row.querySelectorAll('.tracy-label');
+ for (i = 0; i < labels.length && row.clientWidth < width; i++) {
+ labels.item(i).hidden = false;
+ }
+ for (i = labels.length - 1; i >= 0 && row.clientWidth >= width; i--) {
+ labels.item(i).hidden = true;
+ }
+ });
+ }
+
+
+ close() {
+ document.getElementById('tracy-debug').style.display = 'none';
+ }
+
+
+ reposition(deltaX, deltaY) {
+ let pos = getPosition(this.elem);
+ if (pos.width) { // is visible?
+ setPosition(this.elem, {left: pos.left + (deltaX || 0), top: pos.top + (deltaY || 0)});
+ this.savePosition();
+ }
+ }
+
+
+ savePosition() {
+ let pos = getPosition(this.elem);
+ if (pos.width) { // is visible?
+ localStorage.setItem(this.id, JSON.stringify(this.isAtTop() ? {right: pos.right, top: pos.top} : {right: pos.right, bottom: pos.bottom}));
+ }
+ }
+
+
+ restorePosition() {
+ let pos = JSON.parse(localStorage.getItem(this.id));
+ setPosition(this.elem, pos || {right: 0, bottom: 0});
+ this.savePosition();
+ }
+
+
+ isAtTop() {
+ let pos = getPosition(this.elem);
+ return pos.top < 100 && pos.bottom > pos.top;
+ }
+ }
+
+
+ class Debug
+ {
+ static init(content) {
+ Debug.layer = document.createElement('div');
+ Debug.layer.setAttribute('id', 'tracy-debug');
+ Debug.layer.innerHTML = addNonces(content);
+ (document.body || document.documentElement).appendChild(Debug.layer);
+ evalScripts(Debug.layer);
+ Tracy.Dumper.init(); // for common dump()
+ Debug.layer.style.display = 'block';
+ Debug.bar.init();
+
+ Debug.layer.querySelectorAll('.tracy-panel').forEach((panel) => {
+ Debug.panels[panel.id] = new Panel(panel.id);
+ Debug.panels[panel.id].restorePosition();
+ });
+
+ Debug.captureWindow();
+ Debug.captureAjax();
+
+ Tracy.TableSort.init();
+ }
+
+
+ static loadAjax(content) {
+ let rows = Debug.bar.elem.querySelectorAll('.tracy-row[data-tracy-group=ajax]');
+ rows = Array.from(rows).reverse();
+ let max = window.TracyMaxAjaxRows || 3;
+ rows.forEach((row) => {
+ if (--max > 0) {
+ return;
+ }
+ row.querySelectorAll('a[rel]').forEach((tab) => {
+ let panel = Debug.panels[tab.rel];
+ if (panel.is(Panel.PEEK)) {
+ delete Debug.panels[tab.rel];
+ panel.elem.parentNode.removeChild(panel.elem);
+ }
+ });
+ row.parentNode.removeChild(row);
+ });
+
+ if (rows[0]) { // update content in first-row panels
+ rows[0].querySelectorAll('a[rel]').forEach((tab) => {
+ Debug.panels[tab.rel].savePosition();
+ Debug.panels[tab.rel].toPeek();
+ });
+ }
+
+ Debug.layer.insertAdjacentHTML('beforeend', content.panels);
+ evalScripts(Debug.layer);
+ Debug.bar.elem.insertAdjacentHTML('beforeend', content.bar);
+ let ajaxBar = Debug.bar.elem.querySelector('.tracy-row:last-child');
+
+ Debug.layer.querySelectorAll('.tracy-panel').forEach((panel) => {
+ if (!Debug.panels[panel.id]) {
+ Debug.panels[panel.id] = new Panel(panel.id);
+ Debug.panels[panel.id].restorePosition();
+ }
+ });
+
+ Debug.bar.initTabs(ajaxBar);
+ }
+
+
+ static captureWindow() {
+ let size = getWindowSize();
+
+ window.addEventListener('resize', () => {
+ let newSize = getWindowSize();
+
+ Debug.bar.reposition(newSize.width - size.width, newSize.height - size.height);
+ Debug.bar.autoHideLabels();
+
+ for (let id in Debug.panels) {
+ Debug.panels[id].reposition(newSize.width - size.width, newSize.height - size.height);
+ }
+
+ size = newSize;
+ });
+
+ window.addEventListener('unload', () => {
+ for (let id in Debug.panels) {
+ Debug.panels[id].savePosition();
+ }
+ });
+ }
+
+
+ static captureAjax() {
+ let header = Tracy.getAjaxHeader();
+ if (!header) {
+ return;
+ }
+ let oldOpen = XMLHttpRequest.prototype.open;
+
+ XMLHttpRequest.prototype.open = function() {
+ oldOpen.apply(this, arguments);
+ if (window.TracyAutoRefresh !== false && new URL(arguments[1], location.origin).host === location.host) {
+ let reqId = header + '_' + ajaxCounter++;
+ this.setRequestHeader('X-Tracy-Ajax', reqId);
+ this.addEventListener('load', function() {
+ if (this.getAllResponseHeaders().match(/^X-Tracy-Ajax: 1/mi)) {
+ Debug.loadScript(baseUrl + '_tracy_bar=content-ajax.' + reqId + '&XDEBUG_SESSION_STOP=1&v=' + Math.random());
+ }
+ });
+ }
+ };
+
+ let oldFetch = window.fetch;
+ window.fetch = function(request, options) {
+ request = request instanceof Request ? request : new Request(request, options || {});
+
+ if (window.TracyAutoRefresh !== false && new URL(request.url, location.origin).host === location.host) {
+ let reqId = header + '_' + ajaxCounter++;
+ request.headers.set('X-Tracy-Ajax', reqId);
+ return oldFetch(request).then((response) => {
+ if (response.headers.has('X-Tracy-Ajax') && response.headers.get('X-Tracy-Ajax')[0] === '1') {
+ Debug.loadScript(baseUrl + '_tracy_bar=content-ajax.' + reqId + '&XDEBUG_SESSION_STOP=1&v=' + Math.random());
+ }
+
+ return response;
+ });
+ }
+
+ return oldFetch(request);
+ };
+ }
+
+
+ static loadScript(url) {
+ if (Debug.scriptElem) {
+ Debug.scriptElem.parentNode.removeChild(Debug.scriptElem);
+ }
+ Debug.scriptElem = document.createElement('script');
+ Debug.scriptElem.src = url;
+ Debug.scriptElem.setAttribute('nonce', nonce);
+ (document.body || document.documentElement).appendChild(Debug.scriptElem);
+ }
+ }
+
+
+ function evalScripts(elem) {
+ elem.querySelectorAll('script').forEach((script) => {
+ if ((!script.hasAttribute('type') || script.type === 'text/javascript' || script.type === 'application/javascript') && !script.tracyEvaluated) {
+ let document = script.ownerDocument;
+ let dolly = document.createElement('script');
+ dolly.textContent = script.textContent;
+ dolly.setAttribute('nonce', nonce);
+ (document.body || document.documentElement).appendChild(dolly);
+ script.tracyEvaluated = true;
+ }
+ });
+ }
+
+
+ let dragging;
+
+ function draggable(elem, options) {
+ let dE = document.documentElement, started, deltaX, deltaY, clientX, clientY;
+ options = options || {};
+
+ let redraw = function () {
+ if (dragging) {
+ setPosition(elem, {left: clientX + deltaX, top: clientY + deltaY});
+ requestAnimationFrame(redraw);
+ }
+ };
+
+ let onMove = function(e) {
+ if (e.buttons === 0) {
+ return onEnd(e);
+ }
+ if (!started) {
+ if (options.draggedClass) {
+ elem.classList.add(options.draggedClass);
+ }
+ if (options.start) {
+ options.start(e, elem);
+ }
+ started = true;
+ }
+
+ clientX = e.touches ? e.touches[0].clientX : e.clientX;
+ clientY = e.touches ? e.touches[0].clientY : e.clientY;
+ return false;
+ };
+
+ let onEnd = function(e) {
+ if (started) {
+ if (options.draggedClass) {
+ elem.classList.remove(options.draggedClass);
+ }
+ if (options.stop) {
+ options.stop(e, elem);
+ }
+ }
+ dragging = null;
+ dE.removeEventListener('mousemove', onMove);
+ dE.removeEventListener('mouseup', onEnd);
+ dE.removeEventListener('touchmove', onMove);
+ dE.removeEventListener('touchend', onEnd);
+ return false;
+ };
+
+ let onStart = function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ if (dragging) { // missed mouseup out of window?
+ return onEnd(e);
+ }
+
+ let pos = getPosition(elem);
+ clientX = e.touches ? e.touches[0].clientX : e.clientX;
+ clientY = e.touches ? e.touches[0].clientY : e.clientY;
+ deltaX = pos.left - clientX;
+ deltaY = pos.top - clientY;
+ dragging = true;
+ started = false;
+ dE.addEventListener('mousemove', onMove);
+ dE.addEventListener('mouseup', onEnd);
+ dE.addEventListener('touchmove', onMove);
+ dE.addEventListener('touchend', onEnd);
+ requestAnimationFrame(redraw);
+ if (options.start) {
+ options.start(e, elem);
+ }
+ };
+
+ options.handles.forEach((handle) => {
+ handle.addEventListener('mousedown', onStart);
+ handle.addEventListener('touchstart', onStart);
+
+ handle.addEventListener('click', (e) => {
+ if (started) {
+ e.stopImmediatePropagation();
+ }
+ });
+ });
+ }
+
+
+ // returns total offset for element
+ function getOffset(elem) {
+ let res = {left: elem.offsetLeft, top: elem.offsetTop};
+ while (elem = elem.offsetParent) { // eslint-disable-line no-cond-assign
+ res.left += elem.offsetLeft; res.top += elem.offsetTop;
+ }
+ return res;
+ }
+
+
+ function getWindowSize() {
+ return {
+ width: document.documentElement.clientWidth,
+ height: document.compatMode === 'BackCompat' ? window.innerHeight : document.documentElement.clientHeight
+ };
+ }
+
+
+ // move to new position
+ function setPosition(elem, coords) {
+ let win = getWindowSize();
+ if (typeof coords.right !== 'undefined') {
+ coords.left = win.width - elem.offsetWidth - coords.right;
+ }
+ if (typeof coords.bottom !== 'undefined') {
+ coords.top = win.height - elem.offsetHeight - coords.bottom;
+ }
+ elem.style.left = Math.max(0, Math.min(coords.left, win.width - elem.offsetWidth)) + 'px';
+ elem.style.top = Math.max(0, Math.min(coords.top, win.height - elem.offsetHeight)) + 'px';
+ }
+
+
+ // returns current position
+ function getPosition(elem) {
+ let win = getWindowSize();
+ return {
+ left: elem.offsetLeft,
+ top: elem.offsetTop,
+ right: win.width - elem.offsetWidth - elem.offsetLeft,
+ bottom: win.height - elem.offsetHeight - elem.offsetTop,
+ width: elem.offsetWidth,
+ height: elem.offsetHeight
+ };
+ }
+
+
+ function addNonces(html) {
+ let el = document.createElement('div');
+ el.innerHTML = html;
+ el.querySelectorAll('style').forEach((style) => {
+ style.setAttribute('nonce', nonce);
+ });
+ return el.innerHTML;
+ }
+
+
+ if (document.currentScript) {
+ nonce = document.currentScript.getAttribute('nonce') || document.currentScript.nonce;
+ contentId = document.currentScript.dataset.id;
+ }
+
+ let Tracy = window.Tracy = window.Tracy || {};
+ Tracy.panelZIndex = Tracy.panelZIndex || 20000;
+ Tracy.DebugPanel = Panel;
+ Tracy.DebugBar = Bar;
+ Tracy.Debug = Debug;
+ Tracy.getAjaxHeader = () => contentId;
+
+ Debug.bar = new Bar;
+ Debug.panels = {};
+})();
diff --git a/lib/Tracy/Bar/assets/bar.phtml b/lib/Tracy/Bar/assets/bar.phtml
new file mode 100644
index 0000000..8fa3a86
--- /dev/null
+++ b/lib/Tracy/Bar/assets/bar.phtml
@@ -0,0 +1,37 @@
+
+
+
+
+ - ">
+
+
+
+ - redirect
+
+ - AJAX
+
+
+tab) { ?>
+ - panel): ?>= trim($panel->tab) ?>', trim($panel->tab), ''; endif ?>
+
+
+
+ - ×
+
+
diff --git a/lib/Tracy/Bar/assets/loader.phtml b/lib/Tracy/Bar/assets/loader.phtml
new file mode 100644
index 0000000..53b0405
--- /dev/null
+++ b/lib/Tracy/Bar/assets/loader.phtml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/Tracy/Bar/assets/panels.phtml b/lib/Tracy/Bar/assets/panels.phtml
new file mode 100644
index 0000000..6286425
--- /dev/null
+++ b/lib/Tracy/Bar/assets/panels.phtml
@@ -0,0 +1,35 @@
+
+ ¤
+ ×
+
+';
+
+echo '';
+
+foreach ($panels as $panel) {
+ $content = $panel->panel ? ($panel->panel . "\n" . $icons) : '';
+ $class = 'tracy-panel ' . ($type === 'ajax' ? '' : 'tracy-panel-persist') . ' tracy-panel-' . $type; ?>
+ '> ';
+echo ' ';
diff --git a/lib/Tracy/Bar/panels/dumps.panel.phtml b/lib/Tracy/Bar/panels/dumps.panel.phtml
new file mode 100644
index 0000000..8f04738
--- /dev/null
+++ b/lib/Tracy/Bar/panels/dumps.panel.phtml
@@ -0,0 +1,35 @@
+
+
+
+Dumps
+
+
+
+
+ = Helpers::escapeHtml($item['title']) ?>
+
+
+ = $item['dump'] ?>
+
+
diff --git a/lib/Tracy/Bar/panels/dumps.tab.phtml b/lib/Tracy/Bar/panels/dumps.tab.phtml
new file mode 100644
index 0000000..399a641
--- /dev/null
+++ b/lib/Tracy/Bar/panels/dumps.tab.phtml
@@ -0,0 +1,19 @@
+
+dumps
diff --git a/lib/Tracy/Bar/panels/errors.panel.phtml b/lib/Tracy/Bar/panels/errors.panel.phtml
new file mode 100644
index 0000000..8a44709
--- /dev/null
+++ b/lib/Tracy/Bar/panels/errors.panel.phtml
@@ -0,0 +1,26 @@
+
+Errors
+
+
+
+ $count): list($file, $line, $message) = explode('|', $item, 3) ?>
+
+ = $count ? "$count\xC3\x97" : '' ?> |
+ = Helpers::escapeHtml($message), ' in ', Helpers::editorLink($file, (int) $line) ?> |
+
+
+
+
diff --git a/lib/Tracy/Bar/panels/errors.tab.phtml b/lib/Tracy/Bar/panels/errors.tab.phtml
new file mode 100644
index 0000000..75a15b2
--- /dev/null
+++ b/lib/Tracy/Bar/panels/errors.tab.phtml
@@ -0,0 +1,31 @@
+
+
+
+= $sum = array_sum($data), $sum > 1 ? ' errors' : ' error' ?>
+
diff --git a/lib/Tracy/Bar/panels/info.panel.phtml b/lib/Tracy/Bar/panels/info.panel.phtml
new file mode 100644
index 0000000..9719299
--- /dev/null
+++ b/lib/Tracy/Bar/panels/info.panel.phtml
@@ -0,0 +1,127 @@
+cpuUsage) && $this->time) {
+ foreach (getrusage() as $key => $val) {
+ $this->cpuUsage[$key] -= $val;
+ }
+ $userUsage = -round(($this->cpuUsage['ru_utime.tv_sec'] * 1e6 + $this->cpuUsage['ru_utime.tv_usec']) / $this->time / 10000);
+ $systemUsage = -round(($this->cpuUsage['ru_stime.tv_sec'] * 1e6 + $this->cpuUsage['ru_stime.tv_usec']) / $this->time / 10000);
+}
+
+$countClasses = function (array $list): int {
+ return count(array_filter($list, function (string $name): bool {
+ return (new \ReflectionClass($name))->isUserDefined();
+ }));
+};
+
+$ipFormatter = static function (?string $ip): ?string {
+ if ($ip === '127.0.0.1' || $ip === '::1') {
+ $ip .= ' (localhost)';
+ }
+ return $ip;
+};
+
+$opcache = function_exists('opcache_get_status') ? @opcache_get_status() : null; // @ can be restricted
+$cachedFiles = isset($opcache['scripts']) ? array_intersect(array_keys($opcache['scripts']), get_included_files()) : [];
+
+$info = [
+ 'Execution time' => number_format($this->time * 1000, 1, '.', ' ') . ' ms',
+ 'CPU usage user + system' => isset($userUsage) ? (int) $userUsage . ' % + ' . (int) $systemUsage . ' %' : null,
+ 'Peak of allocated memory' => number_format(memory_get_peak_usage() / 1000000, 2, '.', ' ') . ' MB',
+ 'Included files' => count(get_included_files()),
+ 'OPcache' => $opcache ? round(count($cachedFiles) * 100 / count(get_included_files())) . '% cached' : null,
+ 'Classes + interfaces + traits' => $countClasses(get_declared_classes()) . ' + '
+ . $countClasses(get_declared_interfaces()) . ' + ' . $countClasses(get_declared_traits()),
+ 'Your IP' => $ipFormatter($_SERVER['REMOTE_ADDR'] ?? null),
+ 'Server IP' => $ipFormatter($_SERVER['SERVER_ADDR'] ?? null),
+ 'HTTP method / response code' => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] . ' / ' . http_response_code() : null,
+ 'PHP' => PHP_VERSION,
+ 'Xdebug' => extension_loaded('xdebug') ? phpversion('xdebug') : null,
+ 'Tracy' => Debugger::VERSION,
+ 'Server' => $_SERVER['SERVER_SOFTWARE'] ?? null,
+];
+
+$info = array_map('strval', array_filter($info + (array) $this->data));
+
+$packages = $devPackages = [];
+if (class_exists('Composer\Autoload\ClassLoader', false)) {
+ $baseDir = (function () {
+ @include dirname((new \ReflectionClass('Composer\Autoload\ClassLoader'))->getFileName()) . '/autoload_psr4.php'; // @ may not exist
+ return $baseDir;
+ })();
+ $composer = @json_decode((string) file_get_contents($baseDir . '/composer.lock')); // @ may not exist or be valid
+ list($packages, $devPackages) = [(array) @$composer->packages, (array) @$composer->{'packages-dev'}]; // @ keys may not exist
+ foreach ([&$packages, &$devPackages] as &$items) {
+ array_walk($items, function($package) {
+ $package->hash = $package->source->reference ?? $package->dist->reference ?? null;
+ }, $items);
+ usort($items, function ($a, $b): int { return $a->name <=> $b->name; });
+ }
+}
+
+?>
+
+
+System info
+
+
+
+
+ $val): ?>
+
+ 25): ?>
+ = Helpers::escapeHtml($key) ?> = Helpers::escapeHtml($val) ?> |
+
+ = Helpers::escapeHtml($key) ?> | = Helpers::escapeHtml($val) ?> |
+
+
+
+
+
+
+
+
+
+
+
+
+ = Helpers::escapeHtml($package->name) ?> | = Helpers::escapeHtml($package->version . (strpos($package->version, 'dev') !== false && $package->hash ? ' #' . substr($package->hash, 0, 4) : '')) ?> |
+
+
+
+
+
+ Dev Packages
+
+
+ = Helpers::escapeHtml($package->name) ?> | = Helpers::escapeHtml($package->version . (strpos($package->version, 'dev') !== false && $package->hash ? ' #' . substr($package->hash, 0, 4) : '')) ?> |
+
+
+
+
+
+
+
diff --git a/lib/Tracy/Bar/panels/info.tab.phtml b/lib/Tracy/Bar/panels/info.tab.phtml
new file mode 100644
index 0000000..19926b7
--- /dev/null
+++ b/lib/Tracy/Bar/panels/info.tab.phtml
@@ -0,0 +1,20 @@
+time = microtime(true) - Debugger::$time;
+
+?>
+
+= number_format($this->time * 1000, 1, '.', ' ') ?> ms
+
diff --git a/lib/Tracy/BlueScreen/BlueScreen.php b/lib/Tracy/BlueScreen/BlueScreen.php
new file mode 100644
index 0000000..809beea
--- /dev/null
+++ b/lib/Tracy/BlueScreen/BlueScreen.php
@@ -0,0 +1,385 @@
+collapsePaths[] = preg_match('#(.+/vendor)/tracy/tracy/src/Tracy/BlueScreen$#', strtr(__DIR__, '\\', '/'), $m)
+ ? $m[1]
+ : __DIR__;
+ }
+
+
+ /**
+ * Add custom panel as function (?\Throwable $e): ?array
+ * @return static
+ */
+ public function addPanel(callable $panel): self
+ {
+ if (!in_array($panel, $this->panels, true)) {
+ $this->panels[] = $panel;
+ }
+ return $this;
+ }
+
+
+ /**
+ * Add action.
+ * @return static
+ */
+ public function addAction(callable $action): self
+ {
+ $this->actions[] = $action;
+ return $this;
+ }
+
+
+ /**
+ * Renders blue screen.
+ */
+ public function render(\Throwable $exception): void
+ {
+ if (Helpers::isAjax() && session_status() === PHP_SESSION_ACTIVE) {
+ $_SESSION['_tracy']['bluescreen'][$_SERVER['HTTP_X_TRACY_AJAX']] = [
+ 'content' => Helpers::capture(function () use ($exception) {
+ $this->renderTemplate($exception, __DIR__ . '/assets/content.phtml');
+ }),
+ 'time' => time(),
+ ];
+
+ } else {
+ $this->renderTemplate($exception, __DIR__ . '/assets/page.phtml');
+ }
+ }
+
+
+ /**
+ * Renders blue screen to file (if file exists, it will not be overwritten).
+ */
+ public function renderToFile(\Throwable $exception, string $file): bool
+ {
+ if ($handle = @fopen($file, 'x')) {
+ ob_start(); // double buffer prevents sending HTTP headers in some PHP
+ ob_start(function ($buffer) use ($handle): void { fwrite($handle, $buffer); }, 4096);
+ $this->renderTemplate($exception, __DIR__ . '/assets/page.phtml', false);
+ ob_end_flush();
+ ob_end_clean();
+ fclose($handle);
+ return true;
+ }
+ return false;
+ }
+
+
+ private function renderTemplate(\Throwable $exception, string $template, $toScreen = true): void
+ {
+ $messageHtml = Dumper::encodeString((string) $exception->getMessage(), self::MAX_MESSAGE_LENGTH);
+ $messageHtml = htmlspecialchars($messageHtml, ENT_SUBSTITUTE, 'UTF-8');
+ $messageHtml = preg_replace(
+ '#\'\S(?:[^\']|\\\\\')*\S\'|"\S(?:[^"]|\\\\")*\S"#',
+ '$0',
+ $messageHtml
+ );
+ $messageHtml = preg_replace_callback(
+ '#\w+\\\\[\w\\\\]+\w#',
+ function ($m) {
+ return class_exists($m[0], false) || interface_exists($m[0], false)
+ ? '' . $m[0] . ''
+ : $m[0];
+ },
+ $messageHtml
+ );
+
+ $info = array_filter($this->info);
+ $source = Helpers::getSource();
+ $title = $exception instanceof \ErrorException
+ ? Helpers::errorTypeToString($exception->getSeverity())
+ : Helpers::getClass($exception);
+ $lastError = $exception instanceof \ErrorException || $exception instanceof \Error ? null : error_get_last();
+
+ if (function_exists('apache_request_headers')) {
+ $httpHeaders = apache_request_headers();
+ } else {
+ $httpHeaders = array_filter($_SERVER, function ($k) { return strncmp($k, 'HTTP_', 5) === 0; }, ARRAY_FILTER_USE_KEY);
+ $httpHeaders = array_combine(array_map(function ($k) { return strtolower(strtr(substr($k, 5), '_', '-')); }, array_keys($httpHeaders)), $httpHeaders);
+ }
+
+ $snapshot = &$this->snapshot;
+ $snapshot = [];
+ $dump = $this->getDumper();
+
+ $css = array_map('file_get_contents', array_merge([
+ __DIR__ . '/assets/bluescreen.css',
+ __DIR__ . '/../Toggle/toggle.css',
+ __DIR__ . '/../TableSort/table-sort.css',
+ __DIR__ . '/../Dumper/assets/dumper.css',
+ ], Debugger::$customCssFiles));
+ $css = preg_replace('#\s+#u', ' ', implode($css));
+
+ $nonce = $toScreen ? Helpers::getNonce() : null;
+ $actions = $toScreen ? $this->renderActions($exception) : [];
+
+ require $template;
+ }
+
+
+ /**
+ * @return \stdClass[]
+ */
+ private function renderPanels(?\Throwable $ex): array
+ {
+ $obLevel = ob_get_level();
+ $res = [];
+ foreach ($this->panels as $callback) {
+ try {
+ $panel = $callback($ex);
+ if (empty($panel['tab']) || empty($panel['panel'])) {
+ continue;
+ }
+ $res[] = (object) $panel;
+ continue;
+ } catch (\Throwable $e) {
+ }
+ while (ob_get_level() > $obLevel) { // restore ob-level if broken
+ ob_end_clean();
+ }
+ is_callable($callback, true, $name);
+ $res[] = (object) [
+ 'tab' => "Error in panel $name",
+ 'panel' => nl2br(Helpers::escapeHtml($e)),
+ ];
+ }
+ return $res;
+ }
+
+
+ /**
+ * @return array[]
+ */
+ private function renderActions(\Throwable $ex): array
+ {
+ $actions = [];
+ foreach ($this->actions as $callback) {
+ $action = $callback($ex);
+ if (!empty($action['link']) && !empty($action['label'])) {
+ $actions[] = $action;
+ }
+ }
+
+ if (property_exists($ex, 'tracyAction') && !empty($ex->tracyAction['link']) && !empty($ex->tracyAction['label'])) {
+ $actions[] = $ex->tracyAction;
+ }
+
+ if (preg_match('# ([\'"])(\w{3,}(?:\\\\\w{3,})+)\1#i', $ex->getMessage(), $m)) {
+ $class = $m[2];
+ if (
+ !class_exists($class) && !interface_exists($class) && !trait_exists($class)
+ && ($file = Helpers::guessClassFile($class)) && !is_file($file)
+ ) {
+ $actions[] = [
+ 'link' => Helpers::editorUri($file, 1, 'create'),
+ 'label' => 'create class',
+ ];
+ }
+ }
+
+ if (preg_match('# ([\'"])((?:/|[a-z]:[/\\\\])\w[^\'"]+\.\w{2,5})\1#i', $ex->getMessage(), $m)) {
+ $file = $m[2];
+ $actions[] = [
+ 'link' => Helpers::editorUri($file, 1, $label = is_file($file) ? 'open' : 'create'),
+ 'label' => $label . ' file',
+ ];
+ }
+
+ $query = ($ex instanceof \ErrorException ? '' : Helpers::getClass($ex) . ' ')
+ . preg_replace('#\'.*\'|".*"#Us', '', $ex->getMessage());
+ $actions[] = [
+ 'link' => 'https://www.google.com/search?sourceid=tracy&q=' . urlencode($query),
+ 'label' => 'search',
+ 'external' => true,
+ ];
+
+ if (
+ $ex instanceof \ErrorException
+ && !empty($ex->skippable)
+ && preg_match('#^https?://#', $source = Helpers::getSource())
+ ) {
+ $actions[] = [
+ 'link' => $source . (strpos($source, '?') ? '&' : '?') . '_tracy_skip_error',
+ 'label' => 'skip error',
+ ];
+ }
+ return $actions;
+ }
+
+
+ /**
+ * Returns syntax highlighted source code.
+ */
+ public static function highlightFile(string $file, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): ?string
+ {
+ $source = @file_get_contents($file); // @ file may not exist
+ if ($source) {
+ $source = static::highlightPhp($source, $line, $lines, $vars, $keysToHide);
+ if ($editor = Helpers::editorUri($file, $line)) {
+ $source = substr_replace($source, ' data-tracy-href="' . Helpers::escapeHtml($editor) . '"', 4, 0);
+ }
+ return $source;
+ }
+ }
+
+
+ /**
+ * Returns syntax highlighted source code.
+ */
+ public static function highlightPhp(string $source, int $line, int $lines = 15, array $vars = [], array $keysToHide = []): string
+ {
+ if (function_exists('ini_set')) {
+ ini_set('highlight.comment', '#998; font-style: italic');
+ ini_set('highlight.default', '#000');
+ ini_set('highlight.html', '#06B');
+ ini_set('highlight.keyword', '#D24; font-weight: bold');
+ ini_set('highlight.string', '#080');
+ }
+
+ $source = str_replace(["\r\n", "\r"], "\n", $source);
+ $source = explode("\n", highlight_string($source, true));
+ $out = $source[0]; //
+ $source = str_replace(' ', "\n", $source[1]);
+ $out .= static::highlightLine($source, $line, $lines);
+
+ if ($vars) {
+ $out = preg_replace_callback('#">\$(\w+)( )?#', function (array $m) use ($vars, $keysToHide): string {
+ if (array_key_exists($m[1], $vars)) {
+ $dump = Dumper::toHtml($vars[$m[1]], [
+ Dumper::DEPTH => 1,
+ Dumper::KEYS_TO_HIDE => $keysToHide,
+ ]);
+ return '" title="' . str_replace('"', '"', trim(strip_tags($dump))) . $m[0];
+ }
+ return $m[0];
+ }, $out);
+ }
+
+ $out = str_replace(' ', ' ', $out);
+ return "$out ";
+ }
+
+
+ /**
+ * Returns highlighted line in HTML code.
+ */
+ public static function highlightLine(string $html, int $line, int $lines = 15): string
+ {
+ $source = explode("\n", "\n" . str_replace("\r\n", "\n", $html));
+ $out = '';
+ $spans = 1;
+ $start = $i = max(1, min($line, count($source) - 1) - (int) floor($lines * 2 / 3));
+ while (--$i >= 1) { // find last highlighted block
+ if (preg_match('#.*(?span[^>]*>)#', $source[$i], $m)) {
+ if ($m[1] !== '') {
+ $spans++;
+ $out .= $m[1];
+ }
+ break;
+ }
+ }
+
+ $source = array_slice($source, $start, $lines, true);
+ end($source);
+ $numWidth = strlen((string) key($source));
+
+ foreach ($source as $n => $s) {
+ $spans += substr_count($s, ']+>#', $s, $tags);
+ if ($n == $line) {
+ $out .= sprintf(
+ "%{$numWidth}s: %s\n%s",
+ $n,
+ strip_tags($s),
+ implode('', $tags[0])
+ );
+ } else {
+ $out .= sprintf("%{$numWidth}s: %s\n", $n, $s);
+ }
+ }
+ $out .= str_repeat('', $spans) . ' ';
+ return $out;
+ }
+
+
+ /**
+ * Should a file be collapsed in stack trace?
+ */
+ public function isCollapsed(string $file): bool
+ {
+ $file = strtr($file, '\\', '/') . '/';
+ foreach ($this->collapsePaths as $path) {
+ $path = strtr($path, '\\', '/') . '/';
+ if (strncmp($file, $path, strlen($path)) === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public function getDumper(): \Closure
+ {
+ $keysToHide = array_flip(array_map('strtolower', $this->keysToHide));
+
+ return function ($v, $k = null) use ($keysToHide): string {
+ if (is_string($k) && isset($keysToHide[strtolower($k)])) {
+ $v = Dumper::HIDDEN_VALUE;
+ }
+ return Dumper::toHtml($v, [
+ Dumper::DEPTH => $this->maxDepth,
+ Dumper::TRUNCATE => $this->maxLength,
+ Dumper::SNAPSHOT => &$this->snapshot,
+ Dumper::LOCATION => Dumper::LOCATION_CLASS,
+ Dumper::KEYS_TO_HIDE => $this->keysToHide,
+ ]);
+ };
+ }
+}
diff --git a/lib/Tracy/BlueScreen/assets/bluescreen.css b/lib/Tracy/BlueScreen/assets/bluescreen.css
new file mode 100644
index 0000000..cdf8bfc
--- /dev/null
+++ b/lib/Tracy/BlueScreen/assets/bluescreen.css
@@ -0,0 +1,273 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+#tracy-bs {
+ font: 9pt/1.5 Verdana, sans-serif;
+ background: white;
+ color: #333;
+ position: absolute;
+ z-index: 20000;
+ left: 0;
+ top: 0;
+ width: 100%;
+ text-align: left;
+}
+
+#tracy-bs a {
+ text-decoration: none;
+ color: #328ADC;
+ padding: 2px 4px;
+ margin: -2px -4px;
+}
+
+#tracy-bs a:hover,
+#tracy-bs a:focus {
+ color: #085AA3;
+}
+
+#tracy-bs-toggle {
+ position: absolute;
+ right: .5em;
+ top: .5em;
+ text-decoration: none;
+ background: #CD1818;
+ color: white !important;
+ padding: 3px;
+}
+
+.tracy-bs-main {
+ display: flex;
+ flex-direction: column;
+ min-height: 100vh;
+}
+
+.tracy-bs-main.tracy-collapsed {
+ display: none;
+}
+
+#tracy-bs div.panel:last-of-type {
+ flex: 1;
+}
+
+#tracy-bs-error {
+ background: #CD1818;
+ color: white;
+ font-size: 13pt;
+}
+
+#tracy-bs-error a {
+ border-bottom-color: rgba(255, 255, 255, .3) !important;
+}
+
+#tracy-bs-error a.action {
+ color: white !important;
+ opacity: 0;
+ font-size: .7em;
+ border-bottom: none !important;
+}
+
+#tracy-bs-error:hover a.action {
+ opacity: .6;
+}
+
+#tracy-bs-error a.action:hover {
+ opacity: 1;
+}
+
+#tracy-bs-error i {
+ color: #ffefa1;
+ font-style: normal;
+}
+
+#tracy-bs h1 {
+ font-size: 15pt;
+ font-weight: normal;
+ text-shadow: 1px 1px 2px rgba(0, 0, 0, .3);
+ margin: .7em 0;
+}
+
+#tracy-bs h1 span {
+ white-space: pre-wrap;
+}
+
+#tracy-bs h2 {
+ font-size: 14pt;
+ font-weight: normal;
+ margin: .6em 0;
+}
+
+#tracy-bs h3 {
+ font-size: 10pt;
+ font-weight: bold;
+ margin: 1em 0;
+ padding: 0;
+}
+
+#tracy-bs p,
+#tracy-bs pre {
+ margin: .8em 0
+}
+
+#tracy-bs pre,
+#tracy-bs code,
+#tracy-bs table {
+ font: 9pt/1.5 Consolas, monospace !important;
+}
+
+#tracy-bs pre,
+#tracy-bs table {
+ background: #FDF5CE;
+ padding: .4em .7em;
+ border: 1px dotted silver;
+ overflow: auto;
+}
+
+#tracy-bs table pre {
+ padding: 0;
+ margin: 0;
+ border: none;
+}
+
+#tracy-bs table {
+ border-collapse: collapse;
+ width: 100%;
+ margin-bottom: 1em;
+}
+
+#tracy-bs td,
+#tracy-bs th {
+ vertical-align: top;
+ text-align: left;
+ padding: 2px 6px;
+ border: 1px solid #e6dfbf;
+}
+
+#tracy-bs th {
+ font-weight: bold;
+}
+
+#tracy-bs tr > :first-child {
+ width: 20%;
+}
+
+#tracy-bs tr:nth-child(2n),
+#tracy-bs tr:nth-child(2n) pre {
+ background-color: #F7F0CB;
+}
+
+#tracy-bs ol {
+ margin: 1em 0;
+ padding-left: 2.5em;
+}
+
+#tracy-bs ul {
+ font-size: 7pt;
+ padding: 2em 3em;
+ margin: 1em 0 0;
+ color: #777;
+ background: #F6F5F3;
+ border-top: 1px solid #DDD;
+ list-style: none;
+}
+
+#tracy-bs .footer-logo a {
+ position: absolute;
+ bottom: 0;
+ right: 0;
+ width: 100px;
+ height: 50px;
+ background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAUBAMAAAD/1DctAAAAMFBMVEWupZzj39rEvbTy8O3X0sz9/PvGwLu8tavQysHq6OS0rKP5+Pbd2dT29fPMxbzPx8DKErMJAAAACXBIWXMAAAsTAAALEwEAmpwYAAACGUlEQVQoFX3TQWgTQRQA0MWLIJJDYehBTykhG5ERTx56K1u8eEhCYtomE7x5L4iLh0ViF7egewuFFqSIYE6hIHsIYQ6CQSg9CDKn4QsNCRlB59C74J/ZNHW1+An5+bOPyf6/s46oz2P+A0yIeZZ2ieEHi6TOnLKTxvWq+b52mxlVO3xnM1s7xLX1504XQH65OnW2dBqn7cCkYsFsfYsWpyY/2salmFTpEyzeR8zosYqMdiPDXdyU52K1wgEa/SjGpdEwUAxqvRfckQCDOyFearsEHe2grvkh/cFAHKvdtI3lcVceKQIOFpv+FOZaNPQBwJZLPp+hfrvT5JZXaUFsR8zqQc9qSgAharkfS5M/5F6nGJJAtXq/eLr3ucZpHccSxOOIPaQhtHohpCH2Xu6rLmQ0djnr4/+J3C6v+AW8/XWYxwYNdlhWj/P5fPSTQwVr0T9lGxdaBCqErNZaqYnEwbkjEB3NasGF3lPdrHa1nnxNOMgj0+neePUPjd2v/qVvUv29ifvc19huQ48qwXShy/9o8o3OSk0cs37mOFd0Ydgvsf/oZEnPVtggfd66lORn9mDyyzXU13SRtH2L6aR5T/snGAcZPfAXz5J1YlJWBEuxdMYqQecpBrlM49xAbmqyHA+xlA1FxBtqT2xmJoNXZlIt74ZBLeJ9ZGDqByNI7p543idzJ23vXEv7IgnsxiS+eNtwNbFdLq7+Bi4wQ0I4SVb9AAAAAElFTkSuQmCC') no-repeat;
+ opacity: .6;
+ padding: 0;
+ margin: 0;
+}
+
+#tracy-bs .footer-logo a:hover,
+#tracy-bs .footer-logo a:focus {
+ opacity: 1;
+ transition: opacity 0.1s;
+}
+
+
+#tracy-bs div.panel {
+ padding: 1px 25px;
+}
+
+#tracy-bs div.inner {
+ background: #F4F3F1;
+ padding: .1em 1em 1em;
+ border-radius: 8px;
+}
+
+#tracy-bs .outer {
+ overflow: auto;
+}
+
+#tracy-bs.mac .outer {
+ padding-bottom: 12px;
+}
+
+
+/* source code */
+#tracy-bs pre.code > div {
+ min-width: 100%;
+ float: left;
+ white-space: pre;
+}
+
+#tracy-bs .highlight {
+ background: #CD1818;
+ color: white;
+ font-weight: bold;
+ font-style: normal;
+ display: block;
+ padding: 0 .4em;
+ margin: 0 -.4em;
+}
+
+#tracy-bs .line {
+ color: #9F9C7F;
+ font-weight: normal;
+ font-style: normal;
+}
+
+#tracy-bs pre:hover span[title] {
+ border-bottom: 1px solid rgba(0, 0, 0, 0.2);
+}
+
+#tracy-bs a[href^=editor\:] {
+ color: inherit;
+ border-bottom: 1px dotted rgba(0, 0, 0, .3);
+}
+
+#tracy-bs span[data-tracy-href] {
+ border-bottom: 1px dotted rgba(0, 0, 0, .3);
+}
+
+#tracy-bs .tracy-dump-whitespace {
+ color: #0003;
+}
+
+#tracy-bs .caused {
+ float: right;
+ padding: .3em .6em;
+ background: #df8075;
+ border-radius: 0 0 0 8px;
+ white-space: nowrap;
+}
+
+#tracy-bs .caused a {
+ color: white;
+}
+
+#tracy-bs .args tr:first-child > * {
+ position: relative;
+}
+
+#tracy-bs .args tr:first-child td:before {
+ position: absolute;
+ right: .3em;
+ content: 'may not be true';
+ opacity: .4;
+}
diff --git a/lib/Tracy/BlueScreen/assets/bluescreen.js b/lib/Tracy/BlueScreen/assets/bluescreen.js
new file mode 100644
index 0000000..a4638ab
--- /dev/null
+++ b/lib/Tracy/BlueScreen/assets/bluescreen.js
@@ -0,0 +1,75 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+'use strict';
+
+(function(){
+ class BlueScreen
+ {
+ static init(ajax) {
+ let blueScreen = document.getElementById('tracy-bs');
+ let styles = [];
+
+ for (let i = 0; i < document.styleSheets.length; i++) {
+ let style = document.styleSheets[i];
+ if (!style.ownerNode.classList.contains('tracy-debug')) {
+ style.oldDisabled = style.disabled;
+ style.disabled = true;
+ styles.push(style);
+ }
+ }
+
+ if (navigator.platform.indexOf('Mac') > -1) {
+ blueScreen.classList.add('mac');
+ }
+
+ document.getElementById('tracy-bs-toggle').addEventListener('tracy-toggle', function() {
+ let collapsed = this.classList.contains('tracy-collapsed');
+ for (let i = 0; i < styles.length; i++) {
+ styles[i].disabled = collapsed ? styles[i].oldDisabled : true;
+ }
+ });
+
+ if (!ajax) {
+ document.body.appendChild(blueScreen);
+ let id = location.href + document.getElementById('tracy-bs-error').textContent;
+ Tracy.Toggle.persist(blueScreen, sessionStorage.getItem('tracy-toggles-bskey') === id);
+ sessionStorage.setItem('tracy-toggles-bskey', id);
+ }
+
+ if (inited) {
+ return;
+ }
+ inited = true;
+
+ // enables toggling via ESC
+ document.addEventListener('keyup', (e) => {
+ if (e.keyCode === 27 && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) { // ESC
+ Tracy.Toggle.toggle(document.getElementById('tracy-bs-toggle'));
+ }
+ });
+
+ Tracy.TableSort.init();
+ }
+
+
+ static loadAjax(content) {
+ let ajaxBs = document.getElementById('tracy-bs');
+ if (ajaxBs) {
+ ajaxBs.parentNode.removeChild(ajaxBs);
+ }
+ document.body.insertAdjacentHTML('beforeend', content);
+ ajaxBs = document.getElementById('tracy-bs');
+ Tracy.Dumper.init(ajaxBs);
+ BlueScreen.init(true);
+ window.scrollTo(0, 0);
+ }
+ }
+
+ let inited;
+
+
+ let Tracy = window.Tracy = window.Tracy || {};
+ Tracy.BlueScreen = BlueScreen;
+})();
diff --git a/lib/Tracy/BlueScreen/assets/content.phtml b/lib/Tracy/BlueScreen/assets/content.phtml
new file mode 100644
index 0000000..a2c255b
--- /dev/null
+++ b/lib/Tracy/BlueScreen/assets/content.phtml
@@ -0,0 +1,369 @@
+getCode() ? ' #' . $exception->getCode() : '';
+
+?>
+
+
+
+
+ getMessage()): ?> = Helpers::escapeHtml(Dumper::encodeString($title . $code, self::MAX_MESSAGE_LENGTH)) ?>
+
+
+ = $messageHtml ?: Helpers::escapeHtml(Dumper::encodeString($title . $code, self::MAX_MESSAGE_LENGTH)) ?>
+
+ >= Helpers::escapeHtml($item['label']) ?>►
+
+
+
+ getPrevious()): ?>
+
+
+
+
+
+
+
+
+ >
+
+
+
+
+ = Helpers::escapeHtml(Helpers::getClass($ex) . ($ex->getCode() ? ' #' . $ex->getCode() : '')) ?>
+
+ = Helpers::escapeHtml($ex->getMessage()) ?>
+
+
+
+
+ renderPanels($ex) as $panel): ?>
+
+
+
+
+ = $panel->panel ?>
+
+
+
+
+ getTrace(); $expanded = null ?>
+ getSeverity(), [E_USER_NOTICE, E_USER_WARNING, E_USER_DEPRECATED], true)) && $this->isCollapsed($ex->getFile())) {
+ foreach ($stack as $key => $row) {
+ if (isset($row['file']) && !$this->isCollapsed($row['file'])) { $expanded = $key; break; }
+ }
+ } ?>
+
+
+
+
+
+ File: = Helpers::editorLink($ex->getFile(), $ex->getLine()) ?>
+ getFile())): ?>= self::highlightFile($ex->getFile(), $ex->getLine(), 15, $ex instanceof \ErrorException && isset($ex->context) ? $ex->context : [], $this->keysToHide) ?>
+
+
+
+
+
+
+
+
+
+
+ $row): ?>
+
+
+
+ = Helpers::editorLink($row['file'], $row['line']) ?>
+
+ inner-code
+
+
+ source
+
+ ";
+ if (isset($row['class'])) echo Helpers::escapeHtml($row['class'] . $row['type']);
+ if (isset($row['object'])) echo '';
+ echo Helpers::escapeHtml($row['function']), '(';
+ if (!empty($row['args'])): ?>arguments)
+
+
+
+ = self::highlightFile($row['file'], $row['line']) ?>
+
+
+
+ = $dump($row['object']) ?>
+
+
+
+
+
+ getParameters();
+ } catch (\Exception $e) {
+ $params = [];
+ }
+ foreach ($row['args'] as $k => $v) {
+ echo '', Helpers::escapeHtml(isset($params[$k]) ? '$' . $params[$k]->name : "#$k"), ' | ';
+ echo $dump($v, isset($params[$k]) ? $params[$k]->name : null);
+ echo " | \n";
+ }
+ ?>
+
+
+
+
+
+
+
+
+
+
+ context) && is_array($ex->context)):?>
+
+
+
+
+
+
+ context as $k => $v) {
+ echo '$', Helpers::escapeHtml($k), ' | ', $dump($v, $k), " | \n";
+ }
+ ?>
+
+
+
+
+
+ getPrevious()); ?>
+ ' ?>
+
+
+ count((array) new \Exception)):?>
+
+
+
+ = $dump($exception) ?>
+
+
+
+
+
+
+
+
+
+ = Helpers::errorTypeToString($lastError['type']) ?>: = Helpers::escapeHtml($lastError['message']) ?>
+
+ = Helpers::editorLink($lastError['file'], $lastError['line']) ?>
+ = self::highlightFile($lastError['file'], $lastError['line']) ?>
+
+ inner-code
+
+
+
+
+
+
+
+ renderPanels(null) as $panel): ?>
+ bottom)) { $bottomPanels[] = $panel; continue; } ?>
+ collapsed) || $panel->collapsed ? ' tracy-collapsed' : ''; ?>
+
+
+
+
+ = $panel->panel ?>
+
+
+
+
+
+
+
+
+
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', $dump($v, $k), " | \n";
+ ?>
+
+
+
+
+
+
+
+ empty
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', $k === '__NF' ? 'Nette Session' : $dump($v, $k), " | \n";
+ ?>
+
+
+
+
+
+
+
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', $dump($v, $k), " | \n";
+ ?>
+
+
+
+
+
+
+
+
+
+ $v) {
+ echo '', Helpers::escapeHtml($k), ' | ';
+ echo '', $dump($v, $k), " | \n";
+ }
+ ?>
+
+
+
+
+
+
+
+ |.+\z#s', '', $phpinfo) ?>
+
+
+
+
+
+
+
+
+
+ Process ID = Helpers::escapeHtml(getmypid()) ?>
+ php= Helpers::escapeHtml(explode('):', $source, 2)[1]) ?>
+
+ Arguments
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', Helpers::escapeHtml($v), " | \n";
+ ?>
+
+
+
+
+
+
+
+
+
+
+ URL
+ = Helpers::escapeHtml($source) ?>
+
+ Headers
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', Helpers::escapeHtml($v), " | \n";
+ ?>
+
+
+
+
+
+ $= Helpers::escapeHtml($name) ?>
+
+ empty
+
+
+
+ $v) echo '', Helpers::escapeHtml($k), ' | ', $dump($v, $k), " | \n";
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ Headers
+
+
+
+ ', Helpers::escapeHtml($s[0]), ' | ', Helpers::escapeHtml(trim($s[1])), " | \n"; }
+ ?>
+
+
+
+ no headers
+
+
+
+
+
+
+
+
+
+
+ = $panel->panel ?>
+
+
+
+
+
+ >
+
diff --git a/lib/Tracy/BlueScreen/assets/page.phtml b/lib/Tracy/BlueScreen/assets/page.phtml
new file mode 100644
index 0000000..a8e9cd7
--- /dev/null
+++ b/lib/Tracy/BlueScreen/assets/page.phtml
@@ -0,0 +1,55 @@
+getCode() ? ' #' . $exception->getCode() : '';
+$nonceAttr = $nonce ? ' nonce="' . Helpers::escapeHtml($nonce) . '"' : '';
+?>
+
+
+
+
+
+
+ = Helpers::escapeHtml($title . ': ' . $exception->getMessage() . $code) ?>
+
+ getPrevious()): ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/Tracy/Debugger/Debugger.php b/lib/Tracy/Debugger/Debugger.php
new file mode 100644
index 0000000..dd7325a
--- /dev/null
+++ b/lib/Tracy/Debugger/Debugger.php
@@ -0,0 +1,608 @@
+dispatchAssets()) {
+ exit;
+ }
+ }
+
+
+ /**
+ * Renders loading
+
+
+
+ Server Error
+
+
+
+
+
+ Server Error
+
+ We're sorry! The server encountered an internal error and
+ was unable to complete your request. Please try again later.
+
+ error 500 | Tracy is unable to log error.
+
+
+
+
diff --git a/lib/Tracy/Dumper/Dumper.php b/lib/Tracy/Dumper/Dumper.php
new file mode 100644
index 0000000..b64638b
--- /dev/null
+++ b/lib/Tracy/Dumper/Dumper.php
@@ -0,0 +1,686 @@
+ '1;33',
+ 'null' => '1;33',
+ 'number' => '1;32',
+ 'string' => '1;36',
+ 'array' => '1;31',
+ 'key' => '1;37',
+ 'object' => '1;31',
+ 'visibility' => '1;30',
+ 'resource' => '1;37',
+ 'indent' => '1;30',
+ ];
+
+ /** @var array */
+ public static $resources = [
+ 'stream' => 'stream_get_meta_data',
+ 'stream-context' => 'stream_context_get_options',
+ 'curl' => 'curl_getinfo',
+ ];
+
+ /** @var array */
+ public static $objectExporters = [
+ 'Closure' => [self::class, 'exportClosure'],
+ 'SplFileInfo' => [self::class, 'exportSplFileInfo'],
+ 'SplObjectStorage' => [self::class, 'exportSplObjectStorage'],
+ '__PHP_Incomplete_Class' => [self::class, 'exportPhpIncompleteClass'],
+ ];
+
+ /** @var int|null */
+ private $maxDepth = 4;
+
+ /** @var int|null */
+ private $maxLength = 150;
+
+ /** @var int|bool */
+ private $collapseTop = 14;
+
+ /** @var int */
+ private $collapseSub = 7;
+
+ /** @var int */
+ private $location = 0;
+
+ /** @var bool|null lazy-loading via JavaScript? true=full, false=none, null=collapsed parts */
+ private $lazy;
+
+ /** @var array|null */
+ private $snapshot;
+
+ /** @var bool */
+ private $debugInfo = false;
+
+ /** @var array */
+ private $keysToHide = [];
+
+ /** @var callable[] */
+ private $resourceDumpers;
+
+ /** @var callable[] */
+ private $objectDumpers;
+
+
+ /**
+ * Dumps variable to the output.
+ * @return mixed variable
+ */
+ public static function dump($var, array $options = [])
+ {
+ if (PHP_SAPI !== 'cli' && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list()))) {
+ echo self::toHtml($var, $options);
+ } elseif (self::detectColors()) {
+ echo self::toTerminal($var, $options);
+ } else {
+ echo self::toText($var, $options);
+ }
+ return $var;
+ }
+
+
+ /**
+ * Dumps variable to HTML.
+ */
+ public static function toHtml($var, array $options = []): string
+ {
+ return (new static($options))->asHtml($var);
+ }
+
+
+ /**
+ * Dumps variable to plain text.
+ */
+ public static function toText($var, array $options = []): string
+ {
+ return (new static($options))->asTerminal($var);
+ }
+
+
+ /**
+ * Dumps variable to x-terminal.
+ */
+ public static function toTerminal($var, array $options = []): string
+ {
+ return (new static($options))->asTerminal($var, self::$terminalColors);
+ }
+
+
+ private function __construct(array $options = [])
+ {
+ $this->maxDepth = $options[self::DEPTH] ?? $this->maxDepth;
+ $this->maxLength = $options[self::TRUNCATE] ?? $this->maxLength;
+ $this->collapseTop = $options[self::COLLAPSE] ?? $this->collapseTop;
+ $this->collapseSub = $options[self::COLLAPSE_COUNT] ?? $this->collapseSub;
+ $this->location = $options[self::LOCATION] ?? $this->location;
+ $this->location = $this->location === true ? ~0 : (int) $this->location;
+ $this->snapshot = &$options[self::SNAPSHOT];
+ if ($options[self::LIVE] ?? false) {
+ $this->snapshot = &self::$liveSnapshot;
+ }
+ $this->lazy = is_array($this->snapshot) ? true : ($options[self::LAZY] ?? $this->lazy);
+ $this->debugInfo = $options[self::DEBUGINFO] ?? $this->debugInfo;
+ $this->keysToHide = array_flip(array_map('strtolower', $options[self::KEYS_TO_HIDE] ?? []));
+ $this->resourceDumpers = ($options['resourceExporters'] ?? []) + self::$resources;
+ $this->objectDumpers = ($options[self::OBJECT_EXPORTERS] ?? []) + self::$objectExporters;
+ uksort($this->objectDumpers, function ($a, $b): int {
+ return $b === '' || (class_exists($a, false) && is_subclass_of($a, $b)) ? -1 : 1;
+ });
+ }
+
+
+ /**
+ * Dumps variable to HTML.
+ */
+ private function asHtml($var): string
+ {
+ [$file, $line, $code] = $this->location ? $this->findLocation() : null;
+ $locAttrs = $file && $this->location & self::LOCATION_SOURCE ? Helpers::formatHtml(
+ ' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line, Helpers::editorUri($file, $line)
+ ) : null;
+
+ if (is_array($this->snapshot)) {
+ $options[self::SNAPSHOT] = &$this->snapshot;
+ }
+ $snapshot = &$options[self::SNAPSHOT]; // reference must exist
+
+ $html = $json = null;
+ if ($this->lazy && (is_array($var) || is_object($var) || is_resource($var)) && $var) {
+ $json = $this->toJson($var, $options);
+ $snapshot = (array) $snapshot;
+ } else {
+ $html = $this->dumpVar($var, $options + [self::LAZY => $this->lazy]);
+ }
+
+ return ' snapshot) ? ' data-tracy-snapshot=' . $this->formatSnapshotAttribute($snapshot) : '')
+ . ($json ? " data-tracy-dump='" . json_encode($json, JSON_HEX_APOS | JSON_HEX_AMP) . "'>" : '>')
+ . $html
+ . ($file && $this->location & self::LOCATION_LINK ? 'in ' . Helpers::editorLink($file, $line) . '' : '')
+ . " \n";
+ }
+
+
+ /**
+ * Dumps variable to x-terminal.
+ */
+ private function asTerminal($var, array $colors = []): string
+ {
+ $s = $this->dumpVar($var, [self::LAZY => false]);
+ if ($colors) {
+ $s = preg_replace_callback('# |#', function ($m) use ($colors): string {
+ return "\033[" . (isset($m[1], $colors[$m[1]]) ? $colors[$m[1]] : '0') . 'm';
+ }, $s);
+ }
+ $s = htmlspecialchars_decode(strip_tags($s), ENT_QUOTES);
+ if ($this->location & self::LOCATION_LINK && ([$file, $line] = $this->findLocation())) {
+ $s .= "in $file:$line";
+ }
+ return $s;
+ }
+
+
+ /**
+ * Internal toHtml() dump implementation.
+ * @param mixed $var
+ */
+ private function dumpVar(&$var, array $options, int $level = 0): string
+ {
+ if (method_exists(__CLASS__, $m = 'dump' . gettype($var))) {
+ return $this->$m($var, $options, $level);
+ } else {
+ return " unknown type\n";
+ }
+ }
+
+
+ private function dumpNull(): string
+ {
+ return " null\n";
+ }
+
+
+ private function dumpBoolean(&$var): string
+ {
+ return ' ' . ($var ? 'true' : 'false') . "\n";
+ }
+
+
+ private function dumpInteger(&$var): string
+ {
+ return " $var\n";
+ }
+
+
+ private function dumpDouble(&$var): string
+ {
+ $var = is_finite($var)
+ ? ($tmp = json_encode($var)) . (strpos($tmp, '.') === false ? '.0' : '')
+ : var_export($var, true);
+ return " $var\n";
+ }
+
+
+ private function dumpString(&$var): string
+ {
+ return ' "'
+ . Helpers::escapeHtml($this->encodeString($var, $this->maxLength))
+ . '"' . (strlen($var) > 1 ? ' (' . strlen($var) . ')' : '') . "\n";
+ }
+
+
+ private function dumpArray(&$var, array $options, int $level): string
+ {
+ $out = ' array (';
+
+ if (empty($var)) {
+ return $out . ")\n";
+
+ } elseif (in_array($var, $options['parents'] ?? [], true)) {
+ return $out . (count($var) - 1) . ") [ RECURSION ]\n";
+
+ } elseif (!$this->maxDepth || $level < $this->maxDepth) {
+ $collapsed = $level
+ ? count($var) >= $this->collapseSub
+ : (is_int($this->collapseTop) ? count($var) >= $this->collapseTop : $this->collapseTop);
+
+ $span = ' "
+ . $out . count($var) . ")\n";
+
+ } else {
+ $out = $span . '>' . $out . count($var) . ")\n" . ' ';
+ $options['parents'][] = $var;
+ foreach ($var as $k => &$v) {
+ $hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
+ $out .= ' ' . str_repeat('| ', $level) . ''
+ . '' . Helpers::escapeHtml($this->encodeKey($k)) . ' => '
+ . ($hide
+ ? Helpers::escapeHtml(self::hideValue($v)) . "\n"
+ : $this->dumpVar($v, $options, $level + 1)
+ );
+ }
+ array_pop($options['parents']);
+
+ return $out . ' ';
+ }
+
+ } else {
+ return $out . count($var) . ") [ ... ]\n";
+ }
+ }
+
+
+ private function dumpObject(&$var, array $options, int $level): string
+ {
+ $fields = $this->exportObject($var);
+
+ $editorAttributes = '';
+ if ($this->location & self::LOCATION_CLASS) {
+ $rc = $var instanceof \Closure ? new \ReflectionFunction($var) : new \ReflectionClass($var);
+ $editor = $rc->getFileName() ? Helpers::editorUri($rc->getFileName(), $rc->getStartLine()) : null;
+ if ($editor) {
+ $editorAttributes = Helpers::formatHtml(
+ ' title="Declared in file % on line %" data-tracy-href="%"',
+ $rc->getFileName(),
+ $rc->getStartLine(),
+ $editor
+ );
+ }
+ }
+ $out = ' '
+ . Helpers::escapeHtml(Helpers::getClass($var))
+ . ' #' . substr(md5(spl_object_hash($var)), 0, 4) . '';
+
+ if (empty($fields)) {
+ return $out . "\n";
+
+ } elseif (in_array($var, $options['parents'] ?? [], true)) {
+ return $out . " { RECURSION }\n";
+
+ } elseif (!$this->maxDepth || $level < $this->maxDepth || $var instanceof \Closure) {
+ $collapsed = $level
+ ? count($fields) >= $this->collapseSub
+ : (is_int($this->collapseTop) ? count($fields) >= $this->collapseTop : $this->collapseTop);
+
+ $span = ' " . $out . "\n";
+
+ } else {
+ $out = $span . '>' . $out . "\n" . ' ';
+ $options['parents'][] = $var;
+ foreach ($fields as $k => &$v) {
+ $vis = '';
+ if (isset($k[0]) && $k[0] === "\x00") {
+ $vis = ' ' . ($k[1] === '*' ? 'protected' : 'private') . '';
+ $k = substr($k, strrpos($k, "\x00") + 1);
+ }
+ $hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
+ $out .= ' ' . str_repeat('| ', $level) . ''
+ . '' . Helpers::escapeHtml($this->encodeKey($k)) . "$vis => "
+ . ($hide
+ ? Helpers::escapeHtml(self::hideValue($v)) . "\n"
+ : $this->dumpVar($v, $options, $level + 1)
+ );
+ }
+ array_pop($options['parents']);
+
+ return $out . ' ';
+ }
+
+
+ } else {
+ return $out . " { ... }\n";
+ }
+ }
+
+
+ private function dumpResource(&$var, array $options, int $level): string
+ {
+ $type = get_resource_type($var);
+ $out = ' ' . Helpers::escapeHtml($type) . ' resource '
+ . ' #' . (int) $var . '';
+ if (isset($this->resourceDumpers[$type])) {
+ $out = " $out\n ";
+ foreach (($this->resourceDumpers[$type])($var) as $k => $v) {
+ $out .= ' ' . str_repeat('| ', $level) . ''
+ . '' . Helpers::escapeHtml($k) . ' => ' . $this->dumpVar($v, $options, $level + 1);
+ }
+ return $out . ' ';
+ }
+ return "$out\n";
+ }
+
+
+ /**
+ * @return mixed
+ */
+ private function toJson(&$var, array $options = [], int $level = 0)
+ {
+ if (is_bool($var) || $var === null || is_int($var)) {
+ return $var;
+
+ } elseif (is_float($var)) {
+ return is_finite($var)
+ ? (strpos($tmp = json_encode($var), '.') ? $var : ['number' => "$tmp.0"])
+ : ['type' => (string) $var];
+
+ } elseif (is_string($var)) {
+ return $this->encodeString($var, $this->maxLength);
+
+ } elseif (is_array($var)) {
+ if (count($var) && (($rec = in_array($var, $options['parents'] ?? [], true)) || $level >= $this->maxDepth)) {
+ return ['stop' => [count($var), $rec]];
+ }
+ $res = [];
+ $options['parents'][] = $var;
+ foreach ($var as $k => &$v) {
+ $hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
+ $res[] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1)];
+ }
+ array_pop($options['parents']);
+ return $res;
+
+ } elseif (is_object($var)) {
+ $hash = spl_object_hash($var);
+ $obj = &$options[self::SNAPSHOT][$hash];
+ if ($obj && $obj['level'] <= $level) {
+ return ['object' => $obj['id']];
+ }
+
+ $obj = $obj ?: [
+ 'id' => count($options[self::SNAPSHOT]),
+ 'name' => Helpers::getClass($var),
+ 'hash' => substr(md5($hash), 0, 4),
+ 'level' => $level,
+ 'object' => $var,
+ ];
+ if (empty($obj['editor']) && ($this->location & self::LOCATION_CLASS)) {
+ $rc = $var instanceof \Closure ? new \ReflectionFunction($var) : new \ReflectionClass($var);
+ if ($editor = $rc->getFileName() ? Helpers::editorUri($rc->getFileName(), $rc->getStartLine()) : null) {
+ $obj['editor'] = ['file' => $rc->getFileName(), 'line' => $rc->getStartLine(), 'url' => $editor];
+ }
+ }
+
+ if ($level < $this->maxDepth || !$this->maxDepth) {
+ $obj['level'] = $level;
+ $obj['items'] = [];
+
+ foreach ($this->exportObject($var) as $k => $v) {
+ $vis = 0;
+ if (isset($k[0]) && $k[0] === "\x00") {
+ $vis = $k[1] === '*' ? 1 : 2;
+ $k = substr($k, strrpos($k, "\x00") + 1);
+ }
+ $hide = is_string($k) && isset($this->keysToHide[strtolower($k)]);
+ $obj['items'][] = [$this->encodeKey($k), $hide ? ['type' => self::hideValue($v)] : $this->toJson($v, $options, $level + 1), $vis];
+ }
+ }
+ return ['object' => $obj['id']];
+
+ } elseif (is_resource($var)) {
+ $obj = &$options[self::SNAPSHOT][(string) $var];
+ if (!$obj) {
+ $type = get_resource_type($var);
+ $obj = ['id' => count($options[self::SNAPSHOT]), 'name' => $type . ' resource', 'hash' => (int) $var];
+ if (isset($this->resourceDumpers[$type])) {
+ foreach (($this->resourceDumpers[$type])($var) as $k => $v) {
+ $obj['items'][] = [$k, $this->toJson($v, $options, $level + 1)];
+ }
+ }
+ }
+ return ['resource' => $obj['id']];
+
+ } else {
+ return ['type' => 'unknown type'];
+ }
+ }
+
+
+ public static function formatSnapshotAttribute(array &$snapshot): string
+ {
+ $res = [];
+ foreach ($snapshot as $obj) {
+ $id = $obj['id'];
+ unset($obj['level'], $obj['object'], $obj['id']);
+ $res[$id] = $obj;
+ }
+ $snapshot = [];
+ return "'" . json_encode($res, JSON_HEX_APOS | JSON_HEX_AMP) . "'";
+ }
+
+
+ /**
+ * @internal
+ */
+ public static function encodeString(string $s, int $maxLength = null): string
+ {
+ if ($maxLength) {
+ $s = self::truncateString($tmp = $s, $maxLength);
+ $shortened = $s !== $tmp;
+ }
+
+ if (preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $s) || preg_last_error()) { // is binary?
+ static $table;
+ if ($table === null) {
+ foreach (array_merge(range("\x00", "\x1F"), range("\x7F", "\xFF")) as $ch) {
+ $table[$ch] = '\x' . str_pad(dechex(ord($ch)), 2, '0', STR_PAD_LEFT);
+ }
+ $table['\\'] = '\\\\';
+ $table["\r"] = '\r';
+ $table["\n"] = '\n';
+ $table["\t"] = '\t';
+ }
+
+ $s = strtr($s, $table);
+ }
+
+ return $s . (empty($shortened) ? '' : ' ... ');
+ }
+
+
+ /**
+ * @internal
+ */
+ public static function truncateString(string $s, int $maxLength): string
+ {
+ if (!preg_match('##u', $s)) {
+ $s = substr($s, 0, $maxLength); // not UTF-8
+ } elseif (function_exists('mb_substr')) {
+ $s = mb_substr($s, 0, $maxLength, 'UTF-8');
+ } else {
+ $i = $len = 0;
+ while (isset($s[$i])) {
+ if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && (++$len > $maxLength)) {
+ $s = substr($s, 0, $i);
+ break;
+ }
+ $i++;
+ }
+ }
+ return $s;
+ }
+
+
+ /**
+ * @param int|string $k
+ * @return int|string
+ */
+ private function encodeKey($key)
+ {
+ return is_int($key) || preg_match('#^[!\#$%&()*+,./0-9:;<=>?@A-Z[\]^_`a-z{|}~-]{1,50}$#D', $key)
+ ? $key
+ : '"' . $this->encodeString($key, $this->maxLength) . '"';
+ }
+
+
+ /**
+ * @param object $obj
+ */
+ private function exportObject($obj): array
+ {
+ foreach ($this->objectDumpers as $type => $dumper) {
+ if (!$type || $obj instanceof $type) {
+ return $dumper($obj);
+ }
+ }
+
+ if ($this->debugInfo && method_exists($obj, '__debugInfo')) {
+ return $obj->__debugInfo();
+ }
+
+ return (array) $obj;
+ }
+
+
+ private static function exportClosure(\Closure $obj): array
+ {
+ $rc = new \ReflectionFunction($obj);
+ $res = [];
+ foreach ($rc->getParameters() as $param) {
+ $res[] = '$' . $param->getName();
+ }
+ return [
+ 'file' => $rc->getFileName(),
+ 'line' => $rc->getStartLine(),
+ 'variables' => $rc->getStaticVariables(),
+ 'parameters' => implode(', ', $res),
+ ];
+ }
+
+
+ private static function exportSplFileInfo(\SplFileInfo $obj): array
+ {
+ return ['path' => $obj->getPathname()];
+ }
+
+
+ private static function exportSplObjectStorage(\SplObjectStorage $obj): array
+ {
+ $res = [];
+ foreach (clone $obj as $item) {
+ $res[] = ['object' => $item, 'data' => $obj[$item]];
+ }
+ return $res;
+ }
+
+
+ private static function exportPhpIncompleteClass(\__PHP_Incomplete_Class $obj): array
+ {
+ $info = ['className' => null, 'private' => [], 'protected' => [], 'public' => []];
+ foreach ((array) $obj as $name => $value) {
+ if ($name === '__PHP_Incomplete_Class_Name') {
+ $info['className'] = $value;
+ } elseif (preg_match('#^\x0\*\x0(.+)$#D', $name, $m)) {
+ $info['protected'][$m[1]] = $value;
+ } elseif (preg_match('#^\x0(.+)\x0(.+)$#D', $name, $m)) {
+ $info['private'][$m[1] . '::$' . $m[2]] = $value;
+ } else {
+ $info['public'][$name] = $value;
+ }
+ }
+ return $info;
+ }
+
+
+ private static function hideValue($var): string
+ {
+ return self::HIDDEN_VALUE . ' (' . (is_object($var) ? Helpers::getClass($var) : gettype($var)) . ')';
+ }
+
+
+ /**
+ * Finds the location where dump was called. Returns [file, line, code]
+ */
+ private static function findLocation(): ?array
+ {
+ foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
+ if (isset($item['class']) && $item['class'] === __CLASS__) {
+ $location = $item;
+ continue;
+ } elseif (isset($item['function'])) {
+ try {
+ $reflection = isset($item['class'])
+ ? new \ReflectionMethod($item['class'], $item['function'])
+ : new \ReflectionFunction($item['function']);
+ if ($reflection->isInternal() || preg_match('#\s@tracySkipLocation\s#', (string) $reflection->getDocComment())) {
+ $location = $item;
+ continue;
+ }
+ } catch (\ReflectionException $e) {
+ }
+ }
+ break;
+ }
+
+ if (isset($location['file'], $location['line']) && is_file($location['file'])) {
+ $lines = file($location['file']);
+ $line = $lines[$location['line'] - 1];
+ return [
+ $location['file'],
+ $location['line'],
+ trim(preg_match('#\w*dump(er::\w+)?\(.*\)#i', $line, $m) ? $m[0] : $line),
+ ];
+ }
+ return null;
+ }
+
+
+ private static function detectColors(): bool
+ {
+ return self::$terminalColors &&
+ (getenv('ConEmuANSI') === 'ON'
+ || getenv('ANSICON') !== false
+ || getenv('term') === 'xterm-256color'
+ || (defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT)));
+ }
+}
diff --git a/lib/Tracy/Dumper/assets/dumper.css b/lib/Tracy/Dumper/assets/dumper.css
new file mode 100644
index 0000000..2d2624f
--- /dev/null
+++ b/lib/Tracy/Dumper/assets/dumper.css
@@ -0,0 +1,70 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+pre.tracy-dump {
+ text-align: left;
+ color: #444;
+ background: white;
+}
+
+pre.tracy-dump div {
+ padding-left: 3ex;
+}
+
+pre.tracy-dump div div {
+ border-left: 1px solid rgba(0, 0, 0, .1);
+ margin-left: .5ex;
+}
+
+pre.tracy-dump a {
+ color: #125EAE;
+ text-decoration: none;
+}
+
+pre.tracy-dump a:hover,
+pre.tracy-dump a:focus {
+ background-color: #125EAE;
+ color: white;
+}
+
+.tracy-dump-array,
+.tracy-dump-object {
+ color: #C22;
+}
+
+.tracy-dump-string {
+ color: #35D;
+}
+
+.tracy-dump-number {
+ color: #090;
+}
+
+.tracy-dump-null,
+.tracy-dump-bool {
+ color: #850;
+}
+
+.tracy-dump-visibility,
+.tracy-dump-hash {
+ font-size: 85%; color: #999;
+}
+
+.tracy-dump-indent {
+ display: none;
+}
+
+span[data-tracy-href] {
+ border-bottom: 1px dotted rgba(0, 0, 0, .2);
+}
+
+.tracy-dump-flash {
+ animation: tracy-dump-flash .2s ease;
+}
+
+@keyframes tracy-dump-flash {
+ 0% {
+ background: #c0c0c033;
+ }
+}
diff --git a/lib/Tracy/Dumper/assets/dumper.js b/lib/Tracy/Dumper/assets/dumper.js
new file mode 100644
index 0000000..b889a7f
--- /dev/null
+++ b/lib/Tracy/Dumper/assets/dumper.js
@@ -0,0 +1,214 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+'use strict';
+
+(function() {
+ const
+ COLLAPSE_COUNT = 7,
+ COLLAPSE_COUNT_TOP = 14;
+
+ class Dumper
+ {
+ static init(context) {
+ (context || document).querySelectorAll('[itemprop=tracy-snapshot], [data-tracy-snapshot]').forEach((el) => {
+ let preList, snapshot = JSON.parse(el.getAttribute('data-tracy-snapshot'));
+
+ if (el.tagName === 'META') { //
+ snapshot = JSON.parse(el.getAttribute('content'));
+ preList = el.parentElement.querySelectorAll('[data-tracy-dump]');
+ } else if (el.matches('[data-tracy-dump]')) { //
+ preList = [el];
+ el.removeAttribute('data-tracy-snapshot');
+ } else { //
+ el.querySelectorAll('[data-tracy-dump]').forEach((el) => {
+ el.parentNode.removeChild(el.nextSibling); // remove \n after toggler
+ el.parentNode.replaceChild( // replace toggler
+ build(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el.classList.contains('tracy-collapsed')),
+ el
+ );
+ });
+ return;
+ }
+
+ preList.forEach((el) => { //
+ let built = build(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el.classList.contains('tracy-collapsed'));
+ el.insertBefore(built, el.lastChild);
+ el.classList.remove('tracy-collapsed');
+ el.removeAttribute('data-tracy-dump');
+ });
+ });
+
+ if (Dumper.inited) {
+ return;
+ }
+ Dumper.inited = true;
+
+ // enables & ctrl key
+ document.documentElement.addEventListener('click', (e) => {
+ let el;
+ if (e.ctrlKey && (el = e.target.closest('[data-tracy-href]'))) {
+ location.href = el.getAttribute('data-tracy-href');
+ return false;
+ }
+ });
+
+ document.documentElement.addEventListener('tracy-toggle', (e) => {
+ if (e.target.matches('.tracy-dump *')) {
+ e.detail.relatedTarget.classList.toggle('tracy-dump-flash', !e.detail.collapsed);
+ }
+ });
+
+ document.documentElement.addEventListener('animationend', (e) => {
+ if (e.animationName === 'tracy-dump-flash') {
+ e.target.classList.toggle('tracy-dump-flash', false);
+ }
+ });
+
+ Tracy.Toggle.init();
+ }
+ }
+
+
+ function build(data, repository, collapsed, parentIds) {
+ let type = data === null ? 'null' : typeof data,
+ collapseCount = collapsed === null ? COLLAPSE_COUNT : COLLAPSE_COUNT_TOP;
+
+ if (type === 'null' || type === 'string' || type === 'number' || type === 'boolean') {
+ data = type === 'string' ? '"' + data + '"' : (data + '');
+ return createEl(null, null, [
+ createEl(
+ 'span',
+ {'class': 'tracy-dump-' + type.replace('ean', '')},
+ [data + '\n']
+ )
+ ]);
+
+ } else if (Array.isArray(data)) {
+ return buildStruct(
+ [
+ createEl('span', {'class': 'tracy-dump-array'}, ['array']),
+ ' (' + (data[0] && data.length || '') + ')'
+ ],
+ ' [ ... ]',
+ data[0] === null ? null : data,
+ collapsed === true || data.length >= collapseCount,
+ repository,
+ parentIds
+ );
+
+ } else if (data.stop) {
+ return createEl(null, null, [
+ createEl('span', {'class': 'tracy-dump-array'}, ['array']),
+ ' (' + data.stop[0] + ')',
+ data.stop[1] ? ' [ RECURSION ]\n' : ' [ ... ]\n',
+ ]);
+
+ } else if (data.number) {
+ return createEl(null, null, [
+ createEl('span', {'class': 'tracy-dump-number'}, [data.number + '\n'])
+ ]);
+
+ } else if (data.type) {
+ return createEl(null, null, [
+ createEl('span', null, [data.type + '\n'])
+ ]);
+
+ } else {
+ let id = data.object || data.resource,
+ object = repository[id];
+
+ if (!object) {
+ throw new UnknownEntityException;
+ }
+ parentIds = parentIds ? parentIds.slice() : [];
+ let recursive = parentIds.indexOf(id) > -1;
+ parentIds.push(id);
+
+ return buildStruct(
+ [
+ createEl('span', {
+ 'class': data.object ? 'tracy-dump-object' : 'tracy-dump-resource',
+ title: object.editor ? 'Declared in file ' + object.editor.file + ' on line ' + object.editor.line : null,
+ 'data-tracy-href': object.editor ? object.editor.url : null
+ }, [object.name]),
+ ' ',
+ createEl('span', {'class': 'tracy-dump-hash'}, ['#' + object.hash])
+ ],
+ recursive ? ' { RECURSION }' : ' { ... }',
+ recursive ? null : object.items,
+ collapsed === true || (object.items && object.items.length >= collapseCount),
+ repository,
+ parentIds
+ );
+ }
+ }
+
+
+ function buildStruct(span, ellipsis, items, collapsed, repository, parentIds) {
+ let res, toggle, div, handler;
+
+ if (!items || !items.length) {
+ span.push(!items || items.length ? ellipsis + '\n' : '\n');
+ return createEl(null, null, span);
+ }
+
+ res = createEl(null, null, [
+ toggle = createEl('span', {'class': collapsed ? 'tracy-toggle tracy-collapsed' : 'tracy-toggle'}, span),
+ '\n',
+ div = createEl('div', {'class': collapsed ? 'tracy-collapsed' : null})
+ ]);
+
+ if (collapsed) {
+ toggle.addEventListener('tracy-toggle', handler = function() {
+ toggle.removeEventListener('tracy-toggle', handler);
+ createItems(div, items, repository, parentIds);
+ });
+ } else {
+ createItems(div, items, repository, parentIds);
+ }
+ return res;
+ }
+
+
+ function createEl(el, attrs, content) {
+ if (!(el instanceof Node)) {
+ el = el ? document.createElement(el) : document.createDocumentFragment();
+ }
+ for (let id in attrs || {}) {
+ if (attrs[id] !== null) {
+ el.setAttribute(id, attrs[id]);
+ }
+ }
+ content = content || [];
+ for (let id = 0; id < content.length; id++) {
+ let child = content[id];
+ if (child !== null) {
+ el.appendChild(child instanceof Node ? child : document.createTextNode(child));
+ }
+ }
+ return el;
+ }
+
+
+ function createItems(el, items, repository, parentIds) {
+ for (let i = 0; i < items.length; i++) {
+ let vis = items[i][2];
+ createEl(el, null, [
+ createEl('span', {'class': 'tracy-dump-key'}, [items[i][0]]),
+ vis ? ' ' : null,
+ vis ? createEl('span', {'class': 'tracy-dump-visibility'}, [vis === 1 ? 'protected' : 'private']) : null,
+ ' => ',
+ build(items[i][1], repository, null, parentIds)
+ ]);
+ }
+ }
+
+
+ function UnknownEntityException() {}
+
+
+ let Tracy = window.Tracy = window.Tracy || {};
+ Tracy.Dumper = Dumper;
+})();
diff --git a/lib/Tracy/Helpers.php b/lib/Tracy/Helpers.php
new file mode 100644
index 0000000..a617527
--- /dev/null
+++ b/lib/Tracy/Helpers.php
@@ -0,0 +1,335 @@
+ strlen($m[0])) {
+ $file = '...' . $m[0];
+ }
+ $file = strtr($file, '/', DIRECTORY_SEPARATOR);
+ return self::formatHtml('%%%',
+ $editor,
+ $origFile . ($line ? ":$line" : ''),
+ rtrim(dirname($file), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
+ basename($file),
+ $line ? ":$line" : ''
+ );
+ } else {
+ return self::formatHtml('%', $file . ($line ? ":$line" : ''));
+ }
+ }
+
+
+ /**
+ * Returns link to editor.
+ */
+ public static function editorUri(string $file, int $line = null, string $action = 'open', string $search = '', string $replace = ''): ?string
+ {
+ if (Debugger::$editor && $file && ($action === 'create' || is_file($file))) {
+ $file = strtr($file, '/', DIRECTORY_SEPARATOR);
+ $file = strtr($file, Debugger::$editorMapping);
+ return strtr(Debugger::$editor, [
+ '%action' => $action,
+ '%file' => rawurlencode($file),
+ '%line' => $line ?: 1,
+ '%search' => rawurlencode($search),
+ '%replace' => rawurlencode($replace),
+ ]);
+ }
+ return null;
+ }
+
+
+ public static function formatHtml(string $mask): string
+ {
+ $args = func_get_args();
+ return preg_replace_callback('#%#', function () use (&$args, &$count): string {
+ return self::escapeHtml($args[++$count]);
+ }, $mask);
+ }
+
+
+ public static function escapeHtml($s): string
+ {
+ return htmlspecialchars((string) $s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
+ }
+
+
+ public static function findTrace(array $trace, $method, int &$index = null): ?array
+ {
+ $m = is_array($method) ? $method : explode('::', $method);
+ foreach ($trace as $i => $item) {
+ if (
+ isset($item['function'])
+ && $item['function'] === end($m)
+ && isset($item['class']) === isset($m[1])
+ && (!isset($item['class']) || $m[0] === '*' || is_a($item['class'], $m[0], true))
+ ) {
+ $index = $i;
+ return $item;
+ }
+ }
+ return null;
+ }
+
+
+ public static function getClass($obj): string
+ {
+ return explode("\x00", get_class($obj))[0];
+ }
+
+
+ /** @internal */
+ public static function fixStack(\Throwable $exception): \Throwable
+ {
+ if (function_exists('xdebug_get_function_stack')) {
+ $stack = [];
+ foreach (array_slice(array_reverse(xdebug_get_function_stack()), 2, -1) as $row) {
+ $frame = [
+ 'file' => $row['file'],
+ 'line' => $row['line'],
+ 'function' => $row['function'] ?? '*unknown*',
+ 'args' => [],
+ ];
+ if (!empty($row['class'])) {
+ $frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::';
+ $frame['class'] = $row['class'];
+ }
+ $stack[] = $frame;
+ }
+ $ref = new \ReflectionProperty('Exception', 'trace');
+ $ref->setAccessible(true);
+ $ref->setValue($exception, $stack);
+ }
+ return $exception;
+ }
+
+
+ /** @internal */
+ public static function fixEncoding(string $s): string
+ {
+ return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
+ }
+
+
+ /** @internal */
+ public static function errorTypeToString(int $type): string
+ {
+ $types = [
+ E_ERROR => 'Fatal Error',
+ E_USER_ERROR => 'User Error',
+ E_RECOVERABLE_ERROR => 'Recoverable Error',
+ E_CORE_ERROR => 'Core Error',
+ E_COMPILE_ERROR => 'Compile Error',
+ E_PARSE => 'Parse Error',
+ E_WARNING => 'Warning',
+ E_CORE_WARNING => 'Core Warning',
+ E_COMPILE_WARNING => 'Compile Warning',
+ E_USER_WARNING => 'User Warning',
+ E_NOTICE => 'Notice',
+ E_USER_NOTICE => 'User Notice',
+ E_STRICT => 'Strict standards',
+ E_DEPRECATED => 'Deprecated',
+ E_USER_DEPRECATED => 'User Deprecated',
+ ];
+ return $types[$type] ?? 'Unknown error';
+ }
+
+
+ /** @internal */
+ public static function getSource(): string
+ {
+ if (isset($_SERVER['REQUEST_URI'])) {
+ return (!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://')
+ . ($_SERVER['HTTP_HOST'] ?? '')
+ . $_SERVER['REQUEST_URI'];
+ } else {
+ return 'CLI (PID: ' . getmypid() . ')'
+ . ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv']));
+ }
+ }
+
+
+ /** @internal */
+ public static function improveException(\Throwable $e): void
+ {
+ $message = $e->getMessage();
+ if ((!$e instanceof \Error && !$e instanceof \ErrorException) || strpos($e->getMessage(), 'did you mean')) {
+ // do nothing
+ } elseif (preg_match('#^Call to undefined function (\S+\\\\)?(\w+)\(#', $message, $m)) {
+ $funcs = array_merge(get_defined_functions()['internal'], get_defined_functions()['user']);
+ $hint = self::getSuggestion($funcs, $m[1] . $m[2]) ?: self::getSuggestion($funcs, $m[2]);
+ $message = "Call to undefined function $m[2](), did you mean $hint()?";
+ $replace = ["$m[2](", "$hint("];
+
+ } elseif (preg_match('#^Call to undefined method ([\w\\\\]+)::(\w+)#', $message, $m)) {
+ $hint = self::getSuggestion(get_class_methods($m[1]) ?: [], $m[2]);
+ $message .= ", did you mean $hint()?";
+ $replace = ["$m[2](", "$hint("];
+
+ } elseif (preg_match('#^Undefined variable: (\w+)#', $message, $m) && !empty($e->context)) {
+ $hint = self::getSuggestion(array_keys($e->context), $m[1]);
+ $message = "Undefined variable $$m[1], did you mean $$hint?";
+ $replace = ["$$m[1]", "$$hint"];
+
+ } elseif (preg_match('#^Undefined property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
+ $rc = new \ReflectionClass($m[1]);
+ $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
+ $hint = self::getSuggestion($items, $m[2]);
+ $message .= ", did you mean $$hint?";
+ $replace = ["->$m[2]", "->$hint"];
+
+ } elseif (preg_match('#^Access to undeclared static property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
+ $rc = new \ReflectionClass($m[1]);
+ $items = array_intersect($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
+ $hint = self::getSuggestion($items, $m[2]);
+ $message .= ", did you mean $$hint?";
+ $replace = ["::$$m[2]", "::$$hint"];
+ }
+
+ if (isset($hint)) {
+ $ref = new \ReflectionProperty($e, 'message');
+ $ref->setAccessible(true);
+ $ref->setValue($e, $message);
+ $e->tracyAction = [
+ 'link' => self::editorUri($e->getFile(), $e->getLine(), 'fix', $replace[0], $replace[1]),
+ 'label' => 'fix it',
+ ];
+ }
+ }
+
+
+ /** @internal */
+ public static function improveError(string $message, array $context = []): string
+ {
+ if (preg_match('#^Undefined variable: (\w+)#', $message, $m) && $context) {
+ $hint = self::getSuggestion(array_keys($context), $m[1]);
+ return $hint ? "Undefined variable $$m[1], did you mean $$hint?" : $message;
+
+ } elseif (preg_match('#^Undefined property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
+ $rc = new \ReflectionClass($m[1]);
+ $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
+ $hint = self::getSuggestion($items, $m[2]);
+ return $hint ? $message . ", did you mean $$hint?" : $message;
+ }
+ return $message;
+ }
+
+
+ /** @internal */
+ public static function guessClassFile(string $class): ?string
+ {
+ $segments = explode(DIRECTORY_SEPARATOR, $class);
+ $res = null;
+ $max = 0;
+ foreach (get_declared_classes() as $class) {
+ $parts = explode(DIRECTORY_SEPARATOR, $class);
+ foreach ($parts as $i => $part) {
+ if ($part !== $segments[$i] ?? null) {
+ break;
+ }
+ }
+ if ($i > $max && ($file = (new \ReflectionClass($class))->getFileName())) {
+ $max = $i;
+ $res = array_merge(array_slice(explode(DIRECTORY_SEPARATOR, $file), 0, $i - count($parts)), array_slice($segments, $i));
+ $res = implode(DIRECTORY_SEPARATOR, $res) . '.php';
+ }
+ }
+ return $res;
+ }
+
+
+ /**
+ * Finds the best suggestion.
+ * @internal
+ */
+ public static function getSuggestion(array $items, string $value): ?string
+ {
+ $best = null;
+ $min = (strlen($value) / 4 + 1) * 10 + .1;
+ foreach (array_unique($items, SORT_REGULAR) as $item) {
+ $item = is_object($item) ? $item->getName() : $item;
+ if (($len = levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
+ $min = $len;
+ $best = $item;
+ }
+ }
+ return $best;
+ }
+
+
+ /** @internal */
+ public static function isHtmlMode(): bool
+ {
+ return empty($_SERVER['HTTP_X_REQUESTED_WITH']) && empty($_SERVER['HTTP_X_TRACY_AJAX'])
+ && PHP_SAPI !== 'cli'
+ && !preg_match('#^Content-Type: (?!text/html)#im', implode("\n", headers_list()));
+ }
+
+
+ /** @internal */
+ public static function isAjax(): bool
+ {
+ return isset($_SERVER['HTTP_X_TRACY_AJAX']) && preg_match('#^\w{10,15}$#D', $_SERVER['HTTP_X_TRACY_AJAX']);
+ }
+
+
+ /** @internal */
+ public static function getNonce(): ?string
+ {
+ return preg_match('#^Content-Security-Policy(?:-Report-Only)?:.*\sscript-src\s+(?:[^;]+\s)?\'nonce-([\w+/]+=*)\'#mi', implode("\n", headers_list()), $m)
+ ? $m[1]
+ : null;
+ }
+
+
+ /**
+ * Escape a string to be used as a shell argument.
+ */
+ private static function escapeArg(string $s): string
+ {
+ if (preg_match('#^[a-z0-9._=/:-]+$#Di', $s)) {
+ return $s;
+ }
+
+ return defined('PHP_WINDOWS_VERSION_BUILD')
+ ? '"' . str_replace('"', '""', $s) . '"'
+ : escapeshellarg($s);
+ }
+
+
+ /**
+ * Captures PHP output into a string.
+ */
+ public static function capture(callable $func): string
+ {
+ ob_start(function () {});
+ try {
+ $func();
+ return ob_get_clean();
+ } catch (\Throwable $e) {
+ ob_end_clean();
+ throw $e;
+ }
+ }
+}
diff --git a/lib/Tracy/Logger/FireLogger.php b/lib/Tracy/Logger/FireLogger.php
new file mode 100644
index 0000000..bef9151
--- /dev/null
+++ b/lib/Tracy/Logger/FireLogger.php
@@ -0,0 +1,180 @@
+ []];
+
+
+ /**
+ * Sends message to FireLogger console.
+ * @param mixed $message
+ */
+ public function log($message, $level = self::DEBUG): bool
+ {
+ if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
+ return false;
+ }
+
+ $item = [
+ 'name' => 'PHP',
+ 'level' => $level,
+ 'order' => count($this->payload['logs']),
+ 'time' => str_pad(number_format((microtime(true) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
+ 'template' => '',
+ 'message' => '',
+ 'style' => 'background:#767ab6',
+ ];
+
+ $args = func_get_args();
+ if (isset($args[0]) && is_string($args[0])) {
+ $item['template'] = array_shift($args);
+ }
+
+ if (isset($args[0]) && $args[0] instanceof \Throwable) {
+ $e = array_shift($args);
+ $trace = $e->getTrace();
+ if (
+ isset($trace[0]['class'])
+ && $trace[0]['class'] === Debugger::class
+ && ($trace[0]['function'] === 'shutdownHandler' || $trace[0]['function'] === 'errorHandler')
+ ) {
+ unset($trace[0]);
+ }
+
+ $file = str_replace(dirname($e->getFile(), 3), "\xE2\x80\xA6", $e->getFile());
+ $item['template'] = ($e instanceof \ErrorException ? '' : Helpers::getClass($e) . ': ')
+ . $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine();
+ $item['pathname'] = $e->getFile();
+ $item['lineno'] = $e->getLine();
+
+ } else {
+ $trace = debug_backtrace();
+ if (
+ isset($trace[1]['class'])
+ && $trace[1]['class'] === Debugger::class
+ && ($trace[1]['function'] === 'fireLog')
+ ) {
+ unset($trace[0]);
+ }
+
+ foreach ($trace as $frame) {
+ if (isset($frame['file']) && is_file($frame['file'])) {
+ $item['pathname'] = $frame['file'];
+ $item['lineno'] = $frame['line'];
+ break;
+ }
+ }
+ }
+
+ $item['exc_info'] = ['', '', []];
+ $item['exc_frames'] = [];
+
+ foreach ($trace as $frame) {
+ $frame += ['file' => null, 'line' => null, 'class' => null, 'type' => null, 'function' => null, 'object' => null, 'args' => null];
+ $item['exc_info'][2][] = [$frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']];
+ $item['exc_frames'][] = $frame['args'];
+ }
+
+ if (isset($args[0]) && in_array($args[0], [self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL], true)) {
+ $item['level'] = array_shift($args);
+ }
+
+ $item['args'] = $args;
+
+ $this->payload['logs'][] = $this->jsonDump($item, -1);
+ foreach (str_split(base64_encode(json_encode($this->payload)), 4990) as $k => $v) {
+ header("FireLogger-de11e-$k: $v");
+ }
+ return true;
+ }
+
+
+ /**
+ * Dump implementation for JSON.
+ * @param mixed $var
+ * @return array|null|int|float|bool|string
+ */
+ private function jsonDump(&$var, int $level = 0)
+ {
+ if (is_bool($var) || $var === null || is_int($var) || is_float($var)) {
+ return $var;
+
+ } elseif (is_string($var)) {
+ return Dumper::encodeString($var, $this->maxLength);
+
+ } elseif (is_array($var)) {
+ static $marker;
+ if ($marker === null) {
+ $marker = uniqid("\x00", true);
+ }
+ if (isset($var[$marker])) {
+ return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
+
+ } elseif ($level < $this->maxDepth || !$this->maxDepth) {
+ $var[$marker] = true;
+ $res = [];
+ foreach ($var as $k => &$v) {
+ if ($k !== $marker) {
+ $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
+ }
+ }
+ unset($var[$marker]);
+ return $res;
+
+ } else {
+ return " \xE2\x80\xA6 ";
+ }
+
+ } elseif (is_object($var)) {
+ $arr = (array) $var;
+ static $list = [];
+ if (in_array($var, $list, true)) {
+ return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
+
+ } elseif ($level < $this->maxDepth || !$this->maxDepth) {
+ $list[] = $var;
+ $res = ["\x00" => '(object) ' . Helpers::getClass($var)];
+ foreach ($arr as $k => &$v) {
+ if (isset($k[0]) && $k[0] === "\x00") {
+ $k = substr($k, strrpos($k, "\x00") + 1);
+ }
+ $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
+ }
+ array_pop($list);
+ return $res;
+
+ } else {
+ return " \xE2\x80\xA6 ";
+ }
+
+ } elseif (is_resource($var)) {
+ return 'resource ' . get_resource_type($var);
+
+ } else {
+ return 'unknown type';
+ }
+ }
+}
diff --git a/lib/Tracy/Logger/ILogger.php b/lib/Tracy/Logger/ILogger.php
new file mode 100644
index 0000000..4746c69
--- /dev/null
+++ b/lib/Tracy/Logger/ILogger.php
@@ -0,0 +1,27 @@
+directory = $directory;
+ $this->email = $email;
+ $this->blueScreen = $blueScreen;
+ $this->mailer = [$this, 'defaultMailer'];
+ }
+
+
+ /**
+ * Logs message or exception to file and sends email notification.
+ * @param mixed $message
+ * @param string $level one of constant ILogger::INFO, WARNING, ERROR (sends email), EXCEPTION (sends email), CRITICAL (sends email)
+ * @return string|null logged error filename
+ */
+ public function log($message, $level = self::INFO)
+ {
+ if (!$this->directory) {
+ throw new \LogicException('Logging directory is not specified.');
+ } elseif (!is_dir($this->directory)) {
+ throw new \RuntimeException("Logging directory '$this->directory' is not found or is not directory.");
+ }
+
+ $exceptionFile = $message instanceof \Throwable
+ ? $this->getExceptionFile($message, $level)
+ : null;
+ $line = static::formatLogLine($message, $exceptionFile);
+ $file = $this->directory . '/' . strtolower($level ?: self::INFO) . '.log';
+
+ if (!@file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX)) { // @ is escalated to exception
+ throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?");
+ }
+
+ if ($exceptionFile) {
+ $this->logException($message, $exceptionFile);
+ }
+
+ if (in_array($level, [self::ERROR, self::EXCEPTION, self::CRITICAL], true)) {
+ $this->sendEmail($message);
+ }
+
+ return $exceptionFile;
+ }
+
+
+ /**
+ * @param mixed $message
+ */
+ public static function formatMessage($message): string
+ {
+ if ($message instanceof \Throwable) {
+ while ($message) {
+ $tmp[] = ($message instanceof \ErrorException
+ ? Helpers::errorTypeToString($message->getSeverity()) . ': ' . $message->getMessage()
+ : Helpers::getClass($message) . ': ' . $message->getMessage() . ($message->getCode() ? ' #' . $message->getCode() : '')
+ ) . ' in ' . $message->getFile() . ':' . $message->getLine();
+ $message = $message->getPrevious();
+ }
+ $message = implode("\ncaused by ", $tmp);
+
+ } elseif (!is_string($message)) {
+ $message = Dumper::toText($message);
+ }
+
+ return trim($message);
+ }
+
+
+ /**
+ * @param mixed $message
+ */
+ public static function formatLogLine($message, string $exceptionFile = null): string
+ {
+ return implode(' ', [
+ @date('[Y-m-d H-i-s]'), // @ timezone may not be set
+ preg_replace('#\s*\r?\n\s*#', ' ', static::formatMessage($message)),
+ ' @ ' . Helpers::getSource(),
+ $exceptionFile ? ' @@ ' . basename($exceptionFile) : null,
+ ]);
+ }
+
+
+ public function getExceptionFile(\Throwable $exception, string $level = self::EXCEPTION): string
+ {
+ while ($exception) {
+ $data[] = [
+ get_class($exception), $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine(),
+ array_map(function (array $item): array { unset($item['args']); return $item; }, $exception->getTrace()),
+ ];
+ $exception = $exception->getPrevious();
+ }
+ $hash = substr(md5(serialize($data)), 0, 10);
+ $dir = strtr($this->directory . '/', '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
+ foreach (new \DirectoryIterator($this->directory) as $file) {
+ if (strpos($file->getBasename(), $hash)) {
+ return $dir . $file;
+ }
+ }
+ return $dir . $level . '--' . @date('Y-m-d--H-i') . "--$hash.html"; // @ timezone may not be set
+ }
+
+
+ /**
+ * Logs exception to the file if file doesn't exist.
+ * @return string logged error filename
+ */
+ protected function logException(\Throwable $exception, string $file = null): string
+ {
+ $file = $file ?: $this->getExceptionFile($exception);
+ $bs = $this->blueScreen ?: new BlueScreen;
+ $bs->renderToFile($exception, $file);
+ return $file;
+ }
+
+
+ /**
+ * @param mixed $message
+ */
+ protected function sendEmail($message): void
+ {
+ $snooze = is_numeric($this->emailSnooze)
+ ? $this->emailSnooze
+ : @strtotime($this->emailSnooze) - time(); // @ timezone may not be set
+
+ if (
+ $this->email
+ && $this->mailer
+ && @filemtime($this->directory . '/email-sent') + $snooze < time() // @ file may not exist
+ && @file_put_contents($this->directory . '/email-sent', 'sent') // @ file may not be writable
+ ) {
+ ($this->mailer)($message, implode(', ', (array) $this->email));
+ }
+ }
+
+
+ /**
+ * Default mailer.
+ * @param mixed $message
+ * @internal
+ */
+ public function defaultMailer($message, string $email): void
+ {
+ $host = preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n'));
+ $parts = str_replace(
+ ["\r\n", "\n"],
+ ["\n", PHP_EOL],
+ [
+ 'headers' => implode("\n", [
+ 'From: ' . ($this->fromEmail ?: "noreply@$host"),
+ 'X-Mailer: Tracy',
+ 'Content-Type: text/plain; charset=UTF-8',
+ 'Content-Transfer-Encoding: 8bit',
+ ]) . "\n",
+ 'subject' => "PHP: An error occurred on the server $host",
+ 'body' => static::formatMessage($message) . "\n\nsource: " . Helpers::getSource(),
+ ]
+ );
+
+ mail($email, $parts['subject'], $parts['body'], $parts['headers']);
+ }
+}
diff --git a/lib/Tracy/OutputDebugger/OutputDebugger.php b/lib/Tracy/OutputDebugger/OutputDebugger.php
new file mode 100644
index 0000000..85f152b
--- /dev/null
+++ b/lib/Tracy/OutputDebugger/OutputDebugger.php
@@ -0,0 +1,80 @@
+start();
+ }
+
+
+ public function start(): void
+ {
+ foreach (get_included_files() as $file) {
+ if (fread(fopen($file, 'r'), 3) === self::BOM) {
+ $this->list[] = [$file, 1, self::BOM];
+ }
+ }
+ ob_start([$this, 'handler'], 1);
+ }
+
+
+ /** @internal */
+ public function handler(string $s, int $phase): ?string
+ {
+ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ if (isset($trace[0]['file'], $trace[0]['line'])) {
+ $stack = $trace;
+ unset($stack[0]['line'], $stack[0]['args']);
+ $i = count($this->list);
+ if ($i && $this->list[$i - 1][3] === $stack) {
+ $this->list[$i - 1][2] .= $s;
+ } else {
+ $this->list[] = [$trace[0]['file'], $trace[0]['line'], $s, $stack];
+ }
+ }
+ return $phase === PHP_OUTPUT_HANDLER_FINAL
+ ? $this->renderHtml()
+ : null;
+ }
+
+
+ private function renderHtml(): string
+ {
+ $res = '';
+ foreach ($this->list as $item) {
+ $stack = [];
+ foreach (array_slice($item[3], 1) as $t) {
+ $t += ['class' => '', 'type' => '', 'function' => ''];
+ $stack[] = "$t[class]$t[type]$t[function]()"
+ . (isset($t['file'], $t['line']) ? ' in ' . basename($t['file']) . ":$t[line]" : '');
+ }
+
+ $res .= ''
+ . Helpers::editorLink($item[0], $item[1]) . ' '
+ . str_replace(self::BOM, 'BOM', Dumper::toHtml($item[2]))
+ . " \n";
+ }
+ return $res . ' ';
+ }
+}
diff --git a/lib/Tracy/TableSort/table-sort.css b/lib/Tracy/TableSort/table-sort.css
new file mode 100644
index 0000000..e24286c
--- /dev/null
+++ b/lib/Tracy/TableSort/table-sort.css
@@ -0,0 +1,15 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+.tracy-sortable tr:first-child > * {
+ position: relative;
+}
+
+.tracy-sortable tr:first-child > *:hover:before {
+ position: absolute;
+ right: .3em;
+ content: "\21C5";
+ opacity: .4;
+ font-weight: normal;
+}
diff --git a/lib/Tracy/TableSort/table-sort.js b/lib/Tracy/TableSort/table-sort.js
new file mode 100644
index 0000000..6e2ab1f
--- /dev/null
+++ b/lib/Tracy/TableSort/table-sort.js
@@ -0,0 +1,43 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+'use strict';
+
+(function() {
+
+ // enables
+ class TableSort
+ {
+ static init() {
+ document.documentElement.addEventListener('click', (e) => {
+ if (e.target.matches('.tracy-sortable tr:first-child *')) {
+ TableSort.sort(e.target.closest('td,th'));
+ }
+ });
+
+ TableSort.init = function() {};
+ }
+
+ static sort(tcell) {
+ let tbody = tcell.closest('table').tBodies[0];
+ let preserveFirst = !tcell.closest('thead') && !tcell.parentNode.querySelectorAll('td').length;
+ let asc = !(tbody.tracyAsc === tcell.cellIndex);
+ tbody.tracyAsc = asc ? tcell.cellIndex : null;
+ let getText = (cell) => { return cell ? cell.innerText : ''; };
+
+ Array.from(tbody.children)
+ .slice(preserveFirst ? 1 : 0)
+ .sort((a, b) => {
+ return function(v1, v2) {
+ return v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2);
+ }(getText((asc ? a : b).children[tcell.cellIndex]), getText((asc ? b : a).children[tcell.cellIndex]));
+ })
+ .forEach((tr) => { tbody.appendChild(tr); });
+ }
+ }
+
+
+ let Tracy = window.Tracy = window.Tracy || {};
+ Tracy.TableSort = Tracy.TableSort || TableSort;
+})();
diff --git a/lib/Tracy/Toggle/toggle.css b/lib/Tracy/Toggle/toggle.css
new file mode 100644
index 0000000..eb985f1
--- /dev/null
+++ b/lib/Tracy/Toggle/toggle.css
@@ -0,0 +1,29 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+.tracy-collapsed {
+ display: none;
+}
+
+.tracy-toggle.tracy-collapsed {
+ display: inline;
+}
+
+.tracy-toggle {
+ cursor: pointer;
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ -khtml-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
+
+.tracy-toggle:after {
+ content: "\A0\25BC";
+ opacity: .4;
+}
+
+.tracy-toggle.tracy-collapsed:after {
+ content: "\A0\25BA";
+}
diff --git a/lib/Tracy/Toggle/toggle.js b/lib/Tracy/Toggle/toggle.js
new file mode 100644
index 0000000..a4ad6c2
--- /dev/null
+++ b/lib/Tracy/Toggle/toggle.js
@@ -0,0 +1,107 @@
+/**
+ * This file is part of the Tracy (https://tracy.nette.org)
+ */
+
+'use strict';
+
+(function() {
+
+ // enables or toggling
+ class Toggle
+ {
+ static init() {
+ document.documentElement.addEventListener('click', (e) => {
+ let el = e.target.closest('.tracy-toggle');
+ if (el && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) {
+ Toggle.toggle(el);
+ e.stopImmediatePropagation();
+ }
+ });
+ Toggle.init = function() {};
+ }
+
+
+ // changes element visibility
+ static toggle(el, show) {
+ let collapsed = el.classList.contains('tracy-collapsed'),
+ ref = el.getAttribute('data-tracy-ref') || el.getAttribute('href', 2),
+ dest = el;
+
+ if (typeof show === 'undefined') {
+ show = collapsed;
+ } else if (!show === collapsed) {
+ return;
+ }
+
+ if (!ref || ref === '#') {
+ ref = '+';
+ } else if (ref.substr(0, 1) === '#') {
+ dest = document;
+ }
+ ref = ref.match(/(\^\s*([^+\s]*)\s*)?(\+\s*(\S*)\s*)?(.*)/);
+ dest = ref[1] ? dest.parentNode : dest;
+ dest = ref[2] ? dest.closest(ref[2]) : dest;
+ dest = ref[3] ? Toggle.nextElement(dest.nextElementSibling, ref[4]) : dest;
+ dest = ref[5] ? dest.querySelector(ref[5]) : dest;
+
+ el.classList.toggle('tracy-collapsed', !show);
+ dest.classList.toggle('tracy-collapsed', !show);
+
+ el.dispatchEvent(new CustomEvent('tracy-toggle', {
+ bubbles: true,
+ detail: {relatedTarget: dest, collapsed: !show}
+ }));
+ }
+
+
+ // save & restore toggles
+ static persist(baseEl, restore) {
+ let saved = [];
+ baseEl.addEventListener('tracy-toggle', (e) => {
+ if (saved.indexOf(e.target) < 0) {
+ saved.push(e.target);
+ }
+ });
+
+ let toggles = JSON.parse(sessionStorage.getItem('tracy-toggles-' + baseEl.id));
+ if (toggles && restore !== false) {
+ toggles.forEach((item) => {
+ let el = baseEl;
+ for (let i in item.path) {
+ if (!(el = el.children[item.path[i]])) {
+ return;
+ }
+ }
+ if (el.textContent === item.text) {
+ Toggle.toggle(el, item.show);
+ }
+ });
+ }
+
+ window.addEventListener('unload', () => {
+ toggles = saved.map((el) => {
+ let item = {path: [], text: el.textContent, show: !el.classList.contains('tracy-collapsed')};
+ do {
+ item.path.unshift(Array.from(el.parentNode.children).indexOf(el));
+ el = el.parentNode;
+ } while (el && el !== baseEl);
+ return item;
+ });
+ sessionStorage.setItem('tracy-toggles-' + baseEl.id, JSON.stringify(toggles));
+ });
+ }
+
+
+ // finds next matching element
+ static nextElement(el, selector) {
+ while (el && selector && !el.matches(selector)) {
+ el = el.nextElementSibling;
+ }
+ return el;
+ }
+ }
+
+
+ let Tracy = window.Tracy = window.Tracy || {};
+ Tracy.Toggle = Tracy.Toggle || Toggle;
+})();
diff --git a/lib/Tracy/shortcuts.php b/lib/Tracy/shortcuts.php
new file mode 100644
index 0000000..f110f22
--- /dev/null
+++ b/lib/Tracy/shortcuts.php
@@ -0,0 +1,46 @@
+file = $backtrace[1]['file'];
+ $this->line = $backtrace[1]['line'];
+ // TODO - kompletovat metodu
+ }
+}
\ No newline at end of file
diff --git a/lib/severak/database/query.php b/lib/severak/database/query.php
new file mode 100644
index 0000000..a7e07c2
--- /dev/null
+++ b/lib/severak/database/query.php
@@ -0,0 +1,64 @@
+sql = $sql;
+ $this->params = $params;
+ }
+
+ public function add($other, $params=[])
+ {
+ if (is_string($other)) {
+ if (count($params) != substr_count($other, '?')) {
+ throw new usageException('Bad number of new query params.');
+ }
+ return new query(
+ $this->sql . ' ' . $other,
+ array_merge($this->params, $params)
+ );
+ } elseif (is_object($other) && $other instanceof query) {
+ return new query(
+ $this->sql . ' '. $other->sql,
+ array_merge($this->params, $other->params)
+ );
+ }
+ throw new usageException('Bad parameters!');
+ }
+
+ public function interpolate()
+ {
+ $pdo = new \PDO('sqlite::memory:');
+ $sql = $this->sql;
+ foreach ($this->params as $param) {
+ if (is_null($param)) {
+ $param = 'NULL';
+ } elseif (is_numeric($param)) {
+ $param = sprintf('%d', $param);
+ } elseif (is_string($param)) {
+ $param = $pdo->quote($param);
+ } else {
+ // todo: co v tomto případě?
+ }
+ $sql = preg_replace('~\?~', $param, $sql, 1);
+ }
+ $pdo = null; // let's GC destroy that
+ return $sql;
+ }
+
+ function __toString()
+ {
+ return $this->interpolate();
+ }
+}
\ No newline at end of file
diff --git a/lib/severak/database/rows.php b/lib/severak/database/rows.php
new file mode 100644
index 0000000..7f5068f
--- /dev/null
+++ b/lib/severak/database/rows.php
@@ -0,0 +1,241 @@
+setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $this->pdo = $pdo;
+ }
+
+ public function one($table, $where=[], $order=[])
+ {
+ $Q = $this->fragment('SELECT '.$this->_what($table).' FROM ' . $table);
+ $Q = $this->_addJoins($Q, $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+ $Q = $this->_addOrder($Q, $order);
+ $Q = $this->_addLimit($Q, 1);
+ $this->_reset();
+ return $this->_execute($Q)->fetch(PDO::FETCH_ASSOC);
+ }
+
+ public function more($table, $where=[], $order=[], $limit=30)
+ {
+ $Q = $this->fragment('SELECT '.$this->_what($table).' FROM ' . $table);
+ $Q = $this->_addJoins($Q, $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+ $Q = $this->_addOrder($Q, $order);
+ $Q = $this->_addLimit($Q, $limit);
+ $this->_reset();
+ return $this->_execute($Q)->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ public function count($table, $where=[])
+ {
+ $Q = $this->fragment('SELECT count(*) FROM ' . $table);
+ $Q = $this->_addJoins($Q, $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+ $this->_reset();
+ return (int) $this->_execute($Q)->fetchColumn();
+ }
+
+ public function page($table, $where=[], $order=[], $page=1, $perPage=30)
+ {
+ $Q = $this->fragment('SELECT count(*) FROM ' . $table);
+ $Q = $this->_addJoins($Q, $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+ $count = $this->_execute($Q)->fetchColumn();
+
+ $Q = $this->fragment('SELECT '.$this->_what($table).' FROM ' . $table);
+ $Q = $this->_addJoins($Q, $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+ $Q = $this->_addOrder($Q, $order);
+ $Q = $this->_addLimit($Q, $perPage);
+ $Q = $this->_addOffset($Q, $perPage * ($page-1));
+
+ $this->_reset();
+ $this->pages = ceil($count/$perPage);
+ return $this->_execute($Q)->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ public function with($table, $from='id', $to='id', $where=[])
+ {
+ $this->_with[] = ['table'=>$table, 'from'=>$from, 'to'=>$to, 'where'=>$where, 'inner'=>true];
+ return $this;
+ }
+
+ public function insert($table, $data)
+ {
+ if (!empty($this->_with)) throw new usageException('Method rows::insert doesn\'t work with JOINs.');
+ $questions = array_fill(0, count($data), '?');
+ $Q = $this->fragment('INSERT INTO ' . $table . '(' . implode(',', array_keys($data)) . ') VALUES (' . implode(',', $questions) . ')', array_values($data));
+ $this->_execute($Q);
+ $this->_reset();
+ return $this->pdo->lastInsertId();
+ }
+
+ public function update($table, $data, $where)
+ {
+ if (!empty($this->_with)) throw new usageException('Method rows::update doesn\'t work with JOINs.');
+ if (empty($where)) throw new usageException('Method rows::update with empty WHERE is insecure.');
+
+ $Q = $this->fragment('UPDATE ' . $table . ' SET');
+ $and = '';
+ foreach ($data as $k=>$v) {
+ $Q = $Q->add($and . $k.'=?', [$v]);
+ $and = ', ';
+ }
+ $Q = $this->_addWhere($Q, $where, $table);
+
+ $this->_reset();
+
+ return $this->_execute($Q)->rowCount();
+ }
+
+ public function delete($table, $where)
+ {
+ if (!empty($this->_with)) throw new usageException('Method rows::delete doesn\'t work with JOINs.');
+ if (empty($where)) throw new usageException('Method rows::delete with empty WHERE is insecure.');
+
+ $Q = $this->fragment('DELETE FROM ' . $table);
+ $Q = $this->_addWhere($Q, $where, $table);
+
+ $this->_reset();
+
+ return $this->_execute($Q)->rowCount();
+ }
+
+ public function fragment($sql, $params=[])
+ {
+ return new query($sql, $params);
+ }
+
+ public function query($sql, $params)
+ {
+ if (func_num_args()>1 && !is_array($params)) {
+ $args = func_get_args();
+ array_shift($args);
+ $params = $args;
+ }
+ return new query($sql, $params);
+ }
+
+ protected function _addJoins(query $Q, $table)
+ {
+ if (empty($this->_with)) {
+ return $Q;
+ }
+
+ foreach ($this->_with as $with) {
+ $Q = $Q->add('INNER JOIN ' . $with['table'] . ' ON ' . $table . '.' . $with['from'] . '=' . $with['table'] . '.' . $with['to']);
+ if (!empty($with['where'])) {
+ $Q = $Q->add('AND')->add($this->_where($with['where'], $with['table']));
+ }
+ }
+ return $Q;
+ }
+
+ protected function _what($table) {
+ if (empty($this->_with)) {
+ return '*';
+ }
+ $joined = [];
+ foreach ($this->_with as $with) {
+ $joined[] = $with['table'] . '.*';
+ }
+ return implode(', ', $joined) . ', ' . $table . '.*';
+
+ }
+
+ protected function _addWhere(query $Q, $where, $table)
+ {
+ if (empty($where)) {
+ return $Q;
+ }
+ return $Q->add('WHERE')->add($this->_where($where, $table));
+ }
+
+ protected function _where($where, $table)
+ {
+ if (is_numeric($where)) {
+ return $this->fragment($table.'.id=?', [$where]);
+ }
+ if (is_object($where) and $where instanceof query) {
+ return $where;
+ }
+
+ $Q = $this->fragment('');
+ $and = '';
+ foreach ($where as $k=>$v) {
+ if (is_object($v) and $v instanceof query) {
+ $Q = $Q->add($and)->add($v);
+ } elseif (is_array($v)) {
+ $questions = array_fill(0, count($v), '?');
+ $Q = $Q->add($and . $table.'.'.$k.' IN (' . implode(', ', $questions) . ')', $v);
+ } elseif (is_null($v)) {
+ $Q = $Q->add($and . $table.'.'.$k . ' IS NULL');
+ } else {
+ $Q = $Q->add($and . $table.'.'.$k . '=?', [$v]);
+ }
+ $and = 'AND ';
+ }
+ return $Q;
+ }
+
+ protected function _addOrder($Q, $order)
+ {
+ if (empty($order)) {
+ return $Q;
+ }
+ $Q = $Q->add('ORDER BY');
+ $and = '';
+ foreach ($order as $k=>$v) {
+ $Q = $Q->add($and . $k . ' ' . (strtoupper($v)=='ASC' ? 'ASC' : 'DESC'));
+ $and = ', ';
+ }
+ return $Q;
+ }
+
+ protected function _addLimit($Q, $limit)
+ {
+ return $Q->add('LIMIT ' . sprintf('%d', $limit));
+ }
+
+ protected function _addOffset($Q, $offset)
+ {
+ return $Q->add('OFFSET ' . sprintf('%d', $offset));
+ }
+
+ protected function _execute(query $Q)
+ {
+ return $this->execute($Q);
+ }
+
+ public function execute(query $Q)
+ {
+ $this->log[] = $Q;
+
+ $stmt = $this->pdo->prepare($Q->sql);
+ $stmt->execute($Q->params);
+
+ return $stmt;
+ }
+
+ protected function _reset()
+ {
+ $this->_with = [];
+ $this->pages = -1;
+ }
+}
\ No newline at end of file
diff --git a/lib/severak/database/usageException.php b/lib/severak/database/usageException.php
new file mode 100644
index 0000000..5258341
--- /dev/null
+++ b/lib/severak/database/usageException.php
@@ -0,0 +1,6 @@
+ 'Field is required.'
+ ];
+
+ public function __construct($attr=[])
+ {
+ if (empty($attr['id'])) $attr['id'] = 'form';
+
+ $this->attr = $attr;
+ }
+
+ public function field($name, $attr=[])
+ {
+ if (isset($this->fields[$name])) {
+ throw new usageException('Field "'.$name.'" already defined.');
+ }
+ $attr['name'] = $name;
+
+ // sensible defaults:
+ if (empty($attr['type'])) $attr['type'] = 'text';
+ if (empty($attr['label'])) $attr['label'] = ucfirst($name);
+
+ if ($attr['type']=='submit') $attr['value'] = $attr['label'];
+
+ if ($attr['type']=='checkbox' && empty($attr['value'])) $attr['value'] = 1;
+ if ($attr['type']=='select' && empty($attr['options'])) $attr['options'] = [];
+
+ // automatic element ID:
+ if (empty($attr['id'])) $attr['id'] = $this->attr['id'] . '_' . $name;
+ // ---
+ $this->fields[$name] = $attr;
+
+ if ($attr['type']=='file') $this->attr['enctype'] = 'multipart/form-data'; // enable upload
+
+ // implicit rule's
+ if (!empty($attr['required'])) $this->rule($name, 'severak\forms\rules::required', $this->messages['required']);
+ // todo: numeric, email etc...
+ }
+
+ public function rule($name, $callback, $message)
+ {
+ $this->_rules[$name][] = ['check'=>$callback, 'message'=>$message];
+ }
+
+ public function fill($data)
+ {
+ // prefill checkboxes:
+ foreach ($this->fields as $key=>$val) {
+ if ($val['type']=='checkbox') {
+ $this->values[$key] = 0;
+ }
+ }
+ // fill data:
+ foreach ($data as $key=>$val) {
+ if (!empty($this->fields[$key])) {
+ $this->values[$key] = $val;
+ }
+ }
+
+ return $this->values;
+ }
+
+ public function error($name, $message)
+ {
+ $this->errors[$name] = $message;
+ $this->isValid = false;
+ }
+
+ public function validate()
+ {
+ foreach ($this->_rules as $name => $rules) {
+ $fieldValue = isset($this->values[$name]) ? $this->values[$name] : '';
+
+ foreach ($rules as $rule) {
+ $passed = call_user_func_array($rule['check'], [$fieldValue, $this->values]);
+ if (empty($passed)) {
+ $this->error($name, $rule['message']);
+ break;
+ }
+ }
+ }
+ return $this->isValid;
+ }
+
+ function __toString()
+ {
+ return (string) new html($this);
+ }
+
+}
\ No newline at end of file
diff --git a/lib/severak/forms/html.php b/lib/severak/forms/html.php
new file mode 100644
index 0000000..1d31ca9
--- /dev/null
+++ b/lib/severak/forms/html.php
@@ -0,0 +1,141 @@
+_form = $form;
+ $this->fields = array_keys($form->fields);
+ }
+
+ protected function _text($value)
+ {
+ return htmlspecialchars($value);
+ }
+
+ protected function _attr($attr=[])
+ {
+ $out = ' ';
+ foreach ($attr as $key=>$val) {
+ if (is_array($val)) continue; // skip options etc
+
+ if ($val===true) {
+ $out .= $key . ' ';
+ } else {
+ $out .= $key . '="' . htmlspecialchars($val, ENT_QUOTES). '" ';
+ }
+ }
+ return $out;
+ }
+
+ function open($attr=[])
+ {
+ $attr = $attr + $this->_form->attr;
+ return '';
+ }
+
+
+ function all()
+ {
+ $form = $this->_form;
+
+ $out = $this->open();
+ foreach ($this->fields as $fieldName) {
+ $out .= $this->label($fieldName);
+ $out .= $this->field($fieldName);
+
+ if (!empty($form->errors[$fieldName])) {
+ // todo: nechceme spíš pole chyb?
+ $out .= '' . $this->_text($form->errors[$fieldName]) . ' ';
+ }
+ }
+ $out .= $this->close();
+
+ return $out;
+ }
+
+ function __toString()
+ {
+ return $this->all();
+ }
+
+}
\ No newline at end of file
diff --git a/lib/severak/forms/rules.php b/lib/severak/forms/rules.php
new file mode 100644
index 0000000..de7f764
--- /dev/null
+++ b/lib/severak/forms/rules.php
@@ -0,0 +1,10 @@
+2, 'Wrong number of arguments to function on.');
+ if (type(elem)=='String') elem = gebi(elem);
+ if (arguments.length==4) {
+ var selector = fun;
+ var context = elem;
+ addEvent(context || document, eventName, function(e) {
+ var found, el = e.target || e.srcElement;
+ while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
+ if (found) fun2.call(el, e);
+ });
+ } else {
+ addEvent(elem, eventName, fun);
+ }
+}
+// sub variant with on(elem, eventName, subselector, fun)
+
+function hasClass(elem, className) {
+ if (type(elem)=='String') elem = gebi(elem);
+ return elem.classList ? elem.classList.contains(className) : new RegExp('\\b'+ className+'\\b').test(elem.className);
+}
+
+function addClass(elem, className) {
+ if (type(elem)=='String') elem = gebi(elem);
+ if (elem.classList) elem.classList.add(className);
+ else if (!hasClass(elem, className)) elem.className += ' ' + className;
+}
+
+function delClass(elem, className) {
+ if (type(elem)=='String') elem = gebi(elem);
+ if (elem.classList) elem.classList.remove(className);
+ else elem.className = elem.className.replace(new RegExp('\\b'+ className+'\\b', 'g'), '');
+}
+
+// jQuery-like DOM ready
+function whenReady(fun) {
+ // in case the document is already rendered
+ if (document.readyState!='loading') fun();
+ // modern browsers
+ else if (document.addEventListener) document.addEventListener('DOMContentLoaded', fun);
+ // IE <= 8
+ else document.attachEvent('onreadystatechange', function(){
+ if (document.readyState=='complete') fun();
+ });
+}
\ No newline at end of file
diff --git a/tpl/404.html b/tpl/404.html
new file mode 100644
index 0000000..ad53f0e
--- /dev/null
+++ b/tpl/404.html
@@ -0,0 +1,41 @@
+
+
+
+
+
+ Stránka nenalezena - Stela
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tpl/500.html b/tpl/500.html
new file mode 100644
index 0000000..c792876
--- /dev/null
+++ b/tpl/500.html
@@ -0,0 +1,39 @@
+
+
+
+
+
+ Neočekávaná chyba - Stela
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Nastala neočekávaná chyba.
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tpl/_footer.php b/tpl/_footer.php
new file mode 100644
index 0000000..19c5e9b
--- /dev/null
+++ b/tpl/_footer.php
@@ -0,0 +1,136 @@
+
+
+
+
+
+ 🎥 Unable to access video stream (please make sure you have a webcam enabled)
+
+
+
+
+ No QR code detected.
+ Data:
+
+ zadat QR kód ručně
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tpl/_header.php b/tpl/_header.php
new file mode 100644
index 0000000..9bbebfe
--- /dev/null
+++ b/tpl/_header.php
@@ -0,0 +1,94 @@
+
+
+
+
+
+ Stela
+
+
+
+
+
+
+
+
+
+
+
+
+ $messages) {
+ foreach ($messages as $message) {
+ echo ' ';
+ }
+ unset($_SESSION['flashes'][$flashtype]);
+ }
+ }
+ ?>
+
\ No newline at end of file
diff --git a/tpl/_pagination.php b/tpl/_pagination.php
new file mode 100644
index 0000000..f33318a
--- /dev/null
+++ b/tpl/_pagination.php
@@ -0,0 +1,12 @@
+1) { ?>
+
+
\ No newline at end of file
diff --git a/tpl/bar.php b/tpl/bar.php
new file mode 100644
index 0000000..2b365c1
--- /dev/null
+++ b/tpl/bar.php
@@ -0,0 +1,239 @@
+=render('_header', ['title'=>$title ?? null]); ?>
+
+
+
+
+
+
+ Nákup proběhl úspěšně. Můžete zadat další.
+
+
+
+
+
+
+
+ |