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.
  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.16 2005/02/10 21:22:44 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.16
  32. * @date 2005/02/10 21:22:44
  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. * Pretend to lookup a message in a specific domain.
  56. *
  57. * This is just a stub which will return the original message
  58. * untranslated. The function will only be defined if the Gettext
  59. * extension has not already defined it.
  60. *
  61. * @param string $domain the domain.
  62. *
  63. * @param string $str the message to be translated.
  64. *
  65. * @return string the original, untranslated message.
  66. */
  67. function dgettext($domain, $str) {
  68. return $str;
  69. }
  70. }
  71.  
  72.  
  73. /**
  74. * Class with miscellaneous static methods.
  75. *
  76. * This class will contain various methods that govern the overall
  77. * behavior of PEL.
  78. *
  79. * Debugging output from PEL can be turned on and off by assigning
  80. * true or false to {@link Pel::$debug}.
  81. *
  82. * @author Martin Geisler <gimpster@users.sourceforge.net>
  83. * @package PEL
  84. */
  85. class Pel {
  86.  
  87. /**
  88. * Flag for controlling debug information.
  89. *
  90. * The methods producing debug information ({@link debug()} and
  91. * {@link warning()}) will only output something if this variable is
  92. * set to true.
  93. *
  94. * @var boolean
  95. */
  96. static $debug = false;
  97.  
  98. /**
  99. * Conditionally output debug information.
  100. *
  101. * This method works just like printf() except that it always
  102. * terminates the output with a newline, and that it only outputs
  103. * something if the PEL_DEBUG defined to some true value.
  104. *
  105. * @param string $format the format string.
  106. *
  107. * @param mixed $args,... any number of arguments can be given. The
  108. * arguments will be available for the format string as usual with
  109. * sprintf().
  110. */
  111. static function debug() {
  112. if (self::$debug) {
  113. $args = func_get_args();
  114. $str = array_shift($args);
  115. vprintf($str . "\n", $args);
  116. }
  117. }
  118.  
  119. /**
  120. * Conditionally output a warning.
  121. *
  122. * This method works just like printf() except that it prepends the
  123. * output with the string 'Warning: ', terminates the output with a
  124. * newline, and that it only outputs something if the PEL_DEBUG
  125. * defined to some true value.
  126. *
  127. * @param string $format the format string.
  128. *
  129. * @param mixed $args,... any number of arguments can be given. The
  130. * arguments will be available for the format string as usual with
  131. * sprintf().
  132. */
  133. static function warning() {
  134. if (self::$debug) {
  135. $args = func_get_args();
  136. $str = array_shift($args);
  137. vprintf('Warning: ' . $str . "\n", $args);
  138. }
  139. }
  140.  
  141.  
  142. /**
  143. * Translate a string.
  144. *
  145. * This static function will use Gettext to translate a string. By
  146. * always using this function for static string one is assured that
  147. * the translation will be taken from the correct text domain.
  148. * Dynamic strings should be passed to {@link fmt} instead.
  149. *
  150. * @param string the string that should be translated.
  151. *
  152. * @return string the translated string, or the original string if
  153. * no translation could be found.
  154. */
  155. static function tra($str) {
  156. return dgettext('pel', $str);
  157. }
  158.  
  159. /**
  160. * Translate and format a string.
  161. *
  162. * This static function will first use Gettext to translate a format
  163. * string, which will then have access to any extra arguments. By
  164. * always using this function for dynamic string one is assured that
  165. * the translation will be taken from the correct text domain. If
  166. * the string is static, use {@link tra} instead as it will be
  167. * faster.
  168. *
  169. * @param string $format the format string. This will be translated
  170. * before being used as a format string.
  171. *
  172. * @param mixed $args,... any number of arguments can be given. The
  173. * arguments will be available for the format string as usual with
  174. * sprintf().
  175. *
  176. * @return string the translated string, or the original string if
  177. * no translation could be found.
  178. */
  179. static function fmt() {
  180. $args = func_get_args();
  181. $str = array_shift($args);
  182. return vsprintf(dgettext('pel', $str), $args);
  183. }
  184.  
  185. }
  186.  
  187. ?>

SourceForge.net Logo Documentation generated on Fri, 18 Feb 2005 01:43:09 +0100 by phpDocumentor 1.3.0RC3