forked from Open-Web-Analytics/Open-Web-Analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
owa_coreAPI.php
1685 lines (1202 loc) · 41.8 KB
/
owa_coreAPI.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
//
// Open Web Analytics - An Open Source Web Analytics Framework
//
// Copyright 2006 Peter Adams. All rights reserved.
//
// Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $Id$
//
require_once(OWA_BASE_DIR.'/owa_lib.php');
/**
* OWA Core API
*
* @author Peter Adams <[email protected]>
* @copyright Copyright © 2006 Peter Adams <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GPL v2.0
* @category owa
* @package owa
* @version $Revision$
* @since owa 1.0.0
*/
class owa_coreAPI {
// @depricated
// @todo remove
public static function singleton($params = array()) {
static $api;
if(!isset($api)):
$api = new owa_coreAPI();
endif;
if(!empty($params)):
$api->params = $params;
endif;
return $api;
}
public static function setupStorageEngine($type) {
if (!class_exists('owa_db')) {
require_once(OWA_BASE_CLASSES_DIR.'owa_db.php');
}
if ($type) {
$connection_class = "owa_db_" . $type;
if (!class_exists($connection_class)) {
$connection_class_path = OWA_PLUGINS_DIR.'/db/' . $connection_class . ".php";
if (!require_once($connection_class_path)) {
owa_coreAPI::error(sprintf('Cannot locate proper db class at %s.', $connection_class_path));
return false;
}
}
}
return true;
}
/**
* @return owa_db
*/
public static function dbSingleton() {
static $db;
if (!isset($db)) {
$db = owa_coreAPI::dbFactory();
}
return $db;
}
public static function dbFactory() {
$db_type = owa_coreAPI::getSetting('base', 'db_type');
$ret = owa_coreAPI::setupStorageEngine($db_type);
if (!$ret) {
owa_coreAPI::error(sprintf('Cannot locate proper db class at %s. Exiting.', $connection_class_path));
return;
} else {
$connection_class = 'owa_db_'.$db_type;
$db = new $connection_class(
owa_coreAPI::getSetting('base','db_host'),
owa_coreAPI::getSetting('base','db_name'),
owa_coreAPI::getSetting('base','db_user'),
owa_coreAPI::getSetting('base','db_password'),
owa_coreAPI::getSetting('base','db_force_new_connections'),
owa_coreAPI::getSetting('base','db_make_persistant_connections')
);
return $db;
}
}
/**
* @return owa_settings
*/
public static function configSingleton() {
static $config;
if( ! isset( $config ) ) {
if ( ! class_exists( 'owa_settings' ) ) {
require_once( OWA_BASE_CLASS_DIR.'settings.php' );
}
$config = owa_coreAPI::supportClassFactory( 'base', 'settings' );
}
return $config;
}
public static function errorSingleton() {
static $e;
if( ! $e ) {
if ( ! class_exists( 'owa_error' ) ) {
require_once( OWA_BASE_CLASS_DIR.'error.php' );
}
$e = owa_coreAPI::supportClassFactory( 'base', 'error' );
}
return $e;
}
public static function getSetting($module, $name) {
$s = owa_coreAPI::configSingleton();
return $s->get($module, $name);
}
public static function setSetting($module, $name, $value, $persist = false) {
$s = owa_coreAPI::configSingleton();
if ($persist === true) {
$s->persistSetting($module, $name, $value);
} else {
$s->setSetting($module, $name, $value);
}
}
public static function persistSetting($module, $name, $value) {
$s = owa_coreAPI::configSingleton();
$s->persistSetting($module, $name, $value);
}
public static function getSiteSetting($site_id, $name) {
$site = owa_coreAPI::entityFactory('base.site');
$site->load( $site->generateId( $site_id ) );
if ( $site->wasPersisted() ) {
return $site->getSiteSetting($name);
}
}
public static function getRegisteredDomain( $full_domain ) {
static $psl;
if ( ! $psl ) {
$psl = owa_coreAPI::supportClassFactory( 'base', 'pslReader' );
}
return $psl->getRegisteredDomain( $full_domain );
}
public static function persistSiteSetting($site_id, $name, $value) {
$site = owa_coreAPI::entityFactory('base.site');
$site->load( $site->generateId( $site_id ) );
if ( $site->wasPersisted() ) {
$settings = $site->get('settings');
if ( ! $settings ) {
$settings = array();
}
$settings[$name] = $value;
$site->set('settings', $settings);
$site->update();
}
}
public static function getSiteSettings($site_id) {
$site = owa_coreAPI::entityFactory('base.site');
$site->load( $site->generateId( $site_id ) );
if ( $site->wasPersisted() ) {
$settings = $site->get('settings');
if ( $settings ) {
return $settings;
} else {
return array();
}
}
}
public static function getAllRoles() {
$caps = owa_coreAPI::getSetting('base', 'capabilities');
return array_keys($caps);
}
public static function getCapabilities($role) {
$caps = owa_coreAPI::getSetting('base', 'capabilities');
if (array_key_exists($role, $caps)) {
return $caps[$role];
} else {
return array();
}
}
/**
* @return owa_serviceUser
*/
public static function getCurrentUser() {
$s = owa_coreAPI::serviceSingleton();
return $s->getCurrentUser();
}
/**
* check to see if the current user has a capability
* always returns a bool
* @return boolean
*/
public static function isCurrentUserCapable($capability, $site_id = null) {
$cu = owa_coreAPI::getCurrentUser();
owa_coreAPI::debug("Current User Role: ".$cu->getRole());
owa_coreAPI::debug("Current User Authentication: ".$cu->isAuthenticated());
$ret = $cu->isCapable($capability, $site_id);
owa_coreAPI::debug("Is current User capable: ".$ret);
return $ret;
}
public static function isCurrentUserAuthenticated() {
$cu = owa_coreAPI::getCurrentUser();
return $cu->isAuthenticated();
}
/**
* @return owa_service
*/
public static function serviceSingleton() {
static $s;
if(empty($s)) {
if (!class_exists('owa_service')) {
require_once(OWA_BASE_CLASS_DIR.'service.php');
}
$s = owa_coreAPI::supportClassFactory('base', 'service');
}
return $s;
}
public static function cacheSingleton($params = array()) {
static $cache;
if ( !isset ( $cache ) ) {
$cache_type = owa_coreAPI::getSetting('base', 'cacheType');
switch ($cache_type) {
case "memcached":
$implementation = array('owa_memcachedCache', OWA_BASE_CLASS_DIR.'memcachedCache.php');
break;
default:
$implementation = array('owa_fileCache', OWA_BASE_CLASS_DIR.'fileCache.php');
}
if ( ! class_exists( $implementation[0] ) ) {
require_once( $implementation[1] );
}
// make this plugable
$cache = new $implementation[0];
}
return $cache;
}
public static function requestContainerSingleton() {
static $request;
if(!isset($request)):
if (!class_exists('owa_requestContainer')):
require_once(OWA_DIR.'owa_requestContainer.php');
endif;
$request = owa_lib::factory(OWA_DIR, '', 'owa_requestContainer');
endif;
return $request;
}
public static function moduleRequireOnce($module, $class_dir, $file) {
if (!empty($class_dir)) {
$class_dir .= '/';
}
$full_file_path = OWA_BASE_DIR.'/modules/'.$module.'/'.$class_dir.$file.'.php';
if (file_exists($full_file_path)) {
return require_once($full_file_path);
} else {
owa_coreAPI::debug("moduleRequireOnce says no file found at: $full_file_path");
return false;
}
}
public static function moduleFactory($modulefile, $class_suffix = null, $params = '', $class_ns = 'owa_') {
list($module, $file) = explode(".", $modulefile);
$class = $class_ns.$file.$class_suffix;
//print $class;
// Require class file if class does not already exist
if(!class_exists($class)):
owa_coreAPI::moduleRequireOnce($module, '', $file);
endif;
$obj = owa_lib::factory(OWA_BASE_DIR.'/modules/'.$module, '', $class, $params);
//if (isset($obj->module)):
$obj->module = $module;
//endif;
return $obj;
}
public static function moduleGenericFactory($module, $sub_directory, $file, $class_suffix = null, $params = '', $class_ns = 'owa_') {
$class = $class_ns.$file.$class_suffix;
// Require class file if class does not already exist
if(!class_exists($class)):
owa_coreAPI::moduleRequireOnce($module, $sub_directory, $file);
endif;
$obj = owa_lib::factory(OWA_DIR.'modules'.'/'.$module.'/'.$sub_directory, '', $class, $params);
return $obj;
}
/**
* Produces Module Classes (module.php)
*
* @return Object module class object
*/
public static function moduleClassFactory($module) {
if (!class_exists('owa_module')):
require_once(OWA_BASE_CLASSES_DIR.'owa_module.php');
endif;
require_once(OWA_BASE_DIR.'/modules/'.$module.'/module.php');
return owa_lib::factory(OWA_BASE_CLASSES_DIR.$module, 'owa_', $module.'Module');
}
public static function updateFactory($module, $filename, $class_ns = 'owa_') {
require_once(OWA_BASE_CLASS_DIR.'update.php');
//$obj = owa_coreAPI::moduleGenericFactory($module, 'updates', $filename, '_update');
$class = $class_ns.$module.'_'.$filename.'_update';
// Require class file if class does not already exist
if(!class_exists($class)):
owa_coreAPI::moduleRequireOnce($module, 'updates', $filename);
endif;
$obj = owa_lib::factory(OWA_DIR.'modules'.'/'.$module.'/'.'updates', '', $class);
$obj->module_name = $module;
if (!$obj->schema_version) {
$obj->schema_version = $filename;
}
return $obj;
}
public static function subViewFactory($subview, $params = array()) {
list($module, $class) = explode(".", $subview);
//print_r($module.' ' . $class);
//owa_lib::moduleRequireOnce($module, $class);
$subview = owa_lib::moduleFactory($subview, 'View', $params);
$subview->is_subview = true;
return $subview;
}
public static function supportClassFactory($module, $class, $params = array(),$class_ns = 'owa_') {
$obj = owa_lib::factory(OWA_BASE_DIR.'/'.'modules'.'/'.$module.'/'.'classes'.'/', $class_ns, $class, $params);
$obj->module = $module;
return $obj;
}
/**
* Convienence method for generating entities
*
* @param unknown_type $entity_name
* @return unknown
*/
public static function entityFactory($entity_name) {
/* SETUP STORAGE ENGINE */
// Must be called before any entities are created
if (!defined('OWA_DTD_INT')) {
if (defined('OWA_DB_TYPE')) {
owa_coreAPI::setupStorageEngine(OWA_DB_TYPE);
} else {
owa_coreAPI::setupStorageEngine('mysql');
}
}
if (!class_exists('owa_entity')):
require_once(OWA_BASE_CLASSES_DIR.'owa_entity.php');
endif;
$entity = owa_coreAPI::moduleSpecificFactory($entity_name, 'entities', '', '', false);
$entity->name = $entity_name;
return $entity;
//return owa_coreAPI::supportClassFactory('base', 'entityManager', $entity_name);
}
/**
* Convienence method for generating entities
*
* @param unknown_type $entity_name
* @return unknown
* @depricated
* @todo REMOVE
*/
public static function rawEntityFactory($entity_name) {
return owa_coreAPI::entityFactory($entity_name);
}
/**
* Factory for generating module specific classes
*
* @param string $modulefile
* @param string $class_dir
* @param string $class_suffix
* @param array $params
* @return unknown
*/
public static function moduleSpecificFactory($modulefile, $class_dir, $class_suffix = null, $params = '', $add_module_name = true, $class_ns = 'owa_') {
list($module, $file) = explode(".", $modulefile);
$class = $class_ns.$file.$class_suffix;
// Require class file if class does not already exist
if(!class_exists($class)):
owa_coreAPI::moduleRequireOnce($module, $class_dir, $file);
endif;
$obj = owa_lib::factory(OWA_BASE_DIR.'/'.'modules'.'/'.$class_dir.'/'.$module, '', $class, $params);
if ($add_module_name == true):
$obj->module = $module;
endif;
return $obj;
}
public static function executeApiCommand($map) {
if (!array_key_exists('do', $map)) {
echo ("API Command missing from request.");
owa_coreAPI::debug('API Command missing from request. Aborting.');
exit;
} else {
// load service
$s = owa_coreAPI::serviceSingleton();
// lookup method class
$do = $s->getApiMethodClass($map['do']);
}
// if exists, pass to OWA as a request
if ($do) {
if (array_key_exists('args', $do)) {
$passed_args = array();
foreach ($do['args'] as $arg) {
if (isset($map[$arg])) {
$passed_args[] = $map[$arg];
} else {
$passed_args[] = '';
}
}
if (!empty($do['file'])) {
if (!class_exists($do['callback'][0])) {
require_once($file);
}
}
$something = call_user_func_array($do['callback'], $passed_args);
}
return $something;
} else {
echo "No API Method Found.";
}
}
/**
* Convienence method for generating metrics
*
* @param unknown_type $entity_name
* @return unknown
*/
public static function metricFactory($metric_name, $params = array()) {
if (!strpos($metric_name, '.')) {
$s = owa_coreAPI::serviceSingleton();
$metric_name = $s->getMetricClasses($metric_name);
}
if (!class_exists('owa_metric')) {
require_once(OWA_BASE_CLASSES_DIR.'owa_metric.php');
}
return owa_coreAPI::moduleSpecificFactory($metric_name, 'metrics', '', $params, false);
}
/**
* Returns a consolidated list of admin/options panels from all active modules
*
* @return array
*/
public static function getAdminPanels() {
$panels = array();
$service = owa_coreAPI::serviceSingleton();
foreach ($service->modules as $k => $v) {
$v->registerAdminPanels();
$module_panels = $v->getAdminPanels();
if ($module_panels) {
foreach ($module_panels as $key => $value) {
$panels[$value['group']][] = $value;
}
}
}
return $panels;
}
/**
* Returns a consolidated list of nav links from all active modules for a particular view
* and named navigation element.
*
* @param string nav_name the name of the navigation element that you want links for
* @param string sortby the array value to sort the navigation array by
* @return array
*/
public static function getNavigation($view, $nav_name, $sortby ='order') {
$links = array();
$service = owa_coreAPI::serviceSingleton();
foreach ($service->modules as $k => $v) {
// If the module does not have nav links, register them. needed in case this function is called twice on
// same view.
if (empty($v->nav_links)):
$v->registerNavigation();
endif;
$module_nav = $v->getNavigationLinks();
if (!empty($module_nav)) {
// assemble the navigation for a specific view's named navigation element'
foreach ($module_nav as $key => $value) {
$links[$value['view']][$value['nav_name']][] = $value;
}
}
}
//print_r($links[$view][$nav_name]);
if (!empty($links[$view][$nav_name])):
// anonymous sorting function, takes sort by variable.
$code = "return strnatcmp(\$a['$sortby'], \$b['$sortby']);";
// sort the array
$ret = usort($links[$view][$nav_name], create_function('$a,$b', $code));
return $links[$view][$nav_name];
else:
return false;
endif;
}
public static function getGroupNavigation($group_name, $sortby ='order') {
$links = array();
$service = owa_coreAPI::serviceSingleton();
foreach ($service->modules as $k => $v) {
// If the module does not have nav links, register them. needed in case this function is called twice on
// same view.
if ( empty( $v->nav_links ) ) {
$v->registerNavigation();
}
$module_nav = $v->getNavigationLinks();
if ( $module_nav ) {
//loop through returned nav array
foreach ( $module_nav as $group => $nav_links ) {
foreach ( $nav_links as $subgroup => $link ) {
// check to see if group exists
if ( array_key_exists( $group, $links ) ) {
// check to see if subgroup is already present in the main array
if ( array_key_exists( $subgroup, $links[ $group ] ) ) {
// merge various elements?? not now.
//check to see if there is an existing set of subgroup links
if ( array_key_exists( 'subgroup', $links[ $group ][ $subgroup ] ) ) {
// if so, merge the subgroups
$links[ $group ][ $subgroup ][ 'subgroup' ] = array_merge( $links[ $group ][ $subgroup ][ 'subgroup' ], $link[ 'subgroup' ] );
} else {
}
} else {
// else populate the link
$links[$group][$subgroup] = $link;
}
} else {
$links[$group][$subgroup] = $link;
}
}
}
}
}
if ( isset( $links[$group_name] ) ) {
return $links[$group_name];
}
}
/**
* @Todo REMOVE
*/
public static function getNavSort($a, $b) {
return strnatcmp($a['order'], $b['order']);
}
public static function getActiveModules() {
$c = owa_coreAPI::configSingleton();
$config = $c->config->get('settings');
$active_modules = array();
foreach ($config as $k => $module) {
if ( isset($module['is_active']) && $module['is_active'] == true) {
$active_modules[] = $k;
}
}
return $active_modules;
}
public static function getModulesNeedingUpdates() {
$service = owa_coreAPI::serviceSingleton();
return $service->getModulesNeedingUpdates();
}
/**
* Invokes controller to perform controller
*
* @param $action string
*
*/
public static function performAction($action, $params = array()) {
// Load action from service map
$service = owa_coreAPI::serviceSingleton();
$action_map = $service->getMapValue('actions', $action );
// create the controller object
if ( $action_map ) {
$controller = owa_lib::simpleFactory( $action_map['class_name'], $action_map['file'], $params );
} else {
// attempt to use old style convention
$controller = owa_coreAPI::moduleFactory($action, 'Controller', $params);
}
if ( ! $controller || ! method_exists( $controller, 'doAction' ) ) {
owa_coreAPI::debug("No controller is associated with $action.");
return;
}
// call the doAction method which is part of the abstract controller class
// inherited by all other controller classes
$data = $controller->doAction();
// Display view if controller calls for one.
if ( ! empty( $data['view'] ) || ! empty( $data['action'] ) ) {
// Redirect to a view
if ( $data['view_method'] == 'redirect' ) {
return owa_lib::redirectToView( $data );
// return an image . Will output headers and binary data.
} elseif ( $data['view_method'] == 'image' ) {
return owa_coreAPI::displayImage( $data );
} else {
return owa_coreAPI::displayView( $data );
}
} elseif( ! empty( $data['do'] ) ) {
return owa_lib::redirectToView( $data );
}
}
/**
* Logs an event to the event queue
*
* take an owa_event object as a message.
*
* @param string $event_type
* @param object $message
* @return boolean
*/
public static function logEvent($event_type, $message = '') {
// debug
owa_coreAPI::debug("logging event $event_type");
if (owa_coreAPI::getSetting('base', 'error_log_level') > 9) {
owa_coreAPI::debug("PHP Server Global: ".print_r($_SERVER, true));
}
// Check to see if named users should be logged
if (owa_coreAPI::getSetting('base', 'log_named_users') != true) {
$cu = owa_coreAPI::getCurrentUser();
$cu_user_id = $cu->getUserData('user_id');
if(!empty($cu_user_id)) {
return false;
}
}
// do not log if the request is robotic
$service = owa_coreAPI::serviceSingleton();
$bcap = $service->getBrowscap();
owa_coreAPI::profile(__CLASS__, __FUNCTION__, __LINE__);
if (!owa_coreAPI::getSetting('base', 'log_robots')) {
if ($bcap->robotCheck()) {
owa_coreAPI::debug("ABORTING: request appears to be from a robot");
owa_coreAPI::setRequestParam('is_robot', true);
return;
}
owa_coreAPI::profile(__CLASS__, __FUNCTION__, __LINE__);
}
// form event if one was not passed
$class= 'owa_event';
if (!($message instanceof $class)) {
$event = owa_coreAPI::supportClassFactory('base', 'event');
$event->setProperties($message);
$event->setEventType($event_type);
} else {
$event = $message;
}
// STAGE 1 - set environmental properties from SERVER
$teh = owa_coreAPI::getInstance( 'owa_trackingEventHelpers', OWA_BASE_CLASS_DIR.'trackingEventHelpers.php');
$environmentals = $service->getMap( 'tracking_properties_environmental' );
$teh->setTrackerProperties( $event, $environmentals );
// Filter XSS exploits from event properties
//$event->cleanProperties();
// do not log if the do not log property is set on the event.
if ($event->get('do_not_log')) {
return false;
}
// check to see if IP should be excluded
if ( owa_coreAPI::isIpAddressExcluded( $event->get('ip_address') ) ) {
owa_coreAPI::debug("Not logging event. IP address found in exclusion list.");
return false;
}
// queue for later or process event straight away
if ( owa_coreAPI::getSetting( 'base', 'queue_events' ) ||
owa_coreAPI::getSetting( 'base', 'queue_incoming_tracking_events' ) ) {
$q = owa_coreAPI::getEventQueue( 'incoming_tracking_events' );
owa_coreAPI::debug('Queuing '.$event->getEventType().' event with properties: '.print_r($event->getProperties(), true ) );
$q->sendMessage( $event );
} else {
// lookup which event processor to use to process this event type
$processor_action = owa_coreAPI::getEventProcessor( $event->getEventType() );
return owa_coreAPI::handleRequest( array( 'event' => $event ), $processor_action );
}
}
public static function getInstance( $class, $path ) {
if ( ! class_exists( $class ) ) {
require_once( $path );
}
return $class::getInstance();
}
public static function displayImage($data) {
header('Content-type: image/gif');
header('P3P: CP="'.owa_coreAPI::getSetting('base', 'p3p_policy').'"');
header('Expires: Sat, 22 Apr 1978 02:19:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
echo owa_coreAPI::displayView($data);
}
/**
* Displays a View without user authentication. Takes array of data as input
*
* @param array $data
* @param string $viewfile a specific view file to use
* @return string
*
*/
public static function displayView($data, $viewfile = '') {
if (empty($viewfile)):
$viewfile = $data['view'];
endif;
$view = owa_coreAPI::moduleFactory($viewfile, 'View');
$view->setData($data);
return $view->assembleView($data);
}
public static function displaySubView($data, $viewfile = '') {
if (empty($viewfile)):
$viewfile = $data['view'];
endif;
$view = owa_coreAPI::subViewFactory($viewfile);
return $view->assembleView($data);
}
/**
* Strip a URL of certain GET params
* @depricated
* @return string
* @todo REMOVE
*/
function stripDocumentUrl($url) {
if (owa_coreAPI::getSetting('base', 'clean_query_string')):
if (owa_coreAPI::getSetting('base', 'query_string_filters')):
$filters = str_replace(' ', '', owa_coreAPI::getSetting('base', 'query_string_filters'));
$filters = explode(',', $filters);
else:
$filters = array();
endif;
// OWA specific params to filter
array_push($filters, owa_coreAPI::getSetting('base', 'source_param'));
array_push($filters, owa_coreAPI::getSetting('base', 'ns').owa_coreAPI::getSetting('base', 'feed_subscription_param'));
//print_r($filters);
foreach ($filters as $filter => $value) {
$url = preg_replace(
'#\?' .
$value .
'=.*$|&' .
$value .
'=.*$|' .
$value .
'=.*&#msiU',
'',
$url
);
}
endif;
//print $url;