Example #1
0
 public static function get()
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
     }
     return self::$_instance;
 }
Example #2
0
    /**
     * checks if current user has given right
     * 
     * @param string $right
     * @return boolean
     */
    public function hasRight($right)
    {
        if (!$this->authId) {
            return false;
        }
        if (!($rightId = $this->checkRight($right))) {
            return false;
        }
        if (!($right = $this->_parseRight($right))) {
            return false;
        }
        if (PVars::get()->debug) {
            $t = microtime();
            PSurveillance::setPoint('MOD_user_auth' . $t);
        }
        $query = '
SELECT
    r.`id`
FROM `mod_user_auth` AS a
LEFT JOIN `mod_user_authrights` AS ar ON
    ar.`auth_id` = a.`id`
LEFT JOIN `mod_user_rights` AS r ON
    r.`id` = ar.`right_id`
LEFT JOIN `mod_user_groupauth` AS ga ON
    ga.`auth_id` = a.`id`
LEFT JOIN `mod_user_authgroups` AS g ON
    g.`id` = ga.`group_id`
LEFT JOIN `mod_user_grouprights` AS gr ON
    gr.`group_id` = g.`id`
LEFT JOIN `mod_user_implications` AS i ON
    r.`has_implied` = 1 AND i.`right_id` = r.`id`
LEFT JOIN `mod_user_rights` AS r2 ON
    r2.`id` = gr.`right_id`
LEFT JOIN `mod_user_implications` AS i2 ON
    r2.`has_implied` = 1 AND i2.`right_id` = r2.`id`
WHERE 
    a.`id` = ' . (int) $this->authId . '
    AND 
    (r.`id` = ' . (int) $rightId . ' OR gr.`right_id` = ' . (int) $rightId . ' OR i.`implies_id` = ' . (int) $rightId . ' OR i2.`implies_id` = ' . (int) $rightId . ') 
        ';
        $s = $this->dao->query($query);
        if (!isset($right['app'])) {
            $right['app'] = null;
        }
        if (PVars::get()->debug) {
            PSurveillance::setPoint('eoMOD_user_auth' . $t);
        }
        return $s->numRows();
    }
 protected function loadPApps($class_loader)
 {
     $Apps = PApps::get();
     $Apps->build();
     // process includes
     $includes = $Apps->getIncludes();
     if ($includes) {
         foreach ($includes as $inc) {
             require_once $inc;
         }
     }
     PSurveillance::setPoint('apps_loaded');
 }
 /**
  * prepares a statement
  * 
  * returns the key of the statement
  * 
  * @param string $statement
  * @return int
  */
 public function prepare($statement)
 {
     if (PVars::get()->debug) {
         $tm = microtime();
         PSurveillance::setPoint('statement_prepare' . $tm);
     }
     if (isset($this->result) && $this->result) {
         $this->result->close();
         unset($this->result);
     }
     $statement = $this->_dao->MySQLi->prepare($statement);
     if (!$statement) {
         $e = new PException('Could not prepare statement!', 1000);
         $e->addInfo($this->_dao->getErrNo());
         $e->addInfo($this->_dao->getErrMsg());
         throw $e;
     }
     $this->_statement[] = $statement;
     end($this->_statement);
     $k = key($this->_statement);
     $this->_bound = array();
     if (PVars::get()->debug) {
         PSurveillance::setPoint('eostatement_prepare' . $tm);
     }
     $this->_i = $k;
     return $k;
 }
Example #5
0
 /**
  * connector
  * 
  * there will be only one connection instance
  * 
  * @param array $args
  * @param string $user
  * @param string $password
  * @return PDB_mysqli
  */
 protected static function connect($args, $user = false, $password = false)
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
         if (PVars::get()->debug) {
             $t = microtime();
             PSurveillance::setPoint('connect' . $t);
         }
         if (!isset($args['host'])) {
             throw new PException('Host not set!');
         }
         if (!isset($args['dbname'])) {
             throw new PException('DB name not set!');
         }
         $mysqli = @new mysqli($args['host'], $user, $password, $args['dbname']);
         if (!$mysqli || mysqli_connect_errno()) {
             $E = new PException('Could not connect!');
             $E->addInfo(mysqli_connect_error());
             throw $E;
         }
         self::$_instance->_MySQLi = $mysqli;
         self::$_instance->_dbname = $args['dbname'];
         $queries = array("SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'", "SET collation_connection='utf8_general_ci'");
         foreach ($queries as $query) {
             $q = self::$_instance->exec($query);
             if (!$q) {
                 throw new PException('MySQL collation error!', 1000);
             }
         }
         if (PVars::get()->debug) {
             PSurveillance::setPoint('eoconnect' . $t);
         }
     }
     return self::$_instance;
 }
 /**
  * prepares a statement
  * 
  * returns the key of the statement
  * 
  * @param string $statement
  * @return int
  */
 public function prepare($statement)
 {
     if (PVars::get()->debug) {
         $tm = microtime();
         PSurveillance::setPoint('statement_prepare' . $tm);
     }
     $tokens = preg_split('%((?<!\\\\)(?:\\?|:[a-z]+))%', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
     $newtokens = array();
     $rep = array();
     foreach ($tokens as $pos => $t) {
         switch (true) {
             case preg_match('%^:[a-z]+$%', $t):
             case $t == '?':
                 $rep[$pos] = $t;
                 $newtokens[$pos] = $t;
                 break;
             default:
                 $newtokens[$pos] = preg_replace('%\\\\(\\?|:[a-z]+)%', '\\1', $t);
                 break;
         }
     }
     $this->_statement[] = array($newtokens, $rep);
     end($this->_statement);
     $k = key($this->_statement);
     $this->_bound = array();
     if (PVars::get()->debug) {
         PSurveillance::setPoint('eostatement_prepare' . $tm);
     }
     return $k;
 }
Example #7
0
 /**
  * connector
  * 
  * there will be only one connection instance
  * 
  * @param array $args
  * @param string $user
  * @param string $password
  * @return PDB_mysql
  */
 protected static function connect($args, $user = false, $password = false)
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
         if (PVars::get()->debug) {
             $t = microtime();
             PSurveillance::setPoint('connect' . $t);
         }
         if (!isset($args['host'])) {
             throw new PException('Host not set!');
         }
         if (!isset($args['dbname'])) {
             throw new PException('DB name not set!');
         }
         $cr = @mysql_connect($args['host'], $user, $password, true);
         if (!$cr) {
             throw new PException('Could not connect!');
         }
         self::$_instance->_cr = $cr;
         if (!@mysql_select_db($args['dbname'])) {
             throw new PException('Could not select DB: ' . $args['dbname'] . '!');
         }
         self::$_instance->_dbname = $args['dbname'];
         $queries = array("SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'", "SET collation_connection='utf8_general_ci'");
         foreach ($queries as $query) {
             $q = self::$_instance->query($query);
             if (!$q) {
                 throw new PException('MySQL collation error!', 1000);
             }
         }
         if (PVars::get()->debug) {
             PSurveillance::setPoint('eoconnect' . $t);
         }
     }
     return self::$_instance;
 }