function shortcode($attributes) { // extract the shortcode attributes extract(shortcode_atts(array('library_type' => false, 'library_id' => false, 'library_slug' => "", 'api_key' => false, 'item_key' => false, 'collection_key' => false, 'content' => 'bib,coins', 'style' => false, 'order' => 'creator', 'sort' => 'asc', 'limit' => "100", 'format' => false, 'tag_name' => false, 'cache_time' => "3600"), $attributes)); $params = array(); if ($collection_key) { $params['collectionKey'] = $collection_key; } if ($content) { $params['content'] = $content; } if ($style) { $params['style'] = $style; } if ($order) { $params['order'] = $order; } if ($sort) { $params['sort'] = $sort; } if ($limit) { $totalItemLimit = $limit; } if ($format) { $params['format'] = $format; } if ($item_key) { $params['itemKey'] = $item_key; } $base_url = "http://www.zotero.org"; $library = new Zotero_Library($library_type, $library_id, $library_slug, $api_key, $base_url, $cache_time); // code to step through multiple requests for bibliographies longer than 100 items //start at the beginning of our list by setting an offset of 0 $offset = 0; //limit to 100 items per http request //this is the maximum number of items the API will return in a single request $perRequestLimit = 100; //keep count of the items we've gotten $fetchedItemsCount = 0; //keep track of whether there are more items to fetch $moreItems = true; //where we'll keep the list of items we retrieve $items = array(); //while there are more items and we haven't gotten to our limit yet while ($fetchedItemsCount < $totalItemLimit && $moreItems) { //fetching items starting at $offset with $perRequestLimit items per request $fetchedItems = $library->fetchItemsTop(array_merge($params, array('limit' => $perRequestLimit, 'start' => $offset))); //put the items from this last request into our array of items $items = array_merge($items, $fetchedItems); //update the count of items we've got and offset by that amount $fetchedItemsCount += count($fetchedItems); $offset = $fetchedItemsCount; //Zotero_Library keeps track of the last feed it got so we can check if there is a 'next' link //indicating more results to be fetched if (!isset($library->getLastFeed()->links['next'])) { $moreItems = false; } } return $this->display_zotero_items($items); }
$moreItems = true; //where we'll keep the list of items we retrieve $items = array(); //while there are more items and we haven't gotten to our limit yet while ($fetchedItemsCount < $totalItemLimit && $moreItems) { echo "fetching items starting at {$offset} with {$perRequestLimit} items per request <br />"; //fetching items starting at $offset with $perRequestLimit items per request $fetchedItems = $library->fetchItemsTop(array_merge($feedParams, array('limit' => $perRequestLimit, 'start' => $offset))); //put the items from this last request into our array of items $items = array_merge($items, $fetchedItems); //update the count of items we've got and offset by that amount $fetchedItemsCount += count($fetchedItems); $offset = $fetchedItemsCount; //Zotero_Library keeps track of the last feed it got so we can check if there is a 'next' link //indicating more results to be fetched if (!isset($library->getLastFeed()->links['next'])) { $moreItems = false; } } //output the page ?> <!DOCTYPE html> <html> <head> <title>Dump Items</title> <meta charset="utf-8"> </head> <body> <p>Here we fetch a set of items from our library ordered by title and display the itemKey and title of each item in the list below.</p> <ul>