)
)
);
- $syncdata = $this->notes->loadSyncData($username);
+ $syncdata = $this->notes->loadSyncData();
$data = array(
'user-name' => $username,
)
)
);
- $syncdata = $this->notes->loadSyncData($username);
- return $this->fetchNotes($username, $syncdata);
+ $syncdata = $this->notes->loadSyncData();
+ return $this->fetchNotes($syncdata);
}
/**
)
)
);
- $syncdata = $this->notes->loadSyncData($username);
+ $syncdata = $this->notes->loadSyncData();
$res = $this->handleNoteSave($username, $syncdata);
if ($res instanceof \OCP\AppFramework\Http\Response) {
return $res;
}
- return $this->fetchNotes($username, $syncdata);
+ return $this->fetchNotes($syncdata);
}
- protected function fetchNotes($username, $syncdata)
+ protected function fetchNotes($syncdata)
{
$since = null;
if (isset($_GET['since'])) {
}
if (isset($_GET['include_notes']) && $_GET['include_notes']) {
- $notes = $this->notes->loadNotesFull($username, $since);
+ $notes = $this->notes->loadNotesFull($since);
} else {
- $notes = $this->notes->loadNotesOverview($username, $since);
+ $notes = $this->notes->loadNotesOverview($since);
}
//work around bug https://bugzilla.gnome.org/show_bug.cgi?id=734313
//owncloud converts object to array, so we reverse
$noteUpdate = (object) $noteUpdate;
- $note = $this->notes->load($username, $noteUpdate->guid);
+ $note = $this->notes->load($noteUpdate->guid);
if (isset($noteUpdate->command) && $noteUpdate->command == 'delete') {
- $this->notes->delete($username, $noteUpdate->guid);
+ $this->notes->delete($noteUpdate->guid);
} else {
$this->notes->update(
$note, $noteUpdate, $syncdata->latestSyncRevision
);
- $this->notes->save($username, $note);
+ $this->notes->save($note);
}
}
- $this->notes->saveSyncData($username, $syncdata);
+ $this->notes->saveSyncData($syncdata);
}
/**
* @NoCSRFRequired
* @PublicPage
*/
- public function note()
+ public function note($username, $guid)
{
- //FIXME
- $deps = Dependencies::get();
- $username = $deps->urlGen->loadUsername();
- $guid = $deps->urlGen->loadGuid();
- $oauth = new \OAuth();
- $oauth->setDeps($deps);
- $oauth->verifyOAuthUser($username, $deps->urlGen->note($username, $guid));
+ $this->verifyUser(
+ $username,
+ $this->deps->urlGen->getAbsoluteURL(
+ $this->deps->urlGen->linkToRoute(
+ 'grauphel.api.note',
+ array('username' => $username, 'guid' => $guid)
+ )
+ )
+ );
- $note = $this->notes->load($username, $guid, false);
+ $note = $this->notes->load($guid, false);
if ($note === null) {
header('HTTP/1.0 404 Not Found');
header('Content-type: text/plain');
exit(1);
}
- $data = array('note' => array($note));
- $deps->renderer->sendJson($data);
+ return new JSONResponse($note);
}
/**
*/
protected function verifyUser($username, $curUrl)
{
- if ($this->user !== null && $this->user->getUID() == $username) {
+ if ($this->user !== null && $this->user->getUid() == $username) {
+ $this->notes->setUsername($username);
return true;
}
$oauth = new OAuth();
$oauth->setDeps($this->deps);
$oauth->verifyOAuthUser($username, $curUrl);
+
+ $this->notes->setUsername($username);
+ return true;
}
}
?>
$this->checkDeps();
$res = new TemplateResponse('grauphel', 'index');
- $res->setParams(array('apiurl' => $this->getApiUrl()));
+ $res->setParams(
+ array(
+ 'apiroot' => $this->getApiRootUrl(),
+ 'apiurl' => $this->urlGen->linkToRoute('grauphel.api.index')
+ )
+ );
$this->addNavigation($res);
$this->addStats($res);
return $res;
protected function addNavigation(TemplateResponse $res)
{
$nav = new \OCP\Template('grauphel', 'appnavigation', '');
- $nav->assign('apiurl', $this->getApiUrl());
+ $nav->assign('apiroot', $this->getApiRootUrl());
$params = $res->getParams();
$params['appNavigation'] = $nav;
$username = $this->user->getUid();
$notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen);
+ $notes->setUsername($username);
$tokens = new \OCA\Grauphel\Lib\TokenStorage();
$nav = new \OCP\Template('grauphel', 'indexStats', '');
- $nav->assign('notes', count($notes->loadNotesOverview($username)));
- $nav->assign('syncrev', $notes->loadSyncData($username)->latestSyncRevision);
+ $nav->assign('notes', count($notes->loadNotesOverview()));
+ $nav->assign('syncrev', $notes->loadSyncData()->latestSyncRevision);
$nav->assign('tokens', count($tokens->loadForUser($username, 'access')));
$params = $res->getParams();
}
}
- protected function getApiUrl()
+ protected function getApiRootUrl()
{
//we need to remove the trailing / for tomdroid and conboy
return rtrim(
class NoteStorage
{
protected $urlGen;
+ protected $username;
public function __construct($urlGen)
{
- $this->urlGen = $urlGen;
+ $this->urlGen = $urlGen;
}
+
+ public function setUsername($username)
+ {
+ $this->username = $username;
+ }
+
/**
* Create a new sync data object for fresh users.
* Used by loadSyncData()
*
- * @param string $username User name
- *
* @return SyncData New synchronization statistics
*/
- protected function getNewSyncData($username)
+ protected function getNewSyncData()
{
$syncdata = new SyncData();
- $syncdata->initNew($username);
+ $syncdata->initNew($this->username);
return $syncdata;
}
+ public function getTags()
+ {
+ }
+
/**
* Updates the given $note object with data from $noteUpdate.
* Sets the last-sync-revision to $syncRevision
* Loads synchronization data for the given user.
* Creates fresh sync data if there are none for the user.
*
- * @param string $username User name
- *
* @return SyncData Synchronization statistics (revision, sync guid)
*/
- public function loadSyncData($username)
+ public function loadSyncData()
{
$row = \OC_DB::executeAudited(
'SELECT * FROM `*PREFIX*grauphel_syncdata`'
. ' WHERE `syncdata_user` = ?',
- array($username)
+ array($this->username)
)->fetchRow();
if ($row === false) {
- $syncdata = $this->getNewSyncData($username);
- $this->saveSyncData($username, $syncdata);
+ $syncdata = $this->getNewSyncData($this->username);
+ $this->saveSyncData($this->username, $syncdata);
} else {
$syncdata = new SyncData();
$syncdata->latestSyncRevision = (int) $row['syncdata_latest_sync_revision'];
/**
* Save synchronization data for the given user.
*
- * @param string $username User name
* @param SyncData $syncdata Synchronization data object
*
* @return void
*/
- public function saveSyncData($username, SyncData $syncdata)
+ public function saveSyncData(SyncData $syncdata)
{
$row = \OC_DB::executeAudited(
'SELECT * FROM `*PREFIX*grauphel_syncdata`'
. ' WHERE `syncdata_user` = ?',
- array($username)
+ array($this->username)
)->fetchRow();
if ($row === false) {
. '(`syncdata_user`, `syncdata_latest_sync_revision`, `syncdata_current_sync_guid`)'
. ' VALUES(?, ?, ?)';
$params = array(
- $username,
+ $this->username,
$syncdata->latestSyncRevision,
$syncdata->currentSyncGuid
);
. ' `' . implode('` = ?, `', array_keys($data)) . '` = ?'
. ' WHERE `syncdata_user` = ?';
$params = array_values($data);
- $params[] = $username;
+ $params[] = $this->username;
}
\OC_DB::executeAudited($sql, $params);
}
/**
* Load a note from the storage.
*
- * @param string $username User name
* @param string $guid Note identifier
* @param boolean $createNew Create a new note if it does not exist
*
* @return object Note object, NULL if !$createNew and note does not exist
*/
- public function load($username, $guid, $createNew = true)
+ public function load($guid, $createNew = true)
{
$row = \OC_DB::executeAudited(
'SELECT * FROM `*PREFIX*grauphel_notes`'
. ' WHERE `note_user` = ? AND `note_guid` = ?',
- array($username, $guid)
+ array($this->username, $guid)
)->fetchRow();
if ($row === false) {
/**
* Save a note into storage.
*
- * @param string $username User name
- * @param object $note Note to save
+ * @param object $note Note to save
*
* @return void
*/
- public function save($username, $note)
+ public function save($note)
{
$row = \OC_DB::executeAudited(
'SELECT * FROM `*PREFIX*grauphel_notes`'
. ' WHERE `note_user` = ? AND `note_guid` = ?',
- array($username, $note->guid)
+ array($this->username, $note->guid)
)->fetchRow();
$data = $this->rowFromNote($note);
if ($row === false) {
//INSERT
- $data['note_user'] = $username;
+ $data['note_user'] = $this->username;
$sql = 'INSERT INTO `*PREFIX*grauphel_notes`'
. ' (`' . implode('`, `', array_keys($data)) . '`)'
. ' VALUES(' . implode(', ', array_fill(0, count($data), '?')) . ')';
. '`' . implode('` = ?, `', array_keys($data)) . '` = ?'
. ' WHERE `note_user` = ? AND `note_guid` = ?';
$params = array_values($data);
- $params[] = $username;
+ $params[] = $this->username;
$params[] = $note->guid;
}
\OC_DB::executeAudited($sql, $params);
/**
* Delete a note from storage.
*
- * @param string $username User name
- * @param object $guid ID of the note
+ * @param object $guid ID of the note
*
* @return void
*/
- public function delete($username, $guid)
+ public function delete($guid)
{
\OC_DB::executeAudited(
'DELETE FROM `*PREFIX*grauphel_notes`'
. ' WHERE `note_user` = ? AND `note_guid` = ?',
- array($username, $guid)
+ array($this->username, $guid)
);
}
* Load notes for the given user in short form.
* Optionally only those changed after $since revision
*
- * @param string $username User name
- * @param integer $since Revision number after which the notes changed
+ * @param integer $since Revision number after which the notes changed
*
* @return array Array of short note objects
*/
- public function loadNotesOverview($username, $since = null)
+ public function loadNotesOverview($since = null)
{
$result = \OC_DB::executeAudited(
'SELECT `note_guid`, `note_title`, `note_last_sync_revision`'
. ' FROM `*PREFIX*grauphel_notes`'
. ' WHERE note_user = ?',
- array($username)
+ array($this->username)
);
$notes = array();
$this->urlGen->linkToRoute(
'grauphel.api.note',
array(
- 'username' => $username,
+ 'username' => $this->username,
'guid' => $row['note_guid']
)
)
* Load notes for the given user in full form.
* Optionally only those changed after $since revision
*
- * @param string $username User name
- * @param integer $since Revision number after which the notes changed
+ * @param integer $since Revision number after which the notes changed
*
* @return array Array of full note objects
*/
- public function loadNotesFull($username, $since = null)
+ public function loadNotesFull($since = null)
{
$result = \OC_DB::executeAudited(
'SELECT * FROM `*PREFIX*grauphel_notes`'
. ' WHERE note_user = ?',
- array($username)
+ array($this->username)
);
$notes = array();