Source for file Pel.php

Documentation is available at Pel.php

  1. <?php
  2.  
  3. /* PEL: PHP EXIF Library. A library with support for reading and
  4. * writing all EXIF headers in JPEG and TIFF images using PHP.
  5. *
  6. * Copyright (C) 2004 Martin Geisler <gimpster@users.sourceforge.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program in the file COPYING; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  21. * Boston, MA 02111-1307 USA
  22. */
  23.  
  24. /* Pel.php,v 1.14 2004/10/10 16:16:18 gimpster Exp */
  25.  
  26.  
  27. /**
  28. * Miscellaneous stuff for the overall behavior of PEL.
  29. *
  30. * @author Martin Geisler <gimpster@users.sourceforge.net>
  31. * @version 1.14
  32. * @date 2004/10/10 16:16:18
  33. * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  34. * License (GPL)
  35. * @package PEL
  36. */
  37.  
  38.  
  39. /* Initialize Gettext, if available. This must be done before any
  40. * part of PEL calls Pel::tra() or Pel::fmt() --- this is ensured if
  41. * every piece of code using those two functions require() this file.
  42. *
  43. * If Gettext is not available, wrapper functions will be created,
  44. * allowing PEL to function, but without any translations.
  45. *
  46. * The PEL translations are stored in './locale'. It is important to
  47. * use an absolute path here because the lookups will be relative to
  48. * the current directory. */
  49.  
  50. if (function_exists('dgettext')) {
  51. bindtextdomain('pel', dirname(__FILE__) . '/locale');
  52. } else {
  53.  
  54. /**
  55. * Lookup a message in a specific domain.
  56. *
  57. * This is just a stub which will return the message untranslated.
  58. *
  59. * @param string $domain the domain.
  60. *
  61. * @param string $str the message to be translated.
  62. *
  63. * @return string the untranslated message.
  64. */
  65. function dgettext($domain, $str) {
  66. return $str;
  67. }
  68. }
  69.  
  70.  
  71. /**
  72. * Class with miscellaneous static methods.
  73. *
  74. * This class will contain various methods that govern the overall
  75. * behavior of PEL.
  76. *
  77. * @author Martin Geisler <gimpster@users.sourceforge.net>
  78. * @package PEL
  79. */
  80. class Pel {
  81.  
  82. /**
  83. * Flag for controlling debug information.
  84. *
  85. * The methods producing debug information ({@link debug()} and
  86. * {@link warning()}) will only output something if this variable is
  87. * set to true.
  88. *
  89. * @var boolean
  90. */
  91. static $debug = false;
  92.  
  93. /**
  94. * Conditionally output debug information.
  95. *
  96. * This method works just like printf() except that it always
  97. * terminates the output with a newline, and that it only outputs
  98. * something if the PEL_DEBUG defined to some true value.
  99. *
  100. * @param string $format the format string.
  101. *
  102. * @param mixed $args,... any number of arguments can be given. The
  103. * arguments will be available for the format string as usual with
  104. * sprintf().
  105. */
  106. static function debug() {
  107. if (self::$debug) {
  108. $args = func_get_args();
  109. $str = array_shift($args);
  110. vprintf($str . "\n", $args);
  111. }
  112. }
  113.  
  114. /**
  115. * Conditionally output a warning.
  116. *
  117. * This method works just like printf() except that it prepends the
  118. * output with the string 'Warning: ', terminates the output with a
  119. * newline, and that it only outputs something if the PEL_DEBUG
  120. * defined to some true value.
  121. *
  122. * @param string $format the format string.
  123. *
  124. * @param mixed $args,... any number of arguments can be given. The
  125. * arguments will be available for the format string as usual with
  126. * sprintf().
  127. */
  128. static function warning() {
  129. if (self::$debug) {
  130. $args = func_get_args();
  131. $str = array_shift($args);
  132. vprintf('Warning: ' . $str . "\n", $args);
  133. }
  134. }
  135.  
  136.  
  137. /**
  138. * Translate a string.
  139. *
  140. * This static function will use Gettext to translate a string. By
  141. * always using this function for static string one is assured that
  142. * the translation will be taken from the correct text domain.
  143. * Dynamic strings should be passed to {@link fmt} instead.
  144. *
  145. * @param string the string that should be translated.
  146. *
  147. * @return string the translated string, or the original string if
  148. * no translation could be found.
  149. */
  150. static function tra($str) {
  151. return dgettext('pel', $str);
  152. }
  153.  
  154. /**
  155. * Translate and format a string.
  156. *
  157. * This static function will first use Gettext to translate a format
  158. * string, which will then have access to any extra arguments. By
  159. * always using this function for dynamic string one is assured that
  160. * the translation will be taken from the correct text domain. If
  161. * the string is static, use {@link tra} instead as it will be
  162. * faster.
  163. *
  164. * @param string $format the format string. This will be translated
  165. * before being used as a format string.
  166. *
  167. * @param mixed $args,... any number of arguments can be given. The
  168. * arguments will be available for the format string as usual with
  169. * sprintf().
  170. *
  171. * @return string the translated string, or the original string if
  172. * no translation could be found.
  173. */
  174. static function fmt() {
  175. $args = func_get_args();
  176. $str = array_shift($args);
  177. return vsprintf(dgettext('pel', $str), $args);
  178. }
  179.  
  180. }
  181.  
  182. ?>

SourceForge.net Logo Documentation generated on Sun, 10 Oct 2004 19:08:02 +0200 by phpDocumentor 1.3.0RC3