Modifiche sistema di render e contenuti multimediali;

Aggiunto renderer PDF;
This commit is contained in:
Riccardo Di Dato
2016-03-04 12:26:30 +01:00
parent 074c9d9ff9
commit 1a4a85f4da
16 changed files with 120 additions and 37 deletions
+4 -4
View File
@@ -59,13 +59,13 @@ class MediaModel extends Model implements MediaInterface{
}
}
public function asText(){
return $this->mediaRenderer->asText();
public function asText(array $opts = array()){
return $this->mediaRenderer->asText($opts);
}
public function renderMedia(){
public function renderMedia(array $opts = array()){
// var_dump($this->mediaRenderer);
$this->mediaRenderer->render();
$this->mediaRenderer->render($opts);
}
public function getType(){
+1 -1
View File
@@ -15,7 +15,7 @@ class NotiziaBlock {
$mainMedia = DaoMediaHandler::getMainMediaFromModel($this->notizia);
$mediaText = "";
if (!is_null($mainMedia)){
$mediaText = $mainMedia->asText();
$mediaText = $mainMedia->asText(array("clickable"=>true));
}
$rval = '<div class="notiziaBlock">';
$rval.= '<div class="notiziaMainMedia">'.$mediaText.'</div>';
@@ -1,6 +1,25 @@
<?php
interface MediaRendererInterface{
const SIZE_SMALL = 1;
const SIZE_SMALL_W = 160;
const SIZE_SMALL_H = 120;
const SIZE_MEDIUM = 2;
const SIZE_MEDIUM_W = 240;
const SIZE_MEDIUM_H = 205;
const SIZE_BIG = 3;
const SIZE_BIG_H = 800;
const SIZE_BIG_W = 600;
const SIZE_ORIGINAL = 4;
const SIZE_ORIGINAL_H = null;
const SIZE_ORIGINAL_W = null;
public function asText(array $opt = array()) ;
public function render(array $opt = array());
+2
View File
@@ -13,6 +13,8 @@ require_once(dirname(__FILE__)."/MediaHandlerInterface.php");
require_once(dirname(__FILE__)."/MediaRendererInterface.php");
require_once(dirname(__FILE__)."/mediaRenderers/MediaRenderer.php");
require_once(dirname(__FILE__)."/mediaRenderers/MediaHtml5.php");
require_once(dirname(__FILE__)."/mediaRenderers/MediaImage.php");
require_once(dirname(__FILE__)."/mediaRenderers/MediaPdf.php");
@@ -1,6 +1,6 @@
<?php
class MediaHtml5 implements MediaRendererInterface{
class MediaHtml5 extends MediaRenderer{
private $code;
public function __construct($code){
@@ -8,7 +8,16 @@ class MediaHtml5 implements MediaRendererInterface{
}
public function asText(array $opt = array()){
return $this->code;
$size = MediaRendererInterface::SIZE_ORIGINAL;
$width = '';
$height = '';
if(array_key_exists("size", $opt) && array_key_exists($opt["size"], self::$SIZES)){
$size = $opt["size"];
$width = 'height:'.self::$SIZES[$size]["width"].'px;';
$height = 'width:'.self::$SIZES[$size]["height"].'px;';
}
return '<div style="'.$height.$width.'overflow:hidden;">'.$this->code.'</div>';
}
public function render(array $opt = array()){
@@ -1,14 +1,16 @@
<?php
class MediaImage implements MediaRendererInterface{
class MediaImage extends MediaRenderer{
private $id;
public function __construct($id){
$this->id = $id;
}
public function asText(array $opt = array()){
$size = "small";
if(sizeof($opt)>0 && array_key_exists("size", $opt)){
$size = MediaRendererInterface::SIZE_ORIGINAL;
if(array_key_exists("size", $opt) && array_key_exists($opt["size"], self::$SIZES)){
$size = $opt["size"];
}
return '<img src="'.GUIHandler::getBaseUrl().'getImage.php?id='.$this->id.'&size='.$size.'"/>';
@@ -1,6 +1,6 @@
<?php
class MediaLocalVideo implements MediaRendererInterface{
class MediaLocalVideo extends MediaRenderer{
private $id;
public function __construct($model){
+13 -2
View File
@@ -1,6 +1,6 @@
<?php
class MediaPdf implements MediaRendererInterface{
class MediaPdf extends MediaRenderer{
private $id;
public function __construct($model){
@@ -8,7 +8,18 @@ class MediaPdf implements MediaRendererInterface{
}
public function asText(array $opt = array()){
return GlobalVariables::get("config")->paths->media."/".$this->id.".pdf";
$clickable = false;
if (array_key_exists("clickable", $opt)){
$clickable = $opt["clickable"];
}
if ($clickable){
return '<a href="'.GUIHandler::getBaseUrl().'getPDF.php?id='.$this->id.'"><img src="'.GUIHandler::getBaseUrl().'images/pdf.png"/></a>';
}
else {
return '<img src="'.GUIHandler::getBaseUrl().'images/pdf.png"/>';
}
// return GlobalVariables::get("config")->paths->media."/".$this->id.".pdf";
}
public function render(array $opt = array()){
@@ -0,0 +1,16 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 04/mar/2016
*/
abstract class MediaRenderer implements MediaRendererInterface{
public static $SIZES = array(
MediaRendererInterface::SIZE_SMALL => array("width"=>MediaRendererInterface::SIZE_SMALL_W,"height"=>MediaRendererInterface::SIZE_SMALL_H),
MediaRendererInterface::SIZE_MEDIUM => array("width"=>MediaRendererInterface::SIZE_MEDIUM_W,"height"=>MediaRendererInterface::SIZE_MEDIUM_H),
MediaRendererInterface::SIZE_BIG => array("width"=>MediaRendererInterface::SIZE_BIG_W,"height"=>MediaRendererInterface::SIZE_BIG_H),
MediaRendererInterface::SIZE_ORIGINAL => array("width"=>MediaRendererInterface::SIZE_ORIGINAL_W,"height"=>MediaRendererInterface::SIZE_ORIGINAL_H)
);
}
?>
@@ -1,6 +1,6 @@
<?php
class MediaYoutube implements MediaRendererInterface{
class MediaYoutube extends MediaRenderer{
private $link;
public function __construct($model){
+1 -1
View File
@@ -97,7 +97,7 @@ try{
<div><span class="label">Tipo</span><?php echo $bannerTypeString;?></div>
</div>
<div>
<?php $media->renderMedia(); ?>
<?php $media->renderMedia(array("size"=>MediaRenderer::SIZE_MEDIUM)); ?>
</div>
</div>
<div class="bannerMenuContainer">
+1 -1
View File
@@ -86,7 +86,7 @@ HTMLHelper::generateAdminHead();
<?php if(sizeof($medias)>0){
foreach ($medias as $media){
if($media->id == $notizia->getMainMediaReference()){?>
<div style="display:background-color:yellow;" class="mediaElement" idref="<?php echo $media->id;?>">
<div style="" class="mediaElement mainElement" idref="<?php echo $media->id;?>">
<?php }
else{?>
<div class="mediaElement" idref="<?php echo $media->id;?>">
+13 -18
View File
@@ -6,20 +6,15 @@ Creation Date: 14/gen/2016
require_once(dirname(__FILE__)."/load.php");
$sizes = array(
"large"=>array("width"=>800,"height"=>600),
"small"=>array("width"=>160,"height"=>120)
);
// $sizes = array(
// "large"=>array("width"=>800,"height"=>600),
// "small"=>array("width"=>160,"height"=>120)
// );
if (array_key_exists("id",$_GET)) {
if (array_key_exists('size',$_GET)){
$size=$_GET['size'];
}
else {
$size = "original";
}
if (!array_key_exists($size, $sizes) || strcmp("original", $size)==0){
$size = null;
$size = MediaImage::SIZE_ORIGINAL;
if (array_key_exists('size',$_GET) && array_key_exists(intval($_GET["size"]), MediaImage::$SIZES)){
$size=intval($_GET['size']);
}
$img = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
@@ -32,12 +27,12 @@ if (array_key_exists("id",$_GET)) {
$geom = $thumb->getimagegeometry();
if($img->extension != "gif"){
if (!is_null($size)){
if ($size!=MediaImage::SIZE_ORIGINAL){
if ($geom["width"]>=$geom["height"]){
$thumb->scaleimage($sizes[$size]["width"], 0,false);
$thumb->scaleimage(MediaImage::$SIZES[$size]["width"], 0,false);
}
else {
$thumb->scaleimage(0, $sizes[$size]["height"],false);
$thumb->scaleimage(0, MediaImage::$SIZES[$size]["height"],false);
}
}
@@ -47,13 +42,13 @@ if (array_key_exists("id",$_GET)) {
else{
$thumb = $thumb->coalesceimages();
if (!is_null($size)){
if ($size!=MediaImage::SIZE_ORIGINAL){
foreach ($thumb as $frame){
if ($geom["width"]>=$geom["height"]){
$thumb->scaleimage($sizes[$size]["width"], 0,false);
$thumb->scaleimage(MediaImage::$SIZES[$size]["width"], 0,false);
}
else {
$thumb->scaleimage(0, $sizes[$size]["height"],false);
$thumb->scaleimage(0, MediaImage::$SIZES[$size]["height"],false);
}
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
/*
Author: Riccardo Di Dato
Creation Date: 04/mar/2016
*/
require_once(dirname(__FILE__). "/load.php");
if (array_key_exists("id",$_GET)) {
$pdfModel = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$_GET['id']));
$id = $_GET["id"];
if (!is_null($pdfModel)){
$localFilePath = GlobalVariables::get("config")->paths->media."/".$id.".pdf";
$exposedFilePath = GlobalVariables::get("config")->paths->xsendfile."/".$id.".pdf";
if (!SFSManager::fileExists($exposedFilePath)){
SystemController::shellExec("ln",'-s "'.$localFilePath.'" "'.$exposedFilePath.'"');
}
header('X-Sendfile: '.$exposedFilePath.'');
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . basename($exposedFilePath) . '"');
}
}
?>
+3 -2
View File
@@ -84,8 +84,9 @@ div.notiziaStat >div > div {text-align:center;}
| | | | __/ (_| | | (_| |
|_| |_|\___|\__,_|_|\__,_|
*/
.mediaElement{display:inline-block; background-color:yellow;padding:15px;}
*/
.mediaElement.mainElement{background-color:yellow;}
.mediaElement{display:inline-block; padding:15px;}
.mediaElement.selected {opacity:0.4;background-color:orange;}
/*
+2 -1
View File
@@ -74,7 +74,8 @@ body{font-family:lato, arial;}
.ansa{border:solid #d6d6d6 1px;border-left:0px;border-right:0px;border-top:0px;height:180px;}
.ansa> div {display:inline-block;vertical-align:top;}
.ansaImage{display:inline-block;margin:15px 7px;width:150px;overflow:hidden;text-align:center;}
.ansaImage{display:inline-block;margin:15px 7px;width:150px; height:113px; overflow:hidden;text-align:center;}
.ansaImage > * {max-height:100%;max-width:100%;}
.ansaNews{margin-top:2px;width:330px;cursor:pointer;}
.ansaTitolo{font-weight:bold;font-size:20px;text-align:justify;}
.ansaSottotitolo{font-size:17px;color:#767676;text-align:justify;}