Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * This file contains the cZipArchive util class.
  5:  *
  6:  * @package Core
  7:  * @subpackage Util
  8:  * @version SVN Revision $Rev:$
  9:  *
 10:  * @author claus.schunk@4fb.de
 11:  * @copyright four for business AG <www.4fb.de>
 12:  * @license http://www.contenido.org/license/LIZENZ.txt
 13:  * @link http://www.4fb.de
 14:  * @link http://www.contenido.org
 15:  */
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * This class contains the functionalities to handle zip archives.
 20:  *
 21:  * @author claus.schunk@4fb.de
 22:  */
 23: class cZipArchive {
 24: 
 25:     /**
 26:      * Read all files from given path excluding files which names start with a
 27:      * dot or are not valid according to CONTENIDO standards
 28:      * (validateFilename()).
 29:      *
 30:      * @param string $dirPath
 31:      * @return array of files
 32:      * @see cFileHandler::validateFilename()
 33:      */
 34:     public static function readExistingFiles($dirPath) {
 35: 
 36:         // check if $dirPath is a dir
 37:         if (!is_dir($dirPath)) {
 38:             return array();
 39:         }
 40: 
 41:         // try to read $dirPath
 42:         if (false === ($handle = cDirHandler::read($dirPath))) {
 43:             return array();
 44:         }
 45:         
 46:         $array = array();
 47:         foreach ($handle as $file) {
 48:             if (cFileHandler::fileNameBeginsWithDot($file)) {
 49:                 // exclude file if name starts with a dot
 50:                 // hotfix : fileHandler returns filename '.' als valid filename
 51:                 continue;
 52:             } else if (!cFileHandler::validateFilename($file, false)) {
 53:                 // exclude file if name is not valid according to CONTENIDO
 54:                 // standards
 55:                 continue;
 56:             } else {
 57:                 $array[] = $file;
 58:             }
 59:         }
 60: 
 61:         // return array of files
 62:         return $array;
 63:     }
 64: 
 65:     /**
 66:      * This function checks if the given path already exists.
 67:      *
 68:      * @param string $dirPath
 69:      * @return boolean
 70:      */
 71:     public static function isExtracted($dirPath) {
 72:         if (!file_exists($dirPath)) {
 73:             return false;
 74:         } else if (!is_dir($dirPath)) {
 75:             return false;
 76:         } else {
 77:             return true;
 78:         }
 79:     }
 80: 
 81:     /**
 82:      * This function contains the functionality to extract archive and overwrite
 83:      * existing files.
 84:      *
 85:      * @param string $file zip file
 86:      * @param string $extractPath extraction path
 87:      * @param string $extractPathUserInput user specified extraction path
 88:      */
 89:     public static function extractOverRide($file, $extractPath, $extractPathUserInput = NULL) {
 90: 
 91:         // validate user input
 92:         if (isset($extractPathUserInput)) {
 93:             $extractPath .= uplCreateFriendlyName($extractPathUserInput);
 94:         }
 95: 
 96:         $zip = new ZipArchive();
 97: 
 98:         // try to open archive
 99:         if (!$zip->open($file)) {
100:             echo ('can not open zip file!');
101:             return;
102:         }
103: 
104:         for ($i = 0; $i < $zip->numFiles; $i++) {
105:             $file = $zip->getNameIndex($i);
106:             // remove '/' for validation -> directory names
107:             $tmpFile = str_replace('/', '', $file);
108:             // extract only file with valid filename
109:             if (cFileHandler::validateFilename($tmpFile, FALSE) && (substr($tmpFile, 0, 1) != '.') && (substr($tmpFile, 0, 1) != '_')) {
110:                 $zip->extractTo($extractPath, $file);
111:             }
112:         }
113: 
114:         $zip->close();
115:     }
116: 
117:     /**
118:      * This function contains the functionality to extract archive.
119:      *
120:      * @param string $file zip file
121:      * @param string $extractPath extraction path
122:      * @param string $extractPathUserInput user specified extraction path
123:      */
124:     public static function extract($file, $extractPath, $extractPathUserInput = NULL) {
125:         if (isset($extractPathUserInput)) {
126: 
127:             // validate user input
128:             $extractPath .= uplCreateFriendlyName($extractPathUserInput);
129:         }
130: 
131:         if (file_exists($extractPath) and is_dir($extractPath)) {
132:             $ar = cZipArchive::readExistingFiles($extractPath);
133:         }
134:         $zip = new ZipArchive();
135: 
136:         // try to open archive
137:         if (!$zip->open($file)) {
138:             echo ('can not open zip file!');
139:             return;
140:         }
141: 
142:         // check if directory already exist
143:         if (cZipArchive::isExtracted($extractPath)) {
144:             for ($i = 0; $i < $zip->numFiles; $i++) {
145:                 $file = $zip->getNameIndex($i);
146:                 $tmpFile = str_replace('/', '', $file);
147:                 if (cFileHandler::validateFilename($tmpFile, FALSE) && (substr($tmpFile, 0, 1) != '.') && (substr($tmpFile, 0, 1) != '_')) {
148:                     if (!file_exists($extractPath . '/' . $file)) {
149:                         $zip->extractTo($extractPath, $file);
150:                     }
151:                 }
152:             }
153:         } else {
154:             for ($i = 0; $i < $zip->numFiles; $i++) {
155:                 $file = $zip->getNameIndex($i);
156:                 // remove '/' for validation -> directory names
157:                 $tmpFile = str_replace('/', '', $file);
158:                 if (cFileHandler::validateFilename($tmpFile, FALSE) && (substr($tmpFile, 0, 1) != '.') && (substr($tmpFile, 0, 1) != '_')) {
159:                     $zip->extractTo($extractPath, $file);
160:                 }
161:             }
162:         }
163:         $zip->close();
164:     }
165: 
166:     /**
167:      * This function contains the functionality to create archives.
168:      *
169:      * @param string $zipFilePath file path
170:      * @param string $dirPath directory path
171:      * @param array $filePathes files to store in archive
172:      */
173:     public static function createZip($zipFilePath, $dirPath, array $filePathes) {
174:         $zip = new ZipArchive();
175:         if ($zip->open($dirPath . $zipFilePath, ZipArchive::CREATE) == TRUE) {
176:             foreach ($filePathes as $key => $file) {
177:                 $zip->addFile($dirPath . $file, $file);
178:             }
179:             $zip->close();
180:         }
181:     }
182: }
183: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen