PluginProbe
Zotpress / 7.3.7
Zotpress v7.3.7
7.4.4 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 2.0 2.1 2.2 2.3 2.4 2.5 2.5.1 2.5.2 2.6 2.6.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 All 138 releases
zotpress / zotpress.php

zotpress.php in Zotpress 7.3.7, at zotpress.php

484 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4
5 Plugin Name: Zotpress
6 Plugin URI: http://katieseaborn.com/plugins
7 Description: Bringing Zotero and scholarly blogging to your WordPress website.
8 Author: Katie Seaborn
9 Version: 7.3.7
10 Author URI: http://katieseaborn.com
11 Text Domain: zotpress
12 Domain Path: /languages/
13
14 */
15
16 /*
17
18 Copyright 2023 Katie Seaborn
19
20 Licensed under the Apache License, Version 2.0 (the "License");
21 you may not use this file except in compliance with the License.
22 You may obtain a copy of the License at
23
24 http://www.apache.org/licenses/LICENSE-2.0
25
26 Unless required by applicable law or agreed to in writing, software
27 distributed under the License is distributed on an "AS IS" BASIS,
28 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 See the License for the specific language governing permissions and
30 limitations under the License.
31
32 */
33
34
35 // DESIGN ---------------------------------------------------------------------------------------
36 /*
37
38 For requests:
39
40 - Check the database for cached items with PHP:
41 - If using the cache, indicate with `used_cache` class
42 - If no cache, switch to JS and save to cache
43 - Format with JS
44 - Check for updates with JS
45 - Format again with JS
46
47 To-do:
48 * Zotero-API-Key` rather than `key=`.
49 * qmode=titleCreatorYear&q=2000,2001 -> v3 doesn't work
50 * multiple itemtype
51
52 */
53 // DESIGN ---------------------------------------------------------------------------------------
54
55
56
57 // GLOBAL VARS ----------------------------------------------------------------------------------
58
59 define('ZOTPRESS_PLUGIN_FILE', __FILE__ );
60 define('ZOTPRESS_PLUGIN_URL', plugin_dir_url( ZOTPRESS_PLUGIN_FILE ));
61 define('ZOTPRESS_PLUGIN_DIR', dirname( __FILE__ ));
62 define('ZOTPRESS_VERSION', '7.3.7' );
63 define('ZOTPRESS_LIVEMODE', true ); // NOTE: Remember to set to TRUE
64
65 $GLOBALS['zp_is_shortcode_displayed'] = false;
66 $GLOBALS['zp_shortcode_instances'] = array();
67
68 $GLOBALS['Zotpress_update_db_by_version'] = '7.1.4'; // NOTE: Only change if the db needs updating - 5.2.6
69
70 // GLOBAL VARS ----------------------------------------------------------------------------------
71
72
73
74 // LOCALIZATION ----------------------------------------------------------------------------------
75
76 // TODO: Apply localization to the entire plugin.
77 // TODO: Don't forget JS files, which have a special procedure.
78
79 function Zotpress_load_plugin_textdomain() {
80 load_plugin_textdomain( 'zotpress', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
81 }
82 add_action( 'plugins_loaded', 'Zotpress_load_plugin_textdomain' );
83
84 // LOCALIZATION ----------------------------------------------------------------------------------
85
86
87
88 // INSTALL -----------------------------------------------------------------------------------------
89
90 include( dirname(__FILE__) . '/lib/admin/admin.install.php' );
91
92 // INSTALL -----------------------------------------------------------------------------------------
93
94
95
96 // ADMIN -------------------------------------------------------------------------------------------
97
98 include( dirname(__FILE__) . '/lib/admin/admin.php' );
99
100 add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'zotpress_add_plugin_page_settings_link');
101 function zotpress_add_plugin_page_settings_link( $links ) {
102 $links[] = '<a href="' .
103 admin_url( 'admin.php?page=Zotpress' ) .
104 '">' . __('Explore','zotpress') . '</a>';
105 return $links;
106 }
107
108 // END ADMIN --------------------------------------------------------------------------------------
109
110
111
112 // SHORTCODE -------------------------------------------------------------------------------------
113
114 include( dirname(__FILE__) . '/lib/shortcode/shortcode.php' );
115 include( dirname(__FILE__) . '/lib/shortcode/shortcode.intext.php' );
116 include( dirname(__FILE__) . '/lib/shortcode/shortcode.intextbib.php' );
117 include( dirname(__FILE__) . '/lib/shortcode/shortcode.lib.php' );
118
119 // SHORTCODE -------------------------------------------------------------------------------------
120
121
122
123 // WIDGET & METABOX -----------------------------------------------------------------------------
124
125 include( dirname(__FILE__) . '/lib/widget/widget.sidebar.php' );
126 include( dirname(__FILE__) . '/lib/widget/widget.php' );
127
128 function Zotpress_format_script_register()
129 {
130 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
131
132 wp_register_script(
133 'zotpress.gutenberg'.$minify.'.js',
134 ZOTPRESS_PLUGIN_URL . 'js/zotpress.gutenberg'.$minify.'.js',
135 array( 'wp-rich-text', 'wp-element', 'wp-editor', 'jquery' )
136 );
137 }
138 add_action( 'init', 'Zotpress_format_script_register' );
139
140 function Zotpress_format_enqueue_assets_editor()
141 {
142 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
143
144 wp_enqueue_script( 'jquery' );
145 wp_enqueue_script( 'zotpress.gutenberg'.$minify.'.js' );
146 wp_localize_script(
147 'zotpress.gutenberg'.$minify.'.js',
148 'zpTranslate',
149 array(
150 'txt_insertsc' => __('Insert Shortcode','zotpress'),
151 'txt_generatesc' => __('Generate Shortcode','zotpress')
152 )
153 );
154 }
155 add_action( 'enqueue_block_editor_assets', 'Zotpress_format_enqueue_assets_editor' );
156
157 // WIDGET & METABOX -----------------------------------------------------------------------------
158
159
160
161 // REGISTER ACTIONS -----------------------------------------------------------------------------
162
163 /**
164 * Admin scripts and styles
165 */
166 function Zotpress_admin_scripts_css($hook)
167 {
168 // Turn on/off minified versions if testing/live
169 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
170
171 if ( isset($_GET['page']) && ($_GET['page'] == 'Zotpress') )
172 {
173 wp_enqueue_script( 'jquery' );
174 wp_enqueue_media();
175 wp_enqueue_script( 'jquery.dotimeout.min.js', ZOTPRESS_PLUGIN_URL . 'js/jquery.dotimeout.min.js', array( 'jquery' ) );
176
177 if ( !in_array( $hook, array('post.php', 'post-new.php') ) )
178 {
179 wp_enqueue_script( 'jquery.livequery.min.js', ZOTPRESS_PLUGIN_URL . 'js/jquery.livequery.min.js', array( 'jquery' ) );
180 }
181
182 if ( isset($_GET['help']) && ($_GET['help'] == 'true') )
183 {
184 wp_enqueue_script( 'jquery-ui-core' );
185 wp_enqueue_script( 'jquery-ui-tabs' );
186 wp_enqueue_style( 'zotpress.help'.$minify.'.css', ZOTPRESS_PLUGIN_URL . 'css/zotpress.help'.$minify.'.css' );
187 wp_enqueue_script( 'zotpress.help.min.js', ZOTPRESS_PLUGIN_URL . 'js/zotpress.help.min.js', array( 'jquery' ) );
188 }
189
190 wp_enqueue_style( 'zotpress.shortcode'.$minify.'.css', ZOTPRESS_PLUGIN_URL . 'css/zotpress.shortcode'.$minify.'.css' );
191 wp_enqueue_style( 'zotpress.admin'.$minify.'.css', ZOTPRESS_PLUGIN_URL . 'css/zotpress.admin'.$minify.'.css' );
192 }
193 }
194 add_action( 'admin_enqueue_scripts', 'Zotpress_admin_scripts_css' );
195
196
197 function Zotpress_enqueue_admin_ajax( $hook )
198 {
199 // Turn on/off minified versions if testing/live
200 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
201
202 if ( stripos( $hook, "zotpress" ) !== false )
203 {
204 wp_enqueue_script( 'zotpress.admin'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.admin'.$minify.'.js', array( 'jquery','media-upload','thickbox' ) );
205 wp_localize_script(
206 'zotpress.admin'.$minify.'.js',
207 'zpAccountsAJAX',
208 array(
209 'ajaxurl' => admin_url( 'admin-ajax.php' ),
210 'zpAccountsAJAX_nonce' => wp_create_nonce( 'zpAccountsAJAX_nonce_val' ),
211 'action' => 'zpAccountsViaAJAX',
212 'txt_success' => __('Success','zotpress'),
213 'txt_chooseimg' => __('Choose Image','zotpress'),
214 'txt_accvalid' => __('Your Zotero account has been validated.','zotpress'),
215 'txt_sureremove' => __('Are you sure you want to remove this account?','zotpress'),
216 'txt_surecache' => __('Are you sure you want to clear the cache for this account?','zotpress'),
217 'txt_cachecleared' => __('Cache cleared!','zotpress'),
218 'txt_oops' => __('Oops!','zotpress'),
219 'txt_changeimg' => __( 'Change Image', 'zotpress' ),
220 'txt_setimg' => __( 'Set Image', 'zotpress' ),
221 'txt_removeimg' => __( 'Remove Image', 'zotpress' ),
222 'txt_surereset' => __('Are you sure you want to reset Zotpress? This cannot be undone.','zotpress'),
223 'txt_default' => __('Default','zotpress')
224 )
225 );
226 } // Zotpress pages only
227
228 wp_enqueue_script( 'zotpress.admin.notices'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.admin.notices'.$minify.'.js', array( 'jquery' ) );
229 wp_localize_script(
230 'zotpress.admin.notices'.$minify.'.js',
231 'zpNoticesAJAX',
232 array(
233 'ajaxurl' => admin_url( 'admin-ajax.php' ),
234 'zpNoticesAJAX_nonce' => wp_create_nonce( 'zpNoticesAJAX_nonce_val' ),
235 'action' => 'zpNoticesViaAJAX'
236 )
237 );
238 }
239 add_action( 'admin_enqueue_scripts', 'Zotpress_enqueue_admin_ajax' );
240
241
242 /**
243 * Add Zotpress to admin menu
244 */
245 function Zotpress_admin_menu()
246 {
247 add_menu_page( "Zotpress", "Zotpress", "edit_posts", "Zotpress", "Zotpress_options", ZOTPRESS_PLUGIN_URL."images/icon-menu.svg" );
248 add_submenu_page( "Zotpress", "Zotpress", __('Browse','zotpress'), "edit_posts", "Zotpress" );
249 add_submenu_page( "Zotpress", "Accounts", __('Accounts','zotpress'), "edit_posts", "admin.php?page=Zotpress&accounts=true" );
250 add_submenu_page( "Zotpress", "Options", __('Options','zotpress'), "edit_posts", "admin.php?page=Zotpress&options=true" );
251 add_submenu_page( "Zotpress", "Help", __('Help','zotpress'), "edit_posts", "admin.php?page=Zotpress&help=true" );
252 }
253 add_action( 'admin_menu', 'Zotpress_admin_menu' );
254
255 function Zotpress_admin_menu_submenu($parent_file)
256 {
257 global $submenu_file;
258
259 if ( isset($_GET['accounts']) || isset($_GET['selective']) || isset($_GET['import']) ) $submenu_file = 'admin.php?page=Zotpress&accounts=true';
260 if ( isset($_GET['options']) ) $submenu_file = 'admin.php?page=Zotpress&options=true';
261 if ( isset($_GET['help']) ) $submenu_file = 'admin.php?page=Zotpress&help=true';
262
263 return $parent_file;
264 }
265 add_filter('parent_file', 'Zotpress_admin_menu_submenu');
266
267
268 /**
269 * Add shortcode styles to user's theme
270 * Note that this always displays: There's no way to conditionally include it,
271 * because the existence of shortcodes is checked after CSS is included.
272 */
273 function Zotpress_theme_includes()
274 {
275 // Turn on/off minified versions if testing/live
276 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
277
278 wp_register_style('zotpress.shortcode'.$minify.'.css', ZOTPRESS_PLUGIN_URL . 'css/zotpress.shortcode'.$minify.'.css');
279 wp_enqueue_style('zotpress.shortcode'.$minify.'.css');
280 }
281 add_action('wp_print_styles', 'Zotpress_theme_includes');
282
283
284 /**
285 * Change HTTP request timeout
286 * Changed in 7.3.7
287 */
288 // function Zotpress_change_timeout($time): int { return 60; /* second */ }
289 function Zotpress_change_timeout($time) { return 60; /* second */ }
290 add_filter('http_request_timeout', 'Zotpress_change_timeout');
291
292
293
294 // Enqueue jQuery in theme if it isn't already enqueued
295 // Thanks to WordPress user "eceleste"
296 function Zotpress_enqueue_scripts()
297 {
298 if ( ! isset( $GLOBALS['wp_scripts']->registered[ "jquery" ] ) )
299 wp_enqueue_script("jquery");
300 }
301 add_action( 'wp_enqueue_scripts' , 'Zotpress_enqueue_scripts' );
302
303 // Add shortcodes and sidebar widget
304 add_shortcode( 'zotpress', 'Zotpress_func' );
305 add_shortcode( 'zotpressInText', 'Zotpress_zotpressInText' );
306 add_shortcode( 'zotpressInTextBib', 'Zotpress_zotpressInTextBib' );
307 add_shortcode( 'zotpressLib', 'Zotpress_zotpressLib' );
308 add_action( 'widgets_init', 'ZotpressSidebarWidgetInit' );
309
310 // Conditionally serve shortcode scripts
311 function Zotpress_theme_conditional_scripts_footer()
312 {
313 // Turn on/off minified versions if testing/live
314 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
315
316 if ( $GLOBALS['zp_is_shortcode_displayed'] === true )
317 {
318 if ( ! is_admin() ) wp_enqueue_script('jquery');
319 wp_register_script('jquery.livequery.min.js', ZOTPRESS_PLUGIN_URL . 'js/jquery.livequery.min.js', array('jquery'));
320 wp_enqueue_script('jquery.livequery.min.js');
321
322 wp_enqueue_script("jquery-effects-core");
323 wp_enqueue_script("jquery-effects-highlight");
324
325 wp_enqueue_script( 'zotpress.default'.$minify.'.js', ZOTPRESS_PLUGIN_URL . 'js/zotpress.default'.$minify.'.js', array( 'jquery' ) );
326 }
327 }
328 add_action('wp_footer', 'Zotpress_theme_conditional_scripts_footer');
329
330
331 function Zotpress_enqueue_shortcode_bib()
332 {
333 // Turn on/off minified versions if testing/live
334 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
335
336 wp_register_script( 'zotpress.shortcode.bib'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.shortcode.bib'.$minify.'.js', array( 'jquery' ), false, true );
337 wp_localize_script(
338 'zotpress.shortcode.bib'.$minify.'.js',
339 'zpShortcodeAJAX',
340 array(
341 'ajaxurl' => admin_url( 'admin-ajax.php' ),
342 'zpShortcode_nonce' => wp_create_nonce( 'zpShortcode_nonce_val' ),
343 'action' => 'zpRetrieveViaShortcode',
344 'txt_removeimg' => __('Remove Image', 'zotpress'),
345 'txt_zperror' => __('There was a Zotpress error:', 'zotpress'),
346 'txt_noitemsfound' => __( 'No items found.', 'zotpress' )
347 )
348 );
349 }
350 add_action( 'wp_enqueue_scripts', 'Zotpress_enqueue_shortcode_bib' );
351
352
353 function Zotpress_enqueue_shortcode_intext()
354 {
355 // Turn on/off minified versions if testing/live
356 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
357
358 wp_register_script( 'zotpress.shortcode.intext'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.shortcode.intext'.$minify.'.js', array( 'jquery' ), false, true );
359 wp_localize_script(
360 'zotpress.shortcode.intext'.$minify.'.js',
361 'zpShortcodeAJAX',
362 array(
363 'ajaxurl' => admin_url( 'admin-ajax.php' ),
364 'zpShortcode_nonce' => wp_create_nonce( 'zpShortcode_nonce_val' ),
365 'action' => 'zpRetrieveViaShortcode',
366 'txt_zperror' => __('There was a Zotpress error:', 'zotpress'),
367 'txt_noitemsfound' => __( 'No items found.', 'zotpress' )
368 )
369 );
370 }
371 add_action( 'wp_enqueue_scripts', 'Zotpress_enqueue_shortcode_intext' );
372
373
374 function Zotpress_enqueue_lib_dropdown()
375 {
376 // Turn on/off minified versions if testing/live
377 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
378
379 wp_register_script( 'zotpress.lib'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.lib'.$minify.'.js', array( 'jquery' ), false, true );
380 wp_register_script( 'zotpress.lib.dropdown'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.lib.dropdown'.$minify.'.js', array( 'jquery' ), false, true );
381 wp_localize_script(
382 'zotpress.lib.dropdown'.$minify.'.js',
383 'zpShortcodeAJAX',
384 array(
385 'ajaxurl' => admin_url( 'admin-ajax.php' ),
386 'zpShortcode_nonce' => wp_create_nonce( 'zpShortcode_nonce_val' ),
387 'action' => 'zpRetrieveViaShortcode',
388 'txt_loading' => __( 'Loading', 'zotpress' ),
389 'txt_items' => __( 'items', 'zotpress' ),
390 'txt_subcoll' => __( 'subcollections', 'zotpress' ),
391 'txt_changeimg' => __( 'Change Image', 'zotpress' ),
392 'txt_setimg' => __( 'Set Image', 'zotpress' ),
393 'txt_itemkey' => __( 'Item Key', 'zotpress' ),
394 'txt_nocitations' => __( 'There are no citations to display.', 'zotpress' ),
395 'txt_toplevel' => __( 'Top Level', 'zotpress' ),
396 'txt_nocollsel' => __( 'No Collection Selected', 'zotpress' ),
397 'txt_backtotop' => __( 'Back', 'zotpress' ),
398 'txt_unsettag' => __( 'Unset Tag', 'zotpress' ),
399 'txt_notagsel' => __( 'No Tag Selected', 'zotpress' ),
400 'txt_notags' => __( 'No tags to display', 'zotpress' )
401 )
402 );
403 }
404 add_action( 'wp_enqueue_scripts', 'Zotpress_enqueue_lib_dropdown' );
405 add_action( 'admin_enqueue_scripts', 'Zotpress_enqueue_lib_dropdown' );
406
407
408 function Zotpress_enqueue_lib_searchbar()
409 {
410 // Turn on/off minified versions if testing/live
411 $minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min';
412
413 wp_register_script( 'zotpress.lib'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.lib'.$minify.'.js', array( 'jquery' ), false, true );
414 wp_register_script( 'zotpress.lib.searchbar'.$minify.'.js', plugin_dir_url( __FILE__ ) . 'js/zotpress.lib.searchbar'.$minify.'.js', array( 'jquery' ), false, true );
415 wp_localize_script(
416 'zotpress.lib.searchbar'.$minify.'.js',
417 'zpShortcodeAJAX',
418 array(
419 'ajaxurl' => admin_url( 'admin-ajax.php' ),
420 'zpShortcode_nonce' => wp_create_nonce( 'zpShortcode_nonce_val' ),
421 'action' => 'zpRetrieveViaShortcode',
422 'txt_typetosearch' => __('Type to search','zotpress')
423 )
424 );
425 }
426 add_action( 'wp_enqueue_scripts', 'Zotpress_enqueue_lib_searchbar' );
427 add_action( 'admin_enqueue_scripts', 'Zotpress_enqueue_lib_searchbar' );
428
429 // REGISTER ACTIONS --------------------------------------------------------------------------------
430
431
432 // SECURITY ----------------------------------------------------------------------------------------
433
434 function zp_nonce_life() {
435 return 24 * HOUR_IN_SECONDS;
436 }
437 add_filter( 'nonce_life', 'zp_nonce_life' );
438
439 // SECURITY ----------------------------------------------------------------------------------------
440
441
442 // ZOTPRESS NOTIFICATIONS ------------------------------------------------------------------------
443
444 if ( in_array( ZOTPRESS_VERSION, array( "6.2.1", "6.2.2", "7.1.1", "7.1.2", "7.1.3", "7.1.4" ) ) )
445 {
446 function Zotpress_plugin_update_message( $data, $response ) {
447 printf(
448 '<span style="display:block;font-weight:bold;margin:0.7em 0;"><span class="dashicons dashicons-warning" style="margin-right:6px;"></span>%s</span>',
449 __( 'Be sure to clear the Zotpress cache for each account after updating!', 'zotpress' )
450 );
451 }
452 add_action( 'in_plugin_update_message-zotpress/zotpress.php', 'Zotpress_plugin_update_message', 10, 2 );
453 }
454
455 if ( in_array( ZOTPRESS_VERSION, array( "6.2.1", "6.2.2", "7.1.4" ) ) )
456 {
457 if ( zp_get_total_accounts() > 0
458 && ! get_option( 'Zotpress_update_notice_dismissed' ) )
459 add_action( 'admin_notices', 'Zotpress_update_notice' );
460
461 function Zotpress_update_notice()
462 {
463 ?>
464 <div class="notice update-nag Zotpress_update_notice is-dismissible" >
465 <p><?php echo __( '<strong>Warning:</strong> Due to major updates in this version of Zotpress, you may need to clear the cache of each synced Zotero account.', 'zotpress' ); ?></p>
466 <p>&raquo; <a href="admin.php?page=Zotpress&accounts=true"><?php echo __( 'Acccounts'); ?></a></p>
467 </div>
468 <?php
469 }
470
471 function Zotpress_dismiss_update_notice()
472 {
473 if ( ! get_option( 'Zotpress_update_notice_dismissed' )
474 || get_option( 'Zotpress_update_notice_dismissed' ) == 0 )
475 update_option( 'Zotpress_update_notice_dismissed', 1 );
476 }
477 add_action( 'wp_ajax_zpNoticesViaAJAX', 'Zotpress_dismiss_update_notice' );
478 }
479
480 // ZOTPRESS NOTIFICATIONS ------------------------------------------------------------------------
481
482
483 ?>
484