mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
127 lines
1.9 KiB
PHP
127 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2013 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
abstract class media_abstract
|
|
{
|
|
/**
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $url;
|
|
|
|
/**
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $height;
|
|
|
|
/**
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $width;
|
|
|
|
const PORTRAIT = 'PORTRAIT';
|
|
const PAYSAGE = 'LANDSCAPE';
|
|
|
|
/**
|
|
*
|
|
* @param string $url
|
|
* @param int $width
|
|
* @param int $height
|
|
* @return media
|
|
*/
|
|
public function __construct($url, $width, $height)
|
|
{
|
|
$this->url = $url;
|
|
$this->height = (int) $height;
|
|
$this->width = (int) $width;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_random()
|
|
{
|
|
return md5(time() . mt_rand(100000, 999999));
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_url()
|
|
{
|
|
return $this->url;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return int
|
|
*/
|
|
public function get_width()
|
|
{
|
|
return $this->width;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return int
|
|
*/
|
|
public function get_height()
|
|
{
|
|
return $this->height;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_type()
|
|
{
|
|
return 'image';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_orientation()
|
|
{
|
|
if ($this->width > $this->height) {
|
|
return self::PAYSAGE;
|
|
} else {
|
|
return self::PORTRAIT;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_paysage()
|
|
{
|
|
return $this->get_orientation() == self::PAYSAGE;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_portrait()
|
|
{
|
|
return $this->get_orientation() == self::PORTRAIT;
|
|
}
|
|
}
|