public function extract($zip_file)
 {
     $posts = array();
     if (!$zip_file) {
         return $posts;
     }
     $z = new Zip();
     $result = $z->Extract($zip_file, ".");
     if (!$result) {
         $posts;
     }
     foreach ($result as $key => $value) {
         if (!self::is_file_with_extension($key, 'xliff')) {
             continue;
         }
         $xliff = self::get_xliff($value);
         $translation_item = self::get_translation_item($xliff->children());
         if (!self::is_valid($translation_item)) {
             continue;
         }
         $post = get_post($translation_item['id']);
         if (!$post) {
             continue;
         }
         if ($post->post_title != $translation_item['title']) {
             $post->post_title = $translation_item['title'];
         }
         if ($post->post_content != $translation_item['content']) {
             $post->post_content = $translation_item['content'];
         }
         array_push($posts, $post);
     }
     return $posts;
 }
Exemplo n.º 2
0
 public static function export($idstr)
 {
     $idArr = is_array($idstr) ? $idstr : explode(",", $idstr);
     if (1 < count($idArr)) {
         $zip = new Zip();
         $exportFileName = Ibos::lang("Form export file pack", "workflow.default", array("{date}" => date("Y-m-d")));
         $zipFileName = FileUtil::getTempPath() . "/" . TIMESTAMP . ".zip";
         foreach ($idArr as $id) {
             $form = self::handleExportSingleForm($id);
             $zip->addFile($form["content"], sprintf("%s.html", ConvertUtil::iIconv($form["title"], CHARSET, "gbk")));
         }
         $fp = fopen($zipFileName, "w");
         if (@fwrite($fp, $zip->file()) !== false) {
             header("Cache-control: private");
             header("Content-type: application/octet-stream");
             header("Accept-Ranges: bytes");
             header("Content-Length: " . sprintf("%u", FileUtil::fileSize($zipFileName)));
             header("Content-Disposition: attachment; filename=" . $exportFileName . ".zip");
             readfile($zipFileName);
             exit;
         }
     } else {
         $id = implode(",", $idArr);
         $form = self::handleExportSingleForm($id);
         ob_end_clean();
         header("Cache-control: private");
         header("Content-type: text/plain");
         header("Accept-Ranges: bytes");
         header("Accept-Length: " . strlen($form["content"]));
         header("Content-Disposition: attachment; filename=" . $form["title"] . ".html");
         echo $form["content"];
     }
 }
Exemplo n.º 3
0
 public function index()
 {
     // Define directory separator
     define(MYDS, '/');
     if ($_POST['submit']) {
         $yui = new Yui();
         $yui->compressor_dir = '/assets' . DS . 'compressor' . DS;
         $yui->params = array('nomunge' => $_POST['nomunge'], 'preserve-semi' => $_POST['preserve-semi'], 'disable-optimizations' => $_POST['disable-optimizations']);
         $yui->execute(array_merge($_FILES, $_POST));
         $this->vars['error'] = $yui->error;
         $file_loc = $yui->compressed['dir'] . $yui->compressed['file'];
         $filename = $yui->compressed['file'];
         $filename_zip = current(explode('.', $yui->compressed['file'])) . '.zip';
         $zip_file_with_path = $yui->compressed['dir'] . $filename_zip;
         if ($_POST['zipped'] === "1") {
             $zip = new Zip();
             $zip->addFile($file_loc, $filename);
             $zip->save($zip_file_with_path);
             $this->vars['zipped_file'] = '<a href="' . $zip_file_with_path . '" target="_blank">' . $filename_zip . '</a>';
         }
         $this->vars['compressed_file'] = '<a href="' . $file_loc . '" target="_blank">' . $filename . '</a>';
     }
     $this->layout_vars['page_title'] = 'YUI Compression tool';
     $this->display('home/index', $this->vars);
 }
Exemplo n.º 4
0
 function upload($incVersion)
 {
     $vs = qg::remoteGet($this->name);
     if (!is_dir(sysPATH . $this->name)) {
         return false;
     }
     $v = explode('.', $vs['version']);
     $v = @array((int) $v[0], (int) $v[1], (int) $v[2]);
     foreach ($v as $i => $vp) {
         if ($i >= $incVersion) {
             $v[$i] = 0;
         }
     }
     isset($v[$incVersion - 1]) && ++$v[$incVersion - 1];
     $vs['version'] = implode('.', $v);
     $tmpFile = appPATH . 'cache/tmp/module_export1.zip';
     is_file($tmpFile) && unlink($tmpFile);
     // zzz unlink???
     ini_set('max_execution_time', '600');
     $zip = new Zip();
     $zip->open($tmpFile, Zip::CREATE);
     $zip->addDir(sysPATH . $this->name, null, '/(\\.svn)|(zzz)/');
     $zip->close();
     $vs['size'] = filesize($tmpFile);
     $this->local_version = $vs['version'];
     @qg::Ftp()->mkdir('/module/' . $this->name . '/');
     qg::Ftp()->put('/module/' . $this->name . '/' . $vs['version'] . '.zip', $tmpFile, FTP_BINARY);
     qg::remoteSet($this->name, $vs);
     return $vs['version'];
 }
Exemplo n.º 5
0
 /**
  * Compresses the directory with ZIP.
  * @param string $fileName The file name of the ZIP archive.
  * @param int $flags [optional] The mode to use to open the archive.
  * @return mixed The ZIP archive or an error code on failure.
  */
 public function compress($fileName, $flags = \ZipArchive::CREATE)
 {
     $zip = new Zip();
     if (($res = $zip->open($fileName, $flags)) === true) {
         $zip->addDir($this->path);
         $zip->close();
         return $zip;
     }
     return $res;
 }
Exemplo n.º 6
0
 function run($args)
 {
     if (empty($args[1])) {
         echo $this->getHelp();
         return;
     }
     $path = $args[0];
     $version = $args[1];
     echo "Preparing {$path} release.\n";
     require dirname(__FILE__) . '/GenerateDocsCommand.php';
     $docProcessor = new GenerateDocsCommand($this->getName(), $this->getCommandRunner());
     $outFiles = $docProcessor->processDocuments($path);
     // copy extension dir to temp
     $extPath = Yii::getPathOfAlias('ext') . '/' . $path;
     $copiedExtRoot = Yii::getPathOfAlias('application.runtime.extension');
     echo "Removing {$copiedExtRoot}.\n";
     if (file_exists($copiedExtRoot)) {
         $this->recursiveDelete($copiedExtRoot);
     }
     $copiedExtPath = $copiedExtRoot . '/' . $path;
     if (!file_exists($copiedExtPath)) {
         mkdir($copiedExtPath, 0777, true);
     }
     echo "Copying extension files from {$extPath} to {$copiedExtPath}.\n";
     CFileHelper::copyDirectory($extPath, $copiedExtPath, array('exclude' => array('.svn', 'readme_en.txt', 'readme_ru.txt')));
     echo "Copying documentation to {$copiedExtPath}.\n";
     foreach ($outFiles as $file) {
         copy($file, $copiedExtPath . '/' . basename($file));
     }
     $pathExp = explode('/', $path);
     $zipName = end($pathExp) . '_' . $version . '.zip';
     $releasePath = Yii::getPathOfAlias('application.releases');
     if (!file_exists($releasePath)) {
         mkdir($releasePath, 0777, true);
     }
     $zipPath = "{$releasePath}/{$zipName}";
     if (file_exists($zipPath)) {
         unlink($zipPath);
     }
     //touch($zipPath);
     echo "Creating Zip {$zipPath}.\n";
     require dirname(__FILE__) . '/Zip.php';
     $zip = new Zip();
     if ($zip->open($zipPath, ZipArchive::OVERWRITE | ZipArchive::CREATE) !== TRUE) {
         die("Failed to open Zip {$zipPath}.\n");
     }
     if (!$zip->addDir($copiedExtRoot)) {
         die("Failed adding {$copiedExtRoot} to Zip.\n");
     }
     if ($zip->close()) {
         echo "Done.\n";
     } else {
         die("Failed to write Zip {$zipPath}.\n");
     }
 }
Exemplo n.º 7
0
 static function download($name, $beta = false)
 {
     $vs = self::remoteGet($name, $beta);
     self::ftp()->get(appPATH . 'cache/tmp/pri/remoteModule.zip', '/module/' . $name . '/' . $vs['version'] . '.zip', FTP_BINARY);
     $zip = new Zip();
     $go = $zip->open(appPATH . 'cache/tmp/pri/remoteModule.zip');
     if (!$go) {
         return;
     }
     rrmdir(sysPATH . $name);
     $zip->extractTo(sysPATH);
     $zip->close();
     return $vs;
 }
Exemplo n.º 8
0
 /**
  * Megnézi, hogy a paraméterben kapott zip file-ban létezik e a pom.xml file.
  * @param string $pin_FileName          A vizsgált zip file
  * @return bool                         Létezik e a pom vagy sem
  */
 public static function isPOMExists(string $pin_FileName) : bool
 {
     $obj_Zip = new Zip();
     $obj_Zip->setZipFile($pin_FileName);
     (array) ($loc_Zip = $obj_Zip->getZipFileContent());
     (array) ($loc_Tmp = array());
     foreach ($loc_Zip as $loc_File) {
         $loc_Tmp = array_merge($loc_Tmp, explode('/', $loc_File));
     }
     if (in_array('pom.xml', $loc_Tmp)) {
         return true;
     }
     return false;
 }
Exemplo n.º 9
0
 public function install($filename)
 {
     $src = ROOT . '/sys/tmp/' . $filename;
     $dest = ROOT . '/sys/tmp/install_plugin/';
     Zip::extractZip($src, $dest);
     if (!file_exists($dest)) {
         $this->errors = __('Some error occurred');
         return false;
     }
     $tmp_plugin_path = glob($dest . '*', GLOB_ONLYDIR);
     $tmp_plugin_path = $tmp_plugin_path[0];
     $plugin_basename = substr(strrchr($tmp_plugin_path, '/'), 1);
     $plugin_path = ROOT . '/sys/plugins/' . $plugin_basename;
     copyr($dest, ROOT . '/sys/plugins/', 0755);
     $this->files = getDirFiles($plugin_path);
     if (file_exists($plugin_path . '/config.dat')) {
         $config = json_decode(file_get_contents($plugin_path . '/config.dat'), true);
         include_once $plugin_path . '/index.php';
         $className = $config['className'];
         $obj = new $className(null);
         if (method_exists($obj, 'install')) {
             $obj->install();
         }
     }
     _unlink($src);
     _unlink($dest);
     return true;
 }
Exemplo n.º 10
0
 public function action_zip($articulo_id = null)
 {
     is_null($articulo_id) and Response::redirect('diagramador');
     $articulos = Model_Articulo::find('all', array('related' => array('fotos', 'seccion'), 'where' => array(array('id', '=', $articulo_id))));
     $files_to_zip = array();
     $archivo_informacion = '';
     foreach ($articulos as $articulo) {
         $archivo_informacion .= "Nombre del Articulo: " . $articulo->nombre . "\n";
         $archivo_informacion .= "Seccion del Articulo: " . $articulo->seccion->descripcion . "\n";
         $archivo_informacion .= "Fecha del Articulo: " . date('Y-m-d H:i:s', $articulo->fecha_publicacion) . "\n";
         $archivo_informacion .= "\n ==========================\n";
         foreach ($articulo->fotos as $foto) {
             if ($foto->estado == 1) {
                 array_push($files_to_zip, $foto->imagen);
                 $nombre_archivo = str_ireplace(".jpg", "-" . $articulo->pagina->descripcion . ".jpg", $foto->imagen);
                 $pieces = explode("/", $nombre_archivo);
                 $count_foto = count($pieces);
                 $nombre_archivo = $pieces[$count_foto - 1];
                 $archivo_informacion .= $nombre_archivo . "\n" . "Medida: " . $foto->dimension->descipcion . "\n" . "Pagina: " . $articulo->pagina->descripcion . "\n ==========================\n";
             }
         }
     }
     $time = time();
     File::create(DOCROOT . "zip/", "info_{$articulo_id}_{$time}.txt", $archivo_informacion);
     array_push($files_to_zip, "/gr/public/zip/info_{$articulo_id}_{$time}.txt");
     Zip::create_zip($files_to_zip, $articulo_id, true, $time, $articulo->pagina->descripcion);
 }
Exemplo n.º 11
0
 /**
  * Download zipfile.
  *
  * @param array  $files
  * @param string $filename
  *
  * @return string
  */
 public function download($files, $filename)
 {
     // Get assets
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $files;
     $criteria->limit = null;
     $assets = $criteria->find();
     // Set destination zip
     $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
     // Create the zipfile
     IOHelper::createFile($destZip);
     // Loop through assets
     foreach ($assets as $asset) {
         // Get asset source
         $source = $asset->getSource();
         // Get asset source type
         $sourceType = $source->getSourceType();
         // Get asset file
         $file = $sourceType->getLocalCopy($asset);
         // Add to zip
         Zip::add($destZip, $file, dirname($file));
     }
     // Return zip destination
     return $destZip;
 }
Exemplo n.º 12
0
 /**
  * @param mixed $plugin
  * @throws \RuntimeException
  * @return array
  */
 public function getPluginInfo($plugin)
 {
     switch (true) {
         case is_array($plugin):
             $backend = new ArrayTestCase();
             break;
         case is_dir($plugin):
             $backend = new Directory();
             break;
         case is_file($plugin):
             $backend = new Zip();
             break;
         default:
             throw new \RuntimeException("Could not automatically detect type of given plugin");
     }
     return $backend->getPluginInfo($plugin);
 }
Exemplo n.º 13
0
 public function rebuildZipFile($workshopId)
 {
     $documents = $this->getDocumentsForWorkshop($workshopId);
     $config = Zend_Registry::get('config');
     if (!is_readable($config->user->fileUploadPathWorkshop->val)) {
         throw new Ot_Exception_Data('Target directory is not readable');
     }
     $zip = new Zip($config->user->fileUploadPathWorkshop->val . '/' . $workshopId . '/all_handouts.zip');
     $filesToAdd = array();
     foreach ($documents as $d) {
         $target = $config->user->fileUploadPathWorkshop->val . '/' . $workshopId . '/' . $d['name'];
         if (is_file($target)) {
             $filesToAdd[] = $target;
         } else {
             throw new Ot_Exception_Data('File not found: ' . $target);
         }
     }
     $zip->addFiles($filesToAdd);
     $zip->createZipFile();
 }
function create_zip_Zip($files = array(), $destination = '')
{
    if (count($files)) {
        //create the archive
        if (file_exists($destination)) {
            unlink($destination);
        }
        $zip = new Zip();
        $zip->setZipFile($destination);
        foreach ($files as $file) {
            $zip->addFile(file_get_contents($file), str_replace('/', '', strrchr($file, '/')));
        }
        $zip->finalize();
        $zip->setZipFile($destination);
        //check to make sure the file exists
        return (string) file_exists($destination);
    } else {
        return "No valid files found. Exiting<br/>";
    }
}
Exemplo n.º 15
0
 /**
  * Create a Zip object and store the query results
  *
  * @param mysqli_result $QueryResult results from a query on the collector pages
  * @param string $Title name of the collection that will be created
  * @param string $AnnounceURL URL to add to the created torrents
  */
 public function __construct(&$QueryResult, $Title)
 {
     G::$Cache->InternalCache = false;
     // The internal cache is almost completely useless for this
     Zip::unlimit();
     // Need more memory and longer timeout
     $this->QueryResult = $QueryResult;
     $this->Title = $Title;
     $this->User = G::$LoggedUser;
     $this->AnnounceURL = ANNOUNCE_URL . '/' . G::$LoggedUser['torrent_pass'] . '/announce';
     $this->Zip = new Zip(Misc::file_string($Title));
 }
Exemplo n.º 16
0
 /**
  * Creates a new archive with the specified name and files
  * @param string $name Path to the archive with name and extension
  * @param array $files A numeric array of files
  * @param string $replace
  * @return int How many files has been successfully handled
  */
 public function getArchive($name, array $files, $replace = ABSPATH)
 {
     set_time_limit(300);
     if (!class_exists('Zip', false)) {
         /** @var backupBup $backup */
         $backup = $this->getModule();
         $backup->loadLibrary('zip');
     }
     $zip = new Zip();
     $zip->setZipFile($name);
     foreach ($files as $file) {
         $filename = str_replace($replace, '', $file);
         if (file_exists($file) && is_readable($file) && (substr(basename($file), 0, 3) != 'pcl' && substr($file, -2) != 'gz')) {
             $stream = @fopen($file, 'rb');
             if ($stream) {
                 $zip->addLargeFile($stream, $filename);
             }
         }
     }
     $zip->finalize();
     /* backward */
     return rand(100, 1000);
 }
Exemplo n.º 17
0
 /**
  * Performs the tool's action.
  *
  * @param array $params
  * @return array
  */
 public function performAction($params = array())
 {
     $file = craft()->db->backup();
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
Exemplo n.º 18
0
 /**
  * @inheritDoc ITool::performAction()
  *
  * @param array $params
  *
  * @return array
  */
 public function performAction($params = array())
 {
     // In addition to the default tables we want to ignore data in, we also don't care about data in the session
     // table in this tools' case.
     $file = craft()->db->backup(array('sessions'));
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
Exemplo n.º 19
0
 public function PreProcess()
 {
     $v = Validator::Create();
     $v->Register($this->source[Video_Source::FIELD_EMBED], Validator_Type::NOT_EMPTY, 'The Embed Code field is required');
     $v->Register($this->source[Video_Source::FIELD_DURATION], Validator_Type::VALID_TIME, 'The Video Duration field must be in HH:MM:SS format');
     $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
     $this->video_dir = new Video_Dir(null, 0700);
     Request::FixFiles();
     // No thumbnails uploaded
     if (!isset($_FILES[Video_Source::FIELD_THUMBNAILS])) {
         return;
     }
     // Process each uploaded file
     foreach ($_FILES[Video_Source::FIELD_THUMBNAILS] as $upload) {
         // No file uploaded in this field
         if ($upload['error'] == UPLOAD_ERR_NO_FILE) {
             continue;
         }
         // Check for other errors
         if ($upload['error'] != UPLOAD_ERR_OK) {
             throw new BaseException(Uploads::CodeToMessage($upload['error']));
         }
         switch (File::Type($upload['name'])) {
             case File::TYPE_ZIP:
                 foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_JPEG) as $name => $data) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                 }
                 break;
             case File::TYPE_JPEG:
                 $thumbs[] = $this->video_dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION);
                 break;
         }
     }
     // Resize (if possible) and move images to the correct directory
     if (Video_Thumbnail::CanResize()) {
         $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
     } else {
         $this->thumbs = $this->video_dir->MoveFiles(Video_Dir::TEMP, Video_Dir::THUMBS, JPG_EXTENSION);
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
 function export_and_download_layouts()
 {
     if (isset($_POST['export_and_download'])) {
         $nonce = $_POST["wp_nonce_export_layouts"];
         if (WPDD_Utils::user_not_admin()) {
             die(__("You don't have permission to perform this action!", 'ddl-layouts'));
         }
         if (wp_verify_nonce($nonce, 'wp_nonce_export_layouts')) {
             $results = $this->export_for_download();
             $sitename = sanitize_key(get_bloginfo('name'));
             if (!empty($sitename)) {
                 $sitename .= '.';
             }
             require_once WPDDL_TOOLSET_COMMON_ABSPATH . '/Zip.php';
             if (class_exists('Zip')) {
                 $dirname = $sitename . 'dd-layouts.' . date('Y-m-d');
                 $zipName = $dirname . '.zip';
                 $zip = new Zip();
                 $zip->addDirectory($dirname);
                 foreach ($results as $file_data) {
                     $zip->addFile($file_data['file_data'], $dirname . '/' . $file_data['file_name']);
                 }
                 $zip->sendZip($zipName);
             }
         }
         die;
     }
 }
Exemplo n.º 21
0
 /**
  * Clean up a path
  * If the path starts with a "/", it is deemed absolute and any /../ in the beginning is stripped off.
  * The returned path will not end in a "/".
  *
  * @param String $relPath The path to clean up
  * @return String the clean path
  * @deprecated Redundant, please use Zip::getRelativePath($relPath) instead.
  */
 function relPath($relPath)
 {
     return Zip::getRelativePath($relPath);
 }
Exemplo n.º 22
0
 public function export()
 {
     $condition['project_id'] = Request::input('project_id');
     //todo
     $projectName = 'catphp';
     $fields = array('name', '_id', 'content');
     $rs = $this->mongo->find('document', $condition, array('sort' => array('sort' => 1)), $fields);
     $mk = new Parsedown();
     $docs = array();
     foreach ($rs as $row) {
         $doc = array();
         $doc['name'] = $row['name'];
         $doc['content'] = $mk->parse($row['content']);
         $docs[] = $doc;
     }
     $this->assign("docs", $docs);
     $content = $this->render('views/document.html', false);
     // $this->staticize('runtime/index.html');
     $download_config = CatConfig::getInstance(APP_PATH . '/config/download.conf.php');
     $download_zip_name = APP_PATH . '/runtime/' . $projectName . date('YmdHis') . '.zip';
     $zip = new Zip($download_zip_name, ZipArchive::OVERWRITE);
     $zip->addContent($content, 'index.html');
     foreach ($download_config->get('default') as $file) {
         $zip->addFile(APP_PATH . '/runtime/' . $file, $file);
     }
     $zip->close();
     $this->download($download_zip_name, $projectName . '.zip');
     // $this->zip($this->render('views/document.html'));
     // var_dump($download_config->get('default'));
 }
Exemplo n.º 23
0
            //$file =& $_FILES['plugin'];
            $file = $superCage->files->getRaw('plugin');
            $info = pathinfo($file['name']);
            if (strtolower($info['extension'] != 'zip')) {
                cpg_die(CRITICAL_ERROR, $lang_pluginmgr_php['not_plugin_package'], __FILE__, __LINE__);
            }
            if (!is_dir('./plugins/receive')) {
                $mask = umask(0);
                mkdir('./plugins/receive', 0777);
                umask($mask);
            }
            if (!move_uploaded_file($superCage->files->getRaw('plugin/tmp_name'), './plugins/receive/' . $file['name'])) {
                cpg_die(CRITICAL_ERROR, $lang_pluginmgr_php['copy_error'], __FILE__, __LINE__);
            }
            require_once './include/zip.lib.php';
            $zip = new Zip();
            $zip->Extract('./plugins/receive/' . $file['name'], './plugins', array(-1));
            unlink('./plugins/receive/' . $file['name']);
        }
        break;
}
pageheader($lang_pluginmgr_php['pmgr']);
if (isset($lang_pluginmgr_php['confirm_version']) != TRUE) {
    $lang_pluginmgr_php['confirm_version'] = 'Could not determine the version requirements for this plugin. This is usually an indicator that the plugin was not designed for your version of coppermine and might therefore crash your gallery. Continue anway (not recommended)?';
}
echo <<<EOT

<script language="javascript" type="text/javascript">
function confirmUninstall(text)
{
    return confirm("{$lang_pluginmgr_php['confirm_uninstall']} (" + text + ")");
Exemplo n.º 24
0
 /**
  * Unzip the downloaded update file into the temp package folder.
  *
  * @param string $downloadFilePath
  * @param string $unzipFolder
  *
  * @return bool
  */
 private function _unpackPackage($downloadFilePath, $unzipFolder)
 {
     Craft::log('Unzipping package to ' . $unzipFolder, LogLevel::Info, true);
     if (Zip::unzip($downloadFilePath, $unzipFolder)) {
         return true;
     }
     return false;
 }
Exemplo n.º 25
0
 public function action_zip($articulo_id)
 {
     include DOCROOT . 'phpthumb/phpthumb.class.php';
     \Config::load('phpthumb');
     $document_root = str_replace("\\", "/", Config::get('document_root'));
     is_null($articulo_id) and Response::redirect('articulo');
     $articulo = Model_Articulo::find('first', array('related' => array('fotos', 'seccion'), 'where' => array(array('id', '=', $articulo_id))));
     $fotos_web = null;
     foreach ($articulo->fotos as $foto) {
         $phpThumb = new phpThumb();
         $phpThumb->setParameter('w', Config::get('web_size'));
         $phpThumb->setParameter('q', 75);
         $phpThumb->setParameter('aoe', true);
         $phpThumb->setParameter('config_output_format', 'jpeg');
         $phpThumb->setParameter('f', 'jpeg');
         $nombre_archivo = str_ireplace(".jpg", Config::get('photos_texto') . '.jpg', $foto->imagen);
         $pieces = explode("/", $nombre_archivo);
         $count_foto = count($pieces);
         $nombre_archivo = $pieces[$count_foto - 1];
         $output_filename = $document_root . "/web/" . $nombre_archivo;
         $phpThumb->setSourceData(file_get_contents($document_root . $foto->imagen));
         if ($phpThumb->GenerateThumbnail()) {
             if ($phpThumb->RenderToFile($output_filename)) {
                 Log::info('Imagen para web generada con exito' . $output_filename);
                 $fotos_web[] = $output_filename;
             } else {
                 Log::info('Error al generar imagen para web ' . $phpThumb->debugmessages);
             }
             $phpThumb->purgeTempFiles();
         } else {
             Log::info('Error Fatal al generar imagen para web ' . $phpThumb->fatalerror . "|" . $phpThumb->debugmessages);
         }
         unset($phpThumb);
     }
     $time = time();
     Zip::create_zip($fotos_web, $articulo_id, true, $time);
 }
function start_unzip($tmp_name, $new_name, $todir = 'zipfile')
{
    $z = new Zip();
    $have_zip_file = 0;
    $upfile = array("tmp_name" => $tmp_name, "name" => $new_name);
    if (is_file($upfile[tmp_name])) {
        $have_zip_file = 1;
        echo "<br>正在解压: {$upfile['name']}<br><br>";
        if (preg_match('/\\.zip$/mis', $upfile[name])) {
            $result = $z->Extract($upfile[tmp_name], $todir);
            if ($result == -1) {
                echo "<br>文件 {$upfile['name']} 错误.<br>";
            }
            echo "<br>完成,共建立 {$z->total_folders} 个目录,{$z->total_files} 个文件.<br><br><br>";
        } else {
            echo "<br>{$upfile['name']} 不是 zip 文件.<br><br>";
        }
        if (realpath($upfile[name]) != realpath($upfile[tmp_name])) {
            @unlink($upfile[name]);
            rename($upfile[tmp_name], $upfile[name]);
        }
    }
}
Exemplo n.º 27
0
 /**
  * Finish importing.
  *
  * @param array  $settings
  * @param string $backup
  */
 public function finish($settings, $backup)
 {
     craft()->import_history->end($settings['history'], ImportModel::StatusFinished);
     if ($settings['email']) {
         // Gather results
         $results = array('success' => $settings['rows'], 'errors' => array());
         // Gather errors
         foreach ($this->log as $line => $result) {
             $results['errors'][$line] = $result;
         }
         // Recalculate successful results
         $results['success'] -= count($results['errors']);
         // Prepare the mail
         $email = new EmailModel();
         $emailSettings = craft()->email->getSettings();
         $email->toEmail = $emailSettings['emailAddress'];
         // Get current user
         $currentUser = craft()->userSession->getUser();
         // Zip the backup
         if ($currentUser->can('backup') && $settings['backup'] && IOHelper::fileExists($backup)) {
             $destZip = craft()->path->getTempPath() . IOHelper::getFileName($backup, false) . '.zip';
             if (IOHelper::fileExists($destZip)) {
                 IOHelper::deleteFile($destZip, true);
             }
             IOHelper::createFile($destZip);
             if (Zip::add($destZip, $backup, craft()->path->getDbBackupPath())) {
                 $backup = $destZip;
             }
         }
         // Set email content
         $email->subject = Craft::t('The import task is finished');
         $email->htmlBody = TemplateHelper::getRaw(craft()->templates->render('import/_email', array('results' => $results, 'backup' => $backup)));
         // Send it
         craft()->email->sendEmail($email);
     }
 }
Exemplo n.º 28
0
 // Log start of Zip creation
 $flush_me .= hesk_date() . " | {$hesklang['cZIP']}<br />\n";
 // Preferrably use the zip extension
 if (extension_loaded('zip')) {
     $save_to_zip = $export_dir . $export_name . '.zip';
     $zip = new ZipArchive();
     $res = $zip->open($save_to_zip, ZipArchive::CREATE);
     if ($res === TRUE) {
         $zip->addFile($save_to, "{$export_name}.xml");
         $zip->close();
     } else {
         die("{$hesklang['eZIP']} <{$save_to_zip}>\n");
     }
 } elseif (class_exists('ZipArchive')) {
     require HESK_PATH . 'inc/zip/Zip.php';
     $zip = new Zip();
     $zip->addLargeFile($save_to, "{$export_name}.xml");
     $zip->finalize();
     $zip->setZipFile($save_to_zip);
 } else {
     require HESK_PATH . 'inc/zip/pclzip.lib.php';
     $zip = new PclZip($save_to_zip);
     $zip->add($save_to, PCLZIP_OPT_REMOVE_ALL_PATH);
 }
 // Delete XML, just leave the Zip archive
 hesk_unlink($save_to);
 // Echo memory peak usage
 $flush_me .= hesk_date() . " | " . sprintf($hesklang['pmem'], @memory_get_peak_usage(true) / 1048576) . "<br />\r\n";
 // We're done!
 $flush_me .= hesk_date() . " | {$hesklang['fZIP']}<br /><br />";
 $flush_me .= '<a href="' . $save_to_zip . '">' . $hesklang['ch2d'] . "</a>\n";
Exemplo n.º 29
0
     list(, $mysql_base) = $_SGLOBAL['db']->fetch_array($query, MYSQL_NUM);
     $dumpfile = $backupfile . '.sql';
     @unlink($dumpfile);
     $mysqlbin = $mysql_base == '/' ? '' : addslashes($mysql_base) . 'bin/';
     $_SC['dbcharset'] = empty($_SC['dbcharset']) ? $_SC['charset'] : $_SC['dbcharset'];
     @shell_exec('"' . $mysqlbin . 'mysqldump" --force --quick --default-character-set=' . $_SC['dbcharset'] . ' ' . ($_SGLOBAL['db']->version() > 4.1 ? '--skip-opt --create-options' : '-all') . ' --add-drop-table' . ($extendins == 1 ? '--extended-insert' : '') . '' . ($_SGLOBAL['db']->version() > '4.1' && $sqlcompat == 'MYSQL40' ? '--compatible=mysql40' : '') . ' --host=' . $_SC['dbhost'] . ($_SC['dbport'] ? is_numeric($_SC['dbport']) ? ' --port=' . $_SC['dbport'] : ' --sock=' . $_SC['dbport'] : '') . ' --user='******'dbuser'] . ' --password='******'dbpw'] . ' ' . $_SC['dbname'] . ' ' . $tablesstr . ' > ' . $dumpfile);
     if (file_exists($dumpfile)) {
         if (is_writable($dumpfile)) {
             $fp = fopen($dumpfile, 'rb+');
             fwrite($fp, $idstring . "# <?exit();?>\n " . $setnames . "\n #");
             fclose($fp);
         }
         if ($usezip) {
             include_once S_ROOT . './source/class_zib.php';
             $zipfilename = $backupfile . '.zip';
             $zipfile = new Zip($zipfilename);
             if ($zipfile->create($dumpfile, PCLZIP_OPT_REMOVE_PATH, S_ROOT . './data/' . $backupdir)) {
                 @unlink($dumpfile);
                 fclose(fopen(S_ROOT . './data/' . $backupdir . '/index.htm', 'a'));
                 cpmessage('successful_data_compression_and_backup_server_to', 'admincp.php?ac=backup');
             } else {
                 cpmessage('backup_file_compression_failure', 'admincp.php?ac=backup');
             }
         } else {
             fclose(fopen(S_ROOT . './data/' . $backupdir . '/index.htm', 'a'));
             cpmessage('successful_data_compression_and_backup_server_to', 'admincp.php?ac=backup');
         }
     } else {
         cpmessage('shell_backup_failure', 'admincp.php?ac=backup');
     }
 }
Exemplo n.º 30
0
\PHPZip\Zip\File\Zip::$temp = function() { return "./tempFile_" . rand(100000, 999999);};

$zip = new \PHPZip\Zip\File\Zip(); // $zip = new Zip();
// Archive comments don't really support utf-8. Some tools detect and read it though.
$zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
$zip->addFile("Hello World!", "hello.txt");

@$handle = opendir($fileDir);
if ($handle) {
	/* This is the correct way to loop over the directory. */
	while (false !== ($file = readdir($handle))) {
		if (strpos($file, ".php") !== false) {
			$pathData = pathinfo($fileDir . $file);
			$fileName = $pathData['filename'];

			$zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file), NULL, TRUE, Zip::getFileExtAttr($file));
		}
	}
}

// Uses my Lipsum generator from https://github.com/Grandt/PHPLipsumGenerator
if(file_exists('./LipsumGenerator.php')) {
	require_once './LipsumGenerator.php';
	$lg = new com\grandt\php\LipsumGenerator();
	$zip->openStream("big one3.txt");
	for ($i = 1 ; $i <= 20 ; $i++) {
		$zip->addStreamData("Chapter $i\r\n\r\n" . $lg->generate(300, 2500) . "\r\n");
	}
	$zip->closeStream();
}
$zip->sendZip("ZipExample3.zip", "application/zip", "ZipExample3.zip");