コード例 #1
0
/**
 * Save a comment made by a visitor
 *
 * @access public
 * @param   int     The ID of an entry
 * @param   array   An array that holds the input data from the visitor
 * @param   string  The type of a comment (normal/trackback)
 * @param   string  Where did a comment come from? (internal|trackback|plugin)
 * @return  boolean Returns true if the comment could be added
 */
function serendipity_saveComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal')
{
    global $serendipity;
    $query = "SELECT id, allow_comments, moderate_comments, last_modified, timestamp, title FROM {$serendipity['dbPrefix']}entries WHERE id = '" . (int) $id . "'";
    $ca = serendipity_db_query($query, true);
    $commentInfo['type'] = $type;
    $commentInfo['source'] = $source;
    serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo);
    if (!is_array($ca) || serendipity_db_bool($ca['allow_comments'])) {
        if ($GLOBALS['tb_logging']) {
            $fp = fopen('trackback2.log', 'a');
            fwrite($fp, '[' . date('d.m.Y H:i') . '] insert comment into DB' . "\n");
            fclose($fp);
        }
        $commentInfo['comment_cid'] = serendipity_insertComment($id, $commentInfo, $type, $source, $ca);
        $commentInfo['comment_id'] = $id;
        serendipity_plugin_api::hook_event('frontend_saveComment_finish', $ca, $commentInfo);
        return true;
    } else {
        if ($GLOBALS['tb_logging']) {
            $fp = fopen('trackback2.log', 'a');
            fwrite($fp, '[' . date('d.m.Y H:i') . '] discarding comment from DB' . "\n");
            fclose($fp);
        }
        return false;
    }
}
コード例 #2
0
 function import()
 {
     global $serendipity;
     if (!file_exists($this->data['url'])) {
         printf(FILE_NOT_FOUND, htmlspecialchars($this->data['url']));
         return false;
     }
     $file = file_get_contents($this->data['url']);
     $tree =& $this->parseXML($file);
     $serendipity['noautodiscovery'] = 1;
     foreach ($tree[0]['children'] as $idx => $entry) {
         if (!is_array($entry)) {
             continue;
         }
         if ($entry['tag'] != 'entry') {
             continue;
         }
         $new_entry = array('allow_comments' => true, 'extended' => '', 'categories' => array(), 'isdraft' => $this->data['type'] == 'draft' ? 'true' : 'false', 'categories' => array($this->data['category'] => $this->data['category']));
         if (!is_array($entry['children'])) {
             continue;
         }
         foreach ($entry['children'] as $idx2 => $entrydata) {
             if (!is_array($entrydata)) {
                 continue;
             }
             switch ($entrydata['tag']) {
                 case 'eventtime':
                     $new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
                     break;
                 case 'date':
                     $new_entry['timestamp'] = $this->getTimestamp($entrydata['value']);
                     break;
                 case 'subject':
                     $new_entry['title'] = $entrydata['value'];
                     break;
                 case 'event':
                     $new_entry['body'] = $entrydata['value'];
                     break;
                 case 'comments':
                     $new_entry['comments'] = $this->gatherComments($entrydata);
                     break;
             }
         }
         $id = serendipity_updertEntry($new_entry);
         echo 'Inserted entry #' . $id . ', "' . htmlspecialchars($new_entry['title']) . '"<br />' . "\n";
         if (is_array($new_entry['comments'])) {
             $cid_map = array();
             $jids = array();
             foreach ($new_entry['comments'] as $comment) {
                 array_push($jids, $comment['jtalkid']);
                 if (array_key_exists($comment['jparentid'], $cid_map)) {
                     $comment['parent_id'] = $cid_map[$comment['jparentid']];
                 }
                 $cid = serendipity_insertComment($id, $comment);
                 $cid_map[$comment['jtalkid']] = $cid;
             }
             echo 'Inserted comments for entry #' . $id . '<br />' . "\n";
         }
         if (function_exists('ob_flush')) {
             @ob_flush();
         }
         if (function_exists('flush')) {
             @flush();
         }
     }
     return true;
 }
コード例 #3
0
function wp_newComment($message)
{
    global $serendipity;
    $val = $message->params[1];
    $username = $val->getval();
    $val = $message->params[2];
    $password = $val->getval();
    if (!serendipity_authenticate_author($username, $password)) {
        return new XML_RPC_Response('', XMLRPC_ERR_CODE_AUTHFAILED, XMLRPC_ERR_NAME_AUTHFAILED);
    }
    $val = $message->params[3];
    $article_id = $val->getval();
    $val = $message->params[4];
    $comment = $val->getval();
    // Setup defaults, if not given by client. The serendipity vars were setup while authenticating.
    if (!empty($serendipity['xmlrpc_asureauthor']) && $serendipity['xmlrpc_asureauthor'] != 'default') {
        $comment['author'] = $serendipity[$serendipity['xmlrpc_asureauthor']];
    }
    if (empty($comment['author'])) {
        $comment['author'] = $serendipity['serendipityRealname'];
    }
    if (empty($comment['author_email'])) {
        $comment['author_email'] = $serendipity['serendipityEmail'];
    }
    $commentInfo['comment'] = $comment['content'];
    $commentInfo['name'] = $comment['author'];
    $commentInfo['url'] = $comment['author_url'];
    $commentInfo['email'] = $comment['author_email'];
    if (!empty($commentInfo['comment_parent'])) {
        $commentInfo['comment_parent'] = $comment['parent_id'];
    }
    universal_debug("Saving new comment: " . print_r($commentInfo, true));
    $id = serendipity_insertComment($article_id, $commentInfo);
    return new XML_RPC_Response(new XML_RPC_Value($id, 'int'));
}
コード例 #4
0
 function check_tweetbacks_save_comment($article_id, $entry, $comment_type, $strip_tags = false)
 {
     $commentInfo = array();
     $commentInfo['title'] = $entry[TWITTER_SEARCHRESULT_REALNAME] . " via Twitter";
     $commentInfo['name'] = $entry[TWITTER_SEARCHRESULT_REALNAME];
     $commentInfo['url'] = $this->comment_url($entry);
     $commentInfo['email'] = $entry[TWITTER_SEARCHRESULT_EMAIL];
     $comment = $entry[TWITTER_SEARCHRESULT_TWEET];
     if ($strip_tags) {
         $comment = strip_tags($comment);
     }
     if (LANG_CHARSET != 'UTF-8' && function_exists("mb_convert_encoding")) {
         $comment = mb_convert_encoding($comment, LANG_CHARSET);
     }
     $commentInfo['comment'] = $comment;
     $commentInfo['time'] = strtotime($entry[TWITTER_SEARCHRESULT_PUBDATE]);
     $commentInfo['source'] = 'tweetback';
     $this->log("Tweetback save: title=[" . $commentInfo['title'] . "], comment=[" . $commentInfo['comment'] . "] articleid=[{$article_id}]");
     // patch old config
     if ('default' == $this->get_config('tweetback_moderate')) {
         $this->set_config('tweetback_moderate', 'approved');
     }
     $comment_moderation = $this->get_config('tweetback_moderate', 'approved');
     if ('save' == $comment_moderation) {
         // save comment starts spam plugin. This might intervent the saving, but we don't want that here.
         // If we have more than 1 tweetback, at least the min posting freq for one IP will hit.
         return serendipity_saveComment($article_id, $commentInfo, $comment_type, 'tweetback');
     } else {
         $ca = array();
         $this->hook_saveComment($ca, $commentInfo);
         return serendipity_insertComment($article_id, $commentInfo, $comment_type, 'tweetback', $ca);
     }
 }