/
Yawp.php
2034 lines (1690 loc) · 52.4 KB
/
Yawp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// =====================================================================
//
// This program is a standard component of Yet Another Web Programming
// (Yawp) foundation for rapid application development with PHP. For
// more information, see <http://phpyawp.com/>.
//
// Copyright (C) 2004 Paul M. Jones. <pmjones@ciaweb.net>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// http://www.gnu.org/copyleft/lesser.html
//
// =====================================================================
/**
* Report all errors; conf will override this later.
*/
ini_set('error_reporting', E_ALL);
/**
* Yawp state is "in the process of starting up".
*/
define('YAWP_STATE_STARTING', 1);
/**
* Yawp state is "started and returned to calling script".
*/
define('YAWP_STATE_STARTED', 2);
/**
* Yawp state is "in the process of stopping".
*/
define('YAWP_STATE_STOPPING', 3);
/**
* Yawp state is "stopped and returned to calling script".
*/
define('YAWP_STATE_STOPPED', 4);
/**
* Error when Yawp::start() cannot find the starting config file.
*/
define('YAWP_ERR_STARTING_CONF', -1);
/**
* Error when Yawp::start() cannot find the redirect config file.
*/
define('YAWP_ERR_REDIRECT_CONF', -2);
/**
* The error messages when Yawp cannot find files.
*/
if (! isset($GLOBALS['_Yawp']['err'])) {
$GLOBALS['_Yawp']['err'] = array(
YAWP_ERR_STARTING_CONF => 'could not read starting config file',
YAWP_ERR_REDIRECT_CONF => 'could not read redirect config file'
);
}
/**
* The default path to the config file.
*/
if (! defined('YAWP_CONF_PATH')) {
define('YAWP_CONF_PATH', $_SERVER['DOCUMENT_ROOT'] . '/Yawp.conf.php');
}
/**
*
* Yawp provides an encapsulated object suite foundation.
*
* To start a Yawp session, just include or require this file, and call
* Yawp::start(). Alternatively, call Yawp::start() with the path to a
* config file as the only parameter.
*
* Use Yawp methods themselves statically.
* Yawp::start();
* Yawp::getGet('get_var', 'default val');
* Yawp::getPost('post_var', 'default val')
* Yawp::stop();
*
* Access Yawp property objects with getObject().
* $auth =& Yawp::getObject('Auth');
* $auth->checkAuth();
*
* $db =& Yawp::getObject('DB');
* $db->query(...);
*
* $Id: Yawp.php,v 1.16 2006/03/07 04:39:13 justinrandell Exp $
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @version 1.2.0 stable
*
*/
class Yawp {
/**
*
* A PEAR Auth instance.
*
* @access public
*
* @var object
*
*/
var $Auth;
/**
*
* A PEAR Benchmark_Timer instance.
*
* @access public
*
* @var object
*
*/
var $Benchmark_Timer;
/**
*
* A PEAR Cache_Lite instance.
*
* @access public
*
* @var object
*
*/
var $Cache_Lite;
/**
*
* A PEAR DB instance.
*
* @access public
*
* @var object
*
*/
var $DB;
/**
*
* A PEAR Log composite instance.
*
* @access public
*
* @var object
*
*/
var $Log;
/**
*
* A PEAR Var_Dump instance.
*
* @access public
*
* @var object
*
*/
var $Var_Dump;
/**
*
* Record of the last authentication error code constant.
*
* @access public
*
* @var int If an authentication error occurred, an AUTH_* constant
* (AUTH_IDLED, AUTH_EXPIRED, or AUTH_WRONG_LOGIN), otherwise false.
*
*/
var $authErr = false;
/**
*
* The array of configuration groups and values from the config file.
*
* @access public
*
* @var array
*
*/
var $conf = array();
/**
*
* The list of optional Yawp property objects.
*
* There are classes that Yawp knows how to auto-load and auto-configure
* as Yawp property objects.
*
* @access public
*
* @var array An associative array where the key is the config file group
* name (also the property name) and the value is the file to include.
*
*/
var $objectConf = array(
'Auth' => 'Auth.php',
'Benchmark_Timer' => 'Benchmark/Timer.php',
'Cache_Lite' => 'Cache/Lite.php',
'DB' => 'DB.php',
'Log' => 'Log.php',
'Var_Dump' => 'Var_Dump.php'
);
/**
*
* An array of "subordinate" PEAR Log objects.
*
* These are children to the composite log object.
*
* @access public
*
* @var bool
*
* @see Yawp::log()
*
*/
var $subLog = array();
/**
*
* The "state" of Yawp.
*
* Indicates if Yawp is starting up, started and in the main,
* stopping, or stopped. If null/0/false, Yawp has not yet started.
*
* @access public
*
* @var int
*
*/
var $state = null;
/**
*
* Return a static $Yawp object and its properties.
*
* @static
*
* @access public
*
* @return object A Yawp object.
*
*/
function &singleton()
{
static $Yawp;
if (! isset($Yawp)) {
// don't use =& here, because a static variable is not
// allowed to be a reference. This is a bug with PHP.
$Yawp = new Yawp;
}
return $Yawp;
}
/**
*
* Initializes the Yawp singleton.
*
* Starts a session, starts the timer, loads objects, and processes
* authentication.
*
* This is a monster method that does *everything* for the startup.
* In theory I should break it down into sub-methods, but that would
* expose methods that I don't want publically available; to make
* them private would break the gentlemens' agreement on calling
* private methods from outside the class, which is what would be
* required using a singleton pattern.
*
* @param string $confFile An aribtrary config file location; default
* is null, in which case the method looks for the config file
* Yawp.conf.php at $_SERVER['DOCUMENT_ROOT'].
*
* @access public
*
* @return void
*
*/
function start($confFile = null)
{
// -------------------------------------------------------------
//
// Preliminaries.
//
$Yawp =& Yawp::singleton();
// Has Yawp already been started?
if ($Yawp->state) {
// yes, don't re-start it
return;
}
// -------------------------------------------------------------
//
// Load the config file file text; we need it now so we can
// "look ahead" for object loading, redirects, etc.
//
// did the user specify a config file location?
if (is_null($confFile)) {
// no, so go to the default
$confFile = YAWP_CONF_PATH;
}
// load the base conf file text
$confText = Yawp::getFile($confFile);
// could we load it?
if ($confText === false) {
$msg = 'Yawp::start() ' .
$GLOBALS['_Yawp']['err'][YAWP_ERR_STARTING_CONF] .
" '$confFile'";
// HALT THE SCRIPT
trigger_error(htmlspecialchars($msg), E_USER_ERROR);
} else {
$confText = trim($confText);
}
// does the first line start with a slash?
if (substr($confText, 0, 1) == '/') {
// the default config file redirects us to the "real" config
// file. treat the first line as an absolute file path. we
// add a \n to the confText so that we know we have at least
// one newline at the end.
$confText .= "\n";
$confFile = substr(
$confText, 0, strpos($confText, "\n")
);
// load up the new config text
$confText = Yawp::getFile($confFile);
// could we load it?
if ($confText === false) {
$msg = 'Yawp::start() ' .
$GLOBALS['_Yawp']['err'][YAWP_ERR_REDIRECT_CONF] .
" '$confFile'";
// HALT THE SCRIPT
trigger_error(htmlspecialchars($msg), E_USER_ERROR);
} else {
$confText = trim($confText);
}
}
// force newlines at the fore and aft for parsing.
$confText = "\n" . $confText . "\n";
// -------------------------------------------------------------
//
// Yawp gets started! Load library files here so that the
// constants in those files are available when we parse the
// config file.
//
$Yawp->state = YAWP_STATE_STARTING;
// load optional library files. we do a lookahead on the config
// file to see if they have config groups noted; if so, load
// the repsective classes.
foreach ($Yawp->objectConf as $name => $file) {
if (strpos($confText, "\n[$name]\n") !== false) {
include_once $file;
}
}
// as long as we're doing lookaheads, find out how many
// log objects we're going to need; this will help later
// when we instantiate log objects.
$logCount = preg_match_all('/\n\[Log\]\n/', $confText, $tmp);
unset($tmp);
// -------------------------------------------------------------
//
// Look at $confText and define constants from the [CONSTANT]
// config file group.
//
$regex = '/^((\[CONSTANT\])\n(.*)\n)(\[|\s|$)/Umsi';
preg_match($regex, $confText, $matches);
if (isset($matches[1])) {
// we found a [CONSTANT] group; parse into an array.
// becuase we leave out the [CONSTANT] line, all the
// values come back as part of the [Root] group,
// which is why we extract from that.
$tmp = explode("\n", $matches[3]);
$tmp2 = Yawp::parseConfLines($tmp);
$const = $tmp2['Root'];
unset($tmp);
unset($tmp2);
// define each constant
foreach ($const as $key => $val) {
// if we find more than one constant with the
// same name, only honor the first one.
if (is_array($val)) {
$val = array_shift($val);
}
// force slashes on DOCUMENT_ROOT and HREF_BASE endings
if (($key == 'DOCUMENT_ROOT' || $key == 'HREF_BASE') &&
substr($val, -1) != '/') {
$val .= '/';
}
// define the constant
if (! defined($key)) {
define($key, $val);
}
}
// clean up
unset($const);
// remove the [CONSTANT] group from the source
$confText = str_replace($matches[1], '', $confText);
}
// was the DOCUMENT_ROOT constant set in the config file?
if (! defined('DOCUMENT_ROOT')) {
// no, so default-define it here, add a trailing slash
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'] . '/');
}
// was HREF_BASE constant set in the config file?
if (! defined('HREF_BASE')) {
// no, so default-define it here
define('HREF_BASE', '/');
}
// was HTTP_HOST constant set in the config file?
if (! defined('HTTP_HOST')) {
// no, so default-define it here
define('HTTP_HOST', $_SERVER['HTTP_HOST']);
}
// -------------------------------------------------------------
//
// Expand %CONSTANT% tags in the config text, then parse the
// source text into the $conf array.
//
// This is where we (finally) set up $Yawp->conf.
//
foreach (get_defined_constants() as $key => $val) {
$confText = str_replace('%' . $key . '%', $val, $confText);
}
$lines = explode("\n", $confText);
$Yawp->conf = Yawp::parseConfLines($lines);
// clean up
unset($lines);
unset($confText);
// -------------------------------------------------------------
//
// Reset the error level
//
ini_set(
'error_reporting',
Yawp::getConfElem('Yawp', 'error_reporting', E_ALL)
);
// -------------------------------------------------------------
//
// Configure and start the session, but only if session_start
// is true, or Auth is configured. Turn off Auth and
// session_start to handle sessions yourself.
//
if (Yawp::getConfElem('Yawp', 'session_start', true) ||
Yawp::getConfGroup('Auth', false)) {
//
// Set zero expiry time and cache_limiter to
// 'private'. This should prevent caches from
// caching the cookie data, and also ensure that
// the cookie lasts as long as the browser.
//
session_name(
Yawp::getConfElem('Yawp', 'session_name', 'YAWP'));
session_cache_expire(0);
session_cache_limiter('private');
ini_set('session.gc_maxlifetime', 86400);
// set session parameters
//
// You cannot set a cookie domain parameter to
// be a TLD -- or any simple string like "localhost".
// It isn't allowed by the HTTP protocol, for security
// reasons. Omitting the domain parameter completely
// seems to solve the problem for the case where the
// server name is "localhost" or similar.
//
// Ref: http://www.php.net/manual/en/function.session-set-cookie-params.php
//
$http_host = Yawp::getConfElem('Yawp', 'session_domain', HTTP_HOST);
if (strpos($http_host, '.')) {
session_set_cookie_params(
Yawp::getConfElem('Yawp', 'session_lifetime', 0),
Yawp::getConfElem('Yawp', 'session_path' , HREF_BASE),
$http_host,
Yawp::getConfElem('Yawp', 'session_secure' , false)
);
} else {
session_set_cookie_params(
Yawp::getConfElem('Yawp', 'session_lifetime', 0),
Yawp::getConfElem('Yawp', 'session_path' , HREF_BASE)
);
}
// silence starting calls per note from Lukas Smith;
// apparently session_start() generates weird errors
// in earlier versions of PHP 4
@session_start();
}
// -------------------------------------------------------------
//
// Process user-defined prep scripts. These are just like the
// start scripts, except they get run before any of the internal
// objects get created, rather than after.
//
if (isset($Yawp->conf['Yawp']['prep'])) {
settype($Yawp->conf['Yawp']['prep'], 'array');
foreach ($Yawp->conf['Yawp']['prep'] as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}
}
// -------------------------------------------------------------
//
// Optionally instantiate Benchmark_Timer and start timer. There
// are no config options for Benchmark_Timer. We start it here
// because we want the timer to capture as much timing data as
// possible.
//
// only create if not already created by a prep hook,
// and then only if we have a Benchmark_Timer conf group.
if (! is_object($Yawp->Benchmark_Timer) &&
isset($Yawp->conf['Benchmark_Timer'])) {
// create and start the timer
$Yawp->Benchmark_Timer =& new Benchmark_Timer();
$Yawp->Benchmark_Timer->start();
} else {
if (! is_object($Yawp->Benchmark_Timer))
$Yawp->Benchmark_Timer = null;
}
// -------------------------------------------------------------
//
// Create an optional instance of Var_Dump.
//
// only create if not already created by a prep hook,
// and then only if there is a Var_Dump conf group.
$opts = Yawp::getConfGroup('Var_Dump', false);
if (! is_object($Yawp->Var_Dump) && is_array($opts)) {
$mode = Yawp::getConfElem(
'Var_Dump', 'display_mode', 'HTML4_Table'
);
// if there are no elements in the [Var_Dump] group,
// then display_mode element is not set. set it!
if (! isset($opts['display_mode'])) {
$opts['display_mode'] = $mode;
}
// get rendering options, if any
$rend = Yawp::getConfGroup("Var_Dump_$mode", array());
// build the object
$Yawp->Var_Dump =& Var_Dump::factory($opts, $rend);
// clean up
unset($mode);
unset($rend);
} else {
if (! is_object($Yawp->Var_Dump))
$Yawp->Var_Dump = null;
}
// clean up
unset($opts);
// -------------------------------------------------------------
//
// Create an optional instance of Cache_Lite
//
// only create if not already created by a prep hook,
// and then only if there is a Cache_Lite conf group.
$opts = Yawp::getConfGroup('Cache_Lite', false);
if (! is_object($Yawp->Cache_Lite) && $opts) {
$Yawp->Cache_Lite =& new Cache_Lite($opts);
} else {
if (! is_object($Yawp->Cache_Lite))
$Yawp->Cache_Lite = null;
}
// clean up
unset($opts);
// -------------------------------------------------------------
//
// Create an optional instance of DB
//
// only create if not already created by a prep hook,
// and then only if we have a DB DSN.
$dsn = Yawp::getConfGroup('DB', false);
if (! is_object($Yawp->DB) && $dsn) {
$opts = Yawp::getConfGroup('DB_Options');
$Yawp->DB =& DB::connect($dsn, $opts);
} else {
if (! is_object($Yawp->DB))
$Yawp->DB = null;
}
// clean up
unset($dsn);
unset($opts);
// -------------------------------------------------------------
//
// Create optional instance of Log and the various log objects.
//
// only create if not already created by a prep hook,
// and then only if logs were requested in the conf file.
if (! is_object($Yawp->Log) && $logCount > 0) {
$Yawp->Log =& Log::singleton('composite');
if ($logCount == 1) {
// if there is only one Log entry, make it the 0-entry in
// a greater array; that way the foreach loop will work
// as expected.
$tmp = array(Yawp::getConfGroup('Log'));
} else {
// get the multiple Log entries
$tmp = Yawp::getConfGroup('Log');
}
foreach ($tmp as $key => $val) {
// get the all-purpose keys needed for every log handler
$handler = (isset($val['handler'])) ? $val['handler'] : false;
$name = (isset($val['name'])) ? $val['name'] : '';
$ident = (isset($val['ident'])) ? $val['ident'] : '';
$level = (isset($val['level'])) ? $val['level'] : PEAR_LOG_DEBUG;
// remove the all-purpose keys, this leaves us
// with only the keys for the handler config
unset($val['handler']);
unset($val['name']);
unset($val['ident']);
unset($val['level']);
// if no handler is specified, skip it.
if (! $handler) {
continue;
}
// special case: if the handler is SQL, and no
// dsn is set, and we have a DB object, use the
// DB object.
if ($handler == 'sql' && is_object($Yawp->DB) &&
(! isset($val['dsn']) || ! $val['dsn'])) {
$val['db'] = $Yawp->DB;
}
// create the sub-log ...
$Yawp->subLog[$key] =& Log::singleton(
$handler, $name, $ident, $val, $level
);
// ... then add it to the composite
$Yawp->Log->addChild($Yawp->subLog[$key]);
}
// clean up
unset($key);
unset($val);
unset($handler);
unset($name);
unset($ident);
unset($level);
unset($tmp);
} else {
// logging not enabled
if (! is_object($Yawp->Log))
$Yawp->Log = null;
}
// clean up
unset($logCount);
// -------------------------------------------------------------
//
// Create optional instance of Auth.
//
// only create if not already created by a prep hook,
// and then only if there is an [Auth] conf group.
if (! is_object($Yawp->Auth) &&
Yawp::getConfGroup('Auth', false)) {
// authentication is on.
// get the container type.
$container = Yawp::getConfElem('Auth', 'container');
// get the container parameters
if ($container == 'File' || $container == 'SMBPasswd') {
// these containers have only one parameter
// (the file name)
$params = Yawp::getConfElem("Auth_$container", 'file');
} else {
$params = Yawp::getConfGroup("Auth_$container");
}
// special case for Auth_DB and Auth_DBLite: if the 'dsn'
// element is null/false/blank/unset, replace it with a
// reference to $Yawp->DB
if (($container == 'DB' || $container == 'DBLite') &&
(! isset($params['dsn']) || ! $params['dsn']) &&
is_object($Yawp->DB)) {
$params['dsn'] = $Yawp->DB;
}
// instantiate the object
$Yawp->Auth =& new Auth($container, $params, '', false);
} else {
// authentication not enabled
if (! is_object($Yawp->Auth))
$Yawp->Auth = null;
}
// -------------------------------------------------------------
//
// Process Auth login/logout/idle/expire/error events, but only
// if we have an Auth object available.
//
if (is_object($Yawp->Auth)) {
// hack to allow logins to work under both Auth 1.2.3 and
// 1.3.0r2 ... does this really work?
if (method_exists($Yawp->Auth, 'setAllowLogin')) {
$Yawp->Auth->setAllowLogin(true);
}
// set idle time
$Yawp->Auth->setIdle(
Yawp::getConfElem('Auth', 'idle', 1800)
);
// set expire time
$Yawp->Auth->setExpire(
Yawp::getConfElem('Auth', 'expire', 3600)
);
// Process explicit login attempts.
if (isset($_POST['LOGIN'])) {
// start an authenticated session; this will
// automatically check credentials ($_POST['username']
// && $_POST['password']) if they were passed.
$Yawp->Auth->start();
// was the login successful?
if ($Yawp->Auth->checkAuth()) {
// yes. clear any prior errors.
$Yawp->clearAuthErr();
//perform login hooks if they exist.
$tmp = Yawp::getConfElem('Yawp', 'login');
settype($tmp, 'array');
// include each file
foreach ($tmp as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}
} else {
// login failed. retain the error status in a
// session variable so we can keep it between
// redirects.
$Yawp->authErr = $Yawp->Auth->getStatus();
$_SESSION['_Yawp']['authErr'] = $Yawp->authErr;
}
// redirect if required.
if (isset($_POST['location']) &&
trim($_POST['location']) != '') {
// THIS WILL END THE STARTUP SEQUENCE AND REDIRECT
// TO ANOTHER PAGE!
session_write_close();
header("Location: {$_POST['location']}");
}
}
// Process explicit logout attempts.
if (isset($_POST['LOGOUT'])) {
// process any customized logout hook scripts
$tmp = Yawp::getConfElem('Yawp', 'logout');
settype($tmp, 'array');
foreach ($tmp as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}
// actually log out
$Yawp->Auth->logout();
// redirect if required.
if (isset($_POST['location']) &&
trim($_POST['location']) != '') {
// THIS WILL END THE STARTUP SEQUENCE AND REDIRECT
// TO ANOTHER PAGE!
session_write_close();
header("Location: {$_POST['location']}");
}
}
// Process authentication errors and idle/expire timeouts.
// get the Auth_Err status from a prior login if
// it exists, or check the current authentication
// state if not.
if (isset($_SESSION['_Yawp']['authErr'])) {
// prior auth error was set, capture it for this
// page load.
$Yawp->authErr = $_SESSION['_Yawp']['authErr'];
} else {
// check current status
$Yawp->Auth->checkAuth();
$Yawp->authErr = $Yawp->Auth->getStatus();
}
// were there auth errors?
if ($Yawp->authErr) {
// run the autherr hooks
$tmp = Yawp::getConfElem('Yawp', 'authErr');
settype($tmp, 'array');
foreach ($tmp as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}
}
}
// -------------------------------------------------------------
//
// Process user-defined start scripts
//
$tmp = Yawp::getConfElem('Yawp', 'start');
settype($tmp, 'array');
foreach ($tmp as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}
// done!
$Yawp->state = YAWP_STATE_STARTED;
}
/**
*
* Run the user-defined "stop" scripts, then stop the timer and set the
* state of Yawp.
*
* @static
*
* @access public
*
* @return void
*
*/
function stop()
{
$Yawp =& Yawp::singleton();
// update the Yawp state
$Yawp->state = YAWP_STATE_STOPPING;
// run the user-defined shutdown scripts
$tmp = Yawp::getConfElem('Yawp', 'stop');
settype($tmp, 'array');
foreach ($tmp as $file) {
if (trim($file) != '') {
Yawp::run($file);
}
}