function addToQueue($event)
 {
     if ($event) {
         $properties['owa_event'] = base64_encode(serialize($event));
         //$properties = array_map('urlencode', $properties);
         $properties = owa_lib::implode_assoc('=', '&', $properties);
         //print_r($properties);
         //return;
     } else {
         return;
     }
     $parts = parse_url($this->endpoint);
     $fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errstr, 30);
     if (!$fp) {
         return false;
     } else {
         $out = "POST " . $parts['path'] . " HTTP/1.1\r\n";
         $out .= "Host: " . $parts['host'] . "\r\n";
         $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
         $out .= "Content-Length: " . strlen($properties) . "\r\n";
         $out .= "Connection: Close\r\n\r\n";
         $out .= $properties;
         owa_coreAPI::debug("out: {$out}");
         fwrite($fp, $out);
         fclose($fp);
         return true;
     }
 }
 /**
  * Notify Handler
  *
  * @access 	public
  * @param 	object $event
  */
 function notify($event)
 {
     $r = owa_coreAPI::entityFactory('base.request');
     $r->load($event->get('guid'));
     if (!$r->wasPersisted()) {
         $r->setProperties($event->getProperties());
         // Set Primary Key
         $r->set('id', $event->get('guid'));
         // Make prior document id
         $r->set('prior_document_id', owa_lib::setStringGuid($event->get('prior_page')));
         // Generate Host id
         $r->set('num_prior_sessions', $event->get('num_prior_sessions'));
         $result = $r->create();
         if ($result == true) {
             $eq = owa_coreAPI::getEventDispatch();
             $nevent = $eq->makeEvent($event->getEventType() . '_logged');
             $nevent->setProperties($event->getProperties());
             $eq->asyncNotify($nevent);
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not persisting. Request already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function action()
 {
     $auth =& owa_auth::get_instance();
     $status = $auth->authenticateUser();
     $go = $this->getParam('go');
     // if authentication is successfull
     if ($status['auth_status'] == true) {
         if (!empty($go)) {
             // redirect to url if present
             $url = urldecode($go);
             $this->e->debug("redirecting browser to...:" . $url);
             owa_lib::redirectBrowser($url);
         } else {
             //else redirect to home page
             // these need to be unset as they were set previously by the doAction method.
             // need to refactor this out.
             $this->set('auth_status', '');
             $this->set('params', '');
             $this->set('site_id', '');
             $this->setRedirectAction($this->config['start_page']);
         }
     } else {
         // return login form with error msg
         $this->setView('base.loginForm');
         $this->set('go', $go);
         $this->set('error_code', 2002);
         $this->set('user_id', $this->getParam('user_id'));
     }
 }
Beispiel #4
0
 function createAdminUser($email_address)
 {
     //create user entity
     $u = owa_coreAPI::entityFactory('base.user');
     // check to see if an admin user already exists
     $u->getByColumn('role', 'admin');
     $id_check = $u->get('id');
     // if not then proceed
     if (empty($id_check)) {
         //Check to see if user name already exists
         $u->getByColumn('user_id', 'admin');
         $id = $u->get('id');
         // Set user object Params
         if (empty($id)) {
             $password = $u->generateRandomPassword();
             $u->set('user_id', 'admin');
             $u->set('role', 'admin');
             $u->set('real_name', '');
             $u->set('email_address', $email_address);
             $u->set('password', owa_lib::encryptPassword($password));
             $u->set('creation_date', time());
             $u->set('last_update_date', time());
             $ret = $u->create();
             owa_coreAPI::debug("Admin user created successfully.");
             return $password;
         } else {
             owa_coreAPI::debug($this->getMsg(3306));
         }
     } else {
         owa_coreAPI::debug("Admin user already exists.");
     }
 }
 /**
  * Notify Handler
  *
  * @access 	public
  * @param 	object $event
  */
 function notify($event)
 {
     $c = owa_coreAPI::entityFactory('base.click');
     $c->load($event->get('guid'));
     if (!$c->wasPersisted()) {
         $c->set('id', $event->get('guid'));
         $c->setProperties($event->getProperties());
         $c->set('visitor_id', $event->get('visitor_id'));
         $c->set('session_id', $event->get('session_id'));
         $c->set('ua_id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         // Make document id
         $c->set('document_id', owa_lib::setStringGuid($event->get('page_url')));
         // Make Target page id
         $c->set('target_id', owa_lib::setStringGuid($c->get('target_url')));
         // Make position id used for group bys
         $c->set('position', $c->get('click_x') . $c->get('click_y'));
         $ret = $c->create();
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $terms = trim(strtolower($event->get('search_terms')));
     if ($terms) {
         $st = owa_coreAPI::entityFactory('base.search_term_dim');
         $st_id = owa_lib::setStringGuid($terms);
         $st->getByPk('id', $st_id);
         $id = $st->get('id');
         if (!$id) {
             $st->set('id', $st_id);
             $st->set('terms', $terms);
             $ret = str_replace("", "", $terms, $count);
             $st->set('term_count', $count);
             $ret = $st->create();
             if ($ret) {
                 return OWA_EHS_EVENT_HANDLED;
             } else {
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             owa_coreAPI::debug('Not Logging. Search term already exists.');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Handler
  *
  * @access 	public
  * @param 	object $event
  */
 function notify($event)
 {
     $c = owa_coreAPI::entityFactory('base.click');
     $c->load($event->get('guid'));
     if (!$c->wasPersisted()) {
         $c->set('id', $event->get('guid'));
         $c->setProperties($event->getProperties());
         $c->set('visitor_id', $event->get('visitor_id'));
         $c->set('session_id', $event->get('session_id'));
         $c->set('ua_id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         // Make document id
         $c->set('document_id', owa_lib::setStringGuid($event->get('page_url')));
         // Make Target page id
         $c->set('target_id', owa_lib::setStringGuid($c->get('target_url')));
         // Make position id used for group bys
         $c->set('position', $c->get('click_x') . $c->get('click_y'));
         $ret = $c->create();
         if ($ret) {
             // Tell others that "dom.click" has been logged
             $eq = owa_coreAPI::getEventDispatch();
             $nevent = $eq->makeEvent($event->getEventType() . '_logged');
             $nevent->setProperties($event->getProperties());
             $eq->asyncNotify($nevent);
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     // Make entity
     $f = owa_coreAPI::entityFactory('base.feed_request');
     $f->load($event->get('guid'));
     if (!$f->wasPersisted()) {
         $f->setProperties($event->getProperties());
         // Set Primary Key
         $f->set('id', $event->get('guid'));
         // Make ua id
         $f->set('ua_id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         // Make OS id
         $f->set('os_id', owa_lib::setStringGuid($event->get('os')));
         // Make document id
         $f->set('document_id', owa_lib::setStringGuid($event->get('page_url')));
         // Generate Host id
         $f->set('host_id', owa_lib::setStringGuid($event->get('host')));
         $f->set('subscription_id', $event->get('feed_subscription_id'));
         // Persist to database
         $ret = $f->create();
         if ($ret) {
             $eq = owa_coreAPI::getEventDispatch();
             $nevent = $eq->makeEvent($event->getEventType() . '_persisted');
             $nevent->setProperties($event->getProperties());
             $eq->notify($nevent);
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not persisting. Feed request already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function __construct($params)
 {
     parent::__construct($params);
     $this->type = 'options';
     $this->setRequiredCapability('edit_settings');
     $this->setNonceRequired();
     $goal = $this->getParam('goal');
     // check that goal number is present
     $v1 = owa_coreAPI::validationFactory('required');
     $v1->setValues($goal['goal_number']);
     $this->setValidation('goal_number', $v1);
     // check that goal status is present
     $v1 = owa_coreAPI::validationFactory('required');
     $v1->setValues($goal['goal_status']);
     $this->setValidation('goal_status', $v1);
     // check that goal status is present
     $v1 = owa_coreAPI::validationFactory('required');
     $v1->setValues($goal['goal_group']);
     $this->setValidation('goal_group', $v1);
     // check that goal type is present
     $v1 = owa_coreAPI::validationFactory('required');
     $v1->setValues($goal['goal_type']);
     $this->setValidation('goal_type', $v1);
     if ($goal['goal_type'] === 'url_destination') {
         // check that match_type is present
         $v1 = owa_coreAPI::validationFactory('required');
         $v1->setValues($goal['details']['match_type']);
         $this->setValidation('match_type', $v1);
         // check that goal_url is present
         $v1 = owa_coreAPI::validationFactory('required');
         $v1->setValues($goal['details']['goal_url']);
         $this->setValidation('goal_url', $v1);
     }
     $steps = $goal['details']['funnel_steps'];
     if (isset($goal['details']['funnel_steps'])) {
         foreach ($goal['details']['funnel_steps'] as $num => $step) {
             if (!empty($step['name']) || !empty($step['url'])) {
                 // check that step name is present
                 $v1 = owa_coreAPI::validationFactory('required');
                 $v1->setValues($step['name']);
                 $this->setValidation('step_name_' . $num, $v1);
                 // check that step url is present
                 $v1 = owa_coreAPI::validationFactory('required');
                 $v1->setValues($step['url']);
                 $this->setValidation('step_url_' . $num, $v1);
             }
             $check = owa_lib::array_values_assoc($step);
             if (!empty($check)) {
                 $step['step_number'] = $num;
                 $this->params['goal']['details']['funnel_steps'][$num] = $step;
             } else {
                 // remove the array as it only contains empty values.
                 // this can happen when the use adds a step but does not fill in any
                 // values.
                 unset($this->params['goal']['details']['funnel_steps'][$num]);
             }
         }
     }
 }
 function render($data)
 {
     //page title
     $this->t->set('page_title', 'Configuration File Generator');
     // load body template
     $this->body->set('config', $this->get('config'));
     $this->body->set_template('install_config_entry.php');
     // prepopulate the public url based on the current url.
     $public_url = owa_lib::get_current_url();
     $pos = strpos($public_url, 'install.php');
     $public_url = substr($public_url, 0, $pos);
     $this->body->set('public_url', $public_url);
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     // Make entity
     $f = owa_coreAPI::entityFactory('base.feed_request');
     $f->load($event->get('guid'));
     if (!$f->wasPersisted()) {
         // rekey Feed subscription id tracking code
         // @todo check the wordpress plugin to see if this is even needed
         if (!$event->get('feed_subscription_id')) {
             $event->set('feed_subscription_id', $event->get(owa_coreAPI::getSetting('base', 'feed_subscription_param')));
         }
         // needed??
         $event->set('feed_reader_guid', $event->setEnvGUID());
         // set feedreader flag to true, browser flag to false
         $event->set('is_feedreader', true);
         $event->set('is_browser', false);
         // set params on entity
         $f->setProperties($event->getProperties());
         // Set Primary Key
         $f->set('id', $event->get('guid'));
         // Make ua id
         $f->set('ua_id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         // Make OS id
         $f->set('os_id', owa_lib::setStringGuid($event->get('os')));
         // Make document id
         $f->set('document_id', owa_lib::setStringGuid($event->get('page_url')));
         // Generate Host id
         $f->set('host_id', owa_lib::setStringGuid($event->get('host')));
         $f->set('subscription_id', $event->get('feed_subscription_id'));
         // Persist to database
         $ret = $f->create();
         if ($ret) {
             $eq = owa_coreAPI::getEventDispatch();
             $nevent = $eq->makeEvent($event->getEventType() . '_logged');
             $nevent->setProperties($event->getProperties());
             $eq->notify($nevent);
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not persisting. Feed request already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $os = owa_coreAPI::entityFactory('base.os');
     $os->getByColumn('id', owa_lib::setStringGuid($event->get('os')));
     if (!$os->get('id')) {
         $os->set('name', $event->get('os'));
         $os->set('id', owa_lib::setStringGuid($event->get('os')));
         $ret = $os->create();
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not persistig. Operating system already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $ua = owa_coreAPI::entityFactory('base.ua');
     $ua->getByColumn('id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
     if (!$ua->get('id')) {
         $ua->setProperties($event->getProperties());
         $ua->set('ua', $event->get('HTTP_USER_AGENT'));
         $ua->set('id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         $ret = $ua->create();
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('not logging, user agent already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     if ($event->get('HTTP_USER_AGENT')) {
         $ua = owa_coreAPI::entityFactory('base.ua');
         $ua->getByColumn('id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
         if (!$ua->get('id')) {
             $ua->setProperties($event->getProperties());
             $ua->set('ua', $event->get('HTTP_USER_AGENT'));
             $ua->set('id', owa_lib::setStringGuid($event->get('HTTP_USER_AGENT')));
             $ret = $ua->create();
             if ($ret) {
                 return OWA_EHS_EVENT_HANDLED;
             } else {
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             $old = $ua->get('browser_type');
             $new = $event->get('browser_type');
             if ($new != $old && $new != 'Default Browser') {
                 $ua->set('browser_type', $new);
                 $ua->set('browser', $event->get('browser'));
                 $ret = $ua->save();
                 if ($ret) {
                     owa_coreAPI::debug('Updating user agent with new browser type: ' . $new);
                     return OWA_EHS_EVENT_HANDLED;
                 } else {
                     return OWA_EHS_EVENT_FAILED;
                 }
             }
             owa_coreAPI::debug('not logging, user agent already exists.');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         owa_coreAPI::debug('not logging, no user agent present.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function generateRandomPassword()
 {
     return substr(owa_lib::encryptPassword(microtime()), 0, 6);
 }
 /**
  * Attach
  *
  * Attaches observers by filter type.
  * Takes a valid user defined callback function for use by PHP's call_user_func_array
  * 
  * @param 	$filter_name	string
  * @param	$observer	mixed can be a function name or function array
  * @return bool
  */
 function attachFilter($filter_name, $observer, $priority = 10)
 {
     $id = owa_lib::generateRandomUid();
     $this->listenersByFilterType[$filter_name][$priority][] = $id;
     $this->listeners[$id] = $observer;
 }
 public static function saltedHash($data, $scheme, $hash_type = 'md5')
 {
     $salt = owa_coreAPI::getSalt($scheme);
     return owa_lib::hash($hash_type, $data, $salt);
 }
 function getDomClicks($pageUrl, $siteId, $startDate, $endDate, $document_id = '', $period = '', $resultsPerPage = 100, $page = 1, $format = 'jsonp')
 {
     // Fetch document object
     $d = owa_coreAPI::entityFactory('base.document');
     if (!$document_id) {
         $eq = owa_coreAPI::getEventDispatch();
         $document_id = $d->generateId($eq->filter('page_url', urldecode($pageUrl), $siteId));
     }
     $d->getByColumn('id', $document_id);
     $rs = owa_coreAPI::supportClassFactory('base', 'paginatedResultSet');
     $db = owa_coreAPI::dbSingleton();
     $db->selectFrom('owa_click');
     $db->selectColumn("click_x as x,\r\n\t\t\t\t\t\t\tclick_y as y,\r\n\t\t\t\t\t\t\tpage_width,\r\n\t\t\t\t\t\t\tpage_height,\r\n\t\t\t\t\t\t\tdom_element_x,\r\n\t\t\t\t\t\t\tdom_element_y,\r\n\t\t\t\t\t\t\tposition");
     $db->orderBy('click_y', 'ASC');
     $db->where('document_id', $document_id);
     $db->where('site_id', $siteId);
     if ($period) {
         $p = owa_coreAPI::supportClassFactory('base', 'timePeriod');
         $p->set($period);
         $startDate = $p->startDate->get('yyyymmdd');
         $endDate = $p->endDate->get('yyyymmdd');
     }
     if ($startDate && $endDate) {
         $db->where('yyyymmdd', array('start' => $startDate, 'end' => $endDate), 'BETWEEN');
     }
     // pass limit to rs object if one exists
     $rs->setLimit($resultsPerPage);
     // pass page to rs object if one exists
     $rs->setPage($page);
     $results = $rs->generate($db);
     //$rs->resultsRows = $results;
     if ($format) {
         owa_lib::setContentTypeHeader($format);
         return $rs->formatResults($format);
     } else {
         return $rs;
     }
 }
 function logSession($event)
 {
     if ($event->get('session_id')) {
         $s = owa_coreAPI::entityFactory('base.session');
         $s->load($event->get('session_id'));
         if (!$s->wasPersisted()) {
             $s->setProperties($event->getProperties());
             // Set Primary Key
             $s->set('id', $event->get('session_id'));
             // set initial number of page views
             $s->set('num_pageviews', 1);
             $s->set('is_bounce', true);
             // set prior session time properties
             $s->set('prior_session_lastreq', $event->get('last_req'));
             $s->set('prior_session_id', $event->get('prior_session_id'));
             if ($s->get('prior_session_lastreq') > 0) {
                 $s->set('time_sinse_priorsession', $s->get('timestamp') - $event->get('last_req'));
                 $s->set('prior_session_year', date("Y", $event->get('last_req')));
                 $s->set('prior_session_month', date("M", $event->get('last_req')));
                 $s->set('prior_session_day', date("d", $event->get('last_req')));
                 $s->set('prior_session_hour', date("G", $event->get('last_req')));
                 $s->set('prior_session_minute', date("i", $event->get('last_req')));
                 $s->set('prior_session_dayofweek', date("w", $event->get('last_req')));
             }
             // set last_req to be the timestamp of the event that triggered this session.
             $s->set('last_req', $event->get('timestamp'));
             $s->set('days_since_first_session', $event->get('days_since_first_session'));
             $s->set('days_since_prior_session', $event->get('days_since_prior_session'));
             $s->set('num_prior_sessions', $event->get('num_prior_sessions'));
             // set medium
             //$s->set('medium', $event->get('medium'));
             // set campaign touches
             $s->set('latest_attributions', $event->get('attribs'));
             // Make document ids
             $s->set('first_page_id', owa_lib::setStringGuid($event->get('page_url')));
             $s->set('last_page_id', $s->get('first_page_id'));
             // Generate Referer id
             if ($event->get('external_referer')) {
                 $s->set('referer_id', owa_lib::setStringGuid($event->get('HTTP_REFERER')));
             }
             // this should already be set by the request handler.
             $s->set('location_id', $event->get('location_id'));
             $ret = $s->create();
             // create event message
             $session = $s->_getProperties();
             $properties = array_merge($event->getProperties(), $session);
             $properties['request_id'] = $event->get('guid');
             $ne = owa_coreAPI::supportClassFactory('base', 'event');
             $ne->setProperties($properties);
             $ne->setEventType('base.new_session');
             // log the new session event to the event queue
             $eq = owa_coreAPI::getEventDispatch();
             $eq->notify($ne);
             if ($ret) {
                 return OWA_EHS_EVENT_HANDLED;
             } else {
                 return OWA_EHS_EVENT_FAILED;
             }
         } else {
             owa_coreAPI::debug('Not persisting new session. Session already exists.');
             return OWA_EHS_EVENT_HANDLED;
         }
     } else {
         owa_coreAPI::debug('Not persisting new session. No session_id present.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function formatCurrency($value)
 {
     return owa_lib::formatCurrency($value, owa_coreAPI::getSetting('base', 'currencyLocal'));
 }
 function notAuthenticatedAction()
 {
     $this->setRedirectAction('base.loginForm');
     $this->set('go', urlencode(owa_lib::get_current_url()));
 }
 function __destruct()
 {
     $this->end_time = owa_lib::microtime_float();
     $total_time = $this->end_time - $this->start_time;
     $this->e->debug(sprintf('Total session time: %s', $total_time));
     $this->e->debug("goodbye from OWA");
     owa_coreAPI::profileDisplay();
     return;
 }
 /**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $medium = $event->get('medium');
     // if there is no session referer then return
     if (!$event->get('session_referer')) {
         return OWA_EHS_EVENT_HANDLED;
     }
     // Make entity
     $r = owa_coreAPI::entityFactory('base.referer');
     $r->load($event->get('referer_id'));
     if (!$r->wasPersisted()) {
         // Set id
         if ($event->get('referer_id')) {
             $r->set('id', $event->get('referer_id'));
         } else {
             $r->set('id', $r->generateId($event->get('session_referer')));
         }
         // set referer url
         $r->set('url', $event->get('session_referer'));
         // Set site
         $url = owa_lib::parse_url($event->get('session_referer'));
         $r->set('site', $url['host']);
         if ($medium === 'organic-search') {
             $r->set('is_searchengine', true);
         }
         // set title. this will be updated later by the crawler.
         $r->set('page_title', '(not set)');
         // Crawl and analyze refering page
         if (owa_coreAPI::getSetting('base', 'fetch_refering_page_info') && $medium != 'organic-search') {
             //owa_coreAPI::debug('hello from logReferer');
             $crawler = new owa_http();
             //$crawler->fetch($this->params['HTTP_REFERER']);
             $res = $crawler->getRequest($event->get('session_referer'));
             owa_coreAPI::debug('http request response: ' . print_r($res, true));
             //Extract Title
             $title = trim($crawler->extract_title());
             if ($title) {
                 $r->set('page_title', owa_lib::utf8Encode($title));
             }
             $se = $r->get('is_searchengine');
             //Extract anchortext and page snippet but not if it's a search engine...
             if ($se != true) {
                 $snippet = $crawler->extract_anchor_snippet($event->get('inbound_page_url'));
                 if ($snippet) {
                     if (function_exists('iconv')) {
                         $snippet = iconv('UTF-8', 'UTF-8//TRANSLIT', $snippet);
                     }
                     $r->set('snippet', $snippet);
                 }
                 $anchortext = $crawler->anchor_info['anchor_text'];
                 if ($anchortext) {
                     $r->set('refering_anchortext', owa_lib::utf8Encode($anchortext));
                 }
             }
         }
         // Persist to database
         $ret = $r->create();
         if ($ret) {
             return OWA_EHS_EVENT_HANDLED;
         } else {
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('Not Persisting. Referrer already exists.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 private function inferTrafficAttribution()
 {
     $ref = owa_coreAPI::getServerParam('HTTP_REFERER');
     $medium = 'direct';
     $source = '(none)';
     $search_terms = '(none)';
     $session_referer = '(none)';
     if ($ref) {
         $uri = owa_lib::parse_url($ref);
         // check for external referer
         $host = owa_coreAPI::getServerParam('HTTP_HOST');
         if ($host != $uri['host']) {
             $medium = 'referral';
             $source = owa_lib::stripWwwFromDomain($uri['host']);
             $engine = $this->isRefererSearchEngine($uri);
             $session_referer = $ref;
             if ($engine) {
                 $medium = 'organic-search';
                 $search_terms = $engine['t'];
             }
         }
     }
     owa_coreAPI::setState('s', 'referer', $session_referer);
     owa_coreAPI::setState('s', 'medium', $medium);
     owa_coreAPI::setState('s', 'source', $source);
     owa_coreAPI::setState('s', 'search_terms', $search_terms);
 }
 /**
  * Must be called before all other event property setting functions
  */
 function pre()
 {
     // ENVIRONMENTAL PARAMS
     // check for no value
     // clean
     // apply default if necessary
     // filter
     // these should really be pulled from the service layer
     $this->event->set('timestamp', owa_coreAPI::getRequestTimestamp());
     $this->event->set('microtime', microtime());
     //set user agent
     if (!$this->event->get('HTTP_USER_AGENT')) {
         $this->event->set('HTTP_USER_AGENT', owa_coreAPI::getServerParam('HTTP_USER_AGENT'));
     }
     // filter user agent
     $this->event->set('HTTP_USER_AGENT', $this->eq->filter('user_agent', $this->event->get('HTTP_USER_AGENT')));
     // set http_host
     if (!$this->event->get('HTTP_HOST')) {
         $this->event->set('HTTP_HOST', owa_coreAPI::getServerParam('HTTP_HOST'));
     }
     //filter http_host
     $this->event->set('HTTP_HOST', $this->eq->filter('HTTP_HOST', $this->event->get('HTTP_HOST')));
     // set language
     if (!$this->event->get('language')) {
         $this->event->set('language', substr(owa_coreAPI::getServerParam('HTTP_ACCEPT_LANGUAGE'), 0, 5));
     }
     // filter language
     $this->event->set('language', $this->eq->filter('language', $this->event->get('language')));
     // Set Ip Address
     if (!$this->event->get('ip_address')) {
         $this->event->set('ip_address', owa_coreAPI::getServerParam('REMOTE_ADDR'));
     }
     $this->event->set('ip_address', $this->eq->filter('ip_address', $this->event->get('ip_address')));
     // Set host related properties
     if (!$this->event->get('REMOTE_HOST')) {
         $this->event->set('REMOTE_HOST', owa_coreAPI::getServerParam('REMOTE_HOST'));
     }
     //$teh = owa_trackingEventHelpers::getInstance();
     //$teh->setEnvironmentals( $this->event );
     /// REQUIRED PARAMS
     // check for value
     // clean based on type
     // filter
     // apply default value if necessary
     // set page type
     // moved
     if (!$this->event->get('page_type')) {
         $this->event->set('page_type', '(not set)');
     }
     //filter page type
     //moved
     $this->event->set('page_type', $this->eq->filter('page_type', $this->event->get('page_type')));
     // filter page_url
     //moved
     $this->event->set('page_url', $this->eq->filter('page_url', $this->event->get('page_url'), $this->event->get('site_id')));
     // Page title
     // moved
     if ($this->event->get('page_title')) {
         $page_title = owa_lib::utf8Encode(trim($this->event->get('page_title')));
     } else {
         $page_title = '(not set)';
     }
     $this->event->set('page_title', $this->eq->filter('page_title', $page_title));
     // needs key translation
     // translated,
     $this->event->set('days_since_first_session', $this->event->get('dsfs'));
     $this->event->set('days_since_prior_session', $this->event->get('dsps'));
     $this->event->set('num_prior_sessions', $this->event->get('nps'));
     // OPTIONAL PARAMS
     // filter http referer
     /* moved */
     if ($this->event->get('HTTP_REFERER')) {
         $this->event->set('HTTP_REFERER', $this->eq->filter('HTTP_REFERER', $this->event->get('HTTP_REFERER')));
     }
     // Filter the target url of clicks
     /* moved */
     if ($this->event->get('target_url')) {
         $this->event->set('target_url', $this->eq->filter('target_url', $this->event->get('target_url'), $this->event->get('site_id')));
     }
     /* moved */
     if ($this->event->get('source')) {
         $this->event->set('source', $this->eq->filter('source', trim(strtolower($this->event->get('source')))));
     }
     /* moved */
     if ($this->event->get('medium')) {
         $this->event->set('medium', $this->eq->filter('medium', trim(strtolower($this->event->get('medium')))));
     }
     // set session referer (the site that originally referer the visit)
     /* moved */
     if ($this->event->get('session_referer')) {
         $this->event->set('session_referer', $this->eq->filter('session_referer', $this->event->get('session_referer')));
     }
     $this->setCustomVariables();
     // DEPENDANT SETS
     // evaluate
     // produce value
     // filter
     // add default if required
     // Set all time related properties
     // depends on 'timestamp'
     /* moved */
     $this->setTimeProperties($this->event);
     /* moved */
     // set repeat visitor type flag visitor is not new.
     if (!$this->event->get('is_new_visitor')) {
         $this->event->set('is_repeat_visitor', true);
     } else {
         // properly cast this to a bool.
         $this->event->set('is_new_visitor', true);
     }
     /* moved */
     if (!$this->event->get('page_uri')) {
         $page_uri = $this->derivePageUri($this->event->get('page_url'));
     }
     $this->event->set('page_uri', $this->eq->filter('page_uri', $page_uri));
     // host properties
     /* mooved */
     $this->event->set('full_host', $this->eq->filter('full_host', $this->event->get('REMOTE_HOST'), $this->event->get('ip_address')));
     // required
     if (!$this->event->get('full_host')) {
         $this->event->set('full_host', '(not set)');
     }
     /* moved */
     $this->event->set('host', $this->eq->filter('host', $this->event->get('full_host'), $this->event->get('ip_address')));
     //required
     if (!$this->event->get('host')) {
         $this->event->set('host', '(not set)');
     }
     // Browser related properties
     // required
     $service = owa_coreAPI::serviceSingleton();
     $bcap = $service->getBrowscap();
     // Assume browser untill told otherwise
     /* moved */
     $this->event->set('is_browser', true);
     /* moved */
     $this->event->set('browser_type', $this->eq->filter('browser_type', $bcap->getUaFamily()));
     /* moved */
     if ($bcap->getUaVersion()) {
         $this->event->set('browser', $this->eq->filter('browser', $bcap->getUaVersion()));
     } else {
         $this->event->set('browser', $this->eq->filter('browser', '(unknown)'));
     }
     //Check for what kind of page request this is
     /* moved */
     if ($bcap->isRobot()) {
         $this->event->set('is_robot', true);
         $this->event->set('is_browser', false);
     }
     /* moved */
     $this->event->set('os', $this->eq->filter('operating_system', $bcap->getOsFamily(), $this->event->get('HTTP_USER_AGENT')));
     /*moved */
     if ($this->event->get('is_new_session')) {
         //mark entry page flag on current request
         $this->event->set('is_entry_page', true);
     }
     /* moved */
     $this->setGeolocation();
     // set prior page properties
     /* moved */
     if ($this->event->get('HTTP_REFERER')) {
         $referer_parse = owa_lib::parse_url($this->event->get('HTTP_REFERER'));
         if ($referer_parse['host'] === $page_parse['host']) {
             $this->event->set('prior_page', $this->eq->filter('prior_page', $this->event->get('HTTP_REFERER'), $this->event->get('site_id')));
         }
     }
     // set  search terms
     /* moved */
     $search_terms = $this->event->get('search_terms');
     if ($search_terms && $search_terms != '(not set)') {
         $this->event->set('search_terms', $this->eq->filter('search_terms', trim(strtolower($this->event->get('search_terms')))));
     }
     // ID GENERATION
     //set user agent id
     /* moved */
     $this->event->set('ua_id', owa_lib::setStringGuid($this->event->get('HTTP_USER_AGENT')));
     // set document/page id
     /* moved */
     if ($this->event->get('page_url')) {
         $this->event->set('document_id', owa_lib::setStringGuid($this->event->get('page_url')));
     }
     // Generate host_id
     /* moved */
     $this->event->set('host_id', owa_lib::setStringGuid($this->event->get('host')));
     // generate os_id
     /* moved */
     $this->event->set('os_id', owa_lib::setStringGuid($this->event->get('os')));
     /* moved */
     if ($this->event->get('campaign')) {
         $this->event->set('campaign_id', owa_lib::setStringGuid(trim(strtolower($this->event->get('campaign')))));
     }
     /* moved */
     if ($this->event->get('ad')) {
         $this->event->set('ad_id', owa_lib::setStringGuid(trim(strtolower($this->event->get('ad')))));
     }
     /* moved */
     if ($this->event->get('source')) {
         $this->event->set('source_id', owa_lib::setStringGuid($this->event->get('source')));
     }
     // set session referer (the site that originally referer the visit)
     /* moved */
     if ($this->event->get('session_referer')) {
         // generate referer_id for downstream handlers
         $this->event->set('referer_id', owa_lib::setStringGuid($this->event->get('session_referer')));
     }
     /* moved */
     if ($this->event->get('search_terms')) {
         $this->event->set('referring_search_term_id', owa_lib::setStringGuid(trim(strtolower($this->event->get('search_terms')))));
     }
     // SHOULD BE A FILTER
     // record and filter personally identifiable info (PII)
     if (owa_coreAPI::getSetting('base', 'log_visitor_pii')) {
         // set user name if one does not already exist on event
         /* moved */
         if (!$this->event->get('user_name') && owa_coreAPI::getSetting('base', 'log_owa_user_names')) {
             $cu = owa_coreAPI::getCurrentUser();
             $this->event->set('user_name', $cu->user->get('user_id'));
         }
         $this->event->set('user_name', $this->eq->filter('user_name', $this->event->get('user_name')));
         // set email_address if one does not already exist on event
         /* moved */
         if (!$this->event->get('email_address')) {
             $cu = owa_coreAPI::getCurrentUser();
             $this->event->set('email_address', $cu->user->get('email_address'));
         }
         $this->event->set('user_email', $this->eq->filter('user_email', $this->event->get('email_address')));
     }
     // anonymize Ip address
     if (owa_coreAPI::getSetting('base', 'anonymize_ips')) {
         $this->event->set('ip_address', $this->anonymizeIpAddress($this->event->get('ip_address')));
         $this->event->set('full_host', '(not set)');
     }
 }
 function setContentTypeHeader($type = 'html')
 {
     owa_lib::setContentTypeHeader($type);
 }
 /**
  * Checks for and applies schema upgrades for the module
  *
  */
 function update()
 {
     // list files in a directory
     $files = owa_lib::listDir(OWA_DIR . 'modules' . '/' . $this->name . '/' . 'updates', false);
     //print_r($files);
     $current_schema_version = $this->c->get($this->name, 'schema_version');
     // extract sequence
     foreach ($files as $k => $v) {
         // the use of %d casts the sequence number as an int which is critical for maintaining the
         // order of the keys in the array that we are going ot create that holds the update objs
         //$n = sscanf($v['name'], '%d_%s', $seq, $classname);
         $seq = substr($v['name'], 0, -4);
         settype($seq, "integer");
         if ($seq > $current_schema_version) {
             if ($seq <= $this->required_schema_version) {
                 $this->updates[$seq] = owa_coreAPI::updateFactory($this->name, substr($v['name'], 0, -4));
                 // if the cli update mode is required and we are not running via cli then return an error.
                 owa_coreAPI::debug('cli update mode required: ' . $this->updates[$seq]->isCliModeRequired());
                 if ($this->updates[$seq]->isCliModeRequired() === true && !defined('OWA_CLI')) {
                     //set flag in module
                     $this->update_from_cli_required = true;
                     owa_coreAPI::notice("Aborting update {$seq}. This update must be applied using the command line interface.");
                     return false;
                 }
                 // set schema version from sequence number in file name. This ensures that only one update
                 // class can ever be in use for a particular schema version
                 $this->updates[$seq]->schema_version = $seq;
             }
         }
     }
     // sort the array
     ksort($this->updates, SORT_NUMERIC);
     //print_r(array_keys($this->updates));
     foreach ($this->updates as $k => $obj) {
         $this->e->notice(sprintf("Applying Update %d (%s)", $k, get_class($obj)));
         $ret = $obj->apply();
         if ($ret == true) {
             $this->e->notice("Update Suceeded");
         } else {
             $this->e->notice("Update Failed");
             return false;
         }
     }
     return true;
 }
 static function utfEncodeProperty($string, $event)
 {
     return owa_lib::utf8Encode(trim($string));
 }
 /**
  * Creates a text snippet of the portion of page where the 
  * specific link is found.
  * 
  * Takes fully qualified URL for the link to search for.
  *
  * @param string $link
  * @return string
  */
 function extract_anchor_snippet($link)
 {
     // Search the page for a specific anchor
     $this->extract_anchor($link);
     if (!empty($this->anchor_info['anchor_tag'])) {
         // drop certain HTML entitities and their content
         $nohtml = $this->strip_selected_tags($this->response, array('title', 'head', 'script', 'object', 'style', 'meta', 'link', 'rdf:'), true);
         //$this->e->debug('Refering page content after certain html entities were dropped: '.$this->results);
         // calc len of the anchor text
         $atext_len = strlen($this->anchor_info['anchor_tag']);
         // find position within document of the anchor text
         $start = strpos($nohtml, $this->anchor_info['anchor_tag']);
         if ($start < $this->snip_len) {
             $part1_start_pos = 0;
             $part1_snip_len = $start;
         } else {
             $part1_start_pos = $start;
             $part1_snip_len = $this->snip_len;
         }
         $replace_items = array("\r\n", "\n\n", "\t", "\r", "\n");
         // Create first segment of snippet
         $first_part = substr($nohtml, 0, $part1_start_pos);
         $first_part = str_replace($replace_items, '', $first_part);
         $first_part = strip_tags(owa_lib::inputFilter($first_part));
         //$part1 = trim(substr($nohtml, $part1_start_pos, $part1_snip_len));
         $part1 = substr($first_part, -$part1_snip_len, $part1_snip_len);
         //$part1 = str_replace(array('\r\n', '\n\n', '\t', '\r', '\n'), '', $part1);
         //$part1 = owa_lib::inputFilter($part1);
         // Create second segment of snippet
         $part2 = trim(substr($nohtml, $start + $atext_len, $this->snip_len + 300));
         $part2 = str_replace($replace_items, '', $part2);
         $part2 = substr(strip_tags(owa_lib::inputFilter($part2)), 0, $this->snip_len);
         // Put humpty dumpy back together again and create actual snippet
         $snippet = $this->snip_str . $part1 . ' <span class="snippet_anchor">' . owa_lib::inputFilter($this->anchor_info['anchor_tag']) . '</span> ' . $part2 . $this->snip_str;
     } else {
         $snippet = '';
     }
     return $snippet;
 }
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $Id$
//
require_once 'owa_env.php';
require_once OWA_DIR . 'owa_php.php';
/**
 * Main Admin Page Wrapper Script
 * 
 * @author      Peter Adams <*****@*****.**>
 * @copyright   Copyright &copy; 2006 Peter Adams <*****@*****.**>
 * @license     http://www.gnu.org/copyleft/gpl.html GPL v2.0
 * @category    owa
 * @package     owa
 * @version		$Revision$	      
 * @since		owa 1.0.0
 */
// Initialize owa admin
$owa = new owa_php();
if (!$owa->isOwaInstalled()) {
    // redirect to install
    owa_lib::redirectBrowser(owa_coreAPI::getSetting('base', 'public_url') . 'install.php');
}
if ($owa->isEndpointEnabled(basename(__FILE__))) {
    // run controller or view and echo page content
    echo $owa->handleRequestFromURL();
} else {
    // unload owa
    $owa->restInPeace();
}