本文整理汇总了PHP中Filesystem::cleanPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::cleanPath方法的具体用法?PHP Filesystem::cleanPath怎么用?PHP Filesystem::cleanPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::cleanPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addSubmenu
/**
* Configure the Submenu links.
*
* @param string The extension being used for the categories.
*
* @return void
* @since 1.6
*/
public static function addSubmenu($extension)
{
// Avoid nonsense situation.
if ($extension == 'com_categories') {
return;
}
$parts = explode('.', $extension);
$component = $parts[0];
if (count($parts) > 1) {
$section = $parts[1];
}
// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$file = Filesystem::cleanPath(PATH_CORE . '/components/' . $component . '/admin/helpers/' . $eName . '.php');
if (file_exists($file)) {
require_once $file;
$prefix = ucfirst(str_replace('com_', '', $component));
$cName = $prefix . 'Helper';
if (class_exists($cName)) {
if (is_callable(array($cName, 'addSubmenu'))) {
$lang = Lang::getRoot();
// loading language file from the administrator/language directory then
// loading language file from the administrator/components/*extension*/language directory
$lang->load($component, JPATH_BASE, null, false, true) || $lang->load($component, Filesystem::cleanPath(PATH_CORE . '/components/' . $component . '/admin'), null, false, true);
call_user_func(array($cName, 'addSubmenu'), 'categories' . (isset($section) ? '.' . $section : ''));
}
}
}
}
示例2: normalizePath
/**
* Strips trailing slashes and ensures path begins with a slash
*
* @param string $path Path to normalize
* @return string
*/
public static function normalizePath($path)
{
$path = \Filesystem::cleanPath($path);
// Make sure the path doesn't end with a slash
$path = rtrim($path, DS);
// Ensure the path starts with a slash
$path = ltrim($path, DS);
$path = DS . $path;
return $path;
}
示例3: populateState
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 1.6
*/
protected function populateState()
{
// Set the component (option) we are dealing with.
$component = Request::getCmd('component');
$this->setState('component.option', $component);
// Set an alternative path for the configuration file.
if ($path = Request::getString('path')) {
$path = Filesystem::cleanPath(PATH_ROOT . '/' . $path);
\Hubzero\Filesystem\Util::checkCheck($path);
$this->setState('component.path', $path);
}
}
示例4: parseXMLTemplateFile
public static function parseXMLTemplateFile($templateBaseDir, $templateDir)
{
$data = new \Hubzero\Base\Object();
// Check of the xml file exists
$filePath = Filesystem::cleanPath($templateBaseDir . '/templates/' . $templateDir . '/templateDetails.xml');
if (is_file($filePath)) {
$xml = JInstaller::parseXMLInstallFile($filePath);
if ($xml['type'] != 'template') {
return false;
}
foreach ($xml as $key => $value) {
$data->set($key, $value);
}
}
return $data;
}
示例5: preprocessForm
/**
* @param object A form object.
* @param mixed The data expected for the form.
* @throws Exception if there is an error in the form event.
* @since 1.6
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
// Initialise variables.
$clientId = $this->getState('item.client_id');
$template = $this->getState('item.template');
$lang = Lang::getRoot();
$client = \Hubzero\Base\ClientManager::client($clientId);
if (!$form->loadFile('style_' . $client->name, true)) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
$base = PATH_CORE;
if (is_dir(PATH_APP . '/templates/' . $template)) {
$base = PATH_APP;
}
$formFile = Filesystem::cleanPath($base . '/templates/' . $template . '/templateDetails.xml');
// Load the core and/or local language file(s).
$lang->load('tpl_' . $template, $base . '/bootstrap/' . $client->name, null, false, true) || $lang->load('tpl_' . $template, $base . '/templates/' . $template, null, false, true);
if (file_exists($formFile)) {
// Get the template form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
}
// Disable home field if it is default style
if (is_array($data) && array_key_exists('home', $data) && $data['home'] == '1' || is_object($data) && isset($data->home) && $data->home == '1') {
$form->setFieldAttribute('home', 'readonly', 'true');
}
// Attempt to load the xml file.
if (!($xml = simplexml_load_file($formFile))) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ? $helpKey : $this->helpKey;
$this->helpURL = $helpURL ? $helpURL : $this->helpURL;
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
示例6: copy
/**
* Method to check if new template name already exists
*
* @return boolean true if name is not used, false otherwise
* @since 2.5
*/
public function copy()
{
if ($template = $this->getTemplate()) {
$client = JApplicationHelper::getClientInfo($template->client_id);
$fromPath = Filesystem::cleanPath($client->path . '/templates/' . $template->element . '/');
// Delete new folder if it exists
$toPath = $this->getState('to_path');
if (Filesystem::exists($toPath)) {
if (!Filesystem::deleteDirectory($toPath)) {
Notify::warning(Lang::txt('COM_TEMPLATES_ERROR_COULD_NOT_WRITE'));
return false;
}
}
// Copy all files from $fromName template to $newName folder
if (!Filesystem::copyDirectory($fromPath, $toPath) || !$this->fixTemplateName()) {
return false;
}
return true;
} else {
Notify::warning(Lang::txt('COM_TEMPLATES_ERROR_INVALID_FROM_NAME'));
return false;
}
}
示例7: getFolderContent
/**
* Get remote folder content
*
* @param Google_DriveService $apiService Drive API service instance
* @param string $folderID Folder ID
* @param array $remotes Array of remote items
* @param string $path Path
* @param array $connections Array of local-remote connections
* @param array &$duplicates Collector array for duplicates
*
* @return void
*/
public static function getFolderContent($apiService, $folderID = 0, $remotes, $path = '', $since, $connections, &$duplicates)
{
// Check for what we need
if (!$apiService || !$folderID) {
return false;
}
$conIds = $connections['ids'];
$conPaths = $connections['paths'];
// Search param
$q = "'" . $folderID . "' in parents";
$parameters = array('q' => $q, 'fields' => 'items(id,title,mimeType,downloadUrl,md5Checksum,labels,fileSize,thumbnailLink,modifiedDate,parents/id,originalFilename,lastModifyingUserName,ownerNames)');
// Get a list of files in remote folder
try {
$data = $apiService->files->listFiles($parameters);
if (!empty($data['items'])) {
$lpath = $path ? $path : '';
foreach ($data['items'] as $item) {
$time = strtotime($item['modifiedDate']);
$status = $item['labels']['trashed'] ? 'D' : 'A';
$skip = 0;
// Check against modified date
$changed = strtotime(date("c", strtotime($item['modifiedDate']))) - strtotime($since);
if ($since && $changed <= 0 && $item['labels']['trashed'] != 1) {
$skip = 1;
}
$converted = preg_match("/google-apps/", $item['mimeType']) && !preg_match("/.folder/", $item['mimeType']) ? 1 : 0;
$url = isset($item['downloadUrl']) ? $item['downloadUrl'] : '';
$original = isset($item['originalFilename']) ? $item['originalFilename'] : '';
$thumb = isset($item['thumbnailLink']) ? $item['thumbnailLink'] : NULL;
$author = isset($item['lastModifyingUserName']) ? utf8_encode($item['lastModifyingUserName']) : utf8_encode($item['ownerNames'][0]);
if (!preg_match("/.folder/", $item['mimeType'])) {
$title = Filesystem::clean($item['title']);
if ($converted) {
$ext = self::getGoogleConversionFormat($item['mimeType'], false, true);
if ($ext) {
$title = $title . '.' . $ext;
}
}
$type = 'file';
} else {
$title = Filesystem::cleanPath($item['title']);
$type = 'folder';
}
$fpath = $lpath ? $lpath . DS . $title : $title;
$synced = isset($conIds[$item['id']]) ? $conIds[$item['id']]['synced'] : NULL;
$md5Checksum = isset($item['md5Checksum']) ? $item['md5Checksum'] : NULL;
$fileSize = isset($item['fileSize']) ? $item['fileSize'] : NULL;
/// Make sure path is not already used (Google allows files with same name in same dir, Git doesn't)
$fpath = self::buildDuplicatePath($item['id'], $fpath, $item['mimeType'], $connections, $remotes, $duplicates);
// Detect a rename or move
$rename = '';
if (isset($conIds[$item['id']])) {
$oFilePath = $conIds[$item['id']]['path'];
$oDirPath = $conIds[$item['id']]['dirpath'];
$nDirPath = dirname($fpath) == '.' ? '' : dirname($fpath);
$nFilePath = $fpath;
if ($oDirPath != $nDirPath && $oFilePath != $nFilePath) {
$status = 'W';
$rename = $oFilePath;
} elseif ($oFilePath != $nFilePath) {
$status = 'R';
$rename = $oFilePath;
}
}
// Check that file was last synced after modified date
// (important to pick up failed updates)
if (isset($conIds[$item['id']])) {
if ($conIds[$item['id']]['modified'] < gmdate('Y-m-d H:i:s', $time)) {
$skip = 0;
}
} elseif ($status == 'A') {
// Never skip new files
$skip = 0;
}
if (!$skip) {
$remotes[$fpath] = array('status' => $status, 'time' => $time, 'modified' => gmdate('Y-m-d H:i:s', $time), 'type' => $type, 'local_path' => $fpath, 'remoteid' => $item['id'], 'title' => $item['title'], 'converted' => $converted, 'rParent' => self::getParentID($item['parents']), 'url' => $url, 'original' => $original, 'author' => $author, 'synced' => $synced, 'md5' => $md5Checksum, 'mimeType' => $item['mimeType'], 'thumb' => $thumb, 'rename' => $rename, 'fileSize' => $fileSize);
}
if (preg_match("/.folder/", $item['mimeType'])) {
// Recurse
$remotes = self::getFolderContent($apiService, $item['id'], $remotes, $fpath, $since, $connections, $duplicates);
}
}
}
} catch (Exception $e) {
return $remotes;
}
return $remotes;
}
示例8: _addFromExtracted
/**
* Add files to repo from extracted archive
*
* @return boolean
*/
protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
{
$reserved = isset($params['reserved']) ? $params['reserved'] : array();
$dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
$extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
// check for viruses - scans the directory for efficency
$command = "clamscan -i --no-summary --block-encrypted -r " . $extractPath;
exec($command, $output, $virus_status);
$virusChecked = FALSE;
if ($virus_status == 0) {
$virusChecked = TRUE;
} else {
Filesystem::deleteDirectory($extractPath);
$this->setError('The antivirus software has rejected your files.');
return false;
}
$z = 0;
foreach ($extracted as $e) {
$fileinfo = pathinfo($e);
$a_dir = $fileinfo['dirname'];
$a_dir = str_replace($extractPath . DS, '', $a_dir);
// Skip certain system files
if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
continue;
}
$file = $fileinfo['basename'];
$size = filesize($e);
// Run some checks, stop in case of a problem
if (!$this->_check($file, $e, $size, $available, $virusChecked)) {
return false;
}
// Clean up filename
$safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
$safe_dir = trim($safe_dir, DS);
$safe_file = Filesystem::clean($file);
// Strips out temporary path
if (strpos($safe_dir, 'tmp/') !== FALSE) {
$parts = explode('/', $safe_dir);
$safe_dir = str_replace($parts[0] . '/', '', $safe_dir);
$safe_dir = str_replace($parts[1] . '/', '', $safe_dir);
}
$skipDir = false;
if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
$skipDir = true;
}
$safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
$localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
$where = $target . DS . $safeName;
$exists = is_file($where) ? true : false;
// Provision directory
if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
// File object
$localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
$fileObject = new Models\File(trim($localDirPath), $this->get('path'));
$fileObject->set('type', 'folder');
$params['file'] = $fileObject;
$params['replace'] = false;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
// Strips out temporary path
if (strpos($safeName, 'tmp/') !== FALSE) {
$parts = explode('/', $safeName);
$safeName = str_replace($parts[0] . '/', '', $safeName);
$safeName = str_replace($parts[1] . '/', '', $safeName);
}
// Copy file into project
if (Filesystem::copy($e, $target . DS . $safeName)) {
// File object
$fileObject = new Models\File(trim($localPath), $this->get('path'));
$params['file'] = $fileObject;
$params['replace'] = $exists;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
return $z;
}
示例9: _addFromExtracted
/**
* Add files to repo from extracted archive
*
* @return boolean
*/
protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
{
$reserved = isset($params['reserved']) ? $params['reserved'] : array();
$dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
$extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
$z = 0;
foreach ($extracted as $e) {
$fileinfo = pathinfo($e);
$a_dir = $fileinfo['dirname'];
$a_dir = str_replace($extractPath . DS, '', $a_dir);
// Skip certain system files
if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
continue;
}
$file = $fileinfo['basename'];
$size = filesize($e);
// Run some checks, stop in case of a problem
if (!$this->_check($file, $e, $size, $available)) {
return false;
}
// Clean up filename
$safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
$safe_dir = trim($safe_dir, DS);
$safe_file = Filesystem::clean($file);
$skipDir = false;
if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
$skipDir = true;
}
$safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
$localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
$where = $target . DS . $safeName;
$exists = is_file($where) ? true : false;
// Provision directory
if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
// File object
$localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
$fileObject = new Models\File(trim($localDirPath), $this->get('path'));
$fileObject->set('type', 'folder');
$params['file'] = $fileObject;
$params['replace'] = false;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
// Copy file into project
if (Filesystem::copy($e, $target . DS . $safeName)) {
// File object
$fileObject = new Models\File(trim($localPath), $this->get('path'));
$params['file'] = $fileObject;
$params['replace'] = $exists;
// Success - check in change
$this->call('checkin', $params);
$z++;
}
}
return $z;
}
示例10: delete
/**
* Deletes paths from the current path
*
* @since 1.5
*/
public function delete()
{
Session::checkToken(['get', 'post']);
// Get some data from the request
$tmpl = Request::getCmd('tmpl');
$paths = Request::getVar('rm', array(), '', 'array');
$folder = Request::getVar('folder', '', '', 'path');
$redirect = 'index.php?option=com_media&folder=' . $folder;
if ($tmpl == 'component') {
// We are inside the iframe
$redirect .= '&view=mediaList&tmpl=component';
}
$this->setRedirect($redirect);
// Nothing to delete
if (empty($paths)) {
return true;
}
// Authorize the user
if (!$this->authoriseUser('delete')) {
return false;
}
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
// Initialise variables.
$ret = true;
foreach ($paths as $path) {
if ($path !== Filesystem::clean($path)) {
// filename is not safe
$filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE))));
continue;
}
$fullPath = Filesystem::cleanPath(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
$object_file = new \Hubzero\Base\Object(array('filepath' => $fullPath));
if (is_file($fullPath)) {
// Trigger the onContentBeforeDelete event.
$result = Event::trigger('content.onContentBeforeDelete', array('com_media.file', &$object_file));
if (in_array(false, $result, true)) {
// There are some errors in the plugins
Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
continue;
}
$ret &= Filesystem::delete($fullPath);
// Trigger the onContentAfterDelete event.
Event::trigger('content.onContentAfterDelete', array('com_media.file', &$object_file));
$this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
} elseif (is_dir($fullPath)) {
$contents = Filesystem::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));
if (empty($contents)) {
// Trigger the onContentBeforeDelete event.
$result = Event::trigger('content.onContentBeforeDelete', array('com_media.folder', &$object_file));
if (in_array(false, $result, true)) {
// There are some errors in the plugins
Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
continue;
}
$ret &= Filesystem::deleteDirectory($fullPath);
// Trigger the onContentAfterDelete event.
Event::trigger('content.onContentAfterDelete', array('com_media.folder', &$object_file));
$this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
} else {
// This makes no sense...
Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE))));
}
}
}
return $ret;
}
示例11: preprocessForm
/**
* Method to preprocess the form.
*
* @param JForm $form A JForm object.
* @param mixed $data The data expected for the form.
* @param string $groups The name of the plugin group to import.
*
* @return void
*
* @see JFormField
* @since 1.6
* @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $group = 'content')
{
jimport('joomla.filesystem.path');
// Initialise variables.
$extension = $this->getState('category.extension');
$component = $this->getState('category.component');
$section = $this->getState('category.section');
// Get the component form if it exists
$name = 'category' . ($section ? '.' . $section : '');
// Looking first in the component models/forms folder
$path = Filesystem::cleanPath(PATH_CORE . "/components/{$component}/admin/models/forms/{$name}.xml");
// Old way: looking in the component folder
if (!file_exists($path)) {
$path = Filesystem::cleanPath(PATH_CORE . "/components/{$component}/admin/{$name}.xml");
}
if (file_exists($path)) {
Lang::load($component, JPATH_BASE, null, false, true);
Lang::load($component, PATH_CORE . '/components/' . $component . '/admin', null, false, true);
if (!$form->loadFile($path, false)) {
throw new Exception(Lang::txt('JERROR_LOADFILE_FAILED'));
}
}
// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$path = Filesystem::cleanPath(PATH_CORE . "/components/{$component}/admin/helpers/category.php");
if (file_exists($path)) {
require_once $path;
$cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) {
Lang::load($component, JPATH_BASE, null, false, true) || Lang::load($component, Filesystem::cleanPath(PATH_CORE . '/components/' . $component . '/admin'), null, false, true);
call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
// Check for an error.
if ($form instanceof Exception) {
$this->setError($form->getMessage());
return false;
}
}
}
// Set the access control rules field component value.
$form->setFieldAttribute('rules', 'component', $component);
$form->setFieldAttribute('rules', 'section', $name);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}