* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
* @since file available since contenido release <= 4.6
*
* $Id$:
*/
if (!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
cInclude("includes", "api/functions.frontend.list.php");
if (!(int) $client > 0) {
#if there is no client selected, display empty page
$oPage = new cPage;
$oPage->render();
return;
}
$appendparameters = $_REQUEST["appendparameters"];
$file = $_REQUEST['file'];
if (!is_array($browserparameters) && ($appendparameters != "imagebrowser" || $appendparameters != "filebrowser")) {
$browserparameters = array();
}
if (!$sess->is_registered("upl_last_path")) {
$upl_last_path = $path;
$sess->register("upl_last_path");
} else if (!isset($path)) {
$path = $upl_last_path;
}
$upl_last_path = $path;
$uploads = new UploadCollection;
$dbfs = new DBFSCollection;
if (is_dbfs($path)) {
$qpath = $path . "/";
} else {
$qpath = $path;
}
if ($path && $action != '') {
$sReloadScript = "";
} else {
$sReloadScript = "";
}
$sErrorMessage = '';
if ((is_writable($cfgClient[$client]["upl"]["path"] . $path) || is_dbfs($path)) && (int) $client > 0) {
$bDirectoryIsWritable = true;
} else {
$bDirectoryIsWritable = false;
$sErrorMessage = $notification->returnNotification("error", i18n("Directory not writable") . ' (' . $cfgClient[$client]["upl"]["path"] . $path . ')');
$sErrorMessage .= '
';
}
if ($action == "upl_modify_file") {
/* Did the user upload a new file? */
if ($bDirectoryIsWritable == true && count($_FILES) == 1 && ($_FILES["file"]["size"] > 0) && ($_FILES["file"]["name"] != "")) {
if ($_FILES['file']['tmp_name'] != "") {
$tmp_name = $_FILES['file']['tmp_name'];
$_cecIterator = $_cecRegistry->getIterator("Contenido.Upload.UploadPreprocess");
if ($_cecIterator->count() > 0) {
/* Copy file to a temporary location */
move_uploaded_file($tmp_name, $cfg["path"]["contenido"] . $cfg["path"]["temp"] . $file);
$tmp_name = $cfg["path"]["contenido"] . $cfg["path"]["temp"] . $file;
while ($chainEntry = $_cecIterator->next()) {
if (is_dbfs($path)) {
$sPathPrepend = '';
$sPathApppend = '/';
} else {
$sPathPrepend = $cfgClient[$client]['upl']['path'];
$sPathApppend = '';
}
$modified = $chainEntry->execute($tmp_name, $sPathPrepend . $path . $sPathApppend . uplCreateFriendlyName($_FILES['file']['name']));
if ($modified !== false) {
$tmp_name = $modified;
}
}
}
if (is_dbfs($path)) {
$dbfs->writeFromFile($tmp_name, $qpath . $file);
unlink($_FILES['file']['tmp_name']);
} else {
unlink($cfgClient[$client]['upl']['path'] . $path . $file);
if (is_uploaded_file($tmp_name)) {
move_uploaded_file($tmp_name, $cfgClient[$client]['upl']['path'] . $path . $file);
} else {
rename($tmp_name, $cfgClient[$client]['upl']['path'] . $path . $file);
}
}
}
}
$uploads->select("idclient = '$client' AND dirname = '$qpath' AND filename='$file'");
$upload = $uploads->next();
$upload->set("description", stripslashes($description));
$upload->store();
$properties = new PropertyCollection;
$properties->setValue("upload", $qpath . $file, "file", "protected", stripslashes($protected));
$bTimeMng = (isset($_REQUEST['timemgmt']) && strlen($_REQUEST['timemgmt']) > 1);
$properties->setValue("upload", $qpath . $file, "file", "timemgmt", ($bTimeMng) ? 1 : 0);
if ($bTimeMng) {
$properties->setValue("upload", $qpath . $file, "file", "datestart", $_REQUEST['datestart']);
$properties->setValue("upload", $qpath . $file, "file", "dateend", $_REQUEST['dateend']);
}
$iIdupl = $upload->get("idupl");
if (!empty($iIdupl) && $iIdupl > 0) {
// check for new entry:
$sSql = "SELECT id_uplmeta FROM " . $cfg['tab']['upl_meta'] . " WHERE idupl = $iIdupl AND idlang = $lang " .
"LIMIT 0, 1";
$db->query($sSql);
if ($db->num_rows() == 0) { // new entry
$iNextId = $db->nextid($cfg['tab']['upl_meta']);
$sSql = "INSERT INTO " . $cfg['tab']['upl_meta'] . " " .
"SET id_uplmeta = $iNextId, idupl = $iIdupl, idlang = $lang, " .
"medianame = '" . Contenido_Security::filter($medianame, $db) . "', " .
"description = '" . Contenido_Security::filter($description, $db) . "', " .
"keywords = '" . Contenido_Security::filter($keywords, $db) . "', " .
"internal_notice = '" . Contenido_Security::filter($medianotes, $db) . "', " .
"copyright = '" . Contenido_Security::filter($copyright, $db) . "', " .
"author = '" . $auth->auth['uid'] . "', " .
"created = NOW(), modified = NOW(), modifiedby = '" . $auth->auth['uid'] . "'";
} else { // update entry
$db->next_record();
$iIduplmeta = $db->f('id_uplmeta');
$sSql = "UPDATE " . $cfg['tab']['upl_meta'] . " " .
"SET " .
"medianame = '" . Contenido_Security::filter($medianame, $db) . "', " .
"description = '" . Contenido_Security::filter($description, $db) . "', " .
"keywords = '" . Contenido_Security::filter($keywords, $db) . "', " .
"internal_notice = '" . Contenido_Security::filter($medianotes, $db) . "', " .
"copyright = '" . Contenido_Security::filter($copyright, $db) . "', " .
"modified = NOW(), modifiedby = '" . $auth->auth['uid'] . "' " .
"WHERE id_uplmeta = " . $iIduplmeta;
}
$db->query($sSql);
}
}
if ($action == "upl_multidelete" && $perm->have_perm_area_action($area, $action) && $bDirectoryIsWritable == true) {
if (is_array($fdelete)) {
/* Check if it is in the upload table */
foreach ($fdelete as $file) {
$uploads->select("idclient = '$client' AND dirname='$qpath' AND filename='$file'");
if ($item = $uploads->next()) {
if (is_dbfs($qpath)) {
$dbfs->remove($qpath . $file);
} else {
unlink($cfgClient[$client]['upl']['path'] . $qpath . $file);
}
/*
* Call chain
*/
$_cecIterator = $_cecRegistry->getIterator("Contenido.Upl_edit.Delete");
if ($_cecIterator->count() > 0) {
while ($chainEntry = $_cecIterator->next()) {
$chainEntry->execute($item->get('idupl'), $qpath, $file);
}
}
}
}
}
}
if ($action == "upl_delete" && $perm->have_perm_area_action($area, $action) && $bDirectoryIsWritable == true) {
$uploads->select("idclient = '$client' AND dirname='$qpath' AND filename='$file'");
if ($uploads->next()) {
if (is_dbfs($qpath)) {
$dbfs->remove($qpath . $file);
} else {
unlink($cfgClient[$client]['upl']['path'] . $qpath . $file);
}
/*
* Call chain
*/
$_cecIterator = $_cecRegistry->getIterator("Contenido.Upl_edit.Delete");
if ($_cecIterator->count() > 0) {
while ($chainEntry = $_cecIterator->next()) {
$chainEntry->execute($uploads->f('idupl'), $qpath, $file);
}
}
}
}
if ($action == "upl_upload" && $bDirectoryIsWritable == true) {
//print_r($_FILES);
$bUplErr = false;
if (count($_FILES) == 1) {
foreach ($_FILES['file']['name'] as $key => $value) {
// new error handling
$iError = (int) $_FILES['file']['error'][$key];
switch ($iError) {
case 1:
$bUplErr = true;
$sErrorMessage .= $notification->returnNotification("error", sprintf(i18n("The uploaded file (%s) exceeds the upload_max_filesize directive in php.ini."), $value));
$sErrorMessage .= '
';
break;
case 2:
case 3:
case 5:
case 6:
case 7:
case 8:
$bUplErr = true;
$sErrorMessage .= $notification->returnNotification("error", sprintf(i18n("Error while uploading file (%s)."), $value));
$sErrorMessage .= '
';
break;
default:
$bUplErr = false;
}
if ($_FILES['file']['tmp_name'][$key] != "") {
$tmp_name = $_FILES['file']['tmp_name'][$key];
$_cecIterator = $_cecRegistry->getIterator("Contenido.Upload.UploadPreprocess");
if ($_cecIterator->count() > 0) {
/* Copy file to a temporary location */
move_uploaded_file($tmp_name, $cfg["path"]["contenido"] . $cfg["path"]["temp"] . $_FILES['file']['name'][$key]);
$tmp_name = $cfg["path"]["contenido"] . $cfg["path"]["temp"] . $_FILES['file']['name'][$key];
while ($chainEntry = $_cecIterator->next()) {
if (is_dbfs($path)) {
$sPathPrepend = '';
$sPathApppend = '/';
} else {
$sPathPrepend = $cfgClient[$client]['upl']['path'];
$sPathApppend = '';
}
$modified = $chainEntry->execute($tmp_name, $sPathPrepend . $path . $sPathApppend . uplCreateFriendlyName($_FILES['file']['name'][$key]));
if ($modified !== false) {
$tmp_name = $modified;
}
}
}
if (is_dbfs($qpath)) {
$dbfs->writeFromFile($tmp_name, $qpath . uplCreateFriendlyName($_FILES['file']['name'][$key]));
unlink($tmp_name);
} else {
if (is_uploaded_file($tmp_name)) {
$final_filename = $cfgClient[$client]['upl']['path'] . $path . uplCreateFriendlyName($_FILES['file']['name'][$key]);
move_uploaded_file($tmp_name, $final_filename);
$iterator = $_cecRegistry->getIterator("Contenido.Upload.UploadPostprocess");
while ($chainEntry = $iterator->next()) {
$chainEntry->execute($final_filename);
}
} else {
rename($tmp_name, $cfgClient[$client]['upl']['path'] . $path . uplCreateFriendlyName($_FILES['file']['name'][$key]));
}
}
}
}
}
if ($bUplErr) {
$sTmpErrorMessage = $notification->returnNotification("warning", i18n("Errors while uploading file(s). Some or all files were not uploaded."));
}
$sErrorMessage = $sTmpErrorMessage . "
" . $sErrorMessage;
}
if ($action == "upl_renamefile" && $bDirectoryIsWritable == true) {
$newname = str_replace("/", "", $newname);
rename($cfgClient[$client]['upl']['path'] . $path . $oldname, $cfgClient[$client]['upl']['path'] . $path . $newname);
}
/**
*
*/
class UploadList extends FrontendList {
var $dark;
var $size;
public function convert($field, $data) {
global $cfg, $path, $sess, $cfgClient, $client, $appendparameters;
switch ($field) {
case 1:
if ($this->dark) {
$data = $cfg["color"]["table_dark"];
} else {
$data = $cfg["color"]["table_light"];
}
$this->dark = !$this->dark;
break;
case 2:
break;
case 3:
/* If this file is an image, try to open */
switch (getFileExtension($data)) {
case "png":
case "gif":
case "tiff":
case "bmp":
case "jpeg":
case "jpg":
case "bmp":
case "iff":
case "xbm":
case "wbmp":
$sCacheThumbnail = uplGetThumbnail($data, 150);
$sCacheName = substr($sCacheThumbnail, strrpos($sCacheThumbnail, "/") + 1, strlen($sCacheThumbnail) - (strrchr($sCacheThumbnail, '/') + 1));
$sFullPath = $cfgClient[$client]['path']['frontend'] . 'cache/' . $sCacheName;
if (file_exists($sFullPath)) {
$aDimensions = getimagesize($sFullPath);
$iWidth = $aDimensions[0];
$iHeight = $aDimensions[1];
} else {
$iWidth = 0;
$iHeight = 0;
}
if (is_dbfs($data)) {
$data = '
';
break;
} else {
$retValue = '
';
$retValue .= '';
$data = $retValue;
}
break;
default:
$sCacheThumbnail = uplGetThumbnail($data, 150);
return '';
}
break;
case 4:
if ($appendparameters == "imagebrowser" || $appendparameters == "filebrowser") {
if (is_dbfs($path . '/' . $data)) {
$mstr = ' ' . $data . '';
} else {
$mstr = ' ' . $data . '';
}
} else {
$tmp_mstr = '%s';
$mstr = sprintf($tmp_mstr, 'right_bottom', $sess->url("main.php?area=upl_edit&frame=4&path=$path&file=$data&appendparameters=$appendparameters&startpage=" . $_REQUEST['startpage'] . "&sortby=" . $_REQUEST['sortby'] . "&sortmode=" . $_REQUEST['sortmode'] . "&thumbnailmode=" . $_REQUEST['thumbnailmode']), 'right_top', $sess->url("main.php?area=upl&frame=3&path=$path&file=$data"), $data);
}
$data = $mstr;
break;
case 5:
$data = human_readable_size($data);
break;
case 6:
$data = uplGetFileTypeDescription($data);
break;
}
return $data;
}
}
/**
*
* @global type $cfg
* @global type $client
* @global type $cfgClient
* @global type $area
* @global type $frame
* @global type $sess
* @global type $browserparameters
* @global type $appendparameters
* @global type $perm
* @global type $auth
* @global type $sReloadScript
* @global type $notification
* @global type $bDirectoryIsWritable
* @param type $path
* @param int $sortby
* @param string $sortmode
* @param type $startpage
* @param type $thumbnailmode
* @param type $sErrorMessage
* @return type
*/
function uplRender($path, $sortby, $sortmode, $startpage = 1, $thumbnailmode, $sErrorMessage) {
global $cfg, $client, $cfgClient, $area, $frame, $sess, $browserparameters, $appendparameters, $perm, $auth, $sReloadScript, $notification, $bDirectoryIsWritable;
if ($sortby == "") {
$sortby = 3;
$sortmode = "ASC";
}
if ($startpage == "") {
$startpage = 1;
}
$thisfile = $sess->url("main.php?idarea=$area&frame=$frame&path=$path&thumbnailmode=$thumbnailmode&appendparameters=$appendparameters");
$scrollthisfile = $thisfile . "&sortmode=$sortmode&sortby=$sortby&appendparameters=$appendparameters";
if ($sortby == 3 && $sortmode == "DESC") {
$fnsort = '' . i18n("Filename / Description") . '';
} else {
if ($sortby == 3) {
$fnsort = '' . i18n("Filename / Description") . '';
} else {
$fnsort = '' . i18n("Filename / Description") . '';
}
}
if ($sortby == 5 && $sortmode == "DESC") {
$sizesort = '' . i18n("Size") . '';
} else {
if ($sortby == 5) {
$sizesort = '' . i18n("Size") . '';
} else {
$sizesort = '' . i18n("Size") . "";
}
}
if ($sortby == 6 && $sortmode == "DESC") {
$typesort = '' . i18n("Type") . '';
} else {
if ($sortby == 6) {
$typesort = '' . i18n("Type") . '';
} else {
$typesort = '' . i18n("Type") . "";
}
}
// Multiple deletes at top of table
if ($perm->have_perm_area_action("upl", "upl_multidelete") && $bDirectoryIsWritable == true) {
$sConfirmation = "box.confirm('" . i18n('Delete Files') . "', '" . i18n('Are you sure you want to delete the selected files?') . "', 'document.del.action.value = \\\\'upl_multidelete\\\\'; document.del.submit()');";
$sDelete = '' . i18n("Delete selected files") . '';
} else {
$sDelete = '';
}
if (is_dbfs($path)) {
$mpath = $path . "/";
} else {
$mpath = "upload/" . $path;
}
$sDisplayPath = generateDisplayFilePath($mpath, 85);
$sToolsRow = '
' . i18n("Mark") . ' | ' . i18n("Preview") . ' | ' . $fnsort . ' | ' . $sizesort . ' | ' . $typesort . ' | ' . i18n("Actions") . ' |
%s | %s | %s | %s | %s | %s |