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){ $matches = array(); // var_dump(PostHandler::get("data")); if ( preg_match("~^https[:]//youtu\.be/(.+)$~", trim(PostHandler::get("data")), $matches) ){ $saveable->link = $matches[1]; } else if (preg_match("~https[:]//www\.youtube\.com/embed/([^\"]+)[\"]~", trim(PostHandler::get("data")), $matches)){ $saveable->link = $matches[1]; } else if (preg_match("~https[:]//www\.youtube\.com/watch[?]v[=](.+)$~", trim(PostHandler::get("data")), $matches)){ $saveable->link = $matches[1]; } else { throw new GUIException("Formato del link youtube non valido"); } // $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 { $file = $_FILES['data']['tmp_name']; $info = pathinfo($_FILES['data']['name']); // $file = PostHandler::get("data"); $media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file,$info["extension"]); } 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 = ' '; $formYoutube = 'url: '; $formHtml = 'Inserire html: '; }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(); ?>
Selezionare tipo multimedia:
// if(strcmp($mediaTypeSaved, MediaModel::TYPE_YOUTUBE)==0){ echo $formYoutube; } else if(strcmp($mediaTypeSaved, MediaModel::TYPE_HTML5)==0){ echo $formHtml; } else{ echo $formFile; } ?>
Invia Back