PluginProbe
Zotpress / 7.3.9
Zotpress v7.3.9
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.9, at zotpress.php

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