本文整理汇总了PHP中Path::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::clean方法的具体用法?PHP Path::clean怎么用?PHP Path::clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path::clean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: folder_slug_exists
/**
* folder_slug_exists
* Checks to see if a given folder $slug exists within any of the given $folders
*
* @param array $folders List of folders to look through
* @param string $slug Slug to check for
* @return boolean
*/
public static function folder_slug_exists($folders, $slug)
{
foreach ($folders as $key => $entry) {
$nslug = substr(Path::clean($entry['slug']), 2);
if ($nslug == $slug) {
return true;
}
}
return false;
}
示例2: get_content_tree
public static function get_content_tree($directory = '/', $depth = 1, $max_depth = 5, $folders_only = false, $include_entries = false, $hide_hidden = true, $include_content = false, $site_root = false)
{
// $folders_only = true only page.md
// folders_only = false includes any numbered or non-numbered page (excluding anything with a fields.yaml file)
// if include_entries is true then any numbered files are included
$content_root = Config::getContentRoot();
$content_type = Config::getContentType();
$site_root = $site_root ? $site_root : Config::getSiteRoot();
$current_url = Path::tidy($site_root . '/' . Request::getResourceURI());
$taxonomy_url = false;
if (Taxonomy::isTaxonomyURL($current_url)) {
list($taxonomy_type, $taxonomy_name) = Taxonomy::getCriteria($current_url);
$taxonomy_url = self::remove_taxonomy_from_path($current_url, $taxonomy_type, $taxonomy_name);
}
$directory = '/' . $directory . '/';
#ensure proper slashing
if ($directory != '/') {
$base = Path::tidy("{$content_root}/{$directory}");
} elseif ($directory == '/') {
$base = "{$content_root}";
} else {
$base = "{$content_root}";
}
$files = glob("{$base}/*");
$data = array();
if ($files) {
foreach ($files as $path) {
$current_name = basename($path);
if (!Pattern::endsWith($current_name, '.yaml')) {
// Hidden page that should be removed
if ($hide_hidden && Pattern::startsWith($current_name, '_')) {
continue;
}
$node = array();
$file = substr($path, strlen($base) + 1, strlen($path) - strlen($base) - strlen($content_type) - 2);
if (is_dir($path)) {
$folder = substr($path, strlen($base) + 1);
$node['type'] = 'folder';
$node['slug'] = basename($folder);
$node['title'] = ucwords(basename($folder));
$node['numeric'] = Slug::getOrderNumber($folder);
$node['file_path'] = Path::tidy($site_root . '/' . $directory . '/' . $folder . '/page');
if (Slug::isNumeric($folder)) {
$pos = strpos($folder, ".");
if ($pos !== false) {
$node['raw_url'] = Path::tidy(Path::clean($site_root . '/' . $directory . '/' . $folder));
$node['url'] = Path::clean($node['raw_url']);
$node['title'] = ucwords(basename(substr($folder, $pos + 1)));
} else {
$node['title'] = ucwords(basename($folder));
$node['raw_url'] = Path::tidy($site_root . '/' . $directory . '/' . $folder);
$node['url'] = Path::clean($node['raw_url']);
}
} else {
$node['title'] = ucwords(basename($folder));
$node['raw_url'] = Path::tidy($site_root . '/' . $directory . '/' . $folder);
$node['url'] = Path::clean($node['raw_url']);
}
$node['depth'] = $depth;
$node['children'] = $depth < $max_depth ? self::get_content_tree($directory . $folder . '/', $depth + 1, $max_depth, $folders_only, $include_entries, $hide_hidden, $include_content, $site_root) : null;
$node['is_current'] = $node['raw_url'] == $current_url || $node['url'] == $current_url ? true : false;
$node['is_parent'] = false;
if ($node['url'] == URL::popLastSegment($current_url) || $taxonomy_url && $node['url'] == $taxonomy_url) {
$node['is_parent'] = true;
}
$node['has_children'] = $node['children'] ? true : false;
// has entries?
if (File::exists(Path::tidy($path . "/fields.yaml"))) {
$node['has_entries'] = true;
} else {
$node['has_entries'] = false;
}
$meta = self::get_content_meta("page", Path::tidy($directory . "/" . $folder), false, true);
//$meta = self::get_content_meta("page", Statamic_Helper::reduce_double_slashes($directory."/".$folder));
if (isset($meta['title'])) {
$node['title'] = $meta['title'];
}
if (isset($meta['last_modified'])) {
$node['last_modified'] = $meta['last_modified'];
}
if ($hide_hidden === true && (isset($meta['status']) && ($meta['status'] == 'hidden' || $meta['status'] == 'draft'))) {
// placeholder condition
} else {
$data[] = $include_content ? array_merge($meta, $node) : $node;
// print_r($data);
}
} else {
if (Pattern::endsWith($path, $content_type)) {
if ($folders_only == false) {
if ($file == 'page' || $file == 'feed' || $file == '404') {
// $node['url'] = $directory;
// $node['title'] = basename($directory);
// $meta = self::get_content_meta('page', substr($directory, 1));
// $node['depth'] = $depth;
} else {
$include = true;
// date based is never included
if (Config::getEntryTimestamps() && Slug::isDateTime(basename($path))) {
$include = false;
} elseif (Slug::isDate(basename($path))) {
//.........这里部分代码省略.........
示例3: update
/**
* Updates the internal content cache
*
* @return boolean
*/
public static function update()
{
// track if any files have changed
$files_changed = false;
// grab length of content type extension
$content_type = Config::getContentType();
$full_content_root = rtrim(Path::tidy(BASE_PATH . "/" . Config::getContentRoot()), "/");
$content_type_length = strlen($content_type) + 1;
// the cache file we'll use
$cache_file = BASE_PATH . "/_cache/_app/content/content.php";
$time_file = BASE_PATH . "/_cache/_app/content/last.php";
$now = time();
// grab the existing cache
$cache = unserialize(File::get($cache_file));
if (!is_array($cache)) {
$cache = array("urls" => array(), "content" => array(), "taxonomies" => array());
}
$last = File::get($time_file);
// grab a list of all files
$finder = new Finder();
$files = $finder->files()->name("*." . Config::getContentType())->in(Config::getContentRoot());
// grab a separate list of files that have changed since last check
$updated_files = clone $files;
$updated = array();
if ($last) {
$updated_files->date(">= " . Date::format("Y-m-d H:i:s", $last));
foreach ($updated_files as $file) {
// we don't want directories, they may show up as being modified
// if a file inside them has changed or been renamed
if (is_dir($file)) {
continue;
}
// this isn't a directory, add it to the list
$updated[] = Path::trimFilesystem(Path::standardize($file->getRealPath()));
}
}
// loop over current files
$current_files = array();
foreach ($files as $file) {
$current_files[] = Path::trimFilesystem(Path::standardize($file->getRealPath()));
}
// get a diff of files we know about and files currently existing
$new_files = array_diff($current_files, $cache['urls']);
// create a master list of files that need updating
$changed_files = array_unique(array_merge($new_files, $updated));
// add to the cache if files have been updated
if (count($changed_files)) {
$files_changed = true;
// build content cache
foreach ($changed_files as $file) {
$file = $full_content_root . $file;
$local_path = Path::trimFilesystem($file);
$local_filename = Path::clean($local_path);
// file parsing
$content = substr(File::get($file), 3);
$divide = strpos($content, "\n---");
$front_matter = trim(substr($content, 0, $divide));
// parse data
$data = YAML::parse($front_matter);
// set additional information
$data['_file'] = $file;
$data['_local_path'] = $local_path;
$data['_order_key'] = null;
$data['datetimestamp'] = null;
// legacy
$data['datestamp'] = null;
$data['date'] = null;
$data['time'] = null;
$data['numeric'] = null;
$data['last_modified'] = filemtime($file);
$data['_is_hidden'] = false;
$data['_is_draft'] = false;
// folder
$data['_folder'] = preg_replace(Pattern::ORDER_KEY, "", str_replace($full_content_root, "", $data['_file']));
$slash = strrpos($data['_folder'], "/");
$data['_folder'] = $slash === 0 ? "" : substr($data['_folder'], 1, $slash - 1);
// fix hidden/draft files
$slug = basename($file, "." . $content_type);
if (substr($slug, 0, 2) === "__") {
$data['_is_hidden'] = true;
$data['slug'] = substr($slug, 2);
} elseif (substr($slug, 0, 1) === "_") {
$data['_is_draft'] = true;
$data['slug'] = substr($slug, 1);
} else {
$data['slug'] = $slug;
}
$data['_basename'] = $data['slug'] . "." . $content_type;
$data['_filename'] = $data['slug'];
$data['_is_entry'] = preg_match(Pattern::ENTRY_FILEPATH, $data['_basename']);
$data['_is_page'] = preg_match(Pattern::PAGE_FILEPATH, $data['_basename']);
// 404 is special
if ($data['_local_path'] === "/404.{$content_type}") {
$local_filename = $local_path;
// order key
//.........这里部分代码省略.........
示例4: aliases
/**
* Adds or deletes path aliases
*
* @uses Module::action
* @uses Path::load
* @uses Path::save
*/
protected function aliases()
{
// Create and save alias for the post
$values = array();
$path = Path::load($this->rawurl);
if ($path) {
$values['id'] = (int) $path['id'];
}
$alias = empty($this->path) ? $this->_object_plural . '/' . $this->title : $this->path;
$values['source'] = $this->rawurl;
$values['alias'] = Path::clean($alias);
$values['type'] = NULL;
$values['action'] = empty($this->action) ? $this->type : $this->action;
$values = Module::action('post_aliases', $values, $this);
Path::save($values);
}
示例5: cron
$output->nav['copyright'] = $root . 'COPYING';
// title and headline
$output->title[0] = 'infoschool';
$output->headline[0] = 'infoschool';
// navigation menu
$output->menu['./'] = 'start';
$output->menu['calendar/'] = 'calendar';
$output->menu['supply/'] = 'supply schedule';
$output->menu['forum/'] = 'Forum';
$output->menu['files/'] = 'file exchange';
$output->menu['messages/'] = 'Messages';
// $output->menu['zensuren/'] = 'grades';
$output->menu['news/'] = 'News';
// $output->menu['benutzer/'] = 'users';
$output->menu['users/'] = 'Users';
if (isset($_SESSION['admin']) && $_SESSION['admin']) {
$output->menu['statistics/'] = 'statistics';
}
$output->menu['dokumentation/'] = 'help';
$output->menu['dokumentation/faq.php'] = 'faq';
$output->menu['about/'] = 'About';
// subdir of the software
$webdir = Path::clean(Path::rm_last($_SERVER['SCRIPT_NAME']) . $root);
// system-root for the user: http://server.domain.tld/foo/
$http_root = 'http://' . $_SERVER['SERVER_NAME'] . $webdir;
// starts outstanding jobs
$cron = new cron();
// $output->out_of_service = true;
if (isset($_GET['oos'])) {
$output->out_of_service = $_GET['oos'];
}
示例6: extractCustom
/**
* Extract a ZIP compressed file to a given path using a php based algorithm that only requires zlib support
*
* @param string $archive Path to ZIP archive to extract.
* @param string $destination Path to extract archive into.
*
* @return mixed True if successful
*
* @since 1.0
* @throws \RuntimeException
*/
protected function extractCustom($archive, $destination)
{
$this->data = null;
$this->metadata = null;
$this->data = file_get_contents($archive);
if (!$this->data) {
throw new \RuntimeException('Unable to read archive (zip)');
}
if (!$this->readZipInfo($this->data)) {
throw new \RuntimeException('Get ZIP Information failed');
}
for ($i = 0, $n = count($this->metadata); $i < $n; $i++) {
$lastPathCharacter = substr($this->metadata[$i]['name'], -1, 1);
if ($lastPathCharacter !== '/' && $lastPathCharacter !== '\\') {
$buffer = $this->getFileData($i);
$path = Path::clean($destination . '/' . $this->metadata[$i]['name']);
// Make sure the destination folder exists
if (!Folder::create(dirname($path))) {
throw new \RuntimeException('Unable to create destination');
}
if (File::write($path, $buffer) === false) {
throw new \RuntimeException('Unable to write entry');
}
}
}
return true;
}
示例7: _aliases
/**
* Adds or deletes path aliases
*
* @uses Path::load
* @uses Path::clean
* @uses Module::action
*/
private function _aliases()
{
// Create and save alias for the post
$values = array();
$path = Path::load($this->rawurl);
if ($path) {
$values['id'] = (int) $path['id'];
}
$alias = empty($this->path) ? 'category/' . $this->name : $this->path;
$values['source'] = $this->rawurl;
$values['alias'] = Path::clean($alias);
$values['type'] = $this->type;
$values['action'] = empty($this->action) ? 'category' : $this->action;
$values = Module::action('term_aliases', $values, $this);
Path::save($values);
}
示例8: redirect
/**
* Wandelt eine relative URL in eine absolute um und modifiziert den
* HTTP-Header(Location). Kehrt nicht zurück.
* @param $path Pfad zur aufzurufenden Webseite
* @param $arg GET-Argumente (?x=23&y=42)
* @param $ilink HTML-interner Link (#foo)
* @return never, Funktion terminiert die Ausführung und kehrt nicht zurück.
*/
function redirect($path = '', $arg = array(), $ilink = '')
{
$protocol = 'http://';
$host = $_SERVER['HTTP_HOST'];
$file = $_SERVER['PHP_SELF'];
$pos = strpos($path, '://');
if ($pos) {
$pos += 3;
$protocol = substr($path, 0, $pos);
$path = substr($path, $pos);
$pos = strpos($path, '/');
$host = substr($path, 0, $pos);
$path = substr($path, $pos);
}
if (!$path) {
$path = $file;
}
if (substr($path, 0, 1) != '/') {
$path = Path::rm_last($file) . $path;
}
$path = Path::clean($path);
if (strstr($path, '#')) {
list($path, $internal_link) = explode('#', $path);
if ($ilink == false) {
$ilink = $internal_link;
}
}
if (is_array($arg) && sizeof($arg) > 0) {
if (strstr($path, '?')) {
$z = '&';
} else {
$z = '?';
}
foreach ($arg as $n => $v) {
$path .= $z . $n . '=' . $v;
$z = '&';
}
}
$path = sessionurl($path);
if ($ilink && substr($_SERVER['HTTP_USER_AGENT'], 0, 5) != 'Opera') {
$path .= '#' . $ilink;
}
if (substr($path, 0, 7) != $protocol) {
$path = $protocol . $host . $path;
}
header('Location:' . $path);
exit;
}
示例9: test_clean_not_to_upper_dir
function test_clean_not_to_upper_dir()
{
$path = '../bla.php';
$this->assertEquals('bla.php', Path::clean($path));
}
示例10: listFolderTree
/**
* Lists folder in format suitable for tree display.
*
* @param string $path The path of the folder to read.
* @param string $filter A filter for folder names.
* @param integer $maxLevel The maximum number of levels to recursively read, defaults to three.
* @param integer $level The current level, optional.
* @param integer $parent Unique identifier of the parent folder, if any.
*
* @return array Folders in the given folder.
*
* @since 1.0
*/
public static function listFolderTree($path, $filter, $maxLevel = 3, $level = 0, $parent = 0)
{
$dirs = array();
if ($level == 0) {
$GLOBALS['_JFolder_folder_tree_index'] = 0;
}
if ($level < $maxLevel) {
$folders = self::folders($path, $filter);
// First path, index foldernames
foreach ($folders as $name) {
$id = ++$GLOBALS['_JFolder_folder_tree_index'];
$fullName = Path::clean($path . '/' . $name);
$dirs[] = array('id' => $id, 'parent' => $parent, 'name' => $name, 'fullname' => $fullName, 'relname' => str_replace(JPATH_ROOT, '', $fullName));
$dirs2 = self::listFolderTree($fullName, $filter, $maxLevel, $level + 1, $id);
$dirs = array_merge($dirs, $dirs2);
}
}
return $dirs;
}
示例11: remove_numerics_from_path
/**
* remove_numerics_from_path
* Strips out any instances of a numeric ordering from a given $path
*
* @deprecated Use Path::clean() instead
*
* @param string $path String to strip out numerics from
* @return string
*/
public static function remove_numerics_from_path($path)
{
Log::warn("Use of Statamic_Helper::remove_numerics_from_path() is deprecated. Use Path::clean() instead.", "core", "Statamic_Helper");
return Path::clean($path);
}
示例12: update
/**
* Updates the internal content cache
*
* @return boolean
*/
public static function update()
{
// start measuring
$content_hash = Debug::markStart('caching', 'content');
// track if any files have changed
$files_changed = false;
$settings_changed = false;
$members_changed = false;
// grab length of content type extension
$content_type = Config::getContentType();
$full_content_root = rtrim(Path::tidy(BASE_PATH . "/" . Config::getContentRoot()), "/");
$content_type_length = strlen($content_type) + 1;
// the cache files we'll use
$cache_file = BASE_PATH . '/_cache/_app/content/content.php';
$settings_file = BASE_PATH . '/_cache/_app/content/settings.php';
$structure_file = BASE_PATH . '/_cache/_app/content/structure.php';
$time_file = BASE_PATH . '/_cache/_app/content/last.php';
$members_file = BASE_PATH . '/_cache/_app/members/members.php';
$now = time();
// start measuring settings hash
$settings_hash = Debug::markStart('caching', 'settings');
// check for current and new settings
$settings = unserialize(File::get($settings_file));
if (!is_array($settings)) {
$settings = array('site_root' => '', 'site_url' => '', 'timezone' => '', 'date_format' => '', 'time_format' => '', 'content_type' => '', 'taxonomy' => '', 'taxonomy_case_sensitive' => '', 'taxonomy_force_lowercase' => '', 'entry_timestamps' => '', 'base_path' => '', 'app_version' => '');
}
// look up current settings
$current_settings = array('site_root' => Config::getSiteRoot(), 'site_url' => Config::getSiteURL(), 'timezone' => Config::get('timezone'), 'date_format' => Config::get('date_format'), 'time_format' => Config::get('time_format'), 'content_type' => Config::get('content_type'), 'taxonomy' => Config::getTaxonomies(), 'taxonomy_case_sensitive' => Config::getTaxonomyCaseSensitive(), 'taxonomy_force_lowercase' => Config::getTaxonomyForceLowercase(), 'entry_timestamps' => Config::getEntryTimestamps(), 'base_path' => BASE_PATH, 'app_version' => STATAMIC_VERSION);
// have cache-altering settings changed?
if ($settings !== $current_settings) {
// settings have changed
$settings_changed = true;
// clear the cache and set current settings
$cache = self::getCleanCacheArray();
$settings = $current_settings;
$last = null;
} else {
// grab the existing cache
$cache = unserialize(File::get($cache_file));
if (!is_array($cache)) {
$cache = self::getCleanCacheArray();
}
$last = File::get($time_file);
}
// mark end of settings hash measuring
Debug::markEnd($settings_hash);
// grab a list of all content files
$files = File::globRecursively(Path::tidy(BASE_PATH . '/' . Config::getContentRoot() . '/*'), Config::getContentType());
// grab a separate list of files that have changed since last check
$updated = array();
$current_files = array();
// loop through files, getting local paths and checking for updated files
foreach ($files as $file) {
$local_file = Path::trimFilesystemFromContent(Path::standardize($file));
// add to current files
$current_files[] = $local_file;
// is this updated?
if ($last && File::getLastModified($file) >= $last) {
$updated[] = $local_file;
}
}
// get a diff of files we know about and files currently existing
$known_files = array();
foreach ($cache['urls'] as $url_data) {
array_push($known_files, $url_data['path']);
}
$new_files = array_diff($current_files, $known_files);
// create a master list of files that need updating
$changed_files = array_unique(array_merge($new_files, $updated));
// store a list of changed URLs
$changed_urls = array();
// add to the cache if files have been updated
if (count($changed_files)) {
$files_changed = true;
// build content cache
foreach ($changed_files as $file) {
$file = $full_content_root . $file;
$local_path = Path::trimFilesystemFromContent($file);
// before cleaning anything, check for hidden or draft content
$is_hidden = Path::isHidden($local_path);
$is_draft = Path::isDraft($local_path);
// now clean up the path
$local_filename = Path::clean($local_path);
// file parsing
$content = substr(File::get($file), 3);
$divide = strpos($content, "\n---");
$front_matter = trim(substr($content, 0, $divide));
$content_raw = trim(substr($content, $divide + 4));
// parse data
$data = YAML::parse($front_matter);
if ($content_raw) {
$data['content'] = 'true';
$data['content_raw'] = 'true';
}
// set additional information
//.........这里部分代码省略.........
示例13: upload
/**
* Moves an uploaded file to a destination folder
*
* @param string $src The name of the php (temporary) uploaded file
* @param string $dest The path (including filename) to move the uploaded file to
* @param boolean $use_streams True to use streams
*
* @return boolean True on success
*
* @since 1.0
* @throws FilesystemException
*/
public static function upload($src, $dest, $use_streams = false)
{
// Ensure that the path is valid and clean
$dest = Path::clean($dest);
// Create the destination directory if it does not exist
$baseDir = dirname($dest);
if (!file_exists($baseDir)) {
Folder::create($baseDir);
}
if ($use_streams) {
$stream = Stream::getStream();
if (!$stream->upload($src, $dest)) {
throw new FilesystemException(__METHOD__ . ': ' . $stream->getError());
}
return true;
} else {
if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) {
// Short circuit to prevent file permission errors
if (Path::setPermissions($dest)) {
return true;
} else {
throw new FilesystemException(__METHOD__ . ': Failed to change file permissions.');
}
} else {
throw new FilesystemException(__METHOD__ . ': Failed to move file.');
}
return false;
}
}
示例14: fromPath
public static function fromPath($path)
{
$url = Path::clean(Url::assemble($path));
return preg_replace('/\\/page$/', '', $url);
}
示例15: getCollections
/**
* Get collections
*
* This will look for any folders with fields.yaml
*
* @return array
*/
private function getCollections()
{
$collections = array();
$paths = File::globRecursively(BASE_PATH . '/' . Config::get('content_root'), 'yaml');
foreach ($paths as $path) {
if (!$this->endsWith($path, 'fields.yaml')) {
continue;
}
$collection = substr(Path::clean(Path::trimFileSystemFromContent($path)), 1, -12);
$contents = YAML::parseFile($path);
$collections[$collection] = array_get($contents, 'type', 'alphabetical');
}
return $collections;
}