source: trunk/plugins/ImageManager/ddt.php @ 43

Last change on this file since 43 was 43, checked in by yermol, 15 years ago

adding modified version of Xiang Wei Zhuo's ImageManager? plugin that
now features a unified single entry-point backend.

Updated full_example to include ImageManager? checkbox.

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