Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanediondev committed Aug 14, 2015
1 parent 242a90f commit cf2c446
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 157 deletions.
192 changes: 89 additions & 103 deletions application/controllers/Evernote.php
Expand Up @@ -71,44 +71,6 @@ public function callback() {
redirect(base_url().'evernote');
}
}
/*function list_notebooks() {
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')
));
$notebooks = $client->getNoteStore()->listNotebooks();
$result = array();
if (!empty($notebooks)) {
foreach ($notebooks as $notebook) {
$result[] = $notebook->name;
}
}
print_r($result);
return TRUE;
} catch (EDAMSystemException $e) {
if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
$lastError = EDAMErrorCode::$__names[$e->errorCode].': '.$e->parameter;
} else {
$lastError = $e->getCode().': '.$e->getMessage();
}
} catch (EDAMUserException $e) {
if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
$lastError = EDAMErrorCode::$__names[$e->errorCode].': '.$e->parameter;
} else {
$lastError = $e->getCode().': '.$e->getMessage();
}
} catch (EDAMNotFoundException $e) {
if (isset(EDAMErrorCode::$__names[$e->errorCode])) {
$lastError = EDAMErrorCode::$__names[$e->errorCode].': '.$e->parameter;
} else {
$lastError = $e->getCode().': '.$e->getMessage();
}
} catch (Exception $e) {
$lastError = $e->getMessage();
}
}*/
function create($itm_id) {
if(!$this->axipi_session->userdata('mbr_id')) {
redirect(base_url());
Expand All @@ -123,6 +85,7 @@ function create($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 {
Expand All @@ -132,85 +95,107 @@ function create($itm_id) {
));
$noteStore = $client->getNoteStore();

$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;
$list_notebooks = $client->getNoteStore()->listNotebooks();
$data['notebooks'] = array();
if(!empty($list_notebooks)) {
foreach ($list_notebooks as $notebook) {
$data['notebooks'][$notebook->guid] = $notebook->name;
}
}

$note = new Note();
$note->title = trim($data['itm']->itm_title);
$note->attributes = $noteAttributes;
$this->load->library(array('form_validation'));

//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;
}
$this->form_validation->set_rules('notebook', 'Notebook', 'required');

//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);
if($this->form_validation->run() == FALSE) {
$content['modal'] = $this->load->view('evernote_create', $data, TRUE);
$this->readerself_library->set_content($content);

$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);
} 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();
}
$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;
}
//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>');
//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>';
$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';
} catch (EDAMUserException $e) {
$data['status'] = 'error';
$data['message'] = $e->parameter;
$content['modal'] = $this->load->view('evernote_create', $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', $data, TRUE);
$this->readerself_library->set_content($content);
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', $data, TRUE);
$content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
$this->readerself_library->set_content($content);
} catch (EDAMUserException $e) {
$data['status'] = 'error';
Expand All @@ -222,7 +207,7 @@ function create($itm_id) {
} else {
$data['message'] = $e->getCode().': '.$e->getMessage();
}
$content['modal'] = $this->load->view('evernote_create', $data, TRUE);
$content['modal'] = $this->load->view('evernote_create_confirm', $data, TRUE);
$this->readerself_library->set_content($content);
} catch (EDAMNotFoundException $e) {
$data['status'] = 'error';
Expand All @@ -231,22 +216,23 @@ function create($itm_id) {
} else {
$data['message'] = $e->getCode().': '.$e->getMessage();
}
$content['modal'] = $this->load->view('evernote_create', $data, TRUE);
$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', $data, TRUE);
$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);
}
$content['modal'] = $this->load->view('evernote_create', $data, TRUE);
$this->readerself_library->set_content($content);
}
function getTemporaryCredentials() {
try {
Expand Down
15 changes: 11 additions & 4 deletions application/controllers/Item.php
Expand Up @@ -117,19 +117,26 @@ public function email($itm_id) {
if($query->num_rows() > 0) {
$data['itm'] = $query->row();

if($data['itm']->auh_id) {
$sql = 'SELECT auh.* FROM '.$this->db->dbprefix('authors').' AS auh WHERE auh.auh_id = ? GROUP BY auh.auh_id';
$data['itm']->auh = $this->db->query($sql, array($data['itm']->auh_id))->row();
} else {
$data['itm']->auh = false;
}

$sql = 'SELECT sub.sub_id, sub.sub_title, fed.fed_title, sub.sub_direction, fed.fed_direction, flr.flr_id, flr.flr_title, flr.flr_direction FROM '.$this->db->dbprefix('subscriptions').' AS sub LEFT JOIN '.$this->db->dbprefix('feeds').' AS fed ON fed.fed_id = sub.fed_id LEFT JOIN '.$this->db->dbprefix('folders').' AS flr ON flr.flr_id = sub.flr_id WHERE sub.fed_id = ? AND sub.mbr_id = ? GROUP BY sub.sub_id';
$data['itm']->sub = $this->db->query($sql, array($data['itm']->fed_id, $this->member->mbr_id))->row();

$data['itm']->categories = false;

if($this->config->item('tags')) {
$categories = $this->db->query('SELECT cat.* FROM '.$this->db->dbprefix('categories').' AS cat WHERE cat.itm_id = ? GROUP BY cat.cat_id', array($itm_id))->result();
$categories = $this->db->query('SELECT tag.* FROM '.$this->db->dbprefix('tags').' AS tag LEFT JOIN '.$this->db->dbprefix('tags_items').' AS tag_itm ON tag_itm.tag_id = tag.tag_id WHERE tag_itm.itm_id = ? GROUP BY tag.tag_id', array($data['itm']->itm_id))->result();
if($categories) {
$data['itm']->categories = array();
foreach($categories as $cat) {
if(substr($cat->cat_title, 0, 17) == 'foursquare:venue=') {
if(substr($cat->tag_title, 0, 17) == 'foursquare:venue=') {
} else {
$data['itm']->categories[] = $cat->cat_title;
$data['itm']->categories[] = $cat->tag_title;
}
}
}
Expand Down Expand Up @@ -171,7 +178,7 @@ public function email($itm_id) {
$this->email->message($message);
$this->email->send();

//$content['modal'] = $this->load->view('item_email_confirm', $data, TRUE);
$content['modal'] = $this->load->view('item_email_confirm', $data, TRUE);
$content['status'] = 'ok';
}
} else {
Expand Down
27 changes: 16 additions & 11 deletions application/views/evernote_create.php
@@ -1,21 +1,26 @@
<div class="mdl-card mdl-shadow--2dp mdl-color--<?php echo $this->config->item('material-design/colors/background/card'); ?> mdl-cell mdl-cell--4-col" id="evernote_<?php echo $itm->itm_id; ?>">
<div class="mdl-card mdl-shadow--2dp mdl-color--<?php echo $this->config->item('material-design/colors/background/card'); ?> mdl-cell mdl-cell--4-col evernote_result" id="evernote_<?php echo $itm->itm_id; ?>">
<div class="mdl-card__title mdl-color-text--<?php echo $this->config->item('material-design/colors/text/card-title'); ?>">
<h1 class="mdl-card__title-text"><i class="material-icons md-18">note_add</i>evernote</h1>
<h1 class="mdl-card__title-text"><i class="material-icons md-18">note_add</i>Send article to Evernote</h1>
<div class="mdl-card__subtitle-text">
</div>
</div>
<div class="mdl-card__supporting-text mdl-color-text--<?php echo $this->config->item('material-design/colors/text/content'); ?>">
<?php if($status == 'no_token') { ?>
<p><a href="<?php echo base_url(); ?>evernote">Click here</a> to connect your account</a></p>
<?php } ?>
<?php echo validation_errors('<p><i class="material-icons md-16">warning</i>', '</p>'); ?>

<?php if($status == 'note_added') { ?>
<p>Note added</p>
<?php } ?>
<?php echo form_open(current_url(), array('data-itm_id'=>$itm->itm_id)); ?>

<?php if($status == 'error') { ?>
<p><?php echo $message; ?></p>
<?php } ?>
<p>
<?php echo form_label('Notebook'); ?>
<?php echo form_dropdown('notebook', $notebooks, set_value('notebook', ''), 'id="notebook" class="required"'); ?>
</p>

<p>
<button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon mdl-color--<?php echo $this->config->item('material-design/colors/background/button'); ?> mdl-color-text--<?php echo $this->config->item('material-design/colors/text/button'); ?>">
<i class="material-icons md-24">done</i>
</button>
</p>

<?php echo form_close(); ?>
</div>
<div class="mdl-card__actions mdl-card--border mdl-color-text--<?php echo $this->config->item('material-design/colors/text/card-actions'); ?>">
<a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon share_email_close" href="#evernote_<?php echo $itm->itm_id; ?>"><i class="material-icons md-18">close</i></a></li>
Expand Down
24 changes: 24 additions & 0 deletions application/views/evernote_create_confirm.php
@@ -0,0 +1,24 @@
<div class="mdl-card mdl-shadow--2dp mdl-color--<?php echo $this->config->item('material-design/colors/background/card'); ?> mdl-cell mdl-cell--4-col" id="evernote_<?php echo $itm->itm_id; ?>">
<div class="mdl-card__title mdl-color-text--<?php echo $this->config->item('material-design/colors/text/card-title'); ?>">
<h1 class="mdl-card__title-text"><i class="material-icons md-18">note_add</i>Send article to Evernote</h1>
<div class="mdl-card__subtitle-text">
</div>
</div>
<div class="mdl-card__supporting-text mdl-color-text--<?php echo $this->config->item('material-design/colors/text/content'); ?>">
<?php if($status == 'no_token') { ?>
<p><a href="<?php echo base_url(); ?>evernote">Click here</a> to connect your account</a></p>
<?php } ?>

<?php if($status == 'note_added') { ?>
<p>Article sent</p>
<?php } ?>

<?php if($status == 'error') { ?>
<p><?php echo $message; ?></p>
<?php } ?>
</div>
<div class="mdl-card__actions mdl-card--border mdl-color-text--<?php echo $this->config->item('material-design/colors/text/card-actions'); ?>">
<a class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon share_email_close" href="#evernote_<?php echo $itm->itm_id; ?>"><i class="material-icons md-18">close</i></a></li>
</div>
</div>

0 comments on commit cf2c446

Please sign in to comment.