open($file, /* ZIPARCHIVE::CHECKCONS */ 4); if (true !== $zopen) { echo('incompatible_archive'); return false; } for ($i = 0; $i < $z->numFiles; $i++) { if (!$info = $z->statIndex($i)) { echo('stat_failed: Could not retrieve file from archive.'); return false; } if ('__MACOSX/' === substr($info['name'], 0, 9)) // Skip the OS X-created __MACOSX directory continue; if ('/' == substr($info['name'], -1)) // directory $needed_dirs[] = $to . untrailingslashit($info['name']); else $needed_dirs[] = $to . untrailingslashit(dirname($info['name'])); } $needed_dirs = array_unique($needed_dirs); foreach ($needed_dirs as $dir) { // Check the parent folders of the folders all exist within the creation array. if (untrailingslashit($to) == $dir) // Skip over the working directory, We know this exists (or will exist) continue; if (strpos($dir, $to) === false) // If the directory is not within the working directory, Skip it continue; $parent_folder = dirname($dir); while (!empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs)) { $needed_dirs[] = $parent_folder; $parent_folder = dirname($parent_folder); } } asort($needed_dirs); // Create those directories if need be: foreach ($needed_dirs as $_dir) { if (!$filesystem->mkdir($_dir, 0755) && !$filesystem->is_dir($_dir)) { // Only check to see if the Dir exists upon creation failure. Less I/O this way. echo('mkdir_failed: Could not create directory ' . $_dir); return false; } } unset($needed_dirs); for ($i = 0; $i < $z->numFiles; $i++) { if (!$info = $z->statIndex($i)) { echo('stat_failed: Could not retrieve file from archive.'); return false; } if ('/' == substr($info['name'], -1)) // directory continue; if ('__MACOSX/' === substr($info['name'], 0, 9)) // Don't extract the OS X-created __MACOSX directory files continue; $contents = $z->getFromIndex($i); if (false === $contents) { echo('extract_failed: Could not extract file from archive.' . $info['name']); return false; } if (!$filesystem->put_contents($to . $info['name'], $contents, 0755)) { echo('copy_failed: Could not copy file. ' . $to . $info['name']); return false; } } $z->close(); return true; } class Sitebill_Error { /** * Stores the list of errors. * * @since 2.1.0 * @var array * @access private */ var $errors = array(); /** * Stores the list of data for error codes. * * @since 2.1.0 * @var array * @access private */ var $error_data = array(); /** * Constructor - Sets up error message. * * If code parameter is empty then nothing will be done. It is possible to * add multiple messages to the same code, but with other methods in the * class. * * All parameters are optional, but if the code parameter is set, then the * data parameter is optional. * * @since 2.1.0 * * @param string|int $code Error code * @param string $message Error message * @param mixed $data Optional. Error data. * @return Sitebill_Error */ function __construct($code = '', $message = '', $data = '') { if (empty($code)) return; $this->errors[$code][] = $message; if (!empty($data)) $this->error_data[$code] = $data; } /** * Retrieve all error codes. * * @since 2.1.0 * @access public * * @return array List of error codes, if available. */ function get_error_codes() { if (empty($this->errors)) return array(); return array_keys($this->errors); } /** * Retrieve first error code available. * * @since 2.1.0 * @access public * * @return string|int Empty string, if no error codes. */ function get_error_code() { $codes = $this->get_error_codes(); if (empty($codes)) return ''; return $codes[0]; } /** * Retrieve all error messages or error messages matching code. * * @since 2.1.0 * * @param string|int $code Optional. Retrieve messages matching code, if exists. * @return array Error strings on success, or empty array on failure (if using code parameter). */ function get_error_messages($code = '') { // Return all messages if no code specified. if (empty($code)) { $all_messages = array(); foreach ((array) $this->errors as $code => $messages) $all_messages = array_merge($all_messages, $messages); return $all_messages; } if (isset($this->errors[$code])) return $this->errors[$code]; else return array(); } /** * Get single error message. * * This will get the first message available for the code. If no code is * given then the first code available will be used. * * @since 2.1.0 * * @param string|int $code Optional. Error code to retrieve message. * @return string */ function get_error_message($code = '') { if (empty($code)) $code = $this->get_error_code(); $messages = $this->get_error_messages($code); if (empty($messages)) return ''; return $messages[0]; } /** * Retrieve error data for error code. * * @since 2.1.0 * * @param string|int $code Optional. Error code. * @return mixed Null, if no errors. */ function get_error_data($code = '') { if (empty($code)) $code = $this->get_error_code(); if (isset($this->error_data[$code])) return $this->error_data[$code]; return null; } /** * Append more error messages to list of error messages. * * @since 2.1.0 * @access public * * @param string|int $code Error code. * @param string $message Error message. * @param mixed $data Optional. Error data. */ function add($code, $message, $data = '') { $this->errors[$code][] = $message; if (!empty($data)) $this->error_data[$code] = $data; } /** * Add data for error code. * * The error code can only contain one error data. * * @since 2.1.0 * * @param mixed $data Error data. * @param string|int $code Error code. */ function add_data($data, $code = '') { if (empty($code)) $code = $this->get_error_code(); $this->error_data[$code] = $data; } } /** * Check whether variable is a Sitebill Error. * * @param mixed $thing Check if unknown variable is Sitebill Error object. * @return bool True, if Sitebill_Error. False, if not Sitebill_Error. */ function is_sitebill_error($thing) { if (is_object($thing) && is_a($thing, 'Sitebill_Error')) return true; return false; } class Sitebill_Filesystem { var $errors = null; /** * constructor * * @param mixed $arg ignored argument */ function __construct() { $this->method = 'direct'; $this->errors = new Sitebill_Error(); } /** * connect filesystem. * * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct). */ function connect() { return true; } /** * Reads entire file into a string * * @param string $file Name of the file to read. * @return string|bool The function returns the read data or false on failure. */ function get_contents($file) { return @file_get_contents($file); } /** * Reads entire file into an array * * @param string $file Path to the file. * @return array|bool the file contents in an array or false on failure. */ function get_contents_array($file) { return @file($file); } /** * Write a string to a file * * @param string $file Remote path to the file where to write the data. * @param string $contents The data to write. * @param int $mode (optional) The file permissions as octal number, usually 0644. * @return bool False upon failure. */ function put_contents($file, $contents, $mode = false) { if (!($fp = @fopen($file, 'w'))) return false; @fwrite($fp, $contents); @fclose($fp); $this->chmod($file, $mode); return true; } /** * Gets the current working directory * * @return string|bool the current working directory on success, or false on failure. */ function cwd() { return @getcwd(); } /** * Change directory * * @param string $dir The new current directory. * @return bool Returns true on success or false on failure. */ function chdir($dir) { return @chdir($dir); } /** * Changes file group * * @param string $file Path to the file. * @param mixed $group A group name or number. * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chgrp($file, $group, $recursive = false) { if (!$this->exists($file)) return false; if (!$recursive) return @chgrp($file, $group); if (!$this->is_dir($file)) return @chgrp($file, $group); //Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ($filelist as $filename) $this->chgrp($file . $filename, $group, $recursive); return true; } /** * Changes filesystem permissions * * @param string $file Path to the file. * @param int $mode (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs. * @param bool $recursive (optional) If set True changes file group recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chmod($file, $mode = false, $recursive = false) { if (!$mode) { if ($this->is_file($file)) $mode = FS_CHMOD_FILE; elseif ($this->is_dir($file)) $mode = FS_CHMOD_DIR; else return false; } if (!$recursive || !$this->is_dir($file)) return @chmod($file, $mode); //Is a directory, and we want recursive $file = trailingslashit($file); $filelist = $this->dirlist($file); foreach ((array) $filelist as $filename => $filemeta) $this->chmod($file . $filename, $mode, $recursive); return true; } /** * Changes file owner * * @param string $file Path to the file. * @param mixed $owner A user name or number. * @param bool $recursive (optional) If set True changes file owner recursively. Defaults to False. * @return bool Returns true on success or false on failure. */ function chown($file, $owner, $recursive = false) { if (!$this->exists($file)) return false; if (!$recursive) return @chown($file, $owner); if (!$this->is_dir($file)) return @chown($file, $owner); //Is a directory, and we want recursive $filelist = $this->dirlist($file); foreach ($filelist as $filename) { $this->chown($file . '/' . $filename, $owner, $recursive); } return true; } /** * Gets file owner * * @param string $file Path to the file. * @return string Username of the user. */ function owner($file) { $owneruid = @fileowner($file); if (!$owneruid) return false; if (!function_exists('posix_getpwuid')) return $owneruid; $ownerarray = posix_getpwuid($owneruid); return $ownerarray['name']; } /** * Gets file permissions * * FIXME does not handle errors in fileperms() * * @param string $file Path to the file. * @return string Mode of the file (last 4 digits). */ function getchmod($file) { return substr(decoct(@fileperms($file)), 3); } function group($file) { $gid = @filegroup($file); if (!$gid) return false; if (!function_exists('posix_getgrgid')) return $gid; $grouparray = posix_getgrgid($gid); return $grouparray['name']; } function copy($source, $destination, $overwrite = false, $mode = false) { if (!$overwrite && $this->exists($destination)) return false; $rtval = copy($source, $destination); if ($mode) $this->chmod($destination, $mode); return $rtval; } function move($source, $destination, $overwrite = false) { if (!$overwrite && $this->exists($destination)) return false; // try using rename first. if that fails (for example, source is read only) try copy if (@rename($source, $destination)) return true; if ($this->copy($source, $destination, $overwrite) && $this->exists($destination)) { $this->delete($source); return true; } else { return false; } } function delete($file, $recursive = false, $type = false) { if (empty($file)) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. return false; $file = str_replace('\\', '/', $file); //for win32, occasional problems deleting files otherwise if ('f' == $type || $this->is_file($file)) return @unlink($file); if (!$recursive && $this->is_dir($file)) return @rmdir($file); //At this point its a folder, and we're in recursive mode $file = trailingslashit($file); $filelist = $this->dirlist($file, true); $retval = true; if (is_array($filelist)) //false if no files, So check first. foreach ($filelist as $filename => $fileinfo) if (!$this->delete($file . $filename, $recursive, $fileinfo['type'])) $retval = false; if (file_exists($file) && !@rmdir($file)) $retval = false; return $retval; } function exists($file) { return @file_exists($file); } function is_file($file) { return @is_file($file); } function is_dir($path) { return @is_dir($path); } function is_readable($file) { return @is_readable($file); } function is_writable($file) { return @is_writable($file); } function atime($file) { return @fileatime($file); } function mtime($file) { return @filemtime($file); } function size($file) { return @filesize($file); } function touch($file, $time = 0, $atime = 0) { if ($time == 0) $time = time(); if ($atime == 0) $atime = time(); return @touch($file, $time, $atime); } function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { // safe mode fails with a trailing slash under certain PHP versions. $path = untrailingslashit($path); if (empty($path)) return false; if (!$chmod) $chmod = FS_CHMOD_DIR; if (!@mkdir($path)) return false; $this->chmod($path, $chmod); if ($chown) $this->chown($path, $chown); if ($chgrp) $this->chgrp($path, $chgrp); return true; } function rmdir($path, $recursive = false) { return $this->delete($path, $recursive); } function dirlist($path, $include_hidden = true, $recursive = false) { if ($this->is_file($path)) { $limit_file = basename($path); $path = dirname($path); } else { $limit_file = false; } if (!$this->is_dir($path)) return false; $dir = @dir($path); if (!$dir) return false; $ret = array(); while (false !== ($entry = $dir->read())) { $struc = array(); $struc['name'] = $entry; if ('.' == $struc['name'] || '..' == $struc['name']) continue; if (!$include_hidden && '.' == $struc['name'][0]) continue; if ($limit_file && $struc['name'] != $limit_file) continue; $struc['perms'] = $this->gethchmod($path . '/' . $entry); $struc['permsn'] = $this->getnumchmodfromh($struc['perms']); $struc['number'] = false; $struc['owner'] = $this->owner($path . '/' . $entry); $struc['group'] = $this->group($path . '/' . $entry); $struc['size'] = $this->size($path . '/' . $entry); $struc['lastmodunix'] = $this->mtime($path . '/' . $entry); $struc['lastmod'] = date('M j', $struc['lastmodunix']); $struc['time'] = date('h:i:s', $struc['lastmodunix']); $struc['type'] = $this->is_dir($path . '/' . $entry) ? 'd' : 'f'; if ('d' == $struc['type']) { if ($recursive) $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } $ret[$struc['name']] = $struc; } $dir->close(); unset($dir); return $ret; } /** * Returns the *nix style file permissions for a file * * From the PHP documentation page for fileperms() * * @link http://docs.php.net/fileperms * @since 2.5 * @access public * * @param string $file string filename * @return int octal representation of permissions */ function gethchmod($file) { $perms = $this->getchmod($file); if (($perms & 0xC000) == 0xC000) // Socket $info = 's'; elseif (($perms & 0xA000) == 0xA000) // Symbolic Link $info = 'l'; elseif (($perms & 0x8000) == 0x8000) // Regular $info = '-'; elseif (($perms & 0x6000) == 0x6000) // Block special $info = 'b'; elseif (($perms & 0x4000) == 0x4000) // Directory $info = 'd'; elseif (($perms & 0x2000) == 0x2000) // Character special $info = 'c'; elseif (($perms & 0x1000) == 0x1000) // FIFO pipe $info = 'p'; else // Unknown $info = 'u'; // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $info; } /** * Converts *nix style file permissions to a octal number. * * Converts '-rw-r--r--' to 0644 * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod() * * @link http://docs.php.net/manual/en/function.chmod.php#49614 * @since 2.5 * @access public * * @param string $mode string *nix style file permission * @return int octal representation */ function getnumchmodfromh($mode) { $realmode = ''; $legal = array('', 'w', 'r', 'x', '-'); $attarray = preg_split('//', $mode); for ($i = 0; $i < count($attarray); $i++) if ($key = array_search($attarray[$i], $legal)) $realmode .= $legal[$key]; $mode = str_pad($realmode, 9, '-'); $trans = array('-' => '0', 'r' => '4', 'w' => '2', 'x' => '1'); $mode = strtr($mode, $trans); $newmode = ''; $newmode .= $mode[0] + $mode[1] + $mode[2]; $newmode .= $mode[3] + $mode[4] + $mode[5]; $newmode .= $mode[6] + $mode[7] + $mode[8]; return $newmode; } /** * Determines if the string provided contains binary characters. * * @since 2.7 * @access private * * @param string $text String to test against * @return bool true if string is binary, false otherwise */ function is_binary($text) { return (bool) preg_match('|[^\x20-\x7E]|', $text); //chr(32)..chr(127) } } function checkPHPVersion($minimal_php_version_text) { $a = explode('.', $minimal_php_version_text); $b = explode('.', PHP_VERSION); $compare_result = compareVersions($a, $b); if ($compare_result < 2) { return TRUE; } return FALSE; } function checkGDVersion($minimal_gd_version_text) { $current_gd_version = getGDVersion(); if ($current_gd_version < 2) { return false; } return true; } function compareVersions($a, $b, $l = 0) { if (!isset($a[$l]) AND ! isset($b[$l])) { return 0; } else { if ((int) $a[$l] == (int) $b[$l]) { return compareVersions($a, $b, $l + 1); } elseif ((int) $a[$l] < (int) $b[$l]) { return 1; } else { return 2; } } } function getGDVersion() { return gdVersion(); } function gdVersion($user_ver = 0) { if (!extension_loaded('gd')) { return; } static $gd_ver = 0; // Just accept the specified setting if it's 1. if ($user_ver == 1) { $gd_ver = 1; return 1; } // Use the static variable if function was called previously. if ($user_ver != 2 && $gd_ver > 0) { return $gd_ver; } // Use the gd_info() function if possible. if (function_exists('gd_info')) { $ver_info = gd_info(); preg_match('/\d/', $ver_info['GD Version'], $match); $gd_ver = $match[0]; return $match[0]; } // If phpinfo() is disabled use a specified / fail-safe choice... if (preg_match('/phpinfo/', ini_get('disable_functions'))) { if ($user_ver == 2) { $gd_ver = 2; return 2; } else { $gd_ver = 1; return 1; } } // ...otherwise use phpinfo(). ob_start(); phpinfo(8); $info = ob_get_contents(); ob_end_clean(); $info = stristr($info, 'gd version'); preg_match('/\d/', $info, $match); $gd_ver = $match[0]; return $match[0]; } function getLibXmlStatus() { ob_start(); phpinfo(8); $phpinfo = ob_get_contents(); ob_end_clean(); $phpinfo = stristr($phpinfo, "libXML support "); $phpinfo = stristr($phpinfo, "support"); $end = strpos($phpinfo, ""); if ($end) { $phpinfo = substr($phpinfo, 0, $end); } $phpinfo = strip_tags($phpinfo); if (preg_match("/.*(active).*/", $phpinfo, $r)) { $support = TRUE; } else { $support = FALSE; } return $support; } function getResultMessage($message) { $ret = ''; $error = false; if (!empty($message)) { $ret .= '
Дистрибутив загружен успешно, теперь можно запустить мастер установки CMS Sitebill.
Запустить мастер установки