예제 #1
0
파일: suxRSS.php 프로젝트: hashimmm/sux0r
 /**
  * @param int $id feed id
  */
 function deleteFeed($id)
 {
     if (!filter_var($id, FILTER_VALIDATE_INT) || $id < 1) {
         return false;
     }
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     $st = $this->db->prepare("DELETE FROM {$this->db_feeds} WHERE id = ? ");
     $st->execute(array($id));
     $st = $this->db->prepare("SELECT id FROM {$this->db_items} WHERE rss_feeds_id = ? ");
     $st->execute(array($id));
     $result = $st->fetchAll(PDO::FETCH_ASSOC);
     // Used with link deletion
     $st = $this->db->prepare("DELETE FROM {$this->db_items} WHERE rss_feeds_id = ? ");
     $st->execute(array($id));
     // Delete links, too
     $link = new suxLink();
     $links = $link->getLinkTables('rss_feeds');
     foreach ($links as $table) {
         $link->deleteLink($table, 'rss_feeds', $id);
     }
     $links = $link->getLinkTables('rss_items');
     foreach ($links as $table) {
         foreach ($result as $key => $val) {
             $link->deleteLink($table, 'rss_items', $val['id']);
         }
     }
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
예제 #2
0
        if ($st->fetchColumn() <= 0) {
            $not_found[] = array($val, $tmp2, $val2[$tmp2], $tmp3, $val2[$tmp3]);
            continue;
        }
        // Table 2
        $query = 'SELECT id FROM ' . $parts[2] . " WHERE id = {$val2[$tmp3]} ";
        $st = $db->query($query);
        if ($st->fetchColumn() <= 0) {
            $not_found[] = array($val, $tmp3, $val2[$tmp3], $tmp2, $val2[$tmp2]);
            continue;
        }
    }
}
// Delete dead links
$count = 0;
$tid = suxDB::requestTransaction();
foreach ($not_found as $val) {
    // $val[0] -> link_table_name
    // $val[1] -> column_name_1
    // $val[2] -> column_id_1
    // $val[3] -> column_name_2
    // $val[4] -> column_id_2
    $query = "DELETE FROM {$val[0]} WHERE {$val[1]} = {$val[2]} AND {$val[3]} = {$val[4]} ";
    if (!$debug) {
        $count += $db->exec($query);
    }
    echo $query . "; <br /> \n";
}
suxDB::commitTransaction($tid);
echo "> {$count} links deleted <br /> \n";
// ----------------------------------------------------------------------------
예제 #3
0
 /**
  * Update probabilities
  */
 function updateProbabilities()
 {
     // A vector is an array of categories. Probabilities must be
     // constrained to vector and not the entire tokens table. We need to
     // join tokens to categories, which contains vector_ids.
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     // Get vector_ids that are actually being used
     $vectors = array();
     $q = "SELECT bayes_vectors_id FROM {$this->db_table_cat} GROUP BY bayes_vectors_id ";
     $st = $this->db->query($q);
     foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $row) {
         $vectors[] = $row['bayes_vectors_id'];
     }
     // Join to categories
     $q = "SELECT {$this->db_table_tok}.bayes_categories_id, SUM({$this->db_table_tok}.count) AS total\n        FROM {$this->db_table_tok} INNER JOIN {$this->db_table_cat}\n        ON {$this->db_table_tok}.bayes_categories_id = {$this->db_table_cat}.id\n        WHERE {$this->db_table_cat}.bayes_vectors_id = ?\n        GROUP BY {$this->db_table_tok}.bayes_categories_id ";
     // Constrain to individual vectors
     foreach ($vectors as $vector_id) {
         // Get the total of all known tokens
         $total_tokens = 0;
         $st = $this->db->prepare($q);
         $st->execute(array($vector_id));
         foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $row) {
             $total_tokens += $row['total'];
         }
         // If there are no tokens, reset everything
         if ($total_tokens == 0) {
             $st = $this->db->prepare("UPDATE {$this->db_table_cat} SET token_count = 0, probability = 0 WHERE bayes_vectors_id = ? ");
             $st->execute(array($vector_id));
             continue;
         }
         // Get all categories
         $categories = array();
         $st = $this->db->prepare("SELECT id FROM {$this->db_table_cat} WHERE bayes_vectors_id = ? ");
         $st->execute(array($vector_id));
         foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $row) {
             $categories[$row['id']] = true;
         }
         // Repeat $q, update probabilities
         $st = $this->db->prepare($q);
         $st->execute(array($vector_id));
         $st2 = $this->db->prepare("UPDATE {$this->db_table_cat} SET token_count = ?, probability = ? WHERE id = ? AND bayes_vectors_id = ? ");
         foreach ($st->fetchAll(PDO::FETCH_ASSOC) as $row) {
             $proba = $row['total'] / $total_tokens;
             $st2->execute(array($row['total'], $proba, $row['bayes_categories_id'], $vector_id));
             unset($categories[$row['bayes_categories_id']]);
         }
         // If there are categories with no tokens, reset those categories
         $st = $this->db->prepare("UPDATE {$this->db_table_cat} SET token_count = 0, probability = 0 WHERE id = ? AND bayes_vectors_id = ? ");
         foreach ($categories as $key => $val) {
             $st->execute(array($key, $vector_id));
         }
     }
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
예제 #4
0
 /**
  * @param  string $document_id document id, must be unique
  * @return bool
  */
 protected function removeDocument($document_id)
 {
     /* Override parent */
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     // Remove any links to category documents in associated link tables
     $links = $this->link->getLinkTables('bayes_documents');
     foreach ($links as $tmp) {
         $this->link->deleteLink($tmp, 'bayes_documents', $document_id);
     }
     $_bool = parent::removeDocument($document_id);
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
     return $_bool;
 }
예제 #5
0
파일: suxTags.php 프로젝트: hashimmm/sux0r
 /**
  * Delete tag
  *
  * @param int $id tag id
  */
 function delete($id)
 {
     if (!filter_var($id, FILTER_VALIDATE_INT) || $id < 1) {
         return false;
     }
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     $st = $this->db->prepare("DELETE FROM {$this->db_table} WHERE id = ? ");
     $st->execute(array($id));
     // Delete links, too
     $link = new suxLink();
     $links = $link->getLinkTables('tags');
     foreach ($links as $table) {
         $link->deleteLink($table, 'tags', $id);
     }
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
예제 #6
0
파일: suxLink.php 프로젝트: hashimmm/sux0r
 /**
  * Delete link
  *
  * @param string $link name of the link table
  * @param string $table name of the table
  * @param int|array $id either a primary key, or an array of primary keys
  * @param bool if true, use the key of $id as the data
  */
 function deleteLink($link, $table, $id, $onkey = false)
 {
     if (!is_array($id)) {
         $tmp = $id;
         unset($id);
         $id[] = $tmp;
     }
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     foreach ($id as $key => $val) {
         $st = $this->db->prepare("DELETE FROM {$link} WHERE {$table}_id = ? ");
         if ($onkey) {
             $st->execute(array($key));
         } else {
             $st->execute(array($val));
         }
     }
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
예제 #7
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // --------------------------------------------------------------------
     // Delete !!!
     // --------------------------------------------------------------------
     if (isset($clean['delete_user']) && $clean['delete_user'] == 1) {
         // Begin transaction
         $db = suxDB::get();
         $tid = suxDB::requestTransaction();
         try {
             $query = 'DELETE FROM bayes_auth WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM bookmarks WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM link__bookmarks__users WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM link__rss_feeds__users WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM messages WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM messages_history WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM openid_trusted WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM photoalbums WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM photos WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM rss_feeds WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM socialnetwork WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM socialnetwork WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM tags WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM users_access WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM users_info WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM users_log WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM users_openid WHERE users_id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             $query = 'DELETE FROM users WHERE id = ? ';
             $st = $db->prepare($query);
             $st->execute(array($this->users_id));
             // Log, private
             $this->log->write($_SESSION['users_id'], "sux0r::adminAccess() deleted users_id: {$this->users_id} ", 1);
         } catch (Exception $e) {
             $db->rollback();
             throw $e;
             // Hot potato!
         }
         suxDB::commitTransaction($tid);
         // Commit
         return;
         // Drop out of this function
     }
     // --------------------------------------------------------------------
     // Resume normal access control
     // --------------------------------------------------------------------
     // Root
     if (isset($clean['root'])) {
         $this->user->root($this->users_id);
     } elseif ($this->users_id != $_SESSION['users_id']) {
         // Don't allow a user to unroot themselves
         $this->user->unroot($this->users_id);
     }
     // Banned
     if (!isset($clean['banned'])) {
         $this->user->unban($this->users_id);
     } elseif ($this->users_id != $_SESSION['users_id']) {
         // Don't allow a user to ban themselves
         $this->user->ban($this->users_id);
     }
     foreach ($GLOBALS['CONFIG']['ACCESS'] as $key => $val) {
         if (isset($clean[$key])) {
             if ($clean[$key]) {
                 $this->user->saveAccess($this->users_id, $key, $clean[$key]);
             } else {
                 $this->user->removeAccess($key, $this->users_id);
             }
         }
     }
     // Log, private
     $this->log->write($_SESSION['users_id'], "sux0r::adminAccess() users_id: {$this->users_id} ", 1);
 }
예제 #8
0
 /**
  * Delete thread
  *
  * @param int $thread_id thread id
  */
 function deleteThread($thread_id)
 {
     if (!filter_var($thread_id, FILTER_VALIDATE_INT) || $thread_id < 1) {
         return false;
     }
     // Begin transaction
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     $st = $this->db->prepare("SELECT id FROM {$this->db_table} WHERE thread_id = ? ");
     $st->execute(array($thread_id));
     $result = $st->fetchAll(PDO::FETCH_ASSOC);
     foreach ($result as $key => $val) {
         $st = $this->db->prepare("DELETE FROM {$this->db_table} WHERE id = ? ");
         $st->execute(array($val['id']));
         $st = $this->db->prepare("DELETE FROM {$this->db_table_hist} WHERE messages_id = ? ");
         $st->execute(array($val['id']));
     }
     // Delete links, too
     $link = new suxLink();
     $links = $link->getLinkTables('messages');
     foreach ($result as $key => $val) {
         foreach ($links as $table) {
             $link->deleteLink($table, 'messages', $val['id']);
         }
     }
     // Commit
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
 }
예제 #9
0
파일: admin.php 프로젝트: hashimmm/sux0r
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     if (isset($clean['delete'])) {
         foreach ($clean['delete'] as $id => $val) {
             // Begin transaction
             $db = suxDB::get();
             $tid = suxDB::requestTransaction();
             try {
                 $query = 'DELETE FROM bayes_auth WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM bookmarks WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM link__bookmarks__users WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM link__rss_feeds__users WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM messages WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM messages_history WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM openid_trusted WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM photoalbums WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM photos WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM rss_feeds WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM socialnetwork WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM socialnetwork WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM tags WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM users_access WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM users_info WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM users_log WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM users_openid WHERE users_id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 $query = 'DELETE FROM users WHERE id = ? ';
                 $st = $db->prepare($query);
                 $st->execute(array($id));
                 // Log, private
                 $this->log->write($_SESSION['users_id'], "sux0r::adminAccess() deleted users_id: {$id} ", 1);
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
                 // Hot potato!
             }
             suxDB::commitTransaction($tid);
             // Commit
             // clear all caches,cheap and easy
             $this->tpl->clearAllCache();
         }
     }
 }
예제 #10
0
파일: suxUser.php 프로젝트: hashimmm/sux0r
 /**
  * Save user
  *
  * @param int $users_id users_id
  * @param array $info keys match SQL table columns of users and users_info
  * @return int users_id
  */
 function save($users_id, array $info)
 {
     /* If users_id is provided, saveUser() will update an existing user.
        Otherwise it will insert a new one */
     // --------------------------------------------------------------------
     // Sanitize
     // --------------------------------------------------------------------
     if ($users_id != null && (!filter_var($users_id, FILTER_VALIDATE_INT) || $users_id < 1)) {
         throw new Exception('Invalid user id');
     }
     if (!empty($info['nickname'])) {
         $tmp = $this->getByNickname($info['nickname']);
         if ($tmp['users_id'] != $users_id) {
             throw new Exception('Duplicate nickname');
         }
     }
     if (!empty($info['email'])) {
         $tmp = $this->getByEmail($info['email']);
         if ($tmp && $tmp['users_id'] != $users_id) {
             throw new Exception('Duplicate email');
         }
     }
     unset($info['id'], $info['users_id']);
     // Don't allow spoofing of the id in the array
     unset($info['root']);
     // Don't allow root changes with this function
     unset($info['banned']);
     // Don't allow banned changes with this function
     unset($info['image']);
     // Don't allow image changes with this function
     // Encrypt the password
     if (!empty($info['password'])) {
         if (empty($info['nickname'])) {
             throw new Exception('No nickname provided');
         }
         $info['password'] = $this->encryptPw($info['nickname'], $info['password']);
     }
     // Move users table info to $user array
     $user = array();
     // Nickname
     if (mb_strtolower($info['nickname']) == 'nobody') {
         throw new Exception('"nobody" is a reservered word');
     }
     if (!empty($info['nickname'])) {
         $user['nickname'] = strip_tags($info['nickname']);
     }
     unset($info['nickname']);
     // Email
     if (!empty($info['email'])) {
         $user['email'] = filter_var($info['email'], FILTER_SANITIZE_EMAIL);
     }
     unset($info['email']);
     // Encrypted password
     if (!empty($info['password'])) {
         $user['password'] = $info['password'];
     }
     unset($info['password']);
     // Move openid_url to variable
     $openid_url = null;
     if (!empty($info['openid_url'])) {
         $openid_url = filter_var($info['openid_url'], FILTER_SANITIZE_URL);
     }
     unset($info['openid_url']);
     // The rest
     foreach ($info as $key => $val) {
         if ($key == 'url') {
             $info[$key] = filter_var($val, FILTER_SANITIZE_URL);
         } else {
             $info[$key] = strip_tags($val);
         }
     }
     // Date of birth
     if (empty($info['dob'])) {
         $info['dob'] = null;
     }
     // We now have two arrays, $user[] and $info[]
     // --------------------------------------------------------------------
     // Go!
     // --------------------------------------------------------------------
     // Begin transaction
     $tid = suxDB::requestTransaction();
     $this->inTransaction = true;
     if ($users_id) {
         // UPDATE
         $user['id'] = $users_id;
         $query = suxDB::prepareUpdateQuery($this->db_table, $user);
         $st = $this->db->prepare($query);
         $st->execute($user);
         $info['users_id'] = $users_id;
         $query = suxDB::prepareUpdateQuery($this->db_table_info, $info, 'users_id');
         $st = $this->db->prepare($query);
         $res = $st->execute($info);
     } else {
         // INSERT
         $query = suxDB::prepareInsertQuery($this->db_table, $user);
         $st = $this->db->prepare($query);
         $st->execute($user);
         if ($this->db_driver == 'pgsql') {
             $users_id = $this->db->lastInsertId("{$this->db_table}_id_seq");
         } else {
             $users_id = $this->db->lastInsertId();
         }
         $info['users_id'] = $users_id;
         $query = suxDB::prepareInsertQuery($this->db_table_info, $info);
         $st = $this->db->prepare($query);
         $st->execute($info);
     }
     if ($openid_url) {
         $this->attachOpenID($openid_url, $users_id);
     }
     // Commit
     suxDB::commitTransaction($tid);
     $this->inTransaction = false;
     return $users_id;
 }