-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
e107_class.php
executable file
·5262 lines (4483 loc) · 148 KB
/
e107_class.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
/*
* e107 website system
*
* Copyright (C) 2008-2012 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* e107 Main
*
* $URL$
* $Id$
*/
if (!defined('e107_INIT')) { exit; }
/**
*
* @package e107
* @category e107_handlers
* @version $Id$
* @author e107inc
*
* e107_class - core class with many system-related methods
*/
class e107
{
/**
* IPV6 string for localhost - as stored in DB
*/
const LOCALHOST_IP = '0000:0000:0000:0000:0000:ffff:7f00:0001';
const LOCALHOST_IP2 = '0000:0000:0000:0000:0000:0000:0000:0001';
public $server_path;
public $e107_dirs = array();
/**
* @var array SQL connection data
*/
protected $e107_config_mysql_info = array();
public $http_path;
public $https_path;
public $base_path;
public $file_path;
public $site_path;
public $relative_base_path;
public $_ip_cache;
public $_host_name_cache;
public $site_theme; // class2 -> check valid theme
public $http_theme_dir; // class2 -> check valid theme
/**
* Contains reference to global $_E107 array
* Assignment is done inside prepare_request() method
*
* @var array
*/
protected $_E107 = array();
/**
* @var string Current request type (http or https)
*/
protected $HTTP_SCHEME;
/**
* Used for runtime caching of user extended struct
*
* @var array
* @see e107::user()
*/
public $extended_struct;
/**
* User login name
*
* @var array
* @see init_session()
*/
public $currentUser;
/**
* Run once load core shortcodes
* while initialize SC parser
*
* @var boolean
*/
protected static $_sc_core_loaded = false;
/**
* Singleton instance
* Allow class extends - override {@link getInstance()}
*
* @var e107
*/
protected static $_instance = null;
/**
* e107 registry
*
* @var array
*/
private static $_registry = array();
/**
* e107 core config object storage
*
* @var array
*/
protected static $_core_config_arr = array();
/**
* e107 plugin config object storage
*
* @var array
*/
protected static $_plug_config_arr = array();
/**
* e107 theme config object storage
*
* @var array
*/
protected static $_theme_config_arr = array();
/**
* e107 e107::css() on/off flag.
*
* @var bool
*/
protected static $_css_enabled = true;
/**
* e107 e107::js() on/off flag.
*
* @var bool
*/
protected static $_js_enabled = true;
protected static $_breadcrumb = array();
/**
* Core handlers array
* For new/missing handler add
* 'class name' => 'path' pair
*
* Used to auto-load core/plugin handlers
* NOTE: aplhabetically sorted! (by class name)
*
* @see addHandler()
* @see setHandlerOverload()
* @see getSingleton()
* @see getObject()
* @var array
*/
protected static $_known_handlers = array(
'UserHandler' => '{e_HANDLER}user_handler.php',
'comment' => '{e_HANDLER}comment_class.php',
'e_date' => '{e_HANDLER}date_handler.php',
'convert' => '{e_HANDLER}date_handler.php', // BC Fix.
'db' => '{e_HANDLER}e_db_pdo_class.php',
// 'db' => '{e_HANDLER}mysql_class.php',
'e107Email' => '{e_HANDLER}mail.php',
'e107_event' => '{e_HANDLER}event_class.php',
'e107_db_debug' => '{e_HANDLER}db_debug_class.php',
'e107_traffic' => '{e_HANDLER}traffic_class.php',
'e107_user_extended' => '{e_HANDLER}user_extended_class.php',
'e107plugin' => '{e_HANDLER}plugin_class.php',
'e_chart' => '{e_HANDLER}chart_class.php',
'e_core_session' => '{e_HANDLER}session_handler.php',
'e_admin_controller' => '{e_HANDLER}admin_ui.php',
'e_admin_controller_ui' => '{e_HANDLER}admin_ui.php',
'e_admin_dispatcher' => '{e_HANDLER}admin_ui.php',
'e_admin_form_ui' => '{e_HANDLER}admin_ui.php',
'e_admin_log' => '{e_HANDLER}admin_log_class.php',
'e_front_model' => '{e_HANDLER}model_class.php',
'e_admin_model' => '{e_HANDLER}model_class.php',
'e_admin_request' => '{e_HANDLER}admin_ui.php',
'e_admin_response' => '{e_HANDLER}admin_ui.php',
'e_admin_ui' => '{e_HANDLER}admin_ui.php',
'e_ajax_class' => '{e_HANDLER}e_ajax_class.php',
'e_array' => '{e_HANDLER}core_functions.php', // Old ArrayStorage.
'e_bbcode' => '{e_HANDLER}bbcode_handler.php',
'e_bb_base' => '{e_HANDLER}bbcode_handler.php',
'e_customfields' => '{e_HANDLER}e_customfields_class.php',
'e_file' => '{e_HANDLER}file_class.php',
'e_form' => '{e_HANDLER}form_handler.php',
'e_jshelper' => '{e_HANDLER}js_helper.php',
'e_media' => '{e_HANDLER}media_class.php',
'e_menu' => '{e_HANDLER}menu_class.php',
'e_model' => '{e_HANDLER}model_class.php',
'e_navigation' => '{e_HANDLER}sitelinks_class.php',
'e_news_item' => '{e_HANDLER}news_class.php',
'e_news_tree' => '{e_HANDLER}news_class.php',
'e_news_category_tree' => '{e_HANDLER}news_class.php',
'e_object' => '{e_HANDLER}model_class.php',
'e_online' => '{e_HANDLER}online_class.php',
'e_parse' => '{e_HANDLER}e_parse_class.php',
'e_parser' => '{e_HANDLER}e_parse_class.php',
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php',
'e_plugin' => '{e_HANDLER}plugin_class.php',
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
'e_system_user' => '{e_HANDLER}user_model.php',
'e_theme' => '{e_HANDLER}theme_handler.php',
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
'e_user_model' => '{e_HANDLER}user_model.php',
'e_user' => '{e_HANDLER}user_model.php',
'e_user_extended_structure_tree' => '{e_HANDLER}user_model.php',
'e_userperms' => '{e_HANDLER}user_handler.php',
'e_validator' => '{e_HANDLER}validator_class.php',
'e_vars' => '{e_HANDLER}model_class.php',
'e_url' => '{e_HANDLER}application.php',
'ecache' => '{e_HANDLER}cache_handler.php',
'eController' => '{e_HANDLER}application.php',
'eDispatcher' => '{e_HANDLER}application.php',
'eException' => '{e_HANDLER}application.php',
'eFront' => '{e_HANDLER}application.php',
'eHelper' => '{e_HANDLER}application.php',
'eIPHandler' => '{e_HANDLER}iphandler_class.php',
'email_validation_class' => '{e_HANDLER}mail_validation_class.php',
'eMessage' => '{e_HANDLER}message_handler.php',
'eRequest' => '{e_HANDLER}application.php',
'eResponse' => '{e_HANDLER}application.php',
'eRouter' => '{e_HANDLER}application.php',
'eShims' => '{e_HANDLER}Shims/eShims.php',
'eUrl' => '{e_HANDLER}e107Url.php',
'eUrlConfig' => '{e_HANDLER}application.php',
'eUrlRule' => '{e_HANDLER}application.php',
'Hybrid_Auth' => '{e_HANDLER}hybridauth/Hybrid/Auth.php',
'language' => '{e_HANDLER}language_class.php',
'news' => '{e_HANDLER}news_class.php',
'notify' => '{e_HANDLER}notify_class.php',
'override' => '{e_HANDLER}override_class.php',
'rater' => '{e_HANDLER}rate_class.php',
'redirection' => '{e_HANDLER}redirection_class.php',
'secure_image' => '{e_HANDLER}secure_img_handler.php',
'sitelinks' => '{e_HANDLER}sitelinks_class.php',
'themeHandler' => '{e_HANDLER}theme_handler.php',
'user_class' => '{e_HANDLER}userclass_class.php',
'user_class_admin' => '{e_HANDLER}userclass_class.php',
'userlogin' => '{e_HANDLER}login.php',
'validatorClass' => '{e_HANDLER}validator_class.php',
'xmlClass' => '{e_HANDLER}xml_class.php',
'e107MailManager' => '{e_HANDLER}mail_manager_class.php',
'e_library_manager' => '{e_HANDLER}library_manager.php',
'error_page' => '{e_HANDLER}error_page_class.php',
);
/**
* Overload core handlers array
* Format: 'core_class' => array('overload_class', 'overload_path');
*
* NOTE: to overload core singleton objects, you have to add record to
* $_overload_handlers before the first singleton call.
*
* Example:
* <code> array('e_form' => array('plugin_myplugin_form_handler' => '{e_PLUGIN}myplugin/includes/form/handler.php'));</code>
*
* Used to auto-load core handlers
*
* @var array
*/
protected static $_overload_handlers = array();
/**
* Constructor
*
* Use {@link getInstance()}, direct instantiating
* is not possible for singleton objects
*
*/
protected function __construct()
{
// FIXME registered shutdown functions not executed after the $page output in footer - investigate
// Currently manually called in front-end/admin footer
//register_shutdown_function(array($this, 'destruct'));
}
/**
* Cloning is not allowed
*
*/
private function __clone()
{
}
/**
* Get singleton instance (php4 no more supported)
*
* @return e107
*/
public static function getInstance()
{
if(null == self::$_instance)
{
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Initialize environment path constants
* Public proxy to the protected method {@link _init()}
*
* @param $e107_paths
* @param $e107_root_path
* @param $e107_config_mysql_info
* @param array $e107_config_override
* @return e107
*/
public function initCore($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override = array())
{
return $this->_init($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override);
}
/**
* Initialize environment path constants while installing e107
*
* @param $e107_paths
* @param $e107_root_path
* @param array $e107_config_override
* @return e107
*/
public function initInstall($e107_paths, $e107_root_path, $e107_config_override = array())
{
$e107_config = 'e107_config.php';
if (!file_exists($e107_config)) // prevent blank-page with missing file during install.
{
if(file_put_contents($e107_config, '')===false)
{
return false;
}
}
// Do some security checks/cleanup, prepare the environment
$this->prepare_request();
//generated from mysql data at stage 5 of install.
$this->site_path = isset($e107_config_override['site_path']) ? $e107_config_override['site_path'] : "[hash]"; // placeholder
// folder info
//$this->e107_dirs = $e107_paths;
$this->setDirs($e107_paths, $e107_config_override);
// build all paths
$this->set_paths();
$this->file_path = $this->fix_windows_paths($e107_root_path)."/";
// set base path, SSL is auto-detected
$this->set_base_path();
// cleanup QUERY_STRING and friends, set related constants
$this->set_request();
// set some core URLs (e_LOGIN/SIGNUP)
$this->set_urls();
return $this;
}
/**
* Resolve paths, will run only once
*
* @param $e107_paths
* @param $e107_root_path
* @param $e107_config_mysql_info
* @param array $e107_config_override
* @return e107
*/
protected function _init($e107_paths, $e107_root_path, $e107_config_mysql_info, $e107_config_override = array())
{
if(!empty($this->e107_dirs)) return $this;
// Do some security checks/cleanup, prepare the environment
$this->prepare_request();
// mysql connection info
$this->e107_config_mysql_info = $e107_config_mysql_info;
// unique folder for e_MEDIA - support for multiple websites from single-install. Must be set before setDirs()
/* if (!empty($e107_config_override['site_path']))
{
// $E107_CONFIG['site_path']
$this->site_path = $e107_config_override['site_path'];
}*/
if(empty($e107_config_override['site_path']))
{
$this->site_path = $this->makeSiteHash($e107_config_mysql_info['mySQLdefaultdb'], $e107_config_mysql_info['mySQLprefix']);
}
// Set default folder (and override paths) if missing from e107_config.php
$this->setDirs($e107_paths, $e107_config_override);
// various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
$this->set_constants();
// build all paths
$this->set_paths();
$this->file_path = $this->fix_windows_paths($e107_root_path);
// set base path, SSL is auto-detected
$this->set_base_path();
// cleanup QUERY_STRING and friends, set related constants
$this->set_request();
// set some core URLs (e_LOGIN/SIGNUP)
$this->set_urls();
if(!is_dir(e_SYSTEM))
{
mkdir(e_SYSTEM, 0755, true);
}
if(!is_dir(e_CACHE_IMAGE))
{
mkdir(e_CACHE_IMAGE, 0755, true);
}
// Prepare essential directories.
$this->prepareDirs();
return $this;
}
/**
* Create a unique hash for each database configuration (multi-site support).
*/
function makeSiteHash($db, $prefix) // also used by install.
{
return substr(md5($db . "." . $prefix), 0, 10);
}
/**
* Set system folders and override paths
* $e107_paths is the 'compact' version of e107_config folder vars ($ADMIN_DIRECTORY, $IMAGES_DIRECTORY, etc)
* $e107_config_override is the new override method - it can do it for all server and http paths via
* the newly introduced $E107_CONFIG array.
*
* Overriding just replace _DIRECTORY with _SERVER or _HTTP:
* - override server path example:
* <code>$E107_CONFIG['SYSTEM_SERVER'] = '/home/user/system/';</code>
*
* - override http path example:
* <code>$E107_CONFIG['MEDIA_VIDEOS_HTTP'] = 'http://static.mydomain.com/videos/';</code>
*
* @param array $e107_dirs Override folder instructions (*_DIRECTORY vars - e107_config.php)
* @param array $e107_config_override Override path insructions ($E107_CONFIG array - e107_config.php)
* @return e107
*/
public function setDirs($e107_dirs, $e107_config_override = array())
{
if(!empty($e107_config_override['site_path'])) // $E107_CONFIG['site_path']
{
$this->site_path = $e107_config_override['site_path'];
}
$override = array_merge((array) $e107_dirs, (array) $e107_config_override);
// override all
$this->e107_dirs = array_merge($this->defaultDirs($override), $override);
// Required for e_MEDIA_BASE, e_SYSTEM_BASE (free of site path constants);
// $this->e107_dirs['MEDIA_BASE_DIRECTORY'] = $this->e107_dirs['MEDIA_DIRECTORY'];
// $this->e107_dirs['SYSTEM_BASE_DIRECTORY'] = $this->e107_dirs['SYSTEM_BASE_DIRECTORY'];
// FIXME - remove this condition because:
// $this->site_path is appended to MEDIA_DIRECTORY in defaultDirs(), which is called above.
if(strpos($this->e107_dirs['MEDIA_DIRECTORY'],$this->site_path) === false)
{
$this->e107_dirs['MEDIA_DIRECTORY'] .= $this->site_path."/"; // multisite support.
}
// FIXME - remove this condition because:
// $this->site_path is appended to SYSTEM_DIRECTORY in defaultDirs(), which is called above.
if(strpos($this->e107_dirs['SYSTEM_DIRECTORY'],$this->site_path) === false)
{
$this->e107_dirs['SYSTEM_DIRECTORY'] .= $this->site_path."/"; // multisite support.
}
// FIXME Quick fix - override base cache folder for legacy configs (e.g. e107_files/cache), discuss
if(strpos($this->e107_dirs['CACHE_DIRECTORY'], $this->site_path) === false)
{
$this->e107_dirs['CACHE_DIRECTORY'] = $this->e107_dirs['SYSTEM_DIRECTORY']."cache/"; // multisite support.
}
return $this;
}
/**
* Prepares essential directories.
*/
public function prepareDirs()
{
$file = e107::getFile();
// Essential directories which should be created and writable.
$essential_directories = array(
'MEDIA_DIRECTORY',
'SYSTEM_DIRECTORY',
'CACHE_DIRECTORY',
'CACHE_CONTENT_DIRECTORY',
'CACHE_IMAGE_DIRECTORY',
'CACHE_DB_DIRECTORY',
'CACHE_URL_DIRECTORY',
'LOGS_DIRECTORY',
'BACKUP_DIRECTORY',
'TEMP_DIRECTORY',
'IMPORT_DIRECTORY',
);
// Create directories which don't exist.
foreach($essential_directories as $directory)
{
if (!isset($this->e107_dirs[$directory])) {
continue;
}
$path = e_ROOT . $this->e107_dirs[$directory];
$file->prepareDirectory($path, FILE_CREATE_DIRECTORY);
}
}
/**
* Get default e107 folders, root folders can be overridden by passed override array
*
* @param array $override_root
* @param boolean $return_root
* @return array
*/
public function defaultDirs($override_root = array(), $return_root = false)
{
$ret = array_merge(array(
'ADMIN_DIRECTORY' => 'e107_admin/',
'IMAGES_DIRECTORY' => 'e107_images/',
'THEMES_DIRECTORY' => 'e107_themes/',
'PLUGINS_DIRECTORY' => 'e107_plugins/',
'FILES_DIRECTORY' => 'e107_files/', // DEPRECATED!!!
'HANDLERS_DIRECTORY' => 'e107_handlers/',
'LANGUAGES_DIRECTORY' => 'e107_languages/',
'DOCS_DIRECTORY' => 'e107_docs/',
'MEDIA_DIRECTORY' => 'e107_media/',
'SYSTEM_DIRECTORY' => 'e107_system/',
'CORE_DIRECTORY' => 'e107_core/',
'WEB_DIRECTORY' => 'e107_web/',
), (array) $override_root);
$ret['MEDIA_BASE_DIRECTORY'] = $ret['MEDIA_DIRECTORY'];
$ret['SYSTEM_BASE_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'];
$ret['MEDIA_DIRECTORY'] .= $this->site_path."/"; // multisite support.
$ret['SYSTEM_DIRECTORY'] .= $this->site_path."/"; // multisite support.
if($return_root) return $ret;
$ret['HELP_DIRECTORY'] = $ret['DOCS_DIRECTORY'].'help/';
$ret['MEDIA_IMAGES_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'images/';
$ret['MEDIA_ICONS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'icons/';
$ret['MEDIA_VIDEOS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'videos/';
$ret['MEDIA_FILES_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'files/';
$ret['MEDIA_UPLOAD_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/'; // security measure. Media is public, system is private.
$ret['AVATARS_DIRECTORY'] = $ret['MEDIA_DIRECTORY'].'avatars/';
$ret['WEB_JS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'js/';
// $ret['WEB_JS_DIRECTORY'] = $ret['FILES_DIRECTORY'].'jslib/';
$ret['WEB_CSS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'css/';
$ret['WEB_IMAGES_DIRECTORY'] = $ret['WEB_DIRECTORY'].'images/';
// $ret['WEB_PACKS_DIRECTORY'] = $ret['WEB_DIRECTORY'].'packages/';
$ret['DOWNLOADS_DIRECTORY'] = $ret['MEDIA_FILES_DIRECTORY'];
$ret['UPLOADS_DIRECTORY'] = $ret['MEDIA_UPLOAD_DIRECTORY'];
$ret['CACHE_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'cache/';
$ret['CACHE_CONTENT_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'content/';
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
$ret['CACHE_IMAGE_DIRECTORY'] = $ret['MEDIA_IMAGES_DIRECTORY'].'cache/';
}
else
{
$ret['CACHE_IMAGE_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'images/';
}
$ret['CACHE_DB_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'db/';
$ret['CACHE_URL_DIRECTORY'] = $ret['CACHE_DIRECTORY'].'url/';
$ret['AVATARS_UPLOAD_DIRECTORY'] = $ret['AVATARS_DIRECTORY'].'upload/';
$ret['AVATARS_DEFAULT_DIRECTORY'] = $ret['AVATARS_DIRECTORY'].'default/';
$ret['LOGS_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'logs/';
$ret['BACKUP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'backup/';
$ret['TEMP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/';
$ret['IMPORT_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'import/';
return $ret;
}
/**
* Set mysql data
*
* @param $e107_config_mysql_info
* @return e107
*/
public function initInstallSql($e107_config_mysql_info)
{
// mysql connection info
$this->e107_config_mysql_info = $e107_config_mysql_info;
// various constants - MAGIC_QUOTES_GPC, MPREFIX, ...
$this->set_constants();
return $this;
}
/**
* Get data from the registry
* Returns $default if data not found
* Replacement of cachevar()
*
* @param string $id
* @param null $default
* @return mixed
*/
public static function getRegistry($id, $default = null)
{
if(isset(self::$_registry[$id]))
{
return self::$_registry[$id];
}
if($id === '_all_')
{
return self::$_registry;
}
return $default;
}
/**
* Add data to the registry - replacement of getcachedvars().
* $id is path-like unique id bind to the passed data.
* If $data argument is null, $id will be removed from the registry.
* When removing objects from the registry, __destruct() method will be auto-executed
* if available
*
* Naming standards (namespaces):
* 'area/area_id/storage_type'<br>
* where <br>
* - area = 'core'|'plugin'|'external' (everything else)
* - area_id = core handler id|plugin name (depends on area)
* - (optional) storage_type = current data storage stack
*
* Examples:
* - 'core/e107/' - reserved for this class
* - 'core/e107/singleton/' - singleton objects repo {@link getSingleton()}
*
* @param string $id
* @param mixed|null $data
* @param bool $allow_override
*/
public static function setRegistry($id, $data = null, $allow_override = true)
{
if(null === $data)
{
if(isset(self::$_registry[$id]) && is_object(self::$_registry[$id]) && method_exists(self::$_registry[$id], '__destruct'))
{
self::$_registry[$id]->__destruct();
}
unset(self::$_registry[$id]);
return;
}
if(!$allow_override && null !== self::getRegistry($id))
{
return;
}
self::$_registry[$id] = $data;
}
/**
* Get folder name (e107_config)
* Replaces all $(*)_DIRECTORY globals
* Example: <code>$e107->getFolder('images')</code>;
*
* @param string $for
* @return string
*/
public static function getFolder($for)
{
$key = strtoupper($for).'_DIRECTORY';
$self = self::getInstance();
return (isset($self->e107_dirs[$key]) ? $self->e107_dirs[$key] : '');
}
/**
* Get value from $_E107 config array
* Note: will always return false if called before prepare_request() method!
*
* @param string $key
* @return boolean
*/
public static function getE107($key = null)
{
$self = self::getInstance();
if(null === $key) return $self->_E107;
return (isset($self->_E107[$key]) && $self->_E107[$key] ? true : false);
}
/**
* Convenient proxy to $_E107 getter - check if
* the system is currently running in cli mode
* Note: will always return false if called before prepare_request() method!
*
* @return boolean
*/
public static function isCli()
{
return self::getE107('cli');
}
/**
* Get mysql config var (e107_config.php)
* Replaces all $mySQL(*) globals
* Example: <code>$e107->getMySQLConfig('prefix');</code>
*
* @param string $for prefix|server|user|password|defaultdb - leave blank for full array.
* @return string|array
*/
public static function getMySQLConfig($for='')
{
$key = 'mySQL'.$for;
$self = self::getInstance();
if($for == '')
{
return $self->e107_config_mysql_info;
}
return (isset($self->e107_config_mysql_info[$key]) ? $self->e107_config_mysql_info[$key] : '');
}
/**
* Return a unique path based on database used. ie. multi-site support from single install.
*
* @return string
* @author
*/
function getSitePath()
{
$self = self::getInstance();
return $self->site_path;
}
/**
* Get known handler path
*
* @param string $class_name
* @param boolean $parse_path [optional] parse path shortcodes
* @return string|null
*/
public static function getHandlerPath($class_name, $parse_path = true)
{
$ret = isset(self::$_known_handlers[$class_name]) ? self::$_known_handlers[$class_name] : null;
if($parse_path && $ret)
{
$ret = self::getParser()->replaceConstants($ret);
}
return $ret;
}
/**
* Add handler to $_known_handlers array on runtime
* If class name is array, method will add it (recursion) and ignore $path argument
*
* @param array|string $class_name
* @param string $path [optional]
* @return void
*/
public static function addHandler($class_name, $path = '')
{
if(is_array($class_name))
{
foreach ($class_name as $cname => $path)
{
self::addHandler($cname, $path);
}
return;
}
if(!self::isHandler($class_name))
{
self::$_known_handlers[$class_name] = $path;
}
}
/**
* Check handler presence
*
* @param string $class_name
* @return boolean
*/
public static function isHandler($class_name)
{
return isset(self::$_known_handlers[$class_name]);
}
/**
* Get overlod class and path (if any)
*
* @param string $class_name
* @param bool|object $default_handler [optional] return data from $_known_handlers if no overload data available
* @param bool|object $parse_path [optional] parse path shortcodes
* @return array
*/
public static function getHandlerOverload($class_name, $default_handler = true, $parse_path = true)
{
$ret = (isset(self::$_overload_handlers[$class_name]) ? self::$_overload_handlers[$class_name] : ($default_handler ? array($class_name, self::getHandlerPath($class_name, false)) : array()));
if ($parse_path && isset($ret[1]))
{
$ret[1] = self::getParser()->replaceConstants($ret[1]);
}
return $ret;
}
/**
* Overload present handler.
* If class name is array, method will add it (recursion) and
* ignore $overload_class_name and $overload_path arguments
*
* @param string $class_name
* @param string $overload_class_name [optional]
* @param string $overload_path [optional]
* @return void
*/
public static function setHandlerOverload($class_name, $overload_class_name = '', $overload_path = '')
{
if(is_array($class_name))
{
foreach ($class_name as $cname => $overload_array)
{
self::setHandlerOverload($cname, $overload_array[0], $overload_array[1]);
}
return;
}
if(self::isHandler($class_name) && !self::isHandlerOverloadable($class_name))
{
self::$_overload_handlers[$class_name] = array($overload_class_name, $overload_path);
}
}
/**
* Check if handler is already overloaded
*
* @param string $class_name
* @return boolean
*/
public static function isHandlerOverloadable($class_name)
{
return isset(self::$_overload_handlers[$class_name]);
}
/**
* Retrieve singleton object
*
* @param string $class_name
* @param string|boolean $path optional script path
* @param string $regpath additional registry path
* @return Object
*/
public static function getSingleton($class_name, $path = true, $regpath = '',$vars=null)
{
$id = 'core/e107/singleton/'.$class_name.$regpath;
if(!empty($vars))
{
$id .= '/';
$id .= is_array($vars) ? crc32(serialize($vars)): crc32($vars);
}
//singleton object found - overload not possible
if(self::getRegistry($id))
{
return self::getRegistry($id);
}
//auto detection + overload check
if(is_bool($path))
{
//overload allowed
if(true === $path && self::isHandlerOverloadable($class_name))
{
$tmp = self::getHandlerOverload($class_name);
$class_name = $tmp[0];
$path = $tmp[1];
}
//overload not allowed
else
{
$path = self::getHandlerPath($class_name);
}
}
if($path && is_string($path) && !class_exists($class_name, false))
{
global $e107_debug, $_E107;
if(($e107_debug || !empty($_E107['debug']) || (defined('e_DEBUG') && e_DEBUG === true) ))
{
require_once($path);
}
else
{
@require_once($path);
}
// remove the need for external function.
//e107_require_once() is available without class2.php. - see core_functions.php
}
if(class_exists($class_name, false))
{
self::setRegistry($id, new $class_name($vars));
}
return self::getRegistry($id);
}
/**
* Retrieve object
* Prepare for __autoload
*
* @param string $class_name
* @param mixed $arguments
* @param string|boolean $path optional script path
* @return object|null
*/
public static function getObject($class_name, $arguments = null, $path = true)
{
if(true === $path)
{
if(isset(self::$_known_handlers[$class_name]))
{
$path = self::getParser()->replaceConstants(self::$_known_handlers[$class_name]);
}
}
//auto detection + overload check
if(is_bool($path))
{
//overload allowed
if(true === $path && self::isHandlerOverloadable($class_name))
{
$tmp = self::getHandlerOverload($class_name);
$class_name = $tmp[0];
$path = $tmp[1];
}
//overload not allowed
else
{
$path = self::getHandlerPath($class_name);
}
}
if($path && is_string($path) && !class_exists($class_name, false))
{
e107_require_once($path); //no existence/security checks here!
}
if(class_exists($class_name, false))
{
if(null !== $arguments) return new $class_name($arguments);
return new $class_name();
}
trigger_error("Class {$class_name} not found!", E_USER_ERROR);
return null;
}