Example #1
1
 /**
  * Render a response object.
  */
 function render($output_body = true)
 {
     $this->outputHeaders();
     if ($output_body) {
         $manifest = $this->stdio->exec(array('get_manifest_of', $this->revision));
         $stanzas = IDF_Scm_Monotone_BasicIO::parse($manifest);
         $zip = new ZipStream();
         foreach ($stanzas as $stanza) {
             if ($stanza[0]['key'] != 'file') {
                 continue;
             }
             $content = $this->stdio->exec(array('get_file', $stanza[1]['hash']));
             $zip->add_file($stanza[0]['values'][0], $content);
         }
         $zip->finish();
     }
 }
Example #2
0
 function __construct($plgFile, $plgName, $domain = '')
 {
     $this->status = '';
     $this->error = '';
     if (empty($plgName)) {
         $plgName = basename($plgFile, '.php');
         $plgName = ucfirst(strtr($plgName, '-_', '  '));
     }
     $this->plgName = $plgName;
     $this->slug = strtolower(strtr($plgName, ' !.,', '----'));
     $this->slug = str_replace("--", "-", $this->slug);
     if (empty($domain)) {
         $domain = $this->slug;
     }
     $this->domain = $domain;
     $this->plgDir = dirname($plgFile);
     $this->plgURL = plugin_dir_url($plgFile);
     $locale = get_locale();
     $this->locale = str_replace('-', '_', $locale);
     $this->target = $this->locale;
     if (!is_admin()) {
         return;
     }
     if (!session_id()) {
         session_start();
     }
     if (!empty($_POST['ezt-savePot']) || !empty($_POST['ezt-download'])) {
         // saving cannot be done from handleSubmits
         // because it would be too late for the headers.
         $slug = $_POST['ezt-slug'];
         if ($slug == $this->slug) {
             if (!empty($_POST['ezt-savePot'])) {
                 $target = $_POST['ezt-target'];
                 $file = "{$slug}-{$target}.zip";
                 $potArray = unserialize(gzinflate(base64_decode($_POST['potArray'])));
                 $poName = $target;
             }
             if (!empty($_POST['ezt-download'])) {
                 require_once ABSPATH . WPINC . '/pluggable.php';
                 global $current_user;
                 get_currentuserinfo();
                 $msg = array();
                 $msg['name'] = $current_user->user_firstname . " " . $current_user->user_lastname;
                 $msg['email'] = $current_user->user_email;
                 $msg['blog'] = get_bloginfo('blog');
                 $msg['url'] = get_bloginfo('url');
                 $msg['charset'] = get_bloginfo('charset');
                 $msg['locale'] = $this->locale;
                 $msg['ezt-target'] = "POT File";
                 $file = "{$slug}.zip";
                 $s = $this->getFileContents();
                 $POs = $this->getTranPOs($s);
                 $potArray = $this->mkPotStr($POs, $msg);
                 $poName = $slug;
             }
             $zip = new ZipStream($file);
             if ($this->isEmbedded && $slug != 'easy-translator' && $slug != 'easy-translator-lite') {
                 $zip->add_file("readme.txt", "Please edit the included PO files using appropriate tools such as poedit (or any text editor) and email them to the plugin author. If you are translating one of my plugins, the email address is manoj@thulasidas.com.");
             }
             foreach ($potArray as $d => $str) {
                 if (empty($d)) {
                     // skip strings with no domain -- they are WP core ones
                     continue;
                 }
                 if ($d == $slug) {
                     $filePO = "{$poName}.po";
                 } else {
                     // d should be 'easy-common'
                     $filePO = "{$poName}_{$d}.po";
                 }
                 $zip->add_file($filePO, $str);
             }
             $zip->finish();
             $this->status .= '<div class="updated">Pot file: ' . $file . ' was saved.</div> ';
             exit(0);
         }
     }
 }
Example #3
0
 public static function apiDownload(Request $r)
 {
     self::authenticateRequest($r);
     self::validateStats($r);
     // Get our runs
     $relevant_columns = array("run_id", "guid", "language", "status", "verdict", "runtime", "penalty", "memory", "score", "contest_score", "time", "submit_delay", "Users.username", "Problems.alias");
     try {
         $runs = RunsDAO::search(new Runs(array("contest_id" => $r["contest"]->getContestId())), "time", "DESC", $relevant_columns);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $zip = new ZipStream($r["contest_alias"] . '.zip');
     // Add runs to zip
     $table = "guid,user,problem,verdict,points\n";
     foreach ($runs as $run) {
         $zip->add_file_from_path("runs/" . $run->getGuid(), RunController::getSubmissionPath($run));
         $columns[0] = 'username';
         $columns[1] = 'alias';
         $usernameProblemData = $run->asFilteredArray($columns);
         $table .= $run->getGuid() . "," . $usernameProblemData['username'] . "," . $usernameProblemData['alias'] . "," . $run->getVerdict() . "," . $run->getContestScore();
         $table .= "\n";
     }
     $zip->add_file("summary.csv", $table);
     // Add problem cases to zip
     $contest_problems = ContestProblemsDAO::GetRelevantProblems($r["contest"]->getContestId());
     foreach ($contest_problems as $problem) {
         $zip->add_file_from_path($problem->getAlias() . "_cases.zip", PROBLEMS_PATH . "/" . $problem->getAlias() . "/cases.zip");
     }
     // Return zip
     $zip->finish();
     die;
 }
Example #4
0
 /**
  *Export an entire collection as a zip file filled with METS xml 
  *files for each item.
  *
  *@param int $collectionID The ID of the omeka collection to export
  *@return void
  */
 public function exportCollectionZip($collectionID)
 {
     include_once dirname(dirname(__FILE__)) . '/libraries/zipstream-php-0.2.2/zipstream.php';
     $collection = get_record_by_id("collection", $collectionID);
     $items = get_records('Item', array('collection' => $collectionID), 999);
     error_reporting(0);
     $zip = new ZipStream('Collection_' . $collection->id . '.zip');
     foreach ($items as $item) {
         ob_start();
         $this->_generateMETS($item->id, false);
         $zip->add_file("Item_" . $item->id . ".mets.xml", ob_get_clean());
     }
     $zip->finish();
 }
 public static function apiDownload(Request $r)
 {
     self::authenticateRequest($r);
     self::validateStats($r);
     // Get our runs
     $relevant_columns = array('run_id', 'guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay', 'Users.username', 'Problems.alias');
     try {
         $runs = RunsDAO::search(new Runs(array('contest_id' => $r['contest']->getContestId())), 'time', 'DESC', $relevant_columns);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $zip = new ZipStream($r['contest_alias'] . '.zip');
     // Add runs to zip
     $table = "guid,user,problem,verdict,points\n";
     foreach ($runs as $run) {
         $zip->add_file_from_path('runs/' . $run->getGuid(), RunController::getSubmissionPath($run));
         $columns[0] = 'username';
         $columns[1] = 'alias';
         $usernameProblemData = $run->asFilteredArray($columns);
         $table .= $run->getGuid() . ',' . $usernameProblemData['username'] . ',' . $usernameProblemData['alias'] . ',' . $run->getVerdict() . ',' . $run->getContestScore();
         $table .= "\n";
     }
     $zip->add_file('summary.csv', $table);
     // Add problem cases to zip
     $contest_problems = ContestProblemsDAO::GetRelevantProblems($r['contest']->getContestId());
     foreach ($contest_problems as $problem) {
         $zip->add_file_from_path($problem->getAlias() . '_cases.zip', PROBLEMS_PATH . '/' . $problem->getAlias() . '/cases.zip');
     }
     // Return zip
     $zip->finish();
     die;
 }
 static function downloadToZip($data)
 {
     // set cookie
     setcookie('fileLoading', true, time() + 10, '/');
     //Create ZipArchive using Stream
     $zipStream = new ZipStream('exams.zip');
     foreach ($data as $item) {
         //Add files
         $filesInDirectory = $item["value"];
         foreach ($filesInDirectory as $file) {
             //Download file
             $downloaded_file = file_get_contents($file);
             //Add to zip
             $zipStream->add_file($item["key"] . "/" . basename($file), $downloaded_file);
         }
     }
     $zipStream->finish();
     //Clean up
     ob_clean();
     flush();
 }
Example #7
0
@(include_once '../conf/configuration.php') or die("Strip It isn't configured yet: conf/configuration.php file is missing.<br/>See README for details.");
@(require_once "zipstream.php");
/**
 * generate the metadata conf
 */
function getMetadataContent($conf)
{
    return "[Desktop Entry]\n" . "Name=" . $conf->title . "\n" . "Comment=" . $conf->title . "\n" . "Type=Service\n" . "X-KDE-ServiceTypes=Plasma/Comic\n" . "Icon=favicon.png\n" . "\n" . "X-KDE-Library=plasma_comic_krossprovider\n" . "X-KDE-PluginInfo-Author=Frederic Forjan\n" . "X-KDE-PluginInfo-Email=fforjab@free.fr\n" . "X-KDE-PluginInfo-Name=" . $conf->title . "\n" . "X-KDE-PluginInfo-Version=0.2\n" . "X-KDE-PluginInfo-Website=http://stripit.sf.net\n" . "X-KDE-PluginInfo-License=GPLv2\n" . "X-KDE-PluginInfo-EnabledByDefault=true\n" . "X-KDE-PlasmaComicProvider-SuffixType=Number";
}
/**
 * return the favicon content
 */
function getFaviconContent()
{
    return implode("", file("../favicon.png"));
}
/**
 * generate the main.es file
 */
function getMainEsContent($conf)
{
    return "//auto-generated URL\nvar URL =  \"" . $conf->url . "/\"\n" . implode("", file("main.es.template"));
}
# create a new stream object
$conf = new configuration();
$zipfile = new ZipStream($conf->title . ".comic", array('content_type' => 'application/octet-stream'));
$conf = new configuration();
$zipfile->add_file("favicon.png", getFaviconContent());
$zipfile->add_file("metadata.desktop", getMetadataContent($conf));
$zipfile->add_file("contents/code/main.es", getMainEsContent($conf));
$zipfile->finish();
Example #8
0
        throw new Exception('Permission denied');
    }
    $app['zadania_service']->delete($id);
    return new RedirectResponse($app['url_generator']->generate('home'));
})->before($checkUser)->bind('zadanie.delete')->convert('id', function ($id) {
    return (int) $id;
});
/**
 * Stahovanie zadani
 */
$app->get('/zadanie/{id}/zip', function (Silex\Application $app, $id) {
    error_reporting(0);
    $filelist = $app['zadania_service']->getFileList($id);
    $notelist = $app['zadania_service']->getNotes($id);
    $stream = function () use($filelist, $notelist, $id) {
        $zip = new ZipStream('zadanie_' . $id . '.zip');
        foreach ($notelist as $note) {
            if (empty($note['poznamka'])) {
                continue;
            }
            $zip->add_file('zadanie_' . $id . '/' . $note['login'] . '/poznamka.txt', $note['poznamka']);
        }
        foreach ($filelist as $subor) {
            $zip->add_file_from_path('zadanie_' . $id . '/' . $subor['login'] . '/' . $subor['nazov'], __DIR__ . '/uploads/' . $subor['cesta']);
        }
        $zip->finish();
    };
    return $app->stream($stream, 200, array('Content-Type' => 'application/zip'));
})->before($checkUser)->bind('zadanie.zip')->convert('id', function ($id) {
    return (int) $id;
});
Example #9
0
<?php

# load zipstream class
require '../zipstream.php';
# get path to current file
$pwd = dirname(__FILE__);
# add some random files
$files = array('../extras/zip-appnote-6.3.1-20070411.txt', '../zipstream.php');
# create new zip stream object
$zip = new ZipStream('test.zip', array('comment' => 'this is a zip file comment.  hello?'));
# common file options
$file_opt = array('time' => time() - 2 * 3600, 'comment' => 'this is a file comment. hi!');
# add files under folder 'asdf'
foreach ($files as $file) {
    # build absolute path and get file data
    $path = $file[0] == '/' ? $file : "{$pwd}/{$file}";
    $data = file_get_contents($path);
    # add file to archive
    $zip->add_file('asdf/' . basename($file), $data, $file_opt);
}
# add same files again wihtout a folder
foreach ($files as $file) {
    # build absolute path and get file data
    $path = $file[0] == '/' ? $file : "{$pwd}/{$file}";
    $data = file_get_contents($path);
    # add file to archive
    $zip->add_file(basename($file), $data, $file_opt);
}
# finish archive
$zip->finish();