/**
  * 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());
 }
Example #2
0
 /**
  * Clear the Smarty cache
  * @return null
  */
 public function clearCache()
 {
     $compileDirectory = Zibo::getInstance()->getConfigValue(SmartyView::CONFIG_COMPILE_DIRECTORY, SmartyView::DEFAULT_COMPILE_DIRECTORY);
     $compileDirectory = new File($compileDirectory);
     $compileDirectory->delete();
 }
Example #3
0
 /**
  * @expectedException zibo\library\archive\exception\ArchiveException
  */
 public function testUncompressWithNonPharPathThrowsException()
 {
     $phar = new Phar($this->nonPharFile);
     $uncompressDirectory = new File('/tmp/zibo/');
     if ($uncompressDirectory->exists()) {
         $uncompressDirectory->delete();
     }
     $phar->uncompress($uncompressDirectory);
 }
 /**
  * Action to delete a file
  * @param string|array $files String with the filename, relative to the root path of theor an array of filename'
  * @return null
  */
 public function deleteAction($files = null)
 {
     if ($files == null) {
         return;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         $file = new File($this->fileBrowser->getRoot(), $file);
         try {
             $file->delete();
         } catch (Exception $exception) {
             $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage()));
         }
         $path = $this->fileBrowser->getPath($file, false)->getPath();
         if (array_key_exists($path, $this->clipboard)) {
             unset($this->clipboard[$path]);
         }
         $this->addInformation(self::TRANSLATION_INFORMATION_DELETED, array('path' => $path));
     }
     $this->response->setRedirect($this->getReferer());
 }
Example #5
0
 /**
  * Clears the cache in the public directory
  * @return null
  */
 public function clearCache()
 {
     $root = Zibo::getInstance()->getRootPath();
     $publicCache = new File($root, Zibo::DIRECTORY_APPLICATION . '/' . Zibo::DIRECTORY_PUBLIC . '/' . Zibo::DIRECTORY_CACHE);
     $publicCache->delete();
 }
Example #6
0
 /**
  * Starts the crawling
  * @param integer $delay Delay between each page in miliseconds
  * @param zibo\library\filesystem\File $statusFile File where the status of the crawling process is written
  * @param zibo\library\filesystem\File $cancelFile File which will cancel/stop the crawling process when exists
  * @return null
  */
 public function crawl($delay = 1000, File $statusFile = null, File $cancelFile = null)
 {
     $prey = $this->web->resetPrey();
     $start = time();
     $index = 0;
     $isCancelled = false;
     while ($prey) {
         if ($cancelFile && $cancelFile->exists()) {
             $cancelFile->delete();
             $isCancelled = true;
             break;
         }
         usleep($delay * 1000);
         $index++;
         $url = $prey->getUrl();
         if ($this->shouldIgnore($url)) {
             $prey->addType(WebNode::TYPE_IGNORED);
             $prey = $this->web->getNextPrey();
             continue;
         }
         if ($statusFile) {
             $status = new SpiderStatus($url, $index, $this->web->countNodes(), $start);
             $status->write($statusFile);
         }
         if (String::startsWith($url, 'mailto:')) {
             $prey->addType(WebNode::TYPE_MAILTO);
             $prey = $this->web->getNextPrey();
             continue;
         }
         try {
             $crawl = new Crawl($url);
             $crawl->performCrawl();
             $response = $crawl->getResponse();
             $prey->setResponse($response);
             if ($response->isRedirect()) {
                 $location = $response->getHeader('Location');
                 if (!String::looksLikeUrl($location)) {
                     if ($location[0] == '/') {
                         $base = $crawl->getBaseUrl();
                     } else {
                         $base = $crawl->getBasePath();
                     }
                     $location = rtrim($base, '/') . '/' . ltrim($location, '/');
                 }
                 if ($url == $location) {
                     throw new Exception('Redirect loop');
                 }
                 $locationNode = $this->web->getNode($location);
                 $locationNode->addReference($prey);
                 $prey->addLink($locationNode);
             }
             if (!String::startsWith($url, $this->baseUrl)) {
                 $prey->addType(WebNode::TYPE_EXTERNAL);
                 if (!$this->willBiteExternalNodes) {
                     $prey = $this->web->getNextPrey();
                     continue;
                 }
             }
             $this->bite($prey, $crawl->getBaseUrl(), $crawl->getBasePath());
         } catch (Exception $exception) {
             if ($crawl) {
                 $response = $crawl->getResponse();
                 if ($response) {
                     $prey->setResponse($response);
                 }
             }
             $prey->setError($exception->getMessage());
         }
         $prey = $this->web->getNextPrey();
     }
     if (!$isCancelled) {
         if ($statusFile) {
             $status = new SpiderStatus("reports", $index, $this->web->countNodes(), $start);
             $status->write($statusFile);
         }
         foreach ($this->reports as $report) {
             $report->setWeb($this->web);
         }
     }
     if ($statusFile) {
         $status = new SpiderStatus(null, $index, $this->web->countNodes(), $start, time());
         $status->write($statusFile);
     }
 }
Example #7
0
 /**
  * Write the model definitions of the provided models to the provided model definition file
  * @param zibo\library\filesystem\File $file
  * @param array $models models to write to file
  * @return null
  */
 public function writeModelsToFile(File $file, array $models)
 {
     if (!$models) {
         if ($file->exists()) {
             $file->delete();
         }
         return;
     }
     $dom = new Document('1.0', 'utf-8');
     $dom->formatOutput = true;
     $modelsElement = $dom->createElement(self::TAG_ROOT);
     $dom->appendChild($modelsElement);
     foreach ($models as $model) {
         $modelElement = $this->getElementFromModel($dom, $model);
         if ($modelElement != null) {
             $importedModelElement = $dom->importNode($modelElement, true);
             $modelsElement->appendChild($importedModelElement);
         }
     }
     $dom->save($file);
 }
Example #8
0
 /**
  * Perform the validation on this field through the added validators
  * @param zibo\library\validation\exception\ValidationException $exception
  * @return zibo\library\validation\exception\ValidationException
  */
 public function validate(ValidationException $exception = null)
 {
     $exception = parent::validate($exception);
     $options = array();
     if ($this->minWidth) {
         $options[ImageValidator::OPTION_WIDTH_MIN] = $this->minWidth;
     }
     if ($this->minHeight) {
         $options[ImageValidator::OPTION_HEIGHT_MIN] = $this->minHeight;
     }
     if ($this->maxWidth) {
         $options[ImageValidator::OPTION_WIDTH_MAX] = $this->maxWidth;
     }
     if ($this->maxHeight) {
         $options[ImageValidator::OPTION_HEIGHT_MAX] = $this->maxHeight;
     }
     $validator = new ImageValidator($options);
     if (!$validator->isValid($this->getValue())) {
         $file = new File($this->getValue());
         if ($file->exists()) {
             $file->delete();
         }
         $this->setValue(null);
         $this->appendToClass(Field::CLASS_VALIDATION_ERROR);
         $exception->addErrors($this->getName(), $validator->getErrors());
     }
     return $exception;
 }
 /**
  * Clears the result cache for all the queries which use the provided model
  * @param string $modelName Name of the model
  * @return null
  */
 public function clearResults($modelName)
 {
     $directoryIndex = new File($this->directoryResultIndex, $modelName);
     if (!$directoryIndex->exists()) {
         return;
     }
     $files = $directoryIndex->read();
     foreach ($files as $file) {
         $this->cache->clear(self::CACHE_TYPE_RESULT, $file->getName());
     }
     $directoryIndex->delete();
 }