function extract_zip() { $zip_file = UPGRADE_PATH . $this->package['release_code'] . '.zip'; require HDWIKI_ROOT . '/lib/zip.class.php'; $zip = new zip(); $swap_dir = UPGRADE_PATH . $this->package['release_code']; if (!is_dir($swap_dir)) { file::forcemkdir($swap_dir); } if (file::iswriteable($swap_dir)) { $zip->extract($zip_file, $swap_dir); } unset($zip); return count(@scandir($swap_dir)) > 0; }
/** * Méthode qui retourne le texte à indexer des docs OpenOffice */ function get_text($filename) { global $charset; $zip = new zip($filename); $texte = $zip->getFileContent("content.xml"); //On enlève toute les balises offices preg_match_all("(<([^<>]*)>)", $texte, $result); for ($i = 0; $i < sizeof($result[0]); $i++) { $texte = str_replace($result[0][$i], " ", $texte); } $texte = str_replace("'", "'", $texte); $texte = str_replace(" ", " ", $texte); if ($charset != "utf-8") { $texte = utf8_decode($texte); } $texte = html_entity_decode($texte, ENT_QUOTES, $charset); return $texte; }
function doinstall() { $appid = $this->get[2]; if (is_numeric($appid)) { $pluginurl = $this->setting['app_url'] . '/hdapp.php?action=download&type=plugin&install=1&id=' . $appid . '&url=' . urlencode(WIKI_URL); $zipcontent = @util::hfopen($pluginurl); if (empty($zipcontent)) { $this->message($this->view->lang['msgConnectFailed']); } $tmpname = HDWIKI_ROOT . '/data/tmp/' . util::random(6) . '.zip'; file::writetofile($tmpname, $zipcontent); if (function_exists('gzopen')) { require HDWIKI_ROOT . "/lib/zip.class.php"; $zip = new zip(); if (!$zip->chk_zip) { $this->message($this->view->lang['pluginInstallNoZlib'], ''); } $ziplist = @$zip->get_List($tmpname); if (!(bool) $ziplist) { unlink($tmpname); $this->message($this->view->lang['pluginAddr'] . $pluginurl . $this->view->lang['pluginAddrFail']); } $lastpos = strpos($ziplist[0]['filename'], '/'); $identifier = substr($ziplist[0]['filename'], 0, $lastpos); @$zip->Extract($tmpname, HDWIKI_ROOT . '/plugins'); } else { $this->message($this->view->lang['pluginInstallNoZlib']); } unlink($tmpname); } else { $identifier = $this->get[2]; } $plugin = $this->db->fetch_by_field('plugin', 'identifier', $identifier); if ($plugin) { $this->message($this->view->lang['pluginAddrName'] . $identifier . $this->view->lang['pluginHasInstall'], 'index.php?admin_plugin-list'); } $this->loadplugin($identifier); $plugin = $_ENV["{$identifier}"]->install(); $_ENV['plugin']->add_plugin($plugin); $this->cache->removecache('plugin'); $this->message($this->view->lang['pluginInstallSuccess'], 'index.php?admin_plugin-list'); }
public static function on_download(Context $ctx) { zip::fromFolder($zipFile = os::path($ctx->config->getPath('main/tmpdir'), 'backup.zip'), MCMS_ROOT, realpath($ctx->config->getPath('main/tmpdir'))); $filename = $ctx->host() . '-' . date('YmdHi', time() - date('Z', time())) . '.zip'; header('Content-Type: application/zip'); header('Content-Length: ' . filesize($zipFile)); header('Content-Disposition: attachment; filename="' . $filename . '"'); readfile($zipFile); unlink($zipFile); die; }
function extract($src, $dest = false) { $path_parts = pathinfo($src); if (!$dest) { $dest = $path_parts['dirname'] . '/'; } $ext = '.' . $path_parts['extension']; $name = $path_parts['filename']; foreach ($this->WathArchive as $key => $val) { if (stripos($ext, $key) !== false) { $comp = $val; } } if ($comp == 'zip') { $zip = new zip(); return $zip->extractZip($src, $dest); } elseif (strlen($comp) > 1) { $tar = new tar(); if ($comp == 'bz') { $bzip2 = new bzip2(); $src = $bzip2->extractBzip2($src); } elseif ($comp == 'gz') { $gzip = new gzip(); $src = $gzip->extractGzip($src); } if ($tar->is_tar($src) || is_file($src)) { return $tar->extractTar($src, $dest); } else { file_put_contents($dest . $name, $src); } return $dest; } return false; }
/** * Обновление конкретного модуля. */ public static function updateModule($name) { $db = self::getAllModules(); if (!array_key_exists($name, $db)) { throw new RuntimeException(t('Нет информации о модуле %name.', array('%name' => $name))); } if (empty($db[$name]['url'])) { Logger::log("no url for module {$name}, not updated."); return false; } $head = http::head($url = $db[$name]['url']); if (200 != $head['_status']) { Logger::log('updateModule: file not found: ' . $url); return false; } $tmp = http::fetch($url); foreach (array('sha1' => 'sha1_file') as $k => $func) { if (!empty($db[$name][$k]) and $db[$name][$k] != $func($tmp)) { Logger::log($k . ' hash mismatch for ' . $url); return false; } } $existed = is_dir($path = os::path('lib', 'modules', $name)); zip::unzipToFolder($tmp, $path); if ($existed) { Logger::log($name . ': updated from v' . $db[$name]['version.local'] . ' to v' . $db[$name]['version'] . '.'); } else { Logger::log($name . ': installed v' . $db[$name]['version'] . '.'); } return true; }
function install_skin() { if (!isset($this->post['submit']) && !isset($this->get['newskin']) && !isset($this->get['skindetails'])) { // Build drop down list for the OLD method $skin_box = ''; $dp = opendir('../skins'); while (($file = readdir($dp)) !== false) { $ext = strtolower(substr($file, -4)); if ($ext == '.mbs') { $skin_box .= "<option value='../skins/{$file}'>" . substr($file, 0, -4) . "</option>\n"; } } closedir($dp); // Now check for skins using the NEW method // build a list of all the xml skin files $tarTool = new archive_tar(); $xmlInfo = new xmlparser(); $new_skin_box = ''; $dp = opendir('../packages'); while (($file = readdir($dp)) !== false) { if (strtolower(substr($file, -4)) == '.tar' || strtolower(substr($file, -7)) == '.tar.gz' && $tarTool->can_gunzip()) { if ($tarTool->open_file_reader('../packages/' . $file)) { // Okay. Look at packages.txt to find our xml file $xmlFilename = $tarTool->extract_file('package.txt'); if ($xmlFilename === false) { continue; } $xmlData = $tarTool->extract_file($xmlFilename); $xmlInfo->parseTar($tarTool, $xmlFilename); } else { continue; } } else { if (strtolower(substr($file, -4)) == '.xml') { $xmlInfo->parse('../packages/' . $file); } else { $xmlInfo->reset(); continue; // skip file } } $node = $xmlInfo->GetNodeByPath('QSFMOD/TYPE'); if ($node['content'] != 'skin') { continue; } // skip other mods $new_skin_box .= " <li><a href=\"{$this->self}?a=templates&s=load&newskin="; if (strtolower(substr($file, -7)) == '.tar.gz') { $new_skin_box .= urlencode(substr($file, 0, -7)) . "\" "; } else { $new_skin_box .= urlencode(substr($file, 0, -4)) . "\" "; } $node = $xmlInfo->GetNodeByPath('QSFMOD/DESCRIPTION'); if (isset($node['content']) && $node['content']) { $new_skin_box .= "title=\"" . htmlspecialchars($node['content']) . "\""; } $new_skin_box .= ">"; $node = $xmlInfo->GetNodeByPath('QSFMOD/TITLE'); $new_skin_box .= "<strong>" . htmlspecialchars($node['content']) . "</strong></a>"; $node = $xmlInfo->GetNodeByPath('QSFMOD/VERSION'); $new_skin_box .= " " . htmlspecialchars($node['content']); $node = $xmlInfo->GetNodeByPath('QSFMOD/AUTHORNAME'); $new_skin_box .= " (" . htmlspecialchars($node['content']) . ")"; $new_skin_box .= "</li>\n"; $xmlInfo->reset(); } closedir($dp); return $this->message($this->lang->install_skin, eval($this->template('ADMIN_INSTALL_SKIN'))); } else { if (isset($this->get['skindetails'])) { // Display some preview information on the skin } else { if (isset($this->get['newskin'])) { // Use new method of install $tarTool = new archive_tar(); // Open and parse the XML file $xmlInfo = new xmlparser(); if (file_exists('../packages/' . $this->get['newskin'] . '.xml')) { $xmlInfo->parse('../packages/' . $this->get['newskin'] . '.xml'); } else { if (file_exists('../packages/' . $this->get['newskin'] . '.tar')) { $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar'); $xmlFilename = $tarTool->extract_file('package.txt'); $xmlInfo->parseTar($tarTool, $xmlFilename); } else { if (file_exists('../packages/' . $this->get['newskin'] . '.tar.gz') && $tarTool->can_gunzip()) { $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar.gz'); $xmlFilename = $tarTool->extract_file('package.txt'); $xmlInfo->parseTar($tarTool, $xmlFilename); } else { return $this->message($this->lang->install_skin, $this->lang->skin_none); } } } // Get the folder name $node = $xmlInfo->GetNodeByPath('QSFMOD/TYPE'); $skin_dir = $node['attrs']['FOLDER']; // Run the uninstall queries packageutil::run_queries($this->db, $xmlInfo->GetNodeByPath('QSFMOD/UNINSTALL')); // Run the install queries packageutil::run_queries($this->db, $xmlInfo->GetNodeByPath('QSFMOD/INSTALL')); // Add the templates packageutil::insert_templates($skin_dir, $this->db, $xmlInfo->GetNodeByPath('QSFMOD/TEMPLATES')); // Extract the files if (file_exists('../packages/' . $this->get['newskin'] . '.tar')) { $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar'); } else { $tarTool->open_file_reader('../packages/' . $this->get['newskin'] . '.tar.gz'); } $nodes = $xmlInfo->GetNodeByPath('QSFMOD/FILES'); foreach ($nodes['child'] as $node) { if ($node['name'] == 'FILE') { $filename = $node['content']; $data = $tarTool->extract_file($filename); if ($data !== false) { $this->_make_dir('../' . $filename); $fh = fopen('../' . $filename, 'wb'); fwrite($fh, $data); fclose($fh); } } } $tarTool->close_file(); $this->chmod('../skins/' . $skin_dir, 0777, true); return $this->message($this->lang->install_skin, $this->lang->install_done); } else { // Use old method of install if (!isset($this->get['temp']) && !isset($this->get['install'])) { if (!isset($this->post['install'])) { return $this->message($this->lang->install_skin, $this->lang->skin_none); } $dir = md5(microtime()); $zip = new zip(); $zip->extract($this->post['install'], "../skins/{$dir}"); $this->chmod("../skins/{$dir}", 0777, true); include "../skins/{$dir}/info.php"; if (is_dir("../skins/{$skin['dir']}")) { return $this->message($this->lang->install_skin, "{$this->lang->install_exists1} <b>{$skin['name']}</b> {$this->lang->install_exists2}", $this->lang->install_overwrite, "{$this->self}?a=templates&s=load&temp={$dir}"); } $this->get['temp'] = $dir; } $dir = $this->get['temp']; include "../skins/{$dir}/info.php"; if (is_dir("../skins/{$skin['dir']}")) { $this->remove_dir("../skins/{$skin['dir']}"); } rename("../skins/{$dir}", "../skins/{$skin['dir']}"); $this->chmod("../skins/{$skin['dir']}", 0777, true); $dir = $skin['dir']; $queries = array(); $pre = $this->db->prefix; include "../skins/{$dir}/templates.php"; $this->db->query("DELETE FROM %pskins WHERE skin_dir='%s'", $dir); $this->db->query("INSERT INTO %pskins (skin_name, skin_dir) VALUES ('%s', '%s')", $skin['name'], $dir); $this->db->query("DELETE FROM %ptemplates WHERE template_skin='%s'", $dir); $this->execute_queries($queries); return $this->message($this->lang->install_skin, $this->lang->install_done); } } } }
function InportDict($targetfile) { if (!ini_set('memory_limit', '128M')) { exit('设置内存错误,请到dede官网下载解压版的base_dic_full.dic!'); } require_once DEDEINC . '/zip.class.php'; $zip = new zip(); //echo $targetfile; $unpackagefile = array_keys($zip->Extract($targetfile, DEDEINC . '/data/')); //exit(); $this->MakeDict(DEDEINC . '/data/' . $unpackagefile[0]); unlink(DEDEINC . '/data/' . $unpackagefile[0]); return true; }
function write_to_zip($backupfilename, $dumpfile, $volume) { require_once TIPASK_ROOT . '/lib/zip.class.php'; $zip = new zip(); if (!$zip->chk_zip) { $this->message('??§á???gzopen??'); } $zipfilename = $backupfilename . '.zip'; $unlinks = ''; for ($i = 1; $i <= $volume; $i++) { $filename = sprintf($dumpfile, $i); $fp = fopen($filename, "r"); $content = @fread($fp, filesize($filename)); fclose($fp); $zip->add_File($content, basename($filename)); $unlinks .= "@unlink('{$filename}');"; } $fp = fopen($zipfilename, 'w'); if (@fwrite($fp, $zip->get_file()) !== FALSE) { eval($unlinks); } unset($sqldump, $zip, $content); }
public function import() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->post(); if (empty($_FILES['Filedata'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request')); } $csv = $_FILES['Filedata']; if (empty($csv['name']) or empty($csv['tmp_name'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request')); } $csv['name'] = trim($csv['name']); if (strpos($csv['name'], '.')) { $postfix = strtoupper(substr($csv['name'], strrpos($csv['name'], '.') + 1)); } else { $postfix = ''; } if ($postfix != 'TSV' and $postfix != 'CSV' and $postfix != 'ZIP') { throw new MyRuntimeException(Kohana::lang('o_global.bad_request')); } if (!is_uploaded_file($csv['tmp_name'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request')); } if ($postfix == 'CSV' || $postfix == 'TSV') { $csv = file_get_contents($csv['tmp_name']); $dir = NULL; } else { $zip = zip::factory($csv['tmp_name']); $csv = NULL; $dir = Kohana::config('product.import_tmp_dir'); $dir = rtrim(trim($dir), '/'); $dir .= '/' . uniqid(); if (!is_dir($dir) and !@mkdir($dir, 0777, TRUE)) { throw new MyRuntimeException(Kohana::lang('o_product.import_cte_tmpdir_failed')); } if (!is_object($zip) or !$zip->extract($dir)) { throw new MyRuntimeException(Kohana::lang('o_product.import_wte_tmp_failed')); } $dirs = array($dir); while ($direct = array_shift($dirs)) { $handler = opendir($direct); while (($item = readdir($handler)) !== FALSE) { if ($item !== '.' and $item !== '..') { $path = $dir . '/' . $item; if (is_dir($path)) { $dirs[] = $path; } else { $extfnm = strtoupper(substr($path, strrpos($path, '.') + 1)); if (strpos($path, '.') && ($extfnm === 'CSV' || $extfnm === 'TSV')) { $dirs = array(); $csv = file_get_contents($path); $dir = dirname($path); break; } } } } closedir($handler); } if (is_null($csv)) { throw new MyRuntimeException(Kohana::lang('o_product.import_csv_not_found')); } } $i = 1; $csv = iconv('GBK', 'UTF-8//IGNORE', $csv); //$import = ImportService::get_instance()->run($csv, $dir); $import = ImportService::get_instance()->parse_csv($csv, $dir); $errs = ''; foreach ($import['errors'] as $l => $err) { foreach ($err as $item) { $errs .= $i . '、' . $item->getMessage() . ';<br/>'; $i++; } } if (empty($errs)) { /*require_once Kohana::find_file('vendor', 'phprpc/phprpc_client',TRUE); $site_id = 0; $site_domain = ''; $mime_type2postfix = Kohana::config('mimemap.type2postfix'); $mime_postfix2type = Kohana::config('mimemap.postfix2type'); $phprpc_api_key = Kohana::config('phprpc.remote.Attachment.apiKey'); $attachment_service = new PHPRPC_Client(Kohana::config('phprpc.remote.Attachment.host')); foreach ($import['products'] as $product) { $goods = array(); $description = $product['description']; $pictures = $product['pictures']; $product_attributeoption_relation = !empty($product['goods_attributeoption_relation_struct_default']['items']) ? $product['goods_attributeoption_relation_struct_default']['items'] : array(); $product_featureoption_relation = !empty($product['product_featureoption_relation_struct']['items']) ? $product['product_featureoption_relation_struct']['items'] : array(); unset($product['description'], $product['pictures']); if (!empty($product['goods'])) { $goods = $product['goods']; unset($product['goods']); } if ($product['site_id'] != $site_id) { $site_id = $product['site_id']; $site_domain = Mysite::instance($site_id)->get('domain'); } try { $product = coding::encode_product($product); if (isset($product['id'])) { ProductService::get_instance()->set($product['id'], $product); $product_id = $product['id']; } else { $product_id = ProductService::get_instance()->create($product); } if (!empty($product['goods_attributeoption_relation_struct_default'])) { $product['goods_attributeoption_relation_struct_default'] = json_decode($product['goods_attributeoption_relation_struct_default'], TRUE); } if (!empty($product['product_featureoption_relation_struct'])) { $product['product_featureoption_relation_struct'] = json_decode($product['product_featureoption_relation_struct'], TRUE); } ProductsearchService::get_instance()->set_single(array( 'product_id' => $product_id, 'site_id' => $product['site_id'], 'category_id' => $product['category_id'], 'brand_id' => $product['brand_id'], 'title' => $product['title'], 'brief' => $product['brief'], 'description' => $description['content'], 'attributes' => empty($product['goods_attributeoption_relation_struct_default']['items']) ? array() : $product['goods_attributeoption_relation_struct_default']['items'], 'features' => empty($product['product_featureoption_relation_struct']['items']) ? array() : $product['product_featureoption_relation_struct']['items'], )); } catch (MyRuntimeException $ex) { break; } try { $description['product_id'] = $product_id; if (isset($description['id'])) { ProductdescsectionService::get_instance()->set($description['id'], $description); } else { ProductdescsectionService::get_instance()->create($description); } } catch (MyRuntimeException $ex) { ProductService::get_instance()->delete_by_product_id($product_id); break; } try { ORM::factory('product_featureoption_relation')->where('product_id', $product_id)->delete_all(); if (!empty($product_featureoption_relation)) { foreach ($product_featureoption_relation as $fid => $oid) { Product_featureoption_relationService::get_instance()->create(array( 'site_id' => $product['site_id'], 'product_id' => $product_id, 'featureoption_id' => $oid, 'feature_id' => $fid, )); } } } catch (MyRuntimeException $ex) { ProductService::get_instance()->delete_by_product_id($product_id); break; } try { ORM::factory('product_argument')->where('product_id', $product_id)->delete_all(); if (!empty($product['arguments'])) { Product_argumentService::get_instance()->create(array( 'product_id' => $product_id, 'arguments' => json_encode($product['arguments']), )); } } catch (MyRuntimeException $ex) { ProductService::get_instance()->delete_by_product_id($product_id); break; } try { ksort($pictures); $i = 0; foreach ($pictures as $picname => $picpath) { $attachment = array( 'fileName' => strip_tags($picname), 'fileSize' => filesize($picpath), 'filePostfix' => strtolower(substr($picname, strrpos($picname, '.') + 1)), 'srcIp' => $this->input->ip_address(), 'attachMeta' => json_encode(array( 'siteId' => $site_id, 'siteDomain' => $site_domain, )), 'createTimestamp' => time(), 'updateTimestamp' => time(), ); if(array_key_exists($attachment['filePostfix'], $mime_postfix2type)){ $attachment['fileMimeType'] = $mime_postfix2type[$attachment['filePostfix']]; }else{ $attachment['fileMimeType'] = 'application/octet-stream'; } $pic_args = array($attachment); $pic_sign = md5(json_encode($pic_args).$phprpc_api_key); $attachment_id = $attachment_service->phprpc_addAttachmentFileData($attachment, @file_get_contents($picpath), $pic_sign); if (is_numeric($attachment_id)) { $productpic_id = ProductpicService::get_instance()->add(array( 'site_id' => $site_id, 'product_id' => $product_id, 'is_default' => ProductpicService::PRODUCTPIC_IS_DEFAULT_FALSE, 'title' => '', 'attach_id' => $attachment_id, 'meta_struct' => NULL, 'create_timestamp' => time(), 'update_timestamp' => time(), )); if ($i == 0) { ProductpicService::get_instance()->set_default_pic_by_productpic_id($productpic_id, $product_id, $site_id); } $pictures[$picname] = $productpic_id; } else { //throw new MyRuntimeException('图片存储失败'); } $i ++; } } catch (MyRuntimeException $ex) { ProductService::get_instance()->delete_by_product_id($product_id); break; } if (!empty($goods)) { try { $good_ids = array(); $aopt_ids = array(); if (isset($product['id'])) { $query_struct = array('where' => array( 'product_id' => $product_id, )); // 获取原有货品 ID 列表 foreach (GoodService::get_instance()->query_assoc($query_struct) as $item) { $good_ids[$item['id']] = TRUE; } // 获取原有商品所关联的规格项 ID 列表 foreach (Product_attributeoption_relationService::get_instance()->query_assoc($query_struct) as $item) { $aopt_ids[$item['attributeoption_id']] = TRUE; } // 删除商品、货品与规格项的关联 ORM::factory('goods_attributeoption_relation')->where('product_id', $product_id)->delete_all(); ORM::factory('product_attributeoption_relation')->where('product_id', $product_id)->delete_all(); // 保存现有的商品与规格项关联,并且从原有关联列表中删除掉当前保存的 foreach ($product_attributeoption_relation as $aid => $oids) { foreach ($oids as $oid) { Product_attributeoption_relationService::get_instance()->create(array( 'site_id' => $product['site_id'], 'product_id' => $product_id, 'attributeoption_id' => $oid, 'attribute_id' => $aid, )); unset($aopt_ids[$oid]); } } // 清理掉不再关联的规格项对应的图片关联 if (!empty($aopt_ids)) { ORM::factory('product_attributeoption_productpic_relation')->where('product_id', $product_id)->in('attributeoption_id', array_keys($aopt_ids))->delete_all(); } } foreach ($goods as $good) { // 获取货品所关联的图片 ID 列表 $goodpics = array(); if (!empty($good['pictures'])) { foreach ($good['pictures'] as $goodpic) { if (isset($pictures[$goodpic]) AND preg_match('/^\d+$/', $pictures[$goodpic])) { $goodpics[] = $pictures[$goodpic]; } } $good['goods_productpic_relation_struct'] = array( 'items' => $goodpics ); } $good['product_id'] = $product_id; $good_attributeoption_relation = $good['goods_attributeoption_relation_struct']['items']; $good = coding::encode_good($good); // 存在 ID 时为更新,否则为新建 if (isset($good['id'])) { GoodService::get_instance()->set($good['id'], $good); $good_id = $good['id']; unset($good_ids[$good['id']]); } else { $good_id = GoodService::get_instance()->create($good); } // 保存货品与图片的关联 foreach ($goodpics as $productpic_id) { Goods_productpic_relationService::get_instance()->create(array( 'site_id' => $site_id, 'product_id' => $product_id, 'goods_id' => $good_id, 'productpic_id' => $productpic_id, )); } // 保存货品与规格项的关联 foreach ($good_attributeoption_relation as $aid => $oid) { Goods_attributeoption_relationService::get_instance()->create(array( 'site_id' => $product['site_id'], 'product_id' => $product_id, 'goods_id' => $good_id, 'attributeoption_id' => $oid, 'attribute_id' => $aid, )); } } // 删除原有的,当前已不存在的货品相关数据 if (!empty($good_ids)) { $good_ids = array_keys($good_ids); ORM::factory('good')->where('product_id', $product_id)->in('id', $good_ids)->delete_all(); ORM::factory('goods_productpic_relation')->where('product_id', $product_id)->in('id', $good_ids)->delete_all(); } } catch (MyRuntimeException $ex) { ProductService::get_instance()->delete_by_product_id($product_id); break; } } else { if (isset($product['id'])) // 清理商品、货品与规格的关联 { ORM::factory('good')->where('product_id', $product_id)->delete_all(); ORM::factory('goods_attributeoption_relation')->where('product_id', $product_id)->delete_all(); ORM::factory('goods_productpic_relation')->where('product_id', $product_id)->delete_all(); ORM::factory('product_attributeoption_relation')->where('product_id', $product_id)->delete_all(); ORM::factory('product_attributeoption_productpic_relation')->where('product_id', $product_id)->delete_all(); } GoodService::get_instance()->create(array( 'on_sale' => $product['on_sale'], 'site_id' => $product['site_id'], 'product_id' => $product_id, 'is_default' => 1, 'sku' => $product['sku'], 'price' => $product['goods_price'], 'market_price' => $product['goods_market_price'], 'title' => $product['title'], 'cost' => $product['goods_cost'], 'store' => $product['store'], 'weight' => $product['weight'], 'create_timestamp' => time(), 'update_timestamp' => time(), )); } }*/ //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = 'Success'; $return_struct['content'] = $return_data; } else { $return_struct['status'] = 0; $return_struct['code'] = 400; $return_struct['msg'] = $errs; $return_struct['content'] = $return_data; } exit(json_encode($return_struct)); //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { $this->template = new View('layout/empty_html'); // html 输出 $this->template->return_struct = $return_struct; $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; $this->template->content->errs = $errs; } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); exit(json_encode($return_struct)); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
function doimport() { set_time_limit(0); if (substr(trim(ini_get('memory_limit')), 0, -1) < 32 && substr(trim(ini_get('memory_limit')), 0, -1) > 0) { @ini_set('memory_limit', '32M'); } $filename = str_replace('*', '.', $this->get[2]); $filenum = $this->get[3] ? $this->get[3] : 1; $filedir = "./data/db_backup/"; $filetype = $this->get[4] ? $this->get[4] : substr($filename, -3); if ($filetype != 'zip' && $filetype != 'sql') { $this->message($this->view->lang['dbBackupFormatError'], 'BACK'); } else { if ($filenum == 1) { if ($filetype == 'zip') { require_once HDWIKI_ROOT . '/lib/zip.class.php'; $zip = new zip(); if (!$zip->chk_zip) { $this->message($this->view->lang['chkziperror'], ''); } $zip->Extract($filedir . $filename, $filedir); $filename = substr($filename, 0, -4) . "_1.sql"; } else { $num = strrpos($filename, "_"); $filename = substr($filename, 0, $num) . "_1.sql"; } } if (file_exists($filedir . $filename)) { $sqldump = file::readfromfile($filedir . $filename); preg_match('/#\\sVersion:\\shdwiki\\s([^\\n]+)\\n/i', $sqldump, $hdversion); if ($hdversion[1] != HDWIKI_VERSION) { $this->message($this->view->lang['dbSqlVersionError'], 'index.php?admin_db-backup'); } $sqlquery = $_ENV['db']->splitsql($sqldump); unset($sqldump); foreach ($sqlquery as $sql) { $sql = $_ENV['db']->syntablestruct(trim($sql), $this->db->version() > '4.1', DB_CHARSET); if ($sql != '') { $this->db->query($sql, 'SILENT'); if (($sqlerror = $this->db->error()) && $this->db->errno() != 1062) { $this->db->halt('MySQL Query Error', $sql); } } } if ($filetype == 'zip') { @unlink($filedir . $filename); } $filenum++; $num = strrpos($filename, "_"); $filename = str_replace('.', '*', substr($filename, 0, $num) . "_" . $filenum . ".sql"); $url = "index.php?admin_db-import-{$filename}-{$filenum}-{$filetype}"; $this->message("<image src='style/default/loading.gif'><br />" . $this->view->lang['dbBackupNext1'] . ($filenum - 1) . $this->view->lang['dbBackupNext2'] . "<script type=\"text/JavaScript\">setTimeout(\"window.location.replace('{$url}');\", 2000);</script>", ''); } else { $this->cache->removecache('import_files'); $this->message($this->view->lang['dbSqlImportSuccess'], 'index.php?admin_db-backup'); } } }
public function run() { $tmpdir = os::mkdir(os::path('tmp', 'modules')); $existing = $this->getExistingModules(); foreach (glob(os::path('lib', 'modules', '*', 'module.ini')) as $inifile) { $module = basename(dirname($inifile)); $ini = array_merge(array('priority' => 'optional', 'section' => 'service'), ini::read($inifile)); foreach (array('section', 'version', 'name') as $k) { if (!array_key_exists($k, $ini)) { printf("warning: %s has no '%s' key, module ignored.\n", $module, $k); continue 2; } } if (!in_array($zipname = $module . '-' . $ini['version'] . '.zip', $existing)) { zip::fromFolder($fullzipname = os::path($tmpdir, $zipname), dirname($inifile)); printf("new file: %s\n", basename($fullzipname)); } foreach ($ini as $k => $v) { if (is_array($v)) { unset($ini[$k]); } } $ini['filename'] = $zipname; $this->modules[$module] = $ini; } ksort($this->modules); ini::write($this->inifile, $this->modules); }
public function stimulate(&$hash) { LINB::checkArgs($hash, array('string' => array('action' => 'open', 'path' => 'linbApp', 'className' => 'App', 'content' => '', 'theme' => 'default', 'lang' => 'en'))); $io = LINB::SC('IO'); //only input relative path, and not ./ or ../ allowed switch ($hash->action) { case 'fetchwebfile': $content = file_get_contents($hash->path); if ($content !== false) { return $content; } else { throw new LINB_E("Error: Can\\'t get " . $hash->path); } break; case 'downloadjs': header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Accept-Ranges: bytes"); header("Content-Disposition: attachment; filename=\"jsLinb.Class.js\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($hash->content)); header("Pragma: public"); header("Expires: 0"); echo $hash->content; return; break; case 'downloadhtml': $template = $io->getString(self::TEMPLATE_SINHTML); $template = LINB::parseTemplate($template, array("libpath" => "http://jslinb.appspot.com/", "clsName" => $hash->clsName, "content" => $hash->content, "theme" => $hash->theme, "lang" => $hash->lang)); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Description: File Transfer"); header("Content-Type: application/force-download"); header("Accept-Ranges: bytes"); header("Content-Disposition: attachment; filename=\"linbApp.html\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . strlen($template)); header("Pragma: public"); header("Expires: 0"); echo $template; return; break; case 'downloadzip2': $zip = new zip(); $fileName = 'jsLinbApp.zip'; $rootName = 'runtime'; $path = self::BASE_PATH; $path2 = 'index.html'; $template = $io->getString(self::TEMPLATE_SINHTML); $template = LINB::parseTemplate($template, array("libpath" => "", "clsName" => $hash->clsName, "content" => $hash->content, "theme" => $hash->theme, "lang" => $hash->lang)); $zip->addFile($template, $path2); $path2 = $rootName . DIRECTORY_SEPARATOR . 'loading.gif'; $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2); $zip->addFile($f, $path2); $path2 = $rootName . DIRECTORY_SEPARATOR . 'addBuilderLink.js'; $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2); $zip->addFile($f, $path2); $io->_zip($path, $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'Locale', $zip); $io->_zip($path, $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'appearance', $zip); $path2 = $rootName . DIRECTORY_SEPARATOR . 'jsLinb' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'linb-all.js'; $f = file_get_contents($path . DIRECTORY_SEPARATOR . $path2); $zip->addFile($f, $path2); $fd = fopen($fileName, "wb"); $out = fwrite($fd, $zip->getZippedfile()); fclose($fd); $zip->forceDownload($fileName); @unlink($fileName); return; break; case 'savetoserver': $io->setString($hash->path, $hash->content); return array('OK' => true); //throw new LINB_E("You cant save file to this server!"); break; case 'del': foreach ($hash->path as $v) { $io->delete($v); } return array('OK' => true); break; case 'add': $file = $hash->path; if ($hash->type == 'file') { $file = $hash->path . '/' . $hash->filename; } if ($io->exists($io->absPath($file))) { throw new LINB_E("'{$file}' exists!"); } if (!$io->exists($hash->path)) { $io->dirMake($hash->path, true); } if ($hash->type == 'file') { $template = " "; if (substr($file, -3, 3) == self::FILE_JS) { $className = "==>specify_class_name_here"; try { // Get js class name $farr = explode('/js/', $file); if (isset($farr[0])) { $farr1 = explode('/', $farr[0]); if (isset($farr[1])) { $farr2 = explode(".", $farr[1]); if (isset($farr2[0])) { $className = $farr1[sizeof($farr1) - 1] . '.' . implode('.', explode('/', $farr2[0])); } } } } catch (Exception $e) { } $template = $io->getString(self::TEMPLATE_JS); $template = LINB::parseTemplate($template, array("className" => $className)); } $io->setString($io->absPath($file), $template); } return array('OK' => true); break; case 'save': $io->setString($hash->path, $hash->content); return array('OK' => true); break; case 'getfile': return array('file' => $io->getString($hash->path)); break; case 'open': $prjpath = $hash->path; if ($prjpath[0] == '.') { throw new LINB_E("Error: Can\\'t handle parent path!"); } $prjpath = str_replace("/", "\\", $prjpath); //$b = $io->dirList($prjpath); $b = $io->search("[a-zA-Z0-9].*", $prjpath, isset($hash->type) ? $hash->type : -1, isset($hash->deep) ? $hash->deep : 0); $root = str_replace("\\", "/", realpath('.')) . '/'; //ensure to return relative url format: '/' foreach ($b as &$v) { $v['location'] = str_replace("\\", "/", $v['location']); $v['location'] = str_replace($root, "", $v['location']); } unset($io); return $b; break; case 'release': $arr = explode(DIRECTORY_SEPARATOR, $hash->path); $name = array_pop($arr); $io->zipDir4Download($hash->path, $name . '.zip'); return; break; case 'upload': LINB::checkArgs($hash, array('string' => array('path' => null))); $uploader = LINB::SC('Uploader'); $uploader->set_type('image'); $name = ""; foreach ($_FILES as $file) { if (!empty($file['name'])) { $name = $file['name']; $save_path = $hash->path . '/'; $uploader->save($file, $save_path); break; } } unset($uploader); return array('OK' => true, 'name' => $name); break; } }
} } /*--------------------- function _getformzip() 处理从ZIP中解压的图片 ---------------------*/ if ($formzip == 1) { include_once DEDEINC . "/zip.class.php"; include_once DEDEADMIN . "/file_class.php"; $zipfile = $cfg_basedir . str_replace($cfg_mainsite, '', $zipfile); $tmpzipdir = DEDEDATA . '/ziptmp/' . cn_substr(md5(ExecTime()), 16); $ntime = time(); if (file_exists($zipfile)) { @mkdir($tmpzipdir, $GLOBALS['cfg_dir_purview']); @chmod($tmpzipdir, $GLOBALS['cfg_dir_purview']); $z = new zip(); $z->ExtractAll($zipfile, $tmpzipdir); $fm = new FileManagement(); $imgs = array(); $fm->GetMatchFiles($tmpzipdir, "jpg|png|gif", $imgs); $i = 0; foreach ($imgs as $imgold) { $i++; $savepath = $cfg_image_dir . "/" . MyDate("Y-m", $ntime); CreateDir($savepath); $iurl = $savepath . "/" . MyDate("d", $ntime) . dd2char(MyDate("His", $ntime) . '-' . $adminid . "-{$i}" . mt_rand(1000, 9999)); $iurl = $iurl . substr($imgold, -4, 4); $imgfile = $cfg_basedir . $iurl; copy($imgold, $imgfile); unlink($imgold); if (is_file($imgfile)) {
<?php /** * MX ZIP for ExpressionEngine3 * * @package ExpressionEngine * @subpackage Plugins * @category Plugins * @author Max Lazar <*****@*****.**> * @purpose MX Zip adds you capability to add files/folders into zipping archive directly from ExpressionEngine * @Commercial - please see LICENSE file included with this distribution */ require_once PATH_THIRD . 'zip/config.php'; $plugin_info = array('pi_name' => MX_ZIP_NAME, 'pi_version' => MX_ZIP_VER, 'pi_author' => MX_ZIP_AUTHOR, 'pi_author_url' => MX_ZIP_DOCS, 'pi_description' => MX_ZIP_DESC, 'pi_usage' => zip::usage()); class Zip { var $return_data = ""; var $remove_path = ""; var $add_path = ""; var $large_files = ""; var $archive_folder = ""; var $archive_name = ""; var $archive_fname = ""; var $comment = null; var $no_compression = false; var $remove_all_path = false; var $cache_path = false; var $speed = 500; function Zip() { $LD = '\\{';
function doinstall() { if (isset($this->get[2]) && is_numeric($this->get[2])) { $style_download_url = $this->setting['app_url'] . "/hdapp.php?action=download&type=template&install=1&id=" . $this->get[2] . "&url=" . WIKI_URL; $zipcontent = @util::hfopen($style_download_url); $tmpdir = HDWIKI_ROOT . '/data/tmp/'; file::forcemkdir($tmpdir); $tmpname = $tmpdir . util::random(6) . '.zip'; file::writetofile($tmpname, $zipcontent); require HDWIKI_ROOT . "/lib/zip.class.php"; require HDWIKI_ROOT . "/lib/xmlparser.class.php"; $zip = new zip(); if (!$zip->chk_zip) { $this->message($this->view->lang['styleInstallNoZlib'], ''); } $ziplist = @$zip->get_List($tmpname); if (!(bool) $ziplist) { @unlink($tmpname); $this->message($this->view->lang['styleZipFail'], 'BACK'); } $theme_name = $_ENV['theme']->get_theme_name($ziplist); @$zip->Extract($tmpname, $tmpdir); @unlink($tmpname); //move file $syle_path = $tmpdir . 'hdwiki'; if (is_dir(HDWIKI_ROOT . '/style/' . $theme_name)) { @file::removedir($syle_path); $this->message($this->view->lang['stylePathRepeat'], 'BACK'); } @file::copydir($syle_path, HDWIKI_ROOT); @file::removedir($syle_path); //save db $style_xml = HDWIKI_ROOT . '/style/' . $theme_name . '/desc.xml'; if (!is_file($style_xml)) { $this->message($this->view->lang['styleXmlNotExist'], 'BACK'); } $xmlnav = $_ENV['theme']->read_xml($theme_name); $style['name'] = $xmlnav['name']; $style['copyright'] = $xmlnav['copyright']; $style['path'] = $theme_name; $stylecon = $_ENV['theme']->add_check_style($style['path']); if ($stylecon == null) { $_ENV['theme']->add_style($style); $this->cache->removecache('style'); $this->message($this->view->lang['styleInstallSuccess'], 'BACK'); } else { $this->message($this->view->lang['styleDbPathRepeat'], 'index.php?admin_theme'); } } else { $this->message($this->view->lang['commonParametersInvalidTip'], 'index.php?admin_theme'); } }
function InportDict($targetfile) { if (!ini_set('memory_limit', '128M')) { exit('设置内存错误,请稍后在试!'); } require_once ROOT_PATH . 'includes/zip.class.php'; $zip = new zip(); //echo $targetfile; $unpackagefile = array_keys($zip->Extract($targetfile, ROOT_PATH . 'includes/codetable/')); //exit(); $this->MakeDict(ROOT_PATH . 'includes/codetable/' . $unpackagefile[0]); unlink(ROOT_PATH . 'includes/codetable/' . $unpackagefile[0]); return true; }
foreach ($zipFiles as $filePath) { if (file_exists(ROOT . $filePath)) { $existingFiles[] = $filePath; } elseif ($filePath == '_files_to_delete.txt') { $toDeleteFiles = explode("\n", $zip->extract_file('_files_to_delete.txt')); } elseif ($filePath == '_maj_infos.txt') { $nameFileToMove = $zip->extract_file('_maj_infos.txt'); } else { $newFiles[] = $filePath; } } move_uploaded_file($file, ROOT . 'uploads/' . url_transform($nameFileToMove) . '.zip'); } if (isset($_GET['confirmMAJ'])) { $file = ROOT . 'uploads/' . $_GET['confirmMAJ'] . '.zip'; $zip = new zip($file); if ($zip->extract(ROOT)) { if (file_exists(ROOT . '_files_to_delete.txt')) { $toDeleteFiles = file(ROOT . '_files_to_delete.txt'); foreach ($toDeleteFiles as $filePathDel) { rm(ROOT . ltrim(trim($filePathDel), '/'), true); } } @unlink(ROOT . '_files_to_delete.txt'); @unlink(ROOT . '_maj_infos.txt'); $error = new Error(); $error->add_error(translate('maj_success'), ERROR_PAGE, __FILE__, __LINE__); } else { $error = new Error(); $error->add_error(translate('maj_fail'), ERROR_PAGE, __FILE__, __LINE__); }
function export_skin() { if (!isset($this->post['skin'])) { $skin_box = $this->select_skins($this->skin); return $this->message('Export a skin', "\r\n\t\t\tSelect a skin to export:<br /><br />\r\n\t\t\t<form action='{$this->self}?a=templates&s=export' method='post'>\r\n\t\t\t\t<select name='skin'>\r\n\t\t\t\t\t{$skin_box}\r\n\t\t\t\t</select>\r\n\t\t\t\t<input type='submit' value='Export Skin'>\r\n\t\t\t</form>"); } else { $templates = $this->dump_database(array('templates' => "template_skin='{$this->post['skin']}'")); $skin = $this->db->fetch("SELECT * FROM {$this->pre}skins WHERE skin_dir='{$this->post['skin']}'"); $info = "<?php\r\n\$skin['name'] = \"" . addslashes($skin['skin_name']) . "\";\r\n\$skin['dir'] = \"" . addslashes($skin['skin_dir']) . "\";\r\n?>"; if (file_exists("../skins/{$this->post['skin']}/info.php")) { unlink("../skins/{$this->post['skin']}/info.php"); } if (file_exists("../skins/{$this->post['skin']}/templates.php")) { unlink("../skins/{$this->post['skin']}/templates.php"); } include '../lib/zip.php'; $this->chmod('..', 0777); $zip = new zip(); $zip->add("../skins/{$this->post['skin']}"); $zip->add_file($info, 'info.php'); $zip->add_file($templates, 'templates.php'); $zip->write_zip("../{$this->post['skin']}.mbs"); return $this->message('Export a Skin', 'Skin exported to the main MercuryBoard directory.', "{$this->post['skin']}.mbs", "../{$this->post['skin']}.mbs"); } }
function init() { parent::init(); if ($_POST['addcomponenttorepository_form_submitted']) { // echo "<pre>"; // print_r($_FILES); // echo "</pre>"; // If not uplaoded sucessfully add error if ($_FILES["component_file"]["error"] > 0) { $this->add('View_Error')->set("Error: " . $_FILES["component_file"]["error"]); } else { // only zip files allowed to upload if ($_FILES['component_file']['type'] != 'application/x-zip' and $_FILES['component_file']['type'] != 'application/zip') { $this->add('View_Error')->set('Component should be uploaded zipped only. found ' . $_FILES['component_file']['type']); } else { // Search for config.xml file in uploaded zip $zip = new \zip(); $config_file = $zip->readFile($_FILES['component_file']['tmp_name'], 'config.xml'); $config_file_data = $config_file['config.xml']['Data']; // if not found set error if (($msg = $this->isValidConfig($config_file_data)) !== true) { $this->add('View_Error')->set($msg); return true; } if (!is_writable(getcwd() . DS . 'epan-components')) { $this->add('View_Error')->set('Writing Permissions Issue'); return; } // read config.xml and search for epan-system variables $xml = simplexml_load_string($config_file_data); $json = json_encode($xml); $config_array = json_decode($json, TRUE); // set error if not found -- not proper xml if ($config_array['namespace'] == "") { $this->add('View_Error')->set('namespace not defined'); return; } // check entry in marketplace if this namespace is already used $marketplace = $this->add('Model_MarketPlace'); $marketplace->tryLoadBy('namespace', $config_array['namespace']); if ($marketplace->loaded()) { if ($_POST['replace_existing']) { // Remove Existing entries $marketplace->ref('Tools')->deleteAll(); $marketplace->ref('Plugins')->deleteAll(); $marketplace->ref('InstalledComponents')->deleteAll(); // $marketplace->delete(); } else { $this->add('View_Error')->set('This namespace is already used and application is installed.'); return; } } // add entry to marketplace table (Model) // throw $this->exception('<pre>'.print_r($config_array,true).'</pre>', 'ValidityCheck')->setField('FieldName'); // $marketplace=$this->add( 'Model_MarketPlace' ); $marketplace['name'] = $config_array['name']; $marketplace['namespace'] = $config_array['namespace']; $marketplace['type'] = $config_array['type']; $marketplace['is_system'] = $config_array['is_system']; $marketplace['description'] = $config_array['description']; $marketplace['default_enabled'] = $config_array['default_enabled']; $marketplace['has_toolbar_tools'] = $config_array['has_toolbar_tools']; $marketplace['has_owner_modules'] = $config_array['has_owner_modules']; $marketplace['has_plugins'] = $config_array['has_plugins']; $marketplace['has_live_edit_app_page'] = $config_array['has_live_edit_app_page']; $marketplace['allowed_children'] = $config_array['allowed_children']; $marketplace['specific_to'] = $config_array['specific_to']; $marketplace['initialize_and_clone_from_git'] = $config_array['initialize_and_clone_from_git']; $marketplace['git_path'] = is_array($config_array['git_path']) ? '' : $config_array['git_path']; $marketplace->isInstalling = true; $marketplace->save(); foreach ($config_array['Tools'] as $tools) { if (is_array($tools[0])) { foreach ($tools as $tool_2) { $tool = $this->add('Model_Tools'); $tool['component_id'] = $marketplace->id; $tool['name'] = $tool_2['name']; $tool['display_name'] = is_array($tool_2['display_name']) ? '' : $tool_2['display_name']; $tool['order'] = is_array($tool_2['order']) ? '' : $tool_2['order']; $tool['is_serverside'] = $tool_2['is_serverside']; $tool['is_resizable'] = $tool_2['is_resizable']; $tool['is_sortable'] = $tool_2['is_sortable']; $tool->isInstalling = true; $tool->save(); } break; } else { $tool = $this->add('Model_Tools'); $tool['component_id'] = $marketplace->id; $tool['name'] = $tools['name']; $tool['display_name'] = is_array($tools['display_name']) ? '' : $tools['display_name']; $tool['order'] = is_array($tools['order']) ? '' : $tools['order']; $tool['is_serverside'] = $tools['is_serverside']; $tool['is_resizable'] = $tools['is_resizable']; $tool['is_sortable'] = $tools['is_sortable']; $tool->isInstalling = true; $tool->save(); } } foreach ($config_array['Plugins'] as $plg) { if (is_array($plg[0])) { foreach ($plg as $plg_2) { $plg_m = $this->add('Model_Plugins'); $plg_m['component_id'] = $marketplace->id; $plg_m['name'] = $plg_2['name']; $plg_m['event'] = $plg_2['event']; $plg_m['params'] = $plg_2['params']; $plg_m['is_system'] = $plg_2['is_system']; $plg_m->isInstalling = true; $plg_m->save(); } break; } else { $plg_m = $this->add('Model_Plugins'); $plg_m['component_id'] = $marketplace->id; $plg_m['name'] = $plg['name']; $plg_m['event'] = $plg['event']; $plg_m['params'] = $plg['params']; $plg_m['is_system'] = $plg['is_system']; $plg_m->isInstalling = true; $plg_m->save(); } } // extract uploaded zip file to epan-components if (!$zip->extractZip($_FILES['component_file']['tmp_name'], getcwd() . DIRECTORY_SEPERATOR . 'epan-components' . DIRECTORY_SEPERATOR . $config_array['namespace'])) { return "Couldn't Extract"; } if ($_POST['replace_existing']) { $this->api->redirect($marketplace['namespace'] . '_page_owner_update'); } // TODO Execute install.sql file IF EXISTS if (file_exists(getcwd() . DIRECTORY_SEPERATOR . 'epan-components' . DIRECTORY_SEPERATOR . $config_array['namespace'] . DS . 'install.sql')) { $sql = file_get_contents(getcwd() . DIRECTORY_SEPERATOR . 'epan-components' . DIRECTORY_SEPERATOR . $config_array['namespace'] . DS . 'install.sql'); $this->api->db->dsql($this->api->db->dsql()->expr($sql))->execute(); } // TODO or execute addcomponentpage etc like removecomponent } } } }
function createPackage($bypasszip = false) { // Make Db Backup (xml config file ) file $xml = new SimpleXMLElement('<xml/>'); $xml->addChild('name', $this['name']); $xml->addChild('namespace', $this['namespace']); $xml->addChild('type', $this['type']); $xml->addChild('allowed_children', $this['allowed_children'] ?: 0); $xml->addChild('specific_to', $this['specific_to'] ?: 0); $xml->addChild('is_system', $this['is_system']); $xml->addChild('description', $this['description'] ?: 0); $xml->addChild('default_enabled', $this['default_enabled']); $xml->addChild('has_toolbar_tools', $this['has_toolbar_tools']); $xml->addChild('has_owner_modules', $this['has_owner_modules']); $xml->addChild('has_live_edit_app_page', $this['has_live_edit_app_page']); $xml->addChild('git_path', $this['git_path'] ?: 0); $xml->addChild('initialize_and_clone_from_git', $this['initialize_and_clone_from_git']); $tools_node = $xml->addChild('Tools'); foreach ($tools = $this->ref('Tools') as $tools_array) { $tool_node = $tools_node->addChild('Tool'); $tool_node->addChild('name', $tools['name']); $tool_node->addChild('display_name', $tools['display_name']); $tool_node->addChild('order', $tools['order']); $tool_node->addChild('is_serverside', $tools['is_serverside']); $tool_node->addChild('is_resizable', $tools['is_resizable']); $tool_node->addChild('is_sortable', $tools['is_sortable']); } $plugins_node = $xml->addChild('Plugins'); foreach ($plugins = $this->ref('Plugins') as $plugin_array) { $plugin_node = $plugins_node->addChild('Plugin'); $plugin_node->addChild('name', $plugins['name']); $plugin_node->addChild('event', $plugins['event']); $plugin_node->addChild('params', $plugins['params']); $plugin_node->addChild('is_system', $plugins['is_system']); } file_put_contents(getcwd() . DS . 'epan-components' . DS . $this['namespace'] . DS . 'config.xml', $xml->asXML()); if (!$bypasszip) { // Zip file $component_zip = new zip(); if (file_exists(getcwd() . DS . 'epan-components' . DS . $this['namespace'] . DS . $this['namespace'] . '.zip')) { unlink(getcwd() . DS . 'epan-components' . DS . $this['namespace'] . DS . $this['namespace'] . '.zip'); } $component_zip->makeZip(getcwd() . DS . 'epan-components' . DS . $this['namespace'] . DS . '/.', getcwd() . DS . 'epan-components' . DS . $this['namespace'] . DS . $this['namespace'] . '.zip'); // Download file // delete created zip file } }
require_once dirname(__FILE__) . "/../include/oxwindow.class.php"; if (empty($action)) { $action = ''; } $mdir = DEDEDATA . '/module'; if ($action == 'upload') { if (!is_uploaded_file($upfile)) { ShowMsg("貌似你什么都没有上传哦!", "javascript:;"); exit; } else { include_once dirname(__FILE__) . "/../include/zip.class.php"; $tmpfilename = $mdir . '/' . ExecTime() . mt_rand(10000, 50000) . '.tmp'; move_uploaded_file($upfile, $tmpfilename) or die("把上传的文件移动到{$tmpfilename}时失败,请检查{$mdir}目录是否有写入权限!"); //ZIP格式的文件 if ($filetype == 1) { $z = new zip(); $files = $z->get_List($tmpfilename); $dedefileindex = -1; //为了节省资源,系统仅以.xml作为扩展名识别ZIP包里了dede模块格式文件 if (is_array($files)) { for ($i = 0; $i < count($files); $i++) { if (preg_match("#\\.xml#i", $files[$i]['filename'])) { $dedefile = $files[$i]['filename']; $dedefileindex = $i; break; } } } if ($dedefileindex == -1) { unlink($tmpfilename); ShowMsg("对不起,你上传的压缩包中不存在dede模块文件!<br /><br /><a href='javascript:history.go(-1);'>>>返回重新上传>></a>", "javascript:;");
function onimport() { set_time_limit(0); if (substr(trim(ini_get('memory_limit')), 0, -1) < 32 && substr(trim(ini_get('memory_limit')), 0, -1) > 0) { @ini_set('memory_limit', '32M'); } $filename = str_replace('*', '.', $this->get[2]); $filenum = $this->get[3] ? $this->get[3] : 1; $filedir = "./data/db_backup/"; $filetype = $this->get[4] ? $this->get[4] : substr($filename, -3); if ($filetype != 'zip' && $filetype != 'sql') { $this->message('文件格式不正确', 'BACK'); } else { if ($filenum == 1) { if ($filetype == 'zip') { require_once TIPASK_ROOT . '/lib/zip.class.php'; $zip = new zip(); if (!$zip->chk_zip) { $this->message('chkziperror', ''); } $zip->Extract($filedir . $filename, $filedir); $filename = substr($filename, 0, -4) . "_1.sql"; } else { $num = strrpos($filename, "_"); $filename = substr($filename, 0, $num) . "_1.sql"; } } if (file_exists($filedir . $filename)) { $sqldump = readfromfile($filedir . $filename); preg_match('/#\\sVersion:\\sTipask\\s([^\\n]+)\\n/i', $sqldump, $tversion); if ($tversion[1] != TIPASK_VERSION) { $this->message('导入的备份数据文件版本不正确', 'admin_db/backup'); } $sqlquery = $_ENV['db']->splitsql($sqldump); unset($sqldump); foreach ($sqlquery as $sql) { $sql = $_ENV['db']->syntablestruct(trim($sql), $this->db->version() > '4.1', DB_CHARSET); if ($sql != '') { $this->db->query($sql, 'SILENT'); if (($sqlerror = $this->db->error()) && $this->db->errno() != 1062) { $this->db->halt('MySQL Query Error', $sql); } } } if ($filetype == 'zip') { @unlink($filedir . $filename); } $filenum++; $num = strrpos($filename, "_"); $filename = str_replace('.', '*', substr($filename, 0, $num) . "_" . $filenum . ".sql"); $this->message("<image src='css/default/loading.gif'><br />" . '第 ' . ($filenum - 1) . ' 个文件已经完成!正在进入下一个备份!', "admin_db/import/{$filename}/{$filenum}/{$filetype}"); } else { $this->cache->remove('import_files'); $this->message('导入数据成功!', 'admin_db/backup'); } } }
function export_skin() { if (!isset($this->post['skin'])) { $skin_box = $this->htmlwidgets->select_skins($this->skin); return $this->message($this->lang->export_skin, "\n\t\t\t{$this->lang->export_select}:<br /><br />\n\t\t\t<form action='{$this->self}?a=templates&s=export' method='post'><div>\n\t\t\t\t<select name='skin'>\n\t\t\t\t\t{$skin_box}\n\t\t\t\t</select>\n\t\t\t\t<input type='submit' value='{$this->lang->export_skin}' /></div>\n\t\t\t</form>"); } else { $templates = $this->dump_database(array('templates' => "template_skin='{$this->post['skin']}'")); $skin = $this->db->fetch("SELECT * FROM {$this->pre}skins WHERE skin_dir='{$this->post['skin']}'"); $info = "<?php\n\$skin['name'] = \"" . addslashes($skin['skin_name']) . "\";\n\$skin['dir'] = \"" . addslashes($skin['skin_dir']) . "\";\n?>"; if (file_exists("../skins/{$this->post['skin']}/info.php")) { unlink("../skins/{$this->post['skin']}/info.php"); } if (file_exists("../skins/{$this->post['skin']}/templates.php")) { unlink("../skins/{$this->post['skin']}/templates.php"); } include '../lib/zip.php'; $this->chmod('../skins', 0777); $zip = new zip(); $zip->add("../skins/{$this->post['skin']}"); $zip->add_file($info, 'info.php'); $zip->add_file($templates, 'templates.php'); $zip->write_zip("../skins/{$this->post['skin']}.mbs"); return $this->message($this->lang->export_skin, $this->lang->export_done, "{$this->post['skin']}.mbs", "../skins/{$this->post['skin']}.mbs"); } }
function loadModulFile() { if (is_uploaded_file($_FILES['modul_file_zip']["tmp_name"])) { if (preg_match('/\\.(zip)$/i', $_FILES['modul_file_zip']['name'])) { require_once 'classes/unzip_class.php'; $zip = new zip(); $zip->unzip($_FILES['modul_file_zip']["tmp_name"], "moduls/", $create_zip_name_dir = true, $overwrite = true); } else { throw new Exception("Musite nahravat zip subor"); } } }
require_once '../../kernel/begin.php'; require_once 'panel_admin.inc.php'; $types = array('lang', 'module', 'design'); $dirs = array('lang', 'modules', 'designs'); $fhs = $formulaires = array(); foreach ($types as $k => $val) { $formulaires[$val] = new Form(translate('file_upload'), 'post', '', true); $formulaires[$val]->add_fieldset(); $formulaires[$val]->add_input('file_' . $val, 'file_' . $val, translate('file_form'), 'file', 'file'); $formulaires[$val]->add_button(); $fhs[$val] = new FormHandle($formulaires[$val]); $fhs[$val]->handle(); if ($fhs[$val]->okay()) { $file = $fhs[$val]->get('file_' . $val); load('core/zip'); $zip = new zip($file); if ($zip->extract(ROOT . 'cache/tmp/' . $dirs[$k] . '/')) { $nameZip = $_FILES['file_' . $val]['name']; if (is_dir(ROOT . $dirs[$k] . '/' . $nameZip)) { $error = new Error(); $error->add_error(translate('file_already_exists'), ERROR_PAGE, __FILE__, __LINE__); } else { if (($dirDbFile = ROOT . 'cache/tmp/' . $dirs[$k] . '/' . $nameZip . 'db/db.sql') && is_file($dirDbFile)) { $bdd->extract_files($dirDbFile); } #rm( ROOT . 'cache/tmp/' . $dirs[$k] . '/' . $nameZip . 'db/' ); rename(ROOT . 'cache/tmp/' . $dirs[$k] . '/' . $nameZip, ROOT . $dirs[$k] . '/' . $nameZip); rm(ROOT . 'cache/tmp/' . $dirs[$k] . '/' . $nameZip); $error = new Error(); $error->add_error(translate('file_success'), ERROR_PAGE, __FILE__, __LINE__); }
function unzip($filename) { global $up_place, $path, $id_rep, $charset, $base_path; $zip = new zip($filename); $zip->readZip(); $cpt = 0; if ($up_place && $path != '') { $up = new upload_folder($id_rep); } if (is_array($zip->entries) && count($zip->entries)) { foreach ($zip->entries as $file) { $encod = mb_detect_encoding($file['fileName'], "UTF-8,ISO-8859-1"); if ($encod && $encod == 'UTF-8' && $charset == "iso-8859-1") { $file['fileName'] = utf8_decode($file['fileName']); } elseif ($encod && $encod == 'ISO-8859-1' && $charset == "utf-8") { $file['fileName'] = utf8_encode($file['fileName']); } if ($up_place && $path != '') { $chemin = $path; if ($up->isHashing()) { $hashname = $up->hachage($file['fileName']); @mkdir($hashname); $filepath = $up->encoder_chaine($hashname . $file['fileName']); } else { $filepath = $up->encoder_chaine($up->formate_nom_to_path($chemin) . $file['fileName']); } //On regarde si le fichier existe avant de le créer $continue = true; $compte = 0; $filepath_tmp = $filepath; do { if (!file_exists($filepath_tmp)) { $continue = false; } else { $compte++; if (preg_match("/^(.+)(\\..+)\$/i", $filepath, $matches)) { $filepath_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $filepath_tmp = $filepath . "_" . $compte; } } } while ($continue); if ($compte) { $filepath = $filepath_tmp; } $fh = fopen($filepath, 'w+'); fwrite($fh, $zip->getFileContent($file['fileName'])); fclose($fh); if ($compte) { if (preg_match("/^(.+)(\\..+)\$/i", $file['fileName'], $matches)) { $file['fileName'] = $matches[1] . "_" . $compte . $matches[2]; } else { $file['fileName'] = $file['fileName'] . "_" . $compte; } } } else { $chemin = $base_path . '/temp/' . $file['fileName']; $fh = fopen($chemin, 'w'); fwrite($fh, $zip->getFileContent($file['fileName'])); $base = true; } $this->unzipped_files[$cpt]['chemin'] = $chemin; $this->unzipped_files[$cpt]['nom'] = $file['fileName']; $this->unzipped_files[$cpt]['base'] = $base; $cpt++; } } }
$floderName = UPDATE_FNAME_CODING; break; default: $c = new wcurl(UPDATE_SERVER_GITHUB); $floderName = UPDATE_FNAME_GITHUB; break; } $file = $c->exec(); $c->close(); $zipPath = UPDATE_CACHE . 'update_' . time() . '.zip'; if (file_put_contents($zipPath, $file) === false) { DeleteFile(UPDATE_CACHE); msg('错误 - 更新失败:<br/><br/>无法从更新服务器下载更新包'); } //解压缩 $z = new zip(); $z->open($zipPath); $z->extract(UPDATE_CACHE); $z->close(); //检查更新文件 $floderName = UPDATE_CACHE . $floderName; if (!is_dir($floderName)) { DeleteFile(UPDATE_CACHE); msg('错误 - 更新失败:<br/><br/>无法解压缩更新包'); } //删除配置文件 if (file_exists($floderName . '/config.php')) { unlink($floderName . '/config.php'); } if (file_exists($floderName . '/app.conf')) { unlink($floderName . '/app.conf');
function share_plugin($plugin) { $identifier = $plugin['identifier']; $descxml = "<?xml version=\"1.0\" encoding=\"" . WIKI_CHARSET . "\"?>\n" . "<theme>\n" . "<author><![CDATA[" . $plugin['author'] . "]]></author>\n" . "<authorurl><![CDATA[" . $plugin['authorurl'] . "]]></authorurl>\n" . "<name><![CDATA[" . $plugin['name'] . "]]></name>\n" . "<tag><![CDATA[" . $plugin['tag'] . "]]></tag>\n" . "<desc><![CDATA[" . $plugin['description'] . "]]></desc>\n" . "<weburl><![CDATA[" . $plugin['weburl'] . "]]></weburl>\n" . "<version><![CDATA[" . $plugin['version'] . "]]></version>\n" . "<hdversion><![CDATA[" . $plugin['hdversion'] . "]]></hdversion>\n" . "<copyright><![CDATA[" . $plugin['copyright'] . "]]></copyright>\n" . "<charset><![CDATA[" . WIKI_CHARSET . "]]></charset>\n" . "</theme>"; file::writetofile(HDWIKI_ROOT . '/plugins/' . $identifier . '/desc.xml', $descxml); require_once HDWIKI_ROOT . '/lib/zip.class.php'; $zip = new zip(); $filedir = array('plugins/' . $identifier); $zipdir = array($identifier); $tmpname = HDWIKI_ROOT . '/data/tmp/' . util::random(6) . '.zip'; @$zip->zip_dir($filedir, $tmpname, $zipdir); $zip_content = file::readfromfile($tmpname); $upload_url = $this->base->setting['app_url'] . '/hdapp.php?action=upload&type=plugin'; $data = 'data=' . base64_encode($zip_content); if ('1' == @util::hfopen($upload_url, 0, $data)) { unlink($tmpname); return true; } return false; }