-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
260 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
namespace Grav\Common\Page\Medium; | ||
|
||
use Grav\Common\GravTrait; | ||
use RocketTheme\Toolbox\Event\Event; | ||
|
||
class ImageFile extends \Gregwar\Image\Image | ||
{ | ||
use GravTrait; | ||
|
||
/** | ||
* This is the same as the Gregwar Image class except this one fires a Grav Event on creation of new cached file | ||
* | ||
* @param string $type the image type | ||
* @param int $quality the quality (for JPEG) | ||
* @param bool $actual | ||
* | ||
* @return mixed|string | ||
*/ | ||
public function cacheFile($type = 'jpg', $quality = 80, $actual = false) | ||
{ | ||
if ($type == 'guess') { | ||
$type = $this->guessType(); | ||
} | ||
|
||
if (!count($this->operations) && $type == $this->guessType() && !$this->forceCache) { | ||
return $this->getFilename($this->getFilePath()); | ||
} | ||
|
||
// Computes the hash | ||
$this->hash = $this->getHash($type, $quality); | ||
|
||
// Generates the cache file | ||
$cacheFile = ''; | ||
|
||
if (!$this->prettyName || $this->prettyPrefix) { | ||
$cacheFile .= $this->hash; | ||
} | ||
|
||
if ($this->prettyPrefix) { | ||
$cacheFile .= '-'; | ||
} | ||
|
||
if ($this->prettyName) { | ||
$cacheFile .= $this->prettyName; | ||
} | ||
|
||
$cacheFile .= '.'.$type; | ||
|
||
// If the files does not exists, save it | ||
$image = $this; | ||
|
||
// Target file should be younger than all the current image | ||
// dependencies | ||
$conditions = array( | ||
'younger-than' => $this->getDependencies() | ||
); | ||
|
||
// The generating function | ||
$generate = function ($target) use ($image, $type, $quality) { | ||
$result = $image->save($target, $type, $quality); | ||
|
||
if ($result != $target) { | ||
throw new GenerationError($result); | ||
} | ||
|
||
self::getGrav()->fireEvent('onImageMediumSaved', new Event(['image' => $target])); | ||
}; | ||
|
||
// Asking the cache for the cacheFile | ||
try { | ||
$file = $this->cache->getOrCreateFile($cacheFile, $conditions, $generate, $actual); | ||
} catch (GenerationError $e) { | ||
$file = $e->getNewFile(); | ||
} | ||
|
||
if ($actual) { | ||
return $file; | ||
} else { | ||
return $this->getFilename($file); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Grav\Common\Twig; | ||
|
||
use Grav\Common\GravTrait; | ||
|
||
/** | ||
* The Twig Environment class is a wrapper that handles configurable permissions | ||
* for the Twig cache files | ||
* | ||
* @author RocketTheme | ||
* @license MIT | ||
*/ | ||
class TraceableTwigEnvironment extends \DebugBar\Bridge\Twig\TraceableTwigEnvironment | ||
{ | ||
use WriteCacheFileTrait; | ||
} |
Oops, something went wrong.