PluginProbe
Cooked – Recipe Management / 1.11.4
Cooked – Recipe Management v1.11.4
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / includes / class.cooked-import.php

class.cooked-import.php in Cooked – Recipe Management 1.11.4, at includes/class.cooked-import.php

187 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register Import
4 *
5 * @package Cooked
6 * @subpackage Import
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Cooked_Import Class
15 *
16 * This class handles the import of recipes from other plugins.
17 *
18 * @since 1.0.0
19 */
20 class Cooked_Import {
21
22 public function __construct() {
23 add_filter( 'admin_init', [&$this, 'init'] );
24 add_filter( 'init', [&$this, 'init'] );
25 }
26
27 public static function init() {
28 register_setting( 'cooked_import_group', 'cooked_import' );
29 register_setting( 'cooked_import_group', 'cooked_import_saved' );
30 }
31
32 public static function tabs_fields() {
33 $Cooked_Delicious_Recipes = new Cooked_Delicious_Recipes();
34 $delicious_recipes = $Cooked_Delicious_Recipes::get_recipes();
35 $cooked_delicious_recipes_imported = get_option( 'cooked_delicious_recipes_imported', false );
36
37 $Cooked_Recipe_Maker_Recipes = new Cooked_Recipe_Maker_Recipes();
38 $wp_recipe_maker_recipes = $Cooked_Recipe_Maker_Recipes::get_recipes();
39 $cooked_wp_recipe_maker_imported = get_option( 'cooked_wp_recipe_maker_imported', false );
40
41 $import_tabs = [];
42 if (!empty($delicious_recipes)) {
43 $total = count($delicious_recipes);
44
45 /* translators: for displaying singular or plural versions depending on the number of recipes. */
46 $html_desc = sprintf( esc_html( _n( 'There is %1$s recipe that should be imported from %2$s.', 'There are %1$s recipes that should be imported from %2$s.', $total, 'cooked' ) ), '<strong>' . number_format( $total ) . '</strong>', '<strong>WP Delicious (formerly Delicious Recipes)</strong>' );
47 $html_desc .= '<br>';
48 $html_desc .= __( 'Before you begin, please make sure you <b>backup your database</b> in case something goes wrong.', 'cooked' );
49 $html_desc .= '<br>';
50 $html_desc .= __( 'Click the button below to import these recipes. Here is what will happen to your recipes:', 'cooked' );
51 $html_desc .= '<ul class="cooked-admin-ul">';
52 $html_desc .= '<li>' . __( 'Recipes will be imported with the <b>\'Draft\'</b> status.', 'cooked' ) . '</li>';
53 $html_desc .= '<li>' . __( 'Comments and ratings data will also be imported (ratings are available in Cooked Pro).', 'cooked' ) . '</li>';
54 $html_desc .= '<li>' . __( 'After the import is complete, you can bulk edit the recipes and change their status to <b>\'Published\'</b>.', 'cooked' ) . '</li>';
55 $html_desc .= '<li>' . __( 'The existing WP Delicious recipes and data will not be modified or deleted.', 'cooked' ) . '</li>';
56 $html_desc .= '<li>' . __( 'Certain data that is not suppoted by Cooked will not be imported (such as Cooking Temp, Estimated Cost, Recipe Keywords, etc).', 'cooked' ) . '</li>';
57 $html_desc .= '<li>' . __( 'You can run the import multiple times, but keep in mind that duplicate recipes will be created.', 'cooked' ) . '</li>';
58 $html_desc .= '</ul>';
59
60 if ($total > 2000) {
61 $html_desc .= '<p class="cooked-import-note"><strong>' . __( 'Wow, you have a lot of recipes!', 'cooked' ) . '</strong><br><em style="color:#333;">' . __( 'It is definitely recommended that you get yourself a cup of coffee or tea after clicking this button.', 'cooked' ) . '</em></p>';
62 } else {
63 $html_desc .= '<p class="cooked-import-note"><strong>' . __( 'Note:', 'cooked' ) . '</strong> ' . __( 'The more recipes you have, the longer this will take.', 'cooked' ) . '</p>';
64 }
65
66 if ($total > 0) {
67 $import_tabs['delicious_recipes_import'] = [
68 'name' => __('WP Delicious - Import', 'cooked'),
69 'icon' => 'migrate',
70 'fields' => [
71 'cooked_import_button' => [
72 'title' => 'WP Delicious (formerly Delicious Recipes)&nbsp;&nbsp;<i class="cooked-icon cooked-icon-angle-right"></i>&nbsp;&nbsp;Cooked',
73 'desc' => $html_desc,
74 'type' => 'import_button',
75 'total' => $total,
76 'import_type' => $Cooked_Delicious_Recipes->import_type,
77 ]
78 ]
79 ];
80 }
81 } else {
82 $import_tabs['no_delicious_recipes'] = [
83 'name' => __('WP Delicious - Import', 'cooked'),
84 'icon' => 'migrate',
85 'fields' => [
86 'cooked_no_delicious_recipes' => [
87 'title' => 'WP Delicious (formerly Delicious Recipes)',
88 'desc' => '',
89 'type' => 'message',
90 'message' => 'There are no recipes to import from WP Delicious.',
91 ]
92 ]
93 ];
94 }
95
96 if (!empty($wp_recipe_maker_recipes)) {
97 $total = count($wp_recipe_maker_recipes);
98
99 /* translators: for displaying singular or plural versions depending on the number of recipes. */
100 $html_desc = sprintf( esc_html( _n( 'There is %1$s recipe that should be imported from %2$s.', 'There are %1$s recipes that should be imported from %2$s.', $total, 'cooked' ) ), '<strong>' . number_format( $total ) . '</strong>', '<strong>WP Recipe Maker</strong>' );
101 $html_desc .= '<br>';
102 $html_desc .= __( 'Before you begin, please make sure you <b>backup your database</b> in case something goes wrong.', 'cooked' );
103 $html_desc .= '<br>';
104 $html_desc .= __( 'Click the button below to import these recipes. Here is what will happen to your recipes:', 'cooked' );
105 $html_desc .= '<ul class="cooked-admin-ul">';
106 $html_desc .= '<li>' . __( 'Recipes will be imported with the <b>\'Draft\'</b> status.', 'cooked' ) . '</li>';
107 $html_desc .= '<li>' . __( 'Comments and ratings data will also be imported (ratings are available in Cooked Pro).', 'cooked' ) . '</li>';
108 $html_desc .= '<li>' . __( 'The difficulty level will be set to <b>Beginner</b> since it is not supported by WP Recipe Maker.', 'cooked' ) . '</li>';
109 $html_desc .= '<li>' . __( 'After the import is complete, you can bulk edit the recipes and change their status to <b>\'Published\'</b>.', 'cooked' ) . '</li>';
110 $html_desc .= '<li>' . __( 'The existing WP Recipe Maker and data will not be modified or deleted.', 'cooked' ) . '</li>';
111 $html_desc .= '<li>' . __( 'Certain data that is not suppoted by Cooked will not be imported (such as Cooking Temp, Estimated Cost, Recipe Keywords, etc).', 'cooked' ) . '</li>';
112 $html_desc .= '<li>' . __( 'You can run the import multiple times, but keep in mind that duplicate recipes will be created.', 'cooked' ) . '</li>';
113 $html_desc .= '</ul>';
114
115 if ($total > 2000) {
116 $html_desc .= '<p class="cooked-import-note"><strong>' . __( 'Wow, you have a lot of recipes!', 'cooked' ) . '</strong><br><em style="color:#333;">' . __( 'It is definitely recommended that you get yourself a cup of coffee or tea after clicking this button.', 'cooked' ) . '</em></p>';
117 } else {
118 $html_desc .= '<p class="cooked-import-note"><strong>' . __( 'Note:', 'cooked' ) . '</strong> ' . __( 'The more recipes you have, the longer this will take.', 'cooked' ) . '</p>';
119 }
120
121 if ($total > 0) {
122 $import_tabs['wp_recipe_maker_import'] = [
123 'name' => __('WP Recipe Maker - Import', 'cooked'),
124 'icon' => 'migrate',
125 'fields' => [
126 'cooked_import_button' => [
127 'title' => 'WP Recipe Maker&nbsp;&nbsp;<i class="cooked-icon cooked-icon-angle-right"></i>&nbsp;&nbsp;Cooked',
128 'desc' => $html_desc,
129 'type' => 'import_button',
130 'total' => $total,
131 'import_type' => $Cooked_Recipe_Maker_Recipes->import_type,
132 ]
133 ]
134 ];
135 }
136 } else {
137 $import_tabs['no_wp_recipe_maker_recipes'] = [
138 'name' => __('WP Recipe Maker - Import', 'cooked'),
139 'icon' => 'migrate',
140 'fields' => [
141 'cooked_no_wp_recipe_maker_recipes' => [
142 'title' => 'WP Recipe Maker',
143 'desc' => '',
144 'type' => 'message',
145 'message' => 'There are no recipes to import from WP Recipe Maker.',
146 ]
147 ]
148 ];
149 }
150
151 $import_tabs['more_imports_coming_soon'] = [
152 'name' => __('More Imports are Coming Soon...', 'cooked'),
153 'icon' => 'migrate',
154 'fields' => [
155 'cooked_more_imports_coming_soon' => [
156 'title' => 'More Imports are Coming Soon...',
157 'desc' => '',
158 'type' => 'message',
159 'message' => 'More Imports are Coming Soon...',
160 ]
161 ]
162 ];
163
164 return apply_filters('cooked_import_tabs_fields', $import_tabs);
165 }
166
167 public static function field_import_button( $name, $field_options, $color, $field ) {
168 $total = $field['total'];
169 $import_type = $field['import_type'];
170
171 if ($total > 0) {
172 echo '<p>';
173 echo '<input id="cooked-import-button" type="button" class="button-secondary" data-import-type="' . esc_attr( $import_type ) . '" name="begin_cooked_migration" value="' . __( 'Begin Import', 'cooked' ) . '">';
174 echo '</p>';
175 echo '<p>';
176 echo '<span id="cooked-import-progress" class="cooked-progress"><span class="cooked-progress-bar"></span></span><span id="cooked-import-progress-text" class="cooked-progress-text">0 / ' . esc_html( $total ) . '</span>';
177 echo '</p>';
178 echo '<p id="cooked-import-completed"><strong>Import Complete!</strong> You can now <a href="' . esc_url( add_query_arg(['page' => 'cooked_import'], admin_url( 'admin.php' ) ) ) . '">' . __( 'reload', 'cooked' ) . '</a> the import screen.</p>';
179 }
180 }
181
182 public static function field_message( $name, $field_options, $color, $field ) {
183 echo '<p>' . $field['message'] . '</p>';
184 }
185
186 }
187