function Query($querid, $query, $postfields = NULL, $extras = NULL)
 {
     if (!empty($query) && preg_match("/^https?:\\/\\//", $query)) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $query);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         if ($postfields) {
             #        $custom_request="POST /boomsvc30/SimpleTxEmail.asmx HTTP/1.1";
             #        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom_request);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
         } else {
             curl_setopt($ch, CURLOPT_HTTPGET, 1);
         }
         if ($extras['timeout']) {
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $extras['timeout']);
         }
         if ($extras['headers']) {
             curl_setopt($ch, CURLOPT_HEADER, 1);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array($extras['headers']));
         } else {
             curl_setopt($ch, CURLOPT_HEADER, 0);
         }
         #echo "[QUERY]".$query."[QUERY]";
         #echo "[POSTFIELDS]".$postfields ."[POSTFIELDS]";
         #echo "[HEADERS]".$extras['headers']."[HEADERS]";
         Logger::Notice("Remotefile Wrapper requesting URL: {$query}");
         if (!empty($postfields)) {
             Logger::Debug($postfields);
         }
         if (!empty($extras['headers'])) {
             Logger::Debug($extras['headers']);
         }
         $ret = curl_exec($ch);
         if (curl_errno($ch)) {
             $ret = curl_errno($ch) . "<br />" . curl_error($ch);
             Logger::Error($ret);
         }
         curl_close($ch);
     }
     #echo "[RETURN]".($ret)."[RETURN]";
     return $ret;
 }
 static function add($args)
 {
     if (empty($args["type"])) {
         $args["type"] = "component";
     }
     $browser = !empty($args["browser"]) ? $args["browser"] : "all";
     $priority = !empty($args["priority"]) ? $args["priority"] : 2;
     if (!isset(self::$dependencies[$priority]) || !is_array(self::$dependencies[$priority])) {
         self::$dependencies[$priority] = array();
     }
     //self::$dependencies[$args["type"]][] = Dependency::create($args["type"], $args);
     $dep = Dependency::create($args["type"], $args);
     if (!isset(self::$dependencies[$priority][$browser][$args["type"]][$dep->id()])) {
         self::$dependencies[$priority][$browser][$args["type"]][$dep->id()] = $dep;
         if (Logger::$enabled) {
             Logger::Notice("Added {$args["type"]} dependency ({$browser}): '{$dep->content()}'");
         }
     }
 }
Example #3
0
 /**
  * This method is used to delete record(s) from
  * a table in the db.
  *
  * @param string the table name
  * @param string the where clause condition
  *        NOTE: this doesn't include the 'where' word.
  *        Example: 'siteid=:siteid and foo=:foo'
  * @param array the bind vars that live in the where clause
  *        Example: array(':siteid' => 69,
  *                       ':foo' => 'blah blah');
  * @return boolean TRUE = success
  */
 public function delete($table, $where_condition = NULL, $bind_vars = array())
 {
     $sql = 'DELETE FROM ' . $table;
     if (!is_null($where_condition)) {
         $sql .= ' WHERE ' . $where_condition;
         Logger::Notice("Execute query: '" . $sql . "' " . print_ln($bind_vars, true));
         //we now have to prepare the query
         //and bind all of the values.
         try {
             $stmt = $this->db->prepare($sql);
         } catch (PDOException $e) {
             //throw new DataBaseException($e->getMessage(), $e->getCode(), $sql, $bind_vars);
             throw $e;
         }
         //ok now bind the parameters
         //first bind the user provided vars
         if (!empty($bind_vars)) {
             $i = 1;
             foreach ($bind_vars as $key => $value) {
                 // determine if this is binding by ? or by :name
                 $key = $key[0] == ":" ? $key : $i;
                 $stmt->bindValue($key, $value);
                 $i++;
             }
         }
     } else {
         //we now have to prepare the query
         //and bind all of the values.
         $stmt = $this->db->prepare($sql);
     }
     //and now execute it!
     $result = $stmt->execute();
     Logger::Debug("Database::delete() - {$sql}");
     return $result;
 }
Example #4
0
 function LoadModel()
 {
     //$cfg = ConfigManager::singleton();
     //$fname = $cfg->locations["config"] . "/model/" . $this->name . ".model";
     $fname = "./config/model/" . $this->name . ".model";
     if (file_exists($fname)) {
         $ormfile = file_get_contents($fname);
         $filesize = strlen($ormfile);
         $modelcfg = json_decode($ormfile);
         if (!empty($modelcfg->classes)) {
             $this->classes = $modelcfg->classes;
         }
     } else {
         Logger::Notice("OrmModel: Couldn't find model config '{$fname}'");
     }
 }
 function LazyOpen($num = 0)
 {
     if ($this->lazy && empty($this->blacklisted[$num])) {
         $pingstatus = $this->Ping($num);
         if ($pingstatus) {
             $ret = true;
         } else {
             // Not connected, let's see what we can do
             Logger::Notice("Establishing connection: {$this->name} (" . get_class($this) . ")");
             if ($this->Open($num)) {
                 $ret = true;
             } else {
                 $this->blacklisted[$num] = true;
                 $ret = false;
             }
         }
     } else {
         $ret = false;
     }
     return $ret;
 }
Example #6
0
 static function Rollback($id)
 {
     Profiler::StartTimer("DataManager::Rollback()");
     $queryid = new DatamanagerQueryID($id);
     if ($source =& DataManager::PickSource($queryid)) {
         $ret = $source->Rollback($queryid);
     }
     Profiler::StopTimer("DataManager::Rollback()");
     Logger::Notice("Rolled back transaction for queryid {$queryid->id}");
     return $ret;
 }
 /**
  * Create a new persist record in the userdata.usersssion table
  */
 protected function create_new_persist_record($force = false)
 {
     // if bot, don't create a db record
     if (function_exists("isBot") && isBot()) {
         return;
     }
     // insert a record into userdata.usersession
     if ($force || !empty($_SESSION["persist"])) {
         $_SESSION["persist"]["has_db_record"] = true;
         $pdata_serialize = serialize($_SESSION["persist"]);
         $ip = $_SERVER['REMOTE_ADDR'];
         Logger::Notice("Creating session in database");
         $result = DataManager::QueryInsert($this->sessionsource . "#{$this->fluid}", $this->sessiontable, array($this->fluid => array("fl_uid" => $this->fluid, "data" => $pdata_serialize, "ip_addr" => $ip)));
         // set the $_SESSION
         $this->has_db_record = true;
     }
 }
 /**
  * Initialize the session.
  * Start the session.
  */
 protected function init()
 {
     $this->data = DataManager::singleton();
     Profiler::StartTimer("SessionManager::Init()", 2);
     /*
     if ($this->data->caches["memcache"]["session"] !== NULL) {
       $this->cache_obj = $this->data->caches["memcache"]["session"];
       //$this->session_cache_expire = $this->data->caches["memcache"]["session"]->lifetime;
     } else {
       // Continue anyway even if cannot connect to memcache.
       // Point the cache_obj to NoCache object
       //print_pre($this->data);
       Logger::Error("SessionManager::init() - Cannot connect to session memcache - " . $this->data->sources);
       $this->cache_obj =& NoCache::singleton();
     }
     */
     if (class_exists("PandoraLog")) {
         // instantiate the pandora object (analytics collection)
         $pandora = PandoraLog::singleton();
     }
     // check to see if there is an existing cookie for flsid
     $has_flsid = isset($_COOKIE['flsid']) || isset($_REQUEST['flsid']);
     $this->is_new_session = $has_flsid == 1 ? 0 : 1;
     // if flsid was passed via the URL, set it as a cookie
     if (!empty($_GET['flsid'])) {
         setcookie("flsid", $_GET['flsid'], 0, '/');
         $this->flsid = $_COOKIE['flsid'] = $_GET['flsid'];
     }
     session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc'));
     // register_shutdown_function('session_write_close');
     // Set session cookie params
     $domain = null;
     $cfgmgr = ConfigManager::singleton();
     $sessioncfg = any($cfgmgr->servers["session"], array());
     $sessionpath = any($sessioncfg["cookiepath"], "/");
     if ($sessioncfg["domaincookie"]) {
         // Determine second-level domain, taking into account any known ccSLDs (.co.uk, etc)
         global $webapp;
         $FQDN = $webapp->request["host"];
         $knownccSLDs = explode(" ", any($sessioncfg["ccSLDs"], ""));
         $parts = explode(".", $FQDN);
         $TLD = array_pop($parts);
         $SLD = array_pop($parts);
         $domain = $SLD . "." . $TLD;
         if (in_array($domain, $knownccSLDs)) {
             $TLD = $domain;
             $SLD = array_pop($parts);
             $domain = $SLD . "." . $domain;
         }
         $excludeDomains = explode(" ", any($sessioncfg["domaincookie_exception"], ""));
         if (in_array($domain, $excludeDomains)) {
             $domain = null;
         }
     }
     session_set_cookie_params(0, $sessionpath, $domain);
     // set the garbage collection lifetime (on the DB persist data)
     ini_set('session.gc_maxlifetime', 31536000);
     // 31536000 = 60 * 60 * 24 * 365
     // set the session cookie name
     session_name($this->cookiename);
     // set the cache limiter to 'private' - keeps us from sending Pragma: no-cache
     session_cache_limiter('private');
     // initiate sessionization
     if (!headers_sent()) {
         session_start();
     }
     /**
      * Read the permanent session ID from cookie.
      * If there isn't one, create one.
      */
     // read the permanent cookie
     $fluid_str = "";
     if (isset($_REQUEST['fluid'])) {
         $fluid_str = $_REQUEST['fluid'];
     } else {
         if (isset($_COOKIE['fl-uid'])) {
             $fluid_str = $_COOKIE['fl-uid'];
         } else {
             if (isset($_SESSION['fluid'])) {
                 $fluid_str = $_SESSION['fluid'];
             }
         }
     }
     $fluid_data = explode(",", $fluid_str);
     $this->fluid = $fluid_data[0];
     $this->session_count = isset($fluid_data[1]) ? $fluid_data[1] : 0;
     $this->last_access = isset($fluid_data[2]) ? $fluid_data[2] : 0;
     $this->first_session_for_day = 0;
     $this->days_since_last_session = 0;
     $this->is_new_user = 0;
     if (empty($this->fluid)) {
         // create new permanent cookie
         $this->is_new_user = 1;
         $this->fluid = $this->generate_fluid();
         $this->session_count = 0;
         $this->last_access = time();
         $this->first_session_for_day = 1;
         $this->days_since_last_session = 0;
         $fluid_data = $this->fluid . ',' . $this->session_count . ',' . $this->last_access;
         //setcookie('fl-uid', $fluid_data, time()+31536000, "/", $domain); // (1 year)
         $pdata_serialize = isset($_SESSION["persist"]) ? serialize($_SESSION["persist"]) : "";
         $this->crc = strlen($pdata_serialize) . crc32($pdata_serialize);
     }
     if (!$has_flsid) {
         // new session -- update the permanent cookie
         // Deal with errant mis-named 'fl_uid' cookies...
         // (this code can safely be removed in a year or so, e.g. February 2010)
         // ^^^ perhaps not?
         if ($fluid_data_recover = explode(",", $_COOKIE['fl_uid'])) {
             $this->fluid = any($this->fluid, $fluid_data_recover[0]);
             $this->session_count = $fluid_data_recover[1];
             $this->last_access = $fluid_data_recover[2];
             //setcookie('fl_uid', '', 0, "/", $domain); // delete the errant cookie
         }
         $this->session_count++;
         if (time() > $this->last_access + 86400) {
             $this->days_since_last_session = floor((time() - $this->last_access) / 86400);
             $this->last_access = time();
             $this->first_session_for_day = 1;
         }
         $fluid_data = $this->fluid . ',' . $this->session_count . ',' . $this->last_access;
         if (!headers_sent()) {
             setcookie('fl-uid', $fluid_data, time() + 31536000, "/", $domain);
             // (update the permanent cookie)
         }
     }
     // debugging
     // print "<hr>In SessionManager::init() - cache_obj extended stats = " . print_pre($this->cache_obj->GetExtendedStats());
     /**
      * First, check to see if there is an entry in the memcache for this fluid.
      * If so, use it.
      * If not, query the DB to get the persistent session data.
      * If not in the DB, create a new session.
      */
     $this->flsid = session_id();
     //$session_memcache = $this->cache_obj->get($this->flsid);
     $session_memcache = DataManager::fetch("memcache.session#{$this->flsid}", $this->flsid);
     //$tmpsession = unserialize($session_memcache);
     if (!empty($session_memcache["fluid"])) {
         $this->fluid = $session_memcache["fluid"];
     }
     if (empty($session_memcache) && !$this->is_new_user) {
         /*
         $result = $this->data->Query("db.userdata.usersession.{$this->flsid}:nocache",
                                      "SELECT data FROM usersession.usersession WHERE fl_uid=:fl_uid LIMIT 1",
                                      array(":fl_uid" => $this->fluid));
         */
         $result = DataManager::QueryFetch($this->sessionsource . "#{$this->fluid}", $this->sessiontable, array("fl_uid" => $this->fluid));
         if ($result && count($result) == 1) {
             $data = current($result);
             $_SESSION["persist"] = unserialize($data["data"]);
             $this->has_db_record = true;
             if (!$_SESSION["persist"]["has_db_record"]) {
                 $_SESSION["persist"]["has_db_record"] = true;
             }
         }
     } else {
         $_SESSION = $session_memcache;
         //Logger::Error(print_r($_SESSION, true));
     }
     $this->has_db_record = isset($_SESSION["persist"]) && $_SESSION["persist"]["has_db_record"] ? true : false;
     // Store permenant session id, actual (temporary) session id,
     // and create pointers to $_SESSION memory space
     $this->flsid = session_id();
     $this->persist =& $_SESSION["persist"];
     $this->temporary =& $_SESSION["temporary"];
     // get from the persist session data if this is a new or registered user
     $userid = $_SESSION["persist"]["user"]["userid"];
     $usertype = $_SESSION["persist"]["user"]["usertype"];
     $userTypeArray = User::$usertypes;
     if (class_exists("PandoraLog")) {
         $pandoraUserTypeNum = any($userTypeArray[$usertype], 0);
         // log this into Pandora
         $pandora_session = array("timestamp" => time(), "session_id" => $this->flsid, "fluid" => $this->fluid, "is_new_user" => $this->is_new_user, "is_registered_user" => $userid ? 1 : 0, "ip_addr" => $_SERVER['REMOTE_ADDR'], "user_agent" => $_SERVER['HTTP_USER_AGENT'], "referrer_url" => $_SERVER['HTTP_REFERER'], "landing_page_url" => "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], "referrer_id" => $webapp->request["args"]["rid"], "widget_id" => $webapp->request["args"]["wid"], "user_registration_id" => "{$pandoraUserTypeNum}.{$userid}", "version" => 0, "cobrand" => $this->root->cobrand, "first_session_for_day" => $this->first_session_for_day, "session_count" => $this->session_count, "days_since_last_session" => $this->days_since_last_session);
         // log this session for data warehouse (once per session)
         if (!$has_flsid) {
             //store the session start time in session
             $_SESSION['session_start_time'] = time();
             $pandora->addData("session", $pandora_session);
         } else {
             Logger::Notice("Pandora: Session already has an flsid. Current start time from session is: " . var_export($_SESSION['session_start_time'], true));
             if (!array_key_exists('session_start_time', $_SESSION)) {
                 $_SESSION['session_start_time'] = time();
                 $pandora->addData("session", $pandora_session);
             } else {
                 Logger::Notice("Pandora: Session already has an flsid. Current start time from session is: " . var_export($_SESSION['session_start_time'], true));
                 if (!array_key_exists('session_start_time', $_SESSION)) {
                     $_SESSION['session_start_time'] = time();
                     Logger::Warn("Pandora: Set or reset the session start time as one did not exist before. Time is: " . var_export($_SESSION['session_start_time'], true));
                 } else {
                     Logger::Notice("Pandora: Session start time was not reset. Time is: " . var_export($_SESSION['session_start_time'], true));
                 }
             }
         }
     }
     //save session data once per session
     //    if(!array_key_exists('pandora_session_data_added', $_SESSION)) {
     //      $pandora->addData("session", $pandora_session);
     //      $_SESSION['pandora_session_data_added'] = true;
     //    }
     $_SESSION["fluid"] = $this->fluid;
     // set the script session ID
     $this->flssid = $this->generate_fluid();
     Profiler::StopTimer("SessionManager::Init()");
 }