public static function getTranslationsFromSource($the_lang, $y_area, $y_subarea) { //-- if (substr((string) $y_area, 0, 1) == '@') { if ((string) $the_lang == 'en') { $fdb_dir = 'lib/app/translations/'; } else { // default is: modules/app/translations/ $fdb_dir = (string) SMART_FRAMEWORK_LANGUAGES_CACHE_DIR; } //end if else $fdb_template = strtolower($y_area . '/' . $y_subarea . '-' . $the_lang); } else { // $y_area can be: apps, mod-something, ... $fdb_dir = (string) Smart::safe_pathname('modules/' . $y_area . '/translations/'); $fdb_template = strtolower($y_subarea . '-' . $the_lang); } //end if else //-- $fdb_file = (string) $fdb_dir . $fdb_template . '.yaml'; SmartFileSysUtils::raise_error_if_unsafe_path($fdb_file); //-- if (!is_dir($fdb_dir)) { Smart::raise_error('Invalid Language Dir: ' . $fdb_dir . ' :: for: ' . $y_area . '@' . $y_subarea, 'Invalid Language Dir for: ' . $y_area . '@' . $y_subarea); return array(); } //end if //-- if (!is_file($fdb_file)) { //-- Smart::raise_error('Invalid Language File: ' . $fdb_file, 'Invalid Language File: ' . $fdb_template); return array(); //-- } //end if //-- $fcontent = SmartFileSystem::staticread($fdb_file); $arr = (new SmartYamlConverter())->parse((string) $fcontent); //-- if (!is_array($arr)) { Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template); return array(); } //end if //-- if (!is_array($arr['TRANSLATIONS'])) { Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template); return array(); } //end if if (Smart::array_size($arr['TRANSLATIONS'][(string) $y_subarea]) <= 0) { Smart::log_warning('Parse Error / TRANSLATIONS.' . $y_subarea . ' :: Language File: ' . $fdb_template); return array(); } //end if //-- return (array) $arr['TRANSLATIONS'][(string) $y_subarea]; //-- }
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 //-- }
/** * Check if Single-User Mode is Enabled * * @access private * @internal * * @return 0/1 */ public static function check_single_user() { //-- $lock_file = (string) self::lock_file(); //-- $out = 0; //-- if (SmartFileSystem::file_or_link_exists($lock_file)) { //-- $lock_content = SmartFileSystem::read($lock_file); $chk_arr = explode("\n", trim($lock_content)); $tmp_time = Smart::format_number_dec(($chk_arr[1] - time()) / 60, 0, '.', ''); //-- if ($tmp_time <= 0) { $out = 1; // TOTAL LOCKED (if greater or equal than ZERO it only warns) ! } //end if //-- } //end if //-- return $out; //-- }
private function folder_iterator($recurring, $dir_name, $include_dot_files, $search_pattern = '', $search_prevent_file = '', $search_prevent_override = '') { //-- $recurring = (bool) $recurring; $dir_name = (string) $dir_name; $include_dot_files = (bool) $include_dot_files; $search_pattern = (string) $search_pattern; $search_prevent_file = (string) $search_prevent_file; $search_prevent_override = (string) $search_prevent_override; //-- if ((string) $dir_name == '') { Smart::log_warning('LibFileSys // ReadsFolderRecurring // Dir Name is Empty !'); return; // this function does not return anything, but just stop here in this case } //end if //-- fix invalid path (must end with /) $dir_name = SmartFileSysUtils::add_dir_last_slash($dir_name); //-- protection SmartFileSysUtils::raise_error_if_unsafe_path($dir_name); //-- @clearstatcache(); //-- $this->pattern_search_str = $search_pattern; $this->search_prevent_file = $search_prevent_file; $this->search_prevent_override = $search_prevent_override; //-- if (SmartFileSystem::file_or_link_exists($dir_name) and !is_file($dir_name)) { // can be dir or link //list //-- if ($handle = opendir($dir_name)) { //--------------------------------------- while (false !== ($file = readdir($handle))) { //-- if ((string) $file != '.' and (string) $file != '..') { //-- if ($include_dot_files or !$include_dot_files and substr($file, 0, 1) != '.') { //-- SmartFileSysUtils::raise_error_if_unsafe_path($dir_name . $file); //-- params to see if counted or added to pattern matches $tmp_allow_addition = 1; $tmp_add_pattern = 0; //-- this is for #private folders, will prevent searching in folders containing for example this file: .private-folder but can be overriden by the $search_prevent_override option exluding a particular path like folder/private/user1 if (strlen($search_prevent_file) > 0 and is_file($dir_name . $search_prevent_file)) { if (strlen($search_prevent_override) <= 0 or strlen($search_prevent_override) > 0 and !is_file($dir_name . $search_prevent_override)) { $tmp_allow_addition = 0; } //end if } //end if //-- this is a search pattern (search pattern does not apply to folders !!) ; if no empty will populate the pattern matches array with all files and folders matching ; to include all, use * or a particular search for the rest like myfile1 if ((string) $search_pattern == '' or is_dir($dir_name . $file)) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { if ($this->limit_search_files <= 0 or Smart::array_size($this->pattern_file_matches) < $this->limit_search_files) { if ((string) $search_pattern == '*' or (string) $search_pattern == '[image]' and (substr($file, -4, 4) == '.png' or substr($file, -4, 4) == '.gif' or substr($file, -4, 4) == '.jpg' or substr($file, -5, 5) == '.jpeg') or (string) $search_pattern != '*' and (string) $search_pattern != '[image]' and stripos($file, $search_pattern) !== false) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { $tmp_allow_addition = 0; } //end if else } //end if } //end if //-- if ($this->limit_search_files > 0) { // the dir should not be taken in count here if ($this->num_files + $this->num_links >= $this->limit_search_files) { break; } //end if } //end if //-- if (!is_link($dir_name . $file)) { //-- if (is_dir($dir_name . $file)) { //-- dir if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_dirs++; $this->num_size += $tmp_fsize; $this->num_dirs_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- if ($recurring) { //-- we go search inside even if this folder name may not match the search pattern, it is a folder, except if dissalow addition from above $this->folder_iterator($recurring, SmartFileSysUtils::add_dir_last_slash($dir_name . $file), $include_dot_files, $search_pattern, $search_prevent_file, $search_prevent_override); //-- } //end if //-- } else { //-- file if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_files++; $this->num_size += $tmp_fsize; $this->num_files_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- } //end else //-- } else { //-- link if ($tmp_allow_addition) { //-- $link_result = SmartFileSystem::link_get_origin($dir_name . $file); //-- if (empty($link_result) or (string) $link_result == '' or !SmartFileSystem::file_or_link_exists($link_result)) { //-- // case of readlink error ..., not includding broken links, they are useless //-- } else { //-- $tmp_size_arr = array(); $tmp_fsize = 0; //$tmp_size_arr = (array) @lstat($dir_name.$file); //$tmp_fsize = Smart::format_number_int($tmp_size_arr[7],'+'); // $tmp_size_arr[7] -> size, but may break compare if on a different file system or in distributed storage on various OS //-- $this->num_links++; //-- if (file_exists($dir_name . $file)) { // here file_exists must be tested because if broken link not stat on it (filemtime) to avoid log un-necessary errors //-- bugfix: not if broken link $this->num_size += $tmp_fsize; if ($tmp_add_pattern) { if (is_dir($dir_name . $file)) { $this->num_dirs++; $this->num_dirs_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } else { $this->num_files++; $this->num_files_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if else } //end if //-- } //end if //-- $tmp_fsize = 0; $tmp_size_arr = array(); //-- } //end if else //-- } //end if //-- } //end if else //-- } //end if //-- } //end if(. ..) //-- } //end while //--------------------------------------- @closedir($handle); //--------------------------------------- } else { //--------------------------------------- $this->errors_arr[] = $dir_name; //--------------------------------------- } //end else //-- } else { //--------------------------------------- // nothing ... //--------------------------------------- } //end if else //-- }
public function ftp_put($remotefile, $localfile, $mode = 1) { //-- if (!SmartFileSystem::file_or_link_exists($localfile)) { $this->error_msg = 'ERROR: PUT command failed // No such file or directory (or broken link): ' . $localfile; return false; } //end if //-- $fp = @fopen($localfile, "rb"); if (!$fp) { $this->error_msg = 'ERROR: PUT command failed // Cannot read file: ' . $localfile; return false; } //end if //-- if (!$this->_type($mode)) { $this->error_msg = 'ERROR: PUT command failed - TYPE: ' . $mode; @fclose($fp); return false; } //end if //-- if (!($string = $this->_pasv())) { $this->error_msg = 'ERROR: PUT command failed - PASSIVE'; @fclose($fp); return false; } //end if //-- $this->_putcmd("STOR", $remotefile); //-- $sock_data = $this->_open_data_connection($string); //-- if (!$sock_data) { $this->error_msg = 'ERROR: PUT // Cannot connect to remote host'; return false; } //end if //-- if (!$this->_ok()) { $this->error_msg = 'ERROR: PUT command failed (1)'; $this->_close_data_connection($sock_data); return false; } //end if //-- $this->_debug_print('OK: PUT // Connected to remote host' . "\n"); if ((string) $this->debug_level == 'full') { $this->_debug_print('Storing local file: ' . $localfile . ' to remote file: ' . $remotefile . "\n"); } //end if //-- while (!feof($fp)) { @fwrite($sock_data, @fread($fp, $this->_buf)); } //end while //-- @fclose($fp); //-- $this->_close_data_connection($sock_data); //-- $response = $this->_ok(); if (!$response) { $this->error_msg = 'ERROR: PUT command failed (2)'; return false; } //end if //-- return $response; //-- }
/** * Read a Marker File Template from FileSystem or from Persistent (Memory) Cache if exists * !!! This is intended for very special usage ... !!! This is used automatically by the render_file_template() and used in combination with render_mixed_template() may produce the same results ... it make non-sense using it with render_template() as this should be used for internal (php) templates as all external templates should be loaded with render_file_template() * * @access private * @internal * * @param STRING $y_file_path :: The relative path to the file markers template * * @return STRING :: The template string * */ public static function read_template_file($y_file_path) { //-- $use_pcache = false; if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { if (defined('SMART_SOFTWARE_MKTPL_PCACHETIME')) { if (is_int(SMART_SOFTWARE_MKTPL_PCACHETIME)) { if ((int) SMART_SOFTWARE_MKTPL_PCACHETIME >= 0 and (int) SMART_SOFTWARE_MKTPL_PCACHETIME <= 31622400) { // 0 unlimited ; 1 sec .. 366 days $use_pcache = true; } //end if } //end if } //end if } //end if if ($use_pcache === true and SmartPersistentCache::isActive() and SmartPersistentCache::isMemoryBased()) { $the_cache_key = 'tpl__' . Smart::safe_pathname((string) Smart::base_name((string) $y_file_path)) . '__' . sha1((string) $y_file_path); } else { $the_cache_key = ''; } //end if else //-- $tpl = ''; //-- if ((string) $the_cache_key != '') { if (SmartPersistentCache::keyExists('smart-markers-templating', (string) $the_cache_key)) { $tpl = (string) SmartPersistentCache::getKey('smart-markers-templating', (string) $the_cache_key); if ((string) $tpl != '') { //Smart::log_notice('TPL found in cache: '.$y_file_path); return (string) $tpl; // return from persistent cache } //end if } //end if } //end if //-- $tpl = (string) SmartFileSystem::staticread((string) $y_file_path); if ((string) $the_cache_key != '') { if ((string) $tpl != '') { SmartPersistentCache::setKey('smart-markers-templating', (string) $the_cache_key . '__path', (string) $y_file_path, (int) SMART_SOFTWARE_MKTPL_PCACHETIME); // set to persistent cache SmartPersistentCache::setKey('smart-markers-templating', (string) $the_cache_key, (string) $tpl, (int) SMART_SOFTWARE_MKTPL_PCACHETIME); // set to persistent cache } //end if } //end if //-- return (string) $tpl; // return from fs read //-- }
public static function print_debug_info($y_area, $y_debug_token) { global $configs; //-- {{{SYNC-DEBUG-DATA}}} if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { return ''; } //end if //-- if ((string) $y_area != 'idx' and (string) $y_area != 'adm') { return ''; } //end if //-- $y_debug_token = trim((string) $y_debug_token); if ((string) $y_debug_token == '') { return ''; } //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 //-- $storage = (new SmartGetFileSystem(true))->get_storage($the_dir, true, false); $arr = array(); if (is_array($storage['list-files'])) { $storage['list-files'] = Smart::array_sort($storage['list-files'], 'natsort'); for ($i = 0; $i < Smart::array_size($storage['list-files']); $i++) { $arr[] = Smart::unseryalize(SmartFileSystem::read($storage['list-files'][$i])); } //end if } //end if $storage = array(); //-- //-- $debug_response = ''; $debug_resources = ''; $debug_environment = ''; $debug_session = ''; $debug_auth = ''; $debug_mail = ''; $debug_dbqueries = ''; $debug_optimizations = ''; $debug_extra = ''; $debug_modules = ''; $tmp_decode_arr = array(); //-- $start_marker = '<div class="smartframework_debugbar_status smartframework_debugbar_status_title"><font size="5"><b># DEBUG Data :: ALL REQUESTS #</b></font></div>'; $end_marker = '<div class="smartframework_debugbar_status smartframework_debugbar_status_title"><font size="3"><b># DEBUG # END #</b></font></div>'; //-- for ($i = 0; $i < Smart::array_size($arr); $i++) { //-- if ($arr[$i]['is-request-main'] === true) { $txt_main = '<div class="smartframework_debugbar_status smartframework_debugbar_status_title"><font size="5"><b># DEBUG Data :: MAIN REQUEST #</b></font></div>'; } else { $txt_main = '<div class="smartframework_debugbar_status smartframework_debugbar_status_title"><font size="3"><b># DEBUG Data :: SUB-REQUEST #</b></font></div>'; } //end if else $txt_token = '<div class="smartframework_debugbar_status smartframework_debugbar_status_token" style="width: 400px; text-align: center;"><font size="2"><b>Debug Token: ' . Smart::escape_html($arr[$i]['debug-token']) . '</b></font></div>'; $txt_url = '<div class="smartframework_debugbar_status smartframework_debugbar_status_url"><font size="2">URL: ' . Smart::escape_html($arr[$i]['request-uri']) . '</font></div>'; //-- $debug_response .= $txt_main . $txt_url . $txt_token . self::print_log_headers($arr[$i]['response-code'], Smart::unseryalize(base64_decode($arr[$i]['response-headers'])), Smart::unseryalize(base64_decode($arr[$i]['request-headers']))) . '<hr>'; //-- $debug_resources .= $txt_main . $txt_url . $txt_token . self::print_log_resources($arr[$i]['resources-time'], $arr[$i]['resources-memory']); //-- $debug_environment .= $txt_main . $txt_url . $txt_token . self::print_log_environment(Smart::unseryalize(base64_decode($arr[$i]['env-req-filtered'])), Smart::unseryalize(base64_decode($arr[$i]['env-cookies'])), Smart::unseryalize(base64_decode($arr[$i]['env-get'])), Smart::unseryalize(base64_decode($arr[$i]['env-post'])), Smart::unseryalize(base64_decode($arr[$i]['env-server']))) . '<hr>'; //-- $debug_session .= $txt_main . $txt_url . $txt_token . self::print_log_session(Smart::unseryalize(base64_decode($arr[$i]['php-session']))) . '<hr>'; //-- $debug_auth .= $txt_main . $txt_url . $txt_token . self::print_log_auth($arr[$i]['auth-data']) . '<hr>'; //-- if (is_array($arr[$i]['log-optimizations'])) { $debug_optimizations .= $txt_main . $txt_url . $txt_token; foreach ($arr[$i]['log-optimizations'] as $key => $val) { $debug_optimizations .= self::print_log_optimizations(strtoupper((string) $key), Smart::unseryalize(base64_decode($val))) . '<hr>'; } //end foreach } //end if //-- if (is_array($arr[$i]['log-mail'])) { $debug_mail .= $txt_main . $txt_url . $txt_token . self::print_log_mail(Smart::unseryalize(base64_decode($arr[$i]['log-mail']))) . '<hr>'; } //end if //-- if (is_array($arr[$i]['log-db'])) { $debug_dbqueries .= $txt_main . $txt_url . $txt_token; foreach ($arr[$i]['log-db'] as $key => $val) { $debug_dbqueries .= self::print_log_database(strtoupper((string) $key), Smart::unseryalize(base64_decode($val))) . '<hr>'; } //end foreach } //end if //-- if (is_array($arr[$i]['log-extra'])) { $debug_extra .= $txt_main . $txt_url . $txt_token; foreach ($arr[$i]['log-extra'] as $key => $val) { $debug_extra .= self::print_log_extra(strtoupper((string) $key), Smart::unseryalize(base64_decode($val))) . '<hr>'; } //end foreach } //end if //-- if (is_array($arr[$i]['log-modules'])) { $debug_modules .= $txt_main . $txt_url . $txt_token; foreach ($arr[$i]['log-modules'] as $key => $val) { $debug_modules .= self::print_log_modules(strtoupper((string) $key), Smart::unseryalize(base64_decode($val))) . '<hr>'; } //end foreach } //end if //-- } //end for //-- if ((string) $debug_optimizations == '') { $debug_optimizations = '<div class="smartframework_debugbar_status smartframework_debugbar_status_nodata"><font size="5"><b>Optimization Hints: N/A</b></font></div>'; } else { $debug_optimizations .= $end_marker; } //end if else //-- if ((string) $debug_mail == '') { $debug_mail = '<div class="smartframework_debugbar_status smartframework_debugbar_status_nodata"><font size="5"><b>Mail Debug: No data</b></font></div>'; } else { $debug_mail .= $end_marker; } //end if else //-- if ((string) $debug_dbqueries == '') { $debug_dbqueries = '<div class="smartframework_debugbar_status smartframework_debugbar_status_nodata"><font size="5"><b>Database Debug: No Queries found</b></font></div>'; } else { $debug_dbqueries .= $end_marker; } //end if else //-- if ((string) $debug_extra == '') { $debug_extra = '<div class="smartframework_debugbar_status smartframework_debugbar_status_nodata"><font size="5"><b>Extra Debug: No data</b></font></div>'; } else { $debug_extra .= $end_marker; } //end if else //-- if ((string) $debug_modules == '') { $debug_modules = '<div class="smartframework_debugbar_status smartframework_debugbar_status_nodata"><font size="5"><b>Modules Debug: No data</b></font></div>'; } else { $debug_modules .= $end_marker; } //end if else //-- //-- return SmartMarkersTemplating::render_file_template('lib/core/templates/debug-profiler-footer.inc.htm', array('DEBUG-TIME' => date('Y-m-d H:i:s O'), 'DEBUG-RUNTIME' => $start_marker . self::print_log_runtime() . $end_marker, 'DEBUG-CONFIGS' => $start_marker . self::print_log_configs() . $end_marker, 'DEBUG-RESOURCES' => $debug_resources . $end_marker, 'DEBUG-HEADERS' => $debug_response . $end_marker, 'DEBUG-ENVIRONMENT' => $debug_environment . $end_marker, 'DEBUG-SESSION' => $debug_session . $end_marker, 'DEBUG-AUTH' => $debug_auth . $end_marker, 'DEBUG-OPTIMIZATIONS' => $debug_optimizations, 'DEBUG-MAIL' => $debug_mail, 'DEBUG-DATABASE' => $debug_dbqueries, 'DEBUG-EXTRA' => $debug_extra, 'DEBUG-MODULES' => $debug_modules), 'no'); //-- }
/** * [PUBLIC] Draw an Image Gallery * * @param STRING $y_title :: a title for the gallery * @param STRING $y_dir :: path to scan * @param *OPTIONAL[yes/no] $y_process_previews_and_images :: If = 'yes', will create previews for images and videos (movies) and will create conformed images * @param *OPTIONAL[yes/no] $y_remove_originals :: If = 'yes', will remove original (images) after creating previews [$y_process_previews_and_images must be yes] * @param *OPTIONAL[>=0] $y_display_limit :: Items limit to display */ public function draw($y_title, $y_dir, $y_process_previews_and_images = 'no', $y_remove_originals = 'no', $y_display_limit = '0') { //-- $y_title = (string) $y_title; //-- $y_dir = (string) $y_dir; //-- $y_process_previews_and_images = (string) $y_process_previews_and_images; if ((string) $y_process_previews_and_images != 'yes') { $y_process_previews_and_images = 'no'; } //end if //-- $y_display_limit = Smart::format_number_int($y_display_limit, '+'); //-- //-- if ((string) $this->use_secure_links == 'yes') { if ((string) $this->secure_download_link == '' or (string) $this->secure_download_ctrl_key == '') { return '<h1>WARNING: Media Gallery / Secure Links Mode is turned ON but at least one of the: download link or the controller was NOT provided ...</h1>'; } //end if } //end if //-- //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_dir)) { return '<h1>ERROR: Invalid Folder for Media Gallery ...</h1>'; } //end if //-- $y_dir = SmartFileSysUtils::add_dir_last_slash($y_dir); SmartFileSysUtils::raise_error_if_unsafe_path($y_dir); //-- if (!is_dir($y_dir)) { return '<h1>WARNING: The Folder for Media Gallery does not exists ...</h1>'; } //end if //-- //-- $this->gallery_items = 0; //-- //-- constraint of params if ((string) $y_process_previews_and_images != 'yes') { $y_remove_originals = 'no'; } //end if //-- if (strlen($this->preview_formvar) > 0) { // avoid processing if it is displayed in a form $y_process_previews_and_images = 'no'; $y_remove_originals = 'no'; } //end if //-- //-- some inits ... $out = ''; $arr_files = array(); $processed = 0; //-- //-- $arr_storage = (array) (new SmartGetFileSystem(true))->get_storage($y_dir, false, false); $all_mg_files = (array) $arr_storage['list-files']; //-- //-- for ($i = 0; $i < Smart::array_size($all_mg_files); $i++) { //-- $file = (string) $all_mg_files[$i]; $ext = strtolower(SmartFileSysUtils::get_file_extension_from_path($file)); //-- if (substr($file, 0, 1) != '.' and strpos($file, '.#') === false and strpos($file, '#.') === false) { //-- if (is_file($y_dir . $file) and ((string) $ext == 'jpeg' or (string) $ext == 'jpg' or (string) $ext == 'gif' or (string) $ext == 'png')) { //-- if (SmartFileSysUtils::version_check($file, 'mg-preview')) { //-- it is an image preview file if (!is_file($y_dir . SmartFileSysUtils::version_add($file, 'mg-image'))) { SmartFileSystem::delete($y_dir . $file); // remove preview if orphan } //end if //-- } elseif (SmartFileSysUtils::version_check($file, 'mg-image')) { //-- it is an image file if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-preview'); //-- if (!is_file($tmp_file)) { //-- $out .= $this->img_preview_create($y_dir . $file, $tmp_file) . '<br>'; $processed += 1; //-- } //end if //-- } //end if //-- $arr_files[] = $file; $this->gallery_items += 1; //-- } elseif (SmartFileSysUtils::version_check($file, 'mg-vpreview')) { //-- it is a movie preview file if (stripos($file, '.#tmp-preview#.jpg') === false) { //-- $tmp_linkback_file = SmartFileSysUtils::get_noext_file_name_from_path(SmartFileSysUtils::version_remove($file)); //-- if (!is_file($y_dir . $tmp_linkback_file)) { SmartFileSystem::delete($y_dir . $file); // remove if orphan } //end if //-- } //end if //-- } else { // unprocessed image //-- if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-image'); //-- if (!is_file($tmp_file)) { //-- if ((string) $y_dir . $file != (string) $y_dir . strtolower($file)) { SmartFileSystem::rename($y_dir . $file, $y_dir . strtolower($file)); // make sure is lowercase, to be ok for back-check since versioned is lowercase } //end if //-- $out .= $this->img_conform_create($y_dir . $file, $tmp_file) . '<br>'; $processed += 1; //-- } else { //-- if ((string) $y_remove_originals == 'yes') { //-- SmartFileSystem::delete($y_dir . $file); $out .= '<table width="550" bgcolor="#FF3300"><tr><td>removing original image: \'' . Smart::escape_html($file) . '\'</td></tr></table><br>'; $processed += 1; //-- } //end if //-- } //end if else //-- } //end if //-- } //end if else //-- } elseif (is_file($y_dir . $file) and ((string) $ext == 'webm' or (string) $ext == 'ogv' or (string) $ext == 'mp4' or (string) $ext == 'mov' or (string) $ext == 'flv')) { // WEBM, OGV, MP4, MOV, FLV //-- process preview FLV / MOV ... if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-vpreview') . '.jpg'; //-- if (!is_file($tmp_file)) { //-- if ((string) $y_dir . $file != (string) $y_dir . strtolower($file)) { SmartFileSystem::rename($y_dir . $file, $y_dir . strtolower($file)); // make sure is lowercase, to be ok for back-check since versioned is lowercase } //end if //-- $out .= $this->mov_preview_create($y_dir . strtolower($file), $tmp_file) . '<br>'; $processed += 1; //-- } //end if //-- } //end if //-- $arr_files[] = $file; $this->gallery_items += 1; //-- } //end if else //-- } //end if //-- } //end for //-- //-- $out .= '<!-- START MEDIA GALLERY -->' . "\n"; //-- if ((string) $this->use_styles == 'yes') { $out .= '<div id="mediagallery_box">' . "\n"; } //end if //-- //-- $out_arr = array(); //-- if ($processed <= 0) { //-- $arr_files = Smart::array_sort($arr_files, 'natsort'); //-- $max_loops = Smart::array_size($arr_files); if ($y_display_limit > 0) { if ($y_display_limit < $max_loops) { $max_loops = $y_display_limit; } //end if } //end if //-- for ($i = 0; $i < $max_loops; $i++) { //-- $tmp_the_ext = strtolower(SmartFileSysUtils::get_file_extension_from_path($arr_files[$i])); // [OK] //-- if ((string) $tmp_the_ext == 'webm' or (string) $tmp_the_ext == 'ogv' or (string) $tmp_the_ext == 'mp4' or (string) $tmp_the_ext == 'mov' or (string) $tmp_the_ext == 'flv') { $out_arr[] = $this->mov_draw_box($y_dir, $arr_files[$i], $tmp_the_ext); } else { $out_arr[] = $this->img_draw_box($y_dir, $arr_files[$i]); } //end if //-- } //end for //-- $out .= '<div title="' . Smart::escape_html($this->gallery_show_counter) . '">' . "\n"; //-- if ((string) $y_title != '') { $out .= '<div id="mediagallery_title">' . Smart::escape_html($y_title) . '</div><br>'; } //end if $out .= '<div id="mediagallery_row">'; for ($i = 0; $i < Smart::array_size($out_arr); $i++) { $out .= '<div id="mediagallery_cell">'; $out .= $out_arr[$i]; $out .= '</div>' . "\n"; } //end for $out .= '</div>'; //-- $out .= '</div>' . "\n"; //-- } //end if //-- $out_arr = array(); //-- //-- if ((string) $this->use_styles == 'yes') { $out .= '</div>' . "\n"; } //end if //-- $out .= '<!-- END MEDIA GALLERY -->' . "\n"; //-- //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { if ($processed > 0) { $out = '<img src="' . $this->pict_reloading . '" alt="[Reloading Page ...]" title="[Reloading Page ...]"><script type="text/javascript">setTimeout(function(){ self.location = self.location; }, 2000);</script>' . '<br><hr><br>' . $out; define('SMART_FRAMEWORK__MEDIA_GALLERY_IS_PROCESSING', $processed); // notice that the media galery is processing } //end if } //end if //-- //-- return $out; //-- }
public function Run() { //-- sample page variable from Request (GET/POST) $some_var_from_request = $this->RequestVarGet('extra_text', 'default', 'string'); //-- //-- $module_area = $this->ControllerGetParam('module-area'); $the_lang = (string) $this->ConfigParamGet('regional.language-id'); $the_xlang = (string) $this->ConfigParamGet('regional.language-id'); // repeat this to check if caching works //-- if ($this->IfDebug()) { $this->SetDebugData('Module Area', $module_area); $this->SetDebugData('Module Path', $this->ControllerGetParam('module-path')); $this->SetDebugData('Module Name', $this->ControllerGetParam('module-name')); $this->SetDebugData('URL Script', $this->ControllerGetParam('url-script')); $this->SetDebugData('URL Path', $this->ControllerGetParam('url-path')); $this->SetDebugData('URL Address', $this->ControllerGetParam('url-addr')); $this->SetDebugData('URL Page', $this->ControllerGetParam('url-page')); $this->SetDebugData('Config / Language ID', $the_lang); } //end if //-- //-- if ($this->PageCacheisActive()) { //-- because the Request can modify the content, also the unique key must take in account variables that will vary the page config or page content vars $the_page_cache_key = 'samples-toolkit-' . $module_area . '__' . SmartHashCrypto::sha384((string) $some_var_from_request); //-- } //end if //-- //-- if ($this->PageCacheisActive()) { //-- $test_cache = $this->PageGetFromCache('cached-samples', $the_page_cache_key); //-- if (Smart::array_size($test_cache) > 0) { if (is_array($test_cache['configs']) && is_array($test_cache['vars'])) { // if valid cache (test as we exported both arrays ... so they must be the 2 arrays again) $this->PageViewSetCfgs((array) $test_cache['configs']); $this->PageViewSetVars((array) $test_cache['vars']); $this->PageViewAppendVar('main', "\n" . '<!-- Redis Cached Content Key: ' . Smart::escape_html($the_page_cache_key) . ' -->' . "\n"); // add a markup to the HTML to know was served from cache ... if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Serving page from Persistent Cache: Redis (override PHP Execution). Page key is: ' . $the_page_cache_key); } // end if return; // the page was served from Cache (stop here) } //end if } //end if //-- } //end if //-- //=== if no cached, execute the code below ... //-- $this->PageViewSetCfg('template-path', 'default'); // set the template path (must be inside etc/templates/) $this->PageViewSetCfg('template-file', 'template.htm'); // set the template file //-- //-- $fcontent = SmartFileSystem::staticread('lib/framework/css/ux-toolkit-samples.html'); $arr_data = explode('<body>', $fcontent); $fcontent = (string) $arr_data[1]; $arr_data = explode('</body>', $fcontent); $fcontent = (string) $arr_data[0]; //-- //-- building a semantic URL $url_test_unit = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.testunit', 'tab' => 0)); // will generate: index.php?page=samples.testunit OR admin.php?page=samples.testunit $url_test_unit = Smart::url_make_semantic($url_test_unit); // convert the above to a pretty URL as: ?/page/samples.testunit (in this case index.php is ignored) OR admin.php?/page/samples.testunit //-- //-- building a regular URL $url_benchmark = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.benchmark.html')); $url_benchmark = Smart::url_make_semantic($url_benchmark); //-- //-- $translator_core = SmartTextTranslations::getTranslator('@core', 'messages'); //-- $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples'); $txt_hello_world = $translator_mod_samples->text('hello-world'); unset($translator_mod_samples); // this is just an internal test, normally the translator should not be unset ... $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples'); $txt_this_is_sf = $translator_mod_samples->text('this-is-smart-framework'); //-- //-- $this->PageViewSetVars(['title' => 'Toolkit Samples', 'main' => '<h1>This text should not be displayed, it was RESET !!!</h1>']); $this->PageViewResetVar('main'); // test reset $this->PageViewSetVar('main', SmartMarkersTemplating::render_template('<h1>' . '[####TXT-HELLO-WORLD####]</h1><div align="right"><b>[####DATE-TIME|html####] [[####TXT-OK####]]' . "\n" . '</b></div><br><a class="ux-button ux-button-special" href="http://sourceforge.net/projects/warp-cms/files/smart-framework/" target="_blank"><i class="fa fa-cloud-download"></i> Download Smart.Framework (latest stable releases)</a> <a class="ux-button ux-button-highlight" href="http://demo.unix-world.org/smart-framework.docs/" target="_blank"><i class="fa fa-book"></i> Documentation for the Smart.Framework</a><br>' . "\n" . '<br><a class="ux-button ux-button-primary" href="[####URL-TESTUNIT|html####]"><i class="fa fa-object-group"></i> Go to the Smart.Framework PHP/Javascript Test & Demo Suite</a> <a class="ux-button ux-button-secondary" href="[####URL-BENCHMARK|html####]"><i class="fa fa-line-chart"></i> Benchmark URL for Smart.Framework</a><br><br>', ['DATE-TIME' => date('Y-m-d H:i:s O'), 'TXT-OK' => $translator_core->text('ok'), 'TXT-HELLO-WORLD' => '<span title="LanguageID: ' . Smart::escape_html($the_xlang) . '" style="cursor:help;">' . '[' . Smart::escape_html($the_lang) . ']' . '</span>' . ' ' . $txt_hello_world . ', ' . $txt_this_is_sf . ' - a modern PHP / Javascript framework featuring MVC + Middlewares', 'URL-TESTUNIT' => $url_test_unit, 'URL-BENCHMARK' => $url_benchmark])); $this->PageViewAppendVar('main', '<hr><div style="color:#DDDDDD">' . Smart::escape_html('Unicode@String :: Smart スマート // Cloud Application Platform クラウドアプリケーションプラットフォーム :: áâãäåāăąÁÂÃÄÅĀĂĄ ćĉčçĆĈČÇ ďĎ èéêëēĕėěęÈÉÊËĒĔĖĚĘ ĝģĜĢ ĥħĤĦ ìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮ ijĵIJĴ ķĶ ĺļľłĹĻĽŁ ñńņňÑŃŅŇ óôõöōŏőøœÒÓÔÕÖŌŎŐØŒ ŕŗřŔŖŘ șşšśŝßȘŞŠŚŜ țţťȚŢŤ ùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲ ŵŴ ẏỳŷÿýẎỲŶŸÝ źżžŹŻŽ') . '</div><hr><div align="right">[' . Smart::escape_html($some_var_from_request) . ']</div>'); $this->PageViewAppendVar('main', trim($fcontent)); //-- //== cache page (if redis - persistent cache is set in config) //-- if Redis is active this will cache the page for 1 hour ... if ($this->PageCacheisActive()) { //-- $this->PageSetInCache('cached-samples', $the_page_cache_key, array('configs' => $this->PageViewGetCfgs(), 'vars' => $this->PageViewGetVars()), 3600); //-- if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Setting page in Persistent Cache: Redis (after PHP Execution). Page key is: ' . $the_page_cache_key); } //end if //-- } else { //-- if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Persistent Cache (Redis) is not active. Serving Page from PHP Execution.'); } //end if //-- } //end if else //-- }
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; //-- }
/** * Start the Session on request * */ public static function start() { //===== //-- if (self::$started !== false) { return; // avoid start session if already started ... } //end if self::$started = true; // avoid run start again //-- //===== //-- $browser_os_ip_identification = SmartUtils::get_os_browser_ip(); // get browser and os identification //-- if ((string) $browser_os_ip_identification['bw'] == '@s#' or (string) $browser_os_ip_identification['bw'] == 'bot') { return; // in this case start no session for robots or the self browser (as they do not need to share info between many visits) ; if the self browser fail to identify will be at least identified as robot in the worst case } //end if //-- //===== //-- no log as the cookies can be dissalowed by the browser if ((string) SMART_APP_VISITOR_COOKIE == '') { return; // session need cookies } //end if //-- //===== //-- $sf_sess_mode = 'files'; $sf_sess_area = 'default-sess'; $sf_sess_ns = 'unknown'; $sf_sess_dir = 'tmp/sess'; //-- //===== if (!defined('SMART_FRAMEWORK_SESSION_PREFIX')) { Smart::log_warning('FATAL ERROR: Invalid Session Prefix :: SMART_FRAMEWORK_SESSION_PREFIX'); return; } //end if if (strlen(SMART_FRAMEWORK_SESSION_PREFIX) < 3 or strlen(SMART_FRAMEWORK_SESSION_PREFIX) > 9) { Smart::log_warning('WARNING: Session Prefix must have a length between 3 and 9 characters :: SMART_FRAMEWORK_SESSION_PREFIX'); return; } //end if if (!preg_match('/^[a-z\\-]+$/', (string) SMART_FRAMEWORK_SESSION_PREFIX)) { Smart::log_warning('WARNING: Session Prefix contains invalid characters :: SMART_FRAMEWORK_SESSION_PREFIX'); return; } //end if //-- if (!defined('SMART_FRAMEWORK_SESSION_NAME')) { Smart::log_warning('FATAL ERROR: Invalid Session Name :: SMART_FRAMEWORK_SESSION_NAME'); return; } //end if if (strlen(SMART_FRAMEWORK_SESSION_NAME) < 10 or strlen(SMART_FRAMEWORK_SESSION_NAME) > 25) { Smart::log_warning('WARNING: Session Name must have a length between 10 and 25 characters :: SMART_FRAMEWORK_SESSION_NAME'); return; } //end if if (!preg_match('/^[_A-Za-z0-9]+$/', (string) SMART_FRAMEWORK_SESSION_NAME)) { Smart::log_warning('WARNING: Session Name contains invalid characters :: SMART_FRAMEWORK_SESSION_NAME'); return; } //end if if (!SmartFrameworkSecurity::ValidateVariableName(strtolower(SMART_FRAMEWORK_SESSION_NAME))) { Smart::log_warning('WARNING: Session Name have an invalid value :: SMART_FRAMEWORK_SESSION_NAME'); return; } //end if //-- if (!defined('SMART_FRAMEWORK_SESSION_LIFETIME')) { Smart::log_warning('FATAL ERROR: Invalid Session GC Lifetime :: SMART_FRAMEWORK_SESSION_LIFETIME'); return; } //end if if (!is_int(SMART_FRAMEWORK_SESSION_LIFETIME)) { Smart::log_warning('Invalid INIT constant value for SMART_FRAMEWORK_SESSION_LIFETIME'); return; } //end if //-- if (!is_dir('tmp/sessions/')) { Smart::log_warning('FATAL ERROR: The Folder \'tmp/sessions/\' does not exists for use with Session !'); return; } //end if //-- $detected_session_mode = (string) ini_get('session.save_handler'); if ((string) $detected_session_mode === 'files') { if ((string) SMART_FRAMEWORK_SESSION_HANDLER !== 'files') { Smart::log_warning('FATAL ERROR: The value set for SMART_FRAMEWORK_SESSION_HANDLER is not set to: files / but the value found in session.save_handler is: ' . $detected_session_mode); return; } //end if } elseif ((string) $detected_session_mode === 'user') { if ((string) SMART_FRAMEWORK_SESSION_HANDLER === 'files') { Smart::log_warning('FATAL ERROR: The value set for SMART_FRAMEWORK_SESSION_HANDLER is set to: files / but the value found in session.save_handler is: ' . $detected_session_mode); return; } //end if } else { Smart::log_warning('FATAL ERROR: The value set for session.save_handler must be set to one of these modes: files or user'); return; } //end if //-- //===== //-- generate a the client private key based on it's IP and Browser $the_sess_client_uuid = SmartUtils::unique_client_private_key(); // SHA512 key to protect session data agains forgers //-- a very secure approach based on a chain, derived with a secret salt from the framework security key: // (1) an almost unique client private key lock based on it's IP and Browser // (2) an entropy derived from the client random cookie combined with the (1) // (3) a unique session name suffix derived from (1) and (2) // (4) a unique session id composed from (1) and (2) //-- thus the correlation between the random public client cookie, the session name suffix and the session id makes impossible to forge it as it locks to IP+Browser, using a public entropy cookie all encrypted with a secret key and derived and related, finally composed. $the_sess_client_lock = SmartHashCrypto::sha1(SMART_FRAMEWORK_SECURITY_KEY . '#' . $the_sess_client_uuid); $the_sess_client_entropy = SmartHashCrypto::sha1(SMART_APP_VISITOR_COOKIE . '*' . $the_sess_client_uuid . '%' . SMART_FRAMEWORK_SECURITY_KEY); $the_sess_nsuffix = SmartHashCrypto::sha1($the_sess_client_uuid . ':' . SMART_FRAMEWORK_SECURITY_KEY . '^' . $the_sess_client_entropy . '+' . $the_sess_client_lock . '$' . SMART_APP_VISITOR_COOKIE); $the_sess_id = $the_sess_client_entropy . '-' . $the_sess_client_lock; // session ID combines the secret client key based on it's IP / Browser and the Client Entropy Cookie //-- $sf_sess_area = Smart::safe_filename((string) SMART_FRAMEWORK_SESSION_PREFIX); $sf_sess_dpfx = substr($the_sess_client_entropy, 0, 1) . '-' . substr($the_sess_client_lock, 0, 1); // this come from hexa so 3 chars are 16x16x16=4096 dirs //-- if ((string) $browser_os_ip_identification['bw'] == '@s#') { $sf_sess_ns = '@sr-' . $sf_sess_dpfx; } elseif ((string) $browser_os_ip_identification['bw'] == 'bot') { $sf_sess_ns = 'r0-' . $sf_sess_dpfx; // we just need a short prefix for robots (on disk is costly for GC to keep separate folders, but of course, not so safe) } else { $sf_sess_ns = 'c-' . substr($browser_os_ip_identification['bw'], 0, 3) . '-' . $sf_sess_dpfx; // we just need a short prefix for clients (on disk is costly for GC to keep separate folders, but of course, not so safe) } //end if else $sf_sess_ns = Smart::safe_filename($sf_sess_ns); //-- by default set for files $sf_sess_mode = 'files'; $sf_sess_dir = 'tmp/sessions/' . $sf_sess_area . '/' . $sf_sess_ns . '/'; if ((string) $detected_session_mode === 'user') { if (class_exists('SmartCustomSession')) { if ((string) get_parent_class('SmartCustomSession') == 'SmartAbstractCustomSession') { $sf_sess_mode = 'user-custom'; $sf_sess_dir = 'tmp/sessions/' . $sf_sess_area . '/'; // here the NS is saved in DB so we do not need to complicate paths } else { Smart::log_warning('SESSION INIT ERROR: Invalid Custom Session Handler. The class SmartCustomSession must be extended from class SmartAbstractCustomSession ...'); return; } //end if else } else { Smart::log_warning('SESSION INIT ERROR: Custom Session Handler requires the class SmartCustomSession ...'); return; } //end if } //end if $sf_sess_dir = Smart::safe_pathname($sf_sess_dir); //-- if (!is_dir($sf_sess_dir)) { SmartFileSystem::dir_recursive_create($sf_sess_dir); } //end if SmartFileSystem::write_if_not_exists('tmp/sessions/' . $sf_sess_area . '/' . 'index.html', ''); //===== //-- @session_save_path($sf_sess_dir); @session_cache_limiter('nocache'); //-- $the_name_of_session = (string) SMART_FRAMEWORK_SESSION_NAME . '__Key_' . $the_sess_nsuffix; // protect session name data agains forgers //-- @session_id((string) $the_sess_id); @session_name((string) $the_name_of_session); //-- $tmp_exp_seconds = Smart::format_number_int(SMART_FRAMEWORK_SESSION_LIFETIME, '+'); if ($tmp_exp_seconds > 0) { @session_set_cookie_params((int) $tmp_exp_seconds, '/'); // session cookie expire and the path } // end if //-- be sure that session_write_close() is executed at the end of script if script if die('') premature and before pgsql shutdown register in the case of DB sessions register_shutdown_function('session_write_close'); //-- handle custom session handler if ((string) $sf_sess_mode === 'user-custom') { //-- $sess_obj = new SmartCustomSession(); $sess_obj->sess_area = (string) $sf_sess_area; $sess_obj->sess_ns = (string) $sf_sess_ns; $sess_obj->sess_expire = (int) $tmp_exp_seconds; //-- session_set_save_handler(array($sess_obj, 'open'), array($sess_obj, 'close'), array($sess_obj, 'read'), array($sess_obj, 'write'), array($sess_obj, 'destroy'), array($sess_obj, 'gc')); //-- } //end if else //-- start session @session_start(); //-- if ((string) $_SESSION['SoftwareFramework_VERSION'] != (string) SMART_FRAMEWORK_VERSION or (string) $_SESSION['website_ID'] != (string) SMART_SOFTWARE_NAMESPACE or strlen($_SESSION['session_ID']) < 32) { //-- $_SESSION['SoftwareFramework_VERSION'] = (string) SMART_FRAMEWORK_VERSION; // software version $_SESSION['SoftwareFramework_SessionMode'] = (string) $sf_sess_mode; // session mode $_SESSION['website_ID'] = (string) SMART_SOFTWARE_NAMESPACE; // the website ID $_SESSION['uniqbrowser_ID'] = (string) $the_sess_client_uuid; // a true unique browser ID (this is a protection against sessionID forgers) $_SESSION['session_ID'] = (string) @session_id(); // read current session ID $_SESSION['session_STARTED'] = (string) date('Y-m-d H:i:s O'); // read current session ID //-- } //end if //-- if (!isset($_SESSION['visit_COUNTER'])) { $_SESSION['visit_COUNTER'] = 1; } else { $_SESSION['visit_COUNTER'] += 1; } //end if else //-- $_SESSION['SmartFramework__Browser__Identification__Data'] = (array) $browser_os_ip_identification; //-- if ((string) $_SESSION['uniqbrowser_ID'] != (string) $the_sess_client_uuid) { // we need at least a md5 session //-- log, then unset old session (these are not well tested ...) Smart::log_notice('Session Security Breakpoint :: Session-BrowserUniqueID = ' . $_SESSION['uniqbrowser_ID'] . "\n" . 'SessionSecurityUniqueID = ' . $the_sess_client_uuid . "\n" . 'Browser Ident = ' . $browser_os_ip_identification['bw'] . "\n" . 'Cookies = ' . print_r($_COOKIE, 1) . "\n" . 'SessID = ' . $_SESSION['session_ID'] . "\n" . 'ClientIP = ' . SmartUtils::get_ip_client() . ' @ ' . $_SERVER['REMOTE_ADDR'] . "\n" . 'UserAgent = ' . $_SERVER['HTTP_USER_AGENT']); $_SESSION = array(); // reset it //-- unset the cookie (from this below is tested) @setcookie($the_name_of_session, 'EXPIRED', 1, '/'); //-- stop execution with message Smart::raise_error('SESSION // SECURITY BREAK POINT: Possible Session Forgery Detected ...', 'SESSION // SECURITY BREAK POINT: Possible Session Forgery Detected ! Please refresh the page ... A new session will be assigned ! If you are not trying to forge another user\' session this situation can occur also if you are behind a proxy and some of your navigation parameters has been changed ! If this problem persist try to restart your browser or use other browser. If still persist, contact the website administrator'); die(''); // just in case return; // or is better to silent discard it ? //-- } //end if //-- self::$active = time(); // successfuly started //-- }
/** * 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; //-- }
private static function read_mime_message($y_enc_msg_file, $y_ctrl_key, $y_process_mode, $y_show_headers, $y_title, $y_link, $y_target) { // $y_process_mode : 'default' | 'print' | 'data-full' | 'data-reply' // $y_show_headers : 'default' | 'subject' (just for mode: 'default' | 'print') //-- $msg_decode_arr = (array) self::decode_mime_fileurl((string) $y_enc_msg_file, (string) $y_ctrl_key); //-- if ((string) $msg_decode_arr['error'] != '') { Smart::raise_error('ERROR: MIME Parser // Mesage File Decode: ' . $msg_decode_arr['error'], 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- //-- $the_message_eml = (string) trim((string) $msg_decode_arr['message-file']); $the_part_id = (string) trim((string) $msg_decode_arr['message-part']); //-- //-- if ((string) $the_message_eml == '' or !is_file((string) $the_message_eml)) { Smart::raise_error('ERROR: MIME Parser // Message File EMPTY or NOT FOUND !: ' . $the_message_eml, 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- if (substr((string) $the_message_eml, -4, 4) != '.eml') { Smart::raise_error('ERROR: MIME Parser // Message File Extension is not .eml !: ' . $the_message_eml, 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- //-- $out = ''; // init $reply_text = array(); // init //-- //== //-- $content = SmartFileSystem::read((string) $the_message_eml); $eml = new SmartMailerMimeDecode(); $head = $eml->get_header(SmartUnicode::sub_str((string) $content, 0, 65535)); // some messages fail with 8192 to decode ; a faster compromise would be 16384, but here we can use a higher value since is done once (text 65535) $msg = $eml->get_bodies((string) $content, (string) $the_part_id); unset($eml); unset($content); //-- //== //-- $reg_atts_num = 0; $reg_atts_list = ''; // list separed by \n //-- if (strlen($the_part_id) <= 0) { //-- display whole message $reg_is_part = 'no'; $skip_part_processing = 'no'; $skip_part_linking = 'no'; //-- } else { //-- display only a part of the message $reg_is_part = 'yes'; $skip_part_processing = 'no'; $skip_part_linking = 'yes'; //-- if (substr($the_part_id, 0, 4) == 'txt_') { //-- text part $tmp_part = $msg['texts'][$the_part_id]; $msg = array(); $msg['texts'][$the_part_id] = (array) $tmp_part; unset($tmp_part); //-- } else { //-- att / cid part $skip_part_processing = 'yes'; //-- if (!is_array($msg['attachments'][$the_part_id])) { // try to normalize name $the_part_id = trim(str_replace(' ', '', $the_part_id)); } //end if //-- $out = (string) $msg['attachments'][$the_part_id]['content']; // DO NO MORE ADD ANYTHING TO $out ... downloading, there are no risk of code injection //-- } //end if else //-- } //end if else //-- //-- if ((string) $y_process_mode == 'print') { $skip_part_linking = 'yes'; // skip links to other sub-parts like texts / attachments but not cids ! } elseif ((string) $y_process_mode == 'data-reply') { $skip_part_linking = 'yes'; } //end if //-- //-- if ((string) $skip_part_processing != 'yes') { //-- if ((string) $y_title != '') { $out .= (string) $y_title; // expects '' or valid HTML } //end if //-- $out .= '<!-- Smart.Framework // MIME MESSAGE HTML --><div align="left"><div id="mime_msg_box">'; //-- if (strlen($the_part_id) <= 0) { //-- $priority_img = ''; switch ((string) $head['priority']) { case '1': // high $priority_img = '<img src="lib/core/plugins/img/email/priority_high.png" align="left" alt="High Priority" title="High Priority">'; break; case '5': // low $priority_img = '<img src="lib/core/plugins/img/email/priority_low.png" align="left" alt="Low Priority" title="Low Priority">'; break; case '3': // medium // medium default: $priority_img = ''; //$priority_img = '<img src="lib/core/plugins/img/email/priority_normal.png" align="left" alt="Normal Priority" title="Normal Priority">'; } //end switch //-- if ((string) $skip_part_linking != 'yes') { // avoid display the print link when only a part is displayed $out .= '<a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $the_part_id, $y_link, $eval_arr[0], $eval_arr[1], 'print') . '" target="' . $y_target . '__mimepart" data-smart="open.modal">' . '<img align="right" src="lib/core/img/buttons/bttn_print.png">' . '</a>'; } //end if //-- switch ((string) $y_show_headers) { case 'subject': //-- if ((string) $head['subject'] != '[?]') { $out .= '<h1><font size="4">' . Smart::escape_html($head['subject']) . '</font></h1><br>'; } //end if //-- break; case 'default': default: //-- if ((string) $head['subject'] != '[?]') { $out .= '<h1><font size="4"> ' . Smart::escape_html($head['subject']) . '</font>' . $priority_img . '</h1><hr>'; } //end if //-- if ((string) $head['date'] != '(?)') { $out .= '<font size="3"><b>Date:</b> ' . Smart::escape_html(date('Y-m-d H:i:s O', @strtotime($head['date']))) . '</font><br>'; } //end if //-- $out .= '<font size="2"><b>From:</b> ' . Smart::escape_html($head['from_addr']) . ' <i>' . Smart::escape_html($head['from_name']) . '</i>' . '</font><br>'; $out .= '<font size="2"><b>To:</b> ' . Smart::escape_html($head['to_addr']) . ' <i>' . Smart::escape_html($head['to_name']) . '</i>' . '</font><br>'; //-- if (strlen($head['cc_addr']) > 0) { $out .= '<font size="2"><b>Cc:</b> '; if (SmartUnicode::str_contains($head['cc_addr'], ',')) { $arr_cc_addr = (array) explode(',', (string) $head['cc_addr']); $arr_cc_name = (array) explode(',', (string) $head['cc_name']); $out .= '[@]'; for ($z = 0; $z < Smart::array_size($arr_cc_addr); $z++) { $out .= '<br> ' . Smart::escape_html(trim($arr_cc_addr[$z])) . ' <i>' . Smart::escape_html(trim($arr_cc_name[$z])) . '</i>'; } //end for } else { $out .= Smart::escape_html($head['cc_addr']) . ' <i>' . Smart::escape_html($head['cc_name']) . '</i>'; } //end if else $out .= '</font><br>'; } //end if //-- if (strlen($head['bcc_addr']) > 0) { $out .= '<font size="2"><b>Bcc:</b> '; $out .= Smart::escape_html($head['bcc_addr']) . ' <i>' . Smart::escape_html($head['bcc_name']) . '</i>'; $out .= '</font><br>'; } //end if //-- } //end switch //-- print attachments if (is_array($msg['attachments'])) { //-- $cnt = 0; //-- $atts = ''; // atts with link $xatts = ''; // atts without link //-- $tmp_att_img = '<img src="lib/core/plugins/img/email/attachment.png">'; //-- foreach ($msg['attachments'] as $key => $val) { //-- $tmp_arr = array(); $tmp_arr = (array) $val; //-- if ((string) $tmp_arr['mode'] == 'normal') { //-- $cnt += 1; //-- $eval_arr = SmartFileSysUtils::mime_eval((string) $tmp_arr['filename']); $tmp_att_name = Smart::escape_html((string) $tmp_arr['filename']); $tmp_att_size = Smart::escape_html((string) SmartUtils::pretty_print_bytes((int) $tmp_arr['filesize'], 1)); //-- $reg_atts_num += 1; $reg_atts_list .= str_replace(array("\r", "\n", "\t"), array('', '', ''), (string) $tmp_arr['filename']) . "\n"; //-- $atts .= '<div align="left"><table border="0" cellpadding="2" cellspacing="0" title="Attachment #' . $cnt . '"><tr><td>' . $tmp_att_img . '</td><td> </td><td><a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $key, $y_link, $eval_arr[0], $eval_arr[1]) . '" target="' . $y_target . '__mimepart" data-smart="open.modal"><font size="1"><b>' . $tmp_att_name . '</b></font></a></td><td><font size="1"> <b><i>' . $tmp_att_size . '</i></b></font></td></tr></table></div>'; $xatts .= '<div align="left">' . $tmp_att_img . ' <font size="1">' . $tmp_att_name . ' <i>' . $tmp_att_size . '</i></font></div>'; //-- } //end if //-- } //end foreach //-- if ($cnt > 0) { if ((string) $skip_part_linking == 'yes') { // avoid displaying attachments links when only a part is displayed $out .= '<hr><div align="left">' . $xatts . '</div>'; } else { $out .= '<hr><div align="left">' . $atts . '</div>'; } //end if } //end if //-- $tmp_att_name = ''; $tmp_att_size = ''; //-- $atts = ''; $xatts = ''; //-- } //end if //-- } else { //-- $out .= '<div align="right"><font size="1">' . Smart::escape_html($head['subject']) . ' // ' . 'MIME Part ID : <i>' . Smart::escape_html($the_part_id) . '</i></font></div>'; //-- } //end if //-- print text bodies $markup_multipart = 'This is a multi-part message in MIME format.'; if (is_array($msg['texts'])) { //-- check similarity and prepare the HTML parts $buff = ''; $buff_id = ''; $xbuff = ''; $xbuff_id = ''; $skips = array(); $numparts = 0; foreach ($msg['texts'] as $key => $val) { //-- $numparts += 1; //-- if ((string) $val['type'] == 'text') { // assure we don't print other things //-- if ((string) $val['mode'] == 'text/plain') { // Plain TEXT //-- sanitize text $val['content'] = '<!-- MIMEREAD:PART:TEXT -->' . Smart::escape_html($val['content']); $val['content'] = str_replace(array("\r\n", "\r", "\n"), array("\n", "\n", '<br>'), $val['content']); $val['content'] = SmartParser::text_urls($val['content']); //-- $msg['texts'][$key]['content'] = $val['content']; // rewrite back //-- assign buffer $buff = SmartUnicode::sub_str($val['content'], 0, 16384); $buff_id = $key; //-- $percent_similar = 0; if (strlen($the_part_id) <= 0) { @similar_text($buff, $markup_multipart, $percent_similar); if ($percent_similar >= 25) { // 25% at least similarity $skips[$buff_id] = $percent_similar; // skip this alternate html part ... } //end if } //end if //-- // clean buffer $xbuff = ''; $xbuff_id = ''; //-- } else { // HTML Parts :: check similarity //-- $val['content'] = '<!-- MIMEREAD:PART:HTML -->' . preg_replace("'" . '<\\?xml' . ".*?" . '>' . "'si", " ", (string) $val['content']); // remove always fake "< ?" as "< ?xml" (fixed with /u modifier for unicode strings) //-- if (SmartUnicode::str_contains($val['content'], '<' . '?') or SmartUnicode::str_contains($val['content'], '?' . '>') or SmartUnicode::str_contains($val['content'], '<' . '%') or SmartUnicode::str_contains($val['content'], '%' . '>')) { //-- $val['content'] = @highlight_string($val['content'], 1); // highlight the PHP* code & sanitize the parts //-- } else { //-- sanitize this html part $val['content'] = (new SmartHtmlParser($val['content']))->get_clean_html(); //-- replace cid images $tmp_matches = array(); preg_match_all('/<img[^>]+src=[\'"]?(cid:)([^\'"]*)[\'"]?[^>]*>/si', (string) $val['content'], $tmp_matches); // fix: previous was just i (not si) ; modified on 160205 // $tmp_matches[0][i] : the full link // $tmp_matches[1][i] : 'cid:' // $tmp_matches[2][i] : cid part id for ($cids = 0; $cids < Smart::array_size($tmp_matches[0]); $cids++) { $tmp_replace_cid_link = ''; $tmp_replace_cid_link = (string) $tmp_matches[0][$cids]; $tmp_replace_cid_link = str_replace("\n", ' ', $tmp_replace_cid_link); $tmp_replace_cid_link = str_replace($tmp_matches[1][$cids] . $tmp_matches[2][$cids], self::mime_link($y_ctrl_key, $the_message_eml, 'cid_' . $tmp_matches[2][$cids], $y_link, 'image', 'inline'), $tmp_replace_cid_link); //echo '<pre>'.Smart::escape_html($tmp_replace_cid_link).'</pre>'; $val['content'] = str_replace($tmp_matches[0][$cids], $tmp_replace_cid_link, $val['content']); } //end for $tmp_matches = array(); //-- } //end if else //-- $msg['texts'][$key]['content'] = $val['content']; // rewrite back //-- $xbuff = SmartUnicode::sub_str(Smart::striptags($val['content']), 0, 16384); $xbuff_id = $key; //-- $percent_similar = 0; if (strlen($the_part_id) <= 0) { @similar_text($buff, $xbuff, $percent_similar); if ($percent_similar >= 15) { // 15% at least similarity $skips[$buff_id] = $percent_similar; // skip this alternate text part ... } //end if } //end if //-- // clean buffer $buff = ''; $buff_id = ''; //-- } //end if //-- } //end if //-- } //end foreach //-- if ($numparts <= 1) { $skips = array(); // disallow skips if only one part } //end if //-- print bodies except the skipped by similarity $out .= '<hr>'; //-- $cnt = 0; foreach ($msg['texts'] as $key => $val) { //-- if ((string) $val['type'] == 'text') { // assure we don't print other things //-- $cnt += 1; //-- $eval_arr = array(); $eval_arr = SmartFileSysUtils::mime_eval('part_' . $cnt . '.html', 'inline'); //-- $tmp_link_pre = '<span title="Mime Part #' . $cnt . ' ( ' . Smart::escape_html(strtolower($val['mode']) . ' : ' . strtoupper($val['charset'])) . ' )"><a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $key, $y_link, $eval_arr[0], $eval_arr[1], 'minimal') . '" target="' . $y_target . '__mimepart" data-smart="open.modal">'; $tmp_link_pst = '</a></span>'; //-- if (strlen($skips[$key]) <= 0) { // print part if not skipped by similarity ... //-- if ((string) $skip_part_linking == 'yes') { // avoid display sub-text part links when only a part is displayed $tmp_pict_img = ''; } else { $tmp_pict_img = '<div align="right">' . $tmp_link_pre . '<img src="lib/framework/img/mark_right.gif">' . $tmp_link_pst . '</div>'; } //end if //-- if ((string) $y_process_mode == 'data-reply') { if (strlen($reply_text['message']) <= 0) { $reply_text['message'] = (string) $val['content']; } //end if } else { $out .= $tmp_pict_img; $out .= $val['content']; $out .= '<br><hr><br>'; } //end if //-- } else { //-- if ((string) $skip_part_linking != 'yes') { // for replies, avoid display sub-text part links when only a part is displayed if ((string) $y_process_mode == 'data-reply') { // nothing } else { $out .= '<div align="right">' . '<span title="' . '~' . Smart::escape_html(Smart::format_number_dec($skips[$key], 0, '.', ',') . '%') . '"> </span>' . $tmp_link_pre . '<img src="lib/framework/img/mark_check.gif">' . $tmp_link_pst . '</div>'; } //end if else } //end if //-- } //end if else //-- } //end if //-- } //end foreach //-- } //end if //-- $out .= '</div></div><!-- END MIME MESSAGE HTML -->'; //-- } //end if else //-- //-- if ((string) $y_process_mode == 'data-full') { // output an array with message and all header info as data structure //-- return array('message' => (string) $out, 'message-id' => (string) $head['message-id'], 'in-reply-to' => (string) $head['in-reply-to'], 'from' => (string) $head['from_addr'], 'to' => (string) $head['to_addr'], 'cc' => (string) $head['cc_addr'], 'date' => (string) $head['date'], 'atts_num' => (int) $reg_atts_num, 'atts_lst' => (string) $reg_atts_list, 'filepath' => (string) $the_message_eml, 'is_part' => (string) $reg_is_part); //-- } elseif ((string) $y_process_mode == 'data-reply') { // output a special array for replies only //-- $reply_text['message'] = (string) $reply_text['message']; // this comes from above $reply_text['from'] = (string) $head['from_addr']; $reply_text['to'] = (string) $head['to_addr']; $reply_text['cc'] = (string) $head['cc_addr']; $reply_text['date'] = (string) $head['date']; $reply_text['subject'] = (string) $head['subject']; $reply_text['message-id'] = (string) $head['message-id']; $reply_text['in-reply-to'] = (string) $head['in-reply-to']; //-- return (array) $reply_text; //-- } else { // 'default' or 'print' :: message as html view //-- return (string) $out; //-- } //end if //-- }