function getFolder($id = '', $folderPath = '', &$response, $noError = false) { global $EDITOR, $DIALOG; // initial var check... if (!is_string($id) && !is_int($id) || !is_string($folderPath)) { if ($response) { $response->addAlert('Datatype error.'); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = 'Datatype error.'; $msg->alert(); } } $fs = new wproFilesystem(); $this->instanceSupport($this->params); if ($id != '') { if ($id == 'image') { $dir = $EDITOR->getDirectories('image'); $dir = $dir[0]; } else { if ($id == 'media') { $dir = $EDITOR->getDirectories('media'); $dir = $dir[0]; } else { if ($id == 'document' || $id == 'link') { $dir = $EDITOR->getDirectories('document'); $dir = $dir[0]; } else { $dir = $EDITOR->getDirById(intval($id)); } } } if ($dir) { if (!empty($dir->dir)) { $changed = false; // check validity of folderPath if ($folderPath != '' && !$fs->dirNameOK($folderPath)) { if (!$noError) { if ($response) { $response->addAlert($DIALOG->langEngine->get('wproCore_fileBrowser', 'badFolderPath')); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = $DIALOG->langEngine->get('wproCore_fileBrowser', 'JSBadFolderPath'); $msg->alert(); } } else { $folderpath = ''; $changed = true; } } if ($folderPath == '/') { $folderpath = ''; } if ($folderPath != '') { // add trailing / if (substr($folderPath, strlen($folderPath) - 1) != '/') { $folderPath .= '/'; } // remove beginning slash if (substr($folderPath, 0, 1) == '/') { $folderPath = substr($folderPath, 1); } } // check that folderpath does not match a filter if (!empty($folderPath)) { $fs = new wproFilesystem(); if ($fs->filterMatch(basename($folderPath), $dir->filters)) { $folderpath = ''; } } // check validity of dir object $oDirectory = $dir->dir; if ($oDirectory != '') { // add trailing / if (substr($oDirectory, strlen($oDirectory) - 1) != '/') { $oDirectory .= '/'; } } $oURL = $dir->URL; if ($oURL != '') { // add trailing / if (substr($oURL, strlen($oURL) - 1) != '/') { $oURL .= '/'; } } if ($noError && $folderPath != '') { if (!file_exists($oDirectory . $folderPath)) { $folderpath = ''; $changed = true; } } // we now have the actual folder and the URL for the folder $directory = $oDirectory . $folderPath; $URL = $oURL . $folderPath; // if the folder does not exist, or is not a folder we must exit if (!file_exists($directory) || is_file($directory)) { if ($response) { $response->addAlert($DIALOG->langEngine->get('wproCore_fileBrowser', 'fileNotExistError')); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = $DIALOG->langEngine->get('wproCore_fileBrowser', 'JSFileNotExistError'); $msg->alert(); } } return array('dir' => $dir, 'directory' => $directory, 'URL' => $URL, 'changed' => $changed); } else { if ($response) { $response->addAlert('The specified directory object is not correctly configured'); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = 'The specified directory object is not correctly configured'; $msg->alert(); } } } else { if ($response) { $response->addAlert('No directory matches this ID'); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = 'No directory matches this ID'; $msg->alert(); } } } else { if ($response) { $response->addAlert('No directory ID specified'); return false; } else { require_once WPRO_DIR . 'core/libs/wproMessageExit.class.php'; $msg = new wproMessageExit(); $msg->msgCode = WPRO_CRITICAL; $msg->msg = 'No directory ID specified'; $msg->alert(); } } }