diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7dc85d41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/logs/*.txt": true, + + }, + "search.exclude": { + "**/che_close": true, + "e_lib/*":true, + }, +} \ No newline at end of file diff --git a/_common.php b/_common.php index bc36bd5c..fecd45f7 100644 --- a/_common.php +++ b/_common.php @@ -7,4 +7,3 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> diff --git a/che_close/_119_b.php b/che_close/_119_b.php index 365c3a7e..ad3027d3 100644 --- a/che_close/_119_b.php +++ b/che_close/_119_b.php @@ -54,4 +54,3 @@ case "락풀기": } echo ""; -?> diff --git a/che_close/_admin1_submit.php b/che_close/_admin1_submit.php index 3f3bd5b2..c48f3ffd 100644 --- a/che_close/_admin1_submit.php +++ b/che_close/_admin1_submit.php @@ -176,5 +176,3 @@ switch($btn) { } echo ""; -?> - diff --git a/che_close/_admin2_submit.php b/che_close/_admin2_submit.php index 295d675e..c08fe206 100644 --- a/che_close/_admin2_submit.php +++ b/che_close/_admin2_submit.php @@ -428,5 +428,4 @@ switch($btn) { } echo ""; -?> diff --git a/che_close/_admin3_submit.php b/che_close/_admin3_submit.php index 60ed41b5..119d7548 100644 --- a/che_close/_admin3_submit.php +++ b/che_close/_admin3_submit.php @@ -130,5 +130,3 @@ switch($btn) { } echo ""; -?> - diff --git a/che_close/_admin4_submit.php b/che_close/_admin4_submit.php index 344f7def..bea27171 100644 --- a/che_close/_admin4_submit.php +++ b/che_close/_admin4_submit.php @@ -103,5 +103,3 @@ switch($btn) { } echo ""; -?> - diff --git a/che_close/_admin5_submit.php b/che_close/_admin5_submit.php index 3a6bcb98..6aa1ea8d 100644 --- a/che_close/_admin5_submit.php +++ b/che_close/_admin5_submit.php @@ -26,5 +26,3 @@ switch($btn) { } echo ""; -?> - diff --git a/che_close/_simul.php b/che_close/_simul.php index b993bd97..5f3b4120 100644 --- a/che_close/_simul.php +++ b/che_close/_simul.php @@ -1559,4 +1559,4 @@ function printSimul($game, $i) { "; } -?> + diff --git a/che_close/a_traffic.php b/che_close/a_traffic.php index 3731917b..1f12bb51 100644 --- a/che_close/a_traffic.php +++ b/che_close/a_traffic.php @@ -254,4 +254,3 @@ function getHexCode($hex) { case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F"; } } -?> diff --git a/che_close/a_vote.php b/che_close/a_vote.php index b6acb56c..b225b11c 100644 --- a/che_close/a_vote.php +++ b/che_close/a_vote.php @@ -335,4 +335,3 @@ function getNewColor($type) { return $color; } -?> diff --git a/che_close/analytics.php b/che_close/analytics.php index bf3f0d19..f0e83ec9 100644 --- a/che_close/analytics.php +++ b/che_close/analytics.php @@ -1,4 +1,4 @@ -"; -?> - diff --git a/che_close/c_double.php b/che_close/c_double.php index 8c99759b..d15b8ce5 100644 --- a/che_close/c_double.php +++ b/che_close/c_double.php @@ -124,5 +124,3 @@ if($command == 46) { echo ""; } -?> - diff --git a/che_close/c_msgsubmit.php b/che_close/c_msgsubmit.php index 4a0eba39..921e575d 100644 --- a/che_close/c_msgsubmit.php +++ b/che_close/c_msgsubmit.php @@ -115,5 +115,3 @@ if($genlist == 9999 && str_replace(" ", "", $msg) != "") { echo ""; -?> - diff --git a/che_close/c_myBossInfo.php b/che_close/c_myBossInfo.php index f12bee51..c4fa16a7 100644 --- a/che_close/c_myBossInfo.php +++ b/che_close/c_myBossInfo.php @@ -252,5 +252,3 @@ if($btn == "추방") { echo ""; -?> - diff --git a/che_close/c_nationrule.php b/che_close/c_nationrule.php index 9744f007..77aeb108 100644 --- a/che_close/c_nationrule.php +++ b/che_close/c_nationrule.php @@ -18,5 +18,3 @@ MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); echo ""; -?> - diff --git a/che_close/c_tournament.php b/che_close/c_tournament.php index 157dc74a..6c1fe646 100644 --- a/che_close/c_tournament.php +++ b/che_close/c_tournament.php @@ -3,6 +3,7 @@ include "lib.php"; include "func.php"; + //로그인 검사 CheckLogin(); $connect = dbConn(); diff --git a/che_close/c_troop.php b/che_close/c_troop.php index 5dbdfb79..0da27a5f 100644 --- a/che_close/c_troop.php +++ b/che_close/c_troop.php @@ -54,5 +54,3 @@ if($btn == "부 대 창 설" && $name != "" && $me[troop] == 0) { echo ""; MYDB_close($connect); -?> - diff --git a/che_close/c_vacation.php b/che_close/c_vacation.php index b4062169..4f161d1b 100644 --- a/che_close/c_vacation.php +++ b/che_close/c_vacation.php @@ -16,5 +16,3 @@ $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"" echo ""; -?> - diff --git a/che_close/config.php b/che_close/config.php index a1daf139..c60c8bb5 100644 --- a/che_close/config.php +++ b/che_close/config.php @@ -1,6 +1,6 @@ - +*/ \ No newline at end of file diff --git a/che_close/d_ally.php b/che_close/d_ally.php index 3e6b36f4..21c29d87 100644 --- a/che_close/d_ally.php +++ b/che_close/d_ally.php @@ -116,5 +116,3 @@ pushGenLog($you, $youlog); echo ""; -?> - diff --git a/che_close/d_cancel.php b/che_close/d_cancel.php index 94281351..7dd03327 100644 --- a/che_close/d_cancel.php +++ b/che_close/d_cancel.php @@ -95,5 +95,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/che_close/d_cease.php b/che_close/d_cease.php index 76c125f7..88dfd30c 100644 --- a/che_close/d_cease.php +++ b/che_close/d_cease.php @@ -100,5 +100,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/che_close/d_merge.php b/che_close/d_merge.php index d57c213e..9a202e95 100644 --- a/che_close/d_merge.php +++ b/che_close/d_merge.php @@ -134,5 +134,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/che_close/d_scout.php b/che_close/d_scout.php index 9900e98f..e427359d 100644 --- a/che_close/d_scout.php +++ b/che_close/d_scout.php @@ -159,6 +159,3 @@ pushAllLog($alllog); pushHistory($connect, $history); echo ""; - -?> - diff --git a/che_close/d_setting/_common.php b/che_close/d_setting/_common.php index 90e4756f..57949e8d 100644 --- a/che_close/d_setting/_common.php +++ b/che_close/d_setting/_common.php @@ -7,4 +7,3 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> diff --git a/che_close/d_surrender.php b/che_close/d_surrender.php index 729fe7fa..d6b37480 100644 --- a/che_close/d_surrender.php +++ b/che_close/d_surrender.php @@ -124,5 +124,4 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/che_close/data/connected.php b/che_close/data/connected.php index caaabefa..6702e873 100644 --- a/che_close/data/connected.php +++ b/che_close/data/connected.php @@ -1 +1 @@ - + - diff --git a/che_close/event_2.php b/che_close/event_2.php index 94bcc518..b104b92b 100644 --- a/che_close/event_2.php +++ b/che_close/event_2.php @@ -253,5 +253,3 @@ function RegGeneral3($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/che_close/event_3.php b/che_close/event_3.php index 48fd3d51..a613f347 100644 --- a/che_close/event_3.php +++ b/che_close/event_3.php @@ -114,5 +114,3 @@ function RegGeneral3($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/che_close/event_4.php b/che_close/event_4.php index 9d3b1c10..0b4ec99d 100644 --- a/che_close/event_4.php +++ b/che_close/event_4.php @@ -143,5 +143,3 @@ function RegGeneral4($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/che_close/func.php b/che_close/func.php index 31577742..7ef2380e 100644 --- a/che_close/func.php +++ b/che_close/func.php @@ -7416,4 +7416,3 @@ function Submit($url, $msg="", $msg2="") { "; } -?> diff --git a/che_close/func_auction.php b/che_close/func_auction.php index 9ffd729c..065d6919 100644 --- a/che_close/func_auction.php +++ b/che_close/func_auction.php @@ -345,4 +345,3 @@ function processAuction($connect) { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/che_close/func_history.php b/che_close/func_history.php index bd18360c..210eca7c 100644 --- a/che_close/func_history.php +++ b/che_close/func_history.php @@ -128,4 +128,3 @@ function LogHistory($connect, $isFirst=0) { if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish'); return true; } -?> diff --git a/che_close/func_http.php b/che_close/func_http.php index 09dd69d3..c809b579 100644 --- a/che_close/func_http.php +++ b/che_close/func_http.php @@ -285,4 +285,3 @@ class HTTP{ } } } -?> \ No newline at end of file diff --git a/che_close/func_npc.php b/che_close/func_npc.php index 9c8f7d1d..c1444023 100644 --- a/che_close/func_npc.php +++ b/che_close/func_npc.php @@ -1861,4 +1861,3 @@ function RiceBillRate($connect, $nation, $rate, $rice_rate, $type, $rice) { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/che_close/func_process.php b/che_close/func_process.php index 7c25f4ff..abcc8493 100644 --- a/che_close/func_process.php +++ b/che_close/func_process.php @@ -6145,4 +6145,3 @@ function process_99($connect, &$general) { pushGenLog($general, $log); } -?> diff --git a/che_close/func_string.php b/che_close/func_string.php index 6c8c0c27..c84011af 100644 --- a/che_close/func_string.php +++ b/che_close/func_string.php @@ -301,4 +301,3 @@ class _String { } } -?> diff --git a/che_close/install2_ok.php b/che_close/install2_ok.php index 9c83711c..1441a8a7 100644 --- a/che_close/install2_ok.php +++ b/che_close/install2_ok.php @@ -345,4 +345,3 @@ function insertCity($connect, $name, $level, $pop2, $agri2, $comm2, $secu2, $def ) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/che_close/install3_ok.php b/che_close/install3_ok.php index 3d4f74b0..4a5fd495 100644 --- a/che_close/install3_ok.php +++ b/che_close/install3_ok.php @@ -6,5 +6,5 @@ $connect=dbConn(); LogHistory($connect, 1); -echo ""; -?> +//echo ""; +echo "index.php"; //TODO:replace diff --git a/che_close/install_ok.php b/che_close/install_ok.php index 3d0326c3..9ae5d345 100644 --- a/che_close/install_ok.php +++ b/che_close/install_ok.php @@ -83,7 +83,7 @@ if(!isTable($connect, "history",$dbname)) @MYDB_query($history_schema, $connect) // 파일로 DB 정보 저장 $file=@fopen("d_setting/set.php","w") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); -@fwrite($file,"\n") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); +@fwrite($file,"
디렉토리의 퍼미션을 707로 주십시요",""); @fclose($file); @mkdir("data",0707); @chmod("data",0707); @@ -93,5 +93,4 @@ $temp=MYDB_fetch_array(MYDB_query("select count(*) from general where level = '1 MYDB_close($connect); -echo ""; -?> +echo "install2.php"; //TODO:location.replace 살려두기 diff --git a/che_close/join_post.php b/che_close/join_post.php index 52384fb3..52d6e10f 100644 --- a/che_close/join_post.php +++ b/che_close/join_post.php @@ -271,5 +271,3 @@ if($id_num) { "); echo(""); } - -?> diff --git a/che_close/join_post.php.orig b/che_close/join_post.php.orig index ed10c24b..c796b36b 100644 --- a/che_close/join_post.php.orig +++ b/che_close/join_post.php.orig @@ -272,4 +272,3 @@ if($id_num) { echo(""); } -?> diff --git a/che_close/join_token.php b/che_close/join_token.php index 87042ec3..992b5b88 100644 --- a/che_close/join_token.php +++ b/che_close/join_token.php @@ -54,5 +54,3 @@ $response['intel'] = $abil['intel']; usleep(100*1000); echo json_encode($response); - -?> \ No newline at end of file diff --git a/che_close/lib.php b/che_close/lib.php index 7166d844..f6159ad3 100644 --- a/che_close/lib.php +++ b/che_close/lib.php @@ -181,4 +181,3 @@ function PrintElapsedTime() { $_endTime = round(getMicroTime() - $_startTime, 3); echo "
경과시간 : {$_endTime}초
"; } -?> diff --git a/che_close/login_process.php b/che_close/login_process.php index 1129f3c1..a3d56c76 100644 --- a/che_close/login_process.php +++ b/che_close/login_process.php @@ -78,4 +78,3 @@ function DeleteSession() { } MYDB_close($connect); -?> diff --git a/che_close/logout_process.php b/che_close/logout_process.php index 17b57479..ba8f1379 100644 --- a/che_close/logout_process.php +++ b/che_close/logout_process.php @@ -16,7 +16,7 @@ $id = $me[user_id]; $pw = $me[password]; $conmsg = $me[conmsg]; -//Ǻ +//���Ǻ��� ���� session_destroy(); echo ""; @@ -33,4 +33,3 @@ a */ -?> diff --git a/che_close/phpinfo.php b/che_close/phpinfo.php deleted file mode 100644 index cf608608..00000000 --- a/che_close/phpinfo.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/d_setting/_common.php b/d_setting/_common.php index cea1c49d..25378505 100644 --- a/d_setting/_common.php +++ b/d_setting/_common.php @@ -7,4 +7,3 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> diff --git a/d_setting/set.php b/d_setting/set.php index f941935e..1cba5893 100644 --- a/d_setting/set.php +++ b/d_setting/set.php @@ -8,4 +8,4 @@ smtp.gmail.com aser ewrwer @gmail.com - */?> + */ diff --git a/e_lib/license.txt b/e_lib/license.txt new file mode 100644 index 00000000..36931abb --- /dev/null +++ b/e_lib/license.txt @@ -0,0 +1 @@ +TODO : adobdb5, phpmailer5(?), plates, utilphp \ No newline at end of file diff --git a/e_lib/meekrodb.2.3.class.php b/e_lib/meekrodb.2.3.class.php index e63d9669..93cba614 100644 --- a/e_lib/meekrodb.2.3.class.php +++ b/e_lib/meekrodb.2.3.class.php @@ -953,4 +953,4 @@ class MeekroDBEval { } } -?> + diff --git a/e_lib/phpmailer5/class.phpmailer.php b/e_lib/phpmailer5/class.phpmailer.php index 4589cd79..2b994574 100644 --- a/e_lib/phpmailer5/class.phpmailer.php +++ b/e_lib/phpmailer5/class.phpmailer.php @@ -2470,4 +2470,4 @@ class phpmailerException extends Exception { return $errorMsg; } } -?> + diff --git a/e_lib/phpmailer5/class.pop3.php b/e_lib/phpmailer5/class.pop3.php index 83df20f3..d15db74c 100644 --- a/e_lib/phpmailer5/class.pop3.php +++ b/e_lib/phpmailer5/class.pop3.php @@ -407,4 +407,4 @@ class POP3 { // End of class } -?> + diff --git a/e_lib/phpmailer5/class.smtp.php b/e_lib/phpmailer5/class.smtp.php index 07c27593..5254943e 100644 --- a/e_lib/phpmailer5/class.smtp.php +++ b/e_lib/phpmailer5/class.smtp.php @@ -814,4 +814,4 @@ class SMTP { } -?> + diff --git a/e_lib/src/utilphp/util.php b/e_lib/src/utilphp/util.php new file mode 100644 index 00000000..0932d7d1 --- /dev/null +++ b/e_lib/src/utilphp/util.php @@ -0,0 +1,2535 @@ + + * @link http://github.com/brandonwamboldt/utilphp/ Official Documentation + */ +class util +{ + /** + * A constant representing the number of seconds in a minute, for + * making code more verbose + * + * @var integer + */ + const SECONDS_IN_A_MINUTE = 60; + + /** + * A constant representing the number of seconds in an hour, for making + * code more verbose + * + * @var integer + */ + const SECONDS_IN_A_HOUR = 3600; + const SECONDS_IN_AN_HOUR = 3600; + + /** + * A constant representing the number of seconds in a day, for making + * code more verbose + * + * @var integer + */ + const SECONDS_IN_A_DAY = 86400; + + /** + * A constant representing the number of seconds in a week, for making + * code more verbose + * + * @var integer + */ + const SECONDS_IN_A_WEEK = 604800; + + /** + * A constant representing the number of seconds in a month (30 days), + * for making code more verbose + * + * @var integer + */ + const SECONDS_IN_A_MONTH = 2592000; + + /** + * A constant representing the number of seconds in a year (365 days), + * for making code more verbose + * + * @var integer + */ + const SECONDS_IN_A_YEAR = 31536000; + + /** + * URL constants as defined in the PHP Manual under "Constants usable with + * http_build_url()". + * + * @see http://us2.php.net/manual/en/http.constants.php#http.constants.url + */ + const HTTP_URL_REPLACE = 1; + const HTTP_URL_JOIN_PATH = 2; + const HTTP_URL_JOIN_QUERY = 4; + const HTTP_URL_STRIP_USER = 8; + const HTTP_URL_STRIP_PASS = 16; + const HTTP_URL_STRIP_AUTH = 32; + const HTTP_URL_STRIP_PORT = 64; + const HTTP_URL_STRIP_PATH = 128; + const HTTP_URL_STRIP_QUERY = 256; + const HTTP_URL_STRIP_FRAGMENT = 512; + const HTTP_URL_STRIP_ALL = 1024; + + /** + * A collapse icon, using in the dump_var function to allow collapsing + * an array or object + * + * @var string + */ + public static $icon_collapse = 'iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAMAAADXT/YiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo3MjlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFNzFDNDQyNEMyQzkxMUUxOTU4MEM4M0UxRDA0MUVGNSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFNzFDNDQyM0MyQzkxMUUxOTU4MEM4M0UxRDA0MUVGNSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo3NDlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo3MjlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PuF4AWkAAAA2UExURU9t2DBStczM/1h16DNmzHiW7iNFrypMvrnD52yJ4ezs7Onp6ejo6P///+Tk5GSG7D9h5SRGq0Q2K74AAAA/SURBVHjaLMhZDsAgDANRY3ZISnP/y1ZWeV+jAeuRSky6cKL4ryDdSggP8UC7r6GvR1YHxjazPQDmVzI/AQYAnFQDdVSJ80EAAAAASUVORK5CYII='; + + /** + * A collapse icon, using in the dump_var function to allow collapsing + * an array or object + * + * @var string + */ + public static $icon_expand = 'iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAMAAADXT/YiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2RpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo3MTlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFQzZERTJDNEMyQzkxMUUxODRCQzgyRUNDMzZEQkZFQiIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFQzZERTJDM0MyQzkxMUUxODRCQzgyRUNDMzZEQkZFQiIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IFdpbmRvd3MiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo3MzlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo3MTlFRjQ2NkM5QzJFMTExOTA0MzkwRkI0M0ZCODY4RCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkmDvWIAAABIUExURU9t2MzM/3iW7ubm59/f5urq85mZzOvr6////9ra38zMzObm5rfB8FZz5myJ4SNFrypMvjBStTNmzOvr+mSG7OXl8T9h5SRGq/OfqCEAAABKSURBVHjaFMlbEoAwCEPRULXF2jdW9r9T4czcyUdA4XWB0IgdNSybxU9amMzHzDlPKKu7Fd1e6+wY195jW0ARYZECxPq5Gn8BBgCr0gQmxpjKAwAAAABJRU5ErkJggg=='; + + private static $hasArray = false; + + /** + * Map of special non-ASCII characters and suitable ASCII replacement + * characters. + * + * Part of the URLify.php Project + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + public static $maps = array( + 'de' => array(/* German */ + 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue', 'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss', + 'ẞ' => 'SS' + ), + 'latin' => array( + 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A','Ă' => 'A', 'Æ' => 'AE', 'Ç' => + 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', + 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => + 'O', 'Ő' => 'O', 'Ø' => 'O','Ș' => 'S','Ț' => 'T', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', + 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => + 'a', 'å' => 'a', 'ă' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', + 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => + 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ș' => 's', 'ț' => 't', 'ù' => 'u', 'ú' => 'u', + 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y' + ), + 'latin_symbols' => array( + '©' => '(c)' + ), + 'el' => array(/* Greek */ + 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8', + 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p', + 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w', + 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's', + 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', + 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8', + 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P', + 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W', + 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I', + 'Ϋ' => 'Y' + ), + 'tr' => array(/* Turkish */ + 'ş' => 's', 'Ş' => 'S', 'ı' => 'i', 'İ' => 'I', 'ç' => 'c', 'Ç' => 'C', 'ü' => 'u', 'Ü' => 'U', + 'ö' => 'o', 'Ö' => 'O', 'ğ' => 'g', 'Ğ' => 'G' + ), + 'ru' => array(/* Russian */ + 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', + 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', + 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', + 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu', + 'я' => 'ya', + 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', + 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', + 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', + 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', + 'Я' => 'Ya', + '№' => '' + ), + 'uk' => array(/* Ukrainian */ + 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G', 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g' + ), + 'cs' => array(/* Czech */ + 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u', + 'ž' => 'z', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', + 'Ů' => 'U', 'Ž' => 'Z' + ), + 'pl' => array(/* Polish */ + 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', + 'ż' => 'z', 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'O', 'Ś' => 'S', + 'Ź' => 'Z', 'Ż' => 'Z' + ), + 'ro' => array(/* Romanian */ + 'ă' => 'a', 'â' => 'a', 'î' => 'i', 'ș' => 's', 'ț' => 't', 'Ţ' => 'T', 'ţ' => 't' + ), + 'lv' => array(/* Latvian */ + 'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', + 'š' => 's', 'ū' => 'u', 'ž' => 'z', 'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', + 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z' + ), + 'lt' => array(/* Lithuanian */ + 'ą' => 'a', 'č' => 'c', 'ę' => 'e', 'ė' => 'e', 'į' => 'i', 'š' => 's', 'ų' => 'u', 'ū' => 'u', 'ž' => 'z', + 'Ą' => 'A', 'Č' => 'C', 'Ę' => 'E', 'Ė' => 'E', 'Į' => 'I', 'Š' => 'S', 'Ų' => 'U', 'Ū' => 'U', 'Ž' => 'Z' + ), + 'vn' => array(/* Vietnamese */ + 'Á' => 'A', 'À' => 'A', 'Ả' => 'A', 'Ã' => 'A', 'Ạ' => 'A', 'Ă' => 'A', 'Ắ' => 'A', 'Ằ' => 'A', 'Ẳ' => 'A', 'Ẵ' => 'A', 'Ặ' => 'A', 'Â' => 'A', 'Ấ' => 'A', 'Ầ' => 'A', 'Ẩ' => 'A', 'Ẫ' => 'A', 'Ậ' => 'A', + 'á' => 'a', 'à' => 'a', 'ả' => 'a', 'ã' => 'a', 'ạ' => 'a', 'ă' => 'a', 'ắ' => 'a', 'ằ' => 'a', 'ẳ' => 'a', 'ẵ' => 'a', 'ặ' => 'a', 'â' => 'a', 'ấ' => 'a', 'ầ' => 'a', 'ẩ' => 'a', 'ẫ' => 'a', 'ậ' => 'a', + 'É' => 'E', 'È' => 'E', 'Ẻ' => 'E', 'Ẽ' => 'E', 'Ẹ' => 'E', 'Ê' => 'E', 'Ế' => 'E', 'Ề' => 'E', 'Ể' => 'E', 'Ễ' => 'E', 'Ệ' => 'E', + 'é' => 'e', 'è' => 'e', 'ẻ' => 'e', 'ẽ' => 'e', 'ẹ' => 'e', 'ê' => 'e', 'ế' => 'e', 'ề' => 'e', 'ể' => 'e', 'ễ' => 'e', 'ệ' => 'e', + 'Í' => 'I', 'Ì' => 'I', 'Ỉ' => 'I', 'Ĩ' => 'I', 'Ị' => 'I', 'í' => 'i', 'ì' => 'i', 'ỉ' => 'i', 'ĩ' => 'i', 'ị' => 'i', + 'Ó' => 'O', 'Ò' => 'O', 'Ỏ' => 'O', 'Õ' => 'O', 'Ọ' => 'O', 'Ô' => 'O', 'Ố' => 'O', 'Ồ' => 'O', 'Ổ' => 'O', 'Ỗ' => 'O', 'Ộ' => 'O', 'Ơ' => 'O', 'Ớ' => 'O', 'Ờ' => 'O', 'Ở' => 'O', 'Ỡ' => 'O', 'Ợ' => 'O', + 'ó' => 'o', 'ò' => 'o', 'ỏ' => 'o', 'õ' => 'o', 'ọ' => 'o', 'ô' => 'o', 'ố' => 'o', 'ồ' => 'o', 'ổ' => 'o', 'ỗ' => 'o', 'ộ' => 'o', 'ơ' => 'o', 'ớ' => 'o', 'ờ' => 'o', 'ở' => 'o', 'ỡ' => 'o', 'ợ' => 'o', + 'Ú' => 'U', 'Ù' => 'U', 'Ủ' => 'U', 'Ũ' => 'U', 'Ụ' => 'U', 'Ư' => 'U', 'Ứ' => 'U', 'Ừ' => 'U', 'Ử' => 'U', 'Ữ' => 'U', 'Ự' => 'U', + 'ú' => 'u', 'ù' => 'u', 'ủ' => 'u', 'ũ' => 'u', 'ụ' => 'u', 'ư' => 'u', 'ứ' => 'u', 'ừ' => 'u', 'ử' => 'u', 'ữ' => 'u', 'ự' => 'u', + 'Ý' => 'Y', 'Ỳ' => 'Y', 'Ỷ' => 'Y', 'Ỹ' => 'Y', 'Ỵ' => 'Y', 'ý' => 'y', 'ỳ' => 'y', 'ỷ' => 'y', 'ỹ' => 'y', 'ỵ' => 'y', + 'Đ' => 'D', 'đ' => 'd' + ), + 'ar' => array(/* Arabic */ + 'أ' => 'a', 'ب' => 'b', 'ت' => 't', 'ث' => 'th', 'ج' => 'g', 'ح' => 'h', 'خ' => 'kh', 'د' => 'd', + 'ذ' => 'th', 'ر' => 'r', 'ز' => 'z', 'س' => 's', 'ش' => 'sh', 'ص' => 's', 'ض' => 'd', 'ط' => 't', + 'ظ' => 'th', 'ع' => 'aa', 'غ' => 'gh', 'ف' => 'f', 'ق' => 'k', 'ك' => 'k', 'ل' => 'l', 'م' => 'm', + 'ن' => 'n', 'ه' => 'h', 'و' => 'o', 'ي' => 'y' + ), + 'sr' => array(/* Serbian */ + 'ђ' => 'dj', 'ј' => 'j', 'љ' => 'lj', 'њ' => 'nj', 'ћ' => 'c', 'џ' => 'dz', 'đ' => 'dj', + 'Ђ' => 'Dj', 'Ј' => 'j', 'Љ' => 'Lj', 'Њ' => 'Nj', 'Ћ' => 'C', 'Џ' => 'Dz', 'Đ' => 'Dj' + ), + 'az' => array(/* Azerbaijani */ + 'ç' => 'c', 'ə' => 'e', 'ğ' => 'g', 'ı' => 'i', 'ö' => 'o', 'ş' => 's', 'ü' => 'u', + 'Ç' => 'C', 'Ə' => 'E', 'Ğ' => 'G', 'İ' => 'I', 'Ö' => 'O', 'Ş' => 'S', 'Ü' => 'U' + ), + ); + + /** + * The character map for the designated language + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + private static $map = array(); + + /** + * The character list as a string. + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + private static $chars = ''; + + /** + * The character list as a regular expression. + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + private static $regex = ''; + + /** + * The current language + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + private static $language = ''; + + /** + * Initializes the character map. + * + * Part of the URLify.php Project + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + */ + private static function initLanguageMap($language = '') + { + if (count(self::$map) > 0 && (($language == '') || ($language == self::$language))) { + return; + } + + // Is a specific map associated with $language? + if (isset(self::$maps[$language]) && is_array(self::$maps[$language])) { + // Move this map to end. This means it will have priority over others + $m = self::$maps[$language]; + unset(self::$maps[$language]); + self::$maps[$language] = $m; + } + + // Reset static vars + self::$language = $language; + self::$map = array(); + self::$chars = ''; + + foreach (self::$maps as $map) { + foreach ($map as $orig => $conv) { + self::$map[$orig] = $conv; + self::$chars .= $orig; + } + } + + self::$regex = '/[' . self::$chars . ']/u'; + } + + + /** + * Access an array index, retrieving the value stored there if it + * exists or a default if it does not. This function allows you to + * concisely access an index which may or may not exist without + * raising a warning. + * + * @param array $var Array value to access + * @param mixed $default Default value to return if the key is not + * present in the array + * @return mixed + */ + public static function array_get(&$var, $default = null) + { + if (isset($var)) { + return $var; + } + + return $default; + } + + /** + * Display a variable's contents using nice HTML formatting and will + * properly display the value of booleans as true or false + * + * @see var_dump_plain() + * + * @param mixed $var The variable to dump + * @return string + */ + public static function var_dump($var, $return = false, $expandLevel = 1) + { + self::$hasArray = false; + $toggScript = 'var colToggle = function(toggID) {var img = document.getElementById(toggID);if (document.getElementById(toggID + "-collapsable").style.display == "none") {document.getElementById(toggID + "-collapsable").style.display = "inline";setImg(toggID, 0);var previousSibling = document.getElementById(toggID + "-collapsable").previousSibling;while (previousSibling != null && (previousSibling.nodeType != 1 || previousSibling.tagName.toLowerCase() != "br")) {previousSibling = previousSibling.previousSibling;}} else {document.getElementById(toggID + "-collapsable").style.display = "none";setImg(toggID, 1);var previousSibling = document.getElementById(toggID + "-collapsable").previousSibling; while (previousSibling != null && (previousSibling.nodeType != 1 || previousSibling.tagName.toLowerCase() != "br")) {previousSibling = previousSibling.previousSibling;}}};'; + $imgScript = 'var setImg = function(objID,imgID,addStyle) {var imgStore = ["data:image/png;base64,' . self::$icon_collapse . '", "data:image/png;base64,' . self::$icon_expand . '"];if (objID) {document.getElementById(objID).setAttribute("src", imgStore[imgID]);if (addStyle){document.getElementById(objID).setAttribute("style", "position:relative;left:-5px;top:-1px;cursor:pointer;");}}};'; + $jsCode = preg_replace('/ +/', ' ', ''); + $html = '
';
+        $done  = array();
+        $html .= self::var_dump_plain($var, intval($expandLevel), 0, $done);
+        $html .= '
'; + + if (self::$hasArray) { + $html = $jsCode . $html; + } + + if (!$return) { + echo $html; + } + + return $html; + } + + /** + * Display a variable's contents using nice HTML formatting (Without + * the
 tag) and will properly display the values of variables
+     * like booleans and resources. Supports collapsable arrays and objects
+     * as well.
+     *
+     * @param  mixed $var The variable to dump
+     * @return string
+     */
+    public static function var_dump_plain($var, $expLevel, $depth = 0, $done = array())
+    {
+        $html = '';
+
+        if ($expLevel > 0) {
+            $expLevel--;
+            $setImg = 0;
+            $setStyle = 'display:inline;';
+        } elseif ($expLevel == 0) {
+            $setImg = 1;
+            $setStyle='display:none;';
+        } elseif ($expLevel < 0) {
+            $setImg = 0;
+            $setStyle = 'display:inline;';
+        }
+
+        if (is_bool($var)) {
+            $html .= 'bool(' . (($var) ? 'true' : 'false') . ')';
+        } elseif (is_int($var)) {
+            $html .= 'int(' . $var . ')';
+        } elseif (is_float($var)) {
+            $html .= 'float(' . $var . ')';
+        } elseif (is_string($var)) {
+            $html .= 'string(' . strlen($var) . ') "' . self::htmlentities($var) . '"';
+        } elseif (is_null($var)) {
+            $html .= 'NULL';
+        } elseif (is_resource($var)) {
+            $html .= 'resource("' . get_resource_type($var) . '") "' . $var . '"';
+        } elseif (is_array($var)) {
+            // Check for recursion
+            if ($depth > 0) {
+                foreach ($done as $prev) {
+                    if ($prev === $var) {
+                        $html .= 'array(' . count($var) . ') *RECURSION DETECTED*';
+                        return $html;
+                    }
+                }
+
+                // Keep track of variables we have already processed to detect recursion
+                $done[] = &$var;
+            }
+
+            self::$hasArray = true;
+            $uuid = 'include-php-' . uniqid() . mt_rand(1, 1000000);
+
+            $html .= (!empty($var) ? ' ' : '') . 'array(' . count($var) . ')';
+            if (!empty($var)) {
+                $html .= ' 
[
'; + + $indent = 4; + $longest_key = 0; + + foreach ($var as $key => $value) { + if (is_string($key)) { + $longest_key = max($longest_key, strlen($key) + 2); + } else { + $longest_key = max($longest_key, strlen($key)); + } + } + + foreach ($var as $key => $value) { + if (is_numeric($key)) { + $html .= str_repeat(' ', $indent) . str_pad($key, $longest_key, ' '); + } else { + $html .= str_repeat(' ', $indent) . str_pad('"' . self::htmlentities($key) . '"', $longest_key, ' '); + } + + $html .= ' => '; + + $value = explode('
', self::var_dump_plain($value, $expLevel, $depth + 1, $done)); + + foreach ($value as $line => $val) { + if ($line != 0) { + $value[$line] = str_repeat(' ', $indent * 2) . $val; + } + } + + $html .= implode('
', $value) . '
'; + } + + $html .= ']
'; + } + } elseif (is_object($var)) { + // Check for recursion + foreach ($done as $prev) { + if ($prev === $var) { + $html .= 'object(' . get_class($var) . ') *RECURSION DETECTED*'; + return $html; + } + } + + // Keep track of variables we have already processed to detect recursion + $done[] = &$var; + + self::$hasArray=true; + $uuid = 'include-php-' . uniqid() . mt_rand(1, 1000000); + + $html .= ' object(' . get_class($var) . ')
[
'; + + $varArray = (array) $var; + + $indent = 4; + $longest_key = 0; + + foreach ($varArray as $key => $value) { + if (substr($key, 0, 2) == "\0*") { + unset($varArray[$key]); + $key = 'protected:' . substr($key, 3); + $varArray[$key] = $value; + } elseif (substr($key, 0, 1) == "\0") { + unset($varArray[$key]); + $key = 'private:' . substr($key, 1, strpos(substr($key, 1), "\0")) . ':' . substr($key, strpos(substr($key, 1), "\0") + 2); + $varArray[$key] = $value; + } + + if (is_string($key)) { + $longest_key = max($longest_key, strlen($key) + 2); + } else { + $longest_key = max($longest_key, strlen($key)); + } + } + + foreach ($varArray as $key => $value) { + if (is_numeric($key)) { + $html .= str_repeat(' ', $indent) . str_pad($key, $longest_key, ' '); + } else { + $html .= str_repeat(' ', $indent) . str_pad('"' . self::htmlentities($key) . '"', $longest_key, ' '); + } + + $html .= ' => '; + + $value = explode('
', self::var_dump_plain($value, $expLevel, $depth + 1, $done)); + + foreach ($value as $line => $val) { + if ($line != 0) { + $value[$line] = str_repeat(' ', $indent * 2) . $val; + } + } + + $html .= implode('
', $value) . '
'; + } + + $html .= ']
'; + } + + return $html; + } + + /** + * Converts any accent characters to their equivalent normal characters + * and converts any other non-alphanumeric characters to dashes, then + * converts any sequence of two or more dashes to a single dash. This + * function generates slugs safe for use as URLs, and if you pass true + * as the second parameter, it will create strings safe for use as CSS + * classes or IDs. + * + * @param string $string A string to convert to a slug + * @param string $separator The string to separate words with + * @param boolean $css_mode Whether or not to generate strings safe for + * CSS classes/IDs (Default to false) + * @return string + */ + public static function slugify($string, $separator = '-', $css_mode = false) + { + // Compatibility with 1.0.* parameter ordering for semvar + if ($separator === true || $separator === false) { + $css_mode = $separator; + $separator = '-'; + + // Raise deprecation error + trigger_error( + 'util::slugify() now takes $css_mode as the third parameter, please update your code', + E_USER_DEPRECATED + ); + } + + $slug = preg_replace('/([^a-z0-9]+)/', $separator, strtolower(self::remove_accents($string))); + + if ($css_mode) { + $digits = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'); + + if (is_numeric(substr($slug, 0, 1))) { + $slug = $digits[substr($slug, 0, 1)] . substr($slug, 1); + } + } + + return $slug; + } + + /** + * Checks to see if a string is utf8 encoded. + * + * NOTE: This function checks for 5-Byte sequences, UTF8 + * has Bytes Sequences with a maximum length of 4. + * + * Written by Tony Ferrara + * + * @param string $string The string to be checked + * @return boolean + */ + public static function seems_utf8($string) + { + if (function_exists('mb_check_encoding')) { + // If mbstring is available, this is significantly faster than + // using PHP regexps. + return mb_check_encoding($string, 'UTF-8'); + } + + // @codeCoverageIgnoreStart + return self::seemsUtf8Regex($string); + // @codeCoverageIgnoreEnd + } + + /** + * A non-Mbstring UTF-8 checker. + * + * @param $string + * @return bool + */ + protected static function seemsUtf8Regex($string) + { + // Obtained from http://stackoverflow.com/a/11709412/430062 with permission. + $regex = '/( + [\xC0-\xC1] # Invalid UTF-8 Bytes + | [\xF5-\xFF] # Invalid UTF-8 Bytes + | \xE0[\x80-\x9F] # Overlong encoding of prior code point + | \xF0[\x80-\x8F] # Overlong encoding of prior code point + | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start + | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start + | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start + | (?<=[\x0-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle + | (? + * + * @param string $brokenSerializedData + * @return string + */ + public static function fix_broken_serialization($brokenSerializedData) + { + $fixdSerializedData = preg_replace_callback('!s:(\d+):"(.*?)";!', function($matches) { + $snip = $matches[2]; + return 's:' . strlen($snip) . ':"' . $snip . '";'; + }, $brokenSerializedData); + + return $fixdSerializedData; + } + + /** + * Checks to see if the page is being server over SSL or not + * + * @return boolean + */ + public static function is_https() + { + return isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'; + } + + /** + * Add or remove query arguments to the URL. + * + * @param mixed $newKey Either newkey or an associative array + * @param mixed $newValue Either newvalue or oldquery or uri + * @param mixed $uri URI or URL to append the queru/queries to. + * @return string + */ + public static function add_query_arg($newKey, $newValue = null, $uri = null) + { + // Was an associative array of key => value pairs passed? + if (is_array($newKey)) { + $newParams = $newKey; + + // Was the URL passed as an argument? + if (!is_null($newValue)) { + $uri = $newValue; + } elseif (!is_null($uri)) { + $uri = $uri; + } else { + $uri = self::array_get($_SERVER['REQUEST_URI'], ''); + } + } else { + $newParams = array($newKey => $newValue); + + // Was the URL passed as an argument? + $uri = is_null($uri) ? self::array_get($_SERVER['REQUEST_URI'], '') : $uri; + } + + // Parse the URI into it's components + $puri = parse_url($uri); + + if (isset($puri['query'])) { + parse_str($puri['query'], $queryParams); + $queryParams = array_merge($queryParams, $newParams); + } elseif (isset($puri['path']) && strstr($puri['path'], '=') !== false) { + $puri['query'] = $puri['path']; + unset($puri['path']); + parse_str($puri['query'], $queryParams); + $queryParams = array_merge($queryParams, $newParams); + } else { + $queryParams = $newParams; + } + + // Strip out any query params that are set to false + foreach ($queryParams as $param => $value) { + if ($value === false) { + unset($queryParams[$param]); + } + } + + // Re-construct the query string + $puri['query'] = http_build_query($queryParams); + + // Re-construct the entire URL + $nuri = self::http_build_url($puri); + + // Make the URI consistent with our input + if ($nuri[0] === '/' && strstr($uri, '/') === false) { + $nuri = substr($nuri, 1); + } + + if ($nuri[0] === '?' && strstr($uri, '?') === false) { + $nuri = substr($nuri, 1); + } + + return rtrim($nuri, '?'); + } + + /** + * Removes an item or list from the query string. + * + * @param string|array $keys Query key or keys to remove. + * @param bool $uri When false uses the $_SERVER value + * @return string + */ + public static function remove_query_arg($keys, $uri = null) + { + if (is_array($keys)) { + return self::add_query_arg(array_combine($keys, array_fill(0, count($keys), null)), $uri); + } + + return self::add_query_arg(array($keys => null), $uri); + } + + /** + * Build a URL. + * + * The parts of the second URL will be merged into the first according to + * the flags argument. + * + * @author Jake Smith + * @see https://github.com/jakeasmith/http_build_url/ + * + * @param mixed $url (part(s) of) an URL in form of a string or + * associative array like parse_url() returns + * @param mixed $parts same as the first argument + * @param int $flags a bitmask of binary or'ed HTTP_URL constants; + * HTTP_URL_REPLACE is the default + * @param array $new_url if set, it will be filled with the parts of the + * composed url like parse_url() would return + * @return string + */ + public static function http_build_url($url, $parts = array(), $flags = self::HTTP_URL_REPLACE, &$new_url = array()) + { + is_array($url) || $url = parse_url($url); + is_array($parts) || $parts = parse_url($parts); + + isset($url['query']) && is_string($url['query']) || $url['query'] = null; + isset($parts['query']) && is_string($parts['query']) || $parts['query'] = null; + + $keys = array('user', 'pass', 'port', 'path', 'query', 'fragment'); + + // HTTP_URL_STRIP_ALL and HTTP_URL_STRIP_AUTH cover several other flags. + if ($flags & self::HTTP_URL_STRIP_ALL) { + $flags |= self::HTTP_URL_STRIP_USER | self::HTTP_URL_STRIP_PASS + | self::HTTP_URL_STRIP_PORT | self::HTTP_URL_STRIP_PATH + | self::HTTP_URL_STRIP_QUERY | self::HTTP_URL_STRIP_FRAGMENT; + } elseif ($flags & self::HTTP_URL_STRIP_AUTH) { + $flags |= self::HTTP_URL_STRIP_USER | self::HTTP_URL_STRIP_PASS; + } + + // Schema and host are alwasy replaced + foreach (array('scheme', 'host') as $part) { + if (isset($parts[$part])) { + $url[$part] = $parts[$part]; + } + } + + if ($flags & self::HTTP_URL_REPLACE) { + foreach ($keys as $key) { + if (isset($parts[$key])) { + $url[$key] = $parts[$key]; + } + } + } else { + if (isset($parts['path']) && ($flags & self::HTTP_URL_JOIN_PATH)) { + if (isset($url['path']) && substr($parts['path'], 0, 1) !== '/') { + $url['path'] = rtrim( + str_replace(basename($url['path']), '', $url['path']), + '/' + ) . '/' . ltrim($parts['path'], '/'); + } else { + $url['path'] = $parts['path']; + } + } + + if (isset($parts['query']) && ($flags & self::HTTP_URL_JOIN_QUERY)) { + if (isset($url['query'])) { + parse_str($url['query'], $url_query); + parse_str($parts['query'], $parts_query); + + $url['query'] = http_build_query( + array_replace_recursive( + $url_query, + $parts_query + ) + ); + } else { + $url['query'] = $parts['query']; + } + } + } + + if (isset($url['path']) && substr($url['path'], 0, 1) !== '/') { + $url['path'] = '/' . $url['path']; + } + + foreach ($keys as $key) { + $strip = 'HTTP_URL_STRIP_' . strtoupper($key); + if ($flags & constant('utilphp\\util::' . $strip)) { + unset($url[$key]); + } + } + + $parsed_string = ''; + + if (isset($url['scheme'])) { + $parsed_string .= $url['scheme'] . '://'; + } + + if (isset($url['user'])) { + $parsed_string .= $url['user']; + + if (isset($url['pass'])) { + $parsed_string .= ':' . $url['pass']; + } + + $parsed_string .= '@'; + } + + if (isset($url['host'])) { + $parsed_string .= $url['host']; + } + + if (isset($url['port'])) { + $parsed_string .= ':' . $url['port']; + } + + if (!empty($url['path'])) { + $parsed_string .= $url['path']; + } else { + $parsed_string .= '/'; + } + + if (isset($url['query'])) { + $parsed_string .= '?' . $url['query']; + } + + if (isset($url['fragment'])) { + $parsed_string .= '#' . $url['fragment']; + } + + $new_url = $url; + + return $parsed_string; + } + + /** + * Converts many english words that equate to true or false to boolean. + * + * Supports 'y', 'n', 'yes', 'no' and a few other variations. + * + * @param string $string The string to convert to boolean + * @param bool $default The value to return if we can't match any + * yes/no words + * @return boolean + */ + public static function str_to_bool($string, $default = false) + { + $yes_words = 'affirmative|all right|aye|indubitably|most assuredly|ok|of course|okay|sure thing|y|yes+|yea|yep|sure|yeah|true|t|on|1|oui|vrai'; + $no_words = 'no*|no way|nope|nah|na|never|absolutely not|by no means|negative|never ever|false|f|off|0|non|faux'; + + if (preg_match('/^(' . $yes_words . ')$/i', $string)) { + return true; + } elseif (preg_match('/^(' . $no_words . ')$/i', $string)) { + return false; + } + + return $default; + } + + /** + * Check if a string starts with the given string. + * + * @param string $string + * @param string $starts_with + * @return boolean + */ + public static function starts_with($string, $starts_with) + { + return strpos($string, $starts_with) === 0; + } + + /** + * Check if a string ends with the given string. + * + * @param string $string + * @param string $starts_with + * @return boolean + */ + public static function ends_with($string, $ends_with) + { + return substr($string, -strlen($ends_with)) === $ends_with; + } + + /** + * Check if a string contains another string. + * + * @param string $haystack + * @param string $needle + * @return boolean + */ + public static function str_contains($haystack, $needle) + { + return strpos($haystack, $needle) !== false; + } + + /** + * Check if a string contains another string. This version is case + * insensitive. + * + * @param string $haystack + * @param string $needle + * @return boolean + */ + public static function str_icontains($haystack, $needle) + { + return stripos($haystack, $needle) !== false; + } + + /** + * Return the file extension of the given filename. + * + * @param string $filename + * @return string + */ + public static function get_file_ext($filename) + { + return pathinfo($filename, PATHINFO_EXTENSION); + } + + /** + * Removes a directory (and its contents) recursively. + * + * Contributed by Askar (ARACOOL) + * + * @param string $dir The directory to be deleted recursively + * @param bool $traverseSymlinks Delete contents of symlinks recursively + * @return bool + * @throws \RuntimeException + */ + public static function rmdir($dir, $traverseSymlinks = false) + { + if (!file_exists($dir)) { + return true; + } elseif (!is_dir($dir)) { + throw new \RuntimeException('Given path is not a directory'); + } + + if (!is_link($dir) || $traverseSymlinks) { + foreach (scandir($dir) as $file) { + if ($file === '.' || $file === '..') { + continue; + } + + $currentPath = $dir . '/' . $file; + + if (is_dir($currentPath)) { + self::rmdir($currentPath, $traverseSymlinks); + } elseif (!unlink($currentPath)) { + // @codeCoverageIgnoreStart + throw new \RuntimeException('Unable to delete ' . $currentPath); + // @codeCoverageIgnoreEnd + } + } + } + + // Windows treats removing directory symlinks identically to removing directories. + if (is_link($dir) && !defined('PHP_WINDOWS_VERSION_MAJOR')) { + if (!unlink($dir)) { + // @codeCoverageIgnoreStart + throw new \RuntimeException('Unable to delete ' . $dir); + // @codeCoverageIgnoreEnd + } + } else { + if (!rmdir($dir)) { + // @codeCoverageIgnoreStart + throw new \RuntimeException('Unable to delete ' . $dir); + // @codeCoverageIgnoreEnd + } + } + + return true; + } + + /** + * Convert entities, while preserving already-encoded entities. + * + * @param string $string The text to be converted + * @return string + */ + public static function htmlentities($string, $preserve_encoded_entities = false) + { + if ($preserve_encoded_entities) { + // @codeCoverageIgnoreStart + if (defined('HHVM_VERSION')) { + $translation_table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); + } else { + $translation_table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES, self::mbInternalEncoding()); + } + // @codeCoverageIgnoreEnd + + $translation_table[chr(38)] = '&'; + return preg_replace('/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', strtr($string, $translation_table)); + } + + return htmlentities($string, ENT_QUOTES, self::mbInternalEncoding()); + } + + /** + * Convert >, <, ', " and & to html entities, but preserves entities that + * are already encoded. + * + * @param string $string The text to be converted + * @return string + */ + public static function htmlspecialchars($string, $preserve_encoded_entities = false) + { + if ($preserve_encoded_entities) { + // @codeCoverageIgnoreStart + if (defined('HHVM_VERSION')) { + $translation_table = get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES); + } else { + $translation_table = get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, self::mbInternalEncoding()); + } + // @codeCoverageIgnoreEnd + + $translation_table[chr(38)] = '&'; + + return preg_replace('/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/', '&', strtr($string, $translation_table)); + } + + return htmlentities($string, ENT_QUOTES, self::mbInternalEncoding()); + } + + /** + * Transliterates characters to their ASCII equivalents. + * + * Part of the URLify.php Project + * + * @see https://github.com/jbroadway/urlify/blob/master/URLify.php + * + * @param string $text Text that might have not-ASCII characters + * @param string $language Specifies a priority for a specific language. + * @return string Filtered string with replaced "nice" characters + */ + public static function downcode($text, $language = '') + { + self::initLanguageMap($language); + + if (self::seems_utf8($text)) { + if (preg_match_all(self::$regex, $text, $matches)) { + for ($i = 0; $i < count($matches[0]); $i++) { + $char = $matches[0][$i]; + if (isset(self::$map[$char])) { + $text = str_replace($char, self::$map[$char], $text); + } + } + } + } else { + // Not a UTF-8 string so we assume its ISO-8859-1 + $search = "\x80\x83\x8a\x8e\x9a\x9e\x9f\xa2\xa5\xb5\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd"; + $search .= "\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9"; + $search .= "\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xff"; + $text = strtr($text, $search, 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); + + // These latin characters should be represented by two characters so + // we can't use strtr + $complexSearch = array("\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe"); + $complexReplace = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); + $text = str_replace($complexSearch, $complexReplace, $text); + } + + return $text; + } + + /** + * Converts all accent characters to ASCII characters. + * + * If there are no accent characters, then the string given is just + * returned. + * + * @param string $string Text that might have accent characters + * @param string $language Specifies a priority for a specific language. + * @return string Filtered string with replaced "nice" characters + */ + public static function remove_accents($string, $language = '') + { + if (!preg_match('/[\x80-\xff]/', $string)) { + return $string; + } + + return self::downcode($string, $language); + } + + /** + * Strip all witespaces from the given string. + * + * @param string $string The string to strip + * @return string + */ + public static function strip_space($string) + { + return preg_replace('/\s+/', '', $string); + } + + /** + * Sanitize a string by performing the following operation : + * - Remove accents + * - Lower the string + * - Remove punctuation characters + * - Strip whitespaces + * + * @param string $string the string to sanitize + * @return string + */ + public static function sanitize_string($string) + { + $string = self::remove_accents($string); + $string = strtolower($string); + $string = preg_replace('/[^a-zA-Z 0-9]+/', '', $string); + $string = self::strip_space($string); + + return $string; + } + + /** + * Pads a given string with zeroes on the left. + * + * @param int $number The number to pad + * @param int $length The total length of the desired string + * @return string + */ + public static function zero_pad($number, $length) + { + return str_pad($number, $length, '0', STR_PAD_LEFT); + } + + /** + * Converts a unix timestamp to a relative time string, such as "3 days ago" + * or "2 weeks ago". + * + * @param int $from The date to use as a starting point + * @param int $to The date to compare to, defaults to now + * @param string $suffix The string to add to the end, defaults to " ago" + * @return string + */ + public static function human_time_diff($from, $to = '', $as_text = false, $suffix = ' ago') + { + if ($to == '') { + $to = time(); + } + + $from = new \DateTime(date('Y-m-d H:i:s', $from)); + $to = new \DateTime(date('Y-m-d H:i:s', $to)); + $diff = $from->diff($to); + + if ($diff->y > 1) { + $text = $diff->y . ' years'; + } elseif ($diff->y == 1) { + $text = '1 year'; + } elseif ($diff->m > 1) { + $text = $diff->m . ' months'; + } elseif ($diff->m == 1) { + $text = '1 month'; + } elseif ($diff->d > 7) { + $text = ceil($diff->d / 7) . ' weeks'; + } elseif ($diff->d == 7) { + $text = '1 week'; + } elseif ($diff->d > 1) { + $text = $diff->d . ' days'; + } elseif ($diff->d == 1) { + $text = '1 day'; + } elseif ($diff->h > 1) { + $text = $diff->h . ' hours'; + } elseif ($diff->h == 1) { + $text = ' 1 hour'; + } elseif ($diff->i > 1) { + $text = $diff->i . ' minutes'; + } elseif ($diff->i == 1) { + $text = '1 minute'; + } elseif ($diff->s > 1) { + $text = $diff->s . ' seconds'; + } else { + $text = '1 second'; + } + + if ($as_text) { + $text = explode(' ', $text, 2); + $text = self::number_to_word($text[0]) . ' ' . $text[1]; + } + + return trim($text) . $suffix; + } + + /** + * Converts a number into the text equivalent. For example, 456 becomes four + * hundred and fifty-six. + * + * Part of the IntToWords Project. + * + * @param int|float $number The number to convert into text + * @return string + */ + public static function number_to_word($number) + { + $number = (string) $number; + + if (strpos($number, '.') !== false) { + list($number, $decimal) = explode('.', $number); + } else { + $decimal = false; + } + + $output = ''; + + if ($number[0] == '-') { + $output = 'negative '; + $number = ltrim($number, '-'); + } elseif ($number[0] == '+') { + $output = 'positive '; + $number = ltrim($number, '+'); + } + + if ($number[0] == '0') { + $output .= 'zero'; + } else { + $length = 19; + $number = str_pad($number, 60, '0', STR_PAD_LEFT); + $group = rtrim(chunk_split($number, 3, ' '), ' '); + $groups = explode(' ', $group); + $groups2 = array(); + + foreach ($groups as $group) { + $group[1] = isset($group[1]) ? $group[1] : null; + $group[2] = isset($group[2]) ? $group[2] : null; + $groups2[] = self::numberToWordThreeDigits($group[0], $group[1], $group[2]); + } + + for ($z = 0; $z < count($groups2); $z++) { + if ($groups2[$z] != '') { + $output .= $groups2[$z] . self::numberToWordConvertGroup($length - $z); + $output .= ($z < $length && ! array_search('', array_slice($groups2, $z + 1, -1)) && $groups2[$length] != '' && $groups[$length][0] == '0' ? ' and ' : ', '); + } + } + + $output = rtrim($output, ', '); + } + + if ($decimal > 0) { + $output .= ' point'; + + for ($i = 0; $i < strlen($decimal); $i++) { + $output .= ' ' . self::numberToWordConvertDigit($decimal[$i]); + } + } + + return $output; + } + + protected static function numberToWordConvertGroup($index) + { + switch($index) { + case 11: + return ' decillion'; + case 10: + return ' nonillion'; + case 9: + return ' octillion'; + case 8: + return ' septillion'; + case 7: + return ' sextillion'; + case 6: + return ' quintrillion'; + case 5: + return ' quadrillion'; + case 4: + return ' trillion'; + case 3: + return ' billion'; + case 2: + return ' million'; + case 1: + return ' thousand'; + case 0: + return ''; + } + + return ''; + } + + protected static function numberToWordThreeDigits($digit1, $digit2, $digit3) + { + $output = ''; + + if ($digit1 == '0' && $digit2 == '0' && $digit3 == '0') { + return ''; + } + + if ($digit1 != '0') { + $output .= self::numberToWordConvertDigit($digit1) . ' hundred'; + + if ($digit2 != '0' || $digit3 != '0') { + $output .= ' and '; + } + } + if ($digit2 != '0') { + $output .= self::numberToWordTwoDigits($digit2, $digit3); + } elseif ($digit3 != '0') { + $output .= self::numberToWordConvertDigit($digit3); + } + + return $output; + } + + protected static function numberToWordTwoDigits($digit1, $digit2) + { + if ($digit2 == '0') { + switch ($digit1) { + case '1': + return 'ten'; + case '2': + return 'twenty'; + case '3': + return 'thirty'; + case '4': + return 'forty'; + case '5': + return 'fifty'; + case '6': + return 'sixty'; + case '7': + return 'seventy'; + case '8': + return 'eighty'; + case '9': + return 'ninety'; + } + } elseif ($digit1 == '1') { + switch ($digit2) { + case '1': + return 'eleven'; + case '2': + return 'twelve'; + case '3': + return 'thirteen'; + case '4': + return 'fourteen'; + case '5': + return 'fifteen'; + case '6': + return 'sixteen'; + case '7': + return 'seventeen'; + case '8': + return 'eighteen'; + case '9': + return 'nineteen'; + } + } else { + $second_digit = self::numberToWordConvertDigit($digit2); + + switch ($digit1) { + case '2': + return "twenty-{$second_digit}"; + case '3': + return "thirty-{$second_digit}"; + case '4': + return "forty-{$second_digit}"; + case '5': + return "fifty-{$second_digit}"; + case '6': + return "sixty-{$second_digit}"; + case '7': + return "seventy-{$second_digit}"; + case '8': + return "eighty-{$second_digit}"; + case '9': + return "ninety-{$second_digit}"; + } + } + } + + /** + * @param $digit + * @return string + * @throws \LogicException + */ + protected static function numberToWordConvertDigit($digit) + { + switch ($digit) { + case '0': + return 'zero'; + case '1': + return 'one'; + case '2': + return 'two'; + case '3': + return 'three'; + case '4': + return 'four'; + case '5': + return 'five'; + case '6': + return 'six'; + case '7': + return 'seven'; + case '8': + return 'eight'; + case '9': + return 'nine'; + default: + throw new \LogicException('Not a number'); + } + } + + /** + * Transmit UTF-8 content headers if the headers haven't already been sent. + * + * @param string $content_type The content type to send out + * @return boolean + */ + public static function utf8_headers($content_type = 'text/html') + { + // @codeCoverageIgnoreStart + if (!headers_sent()) { + header('Content-type: ' . $content_type . '; charset=utf-8'); + + return true; + } + + return false; + // @codeCoverageIgnoreEnd + } + + /** + * Transmit headers that force a browser to display the download file + * dialog. Cross browser compatible. Only fires if headers have not + * already been sent. + * + * @param string $filename The name of the filename to display to + * browsers + * @param string $content The content to output for the download. + * If you don't specify this, just the + * headers will be sent + * @return boolean + */ + public static function force_download($filename, $content = false) + { + // @codeCoverageIgnoreStart + if (!headers_sent()) { + // Required for some browsers + if (ini_get('zlib.output_compression')) { + @ini_set('zlib.output_compression', 'Off'); + } + + header('Pragma: public'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + + // Required for certain browsers + header('Cache-Control: private', false); + + header('Content-Disposition: attachment; filename="' . basename(str_replace('"', '', $filename)) . '";'); + header('Content-Type: application/force-download'); + header('Content-Transfer-Encoding: binary'); + + if ($content) { + header('Content-Length: ' . strlen($content)); + } + + ob_clean(); + flush(); + + if ($content) { + echo $content; + } + + return true; + } + + return false; + // @codeCoverageIgnoreEnd + } + + /** + * Sets the headers to prevent caching for the different browsers. + * + * Different browsers support different nocache headers, so several + * headers must be sent so that all of them get the point that no + * caching should occur + * + * @return boolean + */ + public static function nocache_headers() + { + // @codeCoverageIgnoreStart + if (!headers_sent()) { + header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + header('Cache-Control: no-cache, must-revalidate, max-age=0'); + header('Pragma: no-cache'); + + return true; + } + + return false; + // @codeCoverageIgnoreEnd + } + + /** + * Generates a string of random characters. + * + * @throws LengthException If $length is bigger than the available + * character pool and $no_duplicate_chars is + * enabled + * + * @param integer $length The length of the string to + * generate + * @param boolean $human_friendly Whether or not to make the + * string human friendly by + * removing characters that can be + * confused with other characters ( + * O and 0, l and 1, etc) + * @param boolean $include_symbols Whether or not to include + * symbols in the string. Can not + * be enabled if $human_friendly is + * true + * @param boolean $no_duplicate_chars Whether or not to only use + * characters once in the string. + * @return string + */ + public static function random_string($length = 16, $human_friendly = true, $include_symbols = false, $no_duplicate_chars = false) + { + $nice_chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefhjkmnprstuvwxyz23456789'; + $all_an = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; + $symbols = '!@#$%^&*()~_-=+{}[]|:;<>,.?/"\'\\`'; + $string = ''; + + // Determine the pool of available characters based on the given parameters + if ($human_friendly) { + $pool = $nice_chars; + } else { + $pool = $all_an; + + if ($include_symbols) { + $pool .= $symbols; + } + } + + if (!$no_duplicate_chars) { + return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); + } + + // Don't allow duplicate letters to be disabled if the length is + // longer than the available characters + if ($no_duplicate_chars && strlen($pool) < $length) { + throw new \LengthException('$length exceeds the size of the pool and $no_duplicate_chars is enabled'); + } + + // Convert the pool of characters into an array of characters and + // shuffle the array + $pool = str_split($pool); + $poolLength = count($pool); + $rand = mt_rand(0, $poolLength - 1); + + // Generate our string + for ($i = 0; $i < $length; $i++) { + $string .= $pool[$rand]; + + // Remove the character from the array to avoid duplicates + array_splice($pool, $rand, 1); + + // Generate a new number + if (($poolLength - 2 - $i) > 0) { + $rand = mt_rand(0, $poolLength - 2 - $i); + } else { + $rand = 0; + } + } + + return $string; + } + + /** + * Generate secure random string of given length + * If 'openssl_random_pseudo_bytes' is not available + * then generate random string using default function + * + * Part of the Laravel Project + * + * @param int $length length of string + * @return bool + */ + public static function secure_random_string($length = 16) + { + if (function_exists('openssl_random_pseudo_bytes')) { + $bytes = openssl_random_pseudo_bytes($length * 2); + + if ($bytes === false) { + throw new \LengthException('$length is not accurate, unable to generate random string'); + } + + return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length); + } + + // @codeCoverageIgnoreStart + return static::random_string($length); + // @codeCoverageIgnoreEnd + } + + /** + * Check if a given string matches a given pattern. + * + * Contributed by Abhimanyu Sharma + * + * @param string $pattern Parttern of string exptected + * @param string $string String that need to be matched + * @return bool + */ + public static function match_string($pattern, $string, $caseSensitive = true) + { + if ($pattern == $string) { + return true; + } + + // Preg flags + $flags = $caseSensitive ? '' : 'i'; + + // Escape any regex special characters + $pattern = preg_quote($pattern, '#'); + + // Unescape * which is our wildcard character and change it to .* + $pattern = str_replace('\*', '.*', $pattern); + + return (bool) preg_match('#^' . $pattern . '$#' . $flags, $string); + } + + /** + * Validate an email address. + * + * @param string $possible_email An email address to validate + * @return bool + */ + public static function validate_email($possible_email) + { + return (bool) filter_var($possible_email, FILTER_VALIDATE_EMAIL); + } + + /** + * Return the URL to a user's gravatar. + * + * @param string $email The email of the user + * @param integer $size The size of the gravatar + * @return string + */ + public static function get_gravatar($email, $size = 32) + { + if (self::is_https()) { + $url = 'https://secure.gravatar.com/'; + } else { + $url = 'http://www.gravatar.com/'; + } + + $url .= 'avatar/' . md5($email) . '?s=' . (int) abs($size); + + return $url; + } + + /** + * Turns all of the links in a string into HTML links. + * + * Part of the LinkifyURL Project + * + * @param string $text The string to parse + * @return string + */ + public static function linkify($text) + { + $text = preg_replace('/'/', ''', $text); // IE does not handle ' entity! + $section_html_pattern = '%# Rev:20100913_0900 github.com/jmrware/LinkifyURL + # Section text into HTML tags and everything else. + ( # $1: Everything not HTML tag. + [^<]+(?:(?!... tag. + ]*> # opening tag. + [^<]*(?:(?! # closing tag. + ) # End $2: + %ix'; + + return preg_replace_callback($section_html_pattern, array(__CLASS__, 'linkifyCallback'), $text); + } + + /** + * Callback for the preg_replace in the linkify() method. + * + * Part of the LinkifyURL Project + * + * @param array $matches Matches from the preg_ function + * @return string + */ + protected static function linkifyRegex($text) + { + $url_pattern = '/# Rev:20100913_0900 github.com\/jmrware\/LinkifyURL + # Match http & ftp URL that is not already linkified. + # Alternative 1: URL delimited by (parentheses). + (\() # $1 "(" start delimiter. + ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+) # $2: URL. + (\)) # $3: ")" end delimiter. + | # Alternative 2: URL delimited by [square brackets]. + (\[) # $4: "[" start delimiter. + ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+) # $5: URL. + (\]) # $6: "]" end delimiter. + | # Alternative 3: URL delimited by {curly braces}. + (\{) # $7: "{" start delimiter. + ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+) # $8: URL. + (\}) # $9: "}" end delimiter. + | # Alternative 4: URL delimited by . + (<|&(?:lt|\#60|\#x3c);) # $10: "<" start delimiter (or HTML entity). + ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+) # $11: URL. + (>|&(?:gt|\#62|\#x3e);) # $12: ">" end delimiter (or HTML entity). + | # Alternative 5: URL not delimited by (), [], {} or <>. + (# $13: Prefix proving URL not already linked. + (?: ^ # Can be a beginning of line or string, or + | [^=\s\'"\]] # a non-"=", non-quote, non-"]", followed by + ) \s*[\'"]? # optional whitespace and optional quote; + | [^=\s]\s+ # or... a non-equals sign followed by whitespace. + ) # End $13. Non-prelinkified-proof prefix. + (\b # $14: Other non-delimited URL. + (?:ht|f)tps?:\/\/ # Required literal http, https, ftp or ftps prefix. + [a-z0-9\-._~!$\'()*+,;=:\/?#[\]@%]+ # All URI chars except "&" (normal*). + (?: # Either on a "&" or at the end of URI. + (?! # Allow a "&" char only if not start of an... + &(?:gt|\#0*62|\#x0*3e); # HTML ">" entity, or + | &(?:amp|apos|quot|\#0*3[49]|\#x0*2[27]); # a [&\'"] entity if + [.!&\',:?;]? # followed by optional punctuation then + (?:[^a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]|$) # a non-URI char or EOS. + ) & # If neg-assertion true, match "&" (special). + [a-z0-9\-._~!$\'()*+,;=:\/?#[\]@%]* # More non-& URI chars (normal*). + )* # Unroll-the-loop (special normal*)*. + [a-z0-9\-_~$()*+=\/#[\]@%] # Last char can\'t be [.!&\',;:?] + ) # End $14. Other non-delimited URL. + /imx'; + + $url_replace = '$1$4$7$10$13$2$5$8$11$14$3$6$9$12'; + + return preg_replace($url_pattern, $url_replace, $text); + } + + /** + * Callback for the preg_replace in the linkify() method. + * + * Part of the LinkifyURL Project + * + * @param array $matches Matches from the preg_ function + * @return string + */ + protected static function linkifyCallback($matches) + { + if (isset($matches[2])) { + return $matches[2]; + } + + return self::linkifyRegex($matches[1]); + } + + /** + * Return the current URL. + * + * @return string + */ + public static function get_current_url() + { + $url = ''; + + // Check to see if it's over https + $is_https = self::is_https(); + if ($is_https) { + $url .= 'https://'; + } else { + $url .= 'http://'; + } + + // Was a username or password passed? + if (isset($_SERVER['PHP_AUTH_USER'])) { + $url .= $_SERVER['PHP_AUTH_USER']; + + if (isset($_SERVER['PHP_AUTH_PW'])) { + $url .= ':' . $_SERVER['PHP_AUTH_PW']; + } + + $url .= '@'; + } + + + // We want the user to stay on the same host they are currently on, + // but beware of security issues + // see http://shiflett.org/blog/2006/mar/server-name-versus-http-host + $url .= $_SERVER['HTTP_HOST']; + + $port = $_SERVER['SERVER_PORT']; + + // Is it on a non standard port? + if ($is_https && ($port != 443)) { + $url .= ':' . $_SERVER['SERVER_PORT']; + } elseif (!$is_https && ($port != 80)) { + $url .= ':' . $_SERVER['SERVER_PORT']; + } + + // Get the rest of the URL + if (!isset($_SERVER['REQUEST_URI'])) { + // Microsoft IIS doesn't set REQUEST_URI by default + $url .= $_SERVER['PHP_SELF']; + + if (isset($_SERVER['QUERY_STRING'])) { + $url .= '?' . $_SERVER['QUERY_STRING']; + } + } else { + $url .= $_SERVER['REQUEST_URI']; + } + + return $url; + } + + /** + * Returns the IP address of the client. + * + * @param boolean $trust_proxy_headers Whether or not to trust the + * proxy headers HTTP_CLIENT_IP + * and HTTP_X_FORWARDED_FOR. ONLY + * use if your server is behind a + * proxy that sets these values + * @return string + */ + public static function get_client_ip($trust_proxy_headers = false) + { + if (!$trust_proxy_headers) { + return $_SERVER['REMOTE_ADDR']; + } + + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + $ip = $_SERVER['REMOTE_ADDR']; + } + + return $ip; + } + + /** + * Truncate a string to a specified length without cutting a word off. + * + * @param string $string The string to truncate + * @param integer $length The length to truncate the string to + * @param string $append Text to append to the string IF it gets + * truncated, defaults to '...' + * @return string + */ + public static function safe_truncate($string, $length, $append = '...') + { + $ret = substr($string, 0, $length); + $last_space = strrpos($ret, ' '); + + if ($last_space !== false && $string != $ret) { + $ret = substr($ret, 0, $last_space); + } + + if ($ret != $string) { + $ret .= $append; + } + + return $ret; + } + + + /** + * Truncate the string to given length of charactes. + * + * @param $string + * @param $limit + * @param string $append + * @return string + */ + public static function limit_characters($string, $limit = 100, $append = '...') + { + if (mb_strlen($string) <= $limit) { + return $string; + } + + return rtrim(mb_substr($string, 0, $limit, 'UTF-8')) . $append; + } + + /** + * Truncate the string to given length of words. + * + * @param $string + * @param $limit + * @param string $append + * @return string + */ + public static function limit_words($string, $limit = 100, $append = '...') + { + preg_match('/^\s*+(?:\S++\s*+){1,' . $limit . '}/u', $string, $matches); + + if (!isset($matches[0]) || strlen($string) === strlen($matches[0])) { + return $string; + } + + return rtrim($matches[0]).$append; + } + + /** + * Returns the ordinal version of a number (appends th, st, nd, rd). + * + * @param string $number The number to append an ordinal suffix to + * @return string + */ + public static function ordinal($number) + { + $test_c = abs($number) % 10; + $ext = ((abs($number) % 100 < 21 && abs($number) % 100 > 4) ? 'th' : (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1) ? 'th' : 'st' : 'nd' : 'rd' : 'th')); + + return $number . $ext; + } + + /** + * Returns the file permissions as a nice string, like -rw-r--r-- or false + * if the file is not found. + * + * @param string $file The name of the file to get permissions form + * @param int $perms Numerical value of permissions to display as text. + * @return string + */ + public static function full_permissions($file, $perms = null) + { + if (is_null($perms)) { + if (!file_exists($file)) { + return false; + } + $perms = fileperms($file); + } + + if (($perms & 0xC000) == 0xC000) { + // Socket + $info = 's'; + } elseif (($perms & 0xA000) == 0xA000) { + // Symbolic Link + $info = 'l'; + } elseif (($perms & 0x8000) == 0x8000) { + // Regular + $info = '-'; + } elseif (($perms & 0x6000) == 0x6000) { + // Block special + $info = 'b'; + } elseif (($perms & 0x4000) == 0x4000) { + // Directory + $info = 'd'; + } elseif (($perms & 0x2000) == 0x2000) { + // Character special + $info = 'c'; + } elseif (($perms & 0x1000) == 0x1000) { + // FIFO pipe + $info = 'p'; + } else { + // Unknown + $info = 'u'; + } + + // Owner + $info .= (($perms & 0x0100) ? 'r' : '-'); + $info .= (($perms & 0x0080) ? 'w' : '-'); + $info .= (($perms & 0x0040) ? + (($perms & 0x0800) ? 's' : 'x') : + (($perms & 0x0800) ? 'S' : '-')); + + // Group + $info .= (($perms & 0x0020) ? 'r' : '-'); + $info .= (($perms & 0x0010) ? 'w' : '-'); + $info .= (($perms & 0x0008) ? + (($perms & 0x0400) ? 's' : 'x') : + (($perms & 0x0400) ? 'S' : '-')); + + // World + $info .= (($perms & 0x0004) ? 'r' : '-'); + $info .= (($perms & 0x0002) ? 'w' : '-'); + $info .= (($perms & 0x0001) ? + (($perms & 0x0200) ? 't' : 'x') : + (($perms & 0x0200) ? 'T' : '-')); + + return $info; + } + + /** + * Returns the first element in an array. + * + * @param array $array + * @return mixed + */ + public static function array_first(array $array) + { + return reset($array); + } + + /** + * Returns the last element in an array. + * + * @param array $array + * @return mixed + */ + public static function array_last(array $array) + { + return end($array); + } + + /** + * Returns the first key in an array. + * + * @param array $array + * @return int|string + */ + public static function array_first_key(array $array) + { + reset($array); + + return key($array); + } + + /** + * Returns the last key in an array. + * + * @param array $array + * @return int|string + */ + public static function array_last_key(array $array) + { + end($array); + + return key($array); + } + + /** + * Flatten a multi-dimensional array into a one dimensional array. + * + * Contributed by Theodore R. Smith of PHP Experts, Inc. + * + * @param array $array The array to flatten + * @param boolean $preserve_keys Whether or not to preserve array keys. + * Keys from deeply nested arrays will + * overwrite keys from shallowy nested arrays + * @return array + */ + public static function array_flatten(array $array, $preserve_keys = true) + { + $flattened = array(); + + array_walk_recursive($array, function($value, $key) use (&$flattened, $preserve_keys) { + if ($preserve_keys && !is_int($key)) { + $flattened[$key] = $value; + } else { + $flattened[] = $value; + } + }); + + return $flattened; + } + + /** + * Accepts an array, and returns an array of values from that array as + * specified by $field. For example, if the array is full of objects + * and you call util::array_pluck($array, 'name'), the function will + * return an array of values from $array[]->name. + * + * @param array $array An array + * @param string $field The field to get values from + * @param boolean $preserve_keys Whether or not to preserve the + * array keys + * @param boolean $remove_nomatches If the field doesn't appear to be set, + * remove it from the array + * @return array + */ + public static function array_pluck(array $array, $field, $preserve_keys = true, $remove_nomatches = true) + { + $new_list = array(); + + foreach ($array as $key => $value) { + if (is_object($value)) { + if (isset($value->{$field})) { + if ($preserve_keys) { + $new_list[$key] = $value->{$field}; + } else { + $new_list[] = $value->{$field}; + } + } elseif (!$remove_nomatches) { + $new_list[$key] = $value; + } + } else { + if (isset($value[$field])) { + if ($preserve_keys) { + $new_list[$key] = $value[$field]; + } else { + $new_list[] = $value[$field]; + } + } elseif (!$remove_nomatches) { + $new_list[$key] = $value; + } + } + } + + return $new_list; + } + + /** + * Searches for a given value in an array of arrays, objects and scalar + * values. You can optionally specify a field of the nested arrays and + * objects to search in. + * + * @param array $array The array to search + * @param scalar $search The value to search for + * @param string $field The field to search in, if not specified + * all fields will be searched + * @return boolean|scalar False on failure or the array key on success + */ + public static function array_search_deep(array $array, $search, $field = false) + { + // *grumbles* stupid PHP type system + $search = (string) $search; + + foreach ($array as $key => $elem) { + // *grumbles* stupid PHP type system + $key = (string) $key; + + if ($field) { + if (is_object($elem) && $elem->{$field} === $search) { + return $key; + } elseif (is_array($elem) && $elem[$field] === $search) { + return $key; + } elseif (is_scalar($elem) && $elem === $search) { + return $key; + } + } else { + if (is_object($elem)) { + $elem = (array) $elem; + + if (in_array($search, $elem)) { + return $key; + } + } elseif (is_array($elem) && in_array($search, $elem)) { + return $key; + } elseif (is_scalar($elem) && $elem === $search) { + return $key; + } + } + } + + return false; + } + + /** + * Returns an array containing all the elements of arr1 after applying + * the callback function to each one. + * + * @param string $callback Callback function to run for each + * element in each array + * @param array $array An array to run through the callback + * function + * @param boolean $on_nonscalar Whether or not to call the callback + * function on nonscalar values + * (Objects, resources, etc) + * @return array + */ + public static function array_map_deep(array $array, $callback, $on_nonscalar = false) + { + foreach ($array as $key => $value) { + if (is_array($value)) { + $args = array($value, $callback, $on_nonscalar); + $array[$key] = call_user_func_array(array(__CLASS__, __FUNCTION__), $args); + } elseif (is_scalar($value) || $on_nonscalar) { + $array[$key] = call_user_func($callback, $value); + } + } + + return $array; + } + + public static function array_clean(array $array) + { + return array_filter($array); + } + + /** + * Wrapper to prevent errors if the user doesn't have the mbstring + * extension installed. + * + * @param string $encoding + * @return string + */ + protected static function mbInternalEncoding($encoding = null) + { + if (function_exists('mb_internal_encoding')) { + return $encoding ? mb_internal_encoding($encoding) : mb_internal_encoding(); + } + + // @codeCoverageIgnoreStart + return 'UTF-8'; + // @codeCoverageIgnoreEnd + } + + /** + * Set the writable bit on a file to the minimum value that allows the user + * running PHP to write to it. + * + * @param string $filename The filename to set the writable bit on + * @param boolean $writable Whether to make the file writable or not + * @return boolean + */ + public static function set_writable($filename, $writable = true) + { + $stat = @stat($filename); + + if ($stat === false) { + return false; + } + + // We're on Windows + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + return true; + } + + list($myuid, $mygid) = array(posix_geteuid(), posix_getgid()); + + if ($writable) { + // Set only the user writable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, fileperms($filename) | 0200); + } + + // Set only the group writable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, fileperms($filename) | 0220); + } + + // Set the world writable bit (file isn't owned or grouped by us) + return chmod($filename, fileperms($filename) | 0222); + } else { + // Set only the user writable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, (fileperms($filename) | 0222) ^ 0222); + } + + // Set only the group writable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, (fileperms($filename) | 0222) ^ 0022); + } + + // Set the world writable bit (file isn't owned or grouped by us) + return chmod($filename, (fileperms($filename) | 0222) ^ 0002); + } + } + + /** + * Set the readable bit on a file to the minimum value that allows the user + * running PHP to read to it. + * + * @param string $filename The filename to set the readable bit on + * @param boolean $readable Whether to make the file readable or not + * @return boolean + */ + public static function set_readable($filename, $readable = true) + { + $stat = @stat($filename); + + if ($stat === false) { + return false; + } + + // We're on Windows + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + return true; + } + + list($myuid, $mygid) = array(posix_geteuid(), posix_getgid()); + + if ($readable) { + // Set only the user readable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, fileperms($filename) | 0400); + } + + // Set only the group readable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, fileperms($filename) | 0440); + } + + // Set the world readable bit (file isn't owned or grouped by us) + return chmod($filename, fileperms($filename) | 0444); + } else { + // Set only the user readable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, (fileperms($filename) | 0444) ^ 0444); + } + + // Set only the group readable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, (fileperms($filename) | 0444) ^ 0044); + } + + // Set the world readable bit (file isn't owned or grouped by us) + return chmod($filename, (fileperms($filename) | 0444) ^ 0004); + } + } + + /** + * Set the executable bit on a file to the minimum value that allows the + * user running PHP to read to it. + * + * @param string $filename The filename to set the executable bit on + * @param boolean $executable Whether to make the file executable or not + * @return boolean + */ + public static function set_executable($filename, $executable = true) + { + $stat = @stat($filename); + + if ($stat === false) { + return false; + } + + // We're on Windows + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + return true; + } + + list($myuid, $mygid) = array(posix_geteuid(), posix_getgid()); + + if ($executable) { + // Set only the user readable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, fileperms($filename) | 0100); + } + + // Set only the group readable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, fileperms($filename) | 0110); + } + + // Set the world readable bit (file isn't owned or grouped by us) + return chmod($filename, fileperms($filename) | 0111); + } else { + // Set only the user readable bit (file is owned by us) + if ($stat['uid'] == $myuid) { + return chmod($filename, (fileperms($filename) | 0111) ^ 0111); + } + + // Set only the group readable bit (file group is the same as us) + if ($stat['gid'] == $mygid) { + return chmod($filename, (fileperms($filename) | 0111) ^ 0011); + } + + // Set the world readable bit (file isn't owned or grouped by us) + return chmod($filename, (fileperms($filename) | 0111) ^ 0001); + } + } + + /** + * Returns size of a given directory in bytes. + * + * @param string $dir + * @return integer + */ + public static function directory_size($dir) + { + $size = 0; + foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)) as $file => $key) { + if ($key->isFile()) { + $size += $key->getSize(); + } + } + return $size; + } + + /** + * Returns a home directory of current user. + * + * @return string + */ + public static function get_user_directory() + { + if (isset($_SERVER['HOMEDRIVE'])) return $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; + else return $_SERVER['HOME']; + } + + /** + * Returns all paths inside a directory. + * + * @param string $dir + * @return array + */ + public static function directory_contents($dir) + { + $contents = array(); + foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)) as $pathname => $fi) { + $contents[] = $pathname; + } + natsort($contents); + return $contents; + } +} diff --git a/e_lib/util.php b/e_lib/util.php new file mode 100644 index 00000000..1b209796 --- /dev/null +++ b/e_lib/util.php @@ -0,0 +1,10 @@ + + */ +class util extends \utilphp\util { } diff --git a/e_lib/utilphp-1.1.0/.coveralls.yml b/e_lib/utilphp-1.1.0/.coveralls.yml new file mode 100644 index 00000000..6e649991 --- /dev/null +++ b/e_lib/utilphp-1.1.0/.coveralls.yml @@ -0,0 +1 @@ +service_name: travis-ci \ No newline at end of file diff --git a/e_lib/utilphp-1.1.0/.gitignore b/e_lib/utilphp-1.1.0/.gitignore new file mode 100644 index 00000000..a28cc36f --- /dev/null +++ b/e_lib/utilphp-1.1.0/.gitignore @@ -0,0 +1,4 @@ +test.php +build/* +report/* +tests/test* diff --git a/e_lib/utilphp-1.1.0/.travis.yml b/e_lib/utilphp-1.1.0/.travis.yml new file mode 100644 index 00000000..bfce66e7 --- /dev/null +++ b/e_lib/utilphp-1.1.0/.travis.yml @@ -0,0 +1,22 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm + +matrix: + allow_failures: + - php: hhvm + +before_script: + - pyrus install pear/PHP_CodeSniffer + - wget -nc http://getcomposer.org/composer.phar + - php composer.phar install --dev --no-interaction + - mkdir -p build/logs + - phpenv rehash + +after_script: + - php vendor/bin/coveralls diff --git a/e_lib/utilphp-1.1.0/CHANGELOG.md b/e_lib/utilphp-1.1.0/CHANGELOG.md new file mode 100644 index 00000000..8cbd899f --- /dev/null +++ b/e_lib/utilphp-1.1.0/CHANGELOG.md @@ -0,0 +1,86 @@ +Change Log +========== + +1.1.0 +----- + +This release introduces a deprecation notice for `slugify()`, please update your code. + +* Added a cryptographically secure random string function `secure_random_string`. Thanks to @abhimanyusharma003 via [Pull Request #53](https://github.com/brandonwamboldt/utilphp/pull/53) +* Added `limit_characters` and `limit_words` functions. Thanks to @abhimanyusharma003 via [Pull Request #55](https://github.com/brandonwamboldt/utilphp/pull/55) +* Added `rmdir` method to recursively delete a directory. Thanks to @ARACOOOL via [Pull Request #56](https://github.com/brandonwamboldt/utilphp/pull/56) +* Added `set_executable`, `set_readable`, `set_writable`, `directory_size`, `directory_contents` and `get_user_dir` functions. Thanks to @sergserg via [Pull Request #70](https://github.com/brandonwamboldt/utilphp/pull/70) +* Changed parameter ordering for `slugify`, `$css_mode` is now the third argument. For backwards compatibility, the old order will still work but it will generate an `E_USER_DEPRECATED` warning. Thanks to @abhimanyusharma003 via [Pull Request #71](https://github.com/brandonwamboldt/utilphp/pull/71) +* Added `match_string` method. Thanks to @abhimanyusharma003 via [Pull Request #72](https://github.com/brandonwamboldt/utilphp/pull/72) +* Renamed internal methods (protected ones) for PSR-2 compliance +* General performance improvements, code quality improvements, and increased unit test coverage (special thanks to @hopeseekr for getting us near 100% coverage) + +1.0.7 +----- + +* Added `fix_broken_serialization` to fix broken serialized strings (Thanks to @hopeseekr via [Pull Request #48](https://github.com/brandonwamboldt/utilphp/pull/48)) +* Fixed `get_current_url` appending port 80 or 443 when not needed (Thanks to @scottchiefbaker via [Pull Request #49](https://github.com/brandonwamboldt/utilphp/pull/49)) +* `var_dump` can now handle recursive data structures without crashing +* `var_dump` code was minified and cleaned up +* `array_flatten` was optimized (thanks to @hopeseekr via [Pull Request #47](https://github.com/brandonwamboldt/utilphp/pull/47)) +* `remove_accents` was completely rewritten and is now ~4x faster + +1.0.6 +----- + +* Added `start_with` function +* Added `ends_with` function +* Added `str_contains` function +* Added `str_icontains` function +* Added `get_file_ext` function +* Fixing permissions on the files & directories +* Fixing a bug with the include path of util.php + +1.0.5 +----- + +* [Issue #29](https://github.com/brandonwamboldt/utilphp/issues/29) Fixed error in `var_dump` if mbstring extension wasn't present +* Adding Composer support +* Updating license from GPL to MIT +* Adding Changelog to project +* Bumping minimum version to PHP 5.3.3 + +1.0.4 +----- + +* [Issue #22](https://github.com/brandonwamboldt/utilphp/issues/22) Removed all superglobal *_get functions, you can use the modified array_get now +* [Issue #22](https://github.com/brandonwamboldt/utilphp/issues/22) Modifed the behaviour of `array_get`, see documentation +* [Pull Request #21](https://github.com/brandonwamboldt/utilphp/pull/21) Added multibyte support to html* functions +* [Issue #9](https://github.com/brandonwamboldt/utilphp/issues/9) Removed the `str_to_utf8` function +* [Issue #3](https://github.com/brandonwamboldt/utilphp/issues/3) Removed the `absint` function +* Removed declare() from util.php to avoid errors +* Updated PHPUnit tests to use PHPUnit 3.6 + +1.0.3 +----- + +* [Issue #16](https://github.com/brandonwamboldt/utilphp/issues/16) Improved performance of `slugify` +* [Issue #14](https://github.com/brandonwamboldt/utilphp/issues/14) Modified the regex for `seems_utf8` to be more accurate +* [Issue #13](https://github.com/brandonwamboldt/utilphp/issues/13) Changed `validate_email` to be wrapper for `filter_var` +* Added 'ok' to the list of yes words for `str_to_bool` +* `str_to_bool` matches no followed by any number of 'o's + +1.0.2 +----- + +* [Issue #12](https://github.com/brandonwamboldt/utilphp/issues/12) `get_current_url` now includes the port and user/password if required +* [Issue #11](https://github.com/brandonwamboldt/utilphp/issues/11) `human_time_diff` now uses the DateTime functions +* [Issue #10](https://github.com/brandonwamboldt/utilphp/issues/10) `is_https` no longer checks the port as well + +1.0.1 +----- + +* [Issue #7](https://github.com/brandonwamboldt/utilphp/issues/7) Added the `$trust_proxy_headers` parameter to `get_client_ip` +* [Issue #6](https://github.com/brandonwamboldt/utilphp/issues/6) Removed `is_isset` as the function did not work as intended +* [Issue #6](https://github.com/brandonwamboldt/utilphp/issues/6) Removed `is_empty` as it is redundant, use ! with function calls instead +* Fixed a bug with `get_gravatar` + +1.0.0 +----- + +* Initial release of util.php. diff --git a/e_lib/utilphp-1.1.0/CONTRIBUTORS.md b/e_lib/utilphp-1.1.0/CONTRIBUTORS.md new file mode 100644 index 00000000..7fadf04f --- /dev/null +++ b/e_lib/utilphp-1.1.0/CONTRIBUTORS.md @@ -0,0 +1,48 @@ +# CONTRIBUTORS + +Util.php is the combined effort of many people who contributed new functions and features, bug fixes, tests, and documentation. + +# Maintainer / Lead + +* Brandon Wamboldt (http://brandonwamboldt.ca) + +## Third-Party Projects + +The following projects were fully or partially incorporated into util.php (and properly attributed). + +* IntToWords (https://github.com/hemant347/IntToWords) +* LinkifyURL (https://github.com/jmrware/LinkifyURL) +* URLify.php (https://github.com/jbroadway/urlify/) +* Pure PHP http_build_url (https://github.com/jakeasmith/http_build_url) + +## Methods + +The following developers and/or companies helped contribute to building util.php. + +* PHP Experts, Inc. (http://www.phpexperts.pro/) + - `array_flatten()` + - `fix_broken_serialization()` + - Lots of unit tests. +* Tony Ferrara (ircmaxwell, http://blog.ircmaxell.com/) + - `seemsUtf8Regex()`: http://stackoverflow.com/a/11709412/430062 +* Askar ([@ARACOOOL](https://github.com/ARACOOOL)) + - `rmdir()` + - `limit_characters()` + - `limit_words()` +* Anonymous (tmp1000@fastmail.fm) + - `htmlspecialentities()`: http://php.timesoft.cc/manual/en/function.htmlentities.php + - `htmlspecialchars()` +* Laravel Project (https://github.com/laravel/laravel) + - `secure_random_string()`: http://trac.allenjb.me.uk/php/browser/tagi/vendor/laravel/framework/src/Illuminate/Support/Str.php?rev=87#L127 +* Abhimanyu Sharma ([@abhimanyusharma003](https://github.com/abhimanyusharma003)) + - `limit_characters()` + - `limit_words()` + - `match_string()` +* Scott Baker ([@scottchiefbaker](https://github.com/scottchiefbaker)) +* [@sergserg](https://github.com/sergserg) + - `set_writable()` + - `set_executable()` + - `set_readable()` + - `directory_size()` + - `directory_contents()` + - `get_user_dir()` diff --git a/e_lib/utilphp-1.1.0/LICENSE.md b/e_lib/utilphp-1.1.0/LICENSE.md new file mode 100644 index 00000000..7c3f2915 --- /dev/null +++ b/e_lib/utilphp-1.1.0/LICENSE.md @@ -0,0 +1,24 @@ +The MIT License (MIT) +===================== + +The MIT License (MIT) + +Copyright (c) 2013 Brandon Wamboldt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/e_lib/utilphp-1.1.0/README.md b/e_lib/utilphp-1.1.0/README.md new file mode 100644 index 00000000..3b271796 --- /dev/null +++ b/e_lib/utilphp-1.1.0/README.md @@ -0,0 +1,123 @@ +# Util.php [![Build Status](https://img.shields.io/travis/brandonwamboldt/utilphp.svg)](https://travis-ci.org/brandonwamboldt/utilphp) [![Coverage Status](https://img.shields.io/coveralls/brandonwamboldt/utilphp/master.svg)](https://coveralls.io/r/brandonwamboldt/utilphp) + +[UtilPHP](http://brandonwamboldt.github.com/utilphp/) (Aka util.php) is a +collection of useful functions and snippets that you need or could use every +day. It's implemented as a class with static methods, to avoid conflicts with +your existing code-base. Just drop it in and start using it immediately. + +Included are 55+ functions that provide you with the ability to do common +tasks much easier and more efficiently, without having to find that one comment +on php.net where you know it's been done already. Access superglobals without +checking to see if certain indexes are set first and pass default values, use a +nicely formatted var dump, validate emails, generate random strings, flatten an +array, pull a single column out of a multidimensional array and much more. + +Although it's implemented as one giant class, util.php has extensive +documentation and a full suite of unit tests to avoid breaking +backwards-compatibility unintentionally. + +## Release Information + +This repo contains in development code for future releases as well as the +current stable branch. Development code is contained in the develop branch. + +## Changelog and New Features + +You can find a list of all changes for each release in the +[official documentation](http://brandonwamboldt.github.com/utilphp/#changelog) + +## Installation + +### Server Requirements + +* PHP version 5.3.3 or higher. + +### Standalone File + +Simply drop `util.php` in any project and call `include 'util.php';` in your +project. You can then access the `Util` class. + +### Composer + +Add the following dependency to your composer.json: + +``` +"brandonwamboldt/utilphp": "1.0.*" +``` + +When used with composer, the class is namespaced (`\utilphp\util`) instead of +just `util`. + +## Contributing + +UtilPHP is a community driven project and accepts contributions of code and +documentation from the community. These contributions are made in the form of +Issues or [Pull Requests](http://help.github.com/send-pull-requests/) on the +[UtilityPHP repository](https://github.com/brandonwamboldt/utilphp) on GitHub. + +Issues are a quick way to point out a bug. If you find a bug or documentation +error in UtilityPHP then please check a few things first: + +* There is not already an open Issue +* The issue has already been fixed (check the develop branch, or look for closed Issues) +* Is it something really obvious that you fix it yourself? + +Reporting issues is helpful but an even better approach is to send a Pull +Request, which is done by "Forking" the main repository and committing to your +own copy. This will require you to use the version control system called Git. + +## Guidelines + +Before we look into how, here are the guidelines. If your Pull Requests fail to +pass these guidelines it will be declined and you will need to re-submit when +you’ve made the changes. This might sound a bit tough, but it is required for +me to maintain quality of the code-base. + +### PHP Style + +Please ensure all new contributions match the [PSR-2](http://www.php-fig.org/psr/psr-2/) +coding style guide. + +### Documentation + +If you change anything that requires a change to documentation then you will +need to add it. New methods, parameters, changing default values, adding +constants, etc are all things that will require a change to documentation. The +change-log must also be updated for every change. Also PHPDoc blocks must be +maintained. + +### PHP Version Compatibility + +UtilityPHP is compatible with PHP 5.3.3 so all code supplied must stick to this +requirement. + +Of particular note is avoiding short array notation like this: + +``` +$var = []; +``` + +Please use the old notation instead: + +``` +$var = array(); +``` + +I know it's uglier, but PHP 5.3 while EOL'd, still isn't that old. + +### Branching + +One thing at a time: A pull request should only contain one change. That does +not mean only one commit, but one change - however many commits it took. The +reason for this is that if you change X and Y but send a pull request for both +at the same time, we might really want X but disagree with Y, meaning we cannot +merge the request. Using the Git-Flow branching model you can create new +branches for both of these features and send two requests. + +## License + +UtilPHP is licensed under the MIT license. + +## Resources + +* [Documentation](http://brandonwamboldt.github.com/utilphp/) diff --git a/e_lib/utilphp-1.1.0/composer.json b/e_lib/utilphp-1.1.0/composer.json new file mode 100644 index 00000000..9bf3520e --- /dev/null +++ b/e_lib/utilphp-1.1.0/composer.json @@ -0,0 +1,24 @@ +{ + "name": "brandonwamboldt/utilphp", + "type": "library", + "version": "1.1.0", + "description": "util.php is a collection of useful functions and snippets that you need or could use every day, designed to avoid conflicts with existing projects", + "keywords": ["php", "utility", "collection", "helpers"], + "homepage": "https://github.com/brandonwamboldt/utilphp", + "license": "MIT", + "authors": [ + { + "name": "Brandon Wamboldt", + "email": "brandon.wamboldt@gmail.com" + } + ], + "autoload": { + "psr-0": { "utilphp\\": "src/" } + }, + "require-dev": { + "satooshi/php-coveralls": "dev-master" + }, + "require": { + "php": ">=5.3.3" + } +} diff --git a/e_lib/utilphp-1.1.0/docs/css/docs.css b/e_lib/utilphp-1.1.0/docs/css/docs.css new file mode 100644 index 00000000..77993435 --- /dev/null +++ b/e_lib/utilphp-1.1.0/docs/css/docs.css @@ -0,0 +1,168 @@ +body { + background: #f4f4f4 url('../images/background.png'); + color: #333; + font: 18px/30px "Droid Serif", "Helvetica Neue", Helvetica, Arial; +} + +a { + text-decoration: none; + color: #f00; + padding: 2px; +} + +a:hover { + background: #277585; + color: #fff; + border-radius: 3px; +} + +h1, h2, h3, h4, h5, h6 { + padding-top: 20px; +} + +h2 { + font-size: 40px; + font-weight: normal; + margin: 0 0 15px; +} + +p { + margin: 20px 0; + min-width: 550px; + max-width: 900px; +} + +table, tr, td { + margin: 0; padding: 0; +} + +td { + padding: 2px 12px 2px 0; +} + +ul { + list-style-type: circle; + padding: 0 0 0 20px; +} + +li { + width: 500px; + margin-bottom: 10px; +} + +code, pre, tt { + font-family: Monaco, Consolas, "Lucida Console", monospace; + font-size: 12px; + line-height: 18px; + font-style: normal; +} + +tt { + padding: 0px 3px; + background: #fff; + border: 1px solid #ddd; + zoom: 1; +} + +code { + margin-left: 20px; +} + +pre { + font-size: 12px; + padding: 12px; + background: #fff; + margin: 0px 0 30px; + border-radius: 0 0 2px 2px; + box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); +} + +span.header { + font-size: 24px; + line-height: 30px; + border-left: 10px solid #ddd; + padding-left: 10px; +} + +.desc-text code { + margin-left: 0; + font-size: 18px; + color: #0E04C8; +} + +#sidebar { + background: #fff; + position: fixed; + top: 0; left: 0; bottom: 0; + width: 220px; + overflow-y: auto; + overflow-x: hidden; + padding: 5px 0 30px 10px; + border-right: 1px solid #bbb; + + box-shadow: 0 0 20px #ccc; + -webkit-box-shadow: 0 0 20px #ccc; + -moz-box-shadow: 0 0 20px #ccc; + -webkit-overflow-scrolling: touch; +} + +.toc_title, .toc_title:visited { + display: block; + color: #000; + margin-top: 15px; +} + +.toc_title:hover { + background: none; + color: #f00; +} + +.toc_title .version { + font-size: 12px; + font-weight: normal; +} + +.toc_section { + font-size: 14px; + line-height: 24px; + margin: 5px 0 0 0; + padding-left: 10px; + list-style-type: none; +} + +.toc_section li { + cursor: pointer; + margin: 0 0 3px 0; +} + +.toc_section li a { + text-decoration: none; + color: black; +} + +.toc_section li a:hover { + background: none; + color: #f00; +} + +.container { + min-width: 550px; + max-width: 1000px; + margin: 40px 0 50px 260px; +} + +#documentation section > article > p > code { + color: #999; +} + +#documentation section > article > p > code > .util_class { + color: #bbb; +} + +#documentation section > article > p > code > .func_name { + color: #0E04C8; +} + +#documentation section > article > p > code > .param { + color: #DA72F3; +} diff --git a/e_lib/utilphp-1.1.0/docs/favicon.png b/e_lib/utilphp-1.1.0/docs/favicon.png new file mode 100644 index 00000000..5f17cf1d Binary files /dev/null and b/e_lib/utilphp-1.1.0/docs/favicon.png differ diff --git a/e_lib/utilphp-1.1.0/docs/images/awesome_var_dump.jpg b/e_lib/utilphp-1.1.0/docs/images/awesome_var_dump.jpg new file mode 100644 index 00000000..a697c734 Binary files /dev/null and b/e_lib/utilphp-1.1.0/docs/images/awesome_var_dump.jpg differ diff --git a/e_lib/utilphp-1.1.0/docs/images/background.png b/e_lib/utilphp-1.1.0/docs/images/background.png new file mode 100644 index 00000000..1e6fddd7 Binary files /dev/null and b/e_lib/utilphp-1.1.0/docs/images/background.png differ diff --git a/e_lib/utilphp-1.1.0/docs/images/utility_logo.png b/e_lib/utilphp-1.1.0/docs/images/utility_logo.png new file mode 100644 index 00000000..434c7bc5 Binary files /dev/null and b/e_lib/utilphp-1.1.0/docs/images/utility_logo.png differ diff --git a/e_lib/utilphp-1.1.0/docs/index.html b/e_lib/utilphp-1.1.0/docs/index.html new file mode 100644 index 00000000..3b47bba7 --- /dev/null +++ b/e_lib/utilphp-1.1.0/docs/index.html @@ -0,0 +1,1234 @@ + + + + + + + + + + + + + + + + util.php - The PHP programmers best friend - UtilityPHP + + + + + +
+

+ +

+ +

+ util.php is a collection of useful functions and snippets + that you need or could use every day. It's implemented as a class with static methods, to avoid conflicts with your + existing code-base. Just drop it in and start using it immediately. +

+ +

+ Included are 60+ functions that provide you with the ability to do common tasks much easier and more efficiently, + without having to find that one comment on php.net where you know its been done already. Access superglobals + without checking to see if certain indexes are set first and pass default values, use a nicely formatted var dump, + validate emails, generate random strings, flatten an array, pull a single column out of a multidimensional array + and much more. +

+ +

+ Although it's implemented as one giant class, util.php has extensive documentation and a full suite of unit tests + to avoid breaking backwards-compatibility unintentionally. +

+ +

+ The project is hosted on GitHub. + You can report bugs and discuss features on the + issues page, + or send tweets to @brandonwamboldt. +

+ +

Downloads (Right-click, and use "Save As")

+ +

+ Stable Version (1.1.0)
+ Unstable Version (master) +

+ +

Installation

+ + Server Requirements
+ +
    +
  • PHP 5.3.3+
  • +
+ + Standalone File
+ +

+ Simply drop util.php in any project and call include 'util.php'; in your project. + You can then access the Util class. +

+ + Composer
+ +

+ Add the following dependency to your composer.json: + +

"brandonwamboldt/utilphp": "1.1.*"
+ + When used with composer, the class is namespaced (\utilphp\util) instead of + just util. +

+ +
+

Debugging Functions

+ +
+
+

+ var_dump + + util::var_dump(mixed $var[, bool $return = FALSE]) + +

+ +

+ Nicely prints out the contents of a passed variable. Booleans are properly displayed as 'true' or 'false', + null values are shown as 'NULL', variable types are displayed, and arrays and objects are displayed as a + collapsible tree powered by JavaScript. +

+ +

Usage:

+ +
util::var_dump($var);
+ + +
+
+ +

Array/Object Functions

+ +
+
+

+ array_first + + util::array_first(array $array) + +

+ +

+ Retrieve the first value from an array. Can be run on function callbacks, and it will not modify the pointer + of the source array unlike most other methods of doing this. +

+ +

Usage:

+ +
util::array_first( ['a', 'b', 'c'] );
=> Returns 'a'
+
+ +
+

+ array_first_key + + util::array_first_key(array $array) + +

+ +

+ Retrieve the first key from an array. Can be run on function callbacks, and it will not modify the pointer of + the source array unlike most other methods of doing this. +

+ +

Usage:

+ +
util::array_first_key( $users );
=> Returns 'brandon'
+
+ +
+

+ array_flatten + + util::array_flatten(array $array[, bool $preserve_keys = TRUE]) + +

+ +

Flattens a multi-dimensional array into a one dimensional array

+ +

Usage:

+ +
util::array_flatten( [ 'a', 'b', [ 'c', 'd', 'e', [ 'f', 'g', [ [ [ [ 'h', 'i', 'j' ] ] ] ] ] ] ] );
+=> Returns [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ]
+
+ +
+

+ array_get + + util::array_get($var[, mixed $default = NULL]) + +

+ +

Retrieve a value from an array, or return a given default if the index isn't set

+ +

Usage:

+ +
util::array_get($_POST['action'], 'index');
+=> If $_POST['action'] is set, returns its value, otherwise returns 'index'
+util::array_get($_POST['action']['do'], 'index');
+=> Returns the value of $_POST['action']['do'] or 'index'
+
+ +
+

+ array_last + + util::array_last(array $array) + +

+ +

+ Retrieve the last value from an array. Can be run on function callbacks, and it will not modify the pointer + of the source array unlike most other methods of doing this. +

+ +

Usage:

+ +
util::array_last( [ 'a', 'b', 'c'] );
+=> Returns 'c'
+
+ +
+

+ array_last_key + + util::array_last_key(array $array) + +

+ +

+ Retrieve the last key from an array. Can be run on function callbacks, and it will not modify the pointer of + the source array unlike most other methods of doing this. +

+ +

Usage:

+ +
util::array_last_key( $users );
+=> Returns 'zane'
+
+ +
+

+ array_map_deep + + util::array_map_deep(array $array, callable $callback[, bool $on_nonscalar = FALSE]) + +

+ +

+ Returns an array containing all the elements of $array after applying the callback function to each one recursively. + Particularly useful for avoiding errors when calling functions that only accept scalar values on an array that could + contain nested arrays, such as $_GET or $_POST. +

+ +

Usage:

+ +
util::array_map_deep($_POST, 'htmlentities');
+=> Recursively escapes each scalar value in $_POST
+util::array_map_deep($_POST, 'htmlentities', TRUE);
+=> Recursively escapes each value in $_POST regardless of its type
+
+ +
+

+ array_pluck + + util::array_pluck(array $array, string $field[, bool $preserve_keys, bool $remove_nomatches]) + +

+ +

+ Replaces each value in an array with the specified field of the array or object that used to be the value. Very + useful when you have an array of objects or arrays from a database, and you only want one specific field. For + example, you want an array of emails from an array of users. +

+ +

Usage:

+ +
util::array_pluck([['val' => 1], ['val' => 2], ['val' => 3]], 'val');
+=> Returns [1, 2, 3]
+util::array_pluck($users, 'email');
+=> Returns an array of email addresses for each user
+
+ +
+

+ array_search_deep + + util::array_search_deep(array $array, mixed $search[, string $field = FALSE]) + +

+ +

+ Allows you to search for a value in an array of arrays or an array of objects, and return the key of the value + that matches the search criteria. If $field is unspecified, the entire array/object is searched. +

+ +

Usage:

+ +
util::array_search_deep($_POST, 'delete_post');
+=> Might return 'do' if $_POST['do']['action'] = 'delete_post'
+util::array_search_deep($users, 'rogue_coder', 'username');
+=> Might return 5 if $users[5]->username = 'rogue_coder'
+
+ +
+

+ array_clean + + util::array_clean(array $array) + +

+ +

+ Remove all null/empty/false values from the given array. +

+ +

Usage:

+ +
util::array_clean( array( 'a', 'b', '', null, false, 0) );
=> Returns array('a', 'b');
+
+ +
+ +

URL Functions

+ +
+
+

+ add_query_arg + + util::add_query_arg() + +

+ +

Adds one ore more query args to the query string of the current URL or a given URL

+ +

Usage:

+ +
util::add_query_arg( 'user', '5', '/admin/users?action=edit' );
+=> Returns '/admin/users?action=edit&user=5'
+util::add_query_arg( [ 'user' => 5, 'action' => 'edit' ], '/admin/users' );
+=> Returns '/admin/users?user=5&action=edit'
+
+ +
+

+ get_current_url + + util::get_current_url() + +

+ +

Returns the current URL with hostname

+ +

Usage:

+ +
util::get_current_url();
+=> Returns 'http://brandonwamboldt.ca/utilphp/'
+
+ +
+

+ is_https + + util::is_https() + +

+ +

Returns true if the current page is being loaded over https, false if it isn't

+ +

Usage:

+ +
util::is_https();
+=> Returns false
+
+ +
+

+ http_build_url + + util::http_build_url([mixed $url[, mixed $parts[, int $flags = HTTP_URL_REPLACE[, array &amo;$new_url]]]]) + +

+ +

+ Pure PHP implementation/polyfill for http_build_url + which requires pecl_http to be installed. +

+ +

Usage:

+ +
echo util::http_build_url("http://user@www.example.com/pub/index.php?a=b#files",
+    array(
+        "scheme" => "ftp",
+        "host" => "ftp.example.com",
+        "path" => "files/current/",
+        "query" => "a=c"
+    ),
+    HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
+);
+ +

The above example will output:

+ +
ftp://ftp.example.com/pub/files/current/?a=c
+
+ +
+

+ is_https + + util::is_https() + +

+ +

Returns true if the current page is being loaded over https, false if it isn't

+ +

Usage:

+ +
util::is_https();
+=> Returns false
+
+ +
+

+ remove_query_arg + + util::remove_query_arg( array|string $query_args[, string $url]) + +

+ +

Removes one ore more query args from the query string of the current URL or a given URL

+ +

Usage:

+ +
util::remove_query_arg( 'action', '/admin/users?action=edit&user=5' );
+=> Returns '/admin/users?user=5'
+util::remove_query_arg( [ 'user', 'action'], '/admin/users?action=edit&user=5' );
+=> Returns '/admin/users'
+
+ +
+

+ slugify + + util::slugify(string $string[, string $separator = "-", bool $css_mode = FALSE]) + +

+ +

+ Generate a string safe for use in URLs from any given string. Converts any accent characters + to their equivalent normal characters and converts any other non-alphanumeric characters to + dashes, then converts any sequence of two or more dashes to a single dash. This function + generates slugs safe for use as URLs, and if you pass TRUE as the second parameter, it will + create strings safe for use as CSS classes or IDs. +

+ +

Usage:

+ +
util::slugify('This is a random --string with an Ãccent');
+=> Returns 'this-is-a-random-string-with-an-accent'
+util::slugify('Another String', '.');
+=> Returns 'another.string'
+
+
+ +

String Functions

+ +
+
+

+ htmlentities + + util::htmlentities(string $string[, bool $preserve_encoded_entities = FALSE]) + +

+ +

+ Executes htmlentities with ENT_QUOTES set by default. However, if you pass TRUE as + the second parameter, it will not re-encode entities that are already encoded. +

+ +

Usage:

+ +
util::htmlentities('this string < this string', TRUE);
+=> Returns 'this string < this string'
+
+ +
+

+ htmlspecialchars + + util::htmlspecialchars(string $string[, bool $preserve_encoded_entities = FALSE]) + +

+ +

+ Executes htmlspecialchars with ENT_QUOTES set by default. However, if you pass TRUE as + the second parameter, it will not re-encode entities that are already encoded. +

+ +

Usage:

+ +
util::htmlspecialchars('this string < this string', TRUE);
+=> Returns 'this string < this string'
+
+ +
+

+ linkify + + util::linkify(string $text) + +

+ +

Find's any URLs in the specified text and wraps them with HTML anchor tags

+ +

Usage:

+ +
util::linkify('this string has a link to www.google.com');
+=> Returns 'this string has a link to <a href="http://wwww.google.com/">www.google.com</a>'
+
+ +
+

+ match_string + + util::match_string(string $pattern, string $string[, bool $caseSensitive = true]) + +

+ +

+ Check if a string matches a given pattern. You can use '*' as a wildcard character. +

+ +

Usage:

+ +
util::match_string("test/*", "test/my/test");
+=> Returns true
+util::match_string("test/", "test/my/test");
+=> Returns false
+
+ +
+

+ random_string + + util::random_string(int $length[, bool $human_friendly = TRUE, bool $include_symbols = FALSE, bool $no_duplicate_chars = FALSE]) + +

+ +

+ Generates a random string of the specified length. Human friendly mode + will exclude characters that can be confused with other characters, such + as 0 (zero) and O (capital o), 1 (one) and l (lowercase L). +

+ +

Usage:

+ +
util::random_string(8);
+=> Returns 'a6BiF4UW'
+
+ +
+

+ number_to_word + + util::number_to_word(int|float $number) + +

+ +

Converts a number into its text equivalent. For example, 56 becomes fifty-six.

+ +
util::number_to_word(512.5);
+=> Returns 'five hundred and twelve point five'
+
+ +
+

+ ordinal + + util::ordinal(int $number) + +

+ +

Returns the ordinal version of a number (appends th, st, nd, rd)

+ +

Usage:

+ +
util::ordinal(22);
+=> Returns '22nd'
+
+ +
+

+ remove_accents + + util::remove_accents(string $string) + +

+ +

Converts all accent characters to their ASCII equivalents

+ +

Usage:

+ +
util::remove_accents('Àccent');
+=> Returns 'Accent'
+
+ +
+

+ secure_random_string + + util::secure_random_string(int $length) + +

+ +

Generate a random string of characters. Will attempt to use a secure source (openssl).

+ +

Usage:

+ +
util::secure_random_string(16);
+=> Returns '5bB1RJH0cQhNjviT'
+
+ +
+

+ seems_utf8 + + util::seems_utf8(string $string) + +

+ +

Checks to see if a given string is UTF-8 encoded/safe

+ +

Usage:

+ +
util::seems_utf8('This is some random string user input');
+=> Returns true
+
+ +
+

+ safe_truncate + + util::safe_truncate(string $string, int $length[, string $append = '...']) + +

+ +

Truncate a string to a specified length without cutting a word off

+ +

Usage:

+ +
util::safe_truncate('The quick brown fox jumps over the lazy dog', 24);
+=> Returns 'The quick brown fox...'
+
+ +
+

+ size_format + + util::size_format(int $bytes[, int $decimals = 0]) + +

+ +

Formats an integer as a human friendly size string, such as 4 KiB.

+ +

Usage:

+ +
util::size_format( 25151251, 2 );
+=> Returns '23.99 MiB'
+
+ +
+

+ str_to_bool + + util::str_to_bool(string $string) + +

+ +

Converts a string to boolean, looking for yes/no words like 'yes', 'no', 'true', 'false', 'y', 'n', etc

+ +

Usage:

+ +
util::str_to_bool('yes');
+=> Returns true
+
+ +
+

+ zero_pad + + util::zero_pad(int $number, int $length) + +

+ +

Pads a given number with zeroes on the left

+ +

Usage:

+ +
util::zero_pad(341, 8);
+=> Returns '00000341'
+
+ +
+

+ strip_space + + util::strip_space(string $string) + +

+ +

Strip all withspace from the given string

+ +

Usage:

+ +
util::strip_space(' The quick brown fox jumps over the lazy dog ');
+=> Returns 'Thequickbrownfoxjumpsoverthelazydog'
+
+ +
+

+ sanitize_string + + util::sanitize_string(string $string) + +

+ +

+ Sanitize a string by performing the following operation : +

    +
  • Remove accents
  • +
  • Lower the string
  • +
  • Remove punctuation characters
  • +
  • Strip whitespaces
  • +
+ +

+

Usage:

+ +
util::sanitize_string(' Benoit! à New-York? j’ai perçu 1 % : Qu’as-tu "gagné" chez M. V. Noël? Dix francs.');
+=> Returns 'benoitanewyorkjaipercu1quastugagnechezmvnoeldixfrancs'
+
+
+ +

Files

+ +
+
+

+ full_permissions + + util::full_permissions(string $file) + +

+ +

Returns the file permissions as a nice string, like -rw-r--r--

+ +

Usage:

+ +
util::full_permissions('/etc/passwd');
+=> Returns '-rw-r--r--'
+
+ +
+

+ rmdir + + util::rmdir(string $dir[, bool $traverseSymlinks = false]) + +

+ +

Recursively deletes a directories (including all contents).

+ +

Usage:

+ +
util::rmdir('/tmp/working/dir');
+=> Returns true
+
+
+ +

Serialization

+ +
+
+

+ is_serialized + + util::is_serialized(mixed $data) + +

+ +

Checks to see if a given variable is a seralized data structure

+ +

Usage:

+ +
util::is_serialized( 'a:0:{}' );
+=> Returns true
+
+ +
+

+ maybe_serialize + + util::maybe_serialize(mixed $data) + +

+ +

Serialize data, if needed to store in plaintext (Arrays or objects)

+ +

Usage:

+ +
util::maybe_serialize( 5 );
+=> Returns 5
+util::maybe_serialize( array() );
+=> Returns 'a:0:{}'
+
+ +
+

+ maybe_unserialize + + util::maybe_unserialize(mixed $data) + +

+ +

Unserialize data, if it's a serialized string

+ +

Usage:

+ +
util::maybe_unserialize(5);
+=> Returns 5
+util::maybe_unserialize("a:0:{}");
+=> Returns array()
+
+ +
+

+ fix_broken_serialization + + util::fix_broken_serialization(mixed $data) + +

+ +

+ Attempt to fix a broken serialization string (e.g. where string offsets are incorrect). Can fix + errors that frequently occur with mismatched character sets or higher-than-ASCII characters. +

+ +

Usage:

+ +
util::fix_broken_serialization('a:1:{s:4:"test";s:4:"abc";}');
+=> Returns 'a:1:{s:4:"test";s:3:"abc";}'
+
+
+ +

Other

+ +
+
+

+ force_download + + util::force_download(string $filename, string $content = FALSE) + +

+ +

+ Transmit headers that force a browser to display the download file dialog. Cross + browser compatible. Only fires if headers have not already been sent. +

+ +

Usage:

+ +
util::force_download( 'export.csv', file_get_contents( 'securefile.csv' ) );
+=> The user will be prompted to download the file
+
+ +
+

+ get_client_ip + + util::get_client_ip(bool $trust_proxy_headers = FALSE) + +

+ +

+ Returns the IP address of the client. Only enable $trust_proxy_headers if your server is behind a proxy + that sets the HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR headers. +

+ +

Usage:

+ +
util::get_client_ip();
+=> Returns '12.123.12.100'
+
+ +
+

+ get_gravatar + + util::get_gravatar(string $email, int $size = 32) + +

+ +

Return the URL to a user's gravatar

+ +

Usage:

+ +
util::get_gravatar('brandon.wamboldt@gmail.com');
+=> Returns 'http://www.gravatar.com/avatar/46679faeb6780ecb1ea57527fdc66eb3?s=32'
+
+ +
+

+ human_time_diff + + util::human_time_diff(int $from, int $to = '', int $as_text = FALSE, string $suffix = ' ago') + +

+ +

Converts a unix timestamp to a relative time string, such as "3 days ago" or "2 weeks ago"

+ +

Usage:

+ +
util::human_time_diff(time() - 7400);
+=> Returns '2 hours ago'
+util::human_time_diff(time() - 7400, '', TRUE);
+=> Returns 'two hours ago'
+
+ +
+

+ nocache_headers + + util::nocache_headers(mixed $data) + +

+ +

Sets the headers to prevent caching for the different browsers

+ +

+ Different browsers support different nocache headers, so several headers must be sent + so that all of them get the point that no caching should occur +

+ +

Usage:

+ +
util::nocache_headers();
+
+ +
+

+ utf8_headers + + util::utf8_headers(mixed $content_type = 'text/html') + +

+ +

Transmit UTF-8 content headers if the headers haven't already been sent

+ +

Usage:

+ +
util::utf8_headers();
+
+ +
+

+ validate_email + + util::validate_email(string $possible_email) + +

+ +

Validate an email address

+ +

Usage:

+ +
util::validate_email( 'brandon.wamboldt@gmail.com' );
+=> Returns true
+util::validate_email( 'not an email' );
+=> Returns false
+
+
+ +

Constants

+ +
+
+

+ SECONDS_IN_A_MINUTE + + util::SECONDS_IN_A_MINUTE + +

+ +

The number of seconds in a minute, useful for making code more verbose

+
+ +
+

+ SECONDS_IN_AN_HOUR + + util::SECONDS_IN_AN_HOUR + +

+ +

The number of seconds in an hour, useful for making code more verbose

+
+ +
+

+ SECONDS_IN_A_DAY + + util::SECONDS_IN_A_DAY + +

+ +

The number of seconds in a day, useful for making code more verbose

+
+ +
+

+ SECONDS_IN_A_WEEK + + util::SECONDS_IN_A_WEEK + +

+ +

The number of seconds in a week (7 days), useful for making code more verbose

+
+ +
+

+ SECONDS_IN_A_MONTH + + util::SECONDS_IN_A_MONTH + +

+ +

The number of seconds in a month (30 days), useful for making code more verbose

+
+ +
+

+ SECONDS_IN_A_YEAR + + util::SECONDS_IN_A_YEAR + +

+ +

The number of seconds in a year (365 days), useful for making code more verbose

+
+
+ +

Change Log

+ + + +

+ 1.1.0
+ + This release introduces a deprecation notice for slugify(), please update your code.

+ + - Added a cryptographically secure random string function secure_random_string. Thanks to @abhimanyusharma003 via Pull Request #53
+ - Added limit_characters and limit_words functions. Thanks to @abhimanyusharma003 via Pull Request #55
+ - Added rmdir method to recursively delete a directory. Thanks to @ARACOOOL via Pull Request #56
+ - Added set_executable, set_readable, set_writable, directory_size, directory_contents and get_user_dir functions. Thanks to @sergserg via Pull Request #70
+ - Changed parameter ordering for slugify, $css_mode is now the third argument. For backwards compatibility, the old order will still work but it will generate an E_USER_DEPRECATED warning. Thanks to @abhimanyusharma003 via Pull Request #71
+ - Added match_string method. Thanks to @abhimanyusharma003 via Pull Request #72
+ - Renamed internal methods (protected ones) for PSR-2 compliance
+ - General performance improvements, code quality improvements, and increased unit test coverage (special thanks to @hopeseekr for getting us near 100% coverage)
+

+ +

+ 1.0.7
+ - Added fix_broken_serialization to fix broken serialized strings (Thanks to @hopeseekr via Pull Request #48)
+ - Fixed get_current_url appending port 80 or 443 when not needed (Thanks to @scottchiefbaker via Pull Request #49)
+ - var_dump can now handle recursive data structures without crashing
+ - var_dump code was minified and cleaned up
+ - array_flatten was optimized (thanks to @hopeseekr via Pull Request #47)
+ - remove_accents was completely rewritten and is now ~4x faster
+

+ +

+ 1.0.6
+ - Added start_with function
+ - Added ends_with function
+ - Added str_contains function
+ - Added str_icontains function
+ - Added get_file_ext function
+ - Fixing permissions on the files & directories
+ - Fixing a bug with the include path of util.php
+

+ +

+ 1.0.5
+ - Issue #29 Fixed error in var_dump if mbstring extension wasn't present
+ - Adding Composer support
+ - Updating license from GPL to MIT
+ - Adding Changelog to project
+ - Bumping minimum version to PHP 5.3.3
+

+ +

+ 1.0.4
+ - Issue #22 Removed all superglobal *_get functions, you can use the modified array_get now
+ - Issue #22 Modifed the behaviour of array_get, see documentation
+ - Pull Request #21 Added multibyte support to html* functions
+ - Issue #9 Removed the str_to_utf8 function
+ - Issue #3 Removed the absint function
+ - Removed declare() from util.php to avoid errors
+ - Updated PHPUnit tests to use PHPUnit 3.6 +

+ +

+ 1.0.3
+ - Issue #16 Improved performance of slugify
+ - Issue #14 Modified the regex for seems_utf8 to be more accurate
+ - Issue #13 Changed validate_email to be wrapper for filter_var
+ - Added 'ok' to the list of yes words for str_to_bool
+ - str_to_bool matches no followed by any number of 'o's +

+ +

+ 1.0.2
+ - Issue #12 get_current_url now includes the port and user/password if required
+ - Issue #11 human_time_diff now uses the DateTime functions
+ - Issue #10 is_https no longer checks the port as well +

+ +

+ 1.0.1
+ - Issue #7 Added the $trust_proxy_headers parameter to get_client_ip
+ - Issue #6 Removed is_isset as the function did not work as intended
+ - Issue #6 Removed is_empty as it is redundant, use ! with function calls instead
+ - Fixed a bug with get_gravatar +

+ +

+ 1.0.0
+ Initial release of util.php. +

+
+
+ + + diff --git a/e_lib/utilphp-1.1.0/phpunit.xml.dist b/e_lib/utilphp-1.1.0/phpunit.xml.dist new file mode 100644 index 00000000..d4b9366c --- /dev/null +++ b/e_lib/utilphp-1.1.0/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + ./tests + + + + + ./src + + + + + + \ No newline at end of file diff --git a/e_lib/utilphp-1.1.0/tests/README.md b/e_lib/utilphp-1.1.0/tests/README.md new file mode 100644 index 00000000..e81d26c3 --- /dev/null +++ b/e_lib/utilphp-1.1.0/tests/README.md @@ -0,0 +1,39 @@ +# UtilityPHP Unit Tests # + +### Introduction + +This is the testing documentation for util.php. The unit tests require PHPUnit, +and can be run in your web browser. + +### Requirements + +PHP Unit >= 3.5.6 + +#### Installation of PHPUnit + + # Download the PHPUnit phar. + wget https://phar.phpunit.de/phpunit.phar + + # You can just run it locally. (Preferred for Windows) + php phpunit.phar --version + + # Or install it system-wide. + mv phpunit.phar phpunit + chmod +x phpunit + sudo mv phpunit /usr/local/bin + phpunit --version + +## Test Suites: + +util.php includes a phpunit config file, so just run `phpunit` from the working +directory to run the test suite. + +``` +phpunit +``` + +If you want code coverage reports, use the following: + +``` +phpunit --coverage-html ./report +``` diff --git a/e_lib/utilphp-1.1.0/tests/UtilTest.php b/e_lib/utilphp-1.1.0/tests/UtilTest.php new file mode 100644 index 00000000..404cf7bd --- /dev/null +++ b/e_lib/utilphp-1.1.0/tests/UtilTest.php @@ -0,0 +1,1183 @@ +data = (object)array('a', 'b', 'c'); + } +} + +/** + * PHPUnit test case for the util.php library + * + * @author Brandon Wamboldt + * @since 1.0.000 + */ +class UtilityPHPTest extends PHPUnit_Framework_TestCase +{ + /** + * Allows for the testing of private and protected methods. + * + * @param $name + * @return \ReflectionMethod + */ + protected static function getMethod($name) + { + $class = new \ReflectionClass('util'); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; + } + + public function test_array_get() + { + $_GET = array(); + $_GET['abc'] = 'def'; + $_GET['nested'] = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3' ); + + // Looks for $array['abc'] + $this->assertEquals( 'def', util::array_get( $_GET['abc'] ) ); + + // Looks for $array['nested']['key2'] + $this->assertEquals( 'val2', util::array_get( $_GET['nested']['key2'] ) ); + + // Looks for $array['doesnotexist'] + $this->assertEquals( 'defaultval', util::array_get( $_GET['doesnotexist'], 'defaultval' ) ); + } + + public function test_slugify() + { + $this->assertEquals( 'a-simple-title', util::slugify( 'A simple title' ) ); + $this->assertEquals( 'this-post-it-has-a-dash', util::slugify( 'This post -- it has a dash' ) ); + $this->assertEquals( '123-1251251', util::slugify( '123----1251251' ) ); + $this->assertEquals( 'one23-1251251', util::slugify( '123----1251251', '-', true ) ); + + $this->assertEquals( 'a-simple-title', util::slugify( 'A simple title', '-' ) ); + $this->assertEquals( 'this-post-it-has-a-dash', util::slugify( 'This post -- it has a dash', '-' ) ); + $this->assertEquals( '123-1251251', util::slugify( '123----1251251', '-' ) ); + $this->assertEquals( 'one23-1251251', util::slugify( '123----1251251', '-', true ) ); + + $this->assertEquals( 'a_simple_title', util::slugify( 'A simple title', '_' ) ); + $this->assertEquals( 'this_post_it_has_a_dash', util::slugify( 'This post -- it has a dash', '_' ) ); + $this->assertEquals( '123_1251251', util::slugify( '123----1251251', '_' ) ); + $this->assertEquals( 'one23_1251251', util::slugify( '123----1251251', '_', true ) ); + + // Blank seperator test + $this->assertEquals( 'asimpletitle', util::slugify( 'A simple title', '' ) ); + $this->assertEquals( 'thispostithasadash', util::slugify( 'This post -- it has a dash', '' ) ); + $this->assertEquals( '1231251251', util::slugify( '123----1251251', '' ) ); + $this->assertEquals( 'one231251251', util::slugify( '123----1251251', '', true ) ); + + // Test old parameter ordering for backwards compatability + error_reporting(E_ALL ^ E_USER_DEPRECATED); + $this->assertEquals( 'one23-1251251', util::slugify( '123----1251251', true ) ); + $this->assertEquals( '123-1251251', util::slugify( '123----1251251', false ) ); + } + + public function test_seems_utf8() + { + // Test a valid UTF-8 sequence: "ÜTF-8 Fµñ". + $validUTF8 = "\xC3\x9CTF-8 F\xC2\xB5\xC3\xB1"; + $this->assertTrue( util::seems_utf8( $validUTF8 ) ); + + $this->assertTrue( util::seems_utf8( "\xEF\xBF\xBD this has \xEF\xBF\xBD\xEF\xBF\xBD some invalid utf8 \xEF\xBF\xBD" ) ); + + // Test invalid UTF-8 sequences + $invalidUTF8 = "\xc3 this has \xe6\x9d some invalid utf8 \xe6"; + $this->assertFalse( util::seems_utf8( $invalidUTF8 ) ); + + // And test some plain ASCII + $this->assertTrue( util::seems_utf8( 'The quick brown fox jumps over the lazy dog' ) ); + + // Test an invalid non-UTF-8 string. + if (function_exists('mb_convert_encoding')) { + mb_internal_encoding('UTF-8'); + // Converts the 'ç' UTF-8 character to UCS-2LE + $utf8Char = pack('n', 50087); + $ucsChar = mb_convert_encoding($utf8Char, 'UCS-2LE', 'UTF-8'); + + // Ensure that PHP's internal encoding system isn't malconfigured. + $this->assertEquals( $utf8Char, 'ç', 'This PHP system\'s internal character set is not properly set as UTF-8.' ); + $this->assertEquals( $utf8Char, pack('n', 50087), 'Something is wrong with your ICU unicode library.' ); + + // Test for not UTF-8. + $this->assertFalse( util::seems_utf8( $ucsChar) ); + + // Test the worker method. + $method = self::getMethod('seemsUtf8Regex'); + $this->assertFalse($method->invoke(null, $invalidUTF8), 'util::seemsUtf8Regex did not properly detect invalid UTF-8.'); + $this->assertTrue($method->invoke(null, $validUTF8), 'util::seemsUtf8Regex did not properly detect valid UTF-8.'); + } + } + + public function test_size_format() + { + $size = util::size_format( 512, 0 ); + $this->assertEquals( '512 B', $size ); + + $size = util::size_format( 2048, 1 ); + $this->assertEquals( '2.0 KiB', $size ); + + $size = util::size_format( 25151251, 2 ); + $this->assertEquals( '23.99 MiB', $size ); + + $size = util::size_format( 19971597926, 2 ); + $this->assertEquals( '18.60 GiB', $size ); + + $size = util::size_format( 2748779069440, 1 ); + $this->assertEquals( '2.5 TiB', $size ); + + $size = util::size_format( 2.81475e15, 1 ); + $this->assertEquals( '2.5 PiB', $size ); + + $size = util::size_format( 2.81475e19, 1 ); + $this->assertEquals( '25000.0 PiB', $size ); + } + + public function test_maybe_serialize() + { + $obj = new stdClass(); + $obj->prop1 = 'Hello'; + $obj->prop2 = 'World'; + + $this->assertEquals( 'This is a string', util::maybe_serialize( 'This is a string' ) ); + $this->assertEquals( 5.81, util::maybe_serialize( 5.81 ) ); + $this->assertEquals( 'a:0:{}', util::maybe_serialize( array() ) ); + $this->assertEquals( 'O:8:"stdClass":2:{s:5:"prop1";s:5:"Hello";s:5:"prop2";s:5:"World";}', util::maybe_serialize( $obj ) ); + $this->assertEquals( 'a:4:{i:0;s:4:"test";i:1;s:4:"blah";s:5:"hello";s:5:"world";s:5:"array";O:8:"stdClass":2:{s:5:"prop1";s:5:"Hello";s:5:"prop2";s:5:"World";}}', util::maybe_serialize( array( 'test', 'blah', 'hello' => 'world', 'array' => $obj ) ) ); + } + + public function test_maybe_unserialize() + { + $obj = new stdClass(); + $obj->prop1 = 'Hello'; + $obj->prop2 = 'World'; + + $this->assertNull(util::maybe_unserialize(serialize(null))); + $this->assertFalse(util::maybe_unserialize(serialize(false))); + + $this->assertEquals( 'This is a string', util::maybe_unserialize( 'This is a string' ) ); + $this->assertEquals( 5.81, util::maybe_unserialize( 5.81 ) ); + $this->assertEquals( array(), util::maybe_unserialize( 'a:0:{}' ) ); + $this->assertEquals( $obj, util::maybe_unserialize( 'O:8:"stdClass":2:{s:5:"prop1";s:5:"Hello";s:5:"prop2";s:5:"World";}' ) ); + $this->assertEquals( array( 'test', 'blah', 'hello' => 'world', 'array' => $obj ), util::maybe_unserialize( 'a:4:{i:0;s:4:"test";i:1;s:4:"blah";s:5:"hello";s:5:"world";s:5:"array";O:8:"stdClass":2:{s:5:"prop1";s:5:"Hello";s:5:"prop2";s:5:"World";}}' ) ); + + // Test a broken serialization. + $expectedData = array( + 'Normal', + 'High-value Char: '.chr(231).'a-va?', // High-value Char: ça-va? [in ISO-8859-1] + ); + + $brokenSerialization = 'a:2:{i:0;s:6:"Normal";i:1;s:23:"High-value Char: ▒a-va?";}'; + + $unserializedData = util::maybe_unserialize($brokenSerialization); + $this->assertEquals($expectedData[0], $unserializedData[0], 'Did not properly fix the broken serialized data.'); + $this->assertEquals(substr($expectedData[1], 0, 10), substr($unserializedData[1], 0, 10), 'Did not properly fix the broken serialized data.'); + + // Test unfixable serialization. + $unfixableSerialization = 'a:2:{i:0;s:6:"Normal";}'; + $this->assertEquals($unfixableSerialization, util::maybe_unserialize($unfixableSerialization), 'Somehow the [previously?] impossible happened and utilphp thinks it has unserialized an unfixable serialization.'); + } + + public function test_is_serialized() + { + $this->assertFalse( util::is_serialized(1) ); + $this->assertFalse( util::is_serialized(null) ); + $this->assertFalse( util::is_serialized( 's:4:"test;' ) ); + $this->assertFalse( util::is_serialized( 'a:0:{}!' ) ); + $this->assertFalse( util::is_serialized( 'a:0' ) ); + $this->assertFalse( util::is_serialized( 'This is a string' ) ); + $this->assertFalse( util::is_serialized( 'a string' ) ); + $this->assertFalse( util::is_serialized( 'z:0;' ) ); + $this->assertTrue( util::is_serialized( 'N;' ) ); + $this->assertTrue( util::is_serialized( 'b:1;' ) ); + $this->assertTrue( util::is_serialized( 'a:0:{}' ) ); + $this->assertTrue( util::is_serialized( 'O:8:"stdClass":2:{s:5:"prop1";s:5:"Hello";s:5:"prop2";s:5:"World";}' ) ); + } + + public function test_fix_broken_serialization() + { + $expectedData = array( + 'Normal', + 'High-value Char: '.chr(231).'a-va?', // High-value Char: ça-va? [in ISO-8859-1] + ); + + $brokenSerialization = 'a:2:{i:0;s:6:"Normal";i:1;s:23:"High-value Char: ▒a-va?";}'; + + // Temporarily override error handling to ensure that this is, in fact, [still] a broken serialization. + { + $expectedError = array( + 'errno' => 8, + 'errstr' => 'unserialize(): Error at offset 55 of 60 bytes' + ); + + $reportedError = array(); + set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) use (&$reportedError) { + $reportedError = compact('errno', 'errstr'); + }); + + unserialize($brokenSerialization); + + $this->assertEquals($expectedError['errno'], $reportedError['errno']); + // Because HHVM's unserialize() error message does not contain enough info to properly test. + if (!defined('HHVM_VERSION')) { + $this->assertEquals($expectedError['errstr'], $reportedError['errstr']); + } + restore_error_handler(); + } + + $fixedSerialization = util::fix_broken_serialization($brokenSerialization); + $unserializedData = unserialize($fixedSerialization); + $this->assertEquals($expectedData[0], $unserializedData[0], 'Did not properly fix the broken serialized data.'); + + $this->assertEquals(substr($expectedData[1], 0, 10), substr($unserializedData[1], 0, 10), 'Did not properly fix the broken serialized data.'); + } + + public function test_is_https() + { + $_SERVER['HTTPS'] = null; + + $this->assertFalse( util::is_https() ); + + $_SERVER['HTTPS'] = 'on'; + + $this->assertTrue( util::is_https() ); + } + + public function test_add_query_arg() + { + // Regular tests + $this->assertEquals( '/app/admin/users?user=5', util::add_query_arg( 'user', 5, '/app/admin/users' ) ); + $this->assertEquals( '/app/admin/users?user=5', util::add_query_arg( array( 'user' => 5 ), '/app/admin/users' ) ); + $this->assertEquals( '/app/admin/users?user=5', util::add_query_arg( array( 'user' => 5 ), null, '/app/admin/users' ) ); + $this->assertEquals( '/app/admin/users?action=edit&user=5', util::add_query_arg( 'user', 5, '/app/admin/users?action=edit' ) ); + $this->assertEquals( '/app/admin/users?action=edit&user=5', util::add_query_arg( array( 'user' => 5 ), '/app/admin/users?action=edit' ) ); + $this->assertEquals( '/app/admin/users?action=edit&tab=personal&user=5', util::add_query_arg( 'user', 5, '/app/admin/users?action=edit&tab=personal' ) ); + $this->assertEquals( '/app/admin/users?action=edit&tab=personal&user=5', util::add_query_arg( array( 'user' => 5 ), '/app/admin/users?action=edit&tab=personal' ) ); + + // Ensure strips false. + $this->assertEquals('/index.php', util::add_query_arg('debug', false, '/index.php')); + + // With a URL fragment + $this->assertEquals( '/app/admin/users?user=5#test', util::add_query_arg( 'user', 5, '/app/admin/users#test' ) ); + + // Full URL + $this->assertEquals( 'http://example.com/?a=b', util::add_query_arg( 'a', 'b', 'http://example.com' ) ); + + // Only the query string + $this->assertEquals( '?a=b&c=d', util::add_query_arg( 'c', 'd', '?a=b' ) ); + $this->assertEquals( 'a=b&c=d', util::add_query_arg( 'c', 'd', 'a=b' ) ); + + // Url encoding test + $this->assertEquals( '/app/admin/users?param=containsa%26sym', util::add_query_arg( 'param', 'containsa&sym', '/app/admin/users' ) ); + + // If not provided, grab the URI from the server. + $_SERVER['REQUEST_URI'] = '/app/admin/users'; + $this->assertEquals( '/app/admin/users?user=6', util::add_query_arg( array( 'user' => 6 ) ) ); + $this->assertEquals( '/app/admin/users?user=7', util::add_query_arg( 'user', 7 ) ); + } + + public function test_remove_query_arg() + { + $this->assertEquals( '/app/admin/users', util::remove_query_arg( 'user', '/app/admin/users?user=5' ) ); + $this->assertEquals( '/app/admin/users?action=edit', util::remove_query_arg( 'user', '/app/admin/users?action=edit&user=5' ) ); + $this->assertEquals( '/app/admin/users?user=5', util::remove_query_arg( array( 'tab', 'action' ), '/app/admin/users?action=edit&tab=personal&user=5' ) ); + } + + public function test_http_build_url() + { + $url = 'http://user:pass@example.com:8080/path/?query#fragment'; + + $expected = 'http://example.com/'; + $actual = util::http_build_url($url, array(), util::HTTP_URL_STRIP_ALL); + $this->assertEquals($expected, $actual); + + $expected = 'http://example.com:8080/path/?query#fragment'; + $actual = util::http_build_url($url, array(), util::HTTP_URL_STRIP_AUTH); + $this->assertEquals($expected, $actual); + + $this->assertEquals('https://dev.example.com/', util::http_build_url('http://example.com/', array('scheme' => 'https', 'host' => 'dev.example.com'))); + $this->assertEquals('http://example.com/#hi', util::http_build_url('http://example.com/', array('fragment' => 'hi'), util::HTTP_URL_REPLACE)); + $this->assertEquals('http://example.com/page', util::http_build_url('http://example.com/', array('path' => 'page'), util::HTTP_URL_JOIN_PATH)); + $this->assertEquals('http://example.com/page', util::http_build_url('http://example.com', array('path' => 'page'), util::HTTP_URL_JOIN_PATH)); + $this->assertEquals('http://example.com/?hi=Bro', util::http_build_url('http://example.com/', array('query' => 'hi=Bro'), util::HTTP_URL_JOIN_QUERY)); + $this->assertEquals('http://example.com/?show=1&hi=Bro', util::http_build_url('http://example.com/?show=1', array('query' => 'hi=Bro'), util::HTTP_URL_JOIN_QUERY)); + + $this->assertEquals('http://admin@example.com/', util::http_build_url('http://example.com/', array('user' => 'admin'))); + $this->assertEquals('http://admin:1@example.com/', util::http_build_url('http://example.com/', array('user' => 'admin', 'pass' => '1'))); + } + + public function test_str_to_bool() + { + $this->assertTrue( util::str_to_bool( 'true' ) ); + $this->assertTrue( util::str_to_bool( 'yes' ) ); + $this->assertTrue( util::str_to_bool( 'y' ) ); + $this->assertTrue( util::str_to_bool( 'oui' ) ); + $this->assertTrue( util::str_to_bool( 'vrai' ) ); + + $this->assertFalse( util::str_to_bool( 'false' ) ); + $this->assertFalse( util::str_to_bool( 'no' ) ); + $this->assertFalse( util::str_to_bool( 'n' ) ); + $this->assertFalse( util::str_to_bool( 'non' ) ); + $this->assertFalse( util::str_to_bool( 'faux' ) ); + + $this->assertFalse( util::str_to_bool( 'test' , false) ); + + } + + public function test_array_pluck() + { + $array = array( + array( + 'name' => 'Bob', + 'age' => 37 + ), + array( + 'name' => 'Fred', + 'age' => 37 + ), + array( + 'name' => 'Jane', + 'age' => 29 + ), + array( + 'name' => 'Brandon', + 'age' => 20 + ), + array( + 'age' => 41 + ) + ); + + $obj_array = array( + 'bob' => (object) array( + 'name' => 'Bob', + 'age' => 37 + ), + 'fred' => (object) array( + 'name' => 'Fred', + 'age' => 37 + ), + 'jane' => (object) array( + 'name' => 'Jane', + 'age' => 29 + ), + 'brandon' => (object) array( + 'name' => 'Brandon', + 'age' => 20 + ), + 'invalid' => (object) array( + 'age' => 41 + ) + ); + + $obj_array_expect = array( + 'bob' => 'Bob', + 'fred' => 'Fred', + 'jane' => 'Jane', + 'brandon' => 'Brandon' + ); + + $this->assertEquals( array( 'Bob', 'Fred', 'Jane', 'Brandon' ), util::array_pluck( $array, 'name' ) ); + $this->assertEquals( array( 'Bob', 'Fred', 'Jane', 'Brandon', array( 'age' => 41 ) ), util::array_pluck( $array, 'name', TRUE, FALSE ) ); + $this->assertEquals( $obj_array_expect, util::array_pluck( $obj_array, 'name' ) ); + $this->assertEquals( array( 'Bob', 'Fred', 'Jane', 'Brandon' ), util::array_pluck( $obj_array, 'name', FALSE ) ); + + $expected = array('Bob', 'Fred', 'Jane', 'Brandon', 'invalid' => (object)array('age' => 41)); + $this->assertEquals($expected, util::array_pluck($obj_array, 'name', FALSE, FALSE)); + $expected = array('Bob', 'Fred', 'Jane', 'Brandon', array('age' => 41)); + $this->assertEquals($expected, util::array_pluck($array, 'name', false, false)); + } + + public function test_htmlentities() + { + $this->assertEquals( 'One & Two', util::htmlentities( 'One & Two' ) ); + $this->assertEquals( 'One & Two', util::htmlentities( 'One & Two', TRUE ) ); + } + + public function test_htmlspecialchars() + { + $this->assertEquals( 'One & Two', util::htmlspecialchars( 'One & Two' ) ); + $this->assertEquals( 'One & Two', util::htmlspecialchars( 'One & Two', TRUE ) ); + } + + public function test_remove_accents() + { + $this->assertEquals( 'A', util::remove_accents( "\xC3\x81" ) ); + $this->assertEquals( 'e', util::remove_accents( "\xC4\x97" ) ); + $this->assertEquals( 'U', util::remove_accents( "\xC3\x9C" ) ); + $this->assertEquals( 'Ae', util::remove_accents( "Ä", 'de' ) ); + $this->assertEquals( 'OEoeAEDHTHssaedhth', util::remove_accents(chr(140) . chr(156) . chr(198) . chr(208) . chr(222) . chr(223) . chr(230) . chr(240) . chr(254))); + } + + public function test_zero_pad() + { + $this->assertEquals( '00000341', util::zero_pad( 341, 8 ) ); + $this->assertEquals( '341', util::zero_pad( 341, 1 ) ); + } + + public function test_human_time_diff() + { + $this->assertEquals( '1 second ago', util::human_time_diff( time() - 1 ) ); + $this->assertEquals( '30 seconds ago', util::human_time_diff( time() - 30 ) ); + $this->assertEquals( '1 minute ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MINUTE * 1.4 ) ) ); + $this->assertEquals( '5 minutes ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MINUTE * 5 ) ) ); + $this->assertEquals( '1 hour ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR ) ) ); + $this->assertEquals( '2 hours ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR * 2 ) ) ); + $this->assertEquals( '1 day ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR * 24 ) ) ); + $this->assertEquals( '5 days ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR * 24 * 5 ) ) ); + $this->assertEquals( '1 week ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR * 24 * 7 ) ) ); + $this->assertEquals( '2 weeks ago', util::human_time_diff( time() - ( util::SECONDS_IN_AN_HOUR * 24 * 14 ) ) ); + $this->assertEquals( '1 month ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_WEEK * 5 ) ) ); + $this->assertEquals( '2 months ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_WEEK * 10 ) ) ); + $this->assertEquals( '1 year ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MONTH * 15 ) ) ); + $this->assertEquals( '2 years ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MONTH * 36 ) ) ); + $this->assertEquals( '11 years ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MONTH * 140 ) ) ); + + $this->assertEquals( 'fifteen minutes ago', util::human_time_diff( time() - ( util::SECONDS_IN_A_MINUTE * 15 ), '', TRUE ) ); + } + + public function test_number_to_word() + { + try { + util::number_to_word('junk data'); + $this->fail('Accepted junk data'); + } catch(\LogicException $e) { + $this->assertEquals('Not a number', $e->getMessage()); + } + + // Partially numeric. + $this->assertEquals('', util::number_to_word('1a')); + + // Decimals + $this->assertEquals( 'five point zero five', util::number_to_word('5.05') ); + $this->assertEquals( 'zero point eight', util::number_to_word( 0.8 ) ); + + // Integers + $this->assertEquals( 'positive one', util::number_to_word( '+1' ) ); + $this->assertEquals( 'negative twelve', util::number_to_word( -12 ) ); + $this->assertEquals( 'one', util::number_to_word( 1 ) ); + $this->assertEquals( 'five', util::number_to_word( 5 ) ); + $this->assertEquals( 'fifteen', util::number_to_word( 15 ) ); + $this->assertEquals( 'twenty-one', util::number_to_word( 21 ) ); + $this->assertEquals( 'thirty-two', util::number_to_word( 32 ) ); + $this->assertEquals( 'forty-three', util::number_to_word( 43 ) ); + $this->assertEquals( 'fifty-four', util::number_to_word( 54 ) ); + $this->assertEquals( 'sixty-six', util::number_to_word( 66 ) ); + $this->assertEquals( 'seventy-seven', util::number_to_word( 77 ) ); + $this->assertEquals( 'eighty-eight', util::number_to_word( 88 ) ); + $this->assertEquals( 'ninety-nine', util::number_to_word( 99 ) ); + $this->assertEquals( 'one hundred and thirty-six', util::number_to_word( 136 ) ); + $this->assertEquals( 'ten', util::number_to_word( 10 ) ); + $this->assertEquals( 'twenty', util::number_to_word( 20 ) ); + $this->assertEquals( 'thirty', util::number_to_word( 30 ) ); + $this->assertEquals( 'forty', util::number_to_word( 40 ) ); + $this->assertEquals( 'fifty', util::number_to_word( 50 ) ); + $this->assertEquals( 'sixty', util::number_to_word( 60 ) ); + $this->assertEquals( 'seventy', util::number_to_word( 70 ) ); + $this->assertEquals( 'eighty', util::number_to_word( 80 ) ); + $this->assertEquals( 'ninety', util::number_to_word( 90 ) ); + $this->assertEquals( 'eleven', util::number_to_word( 11 ) ); + $this->assertEquals( 'thirteen', util::number_to_word( 13 ) ); + $this->assertEquals( 'fourteen', util::number_to_word( 14 ) ); + $this->assertEquals( 'fifteen', util::number_to_word( 15 ) ); + $this->assertEquals( 'sixteen', util::number_to_word( 16 ) ); + $this->assertEquals( 'seventeen', util::number_to_word( 17 ) ); + $this->assertEquals( 'eighteen', util::number_to_word( 18 ) ); + $this->assertEquals( 'nineteen', util::number_to_word( 19 ) ); + $this->assertEquals( 'one thousand', util::number_to_word( 1000 ) ); + $this->assertEquals( 'one million', util::number_to_word( 1000000 ) ); + $this->assertEquals( 'one billion', util::number_to_word( 1000000000 ) ); + $this->assertEquals( 'one trillion', util::number_to_word( 1000000000000 ) ); + $this->assertEquals( 'one quadrillion', util::number_to_word( '1000000000000000' ) ); + $this->assertEquals( 'one quintrillion', util::number_to_word( '1000000000000000000' ) ); + $this->assertEquals( 'one sextillion', util::number_to_word( '1000000000000000000000' ) ); + $this->assertEquals( 'one septillion', util::number_to_word( '1000000000000000000000000' ) ); + $this->assertEquals( 'one octillion', util::number_to_word( '1000000000000000000000000000' ) ); + $this->assertEquals( 'one nonillion', util::number_to_word( '1000000000000000000000000000000' ) ); + $this->assertEquals( 'one decillion', util::number_to_word( '1000000000000000000000000000000000' ) ); + $this->assertEquals( 'one', util::number_to_word( '1000000000000000000000000000000000000000000' ) ); + + } + + public function test_array_search_deep() + { + $users = array( + 1 => (object) array( 'username' => 'brandon', 'age' => 20 ), + 2 => (object) array( 'username' => 'matt', 'age' => 27 ), + 3 => (object) array( 'username' => 'jane', 'age' => 53 ), + 4 => (object) array( 'username' => 'john', 'age' => 41 ), + 5 => (object) array( 'username' => 'steve', 'age' => 11 ), + 6 => (object) array( 'username' => 'fred', 'age' => 42 ), + 7 => (object) array( 'username' => 'rasmus', 'age' => 21 ), + 8 => (object) array( 'username' => 'don', 'age' => 15 ), + 9 => array( 'username' => 'darcy', 'age' => 33 ), + ); + + $test = array( + 1 => 'brandon', + 2 => 'devon', + 3 => array( 'troy' ), + 4 => 'annie' + ); + + $this->assertFalse( util::array_search_deep( $test, 'bob' ) ); + $this->assertEquals( 3, util::array_search_deep( $test, 'troy' ) ); + $this->assertEquals( 4, util::array_search_deep( $test, 'annie' ) ); + $this->assertEquals( 2, util::array_search_deep( $test, 'devon', 'devon' ) ); + $this->assertEquals( 7, util::array_search_deep( $users, 'rasmus', 'username' ) ); + $this->assertEquals( 9, util::array_search_deep( $users, 'darcy', 'username' ) ); + $this->assertEquals( 1, util::array_search_deep( $users, 'brandon' ) ); + } + + public function test_array_map_deep() + { + $input = array( + '<', + 'abc', + '>', + 'def', + array( '&', 'test', '123' ), + (object) array( 'hey', '<>' ) + ); + + $expect = array( + '<', + 'abc', + '>', + 'def', + array( '&', 'test', '123' ), + (object) array( 'hey', '<>' ) + ); + + $this->assertEquals( $expect, util::array_map_deep( $input, 'htmlentities' ) ); + } + + public function test_random_string() + { + // Make sure the generated string contains only human friendly characters and is 30 characters long + $str = util::random_string( 30 ); + $this->assertTrue( (bool) preg_match( '/^([ABCDEFGHJKLMNPQRSTUVWXYZabcdefhjkmnprstuvwxyz23456789]{30})$/', $str ) ); + + // Make sure the generated string is 30 characters long + $str = util::random_string( 30, false, true ); + $this->assertTrue( strlen( $str ) === 30, 'random_string produced an invalid length string' ); + + // Make sure the generated string is 120 characters long + $str = util::random_string( 120 ); + $this->assertTrue(strlen( $str ) === 120, 'random_string produced an invalid length string'); + + // Make sure the string doesn't contain duplicate letters + $str = util::random_string( 53, true, false, true ); + $this->assertTrue(strlen($str) === 53, 'random_string produced an invalid length string'); + $this->assertTrue(count(array_unique(str_split($str))) === strlen($str), 'random_string produced a string with duplicate characters'); + + // Longer length than characters available + try { + $str = util::random_string( 55, true, false, true ); + $this->assertTrue( false ); + } catch (Exception $e) { + $this->assertTrue( true ); + } + + // Test secure variant + $str = util::secure_random_string(16); + $this->assertTrue(strlen($str) === 16); + + // Longer length than characters available + try { + $str = util::secure_random_string(0); + $this->assertTrue(false); + } catch (Exception $e) { + $this->assertTrue(true); + } + } + + public function test_match_string() + { + $this->assertTrue( util::match_string('a', 'a') ); + $this->assertFalse( util::match_string('a', ' a') ); + $this->assertFalse( util::match_string('/', '/something') ); + $this->assertTrue( util::match_string('test/*', 'test/first/second') ); + $this->assertTrue( util::match_string('*/test', 'first/second/test') ); + $this->assertFalse( util::match_string('first/', 'first/second/test') ); + $this->assertFalse( util::match_string('test', 'TEST') ); + $this->assertTrue( util::match_string('test', 'TEST', false) ); + } + + public function test_validate_email() + { + $this->assertTrue( util::validate_email( 'john.smith@gmail.com' ) ); + $this->assertTrue( util::validate_email( 'john.smith+label@gmail.com' ) ); + $this->assertTrue( util::validate_email( 'john.smith@gmail.co.uk' ) ); + } + + public function test_safe_truncate() + { + $this->assertEquals( 'The quick brown fox...', util::safe_truncate( 'The quick brown fox jumps over the lazy dog', 24 ) ); + $this->assertEquals( 'The quick brown fox jumps over the lazy dog', util::safe_truncate( 'The quick brown fox jumps over the lazy dog', 55 ) ); + $this->assertEquals( 'Th...', util::safe_truncate( 'The quick brown fox jumps over the lazy dog', 2 ) ); + $this->assertEquals( 'The...', util::safe_truncate( 'The quick brown fox jumps over the lazy dog', 3 ) ); + $this->assertEquals( 'The...', util::safe_truncate( 'The quick brown fox jumps over the lazy dog', 7 ) ); + } + + public function test_limit_characters() + { + $this->assertEquals( 'The quick brown fox jump...', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 24 ) ); + $this->assertEquals( 'The quick brown fox jumps over the lazy dog', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 55 ) ); + $this->assertEquals( 'Th...', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 2 ) ); + $this->assertEquals( 'The...', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 3 ) ); + $this->assertEquals( 'The qui...', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 7 ) ); + $this->assertEquals( 'The quick brown fox jumps over the lazy dog', util::limit_characters( 'The quick brown fox jumps over the lazy dog', 150 ) ); + } + + public function test_limit_words() + { + $this->assertEquals( 'The quick brown...', util::limit_words( 'The quick brown fox jumps over the lazy dog', 3 ) ); + $this->assertEquals( 'The quick brown fox jumps...', util::limit_words( 'The quick brown fox jumps over the lazy dog', 5 ) ); + $this->assertEquals( 'The...', util::limit_words( 'The quick brown fox jumps over the lazy dog', 1 ) ); + $this->assertEquals( 'The quick brown fox jumps over the lazy dog', util::limit_words( 'The quick brown fox jumps over the lazy dog', 90 ) ); + $this->assertEquals( 'The quick brown fox jumps over the...', util::limit_words( 'The quick brown fox jumps over the lazy dog', 7 ) ); + } + + public function test_ordinal() + { + $this->assertEquals( '1st', util::ordinal( 1 ) ); + $this->assertEquals( '2nd', util::ordinal( 2 ) ); + $this->assertEquals( '3rd', util::ordinal( 3 ) ); + $this->assertEquals( '4th', util::ordinal( 4 ) ); + $this->assertEquals( '5th', util::ordinal( 5 ) ); + $this->assertEquals( '6th', util::ordinal( 6 ) ); + $this->assertEquals( '7th', util::ordinal( 7 ) ); + $this->assertEquals( '8th', util::ordinal( 8 ) ); + $this->assertEquals( '9th', util::ordinal( 9 ) ); + $this->assertEquals( '22nd', util::ordinal( 22 ) ); + $this->assertEquals( '23rd', util::ordinal( 23 ) ); + $this->assertEquals( '143rd', util::ordinal( 143 ) ); + } + + public function test_array_first() + { + $test = array( 'a' => array( 'a', 'b', 'c' ) ); + + $this->assertEquals( 'a', util::array_first( util::array_get( $test['a'] ) ) ); + } + + public function test_array_first_key() + { + $test = array( 'a' => array( 'a' => 'b', 'c' => 'd' ) ); + + $this->assertEquals( 'a', util::array_first_key( util::array_get( $test['a'] ) ) ); + } + + public function test_array_last() + { + $test = array( 'a' => array( 'a', 'b', 'c' ) ); + + $this->assertEquals( 'c', util::array_last( util::array_get( $test['a'] ) ) ); + } + + public function test_array_last_key() + { + $test = array( 'a' => array( 'a' => 'b', 'c' => 'd' ) ); + + $this->assertEquals( 'c', util::array_last_key( util::array_get( $test['a'] ) ) ); + } + + public function test_array_flatten() + { + $input = array( 'a', 'b', 'c', 'd', array( 'first' => 'e', 'f', 'second' => 'g', array( 'h', 'third' => 'i', array( array( array( array( 'j', 'k', 'l' ) ) ) ) ) ) ); + $expectNoKeys = range( 'a', 'l' ); + $expectWithKeys = array( + 'a', 'b', 'c', 'd', + 'first' => 'e', + 'f', + 'second' => 'g', + 'h', + 'third' => 'i', + 'j', 'k', 'l' + ); + + $this->assertEquals( $expectWithKeys, util::array_flatten( $input ) ); + $this->assertEquals( $expectNoKeys, util::array_flatten( $input, false ) ); + $this->assertEquals( $expectWithKeys, util::array_flatten( $input, true ) ); + } + + public function test_strip_space() + { + $input = ' The quick brown fox jumps over the lazy dog '; + $expect = 'Thequickbrownfoxjumpsoverthelazydog'; + + $this->assertEquals($expect, Util::strip_space($input)); + } + + public function test_sanitize_string() + { + $input = ' Benoit! à New-York? j’ai perçu 1 % : Qu’as-tu "gagné" chez M. V. Noël? Dix francs.'; + $expect = 'benoitanewyorkjaipercu1quastugagnechezmvnoeldixfrancs'; + + $this->assertEquals($expect, Util::sanitize_string($input)); + } + + public function test_get_gravatar() + { + $_SERVER['HTTPS'] = 'on'; + $this->assertEquals('https://secure.gravatar.com/avatar/a4bf5bbb9feaa2713d99a3b52ab80024?s=32', util::get_gravatar('john.doe@example.org')); + $this->assertEquals('https://secure.gravatar.com/avatar/a4bf5bbb9feaa2713d99a3b52ab80024?s=128', util::get_gravatar('john.doe@example.org', 128)); + + $_SERVER['HTTPS'] = 'off'; + $this->assertEquals('http://www.gravatar.com/avatar/a4bf5bbb9feaa2713d99a3b52ab80024?s=32', util::get_gravatar('john.doe@example.org')); + $this->assertEquals('http://www.gravatar.com/avatar/a4bf5bbb9feaa2713d99a3b52ab80024?s=128', util::get_gravatar('john.doe@example.org', 128)); + } + + public function test_get_client_ip() + { + $_SERVER['REMOTE_ADDR'] = '192.168.30.152'; + $_SERVER['HTTP_CLIENT_IP'] = '192.168.30.153'; + $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.30.154'; + $this->assertEquals('192.168.30.152', util::get_client_ip()); + $this->assertEquals('192.168.30.153', util::get_client_ip(true)); + + unset($_SERVER['HTTP_CLIENT_IP']); + $this->assertEquals('192.168.30.154', util::get_client_ip(true)); + unset($_SERVER['HTTP_X_FORWARDED_FOR']); + $this->assertEquals('192.168.30.152', util::get_client_ip(true)); + } + + public function test_full_permissions() + { + // Text a non-existant file. + $this->assertFalse(util::full_permissions('faker-123.blah'), 'Gave a permission value for a non-existant file.'); + + // Test an existing file. + $expected = '-rw-rw-rw-'; + $tempFile = tempnam(sys_get_temp_dir(), 'foo'); + $this->assertTrue(chmod($tempFile, 0666), 'Oops. Could not change temp file\'s permissions to 0666.'); + $this->assertEquals($expected, util::full_permissions($tempFile), 'Could not properly obtain permissions of an existing file.'); + unlink($tempFile); + + $this->assertEquals('lr--r--r--', util::full_permissions('fake-file-222', octdec('120444'))); + $this->assertEquals('ur--r--r--', util::full_permissions('fake-file-222', octdec('000444'))); + $this->assertEquals('srwxr-xr-x', util::full_permissions('fake-file-222', octdec('140755'))); + $this->assertEquals('drwxr-xr-x', util::full_permissions('fake-file-222', octdec('40755'))); + $this->assertEquals('brw-rw----', util::full_permissions('fake-file-222', octdec('60660'))); + $this->assertEquals('crw-rw----', util::full_permissions('fake-file-222', octdec('20660'))); + $this->assertEquals('prw-rw----', util::full_permissions('fake-file-222', octdec('10660'))); + $this->assertEquals('---x------', util::full_permissions('fake-file-222', octdec('100100'))); + $this->assertEquals('--w-------', util::full_permissions('fake-file-222', octdec('100200'))); + $this->assertEquals('--wx------', util::full_permissions('fake-file-222', octdec('100300'))); + $this->assertEquals('-r--------', util::full_permissions('fake-file-222', octdec('100400'))); + $this->assertEquals('-r-x------', util::full_permissions('fake-file-222', octdec('100500'))); + $this->assertEquals('-rw-------', util::full_permissions('fake-file-222', octdec('100600'))); + $this->assertEquals('-rwx------', util::full_permissions('fake-file-222', octdec('100700'))); + + // Windows does not have the concept of /. + if (!defined('PHP_WINDOWS_VERSION_MAJOR')) { + $this->assertEquals('drwxr-xr-x', util::full_permissions('/')); + } + } + + public function test_array_clean() + { + $input = array( 'a', 'b', '', null, false, 0); + $expect = array('a', 'b'); + $this->assertEquals($expect, Util::array_clean($input)); + } + + public function test_var_dump_plain() + { + $input = 'var'; + $expect = 'string(3) "var"'; + $this->assertEquals($expect, Util::var_dump_plain($input, true)); + + $input = true; + $expect = 'bool(true)'; + $this->assertEquals($expect, Util::var_dump_plain($input, true)); + + $input = 1; + $expect = 'int(1)'; + $this->assertEquals($expect, Util::var_dump_plain($input, true)); + + $input = 1.5; + $expect = 'float(1.5)'; + $this->assertEquals($expect, Util::var_dump_plain($input, true)); + + $input = null; + $expect = 'NULL'; + $this->assertEquals($expect, Util::var_dump_plain($input, true)); + + $input = fopen('php://memory', 'r'); + $expect = 'resource("stream") "' . $input . '"'; + $this->assertEquals($expect, Util::var_dump_plain($input, -1)); + fclose($input); + + // Test complex arrays. + $input = array(1, 2, 4, 6, 10 => 20, 100 => 200); + $actual = util::var_dump_plain($input, true); + $this->assertContains(')', $actual); + + // Test complex objects. + $experiment = new VarDumpExperiment(); + $actual = util::var_dump_plain($experiment, true); + $this->assertContains('1 => string(1', $actual); + } + + public function test_var_dump() + { + $input = 'var'; + $expect = '
string(3) "var"
'; + + // Ensure the proper output is returned + $this->assertEquals($expect, Util::var_dump($input, true)); + + // Ensure the proper output is actually outputted + $this->expectOutputString($expect); + util::var_dump($input); + + // Ensure we avoid infinite recursion on recursive arrays + $a = array('a' => 'value a', 'b' => 'value b'); + $b = array('test' => &$a); + $c = array('a' => &$a, 'b' => &$b); + $a['c'] = &$c; + $b['c'] = &$c; + $this->assertContains('*RECURSION DETECTED*', Util::var_dump($c, true)); + + // Ensure we avoid infinite recursion on recursive objects + $a = (object) array('a' => 'value a', 'b' => 'value b'); + $b = (object) array('test' => &$a); + $c = (object) array('a' => &$a, 'b' => &$b); + $a->c = &$c; + $b->c = &$c; + $this->assertContains('*RECURSION DETECTED*', Util::var_dump($c, true)); + + // Test class scoping. + $experiment = new VarDumpExperiment(); + $actual = util::var_dump($experiment, true); + + $snippet = substr($actual, strrpos($actual, 'display:inline')); + $this->assertContains('"public"', $snippet); + $this->assertContains('"protected:protected"', $snippet); + $this->assertContains('"private:VarDumpExperiment:private"', $actual); + } + + public function test_linkify() + { + $input = 'great websites: http://www.google.com?param=test and http://yahoo.com/a/nested/folder'; + $expect = 'great websites: http://www.google.com?param=test and http://yahoo.com/a/nested/folder'; + $this->assertEquals($expect, Util::linkify($input)); + + $this->assertEquals($expect, util::linkify($expect), 'linkify() tried to double linkify an href.'); + } + + public function test_start_with() + { + $this->assertTrue(Util::starts_with('start a string', 'start a')); + $this->assertFalse(Util::starts_with('start a string', 'string')); + } + + public function test_end_with() + { + $this->assertTrue(Util::ends_with('start a string', 'a string')); + $this->assertFalse(Util::ends_with('start a string', 'start')); + } + + public function test_contains() + { + $this->assertTrue(Util::str_contains('start a string', 'a string')); + $this->assertFalse(Util::str_contains('start a string', 'Start')); + } + + public function test_iContains() + { + $this->assertTrue(Util::str_icontains('start a string', 'a string')); + $this->assertTrue(Util::str_icontains('start a string', 'Start')); + } + + public function test_get_file_ext() + { + $input = 'a_pdf_fil.pdf'; + $expect = 'pdf'; + $this->assertEquals($expect, Util::get_file_ext($input)); + } + + public function test_rmdir() + { + $dirname = dirname(__FILE__); + + // Test deleting a non-existant directory + $this->assertFalse(file_exists($dirname . '/test1')); + $this->assertTrue(util::rmdir($dirname . '/test1')); + + // Test deleting an empty directory + $dir = $dirname . '/test2'; + mkdir($dir); + + $this->assertTrue(is_dir($dir)); + + if (is_dir($dir)) { + util::rmdir($dir); + $this->assertFalse(is_dir($dir)); + } + + // Test deleting a non-empty directory + $dir = $dirname . '/test3'; + $file = $dirname . '/test3/test.txt'; + mkdir($dir); + touch($file); + + $this->assertTrue(is_dir($dir)); + $this->assertTrue(is_file($file)); + + if (is_dir($dir)) { + util::rmdir($dir); + $this->assertFalse(is_dir($dir)); + $this->assertFalse(is_file($file)); + } + + // Test deleting a non-directory path + $file = $dirname . '/test4.txt'; + touch($file); + + try { + $str = util::rmdir($file); + $this->assertTrue(false); + } catch (\Exception $e) { + $this->assertTrue(true); + } + + unlink($file); + + // Test deleting a nested directory + $dir1 = $dirname . '/test5'; + $dir2 = $dirname . '/test5/nested_dir'; + $file1 = $dir1 . '/file1.txt'; + $file2 = $dir2 . '/file2.txt'; + mkdir($dir1); + mkdir($dir2); + touch($file1); + touch($file2); + + $this->assertTrue(is_dir($dir1)); + $this->assertTrue(is_dir($dir2)); + $this->assertTrue(is_file($file1)); + $this->assertTrue(is_file($file2)); + + if (is_dir($dir1)) { + util::rmdir($dir1); + $this->assertFalse(is_dir($dir1)); + $this->assertFalse(is_dir($dir2)); + $this->assertFalse(is_file($file1)); + $this->assertFalse(is_file($file2)); + } + + // Test symlink traversal. + $dir = $dirname . '/test6'; + $nestedDir = "$dir/nested"; + $symlink = "$dir/nested-symlink"; + + mkdir($dir); + mkdir($nestedDir); + + $symlinkStatus = symlink($nestedDir, $symlink); + $this->assertTrue($symlinkStatus, 'The test system does not support making symlinks.'); + + if (!$symlink) { + return; + } + + $this->assertTrue(util::rmdir($symlink, true), 'Could not delete a symlinked directory.'); + $this->assertFalse(file_exists($symlink), 'Could not delete a symlinked directory.'); + util::rmdir($dir, true); + $this->assertFalse(is_dir($dir), 'Could not delete a directory with a symlinked directory inside of it.'); + } + + public function test_get_current_url() + { + $expected = 'http://test.dev/test.php?foo=bar'; + $expectedAuth = 'http://admin:123@test.dev/test.php?foo=bar'; + $expectedPort = 'http://test.dev:443/test.php?foo=bar'; + $expectedPort2 = 'https://test.dev:80/test.php?foo=bar'; + $expectedSSL = 'https://test.dev/test.php?foo=bar'; + + $_SERVER['HTTP_HOST'] = 'test.dev'; + $_SERVER['SERVER_PORT'] = 80; + $_SERVER['REQUEST_URI'] = '/test.php?foo=bar'; + $_SERVER['QUERY_STRING'] = 'foo=bar'; + $_SERVER['PHP_SELF'] = '/test.php'; + + // Test regular. + $this->assertEquals($expected, util::get_current_url()); + + // Test server auth. + $_SERVER['PHP_AUTH_USER'] = 'admin'; + $_SERVER['PHP_AUTH_PW'] = '123'; + $this->assertEquals($expectedAuth, util::get_current_url()); + unset($_SERVER['PHP_AUTH_USER']); + unset($_SERVER['PHP_AUTH_PW']); + + // Test port. + $_SERVER['SERVER_PORT'] = 443; + $this->assertEquals($expectedPort, util::get_current_url()); + + // Test SSL. + $_SERVER['HTTPS'] = 'on'; + $this->assertEquals($expectedSSL, util::get_current_url()); + $_SERVER['SERVER_PORT'] = 80; + $this->assertEquals($expectedPort2, util::get_current_url()); + unset($_SERVER['HTTPS']); + + // Test no $_SERVER['REQUEST_URI'] (e.g., MS IIS). + unset($_SERVER['REQUEST_URI']); + $this->assertEquals($expected, util::get_current_url()); + } + + public function test_set_writable() + { + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + $this->markTestSkipped('This functionality is not working on Windows.'); + } + + if (posix_geteuid() === 0) { + $this->markTestSkipped('These tests don\'t work when run as root'); + } + + $this->assertFalse(util::set_writable('/no/such/file')); + + // Create a file to test with + $dirname = dirname(__FILE__); + $file = $dirname . '/test7'; + touch($file); + chmod($file, 0644); + + // The file is owned by us so it should be writable + $this->assertTrue(is_writable($file)); + $this->assertEquals('-rw-r--r--', util::full_permissions($file)); + + // Toggle writable bit off for us + util::set_writable($file, false); + clearstatcache(); + $this->assertFalse(is_writable($file)); + $this->assertEquals('-r--r--r--', util::full_permissions($file)); + + // Toggle writable bit back on for us + util::set_writable($file, true); + clearstatcache(); + $this->assertTrue(is_writable($file)); + $this->assertEquals('-rw-r--r--', util::full_permissions($file)); + + unlink($file); + } + + public function test_set_readable() + { + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + $this->markTestSkipped('This functionality is not working on Windows.'); + } + + if (posix_geteuid() === 0) { + $this->markTestSkipped('These tests don\'t work when run as root'); + } + + $this->assertFalse(util::set_readable('/no/such/file')); + + $dirname = dirname(__FILE__); + $file = $dirname . '/test8'; + touch($file); + + $this->assertTrue(is_readable($file)); + + util::set_readable($file, false); + clearstatcache(); + $this->assertFalse(is_readable($file)); + + util::set_readable($file, true); + clearstatcache(); + $this->assertTrue(is_readable($file)); + + unlink($file); + } + + public function test_set_executable() + { + if (strncasecmp(PHP_OS, 'WIN', 3) === 0) { + $this->markTestSkipped('This functionality is not working on Windows.'); + } + + if (posix_geteuid() === 0) { + $this->markTestSkipped('These tests don\'t work when run as root'); + } + + $this->assertFalse(util::set_executable('/no/such/file')); + + $dirname = dirname(__FILE__); + $file = $dirname . '/test9'; + touch($file); + + $this->assertFalse(is_executable($file)); + + util::set_executable($file, true); + clearstatcache(); + $this->assertTrue(is_executable($file)); + + util::set_executable($file, false); + clearstatcache(); + $this->assertFalse(is_executable($file)); + + unlink($file); + } + + public function test_directory_size() { + $dirname = dirname(__FILE__); + $dir = $dirname .'/dir1'; + mkdir($dir); + $file1 = $dir .'/file1'; + file_put_contents($file1, '1234567890'); + $file2 = $dir .'/file2'; + file_put_contents($file2, range('a', 'z')); + $this->assertEquals(10 + 26, util::directory_size($dir)); + util::rmdir($dir); + } + + public function test_get_user_directory() { + // Test for OS Default. + $this->assertTrue(is_writable(util::get_user_directory())); + + $oldServer = $_SERVER; + unset($_SERVER); + // Test for UNIX. + $_SERVER['HOME'] = '/home/unknown'; + $this->assertEquals($_SERVER['HOME'], util::get_user_directory(), 'Could not get the user\'s home directory in UNIX.'); + unset($_SERVER); + + // Test for Windows. + $expected = 'X:\Users\ThisUser'; + $_SERVER['HOMEDRIVE'] = 'X:'; + $_SERVER['HOMEPATH'] = '\Users\ThisUser'; + $this->assertEquals($expected, util::get_user_directory(), 'Could not get the user\'s home directory in Windows.'); + + // In case the tests are not being run in isolation. + $_SERVER = $oldServer; + } + + public function test_directory_contents() { + $dirname = dirname(__FILE__); + $dir = $dirname . DIRECTORY_SEPARATOR .'dir1'; + mkdir($dir); + $file1 = $dir . DIRECTORY_SEPARATOR .'file1'; + touch($file1); + $this->assertEquals(array($file1), util::directory_contents($dir)); + util::rmdir($dir); + } +} diff --git a/f_config/DB.php b/f_config/DB.php index 156f53af..58d04ce8 100644 --- a/f_config/DB.php +++ b/f_config/DB.php @@ -9,4 +9,4 @@ if($SETTING->IsExist()) { Error('설정 파일이 없습니다. 설정을 먼저 하십시요!'); } -?> + diff --git a/f_config/DBS.php b/f_config/DBS.php index 9531d717..6f95263f 100644 --- a/f_config/DBS.php +++ b/f_config/DBS.php @@ -10,4 +10,4 @@ for($i=0; $i < $_serverCount; $i++) { } } -?> + diff --git a/f_config/MAIL.php b/f_config/MAIL.php index 63efdfce..9ababf2d 100644 --- a/f_config/MAIL.php +++ b/f_config/MAIL.php @@ -9,4 +9,4 @@ if($SETTING->IsExist()) { Error('설정 파일이 없습니다. 설정을 먼저 하십시요!'); } -?> + diff --git a/f_config/SESSION.php b/f_config/SESSION.php index d34cca64..2a50f81f 100644 --- a/f_config/SESSION.php +++ b/f_config/SESSION.php @@ -10,4 +10,4 @@ if($SESSION->IsLoggedIn() == false) { exit(1); } -?> + diff --git a/f_config/SETTING.php b/f_config/SETTING.php index ad29ba26..31d4665f 100644 --- a/f_config/SETTING.php +++ b/f_config/SETTING.php @@ -4,4 +4,4 @@ require_once(ROOT.W.F_FUNC.W.'class._Setting.php'); $SETTING = new _Setting(ROOT.W.D_SETTING.W.SET.PHP); -?> + diff --git a/f_config/SETTINGS.php b/f_config/SETTINGS.php index cb2e988a..f1e91f30 100644 --- a/f_config/SETTINGS.php +++ b/f_config/SETTINGS.php @@ -8,4 +8,4 @@ foreach($_serverDirs as $serverDir) { $i++; } -?> + diff --git a/f_config/_common.php b/f_config/_common.php index cea1c49d..b25b4786 100644 --- a/f_config/_common.php +++ b/f_config/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/f_config/app.php b/f_config/app.php index 7900672c..25a61033 100644 --- a/f_config/app.php +++ b/f_config/app.php @@ -42,4 +42,4 @@ $_serverLevels = array( 1 ); -?> + diff --git a/f_config/config.php b/f_config/config.php index 03dd7eac..e6133c67 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -53,4 +53,4 @@ define('SLEEP', 'sleep'); //define(BLOCKBODY, ''); define('BLOCKBODY', 'oncontextmenu="return false" onselectstart="return false" ondragstart="return false"'); -?> + diff --git a/f_func/_common.php b/f_func/_common.php index cea1c49d..b25b4786 100644 --- a/f_func/_common.php +++ b/f_func/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/f_func/class._Chat.php b/f_func/class._Chat.php index 85f5d064..1ada9fc6 100644 --- a/f_func/class._Chat.php +++ b/f_func/class._Chat.php @@ -24,4 +24,4 @@ class _Chat { } } -?> + diff --git a/f_func/class._DB.php b/f_func/class._DB.php index 8ba7d4cf..3b7bc593 100644 --- a/f_func/class._DB.php +++ b/f_func/class._DB.php @@ -142,4 +142,4 @@ class _DB { } } -?> + diff --git a/f_func/class._JSON.php b/f_func/class._JSON.php index 2f3641a0..d34c2018 100644 --- a/f_func/class._JSON.php +++ b/f_func/class._JSON.php @@ -52,4 +52,4 @@ class _JSON { } } -?> + diff --git a/f_func/class._Lock.php b/f_func/class._Lock.php index 5dcf8cfa..ac6e5bc4 100644 --- a/f_func/class._Lock.php +++ b/f_func/class._Lock.php @@ -70,4 +70,4 @@ class _Lock { } } -?> + diff --git a/f_func/class._Log.php b/f_func/class._Log.php index c7c88759..6c3b8bec 100644 --- a/f_func/class._Log.php +++ b/f_func/class._Log.php @@ -45,4 +45,4 @@ class _Log { } } -?> + diff --git a/f_func/class._Mail.php b/f_func/class._Mail.php index 3199a606..9d218d20 100644 --- a/f_func/class._Mail.php +++ b/f_func/class._Mail.php @@ -37,4 +37,4 @@ class _Mail { } } -?> + diff --git a/f_func/class._Process.php b/f_func/class._Process.php index 0d5e6b33..035845a5 100644 --- a/f_func/class._Process.php +++ b/f_func/class._Process.php @@ -33,4 +33,4 @@ class _Process { } } -?> + diff --git a/f_func/class._Queue.php b/f_func/class._Queue.php index 87f9000e..6d04a335 100644 --- a/f_func/class._Queue.php +++ b/f_func/class._Queue.php @@ -39,4 +39,4 @@ class _Queue { return $value; } } -?> + diff --git a/f_func/class._Session.php b/f_func/class._Session.php index a96c4d0b..c9c8df9e 100644 --- a/f_func/class._Session.php +++ b/f_func/class._Session.php @@ -72,4 +72,4 @@ class _Session { } } -?> + diff --git a/f_func/class._Setting.php b/f_func/class._Setting.php index afc0c0eb..5cf3d1ce 100644 --- a/f_func/class._Setting.php +++ b/f_func/class._Setting.php @@ -78,4 +78,4 @@ class _Setting { } } -?> + diff --git a/f_func/class._String.php b/f_func/class._String.php index 6a161790..5ab0cbb6 100644 --- a/f_func/class._String.php +++ b/f_func/class._String.php @@ -234,4 +234,3 @@ class _String { } } -?> diff --git a/f_func/class._Time.php b/f_func/class._Time.php index 9f3c7cf8..cc72e34a 100644 --- a/f_func/class._Time.php +++ b/f_func/class._Time.php @@ -44,4 +44,4 @@ class _Time { } } -?> + diff --git a/f_func/class._Validation.php b/f_func/class._Validation.php index 62ee8d1e..dbf4e7da 100644 --- a/f_func/class._Validation.php +++ b/f_func/class._Validation.php @@ -111,4 +111,4 @@ class _Validation { } } -?> + diff --git a/f_func/func.php b/f_func/func.php index deded7cb..4d8a4377 100644 --- a/f_func/func.php +++ b/f_func/func.php @@ -97,4 +97,4 @@ function delExpiredInDir($dir, $t) { return $success; } -?> + diff --git a/f_install/_common.php b/f_install/_common.php index cea1c49d..b25b4786 100644 --- a/f_install/_common.php +++ b/f_install/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/f_install/install1Post.php b/f_install/install1Post.php index b6772741..f025ec74 100644 --- a/f_install/install1Post.php +++ b/f_install/install1Post.php @@ -49,10 +49,12 @@ foreach($querys as $query) { // 파일로 DB 정보 저장 $file = @fopen(ROOT.W.D_SETTING.W.SET.PHP, 'w') or ErrorToScreen('설정 실패. 디렉토리의 퍼미션을 707로 주십시요'); -@fwrite($file, "\n") or ErrorToScreen('설정 실패. 디렉토리의 퍼미션을 707로 주십시요'); +@fwrite($file, " - + +Go to install2.php
+Todo : Back to replace code diff --git a/f_retrival/_common.php b/f_retrival/_common.php index bc36bd5c..9ed1eefa 100644 --- a/f_retrival/_common.php +++ b/f_retrival/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_banner/banner.php b/i_banner/banner.php index 78dc7a6c..5f8da1ca 100644 --- a/i_banner/banner.php +++ b/i_banner/banner.php @@ -54,4 +54,3 @@ switch(rand()%10) { break; } */ -?> diff --git a/i_entrance/_common.php b/i_entrance/_common.php index d56bd857..f57670c9 100644 --- a/i_entrance/_common.php +++ b/i_entrance/_common.php @@ -8,4 +8,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_entrance/adminPost.php b/i_entrance/adminPost.php index c176fe6a..14b36414 100644 --- a/i_entrance/adminPost.php +++ b/i_entrance/adminPost.php @@ -6,6 +6,7 @@ // $_POST['select'] : 0: 폐쇄, 1: 리셋, 2: 오픈 require_once('_common.php'); +require_once(ROOT.W.E_LIB.W.'util.php'); require_once(ROOT.W.F_FUNC.W.'class._JSON.php'); require_once(ROOT.W.F_CONFIG.W.DB.PHP); require_once(ROOT.W.F_CONFIG.W.SESSION.PHP); @@ -23,10 +24,10 @@ function getPost($str){ return $temp; } -$action = getPost('action'); -$notice = getPost('notice'); -$server = getPost('server'); -$select = getPost('select'); +$action = util::array_get($_POST['action'], ''); +$notice = util::array_get($_POST['notice'], ''); +$server = util::array_get($_POST['server'], ''); +$select = util::array_get($_POST['select'], ''); $rs = $DB->Select('GRADE', 'MEMBER', "NO='{$SESSION->NoMember()}'"); @@ -48,7 +49,10 @@ if($member['GRADE'] < 6) { rename(ROOT.W.$serverDir.'_rest', ROOT.W.$serverDir); $response['result'] = 'SUCCESS'; } elseif($select == 1) { - @unlink(ROOT.W.$serverDir.'_close'.W.D_SETTING.W.SET.PHP); + if(file_exists(ROOT.W.$serverDir.'_close'.W.D_SETTING.W.SET.PHP)){ + @unlink(ROOT.W.$serverDir.'_close'.W.D_SETTING.W.SET.PHP); + } + $response['installURL'] = ROOT.W."{$serverDir}_close/install.php"; $response['result'] = 'SUCCESS'; } elseif($select == 2) { @@ -64,5 +68,3 @@ if($member['GRADE'] < 6) { sleep(1); echo json_encode($response); - -?> diff --git a/i_entrance/donation/Get.php b/i_entrance/donation/Get.php index 24e3d354..629556b8 100644 --- a/i_entrance/donation/Get.php +++ b/i_entrance/donation/Get.php @@ -42,4 +42,4 @@ if($member['GRADE'] < 6) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/donation/Post.php b/i_entrance/donation/Post.php index c0cae029..7a4293cd 100644 --- a/i_entrance/donation/Post.php +++ b/i_entrance/donation/Post.php @@ -55,4 +55,4 @@ if($member['GRADE'] < 6) { echo json_encode($response); -?> + diff --git a/i_entrance/donation/_common.php b/i_entrance/donation/_common.php index 90e4756f..d7a78a7b 100644 --- a/i_entrance/donation/_common.php +++ b/i_entrance/donation/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_entrance/donation/calculatePost.php b/i_entrance/donation/calculatePost.php index f413ccd6..2970d44e 100644 --- a/i_entrance/donation/calculatePost.php +++ b/i_entrance/donation/calculatePost.php @@ -43,4 +43,4 @@ if($member['GRADE'] < 6) { echo json_encode($response); -?> + diff --git a/i_entrance/enterPost.php b/i_entrance/enterPost.php index 550878f4..10e785b4 100644 --- a/i_entrance/enterPost.php +++ b/i_entrance/enterPost.php @@ -19,5 +19,3 @@ $response['result'] = 'SUCCESS'; sleep(1); echo json_encode($response); - -?> diff --git a/i_entrance/logoutPost.php b/i_entrance/logoutPost.php index 5d9a5bf6..990d48c8 100644 --- a/i_entrance/logoutPost.php +++ b/i_entrance/logoutPost.php @@ -13,4 +13,4 @@ $response['result'] = 'SUCCESS'; sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/manage/Get.php b/i_entrance/manage/Get.php index 41d73e00..104ae490 100644 --- a/i_entrance/manage/Get.php +++ b/i_entrance/manage/Get.php @@ -75,4 +75,4 @@ $response['result'] = 'SUCCESS'; sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/manage/_common.php b/i_entrance/manage/_common.php index 90e4756f..d7a78a7b 100644 --- a/i_entrance/manage/_common.php +++ b/i_entrance/manage/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_entrance/manage/deletePost.php b/i_entrance/manage/deletePost.php index f810ef4f..aa08f78c 100644 --- a/i_entrance/manage/deletePost.php +++ b/i_entrance/manage/deletePost.php @@ -44,4 +44,4 @@ if($dt == $rf) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/manage/iconPost.php b/i_entrance/manage/iconPost.php index 623eaa69..a77e3e20 100644 --- a/i_entrance/manage/iconPost.php +++ b/i_entrance/manage/iconPost.php @@ -76,4 +76,4 @@ echo ""; -?> + diff --git a/i_entrance/manage/passwordPost.php b/i_entrance/manage/passwordPost.php index f9d2be5f..b0715c75 100644 --- a/i_entrance/manage/passwordPost.php +++ b/i_entrance/manage/passwordPost.php @@ -36,4 +36,4 @@ if($member['PW'] != $pw) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/manage/quitPost.php b/i_entrance/manage/quitPost.php index 1410fb92..d3e1f51f 100644 --- a/i_entrance/manage/quitPost.php +++ b/i_entrance/manage/quitPost.php @@ -33,4 +33,4 @@ if($member['PW'] != $pw) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/member/Get.php b/i_entrance/member/Get.php index dac7382c..be0b8477 100644 --- a/i_entrance/member/Get.php +++ b/i_entrance/member/Get.php @@ -87,4 +87,4 @@ if($member['GRADE'] < 6) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/member/Post.php b/i_entrance/member/Post.php index 55a1b047..5f751122 100644 --- a/i_entrance/member/Post.php +++ b/i_entrance/member/Post.php @@ -118,4 +118,4 @@ if($member['GRADE'] < 6) { sleep(1); echo json_encode($response); -?> + diff --git a/i_entrance/member/_common.php b/i_entrance/member/_common.php index 90e4756f..d7a78a7b 100644 --- a/i_entrance/member/_common.php +++ b/i_entrance/member/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_entrance/serverListPost.php b/i_entrance/serverListPost.php index f48df28d..f6d8f2a3 100644 --- a/i_entrance/serverListPost.php +++ b/i_entrance/serverListPost.php @@ -150,5 +150,5 @@ function getTurnTerm($term) { return $str; } -?> + diff --git a/i_login/Post.php b/i_login/Post.php index b6575890..6043d352 100644 --- a/i_login/Post.php +++ b/i_login/Post.php @@ -51,4 +51,4 @@ if($DB->Count($rs) == 1) { sleep(1); echo json_encode($response); -?> + diff --git a/i_login/_common.php b/i_login/_common.php index cea1c49d..b25b4786 100644 --- a/i_login/_common.php +++ b/i_login/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_login/findpw/Get.php b/i_login/findpw/Get.php index 56fc291d..4f3cb3e5 100644 --- a/i_login/findpw/Get.php +++ b/i_login/findpw/Get.php @@ -12,4 +12,4 @@ $response['result'] = 'SUCCESS'; sleep(1); echo json_encode($response); -?> + diff --git a/i_login/findpw/Post.php b/i_login/findpw/Post.php index e771b808..9e80a86e 100644 --- a/i_login/findpw/Post.php +++ b/i_login/findpw/Post.php @@ -120,4 +120,4 @@ $response['msg'] = "정상적으로 비번이 변경되었습니다. ID: {$id}"; sleep(1); echo json_encode($response); -?> + diff --git a/i_login/findpw/_common.php b/i_login/findpw/_common.php index 90e4756f..d7a78a7b 100644 --- a/i_login/findpw/_common.php +++ b/i_login/findpw/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_login/findpw/checkPost.php b/i_login/findpw/checkPost.php index b2be62b9..630abcb1 100644 --- a/i_login/findpw/checkPost.php +++ b/i_login/findpw/checkPost.php @@ -82,4 +82,4 @@ if($type == 0) { sleep(1); echo json_encode($response); -?> + diff --git a/i_login/findpw/sendCodePost.php b/i_login/findpw/sendCodePost.php index 96878d95..e062ef40 100644 --- a/i_login/findpw/sendCodePost.php +++ b/i_login/findpw/sendCodePost.php @@ -46,4 +46,4 @@ if($err == 1) { //sleep(1); echo json_encode($response); -?> + diff --git a/i_login/findpw/verifyCodePost.php b/i_login/findpw/verifyCodePost.php index f704f9b6..9926eaa9 100644 --- a/i_login/findpw/verifyCodePost.php +++ b/i_login/findpw/verifyCodePost.php @@ -45,4 +45,4 @@ if($err == 1) { sleep(1); echo json_encode($response); -?> + diff --git a/i_login/join/Get.php b/i_login/join/Get.php index 56fc291d..4f3cb3e5 100644 --- a/i_login/join/Get.php +++ b/i_login/join/Get.php @@ -12,4 +12,4 @@ $response['result'] = 'SUCCESS'; sleep(1); echo json_encode($response); -?> + diff --git a/i_login/join/_common.php b/i_login/join/_common.php index 90e4756f..d7a78a7b 100644 --- a/i_login/join/_common.php +++ b/i_login/join/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_login/join/sendCodePost.php b/i_login/join/sendCodePost.php index 31f1526f..5c74adfe 100644 --- a/i_login/join/sendCodePost.php +++ b/i_login/join/sendCodePost.php @@ -46,4 +46,4 @@ if($err == 1) { //sleep(1); echo json_encode($response); -?> + diff --git a/i_login/join/verifyCodePost.php b/i_login/join/verifyCodePost.php index f704f9b6..9926eaa9 100644 --- a/i_login/join/verifyCodePost.php +++ b/i_login/join/verifyCodePost.php @@ -45,4 +45,4 @@ if($err == 1) { sleep(1); echo json_encode($response); -?> + diff --git a/i_other/_common.php b/i_other/_common.php index cea1c49d..b25b4786 100644 --- a/i_other/_common.php +++ b/i_other/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/i_popup/_common.php b/i_popup/_common.php index cea1c49d..b25b4786 100644 --- a/i_popup/_common.php +++ b/i_popup/_common.php @@ -7,4 +7,4 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> + diff --git a/install.php b/install.php index c364afb1..09e0de36 100644 --- a/install.php +++ b/install.php @@ -3,4 +3,6 @@ require_once('_common.php'); ?> - + +Go to f_install/install.php
+Todo : Back to replace code diff --git a/twe_close/MYDB.php b/twe_close/MYDB.php index fff8a763..708a2533 100644 --- a/twe_close/MYDB.php +++ b/twe_close/MYDB.php @@ -38,4 +38,3 @@ function MYDB_close($connect) { return mysqli_close($connect); } -?> diff --git a/twe_close/_119_b.php b/twe_close/_119_b.php index 2f3b9668..9f3d1eb9 100644 --- a/twe_close/_119_b.php +++ b/twe_close/_119_b.php @@ -53,5 +53,5 @@ case "락풀기": break; } -echo ""; -?> +//echo ""; +echo '_119.php';//TODO:replace diff --git a/twe_close/_admin1_submit.php b/twe_close/_admin1_submit.php index 3f3bd5b2..1e0f67c0 100644 --- a/twe_close/_admin1_submit.php +++ b/twe_close/_admin1_submit.php @@ -175,6 +175,6 @@ switch($btn) { break; } -echo ""; -?> +//echo ""; +echo '_admin1.php';//TODO:replace diff --git a/twe_close/_admin2_submit.php b/twe_close/_admin2_submit.php index 295d675e..37c04f3f 100644 --- a/twe_close/_admin2_submit.php +++ b/twe_close/_admin2_submit.php @@ -427,6 +427,6 @@ switch($btn) { break; } -echo ""; -?> +//echo ""; +echo '_admin2.php';//TODO:replace diff --git a/twe_close/_admin3_submit.php b/twe_close/_admin3_submit.php index 60ed41b5..10a09171 100644 --- a/twe_close/_admin3_submit.php +++ b/twe_close/_admin3_submit.php @@ -129,6 +129,6 @@ switch($btn) { break; } -echo ""; -?> +//echo ""; +echo '_admin3.php';//TODO:replace diff --git a/twe_close/_admin4_submit.php b/twe_close/_admin4_submit.php index 344f7def..b9cd07b5 100644 --- a/twe_close/_admin4_submit.php +++ b/twe_close/_admin4_submit.php @@ -102,6 +102,6 @@ switch($btn) { break; } -echo ""; -?> +//echo ""; +echo '_admin4.php'; //TODO:replace diff --git a/twe_close/_admin5_submit.php b/twe_close/_admin5_submit.php index 3a6bcb98..129ad500 100644 --- a/twe_close/_admin5_submit.php +++ b/twe_close/_admin5_submit.php @@ -25,6 +25,7 @@ switch($btn) { break; } -echo ""; -?> +//echo ""; +echo '_admin5.php';//TODO:replace + diff --git a/twe_close/_simul.php b/twe_close/_simul.php index b993bd97..5f3b4120 100644 --- a/twe_close/_simul.php +++ b/twe_close/_simul.php @@ -1559,4 +1559,4 @@ function printSimul($game, $i) { "; } -?> + diff --git a/twe_close/a_traffic.php b/twe_close/a_traffic.php index 3731917b..ac80e299 100644 --- a/twe_close/a_traffic.php +++ b/twe_close/a_traffic.php @@ -254,4 +254,4 @@ function getHexCode($hex) { case 12: return "C"; case 13: return "D"; case 14: return "E"; case 15: return "F"; } } -?> + diff --git a/twe_close/a_vote.php b/twe_close/a_vote.php index b6acb56c..9af23490 100644 --- a/twe_close/a_vote.php +++ b/twe_close/a_vote.php @@ -335,4 +335,4 @@ function getNewColor($type) { return $color; } -?> + diff --git a/twe_close/analytics.php b/twe_close/analytics.php index bf3f0d19..f0e83ec9 100644 --- a/twe_close/analytics.php +++ b/twe_close/analytics.php @@ -1,4 +1,4 @@ - + +b_betting.php diff --git a/twe_close/c_chiefboard.php b/twe_close/c_chiefboard.php index 2f0fa578..00e01c6b 100644 --- a/twe_close/c_chiefboard.php +++ b/twe_close/c_chiefboard.php @@ -42,8 +42,8 @@ if(CheckBlock($connect) != 1 && CheckBlock($connect) != 3) { } } -echo ""; - +//echo ""; +echo 'b_chiefboard.php';//TODO:replace ?> diff --git a/twe_close/c_dipcenter.php b/twe_close/c_dipcenter.php index 65334296..4cf79a5c 100644 --- a/twe_close/c_dipcenter.php +++ b/twe_close/c_dipcenter.php @@ -56,7 +56,7 @@ if($btn == "국가방침") { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } -echo ""; +//echo ""; +echo 'b_dipcenter.php';//TODO:replace -?> diff --git a/twe_close/c_double.php b/twe_close/c_double.php index 8c99759b..8a000e70 100644 --- a/twe_close/c_double.php +++ b/twe_close/c_double.php @@ -124,5 +124,4 @@ if($command == 46) { echo ""; } -?> diff --git a/twe_close/c_msgsubmit.php b/twe_close/c_msgsubmit.php index 4a0eba39..2cfcd684 100644 --- a/twe_close/c_msgsubmit.php +++ b/twe_close/c_msgsubmit.php @@ -113,7 +113,6 @@ if($genlist == 9999 && str_replace(" ", "", $msg) != "") { fclose($fp); } -echo ""; - -?> +//echo ""; +echo 'msglist.php';//TODO:replace diff --git a/twe_close/c_myBossInfo.php b/twe_close/c_myBossInfo.php index f12bee51..7b96765c 100644 --- a/twe_close/c_myBossInfo.php +++ b/twe_close/c_myBossInfo.php @@ -250,7 +250,7 @@ if($btn == "추방") { } } -echo ""; +//echo ""; +echo 'b_myBossInfo.php'//TODO:replace -?> diff --git a/twe_close/c_nationboard.php b/twe_close/c_nationboard.php index 6d3544d3..78e31361 100644 --- a/twe_close/c_nationboard.php +++ b/twe_close/c_nationboard.php @@ -42,7 +42,8 @@ if(CheckBlock($connect) != 1 && CheckBlock($connect) != 3) { } } -echo ""; +//echo ""; +echo 'b_nationboard.php';//TODO:replace ?> diff --git a/twe_close/c_nationrule.php b/twe_close/c_nationrule.php index 9744f007..08563c1a 100644 --- a/twe_close/c_nationrule.php +++ b/twe_close/c_nationrule.php @@ -16,7 +16,6 @@ $msg = addslashes(SQ2DQ($msg)); $query = "update nation set rule='$msg' where nation='$me[nation]'"; MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); -echo ""; - -?> +//echo ""; +echo 'b_nationrule.php';//TODO:replace diff --git a/twe_close/c_tournament.php b/twe_close/c_tournament.php index 157dc74a..666531a9 100644 --- a/twe_close/c_tournament.php +++ b/twe_close/c_tournament.php @@ -202,4 +202,5 @@ if($btn == "자동개최설정" && $me[userlevel] >= 5) { } ?> - + +b_tournament.php diff --git a/twe_close/c_troop.php b/twe_close/c_troop.php index 5dbdfb79..0da27a5f 100644 --- a/twe_close/c_troop.php +++ b/twe_close/c_troop.php @@ -54,5 +54,3 @@ if($btn == "부 대 창 설" && $name != "" && $me[troop] == 0) { echo ""; MYDB_close($connect); -?> - diff --git a/twe_close/c_vacation.php b/twe_close/c_vacation.php index b4062169..8101f999 100644 --- a/twe_close/c_vacation.php +++ b/twe_close/c_vacation.php @@ -14,7 +14,6 @@ $admin[killturn] *= 3; $query = "update general set killturn='$admin[killturn]' where user_id='$_SESSION[p_id]'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); -echo ""; - -?> +//echo ""; +echo 'b_myPage.php'; //TODO:replace diff --git a/twe_close/c_vote.php b/twe_close/c_vote.php index c9e0d242..67798485 100644 --- a/twe_close/c_vote.php +++ b/twe_close/c_vote.php @@ -73,4 +73,5 @@ if($btn == "수정" && $me[userlevel] >= 5) { } ?> - + +a_vote.php diff --git a/twe_close/d_ally.php b/twe_close/d_ally.php index 3e6b36f4..21c29d87 100644 --- a/twe_close/d_ally.php +++ b/twe_close/d_ally.php @@ -116,5 +116,3 @@ pushGenLog($you, $youlog); echo ""; -?> - diff --git a/twe_close/d_cancel.php b/twe_close/d_cancel.php index 94281351..7dd03327 100644 --- a/twe_close/d_cancel.php +++ b/twe_close/d_cancel.php @@ -95,5 +95,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/twe_close/d_cease.php b/twe_close/d_cease.php index 76c125f7..88dfd30c 100644 --- a/twe_close/d_cease.php +++ b/twe_close/d_cease.php @@ -100,5 +100,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/twe_close/d_merge.php b/twe_close/d_merge.php index d57c213e..9a202e95 100644 --- a/twe_close/d_merge.php +++ b/twe_close/d_merge.php @@ -134,5 +134,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/twe_close/d_scout.php b/twe_close/d_scout.php index 9900e98f..934a0503 100644 --- a/twe_close/d_scout.php +++ b/twe_close/d_scout.php @@ -160,5 +160,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/twe_close/d_setting/_common.php b/twe_close/d_setting/_common.php index 90e4756f..57949e8d 100644 --- a/twe_close/d_setting/_common.php +++ b/twe_close/d_setting/_common.php @@ -7,4 +7,3 @@ require_once(ROOT.W.F_CONFIG.W.APP.PHP); require_once(ROOT.W.F_FUNC.W.FUNC.PHP); CustomHeader(); -?> diff --git a/twe_close/d_surrender.php b/twe_close/d_surrender.php index 729fe7fa..799f448a 100644 --- a/twe_close/d_surrender.php +++ b/twe_close/d_surrender.php @@ -124,5 +124,3 @@ pushHistory($connect, $history); echo ""; -?> - diff --git a/twe_close/data/connected.php b/twe_close/data/connected.php index caaabefa..de11d5cd 100644 --- a/twe_close/data/connected.php +++ b/twe_close/data/connected.php @@ -1 +1 @@ - + - diff --git a/twe_close/event_2.php b/twe_close/event_2.php index 94bcc518..b104b92b 100644 --- a/twe_close/event_2.php +++ b/twe_close/event_2.php @@ -253,5 +253,3 @@ function RegGeneral3($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/twe_close/event_3.php b/twe_close/event_3.php index 48fd3d51..a613f347 100644 --- a/twe_close/event_3.php +++ b/twe_close/event_3.php @@ -114,5 +114,3 @@ function RegGeneral3($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/twe_close/event_4.php b/twe_close/event_4.php index 9d3b1c10..0b4ec99d 100644 --- a/twe_close/event_4.php +++ b/twe_close/event_4.php @@ -143,5 +143,3 @@ function RegGeneral4($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> - diff --git a/twe_close/func.php b/twe_close/func.php index 31577742..7ef2380e 100644 --- a/twe_close/func.php +++ b/twe_close/func.php @@ -7416,4 +7416,3 @@ function Submit($url, $msg="", $msg2="") { "; } -?> diff --git a/twe_close/func_auction.php b/twe_close/func_auction.php index 9ffd729c..065d6919 100644 --- a/twe_close/func_auction.php +++ b/twe_close/func_auction.php @@ -345,4 +345,3 @@ function processAuction($connect) { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/twe_close/func_history.php b/twe_close/func_history.php index bd18360c..210eca7c 100644 --- a/twe_close/func_history.php +++ b/twe_close/func_history.php @@ -128,4 +128,3 @@ function LogHistory($connect, $isFirst=0) { if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish'); return true; } -?> diff --git a/twe_close/func_http.php b/twe_close/func_http.php index 09dd69d3..c809b579 100644 --- a/twe_close/func_http.php +++ b/twe_close/func_http.php @@ -285,4 +285,3 @@ class HTTP{ } } } -?> \ No newline at end of file diff --git a/twe_close/func_npc.php b/twe_close/func_npc.php index 9c8f7d1d..c1444023 100644 --- a/twe_close/func_npc.php +++ b/twe_close/func_npc.php @@ -1861,4 +1861,3 @@ function RiceBillRate($connect, $nation, $rate, $rice_rate, $type, $rice) { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/twe_close/func_process.php b/twe_close/func_process.php index b75f7a2b..9e9d6a43 100644 --- a/twe_close/func_process.php +++ b/twe_close/func_process.php @@ -6145,4 +6145,3 @@ function process_99($connect, &$general) { pushGenLog($general, $log); } -?> diff --git a/twe_close/func_string.php b/twe_close/func_string.php index 6c8c0c27..c84011af 100644 --- a/twe_close/func_string.php +++ b/twe_close/func_string.php @@ -301,4 +301,3 @@ class _String { } } -?> diff --git a/twe_close/install.php b/twe_close/install.php index 8deff41b..43790b5c 100644 --- a/twe_close/install.php +++ b/twe_close/install.php @@ -74,7 +74,7 @@ if(!$check) {
- +
diff --git a/twe_close/install2_ok.php b/twe_close/install2_ok.php index 9c83711c..1441a8a7 100644 --- a/twe_close/install2_ok.php +++ b/twe_close/install2_ok.php @@ -345,4 +345,3 @@ function insertCity($connect, $name, $level, $pop2, $agri2, $comm2, $secu2, $def ) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/twe_close/install3_ok.php b/twe_close/install3_ok.php index 3d4f74b0..5ff3b1d3 100644 --- a/twe_close/install3_ok.php +++ b/twe_close/install3_ok.php @@ -6,5 +6,5 @@ $connect=dbConn(); LogHistory($connect, 1); -echo ""; -?> +//echo ""; +echo 'index.php'; //TODO:replace diff --git a/twe_close/install_ok.php b/twe_close/install_ok.php index 3d0326c3..a4ae6fa8 100644 --- a/twe_close/install_ok.php +++ b/twe_close/install_ok.php @@ -5,6 +5,8 @@ include "func.php"; if(file_exists("d_setting/set.php")) error("이미 set.php가 생성되어 있습니다.

재설치하려면 해당 파일을 지우세요"); + + // 호스트네임, 아이디, DB네임, 비밀번호의 공백여부 검사 if(isBlank($hostname)) Error("HostName을 입력하세요",""); if(isBlank($user_id)) Error("User ID 를 입력하세요",""); @@ -83,7 +85,7 @@ if(!isTable($connect, "history",$dbname)) @MYDB_query($history_schema, $connect) // 파일로 DB 정보 저장 $file=@fopen("d_setting/set.php","w") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); -@fwrite($file,"\n") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); +@fwrite($file,"
디렉토리의 퍼미션을 707로 주십시요",""); @fclose($file); @mkdir("data",0707); @chmod("data",0707); @@ -94,4 +96,3 @@ $temp=MYDB_fetch_array(MYDB_query("select count(*) from general where level = '1 MYDB_close($connect); echo ""; -?> diff --git a/twe_close/join_post.php b/twe_close/join_post.php index 52384fb3..f6ab7941 100644 --- a/twe_close/join_post.php +++ b/twe_close/join_post.php @@ -272,4 +272,3 @@ if($id_num) { echo(""); } -?> diff --git a/twe_close/join_post.php.orig b/twe_close/join_post.php.orig index ed10c24b..c796b36b 100644 --- a/twe_close/join_post.php.orig +++ b/twe_close/join_post.php.orig @@ -272,4 +272,3 @@ if($id_num) { echo(""); } -?> diff --git a/twe_close/join_token.php b/twe_close/join_token.php index 87042ec3..dad9d390 100644 --- a/twe_close/join_token.php +++ b/twe_close/join_token.php @@ -55,4 +55,3 @@ $response['intel'] = $abil['intel']; usleep(100*1000); echo json_encode($response); -?> \ No newline at end of file diff --git a/twe_close/lib.php b/twe_close/lib.php index 75399e82..b0807cf0 100644 --- a/twe_close/lib.php +++ b/twe_close/lib.php @@ -7,7 +7,7 @@ // @header ("P3P : CP=\"ALL CURa ADMa DEVa TAIa OUR BUS IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC OTC\""); //디버그용 매크로 -define(__OLINE__,__LINE__); +define('__OLINE__',__LINE__); define(__LINE__,__FILE__." ".__FUNCTION__." ".__LINE__." : "); ini_set("session.cache_expire", 10080); // minutes ini_set("session.gc_maxlifetime", 604800); // seconds @@ -167,4 +167,3 @@ function PrintElapsedTime() { $_endTime = round(getMicroTime() - $_startTime, 3); echo "
경과시간 : {$_endTime}초
"; } -?> diff --git a/twe_close/license.txt b/twe_close/license.txt index ceed7e73..642b3e1a 100644 --- a/twe_close/license.txt +++ b/twe_close/license.txt @@ -1,36 +1 @@ -ZeroBoard에 대한 라이센스 명시입니다. - -아래 라이센스에 동의하시는 분만 제로보드를 사용할수 있습니다. - -프로그램명 : Zeroboard -배포버젼 : 4.1 pl 8 (2006. 3. 15) -개발자 : zero -Homepage : http://zeroboard.com - -1. 제로보드의 배포권은 ZEROBOARD.COM에서 허용한 곳에만 있습니다. - (허락 맡지 않은 재배포는 허용하지 않습니다.) - -2. 제로보드는 저작권을 아래 3번항목에 의해 표기하는 한도내에서 - 개인홈페이지 및 학교나 교회등의 비영리단체, 기업이나 기타 영리단체에서 사용할수 있습니다. - (반국가 단체나 불법 싸이트에서의 사용은 금지합니다) - -3. 제로보드 사용시 저작권 명시부분을 훼손하면 안됩니다. - 프로그램 소스, html소스상의 라이센스 및 웹상 출력물 하단에 있는 카피라이트와 링크를 수정하지 마십시요. - (저작권 표시는 게시판 배포시 작성된 형식만을 허용합니다. 임의 수정은 금지합니다) - -4. 단, 정식 등록버젼은 저작권 표시를 삭제할수 있습니다. - 정식 등록버젼에 대한 문의는 http://zeroboard.com 에서 문의 방법을 찾아주시기 바랍니다. - -5. 링크서비스등의 기본 용도에 맞지 않는 사용은 금지합니다. - -6. 제로보드의 사용으로 인한 데이타 손실 및 기타 손해등 어떠한 사고나 문제에 대해서 ZEROBOARD.COM은 절대 책임을 지지 않습니다. - -7. 제로보드에 대해 ZEROBOARD.COM은 유지/ 보수의 의무가 없습니다. - -8. 제로보드 소스는 개인적으로 사용시 수정하여 사용할수 있지만 수정된 프로그램의 재배포는 금지합니다. - (저작권 관련 부분은 수정금지입니다) - -9. 제로보드에 쓰인 스킨의 저작권은 스킨 제작자에게 있으며 제작자의 동의하에 수정배포가 가능합니다. - -10. 기타 의문사항은 http://zeroboard.com 을 이용해 주시기 바랍니다. - (질문등에 대한 내용은 메일로 받지 않습니다) +Ok Go! \ No newline at end of file diff --git a/twe_close/login_process.php b/twe_close/login_process.php index 1129f3c1..a3d56c76 100644 --- a/twe_close/login_process.php +++ b/twe_close/login_process.php @@ -78,4 +78,3 @@ function DeleteSession() { } MYDB_close($connect); -?> diff --git a/twe_close/logout_process.php b/twe_close/logout_process.php index 17b57479..d892aa75 100644 --- a/twe_close/logout_process.php +++ b/twe_close/logout_process.php @@ -16,10 +16,11 @@ $id = $me[user_id]; $pw = $me[password]; $conmsg = $me[conmsg]; -//Ǻ +//���Ǻ��� ���� session_destroy(); -echo ""; +//echo ""; +echo 'start.php';//TODO:replace /* @@ -33,4 +34,3 @@ a */ -?> diff --git a/twe_close/main.php b/twe_close/main.php index 352962ed..cf243bd1 100644 --- a/twe_close/main.php +++ b/twe_close/main.php @@ -334,5 +334,3 @@ banner(); if($con == 1) { MessageBox("접속제한이 얼마 남지 않았습니다! 제한량이 모자라다면 참여를 해보세요^^"); } if($me[newmsg] == 1) { MessageBox("개인 서신이 도착했습니다!"); } if($me[newvote] == 1) { $develcost = $admin[develcost]*5; MessageBox("설문조사에 참여하시면 금{$develcost}과 유니크템을 드립니다! (우측 상단 설문조사 메뉴)"); } -?> - diff --git a/twe_close/map.php b/twe_close/map.php index af42f272..8c33acb7 100644 --- a/twe_close/map.php +++ b/twe_close/map.php @@ -432,4 +432,3 @@ function getCityLevel($region, $level) { return $str; } -?> diff --git a/twe_close/map_history.php b/twe_close/map_history.php index 8f612467..8da98be7 100644 --- a/twe_close/map_history.php +++ b/twe_close/map_history.php @@ -31,4 +31,3 @@ $map = str_replace('<_quot_>', "'", $map); $map = str_replace('<_dquot_>', '"', $map); echo $map; -?> diff --git a/twe_close/npc_login_process.php b/twe_close/npc_login_process.php index 3dd7c0e5..969c95ae 100644 --- a/twe_close/npc_login_process.php +++ b/twe_close/npc_login_process.php @@ -73,4 +73,3 @@ function DeleteSession() { } MYDB_close($connect); -?> diff --git a/twe_close/phpinfo.php b/twe_close/phpinfo.php deleted file mode 100644 index cf608608..00000000 --- a/twe_close/phpinfo.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/twe_close/preprocessing.php b/twe_close/preprocessing.php index bcd7780b..b6e7ad95 100644 --- a/twe_close/preprocessing.php +++ b/twe_close/preprocessing.php @@ -120,5 +120,3 @@ switch($commandtype) { default: command_Other($connect, $turn, $commandtype); break; } -?> - diff --git a/twe_close/proc.php b/twe_close/proc.php index d1e4003d..7d9408b6 100644 --- a/twe_close/proc.php +++ b/twe_close/proc.php @@ -5,4 +5,3 @@ include "func.php"; $connect = dbConn(); increaseRefresh($connect, "자동", 2); checkTurn($connect); -?> diff --git a/twe_close/process_war.php b/twe_close/process_war.php index 6fba7ba9..f6825014 100644 --- a/twe_close/process_war.php +++ b/twe_close/process_war.php @@ -1845,4 +1845,3 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) { pushHistory($connect, $history); } -?> diff --git a/twe_close/processing.php b/twe_close/processing.php index e5949299..49788cdd 100644 --- a/twe_close/processing.php +++ b/twe_close/processing.php @@ -3125,5 +3125,3 @@ function command_81($connect, $turn, $command) { "; ender(1); } -?> - diff --git a/twe_close/queue.php b/twe_close/queue.php index 05800144..7fa94915 100644 --- a/twe_close/queue.php +++ b/twe_close/queue.php @@ -38,4 +38,3 @@ class Queue { return $value; } } -?> diff --git a/twe_close/reset.php b/twe_close/reset.php index 07c170b3..98d01c04 100644 --- a/twe_close/reset.php +++ b/twe_close/reset.php @@ -67,7 +67,7 @@ if(!isTable($connect, "history",$dbname)) @MYDB_query($history_schema, $connect) // 파일로 DB 정보 저장 $file=@fopen("d_setting/set.php","w") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); -@fwrite($file,"\n") or Error("set.php 파일 생성 실패

디렉토리의 퍼미션을 707로 주십시요",""); +@fwrite($file,"
디렉토리의 퍼미션을 707로 주십시요",""); @fclose($file); @mkdir("data",0707); @chmod("data",0707); @@ -78,4 +78,3 @@ $temp=MYDB_fetch_array(MYDB_query("select count(*) from general where level = '1 MYDB_close($connect); echo ""; -?> diff --git a/twe_close/scenario_1.php b/twe_close/scenario_1.php index d62efaf9..e39633f0 100644 --- a/twe_close/scenario_1.php +++ b/twe_close/scenario_1.php @@ -792,4 +792,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_10.php b/twe_close/scenario_10.php index b6ba094e..47588492 100644 --- a/twe_close/scenario_10.php +++ b/twe_close/scenario_10.php @@ -898,4 +898,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_11.php b/twe_close/scenario_11.php index 47ef5b88..e064095a 100644 --- a/twe_close/scenario_11.php +++ b/twe_close/scenario_11.php @@ -897,4 +897,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_12.php b/twe_close/scenario_12.php index 89d6ff15..73d612cc 100644 --- a/twe_close/scenario_12.php +++ b/twe_close/scenario_12.php @@ -1181,4 +1181,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_2.php b/twe_close/scenario_2.php index 32fc1329..8340b15b 100644 --- a/twe_close/scenario_2.php +++ b/twe_close/scenario_2.php @@ -1711,4 +1711,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_20.php b/twe_close/scenario_20.php index d23ac02d..a4ae577f 100644 --- a/twe_close/scenario_20.php +++ b/twe_close/scenario_20.php @@ -746,4 +746,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_21.php b/twe_close/scenario_21.php index 117867cb..6dd317b0 100644 --- a/twe_close/scenario_21.php +++ b/twe_close/scenario_21.php @@ -774,4 +774,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_22.php b/twe_close/scenario_22.php index 0243103b..5176501c 100644 --- a/twe_close/scenario_22.php +++ b/twe_close/scenario_22.php @@ -194,4 +194,3 @@ function RegGeneral2($connect,$turnterm,$gencount,$name,$leader,$power,$intel,$p } } -?> diff --git a/twe_close/scenario_23.php b/twe_close/scenario_23.php index b4804c15..dee04c1c 100644 --- a/twe_close/scenario_23.php +++ b/twe_close/scenario_23.php @@ -750,4 +750,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_24.php b/twe_close/scenario_24.php index 5053015c..8fb46725 100644 --- a/twe_close/scenario_24.php +++ b/twe_close/scenario_24.php @@ -325,4 +325,3 @@ function RegGeneral3($connect,$turnterm,$gencount,$nation,$level,$name,$leader,$ ) or Error(__LINE__.MYDB_error($connect),""); } -?> diff --git a/twe_close/scenario_25.php b/twe_close/scenario_25.php index 88ac73e7..906f1525 100644 --- a/twe_close/scenario_25.php +++ b/twe_close/scenario_25.php @@ -316,4 +316,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_26.php b/twe_close/scenario_26.php index 271f7876..4f32a294 100644 --- a/twe_close/scenario_26.php +++ b/twe_close/scenario_26.php @@ -313,4 +313,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_27.php b/twe_close/scenario_27.php index 4e66d967..46082d2b 100644 --- a/twe_close/scenario_27.php +++ b/twe_close/scenario_27.php @@ -591,4 +591,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_28.php b/twe_close/scenario_28.php index 9ceca2d3..f233c2bd 100644 --- a/twe_close/scenario_28.php +++ b/twe_close/scenario_28.php @@ -420,4 +420,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_3.php b/twe_close/scenario_3.php index a8c77239..34380b1f 100644 --- a/twe_close/scenario_3.php +++ b/twe_close/scenario_3.php @@ -1752,4 +1752,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_4.php b/twe_close/scenario_4.php index 8658a05c..ffc45ada 100644 --- a/twe_close/scenario_4.php +++ b/twe_close/scenario_4.php @@ -1289,4 +1289,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_5.php b/twe_close/scenario_5.php index 450bfc4c..c621480b 100644 --- a/twe_close/scenario_5.php +++ b/twe_close/scenario_5.php @@ -995,4 +995,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_6.php b/twe_close/scenario_6.php index a4d83d3f..f697a60f 100644 --- a/twe_close/scenario_6.php +++ b/twe_close/scenario_6.php @@ -1041,4 +1041,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_7.php b/twe_close/scenario_7.php index c56de9aa..8cc61f2d 100644 --- a/twe_close/scenario_7.php +++ b/twe_close/scenario_7.php @@ -1093,4 +1093,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_8.php b/twe_close/scenario_8.php index b02d6e0d..6529ca47 100644 --- a/twe_close/scenario_8.php +++ b/twe_close/scenario_8.php @@ -945,4 +945,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/scenario_9.php b/twe_close/scenario_9.php index 5e49bddc..ba703829 100644 --- a/twe_close/scenario_9.php +++ b/twe_close/scenario_9.php @@ -869,4 +869,3 @@ pushHistory($connect, $history); echo ""; -?> diff --git a/twe_close/schema.php b/twe_close/schema.php index 9479dc2a..ceb9050d 100644 --- a/twe_close/schema.php +++ b/twe_close/schema.php @@ -617,5 +617,3 @@ $history_schema = " "; -?> - diff --git a/twe_close/schema.sql.orig b/twe_close/schema.sql.orig index 1654fc77..fa3318af 100644 --- a/twe_close/schema.sql.orig +++ b/twe_close/schema.sql.orig @@ -617,5 +617,3 @@ $history_schema = " "; -?> - diff --git a/twe_close/select_npc_post.php b/twe_close/select_npc_post.php index 9de8fccc..ebe9997c 100644 --- a/twe_close/select_npc_post.php +++ b/twe_close/select_npc_post.php @@ -124,4 +124,3 @@ if($admin[npcmode] != 1) { echo(""); } -?> diff --git a/twe_close/turn.php b/twe_close/turn.php index 8b475519..f7373898 100644 --- a/twe_close/turn.php +++ b/twe_close/turn.php @@ -85,6 +85,3 @@ case 2: } echo ""; - -?> - diff --git a/twe_close/turn_pop_core.php b/twe_close/turn_pop_core.php index d40de774..4198b506 100644 --- a/twe_close/turn_pop_core.php +++ b/twe_close/turn_pop_core.php @@ -12,6 +12,3 @@ $me = MYDB_fetch_array($result); updateCommand($connect, $me[no], 2); echo ""; - -?> - diff --git a/twe_close/turn_push_core.php b/twe_close/turn_push_core.php index b680cd17..740ae1a7 100644 --- a/twe_close/turn_push_core.php +++ b/twe_close/turn_push_core.php @@ -13,5 +13,3 @@ backupdateCommand($connect, $me[no], 2); echo ""; -?> -