classes/php5_classes/File.class.php

Properties

Description

Holds the geoFile class, which is responsible for file-based operations.

Classes

geoFile

Properties

 
 
System  
No 
No 

Description

As the name implies, this is used for file-based utility methods.

Methods

__construct, _adminError, _isAbsolute, absolutize, cleanPath, copy, correctMSDocMagicMime, download, errorMsg, file_get_contents, fwrite, generateRename, getInstance, getMimeType, inJail, isChild, isWindows, jailTo, mkdir, prettySize, rename, scandir, setChmod, unlink, unzip, useChmod, zip,

__construct( string   $instance, bool   $initChmod = true, ) : n/a

Description

Internal method, initializes static vars for use in the different methods.
This is private on purpose, it should only be created by itself

Arguments

Name Type Description Default
$instance string
$initChmod bool true

Return value

Type Description
n/a n/a

_adminError( string   $msg, ) : n/a

Description

Used internally to add an admin error.

Arguments

Name Type Description Default
$msg string

Return value

Type Description
n/a n/a

_isAbsolute( string   $path, ) : bool

Description

Internal method used to determine if the path is already absolute or not.
Since the path is assumed to already be "cleaned" it is not suitable for use outside of this class. This takes into account windows systems and having a:/ at front

Arguments

Name Type Description Default
$path string

The already-cleaned path to check

Return value

Type Description
bool

Tags

Name Description
since Version 7.1.0

absolutize( string   $path, ) : string

Description

Takes the path, runs it through {@link geoFile::cleanPath()}, and if it does not already start with / it prepends it with the current "jailed to" dir.
Path does not need to be inside "jailed" location (unlike other geoFile methods)

Arguments

Name Type Description Default
$path string

Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
string The absolute path.

cleanPath( string   $path, ) : string

Description

Cleans the path, gets rid of any ".", ".
.", and consecutive /, changes the dir seperator to /. Path does not need to be inside "jailed" location (unlike other geoFile methods)

Arguments

Name Type Description Default
$path string

Return value

Type Description
string

copy( string   $from, string   $to, bool   $emptyDirs = false, ) : bool

Description

Kind of like {@link copy()} but can be used on a directory to copy the entire directory's contents to another location.
The paths in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$from string

The file or directory "from" location. Either absolute location, or relative to the current "jailed" directory.

$to string

The file or directory "to" location. Either absolute location, or relative to the current "jailed" directory.

$emptyDirs bool

If true, will create empty directories.

false

Return value

Type Description
bool True on success, false on failure. If failure, an admin message is generated about what did not work.

correctMSDocMagicMime( string   $extension, string   $mime_type, ) : string

Description

Given the "detected" mime-type when magic detection is used (figuring out mime by looking at file contents), and the file's extension, it figures out if the detected mime-type is wrong due to it being MS zipped document, which indicates the detected mime-type should be ignored and the next "detection" should be attempted, or is detected as application/msword when really it is excel or powerpoint.
.. This is a static method since it only takes the extension and detected mime-type into account, there are no "in jail" checks to make for this. This is used internally by getMimeType() but can be used externally if needed.

Arguments

Name Type Description Default
$extension string

The file's extension, not including beginning '.'

$mime_type string

The detected mime type for the file.

Return value

Type Description
string The corrected mime type if correction is needed, or original mime type if no correction is warranted.

Tags

Name Description
since Version 6.0.0

download( string   $filename, ) : bool

Description

Pushes the given file to the browser.
The path in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$filename string

Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool true on success, false on failure. If failure, it will generate an admin error message as well.

errorMsg( ) : string

Description

Gets the latest error produced, or empty string if no errors were produced yet.

Return value

Type Description
string

file_get_contents( string   $filename, ) : n/a

Description

Works just like the PHP function file_get_contents(), but relative to the currently jailed folder, or absolute location as long as it is within the jailed folder.

Arguments

Name Type Description Default
$filename string

Return value

Type Description
n/a n/a

Tags

Name Description
since Version 5.1.1

fwrite( string   $file, string   $contents, bool   $use_lock = true, ) : bool

Description

Writes the given contents to the given file, making checks along the way in case there are problems, so that an accurate error message can be shown in the case of a problem.
The path in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()} As of version 7.3.0, if $use_lock is true (default value), will obtain an exclusive lock (write lock) on the file prior to writing to it.

Arguments

Name Type Description Default
$file string

Either absolute location, or relative to the current "jailed" directory.

$contents string
$use_lock bool

if false, will NOT try to lock the file when writing. Parameter added in version 7.3.0

true

Return value

Type Description
bool true on success, false on failure. If failure, it will generate an admin error message as well.

generateRename( string   $name, string   $parentDir = null, bool   $appendDate = true, ) : string

Description

Generates a new name, useful for coming up with a re-name for something that already exists, like a template set.
The path in this method (if specified) must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$name string

The current (already used) name

$parentDir string

The parent directory (WITH trailing slash) that the new name will be used in, uses this to check to make sure it creates a name not already in use. If not specified, assumes the current jailed dir. If it is specified, either absolute location, or relative to the current "jailed" directory.

null
$appendDate bool

If true, will append the date to the name YYYY-MM-DD

true

Return value

Type Description
string The rename that is not already in use in the given parent dir.

getInstance( string   $instance = 'default', bool   $initChmod = true, ) : \geoFile

Description

Gets an instance, you can specify a different "name" such as "templates" or whatever you want, so that multiple instances of the geoFile class can exist, with different jailed dirs.
Built in instances: geoFile::BASE - used if nothing specified geoFile::TEMPLATES = jail to GEO_TEMPLATE_DIR geoFile::CACHE = jail to CACHE_DIR (not used yet)

Arguments

Name Type Description Default
$instance string 'default'
$initChmod bool

if false, will skip checking whether to CHMOD 777 the files or not.

true

Return value

Type Description
\geoFile

getMimeType( string   $file, string   $uploadName = '', string   $defaultMime = '', bool   $inJail = true, ) : string|bool

Description

Attempts to detect the mime type of the given file.

Arguments

Name Type Description Default
$file string

File location to detect the file for.

$uploadName string

The name that is "reported" as the actual filename, if different from the file being checked. Will be used to look up the mime type according to extension if no other methods work to determine the mime type.

''
$defaultMime string

The mime type set in file info when uploading file, will be used if no other methods work to determine the mime type.

''
$inJail bool

If false, will not check to make sure the file is in jail, for cases when the file is a temporary file like during file upload

true

Return value

Type Description
string|bool The mime type, or false on failure to detect mime type.

Tags

Name Description
since Version 6.0.0

inJail( string   $location, ) : bool

Description

Figures out whether or not the given location is "in jail" or not. If in admin panel, adds an admin error message. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$location string

Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool

isChild( string   $parent, string   $child, ) : bool

Description

Figured out if the given parent directory is really a parent of the given child directory.
If the parent is not a child of the current jailed directory, this check will automatically fail. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$parent string

The parent directory. Either absolute location, or relative to the current "jailed" directory.

$child string

The child directory. Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool

isWindows( ) : boolean

Description

Quick method to determine if it is windows environment or not

Return value

Type Description
boolean

Tags

Name Description
since Version 7.1.0

jailTo( string   $dir, ) : \geoFile

Description

Specify what directory all geoFile operations must be "jailed" to. If any operations done through the geoFile class are attempted on a location outside the jailTo directory, the operation will fail and admin error thrown.
Note that if this method is not called prior to using another geoFile method, it will default to be "jailed" to the GEO_BASE_DIR.

Arguments

Name Type Description Default
$dir string

Absolute directory to jail to

Return value

Type Description
\geoFile Return this for method chaining (as of version 5.2.0)

mkdir( string   $dir, ) : bool

Description

Makes the given directory (parents as well).
The paths in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$dir string

Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool true on success, false on failure. If failure, it will generate an admin error message as well.

prettySize( int   $size, int   $decimals = 2, ) : string

Description

Simple method to get the "pretty" file size.

Arguments

Name Type Description Default
$size int

The file size to show, in bytes

$decimals int

Number of decimal places to round to, default 2

2

Return value

Type Description
string The pretty file size, something like 1.23 KB

Tags

Name Description
since Version 7.3.0

rename( string   $from, string   $to, ) : bool

Description

Kind of like {@link rename()} but does some checks and makes sure the to's parent directory exists before it attempts to re-name.
The paths in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$from string

directory/file location. Either absolute location, or relative to the current "jailed" directory.

$to string

Absolute directory/file location. Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool true on success, false on failure. If failure, it will generate an admin error message as well.

scandir( string   $dir, bool   $recursive = true, bool   $excludeDirs = true, bool   $onlyDirs = false, int   $sorting_order = 0, string   $localBase = '', ) : array

Description

Gives you an array of the contents of the given directory and optionally, sub-directories, with the key == index for easier management.
The paths in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$dir string

Either absolute location, or relative to the current "jailed" directory.

$recursive bool

Whether to parse sub-directories recursively

true
$excludeDirs bool

If false, will include entry for each directory itself.

true
$onlyDirs bool

If true, will only have entries that are directories.

false
$sorting_order int

See sorting_order var used in build-in scandir() PHP function

0
$localBase string

Should not be used, this is used for recuriviness..

''

Return value

Type Description
array

setChmod( bool   $chmod, ) : \geoFile

Description

Allow setting whether or not to chmod 777 a file/folder, call this before calling other stuff, if you need to use setting other than what is set in DB

Arguments

Name Type Description Default
$chmod bool

Return value

Type Description
\geoFile Return this for method chaining (as of version 5.2.0)

unlink( string   $filename, ) : bool

Description

Used by places to clear all the sub-folders of wherever.
This is DANGEROUS! Carefull what dir you are sicking this thing on! The path in this method must be inside the current "jailed" directory, or the operation will fail and an admin error thrown. {@link geoFile::jailTo()}

Arguments

Name Type Description Default
$filename string

Either absolute location, or relative to the current "jailed" directory.

Return value

Type Description
bool Whether file seems to have been removed or not

unzip( string   $absZipFile, string   $destination, ) : bool

Description

Un-zips the given archived file to the given destination, the destination relative to the current jailed folder.

Arguments

Name Type Description Default
$absZipFile string

The absolute location for the zip file to un-zip. Note that this CAN reside outside of the jailed folder, in order to allow un-ziping files from the temp folder, for zip files uploaded by user.

$destination string

The destination folder, relative to the current jailed folder.

Return value

Type Description
bool True if un-zip successful, false otherwise.

Tags

Name Description
since Version 5.2.0

useChmod( ) : bool

Description

Whether or not to chmod to 0777

Return value

Type Description
bool

zip( array   $sources, string   $destination, ) : bool

Description

Add the array of source files to the specified destination zip file. The file structure in the zip file will be relative to the current jailed folder.

Arguments

Name Type Description Default
$sources array

Array of files and folders, relative to the current jailed folder, to add to the zip archive.

$destination string

The location of the zip archive, relative to the current jailed folder.

Return value

Type Description
bool True if successful, false otherwise.

Tags

Name Description
since Version 5.2.0

Properties

$_ignoreFiles, $_instance,

array  private  static $_ignoreFiles = array('.', '..', '_vti_cnf', '_vti_pvt', '_vti_script', '_vti_txt', '_notes')

This is array of files/folders to ignore when getting array of files at a location.
It contains the obvious . (current dir), .. (parent dir), and all the folder names added by frontpage extensions.

\geoFile  private  static $_instance =

Stores the instance of geoFile used Singleton method


Constants

  ADDON = 'addon'




  BASE = 'default'




  CACHE = 'cache'




  TEMPLATES = 'templates'




Documentation was generated by phpDocumentor 2.2.0 .

Namespaces

  • global

    Packages

    • Default
      • ExampleAddon
        • addon_example_admin
          In charge of doing stuff on the admin side, this is optional.
        • addon_example_info
          Required class for addons, this is the Addon information class, used by the addon system to determine what the addon can do. Also contains info about the addon that can be viewed in the addon management page in the admin.
        • addon_example_pages
          Addon page class, used by the addon system to display pages on the client side.
        • addon_example_setup
          This class is not required. If it, and the function for a particular routine exist, then that function will be called IN ADDITION TO the automated routines of the addon framework.
        • addon_example_tags
          Expects one function for each tag. Function name should be the same as the tag name. Can also have a constructor if anything needs to be constructed.
        • addon_example_util
          This is where to put functions that the main part of the addon will use.
        • eWidgetOrderItem
          This order item is designed to allow users on your site to purchase an eWidget.
      • System
        • DataAccess
          This is the main Database access object.
        • Singleton
          Singleton method class
        • _templateOrderItem
          Developers: use this file as a template to create a new order item.
        • _templatePaymentGateway
          This is the "developer template" payment gateway handler, a developer could use this file as a starting point for creating a new payment gateway in the system.
        • geoAPI
          The main system class for receiving and handling remote API calls, this acts as a translation layer between the communication with the "outside" and each API call.
        • geoAddon
          This is the class that handles anything and everything to do with addons.
        • geoArrayTools
          Utility functions for manipulating arrays
        • geoBrowse
          Contains functions common to browsing listings
        • geoBrowsingFilter
          System for activating, storing, and deactivating browsing filters.
        • geoCJAX
          Class that wraps the CJAX_FRAMEWORK, used to get the CJAX class.
        • geoCache
          This is the main part of the Geo cache system, it does all the "low level" stuff like writing files and escaping cache data.
        • geoCacheModule
          Part of Geo Cache system, specifically tuned to work best with cacheing module data (which will be an array).
        • geoCachePage
          Cache system specifically tuned to work best with cacheing output of pages and modules
        • geoCacheSetting
          Part of Geo Cache system, specifically tuned to work best with cacheing site-wide key=value type settings.
        • geoCacheText
          Part of Geo Cache system, this part specifically tuned to work best with cacheing language specific messages.
        • geoCalendar
          Holds utility method(s) for manipulating stuff dealing with calendar selector.
        • geoCart
          This class is behind the cart, loading all the order items and such and displaying, and processing all the different pages.
        • geoCategory
          Utility class that holds various methods to do stuff with categories in the system.
        • geoCombineResources
          This class helps to combine CSS and JS files, minify them, and optionally compress them.
        • geoCron
          This is the cron job backend, it handles all the communication and security and all that.
        • geoCrypt
          Class to use for encrypting information that needs to be able to be retrieved later.
        • geoDate
          Holds utility method(s) for manipulating stuff dealing with dates.
        • geoEmail
          Class that sends out e-mails.
        • geoFields
          Class that holds settings information for fields to use.
        • geoFieldsField
          A mini object to hold data about a specific field.
        • geoFile
          As the name implies, this is used for file-based utility methods.
        • geoFilter
          A few utility methods, good for filtering stuff.
        • geoFormatString
          Used to display a message nice and pretty, we'll probably be getting rid of this class though so don't go crazy using it.
        • geoHTML
          Class to generate chunks of HTML that are very common, used the most in the admin panel.
        • geoImage
          This class is responsible for a lot of the image processing, along with other aspects like generating the image tag for thumbnails.
        • geoInvoice
          This is the invoice object representing an invoice in the system.
        • geoLeveledField
          Class for doing common things with leveled fields.
        • geoListing
          A listing object, basically a container object for particular listing.
        • geoListingDisplay
          This is basically a container that is responsible for helping to display {listing .
        • geoListingFeed
          Class that helps to render RSS or other types of feeds based on list of listings.
        • geoMaster
          This is dedicated class for getting the value of, and setting, the various "master switches" within the software. Since this is meant as an easy way to get the values of master switches, most of the methods are static.
        • geoNumber
          Utility functions relating to number conversion/manipulation/validation ect.
        • geoOrder
          The geoOrder object, an object representation of an order in the system.
        • geoOrderItem
          The class that all order items must extend.
        • geoPC
          Used for login credential validation, password hashing, etc. along with software licensing.
        • geoPagination
          Utility functions useful for generating pagination of a results page such as when browing ads or searching
        • geoPaymentGateway
          This class should be extended by each different payment gateway, this will have some default functions that each gateway will inherit, and also has a few final static methods used by the system to affect all order items.
        • geoPlanItem
          A container to hold settings for a particular order item type, according to price plan ID, and optionally category ID for category specific settings.
        • geoRecurringBilling
          The geoRecurringBilling object, an object representation of a recurring billing in the system.
        • geoRegion
          Stuff for regions and sub-regions.
        • geoRegistry
          Handy little object, can be used to set registry type settings.
        • geoSearchUtils
          Class for search utilities.
        • geoSellerBuyer
          Handles back-end for the seller/buyer payment gateways, to allow the buyer to more easily pay the seller for a won auction. This handles the underlying system, but the actual work is done by individual seller/buyer gateways, for instance the Paypal buy-now functionality.
        • geoSession
          Manages session storage and session cookies for user sessions.
        • geoString
          Utility functions relating to languages and string manipulation.
        • geoStringData
          This class is to store accented chars, to be used by {@link geoString::removeAccents()}, mainly to keep the String.class.php file un-cluttered.
        • geoTable
          NOT FULLY IMPLEMENTED! Do not use this class yet as it is not finished and may change drastically before we are done with it, or may even be removed.
        • geoTableRow
          NOT FULLY IMPLEMENTED! Do not use this class yet as it is not finished and may change drastically before we are done with it, or may even be removed.
        • geoTableRowset
          NOT FULLY IMPLEMENTED! Do not use this class yet as it is not finished and may change drastically before we are done with it, or may even be removed.
        • geoTableSelect
          Class used to generate a select query, useful when multiple areas want to affect a single query, for instance when generating a search query and there are addons involved.
        • geoTables
          Used to hold database table names, used throughout the code.
        • geoTemplate
          Template object that extends the Smarty class (a 3rd party library) to enable using templates to display things.
        • geoTransaction
          This is the object used for a transaction in the order and invoice system.
        • geoUser
          An object representative of a certain user in the system.
        • geoUserRating
          Store, retrieve, and display inter-user ratings
        • geoUtil
          Misc utility functions
        • geoView
          As the name implies, this is used for creating the page view. It does take a little setup (like any class), the setup is normally done in the display_page method in geoSite, or display_page in geoAdmin if displaying a page in the admin.
        • iApiTransport
          Interface for API Transports, a transport must implement this interface for the system to use it.
        • iOrderItem
          You cannot have abstract static functions, so instead need to have an interface to force the given static functions to be defined.
        • metaDbTables
          Used so that old locations that use the old name geoTables will still work.