2016-12-12 22:23:15 +00:00
|
|
|
<?php
|
|
|
|
namespace OCA\GpxEdit\Settings;
|
|
|
|
|
|
|
|
use bantu\IniGetWrapper\IniGetWrapper;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\IRequest;
|
2016-12-15 18:45:22 +00:00
|
|
|
use OCP\IL10N;
|
2016-12-12 22:23:15 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\Settings\ISettings;
|
|
|
|
use OCP\Util;
|
2016-12-13 01:01:47 +00:00
|
|
|
use OCP\IURLGenerator;
|
2016-12-12 22:23:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursive find files from name pattern
|
|
|
|
*/
|
|
|
|
function globRecursive($path, $find, $recursive=True) {
|
|
|
|
$result = Array();
|
|
|
|
$dh = opendir($path);
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
if (substr($file, 0, 1) === '.') continue;
|
|
|
|
$rfile = "{$path}/{$file}";
|
|
|
|
if (is_dir($rfile) and $recursive) {
|
|
|
|
foreach (globRecursive($rfile, $find) as $ret) {
|
|
|
|
array_push($result, $ret);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fnmatch($find, $file)){
|
|
|
|
array_push($result, $rfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($dh);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Admin implements ISettings {
|
|
|
|
|
|
|
|
/** @var IniGetWrapper */
|
|
|
|
private $iniWrapper;
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
private $config;
|
|
|
|
private $dataDirPath;
|
2016-12-13 01:01:47 +00:00
|
|
|
private $urlGenerator;
|
2016-12-15 18:45:22 +00:00
|
|
|
private $l;
|
2016-12-12 22:23:15 +00:00
|
|
|
|
2016-12-13 01:01:47 +00:00
|
|
|
public function __construct(
|
|
|
|
IniGetWrapper $iniWrapper,
|
2016-12-15 18:45:22 +00:00
|
|
|
IL10N $l,
|
2016-12-13 01:01:47 +00:00
|
|
|
IRequest $request,
|
|
|
|
IConfig $config,
|
|
|
|
IURLGenerator $urlGenerator) {
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
2016-12-12 22:23:15 +00:00
|
|
|
$this->iniWrapper = $iniWrapper;
|
|
|
|
$this->request = $request;
|
2016-12-15 18:45:22 +00:00
|
|
|
$this->l = $l;
|
2016-12-12 22:23:15 +00:00
|
|
|
$this->config = $config;
|
|
|
|
$this->dataDirPath = $this->config->getSystemValue('datadirectory').'/gpxedit';
|
|
|
|
if (! is_dir($this->dataDirPath)){
|
|
|
|
mkdir($this->dataDirPath);
|
|
|
|
}
|
|
|
|
if (! is_dir($this->dataDirPath.'/symbols')){
|
|
|
|
mkdir($this->dataDirPath.'/symbols');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
|
|
|
public function getForm() {
|
2016-12-13 01:01:47 +00:00
|
|
|
$uploadPath = $this->urlGenerator->linkToRoute('gpxedit.utils.uploadExtraSymbol');
|
2016-12-12 22:23:15 +00:00
|
|
|
//$extraSymbolList = Array(Array('name'=>'plop', 'url'=>'huhu'), Array('name'=>'lll', 'url'=>'uuu'));
|
|
|
|
$extraSymbolList = Array();
|
|
|
|
foreach(globRecursive($this->dataDirPath.'/symbols', '*.png', False) as $symbolfile){
|
|
|
|
$filename = basename($symbolfile);
|
2016-12-13 01:01:47 +00:00
|
|
|
array_push($extraSymbolList, Array('smallname'=>str_replace('.png', '', $filename), 'name'=>$filename));
|
2016-12-12 22:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$parameters = [
|
2016-12-13 01:01:47 +00:00
|
|
|
'extraSymbolList' => $extraSymbolList,
|
|
|
|
'uploadPath' => $uploadPath
|
2016-12-12 22:23:15 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return new TemplateResponse('gpxedit', 'admin', $parameters, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
*/
|
|
|
|
public function getSection() {
|
|
|
|
return 'additional';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int whether the form should be rather on the top or bottom of
|
|
|
|
* the admin section. The forms are arranged in ascending order of the
|
|
|
|
* priority values. It is required to return a value between 0 and 100.
|
|
|
|
*
|
|
|
|
* E.g.: 70
|
|
|
|
*/
|
|
|
|
public function getPriority() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:20:15 +00:00
|
|
|
/**
|
|
|
|
* @return TemplateResponse
|
|
|
|
* for ownCloud 10+
|
|
|
|
*/
|
|
|
|
public function getPanel() {
|
|
|
|
$uploadPath = $this->urlGenerator->linkToRoute('gpxedit.utils.uploadExtraSymbol');
|
|
|
|
//$extraSymbolList = Array(Array('name'=>'plop', 'url'=>'huhu'), Array('name'=>'lll', 'url'=>'uuu'));
|
|
|
|
$extraSymbolList = Array();
|
|
|
|
foreach(globRecursive($this->dataDirPath.'/symbols', '*.png', False) as $symbolfile){
|
|
|
|
$filename = basename($symbolfile);
|
|
|
|
array_push($extraSymbolList, Array('smallname'=>str_replace('.png', '', $filename), 'name'=>$filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
$parameters = [
|
|
|
|
'extraSymbolList' => $extraSymbolList,
|
|
|
|
'uploadPath' => $uploadPath
|
|
|
|
];
|
|
|
|
|
|
|
|
return new TemplateResponse('gpxedit', 'admin', $parameters, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
* for ownCloud 10+
|
|
|
|
*/
|
|
|
|
public function getSectionID() {
|
|
|
|
return 'additional';
|
|
|
|
}
|
|
|
|
|
2016-12-12 22:23:15 +00:00
|
|
|
}
|