posts} WHERE post_title='$file_name'"; $count = $wpdb->get_var($query); if($count == 0){ if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC . '/class-http.php' ); $http = new WP_Http(); $response = $http->request( $url ); if( $response['response']['code'] != 200 ) { return false; } $upload = wp_upload_bits( basename($url), null, $response['body'] ); if( !empty( $upload['error'] ) ) { return false; } $file_path = $upload['file']; $file_name = basename( $file_path ); $file_type = wp_check_filetype( $file_name, null ); $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) ); $wp_upload_dir = wp_upload_dir(); $post_info = array( 'guid' => $wp_upload_dir['url'] . '/' . $file_name, 'post_mime_type' => $file_type['type'], 'post_title' => $attachment_title, 'post_content' => '', 'post_status' => 'inherit', ); // Create the attachment $attach_id = wp_insert_attachment( $post_info, $file_path, $post_id ); // Include image.php require_once( ABSPATH . 'wp-admin/includes/image.php' ); // Define attachment metadata $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path ); // Assign metadata to attachment wp_update_attachment_metadata( $attach_id, $attach_data ); return $attach_id; }else{ $query = "SELECT ID FROM {$wpdb->posts} WHERE post_title='$file_name'"; $poster_path = $wpdb->get_var($query); return $poster_path; } } } /*----------------------------------*/ # set ajax movie thumnail /*----------------------------------*/ function get_ajax_thumnail_movie(){ global $post; $thumb_id = ( isset( $_REQUEST['thumbnail_id'] ) && is_numeric( $_REQUEST['thumbnail_id'] ) ) ? $_REQUEST['thumbnail_id'] : ''; $post_id = ( isset( $_REQUEST['post_id'] ) && is_numeric( $_REQUEST['post_id'] ) ) ? $_REQUEST['post_id'] : ''; set_post_thumbnail($post_id, $thumb_id); $result = _wp_post_thumbnail_html($thumb_id, $post); echo $result; die(); } add_action( 'wp_ajax_filmchinsetthumb', 'get_ajax_thumnail_movie' ); /*----------------------------------*/ # get ajax movie terms /*----------------------------------*/ function get_ajax_terms_movie(){ $post_id = ( isset( $_REQUEST['post_id'] ) && is_numeric( $_REQUEST['post_id'] ) ) ? $_REQUEST['post_id'] : ''; $genre_terms = get_the_terms($post_id, 'genre'); $actor_terms = get_the_terms($post_id, 'actor'); $director_terms = get_the_terms($post_id, 'director'); $check_term = ''; if(empty($director_terms)){ $term_creators = get_the_terms($post_id, 'creator'); $check_term = 'creator'; }else{ $term_directors = get_the_terms($post_id, 'director'); $check_term = 'director'; } $country_terms = get_the_terms($post_id, 'country'); $release_terms = get_the_terms($post_id, 'release'); $writer_terms = get_the_terms($post_id, 'writer'); $publish = get_the_terms($post_id, 'publish'); // build option genre foreach($genre_terms as $genre_term){ $result['genre_option'][] = '
  • '; } // build option actor foreach($actor_terms as $actor_term){ $result['actor_option'][] = '
  • '; } // build option director if($check_term == 'director'){ foreach($director_terms as $director_term){ $result['director_option'][] = '
  • '; } }else{ foreach($term_creators as $term_creator){ $result['director_option'][] = '
  • '; } } // build option country foreach($country_terms as $country_term){ $result['country_option'][] = '
  • '; } // build option release foreach($release_terms as $release_term){ $result['release_option'][] = '
  • '; } // build option writer foreach($writer_terms as $writer_term){ $result['writer_option'][] = '
  • '; } foreach($publish as $publis){ $result['publish_option'][] = '
  • '; } //send options by json html wp_send_json($result); wp_die(); } add_action( 'wp_ajax_termsajaxset', 'get_ajax_terms_movie' ); /*----------------------------------*/ # get post meta value /*----------------------------------*/ function get_data_movie($str){ global $post; $post_id = $post->ID; $value = get_post_meta($post_id, $str, true); return $value; } /*----------------------------------*/ # get data movie from imdb /*----------------------------------*/ function toolekco_get_movie_form_imdb(){ $imdb_id = ''; $post_id = 0; $imdb_url = ''; $results = array(); $element_html = ''; $element_text = ''; //get post id and imdb id $imdb_id = $_REQUEST['imdb_id']; $post_id = (int) $_REQUEST['post_id']; //Check empty var if(empty($imdb_id)){ $results['success'] = false; wp_send_json_error( $results ); wp_die(); } if(empty($post_id) || !is_numeric($post_id)){ $results['success'] = false; wp_send_json_error( $results ); wp_die(); } //build imdb url $imdb_url = 'https://www.imdb.com/title/'.urlencode($imdb_id).'/'; //get dom html imdb $html = file_get_html($imdb_url); // get movie name $element_html = $html->find("meta[property=og:title]",0); if(isset($element_html) || !empty($element_html)){ $element_text = strip_tags(isset($element_html) ? $element_html->content : "ثبت نشده است"); $results['title'] = preg_replace("/[^A-Za-z0-9 ]/", '', $element_text ); }else{ $results['title'] = 'بدون عنوان'; } //get poster url $element_html = $html->find("div[class=poster] a img",0); if(isset($element_html) || !empty($element_html)){ $poster_imdb_url = substr($element_html->src, 0, strpos($element_html->src, '._V1')) . '._UX500.jpg'; $upload_image_id = toolekco_uploader($poster_imdb_url); $results['poster_id'] = $upload_image_id; $results['poster'] = wp_get_attachment_image_url($upload_image_id, 'full'); }else{ $results['poster'] = get_template_directory_uri().'/img/noimage.jpg'; } // get trailer $trailer_link = $html->find("div[class=slate] a", 0); if(isset($trailer_link) || !empty($trailer_link)){ $trailer_id = $trailer_link->getAttribute("data-video"); if(!isset($trailer_id) || empty($trailer_id)){ $results['trailer'] = 'N/A'; }else{ $url = "http://www.imdb.com/video/imdb/".$trailer_id."/imdb/playlist?index=0&total=9&feature=sims&list=".$imdb_id."&rid=undefined&action=user&refsuffix=tt_ov_vi&ref_=vi_sh_1_tt_ov_vi"; $crawling = file_get_html($url); preg_match_all('/
    loading

    درحال دریافت اطلاعات ، لطفا صبر کنید ...

    ID, 'imdb_rate_movie', true ); ?>
    '; foreach ($fields_pl as $field) { switch($field['type']) { case 'checkbox': ?>
    post_type == 'post'){ global $fields_pl; if (!wp_verify_nonce($_POST['movie_data_nonce'], basename(__FILE__))) return $post_id; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) return $post_id; } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($fields_pl as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; //update other data if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new && $old ) { delete_post_meta($post_id, $field['id'], $old); } } $old_profile_actor_movie = get_post_meta($post_id, 'profile_actor_movie', true); $actor_pro = explode(",", $old_profile_actor_movie); $actornames = get_post_meta( $post_id, 'cast_movie', true ); $actor_names = explode(",", $actornames); if(!empty($actornames)){ $i = 0; foreach($actor_names as $actor_name){ $actor_obj = get_term_by('name', $actor_name, 'actor'); update_term_meta($actor_obj->term_id, 'profile', $actor_pro[$i]); $i++; } } } } add_action('save_post', 'save_movie_meta_pl');