Exemplo n.º 1
0
 /**
  * Starts session
  * Loads / creates a session based on activity
  *
  * @return
  */
 protected function _startSession()
 {
     if (!is_array($this->request['sid'])) {
         $session_id = IPSText::md5Clean($this->request['sid']);
     } else {
         $session_id = '';
     }
     $requestType = $this->request['request_method'] == 'post' ? 'post' : 'get';
     if ($session_id) {
         /* We check on member id 'cos we can. Obviously guests will have a member ID of zero, but meh */
         $this->_session = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'search_sessions', 'where' => 'session_id=\'' . $session_id . '\' AND session_member_id=' . $this->memberData['member_id']));
     }
     /* Deflate */
     if ($this->_session['session_id']) {
         if ($this->_session['session_data']) {
             $this->_session['_session_data'] = unserialize($this->_session['session_data']);
             if (isset($this->_session['_session_data']['search_app_filters'])) {
                 $this->request['search_app_filters'] = is_array($this->request['search_app_filters']) ? array_merge($this->_session['_session_data']['search_app_filters'], $this->request['search_app_filters']) : $this->_session['_session_data']['search_app_filters'];
             }
         }
         IPSDebug::addMessage("Loaded search session: <pre>" . var_export($this->_session['_session_data'], true) . "</pre>");
     } else {
         /* Create a session */
         $this->_session = array('session_id' => md5(uniqid(microtime(), true)), 'session_created' => time(), 'session_updated' => time(), 'session_member_id' => $this->memberData['member_id'], 'session_data' => serialize(array('search_app_filters' => $this->request['search_app_filters'])));
         $this->DB->insert('search_sessions', $this->_session);
         $this->_session['_session_data']['search_app_filters'] = $this->request['search_app_filters'];
         IPSDebug::addMessage("Created search session: <pre>" . var_export($this->_session['_session_data'], true) . "</pre>");
     }
     /* Do we have POST infos? */
     if (isset($_POST['search_app_filters'])) {
         $this->_session['_session_data']['search_app_filters'] = is_array($this->_session['_session_data']['search_app_filters']) ? IPSLib::arrayMergeRecursive($this->_session['_session_data']['search_app_filters'], $_POST['search_app_filters']) : $_POST['search_app_filters'];
         $this->request['search_app_filters'] = $this->_session['_session_data']['search_app_filters'];
         IPSDebug::addMessage("Updated filters: <pre>" . var_export($_POST['search_app_filters'], true) . "</pre>");
     }
     /* Globalize the session ID */
     $this->request['_sid'] = $this->_session['session_id'];
 }