Overview

Packages

  • admin
  • classes
    • media
  • CodeIgniter
    • Libraries
  • core
  • functions
  • JSMin
  • None
  • OpenID
  • PHP
  • PHPMailer
  • plugins
    • admin
    • development
    • feed
    • mail
    • media
    • misc
    • seo
    • spam
    • uploader
    • users
    • zenpage
    • zenphoto
      • news
  • Services
    • JSON

Classes

  • _zp_captcha
  • _zp_HTML_cache
  • admin_approval
  • Album
  • AlbumBase
  • AlbumZip
  • AMFReader
  • AMFStream
  • AnyFile
  • AnyFile_Options
  • Auth_OpenID
  • Auth_OpenID_AlreadySigned
  • Auth_OpenID_AssociateRequest
  • Auth_OpenID_Association
  • Auth_OpenID_AuthRequest
  • Auth_OpenID_AX
  • Auth_OpenID_AX_AttrInfo
  • Auth_OpenID_AX_Error
  • Auth_OpenID_AX_FetchRequest
  • Auth_OpenID_AX_FetchResponse
  • Auth_OpenID_AX_KeyValueMessage
  • Auth_OpenID_AX_Message
  • Auth_OpenID_AX_StoreRequest
  • Auth_OpenID_AX_StoreResponse
  • Auth_OpenID_BcMathWrapper
  • Auth_OpenID_CancelResponse
  • Auth_OpenID_CheckAuthRequest
  • Auth_OpenID_CheckIDRequest
  • Auth_OpenID_Consumer
  • Auth_OpenID_ConsumerResponse
  • Auth_OpenID_CryptUtil
  • Auth_OpenID_DatabaseConnection
  • Auth_OpenID_Decoder
  • Auth_OpenID_DiffieHellman
  • Auth_OpenID_DiffieHellmanSHA1ConsumerSession
  • Auth_OpenID_DiffieHellmanSHA1ServerSession
  • Auth_OpenID_DiffieHellmanSHA256ConsumerSession
  • Auth_OpenID_DiffieHellmanSHA256ServerSession
  • Auth_OpenID_DumbStore
  • Auth_OpenID_Encoder
  • Auth_OpenID_EncodingError
  • Auth_OpenID_Extension
  • Auth_OpenID_FailureResponse
  • Auth_OpenID_FileStore
  • Auth_OpenID_GenericConsumer
  • Auth_OpenID_GmpMathWrapper
  • Auth_OpenID_KVForm
  • Auth_OpenID_MalformedReturnURL
  • Auth_OpenID_MalformedTrustRoot
  • Auth_OpenID_Mapping
  • Auth_OpenID_MathLibrary
  • Auth_OpenID_MDB2Store
  • Auth_OpenID_MemcachedStore
  • Auth_OpenID_Message
  • Auth_OpenID_MySQLStore
  • Auth_OpenID_NamespaceMap
  • Auth_OpenID_NoReturnToError
  • Auth_OpenID_OpenIDStore
  • Auth_OpenID_PAPE_Request
  • Auth_OpenID_PAPE_Response
  • Auth_OpenID_Parse
  • Auth_OpenID_PlainTextConsumerSession
  • Auth_OpenID_PlainTextServerSession
  • Auth_OpenID_PostgreSQLStore
  • Auth_OpenID_Request
  • Auth_OpenID_Server
  • Auth_OpenID_ServerError
  • Auth_OpenID_ServerErrorContainer
  • Auth_OpenID_ServerRequest
  • Auth_OpenID_ServerResponse
  • Auth_OpenID_ServiceEndpoint
  • Auth_OpenID_ServiceEndpointLoader
  • Auth_OpenID_SessionNegotiator
  • Auth_OpenID_SetupNeededResponse
  • Auth_OpenID_Signatory
  • Auth_OpenID_SigningEncoder
  • Auth_OpenID_SQLiteStore
  • Auth_OpenID_SQLStore
  • Auth_OpenID_SRegBase
  • Auth_OpenID_SRegRequest
  • Auth_OpenID_SRegResponse
  • Auth_OpenID_SuccessResponse
  • Auth_OpenID_TrustRoot
  • Auth_OpenID_TypeURIMismatch
  • Auth_OpenID_UntrustedReturnURL
  • Auth_OpenID_WebResponse
  • Auth_Yadis_Discovery
  • Auth_Yadis_DiscoveryResult
  • Auth_Yadis_dom
  • Auth_Yadis_domxml
  • Auth_Yadis_HTTPFetcher
  • Auth_Yadis_HTTPResponse
  • Auth_Yadis_Manager
  • Auth_Yadis_ManagerLoader
  • Auth_Yadis_ParanoidHTTPFetcher
  • Auth_Yadis_ParseHTML
  • Auth_Yadis_PHPSession
  • Auth_Yadis_PlainHTTPFetcher
  • Auth_Yadis_ProxyResolver
  • Auth_Yadis_Service
  • Auth_Yadis_SessionLoader
  • Auth_Yadis_XMLParser
  • Auth_Yadis_XRDS
  • Auth_Yadis_Yadis
  • auto_backup
  • AVCSequenceParameterSetReader
  • bxslider
  • cacheManager
  • cacheManagerFeed
  • CI_jsmin
  • CI_load
  • cloneZenphoto
  • codeIgniter_kludge
  • colorbox
  • Comment
  • comment_form
  • contactformOptions
  • crop_image
  • cycle
  • defaultCodeblocks
  • deprecated_functions
  • DownloadList
  • dynamic_locale
  • dynamicAlbum
  • elFinder_options
  • email_new_user
  • exampleMacros
  • external_auth
  • ExternalFeed
  • externalFeed_options
  • favorites
  • favoritesOptions
  • federated_logon
  • feed
  • fieldExtender
  • flag_thumbnail
  • Gallery
  • galleryArticles
  • getID3
  • getid3_aac
  • getid3_apetag
  • getid3_flv
  • getid3_handler
  • getid3_id3v1
  • getid3_id3v2
  • getid3_lib
  • getid3_lyrics3
  • getid3_mp3
  • getid3_mpeg
  • getid3_quicktime
  • getid3_swf
  • GoogleMap
  • Googlemaps
  • googleVerifyOptions
  • hitcounter
  • HTML
  • htmlmetatags
  • http_auth
  • Image
  • image_effects
  • internal_deprecations
  • ipBlocker
  • jcarousel
  • jPlayer
  • jplayer_options
  • jquery_rating
  • JSMin
  • lib_GD_Options
  • lib_Imagick_Options
  • lib_NoGraphics
  • MediaObject
  • menu_manager
  • MergedRSS
  • MergedRSSOptions
  • mobile
  • Mobile_Detect
  • mobileTheme
  • multipleLayoutOptions
  • null_seo
  • OAuthConsumer
  • OAuthDataStore
  • OAuthRequest
  • OAuthServer
  • OAuthSignatureMethod
  • OAuthSignatureMethod_HMAC_SHA1
  • OAuthSignatureMethod_PLAINTEXT
  • OAuthSignatureMethod_RSA_SHA1
  • OAuthToken
  • OAuthUtil
  • pagedThumbsNav
  • pagedthumbsOptions
  • PclZip
  • PersistentObject
  • PHPMailer
  • PlainText
  • POP3
  • print_album_menu
  • pseudoPlayer
  • publishContent
  • quota_manager
  • reCaptcha
  • ReCaptchaResponse
  • register_user
  • rewriteRules
  • rewriteTokens
  • RSS
  • RSS_internal_deprecations
  • rss_options
  • search_statistics
  • SearchEngine
  • security_logger
  • seo_locale
  • Services_JSON
  • Services_JSON_Error
  • setupexternalFeed
  • setupRSS
  • show_not_loggedin
  • sitemap
  • slideshow
  • SMTP
  • static_html_cache
  • tagsuggest
  • TextObject
  • TextObject_internal_deprecations
  • TextObject_Options
  • ThemeObject
  • themeSwitcher
  • tinymce4Options
  • tinyURL
  • Transientimage
  • tweet
  • TwitterOAuth
  • UploadHandler
  • user_expiry
  • user_groups
  • user_logout_options
  • userAddressFields
  • utf8
  • Video
  • Video_internal_deprecations
  • VideoObject_Options
  • viewer_size_image_options
  • WEBdocs
  • WEBdocs_Options
  • xmpMetadata
  • Zenpage
  • Zenpage_internal_deprecations
  • ZenpageCategory
  • zenpagecms
  • ZenpageItems
  • ZenpageNews
  • ZenpagePage
  • ZenpageRoot
  • Zenphoto_Administrator
  • Zenphoto_Authority
  • zenphoto_org_news
  • zenphoto_seo
  • zenphotoDonate
  • ZipStream
  • zp_PHPMailer
  • zpCaptcha
  • zpFunctions
  • zpLegacySpam
  • zpMutex
  • zpSimpleSpam
  • zpTrivialSpam

Exceptions

  • BadFunctionCallException
  • BadMethodCallException
  • Exception
  • getid3_exception
  • JSMin_UnterminatedCommentException
  • JSMin_UnterminatedRegExpException
  • JSMin_UnterminatedStringException
  • LogicException
  • OAuthExcept
  • phpmailerException

Functions

  • __autoload
  • _escape_xref
  • _recaptcha_aes_encrypt
  • _recaptcha_aes_pad
  • _recaptcha_http_post
  • _recaptcha_mailhide_email_parts
  • _recaptcha_mailhide_urlbase64
  • _recaptcha_qsencode
  • accessAllAlbums
  • add_context
  • addalbumsToDatabase
  • addCategoriesToDatabase
  • addGeoCoord
  • addItem
  • addPagesToDatabase
  • addPluginScript
  • addPluginType
  • addSubalbumMenus
  • admin_album_list
  • admin_securityChecks
  • admin_showupdate
  • adminPageNav
  • adminToolbox
  • albumNumber
  • applyMacros
  • Auth_OpenID_arrangeByType
  • Auth_OpenID_AX_checkAlias
  • Auth_OpenID_AX_toTypeURIs
  • Auth_OpenID_bestMatchingService
  • Auth_OpenID_checkFieldName
  • Auth_OpenID_checkSessionType
  • Auth_OpenID_checkTimestamp
  • Auth_OpenID_detectMathLibrary
  • Auth_OpenID_discover
  • Auth_OpenID_discoverURI
  • Auth_OpenID_discoverWithoutYadis
  • Auth_OpenID_discoverWithYadis
  • Auth_OpenID_discoverXRI
  • Auth_OpenID_extractReturnURL
  • Auth_OpenID_findOPLocalIdentifier
  • Auth_OpenID_getAllAssociationTypes
  • Auth_OpenID_getAllowedReturnURLs
  • Auth_OpenID_getAuthorityPattern
  • Auth_OpenID_getAvailableSessionTypes
  • Auth_OpenID_getDefaultAssociationOrder
  • Auth_OpenID_getDefaultGen
  • Auth_OpenID_getDefaultMod
  • Auth_OpenID_getDefaultNegotiator
  • Auth_OpenID_getEncodedPattern
  • Auth_OpenID_getEncryptedNegotiator
  • Auth_OpenID_getEscapeRE
  • Auth_OpenID_getMathLib
  • Auth_OpenID_getOnlyEncryptedOrder
  • Auth_OpenID_getOpenIDConsumerTypeURIs
  • Auth_OpenID_getOpenIDTypeName
  • Auth_OpenID_getOpenIDTypeURIs
  • Auth_OpenID_getOPOrUserServices
  • Auth_OpenID_getSecretSize
  • Auth_OpenID_getSessionTypes
  • Auth_OpenID_getSupportedAssociationTypes
  • Auth_OpenID_getUnreserved
  • Auth_OpenID_getURIPattern
  • Auth_OpenID_getURLIllegalCharRE
  • Auth_OpenID_HMACSHA1
  • Auth_OpenID_HMACSHA256
  • Auth_OpenID_include_init
  • Auth_OpenID_isError
  • Auth_OpenID_isOpenID1
  • Auth_OpenID_legacy_discover
  • Auth_OpenID_makeOpenIDEndpoints
  • Auth_OpenID_math_extensions
  • Auth_OpenID_mkNonce
  • Auth_OpenID_noMathSupport
  • Auth_OpenID_pct_encoded_replace
  • Auth_OpenID_pct_encoded_replace_unreserved
  • Auth_OpenID_registerNamespaceAlias
  • Auth_OpenID_remove_dot_segments
  • Auth_OpenID_removeNamespaceAlias
  • Auth_OpenID_returnToMatches
  • Auth_OpenID_setNoMathSupport
  • Auth_OpenID_SHA1
  • Auth_OpenID_SHA256
  • Auth_OpenID_splitNonce
  • Auth_OpenID_supportsSReg
  • Auth_OpenID_urinorm
  • Auth_OpenID_verifyReturnTo
  • Auth_Yadis_array_scramble
  • Auth_Yadis_escapeForIRI
  • Auth_Yadis_getCanonicalID
  • Auth_Yadis_getDefaultProxy
  • Auth_Yadis_getEscapeRE
  • Auth_Yadis_getIPrivateChars
  • Auth_Yadis_getNSMap
  • Auth_Yadis_getServiceEndpoints
  • Auth_Yadis_getSupportedExtensions
  • Auth_Yadis_getUCSChars
  • Auth_Yadis_getXMLParser
  • Auth_Yadis_getXRDExpiration
  • Auth_Yadis_getXrefRE
  • Auth_Yadis_getXRIAuthorities
  • Auth_Yadis_identifierScheme
  • Auth_Yadis_iriToURI
  • Auth_Yadis_pct_escape_unicode
  • Auth_Yadis_providerIsAuthoritative
  • Auth_Yadis_rootAuthority
  • Auth_Yadis_setDefaultParser
  • Auth_Yadis_startswith
  • Auth_Yadis_toIRINormal
  • Auth_Yadis_toURINormal
  • Auth_Yadis_XRI
  • Auth_Yadis_XRIAppendArgs
  • authorSelector
  • build_query
  • build_url
  • bulkActionRedirect
  • bulkTags
  • byteConvert
  • cacheImage
  • checkAccess
  • checkAlbumimagesort
  • checkAlbumParentid
  • checkAlbumPassword
  • checkChosenItemStatus
  • checkChosenMenuset
  • checked
  • checkFolder
  • checkForEmptyTitle
  • checkForGuest
  • checkForPage
  • checkForPassword
  • checkForUpdate
  • checkHitcounterDisplay
  • checkIfChecked
  • checkIfLockedNews
  • checkIfLockedPage
  • checkIfNew
  • checkInstall
  • checkLayoutUseForImages
  • checkNewsAccess
  • checkNewsCategoryPassword
  • checkObjectsThumb
  • checkPagePassword
  • checkPageValidity
  • checkParentLayouts
  • checkPublishDates
  • checkRequiredField
  • checkSelectedAlbum
  • checkSignature
  • cleanAlbum
  • cleanHTML
  • clearSitemapCache
  • clonedFrom
  • codeblocktabsJS
  • comment_form_addComment
  • comment_form_handle_comment
  • comment_form_PaginationJS
  • comment_form_postcomment
  • comment_form_print10Most
  • comment_form_visualEditor
  • commentFormUseCaptcha
  • commentReply
  • commentsAllowed
  • consolidatedEditMessages
  • copyLayoutSelection
  • copyThemeDirectory
  • countArticles
  • countCombiNews
  • createMenuIfNotExists
  • createRelatedItemsResultArray
  • cron_starter
  • currentRelativeURL
  • customOptions
  • dateDiff
  • datepickerJS
  • dateTimeConvert
  • db_affected_rows
  • db_close
  • db_collation
  • db_connect
  • db_count
  • db_create
  • db_create_table
  • db_error
  • db_fetch_assoc
  • db_fetch_row
  • db_free_result
  • db_getSQLmode
  • db_insert_id
  • db_LIKE_escape
  • db_list_fields
  • db_name
  • db_num_rows
  • db_permissions
  • db_quote
  • db_setSQLmode
  • db_show
  • db_software
  • db_table_update
  • db_truncate_table
  • debug404
  • debugLog
  • debugLogBacktrace
  • debugLogVar
  • defaultCodeblocks_codebox
  • deleteArticle
  • deleteCategory
  • deleteItem
  • deleteLayoutSelection
  • deletePage
  • deleteThemeDirectory
  • detect_fetcher
  • detect_math
  • detect_query_corruption
  • detect_random
  • detect_stores
  • detect_xml
  • dircopy
  • displayError
  • doIncludes
  • elFinder_admin_tabs
  • elFinder_tinymce
  • enableExtension
  • escape
  • executeRSS
  • exitZP
  • exposeZenPhotoInformations
  • extensionEnabled
  • fetchComments
  • filesystemToInternal
  • filter_extractReturnURL
  • filter_MatchesAnyOpenIDConsumerType
  • filter_MatchesAnyOpenIDType
  • filterImageQuery
  • fix_path_redirect
  • formatList
  • fullText
  • galleryAlbumsPerPage
  • genAlbumList
  • generateCaptcha
  • generateLanguageList
  • generateListFromArray
  • generateListFromFiles
  • generateRadiobuttonsFromArray
  • generateSitemapCacheFile
  • generateSitemapIndexCacheFile
  • generateUnorderedListFromArray
  • get_AnyFile_suffixes
  • get_context
  • get_filterScript
  • get_instance
  • get_language_string
  • getAdminThumb
  • getAlbumArray
  • getAlbumBreadcrumb
  • getAlbumBreadcrumbAdmin
  • getAlbumCustomData
  • getAlbumData
  • getAlbumDate
  • getAlbumDesc
  • getAlbumFolder
  • getAlbumGeodata
  • getAlbumId
  • getAlbumInherited
  • getAlbumLinkURL
  • getAlbumLocation
  • getAlbumPage
  • getAlbumPlace
  • getAlbumStatistic
  • getAlbumThumb
  • getAlbumTitle
  • getAlbumURL
  • getAllAccessibleAlbums
  • getAllAlbums
  • getAllArticleDates
  • getAllCategories
  • getAllDates
  • getAllowedTags
  • getAllSubAlbumIDs
  • getAllSubalbums
  • getAllTagsCount
  • getAllTagsFromAlbum
  • getAllTagsFromAlbum_multi_unique
  • getAllTagsFromZenpage
  • getAllTagsUnique
  • getAllTranslations
  • getAnnotatedAlbumTitle
  • getAnnotatedImageTitle
  • getArticles
  • getAuthor
  • getBare
  • getBareAlbumDesc
  • getBareAlbumTitle
  • getBareGalleryDesc
  • getBareGalleryTitle
  • getBareImageDesc
  • getBareImageTitle
  • getBareNewsAlbumTitle
  • getBareNewsTitle
  • getBarePageTitle
  • getCategory
  • getCategoryID
  • getCategoryLink
  • getCategoryParentID
  • getCategorySortOrder
  • getCategoryTitle
  • getCheckboxState
  • getCodeblock
  • getCombiNews
  • getCommentAddress
  • getCommentAuthorEmail
  • getCommentAuthorLink
  • getCommentAuthorName
  • getCommentAuthorSite
  • getCommentBody
  • getCommentCount
  • getCommentDate
  • getCommentDateTime
  • getCommentErrors
  • getCommentsAllowed
  • getCommentStored
  • getCommentTime
  • getConsumer
  • getContentShorten
  • getCurrentMenuItem
  • getCurrentNewsArchive
  • getCurrentNewsCategory
  • getCurrentNewsCategoryID
  • getCurrentNewsCategoryParentID
  • getCurrentNewsPage
  • getCurrentPage
  • getCurrentTheme
  • getCustomAlbumThumb
  • getCustomAlbumThumbMaxSpace
  • getCustomImageURL
  • getCustomPageURL
  • getCustomSizedImageMaxSpace
  • getCustomSizedImageThumbMaxSpace
  • getDefaultHeight
  • getDefaultSizedImage
  • getDefaultWidth
  • getDownloadLink
  • getdownloadList
  • getDownloadURL
  • getE
  • getEnabledPlugins
  • getExpiryDatePost
  • getFavoritesURL
  • getField
  • getFirstImageURL
  • getFullHeight
  • getFullImageURL
  • getFullNewsImage
  • getFullWidth
  • getGalleryDesc
  • getGalleryIndexURL
  • getGalleryTitle
  • getGeoCoord
  • getHeadTitle
  • getHitcounter
  • getImageArgs
  • getImageCacheFilename
  • getImageCachePostfix
  • getImageCity
  • getImageCountry
  • getImageCustomData
  • getImageData
  • getImageDate
  • getImageDesc
  • getImageEXIFData
  • getImageGeodata
  • getImageID
  • getImageLinkURL
  • getImageLocation
  • getImageMetaData
  • getImageParameters
  • getImageProcessorURI
  • getImageProcessorURIFromCacheName
  • getImageRotation
  • getImageSortOrder
  • getImageState
  • getImageStatistic
  • getImageThumb
  • getImageTitle
  • getImageURI
  • getImageURL
  • getItem
  • getItemByID
  • getItemTitleAndURL
  • getjPlayerSkinCSS
  • getjPlayerSkins
  • getLanguageArray
  • getLanguageFlag
  • getLastImageURL
  • getLatestComments
  • getLatestNews
  • getLatestZenpageComments
  • getLayout
  • getLayoutSelector
  • getLink
  • getLinkHTML
  • getLogTabs
  • getMacros
  • getMainSiteName
  • getMainSiteURL
  • getManagedAlbumList
  • getMaxSpaceContainer
  • getMenuFromLink
  • getMenuItemChilds
  • getMenuItems
  • getMenumanagerPredicessor
  • getMenumanagerSuccessor
  • getMenuSetSelector
  • getMenuVisibility
  • getMimeString
  • getNestedAlbumList
  • getNewsAdminOption
  • getNewsAdminOptionPath
  • getNewsAlbumName
  • getNewsAlbumTitle
  • getNewsAlbumURL
  • getNewsArchivePath
  • getNewsArchiveURL
  • getNewsAuthor
  • getNewsCategories
  • getNewsCategoryCustomData
  • getNewsCategoryDesc
  • getNewsCategoryPath
  • getNewsCategoryURL
  • getNewsContent
  • getNewsContentShorten
  • getNewsCustomData
  • getNewsDate
  • getNewsExtraContent
  • getNewsID
  • getNewsImageTags
  • getNewsIndexURL
  • getNewsLink
  • getNewsPagesStatistic
  • getNewsPathNav
  • getNewsReadMore
  • getNewsTitle
  • getNewsTitleLink
  • getNewsTitlePath
  • getNewsType
  • getNewsURL
  • getNewsVideoContent
  • getNextAlbum
  • getNextAlbumURL
  • getNextImageThumb
  • getNextImageURL
  • getNextNewsPageURL
  • getNextNewsURL
  • getNextPageURL
  • getNextPrevNews
  • getNotViewableAlbums
  • getNotViewableImages
  • getNumAlbums
  • getNumAllSubalbums
  • getNumImages
  • getNumNews
  • getNumPages
  • getNumSubalbums
  • getOpenIDURL
  • getOption
  • getOptionFromDB
  • getOptionList
  • getPageAuthor
  • getPageContent
  • getPageCustomData
  • getPageDate
  • getPageExtraContent
  • getPageID
  • getPageLastChangeDate
  • getPageLinkPath
  • getPageLinkURL
  • getPageNavList
  • getPageNumURL
  • getPageParentID
  • getPageRedirect
  • getPages
  • getPageSelector
  • getPageSortorder
  • getPageTitle
  • getPageTitleLink
  • getPageURL
  • getParentAlbums
  • getParentAlbumsAdmin
  • getParentBreadcrumb
  • getParentItems
  • getParentMenuItems
  • getParentNewsCategories
  • getParentPages
  • getPasswordProtectImage
  • getPHPFiles
  • getPlugin
  • getPluginFiles
  • getPluginTabs
  • getPrevAlbum
  • getPrevAlbumURL
  • getPrevImageThumb
  • getPrevImageURL
  • getPrevNewsPageURL
  • getPrevNewsURL
  • getPrevPageURL
  • getProtectedImageURL
  • getRandomImages
  • getRandomImagesAlbum
  • getRating
  • getRelatedItems
  • getRequestURI
  • getReturnTo
  • getRSSHeaderLink
  • getRSSLink
  • getScheme
  • getSearchDate
  • getSearchURL
  • getSearchWords
  • getSelectedLayout
  • getSerializedArray
  • getSetClause
  • getSiteHomeURL
  • getSitemapAlbumList
  • getSitemapAlbums
  • getSitemapGoogleImageVideoExtras
  • getSitemapGoogleLoopIndex
  • getSitemapImages
  • getSitemapIndexLinks
  • getSitemapZenpageNewsArticles
  • getSitemapZenpageNewsCategories
  • getSitemapZenpageNewsIndex
  • getSitemapZenpagePages
  • getSizeCustomImage
  • getSizeDefaultImage
  • getSizeDefaultThumb
  • getSizedImageURL
  • getSizeFullImage
  • getStore
  • getSubCategories
  • getSubtabs
  • getSuffix
  • getTagCountByAccess
  • getTagOrder
  • getTags
  • gettext_pl
  • gettext_th
  • getTheme
  • getThemeFiles
  • getThemeOption
  • getTimezones
  • getTinyMCE4ConfigFiles
  • getTitle
  • getTotalArticles
  • getTotalImagesIn
  • getTotalNewsPages
  • getTotalPages
  • getTrustRoot
  • getUnprotectedImageURL
  • getUrAlbum
  • getURL
  • getUserIP
  • getUserLocale
  • getVersion
  • getViewerImageSize
  • getWatermarkParam
  • getWatermarkPath
  • getWatermarks
  • getWhereClause
  • getXSRFToken
  • getZenpageHitcounter
  • getZenpageRSSHeaderLink
  • getZenpageRSSLink
  • getZenpageStatistic
  • googleVerifyHead
  • handleSearchParms
  • hasDynamicAlbumSuffix
  • hasNextImage
  • hasNextPage
  • hasPrevImage
  • hasPrevPage
  • hitcounter
  • html_decode
  • html_encode
  • html_encodeTagged
  • httpsRedirect
  • httpUploadHandler
  • httpUploadHandler_admin_tabs
  • i18nSetLocale
  • imageBlurGD
  • imageDebug
  • imageError
  • imageNumber
  • imgSrcURI
  • in_context
  • inNewsCategory
  • inProtectedNewsCategory
  • installSignature
  • instrument
  • inSubNewsCategoryOf
  • internalToFilesystem
  • inventMenuItem
  • iptc_make_tag
  • is_AdminEditPage
  • is_connected
  • is_GalleryNewsType
  • is_News
  • is_NewsArchive
  • is_NewsArticle
  • is_NewsCategory
  • is_NewsPage
  • is_NewsType
  • is_Pages
  • is_valid_email_zp
  • is_valid_image
  • is_valid_other_type
  • is_zip
  • isAlbumClass
  • isAlbumPage
  • isArchive
  • isHandledAlbum
  • isImageClass
  • isImagePage
  • isImagePhoto
  • isImageVideo
  • isLandscape
  • isMyAlbum
  • isMyNews
  • isMyPage
  • isolate
  • isProtectedAlbum
  • isProtectedNewsCategory
  • isProtectedPage
  • isSubNewsCategoryOf
  • isValidURL
  • jQueryUpload_head
  • jQueryUpload_headers
  • jQueryUploadHandler
  • jQueryUploadHandler_admin_tabs
  • js_encode
  • json_decode
  • json_encode
  • kses
  • kses_array_lc
  • kses_attr
  • kses_bad_protocol
  • kses_bad_protocol_once
  • kses_bad_protocol_once2
  • kses_check_attr_val
  • kses_decode_entities
  • kses_hair
  • kses_hook
  • kses_html_error
  • kses_js_entities
  • kses_no_null
  • kses_normalize_entities
  • kses_normalize_entities2
  • kses_split
  • kses_split2
  • kses_stripslashes
  • kses_version
  • ksesProcess
  • layoutSelector
  • layoutSelector_album
  • listDBUses
  • listDirectoryFiles
  • listUses
  • load_zenpage_news
  • load_zenpage_pages
  • loadLocalOptions
  • log_message
  • lookupSortKey
  • macro_admin_tabs
  • macroList_show
  • makeAlbumCurrent
  • makeImageCurrent
  • makeSpecialImageName
  • markRelease_button
  • mb_strlen
  • mb_strpos
  • mb_strrpos
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • menu_admin_toolbox_global
  • menu_tabs
  • minDiff
  • mkdir_recursive
  • my_truncate_string
  • myts_date
  • newAlbum
  • newImage
  • next_album
  • next_comment
  • next_image
  • next_news
  • next_page
  • ngettext_pl
  • ngettext_th
  • normalizeColumns
  • omsAdditions
  • openedForComments
  • parse_query
  • parse_size
  • parseAllowedTags
  • parseHttpAcceptLanguage
  • passAlbums
  • passImages
  • pathurlencode
  • PclZipUtilCopyBlock
  • PclZipUtilOptionText
  • PclZipUtilPathInclusion
  • PclZipUtilPathReduction
  • PclZipUtilRename
  • PclZipUtilTranslateWinPath
  • PHPMailerAutoload
  • populateManagedObjectsList
  • postAlbumSort
  • postIndexDecode
  • postIndexEncode
  • prefix
  • prepareAlbumPage
  • prepareCustomPage
  • prepareImagePage
  • prepareIndexPage
  • print404status
  • print_language_string_list
  • printAddToFavorites
  • printAdminFooter
  • printAdminHeader
  • printAdminRightsTable
  • printAdminToolbox
  • printAlbumBreadcrumb
  • printAlbumButtons
  • printAlbumCustomData
  • printAlbumData
  • printAlbumDate
  • printAlbumDesc
  • printAlbumEditForm
  • printAlbumEditRow
  • printAlbumLegend
  • printAlbumLink
  • printAlbumLocation
  • printAlbumMap
  • printAlbumMenu
  • printAlbumMenuJump
  • printAlbumMenuList
  • printAlbumMenuListAlbum
  • printAlbumPlace
  • printAlbumRating
  • printAlbumsSelector
  • printAlbumStatistic
  • printAlbumStatisticItem
  • printAlbumThumbImage
  • printAlbumTitle
  • printAlbumURL
  • printAlbumZip
  • printAllDates
  • printAllNewsCategories
  • printAllTags
  • printAllTagsAs
  • printAllTagsFromAlbum
  • printAllTagsFromZenpage
  • printAnnotatedAlbumTitle
  • printAnnotatedImageTitle
  • printArticleCategories
  • printArticleDatesDropdown
  • printArticlesPerPageDropdown
  • printBareAlbumDesc
  • printBareAlbumTitle
  • printBareGalleryDesc
  • printBareGalleryTitle
  • printBareImageDesc
  • printBareImageTitle
  • printBareNewsTitle
  • printBarePageTitle
  • printBulkActions
  • printCaptcha
  • printCategoriesStatistic
  • printCategoryCheckboxListEntry
  • printCategoryDropdown
  • printCategoryListSortableTable
  • printCategorySelection
  • printCodeblock
  • printCodeblockEdit
  • printCommentAuthorLink
  • printCommentErrors
  • printCommentForm
  • printContactForm
  • printCurrentNewsArchive
  • printCurrentNewsCategory
  • printCustomAlbumThumbImage
  • printCustomAlbumThumbMaxSpace
  • printCustomMenu
  • printCustomPageSelector
  • printCustomPageURL
  • printCustomSizedImage
  • printCustomSizedImageMaxHeight
  • printCustomSizedImageMaxSpace
  • printCustomSizedImageThumbMaxSpace
  • printDefaultSizedImage
  • printDownloadAlbumZipURL
  • printDownloadLink
  • printDownloadLinkAlbumZip
  • printdownloadList
  • printDownloadURL
  • printEditable
  • printEditCommentLink
  • printEditDropdown
  • printExpired
  • printFavoritesLink
  • printFavoritesURL
  • printField
  • printGalleryDesc
  • printGalleryIndexURL
  • printGalleryTitle
  • printGoogleMap
  • printHeadTitle
  • printHomeLink
  • printImageCustomData
  • printImageData
  • printImageDate
  • printImageDesc
  • printImageDiv
  • printImageEXIFData
  • printImageID
  • printImageLink
  • printImageMap
  • printImageMetadata
  • printImageRating
  • printImageSortOrder
  • printImageStatistic
  • printImageThumb
  • printImageTitle
  • printImageURL
  • printItemEditLink
  • printItemsList
  • printItemsListTable
  • printItemStatusDropdown
  • printjCarouselThumbNav
  • printjPlayerPlaylist
  • printLanguageSelector
  • printLatestAlbums
  • printLatestComments
  • printLatestImages
  • printLatestImagesByDate
  • printLatestImagesByMtime
  • printLatestNews
  • printLatestUpdatedAlbums
  • printLatestZenpageComments
  • printLink
  • printLinkHTML
  • printLogoAndLinks
  • printManagedObjects
  • printMenuemanagerPageList
  • printMenuemanagerPageListWithNav
  • printMenumanagerBreadcrumb
  • printMenumanagerNextLink
  • printMenumanagerPrevLink
  • printMostPopularItems
  • printMostRatedAlbums
  • printMostRatedImages
  • printMostRatedItems
  • printNestedAlbumsList
  • printNestedItemsList
  • printNestedMenu
  • printNews
  • printNewsArchive
  • printNewsAuthor
  • printNewsCategories
  • printNewsCategoryCustomData
  • printNewsCategoryDesc
  • printNewsCategoryURL
  • printNewsContent
  • printNewsCustomData
  • printNewsDate
  • printNewsExtraContent
  • printNewsImageTags
  • printNewsIndexURL
  • printNewsLink
  • printNewsPageList
  • printNewsPageListWithNav
  • printNewsReadMoreLink
  • printNewsStatistic
  • printNewsTitle
  • printNewsTitleLink
  • printNewsURL
  • printNextNewsLink
  • printNextNewsPageLink
  • printNextPageLink
  • printNextPageURL
  • printPageArticleTags
  • printPageAuthor
  • printPageContent
  • printPageCustomData
  • printPageDate
  • printPagedThumbsNav
  • printPageExtraContent
  • printPageID
  • printPageLastChangeDate
  • printPageLinkURL
  • printPageList
  • printPageListWithNav
  • printPageMenu
  • printPageNav
  • printPageSelector
  • printPagesListTable
  • printPagesStatistic
  • printPageTitle
  • printPageTitleLink
  • printPageURL
  • printParentBreadcrumb
  • printParentPagesBreadcrumb
  • printPasswordForm
  • printPopularAlbums
  • printPopularImages
  • printPreloadScript
  • printPrevNewsLink
  • printPrevNewsPageLink
  • printPrevPageLink
  • printPrevPageURL
  • printPublished
  • printPublishIconLink
  • printRandomImages
  • printRating
  • printRegisterURL
  • printRegistrationForm
  • printRelatedItems
  • printRSSHeaderLink
  • printRSSLink
  • printSearchBreadcrumb
  • printSearchForm
  • printSiteHomeURL
  • printSizedImageLink
  • printSizedImageURL
  • printSlideShow
  • printSlideShowJS
  • printSlideShowLink
  • printSortableHead
  • printSortOrderDropdown
  • printSubPagesExcerpts
  • printSubtabs
  • printTabs
  • printTags
  • printThumbNav
  • printTopRatedAlbums
  • printTopRatedImages
  • printTopRatedItems
  • printUnpublishedDropdown
  • printUserLogin_out
  • printUserSizeImage
  • printUserSizeSelector
  • printVersion
  • printZenJavascripts
  • printZenpageIconLegend
  • printZenpageItemsBreadcrumb
  • printZenpageNewsCategorySelector
  • printZenpagePagesSelector
  • printZenpageRSSHeaderLink
  • printZenpageRSSLink
  • printZenpageStatistic
  • printZenphotoLink
  • process_language_string_save
  • processAlbumBulkActions
  • processAlbumEdit
  • processCodeblockSave
  • processCommentBulkActions
  • processCredentials
  • processCustomOptionSave
  • processEditSelection
  • processExpired
  • processImageBulkActions
  • processImageEdit
  • processManagedObjects
  • processMenuBulkActions
  • processOrder
  • processRights
  • processTags
  • processZenpageBulkActions
  • propSizes
  • publishItem
  • purgeOption
  • query
  • query_full_array
  • query_single_row
  • rc4
  • read_exif_data_protected
  • readTags
  • recaptcha_check_answer
  • recaptcha_get_html
  • recaptcha_get_signup_url
  • recaptcha_mailhide_html
  • recaptcha_mailhide_url
  • reconfigureAction
  • reconfigureCS
  • reconfigurePage
  • recordMissing
  • rem_context
  • removeParentAlbumNames
  • resetCurrentAlbum
  • restore_context
  • reveal
  • rewrite_get_album_image
  • rewrite_path
  • rewrite_path_zenpage
  • RSS_Channel
  • RSS_Retrieve
  • RSS_Tags
  • rulesList
  • run
  • safe_fnmatch
  • safe_glob
  • sanitize
  • sanitize_numeric
  • sanitize_path
  • sanitize_script
  • sanitize_string
  • sanitizeRedirect
  • save_context
  • saveLayoutSelection
  • saveZenphotoLayoutSelection
  • search_quote
  • secureServer
  • seo_cleanup_button
  • seoFriendly
  • seoFriendlyJS
  • set_context
  • setAlbumCustomData
  • setAlbumSubtabs
  • setImageCustomData
  • setMainDomain
  • setOption
  • setOptionDefault
  • setPluginDomain
  • setThemeColumns
  • setThemeDomain
  • setThemeOption
  • setThemeOptionDefault
  • setupAllowedMaps
  • setupCurrentLocale
  • setupDomain
  • setupTheme
  • shortenContent
  • showOrNotShowField
  • shuffle_assoc
  • signatureChange
  • site_upgrade_button
  • site_upgrade_status
  • sitemap_echonl
  • sitemap_getChangefreq
  • sitemap_getDateformat
  • sitemap_getDBLimit
  • sitemap_getISO8601Date
  • skipScheduledPublishing
  • sortByKey
  • sortByMultilingual
  • sortMultiArray
  • standardScripts
  • standardThemeOptions
  • stickyNews
  • storeConfig
  • storeTags
  • stripSuffix
  • submenuOf
  • switchLog
  • tagSelector
  • tagSuggestJS
  • tagSuggestJS_admin
  • tagSuggestJS_frontend
  • themeIsEditable
  • themeSetup
  • timezoneDiff
  • tinymce4ConfigJS
  • truncate_string
  • unpublishedZenphotoItemCheck
  • unpublishSubalbums
  • unQuote
  • unzip
  • updateArticle
  • updateCacheName
  • updateCategory
  • updateConfigItem
  • updateItemSortorder
  • updateItemsSortorder
  • updateMenuItem
  • updatePage
  • upload_extra
  • upload_form
  • upload_head
  • user_mailing_list_button
  • validateLocale
  • wordpress_import_button
  • wp_prefix
  • wp_query_full_array
  • wpimport_TryAgainError
  • XSRFdefender
  • XSRFToken
  • zenJavascript
  • zenpageAlbumImage
  • zenpageBulkActionMessage
  • zenpageHitcounter
  • zenpageJSCSS
  • zenpageOpenedForComments
  • zenpagePublish
  • zenphoto_PHPMailer
  • zenphoto_sendmail
  • zenPhotoTheme
  • zp_apply_filter
  • zp_clearCookie
  • zp_colorAllocate
  • zp_cookieEncode
  • zp_copyCanvas
  • zp_createImage
  • zp_drawRectangle
  • zp_error
  • zp_filter_slot
  • zp_filter_unique_id
  • zp_getCookie
  • zp_getFonts
  • zp_graphicsLibInfo
  • zp_handle_password
  • zp_handle_password_single
  • zp_has_filter
  • zp_image_types
  • zp_imageCanRotate
  • zp_imageColorTransparent
  • zp_imageDims
  • zp_imageFill
  • zp_imageFontHeight
  • zp_imageFontWidth
  • zp_imageFromString
  • zp_imageGet
  • zp_imageGray
  • zp_imageHeight
  • zp_imageIPTC
  • zp_imageKill
  • zp_imageLoadFont
  • zp_imageMerge
  • zp_imageOutput
  • zp_imageResizeAlpha
  • zp_imageUnsharpMask
  • zp_imageWidth
  • zp_load_album
  • zp_load_gallery
  • zp_load_image
  • zp_load_page
  • zp_load_request
  • zp_load_search
  • zp_loggedin
  • zp_mail
  • zp_register_filter
  • zp_remove_filter
  • zp_resampleImage
  • zp_rotateImage
  • zp_session_start
  • zp_setCookie
  • zp_writeString
  • zpErrorHandler
  • zpFormattedDate
  • zpRewriteURL
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
   1: <?php
   2: // --------------------------------------------------------------------------------
   3: // PhpConcept Library - Zip Module 2.8.2
   4: // --------------------------------------------------------------------------------
   5: // License GNU/LGPL - Vincent Blavet - August 2009
   6: // http://www.phpconcept.net
   7: // --------------------------------------------------------------------------------
   8: //
   9: // Presentation :
  10: //   PclZip is a PHP library that manage ZIP archives.
  11: //   So far tests show that archives generated by PclZip are readable by
  12: //   WinZip application and other tools.
  13: //
  14: // Description :
  15: //   See readme.txt and http://www.phpconcept.net
  16: //
  17: // Warning :
  18: //   This library and the associated files are non commercial, non professional
  19: //   work.
  20: //   It should not have unexpected results. However if any damage is caused by
  21: //   this software the author can not be responsible.
  22: //   The use of this software is at the risk of the user.
  23: //
  24: // --------------------------------------------------------------------------------
  25: // $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $
  26: // --------------------------------------------------------------------------------
  27: 
  28:   // ----- Constants
  29:   if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
  30:     define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
  31:   }
  32: 
  33:   // ----- File list separator
  34:   // In version 1.x of PclZip, the separator for file list is a space
  35:   // (which is not a very smart choice, specifically for windows paths !).
  36:   // A better separator should be a comma (,). This constant gives you the
  37:   // abilty to change that.
  38:   // However notice that changing this value, may have impact on existing
  39:   // scripts, using space separated filenames.
  40:   // Recommanded values for compatibility with older versions :
  41:   //define( 'PCLZIP_SEPARATOR', ' ' );
  42:   // Recommanded values for smart separation of filenames.
  43:   if (!defined('PCLZIP_SEPARATOR')) {
  44:     define( 'PCLZIP_SEPARATOR', ',' );
  45:   }
  46: 
  47:   // ----- Error configuration
  48:   // 0 : PclZip Class integrated error handling
  49:   // 1 : PclError external library error handling. By enabling this
  50:   //     you must ensure that you have included PclError library.
  51:   // [2,...] : reserved for futur use
  52:   if (!defined('PCLZIP_ERROR_EXTERNAL')) {
  53:     define( 'PCLZIP_ERROR_EXTERNAL', 0 );
  54:   }
  55: 
  56:   // ----- Optional static temporary directory
  57:   //       By default temporary files are generated in the script current
  58:   //       path.
  59:   //       If defined :
  60:   //       - MUST BE terminated by a '/'.
  61:   //       - MUST be a valid, already created directory
  62:   //       Samples :
  63:   // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  64:   // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  65:   if (!defined('PCLZIP_TEMPORARY_DIR')) {
  66:     define( 'PCLZIP_TEMPORARY_DIR', '' );
  67:   }
  68: 
  69:   // ----- Optional threshold ratio for use of temporary files
  70:   //       Pclzip sense the size of the file to add/extract and decide to
  71:   //       use or not temporary file. The algorythm is looking for
  72:   //       memory_limit of PHP and apply a ratio.
  73:   //       threshold = memory_limit * ratio.
  74:   //       Recommended values are under 0.5. Default 0.47.
  75:   //       Samples :
  76:   // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 );
  77:   if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
  78:     define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
  79:   }
  80: 
  81: // --------------------------------------------------------------------------------
  82: // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  83: // --------------------------------------------------------------------------------
  84: 
  85:   // ----- Global variables
  86:   $g_pclzip_version = "2.8.2";
  87: 
  88:   // ----- Error codes
  89:   //   -1 : Unable to open file in binary write mode
  90:   //   -2 : Unable to open file in binary read mode
  91:   //   -3 : Invalid parameters
  92:   //   -4 : File does not exist
  93:   //   -5 : Filename is too long (max. 255)
  94:   //   -6 : Not a valid zip file
  95:   //   -7 : Invalid extracted file size
  96:   //   -8 : Unable to create directory
  97:   //   -9 : Invalid archive extension
  98:   //  -10 : Invalid archive format
  99:   //  -11 : Unable to delete file (unlink)
 100:   //  -12 : Unable to rename file (rename)
 101:   //  -13 : Invalid header checksum
 102:   //  -14 : Invalid archive size
 103:   define( 'PCLZIP_ERR_USER_ABORTED', 2 );
 104:   define( 'PCLZIP_ERR_NO_ERROR', 0 );
 105:   define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
 106:   define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
 107:   define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
 108:   define( 'PCLZIP_ERR_MISSING_FILE', -4 );
 109:   define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
 110:   define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
 111:   define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
 112:   define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
 113:   define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
 114:   define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
 115:   define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
 116:   define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
 117:   define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
 118:   define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
 119:   define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
 120:   define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
 121:   define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
 122:   define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
 123:   define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
 124:   define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
 125:   define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
 126: 
 127:   // ----- Options values
 128:   define( 'PCLZIP_OPT_PATH', 77001 );
 129:   define( 'PCLZIP_OPT_ADD_PATH', 77002 );
 130:   define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
 131:   define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
 132:   define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
 133:   define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
 134:   define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
 135:   define( 'PCLZIP_OPT_BY_NAME', 77008 );
 136:   define( 'PCLZIP_OPT_BY_INDEX', 77009 );
 137:   define( 'PCLZIP_OPT_BY_EREG', 77010 );
 138:   define( 'PCLZIP_OPT_BY_PREG', 77011 );
 139:   define( 'PCLZIP_OPT_COMMENT', 77012 );
 140:   define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
 141:   define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
 142:   define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
 143:   define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
 144:   define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
 145:   // Having big trouble with crypt. Need to multiply 2 long int
 146:   // which is not correctly supported by PHP ...
 147:   //define( 'PCLZIP_OPT_CRYPT', 77018 );
 148:   define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
 149:   define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
 150:   define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
 151:   define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
 152:   define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
 153:   define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
 154:   define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
 155: 
 156:   // ----- File description attributes
 157:   define( 'PCLZIP_ATT_FILE_NAME', 79001 );
 158:   define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
 159:   define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
 160:   define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
 161:   define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
 162:   define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
 163: 
 164:   // ----- Call backs values
 165:   define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
 166:   define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
 167:   define( 'PCLZIP_CB_PRE_ADD', 78003 );
 168:   define( 'PCLZIP_CB_POST_ADD', 78004 );
 169:   /* For futur use
 170:   define( 'PCLZIP_CB_PRE_LIST', 78005 );
 171:   define( 'PCLZIP_CB_POST_LIST', 78006 );
 172:   define( 'PCLZIP_CB_PRE_DELETE', 78007 );
 173:   define( 'PCLZIP_CB_POST_DELETE', 78008 );
 174:   */
 175: 
 176:   // --------------------------------------------------------------------------------
 177:   // Class : PclZip
 178:   // Description :
 179:   //   PclZip is the class that represent a Zip archive.
 180:   //   The public methods allow the manipulation of the archive.
 181:   // Attributes :
 182:   //   Attributes must not be accessed directly.
 183:   // Methods :
 184:   //   PclZip() : Object creator
 185:   //   create() : Creates the Zip archive
 186:   //   listContent() : List the content of the Zip archive
 187:   //   extract() : Extract the content of the archive
 188:   //   properties() : List the properties of the archive
 189:   // --------------------------------------------------------------------------------
 190:   class PclZip
 191:   {
 192:     // ----- Filename of the zip file
 193:     var $zipname = '';
 194: 
 195:     // ----- File descriptor of the zip file
 196:     var $zip_fd = 0;
 197: 
 198:     // ----- Internal error handling
 199:     var $error_code = 1;
 200:     var $error_string = '';
 201: 
 202:     // ----- Current status of the magic_quotes_runtime
 203:     // This value store the php configuration for magic_quotes
 204:     // The class can then disable the magic_quotes and reset it after
 205:     var $magic_quotes_status;
 206: 
 207:   // --------------------------------------------------------------------------------
 208:   // Function : PclZip()
 209:   // Description :
 210:   //   Creates a PclZip object and set the name of the associated Zip archive
 211:   //   filename.
 212:   //   Note that no real action is taken, if the archive does not exist it is not
 213:   //   created. Use create() for that.
 214:   // --------------------------------------------------------------------------------
 215:   function __construct($p_zipname)
 216:   {
 217: 
 218:     // ----- Tests the zlib
 219:     if (!function_exists('gzopen'))
 220:     {
 221:       zp_error('Abort '.basename(__FILE__).' : Missing zlib extensions');
 222:     }
 223: 
 224:     // ----- Set the attributes
 225:     $this->zipname = $p_zipname;
 226:     $this->zip_fd = 0;
 227:     $this->magic_quotes_status = -1;
 228: 
 229:     // ----- Return
 230:     return;
 231:   }
 232:   // --------------------------------------------------------------------------------
 233: 
 234:   // --------------------------------------------------------------------------------
 235:   // Function :
 236:   //   create($p_filelist, $p_add_dir="", $p_remove_dir="")
 237:   //   create($p_filelist, $p_option, $p_option_value, ...)
 238:   // Description :
 239:   //   This method supports two different synopsis. The first one is historical.
 240:   //   This method creates a Zip Archive. The Zip file is created in the
 241:   //   filesystem. The files and directories indicated in $p_filelist
 242:   //   are added in the archive. See the parameters description for the
 243:   //   supported format of $p_filelist.
 244:   //   When a directory is in the list, the directory and its content is added
 245:   //   in the archive.
 246:   //   In this synopsis, the function takes an optional variable list of
 247:   //   options. See bellow the supported options.
 248:   // Parameters :
 249:   //   $p_filelist : An array containing file or directory names, or
 250:   //                 a string containing one filename or one directory name, or
 251:   //                 a string containing a list of filenames and/or directory
 252:   //                 names separated by spaces.
 253:   //   $p_add_dir : A path to add before the real path of the archived file,
 254:   //                in order to have it memorized in the archive.
 255:   //   $p_remove_dir : A path to remove from the real path of the file to archive,
 256:   //                   in order to have a shorter path memorized in the archive.
 257:   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 258:   //                   is removed first, before $p_add_dir is added.
 259:   // Options :
 260:   //   PCLZIP_OPT_ADD_PATH :
 261:   //   PCLZIP_OPT_REMOVE_PATH :
 262:   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 263:   //   PCLZIP_OPT_COMMENT :
 264:   //   PCLZIP_CB_PRE_ADD :
 265:   //   PCLZIP_CB_POST_ADD :
 266:   // Return Values :
 267:   //   0 on failure,
 268:   //   The list of the added files, with a status of the add action.
 269:   //   (see PclZip::listContent() for list entry format)
 270:   // --------------------------------------------------------------------------------
 271:   function create($p_filelist)
 272:   {
 273:     $v_result=1;
 274: 
 275:     // ----- Reset the error handler
 276:     $this->privErrorReset();
 277: 
 278:     // ----- Set default values
 279:     $v_options = array();
 280:     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 281: 
 282:     // ----- Look for variable options arguments
 283:     $v_size = func_num_args();
 284: 
 285:     // ----- Look for arguments
 286:     if ($v_size > 1) {
 287:       // ----- Get the arguments
 288:       $v_arg_list = func_get_args();
 289: 
 290:       // ----- Remove from the options list the first argument
 291:       array_shift($v_arg_list);
 292:       $v_size--;
 293: 
 294:       // ----- Look for first arg
 295:       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 296: 
 297:         // ----- Parse the options
 298:         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 299:                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 300:                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 301:                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 302:                                                    PCLZIP_CB_PRE_ADD => 'optional',
 303:                                                    PCLZIP_CB_POST_ADD => 'optional',
 304:                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
 305:                                                    PCLZIP_OPT_COMMENT => 'optional',
 306:                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 307:                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 308:                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 309:                                                    //, PCLZIP_OPT_CRYPT => 'optional'
 310:                                              ));
 311:         if ($v_result != 1) {
 312:           return 0;
 313:         }
 314:       }
 315: 
 316:       // ----- Look for 2 args
 317:       // Here we need to support the first historic synopsis of the
 318:       // method.
 319:       else {
 320: 
 321:         // ----- Get the first argument
 322:         $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
 323: 
 324:         // ----- Look for the optional second argument
 325:         if ($v_size == 2) {
 326:           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 327:         }
 328:         else if ($v_size > 2) {
 329:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
 330:                                "Invalid number / type of arguments");
 331:           return 0;
 332:         }
 333:       }
 334:     }
 335: 
 336:     // ----- Look for default option values
 337:     $this->privOptionDefaultThreshold($v_options);
 338: 
 339:     // ----- Init
 340:     $v_string_list = array();
 341:     $v_att_list = array();
 342:     $v_filedescr_list = array();
 343:     $p_result_list = array();
 344: 
 345:     // ----- Look if the $p_filelist is really an array
 346:     if (is_array($p_filelist)) {
 347: 
 348:       // ----- Look if the first element is also an array
 349:       //       This will mean that this is a file description entry
 350:       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 351:         $v_att_list = $p_filelist;
 352:       }
 353: 
 354:       // ----- The list is a list of string names
 355:       else {
 356:         $v_string_list = $p_filelist;
 357:       }
 358:     }
 359: 
 360:     // ----- Look if the $p_filelist is a string
 361:     else if (is_string($p_filelist)) {
 362:       // ----- Create a list from the string
 363:       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 364:     }
 365: 
 366:     // ----- Invalid variable type for $p_filelist
 367:     else {
 368:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
 369:       return 0;
 370:     }
 371: 
 372:     // ----- Reformat the string list
 373:     if (sizeof($v_string_list) != 0) {
 374:       foreach ($v_string_list as $v_string) {
 375:         if ($v_string != '') {
 376:           $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 377:         }
 378:         else {
 379:         }
 380:       }
 381:     }
 382: 
 383:     // ----- For each file in the list check the attributes
 384:     $v_supported_attributes
 385:     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 386:              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 387:              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 388:              ,PCLZIP_ATT_FILE_MTIME => 'optional'
 389:              ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 390:              ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 391:                         );
 392:     foreach ($v_att_list as $v_entry) {
 393:       $v_result = $this->privFileDescrParseAtt($v_entry,
 394:                                                $v_filedescr_list[],
 395:                                                $v_options,
 396:                                                $v_supported_attributes);
 397:       if ($v_result != 1) {
 398:         return 0;
 399:       }
 400:     }
 401: 
 402:     // ----- Expand the filelist (expand directories)
 403:     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 404:     if ($v_result != 1) {
 405:       return 0;
 406:     }
 407: 
 408:     // ----- Call the create fct
 409:     $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
 410:     if ($v_result != 1) {
 411:       return 0;
 412:     }
 413: 
 414:     // ----- Return
 415:     return $p_result_list;
 416:   }
 417:   // --------------------------------------------------------------------------------
 418: 
 419:   // --------------------------------------------------------------------------------
 420:   // Function :
 421:   //   add($p_filelist, $p_add_dir="", $p_remove_dir="")
 422:   //   add($p_filelist, $p_option, $p_option_value, ...)
 423:   // Description :
 424:   //   This method supports two synopsis. The first one is historical.
 425:   //   This methods add the list of files in an existing archive.
 426:   //   If a file with the same name already exists, it is added at the end of the
 427:   //   archive, the first one is still present.
 428:   //   If the archive does not exist, it is created.
 429:   // Parameters :
 430:   //   $p_filelist : An array containing file or directory names, or
 431:   //                 a string containing one filename or one directory name, or
 432:   //                 a string containing a list of filenames and/or directory
 433:   //                 names separated by spaces.
 434:   //   $p_add_dir : A path to add before the real path of the archived file,
 435:   //                in order to have it memorized in the archive.
 436:   //   $p_remove_dir : A path to remove from the real path of the file to archive,
 437:   //                   in order to have a shorter path memorized in the archive.
 438:   //                   When $p_add_dir and $p_remove_dir are set, $p_remove_dir
 439:   //                   is removed first, before $p_add_dir is added.
 440:   // Options :
 441:   //   PCLZIP_OPT_ADD_PATH :
 442:   //   PCLZIP_OPT_REMOVE_PATH :
 443:   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 444:   //   PCLZIP_OPT_COMMENT :
 445:   //   PCLZIP_OPT_ADD_COMMENT :
 446:   //   PCLZIP_OPT_PREPEND_COMMENT :
 447:   //   PCLZIP_CB_PRE_ADD :
 448:   //   PCLZIP_CB_POST_ADD :
 449:   // Return Values :
 450:   //   0 on failure,
 451:   //   The list of the added files, with a status of the add action.
 452:   //   (see PclZip::listContent() for list entry format)
 453:   // --------------------------------------------------------------------------------
 454:   function add($p_filelist)
 455:   {
 456:     $v_result=1;
 457: 
 458:     // ----- Reset the error handler
 459:     $this->privErrorReset();
 460: 
 461:     // ----- Set default values
 462:     $v_options = array();
 463:     $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
 464: 
 465:     // ----- Look for variable options arguments
 466:     $v_size = func_num_args();
 467: 
 468:     // ----- Look for arguments
 469:     if ($v_size > 1) {
 470:       // ----- Get the arguments
 471:       $v_arg_list = func_get_args();
 472: 
 473:       // ----- Remove form the options list the first argument
 474:       array_shift($v_arg_list);
 475:       $v_size--;
 476: 
 477:       // ----- Look for first arg
 478:       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 479: 
 480:         // ----- Parse the options
 481:         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 482:                                             array (PCLZIP_OPT_REMOVE_PATH => 'optional',
 483:                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 484:                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 485:                                                    PCLZIP_CB_PRE_ADD => 'optional',
 486:                                                    PCLZIP_CB_POST_ADD => 'optional',
 487:                                                    PCLZIP_OPT_NO_COMPRESSION => 'optional',
 488:                                                    PCLZIP_OPT_COMMENT => 'optional',
 489:                                                    PCLZIP_OPT_ADD_COMMENT => 'optional',
 490:                                                    PCLZIP_OPT_PREPEND_COMMENT => 'optional',
 491:                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 492:                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 493:                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 494:                                                    //, PCLZIP_OPT_CRYPT => 'optional'
 495:                                                    ));
 496:         if ($v_result != 1) {
 497:           return 0;
 498:         }
 499:       }
 500: 
 501:       // ----- Look for 2 args
 502:       // Here we need to support the first historic synopsis of the
 503:       // method.
 504:       else {
 505: 
 506:         // ----- Get the first argument
 507:         $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
 508: 
 509:         // ----- Look for the optional second argument
 510:         if ($v_size == 2) {
 511:           $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
 512:         }
 513:         else if ($v_size > 2) {
 514:           // ----- Error log
 515:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 516: 
 517:           // ----- Return
 518:           return 0;
 519:         }
 520:       }
 521:     }
 522: 
 523:     // ----- Look for default option values
 524:     $this->privOptionDefaultThreshold($v_options);
 525: 
 526:     // ----- Init
 527:     $v_string_list = array();
 528:     $v_att_list = array();
 529:     $v_filedescr_list = array();
 530:     $p_result_list = array();
 531: 
 532:     // ----- Look if the $p_filelist is really an array
 533:     if (is_array($p_filelist)) {
 534: 
 535:       // ----- Look if the first element is also an array
 536:       //       This will mean that this is a file description entry
 537:       if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
 538:         $v_att_list = $p_filelist;
 539:       }
 540: 
 541:       // ----- The list is a list of string names
 542:       else {
 543:         $v_string_list = $p_filelist;
 544:       }
 545:     }
 546: 
 547:     // ----- Look if the $p_filelist is a string
 548:     else if (is_string($p_filelist)) {
 549:       // ----- Create a list from the string
 550:       $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
 551:     }
 552: 
 553:     // ----- Invalid variable type for $p_filelist
 554:     else {
 555:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
 556:       return 0;
 557:     }
 558: 
 559:     // ----- Reformat the string list
 560:     if (sizeof($v_string_list) != 0) {
 561:       foreach ($v_string_list as $v_string) {
 562:         $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
 563:       }
 564:     }
 565: 
 566:     // ----- For each file in the list check the attributes
 567:     $v_supported_attributes
 568:     = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
 569:              ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
 570:              ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
 571:              ,PCLZIP_ATT_FILE_MTIME => 'optional'
 572:              ,PCLZIP_ATT_FILE_CONTENT => 'optional'
 573:              ,PCLZIP_ATT_FILE_COMMENT => 'optional'
 574:                         );
 575:     foreach ($v_att_list as $v_entry) {
 576:       $v_result = $this->privFileDescrParseAtt($v_entry,
 577:                                                $v_filedescr_list[],
 578:                                                $v_options,
 579:                                                $v_supported_attributes);
 580:       if ($v_result != 1) {
 581:         return 0;
 582:       }
 583:     }
 584: 
 585:     // ----- Expand the filelist (expand directories)
 586:     $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
 587:     if ($v_result != 1) {
 588:       return 0;
 589:     }
 590: 
 591:     // ----- Call the create fct
 592:     $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
 593:     if ($v_result != 1) {
 594:       return 0;
 595:     }
 596: 
 597:     // ----- Return
 598:     return $p_result_list;
 599:   }
 600:   // --------------------------------------------------------------------------------
 601: 
 602:   // --------------------------------------------------------------------------------
 603:   // Function : listContent()
 604:   // Description :
 605:   //   This public method, gives the list of the files and directories, with their
 606:   //   properties.
 607:   //   The properties of each entries in the list are (used also in other functions) :
 608:   //     filename : Name of the file. For a create or add action it is the filename
 609:   //                given by the user. For an extract function it is the filename
 610:   //                of the extracted file.
 611:   //     stored_filename : Name of the file / directory stored in the archive.
 612:   //     size : Size of the stored file.
 613:   //     compressed_size : Size of the file's data compressed in the archive
 614:   //                       (without the headers overhead)
 615:   //     mtime : Last known modification date of the file (UNIX timestamp)
 616:   //     comment : Comment associated with the file
 617:   //     folder : true | false
 618:   //     index : index of the file in the archive
 619:   //     status : status of the action (depending of the action) :
 620:   //              Values are :
 621:   //                ok : OK !
 622:   //                filtered : the file / dir is not extracted (filtered by user)
 623:   //                already_a_directory : the file can not be extracted because a
 624:   //                                      directory with the same name already exists
 625:   //                write_protected : the file can not be extracted because a file
 626:   //                                  with the same name already exists and is
 627:   //                                  write protected
 628:   //                newer_exist : the file was not extracted because a newer file exists
 629:   //                path_creation_fail : the file is not extracted because the folder
 630:   //                                     does not exist and can not be created
 631:   //                write_error : the file was not extracted because there was a
 632:   //                              error while writing the file
 633:   //                read_error : the file was not extracted because there was a error
 634:   //                             while reading the file
 635:   //                invalid_header : the file was not extracted because of an archive
 636:   //                                 format error (bad file header)
 637:   //   Note that each time a method can continue operating when there
 638:   //   is an action error on a file, the error is only logged in the file status.
 639:   // Return Values :
 640:   //   0 on an unrecoverable failure,
 641:   //   The list of the files in the archive.
 642:   // --------------------------------------------------------------------------------
 643:   function listContent()
 644:   {
 645:     $v_result=1;
 646: 
 647:     // ----- Reset the error handler
 648:     $this->privErrorReset();
 649: 
 650:     // ----- Check archive
 651:     if (!$this->privCheckFormat()) {
 652:       return(0);
 653:     }
 654: 
 655:     // ----- Call the extracting fct
 656:     $p_list = array();
 657:     if (($v_result = $this->privList($p_list)) != 1)
 658:     {
 659:       unset($p_list);
 660:       return(0);
 661:     }
 662: 
 663:     // ----- Return
 664:     return $p_list;
 665:   }
 666:   // --------------------------------------------------------------------------------
 667: 
 668:   // --------------------------------------------------------------------------------
 669:   // Function :
 670:   //   extract($p_path="./", $p_remove_path="")
 671:   //   extract([$p_option, $p_option_value, ...])
 672:   // Description :
 673:   //   This method supports two synopsis. The first one is historical.
 674:   //   This method extract all the files / directories from the archive to the
 675:   //   folder indicated in $p_path.
 676:   //   If you want to ignore the 'root' part of path of the memorized files
 677:   //   you can indicate this in the optional $p_remove_path parameter.
 678:   //   By default, if a newer file with the same name already exists, the
 679:   //   file is not extracted.
 680:   //
 681:   //   If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
 682:   //   are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
 683:   //   at the end of the path value of PCLZIP_OPT_PATH.
 684:   // Parameters :
 685:   //   $p_path : Path where the files and directories are to be extracted
 686:   //   $p_remove_path : First part ('root' part) of the memorized path
 687:   //                    (if any similar) to remove while extracting.
 688:   // Options :
 689:   //   PCLZIP_OPT_PATH :
 690:   //   PCLZIP_OPT_ADD_PATH :
 691:   //   PCLZIP_OPT_REMOVE_PATH :
 692:   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 693:   //   PCLZIP_CB_PRE_EXTRACT :
 694:   //   PCLZIP_CB_POST_EXTRACT :
 695:   // Return Values :
 696:   //   0 or a negative value on failure,
 697:   //   The list of the extracted files, with a status of the action.
 698:   //   (see PclZip::listContent() for list entry format)
 699:   // --------------------------------------------------------------------------------
 700:   function extract()
 701:   {
 702:     $v_result=1;
 703: 
 704:     // ----- Reset the error handler
 705:     $this->privErrorReset();
 706: 
 707:     // ----- Check archive
 708:     if (!$this->privCheckFormat()) {
 709:       return(0);
 710:     }
 711: 
 712:     // ----- Set default values
 713:     $v_options = array();
 714: //    $v_path = "./";
 715:     $v_path = '';
 716:     $v_remove_path = "";
 717:     $v_remove_all_path = false;
 718: 
 719:     // ----- Look for variable options arguments
 720:     $v_size = func_num_args();
 721: 
 722:     // ----- Default values for option
 723:     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 724: 
 725:     // ----- Look for arguments
 726:     if ($v_size > 0) {
 727:       // ----- Get the arguments
 728:       $v_arg_list = func_get_args();
 729: 
 730:       // ----- Look for first arg
 731:       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 732: 
 733:         // ----- Parse the options
 734:         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 735:                                             array (PCLZIP_OPT_PATH => 'optional',
 736:                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
 737:                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 738:                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 739:                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
 740:                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
 741:                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
 742:                                                    PCLZIP_OPT_BY_NAME => 'optional',
 743:                                                    PCLZIP_OPT_BY_EREG => 'optional',
 744:                                                    PCLZIP_OPT_BY_PREG => 'optional',
 745:                                                    PCLZIP_OPT_BY_INDEX => 'optional',
 746:                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 747:                                                    PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
 748:                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
 749:                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 750:                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 751:                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 752:                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 753:                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 754:                                                     ));
 755:         if ($v_result != 1) {
 756:           return 0;
 757:         }
 758: 
 759:         // ----- Set the arguments
 760:         if (isset($v_options[PCLZIP_OPT_PATH])) {
 761:           $v_path = $v_options[PCLZIP_OPT_PATH];
 762:         }
 763:         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 764:           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 765:         }
 766:         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 767:           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 768:         }
 769:         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 770:           // ----- Check for '/' in last path char
 771:           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 772:             $v_path .= '/';
 773:           }
 774:           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 775:         }
 776:       }
 777: 
 778:       // ----- Look for 2 args
 779:       // Here we need to support the first historic synopsis of the
 780:       // method.
 781:       else {
 782: 
 783:         // ----- Get the first argument
 784:         $v_path = $v_arg_list[0];
 785: 
 786:         // ----- Look for the optional second argument
 787:         if ($v_size == 2) {
 788:           $v_remove_path = $v_arg_list[1];
 789:         }
 790:         else if ($v_size > 2) {
 791:           // ----- Error log
 792:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 793: 
 794:           // ----- Return
 795:           return 0;
 796:         }
 797:       }
 798:     }
 799: 
 800:     // ----- Look for default option values
 801:     $this->privOptionDefaultThreshold($v_options);
 802: 
 803:     // ----- Trace
 804: 
 805:     // ----- Call the extracting fct
 806:     $p_list = array();
 807:     $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
 808:                                          $v_remove_all_path, $v_options);
 809:     if ($v_result < 1) {
 810:       unset($p_list);
 811:       return(0);
 812:     }
 813: 
 814:     // ----- Return
 815:     return $p_list;
 816:   }
 817:   // --------------------------------------------------------------------------------
 818: 
 819: 
 820:   // --------------------------------------------------------------------------------
 821:   // Function :
 822:   //   extractByIndex($p_index, $p_path="./", $p_remove_path="")
 823:   //   extractByIndex($p_index, [$p_option, $p_option_value, ...])
 824:   // Description :
 825:   //   This method supports two synopsis. The first one is historical.
 826:   //   This method is doing a partial extract of the archive.
 827:   //   The extracted files or folders are identified by their index in the
 828:   //   archive (from 0 to n).
 829:   //   Note that if the index identify a folder, only the folder entry is
 830:   //   extracted, not all the files included in the archive.
 831:   // Parameters :
 832:   //   $p_index : A single index (integer) or a string of indexes of files to
 833:   //              extract. The form of the string is "0,4-6,8-12" with only numbers
 834:   //              and '-' for range or ',' to separate ranges. No spaces or ';'
 835:   //              are allowed.
 836:   //   $p_path : Path where the files and directories are to be extracted
 837:   //   $p_remove_path : First part ('root' part) of the memorized path
 838:   //                    (if any similar) to remove while extracting.
 839:   // Options :
 840:   //   PCLZIP_OPT_PATH :
 841:   //   PCLZIP_OPT_ADD_PATH :
 842:   //   PCLZIP_OPT_REMOVE_PATH :
 843:   //   PCLZIP_OPT_REMOVE_ALL_PATH :
 844:   //   PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
 845:   //     not as files.
 846:   //     The resulting content is in a new field 'content' in the file
 847:   //     structure.
 848:   //     This option must be used alone (any other options are ignored).
 849:   //   PCLZIP_CB_PRE_EXTRACT :
 850:   //   PCLZIP_CB_POST_EXTRACT :
 851:   // Return Values :
 852:   //   0 on failure,
 853:   //   The list of the extracted files, with a status of the action.
 854:   //   (see PclZip::listContent() for list entry format)
 855:   // --------------------------------------------------------------------------------
 856:   //function extractByIndex($p_index, options...)
 857:   function extractByIndex($p_index)
 858:   {
 859:     $v_result=1;
 860: 
 861:     // ----- Reset the error handler
 862:     $this->privErrorReset();
 863: 
 864:     // ----- Check archive
 865:     if (!$this->privCheckFormat()) {
 866:       return(0);
 867:     }
 868: 
 869:     // ----- Set default values
 870:     $v_options = array();
 871: //    $v_path = "./";
 872:     $v_path = '';
 873:     $v_remove_path = "";
 874:     $v_remove_all_path = false;
 875: 
 876:     // ----- Look for variable options arguments
 877:     $v_size = func_num_args();
 878: 
 879:     // ----- Default values for option
 880:     $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 881: 
 882:     // ----- Look for arguments
 883:     if ($v_size > 1) {
 884:       // ----- Get the arguments
 885:       $v_arg_list = func_get_args();
 886: 
 887:       // ----- Remove form the options list the first argument
 888:       array_shift($v_arg_list);
 889:       $v_size--;
 890: 
 891:       // ----- Look for first arg
 892:       if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
 893: 
 894:         // ----- Parse the options
 895:         $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
 896:                                             array (PCLZIP_OPT_PATH => 'optional',
 897:                                                    PCLZIP_OPT_REMOVE_PATH => 'optional',
 898:                                                    PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
 899:                                                    PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
 900:                                                    PCLZIP_OPT_ADD_PATH => 'optional',
 901:                                                    PCLZIP_CB_PRE_EXTRACT => 'optional',
 902:                                                    PCLZIP_CB_POST_EXTRACT => 'optional',
 903:                                                    PCLZIP_OPT_SET_CHMOD => 'optional',
 904:                                                    PCLZIP_OPT_REPLACE_NEWER => 'optional'
 905:                                                    ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
 906:                                                    ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
 907:                                                    PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
 908:                                                    PCLZIP_OPT_TEMP_FILE_ON => 'optional',
 909:                                                    PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
 910:                                                    ));
 911:         if ($v_result != 1) {
 912:           return 0;
 913:         }
 914: 
 915:         // ----- Set the arguments
 916:         if (isset($v_options[PCLZIP_OPT_PATH])) {
 917:           $v_path = $v_options[PCLZIP_OPT_PATH];
 918:         }
 919:         if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
 920:           $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
 921:         }
 922:         if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
 923:           $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
 924:         }
 925:         if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
 926:           // ----- Check for '/' in last path char
 927:           if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
 928:             $v_path .= '/';
 929:           }
 930:           $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
 931:         }
 932:         if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
 933:           $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
 934:         }
 935:         else {
 936:         }
 937:       }
 938: 
 939:       // ----- Look for 2 args
 940:       // Here we need to support the first historic synopsis of the
 941:       // method.
 942:       else {
 943: 
 944:         // ----- Get the first argument
 945:         $v_path = $v_arg_list[0];
 946: 
 947:         // ----- Look for the optional second argument
 948:         if ($v_size == 2) {
 949:           $v_remove_path = $v_arg_list[1];
 950:         }
 951:         else if ($v_size > 2) {
 952:           // ----- Error log
 953:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
 954: 
 955:           // ----- Return
 956:           return 0;
 957:         }
 958:       }
 959:     }
 960: 
 961:     // ----- Trace
 962: 
 963:     // ----- Trick
 964:     // Here I want to reuse extractByRule(), so I need to parse the $p_index
 965:     // with privParseOptions()
 966:     $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
 967:     $v_options_trick = array();
 968:     $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
 969:                                         array (PCLZIP_OPT_BY_INDEX => 'optional' ));
 970:     if ($v_result != 1) {
 971:         return 0;
 972:     }
 973:     $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
 974: 
 975:     // ----- Look for default option values
 976:     $this->privOptionDefaultThreshold($v_options);
 977: 
 978:     // ----- Call the extracting fct
 979:     if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
 980:         return(0);
 981:     }
 982: 
 983:     // ----- Return
 984:     return $p_list;
 985:   }
 986:   // --------------------------------------------------------------------------------
 987: 
 988:   // --------------------------------------------------------------------------------
 989:   // Function :
 990:   //   delete([$p_option, $p_option_value, ...])
 991:   // Description :
 992:   //   This method removes files from the archive.
 993:   //   If no parameters are given, then all the archive is emptied.
 994:   // Parameters :
 995:   //   None or optional arguments.
 996:   // Options :
 997:   //   PCLZIP_OPT_BY_INDEX :
 998:   //   PCLZIP_OPT_BY_NAME :
 999:   //   PCLZIP_OPT_BY_EREG :
1000:   //   PCLZIP_OPT_BY_PREG :
1001:   // Return Values :
1002:   //   0 on failure,
1003:   //   The list of the files which are still present in the archive.
1004:   //   (see PclZip::listContent() for list entry format)
1005:   // --------------------------------------------------------------------------------
1006:   function delete()
1007:   {
1008:     $v_result=1;
1009: 
1010:     // ----- Reset the error handler
1011:     $this->privErrorReset();
1012: 
1013:     // ----- Check archive
1014:     if (!$this->privCheckFormat()) {
1015:       return(0);
1016:     }
1017: 
1018:     // ----- Set default values
1019:     $v_options = array();
1020: 
1021:     // ----- Look for variable options arguments
1022:     $v_size = func_num_args();
1023: 
1024:     // ----- Look for arguments
1025:     if ($v_size > 0) {
1026:       // ----- Get the arguments
1027:       $v_arg_list = func_get_args();
1028: 
1029:       // ----- Parse the options
1030:       $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
1031:                                         array (PCLZIP_OPT_BY_NAME => 'optional',
1032:                                                PCLZIP_OPT_BY_EREG => 'optional',
1033:                                                PCLZIP_OPT_BY_PREG => 'optional',
1034:                                                PCLZIP_OPT_BY_INDEX => 'optional' ));
1035:       if ($v_result != 1) {
1036:           return 0;
1037:       }
1038:     }
1039: 
1040:     // ----- Magic quotes trick
1041:     $this->privDisableMagicQuotes();
1042: 
1043:     // ----- Call the delete fct
1044:     $v_list = array();
1045:     if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
1046:       $this->privSwapBackMagicQuotes();
1047:       unset($v_list);
1048:       return(0);
1049:     }
1050: 
1051:     // ----- Magic quotes trick
1052:     $this->privSwapBackMagicQuotes();
1053: 
1054:     // ----- Return
1055:     return $v_list;
1056:   }
1057:   // --------------------------------------------------------------------------------
1058: 
1059:   // --------------------------------------------------------------------------------
1060:   // Function : deleteByIndex()
1061:   // Description :
1062:   //   ***** Deprecated *****
1063:   //   delete(PCLZIP_OPT_BY_INDEX, $p_index) should be preferred.
1064:   // --------------------------------------------------------------------------------
1065:   function deleteByIndex($p_index)
1066:   {
1067: 
1068:     $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
1069: 
1070:     // ----- Return
1071:     return $p_list;
1072:   }
1073:   // --------------------------------------------------------------------------------
1074: 
1075:   // --------------------------------------------------------------------------------
1076:   // Function : properties()
1077:   // Description :
1078:   //   This method gives the properties of the archive.
1079:   //   The properties are :
1080:   //     nb : Number of files in the archive
1081:   //     comment : Comment associated with the archive file
1082:   //     status : not_exist, ok
1083:   // Parameters :
1084:   //   None
1085:   // Return Values :
1086:   //   0 on failure,
1087:   //   An array with the archive properties.
1088:   // --------------------------------------------------------------------------------
1089:   function properties()
1090:   {
1091: 
1092:     // ----- Reset the error handler
1093:     $this->privErrorReset();
1094: 
1095:     // ----- Magic quotes trick
1096:     $this->privDisableMagicQuotes();
1097: 
1098:     // ----- Check archive
1099:     if (!$this->privCheckFormat()) {
1100:       $this->privSwapBackMagicQuotes();
1101:       return(0);
1102:     }
1103: 
1104:     // ----- Default properties
1105:     $v_prop = array();
1106:     $v_prop['comment'] = '';
1107:     $v_prop['nb'] = 0;
1108:     $v_prop['status'] = 'not_exist';
1109: 
1110:     // ----- Look if file exists
1111:     if (@is_file($this->zipname))
1112:     {
1113:       // ----- Open the zip file
1114:       if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
1115:       {
1116:         $this->privSwapBackMagicQuotes();
1117: 
1118:         // ----- Error log
1119:         PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
1120: 
1121:         // ----- Return
1122:         return 0;
1123:       }
1124: 
1125:       // ----- Read the central directory informations
1126:       $v_central_dir = array();
1127:       if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
1128:       {
1129:         $this->privSwapBackMagicQuotes();
1130:         return 0;
1131:       }
1132: 
1133:       // ----- Close the zip file
1134:       $this->privCloseFd();
1135: 
1136:       // ----- Set the user attributes
1137:       $v_prop['comment'] = $v_central_dir['comment'];
1138:       $v_prop['nb'] = $v_central_dir['entries'];
1139:       $v_prop['status'] = 'ok';
1140:     }
1141: 
1142:     // ----- Magic quotes trick
1143:     $this->privSwapBackMagicQuotes();
1144: 
1145:     // ----- Return
1146:     return $v_prop;
1147:   }
1148:   // --------------------------------------------------------------------------------
1149: 
1150:   // --------------------------------------------------------------------------------
1151:   // Function : duplicate()
1152:   // Description :
1153:   //   This method creates an archive by copying the content of an other one. If
1154:   //   the archive already exist, it is replaced by the new one without any warning.
1155:   // Parameters :
1156:   //   $p_archive : The filename of a valid archive, or
1157:   //                a valid PclZip object.
1158:   // Return Values :
1159:   //   1 on success.
1160:   //   0 or a negative value on error (error code).
1161:   // --------------------------------------------------------------------------------
1162:   function duplicate($p_archive)
1163:   {
1164:     $v_result = 1;
1165: 
1166:     // ----- Reset the error handler
1167:     $this->privErrorReset();
1168: 
1169:     // ----- Look if the $p_archive is a PclZip object
1170:     if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
1171:     {
1172: 
1173:       // ----- Duplicate the archive
1174:       $v_result = $this->privDuplicate($p_archive->zipname);
1175:     }
1176: 
1177:     // ----- Look if the $p_archive is a string (so a filename)
1178:     else if (is_string($p_archive))
1179:     {
1180: 
1181:       // ----- Check that $p_archive is a valid zip file
1182:       // TBC : Should also check the archive format
1183:       if (!is_file($p_archive)) {
1184:         // ----- Error log
1185:         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
1186:         $v_result = PCLZIP_ERR_MISSING_FILE;
1187:       }
1188:       else {
1189:         // ----- Duplicate the archive
1190:         $v_result = $this->privDuplicate($p_archive);
1191:       }
1192:     }
1193: 
1194:     // ----- Invalid variable
1195:     else
1196:     {
1197:       // ----- Error log
1198:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1199:       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1200:     }
1201: 
1202:     // ----- Return
1203:     return $v_result;
1204:   }
1205:   // --------------------------------------------------------------------------------
1206: 
1207:   // --------------------------------------------------------------------------------
1208:   // Function : merge()
1209:   // Description :
1210:   //   This method merge the $p_archive_to_add archive at the end of the current
1211:   //   one ($this).
1212:   //   If the archive ($this) does not exist, the merge becomes a duplicate.
1213:   //   If the $p_archive_to_add archive does not exist, the merge is a success.
1214:   // Parameters :
1215:   //   $p_archive_to_add : It can be directly the filename of a valid zip archive,
1216:   //                       or a PclZip object archive.
1217:   // Return Values :
1218:   //   1 on success,
1219:   //   0 or negative values on error (see below).
1220:   // --------------------------------------------------------------------------------
1221:   function merge($p_archive_to_add)
1222:   {
1223:     $v_result = 1;
1224: 
1225:     // ----- Reset the error handler
1226:     $this->privErrorReset();
1227: 
1228:     // ----- Check archive
1229:     if (!$this->privCheckFormat()) {
1230:       return(0);
1231:     }
1232: 
1233:     // ----- Look if the $p_archive_to_add is a PclZip object
1234:     if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
1235:     {
1236: 
1237:       // ----- Merge the archive
1238:       $v_result = $this->privMerge($p_archive_to_add);
1239:     }
1240: 
1241:     // ----- Look if the $p_archive_to_add is a string (so a filename)
1242:     else if (is_string($p_archive_to_add))
1243:     {
1244: 
1245:       // ----- Create a temporary archive
1246:       $v_object_archive = new PclZip($p_archive_to_add);
1247: 
1248:       // ----- Merge the archive
1249:       $v_result = $this->privMerge($v_object_archive);
1250:     }
1251: 
1252:     // ----- Invalid variable
1253:     else
1254:     {
1255:       // ----- Error log
1256:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
1257:       $v_result = PCLZIP_ERR_INVALID_PARAMETER;
1258:     }
1259: 
1260:     // ----- Return
1261:     return $v_result;
1262:   }
1263:   // --------------------------------------------------------------------------------
1264: 
1265: 
1266: 
1267:   // --------------------------------------------------------------------------------
1268:   // Function : errorCode()
1269:   // Description :
1270:   // Parameters :
1271:   // --------------------------------------------------------------------------------
1272:   function errorCode()
1273:   {
1274:     if (PCLZIP_ERROR_EXTERNAL == 1) {
1275:       return(PclErrorCode());
1276:     }
1277:     else {
1278:       return($this->error_code);
1279:     }
1280:   }
1281:   // --------------------------------------------------------------------------------
1282: 
1283:   // --------------------------------------------------------------------------------
1284:   // Function : errorName()
1285:   // Description :
1286:   // Parameters :
1287:   // --------------------------------------------------------------------------------
1288:   function errorName($p_with_code=false)
1289:   {
1290:     $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
1291:                       PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
1292:                       PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
1293:                       PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
1294:                       PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
1295:                       PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
1296:                       PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
1297:                       PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
1298:                       PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
1299:                       PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
1300:                       PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
1301:                       PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
1302:                       PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
1303:                       PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
1304:                       PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
1305:                       PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
1306:                       PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
1307:                       PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
1308:                       PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
1309:                       ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
1310:                       ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
1311:                     );
1312: 
1313:     if (isset($v_name[$this->error_code])) {
1314:       $v_value = $v_name[$this->error_code];
1315:     }
1316:     else {
1317:       $v_value = 'NoName';
1318:     }
1319: 
1320:     if ($p_with_code) {
1321:       return($v_value.' ('.$this->error_code.')');
1322:     }
1323:     else {
1324:       return($v_value);
1325:     }
1326:   }
1327:   // --------------------------------------------------------------------------------
1328: 
1329:   // --------------------------------------------------------------------------------
1330:   // Function : errorInfo()
1331:   // Description :
1332:   // Parameters :
1333:   // --------------------------------------------------------------------------------
1334:   function errorInfo($p_full=false)
1335:   {
1336:     if (PCLZIP_ERROR_EXTERNAL == 1) {
1337:       return(PclErrorString());
1338:     }
1339:     else {
1340:       if ($p_full) {
1341:         return($this->errorName(true)." : ".$this->error_string);
1342:       }
1343:       else {
1344:         return($this->error_string." [code ".$this->error_code."]");
1345:       }
1346:     }
1347:   }
1348:   // --------------------------------------------------------------------------------
1349: 
1350: 
1351: // --------------------------------------------------------------------------------
1352: // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
1353: // *****                                                        *****
1354: // *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****
1355: // --------------------------------------------------------------------------------
1356: 
1357: 
1358: 
1359:   // --------------------------------------------------------------------------------
1360:   // Function : privCheckFormat()
1361:   // Description :
1362:   //   This method check that the archive exists and is a valid zip archive.
1363:   //   Several level of check exists. (futur)
1364:   // Parameters :
1365:   //   $p_level : Level of check. Default 0.
1366:   //              0 : Check the first bytes (magic codes) (default value))
1367:   //              1 : 0 + Check the central directory (futur)
1368:   //              2 : 1 + Check each file header (futur)
1369:   // Return Values :
1370:   //   true on success,
1371:   //   false on error, the error code is set.
1372:   // --------------------------------------------------------------------------------
1373:   function privCheckFormat($p_level=0)
1374:   {
1375:     $v_result = true;
1376: 
1377:     // ----- Reset the file system cache
1378:     clearstatcache();
1379: 
1380:     // ----- Reset the error handler
1381:     $this->privErrorReset();
1382: 
1383:     // ----- Look if the file exits
1384:     if (!is_file($this->zipname)) {
1385:       // ----- Error log
1386:       PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
1387:       return(false);
1388:     }
1389: 
1390:     // ----- Check that the file is readeable
1391:     if (!is_readable($this->zipname)) {
1392:       // ----- Error log
1393:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
1394:       return(false);
1395:     }
1396: 
1397:     // ----- Check the magic code
1398:     // TBC
1399: 
1400:     // ----- Check the central header
1401:     // TBC
1402: 
1403:     // ----- Check each file header
1404:     // TBC
1405: 
1406:     // ----- Return
1407:     return $v_result;
1408:   }
1409:   // --------------------------------------------------------------------------------
1410: 
1411:   // --------------------------------------------------------------------------------
1412:   // Function : privParseOptions()
1413:   // Description :
1414:   //   This internal methods reads the variable list of arguments ($p_options_list,
1415:   //   $p_size) and generate an array with the options and values ($v_result_list).
1416:   //   $v_requested_options contains the options that can be present and those that
1417:   //   must be present.
1418:   //   $v_requested_options is an array, with the option value as key, and 'optional',
1419:   //   or 'mandatory' as value.
1420:   // Parameters :
1421:   //   See above.
1422:   // Return Values :
1423:   //   1 on success.
1424:   //   0 on failure.
1425:   // --------------------------------------------------------------------------------
1426:   function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
1427:   {
1428:     $v_result=1;
1429: 
1430:     // ----- Read the options
1431:     $i=0;
1432:     while ($i<$p_size) {
1433: 
1434:       // ----- Check if the option is supported
1435:       if (!isset($v_requested_options[$p_options_list[$i]])) {
1436:         // ----- Error log
1437:         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
1438: 
1439:         // ----- Return
1440:         return PclZip::errorCode();
1441:       }
1442: 
1443:       // ----- Look for next option
1444:       switch ($p_options_list[$i]) {
1445:         // ----- Look for options that request a path value
1446:         case PCLZIP_OPT_PATH :
1447:         case PCLZIP_OPT_REMOVE_PATH :
1448:         case PCLZIP_OPT_ADD_PATH :
1449:           // ----- Check the number of parameters
1450:           if (($i+1) >= $p_size) {
1451:             // ----- Error log
1452:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1453: 
1454:             // ----- Return
1455:             return PclZip::errorCode();
1456:           }
1457: 
1458:           // ----- Get the value
1459:           $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
1460:           $i++;
1461:         break;
1462: 
1463:         case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
1464:           // ----- Check the number of parameters
1465:           if (($i+1) >= $p_size) {
1466:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1467:             return PclZip::errorCode();
1468:           }
1469: 
1470:           // ----- Check for incompatible options
1471:           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
1472:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
1473:             return PclZip::errorCode();
1474:           }
1475: 
1476:           // ----- Check the value
1477:           $v_value = $p_options_list[$i+1];
1478:           if ((!is_integer($v_value)) || ($v_value<0)) {
1479:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1480:             return PclZip::errorCode();
1481:           }
1482: 
1483:           // ----- Get the value (and convert it in bytes)
1484:           $v_result_list[$p_options_list[$i]] = $v_value*1048576;
1485:           $i++;
1486:         break;
1487: 
1488:         case PCLZIP_OPT_TEMP_FILE_ON :
1489:           // ----- Check for incompatible options
1490:           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
1491:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
1492:             return PclZip::errorCode();
1493:           }
1494: 
1495:           $v_result_list[$p_options_list[$i]] = true;
1496:         break;
1497: 
1498:         case PCLZIP_OPT_TEMP_FILE_OFF :
1499:           // ----- Check for incompatible options
1500:           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
1501:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
1502:             return PclZip::errorCode();
1503:           }
1504:           // ----- Check for incompatible options
1505:           if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
1506:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
1507:             return PclZip::errorCode();
1508:           }
1509: 
1510:           $v_result_list[$p_options_list[$i]] = true;
1511:         break;
1512: 
1513:         case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
1514:           // ----- Check the number of parameters
1515:           if (($i+1) >= $p_size) {
1516:             // ----- Error log
1517:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1518: 
1519:             // ----- Return
1520:             return PclZip::errorCode();
1521:           }
1522: 
1523:           // ----- Get the value
1524:           if (   is_string($p_options_list[$i+1])
1525:               && ($p_options_list[$i+1] != '')) {
1526:             $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
1527:             $i++;
1528:           }
1529:           else {
1530:           }
1531:         break;
1532: 
1533:         // ----- Look for options that request an array of string for value
1534:         case PCLZIP_OPT_BY_NAME :
1535:           // ----- Check the number of parameters
1536:           if (($i+1) >= $p_size) {
1537:             // ----- Error log
1538:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1539: 
1540:             // ----- Return
1541:             return PclZip::errorCode();
1542:           }
1543: 
1544:           // ----- Get the value
1545:           if (is_string($p_options_list[$i+1])) {
1546:               $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
1547:           }
1548:           else if (is_array($p_options_list[$i+1])) {
1549:               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
1550:           }
1551:           else {
1552:             // ----- Error log
1553:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1554: 
1555:             // ----- Return
1556:             return PclZip::errorCode();
1557:           }
1558:           $i++;
1559:         break;
1560: 
1561:         // ----- Look for options that request an EREG or PREG expression
1562:         case PCLZIP_OPT_BY_EREG :
1563:           // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
1564:           // to PCLZIP_OPT_BY_PREG
1565:           $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
1566:         case PCLZIP_OPT_BY_PREG :
1567:         //case PCLZIP_OPT_CRYPT :
1568:           // ----- Check the number of parameters
1569:           if (($i+1) >= $p_size) {
1570:             // ----- Error log
1571:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1572: 
1573:             // ----- Return
1574:             return PclZip::errorCode();
1575:           }
1576: 
1577:           // ----- Get the value
1578:           if (is_string($p_options_list[$i+1])) {
1579:               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
1580:           }
1581:           else {
1582:             // ----- Error log
1583:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1584: 
1585:             // ----- Return
1586:             return PclZip::errorCode();
1587:           }
1588:           $i++;
1589:         break;
1590: 
1591:         // ----- Look for options that takes a string
1592:         case PCLZIP_OPT_COMMENT :
1593:         case PCLZIP_OPT_ADD_COMMENT :
1594:         case PCLZIP_OPT_PREPEND_COMMENT :
1595:           // ----- Check the number of parameters
1596:           if (($i+1) >= $p_size) {
1597:             // ----- Error log
1598:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
1599:                                  "Missing parameter value for option '"
1600:                                  .PclZipUtilOptionText($p_options_list[$i])
1601:                                  ."'");
1602: 
1603:             // ----- Return
1604:             return PclZip::errorCode();
1605:           }
1606: 
1607:           // ----- Get the value
1608:           if (is_string($p_options_list[$i+1])) {
1609:               $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
1610:           }
1611:           else {
1612:             // ----- Error log
1613:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
1614:                                  "Wrong parameter value for option '"
1615:                                  .PclZipUtilOptionText($p_options_list[$i])
1616:                                  ."'");
1617: 
1618:             // ----- Return
1619:             return PclZip::errorCode();
1620:           }
1621:           $i++;
1622:         break;
1623: 
1624:         // ----- Look for options that request an array of index
1625:         case PCLZIP_OPT_BY_INDEX :
1626:           // ----- Check the number of parameters
1627:           if (($i+1) >= $p_size) {
1628:             // ----- Error log
1629:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1630: 
1631:             // ----- Return
1632:             return PclZip::errorCode();
1633:           }
1634: 
1635:           // ----- Get the value
1636:           $v_work_list = array();
1637:           if (is_string($p_options_list[$i+1])) {
1638: 
1639:               // ----- Remove spaces
1640:               $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
1641: 
1642:               // ----- Parse items
1643:               $v_work_list = explode(",", $p_options_list[$i+1]);
1644:           }
1645:           else if (is_integer($p_options_list[$i+1])) {
1646:               $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
1647:           }
1648:           else if (is_array($p_options_list[$i+1])) {
1649:               $v_work_list = $p_options_list[$i+1];
1650:           }
1651:           else {
1652:             // ----- Error log
1653:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1654: 
1655:             // ----- Return
1656:             return PclZip::errorCode();
1657:           }
1658: 
1659:           // ----- Reduce the index list
1660:           // each index item in the list must be a couple with a start and
1661:           // an end value : [0,3], [5-5], [8-10], ...
1662:           // ----- Check the format of each item
1663:           $v_sort_flag=false;
1664:           $v_sort_value=0;
1665:           for ($j=0; $j<sizeof($v_work_list); $j++) {
1666:               // ----- Explode the item
1667:               $v_item_list = explode("-", $v_work_list[$j]);
1668:               $v_size_item_list = sizeof($v_item_list);
1669: 
1670:               // ----- TBC : Here we might check that each item is a
1671:               // real integer ...
1672: 
1673:               // ----- Look for single value
1674:               if ($v_size_item_list == 1) {
1675:                   // ----- Set the option value
1676:                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
1677:                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
1678:               }
1679:               elseif ($v_size_item_list == 2) {
1680:                   // ----- Set the option value
1681:                   $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
1682:                   $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
1683:               }
1684:               else {
1685:                   // ----- Error log
1686:                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1687: 
1688:                   // ----- Return
1689:                   return PclZip::errorCode();
1690:               }
1691: 
1692: 
1693:               // ----- Look for list sort
1694:               if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
1695:                   $v_sort_flag=true;
1696: 
1697:                   // ----- TBC : An automatic sort should be writen ...
1698:                   // ----- Error log
1699:                   PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1700: 
1701:                   // ----- Return
1702:                   return PclZip::errorCode();
1703:               }
1704:               $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
1705:           }
1706: 
1707:           // ----- Sort the items
1708:           if ($v_sort_flag) {
1709:               // TBC : To Be Completed
1710:           }
1711: 
1712:           // ----- Next option
1713:           $i++;
1714:         break;
1715: 
1716:         // ----- Look for options that request no value
1717:         case PCLZIP_OPT_REMOVE_ALL_PATH :
1718:         case PCLZIP_OPT_EXTRACT_AS_STRING :
1719:         case PCLZIP_OPT_NO_COMPRESSION :
1720:         case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
1721:         case PCLZIP_OPT_REPLACE_NEWER :
1722:         case PCLZIP_OPT_STOP_ON_ERROR :
1723:           $v_result_list[$p_options_list[$i]] = true;
1724:         break;
1725: 
1726:         // ----- Look for options that request an octal value
1727:         case PCLZIP_OPT_SET_CHMOD :
1728:           // ----- Check the number of parameters
1729:           if (($i+1) >= $p_size) {
1730:             // ----- Error log
1731:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1732: 
1733:             // ----- Return
1734:             return PclZip::errorCode();
1735:           }
1736: 
1737:           // ----- Get the value
1738:           $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
1739:           $i++;
1740:         break;
1741: 
1742:         // ----- Look for options that request a call-back
1743:         case PCLZIP_CB_PRE_EXTRACT :
1744:         case PCLZIP_CB_POST_EXTRACT :
1745:         case PCLZIP_CB_PRE_ADD :
1746:         case PCLZIP_CB_POST_ADD :
1747:         /* for futur use
1748:         case PCLZIP_CB_PRE_DELETE :
1749:         case PCLZIP_CB_POST_DELETE :
1750:         case PCLZIP_CB_PRE_LIST :
1751:         case PCLZIP_CB_POST_LIST :
1752:         */
1753:           // ----- Check the number of parameters
1754:           if (($i+1) >= $p_size) {
1755:             // ----- Error log
1756:             PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1757: 
1758:             // ----- Return
1759:             return PclZip::errorCode();
1760:           }
1761: 
1762:           // ----- Get the value
1763:           $v_function_name = $p_options_list[$i+1];
1764: 
1765:           // ----- Check that the value is a valid existing function
1766:           if (!function_exists($v_function_name)) {
1767:             // ----- Error log
1768:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
1769: 
1770:             // ----- Return
1771:             return PclZip::errorCode();
1772:           }
1773: 
1774:           // ----- Set the attribute
1775:           $v_result_list[$p_options_list[$i]] = $v_function_name;
1776:           $i++;
1777:         break;
1778: 
1779:         default :
1780:           // ----- Error log
1781:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
1782:                                "Unknown parameter '"
1783:                                .$p_options_list[$i]."'");
1784: 
1785:           // ----- Return
1786:           return PclZip::errorCode();
1787:       }
1788: 
1789:       // ----- Next options
1790:       $i++;
1791:     }
1792: 
1793:     // ----- Look for mandatory options
1794:     if ($v_requested_options !== false) {
1795:       for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
1796:         // ----- Look for mandatory option
1797:         if ($v_requested_options[$key] == 'mandatory') {
1798:           // ----- Look if present
1799:           if (!isset($v_result_list[$key])) {
1800:             // ----- Error log
1801:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
1802: 
1803:             // ----- Return
1804:             return PclZip::errorCode();
1805:           }
1806:         }
1807:       }
1808:     }
1809: 
1810:     // ----- Look for default values
1811:     if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
1812: 
1813:     }
1814: 
1815:     // ----- Return
1816:     return $v_result;
1817:   }
1818:   // --------------------------------------------------------------------------------
1819: 
1820:   // --------------------------------------------------------------------------------
1821:   // Function : privOptionDefaultThreshold()
1822:   // Description :
1823:   // Parameters :
1824:   // Return Values :
1825:   // --------------------------------------------------------------------------------
1826:   function privOptionDefaultThreshold(&$p_options)
1827:   {
1828:     $v_result=1;
1829: 
1830:     if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
1831:         || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
1832:       return $v_result;
1833:     }
1834: 
1835:     // ----- Get 'memory_limit' configuration value
1836:     $v_memory_limit = ini_get('memory_limit');
1837:     $v_memory_limit = trim($v_memory_limit);
1838:     $last = strtolower(substr($v_memory_limit, -1));
1839: 
1840:     if($last == 'g')
1841:         //$v_memory_limit = $v_memory_limit*1024*1024*1024;
1842:         $v_memory_limit = $v_memory_limit*1073741824;
1843:     if($last == 'm')
1844:         //$v_memory_limit = $v_memory_limit*1024*1024;
1845:         $v_memory_limit = $v_memory_limit*1048576;
1846:     if($last == 'k')
1847:         $v_memory_limit = $v_memory_limit*1024;
1848: 
1849:     $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
1850: 
1851: 
1852:     // ----- Sanity check : No threshold if value lower than 1M
1853:     if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
1854:       unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
1855:     }
1856: 
1857:     // ----- Return
1858:     return $v_result;
1859:   }
1860:   // --------------------------------------------------------------------------------
1861: 
1862:   // --------------------------------------------------------------------------------
1863:   // Function : privFileDescrParseAtt()
1864:   // Description :
1865:   // Parameters :
1866:   // Return Values :
1867:   //   1 on success.
1868:   //   0 on failure.
1869:   // --------------------------------------------------------------------------------
1870:   function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
1871:   {
1872:     $v_result=1;
1873: 
1874:     // ----- For each file in the list check the attributes
1875:     foreach ($p_file_list as $v_key => $v_value) {
1876: 
1877:       // ----- Check if the option is supported
1878:       if (!isset($v_requested_options[$v_key])) {
1879:         // ----- Error log
1880:         PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
1881: 
1882:         // ----- Return
1883:         return PclZip::errorCode();
1884:       }
1885: 
1886:       // ----- Look for attribute
1887:       switch ($v_key) {
1888:         case PCLZIP_ATT_FILE_NAME :
1889:           if (!is_string($v_value)) {
1890:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
1891:             return PclZip::errorCode();
1892:           }
1893: 
1894:           $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
1895: 
1896:           if ($p_filedescr['filename'] == '') {
1897:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
1898:             return PclZip::errorCode();
1899:           }
1900: 
1901:         break;
1902: 
1903:         case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
1904:           if (!is_string($v_value)) {
1905:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
1906:             return PclZip::errorCode();
1907:           }
1908: 
1909:           $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
1910: 
1911:           if ($p_filedescr['new_short_name'] == '') {
1912:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
1913:             return PclZip::errorCode();
1914:           }
1915:         break;
1916: 
1917:         case PCLZIP_ATT_FILE_NEW_FULL_NAME :
1918:           if (!is_string($v_value)) {
1919:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
1920:             return PclZip::errorCode();
1921:           }
1922: 
1923:           $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
1924: 
1925:           if ($p_filedescr['new_full_name'] == '') {
1926:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
1927:             return PclZip::errorCode();
1928:           }
1929:         break;
1930: 
1931:         // ----- Look for options that takes a string
1932:         case PCLZIP_ATT_FILE_COMMENT :
1933:           if (!is_string($v_value)) {
1934:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
1935:             return PclZip::errorCode();
1936:           }
1937: 
1938:           $p_filedescr['comment'] = $v_value;
1939:         break;
1940: 
1941:         case PCLZIP_ATT_FILE_MTIME :
1942:           if (!is_integer($v_value)) {
1943:             PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
1944:             return PclZip::errorCode();
1945:           }
1946: 
1947:           $p_filedescr['mtime'] = $v_value;
1948:         break;
1949: 
1950:         case PCLZIP_ATT_FILE_CONTENT :
1951:           $p_filedescr['content'] = $v_value;
1952:         break;
1953: 
1954:         default :
1955:           // ----- Error log
1956:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
1957:                                    "Unknown parameter '".$v_key."'");
1958: 
1959:           // ----- Return
1960:           return PclZip::errorCode();
1961:       }
1962: 
1963:       // ----- Look for mandatory options
1964:       if ($v_requested_options !== false) {
1965:         for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
1966:           // ----- Look for mandatory option
1967:           if ($v_requested_options[$key] == 'mandatory') {
1968:             // ----- Look if present
1969:             if (!isset($p_file_list[$key])) {
1970:               PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
1971:               return PclZip::errorCode();
1972:             }
1973:           }
1974:         }
1975:       }
1976: 
1977:     // end foreach
1978:     }
1979: 
1980:     // ----- Return
1981:     return $v_result;
1982:   }
1983:   // --------------------------------------------------------------------------------
1984: 
1985:   // --------------------------------------------------------------------------------
1986:   // Function : privFileDescrExpand()
1987:   // Description :
1988:   //   This method look for each item of the list to see if its a file, a folder
1989:   //   or a string to be added as file. For any other type of files (link, other)
1990:   //   just ignore the item.
1991:   //   Then prepare the information that will be stored for that file.
1992:   //   When its a folder, expand the folder with all the files that are in that
1993:   //   folder (recursively).
1994:   // Parameters :
1995:   // Return Values :
1996:   //   1 on success.
1997:   //   0 on failure.
1998:   // --------------------------------------------------------------------------------
1999:   function privFileDescrExpand(&$p_filedescr_list, &$p_options)
2000:   {
2001:     $v_result=1;
2002: 
2003:     // ----- Create a result list
2004:     $v_result_list = array();
2005: 
2006:     // ----- Look each entry
2007:     for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
2008: 
2009:       // ----- Get filedescr
2010:       $v_descr = $p_filedescr_list[$i];
2011: 
2012:       // ----- Reduce the filename
2013:       $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
2014:       $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
2015: 
2016:       // ----- Look for real file or folder
2017:       if (file_exists($v_descr['filename'])) {
2018:         if (@is_file($v_descr['filename'])) {
2019:           $v_descr['type'] = 'file';
2020:         }
2021:         else if (@is_dir($v_descr['filename'])) {
2022:           $v_descr['type'] = 'folder';
2023:         }
2024:         else if (@is_link($v_descr['filename'])) {
2025:           // skip
2026:           continue;
2027:         }
2028:         else {
2029:           // skip
2030:           continue;
2031:         }
2032:       }
2033: 
2034:       // ----- Look for string added as file
2035:       else if (isset($v_descr['content'])) {
2036:         $v_descr['type'] = 'virtual_file';
2037:       }
2038: 
2039:       // ----- Missing file
2040:       else {
2041:         // ----- Error log
2042:         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
2043: 
2044:         // ----- Return
2045:         return PclZip::errorCode();
2046:       }
2047: 
2048:       // ----- Calculate the stored filename
2049:       $this->privCalculateStoredFilename($v_descr, $p_options);
2050: 
2051:       // ----- Add the descriptor in result list
2052:       $v_result_list[sizeof($v_result_list)] = $v_descr;
2053: 
2054:       // ----- Look for folder
2055:       if ($v_descr['type'] == 'folder') {
2056:         // ----- List of items in folder
2057:         $v_dirlist_descr = array();
2058:         $v_dirlist_nb = 0;
2059:         if ($v_folder_handler = @opendir($v_descr['filename'])) {
2060:           while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
2061: 
2062:             // ----- Skip '.' and '..'
2063:             if (($v_item_handler == '.') || ($v_item_handler == '..')) {
2064:                 continue;
2065:             }
2066: 
2067:             // ----- Compose the full filename
2068:             $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
2069: 
2070:             // ----- Look for different stored filename
2071:             // Because the name of the folder was changed, the name of the
2072:             // files/sub-folders also change
2073:             if (($v_descr['stored_filename'] != $v_descr['filename'])
2074:                  && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
2075:               if ($v_descr['stored_filename'] != '') {
2076:                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
2077:               }
2078:               else {
2079:                 $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
2080:               }
2081:             }
2082: 
2083:             $v_dirlist_nb++;
2084:           }
2085: 
2086:           @closedir($v_folder_handler);
2087:         }
2088:         else {
2089:           // TBC : unable to open folder in read mode
2090:         }
2091: 
2092:         // ----- Expand each element of the list
2093:         if ($v_dirlist_nb != 0) {
2094:           // ----- Expand
2095:           if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
2096:             return $v_result;
2097:           }
2098: 
2099:           // ----- Concat the resulting list
2100:           $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
2101:         }
2102:         else {
2103:         }
2104: 
2105:         // ----- Free local array
2106:         unset($v_dirlist_descr);
2107:       }
2108:     }
2109: 
2110:     // ----- Get the result list
2111:     $p_filedescr_list = $v_result_list;
2112: 
2113:     // ----- Return
2114:     return $v_result;
2115:   }
2116:   // --------------------------------------------------------------------------------
2117: 
2118:   // --------------------------------------------------------------------------------
2119:   // Function : privCreate()
2120:   // Description :
2121:   // Parameters :
2122:   // Return Values :
2123:   // --------------------------------------------------------------------------------
2124:   function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
2125:   {
2126:     $v_result=1;
2127:     $v_list_detail = array();
2128: 
2129:     // ----- Magic quotes trick
2130:     $this->privDisableMagicQuotes();
2131: 
2132:     // ----- Open the file in write mode
2133:     if (($v_result = $this->privOpenFd('wb')) != 1)
2134:     {
2135:       // ----- Return
2136:       return $v_result;
2137:     }
2138: 
2139:     // ----- Add the list of files
2140:     $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
2141: 
2142:     // ----- Close
2143:     $this->privCloseFd();
2144: 
2145:     // ----- Magic quotes trick
2146:     $this->privSwapBackMagicQuotes();
2147: 
2148:     // ----- Return
2149:     return $v_result;
2150:   }
2151:   // --------------------------------------------------------------------------------
2152: 
2153:   // --------------------------------------------------------------------------------
2154:   // Function : privAdd()
2155:   // Description :
2156:   // Parameters :
2157:   // Return Values :
2158:   // --------------------------------------------------------------------------------
2159:   function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
2160:   {
2161:     $v_result=1;
2162:     $v_list_detail = array();
2163: 
2164:     // ----- Look if the archive exists or is empty
2165:     if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
2166:     {
2167: 
2168:       // ----- Do a create
2169:       $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
2170: 
2171:       // ----- Return
2172:       return $v_result;
2173:     }
2174:     // ----- Magic quotes trick
2175:     $this->privDisableMagicQuotes();
2176: 
2177:     // ----- Open the zip file
2178:     if (($v_result=$this->privOpenFd('rb')) != 1)
2179:     {
2180:       // ----- Magic quotes trick
2181:       $this->privSwapBackMagicQuotes();
2182: 
2183:       // ----- Return
2184:       return $v_result;
2185:     }
2186: 
2187:     // ----- Read the central directory informations
2188:     $v_central_dir = array();
2189:     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
2190:     {
2191:       $this->privCloseFd();
2192:       $this->privSwapBackMagicQuotes();
2193:       return $v_result;
2194:     }
2195: 
2196:     // ----- Go to beginning of File
2197:     @rewind($this->zip_fd);
2198: 
2199:     // ----- Creates a temporay file
2200:     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
2201: 
2202:     // ----- Open the temporary file in write mode
2203:     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
2204:     {
2205:       $this->privCloseFd();
2206:       $this->privSwapBackMagicQuotes();
2207: 
2208:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
2209: 
2210:       // ----- Return
2211:       return PclZip::errorCode();
2212:     }
2213: 
2214:     // ----- Copy the files from the archive to the temporary file
2215:     // TBC : Here I should better append the file and go back to erase the central dir
2216:     $v_size = $v_central_dir['offset'];
2217:     while ($v_size != 0)
2218:     {
2219:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2220:       $v_buffer = fread($this->zip_fd, $v_read_size);
2221:       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
2222:       $v_size -= $v_read_size;
2223:     }
2224: 
2225:     // ----- Swap the file descriptor
2226:     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
2227:     // the following methods on the temporary fil and not the real archive
2228:     $v_swap = $this->zip_fd;
2229:     $this->zip_fd = $v_zip_temp_fd;
2230:     $v_zip_temp_fd = $v_swap;
2231: 
2232:     // ----- Add the files
2233:     $v_header_list = array();
2234:     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
2235:     {
2236:       fclose($v_zip_temp_fd);
2237:       $this->privCloseFd();
2238:       @unlink($v_zip_temp_name);
2239:       $this->privSwapBackMagicQuotes();
2240: 
2241:       // ----- Return
2242:       return $v_result;
2243:     }
2244: 
2245:     // ----- Store the offset of the central dir
2246:     $v_offset = @ftell($this->zip_fd);
2247: 
2248:     // ----- Copy the block of file headers from the old archive
2249:     $v_size = $v_central_dir['size'];
2250:     while ($v_size != 0)
2251:     {
2252:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2253:       $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
2254:       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
2255:       $v_size -= $v_read_size;
2256:     }
2257: 
2258:     // ----- Create the Central Dir files header
2259:     for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
2260:     {
2261:       // ----- Create the file header
2262:       if ($v_header_list[$i]['status'] == 'ok') {
2263:         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
2264:           fclose($v_zip_temp_fd);
2265:           $this->privCloseFd();
2266:           @unlink($v_zip_temp_name);
2267:           $this->privSwapBackMagicQuotes();
2268: 
2269:           // ----- Return
2270:           return $v_result;
2271:         }
2272:         $v_count++;
2273:       }
2274: 
2275:       // ----- Transform the header to a 'usable' info
2276:       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
2277:     }
2278: 
2279:     // ----- Zip file comment
2280:     $v_comment = $v_central_dir['comment'];
2281:     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
2282:       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
2283:     }
2284:     if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
2285:       $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
2286:     }
2287:     if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
2288:       $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
2289:     }
2290: 
2291:     // ----- Calculate the size of the central header
2292:     $v_size = @ftell($this->zip_fd)-$v_offset;
2293: 
2294:     // ----- Create the central dir footer
2295:     if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
2296:     {
2297:       // ----- Reset the file list
2298:       unset($v_header_list);
2299:       $this->privSwapBackMagicQuotes();
2300: 
2301:       // ----- Return
2302:       return $v_result;
2303:     }
2304: 
2305:     // ----- Swap back the file descriptor
2306:     $v_swap = $this->zip_fd;
2307:     $this->zip_fd = $v_zip_temp_fd;
2308:     $v_zip_temp_fd = $v_swap;
2309: 
2310:     // ----- Close
2311:     $this->privCloseFd();
2312: 
2313:     // ----- Close the temporary file
2314:     @fclose($v_zip_temp_fd);
2315: 
2316:     // ----- Magic quotes trick
2317:     $this->privSwapBackMagicQuotes();
2318: 
2319:     // ----- Delete the zip file
2320:     // TBC : I should test the result ...
2321:     @unlink($this->zipname);
2322: 
2323:     // ----- Rename the temporary file
2324:     // TBC : I should test the result ...
2325:     //@rename($v_zip_temp_name, $this->zipname);
2326:     PclZipUtilRename($v_zip_temp_name, $this->zipname);
2327: 
2328:     // ----- Return
2329:     return $v_result;
2330:   }
2331:   // --------------------------------------------------------------------------------
2332: 
2333:   // --------------------------------------------------------------------------------
2334:   // Function : privOpenFd()
2335:   // Description :
2336:   // Parameters :
2337:   // --------------------------------------------------------------------------------
2338:   function privOpenFd($p_mode)
2339:   {
2340:     $v_result=1;
2341: 
2342:     // ----- Look if already open
2343:     if ($this->zip_fd != 0)
2344:     {
2345:       // ----- Error log
2346:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
2347: 
2348:       // ----- Return
2349:       return PclZip::errorCode();
2350:     }
2351: 
2352:     // ----- Open the zip file
2353:     if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
2354:     {
2355:       // ----- Error log
2356:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
2357: 
2358:       // ----- Return
2359:       return PclZip::errorCode();
2360:     }
2361: 
2362:     // ----- Return
2363:     return $v_result;
2364:   }
2365:   // --------------------------------------------------------------------------------
2366: 
2367:   // --------------------------------------------------------------------------------
2368:   // Function : privCloseFd()
2369:   // Description :
2370:   // Parameters :
2371:   // --------------------------------------------------------------------------------
2372:   function privCloseFd()
2373:   {
2374:     $v_result=1;
2375: 
2376:     if ($this->zip_fd != 0)
2377:       @fclose($this->zip_fd);
2378:     $this->zip_fd = 0;
2379: 
2380:     // ----- Return
2381:     return $v_result;
2382:   }
2383:   // --------------------------------------------------------------------------------
2384: 
2385:   // --------------------------------------------------------------------------------
2386:   // Function : privAddList()
2387:   // Description :
2388:   //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
2389:   //   different from the real path of the file. This is usefull if you want to have PclTar
2390:   //   running in any directory, and memorize relative path from an other directory.
2391:   // Parameters :
2392:   //   $p_list : An array containing the file or directory names to add in the tar
2393:   //   $p_result_list : list of added files with their properties (specially the status field)
2394:   //   $p_add_dir : Path to add in the filename path archived
2395:   //   $p_remove_dir : Path to remove in the filename path archived
2396:   // Return Values :
2397:   // --------------------------------------------------------------------------------
2398: //  function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
2399:   function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
2400:   {
2401:     $v_result=1;
2402: 
2403:     // ----- Add the files
2404:     $v_header_list = array();
2405:     if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
2406:     {
2407:       // ----- Return
2408:       return $v_result;
2409:     }
2410: 
2411:     // ----- Store the offset of the central dir
2412:     $v_offset = @ftell($this->zip_fd);
2413: 
2414:     // ----- Create the Central Dir files header
2415:     for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
2416:     {
2417:       // ----- Create the file header
2418:       if ($v_header_list[$i]['status'] == 'ok') {
2419:         if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
2420:           // ----- Return
2421:           return $v_result;
2422:         }
2423:         $v_count++;
2424:       }
2425: 
2426:       // ----- Transform the header to a 'usable' info
2427:       $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
2428:     }
2429: 
2430:     // ----- Zip file comment
2431:     $v_comment = '';
2432:     if (isset($p_options[PCLZIP_OPT_COMMENT])) {
2433:       $v_comment = $p_options[PCLZIP_OPT_COMMENT];
2434:     }
2435: 
2436:     // ----- Calculate the size of the central header
2437:     $v_size = @ftell($this->zip_fd)-$v_offset;
2438: 
2439:     // ----- Create the central dir footer
2440:     if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
2441:     {
2442:       // ----- Reset the file list
2443:       unset($v_header_list);
2444: 
2445:       // ----- Return
2446:       return $v_result;
2447:     }
2448: 
2449:     // ----- Return
2450:     return $v_result;
2451:   }
2452:   // --------------------------------------------------------------------------------
2453: 
2454:   // --------------------------------------------------------------------------------
2455:   // Function : privAddFileList()
2456:   // Description :
2457:   // Parameters :
2458:   //   $p_filedescr_list : An array containing the file description
2459:   //                      or directory names to add in the zip
2460:   //   $p_result_list : list of added files with their properties (specially the status field)
2461:   // Return Values :
2462:   // --------------------------------------------------------------------------------
2463:   function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
2464:   {
2465:     $v_result=1;
2466:     $v_header = array();
2467: 
2468:     // ----- Recuperate the current number of elt in list
2469:     $v_nb = sizeof($p_result_list);
2470: 
2471:     // ----- Loop on the files
2472:     for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
2473:       // ----- Format the filename
2474:       $p_filedescr_list[$j]['filename']
2475:       = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
2476: 
2477: 
2478:       // ----- Skip empty file names
2479:       // TBC : Can this be possible ? not checked in DescrParseAtt ?
2480:       if ($p_filedescr_list[$j]['filename'] == "") {
2481:         continue;
2482:       }
2483: 
2484:       // ----- Check the filename
2485:       if (   ($p_filedescr_list[$j]['type'] != 'virtual_file')
2486:           && (!file_exists($p_filedescr_list[$j]['filename']))) {
2487:         PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
2488:         return PclZip::errorCode();
2489:       }
2490: 
2491:       // ----- Look if it is a file or a dir with no all path remove option
2492:       // or a dir with all its path removed
2493: //      if (   (is_file($p_filedescr_list[$j]['filename']))
2494: //          || (   is_dir($p_filedescr_list[$j]['filename'])
2495:       if (   ($p_filedescr_list[$j]['type'] == 'file')
2496:           || ($p_filedescr_list[$j]['type'] == 'virtual_file')
2497:           || (   ($p_filedescr_list[$j]['type'] == 'folder')
2498:               && (   !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
2499:                   || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
2500:           ) {
2501: 
2502:         // ----- Add the file
2503:         $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
2504:                                        $p_options);
2505:         if ($v_result != 1) {
2506:           return $v_result;
2507:         }
2508: 
2509:         // ----- Store the file infos
2510:         $p_result_list[$v_nb++] = $v_header;
2511:       }
2512:     }
2513: 
2514:     // ----- Return
2515:     return $v_result;
2516:   }
2517:   // --------------------------------------------------------------------------------
2518: 
2519:   // --------------------------------------------------------------------------------
2520:   // Function : privAddFile()
2521:   // Description :
2522:   // Parameters :
2523:   // Return Values :
2524:   // --------------------------------------------------------------------------------
2525:   function privAddFile($p_filedescr, &$p_header, &$p_options)
2526:   {
2527:     $v_result=1;
2528: 
2529:     // ----- Working variable
2530:     $p_filename = $p_filedescr['filename'];
2531: 
2532:     // TBC : Already done in the fileAtt check ... ?
2533:     if ($p_filename == "") {
2534:       // ----- Error log
2535:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
2536: 
2537:       // ----- Return
2538:       return PclZip::errorCode();
2539:     }
2540: 
2541:     // ----- Look for a stored different filename
2542:     /* TBC : Removed
2543:     if (isset($p_filedescr['stored_filename'])) {
2544:       $v_stored_filename = $p_filedescr['stored_filename'];
2545:     }
2546:     else {
2547:       $v_stored_filename = $p_filedescr['stored_filename'];
2548:     }
2549:     */
2550: 
2551:     // ----- Set the file properties
2552:     clearstatcache();
2553:     $p_header['version'] = 20;
2554:     $p_header['version_extracted'] = 10;
2555:     $p_header['flag'] = 0;
2556:     $p_header['compression'] = 0;
2557:     $p_header['crc'] = 0;
2558:     $p_header['compressed_size'] = 0;
2559:     $p_header['filename_len'] = strlen($p_filename);
2560:     $p_header['extra_len'] = 0;
2561:     $p_header['disk'] = 0;
2562:     $p_header['internal'] = 0;
2563:     $p_header['offset'] = 0;
2564:     $p_header['filename'] = $p_filename;
2565: // TBC : Removed    $p_header['stored_filename'] = $v_stored_filename;
2566:     $p_header['stored_filename'] = $p_filedescr['stored_filename'];
2567:     $p_header['extra'] = '';
2568:     $p_header['status'] = 'ok';
2569:     $p_header['index'] = -1;
2570: 
2571:     // ----- Look for regular file
2572:     if ($p_filedescr['type']=='file') {
2573:       $p_header['external'] = 0x00000000;
2574:       $p_header['size'] = filesize($p_filename);
2575:     }
2576: 
2577:     // ----- Look for regular folder
2578:     else if ($p_filedescr['type']=='folder') {
2579:       $p_header['external'] = 0x00000010;
2580:       $p_header['mtime'] = filemtime($p_filename);
2581:       $p_header['size'] = filesize($p_filename);
2582:     }
2583: 
2584:     // ----- Look for virtual file
2585:     else if ($p_filedescr['type'] == 'virtual_file') {
2586:       $p_header['external'] = 0x00000000;
2587:       $p_header['size'] = strlen($p_filedescr['content']);
2588:     }
2589: 
2590: 
2591:     // ----- Look for filetime
2592:     if (isset($p_filedescr['mtime'])) {
2593:       $p_header['mtime'] = $p_filedescr['mtime'];
2594:     }
2595:     else if ($p_filedescr['type'] == 'virtual_file') {
2596:       $p_header['mtime'] = time();
2597:     }
2598:     else {
2599:       $p_header['mtime'] = filemtime($p_filename);
2600:     }
2601: 
2602:     // ------ Look for file comment
2603:     if (isset($p_filedescr['comment'])) {
2604:       $p_header['comment_len'] = strlen($p_filedescr['comment']);
2605:       $p_header['comment'] = $p_filedescr['comment'];
2606:     }
2607:     else {
2608:       $p_header['comment_len'] = 0;
2609:       $p_header['comment'] = '';
2610:     }
2611: 
2612:     // ----- Look for pre-add callback
2613:     if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
2614: 
2615:       // ----- Generate a local information
2616:       $v_local_header = array();
2617:       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
2618: 
2619:       // ----- Call the callback
2620:       // Here I do not use call_user_func() because I need to send a reference to the
2621:       // header.
2622: //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
2623:       $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
2624:       if ($v_result == 0) {
2625:         // ----- Change the file status
2626:         $p_header['status'] = "skipped";
2627:         $v_result = 1;
2628:       }
2629: 
2630:       // ----- Update the informations
2631:       // Only some fields can be modified
2632:       if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
2633:         $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
2634:       }
2635:     }
2636: 
2637:     // ----- Look for empty stored filename
2638:     if ($p_header['stored_filename'] == "") {
2639:       $p_header['status'] = "filtered";
2640:     }
2641: 
2642:     // ----- Check the path length
2643:     if (strlen($p_header['stored_filename']) > 0xFF) {
2644:       $p_header['status'] = 'filename_too_long';
2645:     }
2646: 
2647:     // ----- Look if no error, or file not skipped
2648:     if ($p_header['status'] == 'ok') {
2649: 
2650:       // ----- Look for a file
2651:       if ($p_filedescr['type'] == 'file') {
2652:         // ----- Look for using temporary file to zip
2653:         if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
2654:             && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
2655:                 || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
2656:                     && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
2657:           $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
2658:           if ($v_result < PCLZIP_ERR_NO_ERROR) {
2659:             return $v_result;
2660:           }
2661:         }
2662: 
2663:         // ----- Use "in memory" zip algo
2664:         else {
2665: 
2666:         // ----- Open the source file
2667:         if (($v_file = @fopen($p_filename, "rb")) == 0) {
2668:           PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
2669:           return PclZip::errorCode();
2670:         }
2671: 
2672:         // ----- Read the file content
2673:         $v_content = @fread($v_file, $p_header['size']);
2674: 
2675:         // ----- Close the file
2676:         @fclose($v_file);
2677: 
2678:         // ----- Calculate the CRC
2679:         $p_header['crc'] = @crc32($v_content);
2680: 
2681:         // ----- Look for no compression
2682:         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
2683:           // ----- Set header parameters
2684:           $p_header['compressed_size'] = $p_header['size'];
2685:           $p_header['compression'] = 0;
2686:         }
2687: 
2688:         // ----- Look for normal compression
2689:         else {
2690:           // ----- Compress the content
2691:           $v_content = @gzdeflate($v_content);
2692: 
2693:           // ----- Set header parameters
2694:           $p_header['compressed_size'] = strlen($v_content);
2695:           $p_header['compression'] = 8;
2696:         }
2697: 
2698:         // ----- Call the header generation
2699:         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
2700:           @fclose($v_file);
2701:           return $v_result;
2702:         }
2703: 
2704:         // ----- Write the compressed (or not) content
2705:         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
2706: 
2707:         }
2708: 
2709:       }
2710: 
2711:       // ----- Look for a virtual file (a file from string)
2712:       else if ($p_filedescr['type'] == 'virtual_file') {
2713: 
2714:         $v_content = $p_filedescr['content'];
2715: 
2716:         // ----- Calculate the CRC
2717:         $p_header['crc'] = @crc32($v_content);
2718: 
2719:         // ----- Look for no compression
2720:         if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
2721:           // ----- Set header parameters
2722:           $p_header['compressed_size'] = $p_header['size'];
2723:           $p_header['compression'] = 0;
2724:         }
2725: 
2726:         // ----- Look for normal compression
2727:         else {
2728:           // ----- Compress the content
2729:           $v_content = @gzdeflate($v_content);
2730: 
2731:           // ----- Set header parameters
2732:           $p_header['compressed_size'] = strlen($v_content);
2733:           $p_header['compression'] = 8;
2734:         }
2735: 
2736:         // ----- Call the header generation
2737:         if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
2738:           return $v_result;
2739:         }
2740: 
2741:         // ----- Write the compressed (or not) content
2742:         @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
2743:       }
2744: 
2745:       // ----- Look for a directory
2746:       else if ($p_filedescr['type'] == 'folder') {
2747:         // ----- Look for directory last '/'
2748:         if (@substr($p_header['stored_filename'], -1) != '/') {
2749:           $p_header['stored_filename'] .= '/';
2750:         }
2751: 
2752:         // ----- Set the file properties
2753:         $p_header['size'] = 0;
2754:         //$p_header['external'] = 0x41FF0010;   // Value for a folder : to be checked
2755:         $p_header['external'] = 0x00000010;   // Value for a folder : to be checked
2756: 
2757:         // ----- Call the header generation
2758:         if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
2759:         {
2760:           return $v_result;
2761:         }
2762:       }
2763:     }
2764: 
2765:     // ----- Look for post-add callback
2766:     if (isset($p_options[PCLZIP_CB_POST_ADD])) {
2767: 
2768:       // ----- Generate a local information
2769:       $v_local_header = array();
2770:       $this->privConvertHeader2FileInfo($p_header, $v_local_header);
2771: 
2772:       // ----- Call the callback
2773:       // Here I do not use call_user_func() because I need to send a reference to the
2774:       // header.
2775: //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
2776:       $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
2777:       if ($v_result == 0) {
2778:         // ----- Ignored
2779:         $v_result = 1;
2780:       }
2781: 
2782:       // ----- Update the informations
2783:       // Nothing can be modified
2784:     }
2785: 
2786:     // ----- Return
2787:     return $v_result;
2788:   }
2789:   // --------------------------------------------------------------------------------
2790: 
2791:   // --------------------------------------------------------------------------------
2792:   // Function : privAddFileUsingTempFile()
2793:   // Description :
2794:   // Parameters :
2795:   // Return Values :
2796:   // --------------------------------------------------------------------------------
2797:   function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
2798:   {
2799:     $v_result=PCLZIP_ERR_NO_ERROR;
2800: 
2801:     // ----- Working variable
2802:     $p_filename = $p_filedescr['filename'];
2803: 
2804: 
2805:     // ----- Open the source file
2806:     if (($v_file = @fopen($p_filename, "rb")) == 0) {
2807:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
2808:       return PclZip::errorCode();
2809:     }
2810: 
2811:     // ----- Creates a compressed temporary file
2812:     $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
2813:     if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
2814:       fclose($v_file);
2815:       PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
2816:       return PclZip::errorCode();
2817:     }
2818: 
2819:     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
2820:     $v_size = filesize($p_filename);
2821:     while ($v_size != 0) {
2822:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2823:       $v_buffer = @fread($v_file, $v_read_size);
2824:       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
2825:       @gzputs($v_file_compressed, $v_buffer, $v_read_size);
2826:       $v_size -= $v_read_size;
2827:     }
2828: 
2829:     // ----- Close the file
2830:     @fclose($v_file);
2831:     @gzclose($v_file_compressed);
2832: 
2833:     // ----- Check the minimum file size
2834:     if (filesize($v_gzip_temp_name) < 18) {
2835:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
2836:       return PclZip::errorCode();
2837:     }
2838: 
2839:     // ----- Extract the compressed attributes
2840:     if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
2841:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
2842:       return PclZip::errorCode();
2843:     }
2844: 
2845:     // ----- Read the gzip file header
2846:     $v_binary_data = @fread($v_file_compressed, 10);
2847:     $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
2848: 
2849:     // ----- Check some parameters
2850:     $v_data_header['os'] = bin2hex($v_data_header['os']);
2851: 
2852:     // ----- Read the gzip file footer
2853:     @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
2854:     $v_binary_data = @fread($v_file_compressed, 8);
2855:     $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
2856: 
2857:     // ----- Set the attributes
2858:     $p_header['compression'] = ord($v_data_header['cm']);
2859:     //$p_header['mtime'] = $v_data_header['mtime'];
2860:     $p_header['crc'] = $v_data_footer['crc'];
2861:     $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
2862: 
2863:     // ----- Close the file
2864:     @fclose($v_file_compressed);
2865: 
2866:     // ----- Call the header generation
2867:     if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
2868:       return $v_result;
2869:     }
2870: 
2871:     // ----- Add the compressed data
2872:     if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
2873:     {
2874:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
2875:       return PclZip::errorCode();
2876:     }
2877: 
2878:     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
2879:     fseek($v_file_compressed, 10);
2880:     $v_size = $p_header['compressed_size'];
2881:     while ($v_size != 0)
2882:     {
2883:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
2884:       $v_buffer = @fread($v_file_compressed, $v_read_size);
2885:       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
2886:       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
2887:       $v_size -= $v_read_size;
2888:     }
2889: 
2890:     // ----- Close the file
2891:     @fclose($v_file_compressed);
2892: 
2893:     // ----- Unlink the temporary file
2894:     @unlink($v_gzip_temp_name);
2895: 
2896:     // ----- Return
2897:     return $v_result;
2898:   }
2899:   // --------------------------------------------------------------------------------
2900: 
2901:   // --------------------------------------------------------------------------------
2902:   // Function : privCalculateStoredFilename()
2903:   // Description :
2904:   //   Based on file descriptor properties and global options, this method
2905:   //   calculate the filename that will be stored in the archive.
2906:   // Parameters :
2907:   // Return Values :
2908:   // --------------------------------------------------------------------------------
2909:   function privCalculateStoredFilename(&$p_filedescr, &$p_options)
2910:   {
2911:     $v_result=1;
2912: 
2913:     // ----- Working variables
2914:     $p_filename = $p_filedescr['filename'];
2915:     if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
2916:       $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
2917:     }
2918:     else {
2919:       $p_add_dir = '';
2920:     }
2921:     if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
2922:       $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
2923:     }
2924:     else {
2925:       $p_remove_dir = '';
2926:     }
2927:     if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
2928:       $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
2929:     }
2930:     else {
2931:       $p_remove_all_dir = 0;
2932:     }
2933: 
2934: 
2935:     // ----- Look for full name change
2936:     if (isset($p_filedescr['new_full_name'])) {
2937:       // ----- Remove drive letter if any
2938:       $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
2939:     }
2940: 
2941:     // ----- Look for path and/or short name change
2942:     else {
2943: 
2944:       // ----- Look for short name change
2945:       // Its when we cahnge just the filename but not the path
2946:       if (isset($p_filedescr['new_short_name'])) {
2947:         $v_path_info = pathinfo($p_filename);
2948:         $v_dir = '';
2949:         if ($v_path_info['dirname'] != '') {
2950:           $v_dir = $v_path_info['dirname'].'/';
2951:         }
2952:         $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
2953:       }
2954:       else {
2955:         // ----- Calculate the stored filename
2956:         $v_stored_filename = $p_filename;
2957:       }
2958: 
2959:       // ----- Look for all path to remove
2960:       if ($p_remove_all_dir) {
2961:         $v_stored_filename = basename($p_filename);
2962:       }
2963:       // ----- Look for partial path remove
2964:       else if ($p_remove_dir != "") {
2965:         if (substr($p_remove_dir, -1) != '/')
2966:           $p_remove_dir .= "/";
2967: 
2968:         if (   (substr($p_filename, 0, 2) == "./")
2969:             || (substr($p_remove_dir, 0, 2) == "./")) {
2970: 
2971:           if (   (substr($p_filename, 0, 2) == "./")
2972:               && (substr($p_remove_dir, 0, 2) != "./")) {
2973:             $p_remove_dir = "./".$p_remove_dir;
2974:           }
2975:           if (   (substr($p_filename, 0, 2) != "./")
2976:               && (substr($p_remove_dir, 0, 2) == "./")) {
2977:             $p_remove_dir = substr($p_remove_dir, 2);
2978:           }
2979:         }
2980: 
2981:         $v_compare = PclZipUtilPathInclusion($p_remove_dir,
2982:                                              $v_stored_filename);
2983:         if ($v_compare > 0) {
2984:           if ($v_compare == 2) {
2985:             $v_stored_filename = "";
2986:           }
2987:           else {
2988:             $v_stored_filename = substr($v_stored_filename,
2989:                                         strlen($p_remove_dir));
2990:           }
2991:         }
2992:       }
2993: 
2994:       // ----- Remove drive letter if any
2995:       $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
2996: 
2997:       // ----- Look for path to add
2998:       if ($p_add_dir != "") {
2999:         if (substr($p_add_dir, -1) == "/")
3000:           $v_stored_filename = $p_add_dir.$v_stored_filename;
3001:         else
3002:           $v_stored_filename = $p_add_dir."/".$v_stored_filename;
3003:       }
3004:     }
3005: 
3006:     // ----- Filename (reduce the path of stored name)
3007:     $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
3008:     $p_filedescr['stored_filename'] = $v_stored_filename;
3009: 
3010:     // ----- Return
3011:     return $v_result;
3012:   }
3013:   // --------------------------------------------------------------------------------
3014: 
3015:   // --------------------------------------------------------------------------------
3016:   // Function : privWriteFileHeader()
3017:   // Description :
3018:   // Parameters :
3019:   // Return Values :
3020:   // --------------------------------------------------------------------------------
3021:   function privWriteFileHeader(&$p_header)
3022:   {
3023:     $v_result=1;
3024: 
3025:     // ----- Store the offset position of the file
3026:     $p_header['offset'] = ftell($this->zip_fd);
3027: 
3028:     // ----- Transform UNIX mtime to DOS format mdate/mtime
3029:     $v_date = getdate($p_header['mtime']);
3030:     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
3031:     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
3032: 
3033:     // ----- Packed data
3034:     $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
3035:                           $p_header['version_extracted'], $p_header['flag'],
3036:                           $p_header['compression'], $v_mtime, $v_mdate,
3037:                           $p_header['crc'], $p_header['compressed_size'],
3038:                           $p_header['size'],
3039:                           strlen($p_header['stored_filename']),
3040:                           $p_header['extra_len']);
3041: 
3042:     // ----- Write the first 148 bytes of the header in the archive
3043:     fputs($this->zip_fd, $v_binary_data, 30);
3044: 
3045:     // ----- Write the variable fields
3046:     if (strlen($p_header['stored_filename']) != 0)
3047:     {
3048:       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
3049:     }
3050:     if ($p_header['extra_len'] != 0)
3051:     {
3052:       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
3053:     }
3054: 
3055:     // ----- Return
3056:     return $v_result;
3057:   }
3058:   // --------------------------------------------------------------------------------
3059: 
3060:   // --------------------------------------------------------------------------------
3061:   // Function : privWriteCentralFileHeader()
3062:   // Description :
3063:   // Parameters :
3064:   // Return Values :
3065:   // --------------------------------------------------------------------------------
3066:   function privWriteCentralFileHeader(&$p_header)
3067:   {
3068:     $v_result=1;
3069: 
3070:     // TBC
3071:     //for(reset($p_header); $key = key($p_header); next($p_header)) {
3072:     //}
3073: 
3074:     // ----- Transform UNIX mtime to DOS format mdate/mtime
3075:     $v_date = getdate($p_header['mtime']);
3076:     $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
3077:     $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
3078: 
3079: 
3080:     // ----- Packed data
3081:     $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
3082:                           $p_header['version'], $p_header['version_extracted'],
3083:                           $p_header['flag'], $p_header['compression'],
3084:                           $v_mtime, $v_mdate, $p_header['crc'],
3085:                           $p_header['compressed_size'], $p_header['size'],
3086:                           strlen($p_header['stored_filename']),
3087:                           $p_header['extra_len'], $p_header['comment_len'],
3088:                           $p_header['disk'], $p_header['internal'],
3089:                           $p_header['external'], $p_header['offset']);
3090: 
3091:     // ----- Write the 42 bytes of the header in the zip file
3092:     fputs($this->zip_fd, $v_binary_data, 46);
3093: 
3094:     // ----- Write the variable fields
3095:     if (strlen($p_header['stored_filename']) != 0)
3096:     {
3097:       fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
3098:     }
3099:     if ($p_header['extra_len'] != 0)
3100:     {
3101:       fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
3102:     }
3103:     if ($p_header['comment_len'] != 0)
3104:     {
3105:       fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
3106:     }
3107: 
3108:     // ----- Return
3109:     return $v_result;
3110:   }
3111:   // --------------------------------------------------------------------------------
3112: 
3113:   // --------------------------------------------------------------------------------
3114:   // Function : privWriteCentralHeader()
3115:   // Description :
3116:   // Parameters :
3117:   // Return Values :
3118:   // --------------------------------------------------------------------------------
3119:   function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
3120:   {
3121:     $v_result=1;
3122: 
3123:     // ----- Packed data
3124:     $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
3125:                           $p_nb_entries, $p_size,
3126:                           $p_offset, strlen($p_comment));
3127: 
3128:     // ----- Write the 22 bytes of the header in the zip file
3129:     fputs($this->zip_fd, $v_binary_data, 22);
3130: 
3131:     // ----- Write the variable fields
3132:     if (strlen($p_comment) != 0)
3133:     {
3134:       fputs($this->zip_fd, $p_comment, strlen($p_comment));
3135:     }
3136: 
3137:     // ----- Return
3138:     return $v_result;
3139:   }
3140:   // --------------------------------------------------------------------------------
3141: 
3142:   // --------------------------------------------------------------------------------
3143:   // Function : privList()
3144:   // Description :
3145:   // Parameters :
3146:   // Return Values :
3147:   // --------------------------------------------------------------------------------
3148:   function privList(&$p_list)
3149:   {
3150:     $v_result=1;
3151: 
3152:     // ----- Magic quotes trick
3153:     $this->privDisableMagicQuotes();
3154: 
3155:     // ----- Open the zip file
3156:     if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
3157:     {
3158:       // ----- Magic quotes trick
3159:       $this->privSwapBackMagicQuotes();
3160: 
3161:       // ----- Error log
3162:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
3163: 
3164:       // ----- Return
3165:       return PclZip::errorCode();
3166:     }
3167: 
3168:     // ----- Read the central directory informations
3169:     $v_central_dir = array();
3170:     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
3171:     {
3172:       $this->privSwapBackMagicQuotes();
3173:       return $v_result;
3174:     }
3175: 
3176:     // ----- Go to beginning of Central Dir
3177:     @rewind($this->zip_fd);
3178:     if (@fseek($this->zip_fd, $v_central_dir['offset']))
3179:     {
3180:       $this->privSwapBackMagicQuotes();
3181: 
3182:       // ----- Error log
3183:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
3184: 
3185:       // ----- Return
3186:       return PclZip::errorCode();
3187:     }
3188: 
3189:     // ----- Read each entry
3190:     for ($i=0; $i<$v_central_dir['entries']; $i++)
3191:     {
3192:       // ----- Read the file header
3193:       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
3194:       {
3195:         $this->privSwapBackMagicQuotes();
3196:         return $v_result;
3197:       }
3198:       $v_header['index'] = $i;
3199: 
3200:       // ----- Get the only interesting attributes
3201:       $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
3202:       unset($v_header);
3203:     }
3204: 
3205:     // ----- Close the zip file
3206:     $this->privCloseFd();
3207: 
3208:     // ----- Magic quotes trick
3209:     $this->privSwapBackMagicQuotes();
3210: 
3211:     // ----- Return
3212:     return $v_result;
3213:   }
3214:   // --------------------------------------------------------------------------------
3215: 
3216:   // --------------------------------------------------------------------------------
3217:   // Function : privConvertHeader2FileInfo()
3218:   // Description :
3219:   //   This function takes the file informations from the central directory
3220:   //   entries and extract the interesting parameters that will be given back.
3221:   //   The resulting file infos are set in the array $p_info
3222:   //     $p_info['filename'] : Filename with full path. Given by user (add),
3223:   //                           extracted in the filesystem (extract).
3224:   //     $p_info['stored_filename'] : Stored filename in the archive.
3225:   //     $p_info['size'] = Size of the file.
3226:   //     $p_info['compressed_size'] = Compressed size of the file.
3227:   //     $p_info['mtime'] = Last modification date of the file.
3228:   //     $p_info['comment'] = Comment associated with the file.
3229:   //     $p_info['folder'] = true/false : indicates if the entry is a folder or not.
3230:   //     $p_info['status'] = status of the action on the file.
3231:   //     $p_info['crc'] = CRC of the file content.
3232:   // Parameters :
3233:   // Return Values :
3234:   // --------------------------------------------------------------------------------
3235:   function privConvertHeader2FileInfo($p_header, &$p_info)
3236:   {
3237:     $v_result=1;
3238: 
3239:     // ----- Get the interesting attributes
3240:     $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
3241:     $p_info['filename'] = $v_temp_path;
3242:     $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
3243:     $p_info['stored_filename'] = $v_temp_path;
3244:     $p_info['size'] = $p_header['size'];
3245:     $p_info['compressed_size'] = $p_header['compressed_size'];
3246:     $p_info['mtime'] = $p_header['mtime'];
3247:     $p_info['comment'] = $p_header['comment'];
3248:     $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
3249:     $p_info['index'] = $p_header['index'];
3250:     $p_info['status'] = $p_header['status'];
3251:     $p_info['crc'] = $p_header['crc'];
3252: 
3253:     // ----- Return
3254:     return $v_result;
3255:   }
3256:   // --------------------------------------------------------------------------------
3257: 
3258:   // --------------------------------------------------------------------------------
3259:   // Function : privExtractByRule()
3260:   // Description :
3261:   //   Extract a file or directory depending of rules (by index, by name, ...)
3262:   // Parameters :
3263:   //   $p_file_list : An array where will be placed the properties of each
3264:   //                  extracted file
3265:   //   $p_path : Path to add while writing the extracted files
3266:   //   $p_remove_path : Path to remove (from the file memorized path) while writing the
3267:   //                    extracted files. If the path does not match the file path,
3268:   //                    the file is extracted with its memorized path.
3269:   //                    $p_remove_path does not apply to 'list' mode.
3270:   //                    $p_path and $p_remove_path are commulative.
3271:   // Return Values :
3272:   //   1 on success,0 or less on error (see error code list)
3273:   // --------------------------------------------------------------------------------
3274:   function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
3275:   {
3276:     $v_result=1;
3277: 
3278:     // ----- Magic quotes trick
3279:     $this->privDisableMagicQuotes();
3280: 
3281:     // ----- Check the path
3282:     if (   ($p_path == "")
3283:         || (   (substr($p_path, 0, 1) != "/")
3284:             && (substr($p_path, 0, 3) != "../")
3285:             && (substr($p_path,1,2)!=":/")))
3286:       $p_path = "./".$p_path;
3287: 
3288:     // ----- Reduce the path last (and duplicated) '/'
3289:     if (($p_path != "./") && ($p_path != "/"))
3290:     {
3291:       // ----- Look for the path end '/'
3292:       while (substr($p_path, -1) == "/")
3293:       {
3294:         $p_path = substr($p_path, 0, strlen($p_path)-1);
3295:       }
3296:     }
3297: 
3298:     // ----- Look for path to remove format (should end by /)
3299:     if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
3300:     {
3301:       $p_remove_path .= '/';
3302:     }
3303:     $p_remove_path_size = strlen($p_remove_path);
3304: 
3305:     // ----- Open the zip file
3306:     if (($v_result = $this->privOpenFd('rb')) != 1)
3307:     {
3308:       $this->privSwapBackMagicQuotes();
3309:       return $v_result;
3310:     }
3311: 
3312:     // ----- Read the central directory informations
3313:     $v_central_dir = array();
3314:     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
3315:     {
3316:       // ----- Close the zip file
3317:       $this->privCloseFd();
3318:       $this->privSwapBackMagicQuotes();
3319: 
3320:       return $v_result;
3321:     }
3322: 
3323:     // ----- Start at beginning of Central Dir
3324:     $v_pos_entry = $v_central_dir['offset'];
3325: 
3326:     // ----- Read each entry
3327:     $j_start = 0;
3328:     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
3329:     {
3330: 
3331:       // ----- Read next Central dir entry
3332:       @rewind($this->zip_fd);
3333:       if (@fseek($this->zip_fd, $v_pos_entry))
3334:       {
3335:         // ----- Close the zip file
3336:         $this->privCloseFd();
3337:         $this->privSwapBackMagicQuotes();
3338: 
3339:         // ----- Error log
3340:         PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
3341: 
3342:         // ----- Return
3343:         return PclZip::errorCode();
3344:       }
3345: 
3346:       // ----- Read the file header
3347:       $v_header = array();
3348:       if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
3349:       {
3350:         // ----- Close the zip file
3351:         $this->privCloseFd();
3352:         $this->privSwapBackMagicQuotes();
3353: 
3354:         return $v_result;
3355:       }
3356: 
3357:       // ----- Store the index
3358:       $v_header['index'] = $i;
3359: 
3360:       // ----- Store the file position
3361:       $v_pos_entry = ftell($this->zip_fd);
3362: 
3363:       // ----- Look for the specific extract rules
3364:       $v_extract = false;
3365: 
3366:       // ----- Look for extract by name rule
3367:       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
3368:           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
3369: 
3370:           // ----- Look if the filename is in the list
3371:           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
3372: 
3373:               // ----- Look for a directory
3374:               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
3375: 
3376:                   // ----- Look if the directory is in the filename path
3377:                   if (   (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
3378:                       && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
3379:                       $v_extract = true;
3380:                   }
3381:               }
3382:               // ----- Look for a filename
3383:               elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
3384:                   $v_extract = true;
3385:               }
3386:           }
3387:       }
3388: 
3389:       // ----- Look for extract by ereg rule
3390:       // ereg() is deprecated with PHP 5.3
3391:       /*
3392:       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
3393:                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
3394: 
3395:           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
3396:               $v_extract = true;
3397:           }
3398:       }
3399:       */
3400: 
3401:       // ----- Look for extract by preg rule
3402:       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
3403:                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
3404: 
3405:           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
3406:               $v_extract = true;
3407:           }
3408:       }
3409: 
3410:       // ----- Look for extract by index rule
3411:       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
3412:                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
3413: 
3414:           // ----- Look if the index is in the list
3415:           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
3416: 
3417:               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
3418:                   $v_extract = true;
3419:               }
3420:               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
3421:                   $j_start = $j+1;
3422:               }
3423: 
3424:               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
3425:                   break;
3426:               }
3427:           }
3428:       }
3429: 
3430:       // ----- Look for no rule, which means extract all the archive
3431:       else {
3432:           $v_extract = true;
3433:       }
3434: 
3435:       // ----- Check compression method
3436:       if (   ($v_extract)
3437:           && (   ($v_header['compression'] != 8)
3438:               && ($v_header['compression'] != 0))) {
3439:           $v_header['status'] = 'unsupported_compression';
3440: 
3441:           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
3442:           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
3443:               && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
3444: 
3445:               $this->privSwapBackMagicQuotes();
3446: 
3447:               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
3448:                                    "Filename '".$v_header['stored_filename']."' is "
3449:                                    ."compressed by an unsupported compression "
3450:                                    ."method (".$v_header['compression'].") ");
3451: 
3452:               return PclZip::errorCode();
3453:           }
3454:       }
3455: 
3456:       // ----- Check encrypted files
3457:       if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
3458:           $v_header['status'] = 'unsupported_encryption';
3459: 
3460:           // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
3461:           if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
3462:               && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
3463: 
3464:               $this->privSwapBackMagicQuotes();
3465: 
3466:               PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
3467:                                    "Unsupported encryption for "
3468:                                    ." filename '".$v_header['stored_filename']
3469:                                    ."'");
3470: 
3471:               return PclZip::errorCode();
3472:           }
3473:     }
3474: 
3475:       // ----- Look for real extraction
3476:       if (($v_extract) && ($v_header['status'] != 'ok')) {
3477:           $v_result = $this->privConvertHeader2FileInfo($v_header,
3478:                                                 $p_file_list[$v_nb_extracted++]);
3479:           if ($v_result != 1) {
3480:               $this->privCloseFd();
3481:               $this->privSwapBackMagicQuotes();
3482:               return $v_result;
3483:           }
3484: 
3485:           $v_extract = false;
3486:       }
3487: 
3488:       // ----- Look for real extraction
3489:       if ($v_extract)
3490:       {
3491: 
3492:         // ----- Go to the file position
3493:         @rewind($this->zip_fd);
3494:         if (@fseek($this->zip_fd, $v_header['offset']))
3495:         {
3496:           // ----- Close the zip file
3497:           $this->privCloseFd();
3498: 
3499:           $this->privSwapBackMagicQuotes();
3500: 
3501:           // ----- Error log
3502:           PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
3503: 
3504:           // ----- Return
3505:           return PclZip::errorCode();
3506:         }
3507: 
3508:         // ----- Look for extraction as string
3509:         if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
3510: 
3511:           $v_string = '';
3512: 
3513:           // ----- Extracting the file
3514:           $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
3515:           if ($v_result1 < 1) {
3516:             $this->privCloseFd();
3517:             $this->privSwapBackMagicQuotes();
3518:             return $v_result1;
3519:           }
3520: 
3521:           // ----- Get the only interesting attributes
3522:           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
3523:           {
3524:             // ----- Close the zip file
3525:             $this->privCloseFd();
3526:             $this->privSwapBackMagicQuotes();
3527: 
3528:             return $v_result;
3529:           }
3530: 
3531:           // ----- Set the file content
3532:           $p_file_list[$v_nb_extracted]['content'] = $v_string;
3533: 
3534:           // ----- Next extracted file
3535:           $v_nb_extracted++;
3536: 
3537:           // ----- Look for user callback abort
3538:           if ($v_result1 == 2) {
3539:             break;
3540:           }
3541:         }
3542:         // ----- Look for extraction in standard output
3543:         elseif (   (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
3544:                 && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
3545:           // ----- Extracting the file in standard output
3546:           $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
3547:           if ($v_result1 < 1) {
3548:             $this->privCloseFd();
3549:             $this->privSwapBackMagicQuotes();
3550:             return $v_result1;
3551:           }
3552: 
3553:           // ----- Get the only interesting attributes
3554:           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
3555:             $this->privCloseFd();
3556:             $this->privSwapBackMagicQuotes();
3557:             return $v_result;
3558:           }
3559: 
3560:           // ----- Look for user callback abort
3561:           if ($v_result1 == 2) {
3562:             break;
3563:           }
3564:         }
3565:         // ----- Look for normal extraction
3566:         else {
3567:           // ----- Extracting the file
3568:           $v_result1 = $this->privExtractFile($v_header,
3569:                                               $p_path, $p_remove_path,
3570:                                               $p_remove_all_path,
3571:                                               $p_options);
3572:           if ($v_result1 < 1) {
3573:             $this->privCloseFd();
3574:             $this->privSwapBackMagicQuotes();
3575:             return $v_result1;
3576:           }
3577: 
3578:           // ----- Get the only interesting attributes
3579:           if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
3580:           {
3581:             // ----- Close the zip file
3582:             $this->privCloseFd();
3583:             $this->privSwapBackMagicQuotes();
3584: 
3585:             return $v_result;
3586:           }
3587: 
3588:           // ----- Look for user callback abort
3589:           if ($v_result1 == 2) {
3590:             break;
3591:           }
3592:         }
3593:       }
3594:     }
3595: 
3596:     // ----- Close the zip file
3597:     $this->privCloseFd();
3598:     $this->privSwapBackMagicQuotes();
3599: 
3600:     // ----- Return
3601:     return $v_result;
3602:   }
3603:   // --------------------------------------------------------------------------------
3604: 
3605:   // --------------------------------------------------------------------------------
3606:   // Function : privExtractFile()
3607:   // Description :
3608:   // Parameters :
3609:   // Return Values :
3610:   //
3611:   // 1 : ... ?
3612:   // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
3613:   // --------------------------------------------------------------------------------
3614:   function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
3615:   {
3616:     $v_result=1;
3617: 
3618:     // ----- Read the file header
3619:     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
3620:     {
3621:       // ----- Return
3622:       return $v_result;
3623:     }
3624: 
3625: 
3626:     // ----- Check that the file header is coherent with $p_entry info
3627:     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
3628:         // TBC
3629:     }
3630: 
3631:     // ----- Look for all path to remove
3632:     if ($p_remove_all_path == true) {
3633:         // ----- Look for folder entry that not need to be extracted
3634:         if (($p_entry['external']&0x00000010)==0x00000010) {
3635: 
3636:             $p_entry['status'] = "filtered";
3637: 
3638:             return $v_result;
3639:         }
3640: 
3641:         // ----- Get the basename of the path
3642:         $p_entry['filename'] = basename($p_entry['filename']);
3643:     }
3644: 
3645:     // ----- Look for path to remove
3646:     else if ($p_remove_path != "")
3647:     {
3648:       if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
3649:       {
3650: 
3651:         // ----- Change the file status
3652:         $p_entry['status'] = "filtered";
3653: 
3654:         // ----- Return
3655:         return $v_result;
3656:       }
3657: 
3658:       $p_remove_path_size = strlen($p_remove_path);
3659:       if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
3660:       {
3661: 
3662:         // ----- Remove the path
3663:         $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
3664: 
3665:       }
3666:     }
3667: 
3668:     // ----- Add the path
3669:     if ($p_path != '') {
3670:       $p_entry['filename'] = $p_path."/".$p_entry['filename'];
3671:     }
3672: 
3673:     // ----- Check a base_dir_restriction
3674:     if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
3675:       $v_inclusion
3676:       = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
3677:                                 $p_entry['filename']);
3678:       if ($v_inclusion == 0) {
3679: 
3680:         PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
3681:                                  "Filename '".$p_entry['filename']."' is "
3682:                                  ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
3683: 
3684:         return PclZip::errorCode();
3685:       }
3686:     }
3687: 
3688:     // ----- Look for pre-extract callback
3689:     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
3690: 
3691:       // ----- Generate a local information
3692:       $v_local_header = array();
3693:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
3694: 
3695:       // ----- Call the callback
3696:       // Here I do not use call_user_func() because I need to send a reference to the
3697:       // header.
3698: //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
3699:       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
3700:       if ($v_result == 0) {
3701:         // ----- Change the file status
3702:         $p_entry['status'] = "skipped";
3703:         $v_result = 1;
3704:       }
3705: 
3706:       // ----- Look for abort result
3707:       if ($v_result == 2) {
3708:         // ----- This status is internal and will be changed in 'skipped'
3709:         $p_entry['status'] = "aborted";
3710:         $v_result = PCLZIP_ERR_USER_ABORTED;
3711:       }
3712: 
3713:       // ----- Update the informations
3714:       // Only some fields can be modified
3715:       $p_entry['filename'] = $v_local_header['filename'];
3716:     }
3717: 
3718: 
3719:     // ----- Look if extraction should be done
3720:     if ($p_entry['status'] == 'ok') {
3721: 
3722:     // ----- Look for specific actions while the file exist
3723:     if (file_exists($p_entry['filename']))
3724:     {
3725: 
3726:       // ----- Look if file is a directory
3727:       if (is_dir($p_entry['filename']))
3728:       {
3729: 
3730:         // ----- Change the file status
3731:         $p_entry['status'] = "already_a_directory";
3732: 
3733:         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
3734:         // For historical reason first PclZip implementation does not stop
3735:         // when this kind of error occurs.
3736:         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
3737:             && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
3738: 
3739:             PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
3740:                                  "Filename '".$p_entry['filename']."' is "
3741:                                  ."already used by an existing directory");
3742: 
3743:             return PclZip::errorCode();
3744:             }
3745:       }
3746:       // ----- Look if file is write protected
3747:       else if (!is_writeable($p_entry['filename']))
3748:       {
3749: 
3750:         // ----- Change the file status
3751:         $p_entry['status'] = "write_protected";
3752: 
3753:         // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
3754:         // For historical reason first PclZip implementation does not stop
3755:         // when this kind of error occurs.
3756:         if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
3757:             && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
3758: 
3759:             PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
3760:                                  "Filename '".$p_entry['filename']."' exists "
3761:                                  ."and is write protected");
3762: 
3763:             return PclZip::errorCode();
3764:             }
3765:       }
3766: 
3767:       // ----- Look if the extracted file is older
3768:       else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
3769:       {
3770:         // ----- Change the file status
3771:         if (   (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
3772:             && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
3773:           }
3774:             else {
3775:             $p_entry['status'] = "newer_exist";
3776: 
3777:             // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
3778:             // For historical reason first PclZip implementation does not stop
3779:             // when this kind of error occurs.
3780:             if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
3781:                 && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
3782: 
3783:                 PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
3784:                          "Newer version of '".$p_entry['filename']."' exists "
3785:                         ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
3786: 
3787:                 return PclZip::errorCode();
3788:               }
3789:             }
3790:       }
3791:       else {
3792:       }
3793:     }
3794: 
3795:     // ----- Check the directory availability and create it if necessary
3796:     else {
3797:       if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
3798:         $v_dir_to_check = $p_entry['filename'];
3799:       else if (!strstr($p_entry['filename'], "/"))
3800:         $v_dir_to_check = "";
3801:       else
3802:         $v_dir_to_check = dirname($p_entry['filename']);
3803: 
3804:         if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
3805: 
3806:           // ----- Change the file status
3807:           $p_entry['status'] = "path_creation_fail";
3808: 
3809:           // ----- Return
3810:           //return $v_result;
3811:           $v_result = 1;
3812:         }
3813:       }
3814:     }
3815: 
3816:     // ----- Look if extraction should be done
3817:     if ($p_entry['status'] == 'ok') {
3818: 
3819:       // ----- Do the extraction (if not a folder)
3820:       if (!(($p_entry['external']&0x00000010)==0x00000010))
3821:       {
3822:         // ----- Look for not compressed file
3823:         if ($p_entry['compression'] == 0) {
3824: 
3825:               // ----- Opening destination file
3826:           if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
3827:           {
3828: 
3829:             // ----- Change the file status
3830:             $p_entry['status'] = "write_error";
3831: 
3832:             // ----- Return
3833:             return $v_result;
3834:           }
3835: 
3836: 
3837:           // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
3838:           $v_size = $p_entry['compressed_size'];
3839:           while ($v_size != 0)
3840:           {
3841:             $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
3842:             $v_buffer = @fread($this->zip_fd, $v_read_size);
3843:             /* Try to speed up the code
3844:             $v_binary_data = pack('a'.$v_read_size, $v_buffer);
3845:             @fwrite($v_dest_file, $v_binary_data, $v_read_size);
3846:             */
3847:             @fwrite($v_dest_file, $v_buffer, $v_read_size);
3848:             $v_size -= $v_read_size;
3849:           }
3850: 
3851:           // ----- Closing the destination file
3852:           fclose($v_dest_file);
3853: 
3854:           // ----- Change the file mtime
3855:           touch($p_entry['filename'], $p_entry['mtime']);
3856: 
3857: 
3858:         }
3859:         else {
3860:           // ----- TBC
3861:           // Need to be finished
3862:           if (($p_entry['flag'] & 1) == 1) {
3863:             PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
3864:             return PclZip::errorCode();
3865:           }
3866: 
3867: 
3868:           // ----- Look for using temporary file to unzip
3869:           if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
3870:               && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
3871:                   || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
3872:                       && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
3873:             $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
3874:             if ($v_result < PCLZIP_ERR_NO_ERROR) {
3875:               return $v_result;
3876:             }
3877:           }
3878: 
3879:           // ----- Look for extract in memory
3880:           else {
3881: 
3882: 
3883:             // ----- Read the compressed file in a buffer (one shot)
3884:             $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
3885: 
3886:             // ----- Decompress the file
3887:             $v_file_content = @gzinflate($v_buffer);
3888:             unset($v_buffer);
3889:             if ($v_file_content === FALSE) {
3890: 
3891:               // ----- Change the file status
3892:               // TBC
3893:               $p_entry['status'] = "error";
3894: 
3895:               return $v_result;
3896:             }
3897: 
3898:             // ----- Opening destination file
3899:             if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
3900: 
3901:               // ----- Change the file status
3902:               $p_entry['status'] = "write_error";
3903: 
3904:               return $v_result;
3905:             }
3906: 
3907:             // ----- Write the uncompressed data
3908:             @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
3909:             unset($v_file_content);
3910: 
3911:             // ----- Closing the destination file
3912:             @fclose($v_dest_file);
3913: 
3914:           }
3915: 
3916:           // ----- Change the file mtime
3917:           @touch($p_entry['filename'], $p_entry['mtime']);
3918:         }
3919: 
3920:         // ----- Look for chmod option
3921:         if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
3922: 
3923:           // ----- Change the mode of the file
3924:           @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
3925:         }
3926: 
3927:       }
3928:     }
3929: 
3930:     // ----- Change abort status
3931:     if ($p_entry['status'] == "aborted") {
3932:         $p_entry['status'] = "skipped";
3933:     }
3934: 
3935:     // ----- Look for post-extract callback
3936:     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
3937: 
3938:       // ----- Generate a local information
3939:       $v_local_header = array();
3940:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
3941: 
3942:       // ----- Call the callback
3943:       // Here I do not use call_user_func() because I need to send a reference to the
3944:       // header.
3945: //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
3946:       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
3947: 
3948:       // ----- Look for abort result
3949:       if ($v_result == 2) {
3950:         $v_result = PCLZIP_ERR_USER_ABORTED;
3951:       }
3952:     }
3953: 
3954:     // ----- Return
3955:     return $v_result;
3956:   }
3957:   // --------------------------------------------------------------------------------
3958: 
3959:   // --------------------------------------------------------------------------------
3960:   // Function : privExtractFileUsingTempFile()
3961:   // Description :
3962:   // Parameters :
3963:   // Return Values :
3964:   // --------------------------------------------------------------------------------
3965:   function privExtractFileUsingTempFile(&$p_entry, &$p_options)
3966:   {
3967:     $v_result=1;
3968: 
3969:     // ----- Creates a temporary file
3970:     $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
3971:     if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
3972:       PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
3973:       return PclZip::errorCode();
3974:     }
3975: 
3976: 
3977:     // ----- Write gz file format header
3978:     $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
3979:     @fwrite($v_dest_file, $v_binary_data, 10);
3980: 
3981:     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
3982:     $v_size = $p_entry['compressed_size'];
3983:     while ($v_size != 0)
3984:     {
3985:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
3986:       $v_buffer = @fread($this->zip_fd, $v_read_size);
3987:       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
3988:       @fwrite($v_dest_file, $v_buffer, $v_read_size);
3989:       $v_size -= $v_read_size;
3990:     }
3991: 
3992:     // ----- Write gz file format footer
3993:     $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
3994:     @fwrite($v_dest_file, $v_binary_data, 8);
3995: 
3996:     // ----- Close the temporary file
3997:     @fclose($v_dest_file);
3998: 
3999:     // ----- Opening destination file
4000:     if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
4001:       $p_entry['status'] = "write_error";
4002:       return $v_result;
4003:     }
4004: 
4005:     // ----- Open the temporary gz file
4006:     if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
4007:       @fclose($v_dest_file);
4008:       $p_entry['status'] = "read_error";
4009:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
4010:       return PclZip::errorCode();
4011:     }
4012: 
4013: 
4014:     // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
4015:     $v_size = $p_entry['size'];
4016:     while ($v_size != 0) {
4017:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
4018:       $v_buffer = @gzread($v_src_file, $v_read_size);
4019:       //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
4020:       @fwrite($v_dest_file, $v_buffer, $v_read_size);
4021:       $v_size -= $v_read_size;
4022:     }
4023:     @fclose($v_dest_file);
4024:     @gzclose($v_src_file);
4025: 
4026:     // ----- Delete the temporary file
4027:     @unlink($v_gzip_temp_name);
4028: 
4029:     // ----- Return
4030:     return $v_result;
4031:   }
4032:   // --------------------------------------------------------------------------------
4033: 
4034:   // --------------------------------------------------------------------------------
4035:   // Function : privExtractFileInOutput()
4036:   // Description :
4037:   // Parameters :
4038:   // Return Values :
4039:   // --------------------------------------------------------------------------------
4040:   function privExtractFileInOutput(&$p_entry, &$p_options)
4041:   {
4042:     $v_result=1;
4043: 
4044:     // ----- Read the file header
4045:     if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
4046:       return $v_result;
4047:     }
4048: 
4049: 
4050:     // ----- Check that the file header is coherent with $p_entry info
4051:     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
4052:         // TBC
4053:     }
4054: 
4055:     // ----- Look for pre-extract callback
4056:     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
4057: 
4058:       // ----- Generate a local information
4059:       $v_local_header = array();
4060:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
4061: 
4062:       // ----- Call the callback
4063:       // Here I do not use call_user_func() because I need to send a reference to the
4064:       // header.
4065: //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
4066:       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
4067:       if ($v_result == 0) {
4068:         // ----- Change the file status
4069:         $p_entry['status'] = "skipped";
4070:         $v_result = 1;
4071:       }
4072: 
4073:       // ----- Look for abort result
4074:       if ($v_result == 2) {
4075:         // ----- This status is internal and will be changed in 'skipped'
4076:         $p_entry['status'] = "aborted";
4077:         $v_result = PCLZIP_ERR_USER_ABORTED;
4078:       }
4079: 
4080:       // ----- Update the informations
4081:       // Only some fields can be modified
4082:       $p_entry['filename'] = $v_local_header['filename'];
4083:     }
4084: 
4085:     // ----- Trace
4086: 
4087:     // ----- Look if extraction should be done
4088:     if ($p_entry['status'] == 'ok') {
4089: 
4090:       // ----- Do the extraction (if not a folder)
4091:       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
4092:         // ----- Look for not compressed file
4093:         if ($p_entry['compressed_size'] == $p_entry['size']) {
4094: 
4095:           // ----- Read the file in a buffer (one shot)
4096:           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
4097: 
4098:           // ----- Send the file to the output
4099:           echo $v_buffer;
4100:           unset($v_buffer);
4101:         }
4102:         else {
4103: 
4104:           // ----- Read the compressed file in a buffer (one shot)
4105:           $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
4106: 
4107:           // ----- Decompress the file
4108:           $v_file_content = gzinflate($v_buffer);
4109:           unset($v_buffer);
4110: 
4111:           // ----- Send the file to the output
4112:           echo $v_file_content;
4113:           unset($v_file_content);
4114:         }
4115:       }
4116:     }
4117: 
4118:     // ----- Change abort status
4119:     if ($p_entry['status'] == "aborted") {
4120:       $p_entry['status'] = "skipped";
4121:     }
4122: 
4123:     // ----- Look for post-extract callback
4124:     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
4125: 
4126:       // ----- Generate a local information
4127:       $v_local_header = array();
4128:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
4129: 
4130:       // ----- Call the callback
4131:       // Here I do not use call_user_func() because I need to send a reference to the
4132:       // header.
4133: //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
4134:       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
4135: 
4136:       // ----- Look for abort result
4137:       if ($v_result == 2) {
4138:         $v_result = PCLZIP_ERR_USER_ABORTED;
4139:       }
4140:     }
4141: 
4142:     return $v_result;
4143:   }
4144:   // --------------------------------------------------------------------------------
4145: 
4146:   // --------------------------------------------------------------------------------
4147:   // Function : privExtractFileAsString()
4148:   // Description :
4149:   // Parameters :
4150:   // Return Values :
4151:   // --------------------------------------------------------------------------------
4152:   function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
4153:   {
4154:     $v_result=1;
4155: 
4156:     // ----- Read the file header
4157:     $v_header = array();
4158:     if (($v_result = $this->privReadFileHeader($v_header)) != 1)
4159:     {
4160:       // ----- Return
4161:       return $v_result;
4162:     }
4163: 
4164: 
4165:     // ----- Check that the file header is coherent with $p_entry info
4166:     if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
4167:         // TBC
4168:     }
4169: 
4170:     // ----- Look for pre-extract callback
4171:     if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
4172: 
4173:       // ----- Generate a local information
4174:       $v_local_header = array();
4175:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
4176: 
4177:       // ----- Call the callback
4178:       // Here I do not use call_user_func() because I need to send a reference to the
4179:       // header.
4180: //      eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
4181:       $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
4182:       if ($v_result == 0) {
4183:         // ----- Change the file status
4184:         $p_entry['status'] = "skipped";
4185:         $v_result = 1;
4186:       }
4187: 
4188:       // ----- Look for abort result
4189:       if ($v_result == 2) {
4190:         // ----- This status is internal and will be changed in 'skipped'
4191:         $p_entry['status'] = "aborted";
4192:         $v_result = PCLZIP_ERR_USER_ABORTED;
4193:       }
4194: 
4195:       // ----- Update the informations
4196:       // Only some fields can be modified
4197:       $p_entry['filename'] = $v_local_header['filename'];
4198:     }
4199: 
4200: 
4201:     // ----- Look if extraction should be done
4202:     if ($p_entry['status'] == 'ok') {
4203: 
4204:       // ----- Do the extraction (if not a folder)
4205:       if (!(($p_entry['external']&0x00000010)==0x00000010)) {
4206:         // ----- Look for not compressed file
4207:   //      if ($p_entry['compressed_size'] == $p_entry['size'])
4208:         if ($p_entry['compression'] == 0) {
4209: 
4210:           // ----- Reading the file
4211:           $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
4212:         }
4213:         else {
4214: 
4215:           // ----- Reading the file
4216:           $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
4217: 
4218:           // ----- Decompress the file
4219:           if (($p_string = @gzinflate($v_data)) === FALSE) {
4220:               // TBC
4221:           }
4222:         }
4223: 
4224:         // ----- Trace
4225:       }
4226:       else {
4227:           // TBC : error : can not extract a folder in a string
4228:       }
4229: 
4230:     }
4231: 
4232:     // ----- Change abort status
4233:     if ($p_entry['status'] == "aborted") {
4234:         $p_entry['status'] = "skipped";
4235:     }
4236: 
4237:     // ----- Look for post-extract callback
4238:     elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
4239: 
4240:       // ----- Generate a local information
4241:       $v_local_header = array();
4242:       $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
4243: 
4244:       // ----- Swap the content to header
4245:       $v_local_header['content'] = $p_string;
4246:       $p_string = '';
4247: 
4248:       // ----- Call the callback
4249:       // Here I do not use call_user_func() because I need to send a reference to the
4250:       // header.
4251: //      eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
4252:       $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
4253: 
4254:       // ----- Swap back the content to header
4255:       $p_string = $v_local_header['content'];
4256:       unset($v_local_header['content']);
4257: 
4258:       // ----- Look for abort result
4259:       if ($v_result == 2) {
4260:         $v_result = PCLZIP_ERR_USER_ABORTED;
4261:       }
4262:     }
4263: 
4264:     // ----- Return
4265:     return $v_result;
4266:   }
4267:   // --------------------------------------------------------------------------------
4268: 
4269:   // --------------------------------------------------------------------------------
4270:   // Function : privReadFileHeader()
4271:   // Description :
4272:   // Parameters :
4273:   // Return Values :
4274:   // --------------------------------------------------------------------------------
4275:   function privReadFileHeader(&$p_header)
4276:   {
4277:     $v_result=1;
4278: 
4279:     // ----- Read the 4 bytes signature
4280:     $v_binary_data = @fread($this->zip_fd, 4);
4281:     $v_data = unpack('Vid', $v_binary_data);
4282: 
4283:     // ----- Check signature
4284:     if ($v_data['id'] != 0x04034b50)
4285:     {
4286: 
4287:       // ----- Error log
4288:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
4289: 
4290:       // ----- Return
4291:       return PclZip::errorCode();
4292:     }
4293: 
4294:     // ----- Read the first 42 bytes of the header
4295:     $v_binary_data = fread($this->zip_fd, 26);
4296: 
4297:     // ----- Look for invalid block size
4298:     if (strlen($v_binary_data) != 26)
4299:     {
4300:       $p_header['filename'] = "";
4301:       $p_header['status'] = "invalid_header";
4302: 
4303:       // ----- Error log
4304:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
4305: 
4306:       // ----- Return
4307:       return PclZip::errorCode();
4308:     }
4309: 
4310:     // ----- Extract the values
4311:     $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
4312: 
4313:     // ----- Get filename
4314:     $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
4315: 
4316:     // ----- Get extra_fields
4317:     if ($v_data['extra_len'] != 0) {
4318:       $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
4319:     }
4320:     else {
4321:       $p_header['extra'] = '';
4322:     }
4323: 
4324:     // ----- Extract properties
4325:     $p_header['version_extracted'] = $v_data['version'];
4326:     $p_header['compression'] = $v_data['compression'];
4327:     $p_header['size'] = $v_data['size'];
4328:     $p_header['compressed_size'] = $v_data['compressed_size'];
4329:     $p_header['crc'] = $v_data['crc'];
4330:     $p_header['flag'] = $v_data['flag'];
4331:     $p_header['filename_len'] = $v_data['filename_len'];
4332: 
4333:     // ----- Recuperate date in UNIX format
4334:     $p_header['mdate'] = $v_data['mdate'];
4335:     $p_header['mtime'] = $v_data['mtime'];
4336:     if ($p_header['mdate'] && $p_header['mtime'])
4337:     {
4338:       // ----- Extract time
4339:       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
4340:       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
4341:       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
4342: 
4343:       // ----- Extract date
4344:       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
4345:       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
4346:       $v_day = $p_header['mdate'] & 0x001F;
4347: 
4348:       // ----- Get UNIX date format
4349:       $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
4350: 
4351:     }
4352:     else
4353:     {
4354:       $p_header['mtime'] = time();
4355:     }
4356: 
4357:     // TBC
4358:     //for(reset($v_data); $key = key($v_data); next($v_data)) {
4359:     //}
4360: 
4361:     // ----- Set the stored filename
4362:     $p_header['stored_filename'] = $p_header['filename'];
4363: 
4364:     // ----- Set the status field
4365:     $p_header['status'] = "ok";
4366: 
4367:     // ----- Return
4368:     return $v_result;
4369:   }
4370:   // --------------------------------------------------------------------------------
4371: 
4372:   // --------------------------------------------------------------------------------
4373:   // Function : privReadCentralFileHeader()
4374:   // Description :
4375:   // Parameters :
4376:   // Return Values :
4377:   // --------------------------------------------------------------------------------
4378:   function privReadCentralFileHeader(&$p_header)
4379:   {
4380:     $v_result=1;
4381: 
4382:     // ----- Read the 4 bytes signature
4383:     $v_binary_data = @fread($this->zip_fd, 4);
4384:     $v_data = unpack('Vid', $v_binary_data);
4385: 
4386:     // ----- Check signature
4387:     if ($v_data['id'] != 0x02014b50)
4388:     {
4389: 
4390:       // ----- Error log
4391:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
4392: 
4393:       // ----- Return
4394:       return PclZip::errorCode();
4395:     }
4396: 
4397:     // ----- Read the first 42 bytes of the header
4398:     $v_binary_data = fread($this->zip_fd, 42);
4399: 
4400:     // ----- Look for invalid block size
4401:     if (strlen($v_binary_data) != 42)
4402:     {
4403:       $p_header['filename'] = "";
4404:       $p_header['status'] = "invalid_header";
4405: 
4406:       // ----- Error log
4407:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
4408: 
4409:       // ----- Return
4410:       return PclZip::errorCode();
4411:     }
4412: 
4413:     // ----- Extract the values
4414:     $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
4415: 
4416:     // ----- Get filename
4417:     if ($p_header['filename_len'] != 0)
4418:       $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
4419:     else
4420:       $p_header['filename'] = '';
4421: 
4422:     // ----- Get extra
4423:     if ($p_header['extra_len'] != 0)
4424:       $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
4425:     else
4426:       $p_header['extra'] = '';
4427: 
4428:     // ----- Get comment
4429:     if ($p_header['comment_len'] != 0)
4430:       $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
4431:     else
4432:       $p_header['comment'] = '';
4433: 
4434:     // ----- Extract properties
4435: 
4436:     // ----- Recuperate date in UNIX format
4437:     //if ($p_header['mdate'] && $p_header['mtime'])
4438:     // TBC : bug : this was ignoring time with 0/0/0
4439:     if (1)
4440:     {
4441:       // ----- Extract time
4442:       $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
4443:       $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
4444:       $v_seconde = ($p_header['mtime'] & 0x001F)*2;
4445: 
4446:       // ----- Extract date
4447:       $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
4448:       $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
4449:       $v_day = $p_header['mdate'] & 0x001F;
4450: 
4451:       // ----- Get UNIX date format
4452:       $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
4453: 
4454:     }
4455:     else
4456:     {
4457:       $p_header['mtime'] = time();
4458:     }
4459: 
4460:     // ----- Set the stored filename
4461:     $p_header['stored_filename'] = $p_header['filename'];
4462: 
4463:     // ----- Set default status to ok
4464:     $p_header['status'] = 'ok';
4465: 
4466:     // ----- Look if it is a directory
4467:     if (substr($p_header['filename'], -1) == '/') {
4468:       //$p_header['external'] = 0x41FF0010;
4469:       $p_header['external'] = 0x00000010;
4470:     }
4471: 
4472: 
4473:     // ----- Return
4474:     return $v_result;
4475:   }
4476:   // --------------------------------------------------------------------------------
4477: 
4478:   // --------------------------------------------------------------------------------
4479:   // Function : privCheckFileHeaders()
4480:   // Description :
4481:   // Parameters :
4482:   // Return Values :
4483:   //   1 on success,
4484:   //   0 on error;
4485:   // --------------------------------------------------------------------------------
4486:   function privCheckFileHeaders(&$p_local_header, &$p_central_header)
4487:   {
4488:     $v_result=1;
4489: 
4490:     // ----- Check the static values
4491:     // TBC
4492:     if ($p_local_header['filename'] != $p_central_header['filename']) {
4493:     }
4494:     if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
4495:     }
4496:     if ($p_local_header['flag'] != $p_central_header['flag']) {
4497:     }
4498:     if ($p_local_header['compression'] != $p_central_header['compression']) {
4499:     }
4500:     if ($p_local_header['mtime'] != $p_central_header['mtime']) {
4501:     }
4502:     if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
4503:     }
4504: 
4505:     // ----- Look for flag bit 3
4506:     if (($p_local_header['flag'] & 8) == 8) {
4507:           $p_local_header['size'] = $p_central_header['size'];
4508:           $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
4509:           $p_local_header['crc'] = $p_central_header['crc'];
4510:     }
4511: 
4512:     // ----- Return
4513:     return $v_result;
4514:   }
4515:   // --------------------------------------------------------------------------------
4516: 
4517:   // --------------------------------------------------------------------------------
4518:   // Function : privReadEndCentralDir()
4519:   // Description :
4520:   // Parameters :
4521:   // Return Values :
4522:   // --------------------------------------------------------------------------------
4523:   function privReadEndCentralDir(&$p_central_dir)
4524:   {
4525:     $v_result=1;
4526: 
4527:     // ----- Go to the end of the zip file
4528:     $v_size = filesize($this->zipname);
4529:     @fseek($this->zip_fd, $v_size);
4530:     if (@ftell($this->zip_fd) != $v_size)
4531:     {
4532:       // ----- Error log
4533:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
4534: 
4535:       // ----- Return
4536:       return PclZip::errorCode();
4537:     }
4538: 
4539:     // ----- First try : look if this is an archive with no commentaries (most of the time)
4540:     // in this case the end of central dir is at 22 bytes of the file end
4541:     $v_found = 0;
4542:     if ($v_size > 26) {
4543:       @fseek($this->zip_fd, $v_size-22);
4544:       if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
4545:       {
4546:         // ----- Error log
4547:         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
4548: 
4549:         // ----- Return
4550:         return PclZip::errorCode();
4551:       }
4552: 
4553:       // ----- Read for bytes
4554:       $v_binary_data = @fread($this->zip_fd, 4);
4555:       $v_data = @unpack('Vid', $v_binary_data);
4556: 
4557:       // ----- Check signature
4558:       if ($v_data['id'] == 0x06054b50) {
4559:         $v_found = 1;
4560:       }
4561: 
4562:       $v_pos = ftell($this->zip_fd);
4563:     }
4564: 
4565:     // ----- Go back to the maximum possible size of the Central Dir End Record
4566:     if (!$v_found) {
4567:       $v_maximum_size = 65557; // 0xFFFF + 22;
4568:       if ($v_maximum_size > $v_size)
4569:         $v_maximum_size = $v_size;
4570:       @fseek($this->zip_fd, $v_size-$v_maximum_size);
4571:       if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
4572:       {
4573:         // ----- Error log
4574:         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
4575: 
4576:         // ----- Return
4577:         return PclZip::errorCode();
4578:       }
4579: 
4580:       // ----- Read byte per byte in order to find the signature
4581:       $v_pos = ftell($this->zip_fd);
4582:       $v_bytes = 0x00000000;
4583:       while ($v_pos < $v_size)
4584:       {
4585:         // ----- Read a byte
4586:         $v_byte = @fread($this->zip_fd, 1);
4587: 
4588:         // -----  Add the byte
4589:         //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
4590:         // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
4591:         // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
4592:         $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
4593: 
4594:         // ----- Compare the bytes
4595:         if ($v_bytes == 0x504b0506)
4596:         {
4597:           $v_pos++;
4598:           break;
4599:         }
4600: 
4601:         $v_pos++;
4602:       }
4603: 
4604:       // ----- Look if not found end of central dir
4605:       if ($v_pos == $v_size)
4606:       {
4607: 
4608:         // ----- Error log
4609:         PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
4610: 
4611:         // ----- Return
4612:         return PclZip::errorCode();
4613:       }
4614:     }
4615: 
4616:     // ----- Read the first 18 bytes of the header
4617:     $v_binary_data = fread($this->zip_fd, 18);
4618: 
4619:     // ----- Look for invalid block size
4620:     if (strlen($v_binary_data) != 18)
4621:     {
4622: 
4623:       // ----- Error log
4624:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
4625: 
4626:       // ----- Return
4627:       return PclZip::errorCode();
4628:     }
4629: 
4630:     // ----- Extract the values
4631:     $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
4632: 
4633:     // ----- Check the global size
4634:     if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
4635: 
4636:       // ----- Removed in release 2.2 see readme file
4637:       // The check of the file size is a little too strict.
4638:       // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
4639:       // While decrypted, zip has training 0 bytes
4640:       if (0) {
4641:       // ----- Error log
4642:       PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
4643:                            'The central dir is not at the end of the archive.'
4644:                            .' Some trailing bytes exists after the archive.');
4645: 
4646:       // ----- Return
4647:       return PclZip::errorCode();
4648:       }
4649:     }
4650: 
4651:     // ----- Get comment
4652:     if ($v_data['comment_size'] != 0) {
4653:       $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
4654:     }
4655:     else
4656:       $p_central_dir['comment'] = '';
4657: 
4658:     $p_central_dir['entries'] = $v_data['entries'];
4659:     $p_central_dir['disk_entries'] = $v_data['disk_entries'];
4660:     $p_central_dir['offset'] = $v_data['offset'];
4661:     $p_central_dir['size'] = $v_data['size'];
4662:     $p_central_dir['disk'] = $v_data['disk'];
4663:     $p_central_dir['disk_start'] = $v_data['disk_start'];
4664: 
4665:     // TBC
4666:     //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
4667:     //}
4668: 
4669:     // ----- Return
4670:     return $v_result;
4671:   }
4672:   // --------------------------------------------------------------------------------
4673: 
4674:   // --------------------------------------------------------------------------------
4675:   // Function : privDeleteByRule()
4676:   // Description :
4677:   // Parameters :
4678:   // Return Values :
4679:   // --------------------------------------------------------------------------------
4680:   function privDeleteByRule(&$p_result_list, &$p_options)
4681:   {
4682:     $v_result=1;
4683:     $v_list_detail = array();
4684: 
4685:     // ----- Open the zip file
4686:     if (($v_result=$this->privOpenFd('rb')) != 1)
4687:     {
4688:       // ----- Return
4689:       return $v_result;
4690:     }
4691: 
4692:     // ----- Read the central directory informations
4693:     $v_central_dir = array();
4694:     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
4695:     {
4696:       $this->privCloseFd();
4697:       return $v_result;
4698:     }
4699: 
4700:     // ----- Go to beginning of File
4701:     @rewind($this->zip_fd);
4702: 
4703:     // ----- Scan all the files
4704:     // ----- Start at beginning of Central Dir
4705:     $v_pos_entry = $v_central_dir['offset'];
4706:     @rewind($this->zip_fd);
4707:     if (@fseek($this->zip_fd, $v_pos_entry))
4708:     {
4709:       // ----- Close the zip file
4710:       $this->privCloseFd();
4711: 
4712:       // ----- Error log
4713:       PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
4714: 
4715:       // ----- Return
4716:       return PclZip::errorCode();
4717:     }
4718: 
4719:     // ----- Read each entry
4720:     $v_header_list = array();
4721:     $j_start = 0;
4722:     for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
4723:     {
4724: 
4725:       // ----- Read the file header
4726:       $v_header_list[$v_nb_extracted] = array();
4727:       if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
4728:       {
4729:         // ----- Close the zip file
4730:         $this->privCloseFd();
4731: 
4732:         return $v_result;
4733:       }
4734: 
4735: 
4736:       // ----- Store the index
4737:       $v_header_list[$v_nb_extracted]['index'] = $i;
4738: 
4739:       // ----- Look for the specific extract rules
4740:       $v_found = false;
4741: 
4742:       // ----- Look for extract by name rule
4743:       if (   (isset($p_options[PCLZIP_OPT_BY_NAME]))
4744:           && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
4745: 
4746:           // ----- Look if the filename is in the list
4747:           for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
4748: 
4749:               // ----- Look for a directory
4750:               if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
4751: 
4752:                   // ----- Look if the directory is in the filename path
4753:                   if (   (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
4754:                       && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
4755:                       $v_found = true;
4756:                   }
4757:                   elseif (   (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
4758:                           && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
4759:                       $v_found = true;
4760:                   }
4761:               }
4762:               // ----- Look for a filename
4763:               elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
4764:                   $v_found = true;
4765:               }
4766:           }
4767:       }
4768: 
4769:       // ----- Look for extract by ereg rule
4770:       // ereg() is deprecated with PHP 5.3
4771:       /*
4772:       else if (   (isset($p_options[PCLZIP_OPT_BY_EREG]))
4773:                && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
4774: 
4775:           if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
4776:               $v_found = true;
4777:           }
4778:       }
4779:       */
4780: 
4781:       // ----- Look for extract by preg rule
4782:       else if (   (isset($p_options[PCLZIP_OPT_BY_PREG]))
4783:                && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
4784: 
4785:           if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
4786:               $v_found = true;
4787:           }
4788:       }
4789: 
4790:       // ----- Look for extract by index rule
4791:       else if (   (isset($p_options[PCLZIP_OPT_BY_INDEX]))
4792:                && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
4793: 
4794:           // ----- Look if the index is in the list
4795:           for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
4796: 
4797:               if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
4798:                   $v_found = true;
4799:               }
4800:               if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
4801:                   $j_start = $j+1;
4802:               }
4803: 
4804:               if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
4805:                   break;
4806:               }
4807:           }
4808:       }
4809:       else {
4810:         $v_found = true;
4811:       }
4812: 
4813:       // ----- Look for deletion
4814:       if ($v_found)
4815:       {
4816:         unset($v_header_list[$v_nb_extracted]);
4817:       }
4818:       else
4819:       {
4820:         $v_nb_extracted++;
4821:       }
4822:     }
4823: 
4824:     // ----- Look if something need to be deleted
4825:     if ($v_nb_extracted > 0) {
4826: 
4827:         // ----- Creates a temporay file
4828:         $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
4829: 
4830:         // ----- Creates a temporary zip archive
4831:         $v_temp_zip = new PclZip($v_zip_temp_name);
4832: 
4833:         // ----- Open the temporary zip file in write mode
4834:         if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
4835:             $this->privCloseFd();
4836: 
4837:             // ----- Return
4838:             return $v_result;
4839:         }
4840: 
4841:         // ----- Look which file need to be kept
4842:         for ($i=0; $i<sizeof($v_header_list); $i++) {
4843: 
4844:             // ----- Calculate the position of the header
4845:             @rewind($this->zip_fd);
4846:             if (@fseek($this->zip_fd,  $v_header_list[$i]['offset'])) {
4847:                 // ----- Close the zip file
4848:                 $this->privCloseFd();
4849:                 $v_temp_zip->privCloseFd();
4850:                 @unlink($v_zip_temp_name);
4851: 
4852:                 // ----- Error log
4853:                 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
4854: 
4855:                 // ----- Return
4856:                 return PclZip::errorCode();
4857:             }
4858: 
4859:             // ----- Read the file header
4860:             $v_local_header = array();
4861:             if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
4862:                 // ----- Close the zip file
4863:                 $this->privCloseFd();
4864:                 $v_temp_zip->privCloseFd();
4865:                 @unlink($v_zip_temp_name);
4866: 
4867:                 // ----- Return
4868:                 return $v_result;
4869:             }
4870: 
4871:             // ----- Check that local file header is same as central file header
4872:             if ($this->privCheckFileHeaders($v_local_header,
4873:                                             $v_header_list[$i]) != 1) {
4874:                 // TBC
4875:             }
4876:             unset($v_local_header);
4877: 
4878:             // ----- Write the file header
4879:             if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
4880:                 // ----- Close the zip file
4881:                 $this->privCloseFd();
4882:                 $v_temp_zip->privCloseFd();
4883:                 @unlink($v_zip_temp_name);
4884: 
4885:                 // ----- Return
4886:                 return $v_result;
4887:             }
4888: 
4889:             // ----- Read/write the data block
4890:             if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
4891:                 // ----- Close the zip file
4892:                 $this->privCloseFd();
4893:                 $v_temp_zip->privCloseFd();
4894:                 @unlink($v_zip_temp_name);
4895: 
4896:                 // ----- Return
4897:                 return $v_result;
4898:             }
4899:         }
4900: 
4901:         // ----- Store the offset of the central dir
4902:         $v_offset = @ftell($v_temp_zip->zip_fd);
4903: 
4904:         // ----- Re-Create the Central Dir files header
4905:         for ($i=0; $i<sizeof($v_header_list); $i++) {
4906:             // ----- Create the file header
4907:             if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
4908:                 $v_temp_zip->privCloseFd();
4909:                 $this->privCloseFd();
4910:                 @unlink($v_zip_temp_name);
4911: 
4912:                 // ----- Return
4913:                 return $v_result;
4914:             }
4915: 
4916:             // ----- Transform the header to a 'usable' info
4917:             $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
4918:         }
4919: 
4920: 
4921:         // ----- Zip file comment
4922:         $v_comment = '';
4923:         if (isset($p_options[PCLZIP_OPT_COMMENT])) {
4924:           $v_comment = $p_options[PCLZIP_OPT_COMMENT];
4925:         }
4926: 
4927:         // ----- Calculate the size of the central header
4928:         $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
4929: 
4930:         // ----- Create the central dir footer
4931:         if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
4932:             // ----- Reset the file list
4933:             unset($v_header_list);
4934:             $v_temp_zip->privCloseFd();
4935:             $this->privCloseFd();
4936:             @unlink($v_zip_temp_name);
4937: 
4938:             // ----- Return
4939:             return $v_result;
4940:         }
4941: 
4942:         // ----- Close
4943:         $v_temp_zip->privCloseFd();
4944:         $this->privCloseFd();
4945: 
4946:         // ----- Delete the zip file
4947:         // TBC : I should test the result ...
4948:         @unlink($this->zipname);
4949: 
4950:         // ----- Rename the temporary file
4951:         // TBC : I should test the result ...
4952:         //@rename($v_zip_temp_name, $this->zipname);
4953:         PclZipUtilRename($v_zip_temp_name, $this->zipname);
4954: 
4955:         // ----- Destroy the temporary archive
4956:         unset($v_temp_zip);
4957:     }
4958: 
4959:     // ----- Remove every files : reset the file
4960:     else if ($v_central_dir['entries'] != 0) {
4961:         $this->privCloseFd();
4962: 
4963:         if (($v_result = $this->privOpenFd('wb')) != 1) {
4964:           return $v_result;
4965:         }
4966: 
4967:         if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
4968:           return $v_result;
4969:         }
4970: 
4971:         $this->privCloseFd();
4972:     }
4973: 
4974:     // ----- Return
4975:     return $v_result;
4976:   }
4977:   // --------------------------------------------------------------------------------
4978: 
4979:   // --------------------------------------------------------------------------------
4980:   // Function : privDirCheck()
4981:   // Description :
4982:   //   Check if a directory exists, if not it creates it and all the parents directory
4983:   //   which may be useful.
4984:   // Parameters :
4985:   //   $p_dir : Directory path to check.
4986:   // Return Values :
4987:   //    1 : OK
4988:   //   -1 : Unable to create directory
4989:   // --------------------------------------------------------------------------------
4990:   function privDirCheck($p_dir, $p_is_dir=false)
4991:   {
4992:     $v_result = 1;
4993: 
4994: 
4995:     // ----- Remove the final '/'
4996:     if (($p_is_dir) && (substr($p_dir, -1)=='/'))
4997:     {
4998:       $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
4999:     }
5000: 
5001:     // ----- Check the directory availability
5002:     if ((is_dir($p_dir)) || ($p_dir == ""))
5003:     {
5004:       return 1;
5005:     }
5006: 
5007:     // ----- Extract parent directory
5008:     $p_parent_dir = dirname($p_dir);
5009: 
5010:     // ----- Just a check
5011:     if ($p_parent_dir != $p_dir)
5012:     {
5013:       // ----- Look for parent directory
5014:       if ($p_parent_dir != "")
5015:       {
5016:         if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
5017:         {
5018:           return $v_result;
5019:         }
5020:       }
5021:     }
5022: 
5023:     // ----- Create the directory
5024:     if (!@mkdir($p_dir, 0777))
5025:     {
5026:       // ----- Error log
5027:       PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
5028: 
5029:       // ----- Return
5030:       return PclZip::errorCode();
5031:     }
5032: 
5033:     // ----- Return
5034:     return $v_result;
5035:   }
5036:   // --------------------------------------------------------------------------------
5037: 
5038:   // --------------------------------------------------------------------------------
5039:   // Function : privMerge()
5040:   // Description :
5041:   //   If $p_archive_to_add does not exist, the function exit with a success result.
5042:   // Parameters :
5043:   // Return Values :
5044:   // --------------------------------------------------------------------------------
5045:   function privMerge(&$p_archive_to_add)
5046:   {
5047:     $v_result=1;
5048: 
5049:     // ----- Look if the archive_to_add exists
5050:     if (!is_file($p_archive_to_add->zipname))
5051:     {
5052: 
5053:       // ----- Nothing to merge, so merge is a success
5054:       $v_result = 1;
5055: 
5056:       // ----- Return
5057:       return $v_result;
5058:     }
5059: 
5060:     // ----- Look if the archive exists
5061:     if (!is_file($this->zipname))
5062:     {
5063: 
5064:       // ----- Do a duplicate
5065:       $v_result = $this->privDuplicate($p_archive_to_add->zipname);
5066: 
5067:       // ----- Return
5068:       return $v_result;
5069:     }
5070: 
5071:     // ----- Open the zip file
5072:     if (($v_result=$this->privOpenFd('rb')) != 1)
5073:     {
5074:       // ----- Return
5075:       return $v_result;
5076:     }
5077: 
5078:     // ----- Read the central directory informations
5079:     $v_central_dir = array();
5080:     if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
5081:     {
5082:       $this->privCloseFd();
5083:       return $v_result;
5084:     }
5085: 
5086:     // ----- Go to beginning of File
5087:     @rewind($this->zip_fd);
5088: 
5089:     // ----- Open the archive_to_add file
5090:     if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
5091:     {
5092:       $this->privCloseFd();
5093: 
5094:       // ----- Return
5095:       return $v_result;
5096:     }
5097: 
5098:     // ----- Read the central directory informations
5099:     $v_central_dir_to_add = array();
5100:     if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
5101:     {
5102:       $this->privCloseFd();
5103:       $p_archive_to_add->privCloseFd();
5104: 
5105:       return $v_result;
5106:     }
5107: 
5108:     // ----- Go to beginning of File
5109:     @rewind($p_archive_to_add->zip_fd);
5110: 
5111:     // ----- Creates a temporay file
5112:     $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
5113: 
5114:     // ----- Open the temporary file in write mode
5115:     if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
5116:     {
5117:       $this->privCloseFd();
5118:       $p_archive_to_add->privCloseFd();
5119: 
5120:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
5121: 
5122:       // ----- Return
5123:       return PclZip::errorCode();
5124:     }
5125: 
5126:     // ----- Copy the files from the archive to the temporary file
5127:     // TBC : Here I should better append the file and go back to erase the central dir
5128:     $v_size = $v_central_dir['offset'];
5129:     while ($v_size != 0)
5130:     {
5131:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
5132:       $v_buffer = fread($this->zip_fd, $v_read_size);
5133:       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
5134:       $v_size -= $v_read_size;
5135:     }
5136: 
5137:     // ----- Copy the files from the archive_to_add into the temporary file
5138:     $v_size = $v_central_dir_to_add['offset'];
5139:     while ($v_size != 0)
5140:     {
5141:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
5142:       $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
5143:       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
5144:       $v_size -= $v_read_size;
5145:     }
5146: 
5147:     // ----- Store the offset of the central dir
5148:     $v_offset = @ftell($v_zip_temp_fd);
5149: 
5150:     // ----- Copy the block of file headers from the old archive
5151:     $v_size = $v_central_dir['size'];
5152:     while ($v_size != 0)
5153:     {
5154:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
5155:       $v_buffer = @fread($this->zip_fd, $v_read_size);
5156:       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
5157:       $v_size -= $v_read_size;
5158:     }
5159: 
5160:     // ----- Copy the block of file headers from the archive_to_add
5161:     $v_size = $v_central_dir_to_add['size'];
5162:     while ($v_size != 0)
5163:     {
5164:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
5165:       $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
5166:       @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
5167:       $v_size -= $v_read_size;
5168:     }
5169: 
5170:     // ----- Merge the file comments
5171:     $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
5172: 
5173:     // ----- Calculate the size of the (new) central header
5174:     $v_size = @ftell($v_zip_temp_fd)-$v_offset;
5175: 
5176:     // ----- Swap the file descriptor
5177:     // Here is a trick : I swap the temporary fd with the zip fd, in order to use
5178:     // the following methods on the temporary fil and not the real archive fd
5179:     $v_swap = $this->zip_fd;
5180:     $this->zip_fd = $v_zip_temp_fd;
5181:     $v_zip_temp_fd = $v_swap;
5182: 
5183:     // ----- Create the central dir footer
5184:     if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
5185:     {
5186:       $this->privCloseFd();
5187:       $p_archive_to_add->privCloseFd();
5188:       @fclose($v_zip_temp_fd);
5189:       $this->zip_fd = null;
5190: 
5191:       // ----- Reset the file list
5192:       unset($v_header_list);
5193: 
5194:       // ----- Return
5195:       return $v_result;
5196:     }
5197: 
5198:     // ----- Swap back the file descriptor
5199:     $v_swap = $this->zip_fd;
5200:     $this->zip_fd = $v_zip_temp_fd;
5201:     $v_zip_temp_fd = $v_swap;
5202: 
5203:     // ----- Close
5204:     $this->privCloseFd();
5205:     $p_archive_to_add->privCloseFd();
5206: 
5207:     // ----- Close the temporary file
5208:     @fclose($v_zip_temp_fd);
5209: 
5210:     // ----- Delete the zip file
5211:     // TBC : I should test the result ...
5212:     @unlink($this->zipname);
5213: 
5214:     // ----- Rename the temporary file
5215:     // TBC : I should test the result ...
5216:     //@rename($v_zip_temp_name, $this->zipname);
5217:     PclZipUtilRename($v_zip_temp_name, $this->zipname);
5218: 
5219:     // ----- Return
5220:     return $v_result;
5221:   }
5222:   // --------------------------------------------------------------------------------
5223: 
5224:   // --------------------------------------------------------------------------------
5225:   // Function : privDuplicate()
5226:   // Description :
5227:   // Parameters :
5228:   // Return Values :
5229:   // --------------------------------------------------------------------------------
5230:   function privDuplicate($p_archive_filename)
5231:   {
5232:     $v_result=1;
5233: 
5234:     // ----- Look if the $p_archive_filename exists
5235:     if (!is_file($p_archive_filename))
5236:     {
5237: 
5238:       // ----- Nothing to duplicate, so duplicate is a success.
5239:       $v_result = 1;
5240: 
5241:       // ----- Return
5242:       return $v_result;
5243:     }
5244: 
5245:     // ----- Open the zip file
5246:     if (($v_result=$this->privOpenFd('wb')) != 1)
5247:     {
5248:       // ----- Return
5249:       return $v_result;
5250:     }
5251: 
5252:     // ----- Open the temporary file in write mode
5253:     if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
5254:     {
5255:       $this->privCloseFd();
5256: 
5257:       PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
5258: 
5259:       // ----- Return
5260:       return PclZip::errorCode();
5261:     }
5262: 
5263:     // ----- Copy the files from the archive to the temporary file
5264:     // TBC : Here I should better append the file and go back to erase the central dir
5265:     $v_size = filesize($p_archive_filename);
5266:     while ($v_size != 0)
5267:     {
5268:       $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
5269:       $v_buffer = fread($v_zip_temp_fd, $v_read_size);
5270:       @fwrite($this->zip_fd, $v_buffer, $v_read_size);
5271:       $v_size -= $v_read_size;
5272:     }
5273: 
5274:     // ----- Close
5275:     $this->privCloseFd();
5276: 
5277:     // ----- Close the temporary file
5278:     @fclose($v_zip_temp_fd);
5279: 
5280:     // ----- Return
5281:     return $v_result;
5282:   }
5283:   // --------------------------------------------------------------------------------
5284: 
5285:   // --------------------------------------------------------------------------------
5286:   // Function : privErrorLog()
5287:   // Description :
5288:   // Parameters :
5289:   // --------------------------------------------------------------------------------
5290:   function privErrorLog($p_error_code=0, $p_error_string='')
5291:   {
5292:     if (PCLZIP_ERROR_EXTERNAL == 1) {
5293:       PclError($p_error_code, $p_error_string);
5294:     }
5295:     else {
5296:       $this->error_code = $p_error_code;
5297:       $this->error_string = $p_error_string;
5298:     }
5299:   }
5300:   // --------------------------------------------------------------------------------
5301: 
5302:   // --------------------------------------------------------------------------------
5303:   // Function : privErrorReset()
5304:   // Description :
5305:   // Parameters :
5306:   // --------------------------------------------------------------------------------
5307:   function privErrorReset()
5308:   {
5309:     if (PCLZIP_ERROR_EXTERNAL == 1) {
5310:       PclErrorReset();
5311:     }
5312:     else {
5313:       $this->error_code = 0;
5314:       $this->error_string = '';
5315:     }
5316:   }
5317:   // --------------------------------------------------------------------------------
5318: 
5319:   // --------------------------------------------------------------------------------
5320:   // Function : privDisableMagicQuotes()
5321:   // Description :
5322:   // Parameters :
5323:   // Return Values :
5324:   // --------------------------------------------------------------------------------
5325:   function privDisableMagicQuotes()
5326:   {
5327:     $v_result=1;
5328: 
5329:     // ----- Look if function exists
5330:     if (   (!function_exists("get_magic_quotes_runtime"))
5331:         || (!function_exists("set_magic_quotes_runtime"))) {
5332:       return $v_result;
5333:     }
5334: 
5335:     // ----- Look if already done
5336:     if ($this->magic_quotes_status != -1) {
5337:       return $v_result;
5338:     }
5339: 
5340:     // ----- Get and memorize the magic_quote value
5341:     $this->magic_quotes_status = @get_magic_quotes_runtime();
5342: 
5343:     // ----- Disable magic_quotes
5344:     if ($this->magic_quotes_status == 1) {
5345:       @set_magic_quotes_runtime(0);
5346:     }
5347: 
5348:     // ----- Return
5349:     return $v_result;
5350:   }
5351:   // --------------------------------------------------------------------------------
5352: 
5353:   // --------------------------------------------------------------------------------
5354:   // Function : privSwapBackMagicQuotes()
5355:   // Description :
5356:   // Parameters :
5357:   // Return Values :
5358:   // --------------------------------------------------------------------------------
5359:   function privSwapBackMagicQuotes()
5360:   {
5361:     $v_result=1;
5362: 
5363:     // ----- Look if function exists
5364:     if (   (!function_exists("get_magic_quotes_runtime"))
5365:         || (!function_exists("set_magic_quotes_runtime"))) {
5366:       return $v_result;
5367:     }
5368: 
5369:     // ----- Look if something to do
5370:     if ($this->magic_quotes_status != -1) {
5371:       return $v_result;
5372:     }
5373: 
5374:     // ----- Swap back magic_quotes
5375:     if ($this->magic_quotes_status == 1) {
5376:       @set_magic_quotes_runtime($this->magic_quotes_status);
5377:     }
5378: 
5379:     // ----- Return
5380:     return $v_result;
5381:   }
5382:   // --------------------------------------------------------------------------------
5383: 
5384:   }
5385:   // End of class
5386:   // --------------------------------------------------------------------------------
5387: 
5388:   // --------------------------------------------------------------------------------
5389:   // Function : PclZipUtilPathReduction()
5390:   // Description :
5391:   // Parameters :
5392:   // Return Values :
5393:   // --------------------------------------------------------------------------------
5394:   function PclZipUtilPathReduction($p_dir)
5395:   {
5396:     $v_result = "";
5397: 
5398:     // ----- Look for not empty path
5399:     if ($p_dir != "") {
5400:       // ----- Explode path by directory names
5401:       $v_list = explode("/", $p_dir);
5402: 
5403:       // ----- Study directories from last to first
5404:       $v_skip = 0;
5405:       for ($i=sizeof($v_list)-1; $i>=0; $i--) {
5406:         // ----- Look for current path
5407:         if ($v_list[$i] == ".") {
5408:           // ----- Ignore this directory
5409:           // Should be the first $i=0, but no check is done
5410:         }
5411:         else if ($v_list[$i] == "..") {
5412:           $v_skip++;
5413:         }
5414:         else if ($v_list[$i] == "") {
5415:           // ----- First '/' i.e. root slash
5416:           if ($i == 0) {
5417:             $v_result = "/".$v_result;
5418:             if ($v_skip > 0) {
5419:                 // ----- It is an invalid path, so the path is not modified
5420:                 // TBC
5421:                 $v_result = $p_dir;
5422:                 $v_skip = 0;
5423:             }
5424:           }
5425:           // ----- Last '/' i.e. indicates a directory
5426:           else if ($i == (sizeof($v_list)-1)) {
5427:             $v_result = $v_list[$i];
5428:           }
5429:           // ----- Double '/' inside the path
5430:           else {
5431:             // ----- Ignore only the double '//' in path,
5432:             // but not the first and last '/'
5433:           }
5434:         }
5435:         else {
5436:           // ----- Look for item to skip
5437:           if ($v_skip > 0) {
5438:             $v_skip--;
5439:           }
5440:           else {
5441:             $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
5442:           }
5443:         }
5444:       }
5445: 
5446:       // ----- Look for skip
5447:       if ($v_skip > 0) {
5448:         while ($v_skip > 0) {
5449:             $v_result = '../'.$v_result;
5450:             $v_skip--;
5451:         }
5452:       }
5453:     }
5454: 
5455:     // ----- Return
5456:     return $v_result;
5457:   }
5458:   // --------------------------------------------------------------------------------
5459: 
5460:   // --------------------------------------------------------------------------------
5461:   // Function : PclZipUtilPathInclusion()
5462:   // Description :
5463:   //   This function indicates if the path $p_path is under the $p_dir tree. Or,
5464:   //   said in an other way, if the file or sub-dir $p_path is inside the dir
5465:   //   $p_dir.
5466:   //   The function indicates also if the path is exactly the same as the dir.
5467:   //   This function supports path with duplicated '/' like '//', but does not
5468:   //   support '.' or '..' statements.
5469:   // Parameters :
5470:   // Return Values :
5471:   //   0 if $p_path is not inside directory $p_dir
5472:   //   1 if $p_path is inside directory $p_dir
5473:   //   2 if $p_path is exactly the same as $p_dir
5474:   // --------------------------------------------------------------------------------
5475:   function PclZipUtilPathInclusion($p_dir, $p_path)
5476:   {
5477:     $v_result = 1;
5478: 
5479:     // ----- Look for path beginning by ./
5480:     if (   ($p_dir == '.')
5481:         || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
5482:       $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
5483:     }
5484:     if (   ($p_path == '.')
5485:         || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
5486:       $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
5487:     }
5488: 
5489:     // ----- Explode dir and path by directory separator
5490:     $v_list_dir = explode("/", $p_dir);
5491:     $v_list_dir_size = sizeof($v_list_dir);
5492:     $v_list_path = explode("/", $p_path);
5493:     $v_list_path_size = sizeof($v_list_path);
5494: 
5495:     // ----- Study directories paths
5496:     $i = 0;
5497:     $j = 0;
5498:     while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
5499: 
5500:       // ----- Look for empty dir (path reduction)
5501:       if ($v_list_dir[$i] == '') {
5502:         $i++;
5503:         continue;
5504:       }
5505:       if ($v_list_path[$j] == '') {
5506:         $j++;
5507:         continue;
5508:       }
5509: 
5510:       // ----- Compare the items
5511:       if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != ''))  {
5512:         $v_result = 0;
5513:       }
5514: 
5515:       // ----- Next items
5516:       $i++;
5517:       $j++;
5518:     }
5519: 
5520:     // ----- Look if everything seems to be the same
5521:     if ($v_result) {
5522:       // ----- Skip all the empty items
5523:       while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
5524:       while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
5525: 
5526:       if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
5527:         // ----- There are exactly the same
5528:         $v_result = 2;
5529:       }
5530:       else if ($i < $v_list_dir_size) {
5531:         // ----- The path is shorter than the dir
5532:         $v_result = 0;
5533:       }
5534:     }
5535: 
5536:     // ----- Return
5537:     return $v_result;
5538:   }
5539:   // --------------------------------------------------------------------------------
5540: 
5541:   // --------------------------------------------------------------------------------
5542:   // Function : PclZipUtilCopyBlock()
5543:   // Description :
5544:   // Parameters :
5545:   //   $p_mode : read/write compression mode
5546:   //             0 : src & dest normal
5547:   //             1 : src gzip, dest normal
5548:   //             2 : src normal, dest gzip
5549:   //             3 : src & dest gzip
5550:   // Return Values :
5551:   // --------------------------------------------------------------------------------
5552:   function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
5553:   {
5554:     $v_result = 1;
5555: 
5556:     if ($p_mode==0)
5557:     {
5558:       while ($p_size != 0)
5559:       {
5560:         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
5561:         $v_buffer = @fread($p_src, $v_read_size);
5562:         @fwrite($p_dest, $v_buffer, $v_read_size);
5563:         $p_size -= $v_read_size;
5564:       }
5565:     }
5566:     else if ($p_mode==1)
5567:     {
5568:       while ($p_size != 0)
5569:       {
5570:         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
5571:         $v_buffer = @gzread($p_src, $v_read_size);
5572:         @fwrite($p_dest, $v_buffer, $v_read_size);
5573:         $p_size -= $v_read_size;
5574:       }
5575:     }
5576:     else if ($p_mode==2)
5577:     {
5578:       while ($p_size != 0)
5579:       {
5580:         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
5581:         $v_buffer = @fread($p_src, $v_read_size);
5582:         @gzwrite($p_dest, $v_buffer, $v_read_size);
5583:         $p_size -= $v_read_size;
5584:       }
5585:     }
5586:     else if ($p_mode==3)
5587:     {
5588:       while ($p_size != 0)
5589:       {
5590:         $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
5591:         $v_buffer = @gzread($p_src, $v_read_size);
5592:         @gzwrite($p_dest, $v_buffer, $v_read_size);
5593:         $p_size -= $v_read_size;
5594:       }
5595:     }
5596: 
5597:     // ----- Return
5598:     return $v_result;
5599:   }
5600:   // --------------------------------------------------------------------------------
5601: 
5602:   // --------------------------------------------------------------------------------
5603:   // Function : PclZipUtilRename()
5604:   // Description :
5605:   //   This function tries to do a simple rename() function. If it fails, it
5606:   //   tries to copy the $p_src file in a new $p_dest file and then unlink the
5607:   //   first one.
5608:   // Parameters :
5609:   //   $p_src : Old filename
5610:   //   $p_dest : New filename
5611:   // Return Values :
5612:   //   1 on success, 0 on failure.
5613:   // --------------------------------------------------------------------------------
5614:   function PclZipUtilRename($p_src, $p_dest)
5615:   {
5616:     $v_result = 1;
5617: 
5618:     // ----- Try to rename the files
5619:     if (!@rename($p_src, $p_dest)) {
5620: 
5621:       // ----- Try to copy & unlink the src
5622:       if (!@copy($p_src, $p_dest)) {
5623:         $v_result = 0;
5624:       }
5625:       else if (!@unlink($p_src)) {
5626:         $v_result = 0;
5627:       }
5628:     }
5629: 
5630:     // ----- Return
5631:     return $v_result;
5632:   }
5633:   // --------------------------------------------------------------------------------
5634: 
5635:   // --------------------------------------------------------------------------------
5636:   // Function : PclZipUtilOptionText()
5637:   // Description :
5638:   //   Translate option value in text. Mainly for debug purpose.
5639:   // Parameters :
5640:   //   $p_option : the option value.
5641:   // Return Values :
5642:   //   The option text value.
5643:   // --------------------------------------------------------------------------------
5644:   function PclZipUtilOptionText($p_option)
5645:   {
5646: 
5647:     $v_list = get_defined_constants();
5648:     for (reset($v_list); $v_key = key($v_list); next($v_list)) {
5649:         $v_prefix = substr($v_key, 0, 10);
5650:         if ((   ($v_prefix == 'PCLZIP_OPT')
5651:            || ($v_prefix == 'PCLZIP_CB_')
5652:            || ($v_prefix == 'PCLZIP_ATT'))
5653:             && ($v_list[$v_key] == $p_option)) {
5654:         return $v_key;
5655:         }
5656:     }
5657: 
5658:     $v_result = 'Unknown';
5659: 
5660:     return $v_result;
5661:   }
5662:   // --------------------------------------------------------------------------------
5663: 
5664:   // --------------------------------------------------------------------------------
5665:   // Function : PclZipUtilTranslateWinPath()
5666:   // Description :
5667:   //   Translate windows path by replacing '\' by '/' and optionally removing
5668:   //   drive letter.
5669:   // Parameters :
5670:   //   $p_path : path to translate.
5671:   //   $p_remove_disk_letter : true | false
5672:   // Return Values :
5673:   //   The path translated.
5674:   // --------------------------------------------------------------------------------
5675:   function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
5676:   {
5677:     if (stristr(php_uname(), 'windows')) {
5678:       // ----- Look for potential disk letter
5679:       if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
5680:           $p_path = substr($p_path, $v_position+1);
5681:       }
5682:       // ----- Change potential windows directory separator
5683:       if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
5684:           $p_path = strtr($p_path, '\\', '/');
5685:       }
5686:     }
5687:     return $p_path;
5688:   }
5689:   // --------------------------------------------------------------------------------
5690: 
5691: 
5692: ?>
5693: 
Zenphoto doc API documentation generated by ApiGen