/**
  * mb_form
  */
 function mb_form($params, $content, &$smarty, &$repeat)
 {
     $fields = array("m" => CMbArray::extract($params, "m", null, true), "dosql" => CMbArray::extract($params, "dosql"), "tab" => CMbArray::extract($params, "tab"), "a" => CMbArray::extract($params, "a"));
     $attributes = array("name" => CMbArray::extract($params, "name", null, true), "method" => CMbArray::extract($params, "method", "get"), "action" => CMbArray::extract($params, "action", "?"), "class" => CMbArray::extract($params, "className", ""));
     // If protection enabled
     if (CAppUI::conf("csrf_protection")) {
         // During opening tag, we generate the token
         if ($repeat) {
             // Form is open
             self::$is_open = true;
         } else {
             if (strtoupper($attributes["method"]) == "POST") {
                 $lifetime = CMbArray::extract($params, "lifetime", CAppUI::conf("csrf_token_lifetime"));
                 $lifetime = abs(round($lifetime));
                 $token = CCSRF::generateToken();
                 if ($token) {
                     // Key is token, value is expiration date and fields to check
                     $_SESSION["tokens"][$token] = array("lifetime" => time() + $lifetime, "fields" => self::$csrf_values);
                     // In order to add the hidden input
                     $fields["csrf"] = $token;
                     self::$csrf_values = array();
                 }
             }
             // Form is closing
             self::$is_open = false;
         }
     }
     $attributes += $params;
     $fields = array_filter($fields);
     $_content = "";
     foreach ($fields as $name => $value) {
         $_content .= "\n" . CHTMLResourceLoader::getTag("input", array("type" => "hidden", "name" => $name, "value" => $value));
     }
     $_content .= $content;
     return CHTMLResourceLoader::getTag("form", $attributes, $_content);
 }
Example #2
0
 /**
  * Prepare performance data to be displayed
  *
  * @return void
  */
 static function preparePerformance()
 {
     arsort(CStoredObject::$cachableCounts);
     arsort(CStoredObject::$objectCounts);
     arsort(self::$performance["autoload"]);
     self::$performance["genere"] = round(self::$chrono->total, 3);
     self::$performance["memoire"] = CHTMLResourceLoader::getOutputMemory();
     self::$performance["objets"] = CStoredObject::$objectCount;
     self::$performance["cachableCount"] = array_sum(CMbObject::$cachableCounts);
     self::$performance["cachableCounts"] = CStoredObject::$cachableCounts;
     self::$performance["objectCounts"] = CStoredObject::$objectCounts;
     self::$performance["ip"] = $_SERVER["SERVER_ADDR"];
     self::$performance["size"] = CHTMLResourceLoader::getOutputLength();
     self::$performance["cache"] = array("totals" => Cache::$totals, "total" => Cache::$total);
     self::$performance["enslaved"] = CView::$enslaved;
     $time = 0;
     // Data sources performance
     foreach (CSQLDataSource::$dataSources as $dsn => $ds) {
         if (!$ds) {
             continue;
         }
         $chrono = $ds->chrono;
         $chronoFetch = $ds->chronoFetch;
         $time += $chrono->total + $chronoFetch->total;
         self::$performance["dataSources"][$dsn] = array("count" => $chrono->nbSteps, "time" => $chrono->total, "countFetch" => $chronoFetch->nbSteps, "timeFetch" => $chronoFetch->total);
     }
     self::$performance["dataSourceTime"] = $time;
 }
 /**
  * Embed all the external resources of the current output buffer inside a single file and outputs it.
  *
  * @param string $path Path to save the files to
  * 
  * @return void|string
  */
 private static function allInOne($path = null, $options = array())
 {
     if ($path) {
         self::$_path = rtrim($path, "/\\") . "/";
     }
     CApp::setMemoryLimit("256M");
     self::$_fp_out = CMbPath::getTempFile();
     $re_img = "/<img([^>]*)src\\s*=\\s*[\"']([^\"']+)[\"']([^>]*)(>|\$)/i";
     $re_link = "/<link[^>]*rel=\"stylesheet\"[^>]*href\\s*=\\s*[\"']([^\"']+)[\"'][^>]*>/i";
     $re_script = "/<script[^>]*src\\s*=\\s*[\"']([^\"']+)[\"'][^>]*>\\s*<\\/script>/i";
     $re_a = "/<a([^>]*)href\\s*=\\s*[\"']embed:([^\"']+)[\"']([^>]*)>/i";
     $ignore_scripts = !empty($options["ignore_scripts"]);
     // End Output Buffering
     ob_end_clean();
     ob_start();
     rewind(self::$_fp_in);
     while (!feof(self::$_fp_in)) {
         $line = fgets(self::$_fp_in);
         $line = preg_replace_callback($re_img, array('self', 'replaceImgSrc'), $line);
         $line = preg_replace_callback($re_link, array('self', 'replaceStylesheet'), $line);
         if (!$ignore_scripts) {
             $line = preg_replace_callback($re_script, array('self', 'replaceScriptSrc'), $line);
         }
         if (self::$_path) {
             $line = preg_replace_callback($re_a, array('self', 'replaceAEmbed'), $line);
         }
         fwrite(self::$_fp_out, $line);
     }
     ob_end_clean();
     $length = 0;
     rewind(self::$_fp_out);
     $full_str = "";
     while (!feof(self::$_fp_out)) {
         $line = fgets(self::$_fp_out);
         $length += strlen($line);
         $line = str_replace("[[AIO-length]]", CMbString::toDecaBinary($length), $line);
         if (strpos($line, "[[AIO-memory]]") !== false) {
             $line = str_replace("[[AIO-memory]]", self::getOutputMemory(true), $line);
         }
         if ($path) {
             $full_str .= $line;
         } else {
             echo $line;
         }
     }
     return $full_str;
 }
Example #4
0
    if ($dPconfig["offline_non_admin"] && CAppUI::$user->_id != 0 && !CAppUI::$user->isAdmin()) {
        CApp::goOffline("maintenance");
    }
}
CMbPerformance::mark("user");
// Load DB-stored configuration schema
$configurations = glob(__DIR__ . "/modules/*/configuration.php");
foreach ($configurations as $_configuration) {
    include $_configuration;
}
CMbPerformance::mark("config");
// Init output filter
CHTMLResourceLoader::initOutput(CValue::get("_aio"));
CApp::notify("BeforeMain");
// Check if the mobile feature is available and if the user agent is a mobile
$enable_mobile_ui = CAppUI::pref("MobileUI") || !CAppUI::$instance->user_id;
if (is_file(__DIR__ . "/mobile/main.php") && !empty($_SESSION["browser"]["mobile"]) && $enable_mobile_ui) {
    CAppUI::$mobile = true;
    include __DIR__ . "/mobile/main.php";
} else {
    include __DIR__ . "/includes/main.php";
}
CView::disableSlave();
CApp::notify("AfterMain");
// Send timing data in HTTP header
CMbPerformance::end();
CMbPerformance::writeHeader();
// Output HTML
$aio_options = array("ignore_scripts" => CValue::get("_aio_ignore_scripts"));
CHTMLResourceLoader::output($aio_options);
CApp::rip();