本文整理汇总了PHP中kses_init_filters函数的典型用法代码示例。如果您正苦于以下问题:PHP kses_init_filters函数的具体用法?PHP kses_init_filters怎么用?PHP kses_init_filters使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了kses_init_filters函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_suspend_restore_kses
/**
* Suspend kses which runs on content_save_pre and can corrupt JSON in post_content.
*
* @see Post_Type::suspend_kses()
* @see Post_Type::restore_kses()
*/
function test_suspend_restore_kses()
{
if (!has_filter('content_save_pre', 'wp_filter_post_kses')) {
kses_init_filters();
}
$post_type = new Post_Type($this->plugin->customize_snapshot_manager);
$post_type->suspend_kses();
$this->assertFalse(has_filter('content_save_pre', 'wp_filter_post_kses'));
$post_type->restore_kses();
$this->assertEquals(10, has_filter('content_save_pre', 'wp_filter_post_kses'));
remove_filter('content_save_pre', 'wp_filter_post_kses');
$post_type->suspend_kses();
$post_type->restore_kses();
$this->assertFalse(has_filter('content_save_pre', 'wp_filter_post_kses'));
}
示例2: ajax_comment
function ajax_comment()
{
global $wpdb;
//nocache_headers();
$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
$post = get_post($comment_post_ID);
$post_author = $post->post_author;
if (empty($post->comment_status)) {
do_action('comment_id_not_found', $comment_post_ID);
ajax_comment_err('评论的状态无效');
}
$status = get_post_status($post);
$status_obj = get_post_status_object($status);
if (!comments_open($comment_post_ID)) {
do_action('comment_closed', $comment_post_ID);
ajax_comment_err('抱歉, 此文章已不允许新增评论');
} elseif ('trash' == $status) {
do_action('comment_on_trash', $comment_post_ID);
ajax_comment_err('评论的状态无效');
} elseif (!$status_obj->public && !$status_obj->private) {
do_action('comment_on_draft', $comment_post_ID);
ajax_comment_err('评论的状态无效');
} elseif (post_password_required($comment_post_ID)) {
do_action('comment_on_password_protected', $comment_post_ID);
ajax_comment_err('密码保护中');
} else {
do_action('pre_comment_on_post', $comment_post_ID);
}
$comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : null;
$comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null;
$comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
$edit_id = isset($_POST['edit_id']) ? $_POST['edit_id'] : null;
// 提取 edit_id
$user = wp_get_current_user();
if ($user->exists()) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = $wpdb->escape($user->display_name);
$comment_author_email = $wpdb->escape($user->user_email);
$comment_author_url = $wpdb->escape($user->user_url);
$user_ID = $wpdb->escape($user->ID);
if (current_user_can('unfiltered_html')) {
if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
kses_remove_filters();
kses_init_filters();
}
}
} else {
if (get_option('comment_registration') || 'private' == $status) {
ajax_comment_err('抱歉, 在评论前必须登录');
}
}
$comment_type = '';
if (get_option('require_name_email') && !$user->exists()) {
if (6 > strlen($comment_author_email) || '' == $comment_author) {
ajax_comment_err('失败, 发表留言不能没有署名~');
} elseif (!is_email($comment_author_email)) {
ajax_comment_err('错误: 请输入有效的电子邮箱地址~');
}
}
if ('' == $comment_content) {
ajax_comment_err('失败, 还没有开始写任何评论呢~');
}
$dupe = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = '{$comment_post_ID}' AND ( comment_author = '{$comment_author}' ";
if ($comment_author_email) {
$dupe .= "OR comment_author_email = '{$comment_author_email}' ";
}
$dupe .= ") AND comment_content = '{$comment_content}' LIMIT 1";
if ($wpdb->get_var($dupe)) {
ajax_comment_err('检测到重复的评论, 似乎你已经这样评论过了');
}
if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM {$wpdb->comments} WHERE comment_author = %s ORDER BY comment_date DESC LIMIT 1", $comment_author))) {
$time_lastcomment = mysql2date('U', $lasttime, false);
$time_newcomment = mysql2date('U', current_time('mysql', 1), false);
$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
if ($flood_die) {
ajax_comment_err('你发表评论太快了, 慢点儿吧~');
}
}
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
if ($edit_id) {
$comment_id = $commentdata['comment_ID'] = $edit_id;
if (ihacklog_user_can_edit_comment($commentdata, $comment_id)) {
wp_update_comment($commentdata);
} else {
ajax_comment_err('Cheatin’ uh?');
}
} else {
$comment_id = wp_new_comment($commentdata);
}
$comment = get_comment($comment_id);
do_action('set_comment_cookies', $comment, $user);
$comment_depth = 1;
$tmp_c = $comment;
while ($tmp_c->comment_parent != 0) {
$comment_depth++;
$tmp_c = get_comment($tmp_c->comment_parent);
//.........这里部分代码省略.........
示例3: isset
$comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
// If the user is logged in
$user = wp_get_current_user();
if ($user->exists()) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = wp_slash($user->display_name);
$comment_author_email = wp_slash($user->user_email);
$comment_author_url = wp_slash($user->user_url);
if (current_user_can('unfiltered_html')) {
if (!isset($_POST['_wp_unfiltered_html_comment']) || !wp_verify_nonce($_POST['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID)) {
kses_remove_filters();
// start with a clean slate
kses_init_filters();
// set up the filters
}
}
} else {
if (get_option('comment_registration') || 'private' == $status) {
wp_die(__('Sorry, you must be logged in to post a comment.'), 403);
}
}
$comment_type = '';
if (get_option('require_name_email') && !$user->exists()) {
if (6 > strlen($comment_author_email) || '' == $comment_author) {
wp_die(__('<strong>ERROR</strong>: please fill the required fields (name, email).'), 200);
} elseif (!is_email($comment_author_email)) {
wp_die(__('<strong>ERROR</strong>: please enter a valid email address.'), 200);
}
示例4: kses_init
/**
* Sets up most of the Kses filters for input form content.
*
* If you remove the kses_init() function from 'init' hook and
* 'set_current_user' (priority is default), then none of the Kses filter hooks
* will be added.
*
* First removes all of the Kses filters in case the current user does not need
* to have Kses filter the content. If the user does not have unfiltered_html
* capability, then Kses filters are added.
*
* @since 2.0.0
*/
function kses_init()
{
kses_remove_filters();
if (!current_user_can('unfiltered_html')) {
kses_init_filters();
}
}
示例5: test_the_content_attribute_value_with_colon
function test_the_content_attribute_value_with_colon()
{
kses_init_filters();
// http://bpr3.org/?p=87
// the title attribute should make it through unfiltered
$post_content = <<<EOF
<span title="My friends: Alice, Bob and Carol">foo</span>
EOF;
$expected = <<<EOF
<p><span title="My friends: Alice, Bob and Carol">foo</span></p>
EOF;
$post_id = self::factory()->post->create(compact('post_content'));
$this->go_to(get_permalink($post_id));
$this->assertTrue(is_single());
$this->assertTrue(have_posts());
$this->assertNull(the_post());
$this->assertEquals(strip_ws($expected), strip_ws(get_echo('the_content')));
kses_remove_filters();
}
示例6: setUp
function setUp()
{
parent::setUp();
update_option('use_balanceTags', 1);
kses_init_filters();
}
示例7: ajax_comment_callback
function ajax_comment_callback()
{
global $wpdb;
$comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
$post = get_post($comment_post_ID);
$post_author = $post->post_author;
if (empty($post->comment_status)) {
do_action('comment_id_not_found', $comment_post_ID);
ajax_comment_err('Invalid comment status.');
}
$status = get_post_status($post);
$status_obj = get_post_status_object($status);
if (!comments_open($comment_post_ID)) {
do_action('comment_closed', $comment_post_ID);
ajax_comment_err('Sorry, comments are closed for this item.');
} elseif ('trash' == $status) {
do_action('comment_on_trash', $comment_post_ID);
ajax_comment_err('Invalid comment status.');
} elseif (!$status_obj->public && !$status_obj->private) {
do_action('comment_on_draft', $comment_post_ID);
ajax_comment_err('Invalid comment status.');
} elseif (post_password_required($comment_post_ID)) {
do_action('comment_on_password_protected', $comment_post_ID);
ajax_comment_err('Password Protected');
} else {
do_action('pre_comment_on_post', $comment_post_ID);
}
$comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : null;
$comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null;
$comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
$user = wp_get_current_user();
if ($user->exists()) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = esc_sql($user->display_name);
$comment_author_email = esc_sql($user->user_email);
$comment_author_url = esc_sql($user->user_url);
$user_ID = esc_sql($user->ID);
if (current_user_can('unfiltered_html')) {
if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
kses_remove_filters();
kses_init_filters();
}
}
} else {
if (get_option('comment_registration') || 'private' == $status) {
ajax_comment_err('Sorry, you must be logged in to post a comment.');
}
}
$comment_type = '';
if (get_option('require_name_email') && !$user->exists()) {
if (6 > strlen($comment_author_email) || '' == $comment_author) {
ajax_comment_err('Error: please fill the required fields (name, email).');
} elseif (!is_email($comment_author_email)) {
ajax_comment_err('Error: please enter a valid email address.');
}
}
if ('' == $comment_content) {
ajax_comment_err('Error: please type a comment.');
}
$dupe = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID = '{$comment_post_ID}' AND ( comment_author = '{$comment_author}' ";
if ($comment_author_email) {
$dupe .= "OR comment_author_email = '{$comment_author_email}' ";
}
$dupe .= ") AND comment_content = '{$comment_content}' LIMIT 1";
if ($wpdb->get_var($dupe)) {
ajax_comment_err('Duplicate comment detected; it looks as though you’ve already said that!');
}
if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT comment_date_gmt FROM {$wpdb->comments} WHERE comment_author = %s ORDER BY comment_date DESC LIMIT 1", $comment_author))) {
$time_lastcomment = mysql2date('U', $lasttime, false);
$time_newcomment = mysql2date('U', current_time('mysql', 1), false);
$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
if ($flood_die) {
ajax_comment_err('You are posting comments too quickly. Slow down.');
}
}
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
$comment_id = wp_new_comment($commentdata);
$comment = get_comment($comment_id);
do_action('set_comment_cookies', $comment, $user);
$comment_depth = 1;
$tmp_c = $comment;
while ($tmp_c->comment_parent != 0) {
$comment_depth++;
$tmp_c = get_comment($tmp_c->comment_parent);
}
$GLOBALS['comment'] = $comment;
//这里修改成你的评论结构
?>
<li <?php
comment_class();
?>
id="li-comment-<?php
comment_ID();
?>
" itemtype="http://schema.org/Comment" itemscope itemprop="comment">
<div class="comment-holder">
//.........这里部分代码省略.........
示例8: kses_init
function kses_init() {
remove_filter('pre_comment_author', 'wp_filter_kses');
remove_filter('pre_comment_content', 'wp_filter_kses');
remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('title_save_pre', 'wp_filter_kses');
if (current_user_can('unfiltered_html') == false)
kses_init_filters();
}
示例9: processCommentSubmission
public function processCommentSubmission($values)
{
if ('POST' != $_SERVER['REQUEST_METHOD']) {
header('Allow: POST');
header('HTTP/1.1 405 Method Not Allowed');
header('Content-Type: text/plain');
exit;
}
$values = $_POST;
try {
$comment_post_ID = isset($values['comment_post_ID']) ? (int) $values['comment_post_ID'] : 0;
$post = get_post($comment_post_ID);
if (empty($post->comment_status)) {
/**
* Fires when a comment is attempted on a post that does not exist.
*
* @since 1.5.0
*
* @param int $comment_post_ID Post ID.
*/
do_action('comment_id_not_found', $comment_post_ID);
throw new Exception\UnknownPostCommentedException(sprintf(__('The post with ID %s could not be found', 'wp-ajax-comment'), $comment_post_ID));
}
// get_post_status() will get the parent status for attachments.
$status = get_post_status($post);
$status_obj = get_post_status_object($status);
if (!comments_open($comment_post_ID)) {
/**
* Fires when a comment is attempted on a post that has comments closed.
*
* @since 1.5.0
*
* @param int $comment_post_ID Post ID.
*/
do_action('comment_closed', $comment_post_ID);
throw new Exception\PostCommentDisabledException(sprintf(__('Sorry, comments are closed for this item.', 'wp-ajax-comment'), $comment_post_ID));
} elseif ('trash' == $status) {
/**
* Fires when a comment is attempted on a trashed post.
*
* @since 2.9.0
*
* @param int $comment_post_ID Post ID.
*/
do_action('comment_on_trash', $comment_post_ID);
throw new Exception\PostIsTrashedException(sprintf(__('This post can not be commented as it is in trash', 'wp-ajax-comment'), $comment_post_ID));
} elseif (!$status_obj->public && !$status_obj->private) {
/**
* Fires when a comment is attempted on a post in draft mode.
*
* @since 1.5.1
*
* @param int $comment_post_ID Post ID.
*/
do_action('comment_on_draft', $comment_post_ID);
throw new Exception\PostIsDraftException(sprintf(__('This post is a draft and can not be commented', 'wp-ajax-comment'), $comment_post_ID));
} elseif (post_password_required($comment_post_ID)) {
/**
* Fires when a comment is attempted on a password-protected post.
*
* @since 2.9.0
*
* @param int $comment_post_ID Post ID.
*/
do_action('comment_on_password_protected', $comment_post_ID);
throw new Exception\PostIsPasswordProtectedException(sprintf(__('This post is password-protected and can not be commented', 'wp-ajax-comment'), $comment_post_ID));
} else {
/**
* Fires before a comment is posted.
*
* @since 2.8.0
*
* @param int $comment_post_ID Post ID.
*/
do_action('pre_comment_on_post', $comment_post_ID);
}
} catch (\Exception $e) {
return $this->sendErrorMessage($e);
}
// If the user is logged in
$user = wp_get_current_user();
if ($user->exists()) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$values['author'] = wp_slash($user->display_name);
$values['email'] = wp_slash($user->user_email);
$values['url'] = wp_slash($user->user_url);
if (current_user_can('unfiltered_html')) {
if (!isset($values['_wp_unfiltered_html_comment']) || !wp_verify_nonce($values['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID)) {
kses_remove_filters();
// start with a clean slate
kses_init_filters();
// set up the filters
}
}
} else {
if (get_option('comment_registration') || 'private' == $status) {
$this->sendErrorMessage(new Exception\LoginRequiredForCommentException(__('Sorry, you must be logged in to post a comment.', 'wp-ajax-comment')));
}
//.........这里部分代码省略.........
示例10: update_existing
function update_existing()
{
// Why doesn't wp_insert_post already do this?
$dbpost = $this->normalize_post(false);
if (!is_null($dbpost)) {
$dbpost['post_pingback'] = false;
// Tell WP 2.1 and 2.2 not to process for pingbacks
// This is a ridiculous kludge necessitated by WordPress 2.6 munging authorship meta-data
add_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
// Kludge to prevent kses filters from stripping the
// content of posts when updating without a logged in
// user who has `unfiltered_html` capability.
kses_remove_filters();
add_filter('wp_insert_post_data', array($this, 'update_post_info'));
// Don't munge status fields that the user may have reset manually
if (function_exists('get_post_field')) {
$doNotMunge = array('post_status', 'comment_status', 'ping_status');
foreach ($doNotMunge as $field) {
$dbpost[$field] = get_post_field($field, $this->wp_id());
}
}
$this->_wp_id = wp_insert_post($dbpost);
// Turn off ridiculous kludges #1 and #2
remove_action('_wp_put_post_revision', array($this, 'fix_revision_meta'));
kses_init_filters();
remove_filter('wp_insert_post_data', array($this, 'update_post_info'));
$this->validate_post_id($dbpost, array(__CLASS__, __FUNCTION__));
}
}
示例11: dia_getSave
function dia_getSave()
{
$imgID = isset($_REQUEST['imgid']) ? trim($_REQUEST['imgid']) : '';
$postID = isset($_REQUEST['postid']) ? trim($_REQUEST['postid']) : 0;
//get data from jQuery
$data = array($_GET["top"], $_GET["left"], $_GET["width"], $_GET["height"], $_GET["text"], $_GET["id"], $_GET["noteID"], $_GET["author"], $_GET["email"]);
global $wpdb;
$table_name = $wpdb->prefix . "demon_imagenote";
if ($data[5] != "new") {
//find the old image note from comment
$result = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE note_img_ID='" . $imgID . "' and note_ID='" . $data[5] . "'");
foreach ($result as $commentresult) {
$comment_id = (int) $commentresult->note_comment_ID;
//comment ID
$comment_author = $commentresult->note_author;
//comment Author
$comment_email = $commentresult->note_email;
//comment Email
}
//update comment
if (get_option('demon_image_annotation_comments') == '0') {
$wpdb->query("UPDATE wp_comments SET comment_content = '" . $data[4] . "' WHERE comment_ID = " . $comment_id);
}
//update image note
$wpdb->query("UPDATE " . $table_name . "\r\n\t\tSET note_top = '" . $data[0] . "',\r\n\t\t\tnote_left = '" . $data[1] . "',\r\n\t\t\tnote_width = '" . $data[2] . "',\r\n\t\t\tnote_height = '" . $data[3] . "',\r\n\t\t\tnote_text = '" . $data[4] . "',\r\n\t\t\tnote_text_ID = '" . "id_" . md5($data[4]) . "' WHERE note_ID = " . $data[6]);
} else {
//if image note is new
$comment_post_ID = $postID;
$comment_author = isset($_GET['author']) ? trim(strip_tags($_GET['author'])) : null;
$comment_author_email = isset($_GET['email']) ? trim($_GET['email']) : null;
$comment_author_url = isset($_GET['url']) ? trim($_GET['url']) : null;
$comment_content = $data[4];
//If the user is logged in, get author name and author email
$user = wp_get_current_user();
if ($user->ID) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = $wpdb->escape($user->display_name);
$comment_author_email = $wpdb->escape($user->user_email);
$comment_author_url = $wpdb->escape($user->user_url);
if (current_user_can('unfiltered_html')) {
if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
kses_remove_filters();
kses_init_filters();
}
}
}
$autoapprove = 1;
if (get_option('demon_image_annotation_autoapprove') == '1') {
$autoapprove = 0;
}
//add to comment
if (get_option('demon_image_annotation_comments') == '0') {
$user_ID = $user->ID;
$comment_type = '';
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
if ($autoapprove == 1) {
$comment_id = wp_insert_comment($commentdata);
} else {
$comment_id = wp_new_comment($commentdata);
}
}
//add to image note
$wpdb->query("INSERT INTO `" . $table_name . "`\r\n\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t`note_img_ID`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_comment_ID`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_post_ID`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_author`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_email`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_top`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_left`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_width`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_height`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_text`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_text_id`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_editable`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_approved`,\r\n\t\t\t\t\t\t\t\t\t\t\t`note_date`\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\tVALUES (\r\n\t\t\t\t\t\t\t\t\t\t'" . $imgID . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . $comment_id . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . $postID . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . $comment_author . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . $comment_author_email . "',\r\n\t\t\t\t\t\t\t\t\t\t" . $data[0] . ",\r\n\t\t\t\t\t\t\t\t\t\t" . $data[1] . ",\r\n\t\t\t\t\t\t\t\t\t\t" . $data[2] . ",\r\n\t\t\t\t\t\t\t\t\t\t" . $data[3] . ",\r\n\t\t\t\t\t\t\t\t\t\t'" . $data[4] . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . "id_" . md5($data[4]) . "',\r\n\t\t\t\t\t\t\t\t\t\t1,\r\n\t\t\t\t\t\t\t\t\t\t'" . $autoapprove . "',\r\n\t\t\t\t\t\t\t\t\t\tnow()\r\n\t\t\t\t\t\t\t\t\t\t)");
}
//output JSON array
echo '{ "status":true, "annotation_id": "id_' . md5($data[4]) . '" }';
}
示例12: trim_words_for_post
/**
* Trims the post's content and updates its content or excerpt, depending on its
* feed source's settings.
*
* @param int|string $post_id The ID of the post
* @param int|string $source_id The ID of the feed source
*/
public static function trim_words_for_post( $post_id, $source_id ) {
// Get the post object. If NULL (invalid ID) stop and do nothing
$post = get_post( $post_id );
if ( $post === NULL ) return;
// Get the post's excerpt and content
$post_excerpt = $post->post_excerpt;
$post_content = $post->post_content;
// Get the trimming options
$word_trimming_options = self::trim_words_options( $source_id );
// If not disabled
if ( $word_trimming_options !== FALSE ) {
// Extract the options from the array
list( $word_limit, $trimming_type ) = array_values( $word_trimming_options );
// Whether to switch of KSES
$allow_embedded_content = WPRSS_FTP_Meta::get_instance()->get_meta( $source_id, 'allow_embedded_content' );
$allow_embedded_content = (WPRSS_FTP_Utils::multiboolean( $allow_embedded_content ) === true);
// Keep these tags. All others will be stripped during trimming.
$keep_tags = array( 'p', 'br', 'em', 'strong', 'a' );
if ( $allow_embedded_content ) // Add allowed embed tags, if applicable
$keep_tags = array_merge( $keep_tags, self::get_allowed_embed_tags() );
$keep_tags = apply_filters( 'wprss_ftp_trimming_keep_tags', $keep_tags );
// Generate the trimmed content
$trimmed_content = wprss_trim_words( $post_content, intval( $word_limit ), $keep_tags );
// If trimming type is set to save it as post_content in the databae
$to_update = ( $trimming_type == 'db' )? 'post_content' : 'post_excerpt';
if ( $allow_embedded_content ) kses_remove_filters();
// Update the post
wp_update_post(
array(
'ID' => $post_id,
$to_update => $trimmed_content
)
);
if ( $allow_embedded_content ) kses_init_filters();
}
}
示例13: lp_post_comment
/**
* Receives an ajax request to post a comment, returns comment's state
* Uses a lot of GLOBAL variables and functions
*/
public function lp_post_comment()
{
global $wpdb, $post;
$comment_post_ID = (int) $_POST['comment_post_ID'];
$post = get_post($comment_post_ID);
if (empty($post->comment_status)) {
do_action('comment_id_not_found', $comment_post_ID);
$this->die_post_status_to_json('error');
} elseif (!comments_open($comment_post_ID)) {
do_action('comment_closed', $comment_post_ID);
$this->die_post_status_to_json('closed');
} elseif (in_array($post->post_status, array('draft', 'pending'))) {
$this->die_post_status_to_json('pending');
}
$comment_author = isset($_POST['author']) ? trim(strip_tags($_POST['author'])) : null;
$comment_author_email = isset($_POST['email']) ? trim($_POST['email']) : null;
$comment_author_url = isset($_POST['url']) ? trim($_POST['url']) : null;
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
// If the user is logged in
$user = wp_get_current_user();
if ($user->ID) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = esc_sql($user->display_name);
$comment_author_email = esc_sql($user->user_email);
$comment_author_url = esc_sql($user->user_url);
if (current_user_can('unfiltered_html')) {
if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
kses_remove_filters();
// start with a clean slate
kses_init_filters();
// set up the filters
}
}
} else {
if (get_option('comment_registration')) {
$this->die_post_status_to_json('not_allowed');
}
}
$comment_type = '';
if (get_option('require_name_email') && !$user->ID) {
if (6 > strlen($comment_author_email) || '' == $comment_author) {
$this->die_post_status_to_json('missing_fields');
} elseif (!is_email($comment_author_email)) {
$this->die_post_status_to_json('missing_fields');
}
}
if ('' == $comment_content) {
$this->die_post_status_to_json('missing_fields');
}
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
$comment_id = wp_new_comment($commentdata);
$comment = get_comment($comment_id);
wp_set_comment_cookies($comment, $user);
$this->die_post_status_to_json(wp_get_comment_status($comment_id));
}
示例14: add_comment
private function add_comment($comment)
{
if (!is_array($comment)) {
return new WP_Error('invalid-argument', 'This action requires an array of valid comment entries.');
}
if (!isset($comment['comment_post_ID'])) {
$response = array();
$error_count = 0;
foreach ($comment as $id => $data) {
$response[$id] = $this->add_comment($data);
if (is_wp_error($response[$id])) {
$error_count++;
}
}
if (count($comment) == $error_count) {
return new WP_Error('invalid-argument', 'This action requires an array of valid comment entries.');
}
return $response;
}
$required_indexes = array('comment_author_IP', 'comment_content', 'comment_agent');
$comment_defaults = array('comment_approved' => 1, 'comment_karma' => 0, 'comment_parent' => 0, 'comment_type' => '', 'filtered' => false, 'sync_run_preprocess_comment_filter' => true, 'sync_send_comment_notifications' => true);
// Starting here, much of the following code mirrors similar code from wp-comments-post.php and wp-includes/comment.php from WP version 3.9.1.
// Mirroring this code was the only way to reliably provide full comment functionality and flexibility while staying compatible with the WP API.
if (!empty($comment['user_id'])) {
$user = get_user_by('id', $comment['user_id']);
if (!is_object($user) || !is_a($user, 'WP_User') || !$user->exists()) {
return new WP_Error('invalid-user-id', "A user with an ID of {$comment['user_id']} does not exist.");
}
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment['comment_author'] = wp_slash($user->display_name);
$comment['comment_author_email'] = wp_slash($user->user_email);
$comment['comment_author_url'] = wp_slash($user->user_url);
kses_remove_filters();
kses_init_filters();
} else {
if (isset($comment['comment_author']) && isset($comment['comment_author_email']) && isset($comment['comment_author_url'])) {
$comment['user_id'] = 0;
} else {
return new WP_Error('missing-required-commenter-data', 'Either user_id or comment_author, comment_author_email, and comment_author_url must be supplied.');
}
}
$comment = array_merge($comment_defaults, $comment);
$run_preprocess_comment_filter = $comment['sync_run_preprocess_comment_filter'];
unset($comment['sync_run_preprocess_comment_filter']);
$send_comment_notifications = $comment['sync_send_comment_notifications'];
unset($comment['sync_send_comment_notifications']);
$missing_indexes = array();
foreach ($required_indexes as $index) {
if (empty($comment[$index])) {
$missing_indexes[] = $index;
}
}
if (!empty($missing_indexes)) {
return new WP_Error('missing-comment-data', 'The following required indexes were missing in the comment data: ' . implode(', ', $missing_indexes));
}
if ($run_preprocess_comment_filter) {
apply_filters('preprocess_comment', $comment);
}
$comment['comment_author_IP'] = preg_replace('/[^0-9a-fA-F:., ]/', '', $comment['comment_author_IP']);
$comment['comment_agent'] = substr($comment['comment_agent'], 0, 254);
$comment['comment_date'] = current_time('mysql');
$comment['comment_date_gmt'] = current_time('mysql', 1);
if (!$comment['filtered']) {
$comment = wp_filter_comment($comment);
}
$id = wp_insert_comment($comment);
if (0 == $id) {
if (!empty($GLOBALS['wpdb']->last_error)) {
$error = $GLOBALS['wpdb']->last_error;
} else {
$error = 'An unknown error prevented the comment from being added to the database.';
}
return new WP_Error('comment-insert-failure', $error);
}
do_action('comment_post', $id, $comment['comment_approved']);
if ($send_comment_notifications && 'spam' !== $comment['comment_approved']) {
if ('0' == $comment['comment_approved']) {
wp_notify_moderator($id);
}
if (get_option('comments_notify') && $comment['comment_approved']) {
wp_notify_postauthor($id);
}
}
$comment['comment_ID'] = $id;
return $comment;
}
示例15: prologue_new_comment
function prologue_new_comment()
{
if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'prologue_new_comment') {
check_ajax_referer('ajaxnonce', '_ajax_post');
$comment_content = isset($_POST['comment']) ? trim($_POST['comment']) : null;
$comment_post_ID = isset($_POST['comment_post_ID']) ? trim($_POST['comment_post_ID']) : null;
// If the user is logged in
$user = wp_get_current_user();
if ($user->ID) {
if (empty($user->display_name)) {
$user->display_name = $user->user_login;
}
$comment_author = $user->display_name;
$comment_author_email = $user->user_email;
$comment_author_url = $user->user_url;
$comment_author_url = $user->user_url;
$user_ID = $user->ID;
if (current_user_can('unfiltered_html')) {
if (wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment']) {
kses_remove_filters();
// start with a clean slate
kses_init_filters();
// set up the filters
}
}
} else {
if (get_option('comment_registration')) {
echo 'Error: ' . __('Sorry, you must be logged in to post a comment.');
exit;
}
}
$comment_type = '';
if (get_option('require_name_email') && !$user->ID) {
if (6 > strlen($comment_author_email) || '' == $comment_author) {
echo 'Error: ' . __('Error: please fill the required fields (name, email).');
exit;
} elseif (!is_email($comment_author_email)) {
echo 'Error: ' . __('Error: please enter a valid email address.');
exit;
}
}
if ('' == $comment_content) {
echo 'Error: ' . __('please type a comment.');
exit;
}
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
$comment_id = wp_new_comment($commentdata);
$comment = get_comment($comment_id);
if (!$user->ID) {
setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
}
if ($comment) {
echo $comment_id;
} else {
echo "'Error: '.Unknown error occured. Comment not posted.";
}
}
exit;
}