Example #1
0
 if ($_POST['after'] && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\ [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $_POST['after'])) {
     throw new RuntimeException('Inacceptable Date sent.');
 }
 if ($_POST['before'] && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\ [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $_POST['before'])) {
     throw new RuntimeException('Inacceptable Date sent.');
 }
 if ($_POST['last'] && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\ [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $_POST['last'])) {
     throw new RuntimeException('Inacceptable Date sent.');
 }
 $_mysql = new KSMySQL();
 if (!$_mysql->connect(KSDBConfig::HOST, KSDBConfig::USER, KSDBConfig::PASS)) {
     throw new Exception('DB Failure. Can not read entries at the moment. Try later.');
 }
 // Select articles DB
 $_mysql->selectdb(KSDBConfig::DB);
 $_POST['id'] = mysql_real_escape_string($_POST['id'], $_mysql->link());
 $_POST['author'] = mysql_real_escape_string($_POST['author'], $_mysql->link());
 $_POST['after'] = mysql_real_escape_string($_POST['after'], $_mysql->link());
 $_POST['before'] = mysql_real_escape_string($_POST['before'], $_mysql->link());
 $_POST['last'] = mysql_real_escape_string($_POST['last'], $_mysql->link());
 $_where_condition = '';
 switch ($_POST['mode']) {
     case 'id':
         $_where_condition = " and t1.id in ({$_POST['id']})";
         break;
     case 'author':
         $_res = $_mysql->query("select id from " . KSAdminDBConfig::DB . ".uinfo where name='{$_POST['author']}';");
         if (1 !== $_mysql->numrows()) {
             throw new Exception("Specified Author does not exist.");
         }
         $_row = mysql_fetch_array($_res, MYSQL_ASSOC);
Example #2
0
}
$_POST['id'] = trim(strip_tags(urldecode(stripslashes($_POST['id']))));
$_POST['last'] = trim(strip_tags(urldecode(stripslashes($_POST['last']))));
try {
    if (!preg_match('/^[0-9]{1,5}$/', $_POST['id']) || 65535 < $_POST['id']) {
        throw new RuntimeException('Inexisting Entry.');
    }
    if ($_POST['last'] && !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\ [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $_POST['last'])) {
        throw new RuntimeException('Inacceptable Last Date sent.');
    }
    $_mysql = new KSMySQL();
    if (!$_mysql->connect(KSDBConfig::HOST, KSDBConfig::USER, KSDBConfig::PASS)) {
        throw new Exception('DB Failure. Can not read replies at the moment. Try later.');
    }
    // Select articles DB
    $_mysql->selectdb(KSDBConfig::DB);
    $_POST['id'] = mysql_real_escape_string($_POST['id'], $_mysql->link());
    $_POST['last'] = mysql_real_escape_string($_POST['last'], $_mysql->link());
    // Get replies associated with current entry from DB.
    $_res = $_mysql->query("select t2.id,t2.author as aid,t3.name as author,t2.body,t2.added from rhead as t1 join reply as t2 join " . KSAdminDBConfig::DB . ".uinfo as t3 where t1.eid='{$_POST['id']}' and t1.rid=t2.id and t3.id=t2.author " . ($_POST['last'] ? " and t2.added>'{$_POST['last']}'" : '') . " order by t2.added asc;");
    $_replies = new KSJsonReplies();
    if ($_mysql->numrows()) {
        while ($_row = mysql_fetch_array($_res, MYSQL_ASSOC)) {
            $_replies->push_back(new KSReply($_row['id'], $_row['aid'], $_row['author'], $_row['body'], $_row['added']));
        }
    }
    KSServiceJson::instance()->chain($_replies);
} catch (Exception $exception) {
    KSServiceJson::instance()->chain(new KSJsonError($exception->getMessage()));
}
echo KSServiceJson::instance();