ID;
$ac_api_key = get_user_meta($userid, "ac_api_key", true );
if ( current_user_can( 'edit_posts' ) ) {
$offset = 0;
$limit = 20;
$posts_id = array();
do {
$posts = $wpdb->get_results(
"
SELECT ID, post_title, post_author
FROM {$wpdb->posts}
WHERE post_status = 'publish'
AND post_author = {$userid} AND post_type = 'post'
ORDER BY ID LIMIT {$offset},{$limit}
"
);
foreach ( $posts as $post )
{
$ac_postid = get_post_meta( $post->ID, "ac_postid", true );
if ( strlen( $ac_postid ) > 0 ) {
array_push( $posts_id, $ac_postid );
}
}
$wpdb->flush();
$offset += $limit;
} while ( count( $posts ) > 0 );
$response = atcontent_api_readership( site_url(), json_encode( $posts_id ), $ac_api_key );
// response output
header( "Content-Type: application/json" );
echo json_encode( $response );
}
// IMPORTANT: don't forget to "exit"
exit;
}
function atcontent_ajax_gate() {
$command = $_POST["command"];
switch ( $command ) {
case "repost":
$userid = $_POST["userid"];
$ac_api_key = get_user_meta( $userid, "ac_api_key", true );
$ac_pen_name = get_user_meta( $userid, "ac_pen_name", true );
if ( strlen( $ac_pen_name ) == 0 ) $ac_pen_name = "AtContent";
$ac_postid = $_POST["postid"];
if ( strlen( $ac_api_key ) > 0 && ($ac_api_key == $_POST["key"]) ) {
$repost_title = $_POST["title"];
$ac_content = "";
//$ac_content = "[atcontent id=\"{$ac_postid}\"]";
kses_remove_filters();
$new_post = array(
'post_title' => $repost_title,
'post_content' => $ac_content,
'post_status' => 'publish',
'post_author' => $userid,
'post_category' => array()
);
$new_post_id = wp_insert_post( $new_post );
update_post_meta( $new_post_id, "ac_is_process", "0" );
kses_init_filters();
$original_uri = get_permalink ( $new_post_id );
echo json_encode( array ( "IsOK" => true, "Url" => $original_uri ) );
}
break;
case "getpost":
$userid = $_POST["userid"];
$ac_api_key = get_user_meta( $userid, "ac_api_key", true );
$postid = $_POST["postid"];
if ( strlen( $ac_api_key ) > 0 && ( $ac_api_key == $_POST["key"] ) ) {
$post = get_post( $postid );
if ($post == null) exit;
$ac_user_copyprotect = get_user_meta( $userid, "ac_copyprotect", true );
if ( strlen( $ac_user_copyprotect ) == 0 ) $ac_user_copyprotect = "1";
$ac_is_copyprotect = get_post_meta( $post->ID, "ac_is_copyprotect", true );
if ( strlen( $ac_is_copyprotect ) == 0 ) {
$ac_is_copyprotect = $ac_user_copyprotect;
update_post_meta($post_id, "ac_is_copyprotect", $ac_is_copyprotect);
}
$ac_is_advanced_tracking = get_post_meta( $post->ID, "ac_is_advanced_tracking", true );
if ( strlen( $ac_is_advanced_tracking ) == 0 ) {
$ac_is_advanced_tracking = "1";
update_post_meta( $post_id, "ac_is_advanced_tracking", $ac_is_advanced_tracking );
}
$ac_postid = get_post_meta( $post->ID, "ac_postid", true );
atcontent_coexistense_fixes();
$post_title = $post->post_title;
$post_content = apply_filters( "the_content", $post->post_content );
$comments_json = "";
$comments = get_comments( array(
'post_id' => $post->ID,
'order' => 'ASC',
'orderby' => 'comment_date_gmt',
'status' => 'approve',
) );
if ( !empty( $comments ) ) {
$comments_json .= json_encode( $comments );
}
$tags_json = json_encode( wp_get_post_tags( $post->ID, array( 'fields' => 'slugs' ) ) );
$cats_json = json_encode( wp_get_post_categories( $post->ID, array( 'fields' => 'slugs' ) ) );
$post_published = get_gmt_from_date( $post->post_date );
$post_original_url = get_permalink( $post->ID );
$repost_post_id = '';
$embedid = '';
if ( preg_match_all( '/" .
"";
// Create post object
$new_post = array(
'post_title' => $title,
'post_content' => $ac_content,
'post_status' => 'publish',
'post_author' => $userid,
'post_date' => get_date_from_gmt( date( "Y-m-d H:i:s", $ac_published ) ),
'post_category' => array()
);
kses_remove_filters();
// Insert the post into the database
remove_all_actions( 'publish_post' );
$new_post_id = wp_insert_post( $new_post );
update_post_meta( $new_post_id, "ac_is_process", "0" );
update_post_meta( $new_post_id, "ac_embedid", $embedid );
update_post_meta( $new_post_id, "ac_repost_postid", $ac_postid );
kses_init_filters();
echo json_encode ( array ( "IsOK" => true, "PostId" => $new_post_id ) );
}
break;
case "updatepost":
$userid = $_POST["userid"];
$ac_api_key = get_user_meta( $userid, "ac_api_key", true );
$postid = $_POST["blogpostid"];
$embedid = $_POST["embedid"];
$ac_published = $_POST["published"];
$ac_postid = $_POST["postid"];
if ( strlen( $ac_api_key ) > 0 && ( $ac_api_key == $_POST["key"] ) ) {
$repost_post_id = get_post_meta( intval( $postid ), "ac_repost_postid", true );
if ( strlen( $repost_post_id ) == 0 )
{
update_post_meta( intval( $postid ), "ac_postid", $ac_postid );
update_post_meta( intval( $postid ), "ac_is_process", "1" );
}
else
{
update_post_meta( intval( $postid ), "ac_postid", '' );
}
update_post_meta( intval( $postid ), "ac_embedid", $embedid );
$post = get_post( $postid );
$post_content = $post -> post_content;
$repost_post_id = get_post_meta( intval( $postid ), "ac_repost_postid", true );
if ( strlen( $repost_post_id ) > 0 )
{
remove_filter( 'the_content', 'atcontent_the_content', 1 );
remove_filter( 'the_content', 'atcontent_the_content_after', 100 );
remove_filter( 'the_excerpt', 'atcontent_the_content_after', 100 );
remove_filter( 'the_excerpt', 'atcontent_the_excerpt', 1 );
$ac_pen_name = get_user_meta( intval( $userid ), "ac_pen_name", true );
$embedid = '-/' . $embedid . '/';
if ( preg_match_all( '/