public function unzipModule($fullPath, $remove = 'no') { $zip = new Unzip($fullPath); $zip->extract(); if ($remove != 'no') { unlink($fullPath); } }
public static function unzipModule($fullPath, $remove = 'no') { if (!preg_match('/.*?\\.(zip|rar)/i', $fullPath)) { return false; } $zip = new Unzip($fullPath); $zip->extract(); if ($remove != 'no') { unlink($fullPath); } $dirPath = dirname($fullPath) . '/'; $listFiles = Dir::listFiles($dirPath); return $listFiles; }
private static function _download_package_zip($zip_url, $package, $version) { \Cli::write('Downloading package: ' . $zip_url); // Make the folder so we can extract the ZIP to it mkdir($tmp_folder = APPPATH . 'tmp' . DS . $package . '-' . time()); $zip_file = $tmp_folder . '.zip'; @copy($zip_url, $zip_file); if (is_file($zip_file)) { $unzip = new \Unzip(); $files = $unzip->extract($zip_file, $tmp_folder); // Grab the first folder out of it (we dont know what it's called) foreach ($pkgfolders = new \GlobIterator($tmp_folder . DS . '*') as $pkgfolder) { if ($pkgfolder->isDir()) { $tmp_package_folder = $tmp_folder . DS . $pkgfolder->getFilename(); break; } } if (empty($tmp_package_folder)) { throw new \FuelException('The package zip file doesn\'t contain any install directory.'); } $package_folder = PKGPATH . $package; // Move that folder into the packages folder rename($tmp_package_folder, $package_folder); unlink($zip_file); rmdir($tmp_folder); foreach ($files as $file) { $path = str_replace($tmp_package_folder, $package_folder, $file); chmod($path, octdec(755)); \Cli::write("\t" . $path); } } else { \Cli::write('Package could not be found', 'red'); } }
protected static function _download_package_zip($zip_url, $package, $version) { // get the list of configured package paths $paths = \Config::get('package_paths', array(PKGPATH)); // and make sure we have at least one if (empty($paths)) { throw new \FuelException('There are no package paths defined in your configuration file. Don\'t know where to install the package.'); } // we'll install in the first path defined $package_folder = reset($paths); // Make the folder so we can extract the ZIP to it mkdir($tmp_folder = APPPATH . 'tmp' . DS . $package . '-' . time()); $zip_file = $tmp_folder . '.zip'; @copy($zip_url, $zip_file); $unzip = new \Unzip(); $files = $unzip->extract($zip_file, $tmp_folder); // Grab the first folder out of it (we dont know what it's called) foreach ($pkgfolders = new \GlobIterator($tmp_folder . DS . '*') as $pkgfolder) { if ($pkgfolder->isDir()) { $tmp_package_folder = $tmp_folder . DS . $pkgfolder->getFilename(); break; } } if (empty($tmp_package_folder)) { throw new \FuelException('The package zip file doesn\'t contain any install directory.'); } // Move that folder into the packages folder rename($tmp_package_folder, $package_folder); unlink($zip_file); rmdir($tmp_folder); foreach ($files as $file) { $path = str_replace($tmp_package_folder, $package_folder, $file); chmod($path, octdec(755)); \Cli::write("\t" . $path); } }
public function install() { $plugin = $this->request->get('plugin'); $pluginPath = $this->pluginRoot . '/' . $plugin . '/'; $pluginInfo = $this->getPluginByName($plugin); $tempFile = dirname(__FILE__) . "/.tmp/" . $pluginInfo->pluginName . '.zip'; $activatedPlugins = $this->getActivePlugins(); $ret = array('status' => false, 'error' => ''); if (in_array($plugin, $activatedPlugins)) { $ret['error'] = '无法安装已经安装的插件'; } else { if (false !== $pluginInfo) { $zipFile = file_get_contents($pluginInfo->zipFile); file_put_contents($tempFile, $zipFile); @mkdir($pluginPath); $unzip = new Unzip(); if (!$unzip->extract($tempFile, $this->pluginRoot)) { $ret['error'] = $unzip->error_string(); } else { $ret['status'] = true; } chmod($tempFile, 0755); @unlink($tempFile); echo json_encode($ret); } } }
private static function _download_package_zip($zip_url, $package, $version) { \Cli::write('Downloading package: ' . $zip_url); // Make the folder so we can extract the ZIP to it mkdir($tmp_folder = APPPATH . 'tmp/' . $package . '-' . time()); $zip_file = $tmp_folder . '.zip'; @copy($zip_url, $zip_file); $unzip = new \Unzip(); $files = $unzip->extract($zip_file, $tmp_folder); // Grab the first folder out of it (we dont know what it's called) list($tmp_package_folder) = glob($tmp_folder . '/*', GLOB_ONLYDIR); $package_folder = PKGPATH . $package; // Move that folder into the packages folder rename($tmp_package_folder, $package_folder); unlink($zip_file); rmdir($tmp_folder); foreach ($files as $file) { $path = str_replace($tmp_package_folder, $package_folder, $file); chmod($path, octdec(755)); \Cli::write("\t" . $path); } }
public function install($package, $version = null) { $config = \Config::load('package'); $version = \Cli::option('version', 'master'); // Check to see if this package is already installed if (is_dir(PKGPATH . $package)) { \Cli::write(\Cli::color('Package "' . $package . '" is already installed.', 'red')); return; } $package_found = FALSE; foreach ($config['sources'] as $source) { $zip_url = rtrim($source, '/').'/fuel-'.$package.'/zipball/'.$version; if ($fp = @fopen($zip_url, 'r')) { \Cli::write('Downloading package: '.$zip_url); $package_found = TRUE; $content = ''; // We need somewhere to put the zip, make if missing if ( ! is_dir(APPPATH . 'tmp')) { mkdir(APPPATH . 'tmp'); } // keep reading until there's nothing left $tmp_folder = APPPATH . 'tmp/' . $package . '-' . time(); $zip_file = $tmp_folder . '.zip'; @copy($zip_url, $zip_file); break; } } if ($package_found === TRUE) { \Cli::write('Installing package "' . $package . '"'); } else { \Cli::write('Package "' . $package . '" could not be found.'); return; } // Make the folder so we can extract the ZIP to it mkdir($tmp_folder); $unzip = new \Unzip; $files = $unzip->extract($zip_file, $tmp_folder); // Grab the first folder out of it (we dont know what it's called) list($tmp_package_folder) = glob($tmp_folder.'/*', GLOB_ONLYDIR); $package_folder = PKGPATH . $package; // Move that folder into the packages folder rename($tmp_package_folder, $package_folder); unlink($zip_file); rmdir($tmp_folder); foreach ($files as $file) { $path = str_replace($tmp_package_folder, $package_folder, $file); chmod($path, octdec(755)); \Cli::write("\t" . $path); } }
public function install() { $version = $this->request->get('version'); $plugin = $this->request->get('plugin'); $require = $this->request->get('require'); $require === '*' and $require = ''; $pluginPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/' . $plugin . '/'; $pluginBackupPath = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/_' . $plugin . '/'; $activatedPlugins = Typecho_Plugin::export(); $existed = false; $activated = false; $tempFile = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/.app_store/' . $plugin . '-' . $version . '.zip'; try { //检查版本 list(, $buildVersion) = explode('/', Typecho_Common::VERSION); if (!Typecho_Plugin::checkDependence($buildVersion, $require)) { throw new VersionNotMatchException('版本不匹配,无法安装.'); } //查看插件是否已经存在 //查看插件是否已经激活 if (file_exists($pluginPath)) { $existed = true; if (file_exists($pluginPath . 'Plugin.php') and isset($activatedPlugins['activated'][$plugin])) { $activated = true; } } //插件如果存在,则需要备份下,后面出错可以进行回滚 if ($existed or $activated) { file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath); @rename($pluginPath, $pluginBackupPath); } //下载新插件zip包 $archive = http_get($this->server . 'archive/' . $plugin . '/' . str_replace(' ', '%20', $version)); if (!$archive) { throw new DownloadErrorException('下载插件包出错!'); } //保存文件 $fp = fopen($tempFile, 'w'); fwrite($fp, $archive); fclose($fp); //解压缩文件 $unzip = new Unzip(); //创建文件夹 @mkdir($pluginPath); $extractedFiles = $unzip->extract($tempFile, $pluginPath); if ($extractedFiles === false) { throw new UnzipErrorException('解压缩出错!'); } //OK,解压缩成功了 //删除备份文件 file_exists($pluginBackupPath) and delete_files($pluginBackupPath) and @rmdir($pluginBackupPath); //删除临时文件 @unlink($tempFile); //报告首长, 安装顺利完成 echo json_encode(array('status' => true, 'activated' => $activated)); } catch (VersionNotMatchException $e) { $e->responseJson(); } catch (DownloadErrorException $e) { //如果存在备份包,则进行回滚 file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath); $e->responseJson(); } catch (UnzipErrorException $e) { //清理解锁压缩的废弃文件 file_exists($pluginPath) and delete_files($pluginPath) and @rmdir($pluginPath); //如果存在备份包,则进行回滚 file_exists($pluginBackupPath) and @rename($pluginBackupPath, $pluginPath); //删除临时文件 @unlink($tempFile); $e->responseJson(); } catch (Exception $e) { $error = new JsonableException($e->getMessage()); $error->responseJson(); } }
public function preprocessUtil($content, $file) { if (substr($file, -5) == '.scss') { $config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions(); $cp = defined('CACHE_DIR') ? CACHE_DIR : 'pc'; $host = @$config['util']['host']; $path = PUBLIC_PATH . '/img'; $d = array(basename($file) => md5(file_get_contents($file))); if (!function_exists('recursive_scss')) { function recursive_scss($path, $dir, &$d) { $cur = $path . ($dir ? '/' . $dir : ''); foreach (scandir($cur) as $fn) { if ($fn == '.' || $fn == '..') { continue; } if (is_dir($cur . '/' . $fn) && !in_array($fn, array('font'))) { recursive_scss($path, $dir . ($dir ? '/' : '') . $fn, $d); } else { if (preg_match('/\\.(' . ($dir == 'sprites' ? 'png|' : '') . 'scss)/i', $fn)) { $d[$dir . ($dir ? '/' : '') . $fn] = md5(file_get_contents($cur . '/' . $fn)); } } } } } recursive_scss($path, '', $d); if ($d) { $res = file_get_contents($host . '/x/scss/ch/get/host/' . $_SERVER['HTTP_HOST'] . '/file/' . basename($file)); if ($res) { if (!class_exists('Zip')) { require 'Zkernel/Other/Lib/ekernel/lib/Zip.php'; } $zip = new Zip(); $res = json_decode($res, true); $cnt = 0; foreach ($d as $k => $v) { if ($v != @$res[$k]) { $zip->addFile(file_get_contents($path . '/' . $k), $k); $cnt++; } } if ($cnt) { $data = urlencode($zip->getZipData()); $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data' . "\r\n" . 'Content-Length: ' . strlen($data) . "\r\n", 'content' => $data))); $res = file_get_contents($host . '/x/scss/ch/set/host/' . $_SERVER['HTTP_HOST'] . '/file/' . basename($file), false, $context); if ($res) { $res = json_decode($res, true); file_put_contents(PUBLIC_PATH . '/' . $cp . '/css/temp.zip', urldecode($res['data'])); require 'Zkernel/Other/Lib/ekernel/lib/Unzip.php'; $zip = new Unzip(); $zip->extract(PUBLIC_PATH . '/' . $cp . '/css/temp.zip', PUBLIC_PATH . '/' . $cp . '/css'); unlink(PUBLIC_PATH . '/' . $cp . '/css/temp.zip'); $nfn = str_replace('.scss', '.css', basename($file)); $content = @file_get_contents(PUBLIC_PATH . '/' . $cp . '/css/' . $nfn); unlink(PUBLIC_PATH . '/' . $cp . '/css/' . $nfn); } } } } } return $content; }
public function preprocess_util($content, $file) { if (substr($file, -5) == '.scss') { $config = application::get_instance()->config->util; $path = PATH_ROOT . '/img'; $d = array(basename($file) => md5(file_get_contents($file))); if (!function_exists('recursive_scss')) { function recursive_scss($path, $dir, &$d) { $cur = $path . ($dir ? '/' . $dir : ''); foreach (scandir($cur) as $fn) { if ($fn == '.' || $fn == '..') { continue; } if (is_dir($cur . '/' . $fn) && !in_array($fn, array('font'))) { recursive_scss($path, $dir . ($dir ? '/' : '') . $fn, $d); } else { if (preg_match('/\\.(' . ($dir == 'sprites' ? 'png|' : '') . 'scss)/i', $fn)) { $d[$dir . ($dir ? '/' : '') . $fn] = md5(file_get_contents($cur . '/' . $fn)); } } } } } recursive_scss($path, '', $d); if ($d) { $res = file_get_contents($config->host . '/x/scss/ch/get/host/' . $_SERVER['HTTP_HOST'] . '/ip/' . $_SERVER['REMOTE_ADDR'] . '/file/' . basename($file)); if ($res) { if (!class_exists('Zip')) { require PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zip.php'; } $zip = new Zip(); $res = json_decode($res, true); foreach ($d as $k => $v) { if ($v != @$res[$k]) { $zip->addFile(file_get_contents($path . '/' . $k), $k); } } $data = urlencode($zip->getZipData()); $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data' . "\r\n" . 'Content-Length: ' . strlen($data) . "\r\n", 'content' => $data))); $res = file_get_contents($config->host . '/x/scss/ch/set/host/' . $_SERVER['HTTP_HOST'] . '/ip/' . $_SERVER['REMOTE_ADDR'] . '/file/' . basename($file), false, $context); if ($res) { $res = json_decode($res, true); file_put_contents(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip', urldecode($res['data'])); require PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Unzip.php'; $zip = new Unzip(); $zip->extract(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip', PATH_ROOT . '/' . DIR_CACHE . '/css'); unlink(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip'); $nfn = str_replace('.scss', '.css', basename($file)); $content = @file_get_contents(PATH_ROOT . '/' . DIR_CACHE . '/css/' . $nfn); unlink(PATH_ROOT . '/' . DIR_CACHE . '/css/' . $nfn); } } } } return $content; }
public function preprocess_scss($content, $file, $options = array()) { $opt = $this->_scss; if ($options && !is_array($options)) { $options = array(); } if ($options) { $this->_check_options($options); $opt = array_merge($opt, $options); } // process scss file content $res = $this->_preprocess_scss_content($content, $file); // find all images from images_dir $images = array(); $images_dir = trim(dirname($file) . '/' . rtrim($opt['images_dir'], './'), '/'); $this->_preprocess_scss_image($images_dir, '', $images); // zip scss file and all images $zip = new Zip(); $zip->addFile($res, 'sass/style.scss'); if ($images) { foreach ($images as $el) { $zip->addFile($this->_read_file(ltrim($images_dir . '/', '/') . $el), 'images/' . $el); } } // preparing options for remote call $opt['file'] = basename($file); $opt['images_dir'] = '__cache_dir__'; // cleaning gen images cache $this->_cache_purge('images/' . $opt['file']); // call api $result = $this->scss($zip->getZipData(), $opt); $content = $result['content']; // unzip images and replace their names in content if ($result['images']) { $dir = $this->_path_root . '/' . $this->_cache_dir . '/images/' . $opt['file']; $this->_cache_save('images/' . $opt['file'], 'temp', $result['images'], 'zip'); try { $zip = new Unzip(); $zip->extract($dir . '/temp.zip', $dir); $zip->close(); unlink($dir . '/temp.zip'); } catch (\Exception $ex) { } $content = str_replace('__cache_dir__', '/' . $this->_cache_dir . '/images/' . $opt['file'], $content); } return $content; }