Beispiel #1
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
     //--
 }
 private function _hash($string)
 {
     // force use sha1() encryption (unixman)
     //$result = sha1($string);
     //$out ='';
     // Convert hexadecimal hash value to binary string
     //for($c=0;$c<strlen($result);$c+=2) {
     //	$out .= chr(hexdec($result[$c].$result[$c+1]));
     //} //end for
     //return $out;
     switch ((string) $this->mode) {
         // enhancement by unixman
         case 'md5':
             $result = SmartHashCrypto::md5($string);
             break;
         case 'sha1':
             $result = SmartHashCrypto::sha1($string);
             break;
         case 'sha256':
             $result = SmartHashCrypto::sha256($string);
             break;
         case 'sha384':
             $result = SmartHashCrypto::sha384($string);
             break;
         case 'sha512':
             $result = SmartHashCrypto::sha512($string);
             break;
         default:
             Smart::log_warning('ERROR: Invalid mode for: SmartCryptoCipherHash / _hash: ' . $this->mode . ' ; Using sha1()');
             $result = sha1($string);
     }
     //end switch
     return (string) @hex2bin((string) $result);
     // convert hexadecimal hash value to binary string
 }