MediaRender cambiati per i diversi mediaTypes
Aggiunta funzione per savare media non file based Fixata editNotizie che non salvava l'author addMultimedia funzionante (da testare bene)
This commit is contained in:
@@ -151,7 +151,13 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Richiede un saveable object con almeno la proprietà mediaType e il path del file
|
||||
*
|
||||
* @param stdClass $saveableObj
|
||||
* @param string $filePath
|
||||
* @return MediaModel
|
||||
*/
|
||||
public static function createNewFileBasedMedia($saveableObj, $filePath){
|
||||
$basepath = GlobalVariables::get("config")->paths->media;
|
||||
$info = pathinfo($filePath);
|
||||
@@ -162,6 +168,17 @@ class DaoMediaHandler implements MediaHandlerInterface{
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Richiede un saveable object con la proprietà mediaType settata
|
||||
*
|
||||
* @param stdClass $saveable
|
||||
* @return MediaModel
|
||||
*/
|
||||
public static function createNewTextBasedMedia($saveable){
|
||||
$media = new MediaModel($saveable);
|
||||
return $media;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -6,14 +6,12 @@ class MediaImage implements MediaRendererInterface{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function asText(){
|
||||
return '<a href="'.GUIHandler::getBaseUrl().'getImage.php?id='.$this->id.'&size=original">'.
|
||||
'<img src="'.GUIHandler::getBaseUrl().'getImage.php?id='.$this->id.'&size=small"/>'.
|
||||
'</a>';
|
||||
public function asText($size){
|
||||
return '<img src="'.GUIHandler::getBaseUrl().'getImage.php?id='.$this->id.'&size='.$size.'"/>';
|
||||
}
|
||||
|
||||
public function render(){
|
||||
echo $this->asText();
|
||||
public function render($size = "small"){
|
||||
echo $this->asText($size);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
class MediaLocalVideo implements MediaRendererInterface{
|
||||
private $modelRef;
|
||||
private $id;
|
||||
|
||||
public function __construct(MediaModel $model){
|
||||
$this->modelRef = $model;
|
||||
public function __construct($id){
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function asText(){
|
||||
return $this->modelRef->path;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function render(){
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
class MediaPdf implements MediaRendererInterface{
|
||||
private $modelRef;
|
||||
private $id;
|
||||
|
||||
public function __construct(MediaModel $model){
|
||||
$this->modelRef = $model;
|
||||
public function __construct($id){
|
||||
$this->id = $model;
|
||||
}
|
||||
|
||||
public function asText(){
|
||||
return $this->modelRef->path;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function render(){
|
||||
|
||||
@@ -8,7 +8,9 @@ class MediaYoutube implements MediaRendererInterface{
|
||||
}
|
||||
|
||||
public function asText(){
|
||||
return $this->link;
|
||||
return '<iframe width="420" height="315"
|
||||
src=\"'.$this->link.'?autoplay=0\">
|
||||
</iframe>';
|
||||
}
|
||||
|
||||
public function render(){
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
require_once(dirname(__FILE__)."/../load.php");
|
||||
|
||||
GUIHandler::generateHtmlHeaders(array(),true);
|
||||
|
||||
if (!AdminLoginManager::isLogged()){
|
||||
GUIHandler::redirect("admin/login.php");
|
||||
}
|
||||
else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR) &&
|
||||
!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE)){
|
||||
GUIHandler::redirect("admin/index.php");
|
||||
}
|
||||
|
||||
try{
|
||||
$error = "";
|
||||
$notiziaId = PostHandler::get("id");
|
||||
|
||||
$notizia = new stdClass();
|
||||
if(is_null($notiziaId) || strcmp($notiziaId, "")==0){
|
||||
throw new CoreException("Trying to add a media to an invalid model with id '".$notiziaId. "'");
|
||||
}
|
||||
else{
|
||||
$mediaTypeSaved = PostHandler::get("mediaType");
|
||||
if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "save")==0){
|
||||
$notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$notiziaId));
|
||||
|
||||
$file = "";
|
||||
|
||||
$mediaType = PostHandler::get("mediaType");
|
||||
if(strcmp($mediaType, "")!=0){
|
||||
$tmp = array();
|
||||
$saveable = new stdClass();
|
||||
$saveable->mediaType = $mediaType;
|
||||
if(strcmp($mediaType,MediaModel::TYPE_YOUTUBE)==0){
|
||||
$saveable->link = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewTextBasedMedia($saveable);
|
||||
}
|
||||
else if(strcmp($mediaType,MediaModel::TYPE_HTML5)==0){
|
||||
$saveable->code = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewTextBasedMedia($saveable);
|
||||
}
|
||||
else {
|
||||
$saveable->path = PostHandler::get("data");
|
||||
$file = $_FILES['data']['tmp_name'];
|
||||
// $file = PostHandler::get("data");
|
||||
$media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file);
|
||||
}
|
||||
|
||||
if(!is_null($media)){
|
||||
GlobalVariables::get("dao")->save($media);
|
||||
DaoMediaHandler::addMedia($notizia, $media);
|
||||
GlobalVariables::get("dao")->save($notizia);
|
||||
}
|
||||
else{
|
||||
throw new Exception("Cannot save a null media in the news with id '".$notiziaId."'");
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new Exception("Invalid mediaType '".$mediaType."' while trying to add the media in addMultimedia");
|
||||
}
|
||||
|
||||
GUIHandler::redirectPost("admin/homeMultimedia.php",array("id"=>$notiziaId));
|
||||
}
|
||||
}
|
||||
|
||||
$formFile = '<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
||||
<input type="file" name="data"/>';
|
||||
|
||||
$formYoutube = 'url: <input type="text" name ="data"/>';
|
||||
|
||||
$formHtml = 'Inserire html: <textarea type="text" name ="data"/ rows="5" cols="30"></textarea>';
|
||||
|
||||
}catch(GUIException $ex){
|
||||
$error = $ex->getMessage();
|
||||
}catch (Exception $exec){
|
||||
LoggingFacilityManager::getLogger("gui")->log(LoggingFacility::$LEVEL_ERROR, $exec->getMessage());
|
||||
$error = "Si è verificato un errore inaspettato durante l'esecuzione della pagina. Se l'errore persiste contattare il supporto tecnico.";
|
||||
}
|
||||
|
||||
MenuGenerator::generateMenu();
|
||||
HTMLHelper::generateAdminHead();
|
||||
?>
|
||||
<div>
|
||||
<?php echo $error;?>
|
||||
<div>
|
||||
<form enctype="multipart/form-data" id="loadFile" method="POST">
|
||||
<div style="margin:15px 5px;">Selezionare tipo multimedia:
|
||||
<select id="mediaType" name="mediaType">
|
||||
<?php foreach (MediaModel::$MEDIA_TYPES as $mediaType=>$data){
|
||||
if(strcmp($mediaTypeSaved,$mediaType)==0){?>
|
||||
<option value="<?php echo $mediaType;?>" selected="selected">
|
||||
<?php
|
||||
}
|
||||
else{?>
|
||||
<option value="<?php echo $mediaType;?>">
|
||||
<?php
|
||||
}?>
|
||||
<?php echo $data["label"];?></option>
|
||||
<?php }?>
|
||||
</select>
|
||||
</div>
|
||||
<div style="margin:15px 5px;"><?php
|
||||
// <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
||||
// <input type="file" name="userFile"/>
|
||||
if(strcmp($mediaTypeSaved, MediaModel::TYPE_YOUTUBE)==0){
|
||||
echo $formYoutube;
|
||||
}
|
||||
else if(strcmp($mediaTypeSaved, MediaModel::TYPE_HTML5)==0){
|
||||
echo $formHtml;
|
||||
}
|
||||
else{
|
||||
echo $formFile;
|
||||
}
|
||||
?> <input type="hidden" name="id" value="<?php echo $notiziaId;?>" />
|
||||
<input type="hidden" name="action" value=""/>
|
||||
</form>
|
||||
<div style="margin:15px 5px;">
|
||||
<a href="#" id="submit" >Invia</a>
|
||||
<a href="#" id="back" >Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(event){
|
||||
$("#submit").click(function(event){
|
||||
$("form#loadFile input[type=hidden][name=action]").val("save");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#mediaType").change(function (event){
|
||||
$("form#loadFile input[type=hidden][name=action]").val("change");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
|
||||
$("#back").click(function(event){
|
||||
$("form#loadFile").attr("action","homeMultimedia.php");
|
||||
$("form#loadFile").submit();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -51,7 +51,12 @@ try{
|
||||
$notizia->titolo = PostHandler::get("titolo");
|
||||
$notizia->sottotitolo = PostHandler::get("sottotitolo");
|
||||
$notizia->testo = PostHandler::get("testo");
|
||||
$notizia->about->author = PostHandler::get("author");
|
||||
if(strcmp(PostHandler::get("author"), "")==0){
|
||||
$notizia->about->author = AdminLoginManager::getLogged()->nome." ".AdminLoginManager::getLogged()->cognome;
|
||||
}
|
||||
else{
|
||||
$notizia->about->author = PostHandler::get("author");
|
||||
}
|
||||
$dateString = PostHandler::get("data")." ".PostHandler::get("time");
|
||||
if(!preg_match("/^[0-9]{2}[-][0-9]{2}[-][0-9]{4} [0-9]{2}[:][0-9]{2}$/", $dateString)){
|
||||
throw new GUIException("Il formato della data inserita non è corretto. Per favore segui il seguente formato Date: dd-mm-yyyy hh:ii");
|
||||
@@ -65,7 +70,6 @@ try{
|
||||
|
||||
if(!$edit){
|
||||
$notizia->status = NotiziaModel::STATUS_PENDING;
|
||||
$notizia->about->author = AdminLoginManager::getLogged()->nome." ".AdminLoginManager::getLogged()->cognome;
|
||||
$notizia->about->owner = AdminLoginManager::getLogged()->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,31 +52,42 @@ HTMLHelper::generateAdminHead();
|
||||
<div>
|
||||
<?php echo $error;?>
|
||||
<div class="notiziaContainer">
|
||||
<?php foreach ($medias as $media){?>
|
||||
<div style="display:inline-block;">
|
||||
<?php $media->renderMedia();}?>
|
||||
<?php if(sizeof($medias)>0){
|
||||
foreach ($medias as $media){?>
|
||||
<div style="display:inline-block; margin:5px 15px" class="mediaElement">
|
||||
<?php $media->renderMedia();?>
|
||||
</div>
|
||||
<?php }
|
||||
}?>
|
||||
</div>
|
||||
<div class="notiziaMenu">
|
||||
<ul>
|
||||
<li><a href="#" id="mediaMenu_addMedia">Aggiungi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_rmMedia">Rimuovi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_setMain">Setta Media Principale</a></li>
|
||||
<li><a href="#" id="mediaMenu_unsetMain">Rimuovi Media Principale</a></li>
|
||||
<li><a href="#" id="mediaMenu_back">Back</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="#" id="mediaMenu_addMedia">Aggiungi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_rmMedia">Rimuovi Multimedia</a></li>
|
||||
<li><a href="#" id="mediaMenu_setMain">Setta Media Principale</a></li>
|
||||
<li><a href="#" id="mediaMenu_unsetMain">Rimuovi Media Principale</a></li>
|
||||
<li><a href="#" id="mediaMenu_back">Back</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<form id="mediaForm" method="POST" action="">
|
||||
<input type="hidden" name="id" value="<?php echo $notiziaId;?>" />
|
||||
<input type="hidden" name="addMedia" value="" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(event){
|
||||
$("#mediaMenu_addMedia").click(function(event){
|
||||
$("form#mediaForm").attr("action","addMultimedia.php");
|
||||
$("form#mediaForm input[type=hidden][name=id]").val("<?php echo $notiziaId;?>");
|
||||
$("form#mediaForm input[type=hidden][name=addMedia]").val("true");
|
||||
$("form#mediaForm").submit();
|
||||
});
|
||||
|
||||
$("#mediaMenu_back").click(function(event){
|
||||
$("form#mediaForm").attr("action","homeNotizie.php");
|
||||
$("form#mediaForm input[type=hidden][name=id]").val("<?php echo $notiziaId;?>");
|
||||
$("form#mediaForm").submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -13,7 +13,7 @@
|
||||
#admin_menu ul ul{height:0px;}
|
||||
|
||||
.admin_head{margin-left:300px;}
|
||||
.admin_head + div{margin-left:300px; padding: 20px; position:relative;}
|
||||
.admin_head + div{margin-left:300px; padding: 20px; position:relative;min-height:50px;}
|
||||
|
||||
|
||||
table.dataTable th{text-align:left; }
|
||||
|
||||
Reference in New Issue
Block a user