/** * Writes the cache file with all the cache objects * @return null */ private function writeFile() { if ($this->cache === null) { return; } $parent = $this->file->getParent(); $parent->create(); $output = serialize($this->cache); $this->file->write($output); }
public function testCompressWithNonExistingPharPathCreatesPath() { $nonExistingPath = new File('application/data/non_existing_dir/test.phar'); $archive = new Phar($nonExistingPath); $archive->compress($this->compressFiles); if (!$nonExistingPath->exists()) { $this->fail(); } $nonExistingPath->getParent()->delete(); }
/** * Gets the file from the Zibo include paths * @param string $path Path, in the webdirectory, of the file * @return null|zibo\library\filesystem\File */ private function getFile($path) { $zibo = Zibo::getInstance(); $plainPath = new File(Zibo::DIRECTORY_WEB . File::DIRECTORY_SEPARATOR . $path); $file = $zibo->getFile($plainPath->getPath()); if ($file) { return $file; } $encodedPath = new File($plainPath->getParent()->getPath(), urlencode($plainPath->getName())); return $zibo->getFile($encodedPath->getPath()); }
/** * During construction, you can specify a path to a file and a file name. This * will prep the File instance for an upload. If you do not wish * to upload a file, simply instantiate this class without any attributes. * * If you want to fill this class with the details of a specific file, then * get_file_info and it will be imported into its own Box_Client_File class. * * @param zibo\library\filesystem\File $file Provide a file if you want to upload a directory or a file * @return null */ public function __construct(File $file = null) { $this->attributes = array(); $this->tags = array(); if ($file) { if ($file->isDirectory) { $this->attribute('localpath', $file->getPath()); } else { $this->attribute('localpath', $file->getParent()->getPath()); $this->attribute('filename', $file->getName()); } } }
/** * Finished the installation, remove the installation module and redirect * @return null */ public function finish() { $installModule = new File(__DIR__ . '/../../../../'); $installModule->delete(); $installScript = new File($installModule->getParent()->getParent(), 'install.php'); if ($installScript->exists() && $installScript->isWritable()) { $installScript->delete(); } $zibo = Zibo::getInstance(); $request = $zibo->getRequest(); $response = $zibo->getResponse(); $response->setRedirect($request->getBaseUrl()); }
/** * Connects this connection * @return null * @throws zibo\library\database\mysql\exception\MysqlException when no connection could be made with the host * @throws zibo\library\database\mysql\exception\MysqlException when the database could not be selected */ public function connect() { $file = new File($this->dsn->getPath()); if (!$file->exists()) { $parent = $file->getParent(); $parent->create(); } try { $this->connection = new SQLite3($file->getAbsolutePath()); } catch (Exception $exception) { $this->connection = null; throw new SqliteException($exception->getMessage(), 0, $exception); } }
/** * Gets the dependency container * @param zibo\core\Zibo $zibo Instance of zibo * @return zibo\core\di\DependencyContainer */ public function getContainer(Zibo $zibo) { $file = new File(self::FILE); if ($file->exists()) { require $file; } if (isset($container)) { return $container; } $container = $this->io->getContainer($zibo); $parent = $file->getParent(); $parent->create(); $php = $this->generatePhp($container, $file); $file->write($php); return $container; }
/** * Gets all available locales * @return array all Locale objects */ public function getLocales() { $file = new File(self::FILE); if ($file->exists()) { require $file; } if (isset($locales)) { return $locales; } $locales = $this->io->getLocales(); $parent = $file->getParent(); $parent->create(); $php = $this->generatePhp($locales); $file->write($php); return $locales; }
/** * Action to edit or create a file * * Every argument to this method is a part of the file to edit. eg. * $fb->editAction('application', 'data', 'test.txt') would show the editor for application/data/test.txt * * To create a new file in a directory, give the arguments to a directory instead of a file. * @return null */ public function editAction() { $pieces = func_get_args(); $path = $this->getFileFromPieces($pieces, false); $absolutePath = new File($this->fileBrowser->getRoot(), $path); $basePath = $this->request->getBasePath() . '/'; $saveAction = $basePath . self::ACTION_EDIT . ($path ? '/' . $path : ''); $name = null; $content = null; if ($path) { if (!$absolutePath->exists()) { $this->addError(self::TRANSLATION_ERROR_EXIST_NOT, array('path' => $this->fileBrowser->getPath($path))); $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); $this->response->setView(new BaseView()); return; } if (!$absolutePath->isDirectory()) { $name = $absolutePath->getName(); $path = $absolutePath->getParent(); $content = $absolutePath->read(); } else { $path = $absolutePath; } } else { $path = $absolutePath; } $isWritable = $absolutePath->isWritable(); $path = $this->fileBrowser->getPath($path, false); $form = new EditorForm($saveAction, $path, $name, $content); if ($form->isSubmitted()) { $path = $path->getPath(); $redirectUrl = $basePath . self::ACTION_PATH . ($path != '.' ? '/' . $path : ''); if ($form->isCancelled()) { $this->response->setRedirect($redirectUrl); return; } try { $form->validate(); $content = $form->getFileContent(); $name = $form->getFileName(); $path = $form->getFilePath(); $file = new File($this->fileBrowser->getRoot(), $path . '/' . $name); if ($file->isWritable()) { $file->write($content); $this->addInformation(self::TRANSLATION_INFORMATION_SAVED, array('path' => $this->fileBrowser->getPath($file, false))); $this->response->setRedirect($redirectUrl); } else { $this->addError(self::TRANSLATION_ERROR_WRITABLE, array('path' => $this->fileBrowser->getPath($file, false))); $form->setIsDisabled(true, EditorForm::BUTTON_SUBMIT); $isWritable = true; } } catch (ValidationException $exception) { } catch (Exception $exception) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1); $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage())); $this->response->setStatusCode(Response::STATUS_CODE_SERVER_ERROR); } } if (!$isWritable) { $form->setIsDisabled(true, EditorForm::BUTTON_SUBMIT); $this->addWarning(self::TRANSLATION_ERROR_WRITABLE, array('path' => $path . ($name ? '/' . $name : ''))); } $view = new EditorView($form, $path); $view->setPageTitle(Module::TRANSLATION_FILE_BROWSER, true); $this->response->setView($view); }
public function indexAction() { if (func_get_args()) { $this->setError404(); return; } $id = $this->getSession()->getId(); $fileSpider = new File(self::PATH_DATA, $id . self::SUFFIX_SPIDER); $baseUrl = $this->request->getBaseUrl(); $basePath = $this->request->getBasePath(); $formAction = $basePath; if ($basePath == $baseUrl) { $formAction .= '/'; } $form = new SpiderForm($formAction); if ($form->isSubmitted()) { if ($form->isCancelled()) { $fileCancel = new File(self::PATH_DATA, $id . self::SUFFIX_CANCEL); $fileCancel->write('1'); return; } try { $form->validate(); $url = $form->getUrl(); $delay = $form->getDelay(); $ignore = $form->getIgnore(); $ignore = explode("\n", $ignore); $spider = new Spider($url); foreach ($ignore as $ignoreRegex) { $ignoreRegex = trim($ignoreRegex); if (!$ignoreRegex) { continue; } $spider->addIgnoreRegex($ignoreRegex); } $spider->addBite(new AnchorSpiderBite()); $spider->addBite(new CssSpiderBite()); $spider->addBite(new CssImageSpiderBite()); $spider->addBite(new CssImportSpiderBite()); $spider->addBite(new ImageSpiderBite()); $spider->addBite(new JsSpiderBite()); $spider->addReport(new ErrorReport()); $spider->addReport(new RedirectReport()); $spider->addReport(new SuccessReport()); $spider->addReport(new ImageReport()); $spider->addReport(new CssReport()); $spider->addReport(new JsReport()); $spider->addReport(new ExternalReport()); $spider->addReport(new MailtoReport()); $spider->addReport(new IgnoredReport()); $parent = $fileSpider->getParent(); $parent->create(); $fileSpider->write(serialize($spider)); $php = Zibo::getInstance()->getConfigValue(self::CONFIG_PHP_COMMAND, self::DEFAULT_PHP_COMMAND); System::execute($php . ' ' . $_SERVER['SCRIPT_FILENAME'] . ' spider/crawl/' . $id . '/' . $delay . ' > /dev/null 2> /dev/null & echo $!'); return; } catch (ValidationException $exception) { $form->setValidationException($exception); } } if ($fileSpider->exists()) { $fileSpiderContent = $fileSpider->read(); $spider = unserialize($fileSpiderContent); $form->setUrl($spider->getBaseUrl()); $form->setIsDisabled(true, SpiderForm::FIELD_URL); $form->setIsDisabled(true, SpiderForm::BUTTON_SUBMIT); } $statusUrl = $basePath . '/status/' . $id; $reportUrl = $basePath . '/report/' . $id; $view = new SpiderView($form, $statusUrl, $reportUrl); $view->setTitle('spider.title', true); $this->response->setView($view); }
public function write(File $file) { $output = 'current = "' . $this->current . "\"\n"; $output .= 'visited = ' . $this->visited . "\n"; $output .= 'gathered = ' . $this->gathered . "\n"; $output .= 'start = ' . $this->start . "\n"; $output .= 'stop = ' . $this->stop . "\n"; $parent = $file->getParent(); $parent->create(); $file->write($output); }
/** * Writes the provided translations to the provided file * @param zibo\library\filesystem\File $translationFile File to store the translations in * @param array $translations Array with the translation key as array key and the translation as value * @return null */ private function setTranslationsToFile(File $translationFile, array $translations) { ksort($translations); $ini = ''; foreach ($translations as $key => $translation) { $ini .= $key . ' = "' . str_replace('"', '\\"', $translation) . "\"\n"; } $translationDirectory = $translationFile->getParent(); $translationDirectory->create(); $translationFile->write($ini); }
/** * Copy a file to another file * @param File $source * @param File $destination * @return null * @throws zibo\library\filesystem\exception\FileSystemException when the source could not be copied */ private function copyFile(File $source, File $destination) { $destinationParent = $destination->getParent(); $this->create($destinationParent); $sourcePath = $source->getAbsolutePath(); $destinationPath = $destination->getAbsolutePath(); if ($sourcePath == $destinationPath) { return; } $result = @copy($sourcePath, $destinationPath); if (!$result) { $error = error_get_last(); throw new FileSystemException('Could not copy ' . $sourcePath . ' to ' . $destinationPath . ': ' . $error['message']); } $this->setPermissions($destination, 0644); // $source->getPermissions()); }
/** * Optimizes the provided CSS source * @param string $source CSS source * @param zibo\library\filesystem\File $file The file of the source * @return string optimized and minified CSS source */ protected function optimizeSource($source, File $file) { $source = preg_replace(CSSMin::REGEX_IMPORT, '', $source); $source = $this->getCssMinifier()->minify($source, true); $zibo = Zibo::getInstance(); $parent = $file->getParent(); $source = preg_replace_callback('/url( )?\\(["\']?([^;\\\\"\')]*)(["\']?)\\)([^;\\)]*);/', function ($matches) use($zibo, $parent) { try { $source = new File($parent, $matches[2]); $source = $zibo->getRelativeFile($source); $source = $source->getPath(); } catch (ZiboException $e) { $zibo->runEvent(Zibo::EVENT_LOG, $e->getMessage(), $e->getTraceAsString()); $source = $matches[2]; } try { $image = new Image($source); $image->getHtml(); $source = $image->getSource(); } catch (ZiboException $e) { $zibo->runEvent(Zibo::EVENT_LOG, $e->getMessage(), $e->getTraceAsString()); } return "url(" . $source . ")" . $matches[4] . ';'; }, $source); return $source; }
/** * Gets whether a new generation of the optimized file is necessairy * @param zibo\library\filesystem\File $optimizedFile The file of the optimized source * @param array $files Array with File objects of the files to optimize * @return boolean True if a new generation is necessairy, false otherwise */ private function isGenerateNecessairy(File $optimizedFile, array $files) { if (!$optimizedFile->exists()) { $parent = $optimizedFile->getParent(); if (!$parent->exists()) { $parent->create(); } return true; } $cacheTime = $optimizedFile->getModificationTime(); foreach ($files as $file) { if ($file->getModificationTime() >= $cacheTime) { return true; } } return false; }
/** * Indexes the result of a query * @param string $resultId Unique identifier of the result * @param array $modelName Array with the names of the models used in the query of this result * @return null */ private function indexResult($resultId, array $modelNames) { foreach ($modelNames as $modelName) { $file = new File($this->directoryResultIndex, $modelName . File::DIRECTORY_SEPARATOR . $resultId); $parent = $file->getParent(); $parent->create(); $file->write(); } }