PluginProbe
Recipe Cards For Your Food Blog from Zip Recipes / 8.1.0
Recipe Cards For Your Food Blog from Zip Recipes v8.1.0
trunk 8.0.8 8.0.9 8.1.0 8.1.1 8.2.8
zip-recipes / zip-recipes.php

zip-recipes.php in Recipe Cards For Your Food Blog from Zip Recipes 8.1.0, at zip-recipes.php

209 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Zip Recipes
4 Text Domain: zip-recipes
5 Domain Path: /languages
6 Plugin URI: http://www.ziprecipes.net/
7 Plugin GitHub: https://github.com/Really-Simple-Plugins/zip-recipes-free
8 Description: A plugin that adds all the necessary microdata to your recipes, so they will show up in Google's Recipe Search
9 Version: 8.1.0
10 Author: Really Simple Plugins
11 Author URI: https://www.really-simple-plugins.com/
12 License: GPL2
13 Copyright 2022 Really Simple Plugins
14 This code is derived from the 2.6 version build of ZipList Recipe Plugin released by ZipList Inc.:
15 http://get.ziplist.com/partner-with-ziplist/wordpress-recipe-plugin/ and licensed under GPL2 or later
16 */
17
18 /* Copyright 2022 Zip Recipes BV (email : support@ziprecipes.net)
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License, version 2, as
21 published by the Free Software Foundation.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 namespace ZRDN;
32 defined('ABSPATH') or die("Error! Cannot be called directly.");
33
34 if (!function_exists(__NAMESPACE__ . '\zrdn_activation_check')) {
35 /**
36 * Checks if the plugin can safely be activated, at least php 5.6 and wp 4.6
37 * @since 7.0.0
38 */
39 function zrdn_activation_check()
40 {
41 if (version_compare(PHP_VERSION, '7.2', '<')) {
42 deactivate_plugins(plugin_basename(__FILE__));
43 wp_die(__('Zip Recipes cannot be activated. The plugin requires PHP 7.2 or higher', 'zip-recipes'));
44 }
45
46 global $wp_version;
47 if (version_compare($wp_version, '4.9', '<')) {
48 deactivate_plugins(plugin_basename(__FILE__));
49 wp_die(__('Zip Recipes cannot be activated. The plugin requires WordPress 4.9 or higher', 'zip-recipes'));
50 }
51 }
52 register_activation_hook( __FILE__, __NAMESPACE__ . '\zrdn_activation_check' );
53 }
54
55 if (defined('ZRDN_PLUGIN_BASENAME')) {
56 if (defined('ZRDN_FREE')) {
57 deactivate_plugins('zip-recipes/zip-recipes.php');
58 //add_action('admin_notices', __NAMESPACE__ . '\zrdn_notice_free_active');
59 }elseif (defined('ZRDN_PRODUCT_ID') && ZRDN_PRODUCT_ID === 1851 ) {
60 deactivate_plugins('zip-recipes-friend/zip-recipes-friend.php');
61 //add_action('admin_notices', __NAMESPACE__ . '\zrdn_notice_free_active');
62 } else {
63 deactivate_plugins('zip-recipes-lover/zip-recipes-lover.php');
64 }
65
66 } else {
67 define('ZRDN_PATH', plugin_dir_path( __FILE__ ) );
68 define('ZRDN_FREE', true);
69 define('ZRDN_PLUGIN_DIRECTORY_URL', plugin_dir_url( __FILE__ ));
70 define('ZRDN_PLUGIN_BASENAME', plugin_basename(__FILE__));
71 define('ZRDN_PLUGIN_URL', sprintf('%s/%s/', plugins_url(), dirname(plugin_basename(__FILE__))));
72 define('ZRDN_API_URL', "https://api.ziprecipes.net");
73 define('ZRDN_RECIPEDATABASE_URL', 'https://share.ziprecipes.net/');
74 define('ZRDN_PLUGIN_PRODUCT_NAME', 'Zip Recipes' );
75 $debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? time() : '';
76 define('ZRDN_VERSION_NUM', '8.1.0' . $debug);
77
78 add_action('plugins_loaded', __NAMESPACE__ . '\init', 9);
79 }
80
81 if (!function_exists(__NAMESPACE__ . '\init')) {
82 function init( $className ) {
83 require_once( ZRDN_PATH . '/models/Recipe.php' );
84 require_once( ZRDN_PATH . '_inc/class.ziprecipes.util.php' );
85 require_once( ZRDN_PATH . 'class.ziprecipes.php' );
86 require_once( ZRDN_PATH . 'class-review.php' );
87 require_once( ZRDN_PATH . '_inc/helper_functions.php' );
88 require_once( ZRDN_PATH . '_inc/PluginBase.php' );
89 require_once( ZRDN_PATH . 'RecipeTable/RecipeMenu.php' );
90 require_once( ZRDN_PATH . 'NutritionLabel/NutritionLabel.php' );
91
92 if ( is_admin() ) {
93 require_once( ZRDN_PATH . 'upgrade-zip.php' );
94 require_once( ZRDN_PATH . 'grid/grid-enqueue.php' );
95 require_once( ZRDN_PATH . 'class-field.php' );
96 require_once( ZRDN_PATH . 'shepherd/tour.php' );
97
98 }
99 /**
100 * Recipe sharing
101 */
102 require_once( ZRDN_PATH . 'sharing/class-recipe-sharing-admin.php' );
103
104 /**
105 * API endpoint & Basic Auth
106 */
107 require_once( ZRDN_PATH . "controllers/Response.php" );
108 require_once( ZRDN_PATH . "controllers/EndpointController.php" );
109 if ( ! function_exists( 'is_plugin_active' ) ) {
110 require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
111 }
112 ZipRecipes::init();
113 }
114 }
115
116 if (!function_exists(__NAMESPACE__ . '\zrdn_set_defaults')) {
117 register_activation_hook( __FILE__, __NAMESPACE__ . '\zrdn_set_defaults' );
118
119 /**
120 * set defaults on activation
121 */
122
123 function zrdn_set_defaults() {
124 if (!get_option('zrdn_defaults_set')) {
125 //set some defaults
126 $settings = get_option('zrdn_settings_general');
127 $zrdn_print['show_summary_on_archive_pages'] = true;
128 update_option('zrdn_settings_general', $settings);
129
130 update_option('zrdn_defaults_set', true);
131 }
132 }
133 }
134
135 if (!function_exists(__NAMESPACE__ . '\zrdn_check_translations')) {
136 register_activation_hook(__FILE__, __NAMESPACE__ . '\zrdn_check_translations');
137 function zrdn_check_translations(){
138 //dirname with levels does not exist before php 7
139 if (version_compare(PHP_VERSION, '7.0', '<')) return;
140
141 $path = dirname(ZRDN_PATH, 2)."/languages/plugins/";
142 if (!file_exists($path)) return;
143
144 $extensions = array("po", "mo");
145 if ($handle = opendir($path)) {
146 while (false !== ($file = readdir($handle))) {
147 if ($file != "." && $file != "..") {
148 $file = $path . '/' . $file;
149 $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
150 if (is_file($file) && in_array($ext, $extensions) && strpos($file, 'zip-recipes')!==FALSE && strpos($file, 'backup')===FALSE) {
151 //copy to new file
152 $new_name = str_replace('zip-recipes','zip-recipes-backup',$file);
153
154 rename($file, $new_name);
155 }
156 }
157 }
158 closedir($handle);
159 }
160 }
161 }
162
163 /**
164 * Load iframe has to hook into admin init, otherwise languages are not loaded yet.
165 *
166 * */
167 if (!function_exists(__NAMESPACE__ . '\zrdn_maybe_load_iframe')) {
168 function zrdn_maybe_load_iframe()
169 {
170 // Setup query catch for recipe insertion popup.
171 if (strpos($_SERVER['REQUEST_URI'], 'media-upload.php') && strpos($_SERVER['REQUEST_URI'], '&type=z_recipe') && !strpos($_SERVER['REQUEST_URI'], '&wrt=')) {
172 // pluggable.php is needed for current_user_can
173 require_once(ABSPATH . 'wp-includes/pluggable.php');
174
175 // user is logged in and can edit posts or pages
176 if (\current_user_can('edit_posts') || \current_user_can('edit_pages')) {
177 $get_info = $_REQUEST;
178 $post_id = isset($get_info["post_id"]) ? intval($get_info["post_id"]) : 0;
179
180 if (isset($get_info["recipe_post_id"]) &&
181 !isset($get_info["add-recipe-button"]) &&
182 strpos($get_info["recipe_post_id"], '-') !== false
183 ) { // EDIT recipe
184 $recipe_id = preg_replace('/[0-9]*?\-/i', '', $get_info["recipe_post_id"]);
185 wp_redirect(add_query_arg(array("page"=>"zrdn-recipes","action"=>"new","id"=>$recipe_id, "post_id" => $post_id,"popup"=>true),admin_url("admin.php")));
186
187 } else { // New recipe
188 wp_redirect(add_query_arg(array("page"=>"zrdn-recipes","action"=>"new", "post_id" => $post_id,"popup"=>true),admin_url("admin.php")));
189 }
190 }
191 exit;
192 }
193 }
194 add_action('admin_init', __NAMESPACE__ . '\zrdn_maybe_load_iframe', 30);
195 }
196
197 if ( ! function_exists( __NAMESPACE__ . '\zrdn_start_tour' ) ) {
198 /**
199 * Start the tour of the plugin on activation
200 */
201 function zrdn_start_tour() {
202 if ( ! get_site_option( 'zrdn_tour_shown_once' ) ) {
203 update_site_option( 'zrdn_tour_started', true );
204 }
205 }
206
207 register_activation_hook( __FILE__, __NAMESPACE__ . '\zrdn_start_tour' );
208 }
209