<!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, 'include' => 'data,bib'));
?>
<html>
<head>
    <title>Multi-Content</title>
    <meta charset="utf-8">
</head>
<body>
    <h2>Multi-Content</h2>
    <?php 
foreach ($items as $item) {
    ?>
    <p>Citation:</p>
    <p><?php 
    echo $item->bibContent;
    ?>
</p>
    <p>JSON encoded metadata:</p>
    <p>
    <?php 
    echo json_encode($item->apiObj['data']);
    ?>
    </p>
    <?php 
示例#2
0
<?php

require_once './config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
//load all itemkeys in the library
$itemKeys = $library->fetchItemKeys();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Item Keys</title>
    <meta charset="utf-8">
</head>
<body>
    <p>List of all item keys in the library.</p>
    <p>There are a total of <?php 
echo count($itemKeys);
?>
 items in this library/collection, including top level items and their children (notes/attachments).</p>
    <ul>
        <?php 
foreach ($itemKeys as $itemKey) {
    ?>
        <li><?php 
    echo $itemKey;
    ?>
</li>
        <?php 
}
<?php

require_once './user_writing_config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $userSlug, $apiKey);
//create a new item of type book
$newItem = $library->getTemplateItem('book');
$newItem->set('title', 'This is a book');
$newItem->set('abstractNote', 'Created using a zotero php library and the write api');
$createItemResponse = $library->createItem($newItem);
if ($createItemResponse->isError()) {
    echo $createItemResponse->getStatus() . "\n";
    echo $createItemResponse->getBody() . "\n";
    die("Error creating Zotero item\n\n");
} else {
    //load the item into the library so it is included and has the itemKey and etag
    //and anything else the api populates that we didn't set in our item
    $createItemFeed = new Zotero_Feed($createItemResponse->getBody());
    $createdItem = $library->items->addItemsFromFeed($createItemFeed);
    $createdItem = $createdItem[0];
    echo "Item created\n\n\n<br />";
}
$existingItem = new Zotero_Item($createItemResponse->getBody());
//add child note
$newNoteItem = $library->getTemplateItem('note');
$addNoteResponse = $library->addNotes($existingItem, $newNoteItem);
if ($addNoteResponse->isError()) {
    echo $addNoteResponse->getStatus() . "\n";
    echo $addNoteResponse->getBody() . "\n";
    die("error adding child note to item");
示例#4
0
<?php

//library credentials
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, $userSlug, $apiKey);
//use Alternative PHP Cache to save API responses for 30 minutes
//this will cache unique api responses so we get faster responses
//and don't get rate-limited by the API for making too many requests
$library->setCacheTtl(1800);
//parameters we'll pass when retrieving items to order by item titles
$params = array('order' => 'title');
//restrict the total items we'll fetch to 200
$totalItemLimit = 100;
//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 = 20;
//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
示例#5
0
<!DOCTYPE html>
<?php 
require_once './config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
//load the items currently in the trash
$trashedItems = $library->fetchTrashedItems(array('limit' => 10));
?>
<html>
<head>
    <title>Trash</title>
    <meta charset="utf-8">
</head>
<body>
    <h2>Trashed Items</h2>
    <?php 
if (count($trashedItems) == 0) {
    ?>
    <p>There are no items in this library's trash</p>
    <?php 
} else {
    ?>
    <ul>
        <?php 
    foreach ($trashedItems as $item) {
        ?>
        <li><?php 
        echo $item->get('title');
        ?>
</li>
示例#6
0
<!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, 'include' => '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>
    <?php 
foreach ($items as $item) {
    ?>
    <?php 
    $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;
示例#7
0
<!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>
    <?php 
foreach ($items as $item) {
    ?>
        <li>
        <?php 
    $url = $item->get('url');
示例#8
0
<!DOCTYPE html>
<?php 
require_once './config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
//get permissions for the key
$userID = '';
$key = '';
$permissions = $library->getKeyPermissions($userID, $key);
?>
<html>
<head>
    <title>Key Permissions</title>
    <meta charset="utf-8">
</head>
<body>
    <h2>Key Permissions</h2>
    <?php 
if ($key == '') {
    ?>
        No key specified in library.
    <?php 
} else {
    ?>
        <?php 
    echo json_encode($permissions, JSON_PRETTY_PRINT);
    ?>
    <?php 
}
?>
示例#9
0
<?php

require_once './user_writing_config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
//create the zotero library object which will be our interface for interacting with the Zotero API
$zlib = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
$zItems = array();
for ($i = 0; $i < 5; $i++) {
    $item = $zlib->getTemplateItem('webpage');
    $item->set('title', 'zotero webpage item');
    $zItems[] = $item;
}
#make the request to save the items to the Zotero server
$writtenItems = $zlib->items->writeItems($zItems);
#individual items may fail even if the request goes through, so we should check each one for errors
foreach ($writtenItems as $item) {
    if ($item->writeFailure != false) {
        echo "Failed writing item {$item->writeFailure['key']} - {$item->get('title')}\n";
        echo "Status code: {$item->writeFailure['code']}\n";
        echo "Message: {$item->writeFailure['message']}\n\n";
    } else {
        echo "Item successfully created. itemKey: {$item->get('itemKey')} - {$item->get('title')}";
    }
}
#get the version of the last item to use for delete requests
$version = $writtenItems[count($writtenItems) - 1]->get('itemVersion');
#split written items into chunks since we can only delete 50 at a time
$chunks = array_chunk($writtenItems, 50);
foreach ($chunks as $chunk) {
    $deletedItemResponse = $zlib->items->deleteItems($chunk, $version);
示例#10
0
<!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>
        <?php 
foreach ($collections as $collection) {
    ?>
        <li><?php 
    echo $collection->name;
    ?>
 : <?php 
    echo $collection->collectionKey;
示例#11
0
<!DOCTYPE html>
<?php 
require_once './config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
if (isset($_GET['userID'])) {
    $cv = $library->getCV($_GET['userID']);
} else {
    $cv = false;
}
?>
<html>
<head>
    <title>User C.V.</title>
    <meta charset="utf-8">
</head>
<body>
    <h2>User C.V.</h2>
    <?php 
if ($cv) {
    ?>
        <?php 
    foreach ($cv as $section) {
        ?>
            <div class='cv-section' style="padding:5px; margin:5px;">
            <h2><?php 
        echo $section['title'];
        ?>
</h2>
            <?php 
示例#12
0
<!DOCTYPE html>
<?php 
require_once './config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new \Zotero\Library($libraryType, $libraryID, $librarySlug, $apiKey);
//get some tags
$tags = $library->fetchTags(array('limit' => 20, 'order' => 'title', 'sort' => 'desc'));
?>
<html>
<head>
    <title>Tags</title>
    <meta charset="utf-8">
</head>
<body>
    <h2>Tags</h2>
    <ul>
        <?php 
foreach ($tags as $tag) {
    ?>
        <li><?php 
    echo $tag->name;
    ?>
 has <?php 
    echo $tag->numItems;
    ?>
 items associated with it.</li>
        <?php 
}
?>
    </ul>