public function removeConfigFile() { if (!$this->file || !file_exists($this->file)) { return false; } if ($this->archiver != null) { } else { if ($this->checkZipConsole()) { //todo: implement } else { if ($this->checkZipSupport()) { $zip = new ZipArchive(); $zipRes = $zip->open($this->file); if ($zipRes) { $zip->deleteName('wp-config.php'); $zip->deleteName('clone'); $zip->close(); return true; } return false; } else { //use pclzip $zip = new PclZip($this->file); $list = $zip->delete(PCLZIP_OPT_BY_NAME, 'wp-config.php'); $list2 = $zip->delete(PCLZIP_OPT_BY_NAME, 'clone'); if ($list == 0) { return false; } return true; } } } return false; }
/** * Extracts the current ZIP package. * * @param string $file Full path to the ZIP package * @return bool True on success */ protected function _unzip($file) { include_once Plugin::classPath('Installer') . 'Lib/pclzip.lib.php'; $File = new File($file); $to = normalizePath($File->folder()->pwd() . '/' . $File->name() . '_unzip/'); if (is_readable($to)) { $folder = new Folder($to); $folder->delete(); } else { $folder = new Folder($to, true); } $PclZip = new \PclZip($file); $PclZip->delete(PCLZIP_OPT_BY_EREG, '/__MACOSX/'); $PclZip->delete(PCLZIP_OPT_BY_EREG, '/\\.DS_Store$/'); if ($PclZip->extract(PCLZIP_OPT_PATH, $to)) { list($directories, $files) = $folder->read(false, false, true); if (count($directories) === 1 && empty($files)) { $container = new Folder($directories[0]); $container->move(['to' => $to]); } $this->_workingDir = $to; return true; } $this->err(__d('installer', 'Unzip error: {0}', [$PclZip->errorInfo(true)])); return false; }
function jarCreate($jarName, $id, $product, $ver, $par_song) { trigger_error("jarCreate({$jarName}, {$id}, {$product}, {$ver}, {$par_song})", E_USER_NOTICE); $id_producttype = null; if (isset($product['product']['id_producttype'])) { $id_producttype = $product['product']['id_producttype']; } // tworze archiwum //delete($jarName); // kasowanie plik if (file_exists($jarName)) { unlink($jarName); } $archive = new PclZip($jarName); if ($archive == 0) { trigger_error("Error (new PclZip): " . $archive->errorInfo(true), E_USER_ERROR); } $products_dir = MOBIKAR_PRODUCTS_DIR; $pack_dir = $products_dir . $id_producttype . "/" . $ver . "/"; trigger_error("pack_dir: {$pack_dir}", E_USER_NOTICE); $v_list = $archive->add($pack_dir, PCLZIP_OPT_ADD_PATH, "./", PCLZIP_OPT_REMOVE_PATH, $pack_dir); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } $songs = null; if (isset($product['songs'])) { $songs = $product['songs']; } $i = -1; foreach ($songs as $song) { $i++; $songId = null; if (isset($song['id'])) { $songId = $song['id']; } $song_file = MOBIKAR_TEMPORARY_DIR . "{$i}.midi"; trigger_error("copy({$products_dir}.songs/{$songId}.{$par_song}, {$song_file});" . $archive->errorInfo(true), E_USER_ERROR); copy($products_dir . "songs/{$songId}.{$par_song}", $song_file); $v_list = $archive->add($song_file, PCLZIP_OPT_ADD_PATH, "song", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } $song_file = MOBIKAR_TEMPORARY_DIR . "{$i}.mlyr"; copy($products_dir . "songs/{$songId}.{$par_song}.mlyr", $song_file); $v_list = $archive->add($song_file, PCLZIP_OPT_ADD_PATH, "song", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } } // zmiana nazwy w manifeście $list = $archive->extract(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF", PCLZIP_OPT_EXTRACT_AS_STRING); if ($list == 0) { trigger_error("ERROR : " . $archive->errorInfo(true)); } $manifest = $list[0]['content']; $manifest = str_replace("MIDlet-Name: mobiKAR", "MIDlet-Name: mobiKAR_" . $id, $manifest); $file = fopen(MOBIKAR_TEMPORARY_DIR . "MANIFEST.MF", "wb"); fwrite($file, $manifest); fclose($file); // usuwamy w archiwum starego manifesta $v_list = $archive->delete(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF"); if ($v_list == 0) { trigger_error("Error : " . $archive->errorInfo(true)); } // wgrywany do archiwum nowego Manifesta $v_list = $archive->add(PCLZIP_TEMPORARY_DIR . "MANIFEST.MF", PCLZIP_OPT_ADD_PATH, "META-INF", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } // wysyłka w odpowiedzi manifesta return $manifest; //print_r($pack_dir); }
function SaveXmlToDoc() { // get the source result $this->Show(TBS_NOTHING); // store the merge result in place of the XML source file $fdw = fopen($this->_ooo_basename.'/'.$this->_xml_filename, "w"); fwrite($fdw, $this->Source); fclose ($fdw); // test if XML file exist if (!file_exists($this->_ooo_basename.'/'.$this->_xml_filename)) { $this->meth_Misc_Alert('SaveXmlToDoc method', 'File not found : '.$this->_ooo_basename.'/'.$this->_xml_filename); return false; } // zip and remove the file //ERIC //exec($this->_zip_bin.' -j -m '.$this->_ooo_basename.'.'.$this->_ooo_file_ext.' '.$this->_ooo_basename.'/'.$this->_xml_filename); $this->_nom_fic_archive = $this->_ooo_basename.'.'.$this->_ooo_file_ext; //le nom du fichier ODF (copie unique ID) $archive = new PclZip($this->_ooo_basename.'.'.$this->_ooo_file_ext); // il faut supprimer le fichier dans l'archive. Un add n'�crase pas le fichier !! $v_list = $archive->delete(PCLZIP_OPT_BY_NAME, $this->_xml_filename); //on supprime content.xml if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } $v_list = $archive->add($this->_ooo_basename.'/'.$this->_xml_filename, //on ajoute le fichier content.xml PCLZIP_OPT_ADD_PATH, '', //on remplace le chemin par rien PCLZIP_OPT_REMOVE_PATH, $this->_ooo_basename ); //on ne met pas le dossier dans l'archive if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } return true; }
public function actionImportUpload() { $model = new $this->modelName(); $session = Yii::app()->session; $modelUsers = new User('search'); $modelUsers->resetScope(); $modelUsers->active(); $modelUsers->unsetAttributes(); // clear any default values if (isset($_GET['User'])) { $modelUsers->attributes = $_GET['User']; } if (!isset($_FILES[$this->modelName]) && isset($session['importAds']) && $session['importAds']) { $itemsProvider = new CArrayDataProvider($session['importAds'], array('sort' => array('attributes' => array('title')), 'pagination' => array('pageSize' => count($session['importAds'])))); $this->render('view_import_grid', compact('itemsProvider', 'model', 'modelUsers')); } else { if (isset($_FILES[$this->modelName]) && isset($_FILES[$this->modelName]['name'])) { $model->import = CUploadedFile::getInstance($model, 'import'); if ($model->validate()) { $fileExt = $model->import->extensionName; $fileName = date('Y_m_d_s') . rand(0, 9) . '_import.' . $fileExt; $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; $model->import->saveAs($filePath); $isZip = false; // if zip arhive if ($fileExt == 'zip') { $isZip = true; include_once $model->libraryPath . DIRECTORY_SEPARATOR . 'pclzip.lib.php'; $archive = new PclZip($filePath); $list = $archive->extract(PCLZIP_OPT_PATH, $model->csvPath, PCLZIP_OPT_SET_CHMOD, 0777, PCLZIP_OPT_REMOVE_ALL_PATH); $v_list = $archive->delete(); /* if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } */ foreach ($list as $item) { if (strpos($item["stored_filename"], ".csv")) { if ($item["stored_filename"] != $fileName) { $fileNameCSV = str_replace(".zip", ".csv", $fileName); if (copy($model->csvPath . DIRECTORY_SEPARATOR . $item["stored_filename"], $model->csvPath . DIRECTORY_SEPARATOR . $fileNameCSV)) { @unlink($model->csvPath . DIRECTORY_SEPARATOR . $item["stored_filename"]); } else { Yii::app()->user->setFlash('error', tt('Error copying file. Please try again later and set 0777 for ' . $model->csvPath)); $this->redirect('viewImport'); } @unlink($model->csvPath . DIRECTORY_SEPARATOR . $item["stored_filename"]); @unlink($model->csvPath . DIRECTORY_SEPARATOR . $fileName); $fileName = $fileNameCSV; $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; } break; } } } $import = $rowData = array(); //parse csv file @setlocale(LC_ALL, 'en_US.utf8'); if (($handle = fopen($filePath, "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ";")) !== FALSE) { $import[] = $data; } fclose($handle); $keys = $import[0]; // remove BOM from file $bom = pack('H*', 'EFBBBF'); $keys[0] = preg_replace("/^{$bom}/", '', $keys[0]); unset($import[0]); $j = 1; foreach ($import as $key => $items) { if (count($keys) == count($items)) { $import[$key] = array_combine($keys, $items); $import[$key]["id"] = $j; $j++; } else { continue; } } // insert result into session $session['importAds'] = $import; $session['isZip'] = $isZip; } $itemsProvider = new CArrayDataProvider($import, array('sort' => array('attributes' => array('title')), 'pagination' => array('pageSize' => count($import)))); $this->render('view_import_grid', compact('itemsProvider', 'model', 'modelUsers')); } else { Yii::app()->user->setFlash('error', Yii::t('module_iecsv', 'Please select a *.csv or *.zip file for import. Max size of file is {size}.', array('{size}' => $model->fileMaxSizeMessage))); $this->redirect('viewImport'); } } else { $this->redirect('viewImport'); } } }
function embbedLoader($method, $zipFile, $subZipFile, $outDir) { global $my, $mainframe, $digistor_enc_plugins, $mosConfig_absolute_path; $handler = $this->getEncoder($method); if ($handler == -1) { return -2; } //no handler found - internal error or hijack attempt $loaderFile = $handler->getLoader(); //insert the license file into the zip file include_once $mosConfig_absolute_path . "/administrator/includes/pcl/pclzip.lib.php"; $curdir = getcwd(); chdir($outDir); $srcZip = new PclZip($zipFile); if ($srcZip->extract(PCLZIP_OPT_BY_NAME, $subZipFile) == 0) { die($srcZip->errorInfo(true)); } $subZip = new PclZip($subZipFile); $subZip->add($loaderFile); $srcZip->delete(PCLZIP_OPT_BY_NAME, $subZipFile); $res = $srcZip->add($subZipFile); if ($res == 0) { $srcZip->create($subZipFile); } @unlink($subZipFile); @unlink($loaderFile); //done chdir($curdir); }
/** * Функция установки обновления * @param string $file - путь к архиву обновления * @return bool */ static function setupUpdate($file) { // проверяем файл if (!file_exists($file)) { self::$errorMessage = ERROR_UPDATES_UPDATE_FILE_NOT_FOUND; return false; } // создаем объект $zip = new PclZip($file); // получаем текст из файла обновления (для частичного обновления файлов) // если он есть // извлекаем файлы self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Try get data from update.xml', 'object' => $file)); self::saveLogData(); if ($update = $zip->extract(PCLZIP_OPT_BY_NAME, 'update.xml', PCLZIP_OPT_EXTRACT_AS_STRING)) { // создаем объект SimpleXML, со свойствами файла $xml = new SimpleXMLElement($update[0]['content'], LIBXML_NOCDATA); // делаем обход по объекту, и выполянем необходимые действия foreach ($xml->children() as $child) { // обновление PHP файлов if ($child->getName() == 'php') { self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Update PHP files (PHP-node in XML)', 'object' => 'PHP')); self::saveLogData(); // делаем обход по текущему узлу XML-файла foreach ($child->children() as $children) { // формируем из свойств объекта массив $params = get_object_vars($children); // проверяем, с чем необходимо работать if ($children->getName() == 'expconst') { self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Update constant file (action: ' . $params['action'] . '; string: ' . $params['string'] . '; value: ' . $params['value'] . ')', 'object' => $params['file'])); self::saveLogData(); // если запрос не удался, логируем ошибку if (!self::updateConstFile($params)) { self::setLogData(array('error' => 1, 'message' => self::$errorMessage, 'object' => $params['file'], 'data' => $params)); } else { self::setLogData(array('error' => 0, 'message' => 'Success updated', 'object' => $params['file'], 'data' => $params)); } self::saveLogData(); } elseif ($children->getName() == 'exparray') { global ${$params['subj']}; // так сделано из-за того, что возникают проблемы с объектами SimpleXMLElement // которые попадают в сериализованные данные. Это актуально только для обновления массивов // т.к. там есть вложеность узлов. // В дальнейшем можно сделать рекурсивную функцию для обработки таких объектов // Сейчас не охота такого делать $setParams = array('action' => $params['action'], 'file' => $params['file'], 'subj' => $params['subj']); self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Update array file (action: ' . $params['action'] . '; file: ' . $params['file'] . '; subj: ' . $params['subj'] . ')', 'object' => $params['file'])); self::saveLogData(); // если запрос не удался, логируем ошибку if (!self::updateArrFile($children, ${$params['subj']})) { self::setLogData(array('error' => 1, 'message' => self::$errorMessage, 'object' => $params['file'], 'data' => $setParams)); } else { self::setLogData(array('error' => 0, 'message' => 'Success updated', 'object' => $params['file'], 'data' => $setParams)); } self::saveLogData(); } elseif ($children->getName() == 'expfile') { self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Add text to file (action: ' . $params['action'] . '; string: ' . $params['string'] . ')', 'object' => $params['file'])); self::saveLogData(); // если запрос не удался, логируем ошибку if (!self::updateTextInFile($children)) { self::setLogData(array('error' => 1, 'message' => self::$errorMessage, 'object' => $params['file'], 'data' => $params)); } else { self::setLogData(array('error' => 0, 'message' => 'Success updated', 'object' => $params['file'], 'data' => $params)); } self::saveLogData(); } } } elseif ($child->getName() == 'sql') { self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Update DataBase (SQL-node in XML)', 'object' => 'SQL')); self::saveLogData(); // делаем обход по текущему узлу XML-файла foreach ($child->children() as $children) { $params = get_object_vars($children); self::clearLogData(); self::setLogData(array('error' => 2, 'message' => !empty($params['query']) ? $params['query'] : 'Not query', 'object' => $params['table'] . '; action: ' . $params['action'] . (!empty($params['field']) ? '; field: ' . $params['field'] : ''))); self::saveLogData(); if (self::updateDB($children)) { self::setLogData(array('error' => 0, 'message' => 'Success updated', 'object' => $params['table'], 'data' => $params)); } else { self::setLogData(array('error' => 1, 'message' => self::$errorMessage, 'object' => $params['table'], 'data' => $params)); } self::saveLogData(); } } elseif ($child->getName() == 'delfiles') { self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Delete files', 'object' => 'delfiles')); self::saveLogData(); // делаем обход по текущему узлу XML-файла foreach ($child->children() as $children) { $params = get_object_vars($children); self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Try delete file', 'object' => $params['expfname'])); self::saveLogData(); if (file_exists($params['expfname'])) { if (!unlink($params['expfname'])) { self::setLogData(array('error' => 1, 'message' => 'Unable delete file', 'object' => $params['expfname'])); } else { self::setLogData(array('error' => 0, 'message' => 'File success deleted', 'object' => $params['expfname'])); } self::saveLogData(); } else { self::clearLogData(); self::setLogData(array('error' => 0, 'message' => 'File not exists', 'object' => $params['expfname'])); self::saveLogData(); } } } elseif ($child->getName() == 'deldirs') { // делаем обход по текущему узлу XML-файла self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Delte dirs', 'object' => 'deldirs')); self::saveLogData(); foreach ($child->children() as $children) { $params = get_object_vars($children); self::clearLogData(); self::setLogData(array('error' => 2, 'message' => 'Try delete dir', 'object' => $params['expfname'])); self::saveLogData(); if (file_exists($params['expfname'])) { if (!filesys::removeDir($params['expfname'])) { self::setLogData(array('error' => 1, 'message' => 'Unable delete dir', 'object' => $params['expfname'])); } else { self::setLogData(array('error' => 2, 'message' => 'Dir success deleted', 'object' => $params['expfname'])); } self::saveLogData(); } else { self::clearLogData(); self::setLogData(array('error' => 0, 'message' => 'Dir not exists', 'object' => $params['expfname'])); self::saveLogData(); } } } } // записываем ошибки в лог self::saveLogData(); // удаляем файл из архива $zip->delete(PCLZIP_OPT_BY_NAME, 'update.xml'); self::$message = MESSAGE_UPDATES_UPDATE_DB_SUCCESS; return true; // распаковываем архив //return self::extractUpdate($file); } else { // если этого файла нет, то просто копируем файлы из архива self::clearLogData(); self::setLogData(array('error' => 0, 'message' => 'File update.xml not exists (not required partial update)', 'object' => $file)); self::saveLogData(); self::$message = MESSAGE_UPDATES_UPDATE_DB_NOT_REQUIRED; return true; //return self::extractUpdate($file); } }
/** * createMidlet tworzy w miejscu wskazywanym przez midletFileName dwa pliki: jad i jar * zawierających nazwy plików piosenek zawartych w tablicy arrSongFiles * Nazwy plików mają by rozszerzeń ".midi", ".mlyr". Rozszerzenia te zostaną automatycznie dodane * musicType przyjmuje wartości: "midi", "15k.midi", "mp3", ... * appType przyjmuje wartości: "midp20", "mmapi", "mot", "sam", "sie", ... * id_producttype przyjmuje wartosci 2 - singiel, 3 - paczka * */ function getJadFromCreatedJar($midletFileName, $midletName, $id_producttype, $appType, $musicType, $arrSongFiles) { //}, $jarName, $id, $product, $ver, $par_song) { trigger_error("createMidlet({$midletFileName}, {$midletName}, {$id_producttype}, {$appType}, {$musicType}, {$arrSongFiles})", E_USER_NOTICE); // tworze archiwum $jarName = $midletFileName . ".jar"; // kasowanie pliku if (file_exists($jarName)) { unlink($jarName); } $archive = new PclZip($jarName); if ($archive == 0) { trigger_error("Error (new PclZip): " . $archive->errorInfo(true), E_USER_ERROR); } $products_dir = MOBIKAR_PRODUCTS_DIR; $pack_dir = $products_dir . $id_producttype . "/" . $appType . "/"; trigger_error("pack_dir: {$pack_dir}", E_USER_NOTICE); $v_list = $archive->add($pack_dir, PCLZIP_OPT_ADD_PATH, "./", PCLZIP_OPT_REMOVE_PATH, $pack_dir); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } $i = -1; foreach ($arrSongFiles as $songFileName) { $i++; $songFileNameSource = $songFileName . '.' . $musicType; $songFileNameArchived = MOBIKAR_TEMPORARY_DIR . "{$i}.midi"; trigger_error("copy({$songFileNameSource}, {$songFileNameArchived});" . $archive->errorInfo(true), E_USER_ERROR); copy($songFileNameSource, $songFileNameArchived); $v_list = $archive->add($songFileNameArchived, PCLZIP_OPT_ADD_PATH, "song", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } $songFileNameSource = $songFileName . '.' . $musicType . ".mlyr"; $songFileNameArchived = MOBIKAR_TEMPORARY_DIR . "{$i}.mlyr"; trigger_error("copy({$songFileNameSource}, {$songFileNameArchived});" . $archive->errorInfo(true), E_USER_ERROR); copy($songFileNameSource, $songFileNameArchived); $v_list = $archive->add($songFileNameArchived, PCLZIP_OPT_ADD_PATH, "song", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } } // zmiana nazwy w manifeście $list = $archive->extract(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF", PCLZIP_OPT_EXTRACT_AS_STRING); if ($list == 0) { trigger_error("ERROR : " . $archive->errorInfo(true)); } $manifest = $list[0]['content']; if ($midletName != NULL) { $manifest = str_replace("MIDlet-Name: mobiKAR", "MIDlet-Name: " . $midletName, $manifest); $file = fopen(MOBIKAR_TEMPORARY_DIR . "MANIFEST.MF", "wb"); fwrite($file, $manifest); fclose($file); // usuwamy w archiwum starego manifesta $v_list = $archive->delete(PCLZIP_OPT_BY_NAME, "META-INF/MANIFEST.MF"); if ($v_list == 0) { trigger_error("Error : " . $archive->errorInfo(true)); } // wgrywany do archiwum nowego Manifesta $v_list = $archive->add(PCLZIP_TEMPORARY_DIR . "MANIFEST.MF", PCLZIP_OPT_ADD_PATH, "META-INF", PCLZIP_OPT_REMOVE_PATH, MOBIKAR_TEMPORARY_DIR); if ($v_list == 0) { trigger_error("Error (archive->add): " . $archive->errorInfo(true), E_USER_ERROR); } } return $manifest; //print_r($pack_dir); }
/** * Zipping whole site root folder and append to backup file with database dump * by PclZip library. * * @param string $task_name the name of backup task * @param string $backup_file absolute path to zip file * @param array $exclude array of files of folders to exclude, relative to site's root * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default) * * @return array|bool true if successful or an array with error message if not */ public function pclzip_backup($task_name, $backup_file, $exclude, $include) { define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/'); require_once ABSPATH . '/wp-admin/includes/class-pclzip.php'; /** @handled class */ $zip = new PclZip($backup_file); $add = array(trim(WPINC), trim(basename(WP_CONTENT_DIR)), 'wp-admin'); if (!file_exists(ABSPATH . 'wp-config.php') && file_exists(dirname(ABSPATH) . '/wp-config.php') && !file_exists(dirname(ABSPATH) . '/wp-settings.php')) { $include[] = '../wp-config.php'; } $path = wp_upload_dir(); $path = $path['path']; if (strpos($path, WP_CONTENT_DIR) === false && strpos($path, ABSPATH) === 0) { $add[] = ltrim(substr($path, strlen(ABSPATH)), ' /'); } $include_data = array(); if (!empty($include)) { foreach ($include as $data) { if ($data && file_exists(ABSPATH . $data)) { $include_data[] = ABSPATH . $data . '/'; } } } $include_data = array_merge($add, $include_data); if ($handle = opendir(ABSPATH)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) { $include_data[] = ABSPATH . $file; } } closedir($handle); } $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp']; if ($disable_comp) { $result = $zip->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_NO_COMPRESSION) !== 0; } else { $result = $zip->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH) !== 0; } $exclude_data = array(); if (!empty($exclude)) { foreach ($exclude as $data) { if (file_exists(ABSPATH . $data)) { if (is_dir(ABSPATH . $data)) { $exclude_data[] = $data . '/'; } else { $exclude_data[] = $data; } } } } $result = $result && $zip->delete(PCLZIP_OPT_BY_NAME, $exclude_data); return $result; }
/** * Zipping whole site root folder and append to backup file with database dump * by PclZip library. * * @param string $task_name the name of backup task * @param string $backup_file absolute path to zip file * @param array $exclude array of files of folders to exclude, relative to site's root * @param array $include array of folders from site root which are included to backup (wp-admin, wp-content, wp-includes are default) * @return array|bool true if successful or an array with error message if not */ function pclzip_backup($task_name, $backup_file, $exclude, $include) { define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/'); require_once ABSPATH . '/wp-admin/includes/class-pclzip.php'; $zip = new PclZip($backup_file); $add = array(trim(WPINC), trim(basename(WP_CONTENT_DIR)), "wp-admin"); $include_data = array(); if (!empty($include)) { foreach ($include as $data) { if ($data && file_exists(ABSPATH . $data)) { $include_data[] = ABSPATH . $data . '/'; } } } $include_data = array_merge($add, $include_data); if ($handle = opendir(ABSPATH)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) { $include_data[] = ABSPATH . $file; } } closedir($handle); } $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp']; if ($disable_comp) { $result = $zip->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_NO_COMPRESSION) !== 0; } else { $result = $zip->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH) !== 0; } $exclude_data = array(); if (!empty($exclude)) { foreach ($exclude as $data) { if (file_exists(ABSPATH . $data)) { if (is_dir(ABSPATH . $data)) { $exclude_data[] = $data . '/'; } else { $exclude_data[] = $data; } } } } $result = $result && $zip->delete(PCLZIP_OPT_BY_NAME, $exclude_data); return $result; }
function embbedLoader($method, $zipFile, $subZipFile, $outDir) { $handler = $this->getEncoder($method); if ($handler == -1) { return -2; } //no handler found - internal error or hijack attempt //die ("A"); $loaderFile = $handler->instance->getLoader(); //insert the license file into the zip file jimport("joomla.filesystem.file"); define('PCLZIP_TEMPORARY_DIR', JPATH_ROOT . DS . 'administrator/components/digicom_product_uploads/tmp/'); require_once JPATH_ROOT . DS . "administrator" . DS . "includes" . DS . "pcl" . DS . "pclzip.lib.php"; $curdir = getcwd(); chdir($outDir); echo $outDir; $srcZip = new PclZip($zipFile); if ($srcZip->extract(PCLZIP_OPT_BY_NAME, $subZipFile) == 0) { die($srcZip->errorInfo(true)); } $subZip = new PclZip($subZipFile); $subZip->add($loaderFile); $srcZip->delete(PCLZIP_OPT_BY_NAME, $subZipFile); $res = $srcZip->add($subZipFile); if ($res == 0) { $srcZip->create($subZipFile); } @unlink($subZipFile); @unlink($loaderFile); //done chdir($curdir); }
EOD; if ($fh = fopen($temp_dir . $temp_name . '/plugin_install.php', 'wb')) { fputs($fh, $file_install); fclose($fh); } else { $export_message = $export_message = sprintf($text_failed, $LANG['MOD_OPF']['TXT_WRITE_FAILED'], $temp_dir . $temp_name . '/plugin_install.php'); rm_full_dir($temp_dir . $temp_name); return FALSE; } if (!$archive->create($plugin_dir . $filter['plugin'], PCLZIP_OPT_REMOVE_PATH, $plugin_dir . $filter['plugin'])) { $export_message = sprintf($text_failed, $archive->errorInfo(true)); rm_full_dir($temp_dir . $temp_name); return FALSE; } if (!$archive->delete(PCLZIP_OPT_BY_NAME, 'plugin_install.php')) { $export_message = sprintf($text_failed, $archive->errorInfo(true)); rm_full_dir($temp_dir . $temp_name); return FALSE; } if (!$archive->add($temp_dir . $temp_name . '/plugin_install.php', PCLZIP_OPT_REMOVE_PATH, $temp_dir . $temp_name)) { $export_message = sprintf($text_failed, $archive->errorInfo(true)); rm_full_dir($temp_dir . $temp_name); return FALSE; } } else { // inline-filter // create a plugin-filter $filter['plugin'] = $temp_name; $filter_func = $filter['func']; $filter['func'] = '';
<?php include_once '../scripts/config.php'; $filename = null; if (isset($cfg['Products']['dir'])) { $filename = $cfg['Products']['dir'] . 'test.zip'; } require_once '../scripts/pclzip.lib.php'; $archive = new PclZip($filename); $v_list = $archive->add('add_foot.php,add_head.php,add_main.php,../service/'); if ($v_list == 0) { echo "Error (archive->add): " . $archive->errorInfo(true); } $v_list = $archive->delete(PCLZIP_OPT_BY_EREG, '^service/'); if ($v_list == 0) { echo "Error (archive->delete): " . $archive->errorInfo(true); } $v_list = $archive->add('../service/'); if ($v_list == 0) { echo "Error (archive->add 2): " . $archive->errorInfo(true); } if (($list = $archive->listContent()) == 0) { echo "Error (zip->listContent): " . $zip->errorInfo(true); } for ($i = 0; $i < sizeof($list); $i++) { for (reset($list[$i]); $key = key($list[$i]); next($list[$i])) { echo "File {$i} / [{$key}] = " . $list[$i][$key] . "<br>"; } echo "<br>"; } ?>