echo ZOTPRESS_PLUGIN_URL;
?>
js/jquery-1.5.2.min.js"></script>
        <script type="text/javascript" src="<?php 
echo ZOTPRESS_PLUGIN_URL;
?>
js/jquery.livequery.min.js"></script>
    </head>
    
    <body><?php 
// START WITH ITEMS
if (isset($_GET['step']) && $_GET['step'] == "items") {
    $api_user_id = zp_get_api_user_id();
    if (isset($_SESSION['zp_session'][$api_user_id]['key']) && isset($_GET['key']) && $_SESSION['zp_session'][$api_user_id]['key'] == $_GET['key']) {
        // Get account
        $_SESSION['zp_session'][$api_user_id]['zp_account'] = zp_get_account($wpdb, $api_user_id);
        // Set current sync time
        zp_set_update_time(date('Y-m-d'));
        // GET ITEM COUNT AND LOCAL ITEMS
        $_SESSION['zp_session'][$api_user_id]['items']['zp_local_items'] = zp_get_local_items($wpdb, $api_user_id);
        // Set up session item query vars
        $_SESSION['zp_session'][$api_user_id]['items']['zp_items_to_add'] = array();
        $_SESSION['zp_session'][$api_user_id]['items']['zp_items_to_update'] = array();
        $_SESSION['zp_session'][$api_user_id]['items']['query_total_items_to_add'] = 0;
        // SYNC ITEMS
        ?>
<script type="text/javascript">
            
            jQuery(document).ready(function()
            {
                function zp_get_items (zp_plugin_url, api_user_id, zp_key, zp_start)
Example #2
0
 }
 // IMPORT NEW STYLES
 if ($errorCheck == false) {
     $zp_items_current_style_proceed = false;
     // If style's already been changed, leave it
     $query_items = str_replace(",", "','", $items);
     $zp_items_current_style = $wpdb->get_results("SELECT style FROM " . $wpdb->prefix . "zotpress_zoteroItems WHERE item_key IN ('" . $query_items . "');", OBJECT);
     foreach ($zp_items_current_style as $current_style) {
         if ($current_style->style != $style) {
             $zp_items_current_style_proceed = true;
         }
     }
     if ($zp_items_current_style_proceed) {
         $zp_import_contents = new ZotpressRequest();
         // Get account
         $zp_account = zp_get_account($wpdb, $api_user_id);
         // Figure out whether account needs a key
         //$nokey = zp_get_account_haskey ($zp_account);
         $zp_import_url = "https://api.zotero.org/" . $zp_account[0]->account_type . "/" . $zp_account[0]->api_user_id . "/items?";
         if (is_null($zp_account[0]->public_key) === false && trim($zp_account[0]->public_key) != "") {
             $zp_import_url .= "key=" . $zp_account[0]->public_key . "&";
         }
         $zp_import_url .= "format=atom&content=bib&style=" . $style . "&itemKey=" . $items;
         // Read the external data
         $zp_xml = $zp_import_contents->get_request_contents($zp_import_url, false);
         // Make it DOM-traversable
         $doc_citations = new DOMDocument();
         $doc_citations->loadXML($zp_xml);
         $entries = $doc_citations->getElementsByTagName("entry");
         foreach ($entries as $entry) {
             $item_key = $entry->getElementsByTagNameNS("http://zotero.org/ns/api", "key")->item(0)->nodeValue;
Example #3
0
function zp_get_server_tags($wpdb, $api_user_id, $zp_start)
{
    $zp_import_contents = new ZotpressRequest();
    $zp_account = zp_get_account($wpdb, $api_user_id);
    //$zp_account = $GLOBALS['zp_session'][$api_user_id]['zp_account'];
    // Build request URL
    $zp_import_url = "https://api.zotero.org/" . $zp_account[0]->account_type . "/" . $zp_account[0]->api_user_id . "/tags?limit=50&start=" . $zp_start;
    if (is_null($zp_account[0]->public_key) === false && trim($zp_account[0]->public_key) != "") {
        $zp_import_url .= "&key=" . $zp_account[0]->public_key;
    }
    $zp_xml = $zp_import_contents->get_request_contents($zp_import_url, false);
    // Make it DOM-traversable
    $doc_citations = new DOMDocument();
    $doc_citations->loadXML($zp_xml);
    // Get last set
    if (!isset($GLOBALS['zp_session'][$api_user_id]['tags']['last_set'])) {
        $last_set = "";
        $links = $doc_citations->getElementsByTagName("link");
        foreach ($links as $link) {
            if ($link->getAttribute('rel') == "last") {
                if (stripos($link->getAttribute('href'), "start=") !== false) {
                    $last_set = explode("start=", $link->getAttribute('href'));
                    $GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] = intval($last_set[1]);
                } else {
                    $GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] = 0;
                }
            }
        }
    }
    $entries = $doc_citations->getElementsByTagName("entry");
    foreach ($entries as $entry) {
        $title = $entry->getElementsByTagName("title")->item(0)->nodeValue;
        $retrieved = $entry->getElementsByTagName("updated")->item(0)->nodeValue;
        // Check to see if tags exists in local
        if (array_key_exists(trim($title), $GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'])) {
            // Check to see if it needs updating
            if ($retrieved != $GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'][trim($title)]->retrieved) {
                $GLOBALS['zp_session'][$api_user_id]['tags']['zp_tags_to_update'][trim($title)] = $GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'][trim($title)]->id;
                //unset($GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'][trim($title)]); // Leave only the local ones that should be deleted
                update_option('ZOTPRESS_DELETE_' . $api_user_id, get_option('ZOTPRESS_DELETE_' . $api_user_id) . "," . $item_key);
            } else {
                //unset($GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'][trim($title)]); // Leave only the local ones that should be deleted
                update_option('ZOTPRESS_DELETE_' . $api_user_id, get_option('ZOTPRESS_DELETE_' . $api_user_id) . "," . $item_key);
                continue;
            }
        }
        $numItems = $entry->getElementsByTagNameNS("http://zotero.org/ns/api", "numItems")->item(0)->nodeValue;
        unset($zp_import_contents);
        unset($zp_import_url);
        unset($zp_xml);
        // GET LIST OF ITEM KEYS
        $zp_import_contents = new ZotpressRequest();
        $zp_import_url = "https://api.zotero.org/" . $zp_account[0]->account_type . "/" . $zp_account[0]->api_user_id . "/tags/" . urlencode($title) . "/items?format=keys";
        if (is_null($zp_account[0]->public_key) === false && trim($zp_account[0]->public_key) != "") {
            $zp_import_url .= "&key=" . $zp_account[0]->public_key;
        }
        // Import content
        $zp_xml = $zp_import_contents->get_request_contents($zp_import_url, false);
        $zp_tag_itemkeys = rtrim(str_replace("\n", ",", $zp_xml), ",");
        // If item key needs updating
        if (array_key_exists(trim($title), $GLOBALS['zp_session'][$api_user_id]['tags']['zp_tags_to_update'])) {
            $GLOBALS['zp_session'][$api_user_id]['tags']['zp_tags_to_update'][trim($title)] = array("api_user_id" => $zp_account[0]->api_user_id, "title" => zp_db_prep($title), "retrieved" => zp_db_prep($retrieved), "numItems" => $numItems, "listItems" => zp_db_prep($zp_tag_itemkeys));
        } else {
            if (!array_key_exists(trim($title), $GLOBALS['zp_session'][$api_user_id]['tags']['zp_local_tags'])) {
                array_push($GLOBALS['zp_session'][$api_user_id]['tags']['zp_tags_to_add'], $zp_account[0]->api_user_id, zp_db_prep($title), zp_db_prep($retrieved), $numItems, zp_db_prep($zp_tag_itemkeys));
                $GLOBALS['zp_session'][$api_user_id]['tags']['query_total_tags_to_add']++;
            }
        }
        unset($title);
        unset($retrieved);
        unset($numItems);
        unset($zp_tag_itemkeys);
    }
    // entry
    // LAST SET
    if ($GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] == $zp_start) {
        return false;
    } else {
        return true;
    }
    unset($zp_import_contents);
    unset($zp_import_url);
    unset($zp_xml);
    unset($doc_citations);
    unset($entries);
}
function zp_get_tags($wpdb, $api_user_id, $zp_start, $zp_collection = false)
{
    $zp_import_contents = new ZotpressRequest();
    $zp_account = zp_get_account($wpdb, $api_user_id);
    // Get import url
    if ($zp_collection) {
        $zp_collection = '/collections/' . $zp_collection;
    } else {
        $zp_collection = '';
    }
    $zp_import_url = "https://api.zotero.org/" . $zp_account[0]->account_type . "/" . $zp_account[0]->api_user_id . $zp_collection . "/tags?limit=50&start=" . $zp_start;
    if (is_null($zp_account[0]->public_key) === false && trim($zp_account[0]->public_key) != "") {
        $zp_import_url .= "&key=" . $zp_account[0]->public_key;
    }
    // Import content
    $zp_xml = $zp_import_contents->get_request_contents($zp_import_url, false);
    // Report any errors returned from Zotero
    if (trim(strtolower($zp_xml)) == "forbidden") {
        return "Zotero is telling Zotpress that access is forbidden. Are you sure that the Zotero API key you're using for this account is correct?";
    }
    // Make it DOM-traversable
    $doc_citations = new DOMDocument();
    $doc_citations->loadXML($zp_xml);
    // Get last set
    if (!isset($GLOBALS['zp_session'][$api_user_id]['tags']['last_set'])) {
        $last_set = "";
        $links = $doc_citations->getElementsByTagName("link");
        foreach ($links as $link) {
            if ($link->getAttribute('rel') == "last") {
                if (stripos($link->getAttribute('href'), "start=") !== false) {
                    $last_set = explode("start=", $link->getAttribute('href'));
                    $GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] = intval($last_set[1]);
                } else {
                    $GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] = 0;
                }
            }
        }
    }
    // PREPARE EACH ENTRY FOR DB INSERT
    $entries = $doc_citations->getElementsByTagName("entry");
    foreach ($entries as $entry) {
        $title = str_replace("&", "__and__", $entry->getElementsByTagName("title")->item(0)->nodeValue);
        $retrieved = $entry->getElementsByTagName("updated")->item(0)->nodeValue;
        $numItems = $entry->getElementsByTagNameNS("http://zotero.org/ns/api", "numItems")->item(0)->nodeValue;
        unset($zp_import_contents);
        unset($zp_import_url);
        unset($zp_xml);
        // GET LIST OF ITEM KEYS - now handled in Items import
        //            $zp_import_contents = new ZotpressRequest();
        //
        //            $zp_import_url = "https://api.zotero.org/".$zp_account[0]->account_type."/".$zp_account[0]->api_user_id."/tags/".urlencode($title)."/items?format=keys";
        //            if (is_null($zp_account[0]->public_key) === false && trim($zp_account[0]->public_key) != "")
        //                $zp_import_url .= "&key=".$zp_account[0]->public_key;
        //
        //            // Import content
        //			$zp_xml = $zp_import_contents->get_request_contents( $zp_import_url, false );
        //
        //            $zp_tag_itemkeys = rtrim(str_replace("\n", ",", $zp_xml), ",");
        //
        //            unset($zp_import_contents);
        //            unset($zp_import_url);
        //            unset($zp_xml);
        // Prep for insert into db
        array_push($GLOBALS['zp_session'][$api_user_id]['tags']['query_params'], $zp_account[0]->api_user_id, zp_db_prep($title), zp_db_prep($retrieved), $numItems);
        $GLOBALS['zp_session'][$api_user_id]['tags']['query_total_entries']++;
        unset($title);
        unset($retrieved);
        unset($numItems);
        //unset($zp_tag_itemkeys);
    }
    // entry
    // LAST SET
    if ($GLOBALS['zp_session'][$api_user_id]['tags']['last_set'] == $zp_start) {
        return false;
    } else {
        return true;
    }
    unset($entries);
    unset($doc_citations);
}