Exemplo n.º 1
0
 /**
  * @return string html
  */
 function isSubscribed($feed_id)
 {
     if (!$this->isLoggedIn()) {
         return "<img src='{$this->url}/media/{$this->partition}/assets/sticky.gif' border='0' width='12' height='12' alt='' />";
     }
     // Get config variables for template
     $tpl = new suxTemplate($this->module);
     $tpl->configLoad('my.conf', $this->module);
     $image = $tpl->getConfigVars('imgUnsubscribed');
     // Don't query the database unnecessarily.
     static $img_cache = array();
     if (isset($img_cache[$feed_id])) {
         $image = $img_cache[$feed_id];
     } else {
         // If subscribed, change image
         $query = 'SELECT COUNT(*) FROM link__rss_feeds__users WHERE rss_feeds_id = ? AND users_id = ? ';
         $db = suxDB::get();
         $st = $db->prepare($query);
         $st->execute(array($feed_id, $_SESSION['users_id']));
         if ($st->fetchColumn() > 0) {
             $image = $tpl->getConfigVars('imgSubscribed');
         }
         $img_cache[$feed_id] = $image;
     }
     $html = "<img src='{$this->url}/media/{$this->partition}/assets/{$image}' border='0' width='12' height='12' alt=''\n        onclick=\"toggleSubscription('{$feed_id}');\"\n        style='cursor: pointer;'\n        class='subscription{$feed_id}'\n        />";
     return $html;
 }
Exemplo n.º 2
0
/**
* menu
*
* @author     Dac Chartrand <*****@*****.**>
* @license    http://www.fsf.org/licensing/licenses/gpl-3.0.html
*/
function bookmarks_menu()
{
    if (!isset($_SESSION['users_id'])) {
        return null;
    }
    // Check access
    $user = new suxUser();
    if (!$user->isRoot()) {
        $access = $user->getAccess('bookmarks');
        if ($access < $GLOBALS['CONFIG']['ACCESS']['bookmarks']['admin']) {
            return null;
        }
    }
    $query = 'SELECT COUNT(*) FROM bookmarks WHERE draft = true ';
    $db = suxDB::get();
    $st = $db->query($query);
    $menu = array();
    $count = $st->fetchColumn();
    $text = suxFunct::gtext('bookmarks');
    $menu[$text['admin']] = suxFunct::makeUrl('/bookmarks/admin/');
    $tmp = "{$text['approve_2']} ({$count})";
    $menu[$tmp] = suxFunct::makeUrl('/bookmarks/approve/');
    $menu[$text['new']] = suxFunct::makeUrl('/bookmarks/edit/');
    return $menu;
}
Exemplo n.º 3
0
    }
}
// Enforce config
if (!isset($GLOBALS['CONFIG'])) {
    die("Something is wrong, can't initialize without configuration.");
}
// Set debug stuff
if (isset($GLOBALS['CONFIG']['DEBUG']) && $GLOBALS['CONFIG']['DEBUG']) {
    $GLOBALS['CONFIG']['DEBUG'] = true;
    include_once $GLOBALS['CONFIG']['PATH'] . '/includes/symbionts/dBug.php';
} else {
    $GLOBALS['CONFIG']['DEBUG'] = false;
}
// Initialize suxDB
require_once $GLOBALS['CONFIG']['PATH'] . '/includes/suxDB.php';
suxDB::$dsn = $GLOBALS['CONFIG']['DSN'];
// Include suxFunct
require_once $GLOBALS['CONFIG']['PATH'] . '/includes/suxFunct.php';
// Sessions
ini_set('session.use_only_cookies', true);
session_start();
// Set utf-8
header('Content-Type: text/html;charset=utf-8');
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
mb_language('uni');
// Avoid problems with arg_separator.output
ini_set('arg_separator.output', '&');
// Set the default timezone
date_default_timezone_set($GLOBALS['CONFIG']['TIMEZONE']);
// Get rid of magic quotes
Exemplo n.º 4
0
 protected function getCategorizedSidelist($id)
 {
     $db = suxDB::get();
     // Get Items
     $query = "\n        SELECT messages.id, messages.thread_id, messages.title FROM messages\n        INNER JOIN link__bayes_documents__messages ON link__bayes_documents__messages.messages_id = messages.id\n        INNER JOIN bayes_documents ON link__bayes_documents__messages.bayes_documents_id = bayes_documents.id\n        INNER JOIN bayes_categories ON bayes_documents.bayes_categories_id = bayes_categories.id\n        WHERE bayes_categories.id = ? AND messages.thread_pos = 0 AND messages.blog = true AND {$this->msg->sqlPublished()}\n        ORDER BY {$this->msg->sqlOrder()}\n        ";
     $st = $db->prepare($query);
     $st->execute(array($id));
     return $st->fetchAll(PDO::FETCH_ASSOC);
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // Check $module, assign $table
     $table = $this->getTable($clean['module']);
     if (!$table) {
         throw new Exception('Unsuported $module');
     }
     // --------------------------------------------------------------------
     // Get image from database
     // --------------------------------------------------------------------
     $query = "SELECT users_id, image FROM {$table} WHERE id = ? ";
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($clean['id']));
     $image = $st->fetch(PDO::FETCH_ASSOC);
     if (!$image['image']) {
         throw new Exception('$image not found');
     }
     if ($image['users_id'] != $_SESSION['users_id']) {
         // Security check
         if (!$this->user->isRoot()) {
             $access = $this->user->getAccess($clean['module']);
             if (!isset($GLOBALS['CONFIG']['ACCESS'][$module]['admin'])) {
                 suxFunct::redirect(suxFunct::getPreviousURL('cropper'));
             } elseif ($access < $GLOBALS['CONFIG']['ACCESS'][$clean['module']]['admin']) {
                 suxFunct::redirect(suxFunct::getPreviousURL('cropper'));
             }
         }
     }
     $path_to_dest = "{$GLOBALS['CONFIG']['PATH']}/data/{$clean['module']}/{$image['image']}";
     $path_to_source = suxPhoto::t2fImage($path_to_dest);
     if (!is_writable($path_to_dest)) {
         die('Destination is not writable? ' . $path_to_dest);
     }
     // ----------------------------------------------------------------------------
     // Manipulate And Rewrite Image
     // ----------------------------------------------------------------------------
     // $image
     $format = explode('.', $path_to_source);
     $format = mb_strtolower(end($format));
     if ($format == 'jpg') {
         $format = 'jpeg';
     }
     // fix stupid mistake
     if (!($format == 'jpeg' || $format == 'gif' || $format == 'png')) {
         die('Invalid image format');
     }
     // Try to adjust memory for big files
     suxPhoto::fudgeFactor($format, $path_to_source);
     $func = 'imagecreatefrom' . $format;
     $image = $func($path_to_source);
     if (!$image) {
         die('Invalid image format');
     }
     // $thumb
     $thumb = imagecreatetruecolor($clean['x2'], $clean['y2']);
     $white = imagecolorallocate($thumb, 255, 255, 255);
     ImageFilledRectangle($thumb, 0, 0, $clean['x2'], $clean['y2'], $white);
     imagealphablending($thumb, true);
     // Output
     imagecopyresampled($thumb, $image, 0, 0, $clean['x1'], $clean['y1'], $clean['x2'], $clean['y2'], $clean['width'], $clean['height']);
     $func = 'image' . $format;
     $func($thumb, $path_to_dest);
     // Free memory
     imagedestroy($image);
     imagedestroy($thumb);
     $this->log->write($_SESSION['users_id'], "sux0r::cropper()  {$table}, id: {$clean['id']}", 1);
     // Private
 }
Exemplo n.º 7
0
 /**
  * trust a url
  * @param int $id user id
  * @param string $id url
  * @return bool
  */
 private function trustUrl($id, $url)
 {
     if (!filter_var($id, FILTER_VALIDATE_INT) || $id < 1) {
         return false;
     }
     $url = suxFunct::canonicalizeUrl($url);
     $trusted = array('users_id' => $id, 'auth_url' => $url);
     $query = suxDB::prepareCountQuery($this->db_table_trust, $trusted);
     $st = $this->db->prepare($query);
     $st->execute($trusted);
     if (!$st->fetchColumn()) {
         $query = suxDB::prepareInsertQuery($this->db_table_trust, $trusted);
         $st = $this->db->prepare($query);
         $st->execute($trusted);
     }
 }
Exemplo n.º 8
0
 /**
  * Constructor
  */
 function __construct()
 {
     $this->db = suxDB::get();
     $this->db_driver = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
     set_exception_handler(array($this, 'exceptionHandler'));
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 /**
  * @param int $id id
  * @param string $link link table
  * @param string $module sux0r module, used to clear cache
  * @param string $document document to train
  * @return string html
  */
 function genericBayesInterface($id, $link, $module, $document)
 {
     if ($GLOBALS['CONFIG']['FEATURE']['bayes'] == false) {
         return null;
     }
     // Feature is turned off
     /* Get a list of all the vectors/categories the user has access to */
     // Cache
     static $vectors = null;
     if (!is_array($vectors)) {
         $vectors = array();
         if (isset($_SESSION['users_id'])) {
             foreach ($this->nb->getSharedVectors($_SESSION['users_id']) as $key => $val) {
                 $vectors[$key] = $val;
             }
         }
     }
     if (!count($vectors)) {
         return null;
     }
     // No user vectors, skip
     // Cache
     static $v_trainer = null;
     static $v_user = null;
     if (!is_array($v_trainer) || !is_array($v_user)) {
         /* Split the vectors into those the user can train, and those he/she can't */
         $v_trainer = array();
         $v_user = array();
         foreach ($vectors as $key => $val) {
             if ($val['owner'] || $val['trainer']) {
                 $v_trainer[$key] = array('vector' => $val['vector'], 'categories' => $this->nb->getCategoriesByVector($key));
             } else {
                 $v_user[$key] = array('vector' => $val['vector'], 'categories' => $this->nb->getCategoriesByVector($key));
             }
         }
     }
     /* Get all the bayes categories linked to the document id that the user has access to */
     $link_table = $this->link->buildTableName($link, 'bayes_documents');
     $innerjoin = "\n        INNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id\n        INNER JOIN bayes_documents ON bayes_categories.id = bayes_documents.bayes_categories_id\n        INNER JOIN {$link_table} ON {$link_table}.bayes_documents_id = bayes_documents.id\n        INNER JOIN {$link} ON {$link_table}.{$link}_id = {$link}.id\n        ";
     $query = "\n        SELECT bayes_categories.id FROM bayes_categories\n        {$innerjoin}\n        WHERE {$link}.id = ? AND bayes_auth.users_id = ?\n        ";
     // Note: bayes_auth WHERE condition equivilant to nb->isCategoryUser()
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($id, $_SESSION['users_id']));
     $tmp = $st->fetchAll(PDO::FETCH_ASSOC);
     $categories = array();
     foreach ($tmp as $key => $val) {
         $categories[$val['id']] = true;
     }
     /* Begin rendering */
     $html = "<div class='nbInterface'>\n";
     $i = 0;
     // Used to identify $v_trainer[]
     foreach (array($v_trainer, $v_user) as $vectors2) {
         foreach ($vectors2 as $key => $val) {
             if (count($val['categories']) < 2) {
                 continue;
             }
             // Not enough categories, skip
             // Vector name to be replaced
             $uniqid = time() . substr(md5(microtime()), 0, rand(5, 12));
             $html .= "<span id='nb{$uniqid}'>@_{$uniqid}_@</span>";
             if ($i == 0) {
                 // this is $v_trainer[], Ajax trainable
                 $html .= '<select name="category_id[]" class="nbCatDropdown" ';
                 $html .= "%_{$uniqid}_%";
                 // Action to be replaced
                 $html .= "=\"suxTrain('#nb{$uniqid}', '{$link}', '{$module}', {$id}, this.options[selectedIndex].value);\" ";
                 $html .= '>';
             } else {
                 // this is $v_user[], sit pretty, do nothing
                 $html .= '<select name="null" class="nbCatDropdown" ';
                 $html .= "onchange=\"suxNotTrainer('#nb{$uniqid}');\" ";
                 $html .= '>';
             }
             /* Check if the vector is categorized */
             $is_categorized = false;
             foreach ($val['categories'] as $key2 => $val2) {
                 if (isset($categories[$key2])) {
                     $is_categorized = $key2;
                     break;
                 }
             }
             /* Replace strings */
             if ($is_categorized) {
                 $replace = "<span class='nbVecTrained'>{$val['vector']} : </span>";
                 $replace2 = 'onchange';
             } else {
                 $replace = $val['vector'] . ' : ';
                 $replace2 = 'onmouseup';
             }
             $html = str_replace("@_{$uniqid}_@", $replace, $html);
             $html = str_replace("%_{$uniqid}_%", $replace2, $html);
             /* Get bayesian scores */
             $j = 0;
             $scores = $this->nb->categorize($document, $key);
             foreach ($scores as $key2 => $val2) {
                 $tmp = $val2['category'] . ' (' . round($val2['score'] * 100, 2) . ' %)';
                 $html .= '<option label="' . $tmp . '" value="' . $key2 . '" ';
                 if ($is_categorized == $key2 || $j == 0) {
                     $html .= 'selected="selected" ';
                 }
                 $html .= '>' . $tmp . '</option>';
                 ++$j;
             }
             $html .= '</select>' . "\n";
         }
         ++$i;
         // Used to identify $v_trainer[]
     }
     $html .= "</div>\n";
     return $html;
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
0
 /**
  * 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();
         }
     }
 }
Exemplo n.º 15
0
 /**
  * View photo
  */
 function view($id)
 {
     // Get nickname
     if (isset($_SESSION['nickname'])) {
         $nn = $_SESSION['nickname'];
     } else {
         $nn = 'nobody';
     }
     // "Cache Groups" using a vertical bar |
     $cache_id = "{$nn}|view|{$id}";
     $this->tpl->caching = 1;
     if (!$this->tpl->isCached('view.tpl', $cache_id)) {
         $this->r->arr['photos'] = $this->photo->getPhotoByID($id);
         if ($this->r->arr['photos'] == false || !count($this->r->arr['photos'])) {
             suxFunct::redirect(suxFunct::getPreviousURL());
         } else {
             $this->r->arr['photos']['image'] = suxPhoto::t2fImage($this->r->arr['photos']['image']);
             // Fullsize
             // Album info
             $this->r->arr['album'] = $this->photo->getAlbumByID($this->r->arr['photos']['photoalbums_id']);
             $tmp = $this->user->getByID($this->r->arr['album']['users_id']);
             $this->r->arr['album']['nickname'] = $tmp['nickname'];
             // Previous, next, and page number
             $prev_id = null;
             $next_id = null;
             $page = 1;
             $query = 'SELECT id FROM photos WHERE photoalbums_id = ? ORDER BY image ';
             // Same order as suxPhoto->getPhotos()
             $db = suxDB::get();
             $st = $db->prepare($query);
             $st->execute(array($this->r->arr['photos']['photoalbums_id']));
             $i = 0;
             while ($prev_next = $st->fetch(PDO::FETCH_ASSOC)) {
                 ++$i;
                 if ($prev_next['id'] == $id) {
                     break;
                 }
                 if ($i >= $this->per_page) {
                     $i = 0;
                     ++$page;
                 }
                 $prev_id = $prev_next['id'];
             }
             $prev_next = $st->fetch(PDO::FETCH_ASSOC);
             $next_id = $prev_next['id'];
             $this->r->text['prev_id'] = $prev_id;
             $this->r->text['next_id'] = $next_id;
             $this->r->text['back_url'] = suxFunct::makeUrl('photos/album/' . $this->r->arr['photos']['photoalbums_id'], array('page' => $page));
             $this->r->title .= " | {$this->r->gtext['photos']} | {$this->r->arr['album']['title']}";
         }
     }
     $this->tpl->display('view.tpl', $cache_id);
 }
Exemplo n.º 16
0
 /**
  * Write something to the users_log table
  *
  * @param string $body_html
  * @param int $users_id
  * @param int $private
  */
 function write($users_id, $body_html, $private = false)
 {
     // Any user
     if (!filter_var($users_id, FILTER_VALIDATE_INT) || $users_id < 1) {
         throw new Exception('Invalid user id');
     }
     $private = $private ? true : false;
     $clean['users_id'] = $users_id;
     $clean['private'] = $private;
     $clean['body_html'] = suxFunct::sanitizeHtml($body_html, -1);
     // Convert and copy body to UTF-8 plaintext
     $converter = new suxHtml2UTF8($clean['body_html']);
     $clean['body_plaintext'] = $converter->getText();
     // Timestamp
     $clean['ts'] = date('Y-m-d H:i:s');
     // INSERT
     $query = suxDB::prepareInsertQuery($this->db_table, $clean);
     $st = $this->db->prepare($query);
     // http://bugs.php.net/bug.php?id=44597
     // As of 5.2.6 you still can't use this function's $input_parameters to
     // pass a boolean to PostgreSQL. To do that, you'll have to call
     // bindParam() with explicit types for *each* parameter in the query.
     // Annoying much? This sucks more than you can imagine.
     if ($this->db_driver == 'pgsql') {
         $st->bindParam(':users_id', $clean['users_id'], PDO::PARAM_INT);
         $st->bindParam(':private', $clean['private'], PDO::PARAM_BOOL);
         $st->bindParam(':body_html', $clean['body_html'], PDO::PARAM_STR);
         $st->bindParam(':body_plaintext', $clean['body_plaintext'], PDO::PARAM_STR);
         $st->bindParam(':ts', $clean['ts'], PDO::PARAM_STR);
         $st->execute();
     } else {
         $st->execute($clean);
     }
 }
Exemplo n.º 17
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // --------------------------------------------------------------------
     // Sanity check
     // --------------------------------------------------------------------
     // Date
     $clean['published_on'] = "{$clean['Date']} {$clean['Time_Hour']}:{$clean['Time_Minute']}:{$clean['Time_Second']}";
     $clean['published_on'] = date('Y-m-d H:i:s', strtotime($clean['published_on']));
     // Sanitize
     // Unset image?
     if (!empty($clean['unset_image'])) {
         $clean['image'] = '';
     }
     // Set to empty string
     // Image?
     if (isset($_FILES['image']) && is_uploaded_file($_FILES['image']['tmp_name'])) {
         $format = explode('.', $_FILES['image']['name']);
         $format = strtolower(end($format));
         // Extension
         list($resize, $fullsize) = suxPhoto::renameImage($_FILES['image']['name']);
         $clean['image'] = $resize;
         // Add image to clean array
         $resize = suxFunct::dataDir($this->module) . "/{$resize}";
         $fullsize = suxFunct::dataDir($this->module) . "/{$fullsize}";
         suxPhoto::resizeImage($format, $_FILES['image']['tmp_name'], $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight'));
         move_uploaded_file($_FILES['image']['tmp_name'], $fullsize);
     }
     // Draft
     $clean['draft'] = isset($clean['draft']) && $clean['draft'] ? true : false;
     // --------------------------------------------------------------------
     // Create $msg array
     // --------------------------------------------------------------------
     $msg = array('title' => $clean['title'], 'image' => @$clean['image'], 'body' => $clean['body'], 'published_on' => $clean['published_on'], 'draft' => $clean['draft'], 'blog' => true);
     if (isset($clean['id'])) {
         $msg['id'] = $clean['id'];
     }
     // --------------------------------------------------------------------
     // Put $msg in database
     // --------------------------------------------------------------------
     // New
     $clean['id'] = $this->msg->save($_SESSION['users_id'], $msg, true);
     $this->msg->setPublished(true);
     $tmp = $this->msg->getByID($clean['id']);
     // Is actually published?
     $this->msg->setPublished(null);
     // Revert
     if ($tmp) {
         // Clear all caches, cheap and easy
         $this->tpl->clearAllCache();
         // Log message
         $log = '';
         $url = suxFunct::makeUrl("/user/profile/{$_SESSION['nickname']}", null, true);
         $log .= "<a href='{$url}'>{$_SESSION['nickname']}</a> ";
         $log .= mb_strtolower($this->r->gtext['posted_blog']);
         $url = suxFunct::makeUrl("/blog/view/{$tmp['thread_id']}", null, true);
         $log .= " <a href='{$url}'>{$tmp['title']}</a>";
         // Log
         $this->log->write($_SESSION['users_id'], $log);
         // Clear cache
         $tpl = new suxTemplate('user');
         $tpl->clearCache('profile.tpl', $_SESSION['nickname']);
     }
     $this->log->write($_SESSION['users_id'], "sux0r::blogEdit()  messages_id: {$clean['id']}", 1);
     // Private
     // --------------------------------------------------------------------
     // Tags procedure
     // --------------------------------------------------------------------
     // Parse tags
     $tags = @suxTags::parse($clean['tags']);
     // Save tags into database
     $tag_ids = array();
     foreach ($tags as $tag) {
         $tag_ids[] = $this->tags->save($_SESSION['users_id'], $tag);
     }
     //Delete current links
     $this->link->deleteLink('link__messages__tags', 'messages', $clean['id']);
     // Reconnect links
     foreach ($tag_ids as $id) {
         $this->link->saveLink('link__messages__tags', 'messages', $clean['id'], 'tags', $id);
     }
     // --------------------------------------------------------------------
     // Naive Bayesian procedure
     // --------------------------------------------------------------------
     /*
             `link__bayes_documents__messages` asserts that a message was trained and copied into
             a bayes document, it does not imply that it's the same document
     When a user edits their own document we can assume that we want
             the updated document to represent their selected categories
     However, we cannot assume this for the catgories of others.
     Example:
     I write and classify a 5000 word message.
             Several other users find my post and classify it too.
             Time passes, I'm drunk, I reduce the post to "Eat shit."
     Course of action:
     Deleting all links to a message for which I can train the vector seems
             the safest bet. Other users get to keep what they already classified,
             and can reclassify the modified document at a later date if they wish.
             They can also manually adjust the eroneous documents in the bayes module.
     Problem / TODO:
     I write and classify a 5000 word blog. Someone with permission to edit
             my blog, but who does not share my Bayesian vectors reduces the post to
             "Eat shit." Author's categories are now meaningless as blog tags.
     Now what?
     */
     // Get all the bayes_documents linked to this message where user is trainer
     // untrain it, delete links
     $innerjoin = "\n        INNER JOIN link__bayes_documents__messages ON link__bayes_documents__messages.bayes_documents_id = bayes_documents.id\n        INNER JOIN messages ON link__bayes_documents__messages.messages_id = messages.id\n        INNER JOIN bayes_categories ON bayes_categories.id = bayes_documents.bayes_categories_id\n        INNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id\n        ";
     $query = "\n        SELECT bayes_documents.id FROM bayes_documents\n        {$innerjoin}\n        WHERE messages.id = ?\n        AND bayes_auth.users_id = ? AND (bayes_auth.owner = true OR bayes_auth.trainer = true)\n        ";
     // Note: bayes_auth WHERE condition equivilant to nb->isCategoryTrainer()
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($clean['id'], $_SESSION['users_id']));
     $tmp = $st->fetchAll(PDO::FETCH_ASSOC);
     foreach ($tmp as $val) {
         $this->nb->untrainDocument($val['id']);
     }
     // Regcategorize
     // category ids submitted by the form
     if (isset($clean['category_id'])) {
         foreach ($clean['category_id'] as $val) {
             if (!empty($val) && $this->nb->isCategoryTrainer($val, $_SESSION['users_id'])) {
                 $doc_id = $this->nb->trainDocument("{$clean['title']} \n\n {$clean['body']}", $val);
                 $this->link->saveLink('link__bayes_documents__messages', 'bayes_documents', $doc_id, 'messages', $clean['id']);
             }
         }
     }
     $this->id = $clean['id'];
     // Remember this id
 }
Exemplo n.º 18
0
 /**
  * Return bayes categories associated to this document by author
  *
  * @param int $id messages id
  * @param int $users_id users id (the author)
  * @return string html
  */
 function authorCategories($id, $users_id)
 {
     // ----------------------------------------------------------------
     // SQL
     // ----------------------------------------------------------------
     // Innerjoin query
     $innerjoin = '
     INNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id
     INNER JOIN bayes_documents ON bayes_categories.id = bayes_documents.bayes_categories_id
     INNER JOIN link__bayes_documents__messages ON link__bayes_documents__messages.bayes_documents_id = bayes_documents.id
     INNER JOIN messages ON link__bayes_documents__messages.messages_id = messages.id
     ';
     // Select, equivilant to nb->isCategoryTrainer()
     $query = "\n        SELECT bayes_categories.category, bayes_categories.id FROM bayes_categories\n        {$innerjoin}\n        WHERE messages.id = ? AND bayes_auth.users_id = ? AND (bayes_auth.owner = true OR bayes_auth.trainer = true)\n        ";
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($id, $users_id));
     $cat = $st->fetchAll(PDO::FETCH_ASSOC);
     // ----------------------------------------------------------------
     // Html
     // ----------------------------------------------------------------
     foreach ($cat as $val) {
         $url = suxFunct::makeUrl('/blog/category/' . $val['id']);
         $html .= "<a href='{$url}'>{$val['category']}</a>, ";
     }
     if (!$html) {
         return null;
     }
     // No categories by trainer
     $html = rtrim($html, ', ');
     $html = "<p>{$this->gtext['bayes_categories']}: " . $html . '</p>';
     return $html;
 }
Exemplo n.º 19
0
 /**
  * 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;
 }
Exemplo n.º 20
0
// ---------------------------------------------------------------------------
$feed = new suxRSS();
if (!$feed->getFeedByID($id)) {
    failure('Invalid feed');
}
// ---------------------------------------------------------------------------
// Go
// ---------------------------------------------------------------------------
$module = 'feeds';
$link = 'link__rss_feeds__users';
$col = 'rss_feeds';
// Get image names from template config
$tpl = new suxTemplate($module);
$tpl->configLoad('my.conf', $module);
$image = $tpl->getConfigVars('imgUnsubscribed');
$db = suxDB::get();
$query = "SELECT COUNT(*) FROM {$link} WHERE {$col}_id = ? AND users_id = ? ";
$st = $db->prepare($query);
$st->execute(array($id, $_SESSION['users_id']));
if ($st->fetchColumn() > 0) {
    // Delete
    $query = "DELETE FROM {$link} WHERE {$col}_id = ? AND users_id = ? ";
    $st = $db->prepare($query);
    $st->execute(array($id, $_SESSION['users_id']));
} else {
    // Insert
    $suxLink = new suxLink();
    $suxLink->saveLink($link, 'users', $_SESSION['users_id'], $col, $id);
    $image = $tpl->getConfigVars('imgSubscribed');
}
// Log
Exemplo n.º 21
0
// 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";
// ----------------------------------------------------------------------------
// Purge orphaned images
// ----------------------------------------------------------------------------
// image dir => db table
$image_dirs = array('blog' => 'messages', 'photos' => 'photos', 'user' => 'users_info');
$not_found = array();
foreach ($image_dirs as $dir => $table) {
    $path = $CONFIG['PATH'] . "/data/{$dir}";
    if (is_dir($path)) {
        foreach (new DirectoryIterator($path) as $file) {
            $pattern = '/[^_fullsize](\\.jpe?g|\\.gif|\\.png)$/i';
            if ($file->isFile() && preg_match($pattern, $file)) {
                // Query
                $query = "SELECT id FROM {$table} WHERE image = " . $db->quote("{$file}");
Exemplo n.º 22
0
 protected function getUserItems($users_id, $limit, $start)
 {
     $db = suxDB::get();
     // Get Items
     $query = "\n        SELECT rss_items.* FROM rss_items\n        INNER JOIN rss_feeds on rss_feeds.id = rss_items.rss_feeds_id\n        INNER JOIN link__rss_feeds__users ON link__rss_feeds__users.rss_feeds_id = rss_feeds.id\n        WHERE link__rss_feeds__users.users_id = ?\n        ORDER BY rss_items.published_on DESC, rss_items.id DESC\n        LIMIT {$limit} OFFSET {$start}\n        ";
     $st = $db->prepare($query);
     $st->execute(array($users_id));
     return $st->fetchAll(PDO::FETCH_ASSOC);
 }
Exemplo n.º 23
0
 /**
  * @param int $vector_id vector id
  * @param string $md5 a has of a vector id concatenated with a document
  * @param array $scores
  */
 private function cache($vector_id, $md5, $scores)
 {
     $clean = array('bayes_vectors_id' => $vector_id, 'md5' => $md5, 'expiration' => time() + 3600 * 12, 'scores' => serialize($scores));
     static $st = null;
     // Static as cache, to make categorize() faster
     if (!$st) {
         $q = suxDB::prepareInsertQuery($this->db_table_cache, $clean);
         $st = $this->db->prepare($q);
     }
     try {
         $st->execute($clean);
     } catch (Exception $e) {
         // SQLSTATE 23000: Constraint violation, we don't care, carry on
         if ($st->errorCode() == 23000) {
             return true;
         } else {
             throw $e;
         }
         // Hot potato
     }
 }
Exemplo n.º 24
0
 /**
  * Save relationship
  *
  * @param int $uid users_id
  * @param int $fid the users_id of the friend
  * @param string $rel relationship based on XFN
  * @return bool
  */
 function saveRelationship($uid, $fid, $rel)
 {
     // --------------------------------------------------------------------
     // Sanitize
     // --------------------------------------------------------------------
     if (!filter_var($uid, FILTER_VALIDATE_INT) || $uid < 1) {
         throw new Exception('Invalid user id');
     }
     if (!filter_var($fid, FILTER_VALIDATE_INT) || $fid < 1) {
         throw new Exception('Invalid friend id');
     }
     list($identity, $friendship, $physical, $professional, $geographical, $family, $romantic) = $this->relationshipArray($rel);
     if ($identity) {
         $rel = $identity;
     } else {
         $rel = "{$friendship} {$physical} {$professional} {$geographical} {$family} {$romantic}";
         $rel = preg_replace('/\\s+/', ' ', $rel);
         // Normalize whitespaces
     }
     $rel = trim($rel);
     // --------------------------------------------------------------------
     // Go!
     // --------------------------------------------------------------------
     $st = $this->db->prepare("SELECT COUNT(*) FROM {$this->db_table} WHERE users_id = ? AND friend_users_id = ? ");
     $st->execute(array($uid, $fid));
     $socialnetwork = array('users_id' => $uid, 'friend_users_id' => $fid, 'relationship' => $rel);
     if ($st->fetchColumn() > 0) {
         // UPDATE
         $query = "UPDATE {$this->db_table} SET relationship = :relationship WHERE users_id = :users_id AND friend_users_id = :friend_users_id ";
         $st = $this->db->prepare($query);
         return $st->execute($socialnetwork);
     } else {
         // INSERT
         $query = suxDB::prepareInsertQuery($this->db_table, $socialnetwork);
         $st = $this->db->prepare($query);
         return $st->execute($socialnetwork);
     }
 }
Exemplo n.º 25
0
 protected function getTaggedItems($id, $limit, $start)
 {
     $db = suxDB::get();
     // Get Items
     $query = "\n        SELECT bookmarks.* FROM bookmarks\n        INNER JOIN link__bookmarks__tags ON link__bookmarks__tags.bookmarks_id = bookmarks.id\n        WHERE link__bookmarks__tags.tags_id = ? AND {$this->bm->sqlPublished()}\n        ORDER BY {$this->bm->sqlOrder()}\n        LIMIT {$limit} OFFSET {$start} ";
     $st = $db->prepare($query);
     $st->execute(array($id));
     return $st->fetchAll(PDO::FETCH_ASSOC);
 }
Exemplo n.º 26
0
 /**
  * Attach an openid to a user
  *
  * @param string $openid_url url
  * @param int $users_id users_id
  */
 function attachOpenID($openid_url, $users_id = null)
 {
     // This user
     if (!$users_id) {
         if (!empty($_SESSION['users_id'])) {
             $users_id = $_SESSION['users_id'];
         } else {
             return false;
         }
     }
     // Any user
     if (!filter_var($users_id, FILTER_VALIDATE_INT) || $users_id < 1) {
         throw new Exception('Invalid user id');
     }
     // Canonicalize url
     $openid_url = suxFunct::canonicalizeUrl($openid_url);
     // Sql
     $oid = array('users_id' => $users_id, 'openid_url' => $openid_url);
     $query = suxDB::prepareCountQuery($this->db_table_openid, $oid);
     $st = $this->db->prepare($query);
     $st->execute($oid);
     if (!$st->fetchColumn()) {
         // Insert
         $query = suxDB::prepareInsertQuery($this->db_table_openid, $oid);
         $st = $this->db->prepare($query);
         $st->execute($oid);
     }
 }