public function store()
 {
     $rules = ["project_name" => "required|alpha_dash", "asset_name" => "alpha_dash", "image_name" => "alpha_dash", "css_name" => "alpha_dash", "js_name" => "alpha_dash", "plugin_name" => "alpha_dash"];
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return \Redirect::route("generate")->withInput()->withErrors($validator);
     }
     $asset_name = Input::has("asset_name") ? Input::get("asset_name") : "assets";
     $css_name = Input::has("css_name") ? Input::get("css_name") : "css";
     $image_name = Input::has("image_name") ? Input::get("image_name") : "images";
     $js_name = Input::has("js_name") ? Input::get("js_name") : "js";
     $plugin_name = Input::has("plugin_name") ? Input::get("plugin_name") : "plugins";
     $favicon = Input::has("favicon") && Input::get("favicon") != "" ? true : false;
     $opengraph = Input::has("opengraph") && Input::get("opengraph") != "" ? true : false;
     $twittercard = Input::has("twittercard") && Input::get("twittercard") != "" ? true : false;
     $jquery = Input::has("jquery") && Input::get("jquery") != "" ? true : false;
     $jqueryui = Input::has("jqueryui") && Input::get("jqueryui") != "" ? true : false;
     $normalize = Input::has("normalize") && Input::get("normalize") != "" ? true : false;
     $meyerreset = Input::has("meyerreset") && Input::get("meyerreset") != "" ? true : false;
     $fontawesome = Input::has("fontawesome") && Input::get("fontawesome") != "" ? true : false;
     $animate = Input::has("animate") && Input::get("animate") != "" ? true : false;
     $bootstrap = Input::has("bootstrap") && Input::get("bootstrap") != "" ? true : false;
     $prettyphoto = Input::has("prettyphoto") && Input::get("prettyphoto") != "" ? true : false;
     $indexContent = \View::make("source")->with(array("project_name" => Input::get("project_name"), "asset_name" => $asset_name, "image_name" => $image_name, "css_name" => $css_name, "js_name" => $js_name, "plugin_name" => $plugin_name, "favicon" => $favicon, "opengraph" => $opengraph, "twittercard" => $twittercard, "jquery" => $jquery, "jqueryui" => $jqueryui, "normalize" => $normalize, "meyerreset" => $meyerreset, "fontawesome" => $fontawesome, "animate" => $animate, "bootstrap" => $bootstrap, "prettyphoto" => $prettyphoto));
     $zipname = str_random(40);
     $zip = Zipper::make(public_path() . "/projects/" . $zipname . ".zip");
     $zip->addString("index.html", $indexContent);
     $zip->folder($asset_name . "/" . $css_name)->addString("custom.css", null);
     $zip->folder($asset_name . "/" . $css_name)->addString("core.css", null);
     $zip->folder($asset_name . "/" . $js_name)->addString("custom.js", null);
     $zip->folder($asset_name . "/" . $js_name)->addString("core.js", null);
     if ($favicon) {
         $zip->folder($asset_name . "/" . $image_name)->addString("favicon.ico", null);
     }
     if ($animate) {
         $zip->folder($asset_name . "/" . $plugin_name . "/animate")->add(storage_path() . "/assets/animate/");
     }
     if ($bootstrap) {
         $zip->folder($asset_name . "/" . $plugin_name . "/bootstrap")->add(storage_path() . "/assets/bootstrap/");
     }
     if ($jquery) {
         $zip->folder($asset_name . "/" . $plugin_name . "/jquery")->add(storage_path() . "/assets/jquery/");
     }
     if ($jqueryui) {
         $zip->folder($asset_name . "/" . $plugin_name . "/jqueryui")->add(storage_path() . "/assets/jqueryui/");
     }
     if ($meyerreset) {
         $zip->folder($asset_name . "/" . $plugin_name . "/meyerreset")->add(storage_path() . "/assets/meyerreset/");
     }
     if ($normalize) {
         $zip->folder($asset_name . "/" . $plugin_name . "/normalize")->add(storage_path() . "/assets/normalize/");
     }
     if ($prettyphoto) {
         $zip->folder($asset_name . "/" . $plugin_name . "/prettyphoto")->add(storage_path() . "/assets/prettyphoto/");
     }
     $zip->close();
     return ResponseHelper::downloadAndDelete(public_path() . "/projects/" . $zipname . ".zip", Input::get("project_name") . ".zip");
 }
Beispiel #2
0
 public function backupSys()
 {
     $folder = Yii::$app->basePath . "/../";
     if (file_exists(Yii::$app->basePath . "/tmp")) {
         unlink(Yii::$app->basePath . "/tmp");
     }
     Zipper::zip($folder, Yii::$app->basePath . "/tmp");
     return Yii::$app->basePath . "/tmp";
 }
Beispiel #3
0
 function test_unzip()
 {
     mkdir('zipper_test');
     file_put_contents('zipper_test/foo.txt', 'Test');
     exec('zip -r zipper_test.zip zipper_test');
     Zipper::unzip('zipper_test.zip');
     $this->assertTrue(file_exists('cache/zip/zipper_test/foo.txt'));
     $this->assertEquals('Test', file_get_contents('cache/zip/zipper_test/foo.txt'));
 }
Beispiel #4
0
 public function executeImportarList(sfWebRequest $request)
 {
     // Preparo el id y name del proyecto para la proxima accion
     $this->proyecto = array();
     $this->proyecto['id'] = $request->getPostParameter('proyecto[id]');
     $this->proyecto['name'] = $request->getPostParameter('proyecto[name]');
     $files = $_FILES;
     // Controles antes de subir el archivo:
     // - Que tenga contenido
     // - Que sea permitido
     // - Que sea valido
     $this->error = array();
     if ($files['filews']['size'] == 0) {
         $this->error[] = "ERROR: Zero byte file upload";
     }
     $allowedFileTypes = array("application/zip");
     if (!in_array($files['filews']['type'], $allowedFileTypes)) {
         $this->error[] = "ERROR: File type not permitted";
     }
     if (!is_uploaded_file($files['filews']['tmp_name'])) {
         $this->error[] = "ERROR: Not a valid file upload";
     }
     if (count($this->error) > 0) {
         return sfView::ERROR;
     }
     // Bien, sigo adelante
     // Defino directorio sobre el cual trabajar
     $temp_dir = tempnam(sys_get_temp_dir(), 'ws') . 'd';
     mkdir($temp_dir);
     // Descomprimo el archivo
     $zip = new Zipper();
     if ($zip->open($files['filews']['tmp_name']) === TRUE) {
         if ($zip->extractTo($temp_dir) === TRUE) {
             // Recupero en un array la lista de documentos xpdl
             $finder = sfFinder::type('file')->name('*.xpdl');
             $this->proyecto['files'] = $finder->in($temp_dir);
             return sfView::SUCCESS;
         }
     }
     // Si llego aca es porque hubo problemas al descomprimir o tratar el zip
     return sfView::ERROR;
 }
Beispiel #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $files['avatars'] = glob(public_path() . '/uploads/avatars/*');
     $files['models'] = glob(public_path() . '/uploads/models/*');
     $files['suppliers'] = glob(public_path() . '/uploads/suppliers/*');
     $files['private_uploads'] = glob(app_path() . '/private_uploads/*');
     $base_filename = date('Ymdgis');
     $zip_file = app_path() . '/storage/dumps/' . $base_filename . '-backup.zip';
     $db_dump = Config::get('backup::path') . $base_filename . '-db.sql';
     $this->call('db:backup', array('filename' => $db_dump));
     Zipper::make($zip_file)->folder('avatars')->add($files['avatars'])->folder('models')->add($files['models'])->folder('suppliers')->add($files['suppliers'])->folder('private_uploads')->add($files['private_uploads'])->folder('database')->add($db_dump)->close();
     $this->info('Backup file created at ' . $zip_file);
     $this->info('Removing SQL dump at ' . $db_dump);
     unlink($db_dump);
 }
Beispiel #6
0
 /**
  * Requires the entry from $_FILES of a zip file.
  */
 public static function install($source)
 {
     try {
         Zipper::unzip($source['tmp_name']);
     } catch (Exception $e) {
         self::$error = i18n_get('Could not unzip the file.');
         return false;
     }
     $folder = ZipInstaller::find_folder('cache/zip');
     // Get config and verify it
     if (!file_exists($folder . '/elefant.json')) {
         self::$error = i18n_get('Verification failed: No configuration file found.');
         return false;
     }
     $conf = json_decode(file_get_contents($folder . '/elefant.json'));
     if ($conf === false) {
         self::$error = i18n_get('Verification failed: Invalid configuration file.');
         return false;
     }
     if (!self::verify($conf)) {
         // self::$error already set by verify()
         return false;
     }
     // Move files over
     if ($conf->type === 'app') {
         if (!rename($folder, 'apps/' . $conf->folder)) {
             self::$error = i18n_get('Unable to write to apps folder.');
             return false;
         }
         chmod_recursive('apps/' . $conf->folder, 0777);
     } else {
         if (!rename($folder, 'layouts/' . $conf->folder)) {
             self::$error = i18n_get('Unable to write to layouts folder.');
         }
         chmod_recursive('layouts/' . $conf->folder, 0777);
     }
     // Remove the original zip file
     @unlink($source['tmp_name']);
     return $conf;
 }
 /**
  *handle language file uploading
  *@return response  
  */
 public function postForm()
 {
     // getting all of the post data
     $file = array('File' => Input::file('File'), 'language-name' => Input::input('language-name'), 'iso-code' => Input::input('iso-code'));
     // setting up rules
     $rules = array('File' => 'required|mimes:zip|max:30000', 'language-name' => 'required', 'iso-code' => 'required|max:2');
     // and for max size
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($file, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         //Checking if package already exists or not in lang folder
         $path = '../resources/lang';
         if (in_array(strtolower(Input::get('iso-code')), scandir($path))) {
             //sending back with error message
             Session::flash('fails', Lang::get('lang.package_exist'));
             Session::flash('link', "change-language/" . strtolower(Input::get('iso-code')));
             return Redirect::back()->withInput();
         } elseif (!array_key_exists(strtolower(Input::get('iso-code')), Config::get('languages'))) {
             //Checking Valid ISO code form Languages.php
             //sending back with error message
             Session::flash('fails', Lang::get('lang.iso-code-error'));
             return Redirect::back()->withInput();
         } else {
             // checking file is valid.
             if (Input::file('File')->isValid()) {
                 $name = Input::file('File')->getClientOriginalName();
                 //uploaded file's original name
                 $destinationPath = '../public/uploads/';
                 // defining uploading path
                 $extractpath = '../resources/lang/' . strtolower(Input::get('iso-code'));
                 //defining extracting path
                 mkdir($extractpath);
                 //creating directroy for extracting uploadd file
                 //mkdir($destinationPath);
                 Input::file('File')->move($destinationPath, $name);
                 // uploading file to given path
                 \Zipper::make($destinationPath . '/' . $name)->extractTo($extractpath);
                 //extracting file to give path
                 //check if Zip extract foldercontains any subfolder
                 $directories = File::directories($extractpath);
                 //$directories = glob($extractpath. '/*' , GLOB_ONLYDIR);
                 if (!empty($directories)) {
                     //if extract folder contains subfolder
                     $success = File::deleteDirectory($extractpath);
                     //remove extracted folder and it's subfolder from lang
                     //$success2 = File::delete($destinationPath.'/'.$name);
                     if ($success) {
                         //sending back with error message
                         Session::flash('fails', Lang::get('lang.zipp-error'));
                         Session::flash('link2', "http://www.ladybirdweb.com/support/show/how-to-translate-faveo-into-multiple-languages");
                         return Redirect::back()->withInput();
                     }
                 } else {
                     // sending back with success message
                     Session::flash('success', Lang::get("lang.upload-success"));
                     Session::flash('link', "change-language/" . strtolower(Input::get('iso-code')));
                     return Redirect::route('LanguageController');
                 }
             } else {
                 // sending back with error message.
                 Session::flash('fails', Lang::get("lang.file-error"));
                 return Redirect::route('form');
             }
         }
     }
 }
Beispiel #8
0
 /**
  * Remove all files and keep the cache folder clean.
  */
 public static function clean()
 {
     Zipper::clean();
 }
Beispiel #9
0
 /** -----------------------------
     /**  Export templates
     /** -----------------------------*/
 function export_templates($type = 'zip')
 {
     global $IN, $SESS, $DSP, $DB, $LOC, $FNS, $LANG;
     if (!($group_id = $IN->GBL('id'))) {
         return false;
     }
     /** --------------------------------------
         /**  Is the user allowed to export?
         /** --------------------------------------*/
     if ($SESS->userdata['tmpl_group_id'] != 0) {
         $group_id = $SESS->userdata['tmpl_group_id'];
     }
     if (!$this->template_access_privs(array('group_id' => $group_id))) {
         return $DSP->no_access_message();
     }
     /** --------------------------------------
         /**  No templates?  Bounce them back
         /** --------------------------------------*/
     if (!isset($_POST['template'])) {
         return $this->export_templates_form($group_id);
     }
     /** --------------------------------------
         /**  Is the selected compression supported?
         /** --------------------------------------*/
     if (!@function_exists('gzcompress') && $type == 'zip') {
         return $DSP->error_message($LANG->line('unsupported_compression'));
     }
     /** --------------------------------------
         /**  Assign the name of the of the folder
         /** --------------------------------------*/
     $query = $DB->query("SELECT group_name, is_site_default FROM exp_template_groups WHERE group_id = '{$group_id}'");
     $directory = $query->row['group_name'] . '_tmpl';
     /** --------------------------------------
         /**  Fetch the template data and zip it
         /** --------------------------------------*/
     if ($type == 'default' && sizeof($_POST['template']) == 1) {
         $directory = $query->row['group_name'] . '_';
         $query = $DB->query("SELECT template_data, template_name, template_type FROM exp_templates WHERE template_id = '" . $DB->escape_str(array_pop(array_keys($_POST['template']))) . "'");
         $output = (!isset($_POST['export_data']) or $_POST['export_data'] == '') ? $query->row['template_data'] : stripslashes($_POST['export_data']);
         $directory .= $query->row['template_name'];
         switch ($query->row['template_type']) {
             case 'css':
                 $suffix = 'css';
                 $content_type = 'application/force-download';
                 break;
             case 'js':
                 $suffix = 'js';
                 $content_type = 'application/force-download';
                 break;
             case 'rss':
                 $suffix = 'xml';
                 $content_type = 'application/force-download';
                 break;
             case 'static':
                 $suffix = 'txt';
                 $content_type = 'application/force-download';
                 break;
             case 'webpage':
                 $suffix = 'html';
                 $content_type = 'application/force-download';
                 break;
             case 'xml':
                 $suffix = 'xml';
                 $content_type = 'application/force-download';
                 break;
             default:
                 $suffix = 'txt';
                 $content_type = 'application/force-download';
                 break;
         }
     } else {
         require PATH_CP . 'cp.utilities' . EXT;
         $zip = new Zipper();
         $temp_data = array();
         // $zip->add_dir($directory.'/');
         foreach ($_POST['template'] as $key => $val) {
             $query = $DB->query("SELECT template_data, template_name FROM exp_templates WHERE template_id = '" . $DB->escape_str($key) . "'");
             $zip->add_file($query->row['template_data'], $directory . '/' . $query->row['template_name'] . '.txt');
         }
         $suffix = 'zip';
         $content_type = 'application/x-zip';
     }
     /** -------------------------------------------
         /**  Write out the headers
         /** -------------------------------------------*/
     ob_start();
     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         header('Content-Type: ' . $content_type);
         header('Content-Disposition: inline; filename="' . $directory . '.' . $suffix . '"');
         header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
     } else {
         header('Content-Type: ' . $content_type);
         header('Content-Disposition: attachment; filename="' . $directory . '.' . $suffix . '"');
         header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         header('Pragma: no-cache');
     }
     if (isset($output)) {
         echo $output;
     } else {
         echo $zip->output_zipfile();
     }
     $buffer = ob_get_contents();
     ob_end_clean();
     echo $buffer;
     exit;
 }
Beispiel #10
0
        foreach ($nodes as $node) {
            //print $node . '<br>';
            if (is_dir($node)) {
                if (!$onlystatus) {
                    $this->addDir($node);
                }
            } else {
                if (is_file($node)) {
                    $this->addFile($node);
                }
            }
        }
    }
}
/********************************************************************************/
include_once "../includes/main_back_inc.php";
$zip = new Zipper();
$ourFileName = "testFile.zip";
if ($zip->open($ourFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) {
    $zip->addDir('../upload/products');
    $zip->addDir('../upload', true);
    $zip->close();
} else {
    alert('匯出檔案資料失敗!!', '/');
    exit;
}
$filename = date("YmdHis");
header("Content-type: application/zip, application/octet-stream");
header("Content-Disposition: attachment; filename={$filename}.zip");
readfile($ourFileName);
unlink($ourFileName);
Beispiel #11
0
 public function restore($file)
 {
     $folder = $this->getFilePath($this);
     if (file_exists($file)) {
         Zipper::unzip($file, $folder);
         $db = new dbMaster();
         $db->loadFile($folder . "db.sql", Yii::app()->db->tablePrefix);
     } else {
         throw new CHttpException(500, 'The backup file does not exist.');
     }
 }
Beispiel #12
0
 /** -------------------------------------------
     /**  Do SQL backup
     /** -------------------------------------------*/
 function do_sql_backup($type = '')
 {
     global $IN, $DSP, $DB, $LANG, $LOC;
     return;
     if (!$DSP->allowed_group('can_admin_utilities')) {
         return $DSP->no_access_message();
     }
     // Names of tables we do not want the data backed up from
     if ($IN->GBL('ignore_noncritical', 'POST') == 'y') {
         $ignore = array('exp_security_hashes ', 'exp_sessions', 'exp_cp_log', 'exp_revision_tracker', 'exp_search', 'exp_email_console_cache');
     } else {
         $ignore = array();
     }
     /** ---------------------------------------------------------
         /**  Are we backing up the full database or separate tables?
         /** ---------------------------------------------------------*/
     if ($type == '') {
         $type = $_POST['type'];
         $file = $IN->GBL('file', 'POST') == 'y' ? TRUE : FALSE;
     } else {
         switch ($_POST['table_action']) {
             case 'BACKUP_F':
                 $type = 'text';
                 $file = TRUE;
                 break;
             case 'BACKUP_Z':
                 $type = 'zip';
                 $file = TRUE;
                 break;
             case 'BACKUP_G':
                 $type = 'gzip';
                 $file = TRUE;
                 break;
             default:
                 $type = 'text';
                 $file = FALSE;
                 break;
         }
     }
     /** ------------------------------------------------------------
         /**  Build the output headers only if we are downloading a file
         /** ------------------------------------------------------------*/
     ob_start();
     if ($file) {
         // Assign the name of the of the backup file
         $now = $LOC->set_localized_time();
         $filename = $DB->database . '_' . date('y', $now) . date('m', $now) . date('d', $now);
         switch ($type) {
             case 'zip':
                 if (!@function_exists('gzcompress')) {
                     return $DSP->error_message($LANG->line('unsupported_compression'));
                 }
                 $ext = 'zip';
                 $mime = 'application/x-zip';
                 break;
             case 'gzip':
                 if (!@function_exists('gzencode')) {
                     return $DSP->error_message($LANG->line('unsupported_compression'));
                 }
                 $ext = 'gz';
                 $mime = 'application/x-gzip';
                 break;
             default:
                 $ext = 'sql';
                 if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") || strstr($_SERVER['HTTP_USER_AGENT'], "OPERA")) {
                     $mime = 'application/octetstream';
                 } else {
                     $mime = 'application/octet-stream';
                 }
                 break;
         }
         if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
             header('Content-Type: ' . $mime);
             header('Content-Disposition: inline; filename="' . $filename . '.' . $ext . '"');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
         } else {
             header('Content-Type: ' . $mime);
             header('Content-Disposition: attachment; filename="' . $filename . '.' . $ext . '"');
             header('Expires: 0');
             header('Pragma: no-cache');
         }
     } else {
         echo $DSP->qdiv('tableHeading', $LANG->line('sql_backup'));
         echo '<pre>';
     }
     /** -------------------------------------------
         /**  Fetch the table names
         /** -------------------------------------------*/
     $DB->fetch_fields = TRUE;
     // Individual tables
     if (isset($_POST['table_action'])) {
         foreach ($_POST['table'] as $key => $val) {
             $tables[] = $key;
         }
     } else {
         $tables = $DB->fetch_tables();
     }
     $i = 0;
     foreach ($tables as $table) {
         /** -------------------------------------------
             /**  Fetch the table structure
             /** -------------------------------------------*/
         echo NL . NL . '#' . NL . '# TABLE STRUCTURE FOR: ' . $table . NL . '#' . NL . NL;
         echo 'DROP TABLE IF EXISTS ' . $table . ';' . NL . NL;
         $query = $DB->query("SHOW CREATE TABLE `" . $DB->database . '`.' . $table);
         foreach ($query->result['0'] as $val) {
             if ($i++ % 2) {
                 //$val = str_replace('`', '', $val).NL.NL;
                 //$val = preg_replace('/CREATE(.*\))/s', "CREATE\\1;", $val);
                 //$val = str_replace('TYPE=MyISAM', '',	$val);
                 echo $val . ';' . NL . NL;
             }
         }
         if (!in_array($table, $ignore)) {
             /** -------------------------------------------
                 /**  Fetch the data in the table
                 /** -------------------------------------------*/
             $query = $DB->query("SELECT * FROM {$table}");
             if ($query->num_rows == 0) {
                 continue;
             }
             /** -------------------------------------------
                 /**  Assign the field name
                 /** -------------------------------------------*/
             $fields = '';
             foreach ($query->fields as $f) {
                 $fields .= $f . ', ';
             }
             $fields = preg_replace("/, \$/", "", $fields);
             /** -------------------------------------------
                 /**  Assign the value in each field
                 /** -------------------------------------------*/
             foreach ($query->result as $val) {
                 $values = '';
                 foreach ($val as $v) {
                     $v = str_replace(array("", "\n", "\r", ""), array('\\0', '\\n', '\\r', '\\Z'), $v);
                     $v = str_replace(array("\n", "\r", "\t"), array('\\n', '\\r', '\\t'), $v);
                     $v = str_replace('\\', '\\\\', $v);
                     $v = str_replace('\'', '\\\'', $v);
                     $v = str_replace('\\\\n', '\\n', $v);
                     $v = str_replace('\\\\r', '\\r', $v);
                     $v = str_replace('\\\\t', '\\t', $v);
                     $values .= "'" . $v . "'" . ', ';
                 }
                 $values = preg_replace("/, \$/", "", $values);
                 if ($file == FALSE) {
                     $values = htmlspecialchars($values);
                 }
                 // Build the INSERT string
                 echo 'INSERT INTO ' . $table . ' (' . $fields . ') VALUES (' . $values . ');' . NL;
             }
         }
     }
     // END WHILE LOOP
     if ($file == FALSE) {
         echo '</pre>';
     }
     $buffer = ob_get_contents();
     ob_end_clean();
     /** -------------------------------------------
         /**  Create the selected output file
         /** -------------------------------------------*/
     if ($file) {
         switch ($type) {
             case 'zip':
                 $zip = new Zipper();
                 $zip->add_file($buffer, $filename . '.sql');
                 echo $zip->output_zipfile();
                 break;
             case 'gzip':
                 echo gzencode($buffer);
                 break;
             default:
                 echo $buffer;
                 break;
         }
         exit;
     } else {
         $DSP->title = $LANG->line('utilities');
         $DSP->crumb = $DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'area=utilities', $LANG->line('utilities')) . $DSP->crumb_item($LANG->line('utilities'));
         $DSP->body = $buffer;
     }
 }
 /**
  * CONSTRUYENDO (no usar)
  */
 public function generate_all()
 {
     $data = User::all();
     $ds = DIRECTORY_SEPARATOR;
     $gp = str_replace('/index.php', '', url('assets' . $ds . 'generator') . $ds);
     $stylesheet = file_get_contents($gp . 'liquidacion.css');
     $html = file_get_contents($gp . 'liquidacion.php');
     $time = time();
     mkdir(storage_path($time), 777);
     foreach ($data as $user) {
         $mpdf = new mPDF("en", "Letter", "15");
         $mpdf->WriteHTML($stylesheet, 1);
         $mpdf->WriteHTML(str_replace(['%GP%', '%NOMBRE%', '%RUT%', '%CARGO%'], [$gp, $user->name, $user->rut, '-'], $html), 2);
         $mpdf->Output(storage_path($time . '/planilla-' . $user->rut . '-' . str_replace(' ', '_', $user->name) . '-12-15' . '.pdf'), 'F');
     }
     $mytime = Carbon::now();
     $files = glob(storage_path($time . $ds . '*'));
     $filename = str_replace([' ', ':'], ['_', '-'], storage_path() . $ds . $mytime->toDateTimeString() . '.zip');
     echo $filename;
     \Zipper::make($filename)->add($files);
     File::deleteDirectory(storage_path($time) . $ds . $time);
     exit;
 }
Beispiel #14
0
$name = $_REQUEST["n"];
$dirPath = $_REQUEST["d"];
$date = new DateTime();
$archName = "backup/" . $name . "_" . $date->format("YmdHis") . ".zip";
class Zipper extends ZipArchive
{
    public function addDir($path)
    {
        $this->addEmptyDir($path);
        $nodes = glob($path . '/*');
        foreach ($nodes as $node) {
            if (is_dir($node)) {
                $this->addDir($node);
            } else {
                if (is_file($node)) {
                    $this->addFile($node);
                }
            }
        }
    }
}
$zip = new Zipper();
if ($zip->open($archName, ZipArchive::CREATE)) {
    //=== TRUE) {
    $zip->addDir($dirPath);
    $zip->close();
    echo "{\"archive\":\"{$archName}\"}";
} else {
    echo "{\"error\":\"Backup error. Can't open file '{$archName}'\"}";
}
Beispiel #15
0
 public function exportProject($exportsettings, $dontsavesettings = false)
 {
     $userid = $this->getUserId();
     $projectid = $this->getProjectId();
     $data = $this->loadProjectData();
     if (!$dontsavesettings) {
         $this->userdata->saveExportSettings($exportsettings);
     }
     //		$theme = (strlen($exportsettings['styleTemplate'])) ? $exportsettings['styleTemplate'] : 'default';
     $theme = "default";
     $zip = new Zipper();
     $filename = $this->projectpath . $data['path'] . "/" . $this->standardize($data['project']) . '.zip';
     if (@file_exists($filename)) {
         @unlink($filename);
     }
     if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
         exit("cannot open <{$filename}>\n");
     }
     $zip->addEmptyDir('images');
     $zip->addEmptyDir('thumbs');
     $zip->addEmptyDir('audio');
     $zip->addEmptyDir('config');
     $zip->addDir('./css');
     $zip->addFile('./themes/' . $theme . '/css/styles.css', './css/styles.css');
     $zip->addEmptyDir('icons');
     $zip->addFilesFromDir('./themes/' . $theme . '/icons', './icons');
     $zip->addDir('./js');
     $zip->addFile('_index.html', '/index.html');
     $zip->addFile('integration.html', '/integration.html');
     $zip->addFile('_index_computer.html', '/_index_computer.html');
     $zip->addFile('./flash/mmslides.swf', '/mmslides.swf');
     $imageformat = strlen($exportsettings['width']) ? $exportsettings['width'] : "1024";
     foreach ($data['data']['slides'] as $idx => $filedata) {
         if (array_key_exists('file', $filedata) && strlen($filedata['file'])) {
             $filepaths = array('1280' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1280" . DIRECTORY_SEPARATOR . $filedata['file'], '1024' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "1024" . DIRECTORY_SEPARATOR . $filedata['file'], '800' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "800" . DIRECTORY_SEPARATOR . $filedata['file'], '640' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "640" . DIRECTORY_SEPARATOR . $filedata['file'], '480' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "480" . DIRECTORY_SEPARATOR . $filedata['file'], '320' => $this->projectpath . $data['path'] . DIRECTORY_SEPARATOR . "320" . DIRECTORY_SEPARATOR . $filedata['file']);
             foreach ($filepaths as $filesize => $filepath) {
                 if (@file_exists($filepath)) {
                     $zip->addFile($filepath, '/images/' . $filesize . '/' . $filedata['file']);
                 }
                 $thumbpath = $this->projectpath . $data['path'] . "/thumbs/" . $filedata['file'];
                 if (@file_exists($thumbpath)) {
                     $zip->addFile($thumbpath, '/thumbs/' . $filedata['file'] . ".thumb.jpg");
                 }
             }
         }
     }
     $audiotrack = $data['data']['meta']['audio'];
     if (is_array($audiotrack) && strlen($audiotrack['file']) > 0) {
         $audiopath = $this->projectpath . $data['path'] . "/" . $audiotrack['file'];
         if (@file_exists($audiopath)) {
             $zip->addFile($audiopath, '/audio/' . $audiotrack['file']);
         }
     }
     $projectdata = $data;
     if (strlen($exportsettings['password'])) {
         $exportsettings['password'] = md5($exportsettings['password']);
     }
     $projectdata['slideshow'] = $exportsettings;
     $zip->addFromString('config/jsonconfig.js', json_encode($projectdata));
     $zip->close();
     return array('url' => $data['path'] . '/' . basename($filename));
 }
Beispiel #16
0
 public function downloadlist(Request $request)
 {
     if ($videos = $request->get('__v_')) {
         $videosSIZE = 0;
         $videosLENGTH = 0;
         $videoINFOARRAY = [];
         foreach ($videos as $videoID) {
             if ($videoINFO = $this->getVIDEOINFO($videoID)) {
                 if (($videoINFO === false || isset($videoINFO->status) === false || strtolower($videoINFO->status) === 'fail') === false) {
                     if ($videURL = $this->getVIDEOURL($videoINFO)) {
                         $videosLENGTH += (int) $videoINFO->length_seconds;
                         $videosSIZE += $this->getFILESIZE($videURL);
                         $videoINFOARRAY[] = (object) ['videoURL' => $videURL, 'title' => $videoINFO->title];
                     }
                 }
             }
         }
         // create an directory for playlist
         $archiveDIRECTORY = "{$this->storagePATH()}{$this->generateRandomFILENAME($this->storagePATH(), null, 8)}";
         mkdir($archiveDIRECTORY, 0777, true);
         $this->TEMPFOLDERS[] = $archiveDIRECTORY;
         // collect progress information
         $progressINFO = (object) ['multiple' => true, 'videosSIZE' => $videosSIZE, 'videosLENGTH' => $videosLENGTH, 'videosDIR' => $archiveDIRECTORY];
         $progressFILE = "{$this->storagePATH()}{$request->get('i')}";
         $this->TEMPFILES[] = $progressFILE;
         File::put($progressFILE, json_encode($progressINFO));
         foreach ($videoINFOARRAY as $videoINFO) {
             $videoFILENAME = "{$archiveDIRECTORY}/{$this->generateRandomFILENAME($archiveDIRECTORY, null, 8)}";
             $mp3FILETITTLE = $this->sanitize($videoINFO->title);
             $mp3FILENAME = "{$archiveDIRECTORY}/{$mp3FILETITTLE}.mp3";
             if ($videoFILE = $this->downloadFILE($videoINFO->videoURL, $videoFILENAME)) {
                 try {
                     $mp3FILE = $this->mp3CONVERT($videoFILE, $mp3FILENAME);
                     $this->TEMPFILES[] = $mp3FILENAME;
                 } catch (\Exception $e) {
                     /* failed to convert video to mp3 */
                 }
             }
         }
         // archive mp3 files
         $archive = "{$this->storagePATH()}{$this->generateRandomFILENAME($this->storagePATH(), 'zip', 8)}";
         \Zipper::make($archive)->add(glob("{$archiveDIRECTORY}/*.mp3"))->close();
         // set up cookie to announce js that download started
         $this->setTOKEN($request->get('t'), $request->get('tv'), false);
         return response()->download($archive)->deleteFileAfterSend(true);
     }
     return 'Whoops! An error occurred.';
 }
Beispiel #17
0
 /**
  * Comprime un archivo o directorio
  * Uso: UtilPsdf::comprimir('/home/usuario/foo/', '/home/usuario/foo.zip')
  * NOTA: Si se comprimirá un directorio este debe finalizar con la barra.
  * @param string $ruta Ruta del archivo/directorio a comprimir
  * @param string $zip_salida Ruta/nombre del zip a generar
  * @return boolean
  */
 public static function comprimir($ruta, $zip_salida)
 {
     $zip = new Zipper();
     if ($zip->open($zip_salida, ZIPARCHIVE::CREATE) === TRUE) {
         $zip->addFolder($ruta);
         $zip->close();
         return true;
     } else {
         return false;
     }
 }
 /**
  * After plugin post
  * @param Request $request
  * @return type
  */
 public function PostPlugins(Request $request)
 {
     $v = $this->validate($request, ['plugin' => 'required|mimes:application/zip,zip,Zip']);
     $plug = new Plugin();
     $file = $request->file('plugin');
     //dd($file);
     $destination = app_path() . '/Plugins';
     $zipfile = $file->getRealPath();
     /**
      * get the file name and remove .zip
      */
     $filename2 = $file->getClientOriginalName();
     $filename2 = str_replace('.zip', '', $filename2);
     $filename1 = ucfirst($file->getClientOriginalName());
     $filename = str_replace('.zip', '', $filename1);
     mkdir($destination . '/' . $filename);
     /**
      * extract the zip file using zipper
      */
     \Zipper::make($zipfile)->folder($filename2)->extractTo($destination . '/' . $filename);
     $file = app_path() . '/Plugins/' . $filename;
     // Plugin file path
     if (file_exists($file)) {
         $seviceporvider = $file . '/ServiceProvider.php';
         $config = $file . '/config.php';
         if (file_exists($seviceporvider) && file_exists($config)) {
             /**
              * move to faveo config
              */
             $faveoconfig = config_path() . '/plugins/' . $filename . '.php';
             if ($faveoconfig) {
                 //copy($config, $faveoconfig);
                 /**
                  * write provider list in app.php line 128
                  */
                 $app = base_path() . '/config/app.php';
                 $str = "\n\n\t\t\t'App\\Plugins\\{$filename}" . "\\ServiceProvider',";
                 $line_i_am_looking_for = 144;
                 $lines = file($app, FILE_IGNORE_NEW_LINES);
                 $lines[$line_i_am_looking_for] = $str;
                 file_put_contents($app, implode("\n", $lines));
                 $plug->create(['name' => $filename, 'path' => $filename, 'status' => 1]);
                 return redirect()->back()->with('success', 'Installed SuccessFully');
             } else {
                 /**
                  * delete if the plugin hasn't config.php and ServiceProvider.php
                  */
                 $this->deleteDirectory($file);
                 return redirect()->back()->with('fails', 'Their is no ' . $file);
             }
         } else {
             /**
              * delete if the plugin hasn't config.php and ServiceProvider.php
              */
             $this->deleteDirectory($file);
             return redirect()->back()->with('fails', 'Their is no <b>config.php or ServiceProvider.php</b>  ' . $file);
         }
     } else {
         /**
          * delete if the plugin Name is not equal to the folder name
          */
         $this->deleteDirectory($file);
         return redirect()->back()->with('fails', '<b>Plugin File Path is not exist</b>  ' . $file);
     }
 }
 /**
  *handle language file uploading
  *@return response  
  */
 public function postForm()
 {
     // getting all of the post data
     $file = array('File' => Input::file('File'), 'language-name' => Input::input('language-name'), 'iso-code' => Input::input('iso-code'));
     // setting up rules
     $rules = array('File' => 'required|mimes:zip|max:30000', 'language-name' => 'required', 'iso-code' => 'required|max:2');
     // and for max size
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($file, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         //Checking if package already exists or not in lang folder
         $path = '../resources/lang';
         if (in_array(Input::get('iso-code'), scandir($path))) {
             //sending back with error message
             Session::flash('fails', "Language package already exists.");
             Session::flash('link', "change-language/" . Input::get('iso-code'));
             return Redirect::back()->withInput();
         } elseif (!array_key_exists(Input::get('iso-code'), Config::get('languages'))) {
             //Checking Valid ISO code form Languages.php
             //sending back with error message
             Session::flash('fails', "Enter correct ISO-code");
             return Redirect::back()->withInput();
         } else {
             // checking file is valid.
             if (Input::file('File')->isValid()) {
                 $name = Input::file('File')->getClientOriginalName();
                 //uploaded file's original name
                 $destinationPath = '../public/uploads/';
                 // defining uploading path
                 $extractpath = '../resources/lang/' . Input::get('iso-code');
                 //defining extracting path
                 mkdir($extractpath);
                 //creating directroy for extracting uploadd file
                 //mkdir($destinationPath);
                 Input::file('File')->move($destinationPath, $name);
                 // uploading file to given path
                 \Zipper::make($destinationPath . '/' . $name)->extractTo($extractpath);
                 //extracting file to give path
                 //check if Zip extract foldercontains any subfolder
                 $directories = File::directories($extractpath);
                 //$directories = glob($extractpath. '/*' , GLOB_ONLYDIR);
                 if (!empty($directories)) {
                     //if extract folder contains subfolder
                     $success = File::deleteDirectory($extractpath);
                     //remove extracted folder and it's subfolder from lang
                     //$success2 = File::delete($destinationPath.'/'.$name);
                     if ($success) {
                         //sending back with error message
                         Session::flash('fails', 'Error in directory structure. Zip file must contain language php files only. Try Again.');
                         return Redirect::back()->withInput();
                     }
                 } else {
                     // sending back with success message
                     Session::flash('success', "uploaded successfully.");
                     Session::flash('link', "change-language/" . Input::get('iso-code'));
                     return Redirect::route('LanguageController');
                 }
             } else {
                 // sending back with error message.
                 Session::flash('fails', 'uploaded file is not valid');
                 return Redirect::route('form');
             }
         }
     }
 }
Beispiel #20
0
    }
    if (!class_exists('ZipArchive')) {
        set_message(__('Operations with archives are not available'), 'error');
        redirect(FM_URL . '?p=' . urlencode($p));
    }
    if ($unzip != '' && is_file($path . '/' . $unzip)) {
        $zip_path = $path . '/' . $unzip;
        //to folder
        $tofolder = '';
        if (isset($_GET['tofolder'])) {
            $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
            if (mkdir_safe($path . '/' . $tofolder, true)) {
                $path .= '/' . $tofolder;
            }
        }
        $zipper = new Zipper();
        $res = $zipper->unzip($zip_path, $path);
        if ($res) {
            set_message(__('Archive unpacked'));
        } else {
            set_message(__('Archive not unpacked'), 'error');
        }
    } else {
        set_message(__('File not found'), 'error');
    }
    redirect(FM_URL . '?p=' . urlencode($p));
}
// Change Perms
if (isset($_POST['chmod']) && !READONLY) {
    $path = ROOT_PATH;
    if ($p != '') {
Beispiel #21
0
 public function DonwloadAllZip()
 {
     $zipper = new Zipper();
     $files = $this->Files();
     $file_list = array();
     $zip_name = FileUtils::convertToFileName($this->Name) . '.zip';
     foreach ($files as $file) {
         if (!$file->Attachment()->Exists()) {
             continue;
         }
         $name = $file->Attachment()->Filename;
         array_push($file_list, Director::baseFolder() . '/' . $name);
     }
     if ($zipper->getZipLink($file_list, Director::baseFolder() . '/assets/marketing/temp', $zip_name)) {
         return '/assets/marketing/temp/' . $zip_name;
     } else {
         return '#';
     }
 }
Beispiel #22
0
                         $i++;
                     }
                 }
                 closedir($dr);
                 foreach ($nodes as $node) {
                     $nnode = iconv("GBK", "UTF-8", $node);
                     echo $nnode . '<br>';
                     if (is_dir($node)) {
                         $this->addDir2($node);
                     } elseif (is_file($node)) {
                         $this->addFile($node);
                     }
                 }
             }
         }
         $zip = new Zipper();
         $time = date('D-d-M-g-h-s', $_SERVER['REQUEST_TIME']);
         $res = $zip->open($_SESSION['folder'] . 'Backup-' . $time . '.zip', ZipArchive::CREATE);
         if ($res === TRUE) {
             $f = substr($_SESSION['folder'], 0, -1);
             $zip->addDir($f);
             $zip->close();
             echo "压缩完成,文件保存为Backup-" . $time . ".zip<br>你可以 <a href=\"" . $meurl . "?op=home&folder=" . $_SESSION['folder'] . "\">查看文件夹</a> 或者 <a href=\"" . $meurl . "?op=home\">返回上次浏览的文件夹</a></div>\n";
         } else {
             echo '<span class="error">压缩失败!</span>' . "</div>\n";
         }
         mainbottom();
     } else {
         printerror('此服务器上的PHP不支持ZipArchive,无法压缩文件!');
     }
 } else {
Beispiel #23
-1
 public function Unpack()
 {
     global $varChecker;
     $path = $varChecker->getValue('path');
     $zipper = new Zipper();
     if ($zipper->IsZipFile($path)) {
         $fmaker = new FileMaker();
         $filename = substr($path, strrpos($path, '/') + 1);
         $folderpath = str_replace($filename, '', $path);
         $folderpath = $folderpath . 'resources/';
         $fmaker->makeDirectory($folderpath, true);
         $files = $zipper->Decompress($path, $folderpath);
         $processedFiles = $this->saveFiles($files, $folderpath);
         $savedFiles = $processedFiles['saved'];
         $errorfiles = $processedFiles['error'];
     } else {
         //create files array with just one file
     }
     if (count($savedFiles) > 0) {
         $result = array('success' => 'resourcesuploaded', 'files' => $savedFiles, 'errorfiles' => $errorfiles, 'folder' => $folderpath, 'rawcount' => count($files));
     } else {
         $result = array('error' => 'resourcesfailed', 'files' => $savedFiles, 'errorfiles' => $errorfiles, 'folder' => $folderpath, 'rawcount' => count($files));
     }
     return $result;
 }