private static function display_calendar($y_mode, $y_sel_date, $y_width, $y_highlight_selected, $y_events_arr)
 {
     //--
     global $configs;
     //--
     if ($configs['regional']['calendar-week-start'] == 1) {
         $the_first_day = 1;
         // Calendar Start on Monday
     } else {
         $the_first_day = 0;
         // Calendar Start on Sunday
     }
     //end if else
     //--
     if ((string) $y_sel_date == '') {
         $y_sel_date = date('Y-m-d');
     }
     //end if
     //--
     $translator_core_calendar = SmartTextTranslations::getTranslator('@core', 'calendar');
     //--
     $calendar = new SmartHTMLCalendar(date('Y-m-d', @strtotime($y_sel_date)), $y_highlight_selected, $y_width, (string) $y_mode);
     //-- set months
     $calendar->setMonthNames(array('01' => $translator_core_calendar->text('m_01'), '02' => $translator_core_calendar->text('m_02'), '03' => $translator_core_calendar->text('m_03'), '04' => $translator_core_calendar->text('m_04'), '05' => $translator_core_calendar->text('m_05'), '06' => $translator_core_calendar->text('m_06'), '07' => $translator_core_calendar->text('m_07'), '08' => $translator_core_calendar->text('m_08'), '09' => $translator_core_calendar->text('m_09'), '10' => $translator_core_calendar->text('m_10'), '11' => $translator_core_calendar->text('m_11'), '12' => $translator_core_calendar->text('m_12')));
     //-- set days
     if ((string) $y_mode == 'small') {
         $calendar->setDayNames(array(0 => SmartUnicode::sub_str($translator_core_calendar->text('w_1'), 0, 2), 1 => SmartUnicode::sub_str($translator_core_calendar->text('w_2'), 0, 2), 2 => SmartUnicode::sub_str($translator_core_calendar->text('w_3'), 0, 2), 3 => SmartUnicode::sub_str($translator_core_calendar->text('w_4'), 0, 2), 4 => SmartUnicode::sub_str($translator_core_calendar->text('w_5'), 0, 2), 5 => SmartUnicode::sub_str($translator_core_calendar->text('w_6'), 0, 2), 6 => SmartUnicode::sub_str($translator_core_calendar->text('w_7'), 0, 2)));
     } else {
         $calendar->setDayNames(array(0 => $translator_core_calendar->text('w_1'), 1 => $translator_core_calendar->text('w_2'), 2 => $translator_core_calendar->text('w_3'), 3 => $translator_core_calendar->text('w_4'), 4 => $translator_core_calendar->text('w_5'), 5 => $translator_core_calendar->text('w_6'), 6 => $translator_core_calendar->text('w_7')));
     }
     //end if else
     //-- set start on
     $calendar->setStartOfWeek($the_first_day);
     //--
     if (Smart::array_size($y_events_arr) > 0) {
         for ($i = 0; $i < count($y_events_arr); $i++) {
             if ($y_events_arr[$i]['date-end'] === false) {
                 $calendar->addDayEvent((string) $y_events_arr[$i]['event-html'], date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-start'])), false);
             } else {
                 $calendar->addDayEvent((string) $y_events_arr[$i]['event-html'], date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-start'])), date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-end'])));
             }
             //end if else
         }
         //end for
     }
     //end if
     //-- draw
     return '<div title="' . Smart::escape_html(date('Y-m', @strtotime((string) $y_sel_date))) . '">' . $calendar->draw() . '</div>';
     //--
 }
 /**
  * Provides a fixed length string text ; if longer than allowed length will add trailing dots (...)
  *
  * @param 	STRING 	$ystr 				:: The text string to be processed
  * @param 	STRING 	$ylen 				:: The fixed length of the string
  * @param 	BOOLEAN	$y_cut_words		:: if TRUE, will CUT last word to provide a fixed length ; if FALSE will eliminate unterminate last word ; default is TRUE
  *
  * @return 	STRING						:: The processed string (text)
  */
 public static function text_endpoints($ystr, $ylen, $y_cut_words = true, $y_dots = '...')
 {
     //--
     $ystr = (string) trim((string) $ystr);
     $ylen = Smart::format_number_int($ylen, '+');
     //--
     if ($ylen > 0 and SmartUnicode::str_len($ystr) > $ylen) {
         $ystr = (string) SmartUnicode::sub_str($ystr, 0, $ylen - 3);
         if (!$y_cut_words) {
             $ystr = (string) preg_replace('/\\s+?(\\S+)?$/', '', (string) $ystr);
         }
         //end if
         $ystr .= (string) $y_dots;
     }
     //end if
     //--
     return (string) $ystr;
     //--
 }
 private static function log_template($mtemplate)
 {
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         return (string) $mtemplate;
     } else {
         return (string) SmartUnicode::sub_str($mtemplate, 0, 255) . "\n" . '***** turn on Debugging to see more ... *****';
     }
     //end if else
     //--
 }
 public static function escape_str($db, $y_string)
 {
     //--
     self::check_connection($db);
     //--
     $y_string = (string) SmartUnicode::fix_charset((string) $y_string);
     // Fix
     //--
     $y_string = (string) @$db->escapeString((string) $y_string);
     //--
     return (string) $y_string;
     //--
 }
 private function parseAttributeData($attributeString)
 {
     //--
     $Data = array();
     //--
     $attributes = preg_split('/[ ]+/', $attributeString, -1, PREG_SPLIT_NO_EMPTY);
     //--
     $classes = array();
     foreach ($attributes as $z => $attribute) {
         //--
         if ($attribute[0] === '@') {
             // @
             $tmp_arr = explode('=', $attribute);
             $Data[trim(SmartUnicode::sub_str(trim($tmp_arr[0]), 1))] = trim(str_replace(array(',', '$'), array('.', ' '), trim($tmp_arr[1])));
         } elseif ($attribute[0] === '#') {
             // #
             $Data['id'] = SmartUnicode::sub_str($attribute, 1);
         } else {
             // .
             $classes[] = SmartUnicode::sub_str($attribute, 1);
         }
         //end if else
         //--
     }
     //end foreach
     //--
     if (count($classes) > 0) {
         $Data['class'] = implode(' ', $classes);
     }
     //end if
     //--
     return $Data;
     //--
 }
 /**
  * Escape a string to be compliant and Safe (against SQL Injection) with MySQL standards.
  * This function WILL NOT ADD the SINGLE QUOTES (') arround the string, but just will just escape it to be safe.
  *
  * @param STRING $y_string						:: A String or a Number to be Escaped
  * @param RESOURCE $y_connection 				:: the connection
  * @return STRING 								:: The Escaped String / Number
  *
  */
 public static function escape_str($y_string, $y_connection = 'DEFAULT')
 {
     //==
     $y_connection = self::check_connection($y_connection, 'ESCAPE-STR');
     //==
     //-- Fix
     $y_string = (string) SmartUnicode::fix_charset((string) $y_string);
     //--
     //--
     $y_string = (string) @mysqli_real_escape_string($y_connection, (string) $y_string);
     //--
     //--
     return $y_string;
     //--
 }
 private static function utf8_charAt($str, $num)
 {
     //--
     return SmartUnicode::sub_str($str, $num, 1);
     //--
 }
 public static function Run()
 {
     //--
     global $configs;
     //--
     //==
     //--
     if (self::$MiddlewareCompleted !== false) {
         // avoid to execute more than 1 this middleware !
         self::Raise500Error('Middleware App Execution already completed ...');
         return;
     }
     //end if
     self::$MiddlewareCompleted = true;
     //--
     $the_midmark = '[A]';
     //--
     if (SMART_FRAMEWORK_ADMIN_AREA !== true) {
         Smart::raise_error('Admin Middleware ERROR: SMART_FRAMEWORK_ADMIN_AREA is not set to TRUE', 'Invalid Area / This middleware is designed for Admin area and requires to turn ON the Administration flag ...');
         return;
     }
     //end if
     //--
     if (!defined('SMART_APP_TEMPLATES_DIR')) {
         self::Raise500Error('The SMART_APP_TEMPLATES_DIR not defined ...');
         return;
     }
     //end if
     //--
     if (defined('SMART_APP_MODULE_AREA')) {
         self::Raise500Error('Smart App Area must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_AUTH')) {
         self::Raise500Error('Smart App Module Auth must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_REALM_AUTH')) {
         self::Raise500Error('Smart App Module Realm Auth must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_DIRECT_OUTPUT')) {
         self::Raise500Error('Smart App Module Direct Output must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     //--
     //==
     //--
     $smartframeworkservice = '';
     // special operation
     if (SmartFrameworkRegistry::issetRequestVar('smartframeworkservice') === true) {
         $smartframeworkservice = (string) strtolower((string) SmartUnicode::utf8_to_iso((string) SmartFrameworkRegistry::getRequestVar('smartframeworkservice')));
         switch ((string) $smartframeworkservice) {
             case 'status':
             case 'debug':
                 break;
             default:
                 // invalid value
                 $smartframeworkservice = '';
         }
         //end switch
     }
     //end if
     //--
     //==
     //-- switch language by cookie (this needs to be before loading the app core)
     if (strlen(trim((string) $_COOKIE['SmartApp_ADM_LANGUAGE_SET'])) > 0) {
         SmartTextTranslations::setLanguage(trim((string) $_COOKIE['SmartApp_ADM_LANGUAGE_SET']));
     }
     //end if
     //-- switch language by print cookie (this needs to be before loading the app core and after language by cookie)
     if (SmartFrameworkRegistry::issetRequestVar((string) SMART_FRAMEWORK_URL_PARAM_PRINTABLE) === true) {
         if (strtolower((string) SmartFrameworkRegistry::getRequestVar((string) SMART_FRAMEWORK_URL_PARAM_PRINTABLE)) == strtolower((string) SMART_FRAMEWORK_URL_VALUE_ENABLED)) {
             if (strlen(trim((string) $_COOKIE['SmartApp_ADM_PRINT_LANGUAGE_SET'])) > 0) {
                 SmartTextTranslations::setLanguage(trim((string) $_COOKIE['SmartApp_ADM_PRINT_LANGUAGE_SET']));
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     //== RAW OUTPUT FOR STATUS
     //--
     if ((string) $smartframeworkservice == 'status') {
         //--
         if (SMART_SOFTWARE_DISABLE_STATUS_POWERED === true) {
             $status_powered_info = '';
         } else {
             $status_powered_info = (string) SmartComponents::draw_powered_info('no');
         }
         //end if else
         //--
         self::HeadersNoCache();
         // headers: cache control, force no-cache
         echo SmartComponents::http_status_message('Smart.Framework :: Status :: [OK]', '<script type="text/javascript">setTimeout(function(){ self.location = self.location; }, 60000);</script><img src="lib/core/img/busy_bar.gif"><div><h1>' . date('Y-m-d H:i:s O') . ' // Service Ready :: ' . $the_midmark . '</h1></div>' . $status_powered_info . '<br>');
         //--
         return;
         // break stop
         //--
     }
     //end if
     //--
     //== OVERALL AUTHENTICATION BREAKPOINT
     //--
     SmartAppBootstrap::Authenticate('admin');
     // if the auth uses session it may start now
     //--
     //== RAW OUTPUT FOR DEBUG
     //--
     if ((string) $smartframeworkservice == 'debug') {
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             self::HeadersNoCache();
             // headers: cache control, force no-cache
             $the_debug_cookie = trim((string) $_COOKIE['SmartFramework__DebugAdmID']);
             echo SmartDebugProfiler::print_debug_info('adm', $the_debug_cookie);
         } else {
             http_response_code(404);
             echo SmartComponents::http_message_404_notfound('No Debug service has been activated on this server ...');
         }
         //end if
         //--
         return;
         // break stop
         //--
     }
     //end if else
     //--
     //== LOAD THE MODULE (OR DEFAULT MODULE)
     //--
     $reserved_controller_names = ['php', 'html', 'stml', 'css', 'js', 'json', 'xml', 'rss', 'txt', 'csv', 'sql', 'png', 'gif', 'jpg', 'pdf', 'svg', 'zip', '7z', 'netarch'];
     // these are reserved extensions and cannot be used as controller names because they need to be used also with friendly URLs as the 2nd param if module is missing from URL page param
     //--
     $err404 = '';
     $arr = array();
     //--
     $page = (string) SmartUnicode::utf8_to_iso((string) SmartFrameworkRegistry::getRequestVar('page'));
     $page = trim(str_replace(array('/', '\\', ':', '?', '&', '=', '%'), array('', '', '', '', '', '', ''), $page));
     // fix for get as it automatically replaces . with _ (so, reverse), but also fix some invalid characters ...
     if ((string) $page == '') {
         $page = (string) $configs['app']['admin-home'];
     }
     //end if
     //--
     if (strpos($page, '.') !== false) {
         // page can be as module.controller / module.controller(.php|html|stml|css|js|json|xml|rss|txt|csv|sql|png|gif|jpg|pdf|svg|zip|7z|netarch)
         //--
         $arr = (array) explode('.', (string) $page, 3);
         // separe 1st and 2nd from the rest
         //--
         //#
         //#
         $arr[0] = trim(strtolower((string) $arr[0]));
         // module
         $arr[1] = trim(strtolower((string) $arr[1]));
         // controller
         //#
         //# Admin will NOT integrate with friendly URLs SMART_FRAMEWORK_SEMANTIC_URL_SKIP_MODULE
         //# that feature is just for Index
         //#
         //--
     } elseif ((string) $configs['app']['admin-default-module'] != '') {
         //--
         $arr[0] = trim(strtolower((string) $configs['app']['admin-default-module']));
         // get default module
         $arr[1] = trim(strtolower((string) $page));
         // controller
         //--
     } else {
         //--
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Invalid URL Page Segments Syntax): ' . $page;
         }
         //end if
         //--
     }
     //end if else
     //--
     if ((string) $arr[0] == '' or (string) $arr[1] == '') {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Empty or Missing URL Page Segments): ' . $page;
         }
         //end if
     }
     //end if
     if (!preg_match('/^[a-z0-9_\\-]+$/', (string) $arr[0]) or !preg_match('/^[a-z0-9_\\-]+$/', (string) $arr[1])) {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Invalid Characters in the URL Page Segments): ' . $page;
         }
         //end if
     }
     //end if
     if (in_array((string) $arr[1], (array) $reserved_controller_names)) {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Reserved Page Controller Name): [' . $arr[1] . '] in: ' . $page;
         }
         //end if
     }
     //end if
     //--
     $the_controller_name = (string) $arr[0] . '.' . $arr[1];
     $the_path_to_module = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash('modules/mod-' . Smart::safe_filename($arr[0])));
     $the_module = Smart::safe_pathname($the_path_to_module . Smart::safe_filename($arr[1]) . '.php');
     if (!is_file($the_module)) {
         if ((string) $err404 == '') {
             $err404 = 'Page does not exist: ' . $page;
         }
         //end if
     }
     //end if
     //--
     if ((string) $err404 != '') {
         self::Raise404Error((string) $err404);
         return;
     }
     //end if
     //--
     if (!SmartFileSysUtils::check_file_or_dir_name($the_path_to_module) or !SmartFileSysUtils::check_file_or_dir_name($the_module)) {
         self::Raise400Error('Insecure Module Access for Page: ' . $page);
         return;
     }
     //end if
     //--
     if (class_exists('SmartAppIndexController') or class_exists('SmartAppAdminController')) {
         self::Raise500Error('Module Class Runtimes must be defined only in modules ...');
         return;
     }
     //end if
     //--
     require (string) $the_module;
     //--
     if ((string) SMART_APP_MODULE_AREA !== 'ADMIN' and (string) SMART_APP_MODULE_AREA !== 'SHARED') {
         self::Raise403Error('Page Access Denied for Admin Area: ' . $page);
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_AUTH')) {
         if (SmartAuth::check_login() !== true) {
             self::Raise403Error('Page Access Denied ! No Authentication: ' . $page);
             return;
         }
         //end if
         if (defined('SMART_APP_MODULE_REALM_AUTH')) {
             if ((string) SmartAuth::get_login_realm() !== (string) SMART_APP_MODULE_REALM_AUTH) {
                 self::Raise403Error('Page Access Denied ! Invalid Login Realm: ' . $page);
                 return;
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     if (!class_exists('SmartAppAdminController')) {
         self::Raise500Error('Invalid Module Class Runtime for Page: ' . $page);
         return;
     }
     //end if
     if (!is_subclass_of('SmartAppAdminController', 'SmartAbstractAppController')) {
         self::Raise500Error('Invalid Module Class Inheritance for Controller Page: ' . $page);
         return;
     }
     //end if
     //--
     //== PATHS
     //--
     $base_script = SmartUtils::get_server_current_script();
     $base_full_path = SmartUtils::get_server_current_path();
     $base_full_url = SmartUtils::get_server_current_url();
     //--
     //== RUN THE MODULE
     //--
     $appModule = new SmartAppAdminController($the_path_to_module, $base_script, $base_full_path, $base_full_url, $page, $the_controller_name);
     //--
     if (SMART_APP_MODULE_DIRECT_OUTPUT !== true) {
         ob_start();
     }
     //end if
     $appStatusCode = (int) $appModule->Run();
     $appModule->ShutDown();
     if (SMART_APP_MODULE_DIRECT_OUTPUT !== true) {
         $ctrl_output = ob_get_contents();
         ob_end_clean();
         if ((string) $ctrl_output != '') {
             Smart::log_warning('The middleware service ' . $the_midmark . ' detected an illegal output in the controller: ' . $page . "\n" . 'The result of this output is: ' . $ctrl_output);
         }
         //end if
         $ctrl_output = '';
     } else {
         return;
         // break stop after the controller has terminated the direct output
     }
     //end if else
     //--
     $appSettings = (array) $appModule->PageViewGetCfgs();
     //--
     //== CACHE CONTROL
     //--
     if ((int) $appSettings['expires'] > 0 and (string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') {
         self::HeadersCacheExpire((int) $appSettings['expires'], (int) $appSettings['modified']);
         // headers: cache expiration control
     } else {
         self::HeadersNoCache();
         // headers: cache control, force no-cache
     }
     //end if else
     //--
     //== STATUS CODE
     //--
     switch ((int) $appStatusCode) {
         //-- client errors
         case 400:
             self::Raise400Error((string) $appSettings['error']);
             return;
             break;
         case 401:
             self::Raise401Error((string) $appSettings['error']);
             return;
             break;
         case 403:
             self::Raise403Error((string) $appSettings['error']);
             return;
             break;
         case 404:
             self::Raise404Error((string) $appSettings['error']);
             return;
             break;
         case 429:
             self::Raise429Error((string) $appSettings['error']);
             return;
             break;
             //-- server errors
         //-- server errors
         case 500:
             self::Raise500Error((string) $appSettings['error']);
             return;
             break;
         case 502:
             self::Raise502Error((string) $appSettings['error']);
             return;
             break;
         case 503:
             self::Raise503Error((string) $appSettings['error']);
             return;
             break;
         case 504:
             self::Raise504Error((string) $appSettings['error']);
             return;
             break;
             //-- extended 2xx statuses: NOTICE / WARNING / ERROR that can be used for REST / API
         //-- extended 2xx statuses: NOTICE / WARNING / ERROR that can be used for REST / API
         case 202:
             // NOTICE
             if (!headers_sent()) {
                 http_response_code(202);
                 // Accepted (this should be used only as an alternate SUCCESS code instead of 200 for NOTICES)
             } else {
                 Smart::log_warning('Headers Already Sent before 202 ...');
             }
             //end if else
             break;
         case 203:
             // WARNING
             if (!headers_sent()) {
                 http_response_code(203);
                 // Non-Authoritative Information (this should be used only as an alternate SUCCESS code instead of 200 for WARNINGS)
             } else {
                 Smart::log_warning('Headers Already Sent before 203 ...');
             }
             //end if else
             break;
         case 208:
             // ERROR
             if (!headers_sent()) {
                 http_response_code(208);
                 // Already Reported (this should be used only as an alternate SUCCESS code instead of 200 for ERRORS)
             } else {
                 Smart::log_warning('Headers Already Sent before 208 ...');
             }
             //end if else
             break;
             //-- DEFAULT: OK
         //-- DEFAULT: OK
         case 200:
         default:
             // any other codes not listed above are not supported and will be interpreted as 200
             // nothing to do here ...
     }
     //end switch
     //--
     //== PREPARE THE OUTPUT
     //--
     if (stripos((string) $configs['js']['popup-override-mobiles'], '<' . SmartUtils::get_os_browser_ip('os') . '>') !== false) {
         $configs['js']['popup-mode'] = 'popup';
         // particular os settings for mobiles
     }
     //end if
     //--
     $rawpage = '';
     if (isset($appSettings['rawpage'])) {
         $rawpage = strtolower((string) $appSettings['rawpage']);
         if ((string) $rawpage == 'yes') {
             $rawpage = 'yes';
             // standardize the value
         }
         //end if
     }
     //end if
     if ((string) $rawpage != 'yes') {
         $rawpage = '';
     }
     //end if
     //--
     $rawmime = '';
     if (isset($appSettings['rawmime'])) {
         $rawmime = (string) $appSettings['rawmime'];
         if ((string) $rawmime != '') {
             $rawmime = SmartValidator::validate_mime_type($rawmime);
         }
         //end if
     }
     //end if else
     //--
     $rawdisp = '';
     if (isset($appSettings['rawdisp'])) {
         $rawdisp = (string) $appSettings['rawdisp'];
         if ((string) $rawdisp != '') {
             $rawdisp = SmartValidator::validate_mime_disposition($rawdisp);
         }
         //end if
     }
     //end if else
     //--
     $appData = (array) $appModule->PageViewGetVars();
     //--
     $appData['base-path'] = (string) $base_full_path;
     $appData['base-url'] = (string) $base_full_url;
     //--
     //== REDIRECTION HANDLER (this can be set only explicit from Controllers)
     //--
     if ((string) $appSettings['redirect-url'] != '') {
         // expects a valid URL
         //--
         $the_redirect_link = '<a href="' . Smart::escape_html((string) $appSettings['redirect-url']) . '">' . Smart::escape_html((string) $appSettings['redirect-url']) . '</a>';
         //--
         if (headers_sent()) {
             Smart::log_warning('Headers Already Sent before Redirection: [' . $appStatusCode . '] ; URL: ' . $appSettings['redirect-url']);
             self::Raise500Error('The app failed to Redirect to: ' . $the_redirect_link);
             return;
         }
         //end if
         switch ((int) $appStatusCode) {
             case 301:
                 http_response_code(301);
                 $the_redirect_text = 'Moved Permanently';
                 // permanent redirect for HTTP 1.0 / HTTP 1.1
                 break;
             case 302:
             default:
                 // any other code will be interpreted as 302 (the default redirection in PHP)
                 http_response_code(302);
                 $the_redirect_text = 'Found';
                 // temporary redirect for HTTP 1.0 / HTTP 1.1
                 break;
         }
         //end switch
         header('Location: ' . SmartFrameworkSecurity::FilterUnsafeString((string) $appSettings['redirect-url']));
         echo '<h1>' . Smart::escape_html($the_redirect_text) . '</h1>' . '<br>' . 'If the page redirection fails, click on the below link:' . '<br>' . $the_redirect_link;
         return;
         // break stop
     }
     //end if
     //--
     //== DOWNLOADS HANDLER (downloads can be set only explicit from Controllers)
     //--
     if ((string) $appSettings['download-packet'] != '' and (string) $appSettings['download-key'] != '') {
         // expects an encrypted data packet and a key
         $dwl_result = self::DownloadsHandler((string) $appSettings['download-packet'], (string) $appSettings['download-key']);
         if ((string) $dwl_result != '') {
             Smart::log_info('File Download - Client: ' . SmartUtils::get_visitor_signature(), (string) $dwl_result);
             // log result and mark it as finalized
         }
         //end if
         return;
         // break stop
     }
     //end if
     //--
     //== RAW OUTPUT FOR PAGES
     //--
     if ((string) $rawpage == 'yes') {
         //-- {{{SYNC-RESOURCES}}}
         if (function_exists('memory_get_peak_usage')) {
             $res_memory = @memory_get_peak_usage(false);
         } else {
             $res_memory = 'unknown';
         }
         //end if else
         $res_time = (double) (microtime(true) - (double) SMART_FRAMEWORK_RUNTIME_READY);
         //-- #END-SYNC
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             //-- {{{SYNC-DEBUG-META-INFO}}}
             SmartFrameworkRegistry::setDebugMsg('stats', 'memory', $res_memory);
             // bytes
             SmartFrameworkRegistry::setDebugMsg('stats', 'time', $res_time);
             // seconds
             //-- #END-SYNC
             $the_debug_cookie = trim((string) $_COOKIE['SmartFramework__DebugAdmID']);
             SmartDebugProfiler::save_debug_info('adm', $the_debug_cookie, false);
         } else {
             $the_debug_cookie = '';
         }
         //end if
         //--
         if (headers_sent()) {
             Smart::raise_error('Middleware ERROR: Headers already sent', 'ERROR: Headers already sent !');
             return;
             // avoid serve raw pages with errors injections before headers
         }
         //end if
         //--
         if ((string) $rawmime != '') {
             header('Content-Type: ' . $rawmime);
         }
         //end if
         if ((string) $rawdisp != '') {
             header('Content-Disposition: ' . $rawdisp);
         }
         //end if
         header('Content-Length: ' . (0 + strlen((string) $appData['main'])));
         // must be strlen NOT SmartUnicode::str_len as it must get number of bytes not characters
         echo (string) $appData['main'];
         return;
         // break stop
         //--
     }
     //end if else
     //--
     //== DEFAULT OUTPUT
     //--
     if (isset($appSettings['template-path'])) {
         if ((string) $appSettings['template-path'] == '@') {
             // if template path is set to self (module)
             $the_template_path = '@';
             // this is a special setting
         } else {
             $the_template_path = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash(trim((string) $appSettings['template-path'])));
         }
         //end if else
     } else {
         $the_template_path = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash(trim((string) $configs['app']['admin-template-path'])));
         // use default template path
     }
     //end if else
     //--
     if (isset($appSettings['template-file'])) {
         $the_template_file = Smart::safe_filename(trim((string) $appSettings['template-file']));
     } else {
         $the_template_file = Smart::safe_filename(trim((string) $configs['app']['admin-template-file']));
         // use default template
     }
     //end if else
     //--
     if ((string) $the_template_path == '@') {
         $the_template_path = (string) $the_path_to_module . 'templates/';
         // must have the dir last slash as above
     } else {
         $the_template_path = (string) SMART_APP_TEMPLATES_DIR . $the_template_path;
         // finally normalize and set the complete template path
     }
     //end if else
     $the_template_file = (string) $the_template_file;
     // finally normalize
     //--
     if (!SmartFileSysUtils::check_file_or_dir_name($the_template_path)) {
         Smart::log_warning('Invalid Page Template Path: ' . $the_template_path);
         self::Raise500Error('Invalid Page Template Path. See the error log !');
         return;
     }
     //end if
     if (!is_dir($the_template_path)) {
         Smart::log_warning('Page Template Path does not Exists: ' . $the_template_path);
         self::Raise500Error('Page Template Path does not Exists. See the error log !');
         return;
     }
     //end if
     if (!SmartFileSysUtils::check_file_or_dir_name($the_template_path . $the_template_file)) {
         Smart::log_warning('Invalid Page Template File: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Invalid Page Template File. See the error log !');
         return;
     }
     //end if
     if (!is_file($the_template_path . $the_template_file)) {
         Smart::log_warning('Page Template File does not Exists: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Page Template File does not Exists. See the error log !');
         return;
     }
     //end if
     //--
     $the_template_content = trim(SmartMarkersTemplating::read_template_file($the_template_path . $the_template_file));
     if ((string) $the_template_content == '') {
         Smart::log_warning('Page Template File is Empty or cannot be read: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Page Template File is Empty or cannot be read. See the error log !');
         return;
     }
     //end if
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $the_template_content = str_ireplace('</head>', "\n" . SmartDebugProfiler::js_headers_debug('admin.php?smartframeworkservice=debug') . "\n" . '</head>', $the_template_content);
         $the_template_content = str_ireplace('</body>', "\n" . SmartDebugProfiler::div_main_debug() . "\n" . '</body>', $the_template_content);
     }
     //end if
     //--
     $appData['app-domain'] = (string) $configs['app']['admin-domain'];
     $appData['template-file'] = $the_template_path . $the_template_file;
     $appData['template-path'] = $the_template_path;
     $appData['js.settings'] = SmartComponents::js_inc_settings((string) $configs['js']['popup-mode'], true, (bool) SMART_APP_VISITOR_COOKIE);
     $appData['head-meta'] = (string) $appData['head-meta'];
     if ((string) $appData['head-meta'] == '') {
         $appData['head-meta'] = '<!-- Head Meta -->';
     }
     //end if
     $appData['title'] = (string) $appData['title'];
     $appData['main'] = (string) $appData['main'];
     $appData['lang'] = SmartTextTranslations::getLanguage();
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $the_debug_cookie = 'adm-' . Smart::uuid_10_seq() . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str();
         @setcookie('SmartFramework__DebugAdmID', (string) $the_debug_cookie, 0, '/');
         // debug token cookie is set just on main request
         //--
     }
     //end if
     //--
     echo SmartMarkersTemplating::render_mixed_template((string) $the_template_content, (array) $appData, (string) $appData['template-path'], 'no', 'no');
     //-- {{{SYNC-RESOURCES}}}
     if (function_exists('memory_get_peak_usage')) {
         $res_memory = @memory_get_peak_usage(false);
     } else {
         $res_memory = 'unknown';
     }
     //end if else
     $res_time = (double) (microtime(true) - (double) SMART_FRAMEWORK_RUNTIME_READY);
     //-- #END-SYNC
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //-- {{{SYNC-DEBUG-META-INFO}}}
         SmartFrameworkRegistry::setDebugMsg('stats', 'memory', $res_memory);
         // bytes
         SmartFrameworkRegistry::setDebugMsg('stats', 'time', $res_time);
         // seconds
         //-- #END-SYNC
         SmartDebugProfiler::save_debug_info('adm', $the_debug_cookie, true);
         //--
     }
     //end if else
     //--
     if (SMART_SOFTWARE_DISABLE_STATUS_POWERED !== true) {
         echo "\n" . '<!-- Smart.Framework スマート.フレームワーク :: ' . SMART_FRAMEWORK_RELEASE_TAGVERSION . ' / ' . SMART_FRAMEWORK_RELEASE_VERSION . ' @ ' . $the_midmark . ' :: ' . SMART_FRAMEWORK_RELEASE_URL . ' -->';
     }
     //end if
     echo "\n" . '<!-- Resources: [' . Smart::format_number_dec($res_time, 13, '.', '') . ' sec.] / [' . Smart::format_number_dec($res_memory, 0, '.', ' ') . ' by.]' . ' -->' . "\n";
     //--
 }
 /**
  * Regional Text :: Set Language
  *
  * @param 	STRING 	$y_language 		:: The language ID ; sample (for English) will be: 'en'
  *
  * @return 	BOOLEAN						:: TRUE if successful, FALSE if not
  */
 public static function setLanguage($y_language)
 {
     //--
     global $configs;
     global $languages;
     //--
     $result = false;
     //--
     $tmp_lang = (string) strtolower((string) SmartUnicode::utf8_to_iso((string) $y_language));
     //--
     if (is_array($configs)) {
         if (strlen((string) $tmp_lang) == 2) {
             // if language id have only 2 characters
             if (preg_match('/^[a-z]+$/', (string) $tmp_lang)) {
                 // language id must contain only a..z characters (iso-8859-1)
                 if (is_array($languages)) {
                     if ((string) $languages[(string) $tmp_lang] != '') {
                         // if that lang is set in languages array
                         if ((string) $tmp_lang != (string) $configs['regional']['language-id']) {
                             // if it is the same, don't make sense to set it again !
                             $configs['regional']['language-id'] = (string) $tmp_lang;
                             self::$cache['#LANGUAGE#'] = (string) $tmp_lang;
                             $result = true;
                             if (defined('SMART_FRAMEWORK_INTERNAL_DEBUG')) {
                                 if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                                     SmartFrameworkRegistry::setDebugMsg('extra', '***REGIONAL-TEXTS***', ['title' => 'Set Language in Configs and Internal Cache', 'data' => 'Content: ' . $the_lang]);
                                 }
                                 //end if
                             }
                             //end if
                         }
                         //end if
                     }
                     //end if
                 }
                 //end if
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     return (bool) $result;
     //--
 }
 private function _answer()
 {
     //--
     $this->_resp = '';
     //--
     for ($i = 0; $i < 3; $i++) {
         //--
         $res = @fgets($this->_sock, 512);
         $this->_resp .= $res;
         //--
         $rstop = SmartUnicode::sub_str($res, 3, 1);
         $rstop_plus = SmartUnicode::sub_str($res, 0, 3);
         //--
         if (is_numeric($rstop_plus)) {
             if ((string) $rstop == ' ') {
                 $i = 3;
                 // stop
             } else {
                 $i = 1;
                 // continue
             }
             //end else
         } else {
             $i = 1;
             // continue
         }
         //end if else
         //--
     }
     //end for
     //--
     $this->_debug_print(str_replace("\r\n", "\n", $this->_resp));
     //--
     return $this->_resp;
     //--
 }
 /**
  * Generate a MULTIPLE (many selections) View/Edit List to manage ID Selections
  *
  * @param STRING			$y_id					the HTML element ID
  * @param STRING 			$y_selected_value		selected value(s) data as ARRAY or STRING list as: '<id1>,<id2>'
  * @param ENUM				$y_mode					'form' = display form | checkboxes | 'list' = display list
  * @param ARRAY				$yarr_data				DATASET ROWS AS: ['id' => 'name', 'id2' => 'name2'] OR ['id', 'name', 'id2', 'name2']
  * @param STRING 			$y_varname				as 'frm[test][]'
  * @param ENUM				$y_draw 				list | checkboxes
  * @param YES/NO 			$y_sync_values			If Yes, sync select similar values used (curently works only for checkboxes)
  * @param INTEGER			$y_dimensions			dimensions in pixels (width or width / (list) height for '#JS-UI#' or '#JS-UI-FILTER#')
  * @param CODE				$y_custom_js			custom js code (Ex: submit on change)
  * @param SPECIAL			$y_extrastyle			Extra Style CSS | '#JS-UI#' or '#JS-UI-FILTER#'
  *
  * @return HTMLCode
  */
 public static function html_multi_select_list($y_id, $y_selected_value, $y_mode, $yarr_data, $y_varname = '', $y_draw = 'list', $y_sync_values = 'no', $y_dimensions = '300/0', $y_custom_js = '', $y_extrastyle = '#JS-UI-FILTER#')
 {
     //-- fix associative array
     $arr_type = Smart::array_type_test($yarr_data);
     if ($arr_type === 2) {
         // associative array detected
         $arr_save = (array) $yarr_data;
         $yarr_data = array();
         foreach ((array) $arr_save as $key => $val) {
             $yarr_data[] = (string) $key;
             $yarr_data[] = (string) $val;
         }
         //end foreach
         $arr_save = array();
     }
     //end if
     //--
     //-- bug fix
     if (Smart::array_size($yarr_data) > 2) {
         $use_multi_list_jq = true;
         $use_multi_list_htm = 'multiple size="8"';
     } else {
         $use_multi_list_jq = false;
         $use_multi_list_htm = 'size="1"';
     }
     //end if else
     //--
     //--
     $tmp_dimens = explode('/', trim((string) $y_dimensions));
     $the_width = (int) $tmp_dimens[0];
     $the_height = (int) $tmp_dimens[1];
     //--
     if ($the_width <= 0) {
         $the_width = 150;
     }
     //end if
     if ($the_height < 0) {
         $the_height = 0;
     }
     //end if
     //--
     //--
     $element_id = Smart::escape_html($y_id);
     //--
     //--
     $css_class = '';
     //--
     if ((string) $element_id != '' && ((string) $y_extrastyle == '#JS-UI#' || (string) $y_extrastyle == '#JS-UI-FILTER#')) {
         //--
         $use_blank_value = 'no';
         //--
         $tmp_extra_style = (string) $y_extrastyle;
         $y_extrastyle = '';
         // reset
         //--
         if ((string) $y_mode == 'form') {
             //--
             if ($the_height > 0) {
                 if ($the_height < 50) {
                     $the_height = 50;
                 }
                 //end if
                 if ($the_height > 200) {
                     $the_height = 200;
                 }
                 //end if
             } else {
                 $the_height = (int) ((Smart::array_size($yarr_data) + 1) * 20);
                 if ($the_height > 200) {
                     $the_height = 200;
                 }
                 //end if
             }
             //end if else
             //--
             if ((string) $tmp_extra_style == '#JS-UI-FILTER#') {
                 $have_filter = true;
                 $the_width += 25;
             } else {
                 $have_filter = false;
             }
             //end if else
             //--
             if ($use_multi_list_jq === false) {
                 $use_blank_value = 'yes';
                 $have_filter = false;
                 // if multi will be enforced to single because of just 2 rows or less, disable filter !
             }
             //end if
             //--
             $js = (string) SmartMarkersTemplating::render_file_template('lib/core/templates/ui-list-multi.inc.htm', ['LANG' => (string) SmartTextTranslations::getLanguage(), 'ID' => (string) $element_id, 'WIDTH' => (int) $the_width, 'HEIGHT' => (int) $the_height, 'USE-JQ' => (bool) $use_multi_list_jq, 'HAVE-FILTER' => (bool) $have_filter], 'yes');
             //--
         }
         //end if
         //--
     } else {
         //--
         $use_blank_value = 'no';
         //--
         $js = '';
         $css_class = 'class="ux-field"';
         //--
     }
     //end if else
     //--
     //--
     $out = '';
     //--
     if ((string) $y_mode == 'form') {
         //--
         if ((string) $y_draw == 'checkboxes') {
             // checkboxes
             $out .= '<input type="hidden" name="' . $y_varname . '" value="">' . "\n";
             // we need a hidden value
         } else {
             // list
             $out .= '<select name="' . $y_varname . '" id="' . $element_id . '" ' . $css_class . ' style="width:' . $the_width . 'px; ' . $y_extrastyle . '" ' . $use_multi_list_htm . ' ' . $y_custom_js . '>' . "\n";
             if ((string) $use_blank_value == 'yes') {
                 $out .= '<option value="">&nbsp;</option>' . "\n";
                 // we need a blank value to unselect
             }
             //end if
         }
         //end if else
         //--
     }
     //end if
     //--
     for ($i = 0; $i < Smart::array_size($yarr_data); $i++) {
         //--
         $i_key = $i;
         $i_val = $i + 1;
         $i = $i + 1;
         //--
         if ((string) $y_mode == 'form') {
             //--
             $tmp_el_id = 'SmartFrameworkComponents_MultiSelect_ID__' . sha1($y_varname . $yarr_data[$i_key]);
             //--
             $tmp_sel = '';
             $tmp_checked = '';
             //--
             if (is_array($y_selected_value)) {
                 //--
                 if (in_array($yarr_data[$i_key], $y_selected_value)) {
                     //--
                     $tmp_sel = ' selected';
                     $tmp_checked = ' checked';
                     //--
                 }
                 //end if
                 //--
             } else {
                 //--
                 if (SmartUnicode::str_icontains($y_selected_value, '<' . $yarr_data[$i_key] . '>')) {
                     // multiple categs as <id1>,<id2>
                     //--
                     $tmp_sel = ' selected';
                     $tmp_checked = ' checked';
                     //--
                 }
                 //end if
                 //--
             }
             //end if
             //--
             if ((string) $y_draw == 'checkboxes') {
                 // checkboxes
                 //--
                 if ((string) $y_sync_values == 'yes') {
                     $tmp_onclick = ' onClick="SmartJS_BrowserUtils.checkAll_CkBoxes(this.form.name, \'' . Smart::escape_html($tmp_el_id) . '\', this.checked);"';
                 } else {
                     $tmp_onclick = '';
                 }
                 //end if else
                 //--
                 $out .= '<input type="checkbox" name="' . $y_varname . '" id="' . Smart::escape_html($tmp_el_id) . '" value="' . Smart::escape_html($yarr_data[$i_key]) . '"' . $tmp_checked . $tmp_onclick . '>';
                 $out .= ' &nbsp; ' . Smart::escape_html($yarr_data[$i_val]) . '<br>';
                 //--
             } else {
                 // list
                 //--
                 if ((string) $yarr_data[$i_key] == '#OPTGROUP#') {
                     $out .= '<optgroup label="' . Smart::escape_html($yarr_data[$i_val]) . '">' . "\n";
                     // the optgroup
                 } else {
                     $out .= '<option value="' . Smart::escape_html($yarr_data[$i_key]) . '"' . $tmp_sel . '>&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '</option>' . "\n";
                 }
                 //end if else
                 //--
             }
             //end if else
             //--
         } else {
             //--
             if (is_array($y_selected_value)) {
                 //--
                 if (in_array($yarr_data[$i_key], $y_selected_value)) {
                     //--
                     $out .= '&middot;&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '<br>' . "\n";
                     //--
                 }
                 //end if
                 //--
             } else {
                 //--
                 if (SmartUnicode::str_icontains($y_selected_value, '<' . $yarr_data[$i_key] . '>')) {
                     //-- multiple categs as <id1>,<id2>
                     $out .= '&middot;&nbsp;' . Smart::escape_html($yarr_data[$i_val]) . '<br>' . "\n";
                     //--
                 }
                 // end if
                 //--
             }
             //end if else
             //--
         }
         //end if else
         //--
     }
     //end for
     //--
     if ((string) $y_mode == 'form') {
         //--
         if ((string) $y_draw == 'checkboxes') {
             // checkboxes
             $out .= '<br>' . "\n";
         } else {
             // list
             $out .= '</select>' . "\n";
             $out .= $js . "\n";
         }
         //end if else
         //--
     }
     //end if
     //--
     //--
     return $out;
     //--
 }
 /**
  * Replace HTML type accents in UTF-8 encoded strings, and then DE-ACCENT
  * Replace accented UTF-8 characters like by unaccented ASCII-7 equivalents
  *
  * @param STRING $string
  * @return STRING
  */
 private static function safe_charset($html)
 {
     //--
     return SmartUnicode::html_entities($html);
     //--
 }
 private function parse_banner($reply)
 {
     //--
     $outside = true;
     $banner = '';
     //--
     $reply = trim($reply);
     //--
     for ($i = 0; $i < SmartUnicode::str_len($reply); $i++) {
         //--
         $digit = SmartUnicode::sub_str($reply, $i, 1);
         //--
         if (strlen($digit) > 0) {
             //--
             if (!$outside and (string) $digit != '<' and (string) $digit != '>') {
                 $banner .= $digit;
             }
             //end if
             //--
             if ((string) $digit == '<') {
                 $outside = false;
             }
             //end if
             //--
             if ((string) $digit == '>') {
                 $outside = true;
             }
             //end if
             //--
         }
         //end if
         //--
     }
     //end for
     //--
     $banner = trim($this->strip_clf($banner));
     // just in case
     if (strlen($banner) > 0) {
         $banner = '<' . $banner . '>';
     }
     //end if
     //--
     return $banner;
     //--
 }
 /**
  * Load a File or an URL
  * it may use 3 methods: FileRead, CURL or HTTP-Browser class
  *
  * @param STRING 	$y_url_or_path			:: /path/to/file | http(s)://some.url:port/path (port is optional)
  * @param NUMBER 	$y_timeout				:: timeout in seconds
  * @param ENUM 		$y_method 				:: used only for URLs, the browsing method: GET | POST
  * @param ENUM		$y_ssl_method			:: SSL Mode: tls | sslv3 | sslv2 | ssl
  * @param STRING 	$y_auth_name			:: used only for URLs, the auth user name
  * @param STRING 	$y_auth_pass			:: used only for URLs, the auth password
  * @param YES/NO	y_allow_set_credentials	:: DEFAULT MUST BE set to NO ; if YES must be set just for internal URLs ; if the $y_url_or_path to get is detected to be under current URL will send also the Unique / session IDs ; more if detected that is from admin.php and if this is set to YES will send the HTTP-BASIC Auth credentials if detected (using YES with other URLs than SmartFramework's current URL can be a serious SECURITY ISSUE, so don't !)
  */
 public static function load_url_or_file($y_url_or_path, $y_timeout = 30, $y_method = 'GET', $y_ssl_method = '', $y_auth_name = '', $y_auth_pass = '', $y_allow_set_credentials = 'no')
 {
     //-- v.2016-01-15
     // fixed sessionID with new Dynamic generated
     // TODO: use the CURL to browse also FTP and SSH ...
     //--
     $y_url_or_path = (string) $y_url_or_path;
     //--
     if ((string) $y_url_or_path == '') {
         //--
         return array('log' => 'ERROR: FILE Name is Empty ...', 'mode' => 'file', 'result' => '0', 'code' => '400', 'headers' => '', 'content' => '', 'debuglog' => '');
         //--
     }
     //end if
     //-- detect if file or url
     if (substr($y_url_or_path, 0, 7) == 'http://' or substr($y_url_or_path, 0, 8) == 'https://') {
         $is_file = 0;
         // it is a url
     } else {
         $is_file = 1;
         // it is a file
     }
     //end if
     //--
     if ($is_file == 1) {
         //--
         $y_url_or_path = trim($y_url_or_path);
         //-- try to detect if data:image/ :: {{{SYNC-DATA-IMAGE}}}
         if (strtolower(substr($y_url_or_path, 0, 11)) == 'data:image/' and stripos($y_url_or_path, ';base64,') !== false) {
             //--
             $eimg = explode(';base64,', $y_url_or_path);
             //--
             return array('log' => 'OK ? Not sure, decoded from embedded b64 image: ', 'mode' => 'embedded', 'result' => '1', 'code' => '200', 'headers' => SmartUnicode::sub_str($y_url_or_path, 0, 50) . '...', 'content' => @base64_decode(trim($eimg[1])), 'debuglog' => '');
             //--
         } elseif (is_file($y_url_or_path)) {
             //--
             return array('log' => 'OK: FILE Exists', 'mode' => 'file', 'result' => '1', 'code' => '200', 'headers' => 'Content-Disposition: inline; filename="' . basename($y_url_or_path) . '"' . "\n", 'content' => SmartFileSystem::read($y_url_or_path), 'debuglog' => '');
             //--
         } else {
             //--
             return array('log' => 'ERROR: FILE Not Found or Invalid Data ...', 'mode' => 'file', 'result' => '0', 'code' => '404', 'headers' => '', 'content' => '', 'debuglog' => '');
             //--
         }
         //end if else
         //--
     } else {
         //--
         if ((string) $y_ssl_method == '') {
             if (defined('SMART_FRAMEWORK_SSL_MODE')) {
                 $y_ssl_method = (string) SMART_FRAMEWORK_SSL_MODE;
             } else {
                 Smart::log_notice('NOTICE: LibUtils/Load-URL-or-File // The SSL Method not defined and SMART_FRAMEWORK_SSL_MODE was not defined. Using the `tls` as default ...');
                 $y_ssl_method = 'tls';
             }
             //end if else
         }
         //end if
         //--
         $browser = new SmartHttpClient();
         //--
         $y_timeout = Smart::format_number_int($y_timeout, '+');
         if ($y_timeout <= 0) {
             $y_timeout = 30;
             // default value
         }
         //end if
         $browser->connect_timeout = (int) $y_timeout;
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             $browser->debug = 1;
         }
         //end if
         //--
         if ((string) self::get_server_current_protocol() == 'https://') {
             $tmp_current_protocol = 'https://';
         } else {
             $tmp_current_protocol = 'http://';
         }
         //end if else
         //--
         $tmp_current_server = self::get_server_current_domain_name();
         $tmp_current_port = self::get_server_current_port();
         //--
         $tmp_current_path = self::get_server_current_request_uri();
         $tmp_current_script = self::get_server_current_full_script();
         //--
         $tmp_test_url_arr = Smart::separe_url_parts($y_url_or_path);
         $tmp_test_browser_id = self::get_os_browser_ip();
         //--
         $tmp_extra_log = '';
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             $tmp_extra_log .= "\n" . '===== # =====' . "\n";
         }
         //end if
         //--
         $cookies = array();
         $auth_name = (string) $y_auth_name;
         $auth_pass = (string) $y_auth_pass;
         //--
         if ((string) $y_allow_set_credentials == 'yes') {
             //--
             if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                 $tmp_extra_log .= '[EXTRA]: I will try to detect if this is my current Domain and I will check if it is safe to send my sessionID COOKIE and my Auth CREDENTIALS ...' . "\n";
             }
             //end if
             //--
             if ((string) $tmp_current_protocol == (string) $tmp_test_url_arr['protocol'] and (string) $tmp_current_server == (string) $tmp_test_url_arr['server'] and (string) $tmp_current_port == (string) $tmp_test_url_arr['port']) {
                 //--
                 if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                     $tmp_extra_log .= '[EXTRA]: OK, Seems that the browsed Domain is identical with my current Domain which is: ' . $tmp_current_protocol . $tmp_current_server . ':' . $tmp_current_port . ' and the browsed one is: ' . $tmp_test_url_arr['protocol'] . $tmp_test_url_arr['server'] . ':' . $tmp_test_url_arr['port'] . "\n";
                     $tmp_extra_log .= '[EXTRA]: I will also check if my current script and path are identical with the browsed ones ...' . "\n";
                 }
                 //end if
                 //--
                 if ((string) $tmp_current_script == (string) $tmp_test_url_arr['scriptname'] and substr($tmp_current_path, 0, strlen($tmp_current_script)) == (string) $tmp_test_url_arr['scriptname']) {
                     //--
                     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                         $tmp_extra_log .= '[EXTRA]: OK, Seems that the current script is identical with the browsed one :: ' . 'Current Path is: \'' . $tmp_current_script . '\' / Browsed Path is: \'' . $tmp_test_url_arr['scriptname'] . '\' !' . "\n";
                         $tmp_extra_log .= '[EXTRA]: I will check if I have to send my SessionID so I will check the browserID ...' . "\n";
                     }
                     //end if
                     //--
                     $browser->useragent = (string) self::get_selfrobot_useragent_name();
                     // this must be set just when detected the same path and script ; it is a requirement to detect it as the self-robot [ @s# ] in order to send the credentials or the current
                     //-- {{{SYNC-SMART-UNIQUE-COOKIE}}}
                     if (defined('SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME') and !defined('SMART_FRAMEWORK_UNIQUE_ID_COOKIE_SKIP')) {
                         if ((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME != '') {
                             if (SmartFrameworkSecurity::ValidateVariableName(strtolower((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME))) {
                                 //--
                                 if ((string) SMART_APP_VISITOR_COOKIE != '') {
                                     // if set, then forward
                                     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                                         $tmp_extra_log .= '[EXTRA]: OK, I will send my current Visitor Unique Cookie ID as it is set and not empty ...' . "\n";
                                     }
                                     //end if
                                     $cookies[(string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME] = (string) SMART_APP_VISITOR_COOKIE;
                                     // this is a requirement
                                 }
                                 //end if
                                 //--
                             }
                             //end if
                         }
                         //end if
                     }
                     //end if
                     //-- #end# sync
                     if ((string) SmartAuth::get_login_method() == 'HTTP-BASIC' and (string) $auth_name == '' and (string) $auth_pass == '' and strpos($tmp_current_script, '/admin.php') !== false and strpos($tmp_test_url_arr['scriptname'], '/admin.php') !== false) {
                         //--
                         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                             $tmp_extra_log .= '[EXTRA]: HTTP-BASIC Auth method detected / Allowed to pass the Credentials - as the browsed URL belongs to this ADMIN Server as I run, the Auth credentials are set but passed as empty - everything seems to be safe I will send my credentials: USERNAME = \'' . SmartAuth::get_login_id() . '\' ; PASS = *****' . "\n";
                         }
                         //end if
                         //--
                         $auth_name = (string) SmartAuth::get_login_id();
                         $auth_pass = (string) SmartAuth::get_login_password();
                         //--
                     }
                     //end if
                     //--
                 } else {
                     //--
                     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                         $tmp_extra_log .= '[EXTRA]: Seems that the scripts are NOT identical :: ' . 'Current Script is: \'' . $tmp_current_script . '\' / Browsed Script is: \'' . $tmp_test_url_arr['scriptname'] . '\' !' . "\n";
                         $tmp_extra_log .= '[EXTRA]: This is the diff for having a comparation: ' . substr($tmp_current_path, 0, strlen($tmp_current_script)) . "\n";
                     }
                     //end if
                     //--
                 }
                 //end if
                 //--
             }
             //end if
             //--
         }
         //end if
         //--
         $browser->cookies = (array) $cookies;
         //--
         $data = (array) $browser->browse_url($y_url_or_path, $y_method, $y_ssl_method, $auth_name, $auth_pass);
         // do browse
         //--
         return array('log' => (string) $data['log'] . $tmp_extra_log, 'mode' => (string) $data['mode'], 'result' => (string) $data['result'], 'code' => (string) $data['code'], 'headers' => (string) $data['headers'], 'content' => (string) $data['content'], 'debuglog' => (string) $data['debuglog']);
         //--
     }
     //end if else
     //--
 }
 public function __construct($y_type, $y_title, $y_arr_data, $y_format = 'png', $y_display_graph2 = true, $y_display_graph_depths = true)
 {
     //--
     if (!function_exists('imagecreatetruecolor')) {
         Smart::log_warning('"[ERROR] :: SmartImgGfxCharts :: PHP-GD TrueColor extension is missing ...');
         return;
     }
     //end if
     //--
     switch ((string) $y_type) {
         case 'vbars':
             $this->type = 1;
             break;
         case 'hbars':
             $this->type = 2;
             break;
         case 'dots':
             $this->type = 3;
             break;
         case 'lines':
             $this->type = 4;
             break;
         case 'pie':
             $this->type = 5;
             break;
         case 'donut':
             $this->type = 6;
             break;
         default:
             Smart::log_warning('"[ERROR] :: SmartImgBizCharts :: Invalid Chart Type: ' . $y_type . ' ...');
             return;
     }
     //end if
     //--
     $this->title = (string) SmartUnicode::deaccent_str((string) $y_title);
     //--
     if ((string) $y_format == 'gif') {
         $this->format = 'gif';
     } else {
         $this->format = 'png';
     }
     //end if else
     //--
     $this->skin = 1;
     // by now only this color schema !
     //--
     if (!is_array($y_arr_data)) {
         $y_arr_data = array();
     }
     //end if else
     //--
     $y_display_graph2 = (bool) $y_display_graph2;
     $y_display_graph_depths = (bool) $y_display_graph_depths;
     $this->x = $this->y = $this->z = $this->w = $this->v = array();
     //--
     for ($i = 0; $i < count($y_arr_data); $i++) {
         //--
         $tmp_arr = (array) $y_arr_data[$i];
         //--
         $this->x[$i] = (string) $tmp_arr['x'];
         // label
         $this->y[$i] = (double) $tmp_arr['y'];
         // 1st series
         if ($y_display_graph2 !== false) {
             $this->z[$i] = (double) $tmp_arr['z'];
             // 2nd series
         }
         //end if
         if ($y_display_graph_depths !== false) {
             $this->w[$i] = (int) $tmp_arr['w'];
             // buble size
         }
         //end if
         $this->v[$i] = (string) $tmp_arr['v'];
         // custom color
         //--
     }
     //end for
     //--
 }
 private function retry_data()
 {
     //--
     if (!$this->socket) {
         $this->error = '[ERR] SMTP Retry Data: No connection to server';
         return '';
     }
     //end if
     //--
     $data = '';
     //--
     while ($str = @fgets($this->socket, 515)) {
         // do not change the read buffer (default is set to 515 = 512 + 3)
         //--
         $data .= $str;
         //--
         if ($this->debug) {
             if ($this->dbglevel >= 2) {
                 // advanced debug
                 $this->log .= 'SMTP [3] // RETRY DATA // partial data is: ' . $str . "\n";
             }
             //end if
         }
         //end if
         //-- if the 4th character is a space then we are done reading so just break the loop (else the 4th char. is '-')
         if (SmartUnicode::sub_str($str, 3, 1) == ' ') {
             break;
         }
         //end if
         //--
     }
     //end while
     //--
     return $data;
     //--
 }
 /**
  * Set a Key into the persistent Cache
  *
  * @param STRING 	$y_realm		The Cache Realm
  * @param STRING 	$y_key			The Cache Key
  * @param MIXED 	$y_value		The value to be stored
  * @param INTEGER+ 	$y_expiration	Key Expiration in seconds (zero if key does not expire)
  *
  * @return BOOLEAN	Returns True if the key was set or false if not
  */
 public static function setKey($y_realm, $y_key, $y_value, $y_expiration = 0)
 {
     //--
     if (!self::isActive()) {
         return false;
     }
     //end if
     //--
     if (!self::validateRealm((string) $y_realm)) {
         Smart::log_warning('Persistent Cache / Invalid Realm: ' . $y_realm);
         return false;
     }
     //end if
     if (!self::validateKey((string) $y_key)) {
         Smart::log_warning('Persistent Cache / Invalid Key: ' . $y_key);
         return false;
     }
     //end if
     //--
     self::initCacheManager();
     //--
     $y_value = (string) SmartUnicode::fix_charset((string) $y_value);
     // fix
     $y_expiration = Smart::format_number_int($y_expiration, '+');
     //--
     $resexp = 1;
     if ((string) $y_realm == '') {
         $result = self::$redis->set((string) $y_key, (string) $y_value);
         if ($y_expiration > 0) {
             $resexp = self::$redis->expire((string) $y_key, (int) $y_expiration);
         }
         //end if
     } else {
         $result = self::$redis->set((string) $y_realm . ':' . $y_key, (string) $y_value);
         if ($y_expiration > 0) {
             $resexp = self::$redis->expire((string) $y_realm . ':' . $y_key, (int) $y_expiration);
         }
         //end if
     }
     //end if else
     //--
     if (strtoupper(trim((string) $result)) == 'OK' and $resexp == 1) {
         return true;
     } else {
         return false;
     }
     //end if else
     //--
 }
 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">&nbsp;' . 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']) . ' &nbsp; <i>' . Smart::escape_html($head['from_name']) . '</i>' . '</font><br>';
                     $out .= '<font size="2"><b>To:</b> ' . Smart::escape_html($head['to_addr']) . ' &nbsp; <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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . Smart::escape_html(trim($arr_cc_addr[$z])) . ' &nbsp; <i>' . Smart::escape_html(trim($arr_cc_name[$z])) . '</i>';
                             }
                             //end for
                         } else {
                             $out .= Smart::escape_html($head['cc_addr']) . ' &nbsp; <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']) . ' &nbsp; <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>&nbsp;</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"> &nbsp;<b><i>' . $tmp_att_size . '</i></b></font></td></tr></table></div>';
                         $xatts .= '<div align="left">' . $tmp_att_img . '&nbsp;&nbsp;<font size="1">' . $tmp_att_name . '&nbsp;&nbsp;<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, '.', ',') . '%') . '">&nbsp;</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
     //--
 }
 private function _decodeHeader($input)
 {
     //-- Remove white space between encoded-words
     $input = (string) preg_replace('/(=\\?[^?]+\\?(q|b)\\?[^?]*\\?=)(\\s)+=\\?/i', '\\1=?', (string) $input);
     // insensitive
     //-- For each encoded-word...
     $matches = array();
     while (preg_match('/(=\\?([^?]+)\\?(q|b)\\?([^?]*)\\?=)/i', (string) $input, $matches)) {
         // insensitive
         //--
         $encoded = $matches[1];
         $charset = $matches[2];
         $encoding = $matches[3];
         $text = $matches[4];
         //--
         if ((string) $charset == '' or (string) $charset == 'us-ascii') {
             $charset = 'iso-8859-1';
             // correction :: {{{SYNC-CHARSET-FIX}}}
         }
         //end if
         //--
         switch (strtoupper($encoding)) {
             case 'B':
                 $text = base64_decode($text);
                 $text = SmartUnicode::convert_charset($text, $charset, $this->charset);
                 // {{{SYNC-CHARSET-CONVERT}}}
                 break;
             case 'Q':
                 $text = quoted_printable_decode($text);
                 $text = SmartUnicode::convert_charset($text, $charset, $this->charset);
                 // {{{SYNC-CHARSET-CONVERT}}}
                 break;
             default:
                 // as is
         }
         //end switch
         //--
         $input = (string) str_replace($encoded, $text, $input);
         //--
     }
     //end while
     //--
     return (string) $input;
     //--
 }
 public static function test_sqlite3_json_smartgrid($ofs, $sortby, $sortdir, $sorttype, $src = '')
 {
     //--
     $db = new SmartTestSQLite3Model();
     $model = $db->getConnection();
     //--
     //--
     $data = array();
     $data['status'] = 'OK';
     $data['crrOffset'] = (int) $ofs;
     $data['itemsPerPage'] = 25;
     $data['sortBy'] = (string) $sortby;
     $data['sortDir'] = (string) $sortdir;
     $data['sortType'] = (string) $sorttype;
     $data['filter'] = array('src' => (string) $src);
     //--
     if ((string) strtoupper((string) $sortdir) == 'DESC') {
         $syntax_sort_dir = 'DESC';
     } else {
         $syntax_sort_dir = 'ASC';
     }
     //end if else
     $syntax_sort_mode = '';
     switch ((string) $sortby) {
         case 'iso':
             $syntax_sort_mode = ' ORDER BY iso ' . $syntax_sort_dir;
             break;
         case 'name':
             $syntax_sort_mode = ' ORDER BY name ' . $syntax_sort_dir;
             break;
         case 'iso3':
             $syntax_sort_mode = ' ORDER BY iso3 ' . $syntax_sort_dir;
             break;
         case 'numcode':
             $syntax_sort_mode = ' ORDER BY numcode ' . $syntax_sort_dir;
             break;
         default:
             $syntax_sort_mode = '';
     }
     //end switch
     //--
     $where = '';
     if ((string) $src != '') {
         if (is_numeric($src)) {
             $where = $model->prepare_param_query(' WHERE numcode = ?', array((int) $src));
         } elseif (strlen((string) $src) == 2) {
             $where = $model->prepare_param_query(' WHERE iso = ?', array(SmartUnicode::str_toupper($src)));
         } elseif (strlen((string) $src) == 3) {
             $where = $model->prepare_param_query(' WHERE iso3 = ?', array(SmartUnicode::str_toupper($src)));
         } else {
             $where = $model->prepare_param_query(' WHERE name LIKE ?', array($src . '%'));
         }
         //end if else
     }
     //end if
     $data['totalRows'] = $model->count_data('SELECT COUNT(1) FROM sample_countries' . $where);
     $data['rowsList'] = $model->read_adata('SELECT iso, name, iso3, numcode FROM sample_countries' . $where . $syntax_sort_mode . ' LIMIT ' . (int) $data['itemsPerPage'] . ' OFFSET ' . (int) $data['crrOffset']);
     //--
     unset($db);
     // close
     //--
     //--
     return Smart::json_encode((array) $data);
     //--
 }
Beispiel #21
0
 private function clean_html($y_comments, $y_extra_tags_remove = array(), $y_extra_tags_clean = array(), $y_allowed_tags = array())
 {
     //-- CLEANUP DISSALOWED AND FIX INVALID HTML TAGS
     // * it will use code standardize before to fix active PHP tags and weird characters
     // * will convert all UTF-8 characters to the coresponding HTML-ENTITIES
     // * will remove all tags that are unsafe like <script> or <head> and many other dissalowed unsafe tags
     // * if allowed tags are specified they will take precedence and will be filtered via strip_tags by allowing only these tags, at the end of cleanup to be safer !
     // * if DomDocument is detected and is allowed to be used by current settings will be used finally to do (post-processing) extra cleanup and fixes
     //--
     //--
     if ($this->is_clean != false) {
         return;
         // avoid to re-parse
     }
     //end if
     //--
     $this->is_clean = true;
     //--
     //--
     $this->standardize_html();
     // first, standardize the HTML Code
     //--
     //--
     $arr_tags_0x_list_comments = array('#\\<\\s*?\\!\\-?\\-?(.*?)\\-?\\-?\\>#si');
     //--
     $arr_tags_2x_list_bad = array('head', 'style', 'script', 'noscript', 'frameset', 'frame', 'iframe', 'canvas', 'audio', 'video', 'applet', 'param', 'object', 'form', 'xml', 'xmp', 'o:p');
     if (Smart::array_size($y_extra_tags_remove) > 0) {
         // add extra entries such as: img, p, div, ...
         for ($i = 0; $i < count($y_extra_tags_remove); $i++) {
             if (preg_match((string) $this->regex_tag_name, (string) $y_extra_tags_remove[$i])) {
                 if (!in_array((string) $y_extra_tags_remove[$i], $arr_tags_2x_list_bad)) {
                     $arr_tags_2x_list_bad[] = (string) $y_extra_tags_remove[$i];
                 }
                 //end if
             }
             //end if
         }
         //end for
     }
     //end if
     $arr_tags_2x_repl_bad = (array) $arr_tags_0x_list_comments;
     for ($i = 0; $i < count($arr_tags_0x_list_comments); $i++) {
         $arr_tags_2x_repl_good[] = '<!-- # -->';
         // comment
     }
     //end for
     for ($i = 0; $i < count($arr_tags_2x_list_bad); $i++) {
         $tmp_regex_tag = (array) $this->regex_tag((string) $arr_tags_2x_list_bad[$i]);
         // currently if nested tags some content between those tags may remain not removed ... but that is ok as long as the tag is replaced ; possible fix: match with siU instead of si but will go ungreedy and will match all content until very last end tag ... which may remove too many content
         $arr_tags_2x_repl_bad[] = $tmp_regex_tag['delimiter'] . '(' . $tmp_regex_tag['tag-start'] . ')' . '.*?' . '(' . $tmp_regex_tag['tag-end'] . ')' . $tmp_regex_tag['delimiter'] . 'si';
         // fix: paranthesis are required to correct match in this case (balanced regex)
         $arr_tags_2x_repl_good[] = '<!-- ' . Smart::escape_html((string) $arr_tags_2x_list_bad[$i]) . '/ -->';
     }
     //end if
     //--
     //--
     $arr_tags_1x_list_bad = (array) array_merge((array) $arr_tags_2x_list_bad, array('!doctype', 'html', 'body', 'base', 'meta', 'link', 'track', 'source', 'plaintext', 'marquee'));
     if (Smart::array_size($y_extra_tags_clean) > 0) {
         // add extra entries such as: img, p, div, ...
         for ($i = 0; $i < count($y_extra_tags_clean); $i++) {
             if (preg_match((string) $this->regex_tag_name, (string) $y_extra_tags_clean[$i])) {
                 if (!in_array((string) $y_extra_tags_clean[$i], $arr_tags_1x_list_bad)) {
                     $arr_tags_1x_list_bad[] = (string) $y_extra_tags_clean[$i];
                 }
                 //end if
             }
             //end if
         }
         //end for
     }
     //end if
     $arr_tags_1x_repl_bad = array();
     $arr_tags_1x_repl_good = array();
     for ($i = 0; $i < count($arr_tags_1x_list_bad); $i++) {
         $tmp_regex_tag = (array) $this->regex_tag((string) $arr_tags_1x_list_bad[$i]);
         $arr_tags_1x_repl_bad[] = $tmp_regex_tag['delimiter'] . $tmp_regex_tag['tag-start'] . $tmp_regex_tag['delimiter'] . 'si';
         $arr_tags_1x_repl_bad[] = $tmp_regex_tag['delimiter'] . $tmp_regex_tag['tag-end'] . $tmp_regex_tag['delimiter'] . 'si';
         $arr_tags_1x_repl_good[] = '<!-- ' . Smart::escape_html((string) $arr_tags_1x_list_bad[$i]) . ' -->';
         $arr_tags_1x_repl_good[] = '<!-- /' . Smart::escape_html((string) $arr_tags_1x_list_bad[$i]) . ' -->';
     }
     //end if
     //--
     //--
     $arr_all_repl_bad = (array) array_merge((array) $arr_tags_2x_repl_bad, (array) $arr_tags_1x_repl_bad);
     $arr_all_repl_good = (array) array_merge((array) $arr_tags_2x_repl_good, (array) $arr_tags_1x_repl_good);
     //--
     //print_r($arr_tags_2x_repl_bad);
     //print_r($arr_tags_2x_repl_good);
     //print_r($arr_tags_1x_repl_bad);
     //print_r($arr_tags_1x_repl_good);
     //print_r($arr_all_repl_bad);
     //print_r($arr_all_repl_good);
     //die('');
     //--
     //--
     $this->html = (string) preg_replace((array) $arr_all_repl_bad, (array) $arr_all_repl_good, (string) $this->html);
     //--
     //--
     $this->parse_elements();
     //--
     //--
     for ($i = 0; $i < Smart::array_size($this->elements); $i++) {
         //--
         $code = (string) $this->elements[$i];
         if (substr($code, 0, 4) != '<!--' and (strpos($code, '<') !== false or strpos($code, '>') !== false)) {
             // if valid tag and not a comment
             //--
             $tag_have_endline = false;
             if (substr($code, -1, 1) === "\n") {
                 $tag_have_endline = true;
             }
             //end if
             //--
             $code = trim(str_replace(array("\t", "\n", "\r"), array(' ', ' ', ' '), (string) $code));
             // make tabs and new lines as simple space
             $tmp_parse_attr = (array) $this->get_attributes($code);
             //--
             if (strpos($code, ' ') !== false and Smart::array_size($tmp_parse_attr) > 0) {
                 // tag have attributes
                 //--
                 $tmp_arr = explode(' ', $code);
                 // get tag parts
                 $this->elements[$i] = strtolower((string) $tmp_arr[0]);
                 // recompose the tags
                 foreach ($tmp_parse_attr as $key => $val) {
                     $tmp_is_valid_attr = true;
                     if (!preg_match((string) $this->regex_tag_name, (string) $key)) {
                         $tmp_is_valid_attr = false;
                         // remove invalid attributes
                     } elseif (substr((string) trim((string) $key), 0, 2) == 'on') {
                         $tmp_is_valid_attr = false;
                         // remove attributes starting with 'on' (all JS Events)
                     } elseif (substr((string) trim((string) $key), 0, 10) == 'formaction') {
                         $tmp_is_valid_attr = false;
                         // remove attributes starting with 'formaction'
                     } elseif (substr((string) trim((string) $val), 0, 2) == '&{') {
                         $tmp_is_valid_attr = false;
                         // remove attributes of which value are old Netscape JS ; Ex: border="&{getBorderWidth( )};"
                     } elseif (substr((string) trim((string) $val), 0, 11) == 'javascript:') {
                         $tmp_is_valid_attr = false;
                         // remove attributes that contain javascript:
                     } elseif (stripos((string) trim((string) $val), 'java') !== false and stripos((string) trim((string) $val), 'script') !== false and strpos((string) trim((string) $val), ':') !== false) {
                         $tmp_is_valid_attr = false;
                         // remove attributes that contain java + script + :
                     }
                     //end for
                     if ($tmp_is_valid_attr) {
                         $this->elements[$i] .= ' ' . strtolower($key) . '=' . '"' . str_replace(array('"', '<', '>'), array('&quot;', '&lt;', '&gt;'), (string) $val) . '"';
                     }
                     //end if
                 }
                 //end foreach
                 $this->elements[$i] .= '>';
                 if ($tag_have_endline) {
                     $this->elements[$i] .= "\n";
                 }
                 //end if
                 $tmp_arr = array();
                 //--
             } elseif (preg_match('/^[<' . $this->expr_tag_name . '\\/ >]+$/si', (string) $code)) {
                 // simple tags (includding tags like <br />) ; needs extra / and space
                 //--
                 $this->elements[$i] = strtolower((string) $code);
                 if ($tag_have_endline) {
                     $this->elements[$i] .= "\n";
                 }
                 //end if
                 //--
             } else {
                 //--
                 $this->elements[$i] = '';
                 // invalid tags, clear
                 //--
             }
             //end if
         }
         //end if
         //--
     }
     //end for
     //--
     //--
     $this->html = (string) SmartUnicode::convert_charset((string) implode('', (array) $this->elements), 'UTF-8', 'HTML-ENTITIES');
     //--
     if ($y_comments === false) {
         $this->html = preg_replace((array) $arr_tags_0x_list_comments, '', $this->html);
     }
     //end if
     //--
     //--
     if (Smart::array_size($y_allowed_tags) > 0) {
         $arr_striptags_allow = array();
         for ($i = 0; $i < count($y_allowed_tags); $i++) {
             if (preg_match((string) $this->regex_tag_name, (string) $y_allowed_tags[$i])) {
                 if (!in_array((string) $y_allowed_tags[$i], (array) $arr_striptags_allow)) {
                     // despite if a tag is specified as unallowed, if allowed here will take precedence
                     $arr_striptags_allow[] = '<' . $y_allowed_tags[$i] . '>';
                 }
                 //end if
             }
             //end if
         }
         //end for
         if (Smart::array_size($arr_striptags_allow) > 0) {
             //print_r($arr_striptags_allow);
             $str_striptags_allow = (string) implode(',', (array) $arr_striptags_allow);
             //echo $str_striptags_allow;
             $this->html = (string) strip_tags((string) $this->html, (string) $str_striptags_allow);
         }
         //end if
     }
     //end if
     //--
     //--
     $this->html = (string) trim((string) $this->html);
     //--
     //--
     $use_dom = false;
     //--
     if ($this->dom_processing !== false and class_exists('DOMDocument')) {
         //--
         $use_dom = true;
         //--
         if ((string) $this->html != '') {
             //--
             @libxml_use_internal_errors(true);
             @libxml_clear_errors();
             //--
             $dom = new DOMDocument(5, (string) SMART_FRAMEWORK_CHARSET);
             //--
             $dom->encoding = (string) SMART_FRAMEWORK_CHARSET;
             $dom->strictErrorChecking = false;
             // do not throw errors
             $dom->preserveWhiteSpace = true;
             // do not remove redundant white space
             $dom->formatOutput = true;
             // try to format pretty-print the code
             $dom->resolveExternals = false;
             // disable load external entities from a doctype declaration
             $dom->validateOnParse = false;
             // this must be explicit disabled as if set to true it may try to download the DTD and after to validate (insecure ...)
             //--
             @$dom->loadHTML((string) $this->html, LIBXML_ERR_WARNING | LIBXML_NONET | LIBXML_PARSEHUGE | LIBXML_BIGLINES | LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);
             $this->html = (string) @$dom->saveHTML();
             // get back from DOM
             //print_r($this->html);
             unset($dom);
             // clear DOM
             $this->html = (string) trim((string) preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\\s*~i', '', (string) $this->html));
             // cleanup ; fixes: normally with the above options will add no doctype or html / body tags, but use it just in case ; alternative to this: explode by body to get content
             //--
             if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes' or $this->dom_log_errors === true) {
                 // log errors if set :: OR ((string)$this->html == '')
                 $errors = (array) @libxml_get_errors();
                 if (Smart::array_size($errors) > 0) {
                     $notice_log = '';
                     foreach ($errors as $z => $error) {
                         if (is_object($error)) {
                             $notice_log .= 'PARSE-ERROR: [' . $the_ercode . '] / Level: ' . $error->level . ' / Line: ' . $error->line . ' / Column: ' . $error->column . ' / Code: ' . $error->code . ' / Message: ' . $error->message . "\n";
                         }
                         //end if
                     }
                     //end foreach
                     if ((string) $notice_log != '') {
                         Smart::log_notice('SmartHtmlParser NOTICE [DOMDocument]:' . "\n" . $notice_log . "\n" . '#END' . "\n");
                     }
                     //end if
                     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
                         Smart::log_notice('SmartHtmlParser / Debug HTML-String:' . "\n" . $this->html . "\n" . '#END');
                     }
                     //end if
                 }
                 //end if
             }
             //end if
             //--
             @libxml_clear_errors();
             @libxml_use_internal_errors(false);
             //--
         }
         //end if
         //--
     }
     //end if
     //--
     //--
     if ($this->signature) {
         if ($use_dom) {
             $start_signature = '<!-- Smart/HTML.Cleaner [@] -->';
             $end_signature = '<!-- [/@] Smart/HTML.Cleaner -->';
         } else {
             $start_signature = '<!-- Smart/HTML.Cleaner [#] -->';
             $end_signature = '<!-- [/#] Smart/HTML.Cleaner -->';
         }
         //end if else
     } else {
         $start_signature = '';
         $end_signature = '';
     }
     //end if else
     //--
     //--
     $this->html = (string) $start_signature . $this->html . $end_signature;
     //--
 }
 /**
  * List code points for a given input
  *
  * @param string $input
  * @return array Multi-dimension array with basic, non-basic and aggregated code points
  */
 private function listCodePoints($input)
 {
     $codePoints = array('all' => array(), 'basic' => array(), 'nonBasic' => array());
     $length = (int) SmartUnicode::str_len((string) $input);
     for ($i = 0; $i < $length; $i++) {
         $char = (string) SmartUnicode::sub_str((string) $input, $i, 1);
         $code = $this->charToCodePoint($char);
         if ($code < 128) {
             $codePoints['all'][] = $codePoints['basic'][] = $code;
         } else {
             $codePoints['all'][] = $codePoints['nonBasic'][] = $code;
         }
     }
     //end for
     return $codePoints;
 }
 /**
  * Safe Path Name to be used to process dynamic build paths to avoid weird path character injections
  * To be used for full path to files or full path to dirs or just dir names
  * ALLOWED CHARS: [a-zA-Z0-9] _ - . @ # /
  *
  * @param STRING 		$y_path			:: Path to be processed
  * @param STRING 		$ysupresschar	:: The suppression character to replace weird characters ; optional ; default is ''
  *
  * @return STRING 						:: The safe path
  */
 public static function safe_pathname($y_path, $ysupresschar = '')
 {
     //-- v.160221
     if (preg_match('/^[_a-zA-Z0-9\\-\\.@#\\/]+$/', (string) $y_path)) {
         return (string) $y_path;
     }
     //end if
     //--
     $ysupresschar = (string) $ysupresschar;
     // force string and be sure is lower
     switch ((string) $ysupresschar) {
         case '-':
         case '_':
             break;
         default:
             $ysupresschar = '';
     }
     //end if
     //--
     $y_path = (string) $y_path;
     // force string
     $y_path = (string) preg_replace((string) self::lower_unsafe_characters(), '', (string) $y_path);
     // remove dangerous characters
     $y_path = (string) SmartUnicode::utf8_to_iso($y_path);
     // bring STRING to ISO-8859-1
     $y_path = (string) stripslashes($y_path);
     // remove any possible back-slashes
     $y_path = (string) str_replace('?', $ysupresschar, $y_path);
     // replace questionmark (that may come from utf8 decode)
     $y_path = (string) preg_replace('/[^_a-zA-Z0-9\\-\\.@#\\/]/', $ysupresschar, $y_path);
     // {{{SYNC-SAFE-PATH-CHARS}}} suppress any other characters than these, no unicode modifier
     $y_path = (string) preg_replace("/(\\.)\\1+/", '.', $y_path);
     // suppress multiple . dots and replace with single dot
     $y_path = (string) preg_replace("/(\\/)\\1+/", '/', $y_path);
     // suppress multiple // slashes and replace with single slash
     $y_path = (string) str_replace(array('../', './'), array('-', '-'), $y_path);
     // replace any unsafe path combinations (do not suppress but replace with a fixed character to avoid create security breaches)
     $y_path = (string) trim($y_path);
     // finally trim it
     //--
     return (string) $y_path;
     //--
 }
 /**
  * Fix charset for param queries
  * Used for: pg_query_params()
  *
  * @param ARRAY $arr_params				:: A mixed variable
  * @return STRING 								:: JSON string
  *
  */
 private static function escape_arr_params($arr_params)
 {
     //--
     if (is_array($arr_params)) {
         foreach ($arr_params as $k => $v) {
             $arr_params[$k] = (string) SmartUnicode::fix_charset((string) $v);
             // fix
         }
         //end foreach
     }
     //end if
     //--
     //--
     return $arr_params;
     // this should not be enforced to a type ... must remain as it is
     //--
 }