* @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) - (strlen(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, $thumbnailmode, $sErrorMessage) { global $cfg, $client, $cfgClient, $area, $frame, $sess, $browserparameters, $appendparameters, $perm, $auth, $sReloadScript, $notification, $bDirectoryIsWritable; if(empty($sortby)) { $sortby = 3; $sortmode = "ASC"; } if(empty($startpage)) { $startpage = 1; } if(is_null($path)) { $path = ''; } $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(' . i18n("Delete selected files") . ''; } else { $sDelete = ''; } if (is_dbfs($path)) { $mpath = $path . "/"; } else { $mpath = "upload/" . $path; } $sDisplayPath = generateDisplayFilePath($mpath, 85); $sToolsRow = '
' . i18n( ' . i18n("Flip Selection") . '   ' . $sDelete . '
' . i18n("Path:") . " " . $sDisplayPath . '
'; $sSpacedRow = ' '; /* List wraps */ $pagerwrap = '
-C-SCROLLRIGHT-
-C-PAGE-
-C-SCROLLLEFT-
' . i18n("Files per Page") . ' -C-FILESPERPAGE-
'; $startwrap = ' ' . $pagerwrap . $sSpacedRow . $sToolsRow . $sSpacedRow . ' '; $itemwrap = ''; $endwrap = $sSpacedRow . $sToolsRow . $sSpacedRow . $pagerwrap . '
' . i18n("Mark") . ' ' . i18n("Preview") . ' ' . $fnsort . ' ' . $sizesort . ' ' . $typesort . ' ' . i18n("Actions") . '
%s %s %s %s %s %s
'; /* Object initializing */ $page = new UI_Page; $page->addScript('reloadscript', $sReloadScript); $list2 = new UploadList($startwrap, $endwrap, $itemwrap); $uploads = new UploadCollection; /* Fetch data */ if (substr($path, strlen($path) - 1, 1) != "/") { if ($path != "") { $qpath = $path . "/"; } } else { $qpath = $path; } $uploads->select("idclient = '$client' AND dirname = '$qpath'"); $user = new User; $user->loadUserByUserID($auth->auth["uid"]); if ($thumbnailmode == '') { $current_mode = $user->getUserProperty('upload_folder_thumbnailmode', md5($path)); if ($current_mode != '') { $thumbnailmode = $current_mode; } else { $thumbnailmode = getEffectiveSetting('backend', 'thumbnailmode', 100); } } switch ($thumbnailmode) { case 25: $numpics = 25; break; case 50: $numpics = 50; break; case 100:$numpics = 100; break; case 200:$numpics = 200; break; default: $thumbnailmode = 100; $numpics = 15; break; } # $user->setUserProperty('upload_folder_thumbnailmode', md5($path), $thumbnailmode); $list2->setResultsPerPage($numpics); $list2->size = $thumbnailmode; $rownum = 0; $properties = new PropertyCollection; while ($item = $uploads->next()) { $filename = $item->get("filename"); $bAddFile = true; if ($appendparameters == "imagebrowser") { $restrictvar = "restrict_" . $appendparameters; if (array_key_exists($restrictvar, $browserparameters)) { $extension = getFileExtension($filename); if (count($browserparameters[$restrictvar]) > 0) { $bAddFile = false; if (in_array($extension, $browserparameters[$restrictvar])) { $bAddFile = true; } } } } $dirname = $item->get("dirname"); $filesize = $item->get("size"); if ($filesize == 0) { if (file_exists($cfgClient[$client]["upl"]["path"] . $dirname . $filename)) { $filesize = filesize($cfgClient[$client]["upl"]["path"] . $dirname . $filename); } } $actions = ""; $medianame = $properties->getValue("upload", $path . $filename, "file", "medianame"); $medianotes = $properties->getValue("upload", $path . $filename, "file", "medianotes"); $todo = new TODOLink("upload", $path . $filename, "File $path$filename", ""); $proptitle = i18n("Display properties"); if ($appendparameters == "imagebrowser" || $appendparameters == "filebrowser") { $mstr = ""; } else { $tmp_mstr = '%s'; $mstr = sprintf($tmp_mstr, 'right_bottom', $sess->url("main.php?area=upl_edit&frame=4&path=$path&file=$filename&startpage=$startpage&sortby=$sortby&sortmode=$sortmode&thumbnailmode=$thumbnailmode"), 'right_top', $sess->url("main.php?area=upl&frame=3&path=$path&file=$filename"), '' . $proptitle . ''); } $actions = $mstr . $actions; $showfilename = $filename; $check = new cHTMLCheckbox("fdelete[]", $filename); $mark = $check->toHTML(false); if ($bAddFile == true) { // 'bgcolor' is just a placeholder... $list2->setData($rownum, 'bgcolor', $mark, $dirname . $filename, $showfilename, $filesize, getFileExtension($filename), $todo->render() . $actions); $rownum++; } } if ($rownum == 0) { $markSubItem = markSubMenuItem(0, true); $page->setContent($sErrorMessage . i18n("No files found") . $markSubItem); $page->render(); return; } if ($sortmode == "ASC") { $list2->sort($sortby, SORT_ASC); } else { $list2->sort($sortby, SORT_DESC); } if ($startpage < 1) { $startpage = 1; } if ($startpage > $list2->getNumPages()) { $startpage = $list2->getNumPages(); } $list2->setListStart($startpage); /* Create scroller */ if ($list2->getCurrentPage() > 1) { $prevpage = '' . i18n("Previous Page") . ''; } else { $prevpage = ' '; } if ($list2->getCurrentPage() < $list2->getNumPages()) { $nextpage = '' . i18n("Next Page") . ''; } else { $nextpage = ' '; } #$curpage = $list2->getCurrentPage() . " / ". $list2->getNumPages(); if ($list2->getNumPages() > 1) { $num_pages = $list2->getNumPages(); $paging_form.=""; $paging_form.=""; } else { $paging_form = "1"; } $curpage = $paging_form . " / " . $list2->getNumPages(); $scroller = $prevpage . $nextpage; $output = $list2->output(true); $output = str_replace("-C-SCROLLLEFT-", $prevpage, $output); $output = str_replace("-C-SCROLLRIGHT-", $nextpage, $output); $output = str_replace("-C-PAGE-", i18n("Page") . " " . $curpage, $output); $select = new cHTMLSelectElement("thumbnailmode_input"); $values = Array( 25 => "25", 50 => "50", 100 => "100", 200 => "200"); foreach ($values as $key => $value) { $option = new cHTMLOptionElement($value, $key); $select->addOptionElement($key, $option); } $select->setDefault($thumbnailmode); $select->setEvent('change', "document.del.thumbnailmode.value = this.value;"); $topbar = $select->render() . ''; $output = str_replace("-C-FILESPERPAGE-", $topbar, $output); $page->addScript('messagebox', ''); $sDelTitle = i18n("Delete file"); $sDelDescr = i18n("Do you really want to delete the following file:
"); $script = ' '; $script = str_replace('{SID}', $sess->id, $script); $script = str_replace('{RENAME}', i18n("Enter new filename"), $script); $page->addScript("script", $script); $markSubItem = markSubMenuItem(0, true); $delform = new UI_Form("del"); $delform->setVar("area", $area); $delform->setVar("action", ""); $delform->setVar("startpage", $startpage); $delform->setVar("thumbnailmode", $thumbnailmode); $delform->setVar("sortmode", $sortmode); $delform->setVar("sortby", $sortby); $delform->setVar("appendparameters", $appendparameters); $delform->setVar("path", $path); $delform->setVar("frame", 4); // Table with (preview) images $delform->add("list", $output); $page->addScript('iZoom', ''); $page->addScript('style', ''); $sScriptinBody = ' '; $page->addScript('style', ''); $page->setContent($sScriptinBody . $sErrorMessage . $delform->render()); $page->render(); } uplSyncDirectory($path); uplRender($path, $sortby, $sortmode, $startpage, $thumbnailmode, $sErrorMessage); ?>