protected function loadCachedFile()
 {
     if (!$this->cacheFile->isReadable()) {
         return null;
     }
     if ($this->cacheFile->getMTime() < $this->dataFile->getMTime()) {
         return null;
     }
     $jsonString = file_get_contents($this->cacheFile->getPathname());
     if (false === $jsonString) {
         throw new InvalidArgumentException("Can not read file content from '{$this->cacheFile->getPathname()}'!");
     }
     return CiteCollection::loadFromJson($jsonString);
 }
Example #2
0
 /**
  * @param \SplFileInfo $fileInfo
  * @param string       $downloadDirUrl
  */
 public function __construct(\SplFileInfo $fileInfo, $downloadDirUrl)
 {
     $this->size = $fileInfo->getSize();
     $this->fileName = $fileInfo->getBasename();
     $this->lastModified = \DateTime::createFromFormat("U", $fileInfo->getMTime());
     $this->url = "{$downloadDirUrl}/" . rawurlencode($this->fileName);
 }
Example #3
0
 /**
  * Returns file checksum
  *
  * @param string $file
  * @return string
  */
 public function calculate($file)
 {
     $file = new \SplFileInfo($file);
     if (!$file->isFile() && !$file->isReadable()) {
         throw new \InvalidArgumentException('Invalid argument supplied for checksum calculation, only existing files are allowed');
     }
     return sprintf('%s:%s', $file->getMTime(), $file->getSize());
 }
 public function isModified($timestamp)
 {
     $info = new \SplFileInfo($this->file);
     $mtime = $info->getMTime();
     unset($info);
     if ($mtime != $timestamp) {
         return true;
     }
     return false;
 }
 private function isFileChanged(\SplFileInfo $file, &$previously)
 {
     $name = $file->getFilename();
     $mtime = $file->getMTime();
     if (isset($previously[$name])) {
         $changed = $previously[$name]['mtime'] != $mtime;
     } else {
         $changed = true;
     }
     $previously[$name] = array('mtime' => $mtime);
     return $changed;
 }
 public function gc()
 {
     $cache_seconds = usu::$cachedays * 24 * 60 * 60;
     if (is_readable($this->cachpath)) {
         $fileInfo = new SplFileInfo($this->cachpath);
         if (time() > $fileInfo->getMTime() + $cache_seconds) {
             unlink($this->cachpath);
             return true;
         }
     }
     return false;
 }
Example #7
0
 /**
  * @return bool
  */
 public function isFresh()
 {
     if (!$this->getFileSystem()->exists($this->getCacheDir() . $this->getFileName())) {
         return false;
     }
     $file = new \SplFileInfo($this->getCacheDir() . $this->getFileName());
     $lifetimeEnd = (new \DateTime("@{$file->getMTime()}"))->modify($this->getLifetime());
     if ($lifetimeEnd < new \DateTime()) {
         return false;
     }
     return true;
 }
 /**
  * @return array
  */
 public function toArray()
 {
     $rows = [];
     $currentDir = getcwd() . DIRECTORY_SEPARATOR;
     /* @var $reflection ReflectionFile  */
     foreach ($this->getIterator() as $reflection) {
         $row = [];
         $file = new \SplFileInfo($reflection->getName());
         $row = array("Files" => str_replace($currentDir, "", $file->getPathName()), "Owner" => $file->getOwner(), "Group" => $file->getGroup(), "Permissions" => $file->getPerms(), "Created" => date("d.m.Y h:m:s", $file->getCTime()), "Modified" => date("d.m.Y h:m:s", $file->getMTime()));
         $rows[] = $row;
     }
     return $rows;
 }
Example #9
0
/**
 * Retrieve directory content, directories and files
 *
 * @param Application $app Silex Application
 * @param Request $request Request parameters
 *
 * @return JsonResponse Array of objects
 */
function get_content(Application $app, Request $request)
{
    $dirpath = Utils\check_path($app['cakebox.root'], $request->get('path'));
    if (!isset($dirpath)) {
        $app->abort(400, "Missing parameters");
    }
    $finder = new Finder();
    $finder->followLinks()->depth('< 1')->in("{$app['cakebox.root']}/{$dirpath}")->ignoreVCS(true)->ignoreDotFiles($app['directory.ignoreDotFiles'])->notName($app["directory.ignore"])->sortByType();
    $dirContent = [];
    foreach ($finder as $file) {
        if ($file->isLink()) {
            $linkTo = readlink("{$app['cakebox.root']}/{$dirpath}/{$file->getBasename()}");
            if (file_exists($linkTo) == false) {
                continue;
            }
            $file = new \SplFileInfo($linkTo);
        }
        $pathInfo = [];
        $pathInfo["name"] = $file->getBasename();
        $pathInfo["type"] = $file->getType();
        $pathInfo["mtime"] = $file->getMTime();
        $pathInfo["size"] = Utils\get_size($file);
        $pathInfo["access"] = str_replace('%2F', '/', rawurlencode("{$app['cakebox.access']}/{$dirpath}/{$file->getBasename()}"));
        $pathInfo["extraType"] = "";
        $ext = strtolower($file->getExtension());
        if (in_array($ext, $app["extension.video"])) {
            $pathInfo["extraType"] = "video";
        } else {
            if (in_array($ext, $app["extension.audio"])) {
                $pathInfo["extraType"] = "audio";
            } else {
                if (in_array($ext, $app["extension.image"])) {
                    $pathInfo["extraType"] = "image";
                } else {
                    if (in_array($ext, $app["extension.archive"])) {
                        $pathInfo["extraType"] = "archive";
                    } else {
                        if (in_array($ext, $app["extension.subtitle"])) {
                            $pathInfo["extraType"] = "subtitle";
                        }
                    }
                }
            }
        }
        array_push($dirContent, $pathInfo);
    }
    return $app->json($dirContent);
}
Example #10
0
File: File.php Project: yunaid/yf
 /**
  * Get a stored value
  * @param string $group
  * @param string $name
  * @param mixed $default
  * @return mixed
  */
 public function get($group, $name, $default = NULL)
 {
     // explode on separator
     $parts = explode($this->params['separator'], $name);
     // add group to front
     array_unshift($parts, $group);
     // last part is filename
     $filename = array_pop($parts) . '.cache';
     // get directory
     $directory = $this->dir->getRealPath() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR;
     // get file
     $file = new \SplFileInfo($directory . $filename);
     if (!$file->isFile()) {
         // file doesnt exist: return default
         return $default;
     } else {
         // get time created
         $created = $file->getMTime();
         // get data handle
         $data = $file->openFile();
         // lifetime is the first line
         $lifetime = $data->fgets();
         if ($data->eof()) {
             // end of file: cache is corrupted: delete it and return default
             unlink($file->getRealPath());
             return $default;
         }
         // read data lines
         $cache = '';
         while ($data->eof() === FALSE) {
             $cache .= $data->fgets();
         }
         if ($created + (int) $lifetime < time()) {
             // Expired: delete the file & return default
             unlink($file->getRealPath());
             return $default;
         } else {
             try {
                 $unserialized = unserialize($cache);
             } catch (Exception $e) {
                 // Failed to unserialize: delete file and return default
                 unlink($file->getRealPath());
                 $unserialized = $default;
             }
             return $unserialized;
         }
     }
 }
Example #11
0
 public function __construct($path, $source = null)
 {
     if (!file_exists($path)) {
         throw new \Exception("{$path} file Not Found");
     }
     $this->time_create = time();
     $this->name = session_id() . '_' . md5($path);
     $file = new \SplFileInfo($path);
     $this->file_name_no_extension = str_replace('.' . $file->getExtension(), '', $file->getFilename());
     $this->type = $file->getExtension();
     $this->file_name = $file->getFilename();
     $this->path = $path;
     $this->dir = dirname($path);
     $this->modefy = $file->getMTime();
     $this->source = $source;
 }
Example #12
0
 /**
  * Add a file to the list.
  *
  * @param string $file The file
  * @param \SplFileInfo $fileInfo
  * @return FileList
  */
 public function addFile($file, $fileInfo)
 {
     if (!$fileInfo instanceof SplFileInfo) {
         $fileInfo = new SplFileInfo($fileInfo);
     }
     $this->files[$file] = $fileInfo;
     try {
         $mTime = $fileInfo->getMTime();
     } catch (Exception $e) {
         $mTime = 0;
     }
     if ($mTime > $this->maxMTime) {
         $this->maxMTime = $mTime;
     }
     return $this;
 }
Example #13
0
 /**
  * create file from SplFileInfo
  *
  * @param SplFileInfo $file 
  * @return Post
  */
 private function createFileFromFileInfo(\SplFileInfo $file)
 {
     $post = new Post($this->getFilter());
     $post->setText(file_get_contents((string) $file));
     $post->setIdentifier(str_replace('.markdown', '', $file->getFilename()));
     $post->setCreated($file->getCTime());
     $post->setModified($file->getMTime());
     $matches = array();
     $found = preg_match('/#.*/', $post->getText(), $matches);
     if ($found === false) {
         $title = $file->getFilename();
     } else {
         $title = ltrim(array_shift($matches), '#');
     }
     $post->setTitle($title);
     //parse title out of body text
     return $post;
 }
Example #14
0
 public function checkFile(\SplFileInfo $file)
 {
     $path = $file->getPathname();
     clearstatcache(true, $path);
     $mtime = $file->getMTime();
     $dispatch = false;
     if (isset($this->files[$path])) {
         $previous = $this->files[$path];
         if ($mtime > $previous) {
             $dispatch = true;
             $this->modify($file);
         }
     }
     if ($dispatch) {
         $this->all($file);
     }
     $this->files[$path] = $mtime;
 }
 public function connect(Application $app)
 {
     global $beforeTokenCheker;
     $controllers = $app['controllers_factory'];
     $self = $this;
     // ToDo: Add token check
     $controllers->get('/filedownloader', function (Request $request) use($app, $self) {
         $fileID = $request->get('file');
         $filePath = __DIR__ . '/../../../' . FileController::$fileDirName . "/" . basename($fileID);
         $app['logger']->addDebug($filePath);
         if (file_exists($filePath)) {
             $response = new Response();
             $lastModified = new \DateTime();
             $file = new \SplFileInfo($filePath);
             $lastModified = new \DateTime();
             $lastModified->setTimestamp($file->getMTime());
             $response->setLastModified($lastModified);
             if ($response->isNotModified($request)) {
                 $response->prepare($request)->send();
                 return $response;
             }
             $response = $app->sendFile($filePath);
             $currentDate = new \DateTime(null, new \DateTimeZone('UTC'));
             $response->setDate($currentDate)->prepare($request)->send();
             return $response;
         } else {
             return $self->returnErrorResponse("file doesn't exists.");
         }
     });
     //})->before($app['beforeTokenChecker']);
     // ToDo: Add token check
     $controllers->post('/fileuploader', function (Request $request) use($app, $self) {
         $file = $request->files->get(FileController::$paramName);
         $fineName = \Spika\Utils::randString(20, 20) . time();
         if (!is_writable(__DIR__ . '/../../../' . FileController::$fileDirName)) {
             return $self->returnErrorResponse(FileController::$fileDirName . " dir is not writable.");
         }
         $file->move(__DIR__ . '/../../../' . FileController::$fileDirName, $fineName);
         return $fineName;
     })->before($app['beforeApiGeneral']);
     //})->before($app['beforeTokenChecker']);
     return $controllers;
 }
Example #16
0
 public function cacheMinutesOverLimit($max_minutes)
 {
     $overtime = false;
     //default
     if (file_exists($this->cache_file_path)) {
         $file = new SplFileInfo($this->cache_file_path);
         $time_created = $file->getMTime();
         $now = time();
         $diff = $now - $time_created;
         $minutes_file_is_old = round($diff / 60);
         // echo "<br>now  ".$now."<br>";
         // echo "<br>".$time_created."<br>";
         // echo "<br>".$minutes_file_is_old."<br>";
         if ($minutes_file_is_old >= $max_minutes) {
             $overtime = true;
         }
     }
     return $overtime;
 }
Example #17
0
 /**
  * Overwritten I do not want to throw an exception...just ignore it! return default and delete.
  * Retrieve a cached value entry by id. 
  *
  *     // Retrieve cache entry from file group
  *     $data = Cache::instance('file')->get('foo');
  *
  *     // Retrieve cache entry from file group and return 'bar' if miss
  *     $data = Cache::instance('file')->get('foo', 'bar');
  *
  * @param   string   $id       id of cache to entry
  * @param   string   $default  default value to return if cache miss
  * @return  mixed
  * @throws  Cache_Exception
  */
 public function get($id, $default = NULL)
 {
     $filename = Cache_File::filename($this->_sanitize_id($id));
     $directory = $this->_resolve_directory($filename);
     // Wrap operations in try/catch to return default
     try {
         // Open file
         $file = new SplFileInfo($directory . $filename);
         // If file does not exist
         if (!$file->isFile()) {
             // Return default value
             return $default;
         } else {
             // Open the file and parse data
             $created = $file->getMTime();
             $data = $file->openFile();
             $lifetime = $data->fgets();
             // If we're at the EOF at this point, corrupted!
             if ($data->eof()) {
                 $this->_delete_file($file, NULL, TRUE);
                 return $default;
             }
             $cache = '';
             while ($data->eof() === FALSE) {
                 $cache .= $data->fgets();
             }
             // Test the expiry
             if ($created + (int) $lifetime < time()) {
                 // Delete the file
                 $this->_delete_file($file, NULL, TRUE);
                 return $default;
             } else {
                 return unserialize($cache);
             }
         }
     } catch (ErrorException $e) {
         $this->_delete_file($file, NULL, TRUE);
         return $default;
     }
 }
 private function setupEmoticonsMethod($self, $app, $controllers)
 {
     $controllers->get('/Emoticons', function () use($app, $self) {
         $result = $app['spikadb']->getEmoticons();
         if ($result == null) {
             return $self->returnErrorResponse("load emoticons error");
         }
         if (!isset($result['rows'])) {
             return $self->returnErrorResponse("load emoticons error");
         }
         return json_encode($result);
     })->before($app['beforeApiGeneral'])->before($app['beforeTokenChecker']);
     $controllers->get('/Emoticon/{id}', function (Request $request, $id = "") use($app, $self) {
         if (empty($id)) {
             return $self->returnErrorResponse("please specify emoticon id");
         }
         $emoticonData = $app['spikadb']->getEmoticonById($id);
         $fileID = $emoticonData['file_id'];
         if ($emoticonData == null) {
             return $self->returnErrorResponse("load emoticon error");
         }
         $filePath = $filePath = __DIR__ . '/../../../' . FileController::$fileDirName . "/" . basename($fileID);
         $response = new Response();
         $lastModified = new \DateTime();
         $file = new \SplFileInfo($filePath);
         $lastModified = new \DateTime();
         $lastModified->setTimestamp($file->getMTime());
         $response->setLastModified($lastModified);
         if ($response->isNotModified($request)) {
             $response->prepare($request)->send();
             return $response;
         }
         $response = $app->sendFile($filePath);
         $currentDate = new \DateTime(null, new \DateTimeZone('UTC'));
         $response->setDate($currentDate)->prepare($request)->send();
         return $response;
     })->before($app['beforeApiGeneral']);
 }
 /**
  * Check if we have to build file
  */
 public function needToOverwrite(AdminGenerator $generator)
 {
     if ($this->container->getParameter('admingenerator.overwrite_if_exists')) {
         return true;
     }
     $cacheDir = $this->getCachePath($generator->getFromYaml('params.namespace_prefix'), $generator->getFromYaml('params.bundle_name'));
     if (!is_dir($cacheDir)) {
         return true;
     }
     $fileInfo = new \SplFileInfo($this->getGeneratorYml());
     $finder = new Finder();
     $files = $finder->files()->date('< ' . date('Y-m-d H:i:s', $fileInfo->getMTime()))->in($cacheDir)->count();
     if ($files > 0) {
         return true;
     }
     $finder = new Finder();
     foreach ($finder->files()->in($cacheDir) as $file) {
         if (false !== strpos(file_get_contents($file), 'AdmingeneratorEmptyBuilderClass')) {
             return true;
         }
     }
     return false;
 }
 protected function _loadFile()
 {
     if (!file_exists($this->_filePath)) {
         if ($this->_id > 0) {
             foreach ($this->getOriginalFiles() as $file) {
                 list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file['fileName']);
                 if ($id == $this->_id) {
                     $this->_filePath = $file['filePath'];
                 }
             }
         }
         if (!file_exists($this->_filePath)) {
             $this->_data = false;
             return;
         }
     }
     $file = new SplFileInfo($this->_filePath);
     if (!$file->isFile() or !$file->isReadable() or !$file->isWritable()) {
         return;
     }
     list($title, $id) = DevTools_Helper_File::getIdAndTitleFromFileName($file->getFilename());
     $this->_data = array('id' => $id, 'title' => $title, 'fileName' => $file->getFilename(), 'contents' => file_get_contents($file->getPathname()), 'lastModifiedTime' => $file->getMTime(), 'filePath' => $file->getPathname());
 }
Example #21
0
 /**
  * Gets upgrade script modification time
  *
  * @return   \DateTime Returns upgrade script modification time
  */
 public function getAppearsDt()
 {
     return new \DateTime("@" . $this->fileInfo->getMTime());
 }
Example #22
0
 /**
  * Initializes the page instance variables based on a file
  *
  * @param  \SplFileInfo $file The file information for the .md file that the page represents
  * @param  string       $extension
  */
 public function init(\SplFileInfo $file, $extension = null)
 {
     $this->filePath($file->getPathName());
     $this->modified($file->getMTime());
     $this->id($this->modified() . md5($this->filePath()));
     $this->routable(true);
     $this->header();
     $this->date();
     $this->metadata();
     $this->url();
     $this->visible();
     $this->modularTwig($this->slug[0] == '_');
     $this->setPublishState();
     $this->published();
     // some extension logic
     if (empty($extension)) {
         $this->extension('.' . $file->getExtension());
     } else {
         $this->extension($extension);
     }
     // extract page language from page extension
     $language = trim(basename($this->extension(), 'md'), '.') ?: null;
     $this->language($language);
 }
Example #23
0
 /**
  * Converts a SplFileInfo to a Model
  *
  * @param \SplFileInfo $aFile
  *
  * @return Model
  */
 public static function fileToModel(\SplFileInfo $aFile)
 {
     $model = new \stdClass();
     $model->{'dir'} = $aFile->isDir();
     $model->{'extension'} = $aFile->getExtension();
     $model->{'filename'} = $aFile->getFilename();
     $model->{'path'} = str_replace('\\', '/', $aFile->getPathname());
     if ($aFile->isReadable()) {
         $model->{'last_modified'} = $aFile->getMTime();
         $model->{'size'} = $aFile->getSize();
         $model->{'type'} = $aFile->getType();
     }
     return $model;
 }
Example #24
0
 public function testDecoratedMethods()
 {
     $decorated = $this->getMockBuilder('hanneskod\\classtools\\Tests\\MockSplFileInfo')->setConstructorArgs([''])->getMock();
     $decorated->expects($this->once())->method('getRelativePath');
     $decorated->expects($this->once())->method('getRelativePathname');
     $decorated->expects($this->once())->method('getContents');
     $decorated->expects($this->once())->method('getATime');
     $decorated->expects($this->once())->method('getBasename');
     $decorated->expects($this->once())->method('getCTime');
     $decorated->expects($this->once())->method('getExtension');
     $decorated->expects($this->once())->method('getFileInfo');
     $decorated->expects($this->once())->method('getFilename');
     $decorated->expects($this->once())->method('getGroup');
     $decorated->expects($this->once())->method('getInode');
     $decorated->expects($this->once())->method('getLinkTarget');
     $decorated->expects($this->once())->method('getMTime');
     $decorated->expects($this->once())->method('getOwner');
     $decorated->expects($this->once())->method('getPath');
     $decorated->expects($this->once())->method('getPathInfo');
     $decorated->expects($this->once())->method('getPathname');
     $decorated->expects($this->once())->method('getPerms');
     $decorated->expects($this->once())->method('getRealPath');
     $decorated->expects($this->once())->method('getSize');
     $decorated->expects($this->once())->method('getType');
     $decorated->expects($this->once())->method('isDir');
     $decorated->expects($this->once())->method('isExecutable');
     $decorated->expects($this->once())->method('isFile');
     $decorated->expects($this->once())->method('isLink');
     $decorated->expects($this->once())->method('isReadable');
     $decorated->expects($this->once())->method('isWritable');
     $decorated->expects($this->once())->method('openFile');
     $decorated->expects($this->once())->method('setFileClass');
     $decorated->expects($this->once())->method('setInfoClass');
     $decorated->expects($this->once())->method('__toString')->will($this->returnValue(''));
     $fileInfo = new SplFileInfo($decorated);
     $fileInfo->getRelativePath();
     $fileInfo->getRelativePathname();
     $fileInfo->getContents();
     $fileInfo->getATime();
     $fileInfo->getBasename();
     $fileInfo->getCTime();
     $fileInfo->getExtension();
     $fileInfo->getFileInfo();
     $fileInfo->getFilename();
     $fileInfo->getGroup();
     $fileInfo->getInode();
     $fileInfo->getLinkTarget();
     $fileInfo->getMTime();
     $fileInfo->getOwner();
     $fileInfo->getPath();
     $fileInfo->getPathInfo();
     $fileInfo->getPathname();
     $fileInfo->getPerms();
     $fileInfo->getRealPath();
     $fileInfo->getSize();
     $fileInfo->getType();
     $fileInfo->isDir();
     $fileInfo->isExecutable();
     $fileInfo->isFile();
     $fileInfo->isLink();
     $fileInfo->isReadable();
     $fileInfo->isWritable();
     $fileInfo->openFile();
     $fileInfo->setFileClass();
     $fileInfo->setInfoClass();
     (string) $fileInfo;
 }
Example #25
0
 /**
  * Retrieve a cached value entry by id.
  * 
  *     // Retrieve cache entry from file group
  *     $data = Cache::instance('file')->get('foo');
  * 
  *     // Retrieve cache entry from file group and return 'bar' if miss
  *     $data = Cache::instance('file')->get('foo', 'bar');
  *
  * @param   string   id of cache to entry
  * @param   string   default value to return if cache miss
  * @return  mixed
  * @throws  Cache_Exception
  */
 public function get($id, $default = NULL)
 {
     $filename = Cache_File::filename($this->_sanitize_id($id));
     $directory = $this->_resolve_directory($filename);
     // Wrap operations in try/catch to handle notices
     try {
         // Open file
         $file = new SplFileInfo($directory . $filename);
         // If file does not exist
         if (!$file->isFile()) {
             // Return default value
             return $default;
         } else {
             // Open the file and parse data
             $created = $file->getMTime();
             $data = $file->openFile();
             $lifetime = $data->fgets();
             // If we're at the EOF at this point, corrupted!
             if ($data->eof()) {
                 throw new Cache_Exception(__METHOD__ . ' corrupted cache file!');
             }
             $cache = '';
             while ($data->eof() === FALSE) {
                 $cache .= $data->fgets();
             }
             // Test the expiry
             if ($created + (int) $lifetime < time()) {
                 // Delete the file
                 $this->_delete_file($file, NULL, TRUE);
                 return $default;
             } else {
                 return unserialize($cache);
             }
         }
     } catch (ErrorException $e) {
         // Handle ErrorException caused by failed unserialization
         if ($e->getCode() === E_NOTICE) {
             throw new Cache_Exception(__METHOD__ . ' failed to unserialize cached object with message : ' . $e->getMessage());
         }
         // Otherwise throw the exception
         throw $e;
     }
 }
Example #26
0
 /**
  * returns an unique value identifying the current version of this template,
  * in this case it's the unix timestamp of the last modification
  * @return string
  */
 public function getUid()
 {
     $info = new \SplFileInfo($this->getResourceIdentifier());
     if ($info->isFile()) {
         return (string) $info->getMTime();
     }
     return '';
 }
Example #27
0
 /**
  * Initializes the page instance variables based on a file
  *
  * @param  \SplFileInfo $file The file information for the .md file that the page represents
  * @param  string       $extension
  *
  * @return $this
  */
 public function init(\SplFileInfo $file, $extension = null)
 {
     $config = self::getGrav()['config'];
     $this->hide_home_route = $config->get('system.home.hide_in_urls', false);
     $this->home_route = $config->get('system.home.alias');
     $this->filePath($file->getPathName());
     $this->modified($file->getMTime());
     $this->id($this->modified() . md5($this->filePath()));
     $this->routable(true);
     $this->header();
     $this->date();
     $this->metadata();
     $this->url();
     $this->visible();
     $this->modularTwig($this->slug[0] == '_');
     $this->setPublishState();
     $this->published();
     $this->urlExtension();
     // some extension logic
     if (empty($extension)) {
         $this->extension('.' . $file->getExtension());
     } else {
         $this->extension($extension);
     }
     // extract page language from page extension
     $language = trim(basename($this->extension(), 'md'), '.') ?: null;
     $this->language($language);
     return $this;
 }
Example #28
0
        }
    }
    return new \Symfony\Component\HttpFoundation\RedirectResponse("/releases/v{$latest}/deployer.phar");
})->assert('stable', '(beta\\/)?')->value('stable', '');
// Download page
$controller->get('/download', function (Request $request) use($app) {
    // Getting the manifest data
    $file = new SplFileInfo($app['releases.path'] . '/manifest.json');
    $manifestData = null;
    $response = new Response();
    // Caching setup
    $response->setPublic();
    // Handling the manifest data
    if ($file->isReadable()) {
        // If there were no new releases, then just return with the last on
        $response->setLastModified(new DateTime('@' . $file->getMTime()));
        if ($response->isNotModified($request)) {
            return $response;
        }
        $manifestData = json_decode(file_get_contents($file->getPathname()), true);
        // Sorting the versions in descending order
        $builder = new \Herrera\Version\Builder();
        uasort($manifestData, function ($a, $b) use($builder) {
            if ($a['version'] === $b['version']) {
                return 0;
            }
            return \Herrera\Version\Comparator::isLessThan($builder->importString($a['version'])->getVersion(), $builder->importString($b['version'])->getVersion());
        });
        // Adding the "highlighted" bool value to every version.
        // Only the latest stable release is highlighted in every major version.
        $prevMajorVersion = null;
Example #29
0
</td>
                </tr>
            <?php 
}
?>
            <tr>
                <td class="">Start Time</td>
                <td><?php 
echo date($date_format, $file_info->getCTime());
?>
</td>
            </tr>
            <tr>
                <td class="">Last Modified Time</td>
                <td><?php 
echo date($date_format, $file_info->getMTime());
?>
</td>
            </tr>
            </tbody>
        </table>
    </section>

    <section>
        <a class="anchor" id="memory"></a>

        <h3>Memory Usage</h3>

        <div class="row">
            <div class="span4">
                <div class="well well-small">
Example #30
0
File: Page.php Project: gabykode/tf
 /**
  * Initializes the page instance variables based on a file
  *
  * @param  \SplFileInfo $file The file information for the .md file that the page represents
  * @param  string       $extension
  */
 public function init(\SplFileInfo $file, $extension = null)
 {
     $this->filePath($file->getPathName());
     $this->modified($file->getMTime());
     $this->id($this->modified() . md5($this->filePath()));
     $this->header();
     $this->date();
     $this->metadata();
     $this->url();
     $this->visible();
     $this->modularTwig($this->slug[0] == '_');
     $this->setPublishState();
     $this->published();
     if (empty($extension)) {
         $this->extension('.' . $file->getExtension());
     } else {
         $this->extension($extension);
     }
 }