file = ""; $this->setUploadDirectory(AUDIO_DIR); } /** @see BuildingBlock::install() */ //----------------------------------------------- function install(){ //----------------------------------------------- $query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_audioblock ( id INT not null AUTO_INCREMENT, file VARCHAR(128) not null, PRIMARY KEY(id) )"); $result = dbQuery($query); } /** @see BuildingBlock::load() */ //------------------------------------------------- function load(){ //------------------------------------------------- $query = sprintf("SELECT * FROM bruckm_audioblock WHERE id = %d", $this->id); $result = dbQuery($query); $line = mysqli_fetch_array($result, MYSQLI_ASSOC); $this->file = $line['file']; } /** @see BuildingBlock::doSave() */ //----------------------------------------------- function doSave(){ //----------------------------------------------- $query = sprintf("UPDATE bruckm_audioblock SET file = %s WHERE id = %d", sqlstring($this->file), $this->id); dbQuery($query); } /** @see BuildingBlock::doCreate() */ //----------------------------------------------- function doCreate(){ //----------------------------------------------- $query = sprintf("INSERT INTO bruckm_audioblock (file) VALUES (%s)", sqlstring($this->file)); dbQuery($query); return mysql_insert_id(); } /** @see BuildingBlock::delete() */ //------------------------------------------------- function delete(){ //------------------------------------------------- $query = sprintf("DELETE FROM bruckm_audioblock WHERE id = %d", $this->id); dbQuery($query); @unlink($this->audioDir.$this->file); } /** @see BuildingBlock::update() */ //----------------------------------------------- function update(){ //----------------------------------------------- if(isset($_FILES["audioblock_file".$this->id]) && $_FILES["audioblock_file".$this->id]['error'] == UPLOAD_ERR_OK){ $this->file = $this->findName($this->audioDir, $_FILES["audioblock_file".$this->id]['name']); $this->uploadFile($_FILES["audioblock_file".$this->id]); } } /** @see BuildingBlock::printContent() */ //----------------------------------------------- function printContent($position){ //----------------------------------------------- $t = new Template(CMS_TEMPLATE_DIR."audioblock.html"); $t->setVar("ID", $this->id); $t->setVar("POSITION", $position); if(!empty($this->file) && file_exists($this->audioDir.$this->file)){ $t->setVar("FILE", $this->file); $t->removeBlock("UPLOADAUDIO"); } else{ $t->removeBlock("AUDIO"); } return $t->toString(); } /** @see BuildingBlock::publish() */ //---------------------------------------------- function publish(){ //---------------------------------------------- if(!file_exists($this->audioDir.$this->file)){ logError(3, "Audio ".$this->audioDir.$this->file." doesn't exist", __FILE__, __LINE__); return ""; } $out = '

'; $out .= 'Audiodatei: ' . $this->file . '
'; $out .= ''; $out .= '

'; return $out; } // === ADDITIONAL METHODS ======================================================== // /** uploads an audio file * @param file $_FILES file data */ //------------------------------------------------ function uploadFile($file){ //------------------------------------------------ $path = $this->audioDir . $this->file; if(file_exists($path)){ @unlink($path); } move_uploaded_file($file['tmp_name'], $path); //copy($file['tmp_name'], $path); @chmod($path, 0777); } /** sets the output directories */ //----------------------------------------------- function setUploadDirectory($audio){ //----------------------------------------------- $this->audioDir = $audio; } /** 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("", $this->file); return $xml; } }; ?>