function rksnwp_sync_evernote()
{
    global $rksnwp_path;
    global $rksnwp_options;
    $sdk_path = $rksnwp_path . "lib/";
    require_once $sdk_path . 'autoload.php';
    require_once $sdk_path . 'Evernote/Client.php';
    require_once $sdk_path . 'packages/Errors/Errors_types.php';
    require_once $sdk_path . 'packages/Types/Types_types.php';
    require_once $sdk_path . 'packages/Limits/Limits_constants.php';
    $authToken = $rksnwp_options['evernote']['auth_token'];
    if ($authToken == "your developer token") {
        print "Please fill in your developer token\n";
        print "To get a developer token, visit https://www.evernote.com/api/DeveloperToken.action\n";
        exit(1);
    }
    $client = new Client(array('token' => $authToken, 'sandbox' => false));
    $userStore = $client->getUserStore();
    $noteStore = $client->getNoteStore();
    $search_words = apply_filters('sentinote_evernote_search_string', '');
    // Search and retrieve notes
    $search = new NoteFilter();
    $search->words = $search_words;
    $offset = 0;
    $pageSize = 10;
    $notes = null;
    $guids = array();
    // Evernote GUIDs
    // Find and process each note
    do {
        $result = $noteStore->findNotes($search, $offset, $pageSize);
        $notes = $result->notes;
        if (is_array($notes)) {
            if (count($notes) > 0) {
                foreach ($notes as $note) {
                    // Keep track of read notes
                    array_push($guids, $note->guid);
                    // Note Args
                    $theNote = apply_filters('sentinote_process_en_note_data', array('guid' => $note->guid, 'title' => $note->title, 'updated' => $note->updated, 'created' => $note->created, 'tag_guids' => $note->tagGuids, 'resources' => $note->resources, 'resource_path' => array(), 'resource_url' => array(), 'resource_hash' => array(), 'latitude' => $note->attributes->latitude, 'longitude' => $note->attributes->longitude, 'altitude' => $note->attributes->altitude, 'author' => $note->attributes->author, 'tag_names' => array(), 'action' => 'none', 'content' => null, 'note_store' => $noteStore, 'wp_post' => null, 'wp_attachments' => array()));
                    do_action('sentinote_process_en_note', $theNote);
                    wp_reset_query();
                    // just to be safe
                }
            }
        }
        $offset = $offset + $pageSize;
    } while ($result->totalNotes > $offset);
    do_action('sentinote_evernote_remove_posts', $guids);
}
Example #2
0
function listNotebooks()
{
    global $lastError, $currentStatus;
    try {
        $accessToken = $_SESSION['accessToken'];
        $client = new Client(array('token' => $accessToken, 'sandbox' => SANDBOX));
        $notebooks = $client->getNoteStore()->listNotebooks();
        $result = array();
        if (!empty($notebooks)) {
            foreach ($notebooks as $notebook) {
                $result[] = $notebook->name;
            }
        }
        $_SESSION['notebooks'] = $result;
        $currentStatus = 'Successfully listed content owner\'s notebooks';
        return TRUE;
    } catch (EDAMSystemException $e) {
        if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
            $lastError = 'Error listing notebooks: ' . EDAMErrorCode::$__names[$e->errorCode] . ": " . $e->parameter;
        } else {
            $lastError = 'Error listing notebooks: ' . $e->getCode() . ": " . $e->getMessage();
        }
    } catch (EDAMUserException $e) {
        if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
            $lastError = 'Error listing notebooks: ' . EDAMErrorCode::$__names[$e->errorCode] . ": " . $e->parameter;
        } else {
            $lastError = 'Error listing notebooks: ' . $e->getCode() . ": " . $e->getMessage();
        }
    } catch (EDAMNotFoundException $e) {
        if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
            $lastError = 'Error listing notebooks: ' . EDAMErrorCode::$__names[$e->errorCode] . ": " . $e->parameter;
        } else {
            $lastError = 'Error listing notebooks: ' . $e->getCode() . ": " . $e->getMessage();
        }
    } catch (Exception $e) {
        $lastError = 'Error listing notebooks: ' . $e->getMessage();
    }
    return FALSE;
}
Example #3
0
set_exception_handler('en_exception_handler');
// Real applications authenticate with Evernote using OAuth, but for the
// purpose of exploring the API, you can get a developer token that allows
// you to access your own Evernote account. To get a developer token, visit
// https://sandbox.evernote.com/api/DeveloperToken.action
$authToken = "your developer token";
if ($authToken == "your developer token") {
    print "Please fill in your developer token\n";
    print "To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action\n";
    exit(1);
}
// Initial development is performed on our sandbox server. To use the production
// service, change "sandbox.evernote.com" to "www.evernote.com" and replace your
// developer token above with a token from
// https://www.evernote.com/api/DeveloperToken.action
$client = new Client(array('token' => $authToken));
$userStore = $client->getUserStore();
// Connect to the service and check the protocol version
$versionOK = $userStore->checkVersion("Evernote EDAMTest (PHP)", $GLOBALS['EDAM_UserStore_UserStore_CONSTANTS']['EDAM_VERSION_MAJOR'], $GLOBALS['EDAM_UserStore_UserStore_CONSTANTS']['EDAM_VERSION_MINOR']);
print "Is my Evernote API version up to date?  " . $versionOK . "\n\n";
if ($versionOK == 0) {
    exit(1);
}
$noteStore = $client->getNoteStore();
// List all of the notebooks in the user's account
$notebooks = $noteStore->listNotebooks();
print "Found " . count($notebooks) . " notebooks\n";
foreach ($notebooks as $notebook) {
    print "    * " . $notebook->name . "\n";
}
print "\nCreating a new note in the default notebook\n\n";
Example #4
0
 function getAuthorizationUrl()
 {
     $client = new Client(array('consumerKey' => $this->config->item('evernote/consumer_key'), 'consumerSecret' => $this->config->item('evernote/consumer_secret'), 'sandbox' => $this->config->item('evernote/sandbox')));
     return $client->getAuthorizeUrl($_SESSION['requestToken']);
 }
Example #5
0
function getAuthorizationUrl()
{
    $client = new Client(array('consumerKey' => OAUTH_CONSUMER_KEY, 'consumerSecret' => OAUTH_CONSUMER_SECRET, 'sandbox' => SANDBOX));
    return $client->getAuthorizeUrl($_SESSION['requestToken']);
}