diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 23:16:15 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-10-27 23:16:15 +0100 |
| commit | 0c9b45d210a5d94b3ba219e32b73233a5a795f61 (patch) | |
| tree | b49b11b52c475e04405486775837cdbe24a54a10 | |
| parent | 46a9ff9889466f23c310e2de100d0ae16c5a2a1a (diff) | |
| download | grauphel-0c9b45d210a5d94b3ba219e32b73233a5a795f61.tar.gz grauphel-0c9b45d210a5d94b3ba219e32b73233a5a795f61.zip | |
Download note as XML and JSON
| -rw-r--r-- | appinfo/application.php | 10 | ||||
| -rw-r--r-- | appinfo/routes.php | 5 | ||||
| -rw-r--r-- | controller/guicontroller.php | 10 | ||||
| -rw-r--r-- | controller/notescontroller.php | 104 | ||||
| -rw-r--r-- | grauphel.css | 13 | ||||
| -rw-r--r-- | lib/response/xmlresponse.php | 43 | ||||
| -rw-r--r-- | templates/gui-note.php | 4 |
7 files changed, 189 insertions, 0 deletions
diff --git a/appinfo/application.php b/appinfo/application.php index 66ed557..7761eb5 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -57,6 +57,16 @@ class Application extends App } ); $container->registerService( + 'NotesController', + function($c) { + return new \OCA\Grauphel\Controller\NotesController( + $c->query('AppName'), + $c->query('Request'), + $c->query('Session')->getUser() + ); + } + ); + $container->registerService( 'TokenController', function($c) { Dependencies::get()->urlGen diff --git a/appinfo/routes.php b/appinfo/routes.php index ddfc90b..1c7e50b 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -69,6 +69,11 @@ $application->registerRoutes( 'verb' => 'GET', ), array( + 'url' => '/note/{guid}.xml', + 'name' => 'notes#xml', + 'verb' => 'GET', + ), + array( 'url' => '/note/{guid}', 'name' => 'gui#note', 'verb' => 'GET', diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 4f74ab5..fc97b04 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -96,6 +96,16 @@ class GuiController extends Controller 'note-content' => $converter->convert( $note->{'note-content'} ), + 'links' => array( + 'json' => $this->urlGen->linkToRoute( + 'grauphel.api.note', array( + 'guid' => $guid, 'username' => $this->user->getUid() + ) + ), + 'xml' => $this->urlGen->linkToRoute( + 'grauphel.notes.xml', array('guid' => $guid) + ), + ) ) ); diff --git a/controller/notescontroller.php b/controller/notescontroller.php new file mode 100644 index 0000000..02bfc93 --- /dev/null +++ b/controller/notescontroller.php @@ -0,0 +1,104 @@ +<?php +/** + * Part of grauphel + * + * PHP version 5 + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Controller; + +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http\TemplateResponse; +use \OCA\Grauphel\Lib\Client; +use \OCA\Grauphel\Lib\TokenStorage; +use \OCA\Grauphel\Lib\Response\ErrorResponse; + +/** + * Owncloud frontend: Notes + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class NotesController extends Controller +{ + /** + * constructor of the controller + * + * @param string $appName Name of the app + * @param IRequest $request Instance of the request + */ + public function __construct($appName, \OCP\IRequest $request, $user) + { + parent::__construct($appName, $request); + $this->user = $user; + + //default http header: we assume something is broken + header('HTTP/1.0 500 Internal Server Error'); + } + + /** + * Output a note in tomboy XML format + * + * @link https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function xml($guid) + { + $note = $this->getNotes()->load($guid, false); + + $xw = new \XMLWriter(); + $xw->openMemory(); + $xw->startDocument('1.0', 'utf-8'); + + $xw->startElementNS(null, 'note', 'http://beatniksoftware.com/tomboy'); + $xw->writeAttribute('version', '0.3'); + $xw->writeAttribute('xmlns:link', 'http://beatniksoftware.com/tomboy/link'); + $xw->writeAttribute('xmlns:size', 'http://beatniksoftware.com/tomboy/size'); + + $xw->writeElement('title', $note->title); + $xw->startElement('text'); + $xw->writeAttribute('xml:space', 'preserve'); + + $xw->startElement('note-content'); + $xw->writeAttribute('version', $note->{'note-content-version'}); + $xw->writeRaw($note->{'note-content'}); + $xw->endElement();//note-content + $xw->endElement();//text + + $xw->writeElement('last-change-date', $note->{'last-change-date'}); + $xw->writeElement('last-metadata-change-date', $note->{'last-metadata-change-date'}); + $xw->writeElement('create-date', $note->{'create-date'}); + $xw->writeElement('cursor-position', 0); + $xw->writeElement('width', 450); + $xw->writeElement('height', 360); + $xw->writeElement('x', 0); + $xw->writeElement('y', 0); + $xw->writeElement('open-on-startup', $note->{'open-on-startup'}); + + $xw->endElement();//note + + return new \OCA\Grauphel\Response\XmlResponse($xw->outputMemory()); + } + + protected function getNotes() + { + $username = $this->user->getUid(); + $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); + $notes->setUsername($username); + return $notes; + } +} +?> diff --git a/grauphel.css b/grauphel.css index 1ad5a2d..571e580 100644 --- a/grauphel.css +++ b/grauphel.css @@ -54,6 +54,19 @@ color: green; } +.app-grauphel #app-content .actions { + float: right; +} +.app-grauphel #app-content .actions a { + color: #555; + padding: 14px 10px; + position: relative; + top: 7px; + min-width: 25px; + padding: 5px; + background-color: rgba(240,240,240,.9); +} + .app-grauphel .oauth-authorize { margin: 2ex; text-align: center; diff --git a/lib/response/xmlresponse.php b/lib/response/xmlresponse.php new file mode 100644 index 0000000..050bbff --- /dev/null +++ b/lib/response/xmlresponse.php @@ -0,0 +1,43 @@ +<?php +/** + * Part of grauphel + * + * PHP version 5 + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Response; + +/** + * Returns XML data + * + * @category Tools + * @package Grauphel + * @author Christian Weiske <cweiske@cweiske.de> + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class XmlResponse extends \OCP\AppFramework\Http\Response +{ + protected $xml; + + public function __construct($xml) + { + $this->setStatus(\OCP\AppFramework\Http::STATUS_OK); + $this->addHeader('Content-Type', 'text/xml; charset=utf-8'); + $this->xml = $xml; + } + + public function render() + { + return $this->xml; + } +} +?> diff --git a/templates/gui-note.php b/templates/gui-note.php index 296a0d2..fb2d741 100644 --- a/templates/gui-note.php +++ b/templates/gui-note.php @@ -6,6 +6,10 @@ <script type="text/javascript" src="<?php p(OCP\Util::linkTo('grauphel','js/grauphel.js')); ?>"></script> <div id="app-content" class="content"> + <div class="actions"> + <a class="button" href="<?php echo p($_['links']['json']); ?>">JSON</a> + <a class="button" href="<?php echo p($_['links']['xml']); ?>">XML</a> + </div> <h1><?php echo ($_['note']->title); ?></h1> <p class="muted"> Last modified: |
