Beispiel #1
0
 /**
  * sets the currently used language in the session
  *
  * @access public
  * @return bool
  */
 public function setLanguage()
 {
     if (!$this->isLoaded()) {
         return false;
     }
     $_SESSION['lang'] = $this->ShortCode;
     $_SESSION['IdLanguage'] = $this->id;
     PVars::register('lang', $_SESSION['lang']);
     return true;
 }
 private function __construct()
 {
     if (isset($_SERVER['argc']) && isset($_SERVER['argv']) && is_array($_SERVER['argv']) && $_SERVER['argc'] != 0) {
         $args = $_SERVER['argv'];
         unset($args[0]);
         parse_str(implode('&', $args), $args);
         $this->_cliArgs = $args;
     } else {
         $request = self::parseRequest();
         PVars::register('request', $request);
         $this->_request = $request;
         if (isset($_SESSION['thisRequest'])) {
             $_SESSION['lastRequest'] = $_SESSION['thisRequest'];
         }
         $_SESSION['thisRequest'] = $request;
     }
 }
 /**
  * Initialise the current user.
  * Sets language and online status.
  */
 protected function initUser()
 {
     $this->setLanguage();
     PVars::register('lang', $_SESSION['lang']);
     $roxModelBase = new RoxModelBase();
     $member = $roxModelBase->getLoggedInMember();
     // try restoring session from memory cookie
     if (!$member) {
         $member = $roxModelBase->restoreLoggedInMember();
     }
     $memberId = false;
     if ($member) {
         if ($member->isBanned()) {
             $member->logOut();
         } else {
             $memberId = $member->id;
         }
     }
     $ipAsInt = intval(ip2long($_SERVER['REMOTE_ADDR']));
     MOD_online::get()->iAmOnline($ipAsInt, $memberId);
 }
 /**
  * globals are said to be evil, but we need them, at least for legacy reasons.
  *
  * @param unknown_type $settings
  */
 private function _initPVars($settings)
 {
     $keymap = array();
     foreach ($settings as $key => $value) {
         $keymap[$key] = $key;
     }
     // some of the keys need another name
     foreach (array('db' => 'db', 'config_rdbms' => 'db', 'config_smtp' => 'smtp', 'config_mailAddresses' => 'mailAddresses', 'config_request' => 'request', 'config_google' => 'google', 'env' => 'env') as $key_in_pvars => $key_in_inifile) {
         $keymap[$key_in_pvars] = $key_in_inifile;
     }
     foreach ($keymap as $key => $value) {
         if (isset($settings[$value])) {
             PVars::register($key, $settings[$value]);
         }
     }
     if (empty($_COOKIE[session_name()])) {
         PVars::register('cookiesAccepted', false);
     } else {
         PVars::register('cookiesAccepted', true);
     }
     PVars::register('queries', 0);
 }
 /**
  * execute a prepared statement
  * 
  * the $params parameter is used for backwards compatibility
  */
 public function execute()
 {
     if (is_array($this->_bound) && count($this->_bound) > 0) {
         $bstring = '';
         $args = array();
         foreach ($this->_bound as $val) {
             $bstring .= is_int($val) ? 'i' : is_float($val) ? 'd' : 's';
             $args[] = $val;
         }
         array_unshift($args, $bstring);
         $callback = array(&$this->_statement[$this->_i], 'bind_param');
         if (!call_user_func_array($callback, $args)) {
             print_r($callback);
             print_r($this);
             exit;
         }
         $offs = 0;
         if (substr_count($args[0], 'b') > 0) {
             while ($pos = strpos($args[0], 'b', $offs)) {
                 $blob = str_split($args[$pos], ini_get('max_allowed_packet'));
                 foreach ($blob as $b) {
                     $this->_statement[$this->_i]->send_long_data($pos, $b);
                 }
                 $offs = $pos;
             }
         }
     }
     $q = @$this->_statement[$this->_i]->execute();
     if (!$q) {
         $e = new PException('MySQL error!', 1000);
         if (isset($args)) {
             $e->addInfo(print_r($args, true));
             $e->addInfo(print_r($this->_bound, true));
         }
         $e->addInfo($this->_dao->getErrNo());
         $e->addInfo($this->_dao->getErrMsg());
         throw $e;
     }
     if (is_object($q)) {
         $this->result = $q;
     }
     $this->pos = 0;
     $q = PVars::get()->queries + 1;
     PVars::register('queries', $q);
     return true;
 }
Beispiel #6
0
 /**
  * executes a statement and returns the no of affected rows
  * 
  * @param string $statement
  * @return int
  */
 public function exec($statement)
 {
     try {
         if (!$this->ready()) {
             throw new PException('MySQL connection not ready!');
         }
         $q = $this->_MySQLi->query($statement);
         if (!$q) {
             throw new PException('MySQL error!', 1000);
         }
         $qcount = PVars::get()->queries + 1;
         PVars::register('queries', $qcount);
         if (is_object($q)) {
             return $q->affected_rows;
         } else {
             return $q;
         }
     } catch (PException $e) {
         throw $e;
     }
 }
 public function query($query)
 {
     if (PVars::get()->debug) {
         $start_time = microtime(true);
     }
     $q = @mysql_query($query, $this->_dao->cr);
     if (!$q) {
         $e = new PException('MySQL error!', 1000);
         $e->addInfo('Statement: ' . $query);
         $e->addInfo($this->_dao->getErrNo());
         $e->addInfo($this->_dao->getErrMsg());
         throw $e;
     }
     $this->result = $q;
     $this->pos = 0;
     $q = PVars::get()->queries + 1;
     PVars::register('queries', $q);
     if (PVars::get()->debug) {
         $q = PVars::get()->query_history;
         $query_time = sprintf("%.1f", (microtime(true) - $start_time) * 1000);
         $q[] = "({$query_time} ms) {$query}";
         PVars::register('query_history', $q);
     }
     return true;
 }
Beispiel #8
0
 /**
  * executes a statement and returns the no of affected rows
  * 
  * @param string $statement
  * @return int
  */
 public function exec($statement)
 {
     try {
         if (!$this->ready()) {
             throw new PException('MySQL connection not ready!');
         }
         $q = @mysql_query($statement, $this->_cr);
         if (!$q) {
             throw new PException('MySQL error!', 1000);
         }
         $q = PVars::get()->queries + 1;
         PVars::register('queries', $q);
         return mysql_affected_rows($this->_cr);
     } catch (PException $e) {
         throw $e;
     }
 }