本文整理汇总了PHP中Path::standardize方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::standardize方法的具体用法?PHP Path::standardize怎么用?PHP Path::standardize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path::standardize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanURL
/**
* Removes any filesystem path outside of the site root
*
* @param string $path Path to trim
* @return string
*/
public static function cleanURL($path)
{
return str_replace(Path::standardize(BASE_PATH), "", $path);
}
示例2: 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
//.........这里部分代码省略.........
示例3: index
public function index()
{
/*
|--------------------------------------------------------------------------
| Check for image
|--------------------------------------------------------------------------
|
| Transform just needs the path to an image to get started. If it exists,
| the fun begins.
|
*/
$image_src = $this->fetchParam('src', null, false, false, false);
// Set full system path
$image_path = Path::standardize(Path::fromAsset($image_src));
// Check if image exists before doing anything.
if (!File::isImage($image_path)) {
Log::error("Could not find requested image to transform: " . $image_path, "core", "Transform");
return;
}
/*
|--------------------------------------------------------------------------
| Resizing and cropping options
|--------------------------------------------------------------------------
|
| The first transformations we want to run is for size to reduce the
| memory usage for future effects.
|
*/
$width = $this->fetchParam('width', null, 'is_numeric');
$height = $this->fetchParam('height', null, 'is_numeric');
// resize specific
$ratio = $this->fetchParam('ratio', true, false, true);
$upsize = $this->fetchParam('upsize', true, false, true);
// crop specific
$pos_x = $this->fetchParam('pos_x', 0, 'is_numeric');
$pos_y = $this->fetchParam('pos_y', 0, 'is_numeric');
$quality = $this->fetchParam('quality', '75', 'is_numeric');
/*
|--------------------------------------------------------------------------
| Action
|--------------------------------------------------------------------------
|
| Available actions: resize, crop, and guess.
|
| "Guess" will find the best fitting aspect ratio of your given width and
| height on the current image automatically, cut it out and resize it to
| the given dimension.
|
*/
$action = $this->fetchParam('action', 'resize');
/*
|--------------------------------------------------------------------------
| Extra bits
|--------------------------------------------------------------------------
|
| Delicious and probably rarely used options.
|
*/
$angle = $this->fetchParam('rotate', false);
$flip_side = $this->fetchParam('flip', false);
$blur = $this->fetchParam('blur', false, 'is_numeric');
$pixelate = $this->fetchParam('pixelate', false, 'is_numeric');
$greyscale = $this->fetchParam(array('greyscale', 'grayscale'), false, false, true);
/*
|--------------------------------------------------------------------------
| Assemble filename and check for duplicate
|--------------------------------------------------------------------------
|
| We need to make sure we don't already have this image created, so we
| defer any action until we've processed the parameters, which create
| a unique filename.
|
*/
// Late modified time of original image
$last_modified = File::getLastModified($image_path);
// Find .jpg, .png, etc
$extension = File::getExtension($image_path);
// Filename with the extension removed so we can append our unique filename flags
$stripped_image_path = str_replace('.' . $extension, '', $image_path);
// The possible filename flags
$parameter_flags = array('width' => $width, 'height' => $height, 'quality' => $quality, 'rotate' => $angle, 'flip' => $flip_side, 'pos_x' => $pos_x, 'pos_y' => $pos_y, 'blur' => $blur, 'pixelate' => $pixelate, 'greyscale' => $greyscale, 'modified' => $last_modified);
// Start with a 1 character action flag
$file_breadcrumbs = '-' . $action[0];
foreach ($parameter_flags as $param => $value) {
if ($value) {
$flag = is_bool($value) ? '' : $value;
// don't show boolean flags
$file_breadcrumbs .= '-' . $param[0] . $flag;
}
}
// Allow converting filetypes (jpg, png, gif)
$extension = $this->fetchParam('type', $extension);
// Allow saving in a different directory
$destination = $this->fetchParam('destination', Config::get('transform_destination', false), false, false, false);
if ($destination) {
$destination = Path::tidy(BASE_PATH . '/' . $destination);
// Method checks to see if folder exists before creating it
Folder::make($destination);
$stripped_image_path = Path::tidy($destination . '/' . basename($stripped_image_path));
}
//.........这里部分代码省略.........
示例4: 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
//.........这里部分代码省略.........