本文整理汇总了PHP中wp_filter_comment函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_filter_comment函数的具体用法?PHP wp_filter_comment怎么用?PHP wp_filter_comment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_filter_comment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
function import() {
$comment_author = $this->author;
$comment_author_url = $this->authoruri;
$comment_author_email = $this->authoremail;
$comment_date = $this->updated;
$comment_content = $this->content;
$comment_post_ID = $this->post_ID;
$comment_author_IP = '127.0.0.1'; //Blogger does not supply the IP so default this
// Clean up content
// Simplepie does some cleaning but does not do these.
$comment_content = str_replace('<br>', '<br />', $comment_content);
$comment_content = str_replace('<hr>', '<hr />', $comment_content);
$comment_parent = isset($this->parentcommentid) ? $this->parentcommentid : 0;
$comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email','comment_author_IP','comment_date', 'comment_content', 'comment_parent');
$comment = wp_filter_comment($comment);
$comment_id = wp_insert_comment($comment);
//links of the form /feeds/417730729915399755/8397846992898424746/comments/default/7732208643735403000
add_comment_meta($comment_id, 'blogger_internal', $this->self, true);
return $comment_id;
}
示例2: wp_new_comment
function wp_new_comment($commentdata)
{
$commentdata = apply_filters('preprocess_comment', $commentdata);
$commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
$commentdata['user_ID'] = (int) $commentdata['user_ID'];
$commentdata['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
$commentdata['comment_agent'] = $_SERVER['HTTP_USER_AGENT'];
$commentdata['comment_date'] = current_time('mysql');
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
$comment_ID = wp_insert_comment($commentdata);
do_action('comment_post', $comment_ID, $commentdata['comment_approved']);
if ('spam' !== $commentdata['comment_approved']) {
// If it's spam save it silently for later crunching
if ('0' == $commentdata['comment_approved']) {
wp_notify_moderator($comment_ID);
}
$post =& get_post($commentdata['comment_post_ID']);
// Don't notify if it's your own comment
if (get_settings('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID']) {
wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
}
}
return $comment_ID;
}
示例3: process_comments
function process_comments($post_id, $item_id)
{
if (empty($post_id)) {
return;
}
if (!is_numeric($post_id)) {
return;
}
$comments = $this->model->get_item_comments($item_id);
if (!$comments || !isset($comments['data'])) {
return;
}
$comments = $comments['data'];
if (!count($comments)) {
return false;
}
foreach ($comments as $comment) {
if ($this->model->comment_already_imported($comment['id'])) {
continue;
}
// We already have this comment, continue.
$data = array('comment_post_ID' => $post_id, 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime($comment['created_time'])), 'comment_author' => $comment['from']['name'], 'comment_author_url' => 'http://www.facebook.com/profile.php?id=' . $comment['from']['id'], 'comment_content' => $comment['message']);
$meta = array('fb_comment_id' => $comment['id'], 'fb_author_id' => $comment['from']['id']);
$data = wp_filter_comment($data);
$comment_id = wp_insert_comment($data);
add_comment_meta($comment_id, 'wdfb_comment', $meta);
if ($this->model->data->get_option('wdfb_comments', 'notify_authors')) {
wp_notify_postauthor($comment_id, 'comment');
}
}
}
示例4: spawn_random_comments
public static function spawn_random_comments($post)
{
$fake_comment = array('user_id' => get_current_user_id(), 'comment_author' => 'Author', 'comment_author_IP' => '', 'comment_author_url' => '', 'comment_author_email' => '', 'comment_post_ID' => $post->ID, 'comment_type' => '', 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1), 'comment_approved' => 1, 'comment_content' => 'test stuff author comment');
$comments = array(array_merge($fake_comment, array('user_id' => get_current_user_id(), 'comment_author' => 'Author', 'comment_content' => 'test stuff author comment')), array_merge($fake_comment, array('user_id' => 0, 'comment_author' => 'Visitor', 'comment_content' => 'test stuff visitor comment')), array_merge($fake_comment, array('user_id' => 0, 'comment_author' => 'Trackback', 'comment_type' => 'trackback', 'comment_content' => 'test stuff visitor trackback')), array_merge($fake_comment, array('user_id' => 0, 'comment_author' => 'Pingback', 'comment_type' => 'pingback', 'comment_content' => 'test stuff visitor pingkback')));
foreach ($comments as $cid => $comment) {
$comment['comment_ID'] = $cid;
$comments[$cid] = (object) wp_filter_comment($comment);
}
return $comments;
}
示例5: mdjm_add_journal
/**
* Update the event journal.
*
* @since 1.3
* @param arr $data
* @param arr $meta
* @return: int|bool comment_id or false on failure
*/
function mdjm_add_journal($args = array(), $meta = array())
{
// Return if journaling is disabled.
if (!mdjm_get_option('journaling', false)) {
return false;
}
$defaults = array('user_id' => get_current_user_id(), 'event_id' => '', 'comment_content' => '', 'comment_type' => 'mdjm-journal');
$data = wp_parse_args($args, $defaults);
// Make sure we have the required data
if (empty($data['comment_content']) || empty($data['event_id'])) {
return false;
}
$comment_author = !empty($data['user_id']) ? get_userdata($data['user_id']) : 'mdjm';
$comment_data = apply_filters('mdjm_add_journal', array('comment_post_ID' => (int) $data['event_id'], 'comment_author' => $comment_author != 'mdjm' ? $comment_author->display_name : 'MDJM', 'comment_author_email' => $comment_author != 'mdjm' ? $comment_author->user_email : mdjm_get_option('system_email'), 'comment_author_IP' => '', 'comment_agent' => '', 'comment_author_url' => '', 'comment_date' => current_time('mysql'), 'comment_date_gmt' => current_time('mysql', 1), 'comment_content' => $data['comment_content'], 'comment_type' => 'mdjm-journal', 'user_id' => $comment_author != 'mdjm' ? $comment_author->ID : '0', 'comment_parent' => 0, 'comment_approved' => 1));
// Filter the comment data before inserting
$comment_data = apply_filters('preprocess_comment', $comment_data);
$comment_data = wp_filter_comment($comment_data);
// Disable comment duplication check filter
remove_filter('commentdata', 'comment_duplicate_trigger');
do_action('mdjm_pre_add_journal', $data, $meta, $comment_data);
// Insert the comment
$comment_id = wp_insert_comment($comment_data);
if (!$comment_id) {
return false;
}
$comment_meta = array('mdjm_type' => !empty($meta['type']) ? $meta['type'] : 'mdjm-journal', 'mdjm_visibility' => !empty($meta['visibility']) ? $meta['visibility'] : '0', 'mdjm_notify' => !empty($meta['notify']) ? $meta['notify'] : '', 'mdjm_to' => !empty($meta['to']) ? $meta['to'] : '', 'mdjm_isread' => !empty($meta['isread']) ? $meta['isread'] : '');
$comment_meta = wp_parse_args($meta, $comment_meta);
foreach ($comment_meta as $key => $value) {
if (!empty($value)) {
add_comment_meta($comment_id, $key, $value, false);
}
}
// Enable comment duplication check filter
add_filter('commentdata', 'comment_duplicate_trigger');
do_action('mdjm_post_add_journal', $data, $meta, $comment_data);
return $comment_id;
}
示例6: process_posts
//.........这里部分代码省略.........
if ($post_id = post_exists($post_title, '', $post_date)) {
echo '<li>';
printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
} else {
echo '<li>';
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$post_author = $this->checkauthor($post_author);
//just so that if a post already exists, new users are not created by checkauthor
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
$post_id = wp_insert_post($postdata);
// Add categories.
if (0 != count($post_categories)) {
wp_create_categories($post_categories, $post_id);
}
}
$comment_post_ID = $post_id;
// Now for comments
$comments = explode("-----\nCOMMENT:", $comments[0]);
$num_comments = 0;
foreach ($comments as $comment) {
if ('' != trim($comment)) {
// Author
preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
$comment_author = $wpdb->escape(trim($comment_author[1]));
$comment = preg_replace('|(\\n?AUTHOR:.*)|', '', $comment);
preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
$comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
$comment = preg_replace('|(\\n?EMAIL:.*)|', '', $comment);
preg_match("|IP:(.*)|", $comment, $comment_author_IP);
$comment_author_IP = trim($comment_author_IP[1]);
$comment = preg_replace('|(\\n?IP:.*)|', '', $comment);
preg_match("|URL:(.*)|", $comment, $comment_author_url);
$comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
$comment = preg_replace('|(\\n?URL:.*)|', '', $comment);
preg_match("|DATE:(.*)|", $comment, $comment_date);
$comment_date = trim($comment_date[1]);
$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
$comment = preg_replace('|(\\n?DATE:.*)|', '', $comment);
$comment_content = $wpdb->escape(trim($comment));
$comment_content = str_replace('-----', '', $comment_content);
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_comments++;
}
}
}
if ($num_comments) {
printf(__('(%s comments)'), $num_comments);
}
// Finally the pings
// fix the double newline on the first one
$pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
$pings = explode("-----\nPING:", $pings[0]);
$num_pings = 0;
foreach ($pings as $ping) {
if ('' != trim($ping)) {
// 'Author'
preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
$comment_author = $wpdb->escape(trim($comment_author[1]));
$ping = preg_replace('|(\\n?BLOG NAME:.*)|', '', $ping);
preg_match("|IP:(.*)|", $ping, $comment_author_IP);
$comment_author_IP = trim($comment_author_IP[1]);
$ping = preg_replace('|(\\n?IP:.*)|', '', $ping);
preg_match("|URL:(.*)|", $ping, $comment_author_url);
$comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
$ping = preg_replace('|(\\n?URL:.*)|', '', $ping);
preg_match("|DATE:(.*)|", $ping, $comment_date);
$comment_date = trim($comment_date[1]);
$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
$ping = preg_replace('|(\\n?DATE:.*)|', '', $ping);
preg_match("|TITLE:(.*)|", $ping, $ping_title);
$ping_title = $wpdb->escape(trim($ping_title[1]));
$ping = preg_replace('|(\\n?TITLE:.*)|', '', $ping);
$comment_content = $wpdb->escape(trim($ping));
$comment_content = str_replace('-----', '', $comment_content);
$comment_content = "<strong>{$ping_title}</strong>\n\n{$comment_content}";
$comment_type = 'trackback';
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_pings++;
}
}
}
if ($num_pings) {
printf(__('(%s pings)'), $num_pings);
}
echo "</li>";
}
flush();
}
echo '</ol>';
wp_import_cleanup($this->id);
echo '<h3>' . sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')) . '</h3>';
}
示例7: process_post
//.........这里部分代码省略.........
// Add categories.
if (count($categories) > 0) {
$post_cats = array();
foreach ($categories as $category) {
if ('' == $category) {
continue;
}
$slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
$cat = get_term_by('slug', $slug, 'category');
$cat_ID = 0;
if (!empty($cat)) {
$cat_ID = $cat->term_id;
}
if ($cat_ID == 0) {
$category = $wpdb->escape($category);
$cat_ID = wp_insert_category(array('cat_name' => $category));
if (is_wp_error($cat_ID)) {
continue;
}
}
$post_cats[] = $cat_ID;
}
wp_set_post_categories($post_id, $post_cats);
}
// Add tags.
if (count($tags) > 0) {
$post_tags = array();
foreach ($tags as $tag) {
if ('' == $tag) {
continue;
}
$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
$tag_obj = get_term_by('slug', $slug, 'post_tag');
$tag_id = 0;
if (!empty($tag_obj)) {
$tag_id = $tag_obj->term_id;
}
if ($tag_id == 0) {
$tag = $wpdb->escape($tag);
$tag_id = wp_insert_term($tag, 'post_tag');
if (is_wp_error($tag_id)) {
continue;
}
$tag_id = $tag_id['term_id'];
}
$post_tags[] = intval($tag_id);
}
wp_set_post_tags($post_id, $post_tags);
}
}
// Now for comments
preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
$comments = $comments[1];
$num_comments = 0;
$inserted_comments = array();
if ($comments) {
foreach ($comments as $comment) {
$comment_id = $this->get_tag($comment, 'wp:comment_id');
$newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
$newcomments[$comment_id]['comment_author'] = $this->get_tag($comment, 'wp:comment_author');
$newcomments[$comment_id]['comment_author_email'] = $this->get_tag($comment, 'wp:comment_author_email');
$newcomments[$comment_id]['comment_author_IP'] = $this->get_tag($comment, 'wp:comment_author_IP');
$newcomments[$comment_id]['comment_author_url'] = $this->get_tag($comment, 'wp:comment_author_url');
$newcomments[$comment_id]['comment_date'] = $this->get_tag($comment, 'wp:comment_date');
$newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag($comment, 'wp:comment_date_gmt');
$newcomments[$comment_id]['comment_content'] = $this->get_tag($comment, 'wp:comment_content');
$newcomments[$comment_id]['comment_approved'] = $this->get_tag($comment, 'wp:comment_approved');
$newcomments[$comment_id]['comment_type'] = $this->get_tag($comment, 'wp:comment_type');
$newcomments[$comment_id]['comment_parent'] = $this->get_tag($comment, 'wp:comment_parent');
}
// Sort by comment ID, to make sure comment parents exist (if there at all)
ksort($newcomments);
foreach ($newcomments as $key => $comment) {
// if this is a new post we can skip the comment_exists() check
if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
if (isset($inserted_comments[$comment['comment_parent']])) {
$comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
}
$comment = wp_filter_comment($comment);
$inserted_comments[$key] = wp_insert_comment($comment);
$num_comments++;
}
}
}
if ($num_comments) {
printf(' ' . _n('(%s comment)', '(%s comments)', $num_comments, 'wordpress-importer'), $num_comments);
}
// Now for post meta
preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
$postmeta = $postmeta[1];
if ($postmeta) {
foreach ($postmeta as $p) {
$key = $this->get_tag($p, 'wp:meta_key');
$value = $this->get_tag($p, 'wp:meta_value');
$this->process_post_meta($post_id, $key, $value);
}
}
do_action('import_post_added', $post_id);
print "</li>\n";
}
示例8: sanitize_inputs
function sanitize_inputs($data)
{
// sanitize inputs
$cleaned_data = array();
foreach ($data as $key => $value) {
// 1. do we care ? if so, add it
if (in_array($key, self::$comment_fields)) {
$cleaned_data[$key] = $value;
}
}
return wp_filter_comment($cleaned_data);
}
示例9: download_comment_bodies
function download_comment_bodies()
{
global $wpdb;
$cookie = $this->get_session();
if (is_wp_error($cookie)) {
return $cookie;
}
// Load previous state (if any)
$this->usermap = (array) get_option('ljapi_usermap');
$maxid = get_option('ljapi_maxid') ? (int) get_option('ljapi_maxid') : 1;
$highest_id = (int) get_option('ljapi_highest_comment_id');
$loop = 0;
while ($maxid > $highest_id && $loop < 5) {
// We do 5 loops per call to avoid memory limits
$loop++;
// Get a batch of comments, using the highest_id we've already got as a starting point
$results = wp_remote_get($this->comments_url . '?get=comment_body&startid=' . ($highest_id + 1), array('cookies' => array($cookie), 'timeout' => 20));
if (is_wp_error($results)) {
return new WP_Error('comment_bodies', __('Failed to retrieve comment bodies from LiveJournal. Please try again soon.'));
}
$results = wp_remote_retrieve_body($results);
// Parse out each comment and insert directly
preg_match_all('|<comment id=\'(\\d+)\'.*</comment>|iUs', $results, $matches);
for ($c = 0; $c < count($matches[0]); $c++) {
// Keep track of highest id seen
if ($matches[1][$c] > $highest_id) {
$highest_id = $matches[1][$c];
update_option('ljapi_highest_comment_id', $highest_id);
}
$comment = $matches[0][$c];
// Filter out any captured, deleted comments (nothing useful to import)
$comment = preg_replace('|<comment id=\'\\d+\' jitemid=\'\\d+\' posterid=\'\\d+\' state=\'D\'[^/]*/>|is', '', $comment);
// Parse this comment into an array and insert
$comment = $this->parse_comment($comment);
$comment = wp_filter_comment($comment);
$id = wp_insert_comment($comment);
// Clear cache
clean_comment_cache($id);
}
// Clear cache to preseve memory
wp_cache_flush();
}
// endwhile - all comments downloaded and ready for bulk processing
// Counter just used to show progress to user
update_option('ljapi_comment_batch', (int) get_option('ljapi_comment_batch') + 1);
return true;
}
示例10: import
//.........这里部分代码省略.........
$post_content = $postmaincontent;
if (strlen($postmorecontent) > 3) {
$post_content .= "<!--more--><br /><br />" . $postmorecontent;
}
$post_content = $wpdb->escape($post_content);
$post_karma = $postinfo[12];
$post_status = 'publish';
//in greymatter, there are no drafts
$comment_status = 'open';
$ping_status = 'closed';
if ($post_ID = post_exists($post_title, '', $post_date)) {
echo ' ';
_e('(already exists)');
} else {
//just so that if a post already exists, new users are not created by checkauthor
// we'll check the author is registered, or if it's a deleted author
$user_id = username_exists($post_author);
if (!$user_id) {
// if deleted from GM, we register the author as a level 0 user
$user_ip = "127.0.0.1";
$user_domain = "localhost";
$user_browser = "server";
$user_joindate = "1979-06-06 00:41:00";
$user_login = $wpdb->escape($post_author);
$pass1 = $wpdb->escape("password");
$user_nickname = $wpdb->escape($post_author);
$user_email = $wpdb->escape("user@deleted.com");
$user_url = $wpdb->escape("");
$user_joindate = $wpdb->escape($user_joindate);
$user_info = array("user_login" => $user_login, "user_pass" => $pass1, "user_nickname" => $user_nickname, "user_email" => $user_email, "user_url" => $user_url, "user_ip" => $user_ip, "user_domain" => $user_domain, "user_browser" => $user_browser, "dateYMDhour" => $user_joindate, "user_level" => 0, "user_idmode" => "nickname");
$user_id = wp_insert_user($user_info);
$this->gmnames[$postinfo[1]] = $user_id;
echo ': ';
printf(__('registered deleted user %s at level 0 '), "<em>{$user_login}</em>");
}
if (array_key_exists($postinfo[1], $this->gmnames)) {
$post_author = $this->gmnames[$postinfo[1]];
} else {
$post_author = $user_id;
}
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
$post_ID = wp_insert_post($postdata);
}
$c = count($entry);
if ($c > 4) {
$numAddedComments = 0;
$numComments = 0;
for ($j = 4; $j < $c; $j++) {
$entry[$j] = $this->gm2autobr($entry[$j]);
$commentinfo = explode("|", $entry[$j]);
$comment_post_ID = $post_ID;
$comment_author = $wpdb->escape($commentinfo[0]);
$comment_author_email = $wpdb->escape($commentinfo[2]);
$comment_author_url = $wpdb->escape($commentinfo[3]);
$comment_author_IP = $wpdb->escape($commentinfo[1]);
$commentyear = $commentinfo[7];
$commentmonth = zeroise($commentinfo[5], 2);
$commentday = zeroise($commentinfo[6], 2);
$commenthour = zeroise($commentinfo[8], 2);
$commentminute = zeroise($commentinfo[9], 2);
$commentsecond = zeroise($commentinfo[10], 2);
if ($commentinfo[11] == "PM" && $commenthour != "12") {
$commenthour = $commenthour + 12;
}
$comment_date = "{$commentyear}-{$commentmonth}-{$commentday} {$commenthour}:{$commentminute}:{$commentsecond}";
$comment_content = $wpdb->escape($commentinfo[12]);
if (!comment_exists($comment_author, $comment_date)) {
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$numAddedComments++;
}
$numComments++;
}
if ($numAddedComments > 0) {
echo ': ';
printf(__('imported %d comment(s)'), $numAddedComments);
}
$preExisting = $numComments - numAddedComments;
if ($preExisting > 0) {
echo ' ';
printf(__('ignored %d pre-existing comments'), $preExisting);
}
}
echo '... <strong>' . __('Done') . '</strong></li>';
}
}
?>
</ul><strong><?php
_e('Done');
?>
</strong></li></ul>
<p> </p>
<p><?php
_e('Completed GreyMatter import!');
?>
</p>
<?php
$this->footer();
}
示例11: import_posts
//.........这里部分代码省略.........
$post_title = $wpdb->escape(trim($post_title[1]));
preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
$post_date = strtotime($post_date[1]);
$post_date = gmdate('Y-m-d H:i:s', $post_date);
preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
$categories = $categories[1];
$cat_index = 0;
foreach ($categories as $category) {
$categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
$cat_index++;
}
if(strcasecmp($post_type, "photo") === 0) {
preg_match('|<sizedPhotoUrl>(.*?)</sizedPhotoUrl>|is', $post, $post_content);
$post_content = '<img src="'.trim($post_content[1]).'" />';
$post_content = $this->unhtmlentities($post_content);
} else {
preg_match('|<body>(.*?)</body>|is', $post, $post_content);
$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
$post_content = $this->unhtmlentities($post_content);
}
// Clean up content
$post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);
$post_content = $wpdb->escape($post_content);
$post_author = $current_user->ID;
preg_match('|<postStatus>(.*?)</postStatus>|is', $post, $post_status);
$post_status = trim($post_status[1]);
echo '<li>';
if ($post_id = post_exists($post_title, $post_content, $post_date)) {
printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
} else {
printf(__('Importing post <em>%s</em>...'), stripslashes($post_title));
$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($postdata);
if ( is_wp_error( $post_id ) ) {
return $post_id;
}
if (!$post_id) {
_e("Couldn't get post ID");
echo '</li>';
break;
}
if(0 != count($categories))
wp_create_categories($categories, $post_id);
}
preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
$comments = $comments[1];
if ( $comments ) {
$comment_post_ID = (int) $post_id;
$num_comments = 0;
foreach ($comments as $comment) {
preg_match('|<body>(.*?)</body>|is', $comment, $comment_content);
$comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
$comment_content = $this->unhtmlentities($comment_content);
// Clean up content
$comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
$comment_content = str_replace('<br>', '<br />', $comment_content);
$comment_content = str_replace('<hr>', '<hr />', $comment_content);
$comment_content = $wpdb->escape($comment_content);
preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
$comment_date = trim($comment_date[1]);
$comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
preg_match('|<author>(.*?)</author>|is', $comment, $comment_author);
$comment_author = $wpdb->escape(trim($comment_author[1]));
$comment_author_email = NULL;
$comment_approved = 1;
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_comments++;
}
}
}
if ( $num_comments ) {
echo ' ';
printf( __ngettext('%s comment', '%s comments', $num_comments), $num_comments );
}
echo '</li>';
flush();
ob_flush();
}
echo '</ol>';
}
示例12: wp_update_comment
/**
* wp_update_comment() - Parses and updates an existing comment in the database
*
* {@internal Missing Long Description}}
*
* @since 2.0.0
* @uses $wpdb
*
* @param array $commentarr Contains information on the comment
* @return int Comment was updated if value is 1, or was not updated if value is 0.
*/
function wp_update_comment($commentarr)
{
global $wpdb;
// First, get all of the original fields
$comment = get_comment($commentarr['comment_ID'], ARRAY_A);
// Escape data pulled from DB.
foreach ((array) $comment as $key => $value) {
$comment[$key] = $wpdb->escape($value);
}
// Merge old and new fields with new fields overwriting old ones.
$commentarr = array_merge($comment, $commentarr);
$commentarr = wp_filter_comment($commentarr);
// Now extract the merged array.
extract($commentarr, EXTR_SKIP);
$comment_content = apply_filters('comment_save_pre', $comment_content);
$comment_date_gmt = get_gmt_from_date($comment_date);
$wpdb->query("UPDATE {$wpdb->comments} SET\n\t\t\tcomment_content = '{$comment_content}',\n\t\t\tcomment_author = '{$comment_author}',\n\t\t\tcomment_author_email = '{$comment_author_email}',\n\t\t\tcomment_approved = '{$comment_approved}',\n\t\t\tcomment_author_url = '{$comment_author_url}',\n\t\t\tcomment_date = '{$comment_date}',\n\t\t\tcomment_date_gmt = '{$comment_date_gmt}'\n\t\tWHERE comment_ID = {$comment_ID}");
$rval = $wpdb->rows_affected;
clean_comment_cache($comment_ID);
wp_update_comment_count($comment_post_ID);
do_action('edit_comment', $comment_ID);
return $rval;
}
示例13: add_journal
public function add_journal($data, $meta)
{
global $mdjm, $post;
if (MDJM_JOURNAL != true) {
if (MDJM_DEBUG == true) {
MDJM()->debug->log_it('ERROR: Instructed to Journal whilst Journalling is disabled');
}
return;
}
if (empty($data['comment_content'])) {
if (MDJM_DEBUG == true) {
MDJM()->debug->log_it('ERROR: Missing Comment Contents in ' . __FUNCTION__, true);
}
return false;
}
if (empty($meta['type'])) {
if (MDJM_DEBUG == true) {
MDJM()->debug->log_it('ERROR: Missing Comment Type in ' . __FUNCTION__, true);
}
return false;
}
/* -- Disable Comment Flood Prevention -- */
add_filter('comment_flood_filter', '__return_false');
$event_id = !empty($data['event']) ? $data['event'] : $post->ID;
if (empty($event_id)) {
if (MDJM_DEBUG == true) {
MDJM()->debug->log_it('ERROR: Missing event id in ' . __FUNCTION__, true);
}
return false;
}
/* -- Set the content -- */
if (isset($data['user'])) {
$commenter = get_userdata($data['user']);
} else {
$commenter = 'mdjm';
}
$comment_data = array('comment_post_ID' => (int) $event_id, 'comment_author' => $commenter != 'mdjm' ? $commenter->display_name : '', 'comment_author_email' => $commenter != 'mdjm' ? $commenter->user_email : '', 'comment_author_IP' => !empty($_SERVER['REMOTE_ADDR']) ? preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']) : '', 'comment_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 254) : '', 'comment_author_url' => $commenter != 'mdjm' ? !empty($commenter->user_url) ? $commenter->user_url : '' : '', 'comment_content' => $data['comment_content'] . ' (' . time() . ')', 'comment_type' => !empty($data['comment_type']) ? $data['comment_type'] : 'mdjm-journal', 'comment_date' => !empty($data['comment_date']) ? $data['comment_date'] : current_time('mysql'), 'user_id' => $commenter != 'mdjm' ? $commenter->ID : '0', 'comment_parent' => 0, 'comment_approved' => 1);
// Filter the comment data before inserting
$comment_data = apply_filters('preprocess_comment', $comment_data);
$comment_data = wp_filter_comment($comment_data);
/* -- Disable comment duplication check filter -- */
remove_filter('commentdata', 'comment_duplicate_trigger');
/* -- Insert the entry -- */
$comment_id = wp_insert_comment($comment_data);
if (empty($comment_id)) {
return false;
}
/* -- Set the meta -- */
$comment_meta = array('mdjm_type' => $meta['type'], 'mdjm_visibility' => !empty($meta['visibility']) ? $meta['visibility'] : '0', 'mdjm_notify' => !empty($meta['notify']) ? $meta['notify'] : '', 'mdjm_to' => !empty($meta['to']) ? $meta['to'] : '', 'mdjm_isread' => !empty($meta['isread']) ? $meta['isread'] : '');
/* -- Insert the meta -- */
foreach ($comment_meta as $key => $value) {
if (!empty($value)) {
add_comment_meta($comment_id, $key, $value, false);
}
}
/* -- Enable comment filter -- */
add_filter('commentdata', 'comment_duplicate_trigger');
return $comment_id;
}
示例14: nxs_postNewComment
function nxs_postNewComment($cmnt, $aa = false)
{
$cmnt['comment_post_ID'] = (int) $cmnt['comment_post_ID'];
$cmnt['comment_parent'] = isset($cmnt['comment_parent']) ? absint($cmnt['comment_parent']) : 0;
$parent_status = 0 < $cmnt['comment_parent'] ? wp_get_comment_status($cmnt['comment_parent']) : '';
$cmnt['comment_parent'] = 'approved' == $parent_status || 'unapproved' == $parent_status ? $cmnt['comment_parent'] : 0;
$cmnt['comment_author_IP'] = '';
$cmnt['comment_agent'] = 'SNAP';
$cmnt['comment_date'] = get_date_from_gmt($cmnt['comment_date_gmt']);
$cmnt = wp_filter_comment($cmnt);
if ($aa) {
$cmnt['comment_approved'] = 1;
} else {
$cmnt['comment_approved'] = wp_allow_comment($cmnt);
}
$cmntID = wp_insert_comment($cmnt);
if ('spam' !== $cmnt['comment_approved']) {
if ('0' == $cmnt['comment_approved']) {
wp_notify_moderator($cmntID);
}
$post =& get_post($cmnt['comment_post_ID']);
if (get_option('comments_notify') && $cmnt['comment_approved'] && (!isset($cmnt['user_id']) || $post->post_author != $cmnt['user_id'])) {
wp_notify_postauthor($cmntID, isset($cmnt['comment_type']) ? $cmnt['comment_type'] : '');
}
global $wpdb, $dsq_api;
if (isset($dsq_api)) {
$plugins_url = str_replace('social-networks-auto-poster-facebook-twitter-g/', '', plugin_dir_path(__FILE__));
require_once $plugins_url . 'disqus-comment-system/export.php';
if (function_exists('dsq_export_wp')) {
$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = " . $cmntID));
// prr($comments);
$wxr = dsq_export_wp($post, $comments);
$response = $dsq_api->import_wordpress_comments($wxr, time());
// prr($response);
}
}
}
return $cmntID;
}
示例15: createPost
/**
* 从服务器pull评论到本地
*
* @param array $posts
*/
public function createPost($post)
{
global $wpdb;
// 将img加到白名单中,仅对WordPress 3.5.0以后有效
if (!has_filter('wp_kses_allowed_html', array($this, 'allowedHtml'))) {
add_filter('wp_kses_allowed_html', array($this, 'allowedHtml'));
}
static $approvedMap = array('pending' => '0', 'approved' => '1', 'deleted' => 'trash', 'spam' => 'spam', 'thread-deleted' => 'post-trashed');
$post_id = isset($post['thread_key']) ? $post['thread_key'] : $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'duoshuo_thread_id' AND meta_value = {$post['thread_id']}");
if (!is_numeric($post_id)) {
// 找不到对应的文章
return array();
}
$data = array('comment_author' => trim(strip_tags($post['author_name'])), 'comment_author_email' => $post['author_email'], 'comment_author_url' => $post['author_url'], 'comment_author_IP' => $post['ip'], 'comment_date' => $this->rfc3339_to_mysql($post['created_at']), 'comment_date_gmt' => $this->rfc3339_to_mysql_gmt($post['created_at']), 'comment_content' => $post['message'], 'comment_approved' => $approvedMap[$post['status']], 'comment_agent' => 'Duoshuo/' . self::VERSION . ':' . $post['post_id'], 'comment_type' => $post['type'], 'comment_post_ID' => $post_id);
if ($post['parent_id']) {
$parent_id = $wpdb->get_var("SELECT comment_ID FROM {$wpdb->commentmeta} WHERE meta_key = 'duoshuo_post_id' AND meta_value = '{$post['parent_id']}'");
if (isset($parent_id)) {
$data['comment_parent'] = $parent_id;
}
}
$author_id = isset($post['author_key']) ? $post['author_key'] : $wpdb->get_var("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'duoshuo_user_id' AND meta_value = {$post['author_id']}");
if (is_numeric($author_id)) {
$data['user_id'] = $author_id;
}
if (isset($post['post_key'])) {
$data['comment_ID'] = $post['post_key'];
} elseif (isset($post['post_id'])) {
$data['comment_ID'] = $wpdb->get_var("SELECT comment_ID FROM {$wpdb->commentmeta} WHERE meta_key = 'duoshuo_post_id' AND meta_value = '{$post['post_id']}'");
}
if (isset($data['comment_ID'])) {
// wp_update_comment 中会做 wp_filter_comment
wp_update_comment($data);
} else {
$data = wp_filter_comment($data);
$data['comment_ID'] = wp_insert_comment($data);
}
if ($post['parent_id']) {
update_comment_meta($data['comment_ID'], 'duoshuo_parent_id', $post['parent_id']);
} else {
delete_comment_meta($data['comment_ID'], 'duoshuo_parent_id');
}
update_comment_meta($data['comment_ID'], 'duoshuo_post_id', $post['post_id']);
return array($post_id);
}