Changeset 1792532
- Timestamp:
- 12/26/2017 11:02:05 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
all-in-one-demo-importexport/trunk/classes/class-aiodie-core.php
r1791151 r1792532 190 190 191 191 $status = get_post_statuses(); 192 $comment = get_comments( );192 $comment = get_comments(array('numberposts' => -1)); 193 193 $menu = get_registered_nav_menus(); 194 194 $tags = get_tags(array('get'=>'all')); … … 196 196 197 197 198 if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-export-content'])){ /* Code for Get the customizer and all content data */ 199 198 if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-export-content'])){ 199 200 /* Code for Get the customizer and all content data */ 200 201 $data = array( 201 202 'template' => $template, … … 216 217 217 218 }else if(!empty($_GET['aiodie-export-customize']) && !empty($_GET['aiodie-post-export'])){ 219 218 220 /* Code for the customizer and all post data */ 219 220 221 $cat = $_GET['postform']; 221 222 $postauthor = $_GET['post-author']; … … 248 249 $postcontent = $query->posts; 249 250 $tags = get_tags(); 250 $comment = get_comments( );251 $comment = get_comments(array('numberposts' => -1)); 251 252 $postcontcategory = array(); 252 253 $termcontlist = array(); … … 349 350 $otherargs = array( 350 351 'post_type' => $postty, 351 'posts_per_page' => -1 352 'posts_per_page' => -1, 353 'orderby' => 'title', // or 'date', 'rand' 354 'order' => 'ASC', // or 'DESC' 355 'post_status' => 'any', 352 356 // Several more arguments could go here. Last one without a comma. 353 );357 ); 354 358 $query = new WP_Query( $otherargs ); 355 359 $othercontent = $query->posts; 356 360 $taxonomies = get_object_taxonomies($postty); 361 $comments = get_comments(array('numberposts' => -1)); 357 362 $customotherfields = array(); 358 363 $postothercategory = array(); 359 364 $postotherthumbnail_url =array(); 360 361 365 $taxo = array(); 362 366 $getterms = ''; … … 368 372 $thumbnailpostother_url = wp_get_attachment_image_src(get_post_thumbnail_id($othercont->ID), array('220','220'), true ); 369 373 $postotherthumbnail_url[$othercont->ID] = $thumbnailpostother_url[0]; 370 371 374 372 375 foreach ($taxonomies as $taxonomy) { 373 376 $taxo[] = $taxonomy; … … 392 395 'post_category' => $postothercategory, 393 396 'custom_fields' => $customotherfields, 397 'comment' => $comments, 394 398 ); 395 399 396 400 }else if(!empty($_GET['aiodie-export-customize'])) { 397 398 401 /* Code for Get the customizer data */ 399 402 $data = array( … … 456 459 $postcontent = $query->posts; 457 460 $tags = get_tags(); 458 $comment = get_comments( );461 $comment = get_comments(array('numberposts' => -1)); 459 462 $postcontcategory = array(); 460 463 $termcontlist = array(); … … 464 467 465 468 foreach($postcontent as $postcont){ 466 467 469 $customcont = get_post_custom($postcont->ID); 468 470 $customcontfields[$postcont->ID] = $customcont; … … 491 493 }else if(!empty($_GET['aiodie-page-export'])){ 492 494 /* Code for Get the all page data */ 493 494 495 $pageauthor = $_GET['page-author']; 495 496 $pagestartdate = date( 'Y-m-d', strtotime($_GET['page_str_date'])); … … 515 516 $customcontentfieldspage = array(); 516 517 $pagecontentthumbnail_url = array(); 518 517 519 foreach($pagecontent as $pagecontentpost){ 518 519 520 $customcontentfil = get_post_custom($pagecontentpost->ID); 520 521 $customcontentfieldspage[$pagecontentpost->ID] = $customcontentfil; … … 546 547 547 548 $postty = $_GET['post_type']; 548 549 549 $otherargs = array( 550 550 'post_type' => $postty, 551 'posts_per_page' => -1 551 'posts_per_page' => -1, 552 'orderby' => 'title', // or 'date', 'rand' 553 'order' => 'ASC', // or 'DESC' 554 'post_status' => 'any', 552 555 // Several more arguments could go here. Last one without a comma. 553 );556 ); 554 557 $query = new WP_Query( $otherargs ); 555 558 //$categories = get_categories($otherargs); … … 557 560 $othercontent = $query->posts; 558 561 $taxonomies = get_object_taxonomies($postty); 559 560 562 $customotherfields = array(); 561 563 $postothercategory = array(); 562 564 $postotherthumbnail_url = array(); 563 564 565 $taxo = array(); 565 566 $getterms = ''; 566 567 $comments = get_comments(array('numberposts' => -1)); 568 567 569 foreach($othercontent as $othercont){ 568 570 … … 571 573 $thumbnailpostother_url = wp_get_attachment_image_src(get_post_thumbnail_id($othercont->ID), array('220','220'), true ); 572 574 $postotherthumbnail_url[$othercont->ID] = $thumbnailpostother_url[0]; 573 575 574 576 foreach ($taxonomies as $taxonomy) { 575 577 … … 583 585 $postothercategory[$othercont->ID] = $postterm; 584 586 } 585 586 } 587 587 } 588 588 /* Code for Get the all attachment data */ 589 589 $data = array( … … 593 593 'post_category' => $postothercategory, 594 594 'custom_fields' => $customotherfields, 595 ); 596 597 598 599 } 600 595 'comment' => $comments, 596 ); 597 598 } 599 601 600 // Get options from the Customizer API. 602 601 $settings = $wp_customize->settings(); … … 639 638 header( 'Content-Type: application/octet-stream; charset=' . $charset ); 640 639 641 //var_dump($data);642 640 // Serialize the export data. 643 641 echo serialize($data); … … 717 715 } 718 716 719 if ( $data['template'] != $template ) {720 721 }717 // if ( $data['template'] != $template ) { 718 719 // } 722 720 //Import images. 723 721 if ( isset( $_REQUEST['aiodie-import-images'] ) ) { … … 733 731 $post_author = $lesson->post_author; 734 732 $post_content = $lesson->post_content; 735 $post_type = $lesson->post_type; 733 $post_type = $lesson->post_type; 734 $post_status = $lesson->post_status; 736 735 $check_title=get_page_by_title($post_title, 'OBJECT', 'post'); 737 736 738 737 if (empty($check_title) ){ 739 738 $my_post = array( 740 739 'post_title' => $post_title, 741 740 'post_content' => $post_content, 742 'post_status' => 'publish',741 'post_status' => $post_status, 743 742 'post_author' => $post_author, 744 743 'post_type' => $post_type, 745 744 ); 746 745 $post_insert = wp_insert_post( $my_post ); 747 } 748 else { 746 }else{ 749 747 $my_post = array( 750 748 'ID' => $check_title->ID, 751 749 'post_title' => $post_title, 752 750 'post_content' => $post_content, 753 'post_status' => 'publish',751 'post_status' => $post_status, 754 752 'post_author' => $post_author, 755 753 'post_type' => $post_type, 756 757 754 ); 758 755 $post_insert = wp_update_post( $my_post ); … … 760 757 761 758 if (isset($data['tags_input'])){ 762 wp_set_post_tags($post_insert, $data['tags_input'][$post_id], true);759 wp_set_post_tags($post_insert, $data['tags_input'][$post_id], true); 763 760 } 764 761 765 762 if (isset($data['custom_fields'])){ 766 763 767 $customdata = $data['custom_fields'][$post_id]; 768 769 foreach($customdata as $metakey => $metavalue){ 770 foreach($metavalue as $value){ 771 add_post_meta( $post_insert, $metakey, $value, true ); 772 773 } 764 $customdata = $data['custom_fields'][$post_id]; 765 766 foreach($customdata as $metakey => $metavalue){ 767 foreach($metavalue as $value){ 768 add_post_meta( $post_insert, $metakey, $value, true ); 769 770 } 771 } 774 772 } 775 }776 773 777 774 // Need to require these files … … 832 829 $post_content = $lesson->post_content; 833 830 $post_type = $lesson->post_type; 831 $post_status = $lesson->post_status; 834 832 $check_title=get_page_by_title($post_title, 'OBJECT', 'page'); 835 833 … … 839 837 'post_title' => $post_title, 840 838 'post_content' => $post_content, 841 'post_status' => 'publish',839 'post_status' => $post_status, 842 840 'post_type' => $post_type, 843 841 'post_author' => $post_author, 844 842 ); 845 843 $page_insert = wp_insert_post( $my_post ); 846 } 847 else { 844 }else{ 848 845 $my_post = array( 849 846 'ID' => $check_title->ID, 850 847 'post_title' => $post_title, 851 848 'post_content' => $post_content, 852 'post_status' => 'publish',849 'post_status' => $post_status, 853 850 'post_type' => $post_type, 854 851 'post_author' => $post_author, … … 858 855 859 856 if(isset($data['custom_fieldspage'])){ 860 $custompagedata = $data['custom_fieldspage'][$page_id]; 861 foreach($custompagedata as $metapagekey => $metapagevalue){ 862 foreach($metapagevalue as $val){ 863 add_post_meta( $page_insert, $metapagekey, $val, true ); 857 $custompagedata = $data['custom_fieldspage'][$page_id]; 858 foreach($custompagedata as $metapagekey => $metapagevalue){ 859 foreach($metapagevalue as $val){ 860 add_post_meta( $page_insert, $metapagekey, $val, true ); 861 } 864 862 } 865 }866 863 } 867 864 // Need to require these files … … 897 894 898 895 // If error storing permanently, unlink 899 if ( is_wp_error($id) ) {896 if ( is_wp_error($id) ){ 900 897 @unlink($file_array['tmp_name']); 901 898 return $id; … … 916 913 917 914 if ($data['category'] != ''){ 918 919 /* code for upload the category */ 920 $category_map = array(); 921 foreach($data['category'] as $key => $lesson) 922 { 923 $category = $lesson->cat_ID; 924 $term_id = $lesson->term_id; 925 $cat_name = $lesson->name; 926 927 $cat_slug = $lesson->slug; 928 $taxonomy = $lesson->taxonomy; 929 930 $term = term_exists($cat_name, $taxonomy); 931 if ($term !== 0 && $term !== null) 932 { 933 $termid = $term['term_id']; 934 $term = wp_update_term($termid, $taxonomy ); 935 936 $category_map[$term_id] = $term['term_id']; 937 } 938 else 939 { 940 $term_ins = wp_insert_term($cat_name, $taxonomy, array('slug' => $cat_slug) ); 941 $category_map[$term_id] = $term_ins['term_id']; 942 } 943 944 } 945 946 foreach($postid as $key => $value1){ 947 948 $post_categories = $data['post_category'][$key]; 949 $newcat = array(); 950 foreach( $post_categories as $cat){ 951 foreach($data['category'] as $key => $lesson){ 952 $newcat[] = $category_map[$cat]; 953 $term_id = $lesson->term_id; 954 $taxonomy = $lesson->taxonomy; 955 if($taxonomy == 'category'){ 956 wp_set_post_categories($value1, $newcat); 957 }else{ 958 wp_set_post_terms($value1, $newcat, $taxonomy); 959 960 } 961 } 962 } 963 964 } 915 /* code for upload the category */ 916 $category_map = array(); 917 foreach($data['category'] as $key => $lesson){ 918 $category = $lesson->cat_ID; 919 $term_id = $lesson->term_id; 920 $cat_name = $lesson->name; 921 $cat_slug = $lesson->slug; 922 $taxonomy = $lesson->taxonomy; 923 924 $term = term_exists($cat_name, $taxonomy); 925 if ($term !== 0 && $term !== null){ 926 $termid = $term['term_id']; 927 $term = wp_update_term($termid, $taxonomy ); 928 929 $category_map[$term_id] = $term['term_id']; 930 }else{ 931 $term_ins = wp_insert_term($cat_name, $taxonomy, array('slug' => $cat_slug) ); 932 $category_map[$term_id] = $term_ins['term_id']; 933 } 934 } 935 936 foreach($postid as $key => $value1){ 937 938 $post_categories = $data['post_category'][$key]; 939 $newcat = array(); 940 foreach( $post_categories as $cat){ 941 foreach($data['category'] as $key => $lesson){ 942 $newcat[] = $category_map[$cat]; 943 $term_id = $lesson->term_id; 944 $taxonomy = $lesson->taxonomy; 945 if($taxonomy == 'category'){ 946 wp_set_post_categories($value1, $newcat); 947 }else{ 948 wp_set_post_terms($value1, $newcat, $taxonomy); 949 } 950 } 951 } 952 } 965 953 } 966 954 } 967 955 968 if ( isset( $data['tags'] ) ) {956 if ( isset( $data['tags'] ) ){ 969 957 /* code for upload the tags */ 970 958 $tags_map = array(); … … 977 965 $term = term_exists($tag_name, 'post_tag'); 978 966 if ($term !== 0 && $term !== null) { 979 $termid = $term['term_id'];980 $term = wp_update_term($termid, $taxonomy );981 967 $termid = $term['term_id']; 968 $term = wp_update_term($termid, $taxonomy ); 969 982 970 $tags_map[$term_id] = $term['term_id']; 983 971 }else{ … … 987 975 } 988 976 } 989 if ( isset( $data['comment'] ) ) {977 if ( isset( $data['comment'] ) ){ 990 978 /* code for upload the comment */ 991 979 foreach($data['comment'] as $key => $lesson){ … … 1027 1015 $userlogin = $lesson->user_login; 1028 1016 $user_id = $lesson->ID; 1029 if(username_exists( $user_login )) 1030 { 1017 if(username_exists( $user_login )){ 1031 1018 //echo '---------'; 1032 1019 // echo "Username already exists"; 1033 } 1034 else 1035 { 1020 }else{ 1036 1021 $userdata = array( 1037 1022 'user_login' => $userlogin, … … 1045 1030 echo "User created : ". $user_id; 1046 1031 } 1047 1048 1032 } 1049 1033 } … … 1097 1081 set_post_thumbnail($pagepid, $attachments[0]->ID); 1098 1082 } 1099 1100 } 1101 1083 } 1102 1084 } 1103 1085 … … 1123 1105 // Loop through the mods. 1124 1106 if(isset($data['mods'])){ 1125 foreach ( $data['mods'] as $key => $val ) {1107 foreach ( $data['mods'] as $key => $val ) { 1126 1108 1127 1109 // Call the customize_save_ dynamic action. 1128 do_action( 'customize_save_' . $key, $wp_customize );1110 do_action( 'customize_save_' . $key, $wp_customize ); 1129 1111 // Save the mod. 1130 set_theme_mod( $key, $val );1131 }1112 set_theme_mod( $key, $val ); 1113 } 1132 1114 } 1133 1115 // Call the customize_save_after action. … … 1162 1144 } 1163 1145 } 1164 } 1165 1146 } 1166 1147 return $mods; 1167 1148 } … … 1207 1188 return $id; 1208 1189 } 1209 1210 1190 // Build the object to return. 1211 1191 $meta = wp_get_attachment_metadata( $id ); … … 1216 1196 $data->width = $meta['width']; 1217 1197 } 1218 1219 1198 return $data; 1220 1199 } … … 1230 1209 static private function _is_image_url( $string = '' ) 1231 1210 { 1232 if ( is_string( $string ) ) { 1233 1211 if ( is_string( $string ) ) { 1234 1212 if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) { 1235 1213 return true; 1236 1214 } 1237 } 1238 1215 } 1239 1216 return false; 1240 1217 }
Note: See TracChangeset
for help on using the changeset viewer.