コード例 #1
0
ファイル: score_updater.php プロジェクト: billpeace/Faceless
<?php

/*
 * Copyright (c) delight.im <*****@*****.**>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see {http://www.gnu.org/licenses/}.
 */
require_once __DIR__ . '/../../base.php';
// initialize the database connection
try {
    Database::init(CONFIG_DB_CONNECT_STRING, CONFIG_DB_USERNAME, CONFIG_DB_PASSWORD);
} catch (Exception $e) {
    throw new Exception('Could not connect to database');
}
// list of languages to run the updater for (incomplete - must be updated regularly)
$languages = array('DEU', 'ENG', 'NLD', 'ITA', 'POR', 'SPA', 'FRA', 'RUS', 'RON', 'TUR', 'CES', 'SWE', 'DAN', 'VIE');
$language = $languages[array_rand($languages)];
Database::update("UPDATE messages SET score = " . getScoreUpdateSQL() . " WHERE language_iso3 = " . Database::escape($language) . " ORDER BY score DESC LIMIT 1000");
コード例 #2
0
ファイル: favorites_set.php プロジェクト: billpeace/Faceless
/**
 * Updates the favorites count for the message with the given ID
 *
 * @param int $messageID the ID of the message to update the favorites count for
 * @param boolean $increase whether to increase (true) or decrease (false) the count by one
 */
function updateFavoritesCount($messageID, $increase)
{
    Database::update("UPDATE messages SET favorites_count = favorites_count" . ($increase ? "+1" : "-1") . ", score = " . getScoreUpdateSQL() . " WHERE id = " . intval($messageID));
}
コード例 #3
0
ファイル: comments_new.php プロジェクト: smglaksn/Faceless
 $commentTime = time();
 $commentFields = "message_id, user_id, text_encrypted, comment_secret, time_inserted";
 $commentValues = intval($messageID) . ", " . intval($userID) . ", " . Database::escape($textEncrypted) . ", " . Database::escape($commentSecret) . ", " . $commentTime;
 if (isset($privateToUser)) {
     $commentFields .= ", private_to_user";
     $commentValues .= ", " . intval($privateToUser);
 }
 Database::insert("INSERT INTO comments (" . $commentFields . ") VALUES (" . $commentValues . ")");
 $commentID = Database::getLastInsertID();
 // for private comments
 if (isset($privateToUser)) {
     // update the date of the latest activity
     Database::update("UPDATE messages SET time_active = " . time() . " WHERE id = " . intval($messageID));
 } else {
     // increase the comments count by one, update the score and update the date of the latest activity
     Database::update("UPDATE messages SET comments_count = comments_count+1, score = " . getScoreUpdateSQL() . ", time_active = " . time() . " WHERE id = " . intval($messageID));
 }
 // get the existing degree (if any) or 3 (default)
 $degree = getDegree($userID, $messageID);
 // subscribe to the comments thread (if not done already)
 Database::insert("INSERT IGNORE INTO subscriptions (message_id, user_id, degree) VALUES (" . intval($messageID) . ", " . intval($userID) . ", " . intval($degree) . ")");
 // if this is a private reply
 if (isset($privateToUser)) {
     // notify the recipient of the private reply that there is a new comment
     Database::update("UPDATE subscriptions SET counter = counter+1 WHERE message_id = " . intval($messageID) . " AND user_id = " . intval($privateToUser));
 } else {
     // notify all other subscribers that there is a new comment
     Database::update("UPDATE subscriptions SET counter = counter+1 WHERE message_id = " . intval($messageID) . " AND user_id != " . intval($userID));
 }
 // create a public ID for this user that is unique within this thread (only)
 UserIDsInThread::create($messageID, $userID);