Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ajax-autoimport-feed-item.php(50% WORKING, of 2 Vars, only 1 entries in post_title!):
- // search for 'Hercules'
- <?php
- function RRUN_import_feed_item( $feed_params = null ){
- $auto_update = false;
- if( isset($feed_params) && $feed_params != null ){
- //static process
- $_POST = $feed_params;
- if( isset($_POST['video_infos']) ){
- $feed_item = json_decode( json_encode( (array)$_POST['video_infos'] ) );
- }
- $auto_update = true;
- }else{
- //ajax process
- $nonce = $_POST['nonce'];
- if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
- die ( 'Busted!');
- if( isset($_POST['video_infos']) ){
- $feed_item = json_decode( stripslashes( '[' . $_POST['video_infos'] . ']' ) );
- $feed_item = $feed_item[0];
- }
- }
- if( $feed_item ){
- global $wpdb;
- global $post;
- if( $_POST['method'] != 'update' && $_POST['kw'] == 1 ){
- $_POST['cat_s'] = 'kw::' . sanitize_title( str_replace( array(' ', ',', '+', '.', ';','%20'), '-', $_POST['cat_s'] ) );
- }
- $feed = $_POST['cat_wp'] . '__' . $_POST['source'] . '__' . $_POST['cat_s'];
- if ( get_option( RRUN_LANG . '_import_title' ) == 'no' ) {
- $feed_item->title = 'Untitled';
- }
- if ( get_option( RRUN_LANG . '_import_description' ) == 'no' ) {
- $feed_item->desc = '';
- }
- $cpt = get_option( RRUN_LANG . '_cpt_name' );
- if ( $cpt == '' ) {
- $cpt = 'post';
- }
- /* hercules It's very strange, my action is simple, and because only one variable is added! In the other document, which is responsible for manual import, is the same code and the two are addicted! */
- // MY ACTION:
- // $feed_item->desc .= "{$feed_item->title}{$feed_item->embed}<br>{$feed_item->desc}";
- $feed_item->desc .= "{$feed_item->title}{$feed_item->embed}<br>{$feed_item->desc}";
- $post = array(
- 'post_author' => '1',
- 'post_status' => $_POST['status'],
- 'post_type' => $cpt,
- 'post_title' => (string) $feed_item->title,
- 'post_content' => (string) $feed_item->desc
- );
- $post_id = wp_insert_post( $post );
- update_post_meta($post_id, 'sponsor', (string)$_POST['source']);
- update_post_meta($post_id, 'videoID', (string)$feed_item->id);
- /** Default Thumb **/
- if (get_option( RRUN_LANG . '_custom_field_thumb' ) == false){
- update_post_meta($post_id, 'RRUN_thumb', (string)$feed_item->thumb_url);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_thumb' ) ), (string)$feed_item->thumb_url);
- }
- update_post_meta($post_id, 'url_thumb', (string)$feed_item->thumb_url);
- /** Multi Thumb **/
- if( (string)$feed_item->thumbs_urls != '' ){
- $thumbs = explode( ',', (string)$feed_item->thumbs_urls );
- foreach ($thumbs as $thumb) {
- add_post_meta($post_id, 'RRUN_thumbs', $thumb, false);
- }
- }
- /** Video length **/
- if (get_option( RRUN_LANG . '_custom_field_duration' ) == false){
- update_post_meta($post_id, 'RRUN_duration', (string)$feed_item->length);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_duration' ) ), (string)$feed_item->length);
- }
- update_post_meta($post_id, 'complete', (string)$feed_item->length);
- /** Embed player **/
- if (get_option( RRUN_LANG . '_custom_field_embed' ) == false){
- update_post_meta($post_id, 'RRUN_embed', (string)$feed_item->embed);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_embed' ) ), (string)$feed_item->embed);
- }
- update_post_meta($post_id, 'code', (string)$feed_item->embed);
- /** URL video **/
- if (get_option( RRUN_LANG . '_custom_field_video_url' ) == false){
- update_post_meta($post_id, 'RRUN_video_url', (string)$feed_item->video_url);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_video_url' ) ), (string)$feed_item->video_url);
- }
- update_post_meta($post_id, 'url_video', (string)$feed_item->video_url);
- /** Tracking URL **/
- if (get_option( RRUN_LANG . '_custom_field_sponsored_link' ) == false){
- update_post_meta($post_id, 'RRUN_sponsored_link', (string)$feed_item->join_url);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_sponsored_link' ) ), (string)$feed_item->join_url);
- }
- update_post_meta($post_id, 'url_player', (string)$feed_item->join_url);
- add_post_meta($post_id, 'cat_s', (string)$_POST['cat_s']);
- add_post_meta($post_id, 'flux', (string)$feed);
- //taxonomy
- $tax = get_option( RRUN_LANG . '_cpt_category' );
- if ( $tax == '' ) {
- $tax = 'category';
- }
- wp_set_post_terms( $post_id, $_POST['cat_wp'], rrun()->call_by_ref($tax), false);
- $cpt_tag = get_option( RRUN_LANG . '_cpt_tag' );
- if ( $cpt_tag == '' ) {
- $cpt_tag = 'post_tag';
- }
- //Import tags
- if( get_option( RRUN_LANG . '_import_tags' ) == 'yes' ) {
- wp_set_post_terms( $post_id, str_replace(';', ',', $feed_item->tags), $cpt_tag, false);
- }
- //VR
- if(in_array('vr', (array)explode(',', strtolower(str_replace(';', ',', $feed_item->tags))))){
- update_post_meta($post_id, 'RRUN_vr_video', 'yes');
- }else{
- update_post_meta($post_id, 'RRUN_vr_video', 'no');
- }
- if( get_option( RRUN_LANG . '_import_pornstars' ) == 'yes' ) {
- wp_set_post_terms( $post_id, str_replace(';', ',', $feed_item->pornstars), 'pornstars', false);
- }
- //post format video
- set_post_format( $post_id , 'video');
- //grabbing image
- if ( get_option( RRUN_LANG . '_import_thumb' ) == 'yes' ) {
- $defaultThumb = (string)$feed_item->thumb_url;
- if( ((string)$feed_item->thumbs_urls != '') && (get_option( RRUN_LANG . '_import_thumbs' ) == 'yes') ){
- //Multithumb
- $allThumbs = explode( ',', (string)$feed_item->thumbs_urls );
- $cpt_thumb = 1;
- // magic sideload image returns an HTML image, not an ID
- foreach ($allThumbs as $thumb) {
- if( strpos($thumb, 'http') === false ){
- $thumb = 'http:' . $thumb;
- }
- $medias[$cpt_thumb] = rrun()->media_sideload_image($thumb, $post_id, $feed_item->title, $_POST['source'], $cpt_thumb);
- $cpt_thumb++;
- }
- // therefore we must find it so we can set it as featured ID
- if(!is_array($media) && !is_wp_error($media)){
- $args = array(
- 'post_type' => 'attachment',
- 'posts_per_page' => -1,
- 'post_status' => 'any',
- 'post_parent' => $post_id
- );
- // reference new image to set as featured
- $attachments = get_posts($args);
- if(isset($attachments) && is_array($attachments)){
- foreach($attachments as $attachment){
- set_post_thumbnail($post_id, $attachment->ID);
- //set the first thumb as featured image
- break;
- }
- }
- }
- }else{
- //Only one thumb
- $cpt_thumb = 1;
- if( strpos($defaultThumb, 'http') === false ){
- $defaultThumb = 'http:' . $defaultThumb;
- }
- // magic sideload image returns an HTML image, not an ID
- $media = rrun()->media_sideload_image($defaultThumb, $post_id, null, $_POST['source'], $cpt_thumb);
- // therefore we must find it so we can set it as featured ID
- if(!empty($media) && !is_wp_error($media)){
- $args = array(
- 'post_type' => 'attachment',
- 'posts_per_page' => -1,
- 'post_status' => 'any',
- 'post_parent' => $post_id
- );
- // reference new image to set as featured
- $attachments = get_posts($args);
- if(isset($attachments) && is_array($attachments)){
- foreach($attachments as $attachment){
- // grab source of full size images (so no 300x150 nonsense in path)
- $defaultThumb = wp_get_attachment_image_src($attachment->ID, 'full');
- // determine if in the $media image we created, the string of the URL exists
- if(strpos($media, $defaultThumb[0]) !== false){
- // if so, we found our image. set it as thumbnail
- set_post_thumbnail($post_id, $attachment->ID);
- // only want one image
- break;
- }
- }
- }
- }
- }
- }
- if( $auto_update === true ){
- return true;
- }else{
- echo 1;
- }
- }else{
- if( $auto_update === true ){
- return false;
- }else{
- echo 0;
- }
- }
- die();
- }
- add_action('wp_ajax_RRUN_import_feed_item', 'RRUN_import_feed_item');
- // END FILE 1
- //====================================== The OTHER FILE ==================================================================
- // BEGIN, THE OTHER FILE.
- //ajax-manualimport-feed-item.php(100% WORKING):
- <?php
- function RRUN_import_video(){
- $nonce = $_POST['nonce'];
- if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
- wp_die ( 'Busted!');
- $video = $_POST['video_infos'];
- if( $_POST['kw'] == 1 ){
- $_POST['cat_s'] = 'kw::' . sanitize_title( str_replace( array(' ', ',', '+', '.', ';','%20'), '-', $_POST['cat_s'] ) );
- }
- $status = isset( $_POST['status'] ) && $_POST['status'] != '' ? $_POST['status'] : get_option( RRUN_LANG . '_video_status' );
- $feed = $_POST['cat_wp'] . '__' . $_POST['partner_id'] . '__' . $_POST['cat_s'];
- if ( get_option( RRUN_LANG . '_import_title' ) == 'no' ) {
- $video['title'] = 'Untitled';
- }
- if ( get_option( RRUN_LANG . '_import_description' ) == 'no' ) {
- $video['desc'] = '';
- }
- //custom post type
- $cpt = get_option( RRUN_LANG . '_cpt_name' );
- if ( $cpt == '' ) {
- $cpt = 'post';
- }
- /********** hercules // working 100% //Both variables are added: title and embed. *********/
- /********** hercules // working 100% //Both variables are added: title and embed. *********/
- /********** hercules // working 100% //Both variables are added: title and embed. *********/
- // My action: $video['desc'] .= "{$video['title']}{$video['embed']}<br>{$video['desc']}";
- $video['desc'] .= "{$video['title']}{$video['embed']}<br>{$video['desc']}";
- $post_args = array(
- 'post_author' => '1',
- 'post_status' => $status,
- 'post_type' => $cpt,
- 'post_title' => (string) $video['title'],
- 'post_content' => (string) $video['desc'],
- );
- $post_id = wp_insert_post( $post_args );
- if( $post_id ){
- update_post_meta($post_id, 'sponsor', (string)$_POST['partner_id']);
- update_post_meta($post_id, 'videoID', (string)$video['id']);
- /** Default Thumb **/
- if (get_option( RRUN_LANG . '_custom_field_thumb' ) == false){
- update_post_meta($post_id, 'RRUN_thumb', (string)$video['thumb_url']);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_thumb' ) ), (string)$video['thumb_url']);
- }
- update_post_meta($post_id, 'url_thumb', (string)$video['thumb_url']);
- /** Multi Thumb **/
- if( (string)$video['thumbs_urls'] != '' ){
- $thumbs = explode( ',', (string)$video['thumbs_urls'] );
- foreach ($thumbs as $thumb) {
- add_post_meta($post_id, 'RRUN_thumbs', $thumb, false);
- }
- }
- /** Video length **/
- if (get_option( RRUN_LANG . '_custom_field_duration' ) == false){
- update_post_meta($post_id, 'RRUN_duration', (string)$video['length']);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_duration' ) ), (string)$video['length']);
- }
- update_post_meta($post_id, 'complete', (string)$video['length']);
- /** Embed player **/
- if (get_option( RRUN_LANG . '_custom_field_embed' ) == false){
- update_post_meta($post_id, 'RRUN_embed', (string)$video['embed']);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_embed' ) ), (string)$video['embed']);
- }
- update_post_meta($post_id, 'code', (string)$video['embed']);
- /** URL video **/
- if (get_option( RRUN_LANG . '_custom_field_video_url' ) == false){
- update_post_meta($post_id, 'RRUN_video_url', (string)$video['video_url']);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_video_url' ) ), (string)$video['video_url']);
- }
- update_post_meta($post_id, 'url_video', (string)$video['video_url']);
- /** Sponsored Link **/
- if (get_option( RRUN_LANG . '_custom_field_sponsored_link' ) == false){
- update_post_meta($post_id, 'RRUN_sponsored_link', (string)$video['join_url']);
- }else{
- update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_sponsored_link' ) ), (string)$video['join_url']);
- }
- update_post_meta($post_id, 'url_player', (string)$video['join_url']);
- add_post_meta($post_id, 'cat_s', (string)$_POST['cat_s']);
- add_post_meta($post_id, 'flux', (string)$feed);
- //taxonomy
- $tax = get_option( RRUN_LANG . '_cpt_category' );
- if ( $tax == '' ) {
- $tax = 'category';
- }
- wp_set_post_terms( $post_id, $_POST['cat_wp'], rrun()->call_by_ref($tax), false);
- //tags
- $cpt_tag = get_option( RRUN_LANG . '_cpt_tag' );
- if ( $cpt_tag == '' ) {
- $cpt_tag = 'post_tag';
- }
- if( get_option( RRUN_LANG . '_import_tags' ) == 'yes' ) {
- wp_set_post_terms( $post_id, str_replace(';', ',', $video['tags']), rrun()->call_by_ref($cpt_tag), false);
- }
- //VR
- if(in_array('vr', (array)explode(',', strtolower(str_replace(';', ',', $video['tags']))))){
- update_post_meta($post_id, 'RRUN_vr_video', 'yes');
- }else{
- update_post_meta($post_id, 'RRUN_vr_video', 'no');
- }
- //pornstars
- if( get_option( RRUN_LANG . '_import_pornstars' ) == 'yes' ) {
- wp_set_post_terms( $post_id, str_replace(';', ',', (string)$video['pornstars']), 'pornstars', false);
- }
- //post format video
- set_post_format( $post_id , 'video');
- //grabbing image
- if ( get_option( RRUN_LANG . '_import_thumb' ) == 'yes' ) {
- $defaultThumb = (string)$video['thumb_url'];
- if( ((string)$video['thumbs_urls'] != '') && (get_option( RRUN_LANG . '_import_thumbs' ) == 'yes') ){
- //Multithumb
- $allThumbs = explode( ',', (string)$video['thumbs_urls'] );
- $cpt_thumb = 1;
- // magic sideload image returns an HTML image, not an ID
- foreach ($allThumbs as $thumb) {
- if( strpos($thumb, 'http') === false ){
- $thumb = 'http:' . $thumb;
- }
- $medias[$cpt_thumb] = rrun()->media_sideload_image($thumb, $post_id, (string)$video['title'], $_POST['partner_id'], $cpt_thumb);
- $cpt_thumb++;
- }
- // therefore we must find it so we can set it as featured ID
- if(!is_array($media) && !is_wp_error($media)){
- $args = array(
- 'post_type' => 'attachment',
- 'posts_per_page' => -1,
- 'post_status' => 'any',
- 'post_parent' => $post_id
- );
- // reference new image to set as featured
- $attachments = get_posts($args);
- if(isset($attachments) && is_array($attachments)){
- foreach($attachments as $attachment){
- set_post_thumbnail($post_id, $attachment->ID);
- //set the first thumb as featured image
- break;
- }
- }
- }
- }else{
- //Only one thumb
- $cpt_thumb = 1;
- if( strpos($defaultThumb, 'http') === false ){
- $defaultThumb = 'http:' . $defaultThumb;
- }
- // magic sideload image returns an HTML image, not an ID
- $media = rrun()->media_sideload_image($defaultThumb, $post_id, null, $_POST['partner_id'], $cpt_thumb);
- // therefore we must find it so we can set it as featured ID
- if(!empty($media) && !is_wp_error($media)){
- $args = array(
- 'post_type' => 'attachment',
- 'posts_per_page' => -1,
- 'post_status' => 'any',
- 'post_parent' => $post_id
- );
- // reference new image to set as featured
- $attachments = get_posts($args);
- if(isset($attachments) && is_array($attachments)){
- foreach($attachments as $attachment){
- // grab partner_id of full size images (so no 300x150 nonsense in path)
- $defaultThumb = wp_get_attachment_image_src($attachment->ID, 'full');
- // determine if in the $media image we created, the string of the URL exists
- if(strpos($media, $defaultThumb[0]) !== false){
- // if so, we found our image. set it as thumbnail
- set_post_thumbnail($post_id, $attachment->ID);
- // only want one image
- break;
- }
- }
- }
- }
- }
- }
- echo $video['id'];
- }else{
- echo -1;
- }
- die();
- }
- add_action('wp_ajax_RRUN_import_video', 'RRUN_import_video');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement