XOOPS Docs - kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file tardownloader.php

Documentation is available at tardownloader.php

  1. <?php
  2. // $Id: tardownloader.php 2 2005-11-02 18:23:29Z skalpa $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu)                                          //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31. if (!defined('XOOPS_ROOT_PATH')) {
  32.     exit();
  33. }
  34.  
  35. /**
  36.  * base class
  37.  */
  38. include_once XOOPS_ROOT_PATH.'/class/downloader.php';
  39. /**
  40.  * Class to handle tar files
  41.  */
  42. include_once XOOPS_ROOT_PATH.'/class/class.tar.php';
  43.  
  44. /**
  45.  * Send tar files through a http socket
  46.  *
  47.  * @package        kernel
  48.  * @subpackage    core
  49.  *
  50.  * @author        Kazumi Ono     <onokazu@xoops.org>
  51.  * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org
  52.  */
  53. {
  54.  
  55.     /**
  56.      * Constructor
  57.      * 
  58.      * @param string $ext       file extension
  59.      * @param string $mimyType  Mimetype
  60.      ***/
  61.     function XoopsTarDownloader($ext '.tar.gz'$mimyType 'application/x-gzip')
  62.     {
  63.         $this->archiver = new tar();
  64.         $this->ext = trim($ext);
  65.         $this->mimeType trim($mimyType);
  66.     }
  67.  
  68.     /**
  69.      * Add a file to the archive
  70.      * 
  71.      * @param   string  $filepath       Full path to the file
  72.      * @param   string  $newfilename    Filename (if you don't want to use the original)
  73.      ***/
  74.     function addFile($filepath$newfilename=null)
  75.     {
  76.         $this->archiver->addFile($filepath);
  77.         if (isset($newfilename)) {
  78.             // dirty, but no other way
  79.             for ($i 0$i $this->archiver->numFiles$i++{
  80.                 if ($this->archiver->files[$i]['name'== $filepath{
  81.                     $this->archiver->files[$i]['name'trim($newfilename);
  82.                     break;
  83.                 }
  84.             }
  85.         }
  86.     }
  87.  
  88.     /**
  89.      * Add a binary file to the archive
  90.      * 
  91.      * @param   string  $filepath       Full path to the file
  92.      * @param   string  $newfilename    Filename (if you don't want to use the original)
  93.      ***/
  94.     function addBinaryFile($filepath$newfilename=null)
  95.     {
  96.         $this->archiver->addFile($filepathtrue);
  97.         if (isset($newfilename)) {
  98.             // dirty, but no other way
  99.             for ($i 0$i $this->archiver->numFiles$i++{
  100.                 if ($this->archiver->files[$i]['name'== $filepath{
  101.                     $this->archiver->files[$i]['name'trim($newfilename);
  102.                     break;
  103.                 }
  104.             }
  105.         }
  106.     }
  107.  
  108.     /**
  109.      * Add a dummy file to the archive
  110.      * 
  111.      * @param   string  $data       Data to write
  112.      * @param   string  $filename   Name for the file in the archive
  113.      * @param   integer $time 
  114.      ***/
  115.     function addFileData(&$data$filename$time=0)
  116.     {
  117.         $dummyfile XOOPS_CACHE_PATH.'/dummy_'.time().'.html';
  118.         $fp fopen($dummyfile'w');
  119.         fwrite($fp$data);
  120.         fclose($fp);
  121.         $this->archiver->addFile($dummyfile);
  122.         unlink($dummyfile);
  123.  
  124.         // dirty, but no other way
  125.         for ($i 0$i $this->archiver->numFiles$i++{
  126.             if ($this->archiver->files[$i]['name'== $dummyfile{
  127.                 $this->archiver->files[$i]['name'$filename;
  128.                 if ($time != 0{
  129.                     $this->archiver->files[$i]['time'$time;
  130.                 }
  131.                 break;
  132.             }
  133.         }
  134.     }
  135.  
  136.     /**
  137.      * Add a binary dummy file to the archive
  138.      * 
  139.      * @param   string  $data   Data to write
  140.      * @param   string  $filename   Name for the file in the archive
  141.      * @param   integer $time 
  142.      ***/
  143.     function addBinaryFileData(&$data$filename$time=0)
  144.     {
  145.         $dummyfile XOOPS_CACHE_PATH.'/dummy_'.time().'.html';
  146.         $fp fopen($dummyfile'wb');
  147.         fwrite($fp$data);
  148.         fclose($fp);
  149.         $this->archiver->addFile($dummyfiletrue);
  150.         unlink($dummyfile);
  151.  
  152.         // dirty, but no other way
  153.         for ($i 0$i $this->archiver->numFiles$i++{
  154.             if ($this->archiver->files[$i]['name'== $dummyfile{
  155.                 $this->archiver->files[$i]['name'$filename;
  156.                 if ($time != 0{
  157.                     $this->archiver->files[$i]['time'$time;
  158.                 }
  159.                 break;
  160.             }
  161.         }
  162.     }
  163.  
  164.     /**
  165.      * Send the file to the client
  166.      * 
  167.      * @param   string  $name   Filename
  168.      * @param   boolean $gzip   Use GZ compression
  169.      ***/
  170.     function download($name$gzip true)
  171.     {
  172.         $this->_header($name.$this->ext);
  173.         echo $this->archiver->toTarOutput($name.$this->ext$gzip);
  174.     }
  175. }
  176. ?>

XOOPS Docs generated by phpDocumentor