forked from Open-Web-Analytics/Open-Web-Analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
owa_caller.php
312 lines (229 loc) · 9.14 KB
/
owa_caller.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
<?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$
//
include_once('owa_env.php');
require_once(OWA_BASE_DIR.'/owa_base.php');
require_once(OWA_BASE_DIR.'/owa_requestContainer.php');
require_once(OWA_BASE_DIR.'/owa_auth.php');
require_once(OWA_BASE_DIR.'/owa_coreAPI.php');
require_once(OWA_BASE_CLASS_DIR.'error.php');
/**
* Abstract Caller class used to build application specific invocation classes
*
* @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_caller extends owa_base {
/**
* Request Params from get or post
*
* @var array
*/
var $params;
var $start_time;
var $end_time;
var $update_required;
var $service;
var $site_id;
/**
* Constructor
*
* @param array $config
* @return owa_caller
*/
function __construct( $config = [] ) {
/* PHP ERROR LOGGING */
if ( owa_lib::inDebug() ) {
owa_error::phpErrorSettings();
}
// Start time
$this->start_time = owa_lib::microtime_float();
/* SETUP CONFIGURATION AND ERROR LOGGER */
// Parent Constructor. Sets default config entity and error logger
parent::__construct();
// Log version debug
owa_coreAPI::debug(sprintf('*** Starting Open Web Analytics v%s. Running under PHP v%s (%s) ***', OWA_VERSION, PHP_VERSION, PHP_OS));
if ( array_key_exists('REQUEST_URI', $_SERVER ) ) {
owa_coreAPI::debug( 'Request URL:' . $_SERVER['REQUEST_METHOD'] .' '.$_SERVER['REQUEST_URI'] );
}
if ( array_key_exists('HTTP_USER_AGENT', $_SERVER ) ) {
owa_coreAPI::debug( 'User Agent: '.$_SERVER['HTTP_USER_AGENT'] );
}
if ( array_key_exists('HTTP_HOST', $_SERVER ) ) {
owa_coreAPI::debug( 'Host: '.$_SERVER['HTTP_HOST'] );
}
// load config values from DB
// Applies config from db or cache
// check here is needed for installs when the configuration table does not exist.
if ( $this->c->isConfigFilePresent() && ! owa_coreAPI::getSetting('base', 'useStaticConfigOnly') ) {
$this->c->load( $this->c->get( 'base', 'configuration_id' ) );
}
// set timezone once config is loaded from DB.
$this->c->setTimezone();
/* APPLY CALLER CONFIGURATION OVERRIDES */
// overrides all default and user config values except defined in the config file
// must come after user overides are applied
// This will apply configuration overirdes that are specified by the calling application.
// This is usually used by plugins to setup integration specific configuration values.
$this->overloadConfig( $config );
/* SET ERROR HANDLER */
// Sets the correct mode of the error logger now that final config values are in place
// This will flush buffered msgs that were thrown up untill this point
$this->e->setHandler($this->c->get('base', 'error_handler'));
/* LOAD SERVICE LAYER */
$this->service = owa_coreAPI::serviceSingleton();
// initialize framework
$this->service->initializeFramework();
// notify handlers of 'init' action
$dispatch = owa_coreAPI::getEventDispatch();
$dispatch->notify($dispatch->makeEvent('init'));
/* SET SITE ID */
// needed in standalone installs where site_id is not set in config file.
// still needed??????
if (!empty($this->params['site_id'])) {
$this->c->set('base', 'site_id', $this->params['site_id']);
}
// re-fetch the array now that overrides have been applied.
// needed for backwards compatability
$this->config = $this->c->fetch('base');
/* SETUP REQUEST Params */
// still needed?????
$this->params = $this->service->request->getAllOwaParams();
}
function handleRequestFromUrl() {
//$this->params = owa_lib::getRequestParams();
return $this->handleRequest();
}
/**
* Returns a configured javascript tracker for inclusion in your web page.
* You can pass an options array to control what the tracker will log.
* The options array is a key/value pair format like:
*
* $options = array('do_not_log_pageview' => true);
*
* Option keys include: 'do_not_log_pageview', 'do_not_log_clicks', 'do_not_log_domstream'
*
* @param $echo bool if true the function will echo. if false the tracker is returned asa string.
* @param $options array an key value pair option array
* @return $tag string the tracker javascript.
*/
function placeHelperPageTags($echo = true, $options = array()) {
if( ! owa_coreAPI::getRequestParam( 'is_robot' ) ) {
if ( ! class_exists( 'owa_template' ) ) {
require_once(OWA_BASE_CLASSES_DIR.'owa_template.php');
}
$t = new owa_template();
$t->set_template('js_helper_tags.tpl');
$tracking_code = owa_coreAPI::getJsTrackerTag( $this->getSiteId(), $options );
$t->set('tracking_code', $tracking_code);
$tag = $t->fetch();
if ($echo == false) {
return $tag;
} else {
echo $tag;
}
}
}
// needed?
function handleHelperPageTagsRequest() {
$params = array();
$params['do'] = 'base.helperPageTags';
return $this->handleRequest($params);
}
/**
* Handles OWA internal page/action requests
*
* @return unknown
*/
function handleRequest($caller_params = null, $action = '') {
return owa_coreAPI::handleRequest($caller_params, $action);
}
function __destruct() {
$this->end_time = owa_lib::microtime_float();
$total_time = $this->end_time - $this->start_time;
owa_coreAPI::debug(sprintf('Total session time: %s',$total_time));
owa_coreAPI::debug("Goodbye from OWA");
owa_coreAPI::profileDisplay();
}
function setSetting($module, $name, $value) {
return owa_coreAPI::setSetting($module, $name, $value);
}
function getSetting($module, $name) {
return owa_coreAPI::getSetting($module, $name);
}
function setCurrentUser($role, $login_name = '') {
$cu = owa_coreAPI::getCurrentUser();
$cu->setRole($role);
$cu->setAuthStatus(true);
}
function makeEvent($type = '') {
$event = owa_coreAPI::supportClassFactory('base', 'event');
if ($type) {
$event->setEventType($type);
}
return $event;
}
function setSiteId($site_id) {
$this->site_id = $site_id;
}
function getSiteId() {
return $this->site_id;
}
function setErrorHandler($mode) {
$this->e->setHandler($mode);
}
function isOwaInstalled() {
$version = owa_coreAPI::getSetting('base', 'schema_version');
if ($version > 0) {
return true;
} else {
return false;
}
}
function isEndpointEnabled($file_name) {
if ( ! $this->getSetting('base', 'disableAllEndpoints') ) {
$disabled_endpoints = $this->getSetting('base', 'disabledEndpoints');
if ( ! in_array( $file_name, $disabled_endpoints ) ) {
return true;
}
}
}
/**
* Used by owa_caller to override default config with values based to the caller.
*
*/
private function overloadConfig( $config ) {
if ( ! empty( $config ) ) {
if ( array_key_exists( 'base', $config ) ) {
foreach ($config as $module => $values ) {
$this->c->applyModuleOverrides( $module, $values );
}
} else {
$this->c->applyModuleOverrides('base', $config);
}
owa_coreAPI::debug('Configuration overrides applied.');
}
}
function restInPeace() {
return false;
}
}
?>