/** * Constructor. * * @param File $file The file object for the document to use * * @throws \InvalidArgumentException If the file does not exist or is not readable */ public function __construct(File $file) { if (!$file->isReadable()) { throw new \InvalidArgumentException(sprintf('Document is not readable: `%s`', $file->getRealPath())); } $this->_file = $file; }
/** * {@inheritDoc} */ public function combine($path, array $files = null) { $files = is_array($files) ? $files : array_slice(func_get_args(), 1); if (!$files or 0 === count($files)) { return false; } if (1 === count($files)) { return $files[0]; } $combined = new FPDI(); foreach ($files as $file) { if (!$file instanceof File) { $file = new File($file); } // Get each page of each file $pageCount = $combined->setSourceFile($file->getRealPath()); for ($i = 1; $i <= $pageCount; $i++) { $page = $combined->importPage($i); $size = $combined->getTemplateSize($page); $combined->AddPage($size['w'] > $size['h'] ? 'L' : 'P', array($size['w'], $size['h'])); $combined->useTemplate($page); } } $dest = new File($path); $combined->Output($dest->getRealPath(), 'F'); return $dest; }
public function testIsPublic() { $file = new File('cog://config/hello.txt'); $this->assertFalse($file->isPublic()); $file = new File('cog://public/files/image.jpg'); $this->assertTrue($file->isPublic()); }
public function process() { $path = new File($this->get('image.resize')->getCachePath()); $fs = $this->get('filesystem.finder'); foreach ($fs->depth('== 0')->in($path->getRealPath()) as $file) { $this->get('filesystem')->remove($file->getRealPath()); } return '<info>' . $path . ' has been emptied.</info>'; }
public function share(Page $page, $description = null, File $image = null, array $networks = null) { if ($networks === null) { $networks = ['facebook', 'twitter']; } $schemeAndHost = rtrim($this->get('http.request.master')->getSchemeAndHttpHost(), '/'); // empty breaks so homepage in this case $slug = empty($page->slug) ? '/' : $page->slug; $uri = $schemeAndHost . '/' . trim($this->generateUrl('ms.cms.frontend', ['slug' => $slug]), '/'); return $this->render('Message:Mothership:CMS::modules:social:share', ['social' => $this->get('cfg')->social, 'uri' => $uri, 'title' => $page->metaTitle ?: $page->title, 'description' => $description ?: $page->metaDescription, 'imageUri' => $image ? $schemeAndHost . $image->getUrl() : null, 'networks' => $networks]); }
public function resolve(File $file, $reference) { $basename = $file->getBasename(); $realPath = $file->getRealPath(); if (!file_exists($realPath)) { return false; } include_once $realPath; // Get the class name $classname = str_replace('.php', '', $basename); return new $classname($reference, $file, $this->_query); }
/** * Checks to see if a file is already in the system based on it's checksum. * * @param FilesystemFile $file The file to check * * @return boolean|int Returns the file ID if the checksum already * exists, false if it doesn't. */ public function existsInFileManager(FilesystemFile $file) { $checksum = $file->getChecksum(); $result = $this->_query->run(' SELECT file_id FROM file WHERE checksum = ?s LIMIT 1 ', $checksum); return count($result) ? $result->value() : false; }
/** * Resize a public image based on it's URL * * @param string $url The image to resize * * @return File An object representing the newly resized image. */ public function resize($url) { $url = '/' . ltrim($url, '/'); if (!file_exists($this->_cachePath) || !is_writeable($this->_cachePath)) { throw new \RuntimeException('Cache directory does not exist or is not writeable.'); } // dont cache an already cached file if (substr($url, 0, strlen($this->_cacheDir . '/')) === $this->_cacheDir . '/') { throw new \RuntimeException('Files inside the cache cannot be cached again.'); } // parse the parameters. Matches URLs like // - /resize/files/test_800xAUTO-b151b7.jpg // - /resize/files/another_image-white_400x300-72acf5a.gif if (!preg_match("/(.*)_(.+)\\-([a-f0-9]{6})(\\.[a-zA-Z]+)\$/u", $url, $matches)) { throw new Exception\BadParameters('Not a valid resize path.'); } list($match, $path, $paramString, $hash, $ext) = $matches; $this->_validateHash($path, $paramString, $hash, $ext); $params = $this->_parseParams($paramString); // lets generate an image! $original = new File($this->_publicDirectory . $path . $ext); // ensure original exists if (!file_exists($original) || !is_file($original)) { throw new Exception\NotFound('Neither the original file nor the default-image exist.'); } // make sure the target dir exists and we can write to it. $saved = new File($this->_cachePath . $url); $savedRaw = new File($saved->getRealPath()); $fs = new Filesystem(); $fs->mkdir($savedRaw->getPath(), 0777); if ($params['width'] === self::DIMENSION_AUTO || $params['height'] === self::DIMENSION_AUTO) { $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET; } else { $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND; } $box = new \Imagine\Image\Box($params['width'], $params['height']); $image = $this->_imagine->open($original->getPathname())->thumbnail($box, $mode)->save($saved->getRealPath(), array('quality' => $this->_defaultQuality)); $fs->chmod($saved->getRealPath(), 0777); return $saved; }