Advertisement
herculesnetwork

why this variable not send values?

Mar 31st, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.92 KB | None | 0 0
  1. //ajax-autoimport-feed-item.php(50% WORKING, of 2 Vars, only 1 entries in post_title!):
  2. // search for 'Hercules'
  3.  
  4. <?php
  5. function RRUN_import_feed_item( $feed_params = null ){
  6. $auto_update = false;
  7. if( isset($feed_params) && $feed_params != null ){
  8. //static process
  9. $_POST = $feed_params;
  10. if( isset($_POST['video_infos']) ){
  11. $feed_item = json_decode( json_encode( (array)$_POST['video_infos'] ) );
  12. }
  13. $auto_update = true;
  14. }else{
  15. //ajax process
  16. $nonce = $_POST['nonce'];
  17. if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
  18. die ( 'Busted!');
  19. if( isset($_POST['video_infos']) ){
  20. $feed_item = json_decode( stripslashes( '[' . $_POST['video_infos'] . ']' ) );
  21. $feed_item = $feed_item[0];
  22. }
  23. }
  24. if( $feed_item ){
  25. global $wpdb;
  26. global $post;
  27.  
  28.  
  29. if( $_POST['method'] != 'update' && $_POST['kw'] == 1 ){
  30. $_POST['cat_s'] = 'kw::' . sanitize_title( str_replace( array(' ', ',', '+', '.', ';','%20'), '-', $_POST['cat_s'] ) );
  31.  
  32. }
  33.  
  34. $feed = $_POST['cat_wp'] . '__' . $_POST['source'] . '__' . $_POST['cat_s'];
  35.  
  36. if ( get_option( RRUN_LANG . '_import_title' ) == 'no' ) {
  37. $feed_item->title = 'Untitled';
  38. }
  39. if ( get_option( RRUN_LANG . '_import_description' ) == 'no' ) {
  40. $feed_item->desc = '';
  41. }
  42. $cpt = get_option( RRUN_LANG . '_cpt_name' );
  43. if ( $cpt == '' ) {
  44. $cpt = 'post';
  45. }
  46.  
  47.  
  48.  
  49.  
  50. /* 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! */
  51. // MY ACTION:
  52. // $feed_item->desc .= "{$feed_item->title}{$feed_item->embed}<br>{$feed_item->desc}";
  53.  
  54. $feed_item->desc .= "{$feed_item->title}{$feed_item->embed}<br>{$feed_item->desc}";
  55. $post = array(
  56. 'post_author' => '1',
  57. 'post_status' => $_POST['status'],
  58. 'post_type' => $cpt,
  59. 'post_title' => (string) $feed_item->title,
  60. 'post_content' => (string) $feed_item->desc
  61. );
  62. $post_id = wp_insert_post( $post );
  63. update_post_meta($post_id, 'sponsor', (string)$_POST['source']);
  64. update_post_meta($post_id, 'videoID', (string)$feed_item->id);
  65.  
  66. /** Default Thumb **/
  67. if (get_option( RRUN_LANG . '_custom_field_thumb' ) == false){
  68. update_post_meta($post_id, 'RRUN_thumb', (string)$feed_item->thumb_url);
  69. }else{
  70. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_thumb' ) ), (string)$feed_item->thumb_url);
  71. }
  72. update_post_meta($post_id, 'url_thumb', (string)$feed_item->thumb_url);
  73.  
  74. /** Multi Thumb **/
  75. if( (string)$feed_item->thumbs_urls != '' ){
  76. $thumbs = explode( ',', (string)$feed_item->thumbs_urls );
  77. foreach ($thumbs as $thumb) {
  78. add_post_meta($post_id, 'RRUN_thumbs', $thumb, false);
  79. }
  80. }
  81.  
  82. /** Video length **/
  83. if (get_option( RRUN_LANG . '_custom_field_duration' ) == false){
  84. update_post_meta($post_id, 'RRUN_duration', (string)$feed_item->length);
  85. }else{
  86. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_duration' ) ), (string)$feed_item->length);
  87. }
  88. update_post_meta($post_id, 'complete', (string)$feed_item->length);
  89.  
  90. /** Embed player **/
  91. if (get_option( RRUN_LANG . '_custom_field_embed' ) == false){
  92. update_post_meta($post_id, 'RRUN_embed', (string)$feed_item->embed);
  93. }else{
  94. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_embed' ) ), (string)$feed_item->embed);
  95. }
  96. update_post_meta($post_id, 'code', (string)$feed_item->embed);
  97. /** URL video **/
  98. if (get_option( RRUN_LANG . '_custom_field_video_url' ) == false){
  99. update_post_meta($post_id, 'RRUN_video_url', (string)$feed_item->video_url);
  100. }else{
  101. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_video_url' ) ), (string)$feed_item->video_url);
  102. }
  103. update_post_meta($post_id, 'url_video', (string)$feed_item->video_url);
  104. /** Tracking URL **/
  105. if (get_option( RRUN_LANG . '_custom_field_sponsored_link' ) == false){
  106. update_post_meta($post_id, 'RRUN_sponsored_link', (string)$feed_item->join_url);
  107. }else{
  108. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_sponsored_link' ) ), (string)$feed_item->join_url);
  109. }
  110. update_post_meta($post_id, 'url_player', (string)$feed_item->join_url);
  111. add_post_meta($post_id, 'cat_s', (string)$_POST['cat_s']);
  112. add_post_meta($post_id, 'flux', (string)$feed);
  113.  
  114. //taxonomy
  115. $tax = get_option( RRUN_LANG . '_cpt_category' );
  116. if ( $tax == '' ) {
  117. $tax = 'category';
  118. }
  119. wp_set_post_terms( $post_id, $_POST['cat_wp'], rrun()->call_by_ref($tax), false);
  120.  
  121. $cpt_tag = get_option( RRUN_LANG . '_cpt_tag' );
  122. if ( $cpt_tag == '' ) {
  123. $cpt_tag = 'post_tag';
  124. }
  125. //Import tags
  126. if( get_option( RRUN_LANG . '_import_tags' ) == 'yes' ) {
  127. wp_set_post_terms( $post_id, str_replace(';', ',', $feed_item->tags), $cpt_tag, false);
  128. }
  129.  
  130. //VR
  131. if(in_array('vr', (array)explode(',', strtolower(str_replace(';', ',', $feed_item->tags))))){
  132. update_post_meta($post_id, 'RRUN_vr_video', 'yes');
  133. }else{
  134. update_post_meta($post_id, 'RRUN_vr_video', 'no');
  135. }
  136.  
  137. if( get_option( RRUN_LANG . '_import_pornstars' ) == 'yes' ) {
  138. wp_set_post_terms( $post_id, str_replace(';', ',', $feed_item->pornstars), 'pornstars', false);
  139. }
  140.  
  141. //post format video
  142. set_post_format( $post_id , 'video');
  143.  
  144. //grabbing image
  145. if ( get_option( RRUN_LANG . '_import_thumb' ) == 'yes' ) {
  146.  
  147. $defaultThumb = (string)$feed_item->thumb_url;
  148.  
  149. if( ((string)$feed_item->thumbs_urls != '') && (get_option( RRUN_LANG . '_import_thumbs' ) == 'yes') ){
  150. //Multithumb
  151. $allThumbs = explode( ',', (string)$feed_item->thumbs_urls );
  152. $cpt_thumb = 1;
  153. // magic sideload image returns an HTML image, not an ID
  154. foreach ($allThumbs as $thumb) {
  155. if( strpos($thumb, 'http') === false ){
  156. $thumb = 'http:' . $thumb;
  157. }
  158. $medias[$cpt_thumb] = rrun()->media_sideload_image($thumb, $post_id, $feed_item->title, $_POST['source'], $cpt_thumb);
  159. $cpt_thumb++;
  160. }
  161.  
  162. // therefore we must find it so we can set it as featured ID
  163. if(!is_array($media) && !is_wp_error($media)){
  164. $args = array(
  165. 'post_type' => 'attachment',
  166. 'posts_per_page' => -1,
  167. 'post_status' => 'any',
  168. 'post_parent' => $post_id
  169. );
  170.  
  171. // reference new image to set as featured
  172. $attachments = get_posts($args);
  173. if(isset($attachments) && is_array($attachments)){
  174.  
  175. foreach($attachments as $attachment){
  176.  
  177. set_post_thumbnail($post_id, $attachment->ID);
  178. //set the first thumb as featured image
  179. break;
  180.  
  181. }
  182. }
  183. }
  184.  
  185. }else{
  186. //Only one thumb
  187. $cpt_thumb = 1;
  188.  
  189. if( strpos($defaultThumb, 'http') === false ){
  190. $defaultThumb = 'http:' . $defaultThumb;
  191. }
  192.  
  193. // magic sideload image returns an HTML image, not an ID
  194. $media = rrun()->media_sideload_image($defaultThumb, $post_id, null, $_POST['source'], $cpt_thumb);
  195.  
  196. // therefore we must find it so we can set it as featured ID
  197. if(!empty($media) && !is_wp_error($media)){
  198. $args = array(
  199. 'post_type' => 'attachment',
  200. 'posts_per_page' => -1,
  201. 'post_status' => 'any',
  202. 'post_parent' => $post_id
  203. );
  204.  
  205. // reference new image to set as featured
  206. $attachments = get_posts($args);
  207. if(isset($attachments) && is_array($attachments)){
  208. foreach($attachments as $attachment){
  209. // grab source of full size images (so no 300x150 nonsense in path)
  210. $defaultThumb = wp_get_attachment_image_src($attachment->ID, 'full');
  211. // determine if in the $media image we created, the string of the URL exists
  212. if(strpos($media, $defaultThumb[0]) !== false){
  213. // if so, we found our image. set it as thumbnail
  214. set_post_thumbnail($post_id, $attachment->ID);
  215. // only want one image
  216. break;
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. if( $auto_update === true ){
  224. return true;
  225. }else{
  226. echo 1;
  227. }
  228. }else{
  229. if( $auto_update === true ){
  230. return false;
  231. }else{
  232. echo 0;
  233. }
  234. }
  235. die();
  236. }
  237. add_action('wp_ajax_RRUN_import_feed_item', 'RRUN_import_feed_item');
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245. // END FILE 1
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. //====================================== The OTHER FILE ==================================================================
  257. // BEGIN, THE OTHER FILE.
  258.  
  259. //ajax-manualimport-feed-item.php(100% WORKING):
  260.  
  261.  
  262. <?php
  263.  
  264. function RRUN_import_video(){
  265.  
  266. $nonce = $_POST['nonce'];
  267. if ( ! wp_verify_nonce( $nonce, 'ajax-nonce' ) )
  268. wp_die ( 'Busted!');
  269.  
  270. $video = $_POST['video_infos'];
  271.  
  272. if( $_POST['kw'] == 1 ){
  273. $_POST['cat_s'] = 'kw::' . sanitize_title( str_replace( array(' ', ',', '+', '.', ';','%20'), '-', $_POST['cat_s'] ) );
  274. }
  275.  
  276. $status = isset( $_POST['status'] ) && $_POST['status'] != '' ? $_POST['status'] : get_option( RRUN_LANG . '_video_status' );
  277.  
  278.  
  279. $feed = $_POST['cat_wp'] . '__' . $_POST['partner_id'] . '__' . $_POST['cat_s'];
  280.  
  281. if ( get_option( RRUN_LANG . '_import_title' ) == 'no' ) {
  282. $video['title'] = 'Untitled';
  283. }
  284. if ( get_option( RRUN_LANG . '_import_description' ) == 'no' ) {
  285. $video['desc'] = '';
  286. }
  287.  
  288. //custom post type
  289. $cpt = get_option( RRUN_LANG . '_cpt_name' );
  290. if ( $cpt == '' ) {
  291. $cpt = 'post';
  292. }
  293.  
  294.  
  295.  
  296. /********** hercules // working 100% //Both variables are added: title and embed. *********/
  297. /********** hercules // working 100% //Both variables are added: title and embed. *********/
  298. /********** hercules // working 100% //Both variables are added: title and embed. *********/
  299. // My action: $video['desc'] .= "{$video['title']}{$video['embed']}<br>{$video['desc']}";
  300.  
  301. $video['desc'] .= "{$video['title']}{$video['embed']}<br>{$video['desc']}";
  302. $post_args = array(
  303. 'post_author' => '1',
  304. 'post_status' => $status,
  305. 'post_type' => $cpt,
  306. 'post_title' => (string) $video['title'],
  307. 'post_content' => (string) $video['desc'],
  308. );
  309.  
  310. $post_id = wp_insert_post( $post_args );
  311.  
  312. if( $post_id ){
  313.  
  314. update_post_meta($post_id, 'sponsor', (string)$_POST['partner_id']);
  315. update_post_meta($post_id, 'videoID', (string)$video['id']);
  316.  
  317. /** Default Thumb **/
  318. if (get_option( RRUN_LANG . '_custom_field_thumb' ) == false){
  319. update_post_meta($post_id, 'RRUN_thumb', (string)$video['thumb_url']);
  320. }else{
  321. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_thumb' ) ), (string)$video['thumb_url']);
  322. }
  323. update_post_meta($post_id, 'url_thumb', (string)$video['thumb_url']);
  324.  
  325. /** Multi Thumb **/
  326. if( (string)$video['thumbs_urls'] != '' ){
  327. $thumbs = explode( ',', (string)$video['thumbs_urls'] );
  328. foreach ($thumbs as $thumb) {
  329. add_post_meta($post_id, 'RRUN_thumbs', $thumb, false);
  330. }
  331. }
  332.  
  333. /** Video length **/
  334. if (get_option( RRUN_LANG . '_custom_field_duration' ) == false){
  335. update_post_meta($post_id, 'RRUN_duration', (string)$video['length']);
  336. }else{
  337. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_duration' ) ), (string)$video['length']);
  338. }
  339. update_post_meta($post_id, 'complete', (string)$video['length']);
  340.  
  341. /** Embed player **/
  342. if (get_option( RRUN_LANG . '_custom_field_embed' ) == false){
  343. update_post_meta($post_id, 'RRUN_embed', (string)$video['embed']);
  344. }else{
  345. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_embed' ) ), (string)$video['embed']);
  346. }
  347. update_post_meta($post_id, 'code', (string)$video['embed']);
  348.  
  349. /** URL video **/
  350. if (get_option( RRUN_LANG . '_custom_field_video_url' ) == false){
  351. update_post_meta($post_id, 'RRUN_video_url', (string)$video['video_url']);
  352. }else{
  353. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_video_url' ) ), (string)$video['video_url']);
  354. }
  355. update_post_meta($post_id, 'url_video', (string)$video['video_url']);
  356.  
  357. /** Sponsored Link **/
  358. if (get_option( RRUN_LANG . '_custom_field_sponsored_link' ) == false){
  359. update_post_meta($post_id, 'RRUN_sponsored_link', (string)$video['join_url']);
  360. }else{
  361. update_post_meta($post_id, str_replace(' ', '_', get_option( RRUN_LANG . '_custom_field_sponsored_link' ) ), (string)$video['join_url']);
  362. }
  363. update_post_meta($post_id, 'url_player', (string)$video['join_url']);
  364.  
  365. add_post_meta($post_id, 'cat_s', (string)$_POST['cat_s']);
  366. add_post_meta($post_id, 'flux', (string)$feed);
  367.  
  368. //taxonomy
  369. $tax = get_option( RRUN_LANG . '_cpt_category' );
  370. if ( $tax == '' ) {
  371. $tax = 'category';
  372. }
  373. wp_set_post_terms( $post_id, $_POST['cat_wp'], rrun()->call_by_ref($tax), false);
  374.  
  375. //tags
  376. $cpt_tag = get_option( RRUN_LANG . '_cpt_tag' );
  377. if ( $cpt_tag == '' ) {
  378. $cpt_tag = 'post_tag';
  379. }
  380.  
  381. if( get_option( RRUN_LANG . '_import_tags' ) == 'yes' ) {
  382. wp_set_post_terms( $post_id, str_replace(';', ',', $video['tags']), rrun()->call_by_ref($cpt_tag), false);
  383. }
  384.  
  385. //VR
  386. if(in_array('vr', (array)explode(',', strtolower(str_replace(';', ',', $video['tags']))))){
  387. update_post_meta($post_id, 'RRUN_vr_video', 'yes');
  388. }else{
  389. update_post_meta($post_id, 'RRUN_vr_video', 'no');
  390. }
  391.  
  392. //pornstars
  393. if( get_option( RRUN_LANG . '_import_pornstars' ) == 'yes' ) {
  394. wp_set_post_terms( $post_id, str_replace(';', ',', (string)$video['pornstars']), 'pornstars', false);
  395. }
  396.  
  397. //post format video
  398. set_post_format( $post_id , 'video');
  399.  
  400. //grabbing image
  401. if ( get_option( RRUN_LANG . '_import_thumb' ) == 'yes' ) {
  402.  
  403. $defaultThumb = (string)$video['thumb_url'];
  404.  
  405. if( ((string)$video['thumbs_urls'] != '') && (get_option( RRUN_LANG . '_import_thumbs' ) == 'yes') ){
  406. //Multithumb
  407. $allThumbs = explode( ',', (string)$video['thumbs_urls'] );
  408. $cpt_thumb = 1;
  409. // magic sideload image returns an HTML image, not an ID
  410. foreach ($allThumbs as $thumb) {
  411. if( strpos($thumb, 'http') === false ){
  412. $thumb = 'http:' . $thumb;
  413. }
  414. $medias[$cpt_thumb] = rrun()->media_sideload_image($thumb, $post_id, (string)$video['title'], $_POST['partner_id'], $cpt_thumb);
  415. $cpt_thumb++;
  416. }
  417.  
  418. // therefore we must find it so we can set it as featured ID
  419. if(!is_array($media) && !is_wp_error($media)){
  420. $args = array(
  421. 'post_type' => 'attachment',
  422. 'posts_per_page' => -1,
  423. 'post_status' => 'any',
  424. 'post_parent' => $post_id
  425. );
  426.  
  427. // reference new image to set as featured
  428. $attachments = get_posts($args);
  429. if(isset($attachments) && is_array($attachments)){
  430.  
  431. foreach($attachments as $attachment){
  432.  
  433. set_post_thumbnail($post_id, $attachment->ID);
  434. //set the first thumb as featured image
  435. break;
  436.  
  437. }
  438. }
  439. }
  440.  
  441. }else{
  442. //Only one thumb
  443. $cpt_thumb = 1;
  444.  
  445. if( strpos($defaultThumb, 'http') === false ){
  446. $defaultThumb = 'http:' . $defaultThumb;
  447. }
  448.  
  449. // magic sideload image returns an HTML image, not an ID
  450. $media = rrun()->media_sideload_image($defaultThumb, $post_id, null, $_POST['partner_id'], $cpt_thumb);
  451.  
  452. // therefore we must find it so we can set it as featured ID
  453. if(!empty($media) && !is_wp_error($media)){
  454. $args = array(
  455. 'post_type' => 'attachment',
  456. 'posts_per_page' => -1,
  457. 'post_status' => 'any',
  458. 'post_parent' => $post_id
  459. );
  460.  
  461. // reference new image to set as featured
  462. $attachments = get_posts($args);
  463. if(isset($attachments) && is_array($attachments)){
  464. foreach($attachments as $attachment){
  465. // grab partner_id of full size images (so no 300x150 nonsense in path)
  466. $defaultThumb = wp_get_attachment_image_src($attachment->ID, 'full');
  467. // determine if in the $media image we created, the string of the URL exists
  468. if(strpos($media, $defaultThumb[0]) !== false){
  469. // if so, we found our image. set it as thumbnail
  470. set_post_thumbnail($post_id, $attachment->ID);
  471. // only want one image
  472. break;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479.  
  480. echo $video['id'];
  481. }else{
  482. echo -1;
  483. }
  484.  
  485. die();
  486. }
  487.  
  488. add_action('wp_ajax_RRUN_import_video', 'RRUN_import_video');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement