PluginProbe
Cooked – Recipe Management / 1.9.5
Cooked – Recipe Management v1.9.5
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.9.5, at includes/class.cooked-import.php

128 lines 6.4 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 $import_tabs = [];
38 if (!empty($delicious_recipes)) {
39 $total = count($delicious_recipes);
40
41 /* translators: for displaying singular or plural versions depending on the number of recipes. */
42 $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>' );
43 $html_desc .= '<br>';
44 $html_desc .= __( 'Before you begin, please make sure you <b>backup your database</b> in case something goes wrong.', 'cooked' );
45 $html_desc .= '<br>';
46 $html_desc .= __( 'Click the button below to import these recipes. Here is what will happen to your recipes:', 'cooked' );
47 $html_desc .= '<ul class="cooked-admin-ul">';
48 $html_desc .= '<li>' . __( 'Recipes will be imported with the <b>\'Draft\'</b> status.', 'cooked' ) . '</li>';
49 $html_desc .= '<li>' . __( 'Comments and ratings data will also be imported (ratings are available in Cooked Pro).', 'cooked' ) . '</li>';
50 $html_desc .= '<li>' . __( 'After the import is complete, you can bulk edit the recipes and change their status to <b>\'Published\'</b>.', 'cooked' ) . '</li>';
51 $html_desc .= '<li>' . __( 'The existing WP Delicious recipes and data will not be modified or deleted.', 'cooked' ) . '</li>';
52 $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>';
53 $html_desc .= '<li>' . __( 'You can run the import multiple times, but keep in mind that duplicate recipes will be created.', 'cooked' ) . '</li>';
54 $html_desc .= '</ul>';
55
56 if ($total > 2000) {
57 $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>';
58 } else {
59 $html_desc .= '<p class="cooked-import-note"><strong>' . __( 'Note:', 'cooked' ) . '</strong> ' . __( 'The more recipes you have, the longer this will take.', 'cooked' ) . '</p>';
60 }
61
62 if ($total > 0) {
63 $import_tabs['delicious_recipes_import'] = [
64 'name' => __('WP Delicious - Import', 'cooked'),
65 'icon' => 'migrate',
66 'fields' => [
67 'cooked_import_button' => [
68 'title' => 'WP Delicious (formerly Delicious Recipes)&nbsp;&nbsp;<i class="cooked-icon cooked-icon-angle-right"></i>&nbsp;&nbsp;Cooked',
69 'desc' => $html_desc,
70 'type' => 'import_button',
71 'total' => $total,
72 'import_type' => $Cooked_Delicious_Recipes->import_type,
73 ]
74 ]
75 ];
76 }
77 } else {
78 $import_tabs['no_delicious_recipes'] = [
79 'name' => __('WP Delicious - Import', 'cooked'),
80 'icon' => 'migrate',
81 'fields' => [
82 'cooked_no_delicious_recipes' => [
83 'title' => 'WP Delicious (formerly Delicious Recipes)',
84 'desc' => '',
85 'type' => 'message',
86 'message' => 'There are no recipes to import from WP Delicious.',
87 ]
88 ]
89 ];
90 }
91
92 $import_tabs['more_imports_coming_soon'] = [
93 'name' => __('More Imports are Coming Soon...', 'cooked'),
94 'icon' => 'migrate',
95 'fields' => [
96 'cooked_no_delicious_recipes' => [
97 'title' => 'More Imports are Coming Soon...',
98 'desc' => '',
99 'type' => 'message',
100 'message' => 'More Imports are Coming Soon...',
101 ]
102 ]
103 ];
104
105 return apply_filters('cooked_import_tabs_fields', $import_tabs);
106 }
107
108 public static function field_import_button( $name, $field_options, $color, $field ) {
109 $total = $field['total'];
110 $import_type = $field['import_type'];
111
112 if ($total > 0) {
113 echo '<p>';
114 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' ) . '">';
115 echo '</p>';
116 echo '<p>';
117 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>';
118 echo '</p>';
119 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>';
120 }
121 }
122
123 public static function field_message( $name, $field_options, $color, $field ) {
124 echo '<p>' . $field['message'] . '</p>';
125 }
126
127 }
128