/** * Notify method * * @param object $event * @access public */ function notify($event) { $ds = owa_coreAPI::entityFactory('base.domstream'); $ds->load($event->get('guid')); if (!$ds->wasPersisted()) { $ds->setProperties($event->getProperties()); $ds->set('id', $event->get('guid')); $ds->set('domstream_guid', $event->get('domstream_guid')); $ds->set('document_id', $ds->generateId($event->get('page_url'))); $ds->set('page_url', $event->get('page_url')); $ds->set('events', $event->get('stream_events')); $ds->set('duration', $event->get('duration')); $ret = $ds->create(); if ($ret) { // Tell others that "dom.stream" 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 { owa_coreAPI::debug('No persisting. Domsteam already exists.'); return OWA_EHS_EVENT_HANDLED; } }
function __construct() { $this->params = $this->getArgs(); if (isset($this->params['interval'])) { $this->job_scheduling_interval = $this->params['interval']; } if (isset($this->params['max_workers'])) { $this->max_workers = $this->params['max_workers']; } if (isset($this->params['pid_file_location'])) { $this->pidFileLocation = $this->params['pid_file_location']; } if (isset($this->params['uid'])) { $this->userID = $this->params['uid']; } if (isset($this->params['gid'])) { $this->groupID = $this->params['gid']; } if (isset($this->params['pid_file_location'])) { $this->pidFileLocation = $this->params['pid_file_location']; } $s = owa_coreAPI::serviceSingleton(); $this->jobs = $s->getMap('backgound_jobs'); $this->eq = owa_coreAPI::getEventDispatch(); return parent::__construct(); }
function action() { $status = $this->installSchema(); if ($status == true) { $this->set('status_code', 3305); $password = $this->createAdminUser($this->getParam('email_address'), '', $this->getParam('password')); $site_id = $this->createDefaultSite($this->getParam('protocol') . $this->getParam('domain')); // Set install complete flag. $this->c->persistSetting('base', 'install_complete', true); $save_status = $this->c->save(); if ($save_status == true) { $this->e->notice('Install Complete Flag added to configuration'); } else { $this->e->notice('Could not add Install Complete Flag to configuration.'); } // fire install complete event. $ed = owa_coreAPI::getEventDispatch(); $event = $ed->eventFactory(); $event->set('u', 'admin'); $event->set('p', $password); $event->set('site_id', $site_id); $event->setEventType('install_complete'); $ed->notify($event); // set view $this->set('u', 'admin'); $this->set('p', $password); $this->set('site_id', $site_id); $this->setView('base.install'); $this->setSubview('base.installFinish'); //$this->set('status_code', 3304); } else { $this->set('error_msg', $this->getMsg(3302)); $this->errorAction(); } }
/** * 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 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() { $this->e->notice('About to delete handled events from database event queue.'); $d = owa_coreAPI::getEventDispatch(); $q = $d->getAsyncEventQueue('database'); $this->e->notice('Events removed: ' . $q->flushHandledEvents()); }
/** * 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 action() { if ($this->getParam('source')) { $input_queue_type = $this->getParam('source'); } else { $input_queue_type = owa_coreAPI::getSetting('base', 'event_queue_type'); } $processing_queue_type = $this->getParam('destination'); if (!$processing_queue_type) { $processing_queue_type = owa_coreAPI::getSetting('base', 'event_secondary_queue_type'); } // switch event queue setting in case a new events should be sent to a different type of queue. // this is handy for when processing from a file queue to a database queue if ($processing_queue_type) { owa_coreAPI::setSetting('base', 'event_queue_type', $processing_queue_type); owa_coreAPI::debug("Setting event queue type to {$processing_queue_type} for processing."); } $d = owa_coreAPI::getEventDispatch(); owa_coreAPI::debug("Loading {$input_queue_type} event queue."); $q = $d->getAsyncEventQueue($input_queue_type); $ret = $q->processQueue(); // go ahead and process the secondary event queue if ($ret && $processing_queue_type) { $destq = $d->getAsyncEventQueue($processing_queue_type); $destq->processQueue(); } }
/** * Class Constructor * * @return owa_auth */ function __construct() { // register auth cookies owa_coreAPI::registerStateStore('u', time() + 3600 * 24 * 365 * 10, '', '', 'cookie'); owa_coreAPI::registerStateStore('p', time() + 3600 * 2, '', '', 'cookie'); parent::__construct(); $this->eq = owa_coreAPI::getEventDispatch(); }
function action() { if ($this->getParam('queues')) { $queues = $this->getParam('queues'); } else { $queues = 'incoming_tracking_events,processing'; } owa_coreAPI::notice("About to process event queues: {$queues}"); // pull list of event queues to process from command line $queues = $this->getParam('queues'); if ($queues) { // parse command line $queues = explode(',', $this->getParam('queues')); } else { // get whatever queues are registered by modules $s = owa_coreAPI::serviceSingleton(); $queues = array_keys($s->getMap('event_queues')); } if ($queues) { foreach ($queues as $queue_name) { $q = owa_coreAPI::getEventQueue($queue_name); if ($q->connect()) { $d = owa_coreAPI::getEventDispatch(); $more = true; while ($more) { owa_coreAPI::debug('calling receive message'); // get an item from the queue $event = $q->receiveMessage(); owa_coreAPI::debug('Event returned: ' . print_r($event, true)); if ($event) { // process event if needed // lookup which event processor to use to process this event type $processor_action = owa_coreAPI::getEventProcessor($event->getEventType()); if ($processor_action) { // processor handles it's own event dispatching, so just return return owa_coreAPI::handleRequest(array('event' => $event), $processor_action); } else { // dispatch event $ret = $d->notify($event); } if ($ret = OWA_EHS_EVENT_HANDLED) { // delete event from queue // second param is for backwards compat. remove soon $q->deleteMessage($event->getQueueGuid()); } } else { // if no event, stop the loop $more = false; owa_coreAPI::notice("No more events to process."); } } $q->disconnect(); } } } else { owa_coreAPI::notice("There are no event queues registered."); } }
function action() { $userManager = owa_coreApi::supportClassFactory('base', 'userManager'); $user_params = array('user_id' => trim($this->params['user_id']), 'real_name' => $this->params['real_name'], 'role' => $this->params['role'], 'email_address' => trim($this->params['email_address'])); $temp_passkey = $userManager->createNewUser($user_params); // log account creation event to event queue $ed = owa_coreAPI::getEventDispatch(); $ed->log(array('user_id' => $this->params['user_id'], 'real_name' => $this->params['real_name'], 'role' => $this->params['role'], 'email_address' => $this->params['email_address'], 'temp_passkey' => $temp_passkey), 'base.new_user_account'); $this->setRedirectAction('base.users'); $this->set('status_code', 3000); }
function __construct($params) { if (array_key_exists('event', $params) && !empty($params['event'])) { $this->event = $params['event']; } else { owa_coreAPI::debug("No event object was passed to controller."); $this->event = owa_coreAPI::supportClassFactory('base', 'event'); } $this->eq = owa_coreAPI::getEventDispatch(); return parent::__construct($params); }
function action() { // Log password reset request to event queue $ed = owa_coreAPI::getEventDispatch(); $event = $ed->makeEvent('base.reset_password'); $event->set('email_address', $this->getParam('email_address')); $ed->notify($event); // return view $this->setView('base.passwordResetForm'); $email_address = trim($this->getParam('email_address')); $msg = $this->getMsg(2000, $email_address); $this->set('status_msg', $msg); }
function getGeolocationFromIp($ip_address, $refresh = false) { if (empty($this->properties) || $refresh === true) { $geo = array('ip_address' => $ip_address, 'city' => '', 'country' => '', 'state' => '', 'country_code' => '', 'latitude' => '', 'longitude' => ''); if (owa_coreAPI::getSetting('base', 'geolocation_lookup')) { $eq = owa_coreAPI::getEventDispatch(); $geo = $eq->filter('geolocation', $geo); } foreach ($geo as $k => $v) { if (!$v) { $geo[$k] = '(not set)'; } } $this->properties = $geo; } }
/** * 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; } }
function action() { $auth =& owa_auth::get_instance(); $status = $auth->authenticateUserTempPasskey($this->params['k']); // log to event queue if ($status === true) { $ed = owa_coreAPI::getEventDispatch(); $new_password = array('key' => $this->params['k'], 'password' => $auth->encryptPassword($this->params['password']), 'ip' => $_SERVER['REMOTE_ADDR']); $ed->log($new_password, 'base.set_password'); $auth->deleteCredentials(); $this->setRedirectAction('base.loginForm'); $this->set('status_code', 3006); } else { $this->setRedirectAction('base.loginForm'); $this->set('error_code', 2011); // can't find key in the db } }
public function setTrackerProperties($event, $properties) { $this->registerCallbacks($properties, 0); $eq = owa_coreAPI::getEventDispatch(); foreach ($properties as $name => $property) { $value = $event->get($name); /* if ( isset( $property['data_type'] ) && $property['data_type'] ) { $data_type = $property['data_type']; } $value = $this->setDataType( $value, $data_type ); */ $required = false; if (isset($property['required'])) { $required = $property['required']; } if (!$value && $value !== 0 && $value !== "0") { if (isset($property['alternative_key']) && $property['alternative_key']) { $value = $event->get($property['alternative_key']); // should we delete the original key on the event? if so: //$event->delete( $name ); } } // filter value $value = $eq->filter($name, $value, $event); //set default value if ($required && !$value && $value !== 0 && $value !== "0") { if (isset($property['default_value']) && $property['default_value']) { $value = $property['default_value']; } } // set value on the event if ($required || $value || $value === 0 || $value === "0") { $event->set($name, $value); } } }
/** * Registers a new package of files to be built by * the 'build' CLI command. * * $package array the package array takes the form of * * 'name' => 'mypackage' * 'output_dir' => '/path/to/output' * 'files' => array('foo' => array('path' => '/path/to/file/file.js', * 'compression' => 'minify')) */ protected function registerBuildPackage($package) { if (!isset($package['name'])) { throw exception('Build Package does not have a name.'); } if (!isset($package['output_dir'])) { throw exception('Build Package does not have an output directory.'); } else { //check for trailing slash $check = substr($package['output_dir'], -1, 1); if ($check != '/') { $package['output_dir'] = $package['output_dir'] . '/'; } } if (!isset($package['files'])) { throw exception('Build Package does not any files.'); } // filter the pcakge in case other modules want to change something. $eq = owa_coreAPI::getEventDispatch(); $package = $eq->filter('register_build_package', $package); $s = owa_coreAPI::serviceSingleton(); $s->setMapValue('build_packages', $package['name'], $package); }
/** * OWA Singelton * * Needed to avoid OWA loading for every mediawiki request */ function owa_singleton() { static $owa; if (empty($owa)) { global $wgUser, $wgServer, $wgScriptPath, $wgScript, $wgMainCacheType, $wgMemCachedServers, $wgOwaSiteId, $wgOwaMemCachedServers; /* OWA CONFIGURATION OVERRIDES */ $owa_config = array(); // check for memcache. these need to be passed into OWA to avoid race condition. if ($wgMainCacheType === CACHE_MEMCACHED) { $owa_config['cacheType'] = 'memcached'; $owa_config['memcachedServers'] = $wgMemCachedServers; } $owa = new owa_mw($owa_config); $owa->setSetting('base', 'report_wrapper', 'wrapper_mediawiki.tpl'); $owa->setSetting('base', 'main_url', $wgScriptPath . '/index.php?title=Special:Owa'); $owa->setSetting('base', 'main_absolute_url', $wgServer . $owa->getSetting('base', 'main_url')); $owa->setSetting('base', 'action_url', $wgServer . $wgScriptPath . '/index.php?action=owa&owa_specialAction'); $owa->setSetting('base', 'api_url', $wgServer . $wgScriptPath . '/index.php?action=owa&owa_apiAction'); $owa->setSetting('base', 'link_template', '%s&%s'); $owa->setSetting('base', 'is_embedded', true); $owa->setSetting('base', 'query_string_filters', 'returnto'); $owa->setSetting('base', 'delay_first_hit', false); if (!$wgOwaSiteId) { $wgOwaSiteId = md5($wgServer . $wgScriptPath); } $owa->setSiteId($wgOwaSiteId); // filter authentication $dispatch = owa_coreAPI::getEventDispatch(); // alternative auth method, sets auth status, role, and allowed sites list. $dispatch->attachFilter('auth_status', 'owa_mwAuthUser', 0); //print_r( $current_user ); } return $owa; }
/** * Attaches an event handler to the event queue * * @param array $event_name * @param string $handler_name * @return boolean */ function registerFilter($filter_name, $handler_name, $method, $priority = 10, $dir = 'filters') { if (!is_object($handler_name)) { //$handler = &owa_lib::factory($handler_dir,'owa_', $handler_name); $handler_name = owa_coreAPI::moduleGenericFactory($this->name, $dir, $handler_name, $class_suffix = null, $params = '', $class_ns = 'owa_'); } $eq = owa_coreAPI::getEventDispatch(); $eq->attachFilter($filter_name, array($handler_name, $method), $priority); }
/** * Constructor * * @param array $config * @return owa_caller */ function __construct($config = array()) { if (empty($config)) { $config = array(); } // 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 $this->e->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_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']); } //owa_coreAPI::debug('cookie domain in caller: '. owa_coreAPI::getSetting('base', 'cookie_domain')); // Backtrace. handy for debugging who called OWA //$bt = debug_backtrace(); //$this->e->debug($bt[4]); // 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 (!defined('OWA_INSTALLING')) { if ($this->c->get('base', 'do_not_fetch_config_from_db') != true) { if ($this->c->isConfigFilePresent()) { $this->c->load($this->c->get('base', 'configuration_id')); } } } /* 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->c->applyModuleOverrides('base', $config); $this->e->debug('Caller configuration overrides applied.'); /* 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')); /* PHP ERROR LOGGING */ if (defined('OWA_LOG_PHP_ERRORS')) { $this->e->logPhpErrors(); } /* 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 logEvent($event_type, $properties) { $ed = owa_coreAPI::getEventDispatch(); if (!is_a($properties, 'owa_event')) { $event = owa_coreAPI::supportClassFactory('base', 'event'); $event->setProperties($properties); $event->setEventType($event_type); } else { $event = $properties; } return $ed->notify($event); }
function logSessionUpdate($event) { if ($event->get('session_id')) { // Make entity $s = owa_coreAPI::entityFactory('base.session'); // Fetch from session from database $s->getByPk('id', $event->get('session_id')); $id = $s->get('id'); // fail safe for when there is no existing session in DB if (empty($id)) { owa_coreAPI::debug("Aborting session update as no existing session was found"); return OWA_EHS_EVENT_FAILED; } // idempotent check needed in case updates are processed out of order. // dont update the database if the event timestamp is older that the last_req // timestamp that is already set on the session object. $last_req_time = $s->get('last_req'); $event_req_time = $event->get('timestamp'); $ret = false; if ($event_req_time > $last_req_time) { // increment number of page views $s->set('num_pageviews', $this->summarizePageviews($id)); // set bounce flag to false as there must have been 2 page views $s->set('is_bounce', 'false'); // update timestamp of latest request that triggered the session update $s->set('last_req', $event->get('timestamp')); // update last page id $s->set('last_page_id', $event->get('document_id')); // set medium if ($event->get('medium')) { $s->set('medium', $event->get('medium')); } // set source if ($event->get('source_id')) { $s->set('source_id', $event->get('source_id')); } // set search terms if ($event->get('referring_search_term_id')) { $s->set('referring_search_term_id', $event->get('referring_search_term_id')); } // set campaign if ($event->get('campaign_id')) { $s->set('campaign_id', $event->get('campaign_id')); } // set ad if ($event->get('ad_id')) { $s->set('ad_id', $event->get('ad_id')); } // set campaign touches if ($event->get('attribs')) { $s->set('latest_attributions', $event->get('attribs')); } // update user name if changed. if ($event->get('user_name')) { if (owa_coreAPI::getSetting('base', 'update_session_user_name')) { // check for different user_name $user_name = $event->get('user_name'); $old_user_name = $s->get('user_name'); if ($user_name != $old_user_name) { $s->set('user_name', $user_name); } } } // Persist to database $ret = $s->update(); } // setup 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.session_update'); // Log session update event to event queue $eq = owa_coreAPI::getEventDispatch(); $ret = $eq->notify($ne); if ($ret) { return OWA_EHS_EVENT_HANDLED; } else { return OWA_EHS_EVENT_FAILED; } } else { owa_coreAPI::debug('Not persisting new session. No session_id present.'); return OWA_EHS_EVENT_HANDLED; } }
function processQueue() { $more = true; while ($more) { $items = $this->getNextItems(); if ($items) { foreach ($items as $item) { owa_coreAPI::debug('About to dispatch queue item id: ' . $item->get('id')); $event = unserialize($item->get('event')); $dispatch = owa_coreAPI::getEventDispatch(); $ret = $dispatch->notify($event); owa_coreAPI::debug($ret); $id = $item->get('id'); if ($ret === OWA_EHS_EVENT_HANDLED) { $this->markAsHandled($id); owa_coreAPI::debug("EHS: marked item ({$id}) as handled."); } else { $this->markAsFailed($id); owa_coreAPI::debug("EHS: marked item ({$id}) as failed."); } } } else { $more = false; } } }
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; } }
/** * Singleton Method * * Returns an instance of OWA * * @return $owa object */ function &owa_getInstance() { static $owa; if (empty($owa)) { require_once OWA_BASE_CLASSES_DIR . 'owa_wp.php'; // create owa instance w/ config $owa = new owa_wp(); $owa->setSiteId(md5(get_settings('siteurl'))); $owa->setSetting('base', 'report_wrapper', 'wrapper_wordpress.tpl'); $owa->setSetting('base', 'link_template', '%s&%s'); $owa->setSetting('base', 'main_url', '../wp-admin/index.php?page=owa'); $owa->setSetting('base', 'main_absolute_url', get_bloginfo('url') . '/wp-admin/index.php?page=owa'); $owa->setSetting('base', 'action_url', get_bloginfo('url') . '/index.php?owa_specialAction'); $owa->setSetting('base', 'api_url', get_bloginfo('url') . '/index.php?owa_apiAction'); $owa->setSetting('base', 'is_embedded', true); // needed as old installs might have this turned on by default... $owa->setSetting('base', 'delay_first_hit', false); // Access WP current user object to check permissions //$current_user = owa_getCurrentWpUser(); //print_r($current_user); // Set OWA's current user info and mark as authenticated so that // downstream controllers don't have to authenticate //$cu->isInitialized = true; // register allowedSitesList filter $dispatch = owa_coreAPI::getEventDispatch(); // alternative auth method, sets auth status, role, and allowed sites list. $dispatch->attachFilter('auth_status', 'owa_wpAuthUser', 0); //print_r( $current_user ); } return $owa; }
/** * Attaches an event handler to the event queue * * @param array $event_name * @param string $handler_name * @return boolean */ public static function registerFilter($filter_name, $callback, $priority = 10) { $eq = owa_coreAPI::getEventDispatch(); $eq->attachFilter($filter_name, $callback, $priority); }
function process_event_log($file) { // check to see if event log file exisits if (!file_exists($file)) { owa_coreAPI::debug("Event file does not exist at {$file}"); return false; } // check for access to db $db = owa_coreAPI::dbSingleton(); $db->connect(); if (!$db->isConnectionEstablished()) { owa_coreAPI::debug("Aborting processing of event log file. Could not connect to database."); return false; } //create lock file $this->create_lock_file(); // get event dispatcher $dispatch = owa_coreAPI::getEventDispatch(); // Create a new log file name $new_file_name = $this->queue_dir . time() . "." . getmypid(); $new_file = $new_file_name . ".processing"; // Rename current log file rename($file, $new_file) or die("Could not rename file"); owa_coreAPI::debug('renamed event file.'); // open file for reading $handle = @fopen($new_file, "r"); if ($handle) { while (!feof($handle)) { // Read row $buffer = fgets($handle, 14096); // big enough? // Parse the row $event = $this->parse_log_row($buffer); // Log event to the event queue if (!empty($event)) { //print_r($event); // debug owa_coreAPI::debug(sprintf('Processing: %s (%s)', '', $event->guid)); // send event object to event queue $ret = $dispatch->notify($event); // is the dispatch was not successful then add the event back into the queue. if ($ret != OWA_EHS_EVENT_HANDLED) { $dispatch->asyncNotify($event); } } else { owa_coreAPI::debug("No event found in log row. Must be end of file."); } } //Close file fclose($handle); // rename file to mark it as processed $processed_file_name = $new_file_name . ".processed"; rename($new_file, $processed_file_name) or die("Could not rename file"); owa_coreAPI::debug(sprintf('Processing Complete. Renaming File to %s', $processed_file_name)); //Delete processed file unlink($processed_file_name); owa_coreAPI::debug(sprintf('Deleting File %s', $processed_file_name)); //Delete Lock file unlink($this->lock_file); return true; } else { //could not open file for processing owa_coreAPI::error(sprintf('Could not open file %s. Terminating Run.', $new_file)); } }
/** * Loads internal $this->assignedSites member */ private function loadAssignedSites() { owa_coreAPI::debug('loading assigned sites'); if (!$this->user->get('id')) { throw new Exception('no user object loaded!'); } $site_ids = array(); $db = owa_coreAPI::dbSingleton(); $db->selectFrom('owa_site_user'); $db->selectColumn('*'); $db->where('user_id', $this->user->get('id')); $site_ids = $db->getAllRows(); // filter array of site_ids. $dispatch = owa_coreAPI::getEventDispatch(); $site_ids = $dispatch->filter('allowed_sites_list', $site_ids); $this->setAllowedSitesList($site_ids); }
ignore_user_abort(true); set_time_limit(180); include_once 'owa_env.php'; require_once OWA_BASE_DIR . '/owa_php.php'; /** * Remote Event Queue Endpoint * * @author Peter Adams <*****@*****.**> * @copyright Copyright © 2006 Peter Adams <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 * @category owa * @package owa * @version $Revision$ * @since owa 1.3.0 */ $owa = new owa_php(); if ($owa->isEndpointEnabled(basename(__FILE__))) { $owa->setSetting('base', 'is_remote_event_queue', true); $owa->e->debug('post: ' . print_r($_POST, true)); $raw_event = owa_coreAPI::getRequestParam('event'); if ($raw_event) { $dispatch = owa_coreAPI::getEventDispatch(); $event = $dispatch->makeEvent(); $event->loadFromArray($raw_event); $owa->e->debug(print_r($event, true)); $dispatch->asyncNotify($event); } } else { // unload owa $owa->restInPeace(); }