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 | <?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$ // /** * Abstract OWA Event Class * * @author Peter Adams <peter@openwebanalytics.com> * @copyright Copyright © 2006 Peter Adams <peter@openwebanalytics.com> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.0.0 */ class owa_event { /** * Event Properties * * @var array */ var $properties = array(); /** * State * * @var string */ //var $state; var $eventType; /** * Time since last request. * * Used to tell if a new session should be created. * * @var integer $time_since_lastreq */ var $time_since_lastreq; /** * Event guid * * @var string */ var $guid; /** * Constructor * @access public */ function __construct() { // Set GUID for event $this->guid = $this->set_guid(); //needed? $this->set('guid', $this->guid); $this->set('timestamp', time() ); } function set($name, $value) { $this->properties[$name] = $value; return; } function get($name) { if(array_key_exists($name, $this->properties)) { //print_r($this->properties[$name]); return $this->properties[$name]; } else { return false; } } /** * Sets time related event properties * * @param integer $timestamp */ function setTime($timestamp = null) { if ( $timestamp ) { $this->set('timestamp', $timestamp); } else { $timestamp = $this->get('timestamp'); } // convert to local time and reset timestamp //$timestamp = owa_lib::utcToLocalTimestamp($timestamp); //$this->set('timestamp', $timestamp); $this->set('year', date("Y", $timestamp)); $this->set('month', date("n", $timestamp)); $this->set('day', date("d", $timestamp)); $this->set('yyyymmdd', date("Ymd", $timestamp)); $this->set('dayofweek', date("D", $timestamp)); $this->set('dayofyear', date("z", $timestamp)); $this->set('weekofyear', date("W", $timestamp)); $this->set('hour', date("G", $timestamp)); $this->set('minute', date("i", $timestamp)); $this->set('second', date("s", $timestamp)); //epoc time list($msec, $sec) = explode(" ", microtime()); $this->set('sec', $sec); $this->set('msec', $msec); } function setCookieDomain($domain) { $this->properties['cookie_domain'] = $domain; } /** * Determines the time since the last request from this borwser * * @access private * @return integer */ function timeSinceLastRequest() { return ($this->get('timestamp') - $this->get('last_req')); } /** * Applies calling application specific properties to request * * @access private * @param array $properties */ function setProperties($properties = null) { if(!empty($properties)) { if (empty($this->properties)) { $this->properties = $properties; } else { $this->properties = array_merge($this->properties, $properties); } } } function replaceProperties($properties) { $this->properties = $properties; } /** * Create guid from process id * * @return integer * @access private */ function set_guid() { return crc32(getmypid().time().rand()); } /** * Create guid from string * * @param string $string * @return integer * @access private */ function set_string_guid($string) { return crc32(strtolower($string)); } /** * Attempts to make a unique ID out of http request variables. * This should only be used when storing state in a cookie is impossible. * * @return integer */ function setEnvGUID() { return crc32( $this->get('ua') . $this->get('ip_address') ); } function setSiteSessionState($site_id, $name, $value, $store_type = 'cookie') { $store_name = owa_coreAPI::getSetting('base', 'site_session_param').'_'.$site_id; return owa_coreAPI::setState($store_name, $name, $value, $store_type, true); } function deleteSiteSessionState($site_id, $store_type = 'cookie') { $store_name = owa_coreAPI::getSetting('base', 'site_session_param').'_'.$site_id; return owa_coreAPI::clearState($store_name); } function getProperties() { return $this->properties; } function getEventType() { if (!empty($this->eventType)) { return $this->eventType; } elseif ($this->get('event_type')) { return $this->get('event_type'); } else { return 'unknown_event_type'; } } function setEventType($value) { $this->eventType = $value; } function cleanProperties() { return $this->setProperties(owa_lib::inputFilter($this->getProperties())); } function setPageTitle($value) { $this->set('page_title', $value); } function setSiteId($value) { $this->set('site_id', $value); } function setPageType($value) { $this->set('page_type', $value); } function getGuid() { return $this->guid; } function getSiteSpecificGuid($site_id) { return crc32(getmypid().time().rand().$site_id); } } ?> |