PluginProbe
Zotpress / trunk
Zotpress vtrunk
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 / lib / shortcode / shortcode.functions.php

shortcode.functions.php in Zotpress trunk, at lib/shortcode/shortcode.functions.php

1,228 lines 40.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
3
4 /**
5 * Removes all extra quotations.
6 *
7 * Used by: Shortcodes
8 *
9 * @param str $param The shortcode parameter to clean.
10 *
11 * @return str $clean_param The clean parameter.
12 */
13 function zotpress_clean_param( $param ) {
14
15 // Thanks to Emerson@StackOverflow
16 $search = array(
17 '&#8220;', // 1. Left Double Quotation Mark “
18 '',
19 '&#8221;', // 2. Right Double Quotation Mark ”
20 '',
21 '&#8216;', // 3. Left Single Quotation Mark ‘
22 '',
23 '&#8217;', // 4. Right Single Quotation Mark ’
24 '',
25 // NOTE: We need apostrophes (single quotes) for tags and ...?
26 // '&#039;', // 5. Normal Single Quotation Mark '
27 '&amp;', // 6. Ampersand &
28 '&quot;', // 7. Normal Double Qoute
29 '&lt;', // 8. Less Than <
30 '&gt;' // 9. Greater Than >
31 );
32
33 // Fix the String
34 $clean_param = htmlspecialchars( $param, ENT_QUOTES );
35
36 return str_replace( $search, "", $clean_param );
37 }
38
39
40 /**
41 * Gets the year from a date.
42 *
43 * Used by: In-Text Shortcode, In-Text Bibliography Shortcode
44 *
45 * @param str $date The date to search in.
46 * @param bol $yesnd Return with a "n.d." if no year found.
47 *
48 * @return str $date_return The year found or blank/n.d. if not found.
49 */
50 function zotpress_get_year( $date, $yesnd=false ) {
51
52 $date_return = false;
53
54 preg_match_all( '/(\d{4})/', $date, $matches );
55
56 if (is_null($matches[0][0]))
57 $date_return = $yesnd === true ? "n.d." : "";
58 else
59 $date_return = $matches[0][0];
60
61 return $date_return;
62 }
63
64
65 /**
66 * Sorts by a secondary value.
67 *
68 * Used by: Bibliography Shortcode, In-Text Bibliography Shortcode
69 *
70 * @param arr $item_arr The date to format.
71 * @param str $sortby What attribute to sort by.
72 * @param str $order What is the order (direction of the sort): ASC, DESC.
73 *
74 * @return arr $item_arr The newly sorted array of items.
75 */
76 function zotpress_subval_sort( $item_arr, $sortby, $order ) {
77
78 // Format sort order
79 $order = strtolower($order) == "desc" ? SORT_DESC : SORT_ASC;
80
81 // Author or date
82 if ( $sortby == "author"
83 || $sortby == "date" ) {
84
85 foreach ( $item_arr as $key => $val ) {
86
87 $author[$key] = $val["author"];
88
89 $zpdate = ""; $zpdate = isset( $val["zpdate"] ) ? $val["zpdate"] : $val["date"];
90
91 $date[$key] = zotpress_date_format($zpdate);
92 }
93
94 } elseif ( $sortby == "title" ) {
95
96 foreach ( $item_arr as $key => $val ) {
97
98 $title[$key] = $val["title"];
99 $author[$key] = $val["author"];
100 }
101 }
102
103 // NOTE: array_multisort seems to be ignoring second sort for date->author
104 if ( $sortby == "author" && isset($author) && is_array($author) )
105 array_multisort( $author, $order, $date, $order, $item_arr );
106 elseif ( $sortby == "date" && isset($date) && is_array($date) )
107 array_multisort( $date, $order, $author, SORT_ASC, $item_arr );
108 elseif ( $sortby == "title" && isset($title) && is_array($title) )
109 array_multisort( $title, $order, $author, $order, $item_arr );
110
111 return $item_arr;
112 }
113
114
115 /**
116 * Reformats the date in a standard format: yyyy-mm-dd.
117 *
118 * Can read the following:
119 * - yyyy/mm/dd, mm/dd/yyyy
120 * - the dash equivalents of the above
121 * - mmmm dd, yyyy
122 * - yyyy mmmm, yyyy mmm (and the reverse)
123 * - mm-mm yyyy
124 *
125 * Used by: zotpress_subval_sort
126 *
127 * @param str $date The date to format.
128 *
129 * @return str The formatted date, or the original if formatting fails.
130 */
131 function zotpress_date_format ($date) {
132
133 // Set up search lists
134 $list_month_long = array ( "01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December" );
135 $list_month_short = array ( "01" => "Jan", "02" => "Feb", "03" => "Mar", "04" => "Apr", "05" => "May", "06" => "Jun", "07" => "Jul", "08" => "Aug", "09" => "Sept", "10" => "Oct", "11" => "Nov", "12" => "Dec" );
136
137
138 // Check if it's a mm-mm dash
139 if ( preg_match("/^[a-zA-Z]+[-][a-zA-Z]+[ ]\\d+\$/", $date ) == 1) {
140
141 $temp1 = preg_split( "/-|\//", $date );
142 $temp2 = preg_split( "[\s]", $temp1[1] );
143
144 $date = $temp1[0]." ".$temp2[1];
145 }
146
147 // If it's already formatted with a dash or forward slash
148 if ( strpos( $date, "-" ) !== false
149 || strpos( $date, "/" ) !== false ) {
150
151 // Break it up
152 $temp = preg_split( "/-|\//", $date );
153
154 // If year is last, switch it with first
155 if ( strlen($temp[0]) != 4 ) {
156
157 // Just month and year
158 if ( count($temp) == 2 )
159 $date_formatted = array(
160 "year" => $temp[1],
161 "month" => $temp[0],
162 "day" => false
163 );
164 // Assuming mm dd yyyy
165 else
166 $date_formatted = array(
167 "year" => $temp[2],
168 "month" => $temp[0],
169 "day" => $temp[1]
170 );
171
172 } elseif ( isset($temp[2]) ) {
173
174 // day is set
175 $date_formatted = array(
176 "year" => $temp[0],
177 "month" => $temp[1],
178 "day" => $temp[2]
179 );
180
181 } else {
182
183 $date_formatted = array(
184 "year" => $temp[0],
185 "month" => $temp[1],
186 "day" => false
187 );
188 }
189
190 } elseif ( strpos( $date, "," ) ) {
191
192 $date = trim( str_replace( ", ", ",", $date ) );
193 $temp = preg_split( "/,| /", $date );
194
195 // Convert month
196 $month = array_search( $temp[0], $list_month_long );
197 if ( ! $month )
198 $month = array_search( $temp[0], $list_month_short );
199
200 $date_formatted = array(
201 "year" => $temp[2],
202 "month" => $month,
203 "day" => $temp[1]
204 );
205
206 } else {
207
208 $date = trim( str_replace( " ", "-", $date ) );
209 $temp = explode ( " ", $date );
210
211 // If there's at least two parts to the date
212 if ( $temp !== [] ) {
213
214 // Check if name is first
215 if ( ! is_numeric($temp[0]) ) {
216
217 if ( in_array($temp[0], $list_month_long) ) {
218
219 $date_formatted = array(
220 "year" => $temp[1],
221 "month" => array_search( $temp[0], $list_month_long ),
222 "day" => false
223 );
224
225 } elseif ( in_array($temp[0], $list_month_short) ) {
226
227 $date_formatted = array(
228 "year" => $temp[1],
229 "month" => array_search( $temp[0], $list_month_short ),
230 "day" => false
231 );
232
233 } else // Not a recognizable month word
234
235 $date_formatted = array(
236 "year" => $temp[0], // $temp[1]
237 "month" => false,
238 "day" => false
239 );
240
241 } elseif ( count($temp) > 1 ) {
242
243 if ( in_array($temp[1], $list_month_long) ) {
244
245 $date_formatted = array(
246 "year" => $temp[0],
247 "month" => array_search( $temp[1], $list_month_long ),
248 "day" => false
249 );
250
251 } elseif ( in_array($temp[1], $list_month_short) ) {
252
253 $date_formatted = array(
254 "year" => $temp[0],
255 "month" => array_search( $temp[1], $list_month_short ),
256 "day" => false
257 );
258
259 } else // Not a recognizable month word
260
261 $date_formatted = array(
262 "year" => $temp[0],
263 "month" => false,
264 "day" => false
265 );
266
267 } else { // Only one part in the array
268
269 $date_formatted = array(
270 "year" => $temp[0],
271 "month" => false,
272 "day" => false
273 );
274 }
275 }
276
277 // Otherwise, assume year
278 else
279 {
280 $date_formatted = array(
281 "year" => $temp[0],
282 "month" => false,
283 "day" => false
284 );
285 }
286 }
287
288 // Format date in standard form: yyyy-mm-dd
289 $date_formatted = implode( "-", array_filter( $date_formatted ) );
290
291 if ( ! isset($date_formatted) )
292 $date_formatted = $date;
293
294 return $date_formatted;
295 }
296
297
298 /**
299 * Processes the WP AJAX Zotero request variables.
300 * We need to make sure user input is checked.
301 * For complex strings inc. non-English chars: wp_strip_all_tags()
302 * For all else: sanitize_text_field()
303 *
304 * Used by: shortcode.php, shortcode.intextbib.php
305 *
306 * @param obj $wpdb WP DB object.
307 * @param arr Shortcode attributes.
308 * @param bool Whether library shortcode or not.
309 *
310 * @return string Array with the processed variables.
311 */
312 function Zotpress_prep_ajax_request_vars($wpdb, $atts=false, $is_zplib=false) {
313
314 $zpr = array();
315
316 // Deal with empty atts, assume $_GET
317 if ( $atts === false )
318 $atts = $_GET;
319
320 $zpr["api_user_id"] = false;
321 if ( isset($atts['api_user_id']) && $atts['api_user_id'] !== false )
322 $zpr["api_user_id"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['api_user_id'] )));
323 elseif ( isset($atts['user_id']) && $atts['user_id'] !== false )
324 $zpr["api_user_id"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['user_id'] )));
325 elseif ( isset($atts['userid']) && $atts['userid'] !== false )
326 $zpr["api_user_id"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['userid'] )));
327 // 7.4: Unofficial re-support of user
328 elseif ( isset($atts['user']) && $atts['user'] !== false )
329 $zpr["api_user_id"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['user'] )));
330
331 // 7.3.13: We don't want to set a default at this stage ...
332 // // 7.3.12: Did something change with how WP hands shortcode atts? Doesn't remember defaults
333 // if ( get_option("Zotpress_DefaultAccount") !== false ) {
334
335 // $zpr["api_user_id"] = get_option("Zotpress_DefaultAccount");
336 // }
337 // else { // When all else fails ... assume one account
338
339 // $zp_account_temp = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress LIMIT 1", OBJECT);
340 // $zpr["api_user_id"] = $zp_account_temp->api_user_id;
341 // unset($zp_account_temp);
342 // }
343
344 $zpr['nickname'] = false;
345 if ( isset($atts['nickname']) && $atts['nickname'] !== false )
346 $zpr["nickname"] = zotpress_clean_param(zotpress_clean_param( $atts['nickname'] ));
347 else if ( isset($atts['nick']) && $atts['nick'] !== false )
348 $zpr["nickname"] = zotpress_clean_param(zotpress_clean_param( $atts['nick'] ));
349
350 $zpr["limit"] = 50; // max 100, 22 seconds
351 $zpr["overwrite_request"] = false;
352 $zpr["overwrite_last_request"] = false;
353
354 // Deal with incoming variables
355 // 7.3.9: Added sanitize_text_field()
356 // 7.3.10: Added wp_strip_all_tags()
357 // 7.3.11: Account for ZotpressLib
358 if ( ! $is_zplib ) {
359
360 $zpr["type"] = "basic";
361 if ( isset($atts['type'])
362 && $atts['type'] != "" )
363 $zpr["type"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['type'])));
364 else
365 $zpr["type"] = "basic";
366
367 // Deal with ZotpressLib
368 } else {
369
370 $zpr["type"] = "dropdown";
371 if ( isset($atts['type'])
372 && $atts['type'] != "" )
373 $zpr["type"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['type'])));
374 }
375
376 $zpr["item_type"] = "items";
377 if ( isset($atts['item_type'])
378 && $atts['item_type'] != "" )
379 $zpr["item_type"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['item_type'])));
380
381 $zpr["get_top"] = false;
382 if ( isset($atts['get_top']) ) $zpr["get_top"] = true;
383
384 $zpr["sub"] = false;
385
386 $zpr["is_dropdown"] = false;
387 if ( isset($atts['is_dropdown'])
388 && $atts['is_dropdown'] == "true" )
389 $zpr["is_dropdown"] = true;
390
391 $zpr["update"] = false;
392 if ( isset($atts['update'])
393 && $atts['update'] == "true" )
394 $zpr["update"] = true;
395
396 $zpr["updateneeded"] = false;
397 if ( isset($atts['updateneeded'])
398 && $atts['updateneeded'] == "true" )
399 $zpr["updateneeded"] = true;
400
401 $zpr["request_update"] = false;
402 if ( isset($atts['request_update'])
403 && $atts['request_update'] == "true" )
404 $zpr["request_update"] = true;
405
406 // instance id, item key, collection id, tag id
407 $zpr["instance_id"] = false;
408 if ( isset($atts['instance_id']) )
409 $zpr["instance_id"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['instance_id'])));
410
411 $zpr["item_key"] = false;
412 if ( isset($atts['item_key'])
413 && ( $atts['item_key'] != "false" && $atts['item_key'] !== false ) )
414 $zpr["item_key"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['item_key'])));
415 elseif ( isset($atts['items'])
416 && ( $atts['items'] != "false" && $atts['items'] !== false ) )
417 $zpr["item_key"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['items'])));
418 elseif ( isset($atts['item'])
419 && ( $atts['item'] != "false" && $atts['item'] !== false ) )
420 $zpr["item_key"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['item'])));
421
422 // Deal with multiple items
423 // if ( strpos($zpr["item_key"], ", ") > 0 )
424 if ( strpos($zpr["item_key"], ", ") !== false )
425 $zpr["item_key"] = str_replace(', ', ',', $zpr["item_key"]); // remove spces after commas
426 // $item_key = str_replace(" ", "", $item_key ); // remove any spaces ... not needed?
427
428
429 // REVIEW: Make sure item_key is formatting in the new style
430 //
431 // BIB FORMATS:
432 // [zotpress item="GMGCJU34"]
433 // [zotpress items="GMGCJU34,U9Z5JTKC"]
434
435 // 7.3.13: Not sure why there's a : added ...
436 if ( strpos($zpr["item_key"], "{:") !== false ) {
437 $zpr["item_key"] = str_replace('{:', '', $zpr["item_key"]);
438 $zpr["item_key"] = str_replace('}', '', $zpr["item_key"]);
439 }
440
441 if ( $zpr["item_key"] !== false
442 && strpos( $zpr["item_key"], ":" ) == false ) {
443
444 $temp_reformatted = "";
445 $temp_items = explode( ",", $zpr["item_key"] );
446
447 foreach ( $temp_items as $item )
448 $temp_reformatted .= "{".$zpr["api_user_id"].":".$item."},";
449
450 $zpr["item_key"] = rtrim( $temp_reformatted, ',' );
451 }
452
453 $zpr["itemtype"] = false;
454 if ( isset($atts['itemtype'])
455 && ( $atts['itemtype'] != "false" && $atts['itemtype'] !== false && $atts['itemtype'] !== '' ) )
456 $zpr["itemtype"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['itemtype'] )));
457 elseif ( isset($atts['item_type'])
458 && ( $atts['item_type'] != "false" && $atts['item_type'] !== false && $atts['item_type'] !== '' ) )
459 $zpr["itemtype"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['item_type'] )));
460 elseif ( isset($atts['data_type'])
461 && ( $atts['data_type'] != "false" && $atts['data_type'] !== false && $atts['data_type'] !== '' ) )
462 $zpr["itemtype"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['data_type'] )));
463
464 // Filter by itemtype
465 // TODO: Allow for multiple itemtypes in one shortcode?
466 if ( $zpr["itemtype"] !== false ) {
467
468 // Make sure it's one of the accepted types
469 $officialItemTypes = array(
470 'book',
471 'bookSection',
472 'journalArticle',
473 'conferencePaper',
474 'thesis',
475 'report',
476 'encyclopediaArticle',
477 'newspaperArticle',
478 'magazineArticle',
479 'presentation',
480 'interview',
481 'dictionaryEntry',
482 'document',
483 'manuscript',
484 'patent',
485 'map',
486 'blogPost',
487 'webpage',
488 'artwork',
489 'film',
490 'audioRecording',
491 'statute',
492 'bill',
493 'case',
494 'hearing',
495 'forumPost',
496 'letter',
497 'email',
498 'instantMessage',
499 'software',
500 'podcast',
501 'radioBroadcast',
502 'tvBroadcast',
503 'videoRecording',
504 'attachment',
505 'note',
506 'preprint'
507 );
508
509 $itemtypeCheck = false;
510
511 foreach ( $officialItemTypes as $type )
512 if ( $zpr["itemtype"] == $type )
513 $itemtypeCheck = true;
514
515 if ( ! $itemtypeCheck )
516 $zpr["itemtype"] = false; // Default is no itemtype filter
517 }
518
519 $zpr["collection_id"] = false;
520 if ( isset($atts['collection_id'])
521 && ( $atts['collection_id'] != "false" && $atts['collection_id'] !== false && $atts['collection_id'] !== '' ) )
522 $zpr["collection_id"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['collection_id'])));
523 elseif ( isset($atts['collection'])
524 && ( $atts['collection'] != "false" && $atts['collection'] !== false && $atts['collection'] !== '' ) )
525 $zpr["collection_id"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['collection'])));
526 elseif ( isset($atts['collections'])
527 && ( $atts['collections'] != "false" && $atts['collections'] !== false && $atts['collections'] !== '' ) )
528 $zpr["collection_id"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['collections'])));
529 elseif ( isset($atts['zpcollection'])
530 && ( $atts['zpcollection'] != "false" && $atts['zpcollection'] !== false && $atts['zpcollection'] !== '' ) )
531 $zpr["collection_id"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['zpcollection'])));
532 elseif ( isset($_GET['subcollection_id'])
533 && ( $_GET['subcollection_id'] != "false" && $_GET['subcollection_id'] !== false && $_GET['subcollection_id'] !== '' ) )
534 // && preg_match("/^[a-zA-Z0-9]+$/", $_GET['subcollection_id']) )
535 $zpr["collection_id"] = esc_attr(zotpress_clean_param( sanitize_text_field(wp_unslash($_GET['subcollection_id']))) );
536
537 // $collection_id = str_replace(" ", "", $collection_id );
538
539 // 7.3.10: Originally in shortcode.php but doesn't make sense here ...
540 // // Deal with multiple collection IDs
541 // if ( strpos($zpr["collection_id"], ",") > 0 )
542 // $zpr["collection_id"] = explode(",", $zpr["collection_id"]);
543
544 // Deal with collection item type
545 // CHECK: Is this still used?
546 // if ( $zpr["itemtype"] == "collections"
547 // && isset($_GET['zpcollection']) )
548 // $collection_id = htmlentities( urldecode( $_GET['zpcollection'] ) );
549
550
551 $zpr["tag_id"] = false;
552 if ( isset($atts['tag_id'])
553 && ( $atts['tag_id'] != "false" && $atts['tag_id'] !== false && $atts['tag_id'] !== '' ) )
554 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags($atts['tag_id'])));
555 elseif ( isset($atts['tag_name'])
556 && ( $atts['tag_name'] != "false" && $atts['tag_name'] !== false && $atts['tag_name'] !== '' ) )
557 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags($atts['tag_name'])));
558 elseif ( isset($atts['tags'])
559 && ( $atts['tags'] != "false" && $atts['tags'] !== false && $atts['tags'] !== '' ) )
560 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags($atts['tags'])));
561 elseif ( isset($atts['tag'])
562 && ( $atts['tag'] != "false" && $atts['tag'] !== false && $atts['tag'] !== '' ) )
563 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags($atts['tag'])));
564 elseif ( isset($atts['zptag'])
565 && ( $atts['zptag'] != "false" && $atts['zptag'] !== false && $atts['zptag'] !== '' ) )
566 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags($atts['zptag'])));
567 elseif ( isset($_GET['lib_tag'])
568 && ( $_GET['lib_tag'] != "false" && $_GET['lib_tag'] !== false && $_GET['lib_tag'] !== '' ) )
569 $zpr["tag_id"] = (sanitize_text_field(wp_strip_all_tags(wp_unslash($_GET['lib_tag']))));
570
571 // Deal with plus sign as space
572 if ( $zpr["tag_id"] !== false )
573 $zpr["tag_id"] = str_replace("+", "", $zpr["tag_id"]);
574
575 // 7.3.10: Originally in shortcode.php but doesn't make sense here ...
576 // // Deal with multiple tags
577 // if ( strpos($zpr["tag_id"], ",") > 0 )
578 // $zpr["tag_id"] = explode(",", $zpr["tag_id"]);
579 // if ($item_type == "tags" && isset($_GET['zptag']) ) $tag_id = htmlentities( urldecode( $_GET['zptag'] ) );
580
581 // Author/s, year, style, limit, title
582 $zpr["author"] = false;
583 if ( isset($atts['author'])
584 && $atts['author'] != "false" && $atts['author'] != "" )
585 $zpr["author"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['author'])));
586 elseif ( isset($atts['authors'])
587 && $atts['authors'] != "false" && $atts['authors'] != "" )
588 $zpr["author"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['authors'])));
589
590 // TESTING: urldecode
591 // CHECK: Is this a test ..? Removing for now ...
592 // $zpr["author"] = urldecode($zpr["author"]);
593 $zpr["author"] = htmlspecialchars($zpr["author"]);
594
595
596 $zpr["year"] = false;
597 if ( isset($atts['year'])
598 && $atts['year'] != "false" && $atts['year'] != "" )
599 $zpr["year"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['year'] )));
600 elseif ( isset($atts['years'])
601 && $atts['years'] != "false" && $atts['years'] != "" )
602 $zpr["year"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['years'] )));
603
604 // Deal with multiple years:
605 if ( strpos($zpr["year"], ",") > 0 )
606 $zpr["year"] = explode(",", $zpr["year"]);
607
608 $zpr["style"] = zotpress_get_default_style();
609 if ( isset($atts['style'])
610 && $atts['style'] != "false" && $atts['style'] != "" && $atts['style'] != "default" )
611 // $zpr["style"] = sanitize_text_field(wp_strip_all_tags($atts['style']));
612 // 7.3.14: Need to remove any special quotes, etc.
613 $zpr["style"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags($atts['style'])));
614
615 // NOTE: With PHP 8, watch for URL params that are strings but need to be ints
616 // 7.3.10: CHECK: Ignore if 50
617 if ( isset($atts['limit'])
618 && (int) $atts['limit'] != 0
619 && (int) $atts['limit'] != 50 ) {
620
621 $zpr["limit"] = (int) sanitize_text_field(wp_strip_all_tags($atts['limit']));
622 $zpr["overwrite_request"] = true;
623 }
624
625 // Title
626 $zpr["title"] = false;
627 if ( isset($atts['title']) )
628 if ( in_array( strtolower($atts["title"]), array("yes", "true", "year", "years") ) )
629 $zpr["title"] = "year";
630 elseif ( in_array( strtolower($atts["title"]), array("itemtype", "item_type", "itemtypes", "item_types", "type") ) )
631 $zpr["title"] = "itemtype";
632 else
633 $zpr["title"] = false;
634
635 // Max tags, max results
636 $zpr["maxtags"] = false;
637 if ( $is_zplib) $zpr["maxtags"] = 100;
638 if ( isset($atts['maxtags']) )
639 $zpr["maxtags"] = (int) sanitize_text_field(wp_strip_all_tags($atts['maxtags']));
640
641 $zpr["maxresults"] = false;
642 if ( $is_zplib) $zpr["maxresults"] = 50;
643 if ( isset($atts['maxresults']) )
644 $zpr["maxresults"] = (int) sanitize_text_field(wp_strip_all_tags($atts['maxresults']));
645
646 // Term, filter
647 $zpr["term"] = false;
648 if ( isset($atts['term']) )
649 $zpr["term"] = wp_strip_all_tags($atts['term']);
650
651 $zpr["filter"] = false;
652 if ( isset($atts['filter']) )
653 $zpr["filter"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['filter'])));
654
655 // Sorty by, order
656 $zpr["sortby"] = false;
657 $zpr["order"] = false;
658 $zpr["item_keys_order"] = array();
659
660 // SPECIAL SETTINGS
661 if ( isset($atts['sortby']) ) {
662
663 if ( $atts['sortby'] == "author" ) {
664 $zpr["sortby"] = "creator";
665 $zpr["order"] = "asc";
666 } elseif ( $atts['sortby'] == "default" ) {
667 $zpr["sortby"] = "default";
668 // entry order
669 } elseif ( $atts['sortby'] == "year" ) {
670 $zpr["sortby"] = "date";
671 $zpr["order"] = "desc";
672 } elseif ( $zpr["type"] == "intext"
673 && $atts['sortby'] == "default" ) {
674 $zpr["sortby"] = "default";
675 } else {
676 $zpr["sortby"] = strtolower(esc_attr(sanitize_text_field(wp_strip_all_tags($atts['sortby']))));
677 }
678 }
679
680 if ( isset($atts['order'])
681 && ( strtolower($atts['order']) == "asc" || strtolower($atts['order']) == "desc" ) )
682 $zpr["order"] = strtolower(esc_attr(sanitize_text_field(wp_strip_all_tags($atts['order']))));
683 elseif ( isset($atts['sort'])
684 && ( strtolower($atts['sort']) == "asc" || strtolower($atts['sort']) == "desc" ) )
685 $zpr["order"] = strtolower(esc_attr(sanitize_text_field(wp_strip_all_tags($atts['sort']))));
686
687 // Show images, show tags, downloadable, inclusive, notes, abstracts, citeable
688 // 7.4.3: Added condition via André Lambelet: || $atts['showimage'] == "openlib"
689 $zpr["showimage"] = false;
690 if ( isset($atts['showimage'])
691 && ( $atts['showimage'] == "yes" || $atts['showimage'] == "true" || $atts['showimage'] === true || $atts['showimage'] == 1 || $atts['showimage'] == "openlib" ) )
692 $zpr["showimage"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['showimage'])));
693 elseif ( isset($atts['image'])
694 && ( $atts['image'] == "yes" || $atts['image'] == "true" || $atts['image'] === true || $atts['image'] == 1 || $atts['image'] == "openlib" ) )
695 $zpr["showimage"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['image'])));
696 elseif ( isset($atts['images'])
697 && ( $atts['images'] == "yes" || $atts['images'] == "true" || $atts['images'] === true || $atts['images'] == 1 || $atts['images'] == "openlib" ) )
698 $zpr["showimage"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['images'])));
699
700 // Set value
701 // if ( isset($_GET['showimage']) )
702 if ( $zpr['showimage'] == "yes" || $zpr['showimage'] == "true"
703 || $zpr['showimage'] === true || $zpr['showimage'] == 1 )
704 $zpr["showimage"] = true;
705 elseif ( $zpr['showimage'] == "openlib" )
706 $zpr["showimage"] = "openlib";
707 else
708 $zpr["showimage"] = false;
709
710 $zpr["showtags"] = false;
711 if ( isset($atts['showtags'])
712 && ( $atts['showtags'] == "yes" || $atts['showtags'] == "true"
713 || $atts['showtags'] === true || $atts['showtags'] == 1 ) )
714 $zpr["showtags"] = true;
715
716 $zpr["downloadable"] = false;
717 if ( isset($atts['downloadable'])
718 && ( $atts['downloadable'] == "yes" || $atts['downloadable'] == "true" || $atts['downloadable'] === true || $atts['downloadable'] == 1 ) )
719 $zpr["downloadable"] = true;
720 elseif ( isset($atts['download'])
721 && ( $atts['download'] == "yes" || $atts['download'] == "true" || $atts['download'] === true || $atts['download'] == 1 ) )
722 $zpr["downloadable"] = true;
723
724 $zpr["inclusive"] = false;
725 if ( isset($atts['inclusive'])
726 && ( $atts['inclusive'] == "yes" || $atts['inclusive'] == "true" || $atts['inclusive'] === true || $atts['inclusive'] == 1 ) )
727 $zpr["inclusive"] = true;
728
729 $zpr["shownotes"] = false;
730 if ( isset($atts['shownotes'])
731 && ( $atts['shownotes'] == "yes" || $atts['shownotes'] == "true" || $atts['shownotes'] === true || $atts['shownotes'] == 1 ) )
732 $zpr["shownotes"] = true;
733 elseif ( isset($atts['notes'])
734 && ( $atts['notes'] == "yes" || $atts['notes'] == "true" || $atts['notes'] === true || $atts['notes'] == 1 ) )
735 $zpr["shownotes"] = true;
736 elseif ( isset($atts['note'])
737 && ( $atts['note'] == "yes" || $atts['note'] == "true" || $atts['note'] === true || $atts['note'] == 1 ) )
738 $zpr["shownotes"] = true;
739
740 $zpr["showabstracts"] = false;
741 if ( isset($atts['showabstracts'])
742 && ( $atts['showabstracts'] == "yes" || $atts['showabstracts'] == "true" || $atts['showabstracts'] === true || $atts['showabstracts'] == 1 ) )
743 $zpr["showabstracts"] = true;
744 elseif ( isset($atts['abstracts'])
745 && ( $atts['abstracts'] == "yes" || $atts['abstracts'] == "true" || $atts['abstracts'] === true || $atts['abstracts'] == 1 ) )
746 $zpr["showabstracts"] = true;
747 elseif ( isset($atts['abstract'])
748 && ( $atts['abstract'] == "yes" || $atts['abstract'] == "true" || $atts['abstract'] === true || $atts['abstract'] == 1 ) )
749 $zpr["showabstracts"] = true;
750
751 $zpr["citeable"] = false;
752 if ( isset($atts['citeable'])
753 && ( $atts['citeable'] == "yes" || $atts['citeable'] == "true" || $atts['citeable'] === true || $atts['citeable'] == 1 ) )
754 $zpr["citeable"] = true;
755 elseif ( isset($atts['cite'])
756 && ( $atts['cite'] == "yes" || $atts['cite'] == "true" || $atts['cite'] === true || $atts['cite'] == 1 ) )
757 $zpr["citeable"] = true;
758
759 // Target, urlwrap, forcenum
760 $zpr["target"] = false;
761 if ( isset($atts['target'])
762 && ( $atts['target'] == "yes" || $atts['target'] == "true"
763 || $atts['target'] === true || $atts['target'] == 1
764 || $atts['target'] == "_blank" || $atts['target'] == "new" ) )
765 $zpr["target"] = true;
766
767 $zpr["urlwrap"] = false;
768 if ( isset($atts['urlwrap'])
769 && ( $atts['urlwrap'] == "title" || $atts['urlwrap'] == "image" ) )
770 $zpr["urlwrap"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['urlwrap'])));
771
772 // CHECK: Is htmlentities() and trim() needed anymore?
773 $zpr["highlight"] = false;
774 if ( isset($atts['highlight'])
775 && $atts['highlight'] !== ""
776 && $atts['highlight'] !== false
777 && $atts['highlight'] !== 0
778 && $atts['highlight'] !== "false" )
779 $zpr["highlight"] = trim(htmlentities( zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['highlight'] ))) ));
780
781 $zpr["forcenumber"] = false;
782 if ( isset($atts['forcenumber'])
783 && ( $atts['forcenumber'] == "yes" || $atts['forcenumber'] == "true" || $atts['forcenumber'] === true || $atts['forcenumber'] == 1 ) )
784 $zpr["forcenumber"] = true;
785
786
787
788 // Special attributes for ZotpressLib //
789
790 // Lib toplevel: Set UNLESS there's a tag
791 $zpr["toplevel"] = false;
792 if ( isset($atts['toplevel'])
793 && $zpr["tag_id"] === false ) {
794
795 $zpr["toplevel"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['toplevel'])));
796 // $zpr["collection_id"] = false;
797 }
798 if ( $zpr["collection_id"] == "toplevel" )
799 $zpr["collection_id"] = false;
800
801 $zpr["searchby"] = false;
802 if ( isset($atts['searchby'])
803 && $atts['searchby'] != "false" && $atts['searchby'] != "" )
804 $zpr["searchby"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['searchby'] )));
805
806 $zpr["minlength"] = 3;
807 if ( isset($atts['minlength'])
808 && $atts['minlength'] != "false" && $atts['minlength'] != "" )
809 $zpr["minlength"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['minlength'] )));
810
811 $zpr["maxperpage"] = 10;
812 if ( isset($atts['maxperpage'])
813 && $atts['maxperpage'] != "false" && $atts['maxperpage'] != "" )
814 $zpr["maxperpage"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['maxperpage'] )));
815
816 $zpr["searchby"] = false;
817 if ( isset($atts['searchby'])
818 && $atts['searchby'] != "false" && $atts['searchby'] != "" )
819 $zpr["searchby"] = zotpress_clean_param(sanitize_text_field(wp_strip_all_tags( $atts['searchby'] )));
820
821 // Note: Default is true
822 $zpr["browsebar"] = true;
823 if ( isset($atts['browsebar'])
824 // && ( $atts['browsebar'] == "no" || $atts['browsebar'] == "false" || $atts['browsebar'] === false || $atts['browsebar'] == 0 ) )
825 && ( $atts['browsebar'] != "yes" || $atts['browsebar'] != "true" || $atts['browsebar'] !== true ) )
826 $zpr["browsebar"] = false;
827
828
829 // 7.4.3: Special attributes for ZotpressInText
830
831 // Pages
832 $zpr["pages"] = false;
833 if ( isset($atts['pages']) )
834 $zpr["pages"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['pages'])));
835 else if ( isset($atts['page']) )
836 $zpr["pages"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['page'])));
837
838 // Format
839 $zpr["format"] = false;
840 if ( isset($atts['format']) )
841 $zpr["format"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['format'])));
842
843 // Brackets
844 $zpr["brackets"] = false;
845 if ( isset($atts['brackets']) )
846 $zpr["brackets"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['brackets'])));
847 else if ( isset($atts['bracket']) )
848 $zpr["pages"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['bracket'])));
849
850 // Separator
851 $zpr["separator"] = false;
852 if ( isset($atts['separator']) )
853 if ( $zpr["separator"] == "default" )
854 $zpr["separator"] = false;
855 else
856 $zpr["separator"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['separator'])));
857
858 // Et al.
859 $zpr["etal"] = false;
860 if ( isset($atts['etal']) )
861 if ( $zpr["etal"] == "default" )
862 $zpr["etal"] = false;
863 else
864 $zpr["etal"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['etal'])));
865
866 // And
867 $zpr["and"] = false;
868 if ( isset($atts['and']) )
869 if ( $zpr["and"] == "default" )
870 $zpr["and"] = false;
871 else
872 $zpr["and"] = esc_attr(sanitize_text_field(wp_strip_all_tags($atts['and'])));
873
874
875 // Request variables:
876
877 $zpr["request_start"] = 0;
878 if ( isset($atts['request_start']) )
879 $zpr["request_start"] = (int) sanitize_text_field(wp_strip_all_tags($atts['request_start']));
880
881 $zpr["request_last"] = 0;
882 if ( isset($atts['request_last']) )
883 $zpr["request_last"] = (int) sanitize_text_field(wp_strip_all_tags($atts['request_last']));
884
885 return $zpr;
886
887 } // function Zotpress_prep_ajax_request_vars
888
889
890
891 /**
892 * Preps and formats the Zotero API request URL.
893 *
894 * Handles all possible Zotpress parameters for bibliography
895 * shortcodes. Per user account.
896 *
897 * @param obj $wpdb WP DB object.
898 * @param arr $zpr Holds all params for request.
899 * @param arr $zp_request_queue Holds all requests for all accounts.
900 * @param str $api_user_id Optional. API user ID.
901 *
902 * @return arr $zp_request_queue The new request queue of formatted URLs.
903 */
904 function Zotpress_prep_request_URL( $wpdb, $zpr, $zp_request_queue, $api_user_id=false, $zp_request_data=false ) {
905
906 $tempItemType = "";
907
908 // Get account and $api_user_id
909 if ( $api_user_id ) {
910 $zp_account = zotpress_get_account( $wpdb, $api_user_id );
911 } elseif ( $zpr["api_user_id"] ) {
912 $zp_account = zotpress_get_account( $wpdb, $zpr["api_user_id"] );
913 $api_user_id = $zpr["api_user_id"];
914 } else {
915 $zp_account = zotpress_get_account( $wpdb );
916 $api_user_id = $zp_account[0]->api_user_id;
917 }
918
919 // Make sure account was founded (is synced)
920 if ( count($zp_account) > 0 ) {
921
922 // Basic URL: User type, user id, item type
923 $zp_import_url = "https://api.zotero.org/".$zp_account[0]->account_type."/".$api_user_id."/".$zpr["item_type"];
924
925 // Deal with item type Items
926 if ( $zpr['item_type'] == 'items' ) {
927
928 // Account for single item with new style
929 if ( gettype( $zpr["item_key"] ) == "string"
930 && strlen($zpr["item_key"]) > 0
931 && $zpr["item_key"][0] == "{" ) {
932
933 $zpr_temp = explode(':', $zpr["item_key"]);
934 $zpr_temp = count($zpr_temp) > 1 ? $zpr_temp[1] : $zpr_temp[0];
935 $zpr["item_key"] = rtrim( $zpr_temp, "}");
936
937 // Account for page numbers
938 if ( strpos( $zpr["item_key"], ',' ) ) {
939
940 $zpr_temp = explode(',', $zpr["item_key"]);
941 $zpr["item_key"] = rtrim( $zpr_temp[0], "}");
942 }
943 }
944 elseif ( gettype( $zpr["item_key"] ) == "array"
945 && count( $zpr["item_key"] ) == 1
946 && $zpr["item_key"][0][0] == "{" ) {
947
948 // $zpr["item_key"] = rtrim( explode(':', $zpr["item_key"][0])[1] , "}");
949 $zpr["item_key"] = ltrim( rtrim( $zpr["item_key"][0], "}" ), "{" );
950
951 // Account for page numbers
952 if ( strpos( $zpr["item_key"], ',' ) ) {
953
954 $zpr_temp = explode(',', $zpr["item_key"]);
955 $zpr["item_key"] = rtrim( $zpr_temp[0], "}" );
956 }
957 }
958 } // item type Items
959
960 // Top
961 if ( $zpr["get_top"] ) $zp_import_url .= "/top";
962
963 // Single item key
964 if ( ! empty( $zp_request_queue )
965 && ( ! isset( $zp_request_queue[$api_user_id]["items"] )
966 || strpos($zp_request_queue[$api_user_id]["items"], ',') == false )
967 ) {
968
969 if (isset( $zp_request_data["items"] )) {
970
971 $zp_import_url .= "/" . $zp_request_data["items"];
972 }
973 elseif (gettype( $zpr["item_key"] ) == "array"
974 && count( $zpr["item_key"] ) == 1
975 && strpos( $zpr["item_key"][0], ',' ) == false) {
976
977 $zp_import_url .= "/" . $zpr["item_key"][0];
978 }
979 elseif (gettype( $zpr["item_key"] ) == "string"
980 && ( strpos( $zpr["item_key"], "," ) === false
981 && strpos( $zpr["item_key"], ";" ) === false )) {
982
983 $zp_import_url .= "/" . $zpr["item_key"];
984 }
985 }
986
987 if ( $zpr["collection_id"] )
988 $zp_import_url .= "/" . $zpr["collection_id"];
989
990 if ( $zpr["sub"] )
991 $zp_import_url .= "/" . $zpr["sub"];
992
993 $zp_import_url .= "?";
994
995 // Public key, if needed
996 if ( ! is_null($zp_account[0]->public_key)
997 && trim($zp_account[0]->public_key) != "" )
998 $zp_import_url .= "key=".$zp_account[0]->public_key."&";
999
1000 // Style
1001 $zp_import_url .= "style=".$zpr["style"];
1002
1003 // Format, limit, etc.
1004 $zp_import_url .= "&format=json&include=data,bib&limit=".$zpr["limit"];
1005
1006 // Sort and order
1007 if ( $zpr["sortby"]
1008 // && ( $zpr["sortby"] != "default" && ) ) {
1009 && ! in_array( $zpr["sortby"], array("default", false, "false") ) ) {
1010
1011 $zp_import_url .= "&sort=".$zpr["sortby"];
1012
1013 if ( $zpr["order"] ) $zp_import_url .= "&direction=".$zpr["order"];
1014 }
1015
1016 // Start if multiple
1017 if ( $zpr["request_start"] != 0 )
1018 $zp_import_url .= "&start=".$zpr["request_start"];
1019
1020 // Multiple item keys
1021 // EVENTUAL TODO: Limited to 50 item keys at a time ... can I get around this?
1022 // TODO: Test this with a bib that has 50+ items
1023 // if ( $zpr["item_key"] && strpos( $zpr["item_key"],"," ) !== false ) $zp_import_url .= "&itemKey=" . $zpr["item_key"];
1024 if ( $zp_request_data ) {
1025
1026 if ( substr_count($zp_request_data["items"], ",") >= 50 ) {
1027
1028 // Split items by comma
1029 $items = explode( ",", $zp_request_data["items"] );
1030
1031 $requests = array();
1032 $request_items = array();
1033
1034 foreach ( $items as $item ) {
1035
1036 // Thanks to Tomas Risberg and @ericcorbett2
1037 if ( is_countable($request_items) ) {
1038
1039 if ( count($request_items) < 50 )
1040 $request_items[] = $item;
1041 }
1042 else {
1043
1044 $requests[] = $request_items;
1045 unset( $request_items );
1046 }
1047 // Old code:
1048 // if ( count($request_items) < 50 ) {
1049 // $request_items[] = $item;
1050 // }
1051 // else {
1052 // $requests[] = $request_items;
1053 // unset( $request_items );
1054 // }
1055 }
1056
1057 $zp_request_queue[$api_user_id]["requests"] = $requests;
1058 }
1059 else {
1060 // TODO: Is this necessary?
1061 // $zp_request_queue[$api_user_id]["requests"] = explode( ",", $zp_request_data["items"] );
1062 }
1063 }
1064
1065 // Itemtype-specific
1066 if ( $zpr["itemtype"] )
1067 $zp_import_url .= "&itemType=" . urlencode( stripslashes( $zpr["itemtype"] ));
1068
1069 // Tag-specific
1070 if ( $zpr["tag_id"] ) {
1071
1072 if ( strpos($zpr["tag_id"], ",") !== false ) {
1073
1074 $temp = explode( ",", $zpr["tag_id"] );
1075
1076 foreach ( $temp as $temp_tag )
1077 $zp_import_url .= "&tag=" . urlencode( stripslashes( $temp_tag ));
1078 }
1079 else {
1080
1081 $zp_import_url .= "&tag=" . urlencode( stripslashes( $zpr["tag_id"] ));
1082 }
1083 }
1084
1085 // Filtering: collections and tags take priority over authors and year
1086 // EVENTUAL TODO: Searching by two+ values is not supported on the Zotero side ...
1087 // For now, we get all and manually filter below
1088 $zp_author_or_year_multiple = false;
1089
1090 if ( $zpr["collection_id"]
1091 || $zpr["tag_id"] ) {
1092
1093 // Check if author or year is set
1094 if ( $zpr["year"]
1095 || $zpr["author"] ) {
1096
1097 // Check if author year is set and multiple
1098 if ( ( $zpr["author"] && strpos( $zpr["author"], "," ) !== false )
1099 || ( $zpr["year"] && strpos( $zpr["year"], "," ) !== false ) ) {
1100
1101 $zp_author_or_year_multiple = $zpr["author"] && strpos( $zpr["author"], "," ) !== false ? "author" : "year";
1102 }
1103 else { // Set but not multiple
1104
1105 $zp_import_url .= "&qmode=titleCreatorYear";
1106 // if ( $zpr["author"] ) $zp_import_url .= "&q=".urlencode( $zpr["author"] );
1107 if ( $zpr["author"] ) $zp_import_url .= "&q=".$zpr["author"];
1108 if ( $zpr["year"] && ! $zpr["author"] ) $zp_import_url .= "&q=".$zpr["year"];
1109 }
1110 }
1111 }
1112 elseif ( $zpr["year"]
1113 || $zpr["author"] ) {
1114
1115 $zp_import_url .= "&qmode=titleCreatorYear";
1116
1117 if ( $zpr["author"] ) {
1118
1119 // REVIEW: Deal with authors with multi-part last names
1120 // Replace plus signs with spaces
1121 if ( strpos( $zpr["author"], "+" ) !== -1 )
1122 $zpr["author"] = str_replace( '+', ' ', $zpr["author"] );
1123
1124 if ( $zpr["inclusive"] === false ) {
1125
1126 $zp_authors = explode( ",", $zpr["author"] );
1127 // $zp_import_url .= "&q=".urlencode( $zp_authors[0] );
1128 $zp_import_url .= "&q=".($zp_authors[0]);
1129 unset( $zp_authors[0] );
1130 $zpr["author"] = $zp_authors;
1131 }
1132 else { // inclusive
1133
1134 // $zp_import_url .= "&q=".urlencode( $zpr["author"] );
1135 $zp_import_url .= "&q=".$zpr["author"];
1136 }
1137 }
1138
1139 // CHANGED (7.3): For some reason, urlencode will replace apostrophes
1140 // with &#039; and then encode that to %26%23039%3B
1141 // which breaks ... so let's replace with %27 manually
1142 $zp_import_url = str_replace("%26%23039%3B", "%27", $zp_import_url);
1143
1144 // Deal with just year, no author
1145 if ( $zpr["year"]
1146 && ! $zpr["author"] ) {
1147
1148 if ( is_array($zpr["year"]) )
1149 $zpr["year"] = implode(",", $zpr["year"]);
1150
1151 $zp_import_url .= "&q=".$zpr["year"];
1152 }
1153 }
1154
1155 // Avoid attachments and notes, if not using itemtype filtering
1156 if ( ! $zpr["itemtype"]
1157 && $zpr["item_type"] == "items"
1158 || ( $zpr["sub"] && $zpr["sub"] == "items" ) )
1159 $zp_import_url .= "&itemType=-attachment+||+note";
1160
1161 // Deal with possible term
1162 if ( $zpr["term"] )
1163 if ( $zpr["filter"] && $zpr["filter"] == "tag")
1164 $zp_import_url .= "&tag=".urlencode( $wpdb->esc_like($zpr["term"]) );
1165 else
1166 $zp_import_url .= "&q=".urlencode( $wpdb->esc_like($zpr["term"]) );
1167
1168
1169 // DEAL WITH MULTIPLE REQUESTS
1170 // if ( count($zp_request_queue) > 0 )
1171 if ( $zp_request_queue
1172 && array_key_exists($api_user_id, $zp_request_queue) ) {
1173
1174 // Assume items
1175 // if ( array_key_exists("requests", $zp_request_queue[$api_user_id])
1176 // && count($zp_request_queue[$api_user_id]["requests"]) > 1 )
1177 // Multiple requests
1178 if ( array_key_exists("requests", $zp_request_queue[$api_user_id] )
1179 && count($zp_request_queue[$api_user_id]["requests"]) > 1 ) {
1180
1181 $item_keys = "";
1182 foreach ( $zp_request_queue[$api_user_id]["requests"] as $num => $request ) {
1183
1184 if ( $item_keys != "" ) $item_keys .= ",";
1185 $item_keys .= $request;
1186 }
1187 $zp_request_queue[$api_user_id]["requests"][$num] = $zp_import_url . "&itemKey=" . $item_keys;
1188 }
1189 elseif ( strpos( $zp_request_queue[$api_user_id]["items"], "," ) !== false ) {
1190
1191 if ( is_array($zp_request_queue[$api_user_id]["items"]) )
1192 $zp_request_queue[$api_user_id]["items"] = implode(",", $zp_request_queue[$api_user_id]["items"]);
1193
1194 $zp_request_queue[$api_user_id]["requests"] = array( $zp_import_url . "&itemKey=" . $zp_request_queue[$api_user_id]["items"] );
1195 }
1196 else { // one item
1197
1198 $zp_request_queue[$api_user_id]["requests"] = array( $zp_import_url );
1199 }
1200 }
1201 elseif ( ! $zp_request_queue
1202 && $api_user_id) {
1203
1204 // Assume normal
1205 $zp_request_queue[$api_user_id]["requests"] = array( $zp_import_url );
1206 }
1207 else {
1208
1209 // Assume broken or no requests
1210 $zp_request_queue = false;
1211 // Assume normal
1212 // $zp_request_queue[$api_user_id]["requests"] = array( $zp_import_url );
1213 }
1214 } // count($zp_account) > 0
1215
1216 else { // account not synced
1217
1218 $zp_request_queue = false;
1219 }
1220
1221 return $zp_request_queue;
1222
1223 } // function Zotpress_prep_request_URL
1224
1225
1226
1227 ?>
1228