<?php
/*
* PEAR::HTTP_Upload Klasse laden
* Auslagern der Upload Funktion in externe Klasse.
*/
#require_once("HTTP/Upload.php");
define("MEDIA_USE_TRUE_COLOR", true);
define("MEDIA_USE_LIBRARY_GD2",true);
define("MEDIA_USE_SUBFOLDERS", true);
define("FILE_OPTION_ONLINE", 1 << 0);
/* get GD Version */
if(MEDIA_USE_LIBRARY_GD2 === 'auto') {
$gdversion = MediaManagement::getGDVersion();
if( $gdversion == 2 ) {
$GLOBALS['gd2'] = true;
} elseif( $gdversion == 1 ) {
$GLOBALS['gd2'] = false;
}
} else {
if(MEDIA_USE_LIBRARY_GD2) {
$GLOBALS['gd2'] = true;
} else {
$GLOBALS['gd2'] = false;
}
}
/**
* Klasse zum Verwalten von Mediendaten
*
* Es werden Upload Funktionen, Sicherheitschecks, Dateiverwaltung und mehr geboten
*
* @package CB Media Management
* @access public
* @author Jörg Stöber <hide@address.com>
* @version 0.5.2 ($Id: CB_media.class.php,v 1.2 2004/04/05 00:36:21 cb_fog Exp $)
*/
class MediaManagement {
var $uploadDir, $mediaText, $userID;
var $cbPermObj;
var $userPerm = 0;
var $tpl, $cbOption, $mediaOptions;
var $typeArray, $userArray;
/**
* Konstruktor
* Setzen der Anfangswerte
*
* @access public
*/
function MediaManagement($dir = "uploads/files/") {
$this->uploadDir = $dir;
$this->limit = "2";
$this->mediaTypeID = "";
$this->getInfoArrays();
$this->mediaOptions = new CBOption();
$this->mediaOptions->setModule("media");
$this->mediaOptions->getOptionList();
}
/**
* Setzen des aktuellen Users
*
* @access public
* @param int $bid ID des astes
*/
function setUserID($uid) {
$this->userID = $uid;
$this->cbPermObj = new CBPerm($uid);
$this->userPerm = $this->cbPermObj->getPattern("system");
}
/**
* Setzen der ID des gewählten Astes
*
* @access public
* @param int $bid ID des astes
*/
function setBranchID($bid) {
if (ereg("(^[1-9]?[0-9]*$)", $bid)) {
$this->branchID = $bid;
$bQuery = mysql_fetch_array(mysql_query("SELECT branchName FROM ".TABLE."_mm_folder WHERE branchID = '$bid'"));
$this->branchName = $bQuery['branchName'];
$result = 1;
} else {
$result = &new CB_error("No valid ID", "MEDIA_noBranch");
}
return $result;
}
/**
* Abfragen der ID des gewählten Astes
*
* @access public
* @return int $bid ID des astes
*/
function getBranchID() {
return $this->branchID;
}
/**
* Abfragen des Verzeichnisnamens des gewählten Astes
*
* @access public
* @return string $branchName Verzeichnisname des Astes
*/
function getBranchDirectory() {
return $this->branchName;
}
/**
* Setzen des Limits an Uploadboxen
*
* @access public
* @param int $limit Anzahl der Boxen
*/
function setLimit($limit) {
if (ereg("(^[1-9]?[0-9]*$)", $limit)) {
$this->limit = $limit;
$result = 1;
} else {
$result = &new CB_error("No valid Integer Value", "MEDIA_wrongIntegerValue");
}
return $result;
}
/**
* Abfragen des Limits an Uploadboxen
*
* @access public
* @return int $limit Anz. Uploadboxen
*/
function getLimit() {
return $this->limit;
}
/**
* Template Objekt an MM übergeben
*
* @access public
* @param object $tpl Objekt von patTemplate
*/
function setTemplateObject($tpl = false) {
if (is_object($tpl)) {
$this->tpl = &$tpl;
$this->tpl->template_dir = CB_TEMPLATE_DIR."media/";
$this->tpl->compile_dir = CB_TEMPLATE_DIR."compiled/";
$this->tpl->config_dir = CB_TEMPLATE_DIR."config/";
$this->tplFile = "mediaFiles.template";
$this->tplMessages = "messages.template";
$result = 1;
} else {
$result = &new CB_error("No valid Template Object", "MEDIA_noTplObj");
}
return $result;
}
/**
* Ermittlung der GD Version
*
* @access public
* @return int $r 2, 1, 0, je nach Verison
*/
function getGDVersion() {
ob_start();
phpinfo(8); // Just get the modules loaded
$a = ob_get_contents();
ob_end_clean();
if( preg_match('/.*GD Version.*(1[0-9|\.]+).*/',$a,$m) ) {
$r=1;$v=$m[1];
} elseif( preg_match('/.*GD Version.*(2[0-9|\.]+).*/',$a,$m) ) {
$r=2;$v=$m[1];
} else {
$r=0;$v=$m[1];
}
return $r;
}
/**
* CBOption Objekt an MM übergeben
*
* @access public
* @param object $option Objekt von CBOption
*/
function setOptionObject($option) {
if (is_object($option)) {
$this->cbOption = $option;
$result = 1;
} else {
$result = &new CB_error("No valid Option Object");
}
return $result;
}
/**
* Informationen über alle User und alle Medien Typen aus der Datenbank holen
*
* @access private
*/
function getInfoArrays() {
// Alle Typen abrufen
$typeQuery = mysql_query("SELECT typeID, name FROM ".TABLE."_mm_type");
while ($typeRow = mysql_fetch_object($typeQuery)) {
$this->typeArray[$typeRow->typeID] = $typeRow->name;
} // while
// Alle User abrufen
$userQuery = mysql_query("SELECT name, userid FROM ".TABLE."_user");
while ($userRow = mysql_fetch_object($userQuery)) {
$this->userArray[$userRow->userid] = $userRow->name;
} // while
}
/**
* Methode zum überprüfen, ob eine Media ID noch besteht, und ob sie einem Modul zugeordnet ist
*
* @access public
* @param int $id zu überprüfende ID
* @param string $module Ist dieser Zweig auch dem gewünschten Modul zugeordnet?
* @return boolean $allowed Darf modifiziert werden, ja / nein
*/
function checkMediaID($id, $module = "") {
$allowed = false;
$query = mysql_fetch_object(mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE branchID = '$id'"));
if ($query->branchID != "") {
if ($module != "") {
if ($query->module == $module) {
$allowed = true;
}
} else {
$allowed = true;
}
}
return $allowed;
}
/**
* Methode zum setzen von beliebigen ID's in den Medien Templates
*
* @access public
* @param array $idBox Array Liste der mitzugebenden ID's
*/
function setIdBox($idBox) {
if (is_array($idBox) && count($idBox) > 0) {
foreach($idBox as $k => $v) {
$this->idBoxName[] = $k;
$this->idBoxValue[] = $v;
}
}
$this->tpl->assign(
array ( "IDNAME" => $this->idBoxName,
"IDVALUE" => $this->idBoxValue
)
);
}
/**
* Methode liefert Dateigröße in Bytes, MBytes usw zurück
*
* @access public
* @param string $fileName Name der Datei
* @param string $branchName Name des Verzeichnisses
* @return string $fileSize Größe der Datei
*/
function getFileSize($fileName, $branchName, $ext = 'Byte') {
if(!MEDIA_USE_SUBFOLDERS) { unset($branchName); }
$directory = $this->uploadDir.$branchName."/";
$extension = array("", "K", "M", "G", "T");
$fileSize = filesize($directory.$fileName);
$j = 0;
while($fileSize >= pow(1024, $j)) ++$j;
return round($fileSize / pow(1024, $j-1), 2) . ' ' . $extension[$j-1] . $ext;
}
/**
* Löschen von Dateien. Die Funktion erwartet in jedem Fall ein Array
* mit der fileID als Wert jedes Eintrags
*
* @access public
* @param array $delbox
*/
function deleteFiles($delbox) {
$delbox2 = $delbox;
unset($delbox);
reset($delbox2);
while (list($k, $v) = each($delbox2)) {
if($v != "") {
$delbox[$k] = $v;
}
}
reset($delbox);
while (list($k, $v) = each($delbox)) {
if($v != "" && !empty($v)) {
$fquery = mysql_fetch_object(mysql_query("SELECT * FROM ".TABLE."_mm_files WHERE fileID='$v'"));
$bquery = mysql_fetch_object(mysql_query("SELECT branchName FROM ".TABLE."_mm_folder WHERE branchID='".$fquery->branchID."'"));
$dquery = mysql_query("DELETE FROM ".TABLE."_mm_files WHERE fileID='$v'");
// Don't use sub directories
if(!MEDIA_USE_SUBFOLDERS) {
$branchName = "";
} else {
$branchName = $bquery->branchName;
}
// Delete files
if(@unlink($this->uploadDir . $branchName . "/" . $fquery->filename)) {
$result = 1;
} else {
$result = &new CB_error("Failed: Delete File ". $branchName . "/" . $fquery->filename);
}
// Delete Thumbnails
if($fquery->parameter == "thumbnail") {
@unlink($this->uploadDir.$branchName."/"."thumb".$fquery->filename);
}
}
}
return $result;
}
/**
* Methode zum Löschen von einzelnen Zweigen
*
* @access public
* @param array $delbox Array Liste der zu löschenden Kategorien
*/
function deleteBranch($delbox) {
// Funtkion zum Löschen von Kategorien
$result = 1;
if((is_array($delbox)) && (count($delbox) > 0)) {
foreach($delbox as $v) {
if (!empty($v) && ($v != "0") && ($v != null)) {
$branchExistsQuery = mysql_query("SELECT parameter, branchID, branchName FROM ".TABLE."_mm_folder WHERE branchID = '$v'");
if(mysql_num_rows($branchExistsQuery) == 1) {
$branchExistsRow = mysql_fetch_assoc($branchExistsQuery);
if($branchExistsRow[parameter] != "protected") {
$ndelbox[] = $branchExistsRow[branchID];
$ddelbox[] = $branchExistsRow[branchName];
}
}
}
}
if (!empty($ndelbox)) {
foreach($ndelbox as $k => $v) {
if($v != "" && $v != 0) {
$branchName = $ddelbox[$k];
// Don't use sub directories
$mdelq = mysql_query("SELECT * FROM ".TABLE."_mm_files WHERE branchID = '$v'");
while($fquery = mysql_fetch_object($mdelq)){
if(is_file($this->uploadDir . $branchName . "/" . $fquery->filename)) {
@unlink($this->uploadDir . $branchName . "/" . $fquery->filename);
}
if(is_file($this->uploadDir . $branchName . "/thumb" . $fquery->filename)) {
@unlink($this->uploadDir . $branchName . "/thumb" . $fquery->filename);
}
}
$delete = mysql_query("DELETE FROM ".TABLE."_mm_files WHERE branchID = '$v'");
$delete = mysql_query("DELETE FROM ".TABLE."_mm_folder WHERE branchID = '$v'");
if (is_dir($this->uploadDir . $branchName)) {
if(!@rmdir($this->uploadDir . $branchName)) {
$result = &new CB_error("Failed: Delete Branch ". $branchName, "MEDIA_deleteBranch");
}
}
}
}
}
}
return $result;
}
/**
* Wird momentan dazu genutzt Hauptkategorien zu erzeugen, sollte aber nicht benutzt
* werden, da addSubBranch bei Angabe von 0 als parentID auch eine Hauptkategorie
* erzeugt.
* Als Wert kann sowohl ein Array als auch ein eintelner String übergeben werdne
*
* @access public
* @param string $addmain name der Hauptrubrik
* @return int $dirID ID des erzeugten Eintrags
*/
function addMainBranch($addmain, $folderName = "") {
if (is_array($addmain)) {
// bei einem Array, also mehreren Einträgen
foreach($addmain as $k => $v) {
$name = trim(addslashes($v));
$catSortQ = mysql_fetch_object(mysql_query("SELECT branchID, SUBSTRING(status,5,1) as status, SUBSTRING(status,2,3) as sort FROM ".TABLE."_mm_folder WHERE parentID='' OR parentID='0' OR parentID='NULL' ORDER BY sort DESC LIMIT 1"));
$lastSortNr = $catSortQ->sort + 1;
$lastSortNr = $this->stringTo3($lastSortNr);
$mainStatus = "1" . $lastSortNr . "1";
mysql_query("INSERT INTO ".TABLE."_mm_folder (name, status, parentID) VALUES ('$name', '$mainStatus', '')");
$dirID = mysql_insert_id();
/* Verzeichnisnamen nachtragen */
unset($branchName);
if(is_array($folderName)) {
if(ereg("(^[a-zA-Z0-9_-]*$)", $folderName[$k])) {
$branchName = $folderName[$k];
} else {
$branchName = $dirID;
}
} else {
$branchName = $dirID;
}
mysql_query("UPDATE ".TABLE."_mm_folder SET branchName = '$branchName' WHERE branchID = '$dirID'");
if (!mkdir($this->uploadDir . $branchName, 0775)) {
$this->error[] = "Verzeichniserstellung fehlgeschlagen";
mysql_query("DELETE FROM ".TABLE."_mm_folder WHERE branchID = '$dirID'");
}
}
} else {
// für eine einfache Variable, also ein Eintrag
$name = trim(addslashes($addmain));
$catSortQ = mysql_fetch_object(mysql_query("SELECT branchID, SUBSTRING(status,5,1) as status, SUBSTRING(status,2,3) as sort FROM ".TABLE."_mm_folder WHERE parentID='' OR parentID='0' OR parentID='NULL' ORDER BY sort DESC LIMIT 1"));
$lastSortNr = $catSortQ->sort + 1;
$lastSortNr = $this->stringTo3($lastSortNr);
$mainStatus = "1" . $lastSortNr . "1";
mysql_query("INSERT INTO ".TABLE."_mm_folder (name, status, parentID) VALUES ('$name', '$mainStatus', '')");
$dirID = mysql_insert_id();
/* Verzeichnisnamen nachtragen */
unset($branchName);
if(!is_array($folderName)) {
if(ereg("(^[a-zA-Z0-9_-]*$)", $folderName) && !empty($folderName)) {
$branchName = $folderName;
} else {
$branchName = $dirID;
}
} else {
$branchName = $dirID;
}
mysql_query("UPDATE ".TABLE."_mm_folder SET branchName = '$branchName' WHERE branchID = '$dirID'");
if (!mkdir($this->uploadDir . $branchName, 0775)) {
$this->error[] = "Verzeichniserstellung fehlgeschlagen";
mysql_query("DELETE FROM ".TABLE."_mm_folder WHERE branchID = '$dirID'");
}
}
return $dirID;
}
/**
* Als Wert kann ein Array übergeben werden, der als Schlüssel die Elternkategorie
* enthält, und als Wert den Namen der Kategorie.
* Unter Angabe von 0 als Schlüssel kann eine Hauptkategorie erzeugt werden
*
* @access public
* @param array $addsub Array mit Werten der Unterrubriken
* @return int $dirID ID des letzten erzeugten Eintrags
*/
function addSubBranch($addsub, $folderName = "") {
if (is_array($addsub)) {
/**
* Herausrechnen aller leeren Einträge in addsub
*/
$addsub2 = $addsub;
unset($addsub);
foreach($addsub2 as $k => $v) {
if (!empty($v)) {
$addsub[$k] = $v;
$getCatInfo[] = $k;
}
}
/**
* Alle übrig gebliebene Addsubs haben Eltern. Deren Infos werden komplett
* im 2 dimensionalem Array $catArray gespeichert.
* 1. Dimension: ID der Eltern
* 2. Dimension: alle Schlüssel der DB. Werte sind die Values der DB
*/
if ($getCatInfo) {
$catWhere = "WHERE ";
$mutiple = false;
foreach($getCatInfo as $key => $value) {
if ($multiple) {
$catWhere .= " OR ";
}
$catWhere .= "branchID = '$value' ";
$multiple = true;
}
}
$catArray = array();
$catQ = mysql_query("SELECT branchID, SUBSTRING(status,5,1) as status, SUBSTRING(status,2,3) as sort FROM ".TABLE."_mm_folder $catWhere");
while ($catR = mysql_fetch_array($catQ)) {
$tempID = $catR[branchID];
foreach($catR as $key => $value) {
$catArray[$tempID][$key] = $value;
}
}
/**
* End
*/
if ($addsub) {
$counter = 0;
foreach($addsub as $k => $v) {
$catSortQ = mysql_fetch_object(mysql_query("SELECT branchID, SUBSTRING(status,5,1) as status, SUBSTRING(status,2,3) as sort FROM ".TABLE."_mm_folder WHERE parentID = '$k' ORDER BY sort DESC LIMIT 1"));
$lastSortNr = $catSortQ->sort + 1;
// Sortierung auf Stringlänge 3 erweitern
$lastSortNr = $this->stringTo3($lastSortNr);
$subLevel = $catArray[$k][status] + 1;
$subStatus = (int) "1" . $lastSortNr . $subLevel;
mysql_query("INSERT INTO ".TABLE."_mm_folder (name, status, parentID) VALUES ('$v', '$subStatus', '$k')");
$dirID = mysql_insert_id();
/* Verzeichnisnamen nachtragen */
unset($branchName);
if(is_array($folderName)) {
if(ereg("(^[a-zA-Z0-9_-]*$)", $folderName[$counter])) {
$branchName = $folderName[$counter];
} else {
$branchName = $dirID;
}
} else {
$branchName = $dirID;
}
mysql_query("UPDATE ".TABLE."_mm_folder SET branchName = '$branchName' WHERE branchID = '$dirID'");
++$counter;
if (!mkdir($this->uploadDir . $branchName, 0777)) {
$this->error[] = "Verzeichniserstellung fehlgeschlagen";
mysql_query("DELETE FROM ".TABLE."_mm_folder WHERE branchID = '$dirID'");
}
}
}
}
return $dirID;
}
/**
* Diese Methode fügt einer Rubrik deren Details zu. Als Schlüssel für $details gilt
* der Spaltenname der Detailinformation einer Kategorie, als Wert das was rein soll
* Keine Überprüfung momentan, Mißbrauch möglich
*
* @access public
* @param array $details Array Liste der Details
* @param int $bid ID der Kategorie
*/
function addDetails($details, $bid) {
if (is_array($details)) {
$noDetails = true;
$first = true;
$set = "SET ";
foreach($details as $k => $v) {
if (!empty($v)) {
$noDetails = false;
if ($first == true) {
$first = false;
$set .= $k . " = '" . $v . "'";
} else {
$set .= ", " . $k . " = '" . $v . "'";
}
}
}
if (!$noDetails) {
mysql_query("UPDATE ".TABLE."_mm_folder $set WHERE branchID = '$bid'");
}
}
}
/**
* Diese Methode setzt Klassenvariablen für Keywords, Description und Title einer Datei.
* Es wird kein Update in der Datenbank vorgenommen
*
* @access public
* @param array $valArray Array Liste der Details
*/
function addFileValues($valArray) {
if(is_array($valArray)) {
foreach($valArray as $k => $v) {
if (empty($v)) {
$v = "";
}
$this->{"file_".$k} = $v;
}
} else {
$this->file_title = "";
$this->file_description = "";
$this->file_keywords = "";
}
}
/**
* Diese Methode fügt einem Dateieintrag zusätzliche Informationen wie keywords, description und den title hinzu.
* Die Methode updated einen vorhandenen Eintrag.
*
* @access public
* @param int $fileID ID der Datei
* @param array $valArray Array Liste der Details
* @return boolean $success true / false
*/
function updateFileValues($fileID, $valArray) {
if(is_array($valArray)) {
foreach($valArray as $k => $v) {
if (empty($v)) {
$v = "";
}
$this->{"file_".$k} = $v;
}
} else {
$this->file_title = "";
$this->file_description = "";
$this->file_keywords = "";
}
if(mysql_query("UPDATE ".TABLE."_mm_files SET title = '$this->file_title', keywords = '$this->file_keywords', description = '$this->file_description' WHERE fileID = '$fileID'")) {
return true;
} else {
return false;
}
}
/**
* Methode zum Abrufen der Dateiinformationen in der Datenbank
*
* @access public
* @param int $fileID ID der Datei
* @return array $infos Informationen über die Datei
*/
function getFileValues( $fileID ) {
$fileInfo = mysql_fetch_array(mysql_query("SELECT files.fileID, files.typeID, files.branchID, files.title, files.keywords, files.description, files.filename, folder.branchName FROM ".TABLE."_mm_files AS files, ".TABLE."_mm_folder AS folder WHERE files.branchID = folder.branchID AND files.fileID = '$fileID'"));
return $fileInfo;
}
/**
* Methode registriert in Medien Verzeichnisse liegende Dateien
*
* @access public
* @param string $fileName Name der Datei
* @param int $branchID ID des Verzeichnisses
* @param int $typeID gewünschte Typ ID
* @return boolean $success Status
*/
function registerFile($fileName, $branchID, $typeID) {
$folderDataQuery = mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE branchID = '".$branchID."'");
if(!$folderDataQuery) {
$error = true;
} else {
$folderData = mysql_fetch_object($folderDataQuery);
// Don't use sub directories
if(!MEDIA_USE_SUBFOLDERS) {
$branchName = "";
} else {
$branchName = $folderData->branchName;
}
$directory = $this->uploadDir.$branchName."/";
}
$this->getExtensionList($typeID);
$ext = array_reverse(explode(".", $fileName));
if(!$this->chkExtension($ext[0])) {
$error = true;
}
$success = false;
if(!$error) {
if(file_exists($directory.$fileName)) {
if(mysql_query("INSERT INTO ".TABLE."_mm_files (branchID, typeID, userid, filename, title, description, keywords, insertdate) VALUES ('$branchID', '$typeID', '$this->userID', '$fileName', '', '', '', NOW())")) {
$success = true;
$fileID = mysql_insert_id();
$ext[0] = strtolower($ext[0]);
}
/*
* Thumbnails
* Sollen TN's erstellt werden?
*/
if (($ext[0] == "jpg" || $ext[0] == "gif" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("thumbnails", $typeID)) {
$this->getThumbnail($directory, $fileName, $typeID);
chmod($directory."thumb".$fileName, 0777);
mysql_query("UPDATE ".TABLE."_mm_files SET parameter = 'thumbnail' WHERE fileID = '$fileID'");
}
/*
* Resize
* Sollen Bilder beschnitten werden?
*/
if (($ext[0] == "jpg" || $ext[0] == "gif" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("resizeImages", $typeID)) {
$this->getResizedImage($directory, $fileName, $typeID);
}
}
}
return $success;
}
/**
* Methode zum Umbenennen des Verzeichnisses eines Zweiges
*
* @access public
* @param array $renameArr Array mit Informationen zum Umbenennen
*/
function renameBranch($renameArr) {
if(is_array($renameArr)) {
/* Überprüfung des angegebenen Namen auf Gültigkeit */
if(!ereg("(^[a-zA-Z0-9_-]*$)", $renameArr['newName'])) {
$error = true;
}
/* Überprüfung ob gelieferte Branchid überhaupt existiert */
$query = mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE branchID = '".$renameArr['branchID']."'");
if(!$query) {
$error = true;
}
$success = false;
if(!$error) {
$fquery = mysql_fetch_object($query);
$oldName = $fquery->branchName;
$newName = $renameArr['newName'];
if(is_dir($this->uploadDir . $oldName)) {
/* vorhandenes Verzeichnis umbenennen */
if(rename($this->uploadDir . $oldName, $this->uploadDir . $newName)) {
$uquery = mysql_query("UPDATE ".TABLE."_mm_folder SET branchName = '$newName' WHERE branchID = '".$renameArr['branchID']."'");
if($uquery) {
$success = true;
}
}
} else {
/* falls altes Dir weg, neues anlegen */
if( mkdir($this->uploadDir . $newName, 0777 )) {
$uquery = mysql_query("UPDATE ".TABLE."_mm_folder SET branchName = '$newName' WHERE branchID = '".$renameArr['branchID']."'");
if($uquery) {
$success = true;
}
}
}
}
}
return $success;
}
/**
* Methode zum umbenennen von Dateien
*
* @access public
* @param array $renameArr Array mit Informationen zum Umbenennen
*/
function renameFile($renameArr) {
if(is_array($renameArr)) {
$fileData = mysql_fetch_object(mysql_query("SELECT * FROM ".TABLE."_mm_files WHERE fileID = '".$renameArr['fileID']."'"));
$folderData = mysql_fetch_object(mysql_query("SELECT * FROM ".TABLE."_mm_folder WHERE branchID = '".$fileData->branchID."'"));
// Don't use sub directories
if(!MEDIA_USE_SUBFOLDERS) {
$branchName = "";
} else {
$branchName = $folderData->branchName;
}
$this->getExtensionList($fileData->typeID);
$ext = array_reverse(explode(".", $renameArr[newName]));
if(!$this->chkExtension($ext[0])) {
$error = true;
}
$success = false;
if(!$error) {
$oldName = $fileData->filename;
$newName = $renameArr['newName'];
if(is_file($this->uploadDir . $branchName . "/". $fileData->filename)) {
if(rename( $this->uploadDir . $branchName . "/". $fileData->filename, $this->uploadDir . $branchName . "/". $newName )) {
if($fileData->parameter == "thumbnail") {
rename( $this->uploadDir . $branchName . "/". "thumb" . $fileData->filename, $this->uploadDir . $branchName . "/". "thumb" . $newName );
}
$uquery = mysql_query("UPDATE ".TABLE."_mm_files SET filename = '$newName' WHERE fileID = '".$renameArr['fileID']."'");
if($uquery) {
$success = true;
}
}
}
}
}
return $success;
}
/**
* Methode zum Packen einer kompletten Dateiübersicht einer Kategorie.
* Ausgabe erfolgt mit $this->displayTemplate
*
* @access public
*/
function packFilelistTemplate() {
if(is_array($this->typeArray)) {
foreach($this->typeArray as $key => $value) {
$typeListName[] = $value;
$typeListID[] = $key;
}
}
$fileList = array();
$fileQuery = mysql_query("SELECT fileID, typeID, userid, filename, options, insertdate FROM ".TABLE."_mm_files WHERE branchID = '$this->branchID'");
if($fileQuery) {
while ($fileRow = mysql_fetch_object($fileQuery)) {
$date = explode(" ", $fileRow->insertdate);
$date = explode("-", $date[0]);
$date = $date[2] . "." . $date[1] . "." . $date[0];
if ($fileRow->options & FILE_OPTION_ONLINE) {
$online = 1;
$selected = "";
} else {
$online = 0;
$selected = "checked";
}
$fileList['id'][] = $fileRow->fileID;
$fileList['name'][] = $fileRow->filename;
$fileList['type'][] = $this->typeArray[$fileRow->typeID];
$fileList['user'][] = $this->userArray[$fileRow->userid];
$fileList['date'][] = $date;
$fileList['online'][] = $online;
$fileList['checked'][] = $selected;
} // while
$this->tpl->assign("filelist",
array ( "ID" => $fileList['id'],
"NAME" => $fileList['name'],
"TYPE" => $fileList['type'],
"DATE" => $fileList['date'],
"ONLINE" => $fileList['online'],
"CHECKED" => $fileList['checked'],
"BY" => $fileList['user']
)
);
$this->tpl->assign("filelist_set", "1");
} else {
$this->tpl->assign("filelist_set", "0");
}
$this->tpl->assign("filetypes",
array ( "NAME" => $typeListName,
"VALUE" => $typeListID
)
);
$this->tpl->assign("fileoverview",
array ( "TXT_FILENAME" => $this->mediaText['fileName'],
"TXT_FILETYPE" => $this->mediaText['typeName'],
"TXT_UPLOADED_BY" => $this->mediaText['uploadedBy'],
"TXT_UPLOADED_AT" => $this->mediaText['uploadedAt'],
"TXT_ONLINE" => $this->mediaText['online'],
"TXT_ADD" => $this->mediaText['add']
)
);
$this->tpl->assign("fileoverview_set", "1");
}
/**
* Methode zum Packen einer kompletten Dateiübersicht einer Kategorie.
* Ausgabe erfolgt mit $this->displayTemplate
*
* @access public
*/
function packUnregisteredFilelistTemplate() {
/* Array's der Typ Infos für Templates erstellen */
foreach($this->typeArray as $k => $v) {
$typeListName[] = $v;
$typeListID[] = $k;
}
$branchRow = mysql_fetch_object(mysql_query("SELECT branchID, branchName FROM ".TABLE."_mm_folder WHERE branchID = '$this->branchID'"));
// Don't use sub directories
if(!MEDIA_USE_SUBFOLDERS) {
$branchName = "";
} else {
$branchName = $branchRow->branchName;
}
/*
* alle registrierten Dateien suchen, damit diese aus der Liste
* ausgeschlossen werden können
*/
$fileQuery = mysql_query("SELECT fileID, filename, parameter FROM ".TABLE."_mm_files WHERE branchID = '$this->branchID'");
while ($fileRow = mysql_fetch_object($fileQuery)) {
$fileList[$fileRow->filename] = $fileRow->fileID;
if($fileRow->parameter == "thumbnail") {
$fileList["thumb".$fileRow->filename] = $fileRow->fileID;
}
} // while
//Reading all directory data, search for unregistered files
$fileCounter = 0;
$directory = $this->uploadDir.$branchName;
if(is_dir($directory)) {
$branchDir = dir($directory);
while($branchDirEntry = $branchDir->read()) {
if(!is_dir($directory."/".$branchDirEntry) && ($branchDirEntry != ".") && ($branchDirEntry != "..")) {
if(empty($fileList[$branchDirEntry]) && empty($fileList["thumb".$branchDirEntry])) {
clearstatcache();
$unregisteredList['name'][] = $branchDirEntry;
$unregisteredList['size'][] = $this->getFileSize($branchDirEntry, $branchRow->branchName, 'B');
$unregisteredList['nr'][] = $fileCounter;
$unregisteredSet = true;
++$fileCounter;
}
}
}
$branchDir->close();
}
if($unregisteredSet) {
$this->tpl->assign("unregisteredFileoverview_set", "1");
}
$this->tpl->assign("unregisteredFileoverview",
array ( "TXT_FILENAME" => $this->mediaText['fileName'],
"TXT_FILESIZE" => $this->mediaText['fileSize'],
"TXT_FILETYPES" => $this->mediaText['typeName'],
"TXT_ADD" => $this->mediaText['add']
)
);
$this->tpl->assign("unregisteredFilelist",
array ( "TXT_ADD" => $this->mediaText['add'],
"NAME" => $unregisteredList['name'],
"SIZE" => $unregisteredList['size'],
"COUNTER" => $unregisteredList['nr']
)
);
$this->tpl->assign("filetypes",
array ( "NAME" => $typeListName,
"VALUE" => $typeListID
)
);
}
/**
* Methode zum Packen eines kompletten Uploadformulars für eine Kategorie.
* Ausgabe erfolgt mit $this->displayTemplate
*
* @access public
*/
function packUploadTemplate() {
$filesize = $this->getSingleCBOption("maxfileup", 1000000);
for($i = 1; $i <= $this->limit; $i++) {
$uploadFieldNr[] = $i;
}
$this->tpl->assign("uploads_fields_set", "1");
$this->tpl->assign("upload_fields",
array ( "INFILENR" => $uploadFieldNr,
"TXT_FILENR" => $this->mediaText['filenr']
)
);
$this->tpl->assign("upload_form",
array ( "LIMIT" => $this->limit,
"MAXFILESIZE" => $filesize,
"MEDIATYPEID" => $this->mediaTypeID,
"MEDIATYPENAME" => $this->typeArray[$this->mediaTypeID],
"TXT_UPLOAD" => $this->mediaText['mediaUpload'],
"TXT_KEYWORDS" => $this->mediaText['keywords'],
"TXT_DESCRIPTION" => $this->mediaText['description'],
"TXT_TITLE" => $this->mediaText['title']
)
);
$this->tpl->assign("upload_form_set", "1");
}
/**
* Methode zum Packen eines Update Formulars für einzelne Dateien.
* Ausgabe erfolgt mit $this->displayTemplate
*
* @access public
*/
function packUpdateTemplate($fileID) {
$file = mysql_fetch_object(mysql_query("SELECT files.fileID, files.typeID, files.branchID, files.title, files.keywords, files.description, files.filename, folder.branchName FROM ".TABLE."_mm_files AS files, ".TABLE."_mm_folder AS folder WHERE files.branchID = folder.branchID AND files.fileID = '$fileID'"));
$this->tpl->assign("update_form",
array ( "TXT_KEYWORDS" => $this->mediaText['keywords'],
"TXT_DESCRIPTION" => $this->mediaText['description'],
"TXT_TITLE" => $this->mediaText['title'],
"TXT_RENAME" => $this->mediaText['fileRename'],
"TXT_MODIFY" => $this->mediaText['fileModify'],
"TXT_BACK" => $this->mediaText['back'],
"BRANCHID" => $file->branchID,
"TYPEID" => $file->typeID,
"FILEID" => $fileID,
"FILENAME" => $file->filename
)
);
$this->tpl->assign("fileEditValues",
array (
"KEYWORDS" => $file->keywords,
"TITLE" => $file->title,
"DESCRIPTION" => $file->description
)
);
$this->tpl->assign("update_form_set", "1");
}
/**
* Methode zum Überprüfen des Dateinamens
*
* @access public
*/
function chkFileName($filename) {
$result = true;
if(!ereg("^[a-zA-Z0-9]+([\._a-zA-Z0-9-]+)*$", $filename)) {
$result = false;
}
return $result;
}
/**
* Methode zum ablegen der Dateien. Die Methode überprüft die Erweiterungen auf Gültigkeit
*
* @access public
*/
function moveFiles() {
$error = 0;
$uploadDir = $this->uploadDir;
$extensions = $this->getExtensionList($this->mediaTypeID);
// Don't use sub directories
if(!MEDIA_USE_SUBFOLDERS) {
$branchName = "";
} else {
$branchName = $this->branchName;
}
if(!is_dir($this->uploadDir . $branchName)) {
$error = 1;
$result[] = &new CB_error("Directory '$branchName' does not exist, please create is in your upload directory", "MEDIA_noDirectory");
}
/*
if(!$error) {
$uploadObject = new HTTP_Upload('de');
$files = $uploadObject->getFiles();
foreach($files as $k => $v) {
if((UPLOAD & $this->userPerm) || (ADMIN & $this->userPerm)) {
$v->setValidExtensions($extensions, 'accept');
$v->setName('real');
$result = $v->moveTo($this->uploadDir . $branchName);
echo nl2br($result->message);
if($result === true) {
mysql_query("INSERT INTO ".TABLE."_mm_files (branchID, typeID, userid, filename, title, description, keywords, insertdate) VALUES ('$this->branchID', '$this->mediaTypeID', '$this->userID', '$fileName', '$this->file_title', '$this->file_description', '$this->file_keywords', NOW())");
$fileID = mysql_insert_id();
$ext = array_reverse(explode(".", $v->getProp('name')));
$fileName = $v->getProp('name');
/ *
* Thumbnails
* Sollen TN's erstellt werden?
* /
if (($ext[0] == "jpg" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("thumbnails", $this->mediaTypeID)) {
$thumbResult = $this->getThumbnail($this->uploadDir.$branchName."/", $fileName, $this->mediaTypeID);
if(!is_object($thumbResult)) {
chmod($this->uploadDir.$branchName."/thumb".$fileName, 0777);
mysql_query("UPDATE ".TABLE."_mm_files SET parameter = 'thumbnail' WHERE fileID = '$fileID'");
} else {
$result[] = &new CB_error("Thumbnail Creation failed", $thumbResult->getError);
}
}
/ *
* Resize
* Sollen Bilder beschnitten werden?
* /
if (($ext[0] == "jpg" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("resizeImages", $this->mediaTypeID)) {
$resizeResult = $this->getResizedImage($this->uploadDir.$branchName."/", $fileName, $this->mediaTypeID);
if(is_object($resizeResult)) {
$result[] = &new CB_error("Image Resize failed", $resizeResult->getError);
}
}
}
}
}
}
*/
#/*
if(!$error) {
global $HTTP_POST_FILES, $HTTP_SERVER_VARS;
$postFiles = $HTTP_POST_FILES;
foreach ($postFiles as $userfile => $value) {
if (is_array($value['name'])) {
foreach ($value['name'] as $key => $val) {
$postFileName[] = basename($value['name'][$key]);
$postFileTmpName[] = $value['tmp_name'][$key];
$postFileSize[] = $value['size'][$key];
$postFileType[] = $value['type'][$key];
$postFileFormname[] = $userfile . "[$key]";
}
// One file
} else {
$postFileName[] = basename($value['name']);
$postFileTmpName[] = $value['tmp_name'];
$postFileSize[] = $value['size'];
$postFileType[] = $value['type'];
$postFileFormname[] = $userfile;
}
}
foreach($postFileName as $i => $fileName) {
if($fileName != "") {
$fileCheck = $this->chkFileName($fileName);
if($fileCheck == true) {
@chmod($postFileTmpName[$i], 0777);
if ($postFileTmpName[$i] != "none" && move_uploaded_file($postFileTmpName[$i], $this->uploadDir . $branchName . "/" . $fileName)) {
if((UPLOAD & $this->userPerm) || (ADMIN & $this->userPerm)) {
$ext = array_reverse(explode(".", $fileName));
if (!$this->chkExtension($ext[0])) {
// Remove File if Extension is not valid
@unlink($this->uploadDir . $branchName . "/" . $fileName);
// create error object
$result[] = &new CB_error("No valid extension", "MEDIA_wrongExtension");
} else {
mysql_query("INSERT INTO ".TABLE."_mm_files (branchID, typeID, userid, filename, title, description, keywords, insertdate) VALUES ('$this->branchID', '$this->mediaTypeID', '$this->userID', '$fileName', '$this->file_title', '$this->file_description', '$this->file_keywords', NOW())");
$fileID = mysql_insert_id();
$ext[0] = strtolower($ext[0]);
/*
* Thumbnails
* Sollen TN's erstellt werden?
*/
if (($ext[0] == "jpg" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("thumbnails", $this->mediaTypeID)) {
$thumbResult = $this->getThumbnail($this->uploadDir.$branchName."/", $fileName, $this->mediaTypeID);
if(!is_object($thumbResult)) {
chmod($this->uploadDir.$branchName."/thumb".$fileName, 0777);
mysql_query("UPDATE ".TABLE."_mm_files SET parameter = 'thumbnail' WHERE fileID = '$fileID'");
} else {
$result[] = &new CB_error("Thumbnail Creation failed", $thumbResult->getError);
}
}
/*
* Resize
* Sollen Bilder beschnitten werden?
*/
if (($ext[0] == "jpg" || $ext[0] == "gif" || $ext[0] == "png") && $this->mediaOptions->getSingleOption("resizeImages", $this->mediaTypeID)) {
$resizeResult = $this->getResizedImage($this->uploadDir.$branchName."/", $fileName, $this->mediaTypeID);
if(is_object($resizeResult)) {
$result[] = &new CB_error("Image Resize failed", $resizeResult->getError);
}
}
chmod($this->uploadDir.$branchName."/".$fileName, 0777);
}
} else {
@unlink($this->uploadDir . $branchName . "/" . $fileName);
$result[] = &new CB_error("No permission to upload", "MEDIA_noUploadPerm");
}
}
} else {
$result[] = &new CB_error("No valid Filename", "MEDIA_noValidFileName");
}
}
}
}
#*/
return $result;
}
function setFileStatus($onbox, $offbox) {
/* Comment (ger)
* Funktion, die alle Dateien dieser Seite online setzt.
*/
if(!empty($onbox)) {
$multiple = false;
$onWhere = "WHERE ";
foreach($onbox as $k => $v) {
if($multiple) { $onWhere .= " OR "; }
$onWhere .= "fileID = '$v'";
$multiple = true;
}
if($multiple) {
$onSelect = mysql_query("SELECT * FROM ".TABLE."_mm_files $onWhere");
while($onResult = mysql_fetch_object( $onSelect )) {
$onlineOption = $onResult->options;
$onlineOption |= FILE_OPTION_ONLINE;
$dquery = mysql_query("UPDATE ".TABLE."_mm_files SET options = '$onlineOption' WHERE fileID = '".$onResult->fileID."'");
}
}
}
/*
* Comment (ger)
* Funktion zum Offline-Schalten der Dateien - alle markierten Dateien
* gehen damit offline.
*/
if(!empty($offbox)) {
$multiple = false;
$offWhere = "WHERE ";
foreach($offbox as $k => $v) {
if($multiple) { $offWhere .= " OR "; }
$offWhere .= "fileID = '$v'";
$multiple = true;
}
if($multiple) {
$offSelect = mysql_query("SELECT * FROM ".TABLE."_mm_files $offWhere");
while($offResult = mysql_fetch_object( $offSelect )) {
$onlineOption = $offResult->options;
$onlineOption &= ~FILE_OPTION_ONLINE;
$dquery = mysql_query("UPDATE ".TABLE."_mm_files SET options = '$onlineOption' WHERE fileID = '".$offResult->fileID."'");
}
}
}
}
/**
* Hilfsmethode zum laden von Templates
*
* @access public
* @param string $tplFile Name des zu ladenen Templates
*/
function loadTemplate($tplFile){
$this->tpl->readTemplatesFromFile($tplFile);
}
/**
* Hilfsmethode zum visible setzen von Templates
*
* @access public
* @param string $templte Name des zu ändernden Templates
*/
function activateTemplate($template){
$this->tpl->assign($template, 1);
}
/**
* Hilfsmethode zum hidden setzen von Templates
*
* @access public
* @param string $templte Name des zu ändernden Templates
*/
function disableTemplate($template){
$this->tpl->assign($template, 0);
}
/**
* Hilfsmethode zum Ausgeben setzen von Templates
*
* @access public
* @param string $template Name des zu auszugebenden Templates
*/
function displayTemplate($template = false){
if($template != false) {
$this->tpl->assign($template, 1);
}
$this->tpl->display($this->tplFile);
}
/**
* Hilfsmethode zum Ausgeben setzen von Templates
*
* @access public
* @param string $template Name des zu auszugebenden Templates
*/
function fetchTemplate($template = false){
if($template != false) {
$this->tpl->assign($template, 1);
}
return $this->tpl->fetch($this->tplFile);
}
/**
* Abrufen der erlaubten Dateitypen
*
* @access public
* @param int $typeID ID des Typeintrages in der DB
* @return array $extensions
*/
function getExtensionList($typeID){
$list = mysql_fetch_object(mysql_query("SELECT extension FROM ".TABLE."_mm_type WHERE typeID = '$typeID'"));
$list = explode("; ", $list->extension);
$this->extensionList = array();
$extensions = array();
foreach($list as $key => $value) {
$this->extensionList[$value] = "1";
$extensions[] = $value;
$extensions[] = strtolower($value);
$extensions[] = strtoupper($value);
}
return $extensions;
}
/**
* Überprüfung, ob Dateiendung erlaubt ist
*
* @access public
* @param string $extension zu prüfende Dateiendung
* @return boolean $status 1 für gültig, 0 für nicht geültig
*/
function chkExtension($extension) {
$status = 0;
foreach($this->extensionList as $key => $value) {
if (strtolower($extension) == strtolower($key)) {
$status = 1;
}
}
return $status;
}
/**
* Hilfsmethode zum Erweitern der Sortiernummern auf die Länge 3
*
* @access public
* @param int $sort zu erweiternder Wert
* @return int $sort erweiterter Wert
*/
function stringTo3 ($sort) {
if ($sort < 10) {
$sort = "00" . $sort;
} elseif ($sort < 100 && $sort > 9) {
$sort = "0" . $sort;
} elseif ($sort > 999) {
$sort = 999;
}
return $sort;
}
/**
* Hilfsmethode zum Abfragen von cbOptions Optionen, gibt aber gleichzeitig einen Defaultwert aus, wenn der Wert in der Optionen Liste nicht gefunden werden kann
*
* @access public
* @param string $option abzufragende Option
* @param string $default Defaultwert für die Option (Kann auch leer bleiben)
* @return string $requestedOption Wert der abzufragenden Option
*/
function getSingleCBOption($option, $default = "") {
$requestedOption = $this->cbOption->getSingleOption($option);
if ($requestedOption == "") {
$requestedOption = $default;
}
return $requestedOption;
}
/**
* Methode zur Abfrage der Zweige, die ein Modul modifizieren darf
*
* @access public
* @param string $module
* @return array $branches ID der Branch als Schlüssel, Name als Wert
*/
function getAllowedBranches($module) {
$list = mysql_query("SELECT branchID, name FROM ".TABLE."_mm_folder WHERE module LIKE '$module'");
$branches = array();
while ($listRow = mysql_fetch_object($list)) {
$branches[$listRow->branchID] = $listRow->name;
} // while
return $branches;
}
/**
* Methode zur Abfrage der Medientypen
*
* @access public
* @return array $branches ID des Typ's als Schlüssel, Name als Wert
*/
function getMediaTypes() {
$mediaType = mysql_query("SELECT * FROM ".TABLE."_mm_type ORDER BY name ASC");
while ($mediaRow = mysql_fetch_array($mediaType)) {
$mediaTypeArray[$mediaRow['typeID']] = $mediaRow['name'];
}
return $mediaTypeArray;
}
/**
* Methode zum Ermitteln aller Dateieinträge einer bestimmten Branch und Typ
*
* @access public
* @param int $branchID
* @param int $typeID
* @return array $files ID der Datei als Schlüssel, Name als Wert
*/
function getMediaFiles($branchID, $typeID = "", $parameter = "") {
$mediaFileArray = array();
$query = "SELECT * FROM ".TABLE."_mm_files WHERE branchID = '$branchID' ";
if (ereg("(^[1-9]?[0-9]*$)", $typeID)) {
$query .= "AND typeID = '$typeID' ";
}
if ($parameter != "") {
$query .= "AND parameter LIKE '$parameter' ";
}
$query .= "ORDER BY filename ASC";
$mediaFiles = mysql_query($query);
if ($mediaFiles) {
while ($mediaRow = mysql_fetch_array($mediaFiles)) {
$mediaFileArray[$mediaRow['fileID']] = $mediaRow['filename'];
}
}
return $mediaFileArray;
}
function getDate($date) {
$date = explode(" ", $date);
$date = explode("-", $date[0]);
$date = $date[2] . "." . $date[1] . "." . $date[0];
return $date;
}
function getResizedImage($PicPath, $bild, $typeID) {
$result = 1;
$size = getimagesize($PicPath.$bild);
$breite = $size[0];
$hoehe = $size[1];
$neueHoehe = $this->mediaOptions->getSingleOption("imageResizeHeight", $typeID);
$tempWidth = $this->mediaOptions->getSingleOption("imageResizeWidth", $typeID);
/*
* falls GD2 genutzt wird, truecolor einsetzen
* dynamische Funktion setzen
*/
if( @$GLOBALS['gd2'] == true) {
if(MEDIA_USE_TRUE_COLOR) {
$imageCreateFromType = "imagecreatetruecolor";
} else {
$imageCreateFromType = "imagecreate";
}
$imageResizeFunc = "imagecopyresampled";
} else {
$imageCreateFromType = "imagecreate";
$imageResizeFunc = "imagecopyresized";
}
if($hoehe > $neueHoehe) {
$neueBreite = intval($breite * $neueHoehe / $hoehe);
if($neueBreite > $tempWidth) {
$neueHoehe = intval($tempWidth * $neueHoehe / $neueBreite);
$neueBreite = $tempWidth;
}
if ($size[2] == 2) {
// JPG
$altesBild = imagecreatefromjpeg($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagejpeg($neuesBild, $PicPath.$bild, "95")) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
if ($size[2] == 1) {
// GIF
$altesBild = imagecreatefromgif($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagegif($neuesBild, $PicPath.$bild)) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
if ($size[2] == 3) {
// PNG
$altesBild = imagecreatefrompng($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagepng($neuesBild, $PicPath.$bild, "95")) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
chmod($PicPath.$bild, 0777);
}
return $result;
}
function getThumbnail($PicPath, $bild, $typeID) {
$result = 1;
$size = getimagesize($PicPath.$bild);
$breite = $size[0];
$hoehe = $size[1];
$tnHoehe = $this->mediaOptions->getSingleOption("thumbnailsHeight", $typeID);
$tnBreite = $this->mediaOptions->getSingleOption("thumbnailsWidth", $typeID);
/*
* falls GD2 genutzt wird, truecolor einsetzen
* dynamische Funktion setzen
*/
if( @$GLOBALS['gd2'] == true) {
if(MEDIA_USE_TRUE_COLOR) {
$imageCreateFromType = "imagecreatetruecolor";
} else {
$imageCreateFromType = "imagecreate";
}
$imageResizeFunc = "imagecopyresampled";
} else {
$imageCreateFromType = "imagecreate";
$imageResizeFunc = "imagecopyresized";
}
$neueBreite = intval($breite * $tnHoehe / $hoehe);
if($neueBreite > $tnBreite) {
$neueHoehe = intval($tnHoehe * $tnBreite / $neueBreite);
$neueBreite = $tnBreite;
} else { $neueHoehe = $tnHoehe; }
if ($size[2] == 2) {
// JPG
$altesBild = imagecreatefromjpeg($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagejpeg($neuesBild, $PicPath."thumb".$bild, "95")) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
if ($size[2] == 1) {
// GIF
$altesBild = imagecreatefromgif($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagegif($neuesBild, $PicPath."thumb".$bild)) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
if ($size[2] == 3) {
// PNG
$altesBild = imagecreatefrompng($PicPath.$bild);
$neuesBild = $imageCreateFromType($neueBreite, $neueHoehe);
$imageResizeFunc($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
if(!imagepng($neuesBild, $PicPath."thumb".$bild, "95")) {
$result = &new CB_error("GD Error: Image Creation Failed", "MEDIA_failedImageCreation");
}
}
chmod($PicPath."thumb".$bild, 0777);
return $result;
}
}
?>