function main(&$backRef, $menuItems, $file, $uid) { // Returns directly, because the clicked item was not a file if ($backRef->cmLevel == 0 && $uid != '') { return $menuItems; } // Returns directly, because the clicked item was not the second level menu from DAM records if ($backRef->cmLevel == 1 && t3lib_div::_GP('subname') != 'tx_dam_cm_file') { return $menuItems; } $this->backRef =& $backRef; // this is second level menu from DAM records $fileDAM = t3lib_div::_GP('txdamFile'); $file = $fileDAM ? $fileDAM : $file; if (@is_file($file)) { $item = tx_dam::file_compileInfo($file); $permsEdit = tx_dam::access_checkFile($item) && tx_dam::access_checkFileOperation('editFile'); $permsDelete = tx_dam::access_checkFile($item) && tx_dam::access_checkFileOperation('deleteFile'); } elseif (@is_dir($file)) { $item = tx_dam::path_compileInfo($file); $permsEdit = tx_dam::access_checkPath($item) && tx_dam::access_checkFileOperation('renameFolder'); $permsDelete = tx_dam::access_checkPath($item) && tx_dam::access_checkFileOperation('deleteFolder'); } else { return $menuItems; } // clear the existing menu now and fill it with DAM specific things $damMenuItems = array(); // see typo3/alt_clickmenu.php:clickmenu::enableDisableItems() for iParts[3] // which is called after this function $backRef->iParts[3] = ''; $actionCall = t3lib_div::makeInstance('tx_dam_actionCall'); if (is_array($backRef->disabledItems)) { foreach ($backRef->disabledItems as $idName) { $actionCall->removeAction($idName); } } $actionCall->setRequest('context', $item); $actionCall->setEnv('returnUrl', t3lib_div::_GP('returnUrl')); $actionCall->setEnv('backPath', $backRef->PH_backPath); $actionCall->setEnv('defaultCmdScript', PATH_txdam_rel . 'mod_cmd/index.php'); $actionCall->setEnv('defaultEditScript', PATH_txdam_rel . 'mod_edit/index.php'); $actionCall->setEnv('actionPerms', tx_dam::access_checkFileOperation()); $actionCall->setEnv('permsEdit', $permsEdit); $actionCall->setEnv('permsDelete', $permsDelete); $actionCall->setEnv('cmLevel', $backRef->cmLevel); $actionCall->setEnv('cmParent', t3lib_div::_GP('parentname')); $actionCall->initActions(true); $actions = $actionCall->renderActionsContextMenu(true); foreach ($actions as $id => $action) { if ($action['isDivider']) { $damMenuItems[$id] = 'spacer'; } else { $onclick = $action['onclick'] ? $action['onclick'] : $this->createOnClick($action['url'], $action['dontHide']); $damMenuItems[$id] = $backRef->linkItem($GLOBALS['LANG']->makeEntities($action['label']), $backRef->excludeIcon($action['icon']), $onclick, $action['onlyCM'], $action['dontHide']); } } // clear the file context menu, allow additional items from extensions, // like TemplaVoila, and the display constraints // once a DAM file is found foreach ($menuItems as $key => $var) { if (!t3lib_div::inList('edit,rename,info,copy,cut,delete', $key) && !array_key_exists($key, $damMenuItems)) { $damMenuItems[$key] = $var; } } return $damMenuItems; }
/** * Making the form for create file * * @return string HTML content */ function renderForm($fileContent = '') { global $BE_USER, $LANG, $TYPO3_CONF_VARS; $content = ''; $msg = array(); $this->pObj->markers['FOLDER_INFO'] = tx_dam_guiFunc::getFolderInfoBar(tx_dam::path_compileInfo($this->pObj->media->pathAbsolute)); $msg[] = ' '; $this->pObj->markers['FILE_INFO'] = $GLOBALS['LANG']->sL('LLL:EXT:dam/locallang_db.xml:tx_dam_item.file_name', 1) . ' <strong>' . htmlspecialchars($this->pObj->media->filename) . '</strong>'; $msg[] = ' '; $msg[] = $GLOBALS['LANG']->getLL('tx_dam_cmd_filenew.text_content', 1); $msg[] = '<textarea rows="30" name="data[file_content]" wrap="off"' . $this->pObj->doc->formWidthText(48, 'width:99%;height:65%', 'off') . ' class="fixed-font enable-tab">' . t3lib_div::formatForTextarea($fileContent) . '</textarea>'; $this->pObj->docHeaderButtons['SAVE'] = '<input class="c-inputButton" name="_savedok"' . t3lib_iconWorks::skinImg($this->pObj->doc->backPath, 'gfx/savedok.gif') . ' title="' . $GLOBALS['LANG']->getLL('labelCmdSave', 1) . '" height="16" type="image" width="16">'; $this->pObj->docHeaderButtons['SAVE_CLOSE'] = '<input class="c-inputButton" name="_saveandclosedok"' . t3lib_iconWorks::skinImg($this->pObj->doc->backPath, 'gfx/saveandclosedok.gif') . ' title="' . $GLOBALS['LANG']->getLL('labelCmdSaveClose', 1) . '" height="16" type="image" width="16">'; $this->pObj->docHeaderButtons['CLOSE'] = '<a href="#" onclick="jumpBack(); return false;"><img' . t3lib_iconWorks::skinImg($this->pObj->doc->backPath, 'gfx/closedok.gif') . ' class="c-inputButton" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.cancel', 1) . '" alt="" height="16" width="16"></a>'; if (tx_dam::config_checkValueEnabled('mod.txdamM1_SHARED.displayExtraButtons', 1)) { $buttons = ' <input type="submit" name="save" value="' . $GLOBALS['LANG']->getLL('labelCmdSave', 1) . '" /> <input type="submit" name="_saveandclosedok_x" value="' . $GLOBALS['LANG']->getLL('labelCmdSaveClose', 1) . '" /> <input type="submit" value="' . $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.cancel', 1) . '" onclick="jumpBack(); return false;" />'; } $content .= $GLOBALS['SOBE']->getMessageBox($GLOBALS['SOBE']->pageTitle, $msg, $buttons, 1); return $content; }
/** * Fetches the data for the tree * * @param string Abs file path * @param integer Max depth (recursivity limit) * @param string HTML-code prefix for recursive calls. * @return integer The count of items on the level * @see getBrowsableTree() */ function getFolderTree($files_path, $depth = 999, $depthData = '') { // This generates the directory tree $dirs = t3lib_div::get_dirs($files_path); $c = 0; if (is_array($dirs)) { $depth = intval($depth); $HTML = ''; $a = 0; $c = count($dirs); natcasesort($dirs); foreach ($dirs as $key => $val) { $a++; $this->tree[] = array(); // Reserve space. end($this->tree); $treeKey = key($this->tree); // Get the key for this space $LN = $a == $c ? 'blank' : 'line'; $val = preg_replace('/^\\.\\//', '', $val); $title = $val; $path = $files_path . $val . '/'; $md5_uid = md5($path); $specUID = hexdec(substr($md5_uid, 0, 6)); $this->specUIDmap[$specUID] = $path; $row = array(); $row['path'] = $path; $row['uid'] = $specUID; $row['title'] = $title; if ($depth > 1 && $this->expandNext($specUID)) { $nextCount = $this->getFolderTree($path, $depth - 1, $this->makeHTML ? $depthData . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $LN . '.gif', 'width="18" height="16"') . ' alt="" />' : ''); $exp = 1; // Set "did expand" flag } else { $nextCount = $this->getCount($path); $exp = 0; // Clear "did expand" flag } // Set HTML-icons, if any: if ($this->makeHTML) { $HTML = $depthData . $this->PMicon($row, $a, $c, $nextCount, $exp); $pathInfo = tx_dam::path_compileInfo($path); $HTML .= $this->wrapIcon(tx_dam::icon_getFileTypeImgTag($pathInfo), $row); } // Finally, add the row/HTML content to the ->tree array in the reserved key. $this->tree[$treeKey] = array('row' => $row, 'HTML' => $HTML, 'bank' => $this->bank); } } return $c; }
/** * Output header with path info and folder browser * * @param string $pathInfo Path to show * @param boolean $browsable Define if the info header includes browsable links * @param array $extraIconArr Array of icons with extra HTML code which should be shown additionally at the end of the bar. Could be also a list of icon keys which should not be shown - is the same like array with empty value of a key * @param mixed $allowedIcons Show the icon keys which are allowed to show (array or comma list) * @return string HTML content */ function getPathInfoHeaderBar($pathInfo, $browsable = TRUE, $extraIconArr = array(), $allowedIcons = NULL) { global $LANG, $BACK_PATH, $FILEMOUNTS; $pathInfo = is_array($pathInfo) ? $pathInfo : tx_dam::path_compileInfo($pathInfo); $fileheader = $this->getFolderNavBar($pathInfo, $browsable, $allowedIcons); return $this->getInfoHeaderBar($fileheader, $browsable, $extraIconArr, $allowedIcons); }
/** * Creates a file/folder listing. * The list does not include any actions (delete,rename,...) but can be used to show the files of a folder. Browsing through folders is deactivated * * @param array $pathInfo Path info array from tx_dam::path_compileInfo() * @param boolean $renderFolderInfoBar If set a header with the path will be rendered * @return string HTML output */ function getStaticFolderList($pathInfo, $renderFolderInfoBar = true) { $content = ''; $pathInfo = is_array($pathInfo) ? $pathInfo : tx_dam::path_compileInfo($pathInfo); $this->_filebrowser_makeDataList($pathInfo); $this->_filebrowser_makePreset(); if ($renderFolderInfoBar) { $content .= '<div class="typo3-foldernavbar">' . tx_dam_guiFunc::getFolderInfoBar($pathInfo) . '</div>'; } $content .= $this->getListTable(); return $content; }
/** * Check if a path is accessable. * This includes if the path exist and if the user has access to it. * For further information, like readable, see path_compileInfo() * * Currently for BE usage only * * @param string $path The path * @return boolean True if path exist and user has access otherwise false. * @see tx_dam::path_compileInfo() */ function access_checkPath($path) { if ($pathInfo = tx_dam::path_compileInfo($path)) { if ($pathInfo['dir_accessable']) { return true; } } return false; }
/** * Main function, rendering the content of the rename form * * @return void */ function main() { global $LANG; $content = ''; // Cleaning and checking target $this->folder = tx_dam::path_compileInfo($this->pObj->folder[0]); if ($this->folder['dir_accessable']) { if (is_array($this->pObj->data) and $this->pObj->data['new_name']) { $newFolderName = tx_dam::file_makeCleanName($this->pObj->data['new_name'], true); $error = tx_dam::process_renameFolder($this->folder['dir_path_absolute'], $newFolderName); if ($error) { $content .= $GLOBALS['SOBE']->getMessageBox($LANG->getLL('error'), htmlspecialchars($error), $this->pObj->buttonBack(0), 2); } else { $this->pObj->redirect(true); } } else { $content .= $this->renderForm(); } } else { // this should have happen in index.php already $content .= $this->pObj->accessDeniedMessageBox(tx_dam_guiFunc::getFolderInfoBar($this->folder)); } return $content; }
/** * Returns an array with file/dir items + an array with the sorted items * * @param string Path (absolute) to read * @param mixed $allowTypes List or array of allow directory entry types: file, dir, link. Empty is all kinds of stuff. * @return void */ function read($path, $allowTypes = 'file') { $allowTypes = is_array($allowTypes) ? $allowTypes : t3lib_div::trimExplode(',', $allowTypes, true); if ($path) { $tempArray = array(); $path = tx_dam::path_makeAbsolute($path); if (is_object($d = @dir($path))) { while ($entry = $d->read()) { $filepath = $path . $entry; // check for allow file types: eg. file, dir, link if (@file_exists($filepath) && (!$allowTypes || in_array($type = filetype($filepath), $allowTypes))) { // if filename matches exclude list this file is skipped foreach ($this->excludeRegex as $expr) { if (preg_match($expr, $entry)) { continue 2; } } // if filename don't matches allow list this file is skipped foreach ($this->allowRegex as $expr) { if (!preg_match($expr, $entry)) { continue 2; } } if ($type === 'file') { $fileInfo = tx_dam::file_compileInfo($filepath); if (is_array($meta = tx_dam::meta_getDataForFile($fileInfo))) { // the newer stat data will be merged over the stored meta data $fileInfo = array_merge($meta, $fileInfo); } else { $mimeType = tx_dam::file_getType($filepath); $fileInfo = array_merge($fileInfo, $mimeType); } if (count($this->excludeFileTypes) and in_array($fileInfo['file_type'], $this->excludeFileTypes)) { continue; } if (count($this->allowFileTypes) and !in_array($fileInfo['file_type'], $this->allowFileTypes)) { continue; } if ($this->enableAutoIndexing) { $this->autoIndex($fileInfo); } } elseif ($type === 'dir' or $type === 'link') { $fileInfo = tx_dam::path_compileInfo($filepath); } // the file is valid so we add it to the list $this->entries[] = $fileInfo; $this->countBytes += $fileInfo['file_size']; } } $d->close(); $this->sort(); $this->rewind(); } } }
/** * tx_dam::path_compileInfo() */ public function test_path_compileInfo() { $GLOBALS['T3_VAR']['ext']['dam']['pathInfoCache'] = array(); $filepath = $this->getFixtureFilename(); $filename = tx_dam::file_basename($filepath); $testpath = tx_dam::file_dirname($filepath); $pathInfo = tx_dam::path_compileInfo($testpath); self::assertTrue(is_array($pathInfo), 'Path not found: ' . $testpath); self::assertTrue((bool) $pathInfo['dir_readable'], 'Path not readable: ' . $testpath); self::assertFALSE((bool) $pathInfo['mount_id'], 'Impossible mount found: ' . $pathInfo['mount_path'] . ' (' . $testpath . ')'); $pathInfo = tx_dam::path_compileInfo(PATH_site . 'fileadmin/'); self::assertTrue(is_array($pathInfo), 'Path not found: ' . $testpath); self::assertTrue((bool) $pathInfo['dir_readable'], 'Path not readable: ' . $testpath); self::assertTrue((bool) $pathInfo['mount_id'], 'No mount found: ' . $pathInfo['mount_path'] . ' (' . $testpath . ')'); }
/** * Main function, rendering the content of the rename form * * @return void */ function main() { global $LANG, $BACK_PATH; $content = ''; // Cleaning and checking target $this->folder = tx_dam::path_compileInfo($this->pObj->folder[0]); if ($this->folder['dir_accessable']) { $content .= $this->renderForm(); } else { // this should have happen in index.php already $content .= $this->pObj->accessDeniedMessageBox(tx_dam_guiFunc::getFolderInfoBar($this->folder)); } return $content; }
/** * Main function, rendering the content of the rename form * * @return void */ function main() { global $LANG; $content = ''; // Cleaning and checking target $this->folder = tx_dam::path_compileInfo($this->pObj->folder[0]); if (is_array($this->pObj->data) and $this->pObj->data['file_name']) { // create the file and process DB update $error = tx_dam::process_createFile($this->folder['dir_path_absolute'] . $this->pObj->data['file_name'], $this->pObj->data['file_content']); if ($error) { $content .= $GLOBALS['SOBE']->getMessageBox($LANG->getLL('error'), htmlspecialchars($error), '', 2); $content .= $this->renderForm(); } else { $this->pObj->redirect(true); } } elseif ($this->folder['dir_accessable']) { $content .= $this->renderForm(); } else { // this should have happen in index.php already $content .= $this->pObj->accessDeniedMessageBox(tx_dam_guiFunc::getFolderInfoBar($this->folder)); } return $content; }