コード例 #1
0
ファイル: ajax.toggle.php プロジェクト: hashimmm/sux0r
$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
$log = new suxLog();
$log->write($_SESSION['users_id'], "sux0r::feeds::toggle() bookmarks_id: {$id}", 1);
// Private
// ---------------------------------------------------------------------------
// Clear template caches
// ---------------------------------------------------------------------------
$tpl->clearCache(null, "{$_SESSION['nickname']}");
// clear all caches with "nickname" as the first cache_id group
// ---------------------------------------------------------------------------
// Return image string to Ajax request
// ---------------------------------------------------------------------------
echo trim($image);
コード例 #2
0
ファイル: ajax.train.php プロジェクト: hashimmm/sux0r
// ---------------------------------------------------------------------------
// Get all the bayes_documents linked to this message where user is trainer
// Also get associated vectors
$link_table = $suxLink->buildTableName($link, 'bayes_documents');
$innerjoin = "\nINNER JOIN {$link_table} ON {$link_table}.bayes_documents_id = bayes_documents.id\nINNER JOIN {$link} ON {$link_table}.{$link}_id = {$link}.id\nINNER JOIN bayes_categories ON bayes_categories.id = bayes_documents.bayes_categories_id\nINNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id\n";
$query = "\nSELECT bayes_documents.id, bayes_auth.bayes_vectors_id FROM bayes_documents\n{$innerjoin}\nWHERE {$link}.id = ?\nAND 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($id, $_SESSION['users_id']));
$tmp = $st->fetchAll(PDO::FETCH_ASSOC);
// Since we are only training one category/vector at a time, we need to make
// sure we don't untrain other unrelated vectors here.
$vec_id = $nb->getVectorByCategory($cat_id);
foreach ($tmp as $val) {
    if (isset($vec_id[$val['bayes_vectors_id']])) {
        $nb->untrainDocument($val['id']);
    }
}
// Recategorize
$doc_id = $nb->trainDocument($body, $cat_id);
$suxLink->saveLink($link_table, 'bayes_documents', $doc_id, $link, $id);
// Log
$log->write($_SESSION['users_id'], "sux0r::bayes::train() doc_id: {$doc_id}, cat_id: {$cat_id}", 1);
// Private
// ---------------------------------------------------------------------------
// Clear template caches
// ---------------------------------------------------------------------------
$tpl = new suxTemplate($module);
$tpl->clearCache(null, "{$_SESSION['nickname']}");
// clear all caches with "nickname" as the first cache_id group