| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 2 |
|
| 3 |
require(__DIR__ . '/shortcode.functions.php'); |
| 4 |
require(__DIR__ . '/shortcode.request.php'); |
| 5 |
require(__DIR__ . '/../request/request.dl.php'); |
| 6 |
require(__DIR__ . '/../request/request.cite.php'); |
| 7 |
|
| 8 |
/** |
| 9 |
* Handles the Zotpress bibliography shortcode. |
| 10 |
* 7.3.10: Refined to use $_GET and Zotpress_prep_ajax_request_vars() for processing. |
| 11 |
* |
| 12 |
* Used by: Shortcodes, zotpress.php |
| 13 |
* |
| 14 |
* @param arr $atts The shortcode attributes. |
| 15 |
* |
| 16 |
* @return str $zp_output The in-text shortcode HTML. |
| 17 |
*/ |
| 18 |
function Zotpress_func( $atts ) { |
| 19 |
|
| 20 |
$zp_atts = shortcode_atts( array( |
| 21 |
|
| 22 |
'user_id' => false, // deprecated |
| 23 |
'userid' => false, |
| 24 |
'user' => false, // 7.4: unofficial |
| 25 |
'nickname' => false, |
| 26 |
'nick' => false, |
| 27 |
|
| 28 |
'author' => false, |
| 29 |
'authors' => false, |
| 30 |
'year' => false, |
| 31 |
'years' => false, |
| 32 |
|
| 33 |
'itemtype' => false, // for selecting by itemtype; assumes one type |
| 34 |
'item_type' => 'items', |
| 35 |
'data_type' => false, // deprecated |
| 36 |
'datatype' => 'items', |
| 37 |
|
| 38 |
'collection_id' => false, |
| 39 |
'collection' => false, |
| 40 |
'collections' => false, |
| 41 |
|
| 42 |
'item_key' => false, |
| 43 |
'item' => false, |
| 44 |
'items' => false, |
| 45 |
|
| 46 |
'inclusive' => 'yes', |
| 47 |
|
| 48 |
'tag_name' => false, |
| 49 |
'tag' => false, |
| 50 |
'tags' => false, |
| 51 |
|
| 52 |
'style' => false, |
| 53 |
'limit' => false, |
| 54 |
|
| 55 |
'sortby' => 'default', |
| 56 |
'order' => false, |
| 57 |
'sort' => false, |
| 58 |
|
| 59 |
'title' => 'no', |
| 60 |
|
| 61 |
'image' => false, |
| 62 |
'images' => false, |
| 63 |
'showimage' => 'no', |
| 64 |
|
| 65 |
'showtags' => 'no', |
| 66 |
|
| 67 |
'downloadable' => 'no', |
| 68 |
'download' => 'no', |
| 69 |
|
| 70 |
'shownotes' => false, |
| 71 |
'note' => false, |
| 72 |
'notes' => 'no', |
| 73 |
|
| 74 |
'abstract' => false, |
| 75 |
'abstracts' => 'no', |
| 76 |
|
| 77 |
'cite' => 'no', |
| 78 |
'citeable' => false, |
| 79 |
|
| 80 |
'metadata' => false, |
| 81 |
|
| 82 |
'target' => false, |
| 83 |
'urlwrap' => false, |
| 84 |
|
| 85 |
'highlight' => false, |
| 86 |
'forcenumber' => false, |
| 87 |
'forcenumbers' => false |
| 88 |
|
| 89 |
), $atts ); |
| 90 |
|
| 91 |
|
| 92 |
global $post, $wpdb; |
| 93 |
|
| 94 |
|
| 95 |
// +---------------------------+ |
| 96 |
// | FORMAT & CLEAN PARAMETERS | |
| 97 |
// +---------------------------+ |
| 98 |
|
| 99 |
// 3.9.10: Use the Zotpress_prep_ajax_request_vars() function on bib, lib |
| 100 |
$zpr = Zotpress_prep_ajax_request_vars($wpdb, $zp_atts); |
| 101 |
|
| 102 |
|
| 103 |
// +-------------+ |
| 104 |
// | GET ACCOUNT | |
| 105 |
// +-------------+ |
| 106 |
|
| 107 |
// CHECK: Is this needed? Isn't it already in zotpress.php? |
| 108 |
// CHECK: Yes, but it's not being called ... no idea why ... |
| 109 |
// Turn on/off minified versions if testing/live |
| 110 |
$minify = ''; if ( ZOTPRESS_LIVEMODE ) $minify = '.min'; |
| 111 |
wp_enqueue_script( 'zotpress.shortcode.bib'.$minify.'.js' ); |
| 112 |
|
| 113 |
$zp_account = false; |
| 114 |
|
| 115 |
if ( $zpr['nickname'] !== false ) { |
| 116 |
|
| 117 |
$zp_account = $wpdb->get_row( |
| 118 |
$wpdb->prepare( |
| 119 |
" |
| 120 |
SELECT * FROM `".$wpdb->prefix."zotpress` |
| 121 |
WHERE `nickname`=%s |
| 122 |
", |
| 123 |
array( $zpr['nickname'] ) |
| 124 |
), OBJECT |
| 125 |
); |
| 126 |
if ( is_null($zp_account) ): |
| 127 |
return "<p>Sorry, but the selected Zotpress nickname can't be found.</p>"; |
| 128 |
endif; |
| 129 |
$zpr["api_user_id"] = $zp_account->api_user_id; |
| 130 |
} |
| 131 |
elseif ( $zpr["api_user_id"] !== false ) { |
| 132 |
|
| 133 |
$zp_account = $wpdb->get_row( |
| 134 |
$wpdb->prepare( |
| 135 |
" |
| 136 |
SELECT * FROM `".$wpdb->prefix."zotpress` |
| 137 |
WHERE `api_user_id`=%s |
| 138 |
", |
| 139 |
array( $zpr["api_user_id"] ) |
| 140 |
), OBJECT |
| 141 |
); |
| 142 |
if ( is_null($zp_account) ): |
| 143 |
return "<p>Sorry, but the selected Zotpress account can't be found.</p>"; |
| 144 |
endif; |
| 145 |
$zpr["api_user_id"] = $zp_account->api_user_id; |
| 146 |
} |
| 147 |
elseif ( $zpr["nickname"] === false |
| 148 |
&& $zpr["api_user_id"] === false ) { |
| 149 |
|
| 150 |
if ( get_option("Zotpress_DefaultAccount") !== false ) { |
| 151 |
|
| 152 |
$zpr["api_user_id"] = get_option("Zotpress_DefaultAccount"); |
| 153 |
|
| 154 |
$zp_account = $wpdb->get_row( |
| 155 |
$wpdb->prepare( |
| 156 |
" |
| 157 |
SELECT * FROM `".$wpdb->prefix."zotpress` |
| 158 |
WHERE `api_user_id`=%s |
| 159 |
", |
| 160 |
array( $zpr["api_user_id"] ) |
| 161 |
), OBJECT |
| 162 |
); |
| 163 |
} |
| 164 |
else { // When all else fails ... assume one account |
| 165 |
|
| 166 |
$zp_account = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."zotpress LIMIT 1", OBJECT); |
| 167 |
$zpr["api_user_id"] = $zp_account->api_user_id; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
// Generate instance id for shortcode |
| 172 |
$temp_item_key = is_array( $zpr['item_key'] ) ? implode( "-", $zpr['item_key']) : $zpr['item_key']; |
| 173 |
$temp_collection_id = is_array( $zpr['collection_id'] ) ? implode( "-", $zpr['collection_id']) : $zpr['collection_id']; |
| 174 |
$temp_tag_name = is_array( $zpr['tag_id'] ) ? implode( "-", $zpr['tag_id']) : $zpr['tag_id']; |
| 175 |
$temp_author = is_array( $zpr['author'] ) ? implode( "-", $zpr['author']) : $zpr['author']; |
| 176 |
$temp_year = is_array( $zpr['year'] ) ? implode( "-", $zpr['year']) : $zpr['year']; |
| 177 |
$temp_sortby = is_array( $zpr['sortby'] ) ? implode( "-", $zpr['sortby']) : $zpr['sortby']; |
| 178 |
|
| 179 |
// REVIEW: Added post ID |
| 180 |
// 7.3.10: REVIEW: Removed $nickname, $item_type |
| 181 |
// $instance_id = "zotpress-".md5($post->ID.$api_user_id.$nickname.$temp_author.$temp_year.$itemtype.$item_type.$temp_collection_id.$temp_item_key.$temp_tag_name.$style.$temp_sortby.$order.$limit.$showimage.$showtags.$downloadable.$shownotes.$citeable.$inclusive); |
| 182 |
$instance_id = "zotpress-".md5($post->ID.$zpr["api_user_id"].$temp_author.$temp_year.$zpr['itemtype'].$temp_collection_id.$temp_item_key.$temp_tag_name.$zpr['style'].$temp_sortby.$zpr['order'].$zpr['limit'].$zpr['showimage'].$zpr['showtags'].$zpr['downloadable'].$zpr['shownotes'].$zpr['citeable'].$zpr['inclusive']); |
| 183 |
|
| 184 |
// Prepare item key |
| 185 |
if ( $zpr['item_key'] |
| 186 |
&& gettype( $zpr['item_key'] ) != "string" ) |
| 187 |
$zpr['item_key'] = implode( ",", $zpr['item_key'] ); |
| 188 |
|
| 189 |
// Prepare collection |
| 190 |
if ( $zpr['collection_id'] |
| 191 |
&& gettype( $zpr['collection_id'] ) != "string" ) |
| 192 |
$zpr['collection_id'] = implode( ",", $zpr['collection_id'] ); |
| 193 |
|
| 194 |
// Prepare tags |
| 195 |
if ( $zpr['tag_id'] |
| 196 |
&& gettype( $zpr['tag_id'] ) != "string" ) |
| 197 |
$zpr['tag_id'] = implode( ",", $zpr['tag_id'] ); |
| 198 |
|
| 199 |
// Account for single or multiple years: |
| 200 |
if ( $zpr['year'] |
| 201 |
&& is_array($zpr['year']) ) |
| 202 |
$zpr['year'] = implode( ",", $zpr['year'] ); |
| 203 |
|
| 204 |
// Set up request vars |
| 205 |
$request_start = 0; |
| 206 |
$request_last = 0; |
| 207 |
$overwrite_last_request = false; |
| 208 |
|
| 209 |
// Set up Library vars |
| 210 |
$is_dropdown = false; |
| 211 |
$maxresults = 50; |
| 212 |
$maxperpage = 10; |
| 213 |
$maxtags = 100; |
| 214 |
|
| 215 |
// Set up Search vars |
| 216 |
$term = false; |
| 217 |
|
| 218 |
// Set up Update vars |
| 219 |
$update = false; |
| 220 |
|
| 221 |
$zp_output = '<div id="' . $instance_id . '"'; |
| 222 |
$zp_output .= ' class="zp-Zotpress zp-Zotpress-Bib wp-block-group'; |
| 223 |
if ( $zpr['forcenumber'] ) $zp_output .= " forcenumber"; |
| 224 |
// 7.3.10: REVIEW: Removed the extra row: |
| 225 |
// <span class="ZP_ITEM_TYPE ZP_ATTR">'.$item_type.'</span> |
| 226 |
$zp_output .= '"> |
| 227 |
|
| 228 |
<span class="ZP_API_USER_ID ZP_ATTR">'.$zpr["api_user_id"].'</span> |
| 229 |
<span class="ZP_ITEM_KEY ZP_ATTR">'.$zpr['item_key'].'</span> |
| 230 |
<span class="ZP_COLLECTION_ID ZP_ATTR">'.$zpr['collection_id'].'</span> |
| 231 |
<span class="ZP_TAG_ID ZP_ATTR">'.$zpr['tag_id'].'</span> |
| 232 |
<span class="ZP_AUTHOR ZP_ATTR">'.$zpr['author'].'</span> |
| 233 |
<span class="ZP_YEAR ZP_ATTR">'.$zpr['year'].'</span> |
| 234 |
<span class="ZP_ITEMTYPE ZP_ATTR">'.$zpr['itemtype'].'</span> |
| 235 |
<span class="ZP_INCLUSIVE ZP_ATTR">'.$zpr['inclusive'].'</span> |
| 236 |
<span class="ZP_STYLE ZP_ATTR">'.$zpr['style'].'</span> |
| 237 |
<span class="ZP_LIMIT ZP_ATTR">'.$zpr['limit'].'</span> |
| 238 |
<span class="ZP_SORTBY ZP_ATTR">'.$zpr['sortby'].'</span> |
| 239 |
<span class="ZP_ORDER ZP_ATTR">'.$zpr['order'].'</span> |
| 240 |
<span class="ZP_TITLE ZP_ATTR">'.$zpr['title'].'</span> |
| 241 |
<span class="ZP_SHOWIMAGE ZP_ATTR">'.$zpr['showimage'].'</span> |
| 242 |
<span class="ZP_SHOWTAGS ZP_ATTR">'.$zpr['showtags'].'</span> |
| 243 |
<span class="ZP_DOWNLOADABLE ZP_ATTR">'.$zpr['downloadable'].'</span> |
| 244 |
<span class="ZP_NOTES ZP_ATTR">'.$zpr['shownotes'].'</span> |
| 245 |
<span class="ZP_ABSTRACT ZP_ATTR">'.$zpr['showabstracts'].'</span> |
| 246 |
<span class="ZP_CITEABLE ZP_ATTR">'.$zpr['citeable'].'</span> |
| 247 |
<span class="ZP_TARGET ZP_ATTR">'.$zpr['target'].'</span> |
| 248 |
<span class="ZP_URLWRAP ZP_ATTR">'.$zpr['urlwrap'].'</span> |
| 249 |
<span class="ZP_FORCENUM ZP_ATTR">'.$zpr['forcenumber'].'</span> |
| 250 |
<span class="ZP_HIGHLIGHT ZP_ATTR">'.$zpr['highlight'].'</span> |
| 251 |
<span class="ZP_POSTID ZP_ATTR">'.$post->ID.'</span> |
| 252 |
<span class="ZOTPRESS_PLUGIN_URL ZP_ATTR">'.ZOTPRESS_PLUGIN_URL.'</span> |
| 253 |
|
| 254 |
<div class="zp-List loading">'; |
| 255 |
|
| 256 |
|
| 257 |
// +--------------------------------+ |
| 258 |
// | GENERATE SHORTCODE PLACEHOLDER | |
| 259 |
// +--------------------------------+ |
| 260 |
|
| 261 |
if ( $zp_account === false ) |
| 262 |
{ |
| 263 |
$zp_output .= "\n<div id='".$instance_id."' class='zp-Zotpress'>Sorry, no citation(s) found for this account.</div>\n"; |
| 264 |
} |
| 265 |
else // Make the first request via PHP for SEO purposes |
| 266 |
{ |
| 267 |
$_GET['instance_id'] = $instance_id; |
| 268 |
$_GET['api_user_id'] = $zpr["api_user_id"]; |
| 269 |
$_GET['item_key'] = $zpr['item_key']; |
| 270 |
$_GET['collection_id'] = $zpr['collection_id']; |
| 271 |
$_GET['tag_id'] = $zpr['tag_id']; |
| 272 |
$_GET['author'] = $zpr['author']; |
| 273 |
$_GET['year'] = $zpr['year']; |
| 274 |
$_GET['itemtype'] = $zpr['itemtype']; |
| 275 |
// $_GET['item_type'] = $item_type; // 7.3.10: REVIEW: Extra/repeated? |
| 276 |
$_GET['inclusive'] = $zpr['inclusive']; |
| 277 |
$_GET['style'] = $zpr['style']; |
| 278 |
$_GET['limit'] = $zpr['limit']; |
| 279 |
$_GET['sortby'] = $zpr['sortby']; |
| 280 |
$_GET['order'] = $zpr['order']; |
| 281 |
$_GET['title'] = $zpr['title']; |
| 282 |
$_GET['showimage'] = $zpr['showimage']; |
| 283 |
$_GET['showtags'] = $zpr['showtags']; |
| 284 |
$_GET['downloadable'] = $zpr['downloadable']; |
| 285 |
$_GET['shownotes'] = $zpr['shownotes']; |
| 286 |
$_GET['abstracts'] = $zpr['showabstracts']; |
| 287 |
$_GET['citeable'] = $zpr['citeable']; |
| 288 |
$_GET['target'] = $zpr['target']; |
| 289 |
$_GET['urlwrap'] = $zpr['urlwrap']; |
| 290 |
$_GET['forcenumber'] = $zpr['forcenumber']; |
| 291 |
$_GET['highlight'] = $zpr['highlight']; |
| 292 |
$_GET['request_start'] = $request_start; |
| 293 |
$_GET['request_last'] = $request_last; |
| 294 |
$_GET['is_dropdown'] = $is_dropdown; |
| 295 |
$_GET['maxresults'] = $maxresults; |
| 296 |
$_GET['maxperpage'] = $maxperpage; |
| 297 |
$_GET['maxtags'] = $maxtags; |
| 298 |
$_GET['term'] = $term; |
| 299 |
$_GET['update'] = $update; |
| 300 |
$_GET['overwrite_last_request'] = $overwrite_last_request; |
| 301 |
|
| 302 |
$zp_output .= "\n\t\t\t<div class=\"zp-SEO-Content\">\n"; |
| 303 |
$zp_output .= Zotpress_shortcode_request( $zpr, true ); // Check catche first |
| 304 |
$zp_output .= "\n\t\t\t</div><!-- .zp-zp-SEO-Content -->\n"; |
| 305 |
} |
| 306 |
$zp_output .= "\t\t</div><!-- .zp-List -->\n\t</div><!--.zp-Zotpress-->\n\n"; |
| 307 |
|
| 308 |
// Indicate that shortcode is displayed |
| 309 |
$GLOBALS['zp_is_shortcode_displayed'] = true; |
| 310 |
|
| 311 |
return $zp_output; |
| 312 |
} |
| 313 |
|
| 314 |
?> |