Commit e5c6be809efcf65d1d16e5fe856db2e371d06d3a

Authored by kevin_fourie
1 parent 3c133975

Continuation of merge from DEV trunk.

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7884 c91229c3-7414-0410-bfa2-8a42b809f60b
error_01.gif deleted

2.09 KB

errors.css deleted
1   -div#error-container {
2   - width: 500px;
3   - color: #555;
4   - font-size: 11px;
5   - font-family: Verdana, Arial, sans-serif;
6   -}
7   -div#error-container div {
8   - height: 140px;
9   -}
10   -div#error-container h1 {
11   - font-weight: lighter;
12   - font-size: 22px;
13   - margin-left: 100px;
14   -}
15   -div#error-container p {
16   - margin-left: 100px;
17   -}
18   -
19   - div#acc-error {
20   - background: transparent url(error_01.gif) no-repeat top left;
21   - }
22   - div#acc-suspend {
23   - background: transparent url(error_02.gif) no-repeat top left;
24   - }
25   - div#acc-maint {
26   - background: transparent url(error_03.gif) no-repeat top left;
27   - }
28   -
29   -
30   -
31   -
32   -
33   -
34   -
35   -
36   -
37   -
38   -
39   -
40   -
41   -
42   -
43   -
44 0 \ No newline at end of file
thirdparty/pear/File/Archive/Predicate.php 0 → 100644
  1 +<?php
  2 +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3 +
  4 +/**
  5 + * A predicate is an object that can evaluate to true or false depending on the
  6 + * file currently read by a File_Archive_Reader
  7 + *
  8 + * @see File_Archive_Reader_Filter
  9 + *
  10 + * PHP versions 4 and 5
  11 + *
  12 + * This library is free software; you can redistribute it and/or
  13 + * modify it under the terms of the GNU Lesser General Public
  14 + * License as published by the Free Software Foundation; either
  15 + * version 2.1 of the License, or (at your option) any later version.
  16 + *
  17 + * This library is distributed in the hope that it will be useful,
  18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20 + * Lesser General Public License for more details.
  21 + *
  22 + * You should have received a copy of the GNU Lesser General Public
  23 + * License along with this library; if not, write to the Free Software
  24 + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
  25 + *
  26 + * @category File Formats
  27 + * @package File_Archive
  28 + * @author Vincent Lascaux <vincentlascaux@php.net>
  29 + * @copyright 1997-2005 The PHP Group
  30 + * @license http://www.gnu.org/copyleft/lesser.html LGPL
  31 + * @version CVS: $Id: Predicate.php,v 1.7 2005/05/26 21:30:18 vincentlascaux Exp $
  32 + * @link http://pear.php.net/package/File_Archive
  33 + */
  34 +
  35 +require_once "File/Archive/Reader.php";
  36 +
  37 +/**
  38 + * A predicate is an object that can evaluate to true or false depending on the
  39 + * file currently read by a File_Archive_Reader
  40 + *
  41 + * @see File_Archive_Reader_Filter
  42 + */
  43 +class File_Archive_Predicate
  44 +{
  45 + /**
  46 + * Indicates whether the current file from the reader should be kept
  47 + *
  48 + * @param File_Archive_Reader $source Reader which will be filtered
  49 + * @return bool False iif the current file must be filtered out
  50 + */
  51 + function isTrue(&$source)
  52 + {
  53 + return PEAR::raiseError("Predicat abstract function call");
  54 + }
  55 +}
  56 +
  57 +?>
0 58 \ No newline at end of file
... ...
thirdparty/pear/File/Archive/Reader.php 0 → 100644
  1 +<?php
  2 +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3 +
  4 +/**
  5 + * Abstract base class for all the readers
  6 + *
  7 + * A reader is a compilation of serveral files that can be read
  8 + *
  9 + * PHP versions 4 and 5
  10 + *
  11 + * This library is free software; you can redistribute it and/or
  12 + * modify it under the terms of the GNU Lesser General Public
  13 + * License as published by the Free Software Foundation; either
  14 + * version 2.1 of the License, or (at your option) any later version.
  15 + *
  16 + * This library is distributed in the hope that it will be useful,
  17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19 + * Lesser General Public License for more details.
  20 + *
  21 + * You should have received a copy of the GNU Lesser General Public
  22 + * License along with this library; if not, write to the Free Software
  23 + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
  24 + *
  25 + * @category File Formats
  26 + * @package File_Archive
  27 + * @author Vincent Lascaux <vincentlascaux@php.net>
  28 + * @copyright 1997-2005 The PHP Group
  29 + * @license http://www.gnu.org/copyleft/lesser.html LGPL
  30 + * @version CVS: $Id: Reader.php,v 1.33 2005/07/07 12:24:57 vincentlascaux Exp $
  31 + * @link http://pear.php.net/package/File_Archive
  32 + */
  33 +
  34 +require_once "PEAR.php";
  35 +
  36 +/**
  37 + * Abstract base class for all the readers
  38 + *
  39 + * A reader is a compilation of serveral files that can be read
  40 + */
  41 +class File_Archive_Reader
  42 +{
  43 + /**
  44 + * Move to the next file in the reader
  45 + *
  46 + * @return bool false iif no more files are available
  47 + */
  48 + function next()
  49 + {
  50 + return false;
  51 + }
  52 +
  53 + /**
  54 + * Move to the next file whose name is in directory $filename
  55 + * or is exactly $filename
  56 + *
  57 + * @param string $filename Name of the file to find in the archive
  58 + * @param bool $close If true, close the reader and search from the first file
  59 + * @return bool whether the file was found in the archive or not
  60 + */
  61 + function select($filename, $close = true)
  62 + {
  63 + $std = $this->getStandardURL($filename);
  64 +
  65 + if ($close) {
  66 + $error = $this->close();
  67 + if (PEAR::isError($error)) {
  68 + return $error;
  69 + }
  70 + }
  71 + while (($error = $this->next()) === true) {
  72 + $sourceName = $this->getFilename();
  73 + if (
  74 + empty($std) ||
  75 +
  76 + //$std is a file
  77 + $std == $sourceName ||
  78 +
  79 + //$std is a directory
  80 + strncmp($std.'/', $sourceName, strlen($std)+1) == 0
  81 + ) {
  82 + return true;
  83 + }
  84 + }
  85 + return $error;
  86 + }
  87 +
  88 + /**
  89 + * Returns the standard path
  90 + * Changes \ to /
  91 + * Removes the .. and . from the URL
  92 + * @param string $path a valid URL that may contain . or .. and \
  93 + * @static
  94 + */
  95 + function getStandardURL($path)
  96 + {
  97 + if ($path == '.') {
  98 + return '';
  99 + }
  100 + $std = str_replace("\\", "/", $path);
  101 + while ($std != ($std = preg_replace("/[^\/:?]+\/\.\.\//", "", $std))) ;
  102 + $std = str_replace("/./", "", $std);
  103 + if (strncmp($std, "./", 2) == 0) {
  104 + return substr($std, 2);
  105 + } else {
  106 + return $std;
  107 + }
  108 + }
  109 +
  110 + /**
  111 + * Returns the name of the file currently read by the reader
  112 + *
  113 + * Warning: undefined behaviour if no call to next have been
  114 + * done or if last call to next has returned false
  115 + *
  116 + * @return string Name of the current file
  117 + */
  118 + function getFilename()
  119 + {
  120 + return PEAR::raiseError("Reader abstract function call (getFilename)");
  121 + }
  122 +
  123 + /**
  124 + * Returns the list of filenames from the current pos to the end of the source
  125 + * The source will be closed after having called this function
  126 + * This function goes through the whole archive (which may be slow).
  127 + * If you intend to work on the reader, doing it in one pass would be faster
  128 + *
  129 + * @return array filenames from the current pos to the end of the source
  130 + */
  131 + function getFileList()
  132 + {
  133 + $result = array();
  134 + while ( ($error = $this->next()) === true) {
  135 + $result[] = $this->getFilename();
  136 + }
  137 + $this->close();
  138 + if (PEAR::isError($error)) {
  139 + return $error;
  140 + } else {
  141 + return $result;
  142 + }
  143 + }
  144 +
  145 + /**
  146 + * Returns an array of statistics about the file
  147 + * (see the PHP stat function for more information)
  148 + *
  149 + * The returned array may be empty, even if readers should try
  150 + * their best to return as many data as possible
  151 + */
  152 + function getStat() { return array(); }
  153 +
  154 + /**
  155 + * Returns the MIME associated with the current file
  156 + * The default function does that by looking at the extension of the file
  157 + */
  158 + function getMime()
  159 + {
  160 + require_once "File/Archive/Reader/MimeList.php";
  161 + return File_Archive_Reader_GetMime($this->getFilename());
  162 + }
  163 +
  164 + /**
  165 + * If the current file of the archive is a physical file,
  166 + *
  167 + * @return the name of the physical file containing the data
  168 + * or null if no such file exists
  169 + *
  170 + * The data filename may not be the same as the filename.
  171 + */
  172 + function getDataFilename() { return null; }
  173 +
  174 + /**
  175 + * Reads some data from the current file
  176 + * If the end of the file is reached, returns null
  177 + * If $length is not specified, reads up to the end of the file
  178 + * If $length is specified reads up to $length
  179 + */
  180 + function getData($length = -1)
  181 + {
  182 + return PEAR::raiseError("Reader abstract function call (getData)");
  183 + }
  184 +
  185 + /**
  186 + * Skip some data and returns how many bytes have been skipped
  187 + * This is strictly equivalent to
  188 + * return strlen(getData($length))
  189 + * But could be far more efficient
  190 + */
  191 + function skip($length = -1)
  192 + {
  193 + $data = $this->getData($length);
  194 + if (PEAR::isError($data)) {
  195 + return $data;
  196 + } else {
  197 + return strlen($data);
  198 + }
  199 + }
  200 +
  201 + /**
  202 + * Move the current position back of a given amount of bytes.
  203 + * Not all readers may implement this function (a PEAR error will
  204 + * be returned if the reader can't rewind)
  205 + *
  206 + * @param int $length number of bytes to seek before the current pos
  207 + * or -1 to move back to the begining of the current file
  208 + * @return the number of bytes really rewinded (which may be less than
  209 + * $length if the current pos is less than $length
  210 + */
  211 + function rewind($length = -1)
  212 + {
  213 + return PEAR::raiseError('Rewind function is not implemented on this reader');
  214 + }
  215 +
  216 + /**
  217 + * Returns the current offset in the current file
  218 + */
  219 + function tell()
  220 + {
  221 + $offset = $this->rewind();
  222 + $this->skip($offset);
  223 + return $offset;
  224 + }
  225 +
  226 + /**
  227 + * Put back the reader in the state it was before the first call
  228 + * to next()
  229 + */
  230 + function close()
  231 + {
  232 + }
  233 +
  234 + /**
  235 + * Sends the current file to the Writer $writer
  236 + * The data will be sent by chunks of at most $bufferSize bytes
  237 + * If $bufferSize <= 0 (default), the blockSize option is used
  238 + */
  239 + function sendData(&$writer, $bufferSize = 0)
  240 + {
  241 + if (PEAR::isError($writer)) {
  242 + return $writer;
  243 + }
  244 + if ($bufferSize <= 0) {
  245 + $bufferSize = File_Archive::getOption('blockSize');
  246 + }
  247 +
  248 + $filename = $this->getDataFilename();
  249 + if ($filename !== null) {
  250 + $error = $writer->writeFile($filename);
  251 + if (PEAR::isError($error)) {
  252 + return $error;
  253 + }
  254 + } else {
  255 + while (($data = $this->getData($bufferSize)) !== null) {
  256 + if (PEAR::isError($data)) {
  257 + return $data;
  258 + }
  259 + $error = $writer->writeData($data);
  260 + if (PEAR::isError($error)) {
  261 + return $error;
  262 + }
  263 + }
  264 + }
  265 + }
  266 +
  267 + /**
  268 + * Sends the whole reader to $writer and close the reader
  269 + *
  270 + * @param File_Archive_Writer $writer Where to write the files of the reader
  271 + * @param bool $autoClose If true, close $writer at the end of the function.
  272 + * Default value is true
  273 + * @param int $bufferSize Size of the chunks that will be sent to the writer
  274 + * If $bufferSize <= 0 (default value), the blockSize option is used
  275 + */
  276 + function extract(&$writer, $autoClose = true, $bufferSize = 0)
  277 + {
  278 + if (PEAR::isError($writer)) {
  279 + $this->close();
  280 + return $writer;
  281 + }
  282 +
  283 + while (($error = $this->next()) === true) {
  284 + if ($writer->newFileNeedsMIME()) {
  285 + $mime = $this->getMime();
  286 + } else {
  287 + $mime = null;
  288 + }
  289 + $error = $writer->newFile(
  290 + $this->getFilename(),
  291 + $this->getStat(),
  292 + $mime
  293 + );
  294 + if (PEAR::isError($error)) {
  295 + break;
  296 + }
  297 + $error = $this->sendData($writer, $bufferSize);
  298 + if (PEAR::isError($error)) {
  299 + break;
  300 + }
  301 + }
  302 + $this->close();
  303 + if ($autoClose) {
  304 + $writer->close();
  305 + }
  306 + if (PEAR::isError($error)) {
  307 + return $error;
  308 + }
  309 + }
  310 +
  311 + /**
  312 + * Extract only one file (given by the URL)
  313 + *
  314 + * @param string $filename URL of the file to extract from this
  315 + * @param File_Archive_Writer $writer Where to write the file
  316 + * @param bool $autoClose If true, close $writer at the end of the function
  317 + * Default value is true
  318 + * @param int $bufferSize Size of the chunks that will be sent to the writer
  319 + * If $bufferSize <= 0 (default value), the blockSize option is used
  320 + */
  321 + function extractFile($filename, &$writer,
  322 + $autoClose = true, $bufferSize = 0)
  323 + {
  324 + if (PEAR::isError($writer)) {
  325 + return $writer;
  326 + }
  327 +
  328 + if (($error = $this->select($filename)) === true) {
  329 + $result = $this->sendData($writer, $bufferSize);
  330 + if (!PEAR::isError($result)) {
  331 + $result = true;
  332 + }
  333 + } else if ($error === false) {
  334 + $result = PEAR::raiseError("File $filename not found");
  335 + } else {
  336 + $result = $error;
  337 + }
  338 + if ($autoClose) {
  339 + $error = $writer->close();
  340 + if (PEAR::isError($error)) {
  341 + return $error;
  342 + }
  343 + }
  344 + return $result;
  345 + }
  346 +
  347 + /**
  348 + * Return a writer that allows appending files to the archive
  349 + * After having called makeAppendWriter, $this is closed and should not be
  350 + * used until the returned writer is closed.
  351 + *
  352 + * @return a writer that will allow to append files to an existing archive
  353 + * @see makeWriter
  354 + */
  355 + function makeAppendWriter()
  356 + {
  357 + require_once "File/Archive/Predicate/False.php";
  358 + return $this->makeWriterRemoveFiles(new File_Archive_Predicate_False());
  359 + }
  360 +
  361 + /**
  362 + * Return a writer that has the same properties as the one returned by
  363 + * makeAppendWriter, but after having removed all the files that follow a
  364 + * given predicate.
  365 + * After a call to makeWriterRemoveFiles, $this is closed and should not
  366 + * be used until the returned writer is closed
  367 + *
  368 + * @param File_Archive_Predicate $pred the predicate verified by removed files
  369 + * @return File_Archive_Writer that allows to append files to the archive
  370 + */
  371 + function makeWriterRemoveFiles($pred)
  372 + {
  373 + return PEAR::raiseError("Reader abstract function call (makeWriterRemoveFiles)");
  374 + }
  375 +
  376 + /**
  377 + * Returns a writer that removes the current file
  378 + * This is a syntaxic sugar for makeWriterRemoveFiles(new File_Archive_Predicate_Current());
  379 + */
  380 + function makeWriterRemove()
  381 + {
  382 + require_once "File/Archive/Predicate/Current.php";
  383 + return $this->makeWriterRemoveFiles(new File_Archive_Predicate_Current());
  384 + }
  385 +
  386 + /**
  387 + * Removes the current file from the reader
  388 + */
  389 + function remove()
  390 + {
  391 + $writer = $this->makeWriterRemove();
  392 + if (PEAR::isError($writer)) {
  393 + return $writer;
  394 + }
  395 + $writer->close();
  396 + }
  397 +
  398 + /**
  399 + * Return a writer that has the same properties as the one returned by makeWriter, but after
  400 + * having removed a block of data from the current file. The writer will append data to the current file
  401 + * no data (other than the block) will be removed
  402 + *
  403 + * @param array Lengths of the blocks. The first one will be discarded, the second one kept, the third
  404 + * one discarded... If the sum of the blocks is less than the size of the file, the comportment is the
  405 + * same as if a last block was set in the array to reach the size of the file
  406 + * if $length is -1, the file is truncated from the specified pos
  407 + * It is possible to specify blocks of size 0
  408 + * @param int $seek relative pos of the block
  409 + */
  410 + function makeWriterRemoveBlocks($blocks, $seek = 0)
  411 + {
  412 + return PEAR::raiseError("Reader abstract function call (makeWriterRemoveBlocks)");
  413 + }
  414 +}
  415 +
  416 +?>
0 417 \ No newline at end of file
... ...
thirdparty/pear/File/Archive/Writer.php 0 → 100644
  1 +<?php
  2 +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3 +
  4 +/**
  5 + * Base class for any writer
  6 + *
  7 + * PHP versions 4 and 5
  8 + *
  9 + * This library is free software; you can redistribute it and/or
  10 + * modify it under the terms of the GNU Lesser General Public
  11 + * License as published by the Free Software Foundation; either
  12 + * version 2.1 of the License, or (at your option) any later version.
  13 + *
  14 + * This library is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17 + * Lesser General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU Lesser General Public
  20 + * License along with this library; if not, write to the Free Software
  21 + * Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA
  22 + *
  23 + * @category File Formats
  24 + * @package File_Archive
  25 + * @author Vincent Lascaux <vincentlascaux@php.net>
  26 + * @copyright 1997-2005 The PHP Group
  27 + * @license http://www.gnu.org/copyleft/lesser.html LGPL
  28 + * @version CVS: $Id: Writer.php,v 1.12 2005/05/31 21:22:02 vincentlascaux Exp $
  29 + * @link http://pear.php.net/package/File_Archive
  30 + */
  31 +
  32 +require_once "PEAR.php";
  33 +
  34 +/**
  35 + * Base class for any writer
  36 + */
  37 +class File_Archive_Writer
  38 +{
  39 + /**
  40 + * Create a new file in the writer
  41 + *
  42 + * @param string $filename Name of the file, eventually including a path
  43 + * @param array $stat Its Statistics. None of the indexes are required
  44 + * @param string $mime MIME type of the file
  45 + */
  46 + function newFile($filename, $stat = array(), $mime = "application/octet-stream")
  47 + {
  48 + }
  49 +
  50 + /**
  51 + * Create a new file in the writer with the content of the physical file $filename
  52 + * and then unlink $filename.
  53 + * newFromTempFile($tmpfile, $filename, $stat, $mime) is equivalent to
  54 + * newFile($filename, $stat, $mime); writeFile($tmpfile); unlink($tmpfile);
  55 + * but can be more efficient.
  56 + * A typical use is for File_Archive_Writer_Files: it renames the temporary
  57 + * file instead of copy/delete
  58 + *
  59 + * @param string $tmpfile Name of the physical file that contains data and will be unlinked
  60 + * @param string $filename Name of the file, eventually including a path
  61 + * @param array $stat Its Statistics. None of the indexes are required
  62 + * @param string $mime MIME type of the file
  63 + */
  64 + function newFromTempFile($tmpfile, $filename, $stat = array(), $mime = "application/octet-stream")
  65 + {
  66 + $this->newFile($filename, $stat, $mime);
  67 + $this->writeFile($tmpfile);
  68 + unlink($tmpfile);
  69 + }
  70 +
  71 + /**
  72 + * Returns whether the writer newFile function needs the $mime parameter
  73 + * Default is false
  74 + */
  75 + function newFileNeedsMIME()
  76 + {
  77 + return false;
  78 + }
  79 +
  80 + /**
  81 + * Append the specified data to the writer
  82 + *
  83 + * @param String $data the data to append to the writer
  84 + */
  85 + function writeData($data)
  86 + {
  87 + }
  88 +
  89 + /**
  90 + * Append the content of the physical file $filename to the writer
  91 + * writeFile($filename) must be equivalent to
  92 + * writeData(file_get_contents($filename)) but can be more efficient
  93 + *
  94 + * @param string $filename Name of the file which content must be appended
  95 + * to the writer
  96 + */
  97 + function writeFile($filename)
  98 + {
  99 + $handle = fopen($filename, "r");
  100 + if (!is_resource($handle)) {
  101 + return PEAR::raiseError("Unable to write to $filename");
  102 + }
  103 + while (!feof($handle)) {
  104 + $error = $this->writeData(fread($handle, 102400));
  105 + if (PEAR::isError($error)) {
  106 + return $error;
  107 + }
  108 + }
  109 + fclose($handle);
  110 + }
  111 +
  112 + /**
  113 + * Close the writer, eventually flush the data, write the footer...
  114 + * This function must be called before the end of the script
  115 + */
  116 + function close() { }
  117 +}
  118 +
  119 +?>
0 120 \ No newline at end of file
... ...
thirdparty/pear/MIME/Type.php 0 → 100644
  1 +<?php
  2 +/* vim: set expandtab tabstop=4 shiftwidth=4: */
  3 +// +----------------------------------------------------------------------+
  4 +// | PHP version 4 |
  5 +// +----------------------------------------------------------------------+
  6 +// | Copyright (c) 1997-2002 The PHP Group |
  7 +// +----------------------------------------------------------------------+
  8 +// | This source file is subject to version 3.0 of the PHP license, |
  9 +// | that is bundled with this package in the file LICENSE, and is |
  10 +// | available at through the world-wide-web at |
  11 +// | http://www.php.net/license/3_0.txt. |
  12 +// | If you did not receive a copy of the PHP license and are unable to |
  13 +// | obtain it through the world-wide-web, please send a note to |
  14 +// | license@php.net so we can mail you a copy immediately. |
  15 +// +----------------------------------------------------------------------+
  16 +// | Authors: Ian Eure <ieure@php.net> |
  17 +// +----------------------------------------------------------------------+
  18 +//
  19 +// $Id: Type.php,v 1.2 2004/08/07 22:19:04 ieure Exp $
  20 +
  21 +require_once 'PEAR.php';
  22 +
  23 +$_fileCmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd');
  24 +$_fileCmd = 'file';
  25 +
  26 +/**
  27 + * Class for working with MIME types
  28 + *
  29 + * @version @version@
  30 + * @package @package@
  31 + * @author Ian Eure <ieure@php.net>
  32 + */
  33 +class MIME_Type {
  34 + /**
  35 + * The MIME media type
  36 + *
  37 + * @var string
  38 + */
  39 + var $media = '';
  40 +
  41 + /**
  42 + * The MIME media sub-type
  43 + *
  44 + * @var string
  45 + */
  46 + var $subType = '';
  47 +
  48 + /**
  49 + * Optional MIME parameters
  50 + *
  51 + * @var array
  52 + */
  53 + var $parameters = array();
  54 +
  55 + /**
  56 + * List of valid media types
  57 + *
  58 + * @var array
  59 + */
  60 + var $validMediaTypes = array(
  61 + 'text',
  62 + 'image',
  63 + 'audio',
  64 + 'video',
  65 + 'application',
  66 + 'multipart',
  67 + 'message'
  68 + );
  69 +
  70 +
  71 + /**
  72 + * Constructor.
  73 + *
  74 + * If $type is set, if will be parsed and the appropriate class vars set. If not,
  75 + * you get an empty class. This is useful, but not quite as useful as parsing a
  76 + * type.
  77 + *
  78 + * @param string $type MIME type
  79 + * @return void
  80 + */
  81 + function MIME_Type($type = false)
  82 + {
  83 + if ($type) {
  84 + $this->parse($type);
  85 + }
  86 + }
  87 +
  88 +
  89 + /**
  90 + * Parse a mime-type
  91 + *
  92 + * @param $type string MIME type to parse
  93 + * @return void
  94 + */
  95 + function parse($type)
  96 + {
  97 + $this->media = $this->getMedia($type);
  98 + $this->subType = $this->getSubType($type);
  99 + if (MIME_Type::hasParameters($type)) {
  100 + require_once 'MIME/Type/Parameter.php';
  101 + foreach (MIME_Type::getParameters($type) as $param) {
  102 + $param = &new MIME_Type_Parameter($param);
  103 + $this->parameters[$param->name] = $param;
  104 + }
  105 + }
  106 + }
  107 +
  108 +
  109 + /**
  110 + * Does this type have any parameters?
  111 + *
  112 + * @param $type string MIME type to check
  113 + * @return boolean true if $type has parameters, false otherwise
  114 + * @static
  115 + */
  116 + function hasParameters($type)
  117 + {
  118 + if (strstr($type, ';')) {
  119 + return true;
  120 + }
  121 + return false;
  122 + }
  123 +
  124 +
  125 + /**
  126 + * Get a MIME type's parameters
  127 + *
  128 + * @param $type string MIME type to get parameters of
  129 + * @return array $type's parameters
  130 + * @static
  131 + */
  132 + function getParameters($type)
  133 + {
  134 + $params = array();
  135 + $tmp = explode(';', $type);
  136 + for ($i = 1; $i < count($tmp); $i++) {
  137 + $params[] = trim($tmp[$i]);
  138 + }
  139 + return $params;
  140 + }
  141 +
  142 +
  143 + /**
  144 + * Strip paramaters from a MIME type string
  145 + *
  146 + * @param string $type MIME type string
  147 + * @return string MIME type with parameters removed
  148 + * @static
  149 + */
  150 + function stripParameters($type)
  151 + {
  152 + if (strstr($type, ';')) {
  153 + return substr($type, 0, strpos($type, ';'));
  154 + }
  155 + return $type;
  156 + }
  157 +
  158 +
  159 + /**
  160 + * Get a MIME type's media
  161 + *
  162 + * @note 'media' refers to the portion before the first slash
  163 + * @param $type string MIME type to get media of
  164 + * @return string $type's media
  165 + * @static
  166 + */
  167 + function getMedia($type)
  168 + {
  169 + $tmp = explode('/', $type);
  170 + return strtolower($tmp[0]);
  171 + }
  172 +
  173 +
  174 + /**
  175 + * Get a MIME type's subtype
  176 + *
  177 + * @param $type string MIME type to get subtype of
  178 + * @return string $type's subtype
  179 + * @static
  180 + */
  181 + function getSubType($type)
  182 + {
  183 + $tmp = explode('/', $type);
  184 + $tmp = explode(';', $tmp[1]);
  185 + return strtolower(trim($tmp[0]));
  186 + }
  187 +
  188 +
  189 + /**
  190 + * Create a textual MIME type from object values
  191 + *
  192 + * This function performs the opposite function of parse().
  193 + *
  194 + * @return string MIME type string
  195 + */
  196 + function get()
  197 + {
  198 + $type = strtolower($this->media.'/'.$this->subType);
  199 + if (count($this->parameters)) {
  200 + foreach ($this->parameters as $key => $null) {
  201 + $type .= '; '.$this->parameters[$key]->get();
  202 + }
  203 + }
  204 + return $type;
  205 + }
  206 +
  207 +
  208 + /**
  209 + * Is this type experimental?
  210 + *
  211 + * @note Experimental types are denoted by a leading 'x-' in the media or
  212 + * subtype, e.g. text/x-vcard or x-world/x-vrml.
  213 + * @param string $type MIME type to check
  214 + * @return boolean true if $type is experimental, false otherwise
  215 + * @static
  216 + */
  217 + function isExperimental($type)
  218 + {
  219 + if (substr(MIME_Type::getMedia($type), 0, 2) == 'x-' ||
  220 + substr(MIME_Type::getSubType($type), 0, 2) == 'x-') {
  221 + return true;
  222 + }
  223 + return false;
  224 + }
  225 +
  226 +
  227 + /**
  228 + * Is this a vendor MIME type?
  229 + *
  230 + * @note Vendor types are denoted with a leading 'vnd. in the subtype.
  231 + * @param string $type MIME type to check
  232 + * @return boolean true if $type is a vendor type, false otherwise
  233 + * @static
  234 + */
  235 + function isVendor($type)
  236 + {
  237 + if (substr(MIME_Type::getSubType($type), 0, 4) == 'vnd.') {
  238 + return true;
  239 + }
  240 + return false;
  241 + }
  242 +
  243 +
  244 + /**
  245 + * Is this a wildcard type?
  246 + *
  247 + * @param string $type MIME type to check
  248 + * @return boolean true if $type is a wildcard, false otherwise
  249 + * @static
  250 + */
  251 + function isWildcard($type)
  252 + {
  253 + if ($type == '*/*' || MIME_Type::getSubtype($type) == '*') {
  254 + return true;
  255 + }
  256 + return false;
  257 + }
  258 +
  259 +
  260 + /**
  261 + * Perform a wildcard match on a MIME type
  262 + *
  263 + * Example:
  264 + * MIME_Type::wildcardMatch('image/*', 'image/png')
  265 + *
  266 + * @param string $card Wildcard to check against
  267 + * @param string $type MIME type to check
  268 + * @return boolean true if there was a match, false otherwise
  269 + */
  270 + function wildcardMatch($card, $type)
  271 + {
  272 + if (!MIME_Type::isWildcard($card)) {
  273 + return false;
  274 + }
  275 +
  276 + if ($card == '*/*') {
  277 + return true;
  278 + }
  279 +
  280 + if (MIME_Type::getMedia($card) ==
  281 + MIME_Type::getMedia($type)) {
  282 + return true;
  283 + }
  284 + return false;
  285 + }
  286 +
  287 +
  288 + /**
  289 + * Add a parameter to this type
  290 + *
  291 + * @param string $name Attribute name
  292 + * @param string $value Attribute value
  293 + * @param string $comment Comment for this parameter
  294 + * @return void
  295 + */
  296 + function addParameter($name, $value, $comment = false)
  297 + {
  298 + $tmp = &new MIME_Type_Parameter;
  299 + $tmp->name = $name;
  300 + $tmp->value = $value;
  301 + $tmp->comment = $comment;
  302 + $this->parameters[$name] = $tmp;
  303 + }
  304 +
  305 +
  306 + /**
  307 + * Remove a parameter from this type
  308 + *
  309 + * @param string $name Parameter name
  310 + * @return void
  311 + */
  312 + function removeParameter($name)
  313 + {
  314 + unset ($this->parameters[$name]);
  315 + }
  316 +
  317 +
  318 + /**
  319 + * Autodetect a file's MIME-type
  320 + *
  321 + * This function may be called staticly.
  322 + *
  323 + * @param string $file Path to the file to get the type of
  324 + * @param bool $params Append MIME parameters if true
  325 + * @return string $file's MIME-type on success, PEAR_Error otherwise
  326 + * @since 1.0.0beta1
  327 + * @static
  328 + */
  329 + function autoDetect($file, $params = false)
  330 + {
  331 + @include_once 'System/Command.php';
  332 + if (function_exists('mime_content_type')) {
  333 + $type = mime_content_type($file);
  334 + } else if (class_exists('System_Command')) {
  335 + $type = MIME_Type::_fileAutoDetect($file);
  336 + } else {
  337 + return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function.");
  338 + }
  339 +
  340 + // _fileAutoDetect() may have returned an error.
  341 + if (PEAR::isError($type)) {
  342 + return $type;
  343 + }
  344 +
  345 + // Don't return an empty string
  346 + if (!$type || !strlen($type)) {
  347 + return PEAR::raiseError("Sorry, couldn't determine file type.");
  348 + }
  349 +
  350 + // Strip parameters if present & requested
  351 + if (MIME_Type::hasParameters($type) && !$params) {
  352 + $type = MIME_Type::stripParameters($type);
  353 + }
  354 +
  355 + return $type;
  356 + }
  357 +
  358 + /**
  359 + * Autodetect a file's MIME-type with 'file' and System_Command
  360 + *
  361 + * This function may be called staticly.
  362 + *
  363 + * @param string $file Path to the file to get the type of
  364 + * @return string $file's MIME-type
  365 + * @since 1.0.0beta1
  366 + * @static
  367 + */
  368 + function _fileAutoDetect($file)
  369 + {
  370 + // Sanity checks
  371 + if (!file_exists($file)) {
  372 + return PEAR::raiseError("File \"$file\" doesn't exist");
  373 + }
  374 +
  375 + if (!is_readable($file)) {
  376 + return PEAR::raiseError("File \"$file\" is not readable");
  377 + }
  378 +
  379 + $cmd = new System_Command;
  380 +
  381 +
  382 + // Make sure we have the 'file' command.
  383 + $fileCmd = PEAR::getStaticProperty('MIME_Type', 'fileCmd');
  384 + if (!$cmd->which($fileCmd)) {
  385 + unset($cmd);
  386 + return PEAR::raiseError("Can't find file command \"{$fileCmd}\"");
  387 + }
  388 +
  389 + $cmd->pushCommand($fileCmd, "-bi '{$file}'");
  390 + $res = $cmd->execute();
  391 + unset($cmd);
  392 +
  393 + return $res;
  394 + }
  395 +}
0 396 \ No newline at end of file
... ...