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); }
<!DOCTYPE html> <?php require_once './config.php'; //library credentials require_once '../build/libZoteroSingle.php'; $library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey); //load a couple items with multiple content types $items = $library->fetchItemsTop(array('limit' => 2, 'content' => 'json,bib')); ?> <html> <head> <title>Multi-Content</title> <meta charset="utf-8"> </head> <body> <h2>Multi-Content</h2> <?foreach($items as $item):?> <p>Citation:</p> <p><?php echo $item->bibContent; ?> </p> <p>JSON encoded metadata:</p> <p> <?php echo json_encode($item->apiObject); ?> </p> <?endforeach;?> </body> </html>
//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) { 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>
<!DOCTYPE html> <?php require_once './config.php'; //library credentials require_once '../build/libZoteroSingle.php'; $library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey); $library->setCacheTtl(90); //load a couple items with multiple content types $items = $library->fetchItemsTop(array('limit' => 10, 'content' => 'bib,citation,coins', 'linkwrap' => 1, 'style' => 'chicago-fullnote-bibliography')); ?> <html> <head> <title>Multi-Content</title> <meta charset="utf-8"> </head> <body> <h2>Bib-Content</h2> <?foreach($items as $item):?> <? $doc = new DOMDocument(); $doc->loadXml($item->bibContent); $linkNodes = $doc->getElementsByTagName("a"); foreach($linkNodes as $node){ $node->nodeValue = "Link"; } $newBibContent = $doc->saveXML(); ?> <p><?php echo $newBibContent; ?> </p>
<!DOCTYPE html> <?php //load credentials and library info from our config file require_once './config.php'; //load the zotero php library require_once '../build/libZoteroSingle.php'; //create a library object to interact with the zotero API $library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey); //use Alternative PHP Cache to save API responses for 30 minutes $library->setCacheTtl(1800); //fetch most recently added items from a collection //since the collection will never change we just use a hard coded collection key //that was set in our config file $items = $library->fetchItemsTop(array('limit' => 10, 'collectionKey' => $collectionKey, 'order' => 'dateAdded', 'sort' => 'desc')); //output the page //if the item has a url, we'll turn the title into a link ?> <html> <head> <title>Recent Items</title> <meta charset="utf-8"> </head> <body> <ul> <?foreach($items as $item):?> <li> <?$url = $item->get('url');?> <?if($url):?> <a href="<?php echo $url;
<!DOCTYPE html> <?php require_once './config.php'; //library credentials require_once '../build/libZoteroSingle.php'; $library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey); //fetch subcollections of a collection $collections = $library->fetchCollections(array('collectionKey' => '', 'content' => 'json')); $collectionKey = ''; if (count($collections)) { $collectionKey = $collections[0]->collectionKey; } //fetch items from this library $items = $library->fetchItemsTop(array('limit' => 10, 'collectionKey' => $collectionKey)); ?> <html> <head> <title>Collection and Items</title> <meta charset="utf-8"> </head> <body> <h2>Collections</h2> <ul> <?foreach($collections as $collection):?> <li><?php echo $collection->name; ?> : <?php echo $collection->collectionKey; ?> </li>