/**
  * Function: JS Draw SList
  *
  */
 public static function js_draw_sel_list($y_var_name, $y_options_arr, $y_size = '8')
 {
     //--
     $tmp_init_slist = "\n";
     //--
     $tmp_suffix = '_' . sha1('The-SList-JSComponent:@#' . $y_var_name);
     //--
     $options_html = '';
     //--
     if (is_array($y_options_arr)) {
         foreach ($y_options_arr as $key => $val) {
             // warehouses as arr[]=id
             if (strlen($key) > 0 and strlen($val) > 0) {
                 $options_html .= '<option value="' . \Smart::escape_html((string) $key) . '">' . \Smart::escape_html((string) $val) . '</option>';
             }
             //end if
         }
         //end foreach
     }
     //end if
     //--
     $translator_core_js_messages = \SmartTextTranslations::getTranslator('@core', 'js_messages');
     //--
     $tmp_slist = \SmartMarkersTemplating::render_file_template('modules/mod-js-components/views/js/jsjsslist/slist.inc.htm', array('SIZE' => (int) $y_size, 'VARIABLE_NAME' => \Smart::escape_html((string) $y_var_name), 'TXT_SELECT' => $translator_core_js_messages->text('btn_select'), 'TXT_RESET' => $translator_core_js_messages->text('btn_reset'), 'SLIST_SRC' => 'smartframeworkComponents_SList_SRC' . $tmp_suffix, 'SLIST_SEL' => 'smartframeworkComponents_SList_SEL' . $tmp_suffix, 'SLIST_VAL' => 'smartframeworkComponents_SList_VAL' . $tmp_suffix, 'OPTIONS' => $options_html), 'yes');
     //--
     return (string) $tmp_init_slist . $tmp_slist;
     //--
 }
 public function Run()
 {
     //--
     $title = 'Extended Markers Template Test';
     //--
     $test_switch_arr = ['a', 'b', 'c', 'd'];
     $this->PageViewSetVars(['title' => $title, 'main' => SmartMarkersTemplating::render_file_template($this->ControllerGetParam('module-path') . 'views/templating-test.htm', ['TITLE' => $title, 'TEST-COMPARE' => 'a', 'TESTURL' => 'a"b\'c', 'DATA' => ['This is a sample table', ['id' => 1, 'slug' => 'a', 'name' => 'Letter A', 'is_vowel' => true], ['id' => 2, 'slug' => 'b', 'name' => 'Letter B', 'is_vowel' => false], ['id' => 3, 'slug' => 'c', 'name' => 'Letter C', 'is_vowel' => false], ['id' => 4, 'slug' => 'd', 'name' => 'Letter D', 'is_vowel' => false], ['id' => 5, 'slug' => 'e', 'name' => 'Letter E', 'is_vowel' => true], ['id' => 6, 'slug' => 'f', 'name' => 'Letter F', 'is_vowel' => false], ['id' => 7, 'slug' => 'g', 'name' => 'Letter G', 'is_vowel' => false], ['id' => 8, 'slug' => 'h', 'name' => 'Letter H', 'is_vowel' => false], ['id' => 9, 'slug' => 'i', 'name' => 'Letter I', 'is_vowel' => true], ['id' => 10, 'slug' => 'j', 'name' => 'Letter J', 'is_vowel' => false], ['id' => 11, 'slug' => 'k', 'name' => 'Letter K', 'is_vowel' => false], ['id' => 12, 'slug' => 'l', 'name' => 'Letter L', 'is_vowel' => false], ['id' => 13, 'slug' => 'm', 'name' => 'Letter M', 'is_vowel' => false], ['id' => 14, 'slug' => 'n', 'name' => 'Letter N', 'is_vowel' => false], ['id' => 15, 'slug' => 'o', 'name' => 'Letter O', 'is_vowel' => true]], 'DAT2' => ['key1' => ['id' => 'val1', 'name' => 'Value 1'], 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4'], 'TEST1' => 3, 'TEST2' => Smart::random_number(2, 3), 'TEST3' => 3, 'STATUS' => (string) $test_switch_arr[Smart::random_number(0, 3)]])]);
     //--
 }
 public static function test_sqlite3_json_flexigrid($flexigrid_page, $flexigrid_resperpage, $flexigrid_sortfld, $flexigrid_sortdir, $flexigrid_srcby, $flexigrid_search, $flexigrid_xsrcby, $flexigrid_xsearch)
 {
     //-- ensure the correct types
     $flexigrid_page = (int) $flexigrid_page;
     $flexigrid_resperpage = (int) $flexigrid_resperpage;
     $flexigrid_srcby = (string) $flexigrid_srcby;
     $flexigrid_search = (string) $flexigrid_search;
     $flexigrid_xsrcby = (string) $flexigrid_xsrcby;
     $flexigrid_xsearch = (string) $flexigrid_xsearch;
     $flexigrid_sortfld = (string) $flexigrid_sortfld;
     $flexigrid_sortdir = (string) $flexigrid_sortdir;
     //--
     //-- db init
     $model = new SmartTestSQLite3Model();
     if (!is_object($model)) {
         return Smart::json_encode(array('error' => 'Flexigrid JSON DB Object Failed to initialize'));
     }
     //end if
     //--
     //-- where management (we have 2 situations: 1st is normal search ; 2nd is search by starting letter)
     if ((string) $flexigrid_srcby != '' and (string) $flexigrid_search != '') {
         //-- normal search (by field and value)
         $where_field = $flexigrid_srcby;
         $where_value = $flexigrid_search;
         $where_mode = '';
         //--
     } else {
         //-- search by starting letters
         $where_field = $flexigrid_xsrcby;
         $where_value = $flexigrid_xsearch;
         $where_mode = 'letters';
         //--
     }
     //end if else
     //--
     //-- output data init
     $jsonData = array('page' => $flexigrid_page, 'total' => $model->table_flexigrid_count($where_field, $where_value, $where_mode), 'rows' => array());
     //--
     //-- read data
     $rows = $model->table_flexigrid_read($where_field, $where_value, $where_mode, $flexigrid_sortfld, $flexigrid_sortdir, $flexigrid_resperpage, $flexigrid_page);
     //--
     if (is_array($rows)) {
         foreach ($rows as $row) {
             //--
             $entry = array('id' => 'ID_' . $row['iso'], 'cell' => array('iso' => $row['iso'], 'name' => $row['name'], 'printable_name' => $row['printable_name'], 'iso3' => $row['iso3'], 'numcode' => $row['numcode']));
             //--
             $jsonData['rows'][] = $entry;
             //--
         }
         //end foreach
     }
     //end if
     //--
     //--
     return Smart::json_encode($jsonData);
     //--
 }
 public static function SetVisitorEntropyIDCookie()
 {
     //--
     if (!defined('SMART_FRAMEWORK_VERSION')) {
         die('Smart Runtime // Set Visitor Entropy ID Cookie :: Requires SmartFramework to be loaded ...');
     }
     //end if
     //--
     if (defined('SMART_APP_VISITOR_COOKIE')) {
         die('SetVisitorEntropyIDCookie :: SMART_APP_VISITOR_COOKIE must not be re-defined ...');
     }
     //end if
     //--
     $cookie = '';
     //-- {{{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))) {
                 //--
                 $cookie = (string) trim(strtolower(SmartFrameworkSecurity::FilterUnsafeString((string) $_COOKIE[(string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME])));
                 if ((string) $cookie == '' or strlen((string) $cookie) != 40 or !preg_match('/^[a-f0-9]+$/', (string) $cookie)) {
                     $entropy = (string) sha1((string) Smart::unique_entropy('uuid-cookie'));
                     // generate a random unique key ; cookie was not yet set or is invalid
                     if (defined('SMART_FRAMEWORK_UNIQUE_ID_COOKIE_DOMAIN') and (string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_DOMAIN != '') {
                         @setcookie((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME, (string) $entropy, 0, '/', (string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_DOMAIN);
                         // set it using domain
                     } else {
                         @setcookie((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME, (string) $entropy, 0, '/');
                         // set it
                     }
                     //end if else
                     $cookie = (string) $entropy;
                 }
                 //end if
                 //--
             }
             //end if
         }
         //end if
     }
     //end if
     //-- #end# sync
     define('SMART_APP_VISITOR_COOKIE', (string) $cookie);
     // empty or cookie ID
     //--
 }
 public static function encode_var_post($varname, $value)
 {
     //--
     $varname = (string) trim((string) $varname);
     //--
     if ((string) $varname == '') {
         return '';
     }
     //end if
     //--
     $out = '';
     //--
     if (is_array($value)) {
         $arrtype = Smart::array_type_test($value);
         // 0: not an array ; 1: non-associative ; 2:associative
         if ($arrtype === 1) {
             // 1: non-associative
             for ($i = 0; $i < Smart::array_size($value); $i++) {
                 $out .= urlencode($varname) . '[]=' . rawurlencode($value[$i]) . '&';
             }
             //end foreach
         } else {
             // 2: associative
             foreach ($value as $key => $val) {
                 $out .= urlencode($varname) . '[' . rawurlencode($key) . ']=' . rawurlencode($val) . '&';
             }
             //end foreach
         }
         //end if else
     } else {
         $out = urlencode($varname) . '=' . rawurlencode($value) . '&';
     }
     //end if else
     //--
     return (string) $out;
     //--
 }
 /**
  * Function: Get BarCode as PNG
  *
  * @access 		private
  * @internal
  *
  */
 public static function getBarcodePNG($barcode_arr, $z = 3, $color = array(0, 0, 0))
 {
     //--
     if (!is_array($color)) {
         $color = (string) $color;
         $color = trim(str_replace('#', '', $color));
         $color = array(hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
     }
     //end if
     //--
     if (!is_array($barcode_arr)) {
         //--
         Smart::log_notice('Invalid Barcode2D PNG Data: Not Array !');
         //--
         $width = 125;
         $height = 10;
         //--
         $png = @imagecreate($width, $height);
         $bgcol = @imagecolorallocate($png, 250, 250, 250);
         $fgcol = @imagecolorallocate($png, 255, 0, 0);
         @imagestring($png, 1, 1, 1, "[ INVALID BARCODE (1) ]", $fgcol);
         //--
     } else {
         //--
         $z = self::conformZ($z);
         //-- calculate image size
         $the_width = $barcode_arr['num_cols'] * $z;
         $the_height = $barcode_arr['num_rows'] * $z;
         //--
         $png = null;
         if ($the_width > 0 and $the_height > 0) {
             $png = @imagecreate($the_width, $the_height);
         }
         //end if
         //--
         if (!$png) {
             //--
             Smart::log_notice('Invalid Barcode2D PNG Dimensions: ' . "\n" . 'Code=' . $barcode_arr['code'] . "\n" . 'Cols=' . $barcode_arr['num_cols'] . ' ; Rows=' . $barcode_arr['num_rows']);
             //--
             $width = 125;
             $height = 10;
             //--
             $png = @imagecreate($width, $height);
             $bgcol = @imagecolorallocate($png, 250, 250, 250);
             $fgcol = @imagecolorallocate($png, 255, 0, 0);
             @imagestring($png, 1, 1, 1, "[ INVALID BARCODE (2) ]", $fgcol);
             //--
         } else {
             //--
             $bgcol = @imagecolorallocate($png, 255, 255, 255);
             $fgcol = @imagecolorallocate($png, $color[0], $color[1], $color[2]);
             //-- print barcode elements
             $y = 0;
             //-- for each row
             for ($r = 0; $r < $barcode_arr['num_rows']; ++$r) {
                 //--
                 $x = 0;
                 //-- for each column
                 for ($c = 0; $c < $barcode_arr['num_cols']; ++$c) {
                     //--
                     if ($barcode_arr['bcode'][$r][$c] == 1) {
                         //-- draw a single barcode cell
                         @imagefilledrectangle($png, $x, $y, $x + $z - 1, $y + $z - 1, $fgcol);
                         //--
                     }
                     //end if
                     //--
                     $x += $z;
                     //--
                 }
                 //end for
                 //--
                 $y += $z;
                 //--
             }
             //end for
             //--
         }
         //end if else
         //--
     }
     //end if else
     //--
     ob_start();
     @imagepng($png);
     $imagedata = ob_get_clean();
     @imagedestroy($png);
     //--
     return $imagedata;
     //--
 }
Example #7
0
 public static function get_connection($dsn, $db_user, $db_pass)
 {
     if (self::$connected == true) {
         return self::$connection;
     }
     try {
         self::$connection = new PDO($dsn, $db_user, $db_pass, array(PDO::ATTR_PERSISTENT => false));
     } catch (PDOException $e) {
         self::freichat_debug("unable to connect to database. Error : " . $e->getMessage());
         //die(); //do not die
         return false;
         //instead return false
     }
     self::freichat_debug("connected to database successfully");
     self::$connection->exec("SET CHARACTER SET utf8");
     self::$connection->exec("SET NAMES utf8");
     self::$connected = true;
     return self::$connection;
 }
 private function _boundarySplit($input, $boundary)
 {
     //--
     $tmp = (array) explode('--' . $boundary, (string) $input);
     //--
     for ($i = 1; $i < Smart::array_size($tmp); $i++) {
         $parts[] = $tmp[$i];
     }
     //end for
     //--
     return $parts;
     //--
 }
 private static function print_log_modules($title, $modules_log)
 {
     //--
     $log = '';
     //--
     $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_head"><font size="4"><b>' . Smart::escape_html($title) . ' :: MODULE Log</b></font></div>';
     //--
     $max = Smart::array_size($modules_log);
     if (is_array($modules_log) and $max > 0) {
         //--
         $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;">Total Entries: <b>' . Smart::escape_html($max) . '</b></div>';
         //--
         for ($i = 0; $i < $max; $i++) {
             //--
             $tmp_arr = (array) $modules_log[$i];
             //--
             $log .= '<div class="smartframework_debugbar_inforow" style="font-size:11px; color:#000000;">';
             $log .= '<b>' . Smart::escape_html((string) $tmp_arr['title']) . '</b><br>';
             $log .= '<pre style="font-size:11px; color:#000000;">' . Smart::escape_html(str_replace(array("\r\n", "\r", "\t"), array("\n", "\n", ' '), trim((string) $tmp_arr['data']))) . '</pre>';
             $log .= '</div>';
             //--
         }
         //end for
         //--
     } else {
         //--
         $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_warn" style="width: 100px; text-align: center;"><font size="2"><b>N/A</b></font></div>';
         //--
     }
     //end if
     //--
     return $log;
     //--
 }
 /**
  * Displays the MySQL Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL MySQLi ERROR happens or when a Query Syntax is malformed)
  * PRIVATE
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private static function error($y_connection_id, $y_area, $y_error_message, $y_query, $y_params_or_title, $y_warning = '')
 {
     //--
     $err_log = $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Params / Title:' . "\n" . print_r($y_params_or_title, 1) . "\n" . '*** Query:' . "\n" . $y_query;
     //--
     if (defined('SMART_SOFTWARE_SQLDB_FATAL_ERR') and SMART_SOFTWARE_SQLDB_FATAL_ERR === false) {
         Smart::log_warning('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: WARNING :: ' . $err_log);
         throw new Exception('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: EXCEPTION :: ' . $y_area . "\n" . $y_error_message);
         return;
     }
     //end if
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         if (is_array($y_params_or_title)) {
             $the_params = '*** Params ***' . "\n" . print_r($y_params_or_title, 1);
         } elseif ((string) $y_params_or_title != '') {
             $the_params = '[ Reference Title ]: ' . $y_params_or_title;
         } else {
             $the_params = '- No Params or Reference Title -';
         }
         //end if
         $the_query_info = (string) trim((string) $y_query);
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('MySQLi Client', 'MySQL', 'SQL/DB', 'Server', 'modules/smart-extra-libs/img/mysql_logo_trans.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     Smart::raise_error('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: ERROR :: ' . $err_log, $out);
     die('');
     // just in case
     //--
 }
Example #11
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;
     //--
 }
Example #12
0
 public function Run()
 {
     //-- sample page variable from Request (GET/POST)
     $some_var_from_request = $this->RequestVarGet('extra_text', 'default', 'string');
     //--
     //--
     $module_area = $this->ControllerGetParam('module-area');
     $the_lang = (string) $this->ConfigParamGet('regional.language-id');
     $the_xlang = (string) $this->ConfigParamGet('regional.language-id');
     // repeat this to check if caching works
     //--
     if ($this->IfDebug()) {
         $this->SetDebugData('Module Area', $module_area);
         $this->SetDebugData('Module Path', $this->ControllerGetParam('module-path'));
         $this->SetDebugData('Module Name', $this->ControllerGetParam('module-name'));
         $this->SetDebugData('URL Script', $this->ControllerGetParam('url-script'));
         $this->SetDebugData('URL Path', $this->ControllerGetParam('url-path'));
         $this->SetDebugData('URL Address', $this->ControllerGetParam('url-addr'));
         $this->SetDebugData('URL Page', $this->ControllerGetParam('url-page'));
         $this->SetDebugData('Config / Language ID', $the_lang);
     }
     //end if
     //--
     //--
     if ($this->PageCacheisActive()) {
         //-- because the Request can modify the content, also the unique key must take in account variables that will vary the page config or page content vars
         $the_page_cache_key = 'samples-toolkit-' . $module_area . '__' . SmartHashCrypto::sha384((string) $some_var_from_request);
         //--
     }
     //end if
     //--
     //--
     if ($this->PageCacheisActive()) {
         //--
         $test_cache = $this->PageGetFromCache('cached-samples', $the_page_cache_key);
         //--
         if (Smart::array_size($test_cache) > 0) {
             if (is_array($test_cache['configs']) && is_array($test_cache['vars'])) {
                 // if valid cache (test as we exported both arrays ... so they must be the 2 arrays again)
                 $this->PageViewSetCfgs((array) $test_cache['configs']);
                 $this->PageViewSetVars((array) $test_cache['vars']);
                 $this->PageViewAppendVar('main', "\n" . '<!-- Redis Cached Content Key: ' . Smart::escape_html($the_page_cache_key) . ' -->' . "\n");
                 // add a markup to the HTML to know was served from cache ...
                 if ($this->IfDebug()) {
                     $this->SetDebugData('Page Cache Info', 'Serving page from Persistent Cache: Redis (override PHP Execution). Page key is: ' . $the_page_cache_key);
                 }
                 // end if
                 return;
                 // the page was served from Cache (stop here)
             }
             //end if
         }
         //end if
         //--
     }
     //end if
     //--
     //=== if no cached, execute the code below ...
     //--
     $this->PageViewSetCfg('template-path', 'default');
     // set the template path (must be inside etc/templates/)
     $this->PageViewSetCfg('template-file', 'template.htm');
     // set the template file
     //--
     //--
     $fcontent = SmartFileSystem::staticread('lib/framework/css/ux-toolkit-samples.html');
     $arr_data = explode('<body>', $fcontent);
     $fcontent = (string) $arr_data[1];
     $arr_data = explode('</body>', $fcontent);
     $fcontent = (string) $arr_data[0];
     //--
     //-- building a semantic URL
     $url_test_unit = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.testunit', 'tab' => 0));
     // will generate: index.php?page=samples.testunit OR admin.php?page=samples.testunit
     $url_test_unit = Smart::url_make_semantic($url_test_unit);
     // convert the above to a pretty URL as: ?/page/samples.testunit (in this case index.php is ignored) OR admin.php?/page/samples.testunit
     //--
     //-- building a regular URL
     $url_benchmark = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.benchmark.html'));
     $url_benchmark = Smart::url_make_semantic($url_benchmark);
     //--
     //--
     $translator_core = SmartTextTranslations::getTranslator('@core', 'messages');
     //--
     $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples');
     $txt_hello_world = $translator_mod_samples->text('hello-world');
     unset($translator_mod_samples);
     // this is just an internal test, normally the translator should not be unset ...
     $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples');
     $txt_this_is_sf = $translator_mod_samples->text('this-is-smart-framework');
     //--
     //--
     $this->PageViewSetVars(['title' => 'Toolkit Samples', 'main' => '<h1>This text should not be displayed, it was RESET !!!</h1>']);
     $this->PageViewResetVar('main');
     // test reset
     $this->PageViewSetVar('main', SmartMarkersTemplating::render_template('<h1>' . '[####TXT-HELLO-WORLD####]</h1><div align="right"><b>[####DATE-TIME|html####] [[####TXT-OK####]]' . "\n" . '</b></div><br><a class="ux-button ux-button-special" href="http://sourceforge.net/projects/warp-cms/files/smart-framework/" target="_blank"><i class="fa fa-cloud-download"></i> &nbsp; Download Smart.Framework (latest stable releases)</a> &nbsp;&nbsp;&nbsp; <a class="ux-button ux-button-highlight" href="http://demo.unix-world.org/smart-framework.docs/" target="_blank"><i class="fa fa-book"></i> &nbsp; Documentation for the Smart.Framework</a><br>' . "\n" . '<br><a class="ux-button ux-button-primary" href="[####URL-TESTUNIT|html####]"><i class="fa fa-object-group"></i> &nbsp; Go to the Smart.Framework PHP/Javascript Test &amp; Demo Suite</a> &nbsp;&nbsp;&nbsp; <a class="ux-button ux-button-secondary" href="[####URL-BENCHMARK|html####]"><i class="fa fa-line-chart"></i> &nbsp; Benchmark URL for Smart.Framework</a><br><br>', ['DATE-TIME' => date('Y-m-d H:i:s O'), 'TXT-OK' => $translator_core->text('ok'), 'TXT-HELLO-WORLD' => '<span title="LanguageID: ' . Smart::escape_html($the_xlang) . '" style="cursor:help;">' . '[' . Smart::escape_html($the_lang) . ']' . '</span>' . ' ' . $txt_hello_world . ', ' . $txt_this_is_sf . ' - a modern PHP / Javascript framework featuring MVC + Middlewares', 'URL-TESTUNIT' => $url_test_unit, 'URL-BENCHMARK' => $url_benchmark]));
     $this->PageViewAppendVar('main', '<hr><div style="color:#DDDDDD">' . Smart::escape_html('Unicode@String :: Smart スマート // Cloud Application Platform クラウドアプリケーションプラットフォーム :: áâãäåāăąÁÂÃÄÅĀĂĄ ćĉčçĆĈČÇ ďĎ èéêëēĕėěęÈÉÊËĒĔĖĚĘ ĝģĜĢ ĥħĤĦ ìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮ ijĵIJĴ ķĶ ĺļľłĹĻĽŁ ñńņňÑŃŅŇ óôõöōŏőøœÒÓÔÕÖŌŎŐØŒ ŕŗřŔŖŘ șşšśŝßȘŞŠŚŜ țţťȚŢŤ ùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲ ŵŴ ẏỳŷÿýẎỲŶŸÝ źżžŹŻŽ') . '</div><hr><div align="right">[' . Smart::escape_html($some_var_from_request) . ']</div>');
     $this->PageViewAppendVar('main', trim($fcontent));
     //--
     //== cache page (if redis - persistent cache is set in config)
     //-- if Redis is active this will cache the page for 1 hour ...
     if ($this->PageCacheisActive()) {
         //--
         $this->PageSetInCache('cached-samples', $the_page_cache_key, array('configs' => $this->PageViewGetCfgs(), 'vars' => $this->PageViewGetVars()), 3600);
         //--
         if ($this->IfDebug()) {
             $this->SetDebugData('Page Cache Info', 'Setting page in Persistent Cache: Redis (after PHP Execution). Page key is: ' . $the_page_cache_key);
         }
         //end if
         //--
     } else {
         //--
         if ($this->IfDebug()) {
             $this->SetDebugData('Page Cache Info', 'Persistent Cache (Redis) is not active. Serving Page from PHP Execution.');
         }
         //end if
         //--
     }
     //end if else
     //--
 }
 /**
  * Generate the ODS Document on the fly from an array of data
  *
  * @param STRING $y_table_name					:: The Table Name
  * @param STRING $y_arr_fields					:: Array of Header Fields
  * @param STRING $y_arr_data 					:: Array of Data
  *
  * @returns STRING 								:: The ODS Document Contents
  *
  */
 public function ODS_SpreadSheet($y_table_name, $y_arr_fields, $y_arr_data, $y_arr_process = array(), $y_arr_totals = array(), $y_arr_finals = array(), $y_arr_widths = array(), $y_arr_highlights = array())
 {
     // font-weight="bold"
     // fo:font-style="italic"
     // style:text-underline-type="single"
     //-- header
     $header = '' . '<?xml version="1.0" encoding="UTF-8"?' . '>' . "\n" . '<office:document-content ' . $this->open_document_ns . 'office:version="1.0">' . "\n" . $this->open_document_styles . '<office:body>' . "\n" . '<office:spreadsheet>' . "\n";
     //--
     //-- footer
     $footer = "\n" . '</office:spreadsheet>' . "\n" . '</office:body>' . "\n" . '</office:document-content>';
     //--
     //-- data
     $data = '';
     $data .= '<table:table table:style-name="ta1" table:print="true" table:name="' . Smart::escape_html($y_table_name) . '">' . "\n";
     //--
     //-- table headings
     $num_cols = Smart::array_size($y_arr_fields);
     $num_data = Smart::array_size($y_arr_data);
     //--
     $data .= '<table:table-row table:style-name="ro1">' . "\n";
     //--
     for ($i = 0; $i < $num_cols; $i++) {
         //--
         $data .= '<table:table-cell table:style-name="he1" office:value-type="string">';
         $data .= '<text:p>' . Smart::escape_html($y_arr_fields[$i]) . '</text:p>';
         $data .= '</table:table-cell>' . "\n";
         //--
     }
     //end for
     //--
     $data .= '</table:table-row>' . "\n";
     //--
     for ($n = 0; $n < $num_data; $n++) {
         //--
         $data .= '<table:table-row table:style-name="ro1">' . "\n";
         //--
         for ($i = 0; $i < $num_cols; $i++) {
             //--
             $kk = $i + $n;
             //--
             if ($i % $num_cols == 0 or $i % $num_cols == $num_cols - 1) {
                 $tmp_style = 'ce1';
                 // highlight first and last column
             } elseif ($i % 2) {
                 $tmp_style = 'ce3';
             } else {
                 $tmp_style = 'ce2';
             }
             //end if else
             //--
             if ((string) $y_arr_process[$i] == 'number' or (string) $y_arr_process[$i] == 'decimal2' or (string) $y_arr_process[$i] == 'decimal4') {
                 //--
                 if ((string) $y_arr_process[$i] == 'decimal2') {
                     $y_arr_data[$kk] = (string) Smart::format_number_dec($y_arr_data[$kk], 2, '.', '');
                 } elseif ((string) $y_arr_process[$i] == 'decimal4') {
                     $y_arr_data[$kk] = (string) Smart::format_number_dec($y_arr_data[$kk], 4, '.', '');
                 } else {
                     $y_arr_data[$kk] = (string) $y_arr_data[$kk];
                 }
                 //end if
                 //--
                 //$data .= '<table:table-cell table:style-name="'.$tmp_style.'" office:value-type="float" office:value="'.Smart::escape_html($y_arr_data[$kk]).'">';
                 $data .= '<table:table-cell table:style-name="' . $tmp_style . '" office:value-type="string">';
                 // preserve number as they are, force type string !!!
                 $data .= '<text:p>' . Smart::escape_html($y_arr_data[$kk]) . '</text:p>';
                 $data .= '</table:table-cell>' . "\n";
                 //--
             } else {
                 //--
                 $data .= '<table:table-cell table:style-name="' . $tmp_style . '" office:value-type="string">';
                 $data .= '<text:p>' . Smart::escape_html($y_arr_data[$kk]) . '</text:p>';
                 $data .= '</table:table-cell>' . "\n";
                 //--
             }
             //end if else
             //--
         }
         //end for
         //--
         $data .= '</table:table-row>' . "\n";
         //--
         $n += $num_cols - 1;
         // salt
         //--
     }
     //end for
     //--
     //-- totals row
     if (Smart::array_size($y_arr_totals) > 0) {
         //--
         $data .= '<table:table-row table:style-name="ro1">' . "\n";
         //--
         for ($i = 0; $i < $num_cols; $i++) {
             //--
             $data .= '<table:table-cell table:style-name="he2" office:value-type="string">';
             $data .= '<text:p>' . $y_arr_totals[$i] . '</text:p>';
             $data .= '</table:table-cell>' . "\n";
             //--
         }
         //end for
         //--
         $data .= '</table:table-row>' . "\n";
         //--
     }
     //end if
     //--
     //-- final row
     if (Smart::array_size($y_arr_finals) > 0) {
         //--
         $data .= '<table:table-row table:style-name="ro1">' . "\n";
         //--
         for ($i = 0; $i < $num_cols; $i++) {
             //--
             $data .= '<table:table-cell table:style-name="he3" office:value-type="string">';
             $data .= '<text:p>' . $y_arr_finals[$i] . '</text:p>';
             $data .= '</table:table-cell>' . "\n";
             //--
         }
         //end for
         //--
         $data .= '</table:table-row>' . "\n";
         //--
     }
     //end if
     //--
     //--
     $data .= '</table:table>' . "\n";
     //--
     //--
     return (string) $this->OpenDocument_Template((string) $this->mime_ods, $header . "\n" . $data . "\n" . $footer);
     //--
 }
 public static function getTranslationsFromSource($the_lang, $y_area, $y_subarea)
 {
     //--
     if (substr((string) $y_area, 0, 1) == '@') {
         if ((string) $the_lang == 'en') {
             $fdb_dir = 'lib/app/translations/';
         } else {
             // default is: modules/app/translations/
             $fdb_dir = (string) SMART_FRAMEWORK_LANGUAGES_CACHE_DIR;
         }
         //end if else
         $fdb_template = strtolower($y_area . '/' . $y_subarea . '-' . $the_lang);
     } else {
         // $y_area can be: apps, mod-something, ...
         $fdb_dir = (string) Smart::safe_pathname('modules/' . $y_area . '/translations/');
         $fdb_template = strtolower($y_subarea . '-' . $the_lang);
     }
     //end if else
     //--
     $fdb_file = (string) $fdb_dir . $fdb_template . '.yaml';
     SmartFileSysUtils::raise_error_if_unsafe_path($fdb_file);
     //--
     if (!is_dir($fdb_dir)) {
         Smart::raise_error('Invalid Language Dir: ' . $fdb_dir . ' :: for: ' . $y_area . '@' . $y_subarea, 'Invalid Language Dir for: ' . $y_area . '@' . $y_subarea);
         return array();
     }
     //end if
     //--
     if (!is_file($fdb_file)) {
         //--
         Smart::raise_error('Invalid Language File: ' . $fdb_file, 'Invalid Language File: ' . $fdb_template);
         return array();
         //--
     }
     //end if
     //--
     $fcontent = SmartFileSystem::staticread($fdb_file);
     $arr = (new SmartYamlConverter())->parse((string) $fcontent);
     //--
     if (!is_array($arr)) {
         Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template);
         return array();
     }
     //end if
     //--
     if (!is_array($arr['TRANSLATIONS'])) {
         Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template);
         return array();
     }
     //end if
     if (Smart::array_size($arr['TRANSLATIONS'][(string) $y_subarea]) <= 0) {
         Smart::log_warning('Parse Error / TRANSLATIONS.' . $y_subarea . ' :: Language File: ' . $fdb_template);
         return array();
     }
     //end if
     //--
     return (array) $arr['TRANSLATIONS'][(string) $y_subarea];
     //--
 }
    public static function test_fs()
    {
        //--
        if (SMART_FRAMEWORK_TESTUNIT_ALLOW_FS_TESTS !== true) {
            return SmartComponents::operation_notice('Test Unit File System Tests are DISABLED ...');
        }
        //end if
        //--
        //--
        $time = microtime(true);
        //--
        //--
        $err = '';
        $tests = array();
        //--
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            $tests[] = '##### FileSystem OPERATIONS / TESTS - ALL: #####';
        } else {
            $tests[] = '##### FileSystem OPERATIONS / TESTS *** PARTIAL SUPPORT ONLY (BY PLATFORM) ***: #####';
        }
        //end if else
        //--
        //--
        $test_string = '#START#' . "\n" . 'グッド' . "\n" . 'SmartFramework/Test/FileSystem' . "\n" . time() . "\n" . SMART_FRAMEWORK_HTACCESS_NOINDEXING . SMART_FRAMEWORK_HTACCESS_FORBIDDEN . SMART_FRAMEWORK_HTACCESS_NOEXECUTION . "\n" . '#END#';
        $test_str_cksum = SmartHashCrypto::sha512($test_string);
        $long_prefixed = SmartFileSysUtils::prefixed_sha1_path(sha1(time()));
        $short_prefixed = SmartFileSysUtils::prefixed_uuid10_dir(Smart::uuid_10_seq());
        //--
        $the_base_folder = 'tmp/tests/';
        $the_sufx_folder = 'Folder1';
        $the_base_file = 'NORMAL-Write_123_@#.txt';
        //--
        $the_folder = $the_base_folder . $the_sufx_folder . '/';
        $the_copy_folder = $the_base_folder . 'folder2';
        $the_move_folder = $the_base_folder . 'FOLDER3';
        $the_extra_folder = $the_folder . 'extra/';
        $the_file = $the_folder . $the_base_file;
        //--
        $get_folder = SmartFileSysUtils::add_dir_last_slash(SmartFileSysUtils::get_dir_from_path($the_folder));
        $get_file = SmartFileSysUtils::get_file_name_from_path($the_file);
        $get_xfile = SmartFileSysUtils::get_noext_file_name_from_path($the_file);
        $get_ext = SmartFileSysUtils::get_file_extension_from_path($the_file);
        //--
        $the_copy_file = $the_file . '.copy.txt';
        $the_move_file = $the_extra_folder . $the_base_file . '.copy.moved.txt';
        $the_broken_link = $the_extra_folder . 'a-broken-link';
        $the_broken_dir_link = $the_extra_folder . 'a-broken-dir-link';
        $the_good_link = $the_extra_folder . 'a-good-link';
        $the_good_dir_link = $the_extra_folder . 'a-good-dir-link';
        //--
        //--
        $tests[] = 'INITIAL-FOLDER: ' . $get_folder;
        $tests[] = 'NEW-FOLDER: ' . $the_folder;
        $tests[] = 'NEW-FILE: ' . $the_file;
        //--
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK TEST SAFE PATH NAME: DIR / FILE ...';
            $tests[] = $the_test;
            if ((string) Smart::safe_pathname((string) $get_folder) !== (string) $get_folder or (string) Smart::safe_pathname((string) $the_copy_file) !== (string) $the_copy_file) {
                $err = 'ERROR: SAFE PATH NAME TEST ... FAILED !!!';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK TEST ABSOLUTE / BACKWARD PATHS ...';
            $tests[] = $the_test;
            if (!SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute', 'no') or SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute') or SmartFileSysUtils::check_file_or_dir_name('/this/is/../backward/path')) {
                $err = 'ERROR: CHECK TEST ABSOLUTE / BACKWARD PATHS ... FAILED !!!';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FOLDER FROM PATH ...';
            $tests[] = $the_test;
            if ((string) $get_folder != SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder))) {
                $err = 'ERROR: Path Extraction FAILED: Dir=' . $get_folder . ' ; DirName=' . SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder));
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (1) ...';
            $tests[] = $the_test;
            if ((string) $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file != $the_file) {
                $err = 'ERROR :: Path Extraction FAILED: Re-Composed-File=' . $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file . ' ; File=' . $the_file;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (2) ...';
            $tests[] = $the_test;
            if ((string) $get_file != $get_xfile . '.' . $get_ext) {
                $err = 'ERROR :: Path Extraction FAILED: File=' . $get_file . ' ; XFile=' . $get_xfile . ' ; Ext=' . $get_ext;
            }
            //end if
        }
        //end if
        //--
        SmartFileSysUtils::raise_error_if_unsafe_path($the_folder);
        if ((string) $err == '') {
            $the_test = 'CHECK PATH NAME DIR: check_file_or_dir_name() : ' . $the_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSysUtils::check_file_or_dir_name($the_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        SmartFileSysUtils::raise_error_if_unsafe_path($the_file);
        if ((string) $err == '') {
            $the_test = 'CHECK PATH NAME FILE: check_file_or_dir_name() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSysUtils::check_file_or_dir_name($the_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('');
            $the_test = 'Check Add Dir Last (trailing) Slash: Empty Folder Name';
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('.');
            $the_test = 'Check Add Dir Last (trailing) Slash: Dot Folder Name: ' . $parent_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('./');
            $the_test = 'Check Add Dir Last (trailing) Slash: DotSlash Folder Name: ' . $parent_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_base_folder));
            $the_test = 'Check Parent Dir Name with Add Dir Last (trailing) Slash: ' . $parent_folder . ' # from: ' . $the_base_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != 'tmp/') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            if (is_dir($get_folder)) {
                $the_test = 'DIR DELETE - INIT CLEANUP: dir_delete() + recursive: ' . $get_folder;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_delete($the_base_folder, true);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            } else {
                $tests[] = 'DIR DELETE - INIT CLEANUP: Test Not Run (folder does not exists): ' . $get_folder;
            }
            //end if else
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR CREATE RECURSIVE: dir_recursive_create() : ' . $the_folder . $long_prefixed . $short_prefixed;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_recursive_create($the_folder . $long_prefixed . $short_prefixed);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'DIR CREATE NON-RECURSIVE: dir_create() : extra/ in : ' . $the_extra_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_recursive_create($the_extra_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (1): link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/cache', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE BROKEN FILE LINK (1): delete() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1 || is_link($the_broken_link)) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (2): link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE BROKEN FILE LINK (2): dir_delete() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_delete($the_broken_link);
                if ($result !== 1 || is_link($the_broken_link)) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN DIR LINK: link_create() : as : ' . $the_broken_dir_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/', $the_broken_dir_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE A FILE LINK: link_create() : as : ' . $the_good_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create(Smart::real_path('tmp/index.html'), $the_good_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE A DIR LINK: link_create() : as : ' . $the_good_dir_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create(Smart::real_path('tmp/'), $the_good_dir_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE WRITE with empty content: write() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, '');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write() / before append : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write() +append : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string, 'a');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE READ / Append: read() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) SmartHashCrypto::sha512($test_string . $test_string)) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: re-write() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            if ((string) $err == '') {
                $the_test = 'FILE WRITE TO A BROKEN LINK: write() : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::write($the_broken_link, $test_string);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE THE BROKEN LINK AFTER write() and RE-CREATE IT : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE]: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'FILE WRITE: write_if_not_exists() with Content Compare to a broken link : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::write_if_not_exists($the_broken_link, $test_string, 'yes');
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE THE BROKEN LINK AFTER write_if_not_exists() and RE-CREATE IT : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE-IF-NOT-EXISTS]: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write_if_not_exists() without Content Compare : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write_if_not_exists($the_file, $test_string, 'no');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE READ: read() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE READ: read() Partial Size, First 10 bytes: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file, 10);
            if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) {
                // here we read bytes so substr() not SmartUnicode::sub_str() should be used
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE STATIC-READ: staticread() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::staticread($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE STATIC-READ: staticread() Partial Size, First 10 bytes: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::staticread($the_file, 10);
            if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) {
                // here we read bytes so substr() not SmartUnicode::sub_str() should be used
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE COPY: copy() : ' . $the_file . ' to: ' . $the_copy_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_copy_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE COPY with OVERWRITE: copy() : ' . $the_file . ' to: ' . $the_copy_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_copy_file, true);
            // overwrite destination file(s)
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE RE-COPY (test should re-write the destination): copy() : ' . $the_file . ' to: ' . $the_move_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_move_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            } else {
                $the_test = 'FILE DELETE: delete() : ' . $the_move_file;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_move_file);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE RENAME/MOVE: rename() : ' . $the_copy_file . ' to: ' . $the_move_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::rename($the_copy_file, $the_move_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            if (is_dir('__development/')) {
                //--
                $the_test = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: dir_copy() : ' . '__development/' . ' to: ' . $the_folder . '__development';
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_copy('__development/', $the_folder . '__development');
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
                //--
                if ((string) $err == '') {
                    $the_test = 'DIR COMPARE THE [DEVELOPMENT] SOURCE WITH [DEVELOPMENT] DESTINATION AFTER DIR COPY AND DIR MOVE:' . "\n" . 'compare_folders() : ' . '__development/' . ' with: ' . $the_folder . '__development/';
                    $tests[] = $the_test;
                    $arr_diff = array();
                    $arr_diff = SmartFileSystem::compare_folders('__development', $the_folder . '__development', true, true);
                    if (Smart::array_size($arr_diff) > 0) {
                        $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1);
                    }
                    //end if
                }
                //end if
                //--
            } else {
                $tests[] = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: Test Not Run (Development environment not detected) ...';
            }
            //end if else
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'RECURSIVE COPY (CLONE) DIR: dir_copy() : ' . $the_folder . ' to: ' . $the_copy_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_copy($the_folder, $the_copy_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'MOVE/RENAME DIR: dir_rename() : ' . $the_copy_folder . ' to: ' . $the_move_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_rename($the_copy_folder, $the_move_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR COMPARE THE SOURCE WITH DESTINATION AFTER DIR COPY AND DIR MOVE: ' . $the_folder . ' with: ' . $the_move_folder;
            $tests[] = $the_test;
            $arr_diff = array();
            $arr_diff = SmartFileSystem::compare_folders($the_folder, $the_move_folder, true, true);
            if (Smart::array_size($arr_diff) > 0) {
                $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1);
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR DELETE - SIMPLE: dir_delete() non-recursive: ' . $the_extra_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_delete($the_extra_folder, false);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'DIR DELETE - LAST CLEANUP: dir_delete() + recursive: ' . $get_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_delete($the_base_folder, true);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        $time = 'TOTAL TIME was: ' . (microtime(true) - $time);
        //--
        //--
        $end_tests = '##### END TESTS ... ' . $time . ' sec. #####';
        //--
        //--
        if ((string) $err == '') {
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_completed.png';
            $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; グッド ... パーフェクト</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework FS Operations <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $end_tests)) . '</span>');
        } else {
            $img_sign = 'lib/core/img/sign_error.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; エラーが発生しました ...</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing FS Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
        }
        //end if else
        //--
        //--
        $html = <<<HTML
<h1>SmartFramework LibFileSystem Tests: DONE ... [ Time: {$time} sec. ]</h1>
<script type="text/javascript">
\tSmartJS_BrowserUtils.alert_Dialog(
\t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>',
\t\t'',
\t\t'FileSystem Operations Test Suite for SmartFramework: PHP',
\t\t'920',
\t\t'480'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
 private function generate_captcha_hashed()
 {
     // v.130328
     // based on CodeIgniter
     //--
     $img_width = (int) 0 + $this->width;
     $img_height = (int) 0 + $this->height;
     //--
     //--
     $use_ttf_font = false;
     if (is_int($this->charfont)) {
         $font = $this->charfont;
     } else {
         if (is_file($this->charfont)) {
             if (function_exists('imagettftext') and substr($this->charfont, -4, 4) == '.ttf') {
                 $font = (string) $this->charfont;
                 $use_ttf_font = true;
             } else {
                 // gdf font
                 $font = @imageloadfont($this->charfont);
                 if ($font == false) {
                     $font = 5;
                 }
                 //end if
             }
             //end if else
         } else {
             $font = 5;
             // on error
         }
         //end if else
     }
     //end if
     //--
     //--
     $word = $this->generate_word();
     //--
     //--
     $length = strlen($word);
     $angle = $length >= 6 ? Smart::random_number(-($length - 6), $length - 6) : 0;
     $x_axis = Smart::random_number(6, 360 / $length - 16);
     $y_axis = $angle >= 0 ? Smart::random_number($img_height, $img_width) : Smart::random_number(6, $img_height);
     //--
     //--
     if (function_exists('imagecreatetruecolor')) {
         $im = @imagecreatetruecolor($img_width, $img_height);
     } else {
         $im = @imagecreate($img_width, $img_height);
     }
     //end if else
     //--
     //--
     @imagefilledrectangle($im, 0, 0, $img_width, $img_height, 0xffffff);
     //--
     //--
     $theta = 1;
     $thetac = 7;
     $radius = 16;
     //--
     $circles = (int) ($this->noise / 1.5);
     if ($circles < 1) {
         $circles = 1;
     }
     //end if
     //--
     $points = (int) ($this->noise - $circles);
     if ($points < 1) {
         $points = 1;
     }
     //end if
     //--
     for ($i = 0; $i < $circles * $points - 1; $i++) {
         //--
         $theta = $theta + $thetac;
         $rad = $radius * ($i / $points);
         $x = $rad * cos($theta) + $x_axis;
         $y = $rad * sin($theta) + $y_axis;
         $theta = $theta + $thetac;
         $rad1 = $radius * (($i + 1) / $points);
         $x1 = $rad1 * cos($theta) + $x_axis;
         $y1 = $rad1 * sin($theta) + $y_axis;
         //--
         @imageline($im, $x, $y, $x1, $y1, $this->generate_noise_color());
         //--
         $theta = $theta - $thetac;
         //--
     }
     //end for
     //--
     //--
     $first_x = Smart::random_number(5, $this->charxvar);
     //--
     for ($i = 0; $i < strlen($word); $i++) {
         //--
         $w = substr($word, $i, 1);
         $c = $this->generate_color();
         //--
         if ($use_ttf_font != true) {
             // GDF font
             $y = Smart::random_number(2, $this->charyvar);
             @imagestring($im, $font, $first_x, $y, $w, $c);
         } else {
             // TTF font
             $y = $img_height / 2 + $this->charttfsize / 2 - Smart::random_number(2, $this->charyvar);
             $angle = Smart::random_number(0, 20);
             @imagettftext($im, $this->charttfsize, $angle, $first_x, $y, $c, $font, $w);
         }
         //end if else
         //--
         $first_x += (int) $this->charspace + Smart::random_number(1, 15);
         //--
     }
     //end for
     //--
     //--
     return array('word' => $word, 'rawimage' => $im);
     //--
 }
Example #17
0
 /**
  * Build the associative Array of Auth Privileges
  *
  * @param 	MIXED 	$y_priv_list 			:: List of Privileges as ARRAY Array('priv_1', 'priv_2', ..., 'priv_n') or STRING '<priv_1>, <priv_2>, ..., <priv_n>'
  *
  * @return 	ARRAY							:: returns the associative array of auth privileges as Array('priv_1' => 'Priv 1', 'priv_2' => 'Priv 2', ..., 'priv_n' => 'Priv n')
  */
 public static function build_arr_privileges($y_priv_list)
 {
     //--
     if (!is_array($y_priv_list)) {
         $y_priv_list = (array) Smart::list_to_array((string) $y_priv_list);
     }
     //end if
     //--
     $y_priv_list = (array) $y_priv_list;
     //--
     $out_arr = array();
     for ($i = 0; $i < Smart::array_size($y_priv_list); $i++) {
         //--
         $y_priv_list[$i] = (string) strtolower(trim((string) $y_priv_list[$i]));
         if ((string) $y_priv_list[$i] != '') {
             $out_arr[(string) $y_priv_list[$i]] = (string) trim(ucwords(str_replace(array('_', '-'), array(' ', ' '), (string) $y_priv_list[$i])));
         }
         //end if
         //--
     }
     //end for
     //--
     return (array) $out_arr;
     //--
 }
 /**
  * Format Answer for getLanguageConfidence
  *
  * @param STRING 	$langid		Language ID ; Ex: en
  * @param INTEGER 	$score		Confidence Score
  * @param STRING 	$errmsg 	*OPTIONAL* Error Message
  * @return integer
  */
 private function formatLanguageConfidenceAnswer($langid, $score, $errmsg = '')
 {
     //--
     return (array) ['service-available' => (bool) $this->is_service_available, 'lang-id' => (string) substr((string) strtolower((string) trim((string) $langid)), 0, 2), 'confidence-score' => (string) Smart::format_number_dec((double) $score, 5, '.', ''), 'error-message' => (string) trim((string) $errmsg)];
     //--
 }
 /**
  *
  * @access 		private
  * @internal
  *
  */
 public static function registerOptimizationHintsToDebugLog()
 {
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $optim_msg = [];
         foreach (self::$MkTplFCount as $key => $val) {
             $key = (string) $key;
             if (strpos($key, 'debug') === false) {
                 // avoid hints for debug templates / sub-templates
                 $key = (array) explode(':', $key);
                 $key = (string) $key[1];
                 $val = (int) $val;
                 if ($val > 1) {
                     $optim_msg[] = ['optimal' => false, 'value' => (int) $val, 'key' => (string) $key, 'msg' => 'Optimization Hint: Set Caching Parameter for Rendering this Template to avoid multiple reads on FileSystem'];
                 } else {
                     $optim_msg[] = ['optimal' => true, 'value' => (int) $val, 'key' => (string) $key, 'msg' => 'OK'];
                 }
                 //end if else
             }
             //end if
         }
         //end foreach
         SmartFrameworkRegistry::setDebugMsg('optimizations', '*SMART-CLASSES:OPTIMIZATION-HINTS*', ['title' => 'SmartMarkersTemplating // Optimization Hints @ Number of FileSystem Reads for current Template / Sub-Templates', 'data' => (array) $optim_msg]);
         //--
         $optim_msg = [];
         foreach (self::$MkTplVars as $key => $val) {
             $counter = Smart::array_size($val);
             if ($counter > 0) {
                 $optim_msg[] = ['optimal' => null, 'value' => (int) $counter, 'key' => (string) $key, 'msg' => (string) implode(' ; ', array_unique($val))];
             }
             //end if
         }
         //end foreach
         SmartFrameworkRegistry::setDebugMsg('optimizations', '*SMART-CLASSES:OPTIMIZATION-HINTS*', ['title' => 'SmartMarkersTemplating // Optimization Notices @ Rendering Details of current Template / Sub-Templates', 'data' => (array) $optim_msg]);
         //--
         $optim_msg = [];
         //--
     }
     //end if
     //--
 }
Example #20
0
 private function addArray($incoming_data, $incoming_indent)
 {
     //--
     // print_r ($incoming_data);
     //--
     if (Smart::array_size($incoming_data) > 1) {
         return $this->addArrayInline($incoming_data, $incoming_indent);
     }
     //end if
     //--
     $key = key($incoming_data);
     $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null;
     if ($key === '__!YAMLZero') {
         $key = '0';
     }
     //end if
     //--
     if ($incoming_indent == 0 && !$this->yaml_contains_group_alias && !$this->yaml_contains_group_anchor) {
         // Shortcut for root-level values.
         if ($key || $key === '' || $key === '0') {
             $this->result[$key] = $value;
         } else {
             $this->result[] = $value;
             end($this->result);
             $key = key($this->result);
         }
         //end if else
         $this->path[$incoming_indent] = $key;
         return;
     }
     //end if
     //--
     $history = array();
     //-- Unfolding inner array tree.
     $history[] = $tmp_arr = $this->result;
     foreach ($this->path as $z => $k) {
         $history[] = $tmp_arr = $tmp_arr[$k];
     }
     //end foreach
     //--
     if ($this->yaml_contains_group_alias) {
         $value = $this->referenceContentsByAlias($this->yaml_contains_group_alias);
         $this->yaml_contains_group_alias = false;
     }
     //end if
     //-- Adding string or numeric key to the innermost level or $this->arr.
     if (is_string($key) && $key == '<<') {
         if (!is_array($tmp_arr)) {
             $tmp_arr = array();
         }
         //end if
         $tmp_arr = array_merge($tmp_arr, $value);
     } elseif ($key || $key === '' || $key === '0') {
         if (!is_array($tmp_arr)) {
             $tmp_arr = array($key => $value);
         } else {
             $tmp_arr[$key] = $value;
         }
         //end if else
     } else {
         if (!is_array($tmp_arr)) {
             $tmp_arr = array($value);
             $key = 0;
         } else {
             $tmp_arr[] = $value;
             end($tmp_arr);
             $key = key($tmp_arr);
         }
         //end if else
     }
     //end if else
     //--
     $reverse_path = array_reverse($this->path);
     $reverse_history = array_reverse($history);
     $reverse_history[0] = $tmp_arr;
     $cnt = Smart::array_size($reverse_history) - 1;
     for ($i = 0; $i < $cnt; $i++) {
         $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i];
     }
     //end for
     $this->result = $reverse_history[$cnt];
     $this->path[$incoming_indent] = $key;
     //--
     if ($this->yaml_contains_group_anchor) {
         $this->yaml_arr_saved_groups[$this->yaml_contains_group_anchor] = $this->path;
         if (is_array($value)) {
             $k = key($value);
             if (!is_int($k)) {
                 $this->yaml_arr_saved_groups[$this->yaml_contains_group_anchor][$incoming_indent + 2] = $k;
             }
             //end if
         }
         //end if
         $this->yaml_contains_group_anchor = false;
     }
     //end if
     //--
 }
 private function folder_iterator($recurring, $dir_name, $include_dot_files, $search_pattern = '', $search_prevent_file = '', $search_prevent_override = '')
 {
     //--
     $recurring = (bool) $recurring;
     $dir_name = (string) $dir_name;
     $include_dot_files = (bool) $include_dot_files;
     $search_pattern = (string) $search_pattern;
     $search_prevent_file = (string) $search_prevent_file;
     $search_prevent_override = (string) $search_prevent_override;
     //--
     if ((string) $dir_name == '') {
         Smart::log_warning('LibFileSys // ReadsFolderRecurring // Dir Name is Empty !');
         return;
         // this function does not return anything, but just stop here in this case
     }
     //end if
     //-- fix invalid path (must end with /)
     $dir_name = SmartFileSysUtils::add_dir_last_slash($dir_name);
     //-- protection
     SmartFileSysUtils::raise_error_if_unsafe_path($dir_name);
     //--
     @clearstatcache();
     //--
     $this->pattern_search_str = $search_pattern;
     $this->search_prevent_file = $search_prevent_file;
     $this->search_prevent_override = $search_prevent_override;
     //--
     if (SmartFileSystem::file_or_link_exists($dir_name) and !is_file($dir_name)) {
         // can be dir or link
         //list
         //--
         if ($handle = opendir($dir_name)) {
             //---------------------------------------
             while (false !== ($file = readdir($handle))) {
                 //--
                 if ((string) $file != '.' and (string) $file != '..') {
                     //--
                     if ($include_dot_files or !$include_dot_files and substr($file, 0, 1) != '.') {
                         //--
                         SmartFileSysUtils::raise_error_if_unsafe_path($dir_name . $file);
                         //-- params to see if counted or added to pattern matches
                         $tmp_allow_addition = 1;
                         $tmp_add_pattern = 0;
                         //-- this is for #private folders, will prevent searching in folders containing for example this file: .private-folder but can be overriden by the $search_prevent_override option exluding a particular path like folder/private/user1
                         if (strlen($search_prevent_file) > 0 and is_file($dir_name . $search_prevent_file)) {
                             if (strlen($search_prevent_override) <= 0 or strlen($search_prevent_override) > 0 and !is_file($dir_name . $search_prevent_override)) {
                                 $tmp_allow_addition = 0;
                             }
                             //end if
                         }
                         //end if
                         //-- this is a search pattern (search pattern does not apply to folders !!) ; if no empty will populate the pattern matches array with all files and folders matching ; to include all, use * or a particular search for the rest like myfile1
                         if ((string) $search_pattern == '' or is_dir($dir_name . $file)) {
                             if ($tmp_allow_addition) {
                                 if ($this->list_files_and_dirs) {
                                     $tmp_add_pattern = 1;
                                 }
                                 //end if
                             }
                             //end if
                         } else {
                             if ($this->limit_search_files <= 0 or Smart::array_size($this->pattern_file_matches) < $this->limit_search_files) {
                                 if ((string) $search_pattern == '*' or (string) $search_pattern == '[image]' and (substr($file, -4, 4) == '.png' or substr($file, -4, 4) == '.gif' or substr($file, -4, 4) == '.jpg' or substr($file, -5, 5) == '.jpeg') or (string) $search_pattern != '*' and (string) $search_pattern != '[image]' and stripos($file, $search_pattern) !== false) {
                                     if ($tmp_allow_addition) {
                                         if ($this->list_files_and_dirs) {
                                             $tmp_add_pattern = 1;
                                         }
                                         //end if
                                     }
                                     //end if
                                 } else {
                                     $tmp_allow_addition = 0;
                                 }
                                 //end if else
                             }
                             //end if
                         }
                         //end if
                         //--
                         if ($this->limit_search_files > 0) {
                             // the dir should not be taken in count here
                             if ($this->num_files + $this->num_links >= $this->limit_search_files) {
                                 break;
                             }
                             //end if
                         }
                         //end if
                         //--
                         if (!is_link($dir_name . $file)) {
                             //--
                             if (is_dir($dir_name . $file)) {
                                 //-- dir
                                 if ($tmp_allow_addition) {
                                     //--
                                     $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+');
                                     //--
                                     $this->num_dirs++;
                                     $this->num_size += $tmp_fsize;
                                     $this->num_dirs_size += $tmp_fsize;
                                     //--
                                     $tmp_fsize = 0;
                                     //--
                                     if ($tmp_add_pattern) {
                                         if ($recurring) {
                                             // if recurring, add the full path
                                             $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file);
                                         } else {
                                             // if not recurring, add just base path, without dirname prefix
                                             $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file);
                                         }
                                         //end if else
                                     }
                                     //end if
                                     //--
                                 }
                                 //end if
                                 //--
                                 if ($recurring) {
                                     //-- we go search inside even if this folder name may not match the search pattern, it is a folder, except if dissalow addition from above
                                     $this->folder_iterator($recurring, SmartFileSysUtils::add_dir_last_slash($dir_name . $file), $include_dot_files, $search_pattern, $search_prevent_file, $search_prevent_override);
                                     //--
                                 }
                                 //end if
                                 //--
                             } else {
                                 //-- file
                                 if ($tmp_allow_addition) {
                                     //--
                                     $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+');
                                     //--
                                     $this->num_files++;
                                     $this->num_size += $tmp_fsize;
                                     $this->num_files_size += $tmp_fsize;
                                     //--
                                     $tmp_fsize = 0;
                                     //--
                                     if ($tmp_add_pattern) {
                                         if ($recurring) {
                                             // if recurring, add the full path
                                             $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file);
                                         } else {
                                             // if not recurring, add just base path, without dirname prefix
                                             $this->pattern_file_matches[$file] = @filemtime($dir_name . $file);
                                         }
                                         //end if else
                                     }
                                     //end if
                                     //--
                                 }
                                 //end if
                                 //--
                             }
                             //end else
                             //--
                         } else {
                             //-- link
                             if ($tmp_allow_addition) {
                                 //--
                                 $link_result = SmartFileSystem::link_get_origin($dir_name . $file);
                                 //--
                                 if (empty($link_result) or (string) $link_result == '' or !SmartFileSystem::file_or_link_exists($link_result)) {
                                     //--
                                     // case of readlink error ..., not includding broken links, they are useless
                                     //--
                                 } else {
                                     //--
                                     $tmp_size_arr = array();
                                     $tmp_fsize = 0;
                                     //$tmp_size_arr = (array) @lstat($dir_name.$file);
                                     //$tmp_fsize = Smart::format_number_int($tmp_size_arr[7],'+'); // $tmp_size_arr[7] -> size, but may break compare if on a different file system or in distributed storage on various OS
                                     //--
                                     $this->num_links++;
                                     //--
                                     if (file_exists($dir_name . $file)) {
                                         // here file_exists must be tested because if broken link not stat on it (filemtime) to avoid log un-necessary errors
                                         //-- bugfix: not if broken link
                                         $this->num_size += $tmp_fsize;
                                         if ($tmp_add_pattern) {
                                             if (is_dir($dir_name . $file)) {
                                                 $this->num_dirs++;
                                                 $this->num_dirs_size += $tmp_fsize;
                                                 if ($recurring) {
                                                     // if recurring, add the full path
                                                     $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file);
                                                 } else {
                                                     // if not recurring, add just base path, without dirname prefix
                                                     $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file);
                                                 }
                                                 //end if else
                                             } else {
                                                 $this->num_files++;
                                                 $this->num_files_size += $tmp_fsize;
                                                 if ($recurring) {
                                                     // if recurring, add the full path
                                                     $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file);
                                                 } else {
                                                     // if not recurring, add just base path, without dirname prefix
                                                     $this->pattern_file_matches[$file] = @filemtime($dir_name . $file);
                                                 }
                                                 //end if else
                                             }
                                             //end if else
                                         }
                                         //end if
                                         //--
                                     }
                                     //end if
                                     //--
                                     $tmp_fsize = 0;
                                     $tmp_size_arr = array();
                                     //--
                                 }
                                 //end if else
                                 //--
                             }
                             //end if
                             //--
                         }
                         //end if else
                         //--
                     }
                     //end if
                     //--
                 }
                 //end if(. ..)
                 //--
             }
             //end while
             //---------------------------------------
             @closedir($handle);
             //---------------------------------------
         } else {
             //---------------------------------------
             $this->errors_arr[] = $dir_name;
             //---------------------------------------
         }
         //end else
         //--
     } else {
         //---------------------------------------
         // nothing ...
         //---------------------------------------
     }
     //end if else
     //--
 }
 /**
  * Displays the Solr Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL Solr ERROR happens or when a Data Query fails)
  * PRIVATE
  *
  * @param STRING $y_area :: The Area
  * @param STRING $y_error_message :: The Error Message to Display
  * @param STRING $y_query :: The query
  * @param STRING $y_warning :: The Warning Title
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private function error($y_area, $y_error_message, $y_query = '', $y_warning = '')
 {
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         $the_params = '- Mode: ' . $this->mode . ' -';
         $the_query_info = (string) $y_query;
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('Solr Client', 'Apache-Solr', 'FTS', 'Server', 'modules/smart-extra-libs/img/solr_logo_trans.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     Smart::raise_error('#SOLR-DB# :: Q# // Solr :: ERROR :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Stetement:' . "\n" . $y_query, $out);
     die('');
     // just in case
     //--
 }
 /**
  * Function: Draw Powered Info
  *
  * @access 		private
  * @internal
  *
  */
 public static function draw_powered_info($y_show_versions, $y_software_name = '', $y_software_powered_logo = '')
 {
     //--
     global $configs;
     //--
     $os_pict = self::get_os_pict(SmartUtils::get_server_os(), 'Server Powered by ');
     //--
     if ((string) $y_software_name == '' or (string) $y_software_powered_logo == '') {
         $y_software_name = 'Smart.Framework';
         $y_software_powered_logo = 'lib/framework/img/powered_by_smart_framework.png';
     }
     //end if
     //--
     $tmp_arr_web_server = SmartUtils::get_webserver_version();
     $name_webserver = Smart::escape_html($tmp_arr_web_server['name']);
     //--
     if ((string) $y_show_versions == 'yes') {
         // expose versions (not recommended in web area, except for auth admins)
         //--
         $y_software_name .= ' :: ' . SMART_SOFTWARE_APP_NAME;
         //--
         $version_webserver = ' :: ' . Smart::escape_html($tmp_arr_web_server['version']);
         $version_php = ' :: ' . Smart::escape_html(PHP_VERSION);
         //--
     } else {
         // avoid expose versions
         //--
         $version_webserver = '';
         $version_php = '';
         //--
     }
     //end if else
     //--
     if (trim(strtolower($name_webserver)) == 'apache') {
         $name_webserver = 'Apache';
         $icon_webserver_powered = 'lib/framework/img/powered_by_apache.png';
         $icon_webserver_logo = 'lib/framework/img/apache_logo_small_trans.png';
     } else {
         $icon_webserver_powered = 'lib/framework/img/powered_by_nginx.png';
         $icon_webserver_logo = 'lib/framework/img/nginx_logo_small_trans.png';
     }
     //end if else
     //--
     $version_dbserver = '';
     if (is_array($configs['pgsql'])) {
         if (defined('SMART_FRAMEWORK_DB_VERSION_PostgreSQL') and (string) $y_show_versions == 'yes') {
             $version_dbserver = ' :: ' . Smart::escape_html(SMART_FRAMEWORK_DB_VERSION_PostgreSQL);
         }
         //end if
         $name_dbserver = 'PostgreSQL';
         $icon_dbserver_powered = '<img src="lib/core/img/db/powered_by_postgresql.png">';
         $icon_dbserver_logo = '<img src="lib/core/img/db/postgresql_logo_small_trans.png">';
     } else {
         $name_dbserver = '';
         $icon_dbserver_powered = '';
         $icon_dbserver_logo = '';
     }
     //end if else
     //--
     if (is_array($configs['redis'])) {
         $name_cacheserver = 'Redis';
         $icon_cacheserver_powered = '<img src="lib/core/img/db/powered_by_redis.png">';
         $icon_cacheserver_logo = '<img src="lib/core/img/db/redis_logo_small_trans.png">';
     } else {
         $name_cacheserver = '';
         $icon_cacheserver_powered = '';
         $icon_cacheserver_logo = '';
     }
     //end if
     //--
     $name_dblite = 'SQLite';
     $icon_dblite_powered = 'lib/core/img/db/powered_by_sqlite.png';
     $icon_dblite_logo = 'lib/core/img/db/sqlite_logo_small.png';
     //--
     return (string) SmartMarkersTemplating::render_file_template('lib/core/templates/powered-info.inc.htm', ['OS-LOGO' => $os_pict, 'WEB-SERVER-POWERED-VERSION' => $name_webserver . $version_webserver, 'WEB-SERVER-POWERED-ICON' => $icon_webserver_powered, 'WEB-SERVER-VERSION' => $name_webserver . ' Web Server', 'WEB-SERVER-ICON' => $icon_webserver_logo, 'PHP-VERSION' => $version_php, 'DBSERVER-NAME' => $name_dbserver, 'DBSERVER-VERSION' => $version_dbserver, 'DBSERVER-POWERED-ICON' => $icon_dbserver_powered, 'DBSERVER-POWERED-LOGO' => $icon_dbserver_logo, 'CACHESERVER-NAME' => $name_cacheserver, 'CACHESERVER-POWERED-ICON' => $icon_cacheserver_powered, 'CACHESERVER-POWERED-LOGO' => $icon_cacheserver_logo, 'DBLITE-NAME' => $name_dblite, 'DBLITE-POWERED-ICON' => $icon_dblite_powered, 'DBLITE-POWERED-LOGO' => $icon_dblite_logo, 'SOFTWARE-NAME' => Smart::escape_html($y_software_name), 'SOFTWARE-POWERED-LOGO' => Smart::escape_html($y_software_powered_logo)]);
     //--
 }
 public static function apply_watermark($imagePath, $watermarkPath, $quality, $gravity)
 {
     //-- check for required extension
     self::check_gd_truecolor();
     //--
     //--
     SmartFileSysUtils::raise_error_if_unsafe_path($imagePath);
     SmartFileSysUtils::raise_error_if_unsafe_path($watermarkPath);
     //--
     //--
     $imagePath = (string) $imagePath;
     $watermarkPath = (string) $watermarkPath;
     //--
     //--
     if (is_file($imagePath) and is_file($watermarkPath)) {
         //--
         $arr_imgsize = (array) @getimagesize($watermarkPath);
         $wtmW = (int) $arr_imgsize[0];
         $wtmH = (int) $arr_imgsize[1];
         $t_wtm = (int) $arr_imgsize[2];
         // OK
         unset($arr_imgsize);
         //--
         if ($t_wtm <= 0) {
             Smart::log_notice('Media Gallery // SmartGdImageProcess // Watermark :: Unknown Type [W]: ' . $watermarkPath);
             return 1;
             // not ok (unknown type)
         }
         //end if
         $t_wtm = (string) @image_type_to_mime_type((int) $t_wtm);
         // OK
         //--
         switch ((string) $t_wtm) {
             case 'image/png':
             case 'image/x-png':
                 $watermark = @imagecreatefrompng($watermarkPath);
                 break;
             case 'image/gif':
                 $watermark = @imagecreatefromgif($watermarkPath);
                 break;
             case 'image/pjpeg':
             case 'image/jpeg':
             case 'image/jpg':
                 $watermark = @imagecreatefromjpeg($watermarkPath);
                 break;
             default:
                 Smart::log_notice('Media Gallery // SmartGdImageProcess // Watermark :: Unsupported Type [W] (not PNG/GIF/JPEG ; Type=' . $t_wtm . '): ' . $watermarkPath);
                 return 1;
                 // not ok (invalid type)
         }
         //end switch
         //--
         if (!is_resource($watermark)) {
             // if the immage is corrupt or invalid ...
             Smart::log_warning('Media Gallery // SmartGdImageProcess // Watermark :: Source Watermark Image Failure: ' . $watermarkPath);
             return 2;
             // not ok (there was an error reading the image / have no privileges / or may be an invalid image type)
         }
         //end if
         //--
         //--
         $arr_imgsize = (array) @getimagesize($imagePath);
         $imgW = (int) $arr_imgsize[0];
         $imgH = (int) $arr_imgsize[1];
         $t_img = (int) $arr_imgsize[2];
         // OK
         unset($arr_imgsize);
         //--
         if ($t_img <= 0) {
             Smart::log_notice('Media Gallery // SmartGdImageProcess // Watermark :: Unknown Type [I]: ' . $imagePath);
             return 3;
             // not ok (unknown type)
         }
         //end if
         $t_img = (string) @image_type_to_mime_type((int) $t_img);
         // OK
         //--
         switch ((string) $t_img) {
             case 'image/png':
             case 'image/x-png':
                 $the_type = 'png';
                 $source = @imagecreatefrompng($imagePath);
                 break;
             case 'image/gif':
                 $the_type = 'gif';
                 $source = @imagecreatefromgif($imagePath);
                 break;
             case 'image/pjpeg':
             case 'image/jpeg':
             case 'image/jpg':
                 $the_type = 'jpg';
                 $source = @imagecreatefromjpeg($imagePath);
                 break;
             default:
                 Smart::log_notice('Media Gallery // SmartGdImageProcess // Watermark :: Unsupported Type [I] (not PNG/GIF/JPEG ; Type=' . $t_img . '): ' . $imagePath);
                 return 3;
                 // not ok (invalid type)
         }
         //end switch
         //--
         if (!is_resource($source)) {
             // if the immage is corrupt or invalid ...
             Smart::log_warning('Media Gallery // SmartGdImageProcess // Watermark :: Source Image Failure: ' . $watermarkPath);
             return 4;
             // not ok (there was an error reading the image / have no privileges / or may be an invalid image type)
         }
         //end if
         //--
         //-- apply watermark
         switch ((string) $gravity) {
             // {{{SYNC-GRAVITY}}}
             case 'northwest':
                 $gravityX = 0;
                 $gravityY = 0;
                 break;
             case 'northeast':
                 $gravityX = ceil($imgW - $wtmW);
                 $gravityY = 0;
                 break;
             case 'southwest':
                 $gravityX = 0;
                 $gravityY = ceil($imgH - $wtmH);
                 break;
             case 'southeast':
                 $gravityX = ceil($imgW - $wtmW);
                 $gravityY = ceil($imgH - $wtmH);
                 break;
             case 'center':
             default:
                 $gravityX = ceil($imgW / 2 - $wtmW / 2);
                 $gravityY = ceil($imgH / 2 - $wtmH / 2);
         }
         //end switch
         //--
         @imagecopy($source, $watermark, $gravityX, $gravityY, 0, 0, $wtmW, $wtmH);
         //--
         //-- saving new image
         switch ((string) $the_type) {
             case 'png':
                 @imagepng($source, $imagePath);
                 break;
             case 'gif':
                 @imagegif($source, $imagePath);
                 break;
             case 'jpg':
                 @imagejpeg($source, $imagePath, $quality);
                 // preserve 100% quality for jpeg
                 break;
             default:
                 // this should not happen, it is catched above
         }
         //end switch
         //--
         //--
         @imagedestroy($source);
         @imagedestroy($watermark);
         //--
         //--
         return 0;
         // OK
         //--
     }
     //end if else
     //--
     //--
     return -1;
     // not ok, files do not exists / not files / invalid paths provided
     //--
 }
 private function arr_rotate(&$data, $steps)
 {
     //--
     $count = Smart::array_size($data);
     //--
     if ($steps < 0) {
         $steps = $count + $steps;
     }
     //end if
     $steps = $steps % $count;
     //--
     for ($i = 0; $i < $steps; $i++) {
         array_push($data, array_shift($data));
     }
     //end for
     //--
 }
 /**
  * Decompress RAW LZS
  *
  * @access 		private
  * @internal
  *
  */
 public static function decompressRawLZS($compressed)
 {
     //--
     $unarch = trim(self::RawInflate((string) $compressed));
     //-- checksum verification
     $arr = explode('#CHECKSUM-SHA1#', $unarch);
     $unarch = trim($arr[0]);
     $checksum = trim($arr[1]);
     //--
     if ((string) SmartHashCrypto::sha1($unarch) != (string) $checksum) {
         Smart::log_warning('SmartArchiverLZS/decompressRawLZS: Checksum Failed');
         return '';
         // string is corrupted, avoid to return
     }
     //end if
     //--
     return @hex2bin(strtolower($unarch));
     //--
 }
 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";
     //--
 }
 /**
  * Displays the SQLite Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL SQLite ERROR happens or when a Query Syntax is malformed)
  * PRIVATE
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private static function error($db, $y_area, $y_error_message, $y_query, $y_params_or_title, $y_warning = '')
 {
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         if (is_array($y_params_or_title)) {
             $the_params = '*** Params ***' . "\n" . print_r($y_params_or_title, 1);
         } elseif ((string) $y_params_or_title != '') {
             $the_params = '[ Reference Title ]: ' . $y_params_or_title;
         } else {
             $the_params = '- No Params or Reference Title -';
         }
         //end if
         $the_query_info = (string) trim((string) $y_query);
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('SQLite Client', 'SQLite', 'Embedded', 'SQL/DB', 'lib/core/img/db/sqlite_logo.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     if (!$db instanceof SQLite3) {
         $the_conn = (string) $db;
     } else {
         $the_conn = (string) self::get_connection_id($db);
     }
     //end if else
     //--
     Smart::raise_error('#SQLITE-DB@' . $the_conn . '# :: Q# // SQLite Client :: ERROR :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Params / Title:' . "\n" . print_r($y_params_or_title, 1) . "\n" . '*** Query:' . "\n" . $y_query, $out);
     die('');
     // just in case
     //--
 }
 public function destroy($id)
 {
     //--
     $key = (string) $this->sess_area . ':' . str_replace(':', '-', $id . '-' . $this->sess_ns);
     //--
     $ok = $this->redis->del((string) $key);
     //--
     if ($ok <= 0) {
         Smart::log_warning('Redis Custom Session: Failed to destroy ...');
         return false;
     }
     //end if
     //--
     return true;
     //--
 }
 private function inlineCode($Excerpt)
 {
     //--
     $marker = $Excerpt['text'][0];
     //--
     if (preg_match('/^(' . $marker . '+)[ ]*(.+?)[ ]*(?<!' . $marker . ')\\1(?!' . $marker . ')/s', $Excerpt['text'], $matches)) {
         //--
         $text = $matches[2];
         $text = Smart::escape_html($text);
         // fix from: html special chars ENT_NOQUOTES UTF-8
         $text = preg_replace("/[ ]*\n/", ' ', $text);
         //--
         return array('extent' => strlen($matches[0]), 'element' => array('name' => 'code', 'text' => $text));
         //--
     }
     //end if
     //--
 }