update changelog; prepare 0.4.0
[grauphel.git] / controller / notescontroller.php
1 <?php
2 /**
3  * Part of grauphel
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Grauphel
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/grauphel.htm
13  */
14 namespace OCA\Grauphel\Controller;
15
16 use \OCP\AppFramework\Controller;
17 use \OCP\AppFramework\Http\TemplateResponse;
18 use \OCA\Grauphel\Lib\Client;
19 use \OCA\Grauphel\Lib\TokenStorage;
20 use \OCA\Grauphel\Lib\Response\ErrorResponse;
21
22 /**
23  * Owncloud frontend: Notes
24  *
25  * @category  Tools
26  * @package   Grauphel
27  * @author    Christian Weiske <cweiske@cweiske.de>
28  * @copyright 2014 Christian Weiske
29  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
30  * @version   Release: @package_version@
31  * @link      http://cweiske.de/grauphel.htm
32  */
33 class NotesController extends Controller
34 {
35     /**
36      * constructor of the controller
37      *
38      * @param string   $appName Name of the app
39      * @param IRequest $request Instance of the request
40      */
41     public function __construct($appName, \OCP\IRequest $request, $user)
42     {
43         parent::__construct($appName, $request);
44         $this->user   = $user;
45
46         //default http header: we assume something is broken
47         header('HTTP/1.0 500 Internal Server Error');
48     }
49
50     /**
51      * Output a note in tomboy XML format
52      *
53      * @link https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat
54      *
55      * @NoAdminRequired
56      * @NoCSRFRequired
57      */
58     public function xml($guid)
59     {
60         $note = $this->getNotes()->load($guid, false);
61
62         $xw = new \XMLWriter();
63         $xw->openMemory();
64         $xw->startDocument('1.0', 'utf-8');
65
66         $xw->startElementNS(null, 'note', 'http://beatniksoftware.com/tomboy');
67         $xw->writeAttribute('version', '0.3');
68         $xw->writeAttribute('xmlns:link', 'http://beatniksoftware.com/tomboy/link');
69         $xw->writeAttribute('xmlns:size', 'http://beatniksoftware.com/tomboy/size');
70
71         $xw->writeElement('title', $note->title);
72         $xw->startElement('text');
73         $xw->writeAttribute('xml:space', 'preserve');
74
75         $xw->startElement('note-content');
76         $xw->writeAttribute('version', $note->{'note-content-version'});
77         $xw->writeRaw($note->{'note-content'});
78         $xw->endElement();//note-content
79         $xw->endElement();//text
80
81         $xw->writeElement('last-change-date', $note->{'last-change-date'});
82         $xw->writeElement('last-metadata-change-date', $note->{'last-metadata-change-date'});
83         $xw->writeElement('create-date', $note->{'create-date'});
84         $xw->writeElement('cursor-position', 0);
85         $xw->writeElement('width', 450);
86         $xw->writeElement('height', 360);
87         $xw->writeElement('x', 0);
88         $xw->writeElement('y', 0);
89         $xw->writeElement('open-on-startup', $note->{'open-on-startup'});
90
91         $xw->endElement();//note
92
93         return new \OCA\Grauphel\Response\XmlResponse($xw->outputMemory());
94     }
95
96     protected function getNotes()
97     {
98         $username = $this->user->getUid();
99         $notes  = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
100         $notes->setUsername($username);
101         return $notes;
102     }
103 }
104 ?>