mirror of
https://github.com/getgrav/grav.git
synced 2025-10-26 07:56:07 +01:00
renamed Asset/Assets to Medium/Media
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
title: Assets
|
||||
title: Media
|
||||
validation: loose
|
||||
|
||||
form:
|
||||
@@ -1,58 +1,58 @@
|
||||
jpg:
|
||||
type: image
|
||||
thumb: assets/thumb-jpg.png
|
||||
thumb: thumb-jpg.png
|
||||
mime: image/jpeg
|
||||
jpeg:
|
||||
type: image
|
||||
thumb: assets/thumb-jpeg.png
|
||||
thumb: thumb-jpeg.png
|
||||
mime: image/jpeg
|
||||
png:
|
||||
type: image
|
||||
thumb: assets/thumb-png.png
|
||||
thumb: thumb-png.png
|
||||
mime: image/png
|
||||
gif:
|
||||
type: image
|
||||
thumb: assets/thumb-gif.png
|
||||
thumb: thumb-gif.png
|
||||
mime: image/gif
|
||||
|
||||
mp4:
|
||||
type: video
|
||||
thumb: assets/thumb-mp4.png
|
||||
thumb: thumb-mp4.png
|
||||
mime: video/mp4
|
||||
mov:
|
||||
type: video
|
||||
thumb: assets/thumb-mov.png
|
||||
thumb: thumb-mov.png
|
||||
mime: video/quicktime
|
||||
m4v:
|
||||
type: video
|
||||
thumb: assets/thumb-m4v.png
|
||||
thumb: thumb-m4v.png
|
||||
mime: video/x-m4v
|
||||
swf:
|
||||
type: video
|
||||
thumb: assets/thumb-swf.png
|
||||
thumb: thumb-swf.png
|
||||
mime: video/x-flv
|
||||
|
||||
txt:
|
||||
type: file
|
||||
thumb: assets/thumb-txt.png
|
||||
thumb: thumb-txt.png
|
||||
mime: text/plain
|
||||
doc:
|
||||
type: file
|
||||
thumb: assets/thumb-doc.png
|
||||
thumb: thumb-doc.png
|
||||
mime: application/msword
|
||||
html:
|
||||
type: file
|
||||
thumb: assets/thumb-html.png
|
||||
thumb: thumb-html.png
|
||||
mime: text/html
|
||||
pdf:
|
||||
type: file
|
||||
thumb: assets/thumb-pdf.png
|
||||
thumb: thumb-pdf.png
|
||||
mime: application/pdf
|
||||
zip:
|
||||
type: file
|
||||
thumb: assets/thumb-zip.png
|
||||
thumb: thumb-zip.png
|
||||
mime: application/zip
|
||||
gz:
|
||||
type: file
|
||||
thumb: assets/thumb-gz.png
|
||||
thumb: thumb-gz.png
|
||||
mime: application/gzip
|
||||
@@ -20,8 +20,8 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
/**
|
||||
* Magic setter method
|
||||
*
|
||||
* @param mixed $offset Asset name value
|
||||
* @param mixed $value Asset value
|
||||
* @param mixed $offset Medium name value
|
||||
* @param mixed $value Medium value
|
||||
*/
|
||||
public function __set($offset, $value)
|
||||
{
|
||||
@@ -31,8 +31,8 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
/**
|
||||
* Magic getter method
|
||||
*
|
||||
* @param mixed $offset Asset name value
|
||||
* @return mixed Asset value
|
||||
* @param mixed $offset Medium name value
|
||||
* @return mixed Medium value
|
||||
*/
|
||||
public function __get($offset)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ abstract class Getters implements \ArrayAccess, \Countable
|
||||
/**
|
||||
* Magic method to determine if the attribute is set
|
||||
*
|
||||
* @param mixed $offset Asset name value
|
||||
* @param mixed $offset Medium name value
|
||||
* @return boolean True if the value is set
|
||||
*/
|
||||
public function __isset($offset)
|
||||
|
||||
@@ -7,13 +7,13 @@ use Grav\Config;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* Assets is a holder object that contains references to the assets of page. This object is created and
|
||||
* populated during the getAssets() method in the Pages object
|
||||
* Media is a holder object that contains references to the media of page. This object is created and
|
||||
* populated during the getMedia() method in the Pages object
|
||||
*
|
||||
* @author RocketTheme
|
||||
* @license MIT
|
||||
*/
|
||||
class Assets extends Getters
|
||||
class Media extends Getters
|
||||
{
|
||||
protected $gettersVariable = 'instances';
|
||||
protected $path;
|
||||
@@ -48,25 +48,25 @@ class Assets extends Getters
|
||||
$filename = $info->getFilename();
|
||||
list($basename, $ext, $meta) = $this->getFileParts($filename);
|
||||
|
||||
// Get asset instance creating it if it didn't exist.
|
||||
$asset = $this->get("{$basename}.{$ext}", true);
|
||||
if (!$asset) {
|
||||
// Get medium instance creating it if it didn't exist.
|
||||
$medium = $this->get("{$basename}.{$ext}", true);
|
||||
if (!$medium) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Assign meta files to the asset.
|
||||
// Assign meta files to the medium.
|
||||
if ($meta) {
|
||||
$asset->addMetaFile($meta);
|
||||
$medium->addMetaFile($meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get asset by basename and extension.
|
||||
* Get medium by basename and extension.
|
||||
*
|
||||
* @param string $filename
|
||||
* @param bool $create
|
||||
* @return Asset|null
|
||||
* @return Medium|null
|
||||
*/
|
||||
public function get($filename, $create = false)
|
||||
{
|
||||
@@ -78,8 +78,8 @@ class Assets extends Getters
|
||||
/** @var Config $config */
|
||||
$config = Registry::get('Config');
|
||||
|
||||
// Check if asset type has been configured.
|
||||
$params = $config->get("assets.{$ext}");
|
||||
// Check if medium type has been configured.
|
||||
$params = $config->get("media.{$ext}");
|
||||
if (!$params) {
|
||||
return null;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class Assets extends Getters
|
||||
$filePath = $this->path . '/' . $filename;
|
||||
$params += array(
|
||||
'type' => 'file',
|
||||
'thumb' => 'assets/thumb.png',
|
||||
'thumb' => 'media/thumb.png',
|
||||
'mime' => 'application/octet-stream',
|
||||
'name' => $filename,
|
||||
'filename' => $filename,
|
||||
@@ -108,16 +108,16 @@ class Assets extends Getters
|
||||
}
|
||||
}
|
||||
|
||||
$this->add(new Asset($params));
|
||||
$this->add(new Medium($params));
|
||||
}
|
||||
|
||||
return isset($this->instances[$filename]) ? $this->instances[$filename] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all assets.
|
||||
* Get a list of all media.
|
||||
*
|
||||
* @return array|Asset[]
|
||||
* @return array|Medium[]
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
@@ -125,9 +125,9 @@ class Assets extends Getters
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all image assets.
|
||||
* Get a list of all image media.
|
||||
*
|
||||
* @return array|Asset[]
|
||||
* @return array|Medium[]
|
||||
*/
|
||||
public function images()
|
||||
{
|
||||
@@ -135,9 +135,9 @@ class Assets extends Getters
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all video assets.
|
||||
* Get a list of all video media.
|
||||
*
|
||||
* @return array|Asset[]
|
||||
* @return array|Medium[]
|
||||
*/
|
||||
public function videos()
|
||||
{
|
||||
@@ -145,9 +145,9 @@ class Assets extends Getters
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all file assets.
|
||||
* Get a list of all file media.
|
||||
*
|
||||
* @return array|Asset[]
|
||||
* @return array|Medium[]
|
||||
*/
|
||||
public function files()
|
||||
{
|
||||
@@ -9,7 +9,7 @@ use Grav\Common\Registry;
|
||||
use Gregwar\Image\Image as ImageFile;
|
||||
|
||||
/**
|
||||
* The Image asset holds information related to an individual image. These are then stored in the Assets object.
|
||||
* The Image medium holds information related to an individual image. These are then stored in the Media object.
|
||||
*
|
||||
* @author RocketTheme
|
||||
* @license MIT
|
||||
@@ -26,13 +26,13 @@ use Gregwar\Image\Image as ImageFile;
|
||||
* @property string $mime
|
||||
* @property int $modified
|
||||
*
|
||||
* Asset can have up to 3 files:
|
||||
* - video.mov Asset file itself.
|
||||
* - video.mov.meta.yaml Metadata for the asset.
|
||||
* - video.mov.thumb.jpg Thumbnail image for the asset.
|
||||
* Medium can have up to 3 files:
|
||||
* - video.mov Medium file itself.
|
||||
* - video.mov.meta.yaml Metadata for the medium.
|
||||
* - video.mov.thumb.jpg Thumbnail image for the medium.
|
||||
*
|
||||
*/
|
||||
class Asset extends Data
|
||||
class Medium extends Data
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
@@ -126,7 +126,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <img> tag from the asset.
|
||||
* Returns <img> tag from the medium.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $class
|
||||
@@ -146,7 +146,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML markup from the asset.
|
||||
* Return HTML markup from the medium.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $class
|
||||
@@ -184,7 +184,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Return lightbox HTML for the asset.
|
||||
* Return lightbox HTML for the medium.
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
@@ -198,7 +198,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Return link HTML for the asset.
|
||||
* Return link HTML for the medium.
|
||||
*
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
@@ -264,7 +264,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets asset image, resets image manipulation operations.
|
||||
* Gets medium image, resets image manipulation operations.
|
||||
*
|
||||
* @param string $variable
|
||||
* @return $this
|
||||
@@ -284,7 +284,7 @@ class Asset extends Data
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta file for the asset.
|
||||
* Add meta file for the medium.
|
||||
*
|
||||
* @param $type
|
||||
* @return $this
|
||||
@@ -52,7 +52,7 @@ class Page
|
||||
protected $content;
|
||||
protected $raw_content;
|
||||
protected $pagination;
|
||||
protected $assets;
|
||||
protected $media;
|
||||
protected $title;
|
||||
protected $max_count;
|
||||
protected $menu;
|
||||
@@ -316,7 +316,7 @@ class Page
|
||||
|
||||
$this->content = $content;
|
||||
|
||||
$this->assets();
|
||||
$this->media();
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
@@ -348,17 +348,17 @@ class Page
|
||||
if ($name == 'type') {
|
||||
return basename($this->name(), '.md');
|
||||
}
|
||||
if ($name == 'assets') {
|
||||
return $this->assets()->all();
|
||||
if ($name == 'media') {
|
||||
return $this->media()->all();
|
||||
}
|
||||
if ($name == 'assets.file') {
|
||||
return $this->assets()->files();
|
||||
if ($name == 'media.file') {
|
||||
return $this->media()->files();
|
||||
}
|
||||
if ($name == 'assets.video') {
|
||||
return $this->assets()->videos();
|
||||
if ($name == 'media.video') {
|
||||
return $this->media()->videos();
|
||||
}
|
||||
if ($name == 'assets.image') {
|
||||
return $this->assets()->images();
|
||||
if ($name == 'media.image') {
|
||||
return $this->media()->images();
|
||||
}
|
||||
|
||||
$path = explode('.', $name);
|
||||
@@ -536,29 +536,29 @@ class Page
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and sets the associated assets as found in the page folder.
|
||||
* Gets and sets the associated media as found in the page folder.
|
||||
*
|
||||
* @param Assets $var Representation of associated assets.
|
||||
* @return Assets Representation of associated assets.
|
||||
* @param Media $var Representation of associated media.
|
||||
* @return Media Representation of associated media.
|
||||
*/
|
||||
public function assets($var = null)
|
||||
public function media($var = null)
|
||||
{
|
||||
/** @var Cache $cache */
|
||||
$cache = Registry::get('Cache');
|
||||
|
||||
if ($var) {
|
||||
$this->assets = $var;
|
||||
$this->media = $var;
|
||||
}
|
||||
if ($this->assets === null) {
|
||||
// Use cached assets if possible.
|
||||
$assets_cache_id = md5('assets'.$this->id());
|
||||
if (!$assets = $cache->fetch($assets_cache_id)) {
|
||||
$assets = new Assets($this->path());
|
||||
$cache->save($assets_cache_id, $assets);
|
||||
if ($this->media === null) {
|
||||
// Use cached media if possible.
|
||||
$media_cache_id = md5('media'.$this->id());
|
||||
if (!$media = $cache->fetch($media_cache_id)) {
|
||||
$media = new Media($this->path());
|
||||
$cache->save($media_cache_id, $media);
|
||||
}
|
||||
$this->assets = $assets;
|
||||
$this->media = $media;
|
||||
}
|
||||
return $this->assets;
|
||||
return $this->media;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -169,7 +169,7 @@ class Twig
|
||||
$twig_vars = $this->twig_vars;
|
||||
|
||||
$twig_vars['page'] = $item;
|
||||
$twig_vars['assets'] = $item->assets();
|
||||
$twig_vars['media'] = $item->media();
|
||||
$twig_vars['header'] = $item->header();
|
||||
|
||||
// Get Twig template layout
|
||||
|
||||
Reference in New Issue
Block a user