public static function save_debug_info($y_area, $y_debug_token, $is_main) { //-- {{{SYNC-DEBUG-DATA}}} if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { return false; } //end if //-- if ((string) $y_area != 'idx' and (string) $y_area != 'adm') { return false; } //end if //-- $y_debug_token = trim((string) $y_debug_token); if ((string) $y_debug_token == '') { return false; } //end if //-- $the_dir = 'tmp/logs/' . Smart::safe_filename($y_area) . '/' . date('Y-m-d@H') . '-debug-data/' . Smart::safe_filename($y_debug_token) . '/'; //-- #END# SYNC //-- if ($is_main) { $the_file = $the_dir . 'debug-main.log'; } else { $the_file = $the_dir . 'debug-sub-req-' . time() . '-' . SmartHashCrypto::sha1($_SERVER['REQUEST_URI']) . '.log'; } //end if else //-- //-- if (!is_dir($the_dir)) { SmartFileSystem::dir_recursive_create($the_dir); } //end if //-- if (is_dir($the_dir)) { if (is_writable($the_dir)) { //-- $arr = array(); //-- generate debug info if set to show optimizations SmartMarkersTemplating::registerOptimizationHintsToDebugLog(); //-- generate debug info if set to show internals if (defined('SMART_FRAMEWORK_INTERNAL_DEBUG')) { Smart::registerInternalCacheToDebugLog(); SmartFrameworkRegistry::registerInternalCacheToDebugLog(); SmartAuth::registerInternalCacheToDebugLog(); SmartHashCrypto::registerInternalCacheToDebugLog(); SmartUtils::registerInternalCacheToDebugLog(); SmartMarkersTemplating::registerInternalCacheToDebugLog(); } //end if //-- $dbg_stats = (array) SmartFrameworkRegistry::getDebugMsgs('stats'); //-- $arr['date-time'] = date('Y-m-d H:i:s O'); $arr['debug-token'] = (string) $y_debug_token; $arr['is-request-main'] = $is_main; $arr['request-hash'] = SmartHashCrypto::sha1($_SERVER['REQUEST_URI']); $arr['request-uri'] = (string) $_SERVER['REQUEST_URI']; $arr['resources-time'] = $dbg_stats['time']; $arr['resources-memory'] = $dbg_stats['memory']; $arr['response-code'] = (int) http_response_code(); $arr['response-headers'] = base64_encode(Smart::seryalize((array) headers_list())); if (function_exists('getallheaders')) { $arr['request-headers'] = base64_encode(Smart::seryalize((array) getallheaders())); } else { $arr['request-headers'] = base64_encode(Smart::seryalize('')); } //end if else $arr['env-req-filtered'] = base64_encode(Smart::seryalize((array) SmartFrameworkRegistry::getRequestVars())); $arr['env-get'] = base64_encode(Smart::seryalize((array) $_GET)); $arr['env-post'] = base64_encode(Smart::seryalize((array) $_POST)); $arr['env-cookies'] = base64_encode(Smart::seryalize((array) $_COOKIE)); $arr['env-server'] = base64_encode(Smart::seryalize((array) $_SERVER)); if (@session_status() === PHP_SESSION_ACTIVE) { $arr['php-session'] = base64_encode(Smart::seryalize((array) $_SESSION)); } else { $arr['php-session'] = base64_encode(Smart::seryalize('')); } //end if else if (SmartAuth::check_login() === true) { $arr['auth-data'] = array('is_auth' => true, 'login_data' => (array) SmartAuth::get_login_data(), '#login-pass#', SmartAuth::get_login_password()); } else { $arr['auth-data'] = array('is_auth' => false, 'login_data' => array()); } //end if else foreach ((array) SmartFrameworkRegistry::getDebugMsgs('optimizations') as $key => $val) { $arr['log-optimizations'][(string) $key] = base64_encode(Smart::seryalize((array) $val)); } //end foreach foreach ((array) SmartFrameworkRegistry::getDebugMsgs('extra') as $key => $val) { $arr['log-extra'][(string) $key] = base64_encode(Smart::seryalize((array) $val)); } //end foreach foreach ((array) SmartFrameworkRegistry::getDebugMsgs('db') as $key => $val) { $arr['log-db'][(string) $key] = base64_encode(Smart::seryalize((array) $val)); } //end foreach $arr['log-mail'] = base64_encode(Smart::seryalize((array) SmartFrameworkRegistry::getDebugMsgs('mail'))); foreach ((array) SmartFrameworkRegistry::getDebugMsgs('modules') as $key => $val) { $arr['log-modules'][(string) $key] = base64_encode(Smart::seryalize((array) $val)); } //end foreach //-- SmartFileSystem::write($the_file, Smart::seryalize($arr)); //-- } //end if } //end if //-- //-- return true; //-- }
public static function Create_Required_Dirs() { //-- if (!defined('SMART_FRAMEWORK_VERSION')) { die('Smart Runtime // Create Required Dirs :: Requires SmartFramework to be loaded ...'); } //end if //-- if (self::$RequiredDirsCreated !== false) { return; // avoid run after it was used by runtime } //end if self::$RequiredDirsCreated = true; //-- @clearstatcache(); //-- tmp dir $dir = 'tmp/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); SmartFileSystem::write($dir . '.htaccess', trim((string) SMART_FRAMEWORK_HTACCESS_NOINDEXING) . "\n" . trim((string) SMART_FRAMEWORK_HTACCESS_NOEXECUTION) . "\n" . trim((string) SMART_FRAMEWORK_HTACCESS_FORBIDDEN) . "\n"); } else { // manage debug cleanup if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { if (is_file('tmp/SMART-FRAMEWORK__DEBUG-ON')) { if (is_dir('tmp/logs/idx/')) { SmartFileSystem::dir_delete('tmp/logs/idx/', true); } //end if if (is_dir('tmp/logs/adm/')) { SmartFileSystem::dir_delete('tmp/logs/adm/', true); } //end if SmartFileSystem::delete('tmp/SMART-FRAMEWORK__DEBUG-ON'); } //end if } else { SmartFileSystem::write_if_not_exists('tmp/SMART-FRAMEWORK__DEBUG-ON', 'DEBUG:ON'); } //end if else } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (Temporary Folder is Not Writable)'); die; } //end if if (!is_file($dir . '.htaccess')) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'The .htaccess file is missing on FileSystem #TMP: ' . $dir . '.htaccess', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- tmp locks dir $dir = 'tmp/locks/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- tmp cache dir $dir = 'tmp/cache/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- tmp logs dir $dir = 'tmp/logs/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (Error Log Folder is Not Writable)'); die; } //end if //-- tmp logs/admin dir $dir = 'tmp/logs/adm/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- tmp logs/idx dir $dir = 'tmp/logs/idx/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- tmp sessions dir $dir = 'tmp/sessions/'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- wpub dir $dir = 'wpub/'; // {{{SYNC-WPUB-DIR}}} $ctrlfile = $dir . '#wpub'; $htfile = $dir . '.htaccess'; $robotsfile = $dir . 'robots.txt'; if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); SmartFileSystem::write($robotsfile, 'User-agent: *' . "\n" . 'Disallow: *'); // avoid robots to index it SmartFileSystem::write($ctrlfile, 'FileName: #wpub (#WEB-PUBLIC)' . "\n" . 'Created by: App-Runtime' . "\n" . date('Y-m-d H:i:s O')); SmartFileSystem::write($htfile, trim((string) SMART_FRAMEWORK_HTACCESS_NOEXECUTION) . "\n"); // trim((string)SMART_FRAMEWORK_HTACCESS_NOINDEXING)."\n". } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: #WEB-PUBLIC Folder: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if if (!is_file($ctrlfile)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'Cannot Connect to FileSystem #WEB-PUBLIC: ' . $ctrlfile, 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if if (!is_file($htfile)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'The .htaccess file is missing on FileSystem #WEB-PUBLIC: ' . $htfile, 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- wpub/webapps-content $dir = 'wpub/webapps-content/'; // {{{SYNC-WEBAPPS-DIR}}} if (!is_dir($dir)) { SmartFileSystem::dir_create($dir); SmartFileSystem::write($dir . 'index.html', ''); } // end if if (!is_writable($dir)) { Smart::raise_error('#SMART-FRAMEWORK-CREATE-REQUIRED-DIRS#' . "\n" . 'General ERROR :: \'' . $dir . '\' is NOT writable !', 'App Init ERROR :: (See Error Log for More Details)'); die; } //end if //-- }
public static function mov_pw_process($y_mov_file, $y_mov_img_preview, $y_quality, $y_width, $y_height, $y_watermark = '', $y_waterlocate = 'center', $y_mov_blank_img_preview = '') { //-- $y_mov_file = (string) trim((string) $y_mov_file); $y_mov_img_preview = (string) trim((string) $y_mov_img_preview); $y_mov_blank_img_preview = (string) trim((string) $y_mov_blank_img_preview); $y_watermark = (string) trim((string) $y_watermark); //-- //-- $blank_mov_pw = 'lib/core/plugins/img/mediagallery/video.jpg'; // this must be jpeg like the preview generated by ffmpeg //-- $watermark_mov_pw = 'lib/core/plugins/img/mediagallery/play.png'; //-- //-- if ((string) $y_mov_blank_img_preview == '') { $y_mov_blank_img_preview = $blank_mov_pw; } //end if //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_blank_img_preview)) { $y_mov_blank_img_preview = $blank_mov_pw; } //end if //-- if (!is_file($y_mov_blank_img_preview)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Invalid Blank Preview Path: BLANK-PREVIEW=' . $y_mov_blank_img_preview); return ''; } //end if //-- if ((string) $y_watermark == '') { $y_watermark = $watermark_mov_pw; } //end if //-- //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_file)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: SRC=' . $y_mov_file); return ''; } //end if //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_mov_img_preview)) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: DEST=' . $y_mov_img_preview); return ''; } //end if //-- if ((string) $y_mov_file == (string) $y_mov_img_preview) { Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // The Origin movie and Destination image are the same: SRC=' . $y_mov_file . ' ; DEST=' . $y_mov_img_preview); return ''; } //end if //-- if ((string) $y_watermark != '') { if (!SmartFileSysUtils::check_file_or_dir_name($y_watermark)) { $y_watermark = ''; Smart::log_warning('SmartMediaGalleryConverter :: mov_pw_process // Unsafe Path: WATERMARK=' . $y_watermark); } //end if } //end if //-- //-- $y_quality = Smart::format_number_int($y_quality, '+'); if ($y_quality < 1) { $y_quality = 1; } //end if if ($y_quality > 100) { $y_quality = 100; } //end if //-- //-- $y_width = Smart::format_number_int($y_width, '+'); $y_height = Smart::format_number_int($y_height, '+'); //-- if ($y_width < 10) { $y_width = 10; } //end if if ($y_width > 240) { $y_width = 240; } //end if //-- if ($y_height < 10) { $y_height = 10; } //end if if ($y_height > 240) { $y_height = 240; } //end if //-- //-- {{{SYNC-GRAVITY}}} switch ((string) $y_waterlocate) { case 'northwest': $y_waterlocate = 'northwest'; break; case 'northeast': $y_waterlocate = 'northeast'; break; case 'southwest': $y_waterlocate = 'southwest'; break; case 'southeast': $y_waterlocate = 'southeast'; break; case 'center': default: $y_waterlocate = 'center'; } //end switch //-- //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { SmartFrameworkRegistry::setDebugMsg('extra', 'MEDIA-GALLERY', ['title' => '[INFO] :: MediaUTIL/Mov/Process-Preview', 'data' => "'" . SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER . "'" . ' :: ' . "'" . SMART_FRAMEWORK_MEDIAGALLERY_IMG_COMPOSITE . "'"]); } //end if //-- //-- $out = ''; //-- if (defined('SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER') and (string) SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER != '') { //-- $lock_file = $y_mov_img_preview . '.LOCK-MOV-MEDIAGALLERY'; $temporary_pw = $y_mov_img_preview . '.#tmp-preview#.jpg'; // {{{SYNC-MOV-TMP-PREVIEW}}} //-- $lock_time = Smart::format_number_int(SmartFileSystem::read($lock_file), '+'); //-- if ($lock_time > 0) { if ($lock_time + 45 < time()) { // allow max locktime of 45 seconds SmartFileSystem::delete($temporary_pw); // delete the old temporary if any SmartFileSystem::delete($lock_file); // release the lock file } //end if } //end if //-- if (is_file($y_mov_file) and !SmartFileSystem::file_or_link_exists($y_mov_img_preview) and !SmartFileSystem::file_or_link_exists($lock_file)) { //-- @chmod($y_mov_file, SMART_FRAMEWORK_CHMOD_FILES); //mark chmod //-- $out .= '<table width="550" bgcolor="#74B83F">'; $out .= '<tr><td>Processing Movie Preview:' . ' ' . "'" . Smart::escape_html(basename($y_mov_file)) . "'" . ' -> ' . "'" . Smart::escape_html(basename($y_mov_img_preview)) . "'" . '</td></tr>'; //-- create a lock file SmartFileSystem::write($lock_file, time()); //-- generate preview (jpeg) if (is_executable(SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER)) { // generate a max preview of 240x240 which will be later converted below $exec = SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER . ' -y -i ' . '"' . $y_mov_file . '"' . ' -s 240x240 -vframes 60 -f image2 -vcodec mjpeg -deinterlace ' . '"' . $temporary_pw . '"'; @exec($exec, $arr_result, $exitcode); } else { $arr_result = array('error' => 'IS NOT EXECUTABLE ...', 'movie-thumbnailer' => SMART_FRAMEWORK_MEDIAGALLERY_MOV_THUMBNAILER); $exitcode = -1; } //end if //-- $is_ok_pw = 1; if (!is_file($temporary_pw)) { $is_ok_pw = 0; } elseif (@filesize($temporary_pw) <= 1444) { // detect if blank jpeg of 240x240 $is_ok_pw = 0; } //end if //-- if ($is_ok_pw != 1) { SmartFileSystem::delete($temporary_pw); SmartFileSystem::copy($y_mov_blank_img_preview, $temporary_pw); // in the case ffmpeg fails we avoid enter into a loop, or if ffmpeg is not found we use a blank preview } //end if //-- $out .= '<tr><td>[DONE]</td></tr>'; if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { SmartFrameworkRegistry::setDebugMsg('extra', 'MEDIA-GALLERY', ['title' => '[INFO] :: MediaUTIL/Mov/Process-Preview/FFMpeg', 'data' => 'Runtime Result: ' . "'" . $y_mov_file . "'" . ' -> ' . "'" . $y_mov_img_preview . "'" . ' = [' . $exitcode . '] @ ' . @print_r($arr_result, 1)]); } //end if //-- process and apply watermark if any if (is_file($temporary_pw)) { //-- @chmod($temporary_pw, SMART_FRAMEWORK_CHMOD_FILES); //mark chmod //-- self::img_process('preview', 'no', $temporary_pw, $y_mov_img_preview, $y_quality, $y_width, $y_height, $y_watermark, $y_waterlocate); //-- SmartFileSystem::delete($temporary_pw); //-- } //end if //-- release the lock file SmartFileSystem::delete($lock_file); //-- $out .= '</table>'; //-- } //end if //-- } //end if //-- //-- return $out; //-- }
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; //-- }
/** * Generate a PDF Document on the fly from a piece of HTML code. * * Notice: this is using a secured cache folder, unique per visitor ID * * @param STRING $y_html_content :: The HTML Code * @param ENUM $y_orientation :: Page Orientation: 'normal' | 'wide' * @param STRING $y_runtime_script :: The allowed Runtime Script to allow send credentials for sub-downloads. Ex: admin.php * @param STRING $y_runtime_url :: The allowed Runtime URL ended by '/' to allow send credentials for sub-downloads. Ex: http(s)://some-server/some_path/ ; normally this should be set in config to enforce https:// and a single URL only * @param BOOLEAN $y_allow_send_credentials :: Set to TRUE to allow or set to FALSE to dissalow sending the auth credentials for sub-downloads: in the case there are embedded pictures generated by admin.php which may need authentication before to work, the credentials need to be set automatically in this case * * @returns STRING :: The PDF Document Contents * */ public static function generate($y_html_content, $y_orientation = 'normal', $y_runtime_script = '', $y_runtime_url = '', $y_allow_send_credentials = false) { //-- $pdfdata = ''; //-- $htmldoc = self::is_active(); //-- if ((string) $htmldoc != '') { //-- if ((string) $y_orientation == 'wide') { $orientation = self::tag_page_wide(); } else { $orientation = self::tag_page_normal(); } //end if else //-- $tmp_prefix_dir = 'tmp/cache/pdf/'; $protect_file = $tmp_prefix_dir . '.htaccess'; $dir = $tmp_prefix_dir . SMART_FRAMEWORK_SESSION_PREFIX . '/'; // we use different for index / admin / @ //-- $uniquifier = SmartUtils::unique_auth_client_private_key() . SMART_APP_VISITOR_COOKIE; $the_dir = $dir . Smart::safe_varname(Smart::uuid_10_seq() . '_' . Smart::uuid_10_num() . '_' . SmartHashCrypto::sha1($uniquifier)) . '/'; //-- $tmp_uuid = Smart::uuid_45($uniquifier) . Smart::uuid_36($uniquifier); $file = $the_dir . '__document_' . SmartHashCrypto::sha256('@@PDF#File::Cache@@' . $tmp_uuid) . '.html'; $logfile = $the_dir . '__headers_' . SmartHashCrypto::sha256('@@PDF#File::Cache@@' . $tmp_uuid) . '.log'; //-- if (is_dir($the_dir)) { SmartFileSystem::dir_delete($the_dir); } //end if //-- if (!is_dir($the_dir)) { SmartFileSystem::dir_recursive_create($the_dir); } // end if //-- SmartFileSystem::write_if_not_exists($protect_file, trim(SMART_FRAMEWORK_HTACCESS_FORBIDDEN) . "\n", 'yes'); //-- process the code $y_html_content = (string) self::remove_between_tags((string) $y_html_content); $y_html_content = (string) self::safe_charset((string) $y_html_content); //-- extract images $htmlparser = new SmartHtmlParser((string) $y_html_content); $arr_imgs = $htmlparser->get_tags('img'); $htmlparser = ''; unset($htmlparser); //-- $chk_duplicates_arr = array(); //-- for ($i = 0; $i < Smart::array_size($arr_imgs); $i++) { //-- $tmp_img_src = trim((string) $arr_imgs[$i]['src']); //-- if (strlen($chk_duplicates_arr[$tmp_img_src]) <= 0) { //-- $tmp_url_img_src = ''; //-- if ((string) $y_runtime_script != '' and (string) $y_runtime_url != '') { // replace relative paths if (substr($tmp_img_src, 0, @strlen($y_runtime_script)) == (string) $y_runtime_script) { $tmp_url_img_src = (string) $y_runtime_url . $tmp_img_src; $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $tmp_url_img_src . '"', (string) $y_html_content); $tmp_img_src = (string) $tmp_url_img_src; } //end if } //end if //-- $tmp_img_ext = '.' . strtolower(SmartFileSysUtils::get_file_extension_from_path($tmp_img_src)); // [OK] $tmp_img_cache = 'pdf_img_' . SmartHashCrypto::sha256('@@PDF#File::Cache::IMG@@' . '#' . $i . '@' . $tmp_img_src . '//' . $tmp_uuid); //-- $tmp_arr = array(); //-- if (substr($tmp_img_src, 0, 7) == 'http://' or substr($tmp_img_src, 0, 8) == 'https://') { //-- $tmp_img_ext = ''; // we clear the extension as we don't know yet (we will get it from headers) $tmp_img_cache = 'pdf_url_img_' . SmartHashCrypto::sha256('@@PDF#File::Cache::URL::IMG@@' . '#' . $i . '@' . $tmp_img_src . '//' . $tmp_uuid); //-- } //end if //-- if ($y_allow_send_credentials === true) { $allow_set_credentials = 'yes'; } else { $allow_set_credentials = 'no'; } //end if else //-- $tmp_arr = SmartUtils::load_url_or_file($tmp_img_src, SMART_FRAMEWORK_NETSOCKET_TIMEOUT, 'GET', '', '', '', $allow_set_credentials); // [OK] :: allow set credentials //-- $tmp_img_ext = '.noextension'; $tmp_where_we_guess = ''; //-- $guess_arr = array(); //-- $guess_arr = SmartUtils::guess_image_extension_by_url_head($tmp_arr['headers']); $tmp_img_ext = (string) $guess_arr['extension']; $tmp_where_we_guess = (string) $guess_arr['where-was-detected']; $guess_arr = array(); if ((string) $tmp_img_ext == '') { $tmp_img_ext = SmartUtils::guess_image_extension_by_first_bytes(substr($tmp_arr['content'], 0, 256)); if ((string) $tmp_img_ext != '') { $tmp_where_we_guess = ' First Bytes ...'; } //end if } //end if //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { // if debug, append information to log SmartFileSystem::write($logfile, '####################' . "\n" . '#################### [FILE # ' . $i . ' = \'' . $tmp_img_src . '\']' . "\n\n" . '==== [MODE] :: ' . $tmp_arr['mode'] . "\n" . '==== [LOG] :: ' . "\n" . $tmp_arr['log'] . "\n" . '==== [HEADERS] ::' . "\n" . $tmp_arr['headers'] . "\n" . '########' . "\n" . '==== [GUESS EXTENSION] :: ' . $tmp_where_we_guess . "\n\n" . '###################' . "\n\n\n\n", 'a'); } //end if //-- if ((string) $tmp_arr['result'] == '1' and (string) $tmp_arr['code'] == '200') { //-- SmartFileSystem::write($the_dir . $tmp_img_cache . $tmp_img_ext, $tmp_arr['content']); //-- if empty, it may be a file if ((string) $tmp_img_ext == '' or (string) $tmp_img_ext == '.png' or (string) $tmp_img_ext == '.gif' or (string) $tmp_img_ext == '.jpg') { $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $tmp_img_cache . $tmp_img_ext . '"', (string) $y_html_content); } else { // we want to avoid html code to be loaded as image by mistakes of http browser class or servers $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $y_runtime_url . 'lib/framework/img/sign_warn.png"', (string) $y_html_content); } //end if else //-- } else { //-- $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $y_runtime_url . 'lib/framework/img/sign_error.png"', (string) $y_html_content); //-- } //end if //-- } //end if //-- $chk_duplicates_arr[$tmp_img_src] = 'processed'; //-- } //end for //-- $chk_duplicates_arr = array(); unset($chk_duplicates_arr); $arr_imgs = array(); unset($arr_imgs); //-- SmartFileSystem::write($file, $orientation . "\n" . $y_html_content); //-- if (is_file($file)) { //-- ob_start(); //-- @passthru($htmldoc . ' ' . self::pdf_options($file)); //-- $pdfdata = ob_get_clean(); //-- } else { //-- Smart::log_warning('ERROR: PDF Generator Failed to find the PDF Document: ' . $file . "\n" . $y_html_content); //-- } //end if else //-- cleanup if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { // if not debug, cleanup the dir if (is_dir($the_dir)) { SmartFileSystem::dir_delete($the_dir); } //end if } //end if //-- } else { //-- Smart::log_notice('NOTICE: PDF Generator is INACTIVE ...'); //-- } //end if //-- return (string) $pdfdata; //-- }
/** * Load/Save a cache file from Memory or from a URL * * @param STRING $y_cache_file_extension :: File Extension (example: '.ext') * @param STRING $y_cache_prefix :: prefix dir (at least 3 chars) ended by slash (Example: 'prefix/') * @param STRING $y_load_url :: URL to Load (Ex: http(s)://some/test.txt ; memory://some.unique.key) * @param STRING $y_content :: just for memory:// ; contents of the file to be saved into cache - [set] mode ; if this is empty will just get * @param INT $y_cache_expire :: 0=never ; (>0)=seconds * @param ENUM $y_encrypted :: yes/no to encrypt the file content * @return MIXED :: cached contents */ public static function load_cached_content($y_cache_file_extension, $y_cache_prefix, $y_load_url, $y_content = '', $y_cache_expire = 0, $y_encrypted = 'no') { // v.150209 //-- $y_load_url = (string) $y_load_url; //-- if ((string) $y_load_url == '') { Smart::log_warning('Utils // Load From Cache ... Empty URL ...'); return ''; } //end if //-- //-- $y_cache_file_extension = Smart::safe_validname($y_cache_file_extension); //-- $y_cache_expire = Smart::format_number_int($y_cache_expire, '+'); //-- $y_cache_prefix = (string) $y_cache_prefix; //-- if (strlen($y_cache_prefix) >= 3 and strlen($y_cache_prefix) <= 64) { //-- $y_cache_prefix = SmartFileSysUtils::add_dir_last_slash($y_cache_prefix); // fix trailing slash //-- } else { //-- $y_cache_prefix = 'default/'; //-- } //end if //-- //-- $unique_id = (string) SmartHashCrypto::sha1('@@::SmartFramework::Content::Cache@@' . $y_load_url); //-- $dir = 'tmp/cache/' . $y_cache_prefix . SmartFileSysUtils::prefixed_sha1_path($unique_id); SmartFileSysUtils::raise_error_if_unsafe_path($dir); //-- $file = (string) $dir . $unique_id . $y_cache_file_extension; SmartFileSysUtils::raise_error_if_unsafe_path($file); //-- //-- if (!is_dir($dir)) { SmartFileSystem::dir_recursive_create($dir); } // end if //-- $protect_file = $dir . 'index.html'; if (!is_file($protect_file)) { SmartFileSystem::write($protect_file, ''); } //end if //-- //-- will go through this only if cache expired or no cache if (!is_file($file) or is_file($file) and $y_cache_expire > 0 and @filemtime($file) + $y_cache_expire < time()) { //-- read if (substr($y_load_url, 0, 9) == 'memory://' and (string) $y_content != '') { //-- set the content from memory $tmp_content = (string) $y_content; $tmp_result = '1'; $tmp_code = '200'; //-- } elseif (substr($y_load_url, 0, 9) != 'memory://') { //-- $arr = self::load_url_or_file($y_load_url); // [OK] $tmp_result = $arr['result']; $tmp_code = $arr['code']; $tmp_content = $arr['content']; $arr = array(); //-- } //end if else //-- if required, apply encryption if ((string) $y_encrypted == 'yes') { //-- $tmp_content = self::crypto_blowfish_encrypt($tmp_content); //-- } //end if //-- write to cache if ((string) $tmp_result == '1' and (string) $tmp_code == '200') { //-- SmartFileSystem::write($file, $tmp_content); // save file to cache (safe write is controlled via locks) //-- } //end if //-- $tmp_content = ''; //-- } //end if //-- //-- get from cache $out = SmartFileSystem::read($file); //-- if ((string) $y_encrypted == 'yes') { $out = self::crypto_blowfish_decrypt($out); } //end if //-- //-- return $out; //-- }
/** * Send Email Mime Message from SmartFramework to a destination * * @param STRING $to To: * @param STRING $bcc '' | BCc: * @param STRING $subj Subject: * @param STRING $message Body/Message: * @param TRUE/FALSE $is_html * Format: Html or Text/Plain * @param ARRAY $attachments * $attachments = array('file1.txt'=>'This is the file 1 content', ...); * @param ENUM $charset * charset * @param ENUM $priority * 1=Low ; 3=Normal ; 5=High * @param STRING $logsend_dir '' | path/to/log/messages * @param STRING $cc '' | Cc: * @param STRING $inreplyto '' | In-Reply-To: * @return TRUE/FALSE OPERATION RESULT [0 / 1] */ public static function send_email($to, $bcc, $subj, $message, $is_html, $attachments = array(), $charset = 'UTF-8', $priority = '3', $logsend_dir = '', $cc = '', $inreplyto = '', $replytoaddr = '') { //-- global $configs; //-- SMTP connection vars $server_settings = array('server_name' => $configs['sendmail']['server-host'], 'server_port' => $configs['sendmail']['server-port'], 'server_sslmode' => $configs['sendmail']['server-ssl'], 'server_auth_user' => $configs['sendmail']['auth-user'], 'server_auth_pass' => $configs['sendmail']['auth-password'], 'send_from_addr' => $configs['sendmail']['from-address'], 'send_from_name' => $configs['sendmail']['from-name'], 'smtp_mxdomain' => $configs['sendmail']['server-mx-domain']); //-- $stmp_y = date('Y'); $stmp_m = date('m'); $stmp_d = date('d'); $stmp_time = date('His'); //-- $logsend_dir = trim($logsend_dir); //-- if (strlen($logsend_dir) > 0) { //-- $logsend_dir = SmartFileSysUtils::add_dir_last_slash($logsend_dir); // if the last / is not present will add it $logsend_dir .= $stmp_y . '/' . $stmp_y . '-' . $stmp_m . '/' . $stmp_y . '-' . $stmp_m . '-' . $stmp_d . '/'; //-- SmartFileSystem::dir_recursive_create($logsend_dir); //-- $tmp_send_mode = 'send-return'; //-- } else { //-- $tmp_send_mode = 'send'; //-- } //end if else //-- $arr_send_result = self::send_extended_email($server_settings, $tmp_send_mode, $to, $cc, $subj, $message, $is_html, $attachments, $charset, $priority, $inreplyto, $bcc, $replytoaddr); //-- if (strlen($logsend_dir) > 0) { if (is_dir($logsend_dir)) { if (is_array($to)) { $mark_to = '@multi@'; } else { $mark_to = (string) $to; } //end if else SmartFileSystem::write($logsend_dir . $stmp_y . $stmp_m . $stmp_d . '_' . $stmp_time . '__' . Smart::safe_validname($mark_to) . '__' . sha1($to . $cc . $subj . $message) . '.eml', $arr_send_result['message']); } //end if } //end if //-- return $arr_send_result['result']; // only return the result as 0 for error and 1 for success //-- }