コード例 #1
0
<?php

require_once './user_writing_config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey);
//create parent item that our attachments will live under
$parentItem = $library->getTemplateItem('book');
$parentItem->set('title', "Attachment Example Parent Book");
//create attachment item and upload imported_file
$importedFileItem = $library->getTemplateItem('attachment', 'imported_file');
//create attachment item that is linked_file
$linkedFileItem = $library->getTemplateItem('attachment', 'linked_file');
//create attachment item that is imported_url
$importedUrlItem = $library->getTemplateItem('attachment', 'imported_url');
//create attachment item that is linked_url
$linkedUrlItem = $library->getTemplateItem('attachment', 'linked_url');
//add child attachment
//get attachment template
echo "adding attachment item\n";
try {
    $templateItem = $library->getTemplateItem('attachment', 'imported_file');
    $templateItem->parentKey = 'HP8M9UQB';
    echo "creating attachment \n";
    $createAttachmentResponse = $library->createItem($templateItem);
    if ($createAttachmentResponse->isError()) {
        echo $createAttachmentResponse->getStatus() . "\n";
        echo $createAttachmentResponse->getBody() . "\n";
        die("Error creating attachment item\n\n");
    } else {
        //read new item we created
コード例 #2
0
 $zlib = new Zotero_Library($libraryType, $libraryID, '', $apiKey);
 $starredCollection = $zlib->createCollection('Google Reader Starred');
 if ($starredCollection === false || $starredCollection->writeFailure != false) {
     print "<p>Error creating collection</p>";
     var_dump($zlib->getLastResponse());
     var_dump($starredCollection->writeFailure);
     die;
 }
 print "<p>New Zotero collection created for google reader starred items with collectionKey {$starredCollection->get('collectionKey')}</p>";
 //read the starred items from the json and create a Zotero item for each one
 $starredObject = json_decode($starredJson, true);
 $starredReaderItems = $starredObject['items'];
 $zItems = array();
 foreach ($starredReaderItems as $readerItem) {
     print "<p>Reader starred item: {$readerItem['title']}</p>";
     $item = $zlib->getTemplateItem('webpage');
     $item->set('title', $readerItem['title']);
     $item->set('date', date('Y-m-d', $readerItem['published']));
     $item->addCreator(array('creatorType' => 'author', 'name' => $readerItem['author']));
     if (array_key_exists('content', $readerItem) && array_key_exists('content', $readerItem['content'])) {
         $item->set('abstractNote', $readerItem['content']['content']);
     } elseif (array_key_exists('summary', $readerItem) && array_key_exists('content', $readerItem['summary'])) {
         $item->set('abstractNote', $readerItem['summary']['content']);
     }
     foreach ($readerItem['alternate'] as $alt) {
         if ($alt['type'] == "text/html") {
             $item->set('url', $alt['href']);
             break;
         }
     }
     $item->addToCollection($starredCollection);
コード例 #3
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
$library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey);
/* create a new item of type book
 * getting a template item causes the appropriate fields to be present in the item
 * without doing this the item doesn't know what fields are valid for this item type
 * even if we do
 */
$newBookItem = $library->getTemplateItem('book');
// give the book a title
$newBookItem->set('title', "Foo");
//create a note item that we'll attach to the book
$newNote = $library->getTemplateItem('note');
$newNote->set('note', "Bar");
//create a second note item we'll also attach
$newNote2 = $library->getTemplateItem('note');
$newNote2->set('note', "Baz");
//Attach the items to the book. Attaching them this way means they'll also be
//written to the Zotero server when we write the book.
$newBookItem->addNote($newNote);
$newBookItem->addNote($newNote2);
//create a journal article item we'll also create in the library
$newJournalItem = $library->getTemplateItem('journalArticle');
$newJournalItem->set('title', 'Bat');
//write multiple items in a single request
//we only pass in the book and journal items, since the notes go with the book
//(Note that we could also create the notes separately by giving them a parentItem,
コード例 #4
0
<?php

require_once './user_writing_config.php';
//library credentials
require_once '../build/libZoteroSingle.php';
$library = new Zotero_Library($libraryType, $libraryID, $librarySlug, $apiKey);
//add child attachment
//get attachment template
echo "adding attachment item\n";
try {
    $templateItem = $library->getTemplateItem('attachment', 'imported_file');
    $templateItem->parentKey = 'HP8M9UQB';
    echo "creating attachment \n";
    $createAttachmentResponse = $library->createItem($templateItem);
    if ($createAttachmentResponse->isError()) {
        echo $createAttachmentResponse->getStatus() . "\n";
        echo $createAttachmentResponse->getBody() . "\n";
        die("Error creating attachment item\n\n");
    } else {
        //read new item we created
        $createdAttachmentFeed = new Zotero_Feed($createAttachmentResponse->getBody());
        $createdAttachment = $library->items->addItemsFromFeed($createdAttachmentFeed);
        $createdAttachment = $createdAttachment[0];
        echo "attachment item created \n";
        //upload file for attachment
        $fileContents = file_get_contents('./zotero_sticker.ai');
        $fileinfo = array('md5' => md5($fileContents), 'filename' => 'zotero_sticker.ai', 'filesize' => filesize('./zotero_sticker.ai'), 'mtime' => filemtime('./zotero_sticker.ai'));
        echo "<br /><br />\n\nFile Info:";
        var_dump($fileinfo);
        $res = $library->uploadNewAttachedFile($createdAttachment, $fileContents, $fileinfo);
        if ($res) {
コード例 #5
0
<?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");