public static function read($type, $fileName) { if (!static::exists(app()->cachePath() . $type)) { return false; } $path = app()->cachePath() . $type . DIRECTORY_SEPARATOR . $fileName; return parent::readFile($path); }
public function getView() { $file = new File($this->baseHtml); $this->baseView = $file->readFile(); $this->replaceTag("<!-- TITLE //-->", $this->getTitle()); $this->replaceTag("<!-- TEMPLATE_URL //-->", $this->getTemplateURL()); $this->replaceTag("<!-- SCRIPT //-->", $this->getScript()); $this->replaceTag("<!-- HEADER //-->", $this->getHeader()); $this->replaceTag("<!-- NAVBAR //-->", $this->getNavbar()); $this->replaceTag("<!-- CONTENT //-->", $this->getContent()); $this->replaceTag("<!-- FOOTER //-->", $this->getFooter()); return $this->baseView; }
/** * Saves a setting to the configuration file. If the setting already exists, the current * value is overwritten. Otherwise, it will be appended in the end of the file. * <b>NOTE:</b> This method is highly unoptimized because every time that we call saveValue, * we are writing the whole file to disk... Bad ;) But it works, so we'll leave it as it * is for the time being... * * @param name Name of the setting. * @param value Value of the setting. * @return True if success or false otherwise. */ function saveValue($name, $value) { // open the config file $f = new File($this->_configFile); // there was a problem opening the file if (!$f->open("r+")) { return false; } // now we have to process each of the lines $contents = $f->readFile(); $i = 0; $result = array(); $valueString = $this->_getDataString($value); // depending if it's a string or not, we need a different regexp and a // expression that will replace the original if ($this->_getType($value) == TYPE_STRING) { $regexp = "/ *\\\$config\\[\"{$name}\"\\] *= *\"(.*)\"; */"; $replaceWith = "\$config[\"{$name}\"] = {$valueString};"; } else { $regexp = "/ *\\\$config\\[\"{$name}\"\\] *= *(.*); */"; $replaceWith = "\$config[\"{$name}\"] = {$valueString};"; } while ($i < count($contents)) { $line = $contents[$i]; $newline = preg_replace($regexp, $replaceWith, $line); $i++; // for some reason, looks like we're getting some garbage in the end // of the file... couldn't find any better way to do it if ($newline != "?>") { $newline .= "\n"; array_push($result, $newline); } else { array_push($result, "?>"); break; } } // the only thing we have to do know is save the contents of $result // to the output file $f->writeLines($result); return true; }
public function fetch($cacheID, $display = false, $renew_cachedir = true) { $filepath = PathManager::getCacheDir($cacheID, $this->cache_dir, $renew_cachedir); $_contents = File::readFile($cacheID, $filepath); if ($display) { echo json_decode($_contents, true); return; } return json_decode($_contents, true); }