static function get_connection()
 {
     if (!self::$_connection) {
         self::$_connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
         if (self::$_connection->error) {
             echo '<h1> hi </h1>';
             error_log(self::$_connection->error);
             _error_handler::go_to_errorpage();
         }
     }
     return self::$_connection;
 }
 function __construct()
 {
     $is_auth = rpc::$auth;
     if (!$is_auth) {
         return;
     }
     $uid = rpc::$user['uid'];
     if (!$uid) {
         return;
     }
     $text = rpc::$postparams['comment'];
     $text = trim(strip_tags($text));
     if (!$text) {
         return;
     }
     $doc_id = (int) rpc::$params['doc_id'];
     if (!$doc_id) {
         return;
     }
     $table = mysql_escape_string(rpc::$params['table']);
     $rtable = $table;
     if ($table == 'releases') {
         $table = 'news';
         $rtable = 'releases';
     }
     if ($table == 'video') {
         $table = 'news';
         $rtable = 'video';
     }
     if ($table == 'radio') {
         $table = 'news';
         $rtable = 'radio';
     }
     if (!$table) {
         return;
     }
     $query = 'SELECT max(`id`) as `id` FROM `comments` WHERE
         `doc_id` = ' . $doc_id . ' AND
         `table`=\'' . $table . '\'';
     $id = _database::torow($query);
     $id = isset($id['id']) ? $id['id'] + 1 : 1;
     $parent = rpc::$params['reply_to'];
     $query = 'INSERT INTO `comments` SET
         `doc_id`=' . $doc_id . ',
         `table`=\'' . $table . '\',
         `id`=' . $id . ',
         `parent`=' . $parent . ',
         `id_author`=' . $uid . ',
         `time`=' . time() . ',
         `comment`=\'' . mysql_escape_string($text) . '\'';
     _database::query($query);
     rpc::$params['write_' . $rtable]['redirect'] = $id;
     $query = 'UPDATE `module_' . $table . '` SET `comment_count`=
         (SELECT COUNT(1)  FROM `comments` WHERE
         `doc_id` = ' . $doc_id . ' AND
         `table`=\'' . $table . '\') WHERE id=' . $doc_id;
     _database::query($query);
     $query = 'UPDATE `users` SET comments = (SELECT COUNT(1)  FROM `comments` WHERE `id_author` = ' . $uid . ')
         WHERE `uid`=' . $uid;
     _database::query($query);
 }
Example #3
0
 /**
  *  gets all answers for the the given qid
  */
 public static function _get_all_answer_by_qid($ref_qid)
 {
     $all_answers = array();
     $connection = _database::get_connection();
     $query = "SELECT * FROM `_answers` WHERE `_a_qid` = {$ref_qid} ORDER BY `_a_time` DESC";
     if ($res = $connection->query($query)) {
         $i = 0;
         while ($arr = $res->fetch_array()) {
             $obj = new _answers();
             $obj->setAid($arr['_aid']);
             $obj->setDescription($arr['_description']);
             $obj->setAUid($arr['_a_uid']);
             $obj->setAQid($arr['_a_qid']);
             $obj->setApt($arr['_apt']);
             $obj->setNotApt($arr['_notapt']);
             $obj->setATime($arr['_a_time']);
             $all_answers[$i] = $obj;
             $i++;
         }
         return $all_answers;
     } else {
         return false;
     }
 }
 static function _get_all_question_by_date()
 {
     if (self::$counter == 0) {
         $connection = _database::get_connection();
         $query = "SELECT * FROM `_questions` ORDER BY `_q_time` DESC";
         if (!($res = $connection->query($query))) {
             return false;
         } else {
             $i = 0;
             while ($arr = $res->fetch_array()) {
                 $obj = new _question();
                 $obj->setQid($arr['_qid']);
                 $obj->setQUid($arr['_q_uid']);
                 $obj->setDescription($arr['_description']);
                 $obj->setCurious($arr['_curious']);
                 $obj->setQTime($arr['_q_time']);
                 self::$_all_question[$i] = $obj;
                 $i++;
             }
         }
         return self::$_all_question;
     } else {
         if (self::$counter++ == 10) {
             self::$counter = 0;
         }
         return self::$_all_question;
     }
 }
Example #5
0
 static function _verify_password($_username, $_check_password)
 {
     $connection = _database::get_connection();
     $query = "SELECT `_password` FROM `_users` WHERE _username='******'";
     $result = $connection->query($query);
     if ($result->num_rows > 0) {
         $result_array = $result->fetch_assoc();
         $_temp_password = $result_array['_password'];
         if ($_temp_password == _user::cipher($_check_password)) {
             return true;
         } else {
             return false;
         }
     }
     return false;
 }