getNoteStore() protected method

************************
protected getNoteStore ( $noteStoreUrl )
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
    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";
// To create a new note, simply create a new Note object and fill in
// attributes such as the note's title.
$note = new Note();
$note->title = "Test note from EDAMTest.php";
// To include an attachment such as an image in a note, first create a Resource
// for the attachment. At a minimum, the Resource contains the binary attachment
// data, an MD5 hash of the binary data, and the attachment MIME type. It can also
// include attributes such as filename and location.
Example #4
0
 function create($itm_id)
 {
     if (!$this->axipi_session->userdata('mbr_id')) {
         redirect(base_url());
     }
     $this->readerself_library->set_template('_json');
     $this->readerself_library->set_content_type('application/json');
     $data = array();
     $content = array();
     $content['itm_id'] = $itm_id;
     $data['itm'] = $this->db->query('SELECT * FROM ' . $this->db->dbprefix('items') . ' AS itm WHERE itm.itm_id = ? AND itm.fed_id IN ( SELECT sub.fed_id FROM ' . $this->db->dbprefix('subscriptions') . ' AS sub WHERE sub.fed_id = itm.fed_id AND sub.mbr_id = ? ) GROUP BY itm.itm_id', array($itm_id, $this->member->mbr_id))->row();
     if ($data['itm'] && $this->input->is_ajax_request()) {
         $token = $this->readerself_model->get_token('evernote', $this->member->mbr_id, $this->config->item('evernote/sandbox'));
         if ($token) {
             try {
                 $client = new Client(array('token' => $this->readerself_model->get_token('evernote', $this->member->mbr_id, $this->config->item('evernote/sandbox')), 'sandbox' => $this->config->item('evernote/sandbox')));
                 $noteStore = $client->getNoteStore();
                 $list_notebooks = $client->getNoteStore()->listNotebooks();
                 $data['notebooks'] = array();
                 if (!empty($list_notebooks)) {
                     foreach ($list_notebooks as $notebook) {
                         $data['notebooks'][$notebook->guid] = $notebook->name;
                     }
                 }
                 $this->load->library(array('form_validation'));
                 $this->form_validation->set_rules('notebook', 'Notebook', 'required');
                 if ($this->form_validation->run() == FALSE) {
                     $content['modal'] = $this->load->view('evernote_create', $data, TRUE);
                     $this->readerself_library->set_content($content);
                 } else {
                     $noteAttributes = new NoteAttributes();
                     $noteAttributes->source = 'api';
                     $noteAttributes->sourceURL = trim($data['itm']->itm_link);
                     $noteAttributes->sourceApplication = trim($this->config->item('title'));
                     if ($data['itm']->itm_latitude) {
                         $noteAttributes->latitude = $data['itm']->itm_latitude;
                     }
                     if ($data['itm']->itm_longitude) {
                         $noteAttributes->longitude = $data['itm']->itm_longitude;
                     }
                     $note = new Note();
                     $note->title = trim($data['itm']->itm_title);
                     $note->notebookGuid = $this->input->post('notebook');
                     $note->attributes = $noteAttributes;
                     //get full content with Readability if key exists
                     if ($this->config->item('readability_parser_key')) {
                         $url = 'https://www.readability.com/api/content/v1/parser?url=' . urlencode($data['itm']->itm_link) . '&token=' . $this->config->item('readability_parser_key');
                         $ch = curl_init();
                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                         curl_setopt($ch, CURLOPT_URL, $url);
                         $result = curl_exec($ch);
                         curl_close($ch);
                         $result = json_decode($result);
                         $data['itm']->itm_content = $result->content;
                     }
                     //remove disallowed attributes with DOMDocument
                     if (class_exists('DOMDocument')) {
                         $dom = new DOMDocument();
                         $dom->loadHTML($data['itm']->itm_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
                         $xpath = new DOMXPath($dom);
                         $disallowed_attributes = array('id', 'class', 'onclick', 'ondblclick', 'onmouseover', 'onmouseout', 'accesskey', 'data', 'dynsrc', 'tabindex');
                         foreach ($disallowed_attributes as $attribute) {
                             $nodes = $xpath->query('//*[@' . $attribute . ']');
                             foreach ($nodes as $node) {
                                 $node->removeAttribute($attribute);
                             }
                         }
                         $data['itm']->itm_content = $dom->saveHTML();
                     }
                     //clean all with Tidy
                     if (class_exists('Tidy')) {
                         $options = array('output-xhtml' => true, 'clean' => true, 'wrap-php' => true, 'doctype' => 'omit', 'show-body-only' => true, 'drop-proprietary-attributes' => true);
                         $tidy = new tidy();
                         $tidy->parseString($data['itm']->itm_content, $options, 'utf8');
                         $tidy->cleanRepair();
                         $data['itm']->itm_content = $tidy;
                     }
                     //keep only allowed tags
                     strip_tags($data['itm']->itm_content, '<a>,<abbr>,<acronym>,<address>,<area>,<b>,<bdo>,<big>,<blockquote>,<br/>,<caption>,<center>,<cite>,<code>,<col>,<colgroup>,<dd>,<del>,<dfn>,<div>,<dl>,<dt>,<em>,<font>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<hr/>,<i>,<img>,<ins>,<kbd>,<li>,<map>,<ol>,<p>,<pre>,<q>,<s>,<samp>,<small>,<span>,<strike>,<strong>,<sub>,<sup>,<table>,<tbody>,<td>,<tfoot>,<th>,<thead>,<title>,<tr>,<tt>,<u>,<ul>,<var>,<xmp>');
                     $note->content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>' . $data['itm']->itm_content . '</en-note>';
                     try {
                         $createdNote = $noteStore->createNote($note);
                         $data['status'] = 'note_added';
                         $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                         $this->readerself_library->set_content($content);
                     } catch (EDAMUserException $e) {
                         $data['status'] = 'error';
                         $data['message'] = $e->parameter;
                         $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                         $this->readerself_library->set_content($content);
                     } catch (EDAMNotFoundException $e) {
                         $data['status'] = 'error';
                         $data['message'] = $e->getMessage();
                         $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                         $this->readerself_library->set_content($content);
                     }
                 }
             } catch (EDAMSystemException $e) {
                 $data['status'] = 'error';
                 if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
                     $data['message'] = EDAMErrorCode::$__names[$e->errorCode] . ': ' . $e->parameter;
                 } else {
                     $data['message'] = $e->getCode() . ': ' . $e->getMessage();
                 }
                 $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                 $this->readerself_library->set_content($content);
             } catch (EDAMUserException $e) {
                 $data['status'] = 'error';
                 if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
                     if (EDAMErrorCode::$__names[$e->errorCode] == 'AUTH_EXPIRED') {
                         $data['status'] = 'no_token';
                     }
                     $data['message'] = EDAMErrorCode::$__names[$e->errorCode] . ': ' . $e->parameter;
                 } else {
                     $data['message'] = $e->getCode() . ': ' . $e->getMessage();
                 }
                 $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                 $this->readerself_library->set_content($content);
             } catch (EDAMNotFoundException $e) {
                 $data['status'] = 'error';
                 if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
                     $data['message'] = EDAMErrorCode::$__names[$e->errorCode] . ': ' . $e->parameter;
                 } else {
                     $data['message'] = $e->getCode() . ': ' . $e->getMessage();
                 }
                 $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                 $this->readerself_library->set_content($content);
             } catch (Exception $e) {
                 $data['status'] = 'error';
                 $data['message'] = $e->getMessage();
                 $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
                 $this->readerself_library->set_content($content);
             }
         } else {
             $data['status'] = 'no_token';
             $content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
             $this->readerself_library->set_content($content);
         }
     } else {
         $this->output->set_status_header(403);
     }
 }