Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
Nextcloud 13.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamy committed Feb 14, 2018
1 parent 47476f0 commit 5f5d9eb
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 217 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Authors

* Fallon Turner <[email protected]>
* Dreamy <[email protected]>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Files Share Link Renamer
###A simple and fast share link renamer add-in for Files app in ownCloud >=8 and NextCloud >=9
###A simple and fast share link renamer add-in for Files app in ownCloud >=9 and NextCloud >=9


This is an add-in to the Files app, which allows you to customize your share tokens, so your links can be https://cloud.ex/s/bachelorparty instead of https://cloud.ex/s/qPv1SwbU5M2YEoJZ. Just share a file or folder (or click an already shared one) and a new button will appear below the share link URL in the sidebar of the Files app.
Expand Down
10 changes: 5 additions & 5 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// Hack which only loads the scripts in the Files app
$request = $c->query('Request');
if (isset($request->server['REQUEST_URI'])) {
$url = $request->server['REQUEST_URI'];
if (preg_match('%apps/files(/.*)?%', $url)) {
// add script only when in Files app
Util::addScript($appName, 'sharerenamer');
}
$url = $request->server['REQUEST_URI'];
if (preg_match('%apps/files(/.*)?%', $url)) {
// add script only when in Files app
Util::addScript($appName, 'sharerenamer');
}
}
16 changes: 8 additions & 8 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
*/
class Application extends App {

/**
* Constructor
*
* @param array $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct('sharerenamer', $urlParams);
}
/**
* Constructor
*
* @param array $urlParams
*/
public function __construct(array $urlParams = []) {
parent::__construct('sharerenamer', $urlParams);
}

}
26 changes: 13 additions & 13 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0"?>
<info>
<id>sharerenamer</id>
<name>Files Share Link Renamer</name>
<description>This is an add-in to the Files app, which allows you to customize your share tokens, so your links can be https://cloud.ex/s/bachelorparty instead of https://cloud.ex/s/qPv1SwbU5M2YEoJZ. Just share a file or folder (or click an already shared one) and a new button will appear below the share link URL in the sidebar of the Files app.
</description>
<licence>AGPL</licence>
<author>Fallon Turner</author>
<version>1.3</version>
<namespace>ShareRenamer</namespace>
<category>Tool</category>
<dependencies>
<owncloud min-version="8.0" max-version="11.0"/>
<nextcloud min-version="9.0" max-version="11.0"/>
</dependencies>
<id>sharerenamer</id>
<name>Files Share Link Renamer</name>
<description>This is an add-in to the Files app, which allows you to customize your share tokens, so your links can be https://cloud.ex/s/bachelorparty instead of https://cloud.ex/s/qPv1SwbU5M2YEoJZ. Just share a file or folder (or click an already shared one) and a new button will appear below the share link URL in the sidebar of the Files app.
</description>
<licence>AGPL</licence>
<author>Fallon Turner</author>
<version>1.4</version>
<namespace>ShareRenamer</namespace>
<category>Tool</category>
<dependencies>
<owncloud min-version="9.0" max-version="11.0"/>
<nextcloud min-version="9.0" max-version="13.0"/>
</dependencies>
</info>
12 changes: 6 additions & 6 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
return [
'resources' => [
'sharerenamer' => ['url' => '/sharerenamer']
],
'routes' => [
['name' => 'sharerenamer#rename', 'url' => '/rename', 'verb' => 'POST']
]
'resources' => [
'sharerenamer' => ['url' => '/sharerenamer']
],
'routes' => [
['name' => 'sharerenamer#rename', 'url' => '/rename', 'verb' => 'POST']
]
];
17 changes: 7 additions & 10 deletions controller/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@

use OCA\ShareRenamer\Service\NotFoundException;


trait Errors {

protected function handleNotFound (Closure $callback) {
try {
return new DataResponse($callback());
} catch(NotFoundException $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
}
protected function handleNotFound (Closure $callback) {
try {
return new DataResponse($callback());
} catch(NotFoundException $e) {
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_NOT_FOUND);
}

}
}
42 changes: 21 additions & 21 deletions controller/sharerenamercontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@

class ShareRenamerController extends Controller {

private $service;
private $userId;

use Errors;

public function __construct($AppName, IRequest $request,
ShareRenamerService $service, $UserId){
parent::__construct($AppName, $request);
$this->service = $service;
$this->userId = $UserId;
}

/**
* @NoAdminRequired
*
* @param string $title
* @param string $content
*/
public function rename() {
return $this->service->rename($_POST['old_token'], $_POST['new_token']);
}
private $service;
private $userId;

use Errors;

public function __construct($AppName, IRequest $request,
ShareRenamerService $service, $UserId){
parent::__construct($AppName, $request);
$this->service = $service;
$this->userId = $UserId;
}

/**
* @NoAdminRequired
*
* @param string $title
* @param string $content
*/
public function rename() {
return $this->service->rename($_POST['old_token'], $_POST['new_token']);
}

}
48 changes: 24 additions & 24 deletions db/sharerenamermapper.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php
namespace OCA\ShareRenamer\Db;

use \OCP\IDb;
use \OCP\IDBConnection;
use \OCP\AppFramework\Db\Mapper;

class ShareRenamerMapper extends Mapper {

public function __construct(IDb $db) {
parent::__construct($db, 'share', '\OCA\ShareRenamer\Db\ShareRenamer');
}
public function __construct(IDBConnection $db) {
parent::__construct($db, 'share', '\OCA\ShareRenamer\Db\ShareRenamer');
}

public function trytokeninsert($oldtoken, $newtoken) {
// check if new token already exists
$sql = 'SELECT COUNT(*) AS n FROM *PREFIX*share WHERE token = ?';
$sql = $this->db->prepare($sql);
$sql->bindParam(1, $newtoken, \PDO::PARAM_STR);
$sql->execute();
$row = $sql->fetch();
$sql->closeCursor();
$alreadyexists = $row['n']; // returns 0 or 1
public function trytokeninsert($oldtoken, $newtoken) {
// check if new token already exists
$sql = 'SELECT COUNT(*) AS n FROM *PREFIX*share WHERE token = ?';
$sql = $this->db->prepare($sql);
$sql->bindParam(1, $newtoken, \PDO::PARAM_STR);
$sql->execute();
$row = $sql->fetch();
$sql->closeCursor();
$alreadyexists = $row['n']; // returns 0 or 1

if ($alreadyexists == '1') {
return 'exists';
}
if ($alreadyexists == '1') {
return 'exists';
}

// now change token in database
$sql2 = 'UPDATE *PREFIX*share SET token = ? WHERE token = ?';
$sql2 = $this->db->prepare($sql2);
$sql2->bindParam(1, $newtoken, \PDO::PARAM_STR);
$sql2->bindParam(2, $oldtoken, \PDO::PARAM_STR);
$sql2->execute();
// now change token in database
$sql2 = 'UPDATE *PREFIX*share SET token = ? WHERE token = ?';
$sql2 = $this->db->prepare($sql2);
$sql2->bindParam(1, $newtoken, \PDO::PARAM_STR);
$sql2->bindParam(2, $oldtoken, \PDO::PARAM_STR);
$sql2->execute();

return 'pass';
}
return 'pass';
}
}
Loading

0 comments on commit 5f5d9eb

Please sign in to comment.