示例#1
0
文件: openid.php 项目: hashimmm/sux0r
 /**
  * Constructor
  *
  * @global array $CONFIG['DSN']
  */
 function __construct()
 {
     $this->db = suxDB::get();
     // Db
     $this->db_driver = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
     set_exception_handler(array($this, 'exceptionHandler'));
     // Exception
     $this->user = new suxUser();
     // User
     $this->r = new suxRenderer($this->module);
     // Renderer
     $this->tpl = new suxTemplate($this->module);
     // Template
     $this->tpl->assignByRef('r', $this->r);
     // Renderer referenced in template
     // Defined by OpenID spec
     // http://openid.net/specs/openid-authentication-1_1.html
     // http://openid.net/specs/openid-authentication-1_1.html#pvalue
     $this->assoc_types = array('HMAC-SHA1');
     $this->session_types = array('', 'DH-SHA1');
     $this->g = 2;
     $this->p = '1551728981814736974712322577637155' . '3991572480196691540447970779531405' . '7629378541917580651227423698188993' . '7278161526466314385615958256881888' . '8995127215884267541995034125870655' . '6549803580104870537681476726513255' . '7470407658574792912915723345106432' . '4509471500722962109419434978392598' . '4760375594985848253359305585439638443';
     // OpenID Setup user
     $this->profile = array('my_url' => suxFunct::makeUrl('openid', null, true), 'lifetime' => 1440, 'use_bcmath' => true, 'debug' => false, 'logfile' => '/tmp/openid.debug.log', 'req_url' => $this->getReqUrl());
 }
示例#2
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;
 }
示例#3
0
文件: menu.php 项目: hashimmm/sux0r
/**
* 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;
}
示例#4
0
文件: suxRSS.php 项目: hashimmm/sux0r
 /**
  * Constructor
  *
  * @global string $CONFIG['PATH']
  */
 function __construct()
 {
     parent::__construct();
     // DOMDocument
     $this->formatOutput = true;
     // DOMDocument
     // Cache
     $this->cache_dir = $GLOBALS['CONFIG']['PATH'] . '/temporary/rss_cache';
     // Db
     $this->db = suxDB::get();
     $this->db_driver = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
     set_exception_handler(array($this, 'exceptionHandler'));
 }
示例#5
0
 /**
  * Constructor
  */
 function __construct()
 {
     $this->db = suxDB::get();
     $this->db_driver = $this->db->getAttribute(PDO::ATTR_DRIVER_NAME);
     set_exception_handler(array($this, 'exceptionHandler'));
 }
示例#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
 }
示例#7
0
require_once dirname(__FILE__) . '/../includes/suxFunct.php';
require_once dirname(__FILE__) . '/../includes/suxLink.php';
require_once dirname(__FILE__) . '/../includes/suxPhoto.php';
set_time_limit(900);
// Set the timeout to 15 minutes.
// ----------------------------------------------------------------------------
// Set debug mode, if true nothing actually gets deleted
// ----------------------------------------------------------------------------
$debug = true;
// ----------------------------------------------------------------------------
// Purge orphaned link tables
// ----------------------------------------------------------------------------
if ($debug) {
    echo "> Debug mode = true, nothing will be deleted. <br />\n";
}
$db = suxDB::get();
// Scan for missing links, push them in $not_found array
$link = new suxLink();
$link_tables = $link->getLinkTables();
$not_found = array();
foreach ($link_tables as $val) {
    $parts = explode('__', $val);
    if (count($parts) != 3) {
        die('Unexpected result, ejecting early to avoid catastrophe...');
    }
    $st = $db->query("SELECT * FROM {$val} ");
    $tmp = $st->fetchAll(PDO::FETCH_ASSOC);
    foreach ($tmp as $val2) {
        $tmp2 = "{$parts[1]}_id";
        $tmp3 = "{$parts[2]}_id";
        // Table 1
示例#8
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
 }
示例#9
0
文件: photos.php 项目: hashimmm/sux0r
 /**
  * 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);
 }
示例#10
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();
         }
     }
 }
示例#11
0
 /**
  * Constructor
  */
 function __construct()
 {
     $this->db = suxDB::get();
     set_exception_handler(array($this, 'exceptionHandler'));
 }
示例#12
0
文件: feeds.php 项目: hashimmm/sux0r
 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);
 }
示例#13
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;
 }
示例#14
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);
 }
示例#15
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;
 }
示例#16
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);
 }
示例#17
0
文件: blog.php 项目: hashimmm/sux0r
 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);
 }