private static function replace_marker($mtemplate, $key, $val) { //-- if ((string) $key != '' and preg_match('/^[A-Z0-9_\\-\\.]+$/', (string) $key) and strpos((string) $mtemplate, '[####' . $key) !== false) { //-- $regex = '/\\[####' . preg_quote((string) $key, '/') . '(\\|bool|\\|num|\\|htmid|\\|jsvar|\\|json)?(\\|url)?(\\|js)?(\\|html)?(\\|nl2br)?' . '####\\]/'; //-- if ((string) $val != '') { $val = (string) str_replace(array('[####', '####]', '[%%%%', '%%%%]', '[@@@@', '@@@@]'), array('(####+', '+####)', '(%%%%+', '+%%%%)', '(@@@@+', '+@@@@)'), (string) $val); // protect against cascade / recursion / undefined variables - for content injections of: variables / syntax / sub-templates } //end if //-- $mtemplate = (string) preg_replace_callback((string) $regex, function ($matches) use($val) { //-- Format if ((string) $matches[1] == '|num') { // Number $val = (string) (double) $val; } elseif ((string) $matches[1] == '|bool') { // Boolean if ($val) { $val = 'true'; } else { $val = 'false'; } //end if else } elseif ((string) $matches[1] == '|htmid') { // HTML ID $val = (string) trim((string) preg_replace('/[^a-zA-Z0-9_\\-]/', '', (string) $val)); } elseif ((string) $matches[1] == '|jsvar') { // JS Variable $val = (string) trim((string) preg_replace('/[^a-zA-Z0-9_]/', '', (string) $val)); } elseif ((string) $matches[1] == '|json') { // Json Data (!!! DO NOT ENCLOSE IN ' or " as it can contain them as well as it can be [] or {} ... this is pure JSON !!!) $val = (string) Smart::json_encode($val, false, false); // no pretty print, escape unicode as it is served inline ! } //end if //-- Escape if ((string) $matches[2] == '|url') { $val = (string) Smart::escape_url((string) $val); } //end if if ((string) $matches[3] == '|js') { $val = (string) Smart::escape_js((string) $val); } //end if if ((string) $matches[4] == '|html') { $val = (string) Smart::escape_html((string) $val); } //end if //-- if ((string) $matches[5] == '|nl2br') { $val = (string) Smart::nl_2_br((string) $val); } //end if //-- return (string) $val; //-- }, (string) $mtemplate); //-- } //end if //-- return (string) $mtemplate; //-- }
public static function test_fs() { //-- if (SMART_FRAMEWORK_TESTUNIT_ALLOW_FS_TESTS !== true) { return SmartComponents::operation_notice('Test Unit File System Tests are DISABLED ...'); } //end if //-- //-- $time = microtime(true); //-- //-- $err = ''; $tests = array(); //-- //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! $tests[] = '##### FileSystem OPERATIONS / TESTS - ALL: #####'; } else { $tests[] = '##### FileSystem OPERATIONS / TESTS *** PARTIAL SUPPORT ONLY (BY PLATFORM) ***: #####'; } //end if else //-- //-- $test_string = '#START#' . "\n" . 'グッド' . "\n" . 'SmartFramework/Test/FileSystem' . "\n" . time() . "\n" . SMART_FRAMEWORK_HTACCESS_NOINDEXING . SMART_FRAMEWORK_HTACCESS_FORBIDDEN . SMART_FRAMEWORK_HTACCESS_NOEXECUTION . "\n" . '#END#'; $test_str_cksum = SmartHashCrypto::sha512($test_string); $long_prefixed = SmartFileSysUtils::prefixed_sha1_path(sha1(time())); $short_prefixed = SmartFileSysUtils::prefixed_uuid10_dir(Smart::uuid_10_seq()); //-- $the_base_folder = 'tmp/tests/'; $the_sufx_folder = 'Folder1'; $the_base_file = 'NORMAL-Write_123_@#.txt'; //-- $the_folder = $the_base_folder . $the_sufx_folder . '/'; $the_copy_folder = $the_base_folder . 'folder2'; $the_move_folder = $the_base_folder . 'FOLDER3'; $the_extra_folder = $the_folder . 'extra/'; $the_file = $the_folder . $the_base_file; //-- $get_folder = SmartFileSysUtils::add_dir_last_slash(SmartFileSysUtils::get_dir_from_path($the_folder)); $get_file = SmartFileSysUtils::get_file_name_from_path($the_file); $get_xfile = SmartFileSysUtils::get_noext_file_name_from_path($the_file); $get_ext = SmartFileSysUtils::get_file_extension_from_path($the_file); //-- $the_copy_file = $the_file . '.copy.txt'; $the_move_file = $the_extra_folder . $the_base_file . '.copy.moved.txt'; $the_broken_link = $the_extra_folder . 'a-broken-link'; $the_broken_dir_link = $the_extra_folder . 'a-broken-dir-link'; $the_good_link = $the_extra_folder . 'a-good-link'; $the_good_dir_link = $the_extra_folder . 'a-good-dir-link'; //-- //-- $tests[] = 'INITIAL-FOLDER: ' . $get_folder; $tests[] = 'NEW-FOLDER: ' . $the_folder; $tests[] = 'NEW-FILE: ' . $the_file; //-- //-- if ((string) $err == '') { $the_test = 'CHECK TEST SAFE PATH NAME: DIR / FILE ...'; $tests[] = $the_test; if ((string) Smart::safe_pathname((string) $get_folder) !== (string) $get_folder or (string) Smart::safe_pathname((string) $the_copy_file) !== (string) $the_copy_file) { $err = 'ERROR: SAFE PATH NAME TEST ... FAILED !!!'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'CHECK TEST ABSOLUTE / BACKWARD PATHS ...'; $tests[] = $the_test; if (!SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute', 'no') or SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute') or SmartFileSysUtils::check_file_or_dir_name('/this/is/../backward/path')) { $err = 'ERROR: CHECK TEST ABSOLUTE / BACKWARD PATHS ... FAILED !!!'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'CHECK EXTRACT FOLDER FROM PATH ...'; $tests[] = $the_test; if ((string) $get_folder != SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder))) { $err = 'ERROR: Path Extraction FAILED: Dir=' . $get_folder . ' ; DirName=' . SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder)); } //end if } //end if if ((string) $err == '') { $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (1) ...'; $tests[] = $the_test; if ((string) $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file != $the_file) { $err = 'ERROR :: Path Extraction FAILED: Re-Composed-File=' . $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file . ' ; File=' . $the_file; } //end if } //end if if ((string) $err == '') { $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (2) ...'; $tests[] = $the_test; if ((string) $get_file != $get_xfile . '.' . $get_ext) { $err = 'ERROR :: Path Extraction FAILED: File=' . $get_file . ' ; XFile=' . $get_xfile . ' ; Ext=' . $get_ext; } //end if } //end if //-- SmartFileSysUtils::raise_error_if_unsafe_path($the_folder); if ((string) $err == '') { $the_test = 'CHECK PATH NAME DIR: check_file_or_dir_name() : ' . $the_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSysUtils::check_file_or_dir_name($the_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if SmartFileSysUtils::raise_error_if_unsafe_path($the_file); if ((string) $err == '') { $the_test = 'CHECK PATH NAME FILE: check_file_or_dir_name() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSysUtils::check_file_or_dir_name($the_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash(''); $the_test = 'Check Add Dir Last (trailing) Slash: Empty Folder Name'; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash('.'); $the_test = 'Check Add Dir Last (trailing) Slash: Dot Folder Name: ' . $parent_folder; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash('./'); $the_test = 'Check Add Dir Last (trailing) Slash: DotSlash Folder Name: ' . $parent_folder; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_base_folder)); $the_test = 'Check Parent Dir Name with Add Dir Last (trailing) Slash: ' . $parent_folder . ' # from: ' . $the_base_folder; $tests[] = $the_test; if ((string) $parent_folder != 'tmp/') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- if ((string) $err == '') { if (is_dir($get_folder)) { $the_test = 'DIR DELETE - INIT CLEANUP: dir_delete() + recursive: ' . $get_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_base_folder, true); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } else { $tests[] = 'DIR DELETE - INIT CLEANUP: Test Not Run (folder does not exists): ' . $get_folder; } //end if else } //end if //-- if ((string) $err == '') { $the_test = 'DIR CREATE RECURSIVE: dir_recursive_create() : ' . $the_folder . $long_prefixed . $short_prefixed; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_recursive_create($the_folder . $long_prefixed . $short_prefixed); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DIR CREATE NON-RECURSIVE: dir_create() : extra/ in : ' . $the_extra_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_recursive_create($the_extra_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (1): link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/cache', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE BROKEN FILE LINK (1): delete() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1 || is_link($the_broken_link)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (2): link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE BROKEN FILE LINK (2): dir_delete() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_broken_link); if ($result !== 1 || is_link($the_broken_link)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN DIR LINK: link_create() : as : ' . $the_broken_dir_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/', $the_broken_dir_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE A FILE LINK: link_create() : as : ' . $the_good_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create(Smart::real_path('tmp/index.html'), $the_good_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE A DIR LINK: link_create() : as : ' . $the_good_dir_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create(Smart::real_path('tmp/'), $the_good_dir_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE WRITE with empty content: write() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, ''); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write() / before append : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write() +append : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string, 'a'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE READ / Append: read() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) SmartHashCrypto::sha512($test_string . $test_string)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: re-write() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! if ((string) $err == '') { $the_test = 'FILE WRITE TO A BROKEN LINK: write() : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_broken_link, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE THE BROKEN LINK AFTER write() and RE-CREATE IT : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE]: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write_if_not_exists() with Content Compare to a broken link : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write_if_not_exists($the_broken_link, $test_string, 'yes'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE THE BROKEN LINK AFTER write_if_not_exists() and RE-CREATE IT : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE-IF-NOT-EXISTS]: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE WRITE: write_if_not_exists() without Content Compare : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write_if_not_exists($the_file, $test_string, 'no'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE READ: read() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE READ: read() Partial Size, First 10 bytes: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file, 10); if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) { // here we read bytes so substr() not SmartUnicode::sub_str() should be used $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE STATIC-READ: staticread() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::staticread($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE STATIC-READ: staticread() Partial Size, First 10 bytes: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::staticread($the_file, 10); if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) { // here we read bytes so substr() not SmartUnicode::sub_str() should be used $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE COPY: copy() : ' . $the_file . ' to: ' . $the_copy_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_copy_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE COPY with OVERWRITE: copy() : ' . $the_file . ' to: ' . $the_copy_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_copy_file, true); // overwrite destination file(s) if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE RE-COPY (test should re-write the destination): copy() : ' . $the_file . ' to: ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } else { $the_test = 'FILE DELETE: delete() : ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if if ((string) $err == '') { $the_test = 'FILE RENAME/MOVE: rename() : ' . $the_copy_file . ' to: ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::rename($the_copy_file, $the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { if (is_dir('__development/')) { //-- $the_test = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: dir_copy() : ' . '__development/' . ' to: ' . $the_folder . '__development'; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_copy('__development/', $the_folder . '__development'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if //-- if ((string) $err == '') { $the_test = 'DIR COMPARE THE [DEVELOPMENT] SOURCE WITH [DEVELOPMENT] DESTINATION AFTER DIR COPY AND DIR MOVE:' . "\n" . 'compare_folders() : ' . '__development/' . ' with: ' . $the_folder . '__development/'; $tests[] = $the_test; $arr_diff = array(); $arr_diff = SmartFileSystem::compare_folders('__development', $the_folder . '__development', true, true); if (Smart::array_size($arr_diff) > 0) { $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1); } //end if } //end if //-- } else { $tests[] = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: Test Not Run (Development environment not detected) ...'; } //end if else } //end if //-- if ((string) $err == '') { $the_test = 'RECURSIVE COPY (CLONE) DIR: dir_copy() : ' . $the_folder . ' to: ' . $the_copy_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_copy($the_folder, $the_copy_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'MOVE/RENAME DIR: dir_rename() : ' . $the_copy_folder . ' to: ' . $the_move_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_rename($the_copy_folder, $the_move_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'DIR COMPARE THE SOURCE WITH DESTINATION AFTER DIR COPY AND DIR MOVE: ' . $the_folder . ' with: ' . $the_move_folder; $tests[] = $the_test; $arr_diff = array(); $arr_diff = SmartFileSystem::compare_folders($the_folder, $the_move_folder, true, true); if (Smart::array_size($arr_diff) > 0) { $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1); } //end if } //end if //-- if ((string) $err == '') { $the_test = 'DIR DELETE - SIMPLE: dir_delete() non-recursive: ' . $the_extra_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_extra_folder, false); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DIR DELETE - LAST CLEANUP: dir_delete() + recursive: ' . $get_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_base_folder, true); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- $time = 'TOTAL TIME was: ' . (microtime(true) - $time); //-- //-- $end_tests = '##### END TESTS ... ' . $time . ' sec. #####'; //-- //-- if ((string) $err == '') { $img_sign = 'lib/core/img/sign_info.png'; $img_check = 'lib/core/img/q_completed.png'; $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect :: グッド ... パーフェクト</span>'); $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework FS Operations <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $end_tests)) . '</span>'); } else { $img_sign = 'lib/core/img/sign_error.png'; $img_check = 'lib/core/img/q_warning.png'; $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... :: エラーが発生しました ...</span>'); $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing FS Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>'); } //end if else //-- //-- $html = <<<HTML <h1>SmartFramework LibFileSystem Tests: DONE ... [ Time: {$time} sec. ]</h1> <script type="text/javascript"> \tSmartJS_BrowserUtils.alert_Dialog( \t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>', \t\t'', \t\t'FileSystem Operations Test Suite for SmartFramework: PHP', \t\t'920', \t\t'480' \t); </script> HTML; //-- //-- return $html; //-- }
private static function print_log_database($title, $db_log) { //-- $log = ''; //-- $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_head"><font size="4"><b>' . Smart::escape_html($title) . ' :: DATABASE Queries</b></font></div>'; //-- $max = Smart::array_size($db_log['log']); if (is_array($db_log) and $max > 0) { $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;">Total Queries Number: <b>' . Smart::escape_html(Smart::format_number_int($db_log['total-queries'], '+')) . '</b></div>'; $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;">Total Queries Time: <b>' . Smart::escape_html(Smart::format_number_dec($db_log['total-time'], 9, '.', '')) . ' sec.' . '</b></div>'; $num = 0; for ($i = 0; $i < $max; $i++) { //-- $tmp_arr = (array) $db_log['log'][$i]; //-- switch ((string) $tmp_arr['type']) { case 'transaction': //-- $num++; //-- $tmp_color = '#003399'; //-- $log .= '<div class="smartframework_debugbar_inforow" style="font-size:12px; color:' . $tmp_color . ';">'; $log .= $num . '. ' . '<b>' . Smart::escape_html($tmp_arr['data']) . '</b>'; if ((string) $tmp_arr['connection'] != '') { $log .= ' @ ' . Smart::escape_html($tmp_arr['connection']); } //end if if ($tmp_arr['time'] > 0) { $log .= '<br><span style="padding:1px;"><b>@Time: ' . Smart::format_number_dec($tmp_arr['time'], 9, '.', '') . ' sec.</b></span>'; } //end if if ((string) $tmp_arr['query'] != '') { $log .= '<br><span class="smartframework_debugbar_status_highlight" style="padding:1px;"><b>' . Smart::escape_html($tmp_arr['query']) . '</b></span>'; } //end if $log .= '</div>'; //-- break; case 'set': case 'count': case 'read': case 'write': case 'nosql': //-- if ((string) $tmp_arr['skip-count'] != 'yes') { $num++; } //end if //-- if ((string) $tmp_arr['type'] == 'write') { $tmp_color = '#666699'; } elseif ((string) $tmp_arr['type'] == 'read') { $tmp_color = '#333333'; } elseif ((string) $tmp_arr['type'] == 'count') { $tmp_color = '#339900'; } elseif ((string) $tmp_arr['type'] == 'set') { $tmp_color = '#778899'; } else { // nosql $tmp_color = '#000000'; } //end if else //-- $log .= '<div class="smartframework_debugbar_inforow" style="font-size:11px; color:' . $tmp_color . ';">'; if ((string) $tmp_arr['skip-count'] != 'yes') { $log .= $num . '. '; } //end if else $log .= '<b>' . Smart::escape_html($tmp_arr['data']) . '</b>'; if ((string) $tmp_arr['connection'] != '') { $log .= ' @ ' . Smart::escape_html($tmp_arr['connection']); } //end if if ($tmp_arr['time'] > 0) { if ($tmp_arr['time'] <= $db_log['slow-time']) { $log .= '<br><span style="padding:1px;"><b>@Time: ' . Smart::format_number_dec($tmp_arr['time'], 9, '.', '') . ' sec.</b></span>'; } else { $log .= '<br><span class="smartframework_debugbar_status_warn" style="padding:1px;" title="Slow-Time: ' . Smart::escape_html($db_log['slow-time']) . '"><b>@Time: ' . Smart::format_number_dec($tmp_arr['time'], 9, '.', '') . ' sec.' . '</b></span>'; } //end if else } //end if if ((string) $tmp_arr['query'] != '') { $log .= '<br>' . Smart::escape_html($tmp_arr['query']); if ((string) $tmp_arr['type'] == 'write') { $log .= '<br>' . 'AFFECTED ROWS: #' . $tmp_arr['rows']; } //end if if (Smart::array_size($tmp_arr['params']) > 0) { $tmp_params = array(); foreach ($tmp_arr['params'] as $key => $val) { $tmp_params[] = Smart::escape_html('$' . ($key + 1) . ' => `' . $val . '`'); } //end foreach $log .= '<br>' . '@PARAMS: { ' . implode(', ', $tmp_params) . ' }'; $tmp_params = array(); } //end if } //end if if (is_array($tmp_arr['command'])) { $tmp_params = array(); foreach ($tmp_arr['command'] as $key => $val) { $tmp_params[] = Smart::escape_html($key . ' => `' . self::print_value_by_type($val) . '`'); } //end foreach $log .= '<br>' . '@COMMAND-PARAMS: { ' . implode(', ', $tmp_params) . ' }'; $tmp_params = array(); } elseif ((string) $tmp_arr['command'] != '') { $log .= '<br>' . Smart::nl_2_br(Smart::escape_html(str_replace(array("\r\n", "\r", "\t"), array("\n", "\n", ' '), $tmp_arr['command']))); } //end if $log .= '</div>'; //-- break; case 'open-close': //-- $tmp_color = '#4285F4'; //-- $log .= '<div class="smartframework_debugbar_inforow" style="font-size:12px; color:' . $tmp_color . ';">'; $log .= '<b>' . Smart::escape_html($tmp_arr['data']) . '</b>'; if ((string) $tmp_arr['connection'] != '') { $log .= ' @ ' . Smart::escape_html($tmp_arr['connection']); } //end if $log .= '</div>'; //-- break; case 'metainfo': default: //-- $tmp_color = '#CCCCCC'; //-- $log .= '<div class="smartframework_debugbar_inforow" style="font-size:12px; color:' . $tmp_color . ';">'; $log .= '<b>' . Smart::escape_html($tmp_arr['data']) . '</b>'; if ((string) $tmp_arr['connection'] != '') { $log .= ' @ ' . Smart::escape_html($tmp_arr['connection']); } //end if $log .= '</div>'; //-- } //end switch //-- } //end for //-- } else { //-- $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_warn" style="width: 100px; text-align: center;"><font size="2"><b>N/A</b></font></div>'; //-- } //end if //-- return $log; //-- }
/** * Parse Simple Notes :: '-----< yyyy-mm-dd hh:ii:ss >----- some note\nsome other line' * * @param STRING $ynotes :: The Text or HTML to be processed * @param YES/NO $y_hide_times :: Show / Hide the time stamps * @param #SIZE $y_tblsize :: HTML Table Size * @param #COLOR $ytxtcolor :: HTML Table Color for Text * @param #COLOR $ycolor :: HTML Table Row Color * @param #COLOR $ycolor_alt :: HTML Table Row Alternate Color * @param #COLOR $ybrdcolor :: HTML Table Border Color * @param #STYLE $y_style :: HTML Extra Style * * @access private * @internal * * @return STRING :: The HTML processed code */ public static function simple_notes($ynotes, $y_hide_times, $y_tblsize = '100%', $ytxtcolor = '#000000', $ycolor = '#FFFFFF', $ycolor_alt = '#FFFFFF', $ybrdcolor = '#CCCCCC', $y_style = ' style="overflow: auto; height:200px;"') { //-- if (strpos((string) $ynotes, '-----<') === false) { return $tbl_start . '<tr><td bgcolor="' . $ycolor . '" valign="top"><font size="1">' . Smart::nl_2_br(Smart::escape_html($ynotes)) . '</font></td></tr>' . $tbl_end; // not compatible notes, so we not parse them } //end if //-- $out = ''; //-- $tbl_start = '<table width="' . $y_tblsize . '" cellspacing="0" cellpadding="2" border="1" bordercolor="' . $ybrdcolor . '" style="border-style: solid; border-collapse: collapse;">' . "\n"; $tbl_end = '</table>'; //-- $tmp_shnotes_arr = (array) explode('-----<', (string) $ynotes); //-- $i_alt = 0; //-- if (Smart::array_size($tmp_shnotes_arr) > 0) { //-- $out .= '<!-- OVERFLOW START (S.NOTES) -->' . '<div title="#S.NOTES#"' . $y_style . '>' . "\n"; $out .= $tbl_start; //-- for ($i = 0; $i < Smart::array_size($tmp_shnotes_arr); $i++) { //-- $tmp_shnotes_arr[$i] = (string) trim((string) $tmp_shnotes_arr[$i]); //-- if (Smart::striptags(str_replace('-----<', '', (string) $tmp_shnotes_arr[$i])) != '') { //-- $tmp_expld = (array) explode('>-----', (string) $tmp_shnotes_arr[$i]); //-- $tmp_meta_expl = (array) explode('|', (string) $tmp_expld[0]); $tmp_meta_date = trim((string) $tmp_meta_expl[0]); if (strlen(trim((string) $tmp_meta_expl[1])) > 0) { $tmp_metainfo = ' :: ' . trim($tmp_meta_expl[1]); } else { $tmp_metainfo = ''; } //end if else //-- if (strlen(trim((string) $tmp_expld[1])) > 0) { //-- $i_alt += 1; //-- alternate if ($i_alt % 2) { $alt_color = $ycolor; } else { $alt_color = $ycolor_alt; } //end if else //-- $out .= '<tr>' . "\n"; $out .= '<td bgcolor="' . $alt_color . '" valign="top">' . "\n"; //-- if ((string) $y_hide_times != 'yes') { $out .= '<div align="right" title="' . Smart::escape_html('#' . $i_alt . '.' . $tmp_metainfo) . '"><font size="1" color="' . $ytxtcolor . '"><b>' . Smart::escape_html($tmp_meta_date) . '</b></font></div><font size="1" color="' . $ytxtcolor . '">' . Smart::nl_2_br(Smart::escape_html(trim($tmp_expld[1]))) . '</font>'; } else { $out .= '<div title="' . Smart::escape_html('#' . $i_alt . '. ' . $tmp_meta_date . $tmp_metainfo) . '"><font size="1" color="' . $ytxtcolor . '">' . Smart::nl_2_br(Smart::escape_html(trim($tmp_expld[1]))) . '</font></div>'; } //end if else //-- $out .= '</td>' . "\n"; $out .= '</tr>' . "\n"; //-- } //end if //-- } //end if //-- } //end for //-- $out .= $tbl_end; $out .= '</div>' . '<!-- OVERFLOW END (S.NOTES) -->' . "\n"; //-- } //end if //-- if ($i_alt <= 0) { $out = ''; } //end if //-- return $out; //-- }