Advertisement
herculesnetwork

See the part of the import plugin that creates the post

Apr 25th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. <?php
  2. // this is the file import_ajax.php that plugin to auto fire action. // he too have problem with name images.
  3. // yes my friend, thebrand is just a mask about orginal brand. I used find and replace to change this in all document, irrelevant :-)
  4.  
  5. // hercules: I'm trying to work with this objects: $title $image $thumb_url $thumbid
  6.  
  7. $totalvideo = $_POST['totalvideo'];
  8. if ($totalvideo<>0){
  9. $player_width = get_option('thebrand_player_width');
  10. $player_height = get_option('thebrand_player_height');
  11. $custom_link = get_option('thebrand_import_customfield_link');
  12. $custom_guid = get_option('thebrand_import_customfield_guid');
  13. $custom_duration = get_option('thebrand_import_customfield_duration');
  14. $custom_rate = get_option('thebrand_import_customfield_rate');
  15. $custom_thumb = get_option('thebrand_import_customfield_thumb');
  16. $custom_embed_code = get_option('thebrand_import_customfield_embed_code');
  17. $get_thumb = get_option('get_thumb');
  18. $get_jwplayer = get_option('get_jwplayer');
  19. $title_template = get_option('thebrand_import_title_template');
  20. $content_template = get_option('thebrand_import_content_template');
  21. $get_videojs = get_option('get_videojs');
  22. $rating = $_POST['rating'];
  23. $duration_value = $_POST['duration_value'];
  24.  
  25. $publish_after = $_POST['publish_after'];
  26. $publish_between = $_POST['publish_between'];
  27.  
  28. if($publish_after==0)
  29. {
  30. $start_post_time=current_time('timestamp');
  31. $post_status='publish';
  32. }
  33. else {
  34. $start_post_time=current_time('timestamp')+ $publish_after;
  35. $post_status='future';
  36. }
  37. if($publish_after=="draft")
  38. {
  39. $start_post_time=current_time('timestamp');
  40. $post_status='draft';
  41. }
  42. $post_time=$start_post_time;
  43. $n=0;
  44. for ($i=1;$i<=$totalvideo;$i++)
  45. {
  46. if (($_POST['checkbox_'.$i])=='checked') {$chon = 1;} else{ $chon=0;}
  47. if($chon){
  48. $n++;
  49. $title = $_POST['title_'.$i];
  50.  
  51. $description = $_POST['excerpt_'.$i];
  52.  
  53. $link = urldecode($_POST['secondurl_'.$i]);
  54.  
  55. $guid = urldecode($_POST['videoid_'.$i]);
  56.  
  57. $image = urldecode($_POST['thumb_'.$i]);
  58.  
  59. $excerpt = $_POST['excerpt_'.$i];
  60.  
  61. $duration = urldecode($_POST['duration_'.$i]);
  62. if($get_jwplayer==1) {
  63. $embed_code = '<iframe src="'.plugin_dir_url( __FILE__ ).'jwplayer/?url='.$link.'" frameborder=0 width='.$player_width.' height='.$player_height.' scrolling=no allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';
  64. } else {
  65. $embed_code = '<iframe src="http://flashservice.thebrand.com/embedframe/'.$guid.'" frameborder=0 width='.$player_width.' height='.$player_height.' scrolling=no></iframe>';
  66. }
  67. $tags = $_POST['tags_'.$i];
  68.  
  69. $category = urldecode($_POST['cat_'.$i]);
  70.  
  71. $rate = urldecode($_POST['rate_'.$i]);
  72.  
  73.  
  74. //kiem tra video trung
  75. $args = array('meta_query' => array(array('key' => 'guid','value' => $guid)));
  76. $videoidQuery = new WP_Query( $args );
  77. if ($videoidQuery->have_posts()){
  78. echo "<div id=\"message\" class=\"updated fade\" style='color:red;'><p>$n. $title - Video existed!</p></div>\n";
  79. } else {
  80.  
  81. $post_title = str_replace("{title}", $title, $title_template);
  82. $post_title = str_replace("{duration}", $duration, $post_title);
  83. $post_content = str_replace("{title}", $title, $content_template);
  84. $post_content = str_replace("{duration}", $duration, $post_content);
  85. $post_content = str_replace("{link}", $link, $post_content);
  86. $post_content = str_replace("{excerpt}", $excerpt, $post_content);
  87. $post_content = str_replace("{thumb}", $image, $post_content);
  88. $post_content = str_replace("{rating}", $rate, $post_content);
  89. $post_content = str_replace("{embed_code}", $embed_code, $post_content);
  90.  
  91. // Create post object
  92. $new_post = array(
  93. 'ID' => '',
  94. 'post_title' => $post_title,
  95. 'post_content' => $post_content,
  96. 'post_excerpt' => $excerpt,
  97. 'post_status' => $post_status,
  98. 'tags_input' => $tags ,
  99. 'post_date' => date('Y-m-d H:i:s',$post_time),
  100. 'post_category' => array( 'category' => $category )
  101. );
  102. $post_id = wp_insert_post($new_post);
  103.  
  104. if ($get_thumb==1){
  105.  
  106. $thumb_url = $image;
  107.  
  108. require_once(ABSPATH . 'wp-admin/includes/file.php');
  109. require_once(ABSPATH . 'wp-admin/includes/media.php');
  110. set_time_limit(300);
  111.  
  112. if ( ! empty($thumb_url) ) {
  113. // Download file to temp location
  114. $tmp = download_url( $thumb_url );
  115.  
  116. // hercules , here it seems more like a mess
  117. // Set variables for storage
  118. // fix file filename for query strings
  119. preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
  120. $file_array['name'] = basename($matches[0]);
  121. $file_array['tmp_name'] = $tmp;
  122.  
  123. // If error storing temporarily, unlink
  124. if ( is_wp_error( $tmp ) ) {
  125. @unlink($file_array['tmp_name']);
  126. $file_array['tmp_name'] = '';
  127. }
  128.  
  129. // do the validation and storage stuff
  130. $thumbid = media_handle_sideload( $file_array, $post_id, $desc );
  131. // If error storing permanently, unlink
  132. if ( is_wp_error($thumbid) ) {
  133. @unlink($file_array['tmp_name']);
  134. return $thumbid;
  135. }
  136. }
  137. // hercules - set tha iamgem how featured image
  138. set_post_thumbnail( $post_id, $thumbid );
  139. } else {
  140. add_post_meta($post_id, $custom_thumb, $image, true);
  141. }
  142.  
  143. add_post_meta($post_id, $custom_link, $link, true);
  144. add_post_meta($post_id, $custom_guid, $guid, true);
  145. add_post_meta($post_id, $custom_duration, $duration, true);
  146. add_post_meta($post_id, $custom_rate, $rate, true);
  147. add_post_meta($post_id, $custom_embed_code, $embed_code, true);
  148. echo "<div id=\"message\" class=\"updated fade\"><p>$n. $title - Added Successful!</p></div>\n";
  149. $post_time= $post_time+$publish_between;
  150. }
  151. }
  152. }
  153. $nextpageurl=trim($_POST['nextpageurl']);
  154. if ($nextpageurl!=""){
  155. $nonce = wp_create_nonce( 'thebrand_ajax' );
  156. ?>
  157. <script type='text/javascript'>
  158.  
  159. // When the document loads do everything inside here ...
  160. jQuery(document).ready(function(){
  161. jQuery('#importnextpage').click(function() { //start function when Random button is clicked
  162. jQuery.ajax({
  163. type: "post",url: "admin-ajax.php",data: { action: 'thebrand_load_page', url: jQuery( '#nexturl' ).val() ,cat: escape( jQuery( '#cat1' ).val() ),rating: escape( jQuery( '#rating' ).val() ),duration_value: escape( jQuery( '#duration_value' ).val() ), _ajax_nonce: '<?php echo $nonce; ?>' },
  164. beforeSend: function() {jQuery("#loading").fadeIn('fast');jQuery("#formstatus").fadeOut("fast");}, //fadeIn loading just when link is clicked
  165. success: function(html){ //so, if data is retrieved, store it in html
  166. jQuery("#loading").fadeOut('slow');
  167. jQuery("#formstatus").html( html ); //show the html inside formstatus div
  168. jQuery("#formstatus").fadeIn("fast"); //animation
  169. }
  170. }); //close jQuery.ajax
  171. return false;
  172. })
  173. })
  174.  
  175. -->
  176. </script>
  177. <input name="nexturl" type="hidden" value="<?php echo $nextpageurl; ?>" id="nexturl">
  178. <input name="rating" type="hidden" value="<?php echo $rating; ?>" id="duration_value">
  179. <input name="duration_value" type="hidden" value="<?php echo $duration_value; ?>" id="duration_value">
  180. <input type="submit" value="Import next page" class="button-primary" id="importnextpage" />
  181. <?php
  182. }
  183. }
  184. else{ echo "<div id=\"message\" class=\"updated fade\"><p>No data received!</p></div>\n";}
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement