PageRenderTime 22ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/opencore/js/thirdparty/xinha96r1270/plugins/ImageManager/ddt.php

https://github.com/socialplanning/oc-js
PHP | 288 lines | 112 code | 70 blank | 106 comment | 21 complexity | 29ac2d7f5f1f732e03f0090ec973acac MD5 | raw file
  1. <?php
  2. /*
  3. This ddt library is released under the terms of the HTMLArea license.
  4. See license.txt that is shipped with Xinha.
  5. */
  6. // must be included after the configuration has been loaded.
  7. if ( ! defined( "IM_CONFIG_LOADED" ) )
  8. die( "sorry" );
  9. /**
  10. * Debug and Error Message functions.
  11. *
  12. * These functions implement a procedural version of the formVista DDT debug
  13. * message system.
  14. *
  15. * @package formVista
  16. * @subpackage lib
  17. * @copyright DTLink, LLC 2005
  18. * @author Yermo Lamers
  19. * @see http://www.formvista.com/contact.html
  20. */
  21. // REVISION HISTORY:
  22. //
  23. // 26 Jan 2001 YmL:
  24. // . initial revision
  25. //
  26. // 2002-06-19 YmL:
  27. // . added logging debug and error messages to a file.
  28. //
  29. // 2004-02-06 YmL:
  30. // . added a newline to generated messages.
  31. //
  32. // 2005-01-09 YmL:
  33. // . now checks global $fvDEBUG[ "logfile" ] setting for
  34. // logfile to output to.
  35. // . dumping to file has not been combined into a dumpmsg
  36. // method.
  37. //
  38. // 2005-02-25 YmL:
  39. // . added _error() support for cmdLine programs.
  40. //
  41. // 2005-03-20 YmL:
  42. // . changed license for this file to HTMLArea from RPL.
  43. // . quick hack to repurpose for Xinha.
  44. //
  45. // -------------------------------------------------------
  46. /**
  47. * dumps message to stdout or log file depending upon global.
  48. *
  49. * checks $fvDEBUG["logfile"] global for name of file to dump
  50. * messages to. Opens the file once.
  51. */
  52. function dumpmsg( $msgline )
  53. {
  54. global $fvDEBUG;
  55. if ( @$fvDEBUG[ "logfile" ] != NULL )
  56. {
  57. // only open the file once and store the handle in the global
  58. // fvDEBUG array .. for now.
  59. if ( @$fvDEBUG[ "logfile_fp" ] == NULL )
  60. {
  61. // we clear out the debug file on each run.
  62. if (( $fvDEBUG[ "logfile_fp" ] = fopen( $fvDEBUG[ "logfile" ], "a" )) == NULL )
  63. {
  64. die( "ddt(): unable to open debug log" );
  65. return false ;
  66. }
  67. }
  68. fputs( $fvDEBUG[ "logfile_fp" ], "$msgline" );
  69. fflush( $fvDEBUG[ "logfile_fp" ] );
  70. }
  71. else
  72. {
  73. echo $msgline;
  74. }
  75. } // end of dumpmsg.
  76. /**
  77. * displays a formatted debugging message.
  78. *
  79. * If ddtOn() was called, outputs a formatted debugging message.
  80. *
  81. * @param string $file filename, usually __FILE__
  82. * @param string $line line number in file, usually __LINE__
  83. * @param string $msg debugging message to display
  84. */
  85. function _ddt( $file, $line, $msg )
  86. {
  87. global $_DDT;
  88. global $_DDT_DEBUG_LOG;
  89. global $_DDT_CMDLINE;
  90. $basename = basename( $file );
  91. if ( @$_DDT == "yes" )
  92. {
  93. if ( @$_DDT_CMDLINE == "yes" )
  94. {
  95. dumpmsg( basename( $file ) . ":$line: $msg \n" );
  96. flush();
  97. }
  98. else
  99. {
  100. dumpmsg( "<p>$basename:$line: $msg</p>\n" );
  101. }
  102. }
  103. } // end of _ddt
  104. /**
  105. * displays a formatted dump of an associative array.
  106. *
  107. * If ddtOn() was called, outputs a formatted debugging message showing
  108. * contents of array.
  109. *
  110. * @param string $file filename, usually __FILE__
  111. * @param string $line line number in file, usually __LINE__
  112. * @param string $msg debugging message to display
  113. * @param array $array_var array to dump.
  114. */
  115. function _ddtArray( $file, $line, $msg, $array_var )
  116. {
  117. global $_DDT;
  118. if ( $_DDT == "yes" )
  119. {
  120. dumpmsg( "<h2>$file:$line: $msg</h2>" );
  121. foreach ( $array_var as $name => $value )
  122. {
  123. dumpmsg( "<p><b>$name</b> => <b>$value</b>\n" );
  124. }
  125. }
  126. } // end of _ddtArray
  127. // -----------------------------------------------------------------
  128. /**
  129. * Central Error Function.
  130. *
  131. * Displays a formatted error message to the user.
  132. * If the global _DDT_ERROR_LOG is set the error message is dumped
  133. * to that file instead of being displayed to the user.
  134. */
  135. function _error( $file, $line, $msg )
  136. {
  137. global $_DDT_ERROR_LOG;
  138. global $_DDT_CMDLINE;
  139. if ( @$_DDT_ERROR_LOG == NULL )
  140. {
  141. if ( @$_DDT_CMDLINE == "yes" )
  142. {
  143. echo basename($file) . ":$line: $msg\n";
  144. }
  145. else
  146. {
  147. echo "<h2>$file:$line: $msg</h2>";
  148. }
  149. }
  150. else
  151. {
  152. if (( $fp = fopen( $_DDT_ERROR_LOG, "a" )) != NULL )
  153. {
  154. fputs( $fp, date("D M j G:i:s T Y") . " - $file:$line: $msg\n" );
  155. fclose( $fp );
  156. }
  157. }
  158. } // end of _error
  159. // ----------------------------------------------------------------------
  160. function errorEcho( $title, $field )
  161. {
  162. global $error_msg;
  163. if ( $error_msg[ $field ] != "" )
  164. {
  165. echo "<FONT SIZE=\"+2\" COLOR=\"RED\">$title</FONT>";
  166. }
  167. else
  168. {
  169. echo $title;
  170. }
  171. } // end of errorEcho
  172. /**
  173. * turns on procedural debugging.
  174. *
  175. * Causes _ddt() calls to display debugging messages.
  176. */
  177. function _ddtOn()
  178. {
  179. global $_DDT;
  180. $_DDT = "yes";
  181. }
  182. /**
  183. * set error message destination.
  184. *
  185. * sets the destination for error messages.
  186. *
  187. * @param string $file full path to errorlog.
  188. */
  189. function _setErrorLog( $errorLog )
  190. {
  191. global $_DDT_ERROR_LOG;
  192. $_DDT_ERROR_LOG = $errorLog;
  193. }
  194. /**
  195. * set output file for debugging messages.
  196. *
  197. * sets the destination file for debugging messages.
  198. *
  199. * @param string $file full path to debuglog.
  200. */
  201. function _setDebugLog( $debugLog )
  202. {
  203. global $fvDEBUG;
  204. $fvDEBUG[ "logfile" ] = $debugLog;
  205. }
  206. /**
  207. * set debugging output style to command line.
  208. *
  209. * tells ddt to format debugging messages for a
  210. * command line program.
  211. */
  212. function _ddtSetCmdLine()
  213. {
  214. global $_DDT_CMDLINE;
  215. $_DDT_CMDLINE = "yes";
  216. }
  217. // END
  218. ?>