コード例 #1
0
ファイル: backup.php プロジェクト: hyrmedia/pligg-cms
 function MakeAvatarBackup()
 {
     include 'zip.php';
     $xlist = array();
     //echo mnmpath;
     $pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
     //echo $_SERVER['DOCUMENT_ROOT'];
     //echo $path = substr($_SERVER["SCRIPT_NAME"], 0, $pos);
     //echo my_pligg_base."/avatars/";
     $files = $this->filelist($_SERVER['DOCUMENT_ROOT'] . my_pligg_base . "/avatars/", 1, 0);
     // call the function
     //echo "<pre>";
     //print_r($files);
     foreach ($files as $list) {
         //print array
         if ($list['dir'] == 0) {
             $xlist[] = $list['path'] . $list['name'];
         }
     }
     // Random 5 characters to append to file names to prevent name guessing
     $rand = substr(md5(microtime()), rand(0, 26), 5);
     //print_r($xlist);
     //die("aaa");
     // code from http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/
     $zipname = 'Avatars' . "_" . date("Y-m-d_H-i-s") . '_' . $rand . '.zip';
     $zipfile = new Archive_Zip('./backup/' . $zipname);
     $p_params = array('remove_path' => $_SERVER['DOCUMENT_ROOT'] . my_pligg_base);
     $zipfile->create($xlist, $p_params);
     echo 'Zip file created -- <a href = "' . './backup/' . $zipname . '">' . $zipname . '</a>';
     $this->success = 1;
 }
コード例 #2
0
	function execute(&$controller, &$xoopsUser)
	{
		$form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
		if ($form_cancel != null) {
			return USER_FRAME_VIEW_CANCEL;
		}

		$this->mActionForm->fetch();
		$this->mActionForm->validate();
		
		if ($this->mActionForm->hasError()) {
			return $this->getDefaultView($controller, $xoopsUser);
		}
		
		$formFile = $this->mActionForm->get('upload');		
		$formFileExt = $formFile->getExtension();
		$files = array();
		$avatarimages = array();

		if ( strtolower($formFileExt) == "zip" ) {
		If ( !file_exists(XOOPS_ROOT_PATH . "/class/Archive_Zip.php") ) {
			return USER_FRAME_VIEW_ERROR;
		}
		require_once XOOPS_ROOT_PATH . "/class/Archive_Zip.php" ;
		$zip = new Archive_Zip($formFile->_mTmpFileName) ;
		$files = $zip->extract( array( 'extract_as_string' => true ) ) ;
		if( ! is_array( @$files ) ) {
		return USER_FRAME_VIEW_ERROR;
		}
		if (!$this->_fetchZipAvatarImages($files, $avatarimages)) {
			return USER_FRAME_VIEW_ERROR;
		}		
		}//if zip end
		else { 
		require_once XOOPS_ROOT_PATH . "/class/class.tar.php";
		$tar =new tar();
		$tar->openTar($formFile->_mTmpFileName);
		if (!is_array( @$tar->files)) {
			return USER_FRAME_VIEW_ERROR;
		}
		if (!$this->_fetchTarAvatarImages($tar->files, $avatarimages)) {
			return USER_FRAME_VIEW_ERROR;
		}		
		}//end tar
						
		if (!$this->_saveAvatarImages($avatarimages)) {
			return USER_FRAME_VIEW_ERROR;
		}
		return USER_FRAME_VIEW_SUCCESS;

	}
コード例 #3
0
 public function createAction()
 {
     //ini_set ( "memory_limit", "256M" );
     // Sean Smith: 10/26/2011 - Reworked app packaging to handle multiple
     // sites calling this function at once
     $this->init();
     // Check for existing site directory, copy package files from code
     // source location (/app/desktop/distro) to site dir
     if (!$this->_prepareSiteDirectory()) {
         // If dir structure not right, or a file copy failed,
         // bail and render error page (download.phtml)
         $this->view->assign('error_message', 'Could not create package. The error was: ' . $this->error_message);
         return;
     }
     // Populate sqlite db from mysql db
     $this->dbAction();
     //zip up
     require_once 'app/desktop/Zip.php';
     $file_collection = array();
     $zipNameLen = strlen($this->zip_name);
     unlink($this->package_dir . '/' . $this->zip_name);
     $archive = new Archive_Zip($this->package_dir . '/' . $this->zip_name);
     // Gather up all files in distro directory
     // initialize an iterator pass it the directory to be processed
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Globals::$BASE_PATH . 'app/desktop/distro'));
     // iterate over the directory add each file found to the archive
     foreach ($iterator as $key => $value) {
         // Exclude the zip file itself (if exists from a previous creation)
         if (substr($key, $zipNameLen * -1, $zipNameLen) != $this->zip_name) {
             $core_file_collection[] = realpath($key);
         }
     }
     // Gather up the site specific files (data/settings.xml and data/sqlite.db)
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->package_dir));
     foreach ($iterator as $key => $value) {
         // Exclude the zip file itself
         if (substr($key, $zipNameLen * -1, $zipNameLen) != $this->zip_name) {
             $site_file_collection[] = realpath($key);
         }
     }
     // Files added in two stages because there are two paths to remove
     // (app/desktop/distro and package_dir) but zip procs will only take one path to remove per call
     $archive->create($site_file_collection, array('remove_path' => $this->package_dir, 'add_path' => 'TS'));
     $archive->add($core_file_collection, array('remove_path' => Globals::$BASE_PATH . 'app/desktop/distro', 'add_path' => 'TS'));
 }
コード例 #4
0
 function MakeAvatarBackup()
 {
     include 'zip.php';
     $xlist = array();
     $files = $this->filelist("./avatars/", 1, 0);
     // call the function
     foreach ($files as $list) {
         //print array
         if ($list['dir'] == 0) {
             $xlist[] = $list['path'] . $list['name'];
         }
     }
     // code from http://www.phpit.net/article/creating-zip-tar-archives-dynamically-php/
     $zipname = 'AvatarBackup' . "-" . date("Y-m-d H-i-s") . '.zip';
     $zipfile = new Archive_Zip('./backup/' . $zipname);
     $zipfile->create($xlist);
     echo 'Zip file created -- <a href = "' . './backup/' . $zipname . '">' . $zipname . '</a>';
     $this->success = 1;
 }
コード例 #5
0
 function get_info($file)
 {
     require_once VIVVO_FS_ROOT . "lib/vivvo/framework/PEAR/Archive/zip.php";
     $obj = new Archive_Zip($file);
     $files = $obj->listContent();
     $data = array();
     foreach ($files as $f) {
         if (empty($f['filename'])) {
             continue;
         }
         $size = empty($f['size']) ? '' : ' (' . round($f['size'] / 1024, 2) . ' KB)';
         $data[] = $f['filename'] . $size;
     }
     if ($data) {
         return implode("\n", $data);
     } else {
         return false;
     }
 }
コード例 #6
0
ファイル: Archive.php プロジェクト: alachaum/timetrex
 /**
  * Send a bunch of files or directories as an archive
  * 
  * Example:
  * <code>
  *  require_once 'HTTP/Download/Archive.php';
  *  HTTP_Download_Archive::send(
  *      'myArchive.tgz',
  *      '/var/ftp/pub/mike',
  *      HTTP_DOWNLOAD_BZ2,
  *      '',
  *      '/var/ftp/pub'
  *  );
  * </code>
  *
  * @see         Archive_Tar::createModify()
  * @static
  * @access  public
  * @return  mixed   Returns true on success or PEAR_Error on failure.
  * @param   string  $name       name the sent archive should have
  * @param   mixed   $files      files/directories
  * @param   string  $type       archive type
  * @param   string  $add_path   path that should be prepended to the files
  * @param   string  $strip_path path that should be stripped from the files
  */
 static function send($name, $files, $type = HTTP_DOWNLOAD_TGZ, $add_path = '', $strip_path = '')
 {
     $tmp = System::mktemp();
     switch ($type = strToUpper($type)) {
         case HTTP_DOWNLOAD_TAR:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp);
             $content_type = 'x-tar';
             break;
         case HTTP_DOWNLOAD_TGZ:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp, 'gz');
             $content_type = 'x-gzip';
             break;
         case HTTP_DOWNLOAD_BZ2:
             include_once 'Archive/Tar.php';
             $arc = new Archive_Tar($tmp, 'bz2');
             $content_type = 'x-bzip2';
             break;
         case HTTP_DOWNLOAD_ZIP:
             include_once 'Archive/Zip.php';
             $arc = new Archive_Zip($tmp);
             $content_type = 'x-zip';
             break;
         default:
             return PEAR::raiseError('Archive type not supported: ' . $type, HTTP_DOWNLOAD_E_INVALID_ARCHIVE_TYPE);
     }
     if ($type == HTTP_DOWNLOAD_ZIP) {
         $options = array('add_path' => $add_path, 'remove_path' => $strip_path);
         if (!$arc->create($files, $options)) {
             return PEAR::raiseError('Archive creation failed.');
         }
     } else {
         if (!($e = $arc->createModify($files, $add_path, $strip_path))) {
             return PEAR::raiseError('Archive creation failed.');
         }
         if (PEAR::isError($e)) {
             return $e;
         }
     }
     unset($arc);
     $dl = new HTTP_Download(array('file' => $tmp));
     $dl->setContentType('application/' . $content_type);
     $dl->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name);
     return $dl->send();
 }
コード例 #7
0
ファイル: ZipTask.php プロジェクト: hunde/bsc
 /**
  * do the work
  * @throws BuildException
  */
 public function main()
 {
     if ($this->zipFile === null) {
         throw new BuildException("zipfile attribute must be set!", $this->getLocation());
     }
     if ($this->zipFile->exists() && $this->zipFile->isDirectory()) {
         throw new BuildException("zipfile is a directory!", $this->getLocation());
     }
     if ($this->zipFile->exists() && !$this->zipFile->canWrite()) {
         throw new BuildException("Can not write to the specified zipfile!", $this->getLocation());
     }
     // shouldn't need to clone, since the entries in filesets
     // themselves won't be modified -- only elements will be added
     $savedFileSets = $this->filesets;
     try {
         if ($this->baseDir !== null) {
             if (!$this->baseDir->exists()) {
                 throw new BuildException("basedir does not exist!", $this->getLocation());
             }
             if (empty($this->filesets)) {
                 // add the main fileset to the list of filesets to process.
                 $mainFileSet = new ZipFileSet($this->fileset);
                 $mainFileSet->setDir($this->baseDir);
                 $this->filesets[] = $mainFileSet;
             }
         }
         if (empty($this->filesets)) {
             throw new BuildException("You must supply either a basedir " . "attribute or some nested filesets.", $this->getLocation());
         }
         // check if zip is out of date with respect to each
         // fileset
         $upToDate = true;
         foreach ($this->filesets as $fs) {
             $files = $fs->getFiles($this->project, $this->includeEmpty);
             if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {
                 $upToDate = false;
             }
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {
                     throw new BuildException("A zip file cannot include itself", $this->getLocation());
                 }
             }
         }
         if ($upToDate) {
             $this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", Project::MSG_INFO);
             return;
         }
         $this->log("Building zip: " . $this->zipFile->__toString(), Project::MSG_INFO);
         $zip = new Archive_Zip($this->zipFile->getAbsolutePath());
         foreach ($this->filesets as $fs) {
             $files = $fs->getFiles($this->project, $this->includeEmpty);
             $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project);
             $filesToZip = array();
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 $f = new PhingFile($fsBasedir, $files[$i]);
                 $filesToZip[] = $f->getAbsolutePath();
                 $this->log("Adding " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);
             }
             $zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath()));
         }
     } catch (IOException $ioe) {
         $msg = "Problem creating ZIP: " . $ioe->getMessage();
         $this->filesets = $savedFileSets;
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
     $this->filesets = $savedFileSets;
 }
コード例 #8
0
ファイル: ZipTask.php プロジェクト: taryono/school
 /**
  * do the work
  * @throws BuildException
  */
 public function main()
 {
     if ($this->zipFile === null) {
         throw new BuildException("zipfile attribute must be set!", $this->getLocation());
     }
     if ($this->zipFile->exists() && $this->zipFile->isDirectory()) {
         throw new BuildException("zipfile is a directory!", $this->getLocation());
     }
     if ($this->zipFile->exists() && !$this->zipFile->canWrite()) {
         throw new BuildException("Can not write to the specified zipfile!", $this->getLocation());
     }
     // shouldn't need to clone, since the entries in filesets
     // themselves won't be modified -- only elements will be added
     $savedFileSets = $this->filesets;
     try {
         if ($this->baseDir !== null) {
             if (!$this->baseDir->exists()) {
                 throw new BuildException("basedir does not exist!", $this->getLocation());
             }
             // add the main fileset to the list of filesets to process.
             $mainFileSet = new FileSet($this->fileset);
             $mainFileSet->setDir($this->baseDir);
             $this->filesets[] = $mainFileSet;
         }
         if (empty($this->filesets)) {
             throw new BuildException("You must supply either a basedir " . "attribute or some nested filesets.", $this->getLocation());
         }
         // check if zip is out of date with respect to each
         // fileset
         $upToDate = true;
         foreach ($this->filesets as $fs) {
             $ds = $fs->getDirectoryScanner($this->project);
             $files = $ds->getIncludedFiles();
             if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {
                 $upToDate = false;
             }
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {
                     throw new BuildException("A zip file cannot include itself", $this->getLocation());
                 }
             }
         }
         if ($upToDate) {
             $this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", PROJECT_MSG_INFO);
             return;
         }
         $this->log("Building zip: " . $this->zipFile->__toString(), PROJECT_MSG_INFO);
         $zip = new Archive_Zip($this->zipFile->getAbsolutePath());
         foreach ($this->filesets as $fs) {
             $ds = $fs->getDirectoryScanner($this->project);
             $files = $ds->getIncludedFiles();
             // FIXME
             // Current model is only adding directories implicitly.  This
             // won't add any empty directories.  Perhaps modify FileSet::getFiles()
             // to also include empty directories.  Not high priority, since non-inclusion
             // of empty dirs is probably not unexpected behavior for ZipTask.
             $fsBasedir = $fs->getDir($this->project);
             $filesToZip = array();
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 $f = new PhingFile($fsBasedir, $files[$i]);
                 $filesToZip[] = $f->getAbsolutePath();
             }
             $zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath()));
         }
     } catch (IOException $ioe) {
         $msg = "Problem creating ZIP: " . $ioe->getMessage();
         $this->filesets = $savedFileSets;
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
     $this->filesets = $savedFileSets;
 }
コード例 #9
0
ファイル: index.php プロジェクト: Geeklog-Plugins/monitor
/**
* Handle uploaded plugin
*
* @return   string      HTML or error message
*
*/
function MONITOR_plugin_upload($plugin = '')
{
    global $_CONF, $_MONITOR_CONF, $_TABLES;
    $retval = '';
    if ($plugin == '' || $_MONITOR_CONF['repository'] == '') {
        return;
    }
    $url = "https://api.github.com/repos/{$_MONITOR_CONF['repository']}/" . $plugin . '/releases';
    //Get last release for this plugin
    $releases = MONITOR_curlRequestOnGitApi($url);
    $version = $releases[0]['tag_name'];
    $path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'], strlen($_CONF['site_url']) + 1) . '/';
    $upload_success = false;
    //Download the zip file from repository
    $source = "https://codeload.github.com/{$_MONITOR_CONF['repository']}/{$plugin}/zip/{$version}";
    $destination = fopen($_CONF['path_data'] . $plugin . '.zip', 'w+');
    set_time_limit(0);
    // unlimited max execution time
    $options = array(CURLOPT_FILE => $destination, CURLOPT_TIMEOUT => 28800, CURLOPT_URL => $source, CURLOPT_USERAGENT => $_MONITOR_CONF['repository'], CURLOPT_SSL_VERIFYPEER => false);
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    $plugin_file = $_CONF['path_data'] . $plugin . '.zip';
    // Name the plugin file
    if (!file_exists($plugin_file)) {
        COM_errorLog('MONITOR - Download failed for Plugin: ' . $plugin);
        return 'Download failed for Plugin: ' . $plugin;
    } else {
        chmod($plugin_file, 0755);
    }
    require_once $_CONF['path_system'] . 'classes/unpacker.class.php';
    $archive = new unpacker($plugin_file, 'application/x-zip');
    if ($archive == false) {
        return 72;
    }
    COM_errorLog('MONITOR - Download ' . $plugin . ' plugin: ok');
    $pi_did_exist = false;
    // plugin directory already existed
    $pi_had_entry = false;
    // plugin had an entry in the database
    $pi_was_enabled = false;
    // plugin was enabled
    $alternate = false;
    if (file_exists($_CONF['path'] . 'plugins/' . $plugin)) {
        $pi_did_exist = true;
        // plugin directory already exists
        $pstatus = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '{$plugin}'");
        $A = DB_fetchArray($pstatus);
        if (isset($A['pi_name'])) {
            $pi_had_entry = true;
            $pi_was_enabled = $A['pi_enabled'] == 1;
        }
        if ($pi_was_enabled) {
            // disable temporarily while we move the files around
            DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $plugin);
            COM_errorLog('MONITOR - Disable Plugin: ' . $plugin);
        }
        require_once 'System.php';
        $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin;
        if (file_exists($plugin_dir . '.previous')) {
            @System::rm('-rf ' . $plugin_dir . '.previous');
        }
        if (file_exists($plugin_dir)) {
            rename($plugin_dir, $plugin_dir . '.previous');
            COM_errorLog('MONITOR - Rename: ' . $plugin_dir . ' to ' . $plugin_dir . '.previous');
        }
        $public_dir = $_CONF['path_html'] . $plugin;
        if (file_exists($public_dir . '.previous')) {
            @System::rm('-rf ' . $public_dir . '.previous');
        }
        if (file_exists($public_dir)) {
            rename($public_dir, $public_dir . '.previous');
            COM_errorLog('MONITOR - Rename: ' . $public_dir . ' to ' . $public_dir . '.previous');
        }
        $admin_dir = $path_admin . 'plugins/' . $plugin;
        if (file_exists($admin_dir . '.previous')) {
            @System::rm('-rf ' . $admin_dir . '.previous');
        }
        if (file_exists($admin_dir)) {
            rename($admin_dir, $admin_dir . '.previous');
            COM_errorLog('MONITOR - Rename: ' . $admin_dir . ' to ' . $admin_dir . '.previous');
        }
    }
    $upload_success = false;
    // Extract the uploaded archive to the data directory
    $upload_success = $archive->unpack($_CONF['path_data']);
    if (!$upload_success) {
        //Try alternative unzip
        unset($archive);
        require_once 'Archive/Zip.php';
        $archive = new Archive_Zip($plugin_file);
        if ($archive == false) {
            return 72;
        }
        $params = array('add_path' => $_CONF['path_data']);
        $extract = $archive->extract($params);
        if (is_array($extract)) {
            $upload_success = true;
        }
        $alternate = true;
    }
    if (!$upload_success) {
        COM_errorLog("MONITOR - Can't unzip the archive. Update for {$plugin_dir} plugin failed! Please check the archive in your data folder. Could be an OS issue during unzip.");
        if (file_exists($plugin_dir . '.previous')) {
            rename($plugin_dir . '.previous', $plugin_dir);
            COM_errorLog('MONITOR - Rename: ' . $plugin_dir . '.previous' . ' to ' . $plugin_dir);
        }
        if (file_exists($public_dir . '.previous')) {
            rename($public_dir . '.previous', $public_dir);
            COM_errorLog('MONITOR - Rename: ' . $public_dir . '.previous' . ' to ' . $public_dir);
        }
        if (file_exists($admin_dir . '.previous')) {
            rename($admin_dir . '.previous', $admin_dir);
            COM_errorLog('MONITOR - Rename: ' . $admin_dir . '.previous' . ' to ' . $admin_dir);
        }
        if ($pi_was_enabled) {
            DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin);
            COM_errorLog('MONITOR - Enable Plugin: ' . $plugin);
        }
        return 72;
        exit;
    } else {
        //Move files to plugins directory
        COM_errorLog('MONITOR - Plugin update: ' . $plugin);
        if (!$alternate) {
            $folder_name = $archive->getdir();
        } else {
            $listcontent = $archive->listContent();
            $folder_name = $listcontent[0]['filename'];
            if (substr($folder_name, -1) == '/') {
                $folder_name = substr($folder_name, 0, -1);
            }
        }
        if ($folder_name == '') {
            exit;
        }
        $srcDir = $_CONF['path_data'] . $folder_name;
        $destDir = $_CONF['path'] . 'plugins/' . $plugin;
        //Move from data folder to plugins folder
        rename($srcDir, $destDir);
        $plg_path = $_CONF['path'] . 'plugins/' . $plugin . '/';
        if (file_exists($plg_path . 'public_html')) {
            rename($plg_path . 'public_html', $_CONF['path_html'] . $plugin);
            COM_errorLog('MONITOR - Move ' . $plg_path . 'public_html to ' . $_CONF['path_html'] . $plugin);
        } else {
            COM_errorLog('MONITOR - ' . $plg_path . 'public_html does not exist');
        }
        if (file_exists($plg_path . 'admin')) {
            rename($plg_path . 'admin', $path_admin . 'plugins/' . $plugin);
            COM_errorLog('MONITOR - Move ' . $plg_path . 'admin to ' . $path_admin . 'plugins/' . $plugin);
        } else {
            COM_errorLog('MONITOR - ' . $plg_path . 'admin does not exist');
        }
        unset($archive);
        // Collect some garbage
        // cleanup when uploading a new version
        if ($pi_did_exist) {
            $plugin_dir = $_CONF['path'] . 'plugins/' . $plugin;
            if (file_exists($plugin_dir . '.previous')) {
                @System::rm('-rf ' . $plugin_dir . '.previous');
            }
            $public_dir = $_CONF['path_html'] . $plugin;
            if (file_exists($public_dir . '.previous')) {
                @System::rm('-rf ' . $public_dir . '.previous');
            }
            $admin_dir = $path_admin . 'plugins/' . $plugin;
            if (file_exists($admin_dir . '.previous')) {
                @System::rm('-rf ' . $admin_dir . '.previous');
            }
            if ($pi_was_enabled) {
                DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin);
                COM_errorLog('MONITOR - Enable Plugin: ' . $plugin);
            }
        }
        $msg_with_plugin_name = false;
        if ($pi_did_exist) {
            if ($pi_was_enabled) {
                // check if we have to perform an update
                $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$plugin}'");
                $code_version = PLG_chkVersion($plugin);
                COM_errorLog('MONITOR - Reading' . $plugin . ' plugin installed version: ' . $pi_version . ' and code version: ' . $code_version);
                if (!empty($code_version) && $code_version != $pi_version) {
                    /**
                     * At this point, we would have to call PLG_upgrade().
                     * However, we've loaded the plugin's old functions.inc
                     * (in lib-common.php). We can't load the new one here
                     * now since that would result in duplicate function
                     * definitions. Solution: Trigger a reload (with the new
                     * functions.inc) and continue there.
                     */
                    $url = $_CONF['site_admin_url'] . '/plugins/monitor/index.php' . '?action=continue_upgrade' . '&amp;codeversion=' . urlencode($code_version) . '&amp;piversion=' . urlencode($pi_version) . '&amp;plugin_update=' . urlencode($plugin);
                    COM_errorLog('MONITOR - Update Plugin ' . $plugin . ' from version: ' . $pi_version . ' to code version: ' . $code_version);
                    echo COM_refresh($url);
                    exit;
                } else {
                    $msg = 98;
                    // successfully uploaded
                }
            } else {
                $msg = 98;
                // successfully uploaded
            }
        } elseif (file_exists($plg_path . 'autoinstall.php')) {
            // if the plugin has an autoinstall.php, install it now
            if (plugin_autoinstall($plugin)) {
                PLG_pluginStateChange($plugin, 'installed');
                $msg = 44;
                // successfully installed
            } else {
                $msg = 72;
                // an error occured while installing the plugin
            }
        } else {
            $msg = 98;
            // successfully uploaded
        }
    }
    return $msg;
}
コード例 #10
0
 protected function listArchiveContent(PhingFile $zipfile)
 {
     $zip = new Archive_Zip($zipfile->getAbsolutePath());
     return $zip->listContent();
 }
コード例 #11
0
ファイル: archive.php プロジェクト: BACKUPLIB/mwenhanced
 /**
  * @param	string	The name of the archive
  * @param	mixed	The name of a single file or an array of files
  * @param	string	The compression for the archive
  * @param	string	Path to add within the archive
  * @param	string	Path to remove within the archive
  * @param	boolean	Automatically append the extension for the archive
  * @param	boolean	Remove for source files
  */
 function create($archive, $files, $compress = 'tar', $addPath = '', $removePath = '', $autoExt = false, $cleanUp = false)
 {
     $compress = strtolower($compress);
     if ($compress == 'tgz' || $compress == 'tbz' || $compress == 'tar') {
         require_once _EXT_PATH . '/libraries/Tar.php';
         if (is_string($files)) {
             $files = array($files);
         }
         if ($autoExt) {
             $archive .= '.' . $compress;
         }
         if ($compress == 'tgz') {
             $compress = 'gz';
         }
         if ($compress == 'tbz') {
             $compress = 'bz2';
         }
         $tar = new Archive_Tar($archive, $compress);
         $tar->setErrorHandling(PEAR_ERROR_PRINT);
         $result = $tar->addModify($files, $addPath, $removePath);
         return $result;
     }
     if ($compress == 'zip') {
         /*require_once( _EXT_PATH.'/libraries/lib_zip.php' );
         		$zip = new ZipFile();
         		$zip->addFileList($files, $removePath );
         		return $zip->save($archive);
         		*/
         require_once _EXT_PATH . '/libraries/Zip.php';
         $zip = new Archive_Zip($archive);
         $result = $zip->add($files, array('add_path' => $addPath, 'remove_path' => $removePath));
         /*require_once( _EXT_PATH.'/libraries/pclzip.lib.php' );
         		$zip = new PclZip($archive);
         		$result = $zip->add($files, PCLZIP_OPT_ADD_PATH, $addPath, PCLZIP_OPT_REMOVE_PATH, $removePath );
         		*/
         if ($result == 0) {
             return new PEAR_Error('Unrecoverable error "' . $zip->errorInfo(true) . '"');
         }
     }
 }
コード例 #12
0
ファイル: extract.php プロジェクト: shamblett/janitor
 function execAction($dir, $item)
 {
     global $mosConfig_absolute_path;
     if (!ext_isArchive($item)) {
         ext_Result::sendResult('archive', false, ext_Lang::err('extract_noarchive'));
     } else {
         $archive_name = realpath(get_abs_item($dir, $item));
         $file_info = pathinfo($archive_name);
         if (empty($dir)) {
             $extract_dir = realpath($GLOBALS['home_dir']);
         } else {
             $extract_dir = realpath($GLOBALS['home_dir'] . "/" . $dir);
         }
         $ext = $file_info["extension"];
         switch ($ext) {
             case "zip":
                 require_once _EXT_PATH . "/libraries/Zip.php";
                 $extract_dir = str_replace('\\', '/', $extract_dir);
                 $zip = new Archive_Zip($archive_name);
                 $res = $zip->extract(array('add_path' => $extract_dir));
                 if ($res == 0) {
                     ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure') . ' (' . $zip->errorInfo(true) . ')');
                 } else {
                     ext_Result::sendResult('extract', false, ext_Lang::msg('extract_success'));
                 }
                 break;
             case "gz":
                 // a
             // a
             case "bz":
                 // lot
             // lot
             case "bz2":
                 // of
             // of
             case "bzip2":
                 // fallthroughs,
             // fallthroughs,
             case "tbz":
                 // don't
             // don't
             case "tar":
                 // wonder
                 require_once _EXT_PATH . "/libraries/Tar.php";
                 $archive = new Archive_Tar($archive_name);
                 if ($archive->extract($extract_dir)) {
                     ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success'));
                 } else {
                     ext_Result::sendResult('extract', false, ext_Lang::err('extract_failure'));
                 }
                 break;
             default:
                 ext_Result::sendResult('extract', false, ext_Lang::err('extract_unknowntype'));
                 break;
         }
         /*
         require_once (_EXT_PATH . "/libraries/Archive/archive.php") ;
         
         $result = extArchive::extract( $archive_name, $extract_dir ) ;
         if( PEAR::isError( $result ) ) {
         	ext_Result::sendResult( 'extract', false, ext_Lang::err( 'extract_failure' ) . ': ' . $result->getMessage() ) ;
         }
         */
         ext_Result::sendResult('extract', true, ext_Lang::msg('extract_success'));
     }
 }
コード例 #13
0
 public function install_extension_confirm()
 {
     if ($_FILES['mod_archive']['error'] != UPLOAD_ERR_OK) {
         switch ($_FILES['mod_archive']['error']) {
             case UPLOAD_ERR_INI_SIZE:
             case UPLOAD_ERR_FORM_SIZE:
                 //					echo gt('The file you uploaded exceeded the size limits for the server.').'<br />';
                 flash('error', gt('The file you uploaded exceeded the size limits for the server.'));
                 break;
             case UPLOAD_ERR_PARTIAL:
                 //					echo gt('The file you uploaded was only partially uploaded.').'<br />';
                 flash('error', gt('The file you uploaded was only partially uploaded.'));
                 break;
             case UPLOAD_ERR_NO_FILE:
                 //					echo gt('No file was uploaded.').'<br />';
                 flash('error', gt('No file was uploaded.'));
                 break;
         }
     } else {
         $basename = basename($_FILES['mod_archive']['name']);
         // Check future radio buttons
         // for now, try auto-detect
         $compression = null;
         $ext = '';
         if (substr($basename, -4, 4) == '.tar') {
             $compression = null;
             $ext = '.tar';
         } else {
             if (substr($basename, -7, 7) == '.tar.gz') {
                 $compression = 'gz';
                 $ext = '.tar.gz';
             } else {
                 if (substr($basename, -4, 4) == '.tgz') {
                     $compression = 'gz';
                     $ext = '.tgz';
                 } else {
                     if (substr($basename, -8, 8) == '.tar.bz2') {
                         $compression = 'bz2';
                         $ext = '.tar.bz2';
                     } else {
                         if (substr($basename, -4, 4) == '.zip') {
                             $compression = 'zip';
                             $ext = '.zip';
                         }
                     }
                 }
             }
         }
         if ($ext == '') {
             //				echo gt('Unknown archive format. Archives must either be regular ZIP files, TAR files, Gzipped Tarballs, or Bzipped Tarballs.').'<br />';
             flash('error', gt('Unknown archive format. Archives must either be regular ZIP files, TAR files, Gzipped Tarballs, or Bzipped Tarballs.'));
         } else {
             // Look for stale sessid directories:
             $sessid = session_id();
             if (file_exists(BASE . "tmp/extensionuploads/{$sessid}") && is_dir(BASE . "tmp/extensionuploads/{$sessid}")) {
                 expFile::removeDirectory("tmp/extensionuploads/{$sessid}");
             }
             $return = expFile::makeDirectory("tmp/extensionuploads/{$sessid}");
             if ($return != SYS_FILES_SUCCESS) {
                 switch ($return) {
                     case SYS_FILES_FOUNDFILE:
                     case SYS_FILES_FOUNDDIR:
                         //							echo gt('Found a file in the directory path when creating the directory to store the files in.').'<br />';
                         flash('error', gt('Found a file in the directory path when creating the directory to store the files in.'));
                         break;
                     case SYS_FILES_NOTWRITABLE:
                         //							echo gt('Destination parent is not writable.').'<br />';
                         flash('error', gt('Destination parent is not writable.'));
                         break;
                     case SYS_FILES_NOTREADABLE:
                         //							echo gt('Destination parent is not readable.').'<br />';
                         flash('error', gt('Destination parent is not readable.'));
                         break;
                 }
             }
             $dest = BASE . "tmp/extensionuploads/{$sessid}/archive{$ext}";
             move_uploaded_file($_FILES['mod_archive']['tmp_name'], $dest);
             if ($compression != 'zip') {
                 // If not zip, must be tar
                 include_once BASE . 'external/Tar.php';
                 $tar = new Archive_Tar($dest, $compression);
                 PEAR::setErrorHandling(PEAR_ERROR_PRINT);
                 $return = $tar->extract(dirname($dest));
                 if (!$return) {
                     //						echo '<br />'.gt('Error extracting TAR archive').'<br />';
                     flash('error', gt('Error extracting TAR archive'));
                 } else {
                     //						header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=tar');
                     //						self::verify_extension('tar');
                 }
             } else {
                 // must be zip
                 include_once BASE . 'external/Zip.php';
                 $zip = new Archive_Zip($dest);
                 PEAR::setErrorHandling(PEAR_ERROR_PRINT);
                 if ($zip->extract(array('add_path' => dirname($dest))) == 0) {
                     //						echo '<br />'.gt('Error extracting ZIP archive').':<br />';
                     //						echo $zip->_error_code . ' : ' . $zip->_error_string . '<br />';
                     flash('error', gt('Error extracting ZIP archive: ') . $zip->_error_code . ' : ' . $zip->_error_string . '<br />');
                 } else {
                     //						header('Location: ' . URL_FULL . 'index.php?module=administrationmodule&action=verify_extension&type=zip');
                     //						self::verify_extension('zip');
                 }
             }
             $sessid = session_id();
             $files = array();
             foreach (expFile::listFlat(BASE . 'tmp/extensionuploads/' . $sessid, true, null, array(), BASE . 'tmp/extensionuploads/' . $sessid) as $key => $f) {
                 if ($key != '/archive.tar' && $key != '/archive.tar.gz' && $key != '/archive.tar.bz2' && $key != '/archive.zip') {
                     $files[] = array('absolute' => $key, 'relative' => $f, 'canCreate' => expFile::canCreate(BASE . substr($key, 1)), 'ext' => substr($f, -3, 3));
                 }
             }
             assign_to_template(array('relative' => 'tmp/extensionuploads/' . $sessid, 'files' => $files));
         }
     }
 }
コード例 #14
0
ファイル: fish4.php プロジェクト: jankichaudhari/yii-site
$local_file = $strPath . "/" . $strMMOFile;
// if the file already exists, delete before re-writing
if (file_exists($local_file)) {
    unlink($local_file);
}
// write $render to file
if (!file_put_contents($local_file, $renderMMO)) {
    echo "could not write to file - {$local_file}";
    exit;
}
// add xml to files array
$filesToDelete[] = $local_file;
// write all images and xml file to zip
include 'Archive/Zip.php';
// imports
$obj = new Archive_Zip($strPath . "/" . $strZipFile);
// name of zip file
$files = $filesToDelete;
if ($obj->create($files, array('remove_all_path' => 1))) {
} else {
    $errors[] = 'Error in zip file creation';
}
// delete all files no longer required
foreach ($filesToDelete as $filename) {
    @unlink($filename);
}
/*
FTP Username = pppmgold
FTP Password = kw4djr0x
FTP Hostname = uploads.fish4.co.uk
*/
コード例 #15
0
ファイル: ExtractROIData.php プロジェクト: alonso/fusion
function zip($aszSource, $szDestination)
{
    // include file
    include_once COMMON . "/zip/zip.php";
    // build archive
    $szDirName = dirname($szDestination);
    // specify filename for output file
    $aParams = array();
    $aParams[ARCHIVE_ZIP_PARAM_REMOVE_ALL_PATH] = true;
    $zip = new Archive_Zip($szDestination);
    if (!$zip->create($aszSource, $aParams)) {
        return false;
    } else {
        return true;
    }
}
コード例 #16
0
ファイル: put_templates.php プロジェクト: hiro1173/legacy
}
//ob_buffer over flow
//HACK by suin & nao-pon 2012/01/06
while (ob_get_level() > 0) {
    if (!ob_end_clean()) {
        break;
    }
}
//
// EXTRACT STAGE
//
$orig_filename4check = strtolower($_FILES['tplset_archive']['name']);
if (strtolower(substr($orig_filename4check, -4)) == '.zip') {
    // zip
    require_once dirname(__FILE__) . '/include/Archive_Zip.php';
    $reader = new Archive_Zip($_FILES['tplset_archive']['tmp_name']);
    $files = $reader->extract(array('extract_as_string' => true));
    if (!is_array(@$files)) {
        die($reader->errorName());
    }
    $do_upload = true;
} else {
    if (substr($orig_filename4check, -4) == '.tgz' || substr($orig_filename4check, -7) == '.tar.gz') {
        // tar.gz
        require_once XOOPS_ROOT_PATH . '/class/class.tar.php';
        $tar = new tar();
        $tar->openTar($_FILES['tplset_archive']['tmp_name']);
        $files = array();
        foreach ($tar->files as $id => $info) {
            $files[] = array('filename' => $info['name'], 'mtime' => $info['time'], 'content' => $info['file']);
        }
コード例 #17
0
            }
            $dest = $ext_filename . "/archive{$ext}";
            move_uploaded_file($_FILES['mod_archive']['tmp_name'], $dest);
            if ($compression != 'zip') {
                // If not zip, must be tar
                include_once BASE . 'external/Tar.php';
                $tar = new Archive_Tar($dest, $compression);
                PEAR::setErrorHandling(PEAR_ERROR_PRINT);
                $return = $tar->extract(dirname($dest));
                if (!$return) {
                    echo '<br />' . $i18n['error_tar'] . '<br />';
                } else {
                    header('Location: ' . URL_FULL . 'index.php?module=AdministrationModule&action=verify_extension&type=tar');
                }
            } else {
                // must be zip
                include_once BASE . 'external/Zip.php';
                $zip = new Archive_Zip($dest);
                PEAR::setErrorHandling(PEAR_ERROR_PRINT);
                if ($zip->extract(array('add_path' => dirname($dest))) == 0) {
                    echo '<br />' . $i18n['error_zip'] . ':<br />';
                    echo $zip->_error_code . ' : ' . $zip->_error_string . '<br />';
                } else {
                    header('Location: ' . URL_FULL . 'index.php?module=AdministrationModule&action=verify_extension&type=zip');
                }
            }
        }
    }
} else {
    echo SITE_403_HTML;
}
コード例 #18
0
 /**
  * Extracts an archive into a destination directory
  *
  * @param string $archivePath    Path to the archive file
  * @param string $destinationDir Destination forlder
  *
  * @return integer The number of extracted files or false if failed
  */
 static function extract($archivePath, $destinationDir)
 {
     if (!is_file($archivePath)) {
         trigger_error("Archive could not be found", E_USER_WARNING);
         return false;
     }
     if (!self::forceDir($destinationDir)) {
         trigger_error("Destination directory not existing", E_USER_WARNING);
         return false;
     }
     $nbFiles = 0;
     $extract = false;
     switch (self::getExtension($archivePath)) {
         case "gz":
         case "tgz":
             $archive = new Archive_Tar($archivePath);
             $nbFiles = count($archive->listContent());
             $extract = $archive->extract($destinationDir);
             if (!$extract) {
                 trigger_error($archive->error_object->message, E_USER_WARNING);
             }
             break;
         case "zip":
             if (class_exists("ZipArchive", false)) {
                 $archive = new ZipArchive();
                 $archive->open($archivePath);
                 $nbFiles = $archive->numFiles;
                 $extract = $archive->extractTo($destinationDir);
             } else {
                 require_once "Archive/Zip.php";
                 $archive = new Archive_Zip($archivePath);
                 $nbFiles = count($archive->listContent());
                 $extract = $archive->extract(array("add_path" => $destinationDir));
             }
             break;
     }
     if (!$extract) {
         return false;
     }
     return $nbFiles;
 }
コード例 #19
0
ファイル: Zip.php プロジェクト: alexzita/alex_blog
 /**
  * Archive_Zip::_check_parameters()
  *
  * { Description }
  *
  * @param integer $p_error_code
  * @param string $p_error_string
  */
 function _check_parameters(&$p_params, $p_default)
 {
     // ----- Check that param is an array
     if (!is_array($p_params)) {
         $this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER, 'Unsupported parameter, waiting for an array');
         return Archive_Zip::errorCode();
     }
     // ----- Check that all the params are valid
     for (reset($p_params); list($v_key, $v_value) = each($p_params);) {
         if (!isset($p_default[$v_key])) {
             $this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER, 'Unsupported parameter with key \'' . $v_key . '\'');
             return Archive_Zip::errorCode();
         }
     }
     // ----- Set the default values
     for (reset($p_default); list($v_key, $v_value) = each($p_default);) {
         if (!isset($p_params[$v_key])) {
             $p_params[$v_key] = $p_default[$v_key];
         }
     }
     // ----- Check specific parameters
     $v_callback_list = array('callback_pre_add', 'callback_post_add', 'callback_pre_extract', 'callback_post_extract');
     for ($i = 0; $i < sizeof($v_callback_list); $i++) {
         $v_key = $v_callback_list[$i];
         if (isset($p_params[$v_key]) && $p_params[$v_key] != '') {
             if (!function_exists($p_params[$v_key])) {
                 $this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAM_VALUE, "Callback '" . $p_params[$v_key] . "()' is not an existing function for " . "parameter '" . $v_key . "'");
                 return Archive_Zip::errorCode();
             }
         }
     }
     return 1;
 }
コード例 #20
0
ファイル: zip_test.php プロジェクト: jankichaudhari/yii-site
<?php

include 'Archive/Zip.php';
// imports
$obj = new Archive_Zip('test.zip');
// name of zip file
$files = array('client2area.php', 'edit_property.php', 'find_property_orphan.php');
// files to store
if ($obj->create($files)) {
    echo 'Created successfully!';
} else {
    echo 'Error in file creation';
}