-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pman.php
1002 lines (775 loc) · 30.2 KB
/
Pman.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
/**
* Pman Base class
*
* Provides:
* - base application setup (variables etc to javascript)
*
* - authentication and permission info about user / application
* - json output methods.
* - file upload error checking - checkFileUploadError
* - logging to event table
* - sendTemplate code (normally use the Person version for sending to specific people..)
*
* - doc managment code?? - remarks and tracking??? - MOVEME
* - authentication link checking?? MOVEME?
* - authentication reset password ?? MOVEME?
* ?? arrayClean.. what's it doing here?!? ;)
*
*
* OPTIONS
* Pman['local_autoauth'] // who to login as when using localhost
* Pman['isDev'] // can the site show develpment info.?
* Pman['uiConfig'] // extra variable to export to front end..
* Pman['auth_comptype'] // -- if set to 'OWNER' then only users with company=OWNER can log in
* Pman['authTable'] // the authentication table (default 'person')
*
*
* Usefull implemetors
* DB_DataObject*:*toEventString (for logging - this is generically prefixed to all database operations.)
* - any data object where this method exists, the result will get prefixed to the log remarks
*/
require_once 'Pman/Core/AssetTrait.php';
require_once 'Pman/Core/JsonOutputTrait.php';
class Pman extends HTML_FlexyFramework_Page
{
use Pman_Core_AssetTrait,
//outputJavascriptDir()
//outputCssDir();
Pman_Core_JsonOutputTrait;
// jerr()
// jnotice()
// jerrAuth()
// jerror();
// jok()
// jdata()
// jdataCache()
var $isDev = false;
var $appName= "";
var $appLogo= "";
var $appShortName= "";
var $appVersion = "1.8";
var $version = 'dev';
var $onloadTrack = 0;
var $linkFail = "";
var $showNewPass = 0;
var $logoPrefix = '';
var $appModules = '';
var $appDisabled = array(); // array of disabled modules..
// (based on config option disable)
var $authUser; // always contains the authenticated user..
var $disable_jstemplate = false; /// disable inclusion of jstemplate code..
var $company = false;
var $css_path = ''; // can inject a specific path into the base HTML page.
var $transObj = false; // used to rollback or commit in JOK/JERR
// these are used somewhere -
var $builderJs = false;//
var $serverName = false;
var $lang = false;
var $allowSignup = false;
var $_hasInit;
var $appNameShort;
var $appDisable;
var $uiConfig;
/**
* ------------- Standard getAuth/get/post methods of framework.
*
*
*/
function getAuth() // everyone allowed in!!!!!
{
$this->loadOwnerCompany();
return true;
}
function init($base = false)
{
if (isset($this->_hasInit)) {
return;
}
$this->_hasInit = true;
// move away from doing this ... you can access bootLoader.XXXXXX in the master template..
$boot = HTML_FlexyFramework::get();
// echo'<PRE>';print_R($boot);exit;
$this->appName = $boot->appName;
$this->appNameShort = $boot->appNameShort;
$this->appModules = $boot->enable;
// echo $this->arrayToJsInclude($files);
$this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
$this->css_path = empty($boot->Pman['css_path']) ? '' : $boot->Pman['css_path'];
$this->appDisable = $boot->disable;
$this->appDisabled = explode(',', $boot->disable);
$this->version = $boot->version;
$this->appVersion = $boot->version;
$this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig'];
if (!empty($boot->Pman['local_autoauth']) &&
!empty($_SERVER['SERVER_ADDR']) &&
!empty($_SERVER['REMOTE_ADDR']) &&
($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
($_SERVER['REMOTE_ADDR'] == '127.0.0.1')
) {
$this->isDev = true;
}
if (
!empty($_REQUEST['isDev'])
&&
(
(
!empty($_SERVER['SERVER_ADDR']) &&
(
(($_SERVER['SERVER_ADDR'] == '127.0.0.1') && ($_SERVER['REMOTE_ADDR'] == '127.0.0.1'))
||
(($_SERVER['SERVER_ADDR'] == '::1') && ($_SERVER['REMOTE_ADDR'] == '::1'))
||
(preg_match('/^192\.168/', $_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] == $_SERVER['HTTP_HOST'])
)
)
||
!empty($boot->Pman['enable_isdev_url'])
)
) {
$boot->Pman['isDev'] = true;
$this->isDev = true;
}
// if a file Pman_{module}_Pman exists.. and it has an init function... - call that..
//var_dump($this->appModules);
}
/*
* call a method on {module}/Pman.php
* * initially used on the main page load to call init();
* * also used for ccsIncludes??
*
* // usage: $this->callModules('init', $base)
*
*/
function callModules($fn)
{
$args = func_get_args();
array_shift($args);
foreach(explode(',',$this->appModules) as $m) {
$cls = 'Pman_'. $m . '_Pman';
if (!file_exists($this->rootDir . '/'.str_replace('_','/', $cls). '.php')) {
continue;
}
require_once str_replace('_','/', $cls). '.php';
$c = new $cls();
if (method_exists($c, $fn)) {
call_user_func_array(array($c,$fn),$args);
}
}
}
function get($base, $opts=array())
{
$this->init();
if (empty($base)) {
$this->callModules('init', $this, $base);
}
//$this->allowSignup= empty($opts['allowSignup']) ? 0 : 1;
$bits = explode('/', $base);
// should really be moved to Login...
/*
if ($bits[0] == 'PasswordReset') {
$this->linkFail = $this->resetPassword(@$bits[1],@$bits[2],@$bits[3]);
header('Content-type: text/html; charset=utf-8');
return;
}
*/
$au = $this->getAuthUser();
if ($au) {
$ff= HTML_FlexyFramework::get();
if (!empty($ff->Pman['auth_comptype']) && $au->id > 0 &&
( !$au->company_id || ($ff->Pman['auth_comptype'] != $au->company()->comptype))) {
$au->logout();
$this->jerr("Login not permited to outside companies - please reload");
}
$this->addEvent("RELOAD");
}
if (strlen($base) && $bits[0] != 'PasswordReset') {
$this->jerror("NOTICE-BADURL","invalid url: $base");
}
// deliver template
if (isset($_GET['onloadTrack'])) {
$this->onloadTrack = (int)$_GET['onloadTrack'];
}
// getting this to work with xhtml is a nightmare
// = nbsp / <img> issues screw everyting up.
//var_dump($this->isDev);
// force regeneration on load for development enviroments..
HTML_FlexyFramework::get()->generateDataobjectsCache($this->isDev && !empty($_REQUEST['isDev']));
//header('Content-type: application/xhtml+xml; charset=utf-8');
if ($this->company && $this->company->logo_id) {
$im = DB_DataObject::Factory('Images');
$im->get($this->company->logo_id);
$this->appLogo = $this->baseURL . '/Images/Thumb/x100/'. $this->company->logo_id .'/' . $im->filename;
}
header('Content-type: text/html; charset=utf-8');
}
function post($base) {
return $this->get($base);
}
// --------------- AUTHENTICATION or system information
/**
* loadOwnerCompany:
* finds the compay with comptype=='OWNER'
* ?? what about comptype_id-name ?????
*
* @return {Pman_Core_DataObjects_Companies} the owner company
*/
function loadOwnerCompany()
{
// only applies if authtable is person..
$ff = HTML_FlexyFramework::get();
if (!empty($ff->Pman['authTable']) && !in_array($ff->Pman['authTable'] , [ 'core_person', 'Person' ])) {
return false;
}
$this->company = DB_DataObject::Factory('core_company');
if (!is_a($this->company, 'DB_DataObject')) { // non-core pman projects
return false;
}
$e = DB_DataObject::Factory('core_enum')->lookupObject('COMPTYPE', 'OWNER');
$this->company->get('comptype_id', $e->id);
return $this->company;
}
static function staticGetAuthUser($t) {
if (!empty($t->authUser)) {
return $t->authUser;
}
$ff = HTML_FlexyFramework::get();
$tbl = empty($ff->Pman['authTable']) ? 'core_person' : $ff->Pman['authTable'];
$u = DB_DataObject::factory( $tbl );
if (is_a($u,'PEAR_Error') || !$u->isAuth()) {
return false;
}
$t->authUser =$u->getAuthUser();
return $t->authUser ;
}
/**
* getAuthUser: - get the authenticated user..
*
* @return {DB_DataObject} of type Pman[authTable] if authenticated.
*/
function getAuthUser()
{
return self::staticGetAuthUser($this);
}
/**
* hasPerm:
* wrapper arround authuser->hasPerm
* @see Pman_Core_DataObject_Core_person::hasPerm
*
* @param {String} $name The permission name (eg. Projects.List)
* @param {String} $lvl eg. (C)reate (E)dit (D)elete ... etc.
*
*/
function hasPerm($name, $lvl) // do we have a permission
{
static $pcache = array();
$au = $this->getAuthUser();
return $au && $au->hasPerm($name,$lvl);
}
/**
* modulesList: List the modules in the application
*
* @return {Array} list of modules
*/
function modulesList()
{
$boot = HTML_FlexyFramework::get();
// echo'<PRE>';print_R($boot);exit;
$mods = explode(',', $boot->enable);
if (in_array('Core',$mods)) { // core has to be the first modules loaded as it contains Pman.js
array_unshift($mods, 'Core');
}
if (in_array($boot->appNameShort,$mods)) { // Project has to be the last modules loaded as it contains Pman.js
unset($mods[array_search($boot->appNameShort, $mods)]);
$mods[] = $boot->appNameShort;
}
$mods = array_unique($mods);
$disabled = explode(',', $boot->disable ? $boot->disable : '');
$ret = array();
foreach($mods as $mod) {
// add the css file..
if (in_array($mod, $disabled)) {
continue;
}
$ret[] = $mod;
}
return $ret;
}
function hasModule($name)
{
$this->init();
if (!strpos( $name,'.') ) {
// use enable / disable..
return in_array($name, $this->modules());
}
$x = DB_DataObject::factory('core_group_right');
$ar = $x->defaultPermData();
if (empty($ar[$name]) || empty($ar[$name][0])) {
return false;
}
return true;
}
/**
* ---------------- Global Tools ---------------
*/
function checkFileUploadError() // check for file upload errors.
{
if (
empty($_FILES['File'])
|| empty($_FILES['File']['name'])
|| empty($_FILES['File']['tmp_name'])
|| empty($_FILES['File']['type'])
|| !empty($_FILES['File']['error'])
|| empty($_FILES['File']['size'])
) {
$this->jerr("File upload error: <PRE>" . print_r($_FILES,true) . print_r($_POST,true) . "</PRE>");
}
}
static $deleteOnExit = false;
/**
* generate a tempory file with an extension (dont forget to delete it)
*/
function deleteOnExitAdd($name)
{
if (self::$deleteOnExit === false) {
register_shutdown_function(array('Pman','deleteOnExit'));
self::$deleteOnExit = array();
}
self::$deleteOnExit[] = $name;
}
function tempName($ext, $deleteOnExit=false)
{
$x = tempnam(ini_get('session.save_path'), HTML_FlexyFramework::get()->appNameShort.'TMP');
unlink($x);
$ret = $x .'.'. $ext;
if ($deleteOnExit) {
$this->deleteOnExitAdd($ret);
}
return $ret;
}
static function deleteOnExit()
{
foreach(self::$deleteOnExit as $fn) {
if (file_exists($fn)) {
unlink($fn);
}
}
}
/**
* ------------- Authentication password reset ------ ??? MOVEME?
*
*
*/
/**
* ---------------- OUTPUT
*/
function hasBg($fn) // used on front page to check if logos exist..
{
return file_exists($this->rootDir.'/Pman/'.$this->appNameShort.'/templates/images/'. $fn);
}
/**
* outputJavascriptIncludes:
*
* output <script....> for all the modules in the applcaiton
*
*/
function outputJavascriptIncludes()
{
// BC support - currently 1 project still relies on this.. (MO portal)
$ff = HTML_FlexyFramework::get();
$o = isset($ff->Pman_Core) ? $ff->Pman_Core : array();
if (isset($o['packseed'])) {
return $this->outputJavascriptIncludesBC();
}
$mods = $this->modulesList();
$is_bootstrap = in_array('BAdmin', $mods);
foreach($mods as $mod) {
// add the css file..
if ($is_bootstrap) {
if (!file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
continue;
}
}
$this->outputJavascriptDir("Pman/$mod/widgets", "*.js");
$this->outputJavascriptDir("Pman/$mod", "*.js");
}
if (empty($this->disable_jstemplate)) {
// and finally the JsTemplate...
echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
}
$this->callModules('outputJavascriptIncludes', $this);
return '';
}
var $css_includes = array();
/**
* outputCSSIncludes:
*
* output <link rel=stylesheet......> for all the modules in the applcaiton
*
*
* This could css minify as well.
*/
function outputCSSIncludes() // includes on CSS links.
{
$mods = $this->modulesList();
$is_bootstrap = in_array('BAdmin', $mods);
$this->callModules('applyCSSIncludes', $this);
foreach($this->css_includes as $module => $ar) {
if ($ar) {
$this->assetArrayToHtml( $ar , 'css');
}
}
// old style... - probably remove this...
$this->callModules('outputCSSIncludes', $this);
foreach($mods as $mod) {
// add the css file..
if ($is_bootstrap && !file_exists($this->rootDir."/Pman/$mod/is_bootstrap")) {
echo '<!-- missing '. $this->rootDir."/Pman/$mod/is_bootstrap - skipping -->";
continue;
}
$this->outputCSSDir("Pman/$mod","*.css");
$this->outputSCSS($mod);
}
return ''; // needs to return something as we output it..
}
/**
* while doing batch processes, the database sometimes get's locked up.
* if we are doing another batch process that can be avoided - we should just stop for a while..
*/
function database_is_locked()
{
$cd = DB_DataObject::Factory('core_enum');
$cd->query("show processlist");
$locked = 0;
while ($cd->fetch()) {
if ($cd->State == 'Waiting for table metadata lock') {
$locked++;
}
if ($locked> 10) {
return true;
}
}
return false;
}
// --- OLD CODE - in for BC on MO project.... - needs removing...
// used on old versions.....
function outputJavascriptIncludesBC()
{
$mods = $this->modulesList();
foreach($mods as $mod) {
// add the css file..
$files = $this->moduleJavascriptList($mod.'/widgets');
foreach($files as $f) {
echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
}
$files = $this->moduleJavascriptList($mod);
foreach($files as $f) {
echo '<script type="text/javascript" src="'. $f. '"></script>'."\n";
}
}
if (empty($this->disable_jstemplate)) {
// and finally the JsTemplate...
echo '<script type="text/javascript" src="'. $this->baseURL. '/Core/JsTemplate"></script>'."\n";
}
return '';
}
/**
* Gather infor for javascript files..
*
* @param {String} $mod the module to get info about.
* @return {StdClass} details about module.
*/
function moduleJavascriptFilesInfo($mod)
{
static $cache = array();
if (isset($cache[$mod])) {
return $cache[$mod];
}
$ff = HTML_FlexyFramework::get();
$base = dirname($_SERVER['SCRIPT_FILENAME']);
$dir = $this->rootDir.'/Pman/'. $mod;
$path = $this->rootURL ."/Pman/$mod/";
$ar = glob($dir . '/*.js');
$files = array();
$arfiles = array();
$maxtime = 0;
$mtime = 0;
foreach($ar as $fn) {
$f = basename($fn);
// got the 'module file..'
$mtime = filemtime($dir . '/'. $f);
$maxtime = max($mtime, $maxtime);
$arfiles[$fn] = $mtime;
$files[] = $path . $f . '?ts='.$mtime;
}
ksort($arfiles); // just sort by name so it's consistant for serialize..
// The original idea of this was to serve the files direct from a publicly available 'cache' directory.
// but that doesnt really make sense - as we can just serve it from the session directory where we stick
// cached data anyway.
/*
$compile = empty($ff->Pman['public_cache_dir']) ? 0 : 1;
$basedir = $compile ? $ff->Pman['public_cache_dir'] : false;
$baseurl = $compile ? $ff->Pman['public_cache_url'] : false;
*/
$compile = 1;
$basedir = session_save_path(). '/translate-cache/';
if (!file_exists($basedir)) {
mkdir($basedir,0755);
}
$baseurl = $this->baseURL . '/Admin/Translations';
if (PHP_VERSION_ID < 70000 ) {
$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
usort($files, $lsort);
} else {
usort($files, function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; });
}
$smod = str_replace('/','.',$mod);
$output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js';
// why are translations done like this - we just build them on the fly frmo the database..
$tmtime = file_exists($this->rootDir.'/_translations_/'. $smod.'.js')
? filemtime($this->rootDir.'/_translations_/'. $smod.'.js') : 0;
$cache[$mod] = (object) array(
'smod' => $smod, // module name without '/'
'files' => $files, // list of all files.
'filesmtime' => $arfiles, // map of mtime=>file
'maxtime' => $maxtime, // max mtime
'compile' => $this->isDev ? false : $compile,
'translation_file' => $base .'/_translations_/' . $smod . '.js',
'translation_mtime' => $tmtime,
'output' => $output,
'translation_data' => preg_replace('/\.js$/', '.__translation__.js', $output),
'translation_base' => $dir .'/', //prefix of filename (without moudle name))
'basedir' => $basedir,
'baseurl' => $baseurl,
'module_dir' => $dir,
);
return $cache[$mod];
}
/**
* moduleJavascriptList: list the javascript files in a module
*
* The original version of this.. still needs more thought...
*
* Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js
* Translations are in Pman/_translations_/{$mod}.js
*
* if that stuff does not exist just list files in Pman/{$mod}/*.js
*
* Compiled could be done on the fly..
*
*
*
* @param {String} $mod the module to look at - eg. Pman/{$mod}/*.js
* @return {Array} list of include paths (either compiled or raw)
*
*/
function moduleJavascriptList($mod)
{
$dir = $this->rootDir.'/Pman/'. $mod;
if (!file_exists($dir)) {
echo '<!-- missing directory '. htmlspecialchars($dir) .' -->';
return array();
}
$info = $this->moduleJavascriptFilesInfo($mod);
if (empty($info->files)) {
return array();
}
// finally sort the files, so they are in the right order..
// only compile this stuff if public_cache is set..
// suggestions...
// public_cache_dir = /var/www/myproject_cache
// public_cache_url = /myproject_cache (with Alias apache /myproject_cache/ /var/www/myproject_cache/)
// bit of debugging
if (!$info->compile) {
echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n";
return $info->files;
}
// where are we going to write all of this..
// This has to be done via a
if (!file_exists($info->basedir.'/'.$info->output) || !filesize($info->basedir.'/'.$info->output)) {
require_once 'Pman/Core/JsCompile.php';
$x = new Pman_Core_JsCompile();
$x->pack($info->filesmtime,$info->basedir.'/'.$info->output, $info->translation_base);
} else {
echo "<!-- file exists not exist: {$info->basedir}/{$info->output} -->\n";
}
if (file_exists($info->basedir.'/'.$info->output) &&
filesize($info->basedir.'/'.$info->output)) {
$ret =array(
$info->baseurl.'/'. $info->output,
);
// output all the ava
// fixme - this needs the max datetime for the translation file..
$ret[] = $this->baseURL."/Admin/InterfaceTranslations/".$mod.".js"; //?ts=".$info->translation_mtime;
//if ($info->translation_mtime) {
// $ret[] = $this->rootURL."/_translations_/". $info->smod.".js?ts=".$info->translation_mtime;
//}
return $ret;
}
// give up and output original files...
return $info->files;
}
/**
* Error handling...
* PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
*/
function initErrorHandling()
{
if (!class_exists('HTML_FlexyFramework2')) {
// what about older code that still users PEAR?
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
}
set_exception_handler(array($this,'onException'));
}
static $permitError = false; // static why?
var $showErrorToUser = true;
function onPearError($err)
{
return $this->onException($err);
}
function onException($ex)
{
static $reported = false;
if ($reported) {
return;
}
if (Pman::$permitError) {
return;
}
$reported = true;
$out = (is_a($ex,'Exception') || is_a($ex, 'Error') ? $ex->getMessage() : $ex->toString()) .
' ' . (empty($_SERVER['REQUEST_METHOD']) ? 'cli' : $_SERVER['REQUEST_METHOD'] ) . ' ' .
(empty($_SERVER['REQUEST_URI']) ? 'No URL' : $_SERVER['REQUEST_URI']) .
' ' . (empty($POST) ? '' : file_get_contents('php://input')) ;
//print_R($bt); exit;
$ret = array();
$n = 0;
$bt = is_a($ex,'Exception')|| is_a($ex, 'Error') ? $ex->getTrace() : $ex->backtrace;
if (is_a($ex,'Exception')|| is_a($ex, 'Error') ) {
$ret[] = $ex->getFile() . '('. $ex->getLine() . ')';
}
foreach( $bt as $b) {
$ret[] = @$b['file'] . '(' . @$b['line'] . ')@' . @$b['class'] . '::' . @$b['function'];
if ($n > 20) {
break;
}
$n++;
}
//convert the huge backtrace into something that is readable..
$out .= "\n" . implode("\n", $ret);
$this->addEvent("EXCEPTION", false, $out);
if ($this->showErrorToUser) {
print_R($out);exit;
}
// not sure why this is here... - perhaps doing a jerr() was actually caught by the UI, and hidden from the user..?
$this->jerror(false,"An error Occured, please contact the website owner");
//$this->jerr($out);
}
/**
* ---------------- Logging ---------------
*/
/**
* addEventOnce:
* Log an action (only if it has not been logged already.
*
* @param {String} action - group/name of event
* @param {DataObject|false} obj - dataobject action occured on.
* @param {String} any remarks
* @return {false|DB_DataObject} Event object.,
*/
function addEventOnce($act, $obj = false, $remarks = '')
{
if (!empty(HTML_FlexyFramework::get()->Pman['disable_events'])) {
return;
}
$e = DB_DataObject::factory('Events');
$e->init($act,$obj,$remarks);
if ($e->find(true)) {
return false;
}
return $this->addEvent($act, $obj, $remarks);
}
/**
* addEvent:
* Log an action.
*
* @param {String} action - group/name of event
* @param {DataObject|false} obj - dataobject action occured on.
* @param {String} any remarks
* @return {DB_DataObject} Event object.,
*/
function addEvent($act, $obj = false, $remarks = '')
{
$ff = HTML_FlexyFramework::get();
if (!empty($ff->Pman['disable_events'])
|| !empty($ff->database_is_readonly)
|| substr($act, 0, 7) === 'NOTICE-'
) {
if (!preg_match('/^(ERROR|EXCEPTION)/', $act)) {
return false;
}
$str = $obj !== false ? "{$obj->tableName()}:{$obj->id} " : '';
$de = ini_set('display_errors', 0);
trigger_error("{$act} {$str} {$remarks}" , E_USER_NOTICE);
ini_set('display_errors', $de );
return false;
}
$au = $this->getAuthUser();
$e = DB_DataObject::factory('Events');
$e->init($act,$obj,$remarks);
$e->event_when = $e->sqlValue('NOW()');
$eid = $e->insert();
// fixme - this should be in onInsert..
$wa = DB_DataObject::factory('core_watch');
if (method_exists($wa,'notifyEvent')) {
$wa->notifyEvent($e); // trigger any actions..
}
$e->onInsert(isset($_REQUEST) ? $_REQUEST : array() , $this);
if (!preg_match('/^(ERROR|EXCEPTION)/', $act)) {
return $e;
}
$str = $obj !== false ? "{$obj->tableName()}:{$obj->id} " : '';
$de = ini_set('display_errors', 0);
trigger_error("{$act} [event_id={$e->id}] {$str} {$remarks}" , E_USER_NOTICE);
ini_set('display_errors', $de );
return $e;
}
function addEventNotifyOnly($act, $obj = false, $remarks = '')
{
$au = $this->getAuthUser();
$e = DB_DataObject::factory('Events');
$e->init($act,$obj,$remarks);
$e->event_when = $e->sqlValue('NOW()');
$wa = DB_DataObject::factory('core_watch');
if (method_exists($wa,'notifyEvent')) {
$wa->notifyEvent($e); // trigger any actions..
}
}
// ------------------ DEPERCIATED ----------------------------
// DEPRECITAED - use moduleslist
function modules() { return $this->modulesList(); }
// DEPRICATED USE Pman_Core_Mailer
function emailTemplate($templateFile, $args)
{
require_once 'Pman/Core/Mailer.php';
$r = new Pman_Core_Mailer(array(
'template'=>$templateFile,
'contents' => $args,
'page' => $this
));
return $r->toData();
}
// DEPRICATED - USE Pman_Core_Mailer
// WHAT Part about DEPRICATED Does no one understand??
function sendTemplate($templateFile, $args)
{
require_once 'Pman/Core/Mailer.php';
$r = new Pman_Core_Mailer(array(
'template'=>$templateFile,
'contents' => array(),
'page' => $this
));
return $r->send();