WordPressを読む 10-9 /blog/wp-includes/functions.php 9
2014/11/29
目次
/blog/wp-includes/functions.php 9
読込元 : /blog/wp-settings.php
読込元 : /blog/wp-load.php
関数
path_is_absolute()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | /** * Test if a give filesystem path is absolute. * * For example, '/foo/bar', or 'c:\windows'. * * @since 2.5.0 * * @param string $path File path. * @return bool True if path is absolute, false is not absolute. */ function path_is_absolute( $path ) { /* * This is definitive if true but fails if $path does not exist or contains * a symbolic link. */ if ( realpath($path) == $path ) return true; if ( strlen($path) == 0 || $path[0] == '.' ) return false; // Windows allows absolute paths like this. if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) return true; // A path starting with / or \ is absolute; anything else is relative. return ( $path[0] == '/' || $path[0] == '\\' ); } |
関数
path_join()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Join two filesystem paths together. * * For example, 'give me $path relative to $base'. If the $path is absolute, * then it the full path is returned. * * @since 2.5.0 * * @param string $base Base path. * @param string $path Path relative to $base. * @return string The path with the base or absolute path. */ function path_join( $base, $path ) { if ( path_is_absolute($path) ) return $path; return rtrim($base, '/') . '/' . ltrim($path, '/'); } |
関数
wp_normalize_path()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Normalize a filesystem path. * * Replaces backslashes with forward slashes for Windows systems, and ensures * no duplicate slashes exist. * * @since 3.9.0 * * @param string $path Path to normalize. * @return string Normalized path. */ function wp_normalize_path( $path ) { $path = str_replace( '\\', '/', $path ); $path = preg_replace( '|/+|','/', $path ); return $path; } |
関数
get_temp_dir()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /** * Determine a writable directory for temporary files. * * Function's preference is the return value of sys_get_temp_dir(), * followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, * before finally defaulting to /tmp/ * * In the event that this function does not find a writable location, * It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file. * * @since 2.5.0 * * @return string Writable temporary directory. */ function get_temp_dir() { static $temp; if ( defined('WP_TEMP_DIR') ) return trailingslashit(WP_TEMP_DIR); if ( $temp ) return trailingslashit( $temp ); if ( function_exists('sys_get_temp_dir') ) { $temp = sys_get_temp_dir(); if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) return trailingslashit( $temp ); } $temp = ini_get('upload_tmp_dir'); if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) return trailingslashit( $temp ); $temp = WP_CONTENT_DIR . '/'; if ( is_dir( $temp ) && wp_is_writable( $temp ) ) return $temp; $temp = '/tmp/'; return $temp; } |
関数
wp_is_writable()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Determine if a directory is writable. * * This function is used to work around certain ACL issues in PHP primarily * affecting Windows Servers. * * @since 3.6.0 * * @see win_is_writable() * * @param string $path Path to check for write-ability. * @return bool Whether the path is writable. */ function wp_is_writable( $path ) { if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) return win_is_writable( $path ); else return @is_writable( $path ); } |
関数
win_is_writable()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /** * Workaround for Windows bug in is_writable() function * * PHP has issues with Windows ACL's for determine if a * directory is writable or not, this works around them by * checking the ability to open files rather than relying * upon PHP to interprate the OS ACL. * * @since 2.8.0 * * @see http://bugs.php.net/bug.php?id=27609 * @see http://bugs.php.net/bug.php?id=30931 * * @param string $path Windows path to check for write-ability. * @return bool Whether the path is writable. */ function win_is_writable( $path ) { if ( $path[strlen( $path ) - 1] == '/' ) // if it looks like a directory, check a random file within the directory return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp'); else if ( is_dir( $path ) ) // If it's a directory (and not a file) check a random file within the directory return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' ); // check tmp file for read/write capabilities $should_delete_tmp_file = !file_exists( $path ); $f = @fopen( $path, 'a' ); if ( $f === false ) return false; fclose( $f ); if ( $should_delete_tmp_file ) unlink( $path ); return true; } |