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";
     //--
 }
示例#2
0
 public function get_clean_html($y_comments = true, $y_extra_tags_remove = array(), $y_extra_tags_clean = array(), $y_allowed_tags = array())
 {
     //--
     if (!SmartValidator::validate_html_or_xml_code((string) $this->html)) {
         return (string) $this->html;
     }
     //end if
     //--
     //--
     if (!is_array($y_extra_tags_remove)) {
         $y_extra_tags_remove = array();
     }
     //end if
     //--
     if (!is_array($y_extra_tags_clean)) {
         $y_extra_tags_clean = array();
     }
     //end if
     //--
     if (!is_array($y_allowed_tags)) {
         $y_allowed_tags = array();
     }
     //end if
     //--
     //--
     $this->clean_html((bool) $y_comments, (array) $y_extra_tags_remove, (array) $y_extra_tags_clean, (array) $y_allowed_tags);
     //--
     //--
     //return (string) (print_r($this->elements,1));
     return (string) $this->html;
     //--
 }
 /**
  * Create Escaped SQL Statements from Parameters and Array of Data by replacing ? (question marks)
  * This can be used for a full SQL statement or just for a part.
  * The statement must not contain any Single Quotes to prevent SQL injections which are unpredictable if mixing several statements at once !
  *
  * @param STRING $query							:: SQL Statement to process like '   WHERE ("id" = ?)'
  * @param ARRAY $arrdata 						:: The non-associative array as of: $arr=array('a');
  * @return STRING								:: The SQL processed (partial/full) Statement
  */
 public static function prepare_param_query($db, $query, $replacements_arr)
 {
     // {{{SYNC-SQL-PARAM-QUERY}}}
     //--
     if (!is_string($query)) {
         self::error($db, 'PREPARE-PARAM-QUERY', 'Query is not a string !', print_r($query, 1), $replacements_arr);
         return '';
         // query must be a string
     }
     //end if
     //--
     if ((string) trim((string) $query) == '') {
         self::error($db, 'PREPARE-PARAM-QUERY', 'Query is empty !', (string) $query, $replacements_arr);
         return '';
         // empty query not allowed
     }
     //end if
     //--
     if (strpos($query, "'") !== false) {
         // this must be avoided as below will be exploded by ? thus if a ? is inside '' this is a problem ...
         self::error($db, 'PREPARE-PARAM-QUERY', 'Query used for prepare with params in ' . __FUNCTION__ . '() cannot contain single quotes to prevent possible SQL injections which can produce unpredictable results !', (string) $query, $replacements_arr);
         return '';
         // single quote is not allowed
     }
     //end if
     //--
     if (!is_array($replacements_arr)) {
         self::error($db, 'PREPARE-PARAM-QUERY', 'Query Replacements is NOT Array !', (string) $query, $replacements_arr);
         return '';
         // replacements must be an array
     }
     //end if
     //--
     $out_query = '';
     //--
     if (strpos((string) $query, '?') !== false) {
         //--
         $expr_arr = (array) explode('?', (string) $query);
         $expr_count = count($expr_arr);
         //--
         for ($i = 0; $i < $expr_count; $i++) {
             //--
             $out_query .= (string) $expr_arr[$i];
             //--
             if ($i < $expr_count - 1) {
                 //--
                 if (!array_key_exists((string) $i, $replacements_arr)) {
                     self::error($db, 'PREPARE-PARAM-QUERY', 'Invalid Replacements Array Size ; Key=' . $i, (string) $query, $replacements_arr);
                     return '';
                     // array key does not exists in replacements
                     break;
                 }
                 //end if
                 //--
                 if (SmartValidator::validate_numeric_integer_or_decimal_values($replacements_arr[$i]) === true) {
                     // {{{SYNC-DETECT-PURE-NUMERIC-INT-OR-DECIMAL-VALUES}}}
                     $out_query .= (string) trim((string) $replacements_arr[$i]);
                     // not escaped, it is safe: numeric and can contain just 0-9 - .
                 } else {
                     $out_query .= "'" . self::escape_str($db, (string) $replacements_arr[$i]) . "'";
                 }
                 //end if else
                 //--
             }
             //end if
             //--
         }
         //end for
         //--
     } else {
         //--
         $out_query = (string) $query;
         //--
     }
     //end if else
     //--
     return (string) $out_query;
     //--
 }
    public static function test_strings()
    {
        //--
        $unicode_text = '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド';
        //--
        $idn_domain_unicode = 'jösefsson.tßst123.org';
        $idn_domain_iso = 'xn--jsefsson-n4a.xn--tst123-bta.org';
        $idn_email_unicode = 'räksmörgås@jösefsson.tßst123.org';
        $idn_email_iso = '*****@*****.**';
        //--
        //--
        $err = '';
        //--
        //--
        $tests[] = '##### Unicode STRING / TESTS: #####';
        //--
        //--
        $regex_positive = '/^[\\w"\\:\\?]+$/';
        $regex_negative = '/[^\\w"\\:\\?]/';
        //--
        //--
        if (defined('SMART_FRAMEWORK_SECURITY_FILTER_INPUT')) {
            if ((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT != '') {
                if ((string) $err == '') {
                    $the_test = 'Smart.Framework Security Input Filter Regex - test over a full Unicode String';
                    $tests[] = $the_test;
                    if (preg_match((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT, 'Platform クラウドアプリケーションプラットフォーム \'áâãäåāăąÁÂÃÄÅĀĂĄćĉčçĆĈČÇďĎèéêëēĕėěęÈÉÊËĒĔĖĚĘĝģĜĢĥħĤĦìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮijĵIJĴķĶĺļľłĹĻĽŁñńņňÑŃŅŇòóôõöōŏőøœÒÓÔÕÖŌŎŐØŒŕŗřŔŖŘșşšśŝßȘŞŠŚŜțţťȚŢŤùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲŵŴẏỳŷÿýẎỲŶŸÝźżžŹŻŽ " <p></p> ? & * ^ $ @ ! ` ~ % () [] {} | \\ / + - _ : ; , . #\'0.51085600 1454529112#' . "\r\n\t" . '`~@#$%^&*()-_=+[{]}|;:"<>,.?/\\')) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                    }
                    //end if
                }
                //end if
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Regex Test Positive';
            $tests[] = $the_test;
            if (!preg_match((string) $regex_positive . 'u', (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (1) ...';
            } elseif (preg_match((string) $regex_positive, (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (2) ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Regex Test Negative';
            $tests[] = $the_test;
            if (preg_match((string) $regex_negative . 'u', (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (1) ...';
            } elseif (!preg_match((string) $regex_negative, (string) $unicode_text)) {
                $err = 'ERROR: ' . $the_test . ' FAILED (2) ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Deaccented ISO Regex Test Positive';
            $tests[] = $the_test;
            if (!preg_match((string) $regex_positive, (string) SmartUnicode::deaccent_str($unicode_text))) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Deaccented ISO Regex Test Negative';
            $tests[] = $the_test;
            if (preg_match((string) $regex_negative, (string) SmartUnicode::deaccent_str($unicode_text))) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Strlen Test';
            $tests[] = $the_test;
            if (SmartUnicode::str_len($unicode_text) !== 30) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_ipos
            $the_test = 'Unicode Find Substring (Case Insensitive), Positive';
            $tests[] = $the_test;
            if (SmartUnicode::str_icontains($unicode_text, 'șș') !== true) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_ipos
            $the_test = 'Unicode Find Substring (Case Insensitive), Negative';
            $tests[] = $the_test;
            if (SmartUnicode::str_icontains($unicode_text, 'șş') !== false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_pos
            $the_test = 'Unicode Find Substring (Case Sensitive), Positive';
            $tests[] = $the_test;
            if (SmartUnicode::str_contains($unicode_text, 'țȚ') !== true) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            // this tests also SmartUnicode::str_pos
            $the_test = 'Unicode Find Substring (Case Sensitive), Negative';
            $tests[] = $the_test;
            if (SmartUnicode::str_contains($unicode_text, 'țŢ') !== false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Find Substring (Case Insensitive), Reverse';
            $tests[] = $the_test;
            if (SmartUnicode::str_ripos($unicode_text, 'ţţグ') === false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Find Substring (Case Sensitive), Reverse';
            $tests[] = $the_test;
            if (SmartUnicode::str_rpos($unicode_text, 'ţŢグ') === false) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode Return Substring (Case Insensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::stri_str($unicode_text, 'âȘșȚ') !== 'ÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode Return Substring (Case Sensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::str_str($unicode_text, 'ÂșȘț') !== 'ÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode String to LowerCase';
            $tests[] = $the_test;
            if (SmartUnicode::str_tolower($unicode_text) !== '"unicode78źź:ăăîîââșșțțşşţţグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode String to UpperCase';
            $tests[] = $the_test;
            if (SmartUnicode::str_toupper($unicode_text) !== '"UNICODE78ŹŹ:ĂĂÎÎÂÂȘȘȚȚŞŞŢŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode SubString function (without last param)';
            $tests[] = $the_test;
            if (SmartUnicode::sub_str($unicode_text, 25) !== 'ţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'Unicode SubString function (with last param)';
            $tests[] = $the_test;
            if (SmartUnicode::sub_str($unicode_text, 25, 3) !== 'ţŢグ') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode SubString Count function';
            $tests[] = $the_test;
            if (SmartUnicode::substr_count($unicode_text, 'ţ') !== 1) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Unicode String Replace with Limit (Case Sensitive)';
            $tests[] = $the_test;
            if (SmartUnicode::str_limit_replace('ź', '@', $unicode_text, 1) !== '"Unicode78@ź:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'String Replace without Limit (Case Sensitive)';
            $tests[] = $the_test;
            if (str_replace('ź', '@', $unicode_text) !== '"Unicode78@@:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            /* This test fails if the replacements accented characters are different case than one find in string (upper/lower) ... */
            $the_test = 'String Replace without Limit (Case Insensitive) *** Only with unaccented replacements !!';
            $tests[] = $the_test;
            if (str_ireplace('E7', '@', $unicode_text) !== '"Unicod@8źź:ăĂîÎâÂșȘțȚşŞţŢグッド') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Deaccent String';
            $tests[] = $the_test;
            if (SmartUnicode::deaccent_str($unicode_text) !== '"Unicode78zz:aAiIaAsStTsStT???') {
                $err = 'ERROR: ' . $the_test . ' FAILED ...';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'YAML Unicode Test: Compose from Array / Parse from YAML';
            $tests[] = $the_test;
            $test_arr = array('@test' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, $unicode_text => 'Unicode as Key', 'line3' => ['A' => 'b', 100, 'Thousand'], 'line4' => [1, 0.2, 3.0001], 'line5' => date('Y-m-d H:i:s'));
            $test_yaml = (string) '# start YAML (to test also comments)' . "\n" . (new SmartYamlConverter())->compose($test_arr) . "\n" . '# end YAML';
            $test_parr = (new SmartYamlConverter())->parse($test_yaml);
            if ($test_arr !== $test_parr) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#YAML Array (from YAML String): ' . print_r($test_parr, 1) . "\n\n" . '#YAML String (from ORIGINAL Array): ' . "\n" . $test_yaml;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'XML Unicode Test: Compose from Array / Parse from XML';
            $tests[] = $the_test;
            $test_arr = array('TEST' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, 'line3' => ['A' => 'b', 'c' => 'D'], 'line4' => '', 'line5' => date('Y-m-d H:i:s'));
            $test_xml = (string) (new SmartXmlComposer())->transform($test_arr);
            $test_parr = (new SmartXmlParser())->transform($test_xml);
            if ($test_arr !== $test_parr) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#XML Array (from XML String): ' . print_r($test_parr, 1) . "\n\n" . '#XML String (from ORIGINAL Array): ' . "\n" . $test_xml;
            }
            //end if
        }
        //end if
        //--
        $the_random_unicode_text = sha1($unicode_text . Smart::random_number(1000, 9999)) . '-' . $unicode_text . " \r\n\t" . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str() . '-' . Smart::uuid_10_seq();
        //--
        if ((string) $err == '') {
            $the_test = 'Data: Archive / Unarchive';
            $tests[] = $the_test;
            if (SmartUtils::data_unarchive(SmartUtils::data_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'Cache: Archive / Unarchive';
            $tests[] = $the_test;
            if (SmartUtils::cache_variable_unarchive(SmartUtils::cache_variable_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']';
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            $the_test = 'IDN: Domain Punycode Encode UTF-8 to ISO';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->encode($idn_domain_unicode) != (string) $idn_domain_iso) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_unicode . ' -> ' . $idn_domain_iso . ']';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'IDN: Domain Punycode Decode ISO to UTF-8';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->decode($idn_domain_iso) != (string) $idn_domain_unicode) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_iso . ' -> ' . $idn_domain_unicode . ']';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'IDN: Email Punycode Encode UTF-8 to ISO';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->encode($idn_email_unicode) != (string) $idn_email_iso) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_unicode . ' -> ' . $idn_email_iso . ']';
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'IDN: Email Punycode Decode ISO to UTF-8';
            $tests[] = $the_test;
            if ((string) (new SmartPunycode())->decode($idn_email_iso) != (string) $idn_email_unicode) {
                $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_iso . ' -> ' . $idn_email_unicode . ']';
            }
            //end if
        }
        //end if
        //--
        //-- regex positive tests
        $arr_regex = ['number-integer' => [0, '75', '-101'], 'number-decimal' => [0, '0.0', '0.1', '75', '75.0', '75.1', '-555', '-555.0', '-555.1'], 'number-list-integer' => '1;2;30', 'number-list-decimal' => '1.0;2;30.44', 'url' => ['https://192.168.1.0', 'http://localhost', 'https://www.dom.ext', 'http://dom.ext/path?a=b&c=d%20#s'], 'domain' => ['domain.com', 'sdom.domain.org'], 'email' => ['root@localhost', '*****@*****.**', '*****@*****.**'], 'fax' => ['~+99-(0)999-123.456.78~'], 'macaddr' => ['00:0A:95:9d:68:16', '00-0a-95-9D-68-16'], 'ipv4' => ['192.168.0.1', '169.254.1.0', '1.0.0.1'], 'ipv6' => ['::1', '0000:0000:0000:0000:0000:0000:0000:0001', '2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:dB8::2:1', '2001:db8::1', '3731:54:65fe:2::a7']];
        //--
        foreach ((array) $arr_regex as $key => $val) {
            //--
            if (is_array($val)) {
                for ($i = 0; $i < Smart::array_size($val); $i++) {
                    $the_test = 'Regex Validate Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_string($val[$i], $key) !== true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                        break;
                    }
                    //end if
                    if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) {
                        $the_test = 'Regex Validate Numeric Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                        $tests[] = $the_test;
                        if (SmartValidator::validate_numeric_integer_or_decimal_values($val[$i], $key) !== true) {
                            $err = 'ERROR: ' . $the_test . ' FAILED ...';
                            break;
                        }
                        //end if
                    }
                    //end if
                }
                //end for
            } else {
                $the_test = 'Regex Validate Positive: ' . $key . ' [' . $val . ']';
                $tests[] = $the_test;
                if (SmartValidator::validate_string($val, $key) !== true) {
                    $err = 'ERROR: ' . $the_test . ' FAILED ...';
                }
                //end if
                if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) {
                    $the_test = 'Regex Validate Numeric Positive: ' . $key . ' [' . $val . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_numeric_integer_or_decimal_values($val, $key) !== true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                    }
                    //end if
                }
                //end if
            }
            //end if else
            //--
            if ((string) $err != '') {
                break;
            }
            //end if
            //--
        }
        //end foreach
        //--
        //-- regex negative tests
        $arr_regex = ['number-integer' => ['', '.', 'a9', '7B', '-9 ', ' -7'], 'number-decimal' => ['', '.0', '.1', '-.10', ' -7', '-9.0 '], 'number-list-integer' => '1;2.3;30', 'number-list-decimal' => '1.0;2;30.44a', 'url' => ['http:://192.168.1.0', 'https://local host', 'http:/www.dom.ext', 'https:dom.ext/path?a=b&c=d%20#s'], 'domain' => ['doMain.com', 's dom.domain.org', '.dom.ext', 'dom..ext', 'localhost', 'loc', 'dom.ext.'], 'email' => ['rooT@localhost', 'root@local host.loc', 'sometest-name.extra@do_m.ext'], 'fax' => ['~ +99-(0)999-123.456.78 ~'], 'macaddr' => ['00:0A:95:9z:68:16', '00-0Z-95-9D-68-16'], 'ipv4' => ['192.168.0.', '169..1.0', '1.0.1'], 'ipv6' => ['::x', '00z0:0000:0000:0000:0000:0000:0000:0001', '2001:0dx8:0000:0000:0000:ff00:0042:8329', '2001:WB8::2:1', '2001:@db8::1', '3731:54:65Qe:2::a7']];
        //--
        foreach ((array) $arr_regex as $key => $val) {
            //--
            if (is_array($val)) {
                for ($i = 0; $i < Smart::array_size($val); $i++) {
                    $the_test = 'Regex Validate Negative (#' . $i . '): ' . $key . ' [' . $val[$i] . ']';
                    $tests[] = $the_test;
                    if (SmartValidator::validate_string($val[$i], $key) === true) {
                        $err = 'ERROR: ' . $the_test . ' FAILED ...';
                        break;
                    }
                    //end if
                }
                //end for
            } else {
                $the_test = 'Regex Validate Negative: ' . $key . ' [' . $val . ']';
                $tests[] = $the_test;
                if (SmartValidator::validate_string($val, $key) === true) {
                    $err = 'ERROR: ' . $the_test . ' FAILED ...';
                }
                //end if
            }
            //end if else
            //--
            if ((string) $err != '') {
                break;
            }
            //end if
            //--
        }
        //end foreach
        //--
        //--
        $endtest = '##### END TESTS ... #####';
        //--
        //--
        if ((string) $err == '') {
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_completed.png';
            $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; グッド ... パーフェクト</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Unicode String <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $endtest)) . '</span>');
        } else {
            $img_sign = 'lib/core/img/sign_error.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; エラーが発生しました ...</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Unicode String Tests.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
        }
        //end if else
        //--
        //--
        $html = <<<HTML
<h1>SmartFramework Unicode Strings Tests: DONE ...</h1>
<script type="text/javascript">
\tSmartJS_BrowserUtils.alert_Dialog(
\t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>',
\t\t'',
\t\t'Unicode String Test Suite for SmartFramework: PHP',
\t\t'725',
\t\t'425'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
 /**
  * Replace FAX numbers in a text string with HTML links <a href="(faxNum)" target="{target}">[faxNum]</a>
  *
  * @param 	STRING 	$string 			:: The text string to be processed
  * @param 	STRING 	$yaction			:: Action to append the fax-num link to ; Default is: 'efax:' but can be for example: 'script.php?action=fax&number='
  * @param 	STRING	$ytarget			:: URL target ; default is '_blank' ; can be: '_self' or a specific window name: 'myWindow' ...
  *
  * @return 	STRING						:: The HTML processed text with FAX numbers replaced with real tags as links
  */
 public static function text_faxnums($string, $yaction = 'efax:', $ytarget = '_blank')
 {
     $string = (string) $string;
     $expr = SmartValidator::regex_stringvalidation_expression('fax', 'partial');
     $regex = $expr . 'iu';
     //insensitive, with /u modifier for unicode strings
     $string = preg_replace_callback($regex, function ($matches) use($yaction, $ytarget) {
         return '<a title="@eFax@" id="url_recognition" href="' . Smart::escape_html($yaction . rawurlencode(trim($matches[2]))) . '" target="' . $ytarget . '">' . Smart::escape_html(SmartParser::text_endpoints($matches[2], 75)) . '</a>';
     }, $string);
     return (string) $string;
 }
示例#6
0
 private static function _iplist_get_last_address($ip)
 {
     //--
     if ((string) $ip == '') {
         return '';
     }
     //end if
     //--
     if (strpos((string) $ip, ',') !== false) {
         // if we detect many IPs in a header
         //--
         $arr = explode(',', (string) $ip);
         $ip = '';
         // we clear it
         //--
         $imax = Smart::array_size($arr);
         if ($imax > 1) {
             //--
             for ($i = $imax; $i > 0; $i--) {
                 // loop backward
                 //--
                 $tmp_ip = (string) SmartValidator::validate_filter_ip_address(trim((string) $arr[$i]));
                 // this returns empty if no valid IP
                 //--
                 if (strlen($tmp_ip) >= 7 and strlen($tmp_ip) <= 39) {
                     // valid IP must be in this range
                     $ip = (string) $tmp_ip;
                     break;
                 }
                 //end if
                 //--
             }
             //end for
             //--
         }
         //end if
         //--
     } else {
         //--
         $ip = (string) SmartValidator::validate_filter_ip_address((string) $ip);
         //--
     }
     //end if
     //--
     return (string) $ip;
     //--
 }
示例#7
0
 private function FixXmlRoot($xml_str)
 {
     //--
     $xml_str = (string) trim((string) preg_replace('#<\\?xml (.*?)>#si', '', (string) $xml_str));
     // remove the xml markup tag
     //$xml_str = str_replace(['<'.'?', '?'.'>'], ['<!-- ', ' -->'], $xml_str); // comment out any markup tags
     //--
     if (!SmartValidator::validate_html_or_xml_code($xml_str)) {
         // fix parser bug if empty data passed
         //--
         Smart::log_warning('SmartXmlParser / GetXMLTree: Invalid XML Detected (555)' . "\n" . 'Encoding: ' . $this->encoding . ' // Xml-String:' . "\n" . $xml_str . "\n" . '#END');
         $xml_str = '<' . '?' . 'xml version="1.0" encoding="' . $this->encoding . '"' . '?' . '>' . "\n" . '<smart_framework_xml_data_parser_fix_tag>' . "\n" . '</smart_framework_xml_data_parser_fix_tag>';
         //--
     } else {
         //--
         $xml_str = '<' . '?' . 'xml version="1.0" encoding="' . $this->encoding . '"' . '?' . '>' . "\n" . '<smart_framework_xml_data_parser_fix_tag>' . "\n" . trim($xml_str) . "\n" . '</smart_framework_xml_data_parser_fix_tag>';
         //--
     }
     //end if
     //--
     return (string) $xml_str;
     //--
 }
 /**
  * Check eMail Address
  * [PUBLIC]
  *
  * @param STRING $email					:: eMail Address
  * @param ENUM $ycheckdomain			:: 'no' = only validate if email address is in the form of text@texte.xt | 'yes' = check email with MX + SMTP validation
  * @param STRING $helo					:: SMTP HELO (if check MX + Domain will be used, cannot be empty)
  * @param NUMBER $y_smtp_port			:: SMTP Port (normal is '25')
  * @return STRING
  */
 public static function check_email_address($email, $ycheckdomain = 'no', $helo = '', $y_smtp_port = '25')
 {
     //--
     $out = 'notok';
     $msg = '';
     //--
     //--
     $email = (string) trim((string) $email);
     //--
     //--
     $regex = SmartValidator::regex_stringvalidation_expression('email') . 'i';
     // insensitive, without /u modifier as it does not decodes to punnycode and must contain only ISO-8859-1 charset
     //--
     if ((string) $email != '') {
         if (!preg_match((string) $regex, (string) $email)) {
             // check if address is valid (match pattern '*****@*****.**')
             $msg .= 'The e-mail address does NOT match the pattern \'email@domain.tld\'' . "\n";
         } else {
             $out = 'ok';
         }
         //end if else
     } else {
         $msg .= 'The e-mail address is empty !' . "\n";
     }
     //end if else
     //--
     //--
     if ((string) $out == 'ok') {
         //--
         if ((string) $ycheckdomain == 'yes') {
             //--
             $out = 'notok';
             // reset
             //--
             if (strlen($helo) <= 0) {
                 $helo = '127.0.0.1';
             }
             //end if else
             //--
             $msg .= "\n" . 'Now we CHECK if this is a real email address ...' . "\n\n";
             $chk = self::validate_mx_email_address($helo, $email, $y_smtp_port);
             //--
             if ((string) $chk['status'] == 'ok') {
                 $out = 'ok';
             }
             //end if
             //--
             $msg .= $chk['message'] . "\n";
             //--
             if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') {
                 $msg = '';
                 // hide the message if no debug
             }
             //end if
             //--
         }
         //end if
         //--
     }
     //end if
     //--
     //--
     return array('status' => $out, 'message' => $msg);
     //--
 }