Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // this is the file import_ajax.php that plugin to auto fire action. // he too have problem with name images.
- // yes my friend, thebrand is just a mask about orginal brand. I used find and replace to change this in all document, irrelevant :-)
- // hercules: I'm trying to work with this objects: $title $image $thumb_url $thumbid
- $totalvideo = $_POST['totalvideo'];
- if ($totalvideo<>0){
- $player_width = get_option('thebrand_player_width');
- $player_height = get_option('thebrand_player_height');
- $custom_link = get_option('thebrand_import_customfield_link');
- $custom_guid = get_option('thebrand_import_customfield_guid');
- $custom_duration = get_option('thebrand_import_customfield_duration');
- $custom_rate = get_option('thebrand_import_customfield_rate');
- $custom_thumb = get_option('thebrand_import_customfield_thumb');
- $custom_embed_code = get_option('thebrand_import_customfield_embed_code');
- $get_thumb = get_option('get_thumb');
- $get_jwplayer = get_option('get_jwplayer');
- $title_template = get_option('thebrand_import_title_template');
- $content_template = get_option('thebrand_import_content_template');
- $get_videojs = get_option('get_videojs');
- $rating = $_POST['rating'];
- $duration_value = $_POST['duration_value'];
- $publish_after = $_POST['publish_after'];
- $publish_between = $_POST['publish_between'];
- if($publish_after==0)
- {
- $start_post_time=current_time('timestamp');
- $post_status='publish';
- }
- else {
- $start_post_time=current_time('timestamp')+ $publish_after;
- $post_status='future';
- }
- if($publish_after=="draft")
- {
- $start_post_time=current_time('timestamp');
- $post_status='draft';
- }
- $post_time=$start_post_time;
- $n=0;
- for ($i=1;$i<=$totalvideo;$i++)
- {
- if (($_POST['checkbox_'.$i])=='checked') {$chon = 1;} else{ $chon=0;}
- if($chon){
- $n++;
- $title = $_POST['title_'.$i];
- $description = $_POST['excerpt_'.$i];
- $link = urldecode($_POST['secondurl_'.$i]);
- $guid = urldecode($_POST['videoid_'.$i]);
- $image = urldecode($_POST['thumb_'.$i]);
- $excerpt = $_POST['excerpt_'.$i];
- $duration = urldecode($_POST['duration_'.$i]);
- if($get_jwplayer==1) {
- $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>';
- } else {
- $embed_code = '<iframe src="http://flashservice.thebrand.com/embedframe/'.$guid.'" frameborder=0 width='.$player_width.' height='.$player_height.' scrolling=no></iframe>';
- }
- $tags = $_POST['tags_'.$i];
- $category = urldecode($_POST['cat_'.$i]);
- $rate = urldecode($_POST['rate_'.$i]);
- //kiem tra video trung
- $args = array('meta_query' => array(array('key' => 'guid','value' => $guid)));
- $videoidQuery = new WP_Query( $args );
- if ($videoidQuery->have_posts()){
- echo "<div id=\"message\" class=\"updated fade\" style='color:red;'><p>$n. $title - Video existed!</p></div>\n";
- } else {
- $post_title = str_replace("{title}", $title, $title_template);
- $post_title = str_replace("{duration}", $duration, $post_title);
- $post_content = str_replace("{title}", $title, $content_template);
- $post_content = str_replace("{duration}", $duration, $post_content);
- $post_content = str_replace("{link}", $link, $post_content);
- $post_content = str_replace("{excerpt}", $excerpt, $post_content);
- $post_content = str_replace("{thumb}", $image, $post_content);
- $post_content = str_replace("{rating}", $rate, $post_content);
- $post_content = str_replace("{embed_code}", $embed_code, $post_content);
- // Create post object
- $new_post = array(
- 'ID' => '',
- 'post_title' => $post_title,
- 'post_content' => $post_content,
- 'post_excerpt' => $excerpt,
- 'post_status' => $post_status,
- 'tags_input' => $tags ,
- 'post_date' => date('Y-m-d H:i:s',$post_time),
- 'post_category' => array( 'category' => $category )
- );
- $post_id = wp_insert_post($new_post);
- if ($get_thumb==1){
- $thumb_url = $image;
- require_once(ABSPATH . 'wp-admin/includes/file.php');
- require_once(ABSPATH . 'wp-admin/includes/media.php');
- set_time_limit(300);
- if ( ! empty($thumb_url) ) {
- // Download file to temp location
- $tmp = download_url( $thumb_url );
- // hercules , here it seems more like a mess
- // Set variables for storage
- // fix file filename for query strings
- preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
- $file_array['name'] = basename($matches[0]);
- $file_array['tmp_name'] = $tmp;
- // If error storing temporarily, unlink
- if ( is_wp_error( $tmp ) ) {
- @unlink($file_array['tmp_name']);
- $file_array['tmp_name'] = '';
- }
- // do the validation and storage stuff
- $thumbid = media_handle_sideload( $file_array, $post_id, $desc );
- // If error storing permanently, unlink
- if ( is_wp_error($thumbid) ) {
- @unlink($file_array['tmp_name']);
- return $thumbid;
- }
- }
- // hercules - set tha iamgem how featured image
- set_post_thumbnail( $post_id, $thumbid );
- } else {
- add_post_meta($post_id, $custom_thumb, $image, true);
- }
- add_post_meta($post_id, $custom_link, $link, true);
- add_post_meta($post_id, $custom_guid, $guid, true);
- add_post_meta($post_id, $custom_duration, $duration, true);
- add_post_meta($post_id, $custom_rate, $rate, true);
- add_post_meta($post_id, $custom_embed_code, $embed_code, true);
- echo "<div id=\"message\" class=\"updated fade\"><p>$n. $title - Added Successful!</p></div>\n";
- $post_time= $post_time+$publish_between;
- }
- }
- }
- $nextpageurl=trim($_POST['nextpageurl']);
- if ($nextpageurl!=""){
- $nonce = wp_create_nonce( 'thebrand_ajax' );
- ?>
- <script type='text/javascript'>
- // When the document loads do everything inside here ...
- jQuery(document).ready(function(){
- jQuery('#importnextpage').click(function() { //start function when Random button is clicked
- jQuery.ajax({
- 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; ?>' },
- beforeSend: function() {jQuery("#loading").fadeIn('fast');jQuery("#formstatus").fadeOut("fast");}, //fadeIn loading just when link is clicked
- success: function(html){ //so, if data is retrieved, store it in html
- jQuery("#loading").fadeOut('slow');
- jQuery("#formstatus").html( html ); //show the html inside formstatus div
- jQuery("#formstatus").fadeIn("fast"); //animation
- }
- }); //close jQuery.ajax
- return false;
- })
- })
- -->
- </script>
- <input name="nexturl" type="hidden" value="<?php echo $nextpageurl; ?>" id="nexturl">
- <input name="rating" type="hidden" value="<?php echo $rating; ?>" id="duration_value">
- <input name="duration_value" type="hidden" value="<?php echo $duration_value; ?>" id="duration_value">
- <input type="submit" value="Import next page" class="button-primary" id="importnextpage" />
- <?php
- }
- }
- else{ echo "<div id=\"message\" class=\"updated fade\"><p>No data received!</p></div>\n";}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement