Ejemplo n.º 1
0
             break;
         case 'query_type_get_row':
             $results = $db->get_row($query);
             break;
         case 'query_type_get_var':
             $results = $db->get_var($query);
             break;
         case 'query_type_query':
         default:
             $results = $db->query($query);
             break;
     }
     result_out(print_r($results, true));
     break;
 case 'misc':
     required_post(array('misc_action'));
     switch ($_POST['misc_action']) {
         case 'approve_all':
             $quotes = $db->get_results('SELECT permaid FROM quotes WHERE status = \'pending\' AND db = :db', array(array(':db', $settings->db, PDO::PARAM_STR)));
             if (!$quotes) {
                 die('no_pending_quotes');
                 break;
             }
             require classes_dir . 'quote.php';
             echo 'Approving: ';
             foreach ($quotes as $quoteid) {
                 $quote = new Quote();
                 $quote->permaid = $quoteid['permaid'];
                 if (!$quote->read()) {
                     continue;
                 }
Ejemplo n.º 2
0
        }
        break;
    case 'delete':
        required_post(array('permaid'));
        if (check_key() === null) {
            out(array('results' => array('success' => 0, 'error' => 'access_denied')));
        }
        $quote = new Quote();
        $quote->permaid = $_POST['permaid'];
        if ($quote->read()) {
            $quote->status = 'deleted';
            $quote->save(false);
            $session->log(sprintf('JSON API delete successful: %s - %s', $quote->permaid, $params[1]));
            out(array('results' => array('success' => 1)));
        }
        out(array('results' => array('success' => 0, 'error' => 'no_such_quote')));
        break;
    case 'topic':
        required_post(array('topic'));
        if (check_key() === null) {
            out(array('results' => array('success' => 0, 'error' => 'access_denied')));
        }
        $returna = $db->query('INSERT INTO topics (timestamp, nick, text, db, ip, user_agent)
				VALUES (:timestamp, :nick, :text, :db, :ip, :user_agent)', array(array(':timestamp', time(), PDO::PARAM_INT), array(':nick', isset($_POST['nick']) ? $_POST['nick'] : '', PDO::PARAM_STR), array(':text', $_POST['topic'], PDO::PARAM_STR), array(':db', $settings->db, PDO::PARAM_STR), array(':ip', $session->ip, PDO::PARAM_STR), array(':user_agent', isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', PDO::PARAM_STR)));
        $returnb = $db->query('UPDATE sites SET topic_text = :topic_text, topic_nick = :topic_nick WHERE db = :db', array(array(':topic_text', $_POST['topic'], PDO::PARAM_STR), array(':topic_nick', isset($_POST['nick']) ? $_POST['nick'] : '', PDO::PARAM_STR), array(':db', $settings->db, PDO::PARAM_STR)));
        out(array('results' => array('success' => (bool) $returna && (bool) $returnb ? 1 : 0)));
        break;
    default:
        $session->log(sprintf('JSON API access with invalid METHOD: %s', $params[1]));
        generic_error('method_not_implemented');
}