removed old files
This commit is contained in:
parent
1c4ae20dad
commit
d258d96492
17
ajax/get.php
17
ajax/get.php
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
OC_JSON::callCheck();
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('notes');
|
||||
|
||||
$notes = new \OCA\Notes\Notes(\OCP\User::getUser());
|
||||
|
||||
\OCP\JSON::success(
|
||||
array('data' => $notes->getAll(''))
|
||||
);
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
OC_JSON::callCheck();
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('notes');
|
||||
|
||||
$notes = new \OCA\Notes\Notes(\OCP\User::getUser());
|
||||
|
||||
$category = $_POST['category'];
|
||||
|
||||
// oldname is used to get the existing text file which is identified by the
|
||||
// first line
|
||||
$oldName = $_POST['oldname'];
|
||||
$old = explode('\n', $oldName);
|
||||
$old = $old[0] . '.txt';
|
||||
|
||||
$content = $_POST['content'];
|
||||
|
||||
$new = \OCA\Notes\Notes::createFileName($content);
|
||||
|
||||
|
||||
if ($new != $old) {
|
||||
$notes->remove($category, $old);
|
||||
}
|
||||
|
||||
if ($content) {
|
||||
$notes->save($category, $new, $content);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Notes;
|
||||
|
||||
class Categories {
|
||||
private $user;
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
*/
|
||||
private $view;
|
||||
|
||||
/**
|
||||
* @var Notes
|
||||
*/
|
||||
private $notes;
|
||||
|
||||
public function __construct($user) {
|
||||
$this->user = $user;
|
||||
$this->view = new \OC\Files\View('/' . $this->user . '/files/Notes');
|
||||
$this->notes = new Notes($user);
|
||||
}
|
||||
|
||||
public function listCategories() {
|
||||
$content = $this->view->getDirectoryContent('/');
|
||||
$categories = array();
|
||||
foreach ($content as $item) {
|
||||
if ($item['type'] === 'dir') {
|
||||
$categories[] = $item['name'];
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function create($name) {
|
||||
return $this->view->mkdir($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a category, moving all notes inside it to Geneal
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($name) {
|
||||
$notes = $this->notes->listNotes($name); //move all notes in the category to General
|
||||
foreach ($notes as $note => $mtime) {
|
||||
$this->notes->move($name, $note, '');
|
||||
}
|
||||
|
||||
return $this->view->rmdir($name);
|
||||
}
|
||||
}
|
1732
lib/markdown.php
1732
lib/markdown.php
File diff suppressed because it is too large
Load Diff
160
lib/notes.php
160
lib/notes.php
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Notes;
|
||||
|
||||
class Notes {
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
*/
|
||||
private $view;
|
||||
|
||||
public function __construct($user) {
|
||||
$this->user = $user;
|
||||
$this->view = new \OC\Files\View('/' . $this->user . '/files/Notes');
|
||||
if ($this->view->file_exists('/')) {
|
||||
$this->view->mkdir('/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get all notes and modified dates in a category
|
||||
*
|
||||
* @param string $category
|
||||
* @return array
|
||||
*/
|
||||
public function listNotes($category = '') {
|
||||
$content = $this->view->getDirectoryContent('/' . $category);
|
||||
$notes = array();
|
||||
foreach ($content as $item) {
|
||||
if ($item['type'] === 'file') {
|
||||
$notes[$item['name']] = $item['mtime'];
|
||||
}
|
||||
}
|
||||
arsort($notes);
|
||||
return $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* move a note to a different category
|
||||
*
|
||||
* @param string $sourceCategory
|
||||
* @param string $note
|
||||
* @param string $targetCategory
|
||||
* @return bool
|
||||
*/
|
||||
public function move($sourceCategory, $note, $targetCategory) {
|
||||
return $this->view->rename('/' . $sourceCategory . '/' . $note, '/' . $targetCategory . '/' . $note);
|
||||
}
|
||||
|
||||
/**
|
||||
* rename a note
|
||||
*
|
||||
* @param string $category
|
||||
* @param string $old
|
||||
* @param string $new
|
||||
* @return bool
|
||||
*/
|
||||
public function rename($category, $old, $new) {
|
||||
return $this->view->rename('/' . $category . '/' . $old, '/' . $category . '/' . $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a note
|
||||
*
|
||||
* @param string $catergory
|
||||
* @param string $note
|
||||
* @return bool
|
||||
*/
|
||||
public function remove($category, $note) {
|
||||
if ($note) {
|
||||
return $this->view->unlink('/' . $category . '/' . $note);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the contents of a note
|
||||
*
|
||||
* @param string $category
|
||||
* @param string $note
|
||||
* @return string
|
||||
*/
|
||||
public function get($category, $note) {
|
||||
require_once 'markdown.php';
|
||||
$content = $this->getSource($category, $note);
|
||||
return Markdown($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $category
|
||||
* @param string $note
|
||||
* @return string
|
||||
*/
|
||||
public function getSource($category, $note) {
|
||||
return $this->view->file_get_contents('/' . $category . '/' . $note);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the contents of all notes in a category
|
||||
*
|
||||
* @param string $category
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($category) {
|
||||
require_once 'markdown.php';
|
||||
$content = $this->view->getDirectoryContent('/' . $category);
|
||||
$notes = array();
|
||||
foreach ($content as $item) {
|
||||
if ($item['type'] === 'file') {
|
||||
$note = array(
|
||||
'content' => $this->getSource($category, $item['name']),
|
||||
'modified' => (int) $item['mtime']
|
||||
);
|
||||
$notes[$item['name']] = $note;
|
||||
}
|
||||
}
|
||||
return $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* save a note
|
||||
*
|
||||
* @param string $category
|
||||
* @param string $note
|
||||
* @param string $content
|
||||
* @return bool
|
||||
*/
|
||||
public function save($category, $note, $content) {
|
||||
return $this->view->file_put_contents('/' . $category . '/' . $note, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $category
|
||||
* @return array
|
||||
*/
|
||||
public function getTitles($category) {
|
||||
$notes = $this->listNotes($category);
|
||||
$titles = array();
|
||||
foreach ($notes as $note => $mtime) {
|
||||
$content = $this->getSource($category, $note);
|
||||
list($title,) = explode("\n", trim($content));
|
||||
$titles[$note] = $title;
|
||||
}
|
||||
return $titles;
|
||||
}
|
||||
|
||||
public static function createFileName($content) {
|
||||
list($title,) = explode("\n", trim($content));
|
||||
$title = substr($title, 0, 40);
|
||||
return preg_replace("/[^\w\d ]/u", '-', $title) . '.txt';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue