Exemple #1
0
 public static function upload($prog_dir, $config, $config_file_path)
 {
     FileUtil::write_ini_file(array("production" => $config), $config_file_path, true);
     Console::println("Executing: " . "php " . $prog_dir . "git-deploy " . $config_file_path);
     passthru("php " . $prog_dir . "/git-deploy " . $config_file_path);
     unlink($config_file_path);
 }
Exemple #2
0
 public function save($check = false)
 {
     header("X-C-" . $this->name . ": FALSE");
     if (!$check || $this->dirty) {
         header("X-C-" . $this->name . ": TRUE");
         file_put_contents(\RudraX\Utils\FileUtil::uniform_path($this->hard_file), '<?php return ' . var_export(self::$cache_array[$this->name], true) . ';');
     }
 }
Exemple #3
0
 public function minify()
 {
     if (FIRST_RELOAD || RX_MODE_DEBUG || self::$cache->isEmpty()) {
         foreach ($this->scripts as $key => $value) {
             $newName = self::$BUILD_PATH . $value["file"];
             $this->scripts[$key]["exists"] = file_exists(PROJECT_ROOT_DIR . $value["file"]);
             $this->scripts[$key]["build_path"] = $newName;
             if ($this->const['RX_JS_MIN'] && !$this->scripts[$key]["remote"]) {
                 $this->scripts[$key]["minified"] = $this->minified->minify(PROJECT_ROOT_DIR . $value["file"], $newName);
                 $this->scripts[$key]["link"] = CONTEXT_PATH . str_replace(self::$BUILD_PATH, "", $this->scripts[$key]["minified"]);
             } else {
                 if (!$this->scripts[$key]["remote"]) {
                     \RudraX\Utils\FileUtil::build_copy($value["file"], ResourceUtil::$RESOURCE_DIST_DIR . "/" . $value["file"]);
                 }
             }
         }
         foreach ($this->css as $key => $value) {
             if ($this->const['RX_JS_MIN'] && !$this->css[$key]["remote"]) {
                 Browser::warn("minifying...", $this->css[$key]["minified"], file_exists(PROJECT_ROOT_DIR . $value["file"]), $value["file"]);
                 $newName = self::$BUILD_PATH . $value["file"];
                 $this->css[$key]["exists"] = file_exists($value["file"]);
                 $this->css[$key]["build_path"] = $newName;
                 $inputFile = PROJECT_ROOT_DIR . $value["file"];
                 $inputFileExists = file_exists($inputFile);
                 if ($inputFileExists) {
                     $this->css[$key]["minified"] = $this->minified->minify($inputFile, $newName);
                 } else {
                     $this->css[$key]["minified"] = $newName;
                 }
                 $this->css[$key]["link"] = CONTEXT_PATH . str_replace(self::$BUILD_PATH, "", $this->css[$key]["minified"]);
             }
         }
     }
 }
Exemple #4
0
 public static function read($glob_config, $file, $file2 = null)
 {
     $debug = isset($glob_config["RX_MODE_DEBUG"]) && $glob_config["RX_MODE_DEBUG"] == TRUE;
     $debug_build = isset($_REQUEST["RX_MODE_BUILD"]) && $_REQUEST["RX_MODE_BUILD"] == TRUE;
     self::$cache = new RxCache("config", true);
     $reloadCache = FALSE;
     header("FLAGS:" . self::$cache->isEmpty() . "-" . $glob_config["RX_MODE_DEBUG"] . "-" . $debug);
     if (self::$cache->isEmpty()) {
         $reloadCache = TRUE;
     } else {
         $_glob_config = self::$cache->get("GLOBAL");
         if ($_glob_config["RX_MODE_DEBUG"] != $debug || isset($_GET['ModPagespeed'])) {
             $reloadCache = TRUE;
         }
     }
     $RELOAD_VERSION = self::$cache->get("RELOAD_VERSION");
     if ($debug_build || $debug || $reloadCache) {
         FileUtil::build_check();
         define("FIRST_RELOAD", TRUE);
         $RELOAD_VERSION = microtime(true);
         RxCache::clean();
         self::$cache->set("RELOAD_VERSION", $RELOAD_VERSION);
         $DEFAULT_CONFIG = parse_ini_file("_project.properties", TRUE);
         $localConfig = array();
         if (file_exists($file)) {
             $localConfig = parse_ini_file($file, TRUE);
         }
         $localConfig = array_replace_recursive($DEFAULT_CONFIG, $localConfig);
         if ($file2 != null && file_exists($file2)) {
             $localConfig = array_replace_recursive($localConfig, parse_ini_file($file2, TRUE));
         }
         self::$cache->merge($localConfig);
         self::$cache->set('GLOBAL', array_merge($DEFAULT_CONFIG['GLOBAL'], $localConfig['GLOBAL'], $glob_config));
         $reloadMode = isset($_GET['ModPagespeed']) ? $_GET['ModPagespeed'] : NULL;
         call_user_func(rx_function("rx_reload_cache"), $reloadMode);
         self::$cache->save();
         Browser::header("RX_MODE_BUILD");
     } else {
         define("FIRST_RELOAD", FALSE);
     }
     define("RELOAD_VERSION", $RELOAD_VERSION);
     return self::$cache->getArray();
 }
Exemple #5
0
 public static function scan_modules($dirs = array("lib", "resources"), $target = "resources/bundle.json")
 {
     self::$webmodules = array("_" => array(), "bundles" => array());
     foreach ($dirs as $dir) {
         self::$webmodules = self::scan_modules_dir(self::$PROJECT_ROOT_DIR . $dir, self::$webmodules);
     }
     FileUtil::build_mkdir(self::$RESOURCE_DIST_DIR);
     FileUtil::build_write(self::$RESOURCE_DIST_DIR . "/" . $target, json_encode(self::$webmodules, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     FileUtil::build_export_object(self::$RESOURCE_DIST_DIR . "/" . $target . ".php", self::$webmodules);
     return self::$webmodules;
 }
Exemple #6
0
 public function _interpret_($info, $params)
 {
     $nocache = isset($_REQUEST["_AUTH_"]) || isset($_REQUEST["_NOCACHE_"]);
     $cache = $info["cache"] && !$nocache;
     $cache_file = $info["cache"] === "file" && !empty(Webapp::$REQUEST_FILE_EXT);
     $perform = true;
     $md5key = null;
     $validate = $this->user->validate();
     if ($info["auth"] && !$validate) {
         $this->user->basicAuth();
     }
     if ($info["roles"] !== FALSE) {
         if (!in_array($this->user->role, $info["roles"])) {
             print_r($info["roles"]);
             echo $this->user->role;
             header("HTTP/1.1 403 Unauthorized");
             exit;
         }
     }
     $cache = ($cache || isset($info["guestcache"]) && $info["guestcache"] && !$validate) && !$nocache;
     header("Pragma:");
     header("X-Rudrax-Authd: false");
     if ($cache && !$cache_file) {
         header("X-Rudrax-Enabled: true");
         $this->responseCache = new RxCache('responseCache');
         $this->headerCache = new RxCache('headerCache');
         if (defined("RX_RESP_CACHE_TIME")) {
             $this->cacheDuration = RX_RESP_CACHE_TIME;
         } else {
             $this->cacheDuration = 900;
             // in seconds
         }
         // Client is told to cache these results for set duration
         header('Cache-Control: public,max-age=' . $this->cacheDuration . ',must-revalidate');
         header('Expires: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $this->cacheDuration) . ' GMT');
         header('Last-modified: ' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME']) . ' GMT');
         // Pragma header removed should the server happen to set it automatically
         // Pragma headers can make browser misbehave and still ask data from server
         header_remove('Pragma');
         $md5key = md5($_SERVER["REQUEST_URI"]);
         $response = $this->responseCache->get($md5key, FALSE);
         if (!empty($response)) {
             $perform = false;
             echo $response;
             $headerstr = $this->headerCache->get($md5key);
             $headers = explode(self::$HEADER_GLUE, $headerstr);
             foreach ($headers as $header) {
                 header($header);
             }
             header("X-Rudrax-Cached: true");
             if ($validate) {
                 header("X-Rudrax-Authd: true");
             }
             exit;
         } else {
             if ($validate) {
                 header("X-Rudrax-Authd: true");
             }
             // ob_start('ob_gzhandler');
         }
     }
     if ($perform) {
         $this->_interceptor_($info, $params);
     }
     if ($perform && $cache) {
         $response = ob_get_contents();
         if ($cache_file === true) {
             FileUtil::build_write("/cache_file/" . Webapp::$REQUEST_PATHNAME, $response);
         } else {
             $this->responseCache->set($md5key, $response);
             $this->headerCache->set($md5key, implode(self::$HEADER_GLUE, headers_list()));
         }
         // ob_end_flush();
         // echo $response;
     }
 }