From 0b17fdc6719c24850fa7095bc33f292f97f4ec02 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Fri, 29 Jan 2010 13:57:24 +0100 Subject: [PATCH] more code cleanup according to coding standard --- inc/JSON.php | 245 +++--- inc/JpegMeta.php | 1233 ++++++++++++--------------- inc/ZipLib.class.php | 949 +++++++++++---------- inc/blowfish.php | 55 +- inc/feedcreator.class.php | 114 +-- inc/template.php | 1667 ++++++++++++++++++------------------- 6 files changed, 2090 insertions(+), 2173 deletions(-) diff --git a/inc/JSON.php b/inc/JSON.php index ea66c9c32..7ec400092 100644 --- a/inc/JSON.php +++ b/inc/JSON.php @@ -112,38 +112,35 @@ define('JSON_STRICT_TYPE', 11); * @since * @deprecated */ -class JSON -{ - /** - * constructs a new JSON instance - * - * @param int $use object behavior: when encoding or decoding, - * be loose or strict about object/array usage - * - * possible values: - * JSON_STRICT_TYPE - strict typing, default - * "{...}" syntax creates objects in decode. - * JSON_LOOSE_TYPE - loose typing - * "{...}" syntax creates associative arrays in decode. - */ - function JSON($use=JSON_STRICT_TYPE) - { +class JSON { + /** + * constructs a new JSON instance + * + * @param int $use object behavior: when encoding or decoding, + * be loose or strict about object/array usage + * + * possible values: + * JSON_STRICT_TYPE - strict typing, default + * "{...}" syntax creates objects in decode. + * JSON_LOOSE_TYPE - loose typing + * "{...}" syntax creates associative arrays in decode. + */ + function JSON($use=JSON_STRICT_TYPE) { $this->use = $use; } - /** - * encodes an arbitrary variable into JSON format - * - * @param mixed $var any number, boolean, string, array, or object to be encoded. - * see argument 1 to JSON() above for array-parsing behavior. - * if var is a strng, note that encode() always expects it - * to be in ASCII or UTF-8 format! - * - * @return string JSON string representation of input var - * @access public - */ - function encode($var) - { + /** + * encodes an arbitrary variable into JSON format + * + * @param mixed $var any number, boolean, string, array, or object to be encoded. + * see argument 1 to JSON() above for array-parsing behavior. + * if var is a strng, note that encode() always expects it + * to be in ASCII or UTF-8 format! + * + * @return string JSON string representation of input var + * @access public + */ + function encode($var) { switch (gettype($var)) { case 'boolean': return $var ? 'true' : 'false'; @@ -163,20 +160,30 @@ class JSON $ascii = ''; $strlen_var = strlen($var); - /* - * Iterate over every character in the string, - * escaping with a slash or encoding to UTF-8 where necessary - */ + /* + * Iterate over every character in the string, + * escaping with a slash or encoding to UTF-8 where necessary + */ for ($c = 0; $c < $strlen_var; ++$c) { $ord_var_c = ord($var{$c}); switch ($ord_var_c) { - case 0x08: $ascii .= '\b'; break; - case 0x09: $ascii .= '\t'; break; - case 0x0A: $ascii .= '\n'; break; - case 0x0C: $ascii .= '\f'; break; - case 0x0D: $ascii .= '\r'; break; + case 0x08: + $ascii .= '\b'; + break; + case 0x09: + $ascii .= '\t'; + break; + case 0x0A: + $ascii .= '\n'; + break; + case 0x0C: + $ascii .= '\f'; + break; + case 0x0D: + $ascii .= '\r'; + break; case 0x22: case 0x2F: @@ -259,26 +266,26 @@ class JSON return '"'.$ascii.'"'; case 'array': - /* - * As per JSON spec if any array key is not an integer - * we must treat the the whole array as an object. We - * also try to catch a sparsely populated associative - * array with numeric keys here because some JS engines - * will create an array with empty indexes up to - * max_index which can cause memory issues and because - * the keys, which may be relevant, will be remapped - * otherwise. - * - * As per the ECMA and JSON specification an object may - * have any string as a property. Unfortunately due to - * a hole in the ECMA specification if the key is a - * ECMA reserved word or starts with a digit the - * parameter is only accessible using ECMAScript's - * bracket notation. - */ + /* + * As per JSON spec if any array key is not an integer + * we must treat the the whole array as an object. We + * also try to catch a sparsely populated associative + * array with numeric keys here because some JS engines + * will create an array with empty indexes up to + * max_index which can cause memory issues and because + * the keys, which may be relevant, will be remapped + * otherwise. + * + * As per the ECMA and JSON specification an object may + * have any string as a property. Unfortunately due to + * a hole in the ECMA specification if the key is a + * ECMA reserved word or starts with a digit the + * parameter is only accessible using ECMAScript's + * bracket notation. + */ // treat as a JSON object - if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { + if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { return sprintf('{%s}', join(',', array_map(array($this, 'name_value'), array_keys($var), array_values($var)))); @@ -298,38 +305,35 @@ class JSON } } - /** - * encodes an arbitrary variable into JSON format, alias for encode() - */ - function enc($var) - { + /** + * encodes an arbitrary variable into JSON format, alias for encode() + */ + function enc($var) { return $this->encode($var); } - /** function name_value - * array-walking function for use in generating JSON-formatted name-value pairs - * - * @param string $name name of key to use - * @param mixed $value reference to an array element to be encoded - * - * @return string JSON-formatted name-value pair, like '"name":value' - * @access private - */ - function name_value($name, $value) - { + /** function name_value + * array-walking function for use in generating JSON-formatted name-value pairs + * + * @param string $name name of key to use + * @param mixed $value reference to an array element to be encoded + * + * @return string JSON-formatted name-value pair, like '"name":value' + * @access private + */ + function name_value($name, $value) { return (sprintf("%s:%s", $this->encode(strval($name)), $this->encode($value))); } - /** - * reduce a string by removing leading and trailing comments and whitespace - * - * @param $str string string value to strip of comments and whitespace - * - * @return string string value stripped of comments and whitespace - * @access private - */ - function reduce_string($str) - { + /** + * reduce a string by removing leading and trailing comments and whitespace + * + * @param $str string string value to strip of comments and whitespace + * + * @return string string value stripped of comments and whitespace + * @access private + */ + function reduce_string($str) { $str = preg_replace(array( // eliminate single line comments in '// ...' form @@ -347,20 +351,19 @@ class JSON return trim($str); } - /** - * decodes a JSON string into appropriate variable - * - * @param string $str JSON-formatted string - * - * @return mixed number, boolean, string, array, or object - * corresponding to given JSON input string. - * See argument 1 to JSON() above for object-output behavior. - * Note that decode() always returns strings - * in ASCII or UTF-8 format! - * @access public - */ - function decode($str) - { + /** + * decodes a JSON string into appropriate variable + * + * @param string $str JSON-formatted string + * + * @return mixed number, boolean, string, array, or object + * corresponding to given JSON input string. + * See argument 1 to JSON() above for object-output behavior. + * Note that decode() always returns strings + * in ASCII or UTF-8 format! + * @access public + */ + function decode($str) { $str = $this->reduce_string($str); switch (strtolower($str)) { @@ -399,11 +402,26 @@ class JSON $ord_chrs_c = ord($chrs{$c}); switch ($substr_chrs_c_2) { - case '\b': $utf8 .= chr(0x08); $c+=1; break; - case '\t': $utf8 .= chr(0x09); $c+=1; break; - case '\n': $utf8 .= chr(0x0A); $c+=1; break; - case '\f': $utf8 .= chr(0x0C); $c+=1; break; - case '\r': $utf8 .= chr(0x0D); $c+=1; break; + case '\b': + $utf8 .= chr(0x08); + $c+=1; + break; + case '\t': + $utf8 .= chr(0x09); + $c+=1; + break; + case '\n': + $utf8 .= chr(0x0A); + $c+=1; + break; + case '\f': + $utf8 .= chr(0x0C); + $c+=1; + break; + case '\r': + $utf8 .= chr(0x0D); + $c+=1; + break; case '\\"': case '\\\'': @@ -430,27 +448,32 @@ class JSON } elseif(($ord_chrs_c & 0xE0) == 0xC0) { // characters U-00000080 - U-000007FF, mask 110XXXXX //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 2); $c += 1; + $utf8 .= substr($chrs, $c, 2); + $c += 1; } elseif(($ord_chrs_c & 0xF0) == 0xE0) { // characters U-00000800 - U-0000FFFF, mask 1110XXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 3); $c += 2; + $utf8 .= substr($chrs, $c, 3); + $c += 2; } elseif(($ord_chrs_c & 0xF8) == 0xF0) { // characters U-00010000 - U-001FFFFF, mask 11110XXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 4); $c += 3; + $utf8 .= substr($chrs, $c, 4); + $c += 3; } elseif(($ord_chrs_c & 0xFC) == 0xF8) { // characters U-00200000 - U-03FFFFFF, mask 111110XX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 5); $c += 4; + $utf8 .= substr($chrs, $c, 5); + $c += 4; } elseif(($ord_chrs_c & 0xFE) == 0xFC) { // characters U-04000000 - U-7FFFFFFF, mask 1111110X // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $utf8 .= substr($chrs, $c, 6); $c += 5; + $utf8 .= substr($chrs, $c, 6); + $c += 5; } break; @@ -612,13 +635,11 @@ class JSON } } - /** - * decodes a JSON string into appropriate variable; alias for decode() - */ - function dec($var) - { + /** + * decodes a JSON string into appropriate variable; alias for decode() + */ + function dec($var) { return $this->decode($var); } - } diff --git a/inc/JpegMeta.php b/inc/JpegMeta.php index cb1d7d694..b06764320 100644 --- a/inc/JpegMeta.php +++ b/inc/JpegMeta.php @@ -29,8 +29,7 @@ // | Authors: Sebastian Delmont <sdelmont@zonageek.com> | // +----------------------------------------------------------------------+ -class JpegMeta -{ +class JpegMeta { var $_fileName; var $_fp = null; var $_type = 'unknown'; @@ -44,8 +43,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function JpegMeta($fileName) - { + function JpegMeta($fileName) { $this->_fileName = $fileName; @@ -61,8 +59,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function & getRawInfo() - { + function & getRawInfo() { $this->_parseAll(); if ($this->_markers == null) { @@ -77,8 +74,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function & getBasicInfo() - { + function & getBasicInfo() { $this->_parseAll(); $info = array(); @@ -91,16 +87,14 @@ class JpegMeta if (isset($this->_info['file']['Url'])) { $info['Url'] = $this->_info['file']['Url']; $info['NiceSize'] = "???KB"; - } - else { + } else { $info['Size'] = $this->_info['file']['Size']; $info['NiceSize'] = $this->_info['file']['NiceSize']; } if (@isset($this->_info['sof']['Format'])) { $info['Format'] = $this->_info['sof']['Format'] . " JPEG"; - } - else { + } else { $info['Format'] = $this->_info['sof']['Format'] . " JPEG"; } @@ -129,8 +123,7 @@ class JpegMeta * * @author Andreas Gohr <andi@splitbrain.org> */ - function getField($fields) - { + function getField($fields) { if(!is_array($fields)) $fields = array($fields); $info = false; foreach($fields as $field){ @@ -175,8 +168,7 @@ class JpegMeta * * @author Andreas Gohr <andi@splitbrain.org> */ - function setField($field, $value) - { + function setField($field, $value) { if(strtolower(substr($field,0,5)) == 'iptc.'){ return $this->setIPTCField(substr($field,5),$value); }elseif(strtolower(substr($field,0,5)) == 'exif.'){ @@ -192,8 +184,7 @@ class JpegMeta * * @author Andreas Gohr <andi@splitbrain.org> */ - function deleteField($field) - { + function deleteField($field) { if(strtolower(substr($field,0,5)) == 'iptc.'){ return $this->deleteIPTCField(substr($field,5)); }elseif(strtolower(substr($field,0,5)) == 'exif.'){ @@ -208,8 +199,7 @@ class JpegMeta * * @author Andreas Gohr <andi@splitbrain.org> */ - function getDateField($field) - { + function getDateField($field) { if (!isset($this->_info['dates'])) { $this->_info['dates'] = $this->getDates(); } @@ -226,8 +216,7 @@ class JpegMeta * * @author Andreas Gohr <andi@splitbrain.org> */ - function getFileField($field) - { + function getFileField($field) { if (!isset($this->_info['file'])) { $this->_parseFileInfo(); } @@ -258,8 +247,7 @@ class JpegMeta * * @author Joe Lapp <joe.lapp@pobox.com> */ - function getShutterSpeed() - { + function getShutterSpeed() { if (!isset($this->_info['exif'])) { $this->_parseMarkerExif(); } @@ -277,8 +265,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getExifField($field) - { + function getExifField($field) { if (!isset($this->_info['exif'])) { $this->_parseMarkerExif(); } @@ -299,8 +286,7 @@ class JpegMeta * * @author Hakan Sandell <hakan.sandell@mydata.se> */ - function getXmpField($field) - { + function getXmpField($field) { if (!isset($this->_info['xmp'])) { $this->_parseMarkerXmp(); } @@ -321,8 +307,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getAdobeField($field) - { + function getAdobeField($field) { if (!isset($this->_info['adobe'])) { $this->_parseMarkerAdobe(); } @@ -343,8 +328,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getIPTCField($field) - { + function getIPTCField($field) { if (!isset($this->_info['iptc'])) { $this->_parseMarkerAdobe(); } @@ -366,8 +350,7 @@ class JpegMeta * @author Sebastian Delmont <sdelmont@zonageek.com> * @author Joe Lapp <joe.lapp@pobox.com> */ - function setExifField($field, $value) - { + function setExifField($field, $value) { if (!isset($this->_info['exif'])) { $this->_parseMarkerExif(); } @@ -397,8 +380,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function setAdobeField($field, $value) - { + function setAdobeField($field, $value) { if (!isset($this->_info['adobe'])) { $this->_parseMarkerAdobe(); } @@ -451,8 +433,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function setIPTCField($field, $value) - { + function setIPTCField($field, $value) { if (!isset($this->_info['iptc'])) { $this->_parseMarkerAdobe(); } @@ -475,8 +456,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function deleteExifField($field) - { + function deleteExifField($field) { if (!isset($this->_info['exif'])) { $this->_parseMarkerAdobe(); } @@ -497,8 +477,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function deleteAdobeField($field) - { + function deleteAdobeField($field) { if (!isset($this->_info['adobe'])) { $this->_parseMarkerAdobe(); } @@ -519,8 +498,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function deleteIPTCField($field) - { + function deleteIPTCField($field) { if (!isset($this->_info['iptc'])) { $this->_parseMarkerAdobe(); } @@ -547,12 +525,12 @@ class JpegMeta // try various fields $cap = $this->getField(array('Iptc.Headline', - 'Iptc.Caption', - 'Xmp.dc:title', - 'Exif.UserComment', - 'Exif.TIFFUserComment', - 'Exif.TIFFImageDescription', - 'File.Name')); + 'Iptc.Caption', + 'Xmp.dc:title', + 'Exif.UserComment', + 'Exif.TIFFUserComment', + 'Exif.TIFFImageDescription', + 'File.Name')); if (empty($cap)) return false; if(!$max) return $cap; @@ -568,8 +546,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getDates() - { + function getDates() { $this->_parseAll(); if ($this->_markers == null) { if (@isset($this->_info['file']['UnixTime'])) { @@ -704,8 +681,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getWidth() - { + function getWidth() { if (!isset($this->_info['sof'])) { $this->_parseMarkerSOF(); } @@ -734,8 +710,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getHeight() - { + function getHeight() { if (!isset($this->_info['sof'])) { $this->_parseMarkerSOF(); } @@ -764,8 +739,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function getDimStr() - { + function getDimStr() { if ($this->_markers == null) { return false; } @@ -781,8 +755,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function hasThumbnail($which = 'any') - { + function hasThumbnail($which = 'any') { if (($which == 'any') || ($which == 'exif')) { if (!isset($this->_info['exif'])) { $this->_parseMarkerExif(); @@ -823,8 +796,7 @@ class JpegMeta * * @author Sebastian Delmont <sdelmont@zonageek.com> */ - function sendThumbnail($which = 'any') - { + function sendThumbnail($which = 'any') { $data = null; if (($which == 'any') || ($which == 'exif')) { @@ -892,8 +864,7 @@ class JpegMeta /*************************************************************/ /*************************************************************/ - function _dispose() - { + function _dispose() { $this->_fileName = $fileName; $this->_fp = null; @@ -904,8 +875,7 @@ class JpegMeta } /*************************************************************/ - function _readJPEG() - { + function _readJPEG() { unset($this->_markers); //unset($this->_info); $this->_markers = array(); @@ -919,8 +889,7 @@ class JpegMeta else { $this->_type = 'url'; } - } - else { + } else { $this->_fp = null; return false; // ERROR: Can't open file } @@ -942,14 +911,14 @@ class JpegMeta while (!$done) { $capture = false; - // First, skip any non 0xFF bytes + // First, skip any non 0xFF bytes $discarded = 0; $c = ord(fgetc($this->_fp)); while (!feof($this->_fp) && ($c != 0xFF)) { $discarded++; $c = ord(fgetc($this->_fp)); } - // Then skip all 0xFF until the marker byte + // Then skip all 0xFF until the marker byte do { $marker = ord(fgetc($this->_fp)); } while (!feof($this->_fp) && ($marker == 0xFF)); @@ -971,23 +940,23 @@ class JpegMeta $length = $length - 2; // The length we got counts itself switch ($marker) { - case 0xC0: // SOF0 - case 0xC1: // SOF1 - case 0xC2: // SOF2 - case 0xC9: // SOF9 - case 0xE0: // APP0: JFIF data - case 0xE1: // APP1: EXIF or XMP data - case 0xED: // APP13: IPTC / Photoshop data - $capture = true; - break; - case 0xDA: // SOS: Start of scan... the image itself and the last block on the file - $capture = false; - $length = -1; // This field has no length... it includes all data until EOF - $done = true; - break; - default: - $capture = true;//false; - break; + case 0xC0: // SOF0 + case 0xC1: // SOF1 + case 0xC2: // SOF2 + case 0xC9: // SOF9 + case 0xE0: // APP0: JFIF data + case 0xE1: // APP1: EXIF or XMP data + case 0xED: // APP13: IPTC / Photoshop data + $capture = true; + break; + case 0xDA: // SOS: Start of scan... the image itself and the last block on the file + $capture = false; + $length = -1; // This field has no length... it includes all data until EOF + $done = true; + break; + default: + $capture = true;//false; + break; } $this->_markers[$count] = array(); @@ -1002,7 +971,7 @@ class JpegMeta } elseif (!$done) { $result = @fseek($this->_fp, $length, SEEK_CUR); - // fseek doesn't seem to like HTTP 'files', but fgetc has no problem + // fseek doesn't seem to like HTTP 'files', but fgetc has no problem if (!($result === 0)) { for ($i = 0; $i < $length; $i++) { fgetc($this->_fp); @@ -1021,8 +990,7 @@ class JpegMeta } /*************************************************************/ - function _parseAll() - { + function _parseAll() { if (!isset($this->_info['file'])) { $this->_parseFileInfo(); } @@ -1052,8 +1020,7 @@ class JpegMeta } /*************************************************************/ - function _writeJPEG($outputName) - { + function _writeJPEG($outputName) { $this->_parseAll(); $wroteEXIF = false; @@ -1067,16 +1034,13 @@ class JpegMeta else { $this->_type = 'url'; } - } - else { + } else { $this->_fp = null; return false; // ERROR: Can't open file } $this->_fpout = fopen($outputName, 'wb'); - if ($this->_fpout) { - } - else { + if (!$this->_fpout) { $this->_fpout = null; fclose($this->_fp); $this->_fp = null; @@ -1100,14 +1064,14 @@ class JpegMeta $ok = true; while (!$done) { - // First, skip any non 0xFF bytes + // First, skip any non 0xFF bytes $discarded = 0; $c = ord(fgetc($this->_fp)); while (!feof($this->_fp) && ($c != 0xFF)) { $discarded++; $c = ord(fgetc($this->_fp)); } - // Then skip all 0xFF until the marker byte + // Then skip all 0xFF until the marker byte do { $marker = ord(fgetc($this->_fp)); } while (!feof($this->_fp) && ($marker == 0xFF)); @@ -1156,7 +1120,7 @@ class JpegMeta if (!$wroteAdobe && (($marker < 0xE0) || ($marker > 0xEF))) { if ((isset($this->_info['adobe']) && is_array($this->_info['adobe'])) - || (isset($this->_info['iptc']) && is_array($this->_info['iptc']))) { + || (isset($this->_info['iptc']) && is_array($this->_info['iptc']))) { $adobe =& $this->_createMarkerAdobe(); $this->_writeJPEGMarker(0xED, strlen($adobe), $adobe, 0); unset($adobe); @@ -1188,8 +1152,7 @@ class JpegMeta } /*************************************************************/ - function _writeJPEGMarker($marker, $length, &$data, $origLength) - { + function _writeJPEGMarker($marker, $length, &$data, $origLength) { if ($length <= 0) { return false; } @@ -1212,15 +1175,13 @@ class JpegMeta } } } - } - else { + } else { if ($marker == 0xDA) { // Copy until EOF while (!feof($this->_fp)) { $data = fread($this->_fp, 1024 * 16); fputs($this->_fpout, $data, strlen($data)); } - } - else { // Copy only $length bytes + } else { // Copy only $length bytes $data = @fread($this->_fp, $length); fputs($this->_fpout, $data, $length); } @@ -1235,8 +1196,7 @@ class JpegMeta * @author Sebastian Delmont <sdelmont@zonageek.com> * @author Andreas Gohr <andi@splitbrain.org> */ - function _parseFileInfo() - { + function _parseFileInfo() { if (file_exists($this->_fileName)) { $this->_info['file'] = array(); $this->_info['file']['Name'] = basename($this->_fileName); @@ -1244,14 +1204,11 @@ class JpegMeta $this->_info['file']['Size'] = filesize($this->_fileName); if ($this->_info['file']['Size'] < 1024) { $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B'; - } - elseif ($this->_info['file']['Size'] < (1024 * 1024)) { + } elseif ($this->_info['file']['Size'] < (1024 * 1024)) { $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / 1024) . 'KB'; - } - elseif ($this->_info['file']['Size'] < (1024 * 1024 * 1024)) { + } elseif ($this->_info['file']['Size'] < (1024 * 1024 * 1024)) { $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / (1024*1024)) . 'MB'; - } - else { + } else { $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B'; } $this->_info['file']['UnixTime'] = filemtime($this->_fileName); @@ -1331,8 +1288,7 @@ class JpegMeta default: $this->_info['file']['Mime'] = 'image/unknown'; } - } - else { + } else { $this->_info['file'] = array(); $this->_info['file']['Name'] = basename($this->_fileName); $this->_info['file']['Url'] = $this->_fileName; @@ -1342,8 +1298,7 @@ class JpegMeta } /*************************************************************/ - function _parseMarkerJFIF() - { + function _parseMarkerJFIF() { if (!isset($this->_markers)) { $this->_readJPEG(); } @@ -1372,7 +1327,6 @@ class JpegMeta $pos = 0; $this->_info['jfif'] = array(); - $vmaj = $this->_getByte($data, 5); $vmin = $this->_getByte($data, 6); @@ -1380,18 +1334,18 @@ class JpegMeta $units = $this->_getByte($data, 7); switch ($units) { - case 0: - $this->_info['jfif']['Units'] = 'pixels'; - break; - case 1: - $this->_info['jfif']['Units'] = 'dpi'; - break; - case 2: - $this->_info['jfif']['Units'] = 'dpcm'; - break; - default: - $this->_info['jfif']['Units'] = 'unknown'; - break; + case 0: + $this->_info['jfif']['Units'] = 'pixels'; + break; + case 1: + $this->_info['jfif']['Units'] = 'dpi'; + break; + case 2: + $this->_info['jfif']['Units'] = 'dpcm'; + break; + default: + $this->_info['jfif']['Units'] = 'unknown'; + break; } $xdens = $this->_getShort($data, 8); @@ -1410,8 +1364,7 @@ class JpegMeta } /*************************************************************/ - function _parseMarkerSOF() - { + function _parseMarkerSOF() { if (!isset($this->_markers)) { $this->_readJPEG(); } @@ -1424,13 +1377,13 @@ class JpegMeta $count = count($this->_markers); for ($i = 0; $i < $count; $i++) { switch ($this->_markers[$i]['marker']) { - case 0xC0: // SOF0 - case 0xC1: // SOF1 - case 0xC2: // SOF2 - case 0xC9: // SOF9 - $data =& $this->_markers[$i]['data']; - $marker = $this->_markers[$i]['marker']; - break; + case 0xC0: // SOF0 + case 0xC1: // SOF1 + case 0xC2: // SOF2 + case 0xC9: // SOF9 + $data =& $this->_markers[$i]['data']; + $marker = $this->_markers[$i]['marker']; + break; } } @@ -1442,32 +1395,29 @@ class JpegMeta $pos = 0; $this->_info['sof'] = array(); - switch ($marker) { - case 0xC0: // SOF0 - $format = 'Baseline'; - break; - case 0xC1: // SOF1 - $format = 'Progessive'; - break; - case 0xC2: // SOF2 - $format = 'Non-baseline'; - break; - case 0xC9: // SOF9 - $format = 'Arithmetic'; - break; - default: - return false; - break; + case 0xC0: // SOF0 + $format = 'Baseline'; + break; + case 0xC1: // SOF1 + $format = 'Progessive'; + break; + case 0xC2: // SOF2 + $format = 'Non-baseline'; + break; + case 0xC9: // SOF9 + $format = 'Arithmetic'; + break; + default: + return false; + break; } - - $this->_info['sof']['Format'] = $format; - + $this->_info['sof']['Format'] = $format; $this->_info['sof']['SamplePrecision'] = $this->_getByte($data, $pos + 0); - $this->_info['sof']['ImageHeight'] = $this->_getShort($data, $pos + 1); - $this->_info['sof']['ImageWidth'] = $this->_getShort($data, $pos + 3); - $this->_info['sof']['ColorChannels'] = $this->_getByte($data, $pos + 5); + $this->_info['sof']['ImageHeight'] = $this->_getShort($data, $pos + 1); + $this->_info['sof']['ImageWidth'] = $this->_getShort($data, $pos + 3); + $this->_info['sof']['ColorChannels'] = $this->_getByte($data, $pos + 5); return true; } @@ -1477,8 +1427,7 @@ class JpegMeta * * @author Hakan Sandell <hakan.sandell@mydata.se> */ - function _parseMarkerXmp() - { + function _parseMarkerXmp() { if (!isset($this->_markers)) { $this->_readJPEG(); } @@ -1513,10 +1462,10 @@ class JpegMeta $this->_info['xmp'] = array(); $count = count($values); for ($i = 0; $i < $count; $i++) { - if ($values[$i][tag] == 'rdf:Description' && $values[$i][type] == 'open') { + if ($values[$i]['tag'] == 'rdf:Description' && $values[$i]['type'] == 'open') { - while ($values[++$i][tag] != 'rdf:Description') { - $this->_parseXmpNode($values, $i, $this->_info['xmp'][$values[$i][tag]]); + while ($values[++$i]['tag'] != 'rdf:Description') { + $this->_parseXmpNode($values, $i, $this->_info['xmp'][$values[$i]['tag']]); } } } @@ -1528,43 +1477,41 @@ class JpegMeta * * @author Hakan Sandell <hakan.sandell@mydata.se> */ - function _parseXmpNode($values, &$i, &$meta) - { - if ($values[$i][type] == 'complete') { + function _parseXmpNode($values, &$i, &$meta) { + if ($values[$i]['type'] == 'complete') { // Simple Type property - $meta = $values[$i][value]; + $meta = $values[$i]['value']; return; } $i++; - if ($values[$i][tag] == 'rdf:Bag' || $values[$i][tag] == 'rdf:Seq') { + if ($values[$i]['tag'] == 'rdf:Bag' || $values[$i]['tag'] == 'rdf:Seq') { // Array property $meta = array(); - while ($values[++$i][tag] == 'rdf:li') { + while ($values[++$i]['tag'] == 'rdf:li') { $this->_parseXmpNode($values, $i, $meta[]); } $i++; // skip closing tag - } elseif ($values[$i][tag] == 'rdf:Alt') { + } elseif ($values[$i]['tag'] == 'rdf:Alt') { // Language Alternative property, only the first (default) value is used $i++; $this->_parseXmpNode($values, $i, $meta); - while ($values[++$i][tag] != 'rdf:Alt'); + while ($values[++$i]['tag'] != 'rdf:Alt'); $i++; // skip closing tag } else { // Structure property $meta = array(); - $startTag = $values[$i-1][tag]; + $startTag = $values[$i-1]['tag']; do { - $this->_parseXmpNode($values, $i, $meta[$values[$i][tag]]); - } while ($values[++$i][tag] != $startTag); + $this->_parseXmpNode($values, $i, $meta[$values[$i]['tag']]); + } while ($values[++$i]['tag'] != $startTag); } } /*************************************************************/ - function _parseMarkerExif() - { + function _parseMarkerExif() { if (!isset($this->_markers)) { $this->_readJPEG(); } @@ -1598,11 +1545,9 @@ class JpegMeta if ($byteAlign == 0x4949) { // "II" $isBigEndian = false; - } - elseif ($byteAlign == 0x4D4D) { // "MM" + } elseif ($byteAlign == 0x4D4D) { // "MM" $isBigEndian = true; - } - else { + } else { return false; // Unexpected data } @@ -1612,8 +1557,7 @@ class JpegMeta if ($isBigEndian) { $this->_info['exif']['ByteAlign'] = "Big Endian"; - } - else { + } else { $this->_info['exif']['ByteAlign'] = "Little Endian"; } @@ -1629,8 +1573,7 @@ class JpegMeta } /*************************************************************/ - function _readIFD($data, $base, $offset, $isBigEndian, $mode) - { + function _readIFD($data, $base, $offset, $isBigEndian, $mode) { $EXIFTags = $this->_exifTagNames($mode); $numEntries = $this->_getShort($data, $base + $offset, $isBigEndian); @@ -1658,161 +1601,146 @@ class JpegMeta if ($dataLength > 4) { $dataOffset = $this->_getLong($data, $base + $offset, $isBigEndian); $rawValue = $this->_getFixedString($data, $base + $dataOffset, $dataLength); - } - else { + } else { $rawValue = $this->_getFixedString($data, $base + $offset, $dataLength); } $offset += 4; switch ($type) { - case 1: // UBYTE - if ($count == 1) { - $value = $this->_getByte($rawValue, 0); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getByte($rawValue, $j); - } - break; - case 2: // ASCII - $value = $rawValue; - break; - case 3: // USHORT - if ($count == 1) { - $value = $this->_getShort($rawValue, 0, $isBigEndian); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); - } - break; - case 4: // ULONG - if ($count == 1) { - $value = $this->_getLong($rawValue, 0, $isBigEndian); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); - } - break; - case 5: // URATIONAL - if ($count == 1) { - $a = $this->_getLong($rawValue, 0, $isBigEndian); - $b = $this->_getLong($rawValue, 4, $isBigEndian); - $value = array(); - $value['val'] = 0; - $value['num'] = $a; - $value['den'] = $b; - if (($a != 0) && ($b != 0)) { - $value['val'] = $a / $b; + case 1: // UBYTE + if ($count == 1) { + $value = $this->_getByte($rawValue, 0); + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getByte($rawValue, $j); } - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) { - $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); - $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); + break; + case 2: // ASCII + $value = $rawValue; + break; + case 3: // USHORT + if ($count == 1) { + $value = $this->_getShort($rawValue, 0, $isBigEndian); + } else { $value = array(); - $value[$j]['val'] = 0; - $value[$j]['num'] = $a; - $value[$j]['den'] = $b; - if (($a != 0) && ($b != 0)) - $value[$j]['val'] = $a / $b; + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); } - } - break; - case 6: // SBYTE - if ($count == 1) { - $value = $this->_getByte($rawValue, 0); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getByte($rawValue, $j); - } - break; - case 7: // UNDEFINED - $value = $rawValue; - break; - case 8: // SSHORT - if ($count == 1) { - $value = $this->_getShort($rawValue, 0, $isBigEndian); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); - } - break; - case 9: // SLONG - if ($count == 1) { - $value = $this->_getLong($rawValue, 0, $isBigEndian); - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) - $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); - } - break; - case 10: // SRATIONAL - if ($count == 1) { - $a = $this->_getLong($rawValue, 0, $isBigEndian); - $b = $this->_getLong($rawValue, 4, $isBigEndian); - $value = array(); - $value['val'] = 0; - $value['num'] = $a; - $value['den'] = $b; - if (($a != 0) && ($b != 0)) - $value['val'] = $a / $b; - } - else { - $value = array(); - for ($j = 0; $j < $count; $j++) { - $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); - $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); + break; + case 4: // ULONG + if ($count == 1) { + $value = $this->_getLong($rawValue, 0, $isBigEndian); + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); + } + break; + case 5: // URATIONAL + if ($count == 1) { + $a = $this->_getLong($rawValue, 0, $isBigEndian); + $b = $this->_getLong($rawValue, 4, $isBigEndian); + $value = array(); + $value['val'] = 0; + $value['num'] = $a; + $value['den'] = $b; + if (($a != 0) && ($b != 0)) { + $value['val'] = $a / $b; + } + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) { + $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); + $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); + $value = array(); + $value[$j]['val'] = 0; + $value[$j]['num'] = $a; + $value[$j]['den'] = $b; + if (($a != 0) && ($b != 0)) + $value[$j]['val'] = $a / $b; + } + } + break; + case 6: // SBYTE + if ($count == 1) { + $value = $this->_getByte($rawValue, 0); + } else { $value = array(); - $value[$j]['val'] = 0; - $value[$j]['num'] = $a; - $value[$j]['den'] = $b; + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getByte($rawValue, $j); + } + break; + case 7: // UNDEFINED + $value = $rawValue; + break; + case 8: // SSHORT + if ($count == 1) { + $value = $this->_getShort($rawValue, 0, $isBigEndian); + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getShort($rawValue, $j * 2, $isBigEndian); + } + break; + case 9: // SLONG + if ($count == 1) { + $value = $this->_getLong($rawValue, 0, $isBigEndian); + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) + $value[$j] = $this->_getLong($rawValue, $j * 4, $isBigEndian); + } + break; + case 10: // SRATIONAL + if ($count == 1) { + $a = $this->_getLong($rawValue, 0, $isBigEndian); + $b = $this->_getLong($rawValue, 4, $isBigEndian); + $value = array(); + $value['val'] = 0; + $value['num'] = $a; + $value['den'] = $b; if (($a != 0) && ($b != 0)) - $value[$j]['val'] = $a / $b; + $value['val'] = $a / $b; + } else { + $value = array(); + for ($j = 0; $j < $count; $j++) { + $a = $this->_getLong($rawValue, $j * 8, $isBigEndian); + $b = $this->_getLong($rawValue, ($j * 8) + 4, $isBigEndian); + $value = array(); + $value[$j]['val'] = 0; + $value[$j]['num'] = $a; + $value[$j]['den'] = $b; + if (($a != 0) && ($b != 0)) + $value[$j]['val'] = $a / $b; + } } - } - break; - case 11: // FLOAT - $value = $rawValue; - break; + break; + case 11: // FLOAT + $value = $rawValue; + break; - case 12: // DFLOAT - $value = $rawValue; - break; - default: - return false; // Unexpected Type + case 12: // DFLOAT + $value = $rawValue; + break; + default: + return false; // Unexpected Type } $tagName = ''; if (($mode == 'ifd0') && ($tag == 0x8769)) { // ExifIFDOffset $this->_readIFD($data, $base, $value, $isBigEndian, 'exif'); - } - elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset + } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset $this->_readIFD($data, $base, $value, $isBigEndian, 'gps'); - } - elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets + } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets $exifTIFFOffset = $value; - } - elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts + } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts $exifTIFFLength = $value; - } - elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset + } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset $exifThumbnailOffset = $value; - } - elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength + } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength $exifThumbnailLength = $value; - } - elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset + } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset $this->_readIFD($data, $base, $value, $isBigEndian, 'interop'); } // elseif (($mode == 'exif') && ($tag == 0x927C)) { // MakerNote @@ -1828,18 +1756,19 @@ class JpegMeta } $this->_info['exif'][$tagName][count($this->_info['exif'][$tagName])] = $value; - } - else { + } else { $this->_info['exif'][$tagName] = $value; } } - else { -#echo sprintf("<h1>Unknown tag %02x (t: %d l: %d) %s in %s</h1>", $tag, $type, $count, $mode, $this->_fileName); + /* + else { + echo sprintf("<h1>Unknown tag %02x (t: %d l: %d) %s in %s</h1>", $tag, $type, $count, $mode, $this->_fileName); // Unknown Tags will be ignored!!! // That's because the tag might be a pointer (like the Exif tag) // and saving it without saving the data it points to might // create an invalid file. } + */ } } @@ -1856,8 +1785,7 @@ class JpegMeta } /*************************************************************/ - function & _createMarkerExif() - { + function & _createMarkerExif() { $data = null; $count = count($this->_markers); for ($i = 0; $i < $count; $i++) { @@ -1882,8 +1810,7 @@ class JpegMeta $isBigEndian = true; $aux = "MM"; $pos = $this->_putString($data, $pos, $aux); - } - else { + } else { $isBigEndian = false; $aux = "II"; $pos = $this->_putString($data, $pos, $aux); @@ -1901,8 +1828,7 @@ class JpegMeta } /*************************************************************/ - function _writeIFD(&$data, $pos, $offsetBase, &$entries, $isBigEndian, $hasNext) - { + function _writeIFD(&$data, $pos, $offsetBase, &$entries, $isBigEndian, $hasNext) { $tiffData = null; $tiffDataOffsetPos = -1; @@ -1922,24 +1848,21 @@ class JpegMeta $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); $dataPos = $this->_writeIFD($data, $dataPos, $offsetBase, $entries[$i]['value'], $isBigEndian, false); - } - elseif ($type == -98) { // TIFF Data + } elseif ($type == -98) { // TIFF Data $pos = $this->_putShort($data, $pos, $tag, $isBigEndian); $pos = $this->_putShort($data, $pos, 0x04, $isBigEndian); // LONG $pos = $this->_putLong($data, $pos, 0x01, $isBigEndian); // Count = 1 $tiffDataOffsetPos = $pos; $pos = $this->_putLong($data, $pos, 0x00, $isBigEndian); // For Now $tiffData =& $entries[$i]['value'] ; - } - else { // Regular Entry + } else { // Regular Entry $pos = $this->_putShort($data, $pos, $tag, $isBigEndian); $pos = $this->_putShort($data, $pos, $type, $isBigEndian); $pos = $this->_putLong($data, $pos, $entries[$i]['count'], $isBigEndian); if (strlen($entries[$i]['value']) > 4) { $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); $dataPos = $this->_putString($data, $dataPos, $entries[$i]['value']); - } - else { + } else { $val = str_pad($entries[$i]['value'], 4, "\0"); $pos = $this->_putString($data, $pos, $val); } @@ -1953,8 +1876,7 @@ class JpegMeta if ($hasNext) { $pos = $this->_putLong($data, $pos, $dataPos - $offsetBase, $isBigEndian); - } - else { + } else { $pos = $this->_putLong($data, $pos, 0, $isBigEndian); } @@ -1962,8 +1884,7 @@ class JpegMeta } /*************************************************************/ - function & _getIFDEntries($isBigEndian, $mode) - { + function & _getIFDEntries($isBigEndian, $mode) { $EXIFNames = $this->_exifTagNames($mode); $EXIFTags = $this->_exifNameTags($mode); $EXIFTypeInfo = $this->_exifTagTypes($mode); @@ -1985,60 +1906,47 @@ class JpegMeta else { $value = null; } - } - elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset + } elseif (($mode == 'ifd0') && ($tag == 0x8825)) { // GPSIFDOffset if (isset($this->_info['exif']['GPSVersionID'])) { $value =& $this->_getIFDEntries($isBigEndian, "gps"); $type = -99; - } - else { + } else { $value = null; } - } - elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets + } elseif (($mode == 'ifd1') && ($tag == 0x0111)) { // TIFFStripOffsets if (isset($this->_info['exif']['TIFFStrips'])) { $value =& $this->_info['exif']['TIFFStrips']; $type = -98; - } - else { + } else { $value = null; } - } - elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts + } elseif (($mode == 'ifd1') && ($tag == 0x0117)) { // TIFFStripByteCounts if (isset($this->_info['exif']['TIFFStrips'])) { $value = strlen($this->_info['exif']['TIFFStrips']); - } - else { + } else { $value = null; } - } - elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset + } elseif (($mode == 'ifd1') && ($tag == 0x0201)) { // TIFFJFIFOffset if (isset($this->_info['exif']['JFIFThumbnail'])) { $value =& $this->_info['exif']['JFIFThumbnail']; $type = -98; - } - else { + } else { $value = null; } - } - elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength + } elseif (($mode == 'ifd1') && ($tag == 0x0202)) { // TIFFJFIFLength if (isset($this->_info['exif']['JFIFThumbnail'])) { $value = strlen($this->_info['exif']['JFIFThumbnail']); - } - else { + } else { $value = null; } - } - elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset + } elseif (($mode == 'exif') && ($tag == 0xA005)) { // InteropIFDOffset if (isset($this->_info['exif']['InteroperabilityIndex'])) { $value =& $this->_getIFDEntries($isBigEndian, "interop"); $type = -99; - } - else { + } else { $value = null; } - } - elseif (isset($this->_info['exif'][$name])) { + } elseif (isset($this->_info['exif'][$name])) { $origValue =& $this->_info['exif'][$name]; // This makes it easier to process variable size elements @@ -2055,235 +1963,235 @@ class JpegMeta $value = " "; switch ($type) { - case 1: // UBYTE - if ($count == 0) { - $count = $origCount; - } + case 1: // UBYTE + if ($count == 0) { + $count = $origCount; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { + $j = 0; + while (($j < $count) && ($j < $origCount)) { - $this->_putByte($value, $j, $origValue[$j]); - $j++; - } + $this->_putByte($value, $j, $origValue[$j]); + $j++; + } - while ($j < $count) { - $this->_putByte($value, $j, 0); - $j++; - } - break; - case 2: // ASCII - $v = strval($origValue[0]); - if (($count != 0) && (strlen($v) > $count)) { - $v = substr($v, 0, $count); - } - elseif (($count > 0) && (strlen($v) < $count)) { - $v = str_pad($v, $count, "\0"); - } + while ($j < $count) { + $this->_putByte($value, $j, 0); + $j++; + } + break; + case 2: // ASCII + $v = strval($origValue[0]); + if (($count != 0) && (strlen($v) > $count)) { + $v = substr($v, 0, $count); + } + elseif (($count > 0) && (strlen($v) < $count)) { + $v = str_pad($v, $count, "\0"); + } - $count = strlen($v); + $count = strlen($v); - $this->_putString($value, 0, $v); - break; - case 3: // USHORT - if ($count == 0) { - $count = $origCount; - } - - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); - $j++; - } + $this->_putString($value, 0, $v); + break; + case 3: // USHORT + if ($count == 0) { + $count = $origCount; + } - while ($j < $count) { - $this->_putShort($value, $j * 2, 0, $isBigEndian); - $j++; - } - break; - case 4: // ULONG - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); - $j++; - } + while ($j < $count) { + $this->_putShort($value, $j * 2, 0, $isBigEndian); + $j++; + } + break; + case 4: // ULONG + if ($count == 0) { + $count = $origCount; + } - while ($j < $count) { - $this->_putLong($value, $j * 4, 0, $isBigEndian); - $j++; - } - break; - case 5: // URATIONAL - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $v = $origValue[$j]; - if (is_array($v)) { - $a = $v['num']; - $b = $v['den']; + while ($j < $count) { + $this->_putLong($value, $j * 4, 0, $isBigEndian); + $j++; } - else { - $a = 0; - $b = 0; - // TODO: Allow other types and convert them + break; + case 5: // URATIONAL + if ($count == 0) { + $count = $origCount; } - $this->_putLong($value, $j * 8, $a, $isBigEndian); - $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); - $j++; - } - while ($j < $count) { - $this->_putLong($value, $j * 8, 0, $isBigEndian); - $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); - $j++; - } - break; - case 6: // SBYTE - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $v = $origValue[$j]; + if (is_array($v)) { + $a = $v['num']; + $b = $v['den']; + } + else { + $a = 0; + $b = 0; + // TODO: Allow other types and convert them + } + $this->_putLong($value, $j * 8, $a, $isBigEndian); + $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $this->_putByte($value, $j, $origValue[$j]); - $j++; - } + while ($j < $count) { + $this->_putLong($value, $j * 8, 0, $isBigEndian); + $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); + $j++; + } + break; + case 6: // SBYTE + if ($count == 0) { + $count = $origCount; + } - while ($j < $count) { - $this->_putByte($value, $j, 0); - $j++; - } - break; - case 7: // UNDEFINED - $v = strval($origValue[0]); - if (($count != 0) && (strlen($v) > $count)) { - $v = substr($v, 0, $count); - } - elseif (($count > 0) && (strlen($v) < $count)) { - $v = str_pad($v, $count, "\0"); - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $this->_putByte($value, $j, $origValue[$j]); + $j++; + } - $count = strlen($v); + while ($j < $count) { + $this->_putByte($value, $j, 0); + $j++; + } + break; + case 7: // UNDEFINED + $v = strval($origValue[0]); + if (($count != 0) && (strlen($v) > $count)) { + $v = substr($v, 0, $count); + } + elseif (($count > 0) && (strlen($v) < $count)) { + $v = str_pad($v, $count, "\0"); + } - $this->_putString($value, 0, $v); - break; - case 8: // SSHORT - if ($count == 0) { - $count = $origCount; - } + $count = strlen($v); - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); - $j++; - } + $this->_putString($value, 0, $v); + break; + case 8: // SSHORT + if ($count == 0) { + $count = $origCount; + } - while ($j < $count) { - $this->_putShort($value, $j * 2, 0, $isBigEndian); - $j++; - } - break; - case 9: // SLONG - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $this->_putShort($value, $j * 2, $origValue[$j], $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); - $j++; - } + while ($j < $count) { + $this->_putShort($value, $j * 2, 0, $isBigEndian); + $j++; + } + break; + case 9: // SLONG + if ($count == 0) { + $count = $origCount; + } - while ($j < $count) { - $this->_putLong($value, $j * 4, 0, $isBigEndian); - $j++; - } - break; - case 10: // SRATIONAL - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $this->_putLong($value, $j * 4, $origValue[$j], $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $v = $origValue[$j]; - if (is_array($v)) { - $a = $v['num']; - $b = $v['den']; + while ($j < $count) { + $this->_putLong($value, $j * 4, 0, $isBigEndian); + $j++; } - else { - $a = 0; - $b = 0; - // TODO: Allow other types and convert them + break; + case 10: // SRATIONAL + if ($count == 0) { + $count = $origCount; } - $this->_putLong($value, $j * 8, $a, $isBigEndian); - $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); - $j++; - } - - while ($j < $count) { - $this->_putLong($value, $j * 8, 0, $isBigEndian); - $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); - $j++; - } - break; - case 11: // FLOAT - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $v = $origValue[$j]; + if (is_array($v)) { + $a = $v['num']; + $b = $v['den']; + } + else { + $a = 0; + $b = 0; + // TODO: Allow other types and convert them + } + + $this->_putLong($value, $j * 8, $a, $isBigEndian); + $this->_putLong($value, ($j * 8) + 4, $b, $isBigEndian); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $v = strval($origValue[$j]); - if (strlen($v) > 4) { - $v = substr($v, 0, 4); + while ($j < $count) { + $this->_putLong($value, $j * 8, 0, $isBigEndian); + $this->_putLong($value, ($j * 8) + 4, 0, $isBigEndian); + $j++; } - elseif (strlen($v) < 4) { - $v = str_pad($v, 4, "\0"); + break; + case 11: // FLOAT + if ($count == 0) { + $count = $origCount; } - $this->_putString($value, $j * 4, $v); - $j++; - } - while ($j < $count) { - $this->_putString($value, $j * 4, "\0\0\0\0"); - $j++; - } - break; - case 12: // DFLOAT - if ($count == 0) { - $count = $origCount; - } + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $v = strval($origValue[$j]); + if (strlen($v) > 4) { + $v = substr($v, 0, 4); + } + elseif (strlen($v) < 4) { + $v = str_pad($v, 4, "\0"); + } + $this->_putString($value, $j * 4, $v); + $j++; + } - $j = 0; - while (($j < $count) && ($j < $origCount)) { - $v = strval($origValue[$j]); - if (strlen($v) > 8) { - $v = substr($v, 0, 8); + while ($j < $count) { + $this->_putString($value, $j * 4, "\0\0\0\0"); + $j++; } - elseif (strlen($v) < 8) { - $v = str_pad($v, 8, "\0"); + break; + case 12: // DFLOAT + if ($count == 0) { + $count = $origCount; } - $this->_putString($value, $j * 8, $v); - $j++; - } - while ($j < $count) { - $this->_putString($value, $j * 8, "\0\0\0\0\0\0\0\0"); - $j++; - } - break; - default: - $value = null; - break; + $j = 0; + while (($j < $count) && ($j < $origCount)) { + $v = strval($origValue[$j]); + if (strlen($v) > 8) { + $v = substr($v, 0, 8); + } + elseif (strlen($v) < 8) { + $v = str_pad($v, 8, "\0"); + } + $this->_putString($value, $j * 8, $v); + $j++; + } + + while ($j < $count) { + $this->_putString($value, $j * 8, "\0\0\0\0\0\0\0\0"); + $j++; + } + break; + default: + $value = null; + break; } } @@ -2302,8 +2210,7 @@ class JpegMeta } /*************************************************************/ - function _parseMarkerAdobe() - { + function _parseMarkerAdobe() { if (!isset($this->_markers)) { $this->_readJPEG(); } @@ -2359,36 +2266,36 @@ class JpegMeta $basePos = $pos; switch ($type) { - case 0x0404: // Caption (IPTC Data) - $pos = $this->_readIPTC($data, $pos); - if ($pos == false) - return false; - break; - case 0x040A: // CopyrightFlag - $this->_info['adobe']['CopyrightFlag'] = $this->_getByte($data, $pos); - $pos += $length; - break; - case 0x040B: // ImageURL - $this->_info['adobe']['ImageURL'] = $this->_getFixedString($data, $pos, $length); - $pos += $length; - break; - case 0x040C: // Thumbnail - $aux = $this->_getLong($data, $pos); - $pos += 4; - if ($aux == 1) { - $this->_info['adobe']['ThumbnailWidth'] = $this->_getLong($data, $pos); - $pos += 4; - $this->_info['adobe']['ThumbnailHeight'] = $this->_getLong($data, $pos); + case 0x0404: // Caption (IPTC Data) + $pos = $this->_readIPTC($data, $pos); + if ($pos == false) + return false; + break; + case 0x040A: // CopyrightFlag + $this->_info['adobe']['CopyrightFlag'] = $this->_getByte($data, $pos); + $pos += $length; + break; + case 0x040B: // ImageURL + $this->_info['adobe']['ImageURL'] = $this->_getFixedString($data, $pos, $length); + $pos += $length; + break; + case 0x040C: // Thumbnail + $aux = $this->_getLong($data, $pos); $pos += 4; + if ($aux == 1) { + $this->_info['adobe']['ThumbnailWidth'] = $this->_getLong($data, $pos); + $pos += 4; + $this->_info['adobe']['ThumbnailHeight'] = $this->_getLong($data, $pos); + $pos += 4; - $pos += 16; // Skip some data + $pos += 16; // Skip some data - $this->_info['adobe']['ThumbnailData'] = $this->_getFixedString($data, $pos, $length - 28); - $pos += $length - 28; - } - break; - default: - break; + $this->_info['adobe']['ThumbnailData'] = $this->_getFixedString($data, $pos, $length - 28); + $pos += $length - 28; + } + break; + default: + break; } // We save all blocks, even those we recognized @@ -2404,8 +2311,7 @@ class JpegMeta } /*************************************************************/ - function _readIPTC(&$data, $pos = 0) - { + function _readIPTC(&$data, $pos = 0) { $totalLength = strlen($data); $IPTCTags =& $this->_iptcTagNames(); @@ -2426,8 +2332,7 @@ class JpegMeta if (isset($IPTCTags[$type])) { $label = $IPTCTags[$type]; - } - else { + } else { $label = sprintf('IPTC_0x%02x', $type); } @@ -2439,8 +2344,7 @@ class JpegMeta $this->_info['iptc'][$label] = $aux; } $this->_info['iptc'][$label][ count($this->_info['iptc'][$label]) ] = $this->_getFixedString($data, $pos, $length); - } - else { + } else { $this->_info['iptc'][$label] = $this->_getFixedString($data, $pos, $length); } } @@ -2451,8 +2355,7 @@ class JpegMeta } /*************************************************************/ - function & _createMarkerAdobe() - { + function & _createMarkerAdobe() { if (isset($this->_info['iptc'])) { if (!isset($this->_info['adobe'])) { $this->_info['adobe'] = array(); @@ -2475,11 +2378,11 @@ class JpegMeta reset($this->_info['adobe']['raw']); while (list($key) = each($this->_info['adobe']['raw'])) { $pos = $this->_write8BIM( - $data, - $pos, - $this->_info['adobe']['raw'][$key]['type'], - $this->_info['adobe']['raw'][$key]['header'], - $this->_info['adobe']['raw'][$key]['data'] ); + $data, + $pos, + $this->_info['adobe']['raw'][$key]['type'], + $this->_info['adobe']['raw'][$key]['header'], + $this->_info['adobe']['raw'][$key]['data'] ); } } @@ -2487,8 +2390,7 @@ class JpegMeta } /*************************************************************/ - function _write8BIM(&$data, $pos, $type, $header, &$value) - { + function _write8BIM(&$data, $pos, $type, $header, &$value) { $signature = "8BIM"; $pos = $this->_putString($data, $pos, $signature); @@ -2512,8 +2414,7 @@ class JpegMeta } /*************************************************************/ - function & _writeIPTC() - { + function & _writeIPTC() { $data = " "; $pos = 0; @@ -2521,7 +2422,6 @@ class JpegMeta reset($this->_info['iptc']); - while (list($label) = each($this->_info['iptc'])) { $value =& $this->_info['iptc'][$label]; $type = -1; @@ -2535,7 +2435,8 @@ class JpegMeta if ($type != -1) { if (is_array($value)) { - for ($i = 0; $i < count($value); $i++) { + $vcnt = count($value); + for ($i = 0; $i < $vcnt; $i++) { $pos = $this->_writeIPTCEntry($data, $pos, $type, $value[$i]); } } @@ -2549,8 +2450,7 @@ class JpegMeta } /*************************************************************/ - function _writeIPTCEntry(&$data, $pos, $type, &$value) - { + function _writeIPTCEntry(&$data, $pos, $type, &$value) { $pos = $this->_putShort($data, $pos, 0x1C02); $pos = $this->_putByte($data, $pos, $type); $pos = $this->_putShort($data, $pos, strlen($value)); @@ -2560,8 +2460,7 @@ class JpegMeta } /*************************************************************/ - function _exifTagNames($mode) - { + function _exifTagNames($mode) { $tags = array(); if ($mode == 'ifd0') { @@ -2627,8 +2526,7 @@ class JpegMeta $tags[0x0214] = 'TIFFReferenceBlackWhite'; $tags[0x8298] = 'TIFFCopyright'; $tags[0x9286] = 'TIFFUserComment'; - } - elseif ($mode == 'exif') { + } elseif ($mode == 'exif') { $tags[0x829A] = 'ExposureTime'; $tags[0x829D] = 'FNumber'; $tags[0x8822] = 'ExposureProgram'; @@ -2672,15 +2570,13 @@ class JpegMeta $tags[0xA300] = 'FileSource'; $tags[0xA301] = 'SceneType'; $tags[0xA302] = 'CFAPattern'; - } - elseif ($mode == 'interop') { + } elseif ($mode == 'interop') { $tags[0x0001] = 'InteroperabilityIndex'; $tags[0x0002] = 'InteroperabilityVersion'; $tags[0x1000] = 'RelatedImageFileFormat'; $tags[0x1001] = 'RelatedImageWidth'; $tags[0x1002] = 'RelatedImageLength'; - } - elseif ($mode == 'gps') { + } elseif ($mode == 'gps') { $tags[0x0000] = 'GPSVersionID'; $tags[0x0001] = 'GPSLatitudeRef'; $tags[0x0002] = 'GPSLatitude'; @@ -2714,8 +2610,7 @@ class JpegMeta } /*************************************************************/ - function _exifTagTypes($mode) - { + function _exifTagTypes($mode) { $tags = array(); if ($mode == 'ifd0') { @@ -2781,8 +2676,7 @@ class JpegMeta $tags[0x0214] = array(5, 6); // TIFFReferenceBlackWhite -> RATIONAL, 6 $tags[0x8298] = array(2, 0); // TIFFCopyright -> ASCII, Any $tags[0x9286] = array(2, 0); // TIFFUserComment -> ASCII, Any - } - elseif ($mode == 'exif') { + } elseif ($mode == 'exif') { $tags[0x829A] = array(5, 1); // ExposureTime -> RATIONAL, 1 $tags[0x829D] = array(5, 1); // FNumber -> RATIONAL, 1 $tags[0x8822] = array(3, 1); // ExposureProgram -> SHORT, 1 @@ -2826,15 +2720,13 @@ class JpegMeta $tags[0xA300] = array(7, 1); // FileSource -> UNDEFINED, 1 $tags[0xA301] = array(7, 1); // SceneType -> UNDEFINED, 1 $tags[0xA302] = array(7, 0); // CFAPattern -> UNDEFINED, Any - } - elseif ($mode == 'interop') { + } elseif ($mode == 'interop') { $tags[0x0001] = array(2, 0); // InteroperabilityIndex -> ASCII, Any $tags[0x0002] = array(7, 4); // InteroperabilityVersion -> UNKNOWN, 4 $tags[0x1000] = array(2, 0); // RelatedImageFileFormat -> ASCII, Any $tags[0x1001] = array(4, 1); // RelatedImageWidth -> LONG (or SHORT), 1 $tags[0x1002] = array(4, 1); // RelatedImageLength -> LONG (or SHORT), 1 - } - elseif ($mode == 'gps') { + } elseif ($mode == 'gps') { $tags[0x0000] = array(1, 4); // GPSVersionID -> BYTE, 4 $tags[0x0001] = array(2, 2); // GPSLatitudeRef -> ASCII, 2 $tags[0x0002] = array(5, 3); // GPSLatitude -> RATIONAL, 3 @@ -2868,15 +2760,13 @@ class JpegMeta } /*************************************************************/ - function _exifNameTags($mode) - { + function _exifNameTags($mode) { $tags = $this->_exifTagNames($mode); return $this->_names2Tags($tags); } /*************************************************************/ - function _iptcTagNames() - { + function _iptcTagNames() { $tags = array(); $tags[0x14] = 'SuplementalCategories'; $tags[0x19] = 'Keywords'; @@ -2903,15 +2793,13 @@ class JpegMeta } /*************************************************************/ - function & _iptcNameTags() - { + function & _iptcNameTags() { $tags = $this->_iptcTagNames(); return $this->_names2Tags($tags); } /*************************************************************/ - function _names2Tags($tags2Names) - { + function _names2Tags($tags2Names) { $names2Tags = array(); reset($tags2Names); while (list($tag, $name) = each($tags2Names)) { @@ -2922,14 +2810,12 @@ class JpegMeta } /*************************************************************/ - function _getByte(&$data, $pos) - { + function _getByte(&$data, $pos) { return ord($data{$pos}); } /*************************************************************/ - function _putByte(&$data, $pos, $val) - { + function _putByte(&$data, $pos, $val) { $val = intval($val); $data{$pos} = chr($val); @@ -2938,28 +2824,24 @@ class JpegMeta } /*************************************************************/ - function _getShort(&$data, $pos, $bigEndian = true) - { + function _getShort(&$data, $pos, $bigEndian = true) { if ($bigEndian) { return (ord($data{$pos}) << 8) - + ord($data{$pos + 1}); - } - else { + + ord($data{$pos + 1}); + } else { return ord($data{$pos}) - + (ord($data{$pos + 1}) << 8); + + (ord($data{$pos + 1}) << 8); } } /*************************************************************/ - function _putShort(&$data, $pos = 0, $val, $bigEndian = true) - { + function _putShort(&$data, $pos = 0, $val = 0, $bigEndian = true) { $val = intval($val); if ($bigEndian) { $data{$pos + 0} = chr(($val & 0x0000FF00) >> 8); $data{$pos + 1} = chr(($val & 0x000000FF) >> 0); - } - else { + } else { $data{$pos + 0} = chr(($val & 0x00FF) >> 0); $data{$pos + 1} = chr(($val & 0xFF00) >> 8); } @@ -2968,25 +2850,22 @@ class JpegMeta } /*************************************************************/ - function _getLong(&$data, $pos, $bigEndian = true) - { + function _getLong(&$data, $pos, $bigEndian = true) { if ($bigEndian) { return (ord($data{$pos}) << 24) - + (ord($data{$pos + 1}) << 16) - + (ord($data{$pos + 2}) << 8) - + ord($data{$pos + 3}); - } - else { + + (ord($data{$pos + 1}) << 16) + + (ord($data{$pos + 2}) << 8) + + ord($data{$pos + 3}); + } else { return ord($data{$pos}) - + (ord($data{$pos + 1}) << 8) - + (ord($data{$pos + 2}) << 16) - + (ord($data{$pos + 3}) << 24); + + (ord($data{$pos + 1}) << 8) + + (ord($data{$pos + 2}) << 16) + + (ord($data{$pos + 3}) << 24); } } /*************************************************************/ - function _putLong(&$data, $pos, $val, $bigEndian = true) - { + function _putLong(&$data, $pos, $val, $bigEndian = true) { $val = intval($val); if ($bigEndian) { @@ -2994,8 +2873,7 @@ class JpegMeta $data{$pos + 1} = chr(($val & 0x00FF0000) >> 16); $data{$pos + 2} = chr(($val & 0x0000FF00) >> 8); $data{$pos + 3} = chr(($val & 0x000000FF) >> 0); - } - else { + } else { $data{$pos + 0} = chr(($val & 0x000000FF) >> 0); $data{$pos + 1} = chr(($val & 0x0000FF00) >> 8); $data{$pos + 2} = chr(($val & 0x00FF0000) >> 16); @@ -3006,16 +2884,14 @@ class JpegMeta } /*************************************************************/ - function & _getNullString(&$data, $pos) - { + function & _getNullString(&$data, $pos) { $str = ''; $max = strlen($data); while ($pos < $max) { if (ord($data{$pos}) == 0) { return $str; - } - else { + } else { $str .= $data{$pos}; } $pos++; @@ -3025,8 +2901,7 @@ class JpegMeta } /*************************************************************/ - function & _getFixedString(&$data, $pos, $length = -1) - { + function & _getFixedString(&$data, $pos, $length = -1) { if ($length == -1) { $length = strlen($data) - $pos; } @@ -3035,23 +2910,20 @@ class JpegMeta } /*************************************************************/ - function _putString(&$data, $pos, &$str) - { + function _putString(&$data, $pos, &$str) { $len = strlen($str); for ($i = 0; $i < $len; $i++) { - $data{$pos + $i} = $str{$i}; + $data{$pos + $i} = $str{$i}; } return $pos + $len; } /*************************************************************/ - function _hexDump(&$data, $start = 0, $length = -1) - { + function _hexDump(&$data, $start = 0, $length = -1) { if (($length == -1) || (($length + $start) > strlen($data))) { $end = strlen($data); - } - else { + } else { $end = $start + $length; } @@ -3109,8 +2981,7 @@ class JpegMeta echo "</tt>\n"; } -/*****************************************************************/ + /*****************************************************************/ } /* vim: set expandtab tabstop=4 shiftwidth=4: */ - diff --git a/inc/ZipLib.class.php b/inc/ZipLib.class.php index 836e9d9e6..09dbbd3bd 100644 --- a/inc/ZipLib.class.php +++ b/inc/ZipLib.class.php @@ -5,471 +5,500 @@ * @link http://dev.maxg.info * @link http://forum.maxg.info * - * Modified for Dokuwiki - * @author Christopher Smith <chris@jalakai.co.uk> + * Modified for Dokuwiki + * @author Christopher Smith <chris@jalakai.co.uk> */ -class ZipLib -{ - - var $datasec, $ctrl_dir = array(); - var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; - var $old_offset = 0; var $dirs = Array("."); - - function get_List($zip_name) - { - $zip = @fopen($zip_name, 'rb'); - if(!$zip) return(0); - $centd = $this->ReadCentralDir($zip,$zip_name); - - @rewind($zip); - @fseek($zip, $centd['offset']); - - for ($i=0; $i<$centd['entries']; $i++) - { - $header = $this->ReadCentralFileHeaders($zip); - $header['index'] = $i;$info['filename'] = $header['filename']; - $info['stored_filename'] = $header['stored_filename']; - $info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size']; - $info['crc'] = strtoupper(dechex( $header['crc'] )); - $info['mtime'] = $header['mtime']; $info['comment'] = $header['comment']; - $info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0; - $info['index'] = $header['index'];$info['status'] = $header['status']; - $ret[]=$info; unset($header); - } - return $ret; - } - - function Add($files,$compact) - { - if(!is_array($files[0])) $files=Array($files); - - for($i=0;$files[$i];$i++){ - $fn = $files[$i]; - if(!in_Array(dirname($fn[0]),$this->dirs)) - $this->add_Dir(dirname($fn[0])); - if(basename($fn[0])) - $ret[basename($fn[0])]=$this->add_File($fn[1],$fn[0],$compact); - } - return $ret; - } - - /** - * Zips recursively the $folder directory, from the $basedir directory - */ - function Compress($folder, $basedir=null, $parent=null) - { - $full_path = $basedir."/".$parent.$folder; - $zip_path = $parent.$folder; - if ($zip_path) { - $zip_path .= "/"; - $this->add_dir($zip_path); - } - $dir = new DirectoryIterator($full_path); - foreach($dir as $file) { - if(!$file->isDot()) { - $filename = $file->getFilename(); - if($file->isDir()) { - $this->Compress($filename, $basedir, $zip_path); - } else { - $content = join('', file($full_path.'/'.$filename)); - $this->add_File($content, $zip_path.$filename); +class ZipLib { + + var $datasec; + var $ctrl_dir = array(); + var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; + var $old_offset = 0; + var $dirs = Array("."); + + function get_List($zip_name) { + $zip = @fopen($zip_name, 'rb'); + if(!$zip) return(0); + $centd = $this->ReadCentralDir($zip,$zip_name); + + @rewind($zip); + @fseek($zip, $centd['offset']); + + for ($i=0; $i<$centd['entries']; $i++) { + $header = $this->ReadCentralFileHeaders($zip); + $header['index'] = $i; + + $info['filename'] = $header['filename']; + $info['stored_filename'] = $header['stored_filename']; + $info['size'] = $header['size']; + $info['compressed_size'] = $header['compressed_size']; + $info['crc'] = strtoupper(dechex( $header['crc'] )); + $info['mtime'] = $header['mtime']; + $info['comment'] = $header['comment']; + $info['folder'] = ($header['external']==0x41FF0010||$header['external']==16)?1:0; + $info['index'] = $header['index']; + $info['status'] = $header['status']; + $ret[]=$info; + + unset($header); + } + return $ret; } - } - } - } - - /** - * Returns the Zip file - */ - function get_file() - { - $data = implode('', $this -> datasec); - $ctrldir = implode('', $this -> ctrl_dir); - - return $data . $ctrldir . $this -> eof_ctrl_dir . - pack('v', sizeof($this -> ctrl_dir)).pack('v', sizeof($this -> ctrl_dir)). - pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00"; - } - - function add_dir($name) - { - $name = str_replace("\\", "/", $name); - $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - - $fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); - $fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0); - $this -> datasec[] = $fr; - - $new_offset = strlen(implode("", $this->datasec)); - - $cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - $cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); - $cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 ); - $ext = "\xff\xff\xff\xff"; - $cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name; - - $this -> ctrl_dir[] = $cdrec; - $this -> old_offset = $new_offset; - $this -> dirs[] = $name; - } - - /** - * Add a file named $name from a string $data - */ - function add_File($data, $name, $compact = 1) - { - $name = str_replace('\\', '/', $name); - $dtime = dechex($this->DosTime()); - - $hexdtime = '\x' . $dtime[6] . $dtime[7].'\x'.$dtime[4] . $dtime[5] - . '\x' . $dtime[2] . $dtime[3].'\x'.$dtime[0].$dtime[1]; - eval('$hexdtime = "' . $hexdtime . '";'); - - if($compact) - $fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime; - else $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime; - $unc_len = strlen($data); $crc = crc32($data); - - if($compact){ - $zdata = gzcompress($data); $c_len = strlen($zdata); - $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); - }else{ - $zdata = $data; - } - $c_len=strlen($zdata); - $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); - $fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata; - - $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); - - $this -> datasec[] = $fr; - $new_offset = strlen(implode('', $this->datasec)); - if($compact) - $cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"; - else $cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00"; - $cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); - $cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 ); - $cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 ); - $cdrec .= pack('V', $this -> old_offset ); - - $this -> old_offset = $new_offset; - $cdrec .= $name; - $this -> ctrl_dir[] = $cdrec; - return true; - } - - function DosTime() { - $timearray = getdate(); - if ($timearray['year'] < 1980) { - $timearray['year'] = 1980; $timearray['mon'] = 1; - $timearray['mday'] = 1; $timearray['hours'] = 0; - $timearray['minutes'] = 0; $timearray['seconds'] = 0; - } - return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | - ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); - } - - /** - * Extract a zip file $zn to the $to directory - */ - function Extract ( $zn, $to, $index = Array(-1) ) - { - if(!@is_dir($to)) $this->_mkdir($to); - $ok = 0; $zip = @fopen($zn,'rb'); - if(!$zip) return(-1); - $cdir = $this->ReadCentralDir($zip,$zn); - $pos_entry = $cdir['offset']; - - if(!is_array($index)){ $index = array($index); } - for($i=0; isset($index[$i]);$i++){ - if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries']) - return(-1); - } - - for ($i=0; $i<$cdir['entries']; $i++) - { - @fseek($zip, $pos_entry); - $header = $this->ReadCentralFileHeaders($zip); - $header['index'] = $i; $pos_entry = ftell($zip); - @rewind($zip); fseek($zip, $header['offset']); - if(in_array("-1",$index)||in_array($i,$index)) - $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip); - - } - fclose($zip); - return $stat; - } - - function ReadFileHeader($zip, $header) - { - $binary_data = fread($zip, 30); - $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data); - - $header['filename'] = fread($zip, $data['filename_len']); - if ($data['extra_len'] != 0) { - $header['extra'] = fread($zip, $data['extra_len']); - } else { $header['extra'] = ''; } - - $header['compression'] = $data['compression']; - foreach (array('size','compressed_size','crc') as $hd) { // On ODT files, these headers are 0. Keep the previous value. - if ($data[$hd] != 0) $header[$hd] = $data[$hd]; + + function Add($files,$compact) { + if(!is_array($files[0])) $files=Array($files); + + for($i=0;$files[$i];$i++){ + $fn = $files[$i]; + if(!in_Array(dirname($fn[0]),$this->dirs)) + $this->add_Dir(dirname($fn[0])); + if(basename($fn[0])) + $ret[basename($fn[0])]=$this->add_File($fn[1],$fn[0],$compact); + } + return $ret; + } + + /** + * Zips recursively the $folder directory, from the $basedir directory + */ + function Compress($folder, $basedir=null, $parent=null) { + $full_path = $basedir."/".$parent.$folder; + $zip_path = $parent.$folder; + if ($zip_path) { + $zip_path .= "/"; + $this->add_dir($zip_path); + } + $dir = new DirectoryIterator($full_path); + foreach($dir as $file) { + if(!$file->isDot()) { + $filename = $file->getFilename(); + if($file->isDir()) { + $this->Compress($filename, $basedir, $zip_path); + } else { + $content = join('', file($full_path.'/'.$filename)); + $this->add_File($content, $zip_path.$filename); + } + } + } + } + + /** + * Returns the Zip file + */ + function get_file() { + $data = implode('', $this -> datasec); + $ctrldir = implode('', $this -> ctrl_dir); + + return $data . $ctrldir . $this -> eof_ctrl_dir . + pack('v', count($this->ctrl_dir)).pack('v', count($this->ctrl_dir)). + pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00"; + } + + function add_dir($name) { + $name = str_replace("\\", "/", $name); + $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + + $fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); + $fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0); + $this -> datasec[] = $fr; + + $new_offset = strlen(implode("", $this->datasec)); + + $cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + $cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); + $cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 ); + $ext = "\xff\xff\xff\xff"; + $cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name; + + $this -> ctrl_dir[] = $cdrec; + $this -> old_offset = $new_offset; + $this -> dirs[] = $name; + } + + /** + * Add a file named $name from a string $data + */ + function add_File($data, $name, $compact = 1) { + $name = str_replace('\\', '/', $name); + $dtime = dechex($this->DosTime()); + + $hexdtime = pack('H*',$dtime[6].$dtime[7]. + $dtime[4].$dtime[5]. + $dtime[2].$dtime[3]. + $dtime[0].$dtime[1]); + + if($compact){ + $fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime; + }else{ + $fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime; + } + $unc_len = strlen($data); + $crc = crc32($data); + + if($compact){ + $zdata = gzcompress($data); + $c_len = strlen($zdata); + $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); + }else{ + $zdata = $data; + } + $c_len=strlen($zdata); + $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); + $fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata; + + $fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); + + $this -> datasec[] = $fr; + $new_offset = strlen(implode('', $this->datasec)); + if($compact) { + $cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"; + } else { + $cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00"; + } + $cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len); + $cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 ); + $cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 ); + $cdrec .= pack('V', $this -> old_offset ); + + $this -> old_offset = $new_offset; + $cdrec .= $name; + $this -> ctrl_dir[] = $cdrec; + return true; + } + + function DosTime() { + $timearray = getdate(); + if ($timearray['year'] < 1980) { + $timearray['year'] = 1980; + $timearray['mon'] = 1; + $timearray['mday'] = 1; + $timearray['hours'] = 0; + $timearray['minutes'] = 0; + $timearray['seconds'] = 0; + } + return (($timearray['year'] - 1980) << 25) | + ($timearray['mon'] << 21) | + ($timearray['mday'] << 16) | + ($timearray['hours'] << 11) | + ($timearray['minutes'] << 5) | + ($timearray['seconds'] >> 1); } - $header['flag'] = $data['flag']; - $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime']; - - if ($header['mdate'] && $header['mtime']){ - $hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5; - $seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980; - $month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F; - $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); - }else{$header['mtime'] = time();} - - $header['stored_filename'] = $header['filename']; - $header['status'] = "ok"; - return $header; - } - - function ReadCentralFileHeaders($zip){ - $binary_data = fread($zip, 46); - $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data); - - if ($header['filename_len'] != 0) - $header['filename'] = fread($zip,$header['filename_len']); - else $header['filename'] = ''; - - if ($header['extra_len'] != 0) - $header['extra'] = fread($zip, $header['extra_len']); - else $header['extra'] = ''; - - if ($header['comment_len'] != 0) - $header['comment'] = fread($zip, $header['comment_len']); - else $header['comment'] = ''; - - if ($header['mdate'] && $header['mtime']) - { - $hour = ($header['mtime'] & 0xF800) >> 11; - $minute = ($header['mtime'] & 0x07E0) >> 5; - $seconde = ($header['mtime'] & 0x001F)*2; - $year = (($header['mdate'] & 0xFE00) >> 9) + 1980; - $month = ($header['mdate'] & 0x01E0) >> 5; - $day = $header['mdate'] & 0x001F; - $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); - } else { - $header['mtime'] = time(); + + /** + * Extract a zip file $zn to the $to directory + */ + function Extract ( $zn, $to, $index = Array(-1) ) { + if(!@is_dir($to)) $this->_mkdir($to); + $ok = 0; + $zip = @fopen($zn,'rb'); + if(!$zip) return(-1); + $cdir = $this->ReadCentralDir($zip,$zn); + $pos_entry = $cdir['offset']; + + if(!is_array($index)){ + $index = array($index); + } + for($i=0; isset($index[$i]);$i++){ + if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries']) + return(-1); + } + + for ($i=0; $i<$cdir['entries']; $i++) { + @fseek($zip, $pos_entry); + $header = $this->ReadCentralFileHeaders($zip); + $header['index'] = $i; + $pos_entry = ftell($zip); + @rewind($zip); + fseek($zip, $header['offset']); + if(in_array("-1",$index)||in_array($i,$index)){ + $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip); + } + } + fclose($zip); + return $stat; + } + + function ReadFileHeader($zip, $header) { + $binary_data = fread($zip, 30); + $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data); + + $header['filename'] = fread($zip, $data['filename_len']); + if ($data['extra_len'] != 0) { + $header['extra'] = fread($zip, $data['extra_len']); + } else { + $header['extra'] = ''; + } + + $header['compression'] = $data['compression']; + foreach (array('size','compressed_size','crc') as $hd) { // On ODT files, these headers are 0. Keep the previous value. + if ($data[$hd] != 0) $header[$hd] = $data[$hd]; + } + $header['flag'] = $data['flag']; + $header['mdate'] = $data['mdate']; + $header['mtime'] = $data['mtime']; + + if ($header['mdate'] && $header['mtime']){ + $hour = ($header['mtime']&0xF800)>>11; + $minute = ($header['mtime']&0x07E0)>>5; + $seconde = ($header['mtime']&0x001F)*2; + $year = (($header['mdate']&0xFE00)>>9)+1980; + $month = ($header['mdate']&0x01E0)>>5; + $day = $header['mdate']&0x001F; + $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); + } else { + $header['mtime'] = time(); + } + + $header['stored_filename'] = $header['filename']; + $header['status'] = "ok"; + return $header; + } + + function ReadCentralFileHeaders($zip){ + $binary_data = fread($zip, 46); + $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data); + + if ($header['filename_len'] != 0){ + $header['filename'] = fread($zip,$header['filename_len']); + }else{ + $header['filename'] = ''; + } + + if ($header['extra_len'] != 0){ + $header['extra'] = fread($zip, $header['extra_len']); + }else{ + $header['extra'] = ''; + } + + if ($header['comment_len'] != 0){ + $header['comment'] = fread($zip, $header['comment_len']); + }else{ + $header['comment'] = ''; + } + + if ($header['mdate'] && $header['mtime']) { + $hour = ($header['mtime'] & 0xF800) >> 11; + $minute = ($header['mtime'] & 0x07E0) >> 5; + $seconde = ($header['mtime'] & 0x001F)*2; + $year = (($header['mdate'] & 0xFE00) >> 9) + 1980; + $month = ($header['mdate'] & 0x01E0) >> 5; + $day = $header['mdate'] & 0x001F; + $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year); + } else { + $header['mtime'] = time(); + } + + $header['stored_filename'] = $header['filename']; + $header['status'] = 'ok'; + if (substr($header['filename'], -1) == '/') $header['external'] = 0x41FF0010; + + return $header; + } + + function ReadCentralDir($zip,$zip_name) { + $size = filesize($zip_name); + if ($size < 277){ + $maximum_size = $size; + } else { + $maximum_size=277; + } + + @fseek($zip, $size-$maximum_size); + $pos = ftell($zip); + $bytes = 0x00000000; + + while ($pos < $size) { + $byte = @fread($zip, 1); + $bytes=(($bytes << 8) & 0xFFFFFFFF) | Ord($byte); + if ($bytes == 0x504b0506){ + $pos++; + break; + } + $pos++; + } + + $data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', + fread($zip, 18)); + + if ($data['comment_size'] != 0){ + $centd['comment'] = fread($zip, $data['comment_size']); + } else { + $centd['comment'] = ''; + $centd['entries'] = $data['entries']; + } + $centd['disk_entries'] = $data['disk_entries']; + $centd['offset'] = $data['offset']; + $centd['disk_start'] = $data['disk_start']; + $centd['size'] = $data['size']; + $centd['disk'] = $data['disk']; + return $centd; + } + + function ExtractFile($header,$to,$zip) { + $header = $this->readfileheader($zip, $header); + + if(substr($to,-1)!="/") $to.="/"; + if(substr($header['filename'],-1)=="/") { + $this->_mkdir($to.$header['filename']); + return +2; + } + + if (!$this->_mkdir($to.dirname($header['filename']))) return (-1); + + if (!array_key_exists("external", $header) || (!($header['external']==0x41FF0010)&&!($header['external']==16))) { + if ($header['compression']==0) { + $fp = @fopen($to.$header['filename'], 'wb'); + if(!$fp) return(-1); + $size = $header['compressed_size']; + + while ($size != 0) { + $read_size = ($size < 2048 ? $size : 2048); + $buffer = fread($zip, $read_size); + $binary_data = pack('a'.$read_size, $buffer); + @fwrite($fp, $binary_data, $read_size); + $size -= $read_size; + } + fclose($fp); + touch($to.$header['filename'], $header['mtime']); + + }else{ + if (!is_dir(dirname($to.$header['filename']))) $this->_mkdir(dirname($to.$header['filename'])); + $fp = fopen($to.$header['filename'].'.gz','wb'); + if(!$fp) return(-1); + $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), + Chr(0x00), time(), Chr(0x00), Chr(3)); + + fwrite($fp, $binary_data, 10); + $size = $header['compressed_size']; + + while ($size != 0) { + $read_size = ($size < 1024 ? $size : 1024); + $buffer = fread($zip, $read_size); + $binary_data = pack('a'.$read_size, $buffer); + @fwrite($fp, $binary_data, $read_size); + $size -= $read_size; + } + + $binary_data = pack('VV', $header['crc'], $header['size']); + fwrite($fp, $binary_data,8); + fclose($fp); + + $gzp = @gzopen($to.$header['filename'].'.gz','rb'); + if(!$gzp){ + @gzclose($gzp); + @unlink($to.$header['filename']); + die("Archive is compressed whereas ZLIB is not enabled."); + } + $fp = @fopen($to.$header['filename'],'wb'); + if(!$fp) return(-1); + $size = $header['size']; + + while ($size != 0) { + $read_size = ($size < 2048 ? $size : 2048); + $buffer = gzread($gzp, $read_size); + $binary_data = pack('a'.$read_size, $buffer); + @fwrite($fp, $binary_data, $read_size); + $size -= $read_size; + } + fclose($fp); + gzclose($gzp); + + touch($to.$header['filename'], $header['mtime']); + @unlink($to.$header['filename'].'.gz'); + } + } + return true; + } + + /** + * centralize mkdir calls and use dokuwiki io functions + * + * @author Christopher Smith <chris@jalakai.co.uk> + */ + function _mkdir($d) { + return io_mkdir_p($d); + } + + + function ExtractStr($zn, $name) { + $ok = 0; + $zip = @fopen($zn,'rb'); + if(!$zip) return(null); + $cdir = $this->ReadCentralDir($zip,$zn); + $pos_entry = $cdir['offset']; + + for ($i=0; $i<$cdir['entries']; $i++) { + @fseek($zip, $pos_entry); + $header = $this->ReadCentralFileHeaders($zip); + $header['index'] = $i; + $pos_entry = ftell($zip); + @rewind($zip); + fseek($zip, $header['offset']); + if ($name == $header['stored_filename'] || $name == $header['filename']) { + $str = $this->ExtractStrFile($header, $zip); + fclose($zip); + return $str; + } + + } + fclose($zip); + return null; } - $header['stored_filename'] = $header['filename']; - $header['status'] = 'ok'; - if (substr($header['filename'], -1) == '/') - $header['external'] = 0x41FF0010; - return $header; - } - - function ReadCentralDir($zip,$zip_name) - { - $size = filesize($zip_name); - if ($size < 277) $maximum_size = $size; - else $maximum_size=277; - - @fseek($zip, $size-$maximum_size); - $pos = ftell($zip); $bytes = 0x00000000; - - while ($pos < $size) - { - $byte = @fread($zip, 1); - $bytes=(($bytes << 8) & 0xFFFFFFFF) | Ord($byte); - if ($bytes == 0x504b0506){ $pos++; break; } $pos++; - } - - $data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', - fread($zip, 18)); - - if ($data['comment_size'] != 0) - $centd['comment'] = fread($zip, $data['comment_size']); - else $centd['comment'] = ''; $centd['entries'] = $data['entries']; - $centd['disk_entries'] = $data['disk_entries']; - $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start']; - $centd['size'] = $data['size']; $centd['disk'] = $data['disk']; - return $centd; - } - - function ExtractFile($header,$to,$zip) - { - $header = $this->readfileheader($zip, $header); - - if(substr($to,-1)!="/") $to.="/"; - if(substr($header['filename'],-1)=="/") - { -// @mkdir($to.$header['filename']); --CS - $this->_mkdir($to.$header['filename']); //-- CS - return +2; - } - -// $pth = explode("/",dirname($header['filename'])); -// for($i=0,$tmp="";isset($pth[$i]);$i++){ -// if(!$pth[$i]) continue; -// if(!is_dir($to.$tmp.$pth[$i])) @mkdir($to.$pth[$i],0777); -// $tmp.=$pth[$i]."/"; -// } - if (!$this->_mkdir($to.dirname($header['filename']))) return (-1); //--CS - - if (!array_key_exists("external", $header) || (!($header['external']==0x41FF0010)&&!($header['external']==16))) - { - if ($header['compression']==0) - { - $fp = @fopen($to.$header['filename'], 'wb'); - if(!$fp) return(-1); - $size = $header['compressed_size']; - - while ($size != 0) - { - $read_size = ($size < 2048 ? $size : 2048); - $buffer = fread($zip, $read_size); - $binary_data = pack('a'.$read_size, $buffer); - @fwrite($fp, $binary_data, $read_size); - $size -= $read_size; + + function ExtractStrFile($header,$zip) { + $hdr = $this->readfileheader($zip); + $binary_data = ''; + if (!($header['external']==0x41FF0010) && !($header['external']==16)) { + if ($header['compression']==0) { + while ($size != 0) { + $read_size = ($size < 2048 ? $size : 2048); + $buffer = fread($zip, $read_size); + $binary_data .= pack('a'.$read_size, $buffer); + $size -= $read_size; + } + return $binary_data; + } else { + $size = $header['compressed_size']; + if ($size == 0) { + return ''; + } + //Just in case + if ($size > ($this->_ret_bytes(ini_get('memory_limit'))/2)) { + die("Compressed file is to huge to be uncompress in memory."); + } + while ($size != 0) + { + $read_size = ($size < 2048 ? $size : 2048); + $buffer = fread($zip, $read_size); + $binary_data .= pack('a'.$read_size, $buffer); + $size -= $read_size; + } + $str = gzinflate($binary_data, $header['size']); + if ($header['crc'] == crc32($str)) { + return $str; + } else { + die("Crc Error"); + } + } + } + return null; } - fclose($fp); - touch($to.$header['filename'], $header['mtime']); - - }else{ - if (!is_dir(dirname($to.$header['filename']))) $this->_mkdir(dirname($to.$header['filename'])); //-CS - $fp = fopen($to.$header['filename'].'.gz','wb'); - if(!$fp) return(-1); - $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), - Chr(0x00), time(), Chr(0x00), Chr(3)); - - fwrite($fp, $binary_data, 10); - $size = $header['compressed_size']; - - while ($size != 0) - { - $read_size = ($size < 1024 ? $size : 1024); - $buffer = fread($zip, $read_size); - $binary_data = pack('a'.$read_size, $buffer); - @fwrite($fp, $binary_data, $read_size); - $size -= $read_size; - } - - $binary_data = pack('VV', $header['crc'], $header['size']); - fwrite($fp, $binary_data,8); fclose($fp); - - $gzp = @gzopen($to.$header['filename'].'.gz','rb'); - if(!$gzp){ - @gzclose($gzp); @unlink($to.$header['filename']); - die("Archive is compressed whereas ZLIB is not enabled."); + + function _ret_bytes($val) { + $val = trim($val); + $last = $val{strlen($val)-1}; + switch($last) { + case 'k': + case 'K': + return (int) $val * 1024; + break; + case 'm': + case 'M': + return (int) $val * 1048576; + break; + default: + return $val; + } } - $fp = @fopen($to.$header['filename'],'wb'); - if(!$fp) return(-1); - $size = $header['size']; - - while ($size != 0) - { - $read_size = ($size < 2048 ? $size : 2048); - $buffer = gzread($gzp, $read_size); - $binary_data = pack('a'.$read_size, $buffer); - @fwrite($fp, $binary_data, $read_size); - $size -= $read_size; - } - fclose($fp); gzclose($gzp); - - touch($to.$header['filename'], $header['mtime']); - @unlink($to.$header['filename'].'.gz'); - - }} - return true; - } - - //--CS start - // centralize mkdir calls and use dokuwiki io functions - function _mkdir($d) { - return io_mkdir_p($d); - } - //--CS end - - - function ExtractStr($zn, $name) { - $ok = 0; - $zip = @fopen($zn,'rb'); - if(!$zip) return(NULL); - $cdir = $this->ReadCentralDir($zip,$zn); - $pos_entry = $cdir['offset']; - - for ($i=0; $i<$cdir['entries']; $i++) - { - @fseek($zip, $pos_entry); - $header = $this->ReadCentralFileHeaders($zip); - $header['index'] = $i; - $pos_entry = ftell($zip); - @rewind($zip); - fseek($zip, $header['offset']); - if ($name == $header['stored_filename'] || $name == $header['filename']) { - $str = $this->ExtractStrFile($header, $zip); - fclose($zip); - return $str; - } - - } - fclose($zip); - return null; - } - - function ExtractStrFile($header,$zip) { - $hdr = $this->readfileheader($zip); - $binary_data = ''; - if (!($header['external']==0x41FF0010) && !($header['external']==16)) - { - if ($header['compression']==0) - { - while ($size != 0) - { - $read_size = ($size < 2048 ? $size : 2048); - $buffer = fread($zip, $read_size); - $binary_data .= pack('a'.$read_size, $buffer); - $size -= $read_size; - } - return $binary_data; - } else { - $size = $header['compressed_size']; - if ($size == 0) { - return ''; - } - //Just in case - if ($size > ($this->_ret_bytes(ini_get('memory_limit'))/2)) { - die("Compressed file is to huge to be uncompress in memory."); - } - while ($size != 0) - { - $read_size = ($size < 2048 ? $size : 2048); - $buffer = fread($zip, $read_size); - $binary_data .= pack('a'.$read_size, $buffer); - $size -= $read_size; - } - $str = gzinflate($binary_data, $header['size']); - if ($header['crc'] == crc32($str)) { - return $str; - } else { - die("Crc Error"); - } - } - } - return NULL; - } - - function _ret_bytes($val) { - $val = trim($val); - $last = $val{strlen($val)-1}; - switch($last) { - case 'k': - case 'K': - return (int) $val * 1024; - break; - case 'm': - case 'M': - return (int) $val * 1048576; - break; - default: - return $val; - } - } } diff --git a/inc/blowfish.php b/inc/blowfish.php index 42e3a589a..bcf5804a2 100644 --- a/inc/blowfish.php +++ b/inc/blowfish.php @@ -299,8 +299,7 @@ class Horde_Cipher_blowfish * * @param String $key The key to use */ - function setKey($key) - { + function setKey($key) { $key = $this->_formatKey($key); $keyPos = $keyXor = 0; @@ -318,37 +317,37 @@ class Horde_Cipher_blowfish $encZero = array('L' => 0, 'R' => 0); for ($i = 0; $i + 1 < $iMax; $i += 2) { - $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); - $this->p[$i] = $encZero['L']; - $this->p[$i + 1] = $encZero['R']; + $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); + $this->p[$i] = $encZero['L']; + $this->p[$i + 1] = $encZero['R']; } $iMax = count($this->s1); for ($i = 0; $i < $iMax; $i += 2) { - $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); - $this->s1[$i] = $encZero['L']; - $this->s1[$i + 1] = $encZero['R']; + $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); + $this->s1[$i] = $encZero['L']; + $this->s1[$i + 1] = $encZero['R']; } $iMax = count($this->s2); for ($i = 0; $i < $iMax; $i += 2) { - $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); - $this->s2[$i] = $encZero['L']; - $this->s2[$i + 1] = $encZero['R']; + $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); + $this->s2[$i] = $encZero['L']; + $this->s2[$i + 1] = $encZero['R']; } $iMax = count($this->s3); for ($i = 0; $i < $iMax; $i += 2) { - $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); - $this->s3[$i] = $encZero['L']; - $this->s3[$i + 1] = $encZero['R']; + $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); + $this->s3[$i] = $encZero['L']; + $this->s3[$i + 1] = $encZero['R']; } $iMax = count($this->s4); for ($i = 0; $i < $iMax; $i += 2) { - $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); - $this->s4[$i] = $encZero['L']; - $this->s4[$i + 1] = $encZero['R']; + $encZero = $this->_encryptBlock($encZero['L'], $encZero['R']); + $this->s4[$i] = $encZero['L']; + $this->s4[$i + 1] = $encZero['R']; } } @@ -361,8 +360,7 @@ class Horde_Cipher_blowfish * * @return String the encrypted output */ - function encryptBlock($block, $key = null) - { + function encryptBlock($block, $key = null) { if (!is_null($key)) { $this->setKey($key); } @@ -380,8 +378,7 @@ class Horde_Cipher_blowfish * * @return String The encrypted output. */ - function _encryptBlock($L, $R) - { + function _encryptBlock($L, $R) { $L ^= $this->p[0]; $R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L & 0x0ff]) ^ $this->p[1]; $L ^= ((($this->s1[($R >> 24) & 0xFF] + $this->s2[($R >> 16) & 0x0ff]) ^ $this->s3[($R >> 8) & 0x0ff]) + $this->s4[$R & 0x0ff]) ^ $this->p[2]; @@ -412,13 +409,12 @@ class Horde_Cipher_blowfish * * @return String the decrypted output */ - function decryptBlock($block, $key = null) - { + function decryptBlock($block, $key = null) { if (!is_null($key)) { $this->setKey($key); } -// change for phpMyAdmin + // change for phpMyAdmin $L = null; $R = null; @@ -429,7 +425,7 @@ class Horde_Cipher_blowfish if (isset($retarray[1])) { $R = $retarray[1]; } -// end change for phpMyAdmin + // end change for phpMyAdmin $L ^= $this->p[17]; $R ^= ((($this->s1[($L >> 24) & 0xFF] + $this->s2[($L >> 16) & 0x0ff]) ^ $this->s3[($L >> 8) & 0x0ff]) + $this->s4[$L & 0x0ff]) ^ $this->p[16]; @@ -458,8 +454,7 @@ class Horde_Cipher_blowfish * * @return array The key. */ - function _formatKey($key) - { + function _formatKey($key) { return array_values(unpack('C*', $key)); } @@ -478,8 +473,7 @@ class Horde_Cipher_blowfish * * @author lem9 */ -function PMA_blowfish_encrypt($data, $secret) -{ +function PMA_blowfish_encrypt($data, $secret) { $pma_cipher = new Horde_Cipher_blowfish; $encrypt = ''; @@ -508,8 +502,7 @@ function PMA_blowfish_encrypt($data, $secret) * * @author lem9 */ -function PMA_blowfish_decrypt($encdata, $secret) -{ +function PMA_blowfish_decrypt($encdata, $secret) { $pma_cipher = new Horde_Cipher_blowfish; $decrypt = ''; $data = base64_decode($encdata); diff --git a/inc/feedcreator.class.php b/inc/feedcreator.class.php index 86113e8c3..e7b8d7afc 100644 --- a/inc/feedcreator.class.php +++ b/inc/feedcreator.class.php @@ -336,7 +336,7 @@ class UniversalFeedCreator extends FeedCreator { } } - function _sendMIME($format) { + function _sendMIME() { header('Content-Type: '.$this->contentType.'; charset='.$this->encoding, true); } @@ -369,35 +369,35 @@ class UniversalFeedCreator extends FeedCreator { } - /** - * Turns on caching and checks if there is a recent version of this feed in the cache. - * If there is, an HTTP redirect header is sent. - * To effectively use caching, you should create the FeedCreator object and call this method - * before anything else, especially before you do the time consuming task to build the feed - * (web fetching, for example). - * - * @param string format format the feed should comply to. Valid values are: - * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". - * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). - * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) - */ - function useCached($format="RSS0.91", $filename="", $timeout=3600) { - $this->_setFormat($format); - $this->_feed->useCached($filename, $timeout); - } + /** + * Turns on caching and checks if there is a recent version of this feed in the cache. + * If there is, an HTTP redirect header is sent. + * To effectively use caching, you should create the FeedCreator object and call this method + * before anything else, especially before you do the time consuming task to build the feed + * (web fetching, for example). + * + * @param string format format the feed should comply to. Valid values are: + * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". + * @param filename string optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()). + * @param timeout int optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour) + */ + function useCached($format="RSS0.91", $filename="", $timeout=3600) { + $this->_setFormat($format); + $this->_feed->useCached($filename, $timeout); + } - /** - * Outputs feed to the browser - needed for on-the-fly feed generation (like it is done in WordPress, etc.) - * - * @param format string format the feed should comply to. Valid values are: - * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". - */ - function outputFeed($format='RSS0.91') { + /** + * Outputs feed to the browser - needed for on-the-fly feed generation (like it is done in WordPress, etc.) + * + * @param format string format the feed should comply to. Valid values are: + * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3". + */ + function outputFeed($format='RSS0.91') { $this->_setFormat($format); - $this->_sendMIME($format); + $this->_sendMIME(); $this->_feed->outputFeed(); - } + } } @@ -794,7 +794,8 @@ class RSSCreator10 extends FeedCreator { $feed.= " <dc:date>".htmlspecialchars($now->iso8601())."</dc:date>\n"; $feed.= " <items>\n"; $feed.= " <rdf:Seq>\n"; - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <rdf:li rdf:resource=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; } $feed.= " </rdf:Seq>\n"; @@ -809,7 +810,8 @@ class RSSCreator10 extends FeedCreator { } $feed.= $this->_createAdditionalElements($this->additionalElements, " "); - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n"; //$feed.= " <dc:type>Posting</dc:type>\n"; $feed.= " <dc:format>text/html</dc:format>\n"; @@ -940,7 +942,8 @@ class RSSCreator091 extends FeedCreator { } $feed.= $this->_createAdditionalElements($this->additionalElements, " "); - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <item>\n"; $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n"; $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; @@ -968,7 +971,7 @@ class RSSCreator091 extends FeedCreator { $feed.= " <comments>".htmlspecialchars($this->items[$i]->comments)."</comments>\n"; } if ($this->items[$i]->date!="") { - $itemDate = new FeedDate($this->items[$i]->date); + $itemDate = new FeedDate($this->items[$i]->date); $feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n"; } if ($this->items[$i]->guid!="") { @@ -976,18 +979,15 @@ class RSSCreator091 extends FeedCreator { } $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); - if ($this->RSSVersion == "2.0" && $this->items[$i]->enclosure != NULL) - { - $feed.= " <enclosure url=\""; - $feed.= $this->items[$i]->enclosure->url; - $feed.= "\" length=\""; - $feed.= $this->items[$i]->enclosure->length; - $feed.= "\" type=\""; - $feed.= $this->items[$i]->enclosure->type; - $feed.= "\"/>\n"; - } - - + if ($this->RSSVersion == "2.0" && $this->items[$i]->enclosure != null) { + $feed.= " <enclosure url=\""; + $feed.= $this->items[$i]->enclosure->url; + $feed.= "\" length=\""; + $feed.= $this->items[$i]->enclosure->length; + $feed.= "\" type=\""; + $feed.= $this->items[$i]->enclosure->type; + $feed.= "\"/>\n"; + } $feed.= " </item>\n"; } @@ -1038,7 +1038,8 @@ class PIECreator01 extends FeedCreator { $this->truncSize = 500; $feed.= " <subtitle>".$this->getDescription()."</subtitle>\n"; $feed.= " <link>".$this->link."</link>\n"; - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <entry>\n"; $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n"; $feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n"; @@ -1081,7 +1082,7 @@ class PIECreator01 extends FeedCreator { * @since 1.7.2-mod (modified) * @author Mohammad Hafiz Ismail (mypapit@gmail.com) */ - class AtomCreator10 extends FeedCreator { +class AtomCreator10 extends FeedCreator { function AtomCreator10() { $this->contentType = "application/atom+xml"; @@ -1114,7 +1115,8 @@ class PIECreator01 extends FeedCreator { $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; $feed.= "<link rel=\"self\" type=\"application/atom+xml\" href=\"". $this->syndicationURL . "\" />\n"; $feed.= $this->_createAdditionalElements($this->additionalElements, " "); - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <entry>\n"; $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; @@ -1134,8 +1136,8 @@ class PIECreator01 extends FeedCreator { if ($this->items[$i]->description!="") { $feed.= " <summary>".htmlspecialchars($this->items[$i]->description)."</summary>\n"; } - if ($this->items[$i]->enclosure != NULL) { - $feed.=" <link rel=\"enclosure\" href=\"". $this->items[$i]->enclosure->url ."\" type=\"". $this->items[$i]->enclosure->type."\" length=\"". $this->items[$i]->enclosure->length . "\" />\n"; + if ($this->items[$i]->enclosure != null) { + $feed.=" <link rel=\"enclosure\" href=\"". $this->items[$i]->enclosure->url ."\" type=\"". $this->items[$i]->enclosure->type."\" length=\"". $this->items[$i]->enclosure->length . "\" />\n"; } $feed.= " </entry>\n"; } @@ -1195,7 +1197,8 @@ class AtomCreator03 extends FeedCreator { } $feed.= " <generator>".FEEDCREATOR_VERSION."</generator>\n"; $feed.= $this->_createAdditionalElements($this->additionalElements, " "); - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { $feed.= " <entry>\n"; $feed.= " <title>".htmlspecialchars(strip_tags($this->items[$i]->title))."</title>\n"; $feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->items[$i]->link)."\"/>\n"; @@ -1254,7 +1257,8 @@ class MBOXCreator extends FeedCreator { if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only $c = "=20"; } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required - $h2 = floor($dec/16); $h1 = floor($dec%16); + $h2 = floor($dec/16); + $h1 = floor($dec%16); $c = $escape.$hex["$h2"].$hex["$h1"]; } if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted @@ -1274,7 +1278,8 @@ class MBOXCreator extends FeedCreator { * @return string the feed's complete text */ function createFeed() { - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { if ($this->items[$i]->author!="") { $from = $this->items[$i]->author; } else { @@ -1347,7 +1352,8 @@ class OPMLCreator extends FeedCreator { } $feed.= " </head>\n"; $feed.= " <body>\n"; - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0;$i<$icnt; $i++) { $feed.= " <outline type=\"rss\" "; $title = htmlspecialchars(strip_tags(strtr($this->items[$i]->title,"\n\r"," "))); $feed.= " title=\"".$title."\""; @@ -1468,7 +1474,8 @@ class HTMLCreator extends FeedCreator { $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>"; } - for ($i=0;$i<count($this->items);$i++) { + $icnt = count($this->items); + for ($i=0; $i<$icnt; $i++) { if ($this->separator and $i > 0) { $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>"; } @@ -1528,8 +1535,7 @@ class JSCreator extends HTMLCreator { * writes the javascript * @return string the scripts's complete text */ - function createFeed() - { + function createFeed() { $feed = parent::createFeed(); $feedArray = explode("\n",$feed); diff --git a/inc/template.php b/inc/template.php index 84fbda051..bab68e549 100644 --- a/inc/template.php +++ b/inc/template.php @@ -15,12 +15,12 @@ if(!defined('DOKU_INC')) die('meh.'); * @author Andreas Gohr <andi@splitbrain.org> */ function template($tpl){ - global $conf; + global $conf; - if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) - return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; + if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) + return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; - return DOKU_INC.'lib/tpl/default/'.$tpl; + return DOKU_INC.'lib/tpl/default/'.$tpl; } /** @@ -49,95 +49,95 @@ function tpl_content($prependTOC=true) { } function tpl_content_core(){ - global $ACT; - global $TEXT; - global $PRE; - global $SUF; - global $SUM; - global $IDX; - - switch($ACT){ - case 'show': - html_show(); - break; - case 'preview': - html_edit($TEXT); - html_show($TEXT); - break; - case 'recover': - html_edit($TEXT); - break; - case 'edit': - html_edit(); - break; - case 'draft': - html_draft(); - break; - case 'wordblock': - html_edit($TEXT,'wordblock'); - break; - case 'search': - html_search(); - break; - case 'revisions': - $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - html_revisions($first); - break; - case 'diff': - html_diff(); - break; - case 'recent': - if (is_array($_REQUEST['first'])) { - $_REQUEST['first'] = array_keys($_REQUEST['first']); - $_REQUEST['first'] = $_REQUEST['first'][0]; - } - $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - html_recent($first); - break; - case 'index': - html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? - break; - case 'backlink': - html_backlinks(); - break; - case 'conflict': - html_conflict(con($PRE,$TEXT,$SUF),$SUM); - html_diff(con($PRE,$TEXT,$SUF),false); - break; - case 'locked': - html_locked(); - html_edit(); - break; - case 'login': - html_login(); - break; - case 'register': - html_register(); - break; - case 'resendpwd': - html_resendpwd(); - break; - case 'denied': - print p_locale_xhtml('denied'); - break; - case 'profile' : - html_updateprofile(); - break; - case 'admin': - tpl_admin(); - break; - case 'subscribe': - tpl_subscribe(); - break; - default: - $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); - if ($evt->advise_before()) - msg("Failed to handle command: ".hsc($ACT),-1); - $evt->advise_after(); - unset($evt); - return false; - } - return true; + global $ACT; + global $TEXT; + global $PRE; + global $SUF; + global $SUM; + global $IDX; + + switch($ACT){ + case 'show': + html_show(); + break; + case 'preview': + html_edit($TEXT); + html_show($TEXT); + break; + case 'recover': + html_edit($TEXT); + break; + case 'edit': + html_edit(); + break; + case 'draft': + html_draft(); + break; + case 'wordblock': + html_edit($TEXT,'wordblock'); + break; + case 'search': + html_search(); + break; + case 'revisions': + $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; + html_revisions($first); + break; + case 'diff': + html_diff(); + break; + case 'recent': + if (is_array($_REQUEST['first'])) { + $_REQUEST['first'] = array_keys($_REQUEST['first']); + $_REQUEST['first'] = $_REQUEST['first'][0]; + } + $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; + html_recent($first); + break; + case 'index': + html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? + break; + case 'backlink': + html_backlinks(); + break; + case 'conflict': + html_conflict(con($PRE,$TEXT,$SUF),$SUM); + html_diff(con($PRE,$TEXT,$SUF),false); + break; + case 'locked': + html_locked(); + html_edit(); + break; + case 'login': + html_login(); + break; + case 'register': + html_register(); + break; + case 'resendpwd': + html_resendpwd(); + break; + case 'denied': + print p_locale_xhtml('denied'); + break; + case 'profile' : + html_updateprofile(); + break; + case 'admin': + tpl_admin(); + break; + case 'subscribe': + tpl_subscribe(); + break; + default: + $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); + if ($evt->advise_before()) + msg("Failed to handle command: ".hsc($ACT),-1); + $evt->advise_after(); + unset($evt); + return false; + } + return true; } /** @@ -183,13 +183,13 @@ function tpl_toc($return=false){ } } if ( ($plugin !== null) && - (!$plugin->forAdminOnly() || $INFO['isadmin']) ){ + (!$plugin->forAdminOnly() || $INFO['isadmin']) ){ $toc = $plugin->getTOC(); $TOC = $toc; // avoid later rebuild } } - trigger_event('TPL_TOC_RENDER', $toc, NULL, false); + trigger_event('TPL_TOC_RENDER', $toc, null, false); $html = html_TOC($toc); if($return) return $html; echo $html; @@ -210,8 +210,8 @@ function tpl_admin(){ if (in_array($_REQUEST['page'], $pluginlist)) { - // attempt to load the plugin - $plugin =& plugin_load('admin',$_REQUEST['page']); + // attempt to load the plugin + $plugin =& plugin_load('admin',$_REQUEST['page']); } } @@ -240,130 +240,129 @@ function tpl_admin(){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_metaheaders($alt=true){ - global $ID; - global $REV; - global $INFO; - global $JSINFO; - global $ACT; - global $QUERY; - global $lang; - global $conf; - $it=2; - - // prepare the head array - $head = array(); - - // prepare seed for js and css - $tseed = 0; - $depends = getConfigFiles('main'); - foreach($depends as $f) { - $time = @filemtime($f); - if($time > $tseed) $tseed = $time; - } - - // the usual stuff - $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() ); - $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', - 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); - $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); - if(actionOK('index')){ - $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), - 'title'=>$lang['btn_index'] ); - } - - if($alt){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php'); - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Current Namespace', - 'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']); - if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){ - $head['link'][] = array( 'rel'=>'edit', - 'title'=>$lang['btn_edit'], - 'href'=> wl($ID,'do=edit',false,'&')); - } + global $ID; + global $REV; + global $INFO; + global $JSINFO; + global $ACT; + global $QUERY; + global $lang; + global $conf; + $it=2; + + // prepare the head array + $head = array(); - if($ACT == 'search'){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Search Result', - 'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY); + // prepare seed for js and css + $tseed = 0; + $depends = getConfigFiles('main'); + foreach($depends as $f) { + $time = @filemtime($f); + if($time > $tseed) $tseed = $time; } - if(actionOK('export_xhtml')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML', - 'href'=>exportlink($ID, 'xhtml', '', false, '&')); + // the usual stuff + $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() ); + $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', + 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); + $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); + if(actionOK('index')){ + $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), + 'title'=>$lang['btn_index'] ); } - if(actionOK('export_raw')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup', - 'href'=>exportlink($ID, 'raw', '', false, '&')); + if($alt){ + $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', + 'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php'); + $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', + 'title'=>'Current Namespace', + 'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']); + if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){ + $head['link'][] = array( 'rel'=>'edit', + 'title'=>$lang['btn_edit'], + 'href'=> wl($ID,'do=edit',false,'&')); + } + + if($ACT == 'search'){ + $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', + 'title'=>'Search Result', + 'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY); + } + + if(actionOK('export_xhtml')){ + $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML', + 'href'=>exportlink($ID, 'xhtml', '', false, '&')); + } + + if(actionOK('export_raw')){ + $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup', + 'href'=>exportlink($ID, 'raw', '', false, '&')); + } } - } - // setup robot tags apropriate for different modes - if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ - if($INFO['exists']){ - //delay indexing: - if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ + // setup robot tags apropriate for different modes + if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ + if($INFO['exists']){ + //delay indexing: + if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ + $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); + }else{ + $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); + } + $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') ); + }else{ + $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow'); + } + }elseif(defined('DOKU_MEDIADETAIL')){ $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); - } - $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') ); }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow'); + $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); } - }elseif(defined('DOKU_MEDIADETAIL')){ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); - } - - // set metadata - if($ACT == 'show' || $ACT=='export_xhtml'){ - // date of modification - if($REV){ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV)); - }else{ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod'])); + + // set metadata + if($ACT == 'show' || $ACT=='export_xhtml'){ + // date of modification + if($REV){ + $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV)); + }else{ + $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod'])); + } + + // keywords (explicit or implicit) + if(!empty($INFO['meta']['subject'])){ + $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject'])); + }else{ + $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID)); + } } - // keywords (explicit or implicit) - if(!empty($INFO['meta']['subject'])){ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject'])); - }else{ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID)); + // load stylesheets + $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css', + 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed); + $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css', + 'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed); + $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css', + 'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed); + + // make $INFO and other vars available to JavaScripts + require_once(DOKU_INC.'inc/JSON.php'); + $json = new JSON(); + $script = "var NS='".$INFO['namespace']."';"; + if($conf['useacl'] && $_SERVER['REMOTE_USER']){ + require_once(DOKU_INC.'inc/toolbar.php'); + $script .= "var SIG='".toolbar_signature()."';"; } - } - - // load stylesheets - $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed); - $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed); - $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed); - - // make $INFO and other vars available to JavaScripts - require_once(DOKU_INC.'inc/JSON.php'); - $json = new JSON(); - $script = "var NS='".$INFO['namespace']."';"; - if($conf['useacl'] && $_SERVER['REMOTE_USER']){ - require_once(DOKU_INC.'inc/toolbar.php'); - $script .= "var SIG='".toolbar_signature()."';"; - } - $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; - $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', - '_data'=> $script); - - // load external javascript - $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'', - 'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed); - - - // trigger event here - trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); - return true; + $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; + $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', + '_data'=> $script); + + // load external javascript + $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'', + 'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed); + + // trigger event here + trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); + return true; } /** @@ -379,22 +378,22 @@ function tpl_metaheaders($alt=true){ * @author Andreas Gohr <andi@splitbrain.org> */ function _tpl_metaheaders_action($data){ - foreach($data as $tag => $inst){ - foreach($inst as $attr){ - echo '<',$tag,' ',buildAttributes($attr); - if(isset($attr['_data']) || $tag == 'script'){ - if($tag == 'script' && $attr['_data']) - $attr['_data'] = "<!--//--><![CDATA[//><!--\n". - $attr['_data']. - "\n//--><!]]>"; - - echo '>',$attr['_data'],'</',$tag,'>'; - }else{ - echo '/>'; - } - echo "\n"; + foreach($data as $tag => $inst){ + foreach($inst as $attr){ + echo '<',$tag,' ',buildAttributes($attr); + if(isset($attr['_data']) || $tag == 'script'){ + if($tag == 'script' && $attr['_data']) + $attr['_data'] = "<!--//--><![CDATA[//><!--\n". + $attr['_data']. + "\n//--><!]]>"; + + echo '>',$attr['_data'],'</',$tag,'>'; + }else{ + echo '/>'; + } + echo "\n"; + } } - } } /** @@ -405,12 +404,12 @@ function _tpl_metaheaders_action($data){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_link($url,$name,$more='',$return=false){ - $out = '<a href="'.$url.'" '; - if ($more) $out .= ' '.$more; - $out .= ">$name</a>"; - if ($return) return $out; - print $out; - return true; + $out = '<a href="'.$url.'" '; + if ($more) $out .= ' '.$more; + $out .= ">$name</a>"; + if ($return) return $out; + print $out; + return true; } /** @@ -420,9 +419,9 @@ function tpl_link($url,$name,$more='',$return=false){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function tpl_pagelink($id,$name=NULL){ - print html_wikilink($id,$name); - return true; +function tpl_pagelink($id,$name=null){ + print html_wikilink($id,$name); + return true; } /** @@ -434,16 +433,16 @@ function tpl_pagelink($id,$name=NULL){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_getparent($id){ - global $conf; - $parent = getNS($id).':'; - resolve_pageid('',$parent,$exists); - if($parent == $id) { - $pos = strrpos (getNS($id),':'); - $parent = substr($parent,0,$pos).':'; + global $conf; + $parent = getNS($id).':'; resolve_pageid('',$parent,$exists); - if($parent == $id) return false; - } - return $parent; + if($parent == $id) { + $pos = strrpos (getNS($id),':'); + $parent = substr($parent,0,$pos).':'; + resolve_pageid('',$parent,$exists); + if($parent == $id) return false; + } + return $parent; } /** @@ -467,105 +466,105 @@ function tpl_getparent($id){ * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ function tpl_button($type,$return=false){ - global $ACT; - global $ID; - global $REV; - global $NS; - global $INFO; - global $conf; - global $auth; - - // check disabled actions and fix the badly named ones - $ctype = $type; - if($type == 'history') $ctype='revisions'; - if(!actionOK($ctype)) return false; - - $out = ''; - switch($type){ - case 'edit': - #most complicated type - we need to decide on current action - if($ACT == 'show' || $ACT == 'search'){ - if($INFO['writable']){ - if(!empty($INFO['draft'])){ - $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post'); - }else{ - if($INFO['exists']){ - $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); + global $ACT; + global $ID; + global $REV; + global $NS; + global $INFO; + global $conf; + global $auth; + + // check disabled actions and fix the badly named ones + $ctype = $type; + if($type == 'history') $ctype='revisions'; + if(!actionOK($ctype)) return false; + + $out = ''; + switch($type){ + case 'edit': + // most complicated type - we need to decide on current action + if($ACT == 'show' || $ACT == 'search'){ + if($INFO['writable']){ + if(!empty($INFO['draft'])){ + $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post'); + }else{ + if($INFO['exists']){ + $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); + }else{ + $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); + } + } + }else{ + if(!actionOK('source')) return false; //pseudo action + $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post'); + } }else{ - $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post'); + $out .= html_btn('show',$ID,'v',array('do' => 'show')); } - } - }else{ - if(!actionOK('source')) return false; //pseudo action - $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post'); - } - }else{ - $out .= html_btn('show',$ID,'v',array('do' => 'show')); - } - break; - case 'history': - if(actionOK('revisions')) - $out .= html_btn('revs',$ID,'o',array('do' => 'revisions')); - break; - case 'recent': - if(actionOK('recent')) - $out .= html_btn('recent',$ID,'r',array('do' => 'recent')); - break; - case 'index': - if(actionOK('index')) - $out .= html_btn('index',$ID,'x',array('do' => 'index')); - break; - case 'back': - if ($parent = tpl_getparent($ID)) { - $out .= html_btn('back',$parent,'b',array('do' => 'show')); - } - break; - case 'top': - $out .= html_topbtn(); - break; - case 'login': - if($conf['useacl'] && $auth){ - if(isset($_SERVER['REMOTE_USER'])){ - $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken())); - }else{ - $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken())); - } - } - break; - case 'admin': - if($INFO['ismanager']){ - $out .= html_btn('admin',$ID,'',array('do' => 'admin')); - } - break; - case 'revert': - if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ - $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())); - } - break; - case 'subscribe': - if ($conf['useacl'] && $auth && $ACT == 'show' && - $conf['subscribers'] && isset($_SERVER['REMOTE_USER']) && - actionOK('subscribe')) { - $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); - } - break; - case 'backlink': - if(actionOK('backlink')) - $out .= html_btn('backlink',$ID,'',array('do' => 'backlink')); - break; - case 'profile': - if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth && - $auth->canDo('Profile') && ($ACT!='profile')){ - $out .= html_btn('profile',$ID,'',array('do' => 'profile')); - } - break; - default: - $out .= '[unknown button type]'; - break; - } - if ($return) return $out; - print $out; - return $out ? true : false; + break; + case 'history': + if(actionOK('revisions')) + $out .= html_btn('revs',$ID,'o',array('do' => 'revisions')); + break; + case 'recent': + if(actionOK('recent')) + $out .= html_btn('recent',$ID,'r',array('do' => 'recent')); + break; + case 'index': + if(actionOK('index')) + $out .= html_btn('index',$ID,'x',array('do' => 'index')); + break; + case 'back': + if ($parent = tpl_getparent($ID)) { + $out .= html_btn('back',$parent,'b',array('do' => 'show')); + } + break; + case 'top': + $out .= html_topbtn(); + break; + case 'login': + if($conf['useacl'] && $auth){ + if(isset($_SERVER['REMOTE_USER'])){ + $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken())); + }else{ + $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken())); + } + } + break; + case 'admin': + if($INFO['ismanager']){ + $out .= html_btn('admin',$ID,'',array('do' => 'admin')); + } + break; + case 'revert': + if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ + $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())); + } + break; + case 'subscribe': + if ($conf['useacl'] && $auth && $ACT == 'show' && + $conf['subscribers'] && isset($_SERVER['REMOTE_USER']) && + actionOK('subscribe')) { + $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); + } + break; + case 'backlink': + if(actionOK('backlink')) + $out .= html_btn('backlink',$ID,'',array('do' => 'backlink')); + break; + case 'profile': + if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth && + $auth->canDo('Profile') && ($ACT!='profile')){ + $out .= html_btn('profile',$ID,'',array('do' => 'profile')); + } + break; + default: + $out .= '[unknown button type]'; + break; + } + if ($return) return $out; + print $out; + return $out ? true : false; } /** @@ -590,140 +589,140 @@ function tpl_button($type,$return=false){ * @see tpl_button */ function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ - global $ID; - global $INFO; - global $REV; - global $ACT; - global $conf; - global $lang; - global $auth; - - // check disabled actions and fix the badly named ones - $ctype = $type; - if($type == 'history') $ctype='revisions'; - if(!actionOK($ctype)) return false; - - $out = ''; - switch($type){ - case 'edit': - #most complicated type - we need to decide on current action - if($ACT == 'show' || $ACT == 'search'){ - if($INFO['writable']){ - if(!empty($INFO['draft'])) { - $out .= tpl_link(wl($ID,'do=draft'), - $pre.(($inner)?$inner:$lang['btn_draft']).$suf, - 'class="action edit" accesskey="e" rel="nofollow"',1); - } else { - if($INFO['exists']){ - $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), - $pre.(($inner)?$inner:$lang['btn_edit']).$suf, - 'class="action edit" accesskey="e" rel="nofollow"',1); + global $ID; + global $INFO; + global $REV; + global $ACT; + global $conf; + global $lang; + global $auth; + + // check disabled actions and fix the badly named ones + $ctype = $type; + if($type == 'history') $ctype='revisions'; + if(!actionOK($ctype)) return false; + + $out = ''; + switch($type){ + case 'edit': + // most complicated type - we need to decide on current action + if($ACT == 'show' || $ACT == 'search'){ + if($INFO['writable']){ + if(!empty($INFO['draft'])) { + $out .= tpl_link(wl($ID,'do=draft'), + $pre.(($inner)?$inner:$lang['btn_draft']).$suf, + 'class="action edit" accesskey="e" rel="nofollow"',1); + } else { + if($INFO['exists']){ + $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), + $pre.(($inner)?$inner:$lang['btn_edit']).$suf, + 'class="action edit" accesskey="e" rel="nofollow"',1); + }else{ + $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), + $pre.(($inner)?$inner:$lang['btn_create']).$suf, + 'class="action create" accesskey="e" rel="nofollow"',1); + } + } + }else{ + if(actionOK('source')) //pseudo action + $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), + $pre.(($inner)?$inner:$lang['btn_source']).$suf, + 'class="action source" accesskey="v" rel="nofollow"',1); + } }else{ - $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), - $pre.(($inner)?$inner:$lang['btn_create']).$suf, - 'class="action create" accesskey="e" rel="nofollow"',1); + $out .= tpl_link(wl($ID,'do=show'), + $pre.(($inner)?$inner:$lang['btn_show']).$suf, + 'class="action show" accesskey="v" rel="nofollow"',1); } - } - }else{ - if(actionOK('source')) //pseudo action - $out .= tpl_link(wl($ID,'do=edit&rev='.$REV), - $pre.(($inner)?$inner:$lang['btn_source']).$suf, - 'class="action source" accesskey="v" rel="nofollow"',1); - } - }else{ - $out .= tpl_link(wl($ID,'do=show'), - $pre.(($inner)?$inner:$lang['btn_show']).$suf, - 'class="action show" accesskey="v" rel="nofollow"',1); - } - break; - case 'history': - if(actionOK('revisions')) - $out .= tpl_link(wl($ID,'do=revisions'), - $pre.(($inner)?$inner:$lang['btn_revs']).$suf, - 'class="action revisions" accesskey="o" rel="nofollow"',1); - break; - case 'recent': - if(actionOK('recent')) - $out .= tpl_link(wl($ID,'do=recent'), - $pre.(($inner)?$inner:$lang['btn_recent']).$suf, - 'class="action recent" accesskey="r" rel="nofollow"',1); - break; - case 'index': - if(actionOK('index')) - $out .= tpl_link(wl($ID,'do=index'), - $pre.(($inner)?$inner:$lang['btn_index']).$suf, - 'class="action index" accesskey="x" rel="nofollow"',1); - break; - case 'top': - $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'. - $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>'; - break; - case 'back': - if ($parent = tpl_getparent($ID)) { - $out .= tpl_link(wl($parent,'do=show'), - $pre.(($inner)?$inner:$lang['btn_back']).$suf, - 'class="action back" accesskey="b" rel="nofollow"',1); - } - break; - case 'login': - if($conf['useacl'] && $auth){ - if($_SERVER['REMOTE_USER']){ - $out .= tpl_link(wl($ID,'do=logout&sectok='.getSecurityToken()), - $pre.(($inner)?$inner:$lang['btn_logout']).$suf, - 'class="action logout" rel="nofollow"',1); - }else{ - $out .= tpl_link(wl($ID,'do=login&sectok='.getSecurityToken()), - $pre.(($inner)?$inner:$lang['btn_login']).$suf, - 'class="action login" rel="nofollow"',1); - } - } - break; - case 'admin': - if($INFO['ismanager']){ - $out .= tpl_link(wl($ID,'do=admin'), - $pre.(($inner)?$inner:$lang['btn_admin']).$suf, - 'class="action admin" rel="nofollow"',1); - } - break; - case 'revert': - if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ - $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())), - $pre.(($inner)?$inner:$lang['btn_revert']).$suf, - 'class="action revert" rel="nofollow"',1); - } - break; - case 'subscribe': - case 'subscription': - if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']) { - if($_SERVER['REMOTE_USER']){ - if(actionOK('subscribe')) - $out .= tpl_link(wl($ID,'do=subscribe'), - $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf, - 'class="action subscribe" rel="nofollow"',1); - } - } - break; - case 'backlink': - if(actionOK('backlink')) - $out .= tpl_link(wl($ID,'do=backlink'), - $pre.(($inner)?$inner:$lang['btn_backlink']).$suf, - 'class="action backlink" rel="nofollow"',1); - break; - case 'profile': - if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && - $auth->canDo('Profile') && ($ACT!='profile')){ - $out .= tpl_link(wl($ID,'do=profile'), - $pre.(($inner)?$inner:$lang['btn_profile']).$suf, - 'class="action profile" rel="nofollow"',1); - } - break; - default: - $out .= '[unknown link type]'; - break; - } - if ($return) return $out; - print $out; - return $out ? true : false; + break; + case 'history': + if(actionOK('revisions')) + $out .= tpl_link(wl($ID,'do=revisions'), + $pre.(($inner)?$inner:$lang['btn_revs']).$suf, + 'class="action revisions" accesskey="o" rel="nofollow"',1); + break; + case 'recent': + if(actionOK('recent')) + $out .= tpl_link(wl($ID,'do=recent'), + $pre.(($inner)?$inner:$lang['btn_recent']).$suf, + 'class="action recent" accesskey="r" rel="nofollow"',1); + break; + case 'index': + if(actionOK('index')) + $out .= tpl_link(wl($ID,'do=index'), + $pre.(($inner)?$inner:$lang['btn_index']).$suf, + 'class="action index" accesskey="x" rel="nofollow"',1); + break; + case 'top': + $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'. + $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>'; + break; + case 'back': + if ($parent = tpl_getparent($ID)) { + $out .= tpl_link(wl($parent,'do=show'), + $pre.(($inner)?$inner:$lang['btn_back']).$suf, + 'class="action back" accesskey="b" rel="nofollow"',1); + } + break; + case 'login': + if($conf['useacl'] && $auth){ + if($_SERVER['REMOTE_USER']){ + $out .= tpl_link(wl($ID,'do=logout&sectok='.getSecurityToken()), + $pre.(($inner)?$inner:$lang['btn_logout']).$suf, + 'class="action logout" rel="nofollow"',1); + }else{ + $out .= tpl_link(wl($ID,'do=login&sectok='.getSecurityToken()), + $pre.(($inner)?$inner:$lang['btn_login']).$suf, + 'class="action login" rel="nofollow"',1); + } + } + break; + case 'admin': + if($INFO['ismanager']){ + $out .= tpl_link(wl($ID,'do=admin'), + $pre.(($inner)?$inner:$lang['btn_admin']).$suf, + 'class="action admin" rel="nofollow"',1); + } + break; + case 'revert': + if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ + $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())), + $pre.(($inner)?$inner:$lang['btn_revert']).$suf, + 'class="action revert" rel="nofollow"',1); + } + break; + case 'subscribe': + case 'subscription': + if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']) { + if($_SERVER['REMOTE_USER']){ + if(actionOK('subscribe')) + $out .= tpl_link(wl($ID,'do=subscribe'), + $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf, + 'class="action subscribe" rel="nofollow"',1); + } + } + break; + case 'backlink': + if(actionOK('backlink')) + $out .= tpl_link(wl($ID,'do=backlink'), + $pre.(($inner)?$inner:$lang['btn_backlink']).$suf, + 'class="action backlink" rel="nofollow"',1); + break; + case 'profile': + if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && + $auth->canDo('Profile') && ($ACT!='profile')){ + $out .= tpl_link(wl($ID,'do=profile'), + $pre.(($inner)?$inner:$lang['btn_profile']).$suf, + 'class="action profile" rel="nofollow"',1); + } + break; + default: + $out .= '[unknown link type]'; + break; + } + if ($return) return $out; + print $out; + return $out ? true : false; } /** @@ -755,23 +754,23 @@ function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_searchform($ajax=true,$autocomplete=true){ - global $lang; - global $ACT; - global $QUERY; - - // don't print the search form if search action has been disabled - if (!actionOk('search')) return false; - - print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; - print '<input type="hidden" name="do" value="search" />'; - print '<input type="text" '; - if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; - if(!$autocomplete) print 'autocomplete="off" '; - print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; - print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; - if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; - print '</div></form>'; - return true; + global $lang; + global $ACT; + global $QUERY; + + // don't print the search form if search action has been disabled + if (!actionOk('search')) return false; + + print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">'; + print '<input type="hidden" name="do" value="search" />'; + print '<input type="text" '; + if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" '; + if(!$autocomplete) print 'autocomplete="off" '; + print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />'; + print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />'; + if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>'; + print '</div></form>'; + return true; } /** @@ -780,34 +779,34 @@ function tpl_searchform($ajax=true,$autocomplete=true){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_breadcrumbs($sep='»'){ - global $lang; - global $conf; - - //check if enabled - if(!$conf['breadcrumbs']) return false; - - $crumbs = breadcrumbs(); //setup crumb trace - - //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups - if($lang['direction'] == 'rtl') { - $crumbs = array_reverse($crumbs,true); - $crumbs_sep = ' ‏<span class="bcsep">'.$sep.'</span>‏ '; - } else { - $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; - } - - //render crumbs, highlight the last one - print '<span class="bchead">'.$lang['breadcrumb'].':</span>'; - $last = count($crumbs); - $i = 0; - foreach ($crumbs as $id => $name){ - $i++; - echo $crumbs_sep; - if ($i == $last) print '<span class="curid">'; - tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"'); - if ($i == $last) print '</span>'; - } - return true; + global $lang; + global $conf; + + //check if enabled + if(!$conf['breadcrumbs']) return false; + + $crumbs = breadcrumbs(); //setup crumb trace + + //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups + if($lang['direction'] == 'rtl') { + $crumbs = array_reverse($crumbs,true); + $crumbs_sep = ' ‏<span class="bcsep">'.$sep.'</span>‏ '; + } else { + $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> '; + } + + //render crumbs, highlight the last one + print '<span class="bchead">'.$lang['breadcrumb'].':</span>'; + $last = count($crumbs); + $i = 0; + foreach ($crumbs as $id => $name){ + $i++; + echo $crumbs_sep; + if ($i == $last) print '<span class="curid">'; + tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"'); + if ($i == $last) print '</span>'; + } + return true; } /** @@ -823,59 +822,59 @@ function tpl_breadcrumbs($sep='»'){ * @todo May behave strangely in RTL languages */ function tpl_youarehere($sep=' » '){ - global $conf; - global $ID; - global $lang; - - // check if enabled - if(!$conf['youarehere']) return false; - - $parts = explode(':', $ID); - $count = count($parts); - - if($GLOBALS['ACT'] == 'search') - { - $parts = array($conf['start']); - $count = 1; - } - - echo '<span class="bchead">'.$lang['youarehere'].': </span>'; - - // always print the startpage - $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start']; - if(!$title) $title = $conf['start']; - tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"'); - - // print intermediate namespace links - $part = ''; - for($i=0; $i<$count - 1; $i++){ - $part .= $parts[$i].':'; - $page = $part; - resolve_pageid('',$page,$exists); - if ($page == $conf['start']) continue; // Skip startpage - - // output + global $conf; + global $ID; + global $lang; + + // check if enabled + if(!$conf['youarehere']) return false; + + $parts = explode(':', $ID); + $count = count($parts); + + if($GLOBALS['ACT'] == 'search') + { + $parts = array($conf['start']); + $count = 1; + } + + echo '<span class="bchead">'.$lang['youarehere'].': </span>'; + + // always print the startpage + $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start']; + if(!$title) $title = $conf['start']; + tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"'); + + // print intermediate namespace links + $part = ''; + for($i=0; $i<$count - 1; $i++){ + $part .= $parts[$i].':'; + $page = $part; + resolve_pageid('',$page,$exists); + if ($page == $conf['start']) continue; // Skip startpage + + // output + echo $sep; + if($exists){ + $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; + tpl_link(wl($page),hsc($title),'title="'.$page.'"'); + }else{ + tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); + } + } + + // print current page, skipping start page, skipping for namespace index + if(isset($page) && $page==$part.$parts[$i]) return; + $page = $part.$parts[$i]; + if($page == $conf['start']) return; echo $sep; - if($exists){ - $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; - tpl_link(wl($page),hsc($title),'title="'.$page.'"'); + if(page_exists($page)){ + $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; + tpl_link(wl($page),hsc($title),'title="'.$page.'"'); }else{ - tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); + tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); } - } - - // print current page, skipping start page, skipping for namespace index - if(isset($page) && $page==$part.$parts[$i]) return; - $page = $part.$parts[$i]; - if($page == $conf['start']) return; - echo $sep; - if(page_exists($page)){ - $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; - tpl_link(wl($page),hsc($title),'title="'.$page.'"'); - }else{ - tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"'); - } - return true; + return true; } /** @@ -887,98 +886,98 @@ function tpl_youarehere($sep=' » '){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_userinfo(){ - global $lang; - global $INFO; - if(isset($_SERVER['REMOTE_USER'])){ - print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')'; - return true; - } - return false; -} + global $lang; + global $INFO; + if(isset($_SERVER['REMOTE_USER'])){ + print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')'; + return true; + } + return false; + } -/** - * Print some info about the current page - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -function tpl_pageinfo($ret=false){ - global $conf; - global $lang; - global $INFO; - global $ID; - - // return if we are not allowed to view the page - if (!auth_quickaclcheck($ID)) { return false; } - - // prepare date and path - $fn = $INFO['filepath']; - if(!$conf['fullpath']){ - if($INFO['rev']){ - $fn = str_replace(fullpath($conf['olddir']).'/','',$fn); - }else{ - $fn = str_replace(fullpath($conf['datadir']).'/','',$fn); + /** + * Print some info about the current page + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function tpl_pageinfo($ret=false){ + global $conf; + global $lang; + global $INFO; + global $ID; + + // return if we are not allowed to view the page + if (!auth_quickaclcheck($ID)) { return false; } + + // prepare date and path + $fn = $INFO['filepath']; + if(!$conf['fullpath']){ + if($INFO['rev']){ + $fn = str_replace(fullpath($conf['olddir']).'/','',$fn); + }else{ + $fn = str_replace(fullpath($conf['datadir']).'/','',$fn); + } + } + $fn = utf8_decodeFN($fn); + $date = dformat($INFO['lastmod']); + + // print it + if($INFO['exists']){ + $out = ''; + $out .= $fn; + $out .= ' · '; + $out .= $lang['lastmod']; + $out .= ': '; + $out .= $date; + if($INFO['editor']){ + $out .= ' '.$lang['by'].' '; + $out .= editorinfo($INFO['editor']); + }else{ + $out .= ' ('.$lang['external_edit'].')'; + } + if($INFO['locked']){ + $out .= ' · '; + $out .= $lang['lockedby']; + $out .= ': '; + $out .= editorinfo($INFO['locked']); + } + if($ret){ + return $out; + }else{ + echo $out; + return true; + } + } + return false; + } + + /** + * Prints or returns the name of the given page (current one if none given). + * + * If useheading is enabled this will use the first headline else + * the given ID is used. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function tpl_pagetitle($id=null, $ret=false){ + global $conf; + if(is_null($id)){ + global $ID; + $id = $ID; } - } - $fn = utf8_decodeFN($fn); - $date = dformat($INFO['lastmod']); - // print it - if($INFO['exists']){ - $out = ''; - $out .= $fn; - $out .= ' · '; - $out .= $lang['lastmod']; - $out .= ': '; - $out .= $date; - if($INFO['editor']){ - $out .= ' '.$lang['by'].' '; - $out .= editorinfo($INFO['editor']); - }else{ - $out .= ' ('.$lang['external_edit'].')'; - } - if($INFO['locked']){ - $out .= ' · '; - $out .= $lang['lockedby']; - $out .= ': '; - $out .= editorinfo($INFO['locked']); + $name = $id; + if (useHeading('navigation')) { + $title = p_get_first_heading($id); + if ($title) $name = $title; } - if($ret){ - return $out; - }else{ - echo $out; + + if ($ret) { + return hsc($name); + } else { + print hsc($name); return true; } - } - return false; -} - -/** - * Prints or returns the name of the given page (current one if none given). - * - * If useheading is enabled this will use the first headline else - * the given ID is used. - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -function tpl_pagetitle($id=null, $ret=false){ - global $conf; - if(is_null($id)){ - global $ID; - $id = $ID; - } - - $name = $id; - if (useHeading('navigation')) { - $title = p_get_first_heading($id); - if ($title) $name = $title; - } - - if ($ret) { - return hsc($name); - } else { - print hsc($name); - return true; - } } /** @@ -996,17 +995,17 @@ function tpl_pagetitle($id=null, $ret=false){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_img_getTag($tags,$alt='',$src=null){ - // Init Exif Reader - global $SRC; + // Init Exif Reader + global $SRC; - if(is_null($src)) $src = $SRC; + if(is_null($src)) $src = $SRC; - static $meta = null; - if(is_null($meta)) $meta = new JpegMeta($src); - if($meta === false) return $alt; - $info = $meta->getField($tags); - if($info == false) return $alt; - return $info; + static $meta = null; + if(is_null($meta)) $meta = new JpegMeta($src); + if($meta === false) return $alt; + $info = $meta->getField($tags); + if($info == false) return $alt; + return $info; } /** @@ -1015,52 +1014,52 @@ function tpl_img_getTag($tags,$alt='',$src=null){ * Only allowed in: detail.php */ function tpl_img($maxwidth=0,$maxheight=0){ - global $IMG; - $w = tpl_img_getTag('File.Width'); - $h = tpl_img_getTag('File.Height'); - - //resize to given max values - $ratio = 1; - if($w >= $h){ - if($maxwidth && $w >= $maxwidth){ - $ratio = $maxwidth/$w; - }elseif($maxheight && $h > $maxheight){ - $ratio = $maxheight/$h; + global $IMG; + $w = tpl_img_getTag('File.Width'); + $h = tpl_img_getTag('File.Height'); + + //resize to given max values + $ratio = 1; + if($w >= $h){ + if($maxwidth && $w >= $maxwidth){ + $ratio = $maxwidth/$w; + }elseif($maxheight && $h > $maxheight){ + $ratio = $maxheight/$h; + } + }else{ + if($maxheight && $h >= $maxheight){ + $ratio = $maxheight/$h; + }elseif($maxwidth && $w > $maxwidth){ + $ratio = $maxwidth/$w; + } + } + if($ratio){ + $w = floor($ratio*$w); + $h = floor($ratio*$h); } - }else{ - if($maxheight && $h >= $maxheight){ - $ratio = $maxheight/$h; - }elseif($maxwidth && $w > $maxwidth){ - $ratio = $maxwidth/$w; + + //prepare URLs + $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); + $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); + + //prepare attributes + $alt=tpl_img_getTag('Simple.Title'); + $p = array(); + if($w) $p['width'] = $w; + if($h) $p['height'] = $h; + $p['class'] = 'img_detail'; + if($alt){ + $p['alt'] = $alt; + $p['title'] = $alt; + }else{ + $p['alt'] = ''; } - } - if($ratio){ - $w = floor($ratio*$w); - $h = floor($ratio*$h); - } - - //prepare URLs - $url=ml($IMG,array('cache'=>$_REQUEST['cache'])); - $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h)); - - //prepare attributes - $alt=tpl_img_getTag('Simple.Title'); - $p = array(); - if($w) $p['width'] = $w; - if($h) $p['height'] = $h; - $p['class'] = 'img_detail'; - if($alt){ - $p['alt'] = $alt; - $p['title'] = $alt; - }else{ - $p['alt'] = ''; - } - $p = buildAttributes($p); - - print '<a href="'.$url.'">'; - print '<img src="'.$src.'" '.$p.'/>'; - print '</a>'; - return true; + $p = buildAttributes($p); + + print '<a href="'.$url.'">'; + print '<img src="'.$src.'" '.$p.'/>'; + print '</a>'; + return true; } /** @@ -1071,21 +1070,21 @@ function tpl_img($maxwidth=0,$maxheight=0){ * template */ function tpl_indexerWebBug(){ - global $ID; - global $INFO; - if(!$INFO['exists']) return false; - - if(isHiddenPage($ID)) return false; //no need to index hidden pages - - $p = array(); - $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). - '&'.time(); - $p['width'] = 1; - $p['height'] = 1; - $p['alt'] = ''; - $att = buildAttributes($p); - print "<img $att />"; - return true; + global $ID; + global $INFO; + if(!$INFO['exists']) return false; + + if(isHiddenPage($ID)) return false; //no need to index hidden pages + + $p = array(); + $p['src'] = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID). + '&'.time(); + $p['width'] = 1; + $p['height'] = 1; + $p['alt'] = ''; + $att = buildAttributes($p); + print "<img $att />"; + return true; } // configuration methods @@ -1095,23 +1094,23 @@ function tpl_indexerWebBug(){ * use this function to access template configuration variables */ function tpl_getConf($id){ - global $conf; - global $tpl_configloaded; - - $tpl = $conf['template']; - - if (!$tpl_configloaded){ - $tconf = tpl_loadConfig(); - if ($tconf !== false){ - foreach ($tconf as $key => $value){ - if (isset($conf['tpl'][$tpl][$key])) continue; - $conf['tpl'][$tpl][$key] = $value; - } - $tpl_configloaded = true; + global $conf; + global $tpl_configloaded; + + $tpl = $conf['template']; + + if (!$tpl_configloaded){ + $tconf = tpl_loadConfig(); + if ($tconf !== false){ + foreach ($tconf as $key => $value){ + if (isset($conf['tpl'][$tpl][$key])) continue; + $conf['tpl'][$tpl][$key] = $value; + } + $tpl_configloaded = true; + } } - } - return $conf['tpl'][$tpl][$id]; + return $conf['tpl'][$tpl][$id]; } /** @@ -1121,15 +1120,15 @@ function tpl_getConf($id){ */ function tpl_loadConfig(){ - $file = DOKU_TPLINC.'/conf/default.php'; - $conf = array(); + $file = DOKU_TPLINC.'/conf/default.php'; + $conf = array(); - if (!@file_exists($file)) return false; + if (!@file_exists($file)) return false; - // load default config file - include($file); + // load default config file + include($file); - return $conf; + return $conf; } /** @@ -1146,50 +1145,50 @@ function tpl_loadConfig(){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_mediaContent($fromajax=false){ - global $IMG; - global $AUTH; - global $INUSE; - global $NS; - global $JUMPTO; - - if(is_array($_REQUEST['do'])){ - $do = array_shift(array_keys($_REQUEST['do'])); - }else{ - $do = $_REQUEST['do']; - } - if(in_array($do,array('save','cancel'))) $do = ''; - - if(!$do){ - if($_REQUEST['edit']){ - $do = 'metaform'; - }elseif(is_array($INUSE)){ - $do = 'filesinuse'; - }else{ - $do = 'filelist'; - } - } - - // output the content pane, wrapped in an event. - if(!$fromajax) ptln('<div id="media__content">'); - $data = array( 'do' => $do); - $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); - if ($evt->advise_before()) { - $do = $data['do']; - if($do == 'metaform'){ - media_metaform($IMG,$AUTH); - }elseif($do == 'filesinuse'){ - media_filesinuse($INUSE,$IMG); - }elseif($do == 'filelist'){ - media_filelist($NS,$AUTH,$JUMPTO); - }elseif($do == 'searchlist'){ - media_searchlist($_REQUEST['q'],$NS,$AUTH); + global $IMG; + global $AUTH; + global $INUSE; + global $NS; + global $JUMPTO; + + if(is_array($_REQUEST['do'])){ + $do = array_shift(array_keys($_REQUEST['do'])); }else{ - msg('Unknown action '.hsc($do),-1); + $do = $_REQUEST['do']; + } + if(in_array($do,array('save','cancel'))) $do = ''; + + if(!$do){ + if($_REQUEST['edit']){ + $do = 'metaform'; + }elseif(is_array($INUSE)){ + $do = 'filesinuse'; + }else{ + $do = 'filelist'; + } + } + + // output the content pane, wrapped in an event. + if(!$fromajax) ptln('<div id="media__content">'); + $data = array( 'do' => $do); + $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data); + if ($evt->advise_before()) { + $do = $data['do']; + if($do == 'metaform'){ + media_metaform($IMG,$AUTH); + }elseif($do == 'filesinuse'){ + media_filesinuse($INUSE,$IMG); + }elseif($do == 'filelist'){ + media_filelist($NS,$AUTH,$JUMPTO); + }elseif($do == 'searchlist'){ + media_searchlist($_REQUEST['q'],$NS,$AUTH); + }else{ + msg('Unknown action '.hsc($do),-1); + } } - } - $evt->advise_after(); - unset($evt); - if(!$fromajax) ptln('</div>'); + $evt->advise_after(); + unset($evt); + if(!$fromajax) ptln('</div>'); } @@ -1201,11 +1200,11 @@ function tpl_mediaContent($fromajax=false){ * @author Andreas Gohr <andi@splitbrain.org> */ function tpl_mediaTree(){ - global $NS; + global $NS; - ptln('<div id="media__tree">'); - media_nstree($NS); - ptln('</div>'); + ptln('<div id="media__tree">'); + media_nstree($NS); + ptln('</div>'); } @@ -1225,9 +1224,8 @@ function tpl_actiondropdown($empty='',$button='>'){ global $lang; global $auth; - echo '<form method="post" accept-charset="utf-8">'; #FIXME action - echo '<input type="hidden" name="id" value="'.$ID.'" />'; + echo '<input type="hidden" name="id" value="'.$ID.'" />'; if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />'; echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />'; @@ -1235,60 +1233,60 @@ function tpl_actiondropdown($empty='',$button='>'){ echo '<option value="">'.$empty.'</option>'; echo '<optgroup label=" — ">'; - // 'edit' - most complicated type, we need to decide on current action - if($ACT == 'show' || $ACT == 'search'){ - if($INFO['writable']){ - if(!empty($INFO['draft'])) { - echo '<option value="edit">'.$lang['btn_draft'].'</option>'; - } else { - if($INFO['exists']){ - echo '<option value="edit">'.$lang['btn_edit'].'</option>'; - }else{ - echo '<option value="edit">'.$lang['btn_create'].'</option>'; - } + // 'edit' - most complicated type, we need to decide on current action + if($ACT == 'show' || $ACT == 'search'){ + if($INFO['writable']){ + if(!empty($INFO['draft'])) { + echo '<option value="edit">'.$lang['btn_draft'].'</option>'; + } else { + if($INFO['exists']){ + echo '<option value="edit">'.$lang['btn_edit'].'</option>'; + }else{ + echo '<option value="edit">'.$lang['btn_create'].'</option>'; } - }else if(actionOK('source')) { //pseudo action - echo '<option value="edit">'.$lang['btn_source'].'</option>'; } - }else{ - echo '<option value="show">'.$lang['btn_show'].'</option>'; + }else if(actionOK('source')) { //pseudo action + echo '<option value="edit">'.$lang['btn_source'].'</option>'; } + }else{ + echo '<option value="show">'.$lang['btn_show'].'</option>'; + } - echo '<option value="revisions">'.$lang['btn_revs'].'</option>'; - if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ - echo '<option value="revert">'.$lang['btn_revert'].'</option>'; - } - echo '<option value="backlink">'.$lang['btn_backlink'].'</option>'; + echo '<option value="revisions">'.$lang['btn_revs'].'</option>'; + if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){ + echo '<option value="revert">'.$lang['btn_revert'].'</option>'; + } + echo '<option value="backlink">'.$lang['btn_backlink'].'</option>'; echo '</optgroup>'; echo '<optgroup label=" — ">'; - echo '<option value="recent">'.$lang['btn_recent'].'</option>'; - echo '<option value="index">'.$lang['btn_index'].'</option>'; + echo '<option value="recent">'.$lang['btn_recent'].'</option>'; + echo '<option value="index">'.$lang['btn_index'].'</option>'; echo '</optgroup>'; echo '<optgroup label=" — ">'; - if($conf['useacl'] && $auth){ - if($_SERVER['REMOTE_USER']){ - echo '<option value="logout">'.$lang['btn_logout'].'</option>'; - }else{ - echo '<option value="login">'.$lang['btn_login'].'</option>'; - } + if($conf['useacl'] && $auth){ + if($_SERVER['REMOTE_USER']){ + echo '<option value="logout">'.$lang['btn_logout'].'</option>'; + }else{ + echo '<option value="login">'.$lang['btn_login'].'</option>'; } + } - if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && - $auth->canDo('Profile') && ($ACT!='profile')){ - echo '<option value="profile">'.$lang['btn_profile'].'</option>'; - } + if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && + $auth->canDo('Profile') && ($ACT!='profile')){ + echo '<option value="profile">'.$lang['btn_profile'].'</option>'; + } - if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']){ - if($_SERVER['REMOTE_USER']){ - echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>'; - } + if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']){ + if($_SERVER['REMOTE_USER']){ + echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>'; } + } - if($INFO['ismanager']){ - echo '<option value="admin">'.$lang['btn_admin'].'</option>'; - } + if($INFO['ismanager']){ + echo '<option value="admin">'.$lang['btn_admin'].'</option>'; + } echo '</optgroup>'; echo '</select>'; @@ -1379,7 +1377,6 @@ function tpl_subscribe() { echo '<a href="'.wl($ID,array('do'=>'subscribe','sub_target'=>$sub['target'],'sub_style'=>$sub['style'],'sub_action'=>'unsubscribe')).'" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].'</a>'; - echo '</div></li>'; } echo '</ul>'; @@ -1391,14 +1388,14 @@ function tpl_subscribe() { echo '<div class="level2">'; $ns = getNS($ID).':'; $targets = array( - $ID => '<code class="page">'.prettyprint_id($ID).'</code>', - $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', - ); + $ID => '<code class="page">'.prettyprint_id($ID).'</code>', + $ns => '<code class="ns">'.prettyprint_id($ns).'</code>', + ); $styles = array( - 'every' => $lang['subscr_style_every'], - 'digest' => $lang['subscr_style_digest'], - 'list' => $lang['subscr_style_list'], - ); + 'every' => $lang['subscr_style_every'], + 'digest' => $lang['subscr_style_digest'], + 'list' => $lang['subscr_style_list'], + ); $form = new Doku_Form(array('id' => 'subscribe__form')); $form->startFieldset($lang['subscr_m_subscribe']); -- GitLab