JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
/**
*
*/
class Loco_fs_File {
/**
* Write context for the current file path
*/
private ?Loco_fs_FileWriter $w = null;
/**
* Path to file
*/
private string $path = '';
/**
* Cached pathinfo() data
*/
private ?array $info = null;
/**
* Base path which path has been normalized against
*/
private ?string $base = null;
/**
* Flag set when current path is relative
*/
private bool $rel;
/**
* Check if a path is absolute and return fixed slashes for readability
* @return string fixed path, or "" if not absolute
*/
public static function abs( string $path ):string {
if( '' !== $path ){
$chr1 = substr($path,0,1);
// absolute path if starts "/"
if( '/' === $chr1 ){
// collapse "." and ".." segments, rejecting any attempt to traverse above the root.
// also collapse redundant "/" separators. paths with neither are returned unmodified.
if( preg_match('~(?:^|/)\\.\\.?(?:/|$)~',$path) || false !== strpos($path,'//') ){
$path = implode('/', self::explode($path,[]) );
// a path that collapses down to the root implodes to "", so restore the slash
return '' === $path ? '/' : $path;
}
return $path;
}
// Windows drive path if "X:" or network path if "\\"
$chr2 = substr($path,1,1) ?: '';
if( '' !== $chr2 ){
if( ':' === $chr2 || ( '\\' === $chr1 && '\\' === $chr2 ) ){
return strtoupper($chr1).$chr2.strtr( substr($path,2), '\\', '/' );
}
// Check that relative isn't some other file wrapper uri.
if( preg_match('!^([^/:]+)://!',$path,$r) ){
// allow file:// - pointless but harmless, as long as we pass back through again
if( 'file' === $r[1] ){
return self::abs( substr($path,strlen($r[0])) );
}
// This should never be thrown except in tests, as any illegal input will be rejected earlier.
throw new Loco_error_Exception('Stream wrappers disallowed');
}
}
}
// else path is relative, so return falsy string
return '';
}
/**
* Test if a path looks absolute
*/
public static function is_abs( string $path ):bool {
return '' !== $path && ( '/' === $path[0] || preg_match('!^\\\\\\\\|.:\\\\!',$path) );
}
/**
* Call PHP is_readable() but suppress E_WARNING when path is outside open_basedir.
*/
public static function is_readable( string $path ):bool {
if( '' === $path || '.' === $path[0] ){
throw new InvalidArgumentException('Relative paths disallowed');
}
// Reduce PHP errors from is_readable to debug messages
Loco_error_AdminNotices::capture(E_NOTICE|E_WARNING);
$bool = is_readable($path);
restore_error_handler();
return $bool;
}
/**
* Create file with initial, unvalidated path
*/
public function __construct( string $path ){
$this->setPath( $path );
}
/**
* Internally set path value and flag whether relative or absolute
*/
private function setPath( string $path ):void {
if( $fixed = self::abs($path) ){
$path = $fixed;
$this->rel = false;
}
else {
$this->rel = true;
}
if( $path !== $this->path ){
$this->path = $path;
$this->info = null;
}
}
/**
* Return whether currently configure path is absolute
*/
public function isAbsolute(): bool {
return ! $this->rel;
}
/**
* @internal
*/
public function __clone(){
$this->cloneWriteContext( $this->w );
}
/**
* Copy write context with our file reference
*/
private function cloneWriteContext( ?Loco_fs_FileWriter $context = null ):void {
if( $context ){
$context = clone $context;
$this->w = $context->setFile($this);
}
}
/**
* Get file system context for operations that *modify* the file system.
* Read operations and operations that stat the file will always do so directly.
*/
public function getWriteContext():Loco_fs_FileWriter {
if( ! $this->w ){
$this->w = new Loco_fs_FileWriter( $this );
}
return $this->w;
}
/**
* @internal
*/
private function pathinfo(){
return is_array($this->info) ? $this->info : ( $this->info = pathinfo($this->path) );
}
/**
* Checks if a file exists, and is within open_basedir restrictions.
* This does NOT check if file permissions allow PHP to read it. Call $this->readable() or self::is_readable($path).
*/
public function exists():bool {
return file_exists($this->path);
}
/**
* Check if file is writable by the current write context
*/
public function writable():bool {
return $this->getWriteContext()->writable();
}
/**
* Check if the file exists and is readable by the current PHP process.
*/
public function readable():bool {
return self::is_readable($this->path);
}
/**
* Check if file is removable by the current write context
*/
public function deletable():bool {
$parent = $this->getParent();
if( $parent && $parent->writable() ){
// sticky directory requires that either the file its parent is owned by effective user
if( $parent->mode() & 01000 ){
$writer = $this->getWriteContext();
if( $writer->isDirect() && ( $uid = Loco_compat_PosixExtension::getuid() ) ){
return $uid === $this->uid() || $uid === $parent->uid();
}
// else delete operation won't be done directly, so can't preempt sticky problems
// TODO is it worth comparing FTP username etc.. for ownership?
}
// defaulting to "deletable" based on fact that parent is writable.
return true;
}
return false;
}
/**
* Get owner uid
* @return int|false
*/
public function uid(){
return fileowner($this->path);
}
/**
* Get group gid
* @return int|false
*/
public function gid(){
return filegroup($this->path);
}
/**
* Check if file can't be overwritten when existent, nor created when non-existent
* This does not check permissions recursively as directory trees are not built implicitly
*/
public function locked():bool {
if( $this->exists() ){
return ! $this->writable();
}
if( $dir = $this->getParent() ){
return ! $dir->writable();
}
return true;
}
/**
* Check if full path can be built to non-existent file.
*/
public function creatable():bool {
$file = $this;
while( $file = $file->getParent() ){
if( $file->exists() ){
return $file->writable();
}
}
return false;
}
/**
* Get directory name like dirname()
*/
public function dirname():string{
$info = $this->pathinfo();
return $info['dirname'];
}
/**
* Get base name like basenaame()
*/
public function basename():string {
$info = $this->pathinfo();
return $info['basename'];
}
/**
* Get file name without extension, like filename()
*/
public function filename():string {
$info = $this->pathinfo();
return $info['filename'];
}
/**
* Gets final file extension, e.g. "html" in "foo.php.html"
*/
public function extension():string {
$info = $this->pathinfo();
return $info['extension'] ?? '';
}
/**
* Gets full file extension after first dot separator, e.g. "php.html" in "foo.php.html"
*/
public function fullExtension():string {
$bits = explode('.',$this->basename(),2);
return array_key_exists(1,$bits) ? $bits[1] : '';
}
/**
* Get currently configure path, unmodified
*/
public function getPath():string {
return $this->path;
}
/**
* Get file modification time as unix timestamp in seconds
*/
public function modified():int {
return filemtime($this->path) ?: 0;
}
/**
* Get file size in bytes
*/
public function size():int {
return filesize($this->path) ?: 0;
}
/**
* Get file mode as integer
*/
public function mode():int {
if( is_link($this->path) ){
$stat = lstat( $this->path );
$mode = $stat[2];
}
else {
$mode = fileperms($this->path);
}
return $mode;
}
/**
* Set file mode
* @param int $mode file mode integer e.g 0664
* @param bool $recursive whether to set recursively (directories)
*/
public function chmod( int $mode, bool $recursive = false ):self {
$this->getWriteContext()->chmod( $mode, $recursive );
return $this->clearStat();
}
/**
* Clear stat cache if any file data has changed
*/
public function clearStat():self {
$this->info = null;
// PHP 5.3.0 Added optional clear_realpath_cache and filename parameters.
if( version_compare( PHP_VERSION, '5.3.0', '>=' ) ){
clearstatcache( true, $this->path );
}
// else no choice but to drop entire stat cache
else {
clearstatcache();
}
return $this;
}
/**
* @return string
*/
public function __toString(){
return $this->getPath();
}
/**
* Check if passed path is equal to ours
* @param string|self $ref
*/
public function equal( $ref ):bool {
return $this->path === (string) $ref;
}
/**
* Normalize path for string comparison, resolves redundant dots and slashes.
* @param string $base path to prefix
*/
public function normalize( string $base = '' ):string {
if( $path = self::abs($base) ){
$base = $path;
}
if( $base !== $this->base ){
$path = $this->path;
if( '' === $path ){
$this->setPath($base);
}
else {
if( ! $this->rel || ! $base ){
$b = [];
}
else {
$b = self::explode( $base, [] );
}
$b = self::explode( $path, $b );
$this->setPath( implode('/',$b) );
}
$this->base = $base;
}
return $this->path;
}
/**
* Get real path if file is real, but without altering internal path property.
* Also skips call to realpath() when likely to raise E_WARNING due to open_basedir
*/
public function getRealPath():string {
if( $this->readable() ){
$path = realpath( $this->getPath() );
if( is_string($path) ){
return $path;
}
}
return '';
}
private static function explode( string $path, array $b ):array {
$a = explode( '/', $path );
foreach( $a as $i => $s ){
if( '' === $s ){
if( 0 !== $i ){
continue;
}
}
if( '.' === $s ){
continue;
}
if( '..' === $s ){
$popped = array_pop($b);
// a preceding path segment is absorbed by the parent reference
if( '' !== (string) $popped && '..' !== $popped ){
continue;
}
// popping the leading "" marker means traversing above the root of an absolute path
if( '' === $popped ){
throw new Loco_error_Exception('Invalid path: '.$path);
}
// else nothing to absorb in a relative path; retain ".." for deferred resolution
}
$b[] = $s;
}
return $b;
}
/**
* Get path relative to given location, unless path is already relative
* @param string $base Base path
* @return string path relative to given base
*/
public function getRelativePath( string $base ):string {
$path = $this->normalize();
if( self::abs($path) ){
// base may require normalizing
$file = new Loco_fs_File($base);
$base = $file->normalize();
$length = strlen($base)+1;
// if we are below given base path, return ./relative
if( substr($path,0,$length) === $base.'/' ){
if( strlen($path) > $length ){
return substr( $path, $length );
}
// else paths were identical
return '';
}
// else attempt to find nearest common root
$i = 0;
$source = explode('/',$base);
$target = explode('/',$path);
while( isset($source[$i]) && isset($target[$i]) && $source[$i] === $target[$i] ){
$i++;
}
if( $i > 1 ){
$depth = count($source) - $i;
$build = array_merge( array_fill( 0, $depth, '..' ), array_slice( $target, $i ) );
$path = implode( '/', $build );
}
}
// else return unmodified
return $path;
}
/**
* Test if file is a directory
*/
public function isDirectory():bool {
if( $this->readable() ){
return is_dir($this->path);
}
return '' === $this->extension();
}
/**
* Load contents of file into a string
*/
public function getContents():string {
return file_get_contents($this->path);
}
/**
* Check if path is under a theme directory
*/
public function underThemeDirectory():bool {
return Loco_fs_Locations::getThemes()->check( $this->path );
}
/**
* Check if path is under a plugin directory
*/
public function underPluginDirectory():bool {
return Loco_fs_Locations::getPlugins()->check( $this->path );
}
/**
* Check if path is under wp-content directory
*/
public function underContentDirectory():bool {
return Loco_fs_Locations::getContent()->check( $this->path );
}
/**
* Check if path is under WordPress root directory (ABSPATH)
*/
public function underWordPressDirectory():bool {
return Loco_fs_Locations::getRoot()->check( $this->path );
}
/**
* Check if path is under the global system directory
*/
public function underGlobalDirectory():bool {
return Loco_fs_Locations::getLangs()->check( $this->path );
}
/**
* @return Loco_fs_Directory|null
*/
public function getParent():?Loco_fs_Directory {
$dir = null;
$path = $this->dirname();
if( '.' !== $path && $this->path !== $path ){
$dir = new Loco_fs_Directory( $path );
$dir->cloneWriteContext( $this->w );
}
return $dir;
}
/**
* Copy this file for real
* @param string $dest new path
* @throws Loco_error_WriteException
* @return Loco_fs_File new file
*/
public function copy( string $dest ):self {
$copy = clone $this;
$copy->path = $dest;
$copy->clearStat();
$this->getWriteContext()->copy($copy);
return $copy;
}
/**
* Move/rename this file for real
* @param Loco_fs_File $dest target file with new path
* @throws Loco_error_WriteException
* @return self original file that should no longer exist
*/
public function move( Loco_fs_File $dest ):self {
$this->getWriteContext()->move($dest);
return $this->clearStat();
}
/**
* Delete this file for real
* @throws Loco_error_WriteException
*/
public function unlink():self {
$recursive = $this->isDirectory();
$this->getWriteContext()->delete( $recursive );
return $this->clearStat();
}
/**
* Copy this object with an alternative file extension
* @param string $ext new extension
*/
public function cloneExtension( string $ext ):self {
return $this->cloneBasename( $this->filename().'.'.ltrim($ext,'.') );
}
/**
* Copy this object with an alternative name under the same directory
* @param string $name new name
*/
public function cloneBasename( string $name ):self {
$file = clone $this;
$file->path = rtrim($file->dirname(),'/').'/'.$name;
$file->info = null;
return $file;
}
/**
* Ensure full parent directory tree exists
*/
public function createParent():?Loco_fs_Directory {
$dir = $this->getParent();
if( $dir instanceof Loco_fs_Directory && ! $dir->exists() ){
$dir->mkdir();
}
return $dir;
}
/**
* @param string $data file contents
* @return int number of bytes written to file
*/
public function putContents( string $data ):int {
$this->getWriteContext()->putContents($data);
$this->clearStat();
return $this->size();
}
/**
* Establish what part of the WordPress file system this is.
* Value is that used by WP_Automatic_Updater::should_update.
* @return string "core", "plugin", "theme" or "translation"
*/
public function getUpdateType():string {
// global languages directory root, and canonical subdirectories
$dirpath = (string) ( $this->isDirectory() ? $this : $this->getParent() );
$sub = Loco_fs_Locations::getLangs()->rel($dirpath);
if( is_string($sub) && '' !== $sub ){
list($root) = explode('/', $sub, 2 );
if( '.' === $root || 'themes' === $root || 'plugins' === $root ){
return 'translation';
}
}
// theme and plugin locations can be at any depth
else if( $this->underThemeDirectory() ){
return 'theme';
}
else if( $this->underPluginDirectory() ){
return 'plugin';
}
// core locations are under WordPress root, but not under wp-content
else if( $this->underWordPressDirectory() && ! $this->underContentDirectory() ){
return 'core';
}
// else not an update type
return '';
}
/**
* Get MD5 hash of file contents
*/
public function md5():string {
if( $this->exists() ) {
return md5_file( $this->path );
}
else {
return 'd41d8cd98f00b204e9800998ecf8427e';
}
}
}