file = ""; $this->preview = ""; $this->type = "unknown"; $this->width = 320; $this->height = 240; $this->maxWidth = 500; $this->maxHeight = 500; $this->setUploadDirectories(VIDEO_DIR, IMG_DIR); } /** @see BuildingBlock::install() */ //----------------------------------------------- function install(){ //----------------------------------------------- $query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_videoblock ( id INT not null AUTO_INCREMENT, file VARCHAR(128) not null, preview VARCHAR(128) not null, type ENUM('real','quicktime','windowsmedia','flash','unknown'), width INT not null, height INT not null, PRIMARY KEY(id) )"); $result = dbQuery($query); } /** @see BuildingBlock::load() */ //------------------------------------------------- function load(){ //------------------------------------------------- $query = sprintf("SELECT * FROM bruckm_videoblock WHERE id = %d", $this->id); $result = dbQuery($query); $line = mysqli_fetch_array($result, MYSQLI_ASSOC); $this->file = $line['file']; $this->preview = $line['preview']; $this->type = $line['type']; $this->width = $line['width']; $this->height = $line['height']; } /** @see BuildingBlock::doSave() */ //----------------------------------------------- function doSave(){ //----------------------------------------------- $query = sprintf("UPDATE bruckm_videoblock SET file = %s, preview = %s, type = %s, width = %d, height = %d WHERE id = %d", sqlstring($this->file), sqlstring($this->preview), sqlstring($this->type), sqlnum($this->width), sqlnum($this->height), $this->id); dbQuery($query); } /** @see BuildingBlock::doCreate() */ //----------------------------------------------- function doCreate(){ //----------------------------------------------- $query = sprintf("INSERT INTO bruckm_videoblock (file, type, width, height) VALUES (%s, %s, %d, %d)", sqlstring($this->file), sqlstring($this->type), sqlnum($this->width), sqlnum($this->height)); dbQuery($query); return mysql_insert_id(); } /** @see BuildingBlock::delete() */ //------------------------------------------------- function delete(){ //------------------------------------------------- $query = sprintf("DELETE FROM bruckm_videoblock WHERE id = %d", $this->id); dbQuery($query); @unlink($this->videoDir.$this->file); @unlink($this->previewDir.$this->preview); } /** @see BuildingBlock::update() */ //----------------------------------------------- function update(){ //----------------------------------------------- $this->width = $_POST["videoblock_width".$this->id]; $this->height = $_POST["videoblock_height".$this->id]; if(isset($_FILES["videoblock_file".$this->id]) && $_FILES["videoblock_file".$this->id]['error'] == UPLOAD_ERR_OK){ $this->file = $this->findName($this->videoDir, $_FILES["videoblock_file".$this->id]['name']); $this->uploadVideo($_FILES["videoblock_file".$this->id]); } if(isset($_FILES["videoblock_preview".$this->id]) && $_FILES["videoblock_preview".$this->id]['error'] == UPLOAD_ERR_OK){ $this->preview = $this->findName($this->previewDir, $_FILES["videoblock_preview".$this->id]['name']); $this->uploadPreview($_FILES["videoblock_preview".$this->id]); } } /** @see BuildingBlock::printContent() */ //----------------------------------------------- function printContent($position){ //----------------------------------------------- $t = new Template(CMS_TEMPLATE_DIR."videoblock.html"); $t->setVar("ID", $this->id); $t->setVar("POSITION", $position); $t->setVar("WIDTH", $this->width); $t->setVar("HEIGHT", $this->height); if(!empty($this->file) && file_exists($this->videoDir.$this->file)){ if ($this->type == "real") { $t->setVar("VIDEO", 'Video ansehen'); $t->removeBlock("UPLOADVIDEO"); } else if ($this->type == "quicktime") { $t->setVar("VIDEO", 'Video ansehen'); $t->removeBlock("UPLOADVIDEO"); } else if ($this->type == "windowsmedia") { $t->setVar("VIDEO", 'Video ansehen'); $t->removeBlock("UPLOADVIDEO"); } else if ($this->type == "flash") { $t->setVar("VIDEO", 'Video ansehen'); $t->removeBlock("UPLOADVIDEO"); } else { $t->setVar("VIDEO", 'Unbekannter Dateityp'); } } else{ $t->removeBlock("VIDEO"); } if(!empty($this->preview) && file_exists($this->previewDir.$this->preview)){ $t->setVar("PREVIEW", $this->previewDir . $this->preview); $t->removeBlock("UPLOADPREVIEW"); } else{ $t->removeBlock("PREVIEW"); } return $t->toString(); } /** @see BuildingBlock::publish() */ //---------------------------------------------- function publish(){ //---------------------------------------------- if(!file_exists($this->videoDir.$this->file)){ logError(3, "Video ".$this->videoDir.$this->file." doesn't exist", __FILE__, __LINE__); return ""; } $out = '
'; if(!empty($this->preview)){ $out .= 'Video öffnen'; } else{ $out .= 'Video: ' . $this->file; } $out .= '
'; return $out; } // === ADDITIONAL METHODS ======================================================== // /** shows the video in a separate window */ //------------------------------------------------ function show(){ //------------------------------------------------ $t = new Template("video.html"); if ($this->type == "real") { $t->setVar("VIDEO", $this->printReal($this->file)); } else if ($this->type == "quicktime") { $t->setVar("VIDEO", $this->printQuicktime($this->file)); } else if ($this->type == "windowsmedia") { $t->setVar("VIDEO", $this->printWindowsMedia($this->file)); } else if ($this->type == "flash") { $t->setVar("VIDEO", $this->printFlash($this->file)); } else { $t->setVar("VIDEO", "Video nicht gefunden"); } $t->parse(); } /** prints the source code for embedding a real video * @param path path */ //------------------------------------------------ function printReal($path) { //------------------------------------------------ $width = $this->width; $height = $this->height; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= 'id . '" '; $v .= 'width="' . $width . '" height="' . $height . '" />'; $v .= ''; return $v; } /** prints the source code for embedding a quicktime video * @param path path */ //------------------------------------------------ function printQuicktime($path) { //------------------------------------------------ $width = $this->width; $height = $this->height + 16; $v = ''; $v .= ''; $v .= ''; $v .= ''; $v .= 'width; $height = $this->height + 46; $v = ''; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= 'width; $height = $this->height; $v = 'width . '" height="' . $this->height . '" id="flv' . $this->id . '" align="top">'; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= ''; $v .= '

Download Flash Player

'; $v .= '
'; return $v; } /** uploads a video file * @param file $_FILES file data */ //------------------------------------------------ function uploadVideo($file){ //------------------------------------------------ $path = $this->videoDir . $this->file; if(file_exists($path)){ @unlink($path); } move_uploaded_file($file['tmp_name'], $path); @chmod($path, 0777); $type = substr($path, strrpos($path, ".") + 1); if ($type == "mov" || $type == "qt") { $this->type = "quicktime"; } else if ($type == "rm" || $type == "rmv" || $type == "rmvb") { $this->type = "real"; } else if ($type == "wmv") { $this->type = "windowsmedia"; } else if ($type == "flv") { $this->type = "flash"; } else { $this->type = "unknown"; } } /** uploads the preview image * @param file $_FILES file data */ //------------------------------------------------ function uploadPreview($file){ //------------------------------------------------ $path = $this->previewDir . $this->preview; if(file_exists($path)){ @unlink($path); } //resize image $imgSize = getImageSize($file['tmp_name']); if($imgSize[0] > $this->width || $imgSize[1] > $this->height){ switch($imgSize[2]){ case 1: //gif $original = imageCreateFromGif($file['tmp_name']); break; case 2: //jpg $original = imageCreateFromJpeg($file['tmp_name']); break; case 3: //png $original = imageCreateFromPng($file['tmp_name']); break; } $origWidth = $imgSize[0]; $origHeight = $imgSize[1]; $width = $origWidth; $height = $origHeight; if($width > $this->maxWidth){ $fact = $this->maxWidth / $origWidth; $width *= $fact; $height *= $fact; } if($height > $this->maxHeight){ $fact = $this->maxHeight / $height; $width *= $fact; $height *= $fact; } $small = imageCreateTrueColor($width,$height); imageCopyResampled($small, $original, 0, 0, 0, 0, $width, $height, $origWidth, $origHeight); switch($imgSize[2]){ case 1: if(!@imageGif($small, $path)){ logError(4, "Could not create gif image: $path", __FILE__, __LINE__); return ""; } break; case 2: if(!@imageJpeg($small, $path, 100)){ logError(4, "Could not create jpg image: $path", __FILE__, __LINE__); return ""; } break; case 3: if(!@imagePng($small, $path)){ logError(4, "Could not create png image: $path", __FILE__, __LINE__); return ""; } break; } imageDestroy($small); imageDestroy($original); @chmod($path, 0777); } else{ move_uploaded_file($file['tmp_name'], $path); @chmod($path, 0777); } } /** sets the output directories */ //----------------------------------------------- function setUploadDirectories($video, $preview){ //----------------------------------------------- $this->videoDir = $video; $this->previewDir = $preview; } /** finds a path that does not exist * @param dir target directory * @param name name of the source image * @return filename in the target directory that does not exist */ //----------------------------------------------- function findName($dir, $name){ //----------------------------------------------- $name = strtolower($name); $name = str_replace("ä", "ae", $name); $name = str_replace("ö", "oe", $name); $name = str_replace("ü", "ue", $name); $name = str_replace("ß", "sz", $name); $name = ereg_replace("[^A-Za-z0-9\.-_]", "", $name); if(!file_exists($dir.$name)){ return $name; } //extract file extension $dot = strrpos($name, "."); $ext = substr($name, $dot+1); $name = substr($name, 0, $dot); //add 3-digit number $count = 1; while(file_exists(sprintf("%s%s%03d.%s", $dir, $name, $count, $ext))){ $count++; } return sprintf("%s%03d.%s", $name, $count, $ext); } /** returns video description as xml * @return xml string */ //--------------------------------------------------- function toXml(){ //--------------------------------------------------- $xml = sprintf("