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
14 namespace OCA\Grauphel\Controller;
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;
23 * Owncloud frontend: Notes
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
33 class NotesController extends Controller
36 * constructor of the controller
38 * @param string $appName Name of the app
39 * @param IRequest $request Instance of the request
41 public function __construct($appName, \OCP\IRequest $request, $user)
43 parent::__construct($appName, $request);
46 //default http header: we assume something is broken
47 header('HTTP/1.0 500 Internal Server Error');
51 * Output a note as a standalone HTML file
56 public function html($guid)
58 $note = $this->getNotes()->load($guid, false);
60 $res = new ErrorResponse('Note does not exist');
61 $res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
65 $xw = new \XMLWriter();
68 $xw->setIndentString(' ');
69 $xw->startDocument('1.0', 'utf-8');
71 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
72 . ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
76 $xw->startElementNS(null, 'html', 'http://www.w3.org/1999/xhtml');
79 $xw->startElement('head');
80 $xw->writeElement('title', $note->title);
82 $xw->startElement('meta');
83 $xw->writeAttribute('name', 'author');
84 $xw->writeAttribute('content', $this->user->getDisplayName());
87 $xw->startElement('meta');
88 $xw->writeAttribute('http-equiv', 'Content-Type');
89 $xw->writeAttribute('content', 'text/html; charset=utf-8');
92 $xw->startElement('link');
93 $xw->writeAttribute('rel', 'schema.DC');
94 $xw->writeAttribute('href', 'http://purl.org/dc/elements/1.1/');
97 $xw->startElement('meta');
98 $xw->writeAttribute('name', 'DC.date.created');
100 'content', date('c', strtotime($note->{'create-date'}))
104 $xw->startElement('meta');
105 $xw->writeAttribute('name', 'DC.date.modified');
107 'content', date('c', strtotime($note->{'last-change-date'}))
111 $xw->endElement();//head
114 $xw->startElement('body');
116 $xw->writeElement('h1', $note->title);
118 $converter = new \OCA\Grauphel\Converter\CleanHtml();
119 $converter->internalLinkHandler = array($this, 'htmlNoteLinkHandler');
122 $converter->convert($note->{'note-content'})
124 } catch (\OCA\Grauphel\Converter\Exception $e) {
125 $res = new ErrorResponse(
126 'Error converting note to HTML.'
127 . ' Please repport a bug to the grauphel developers.'
129 $res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
133 $xw->endElement();//body
135 $xw->endElement();//html
136 return new \OCA\Grauphel\Response\XmlResponse($xw->outputMemory());
139 public function htmlNoteLinkHandler($noteTitle)
141 return urlencode($noteTitle) . '.html';
145 * Output a note in tomboy XML format
147 * @link https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat
152 public function xml($guid)
154 $note = $this->getNotes()->load($guid, false);
155 if ($note === null) {
156 $res = new ErrorResponse('Note does not exist');
157 $res->setStatus(\OCP\AppFramework\Http::STATUS_NOT_FOUND);
161 $xw = new \XMLWriter();
163 $xw->startDocument('1.0', 'utf-8');
165 $xw->startElementNS(null, 'note', 'http://beatniksoftware.com/tomboy');
166 $xw->writeAttribute('version', '0.3');
167 $xw->writeAttribute('xmlns:link', 'http://beatniksoftware.com/tomboy/link');
168 $xw->writeAttribute('xmlns:size', 'http://beatniksoftware.com/tomboy/size');
170 $xw->writeElement('title', $note->title);
171 $xw->startElement('text');
172 $xw->writeAttribute('xml:space', 'preserve');
174 $xw->startElement('note-content');
175 $xw->writeAttribute('version', $note->{'note-content-version'});
176 $xw->writeRaw($note->{'note-content'});
177 $xw->endElement();//note-content
178 $xw->endElement();//text
180 $xw->writeElement('last-change-date', $note->{'last-change-date'});
181 $xw->writeElement('last-metadata-change-date', $note->{'last-metadata-change-date'});
182 $xw->writeElement('create-date', $note->{'create-date'});
183 $xw->writeElement('cursor-position', 0);
184 $xw->writeElement('width', 450);
185 $xw->writeElement('height', 360);
186 $xw->writeElement('x', 0);
187 $xw->writeElement('y', 0);
188 $xw->writeElement('open-on-startup', $note->{'open-on-startup'});
190 $xw->endElement();//note
192 return new \OCA\Grauphel\Response\XmlResponse($xw->outputMemory());
195 protected function getNotes()
197 $username = $this->user->getUid();
198 $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
199 $notes->setUsername($username);