Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/apps.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-11-28 16:57:32 +0400
committerBernhard Posselt <nukeawhale@gmail.com>2012-11-28 16:57:32 +0400
commit82375826fd7475a074b51d92ba96296a675db15f (patch)
treef0be53e2d4140201a6b778350be31154f68d0237 /apptemplate
parent31d60de05f5f811f36eca238dff49efb5153225e (diff)
brought back simple apptemplate and moved the changes to apptemplate_advanced
Diffstat (limited to 'apptemplate')
-rw-r--r--apptemplate/3rdparty/Pimple/Pimple.php202
-rw-r--r--apptemplate/ajax/seturl.php14
-rw-r--r--apptemplate/appinfo/app.php42
-rw-r--r--apptemplate/appinfo/bootstrap.php84
-rw-r--r--apptemplate/appinfo/routes.php105
-rw-r--r--apptemplate/appinfo/version2
-rw-r--r--apptemplate/controllers/ajax.controller.php56
-rw-r--r--apptemplate/controllers/index.controller.php60
-rw-r--r--apptemplate/controllers/settings.controller.php58
-rw-r--r--apptemplate/index.php (renamed from apptemplate/admin/settings.php)36
-rw-r--r--apptemplate/js/admin.js16
-rw-r--r--apptemplate/lib/api.php154
-rw-r--r--apptemplate/lib/controller.php66
-rw-r--r--apptemplate/lib/request.php74
-rw-r--r--apptemplate/lib/response.php158
-rw-r--r--apptemplate/lib/security.php114
-rw-r--r--apptemplate/settings.php11
-rw-r--r--apptemplate/templates/main.php2
-rw-r--r--apptemplate/templates/settings.php2
19 files changed, 63 insertions, 1193 deletions
diff --git a/apptemplate/3rdparty/Pimple/Pimple.php b/apptemplate/3rdparty/Pimple/Pimple.php
deleted file mode 100644
index cb1acd5e0..000000000
--- a/apptemplate/3rdparty/Pimple/Pimple.php
+++ /dev/null
@@ -1,202 +0,0 @@
-<?php
-
-/*
- * This file is part of Pimple.
- *
- * Copyright (c) 2009 Fabien Potencier
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is furnished
- * to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * Pimple main class.
- *
- * @package pimple
- * @author Fabien Potencier
- */
-class Pimple implements ArrayAccess
-{
- private $values;
-
- /**
- * Instantiate the container.
- *
- * Objects and parameters can be passed as argument to the constructor.
- *
- * @param array $values The parameters or objects.
- */
- public function __construct (array $values = array())
- {
- $this->values = $values;
- }
-
- /**
- * Sets a parameter or an object.
- *
- * Objects must be defined as Closures.
- *
- * Allowing any PHP callable leads to difficult to debug problems
- * as function names (strings) are callable (creating a function with
- * the same a name as an existing parameter would break your container).
- *
- * @param string $id The unique identifier for the parameter or object
- * @param mixed $value The value of the parameter or a closure to defined an object
- */
- public function offsetSet($id, $value)
- {
- $this->values[$id] = $value;
- }
-
- /**
- * Gets a parameter or an object.
- *
- * @param string $id The unique identifier for the parameter or object
- *
- * @return mixed The value of the parameter or an object
- *
- * @throws InvalidArgumentException if the identifier is not defined
- */
- public function offsetGet($id)
- {
- if (!array_key_exists($id, $this->values)) {
- throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
- }
-
- $isFactory = is_object($this->values[$id]) && method_exists($this->values[$id], '__invoke');
-
- return $isFactory ? $this->values[$id]($this) : $this->values[$id];
- }
-
- /**
- * Checks if a parameter or an object is set.
- *
- * @param string $id The unique identifier for the parameter or object
- *
- * @return Boolean
- */
- public function offsetExists($id)
- {
- return array_key_exists($id, $this->values);
- }
-
- /**
- * Unsets a parameter or an object.
- *
- * @param string $id The unique identifier for the parameter or object
- */
- public function offsetUnset($id)
- {
- unset($this->values[$id]);
- }
-
- /**
- * Returns a closure that stores the result of the given closure for
- * uniqueness in the scope of this instance of Pimple.
- *
- * @param Closure $callable A closure to wrap for uniqueness
- *
- * @return Closure The wrapped closure
- */
- public function share(Closure $callable)
- {
- return function ($c) use ($callable) {
- static $object;
-
- if (null === $object) {
- $object = $callable($c);
- }
-
- return $object;
- };
- }
-
- /**
- * Protects a callable from being interpreted as a service.
- *
- * This is useful when you want to store a callable as a parameter.
- *
- * @param Closure $callable A closure to protect from being evaluated
- *
- * @return Closure The protected closure
- */
- public function protect(Closure $callable)
- {
- return function ($c) use ($callable) {
- return $callable;
- };
- }
-
- /**
- * Gets a parameter or the closure defining an object.
- *
- * @param string $id The unique identifier for the parameter or object
- *
- * @return mixed The value of the parameter or the closure defining an object
- *
- * @throws InvalidArgumentException if the identifier is not defined
- */
- public function raw($id)
- {
- if (!array_key_exists($id, $this->values)) {
- throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
- }
-
- return $this->values[$id];
- }
-
- /**
- * Extends an object definition.
- *
- * Useful when you want to extend an existing object definition,
- * without necessarily loading that object.
- *
- * @param string $id The unique identifier for the object
- * @param Closure $callable A closure to extend the original
- *
- * @return Closure The wrapped closure
- *
- * @throws InvalidArgumentException if the identifier is not defined
- */
- public function extend($id, Closure $callable)
- {
- if (!array_key_exists($id, $this->values)) {
- throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $id));
- }
-
- $factory = $this->values[$id];
-
- if (!($factory instanceof Closure)) {
- throw new InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id));
- }
-
- return $this->values[$id] = function ($c) use ($callable, $factory) {
- return $callable($factory($c), $c);
- };
- }
-
- /**
- * Returns all defined value names.
- *
- * @return array An array of value names
- */
- public function keys()
- {
- return array_keys($this->values);
- }
-}
diff --git a/apptemplate/ajax/seturl.php b/apptemplate/ajax/seturl.php
new file mode 100644
index 000000000..fa6d513b4
--- /dev/null
+++ b/apptemplate/ajax/seturl.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Copyright (c) 2011, Frank Karlitschek <karlitschek@kde.org>
+ * Copyright (c) 2012, Florian Hülsmann <fh@cbix.de>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+OCP\User::checkAdminUser();
+OCP\JSON::callCheck();
+
+OCP\Config::setSystemValue( 'somesetting', $_POST['somesetting'] );
+
+echo 'true';
diff --git a/apptemplate/appinfo/app.php b/apptemplate/appinfo/app.php
index 91a4cc683..951282610 100644
--- a/apptemplate/appinfo/app.php
+++ b/apptemplate/appinfo/app.php
@@ -5,50 +5,30 @@
*
* @author Frank Karlitschek
* @author Florian Hülsmann
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
* @copyright 2011 Frank Karlitschek karlitschek@kde.org
* @copyright 2012 Florian Hülsmann fh@cbix.de
-*
+*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
+* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
-*
+*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
+*
+* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
+*
*/
+OCP\App::registerAdmin( 'apptemplate', 'settings' );
-require_once \OC_App::getAppPath('apptemplate') . '/appinfo/bootstrap.php';
-
-
-\OCP\App::registerAdmin('apptemplate', 'admin/settings');
-
-\OCP\App::addNavigationEntry( array(
-
- // the string under which your app will be referenced
- // in owncloud, for instance: \OC_App::getAppPath('APP_ID')
+OCP\App::addNavigationEntry( array(
'id' => 'apptemplate',
-
- // sorting weight for the navigation. The higher the number, the higher
- // will it be listed in the navigation
'order' => 74,
-
- // the route that will be shown on startup
- 'href' => \OC_Helper::linkToRoute('apptemplate_index'),
-
- // the icon that will be shown in the navigation
- 'icon' => \OCP\Util::imagePath('apptemplate', 'example.png' ),
-
- // the title of your application. This will be used in the
- // navigation or on the settings page of your app
- 'name' => \OC_L10N::get('apptemplate')->t('App Template')
-
+ 'href' => OCP\Util::linkTo( 'apptemplate', 'index.php' ),
+ 'icon' => OCP\Util::imagePath( 'apptemplate', 'example.png' ),
+ 'name' => 'App Template'
));
diff --git a/apptemplate/appinfo/bootstrap.php b/apptemplate/appinfo/bootstrap.php
deleted file mode 100644
index 696f7650e..000000000
--- a/apptemplate/appinfo/bootstrap.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-/**
- * Declare your classes and their include path so that they'll be automatically
- * loaded once you instantiate them
- */
-\OC::$CLASSPATH['Pimple'] = 'apps/apptemplate/3rdparty/Pimple/Pimple.php';
-
-\OC::$CLASSPATH['OCA\AppTemplate\API'] = 'apps/apptemplate/lib/api.php';
-\OC::$CLASSPATH['OCA\AppTemplate\Request'] = 'apps/apptemplate/lib/request.php';
-\OC::$CLASSPATH['OCA\AppTemplate\Security'] = 'apps/apptemplate/lib/security.php';
-\OC::$CLASSPATH['OCA\AppTemplate\Controller'] = 'apps/apptemplate/lib/controller.php';
-\OC::$CLASSPATH['OCA\AppTemplate\TemplateResponse'] = 'apps/apptemplate/lib/response.php';
-\OC::$CLASSPATH['OCA\AppTemplate\JSONResponse'] = 'apps/apptemplate/lib/response.php';
-
-\OC::$CLASSPATH['OCA\AppTemplate\IndexController'] = 'apps/apptemplate/controllers/index.controller.php';
-\OC::$CLASSPATH['OCA\AppTemplate\SettingsController'] = 'apps/apptemplate/controllers/settings.controller.php';
-\OC::$CLASSPATH['OCA\AppTemplate\AjaxController'] = 'apps/apptemplate/controllers/ajax.controller.php';
-
-
-/**
- * @return a new DI container with prefilled values for the news app
- */
-function createDIContainer(){
- $container = new \Pimple();
-
- /**
- * BASE
- */
- $container['API'] = $container->share(function($c){
- return new API('apptemplate');
- });
-
- $container['Security'] = $container->share(function($c){
- return new Security($c['API']->getAppName());
- });
-
- $container['Request'] = $container->share(function($c){
- return new Request($_GET, $_POST);
- });
-
-
- /**
- * CONTROLLERS
- */
- $container['IndexController'] = function($c){
- return new IndexController($c['API'], $c['Request']);
- };
-
- $container['SettingsController'] = function($c){
- return new SettingsController($c['API'], $c['Request']);
- };
-
-
- $container['AjaxController'] = function($c){
- return new AjaxController($c['API'], $c['Request']);
- };
-
-
- return $container;
-} \ No newline at end of file
diff --git a/apptemplate/appinfo/routes.php b/apptemplate/appinfo/routes.php
deleted file mode 100644
index 867abb14a..000000000
--- a/apptemplate/appinfo/routes.php
+++ /dev/null
@@ -1,105 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-require_once \OC_App::getAppPath('apptemplate') . '/appinfo/bootstrap.php';
-
-/**
- * Shortcut for calling a controller method and printing the result
- * @param string $controllerName: the name of the controller under which it is
- * stored in the DI container
- * @param string $methodName: the method that you want to call
- * @param array $urlParams: an array with variables extracted from the routes
- * @param bool $disableAdminCheck: disables the check for adminuser rights
- * @param bool $isAjax: if the request is an ajax request
- */
-function callController($controllerName, $methodName, $urlParams, $disableAdminCheck=true,
- $isAjax=false){
- $container = createDIContainer();
-
- // run security checks
- $security = $container['Security'];
- runSecurityChecks($security, $isAjax, $disableAdminCheck);
-
- // call the controller and render the page
- $controller = $container[$controllerName];
- $response = $controller->$methodName($urlParams);
- echo $response->render();
-}
-
-
-/**
- * Shortcut for calling an ajax controller method and printing the result
- * @param string $controllerName: the name of the controller under which it is
- * stored in the DI container
- * @param string $methodName: the method that you want to call
- * @param array $urlParams: an array with variables extracted from the routes
- * @param bool $disableAdminCheck: disables the check for adminuser rights
- */
-function callAjaxController($controllerName, $methodName, $urlParams, $disableAdminCheck=true){
- callController($controllerName, $methodName, $urlParams, $disableAdminCheck, true);
-}
-
-
-/**
- * Runs the security checks and exits on error
- * @param Security $security: the security object
- * @param bool $isAjax: if true, the ajax checks will be run, otherwise the normal
- * checks
- * @param bool $disableAdminCheck: disables the check for adminuser rights
- */
-function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){
- if($disableAdminCheck){
- $security->setIsAdminCheck(false);
- }
-
- if($isAjax){
- $security->runAJAXChecks();
- } else {
- $security->runChecks();
- }
-}
-
-/*************************
- * Define your routes here
- ************************/
-
-/**
- * Normal Routes
- */
-$this->create('apptemplate_index', '/')->action(
- function($params){
- callController('IndexController', 'index', $params);
- }
-);
-
-/**
- * Ajax Routes
- */
-$this->create('apptemplate_ajax_setsystemvalue', '/setsystemvalue')->post()->action(
- function($params){
- callAjaxController('AjaxController', 'setSystemValue', $params);
- }
-);
diff --git a/apptemplate/appinfo/version b/apptemplate/appinfo/version
index d3827e75a..9459d4ba2 100644
--- a/apptemplate/appinfo/version
+++ b/apptemplate/appinfo/version
@@ -1 +1 @@
-1.0
+1.1
diff --git a/apptemplate/controllers/ajax.controller.php b/apptemplate/controllers/ajax.controller.php
deleted file mode 100644
index e665a6604..000000000
--- a/apptemplate/controllers/ajax.controller.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-class AjaxController extends Controller {
-
-
- /**
- * @param Request $request: an instance of the request
- * @param API $api: an api wrapper instance
- */
- public function __construct($api, $request){
- parent::__construct($api, $request);
- }
-
-
- /**
- * @brief sets a global system value
- * @param array $urlParams: an array with the values, which were matched in
- * the routes file
- */
- public function setSystemValue($urlParams=array()){
- $value = $this->params('somesetting');
- $this->api->setSystemValue('somesetting', $value);
-
- $response = new JSONResponse($this->appName);
-
- $params = array('somesetting' => $value);
- $response->setParams($params);
-
- return $response;
- }
-
-} \ No newline at end of file
diff --git a/apptemplate/controllers/index.controller.php b/apptemplate/controllers/index.controller.php
deleted file mode 100644
index 27cc2aad6..000000000
--- a/apptemplate/controllers/index.controller.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-class IndexController extends Controller {
-
-
- /**
- * @param Request $request: an instance of the request
- * @param API $api: an api wrapper instance
- */
- public function __construct($api, $request){
- parent::__construct($api, $request);
-
- // this will set the current navigation entry of the app, use this only
- // for normal HTML requests and not for AJAX requests
- $this->api->activateNavigationEntry();
- }
-
-
- /**
- * @brief renders the index page
- * @param array $urlParams: an array with the values, which were matched in
- * the routes file
- * @return an instance of a Response implementation
- */
- public function index($urlParams=array()){
- $response = new TemplateResponse($this->appName, 'main');
-
- $params = array(
- 'somesetting' => $this->api->getSystemValue('somesetting')
- );
- $response->setParams($params);
-
- return $response;
- }
-
-} \ No newline at end of file
diff --git a/apptemplate/controllers/settings.controller.php b/apptemplate/controllers/settings.controller.php
deleted file mode 100644
index b0ae87e64..000000000
--- a/apptemplate/controllers/settings.controller.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-class SettingsController extends Controller {
-
-
- /**
- * @param Request $request: an instance of the request
- * @param API $api: an api wrapper instance
- */
- public function __construct($api, $request){
- parent::__construct($api, $request);
- }
-
-
- /**
- * @brief renders the settings page
- * @param array $urlParams: an array with the values, which were matched in
- * the routes file
- */
- public function index($urlParams=array()){
- $this->api->addScript('admin');
-
- $response = new TemplateResponse($this->appName, 'settings');
- $response->renderAs('admin');
-
- $params = array(
- 'url' => $this->api->getSystemValue('somesetting')
- );
- $response->setParams($params);
-
- return $response;
- }
-
-} \ No newline at end of file
diff --git a/apptemplate/admin/settings.php b/apptemplate/index.php
index 69fe3f51d..6beab3153 100644
--- a/apptemplate/admin/settings.php
+++ b/apptemplate/index.php
@@ -3,33 +3,31 @@
/**
* ownCloud - App Template Example
*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
+* @author Frank Karlitschek
+* @author Florian Hülsmann
+* @copyright 2011 Frank Karlitschek karlitschek@kde.org
+* @copyright 2012 Florian Hülsmann fh@cbix.de
+*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
+* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
-*
+*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
+*
+* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
+*
*/
-namespace OCA\AppTemplate;
-
-
-require_once \OC_App::getAppPath('apptemplate') . '/appinfo/bootstrap.php';
-
-$container = createDIContainer();
-
-$security = $container['Security'];
-$security->runChecks();
+// Check if we are a user
+OCP\User::checkLoggedIn();
-$controller = $container['SettingsController'];
-return $controller->index()->render();
+$somesetting = OCP\Config::getSystemValue( "somesetting", '' );
+OCP\App::setActiveNavigationEntry( 'apptemplate' );
+$tmpl = new OCP\Template( 'apptemplate', 'main', 'user' );
+$tmpl->assign( 'somesetting', $somesetting );
+$tmpl->printPage();
diff --git a/apptemplate/js/admin.js b/apptemplate/js/admin.js
index fa9b7dc8c..4b0bef0b5 100644
--- a/apptemplate/js/admin.js
+++ b/apptemplate/js/admin.js
@@ -1,17 +1,15 @@
$(document).ready(function(){
- OC.Router.registerLoadedCallback(function(){
- $('#somesetting').blur(function(event){
-
- event.preventDefault();
- var post = $( "#somesetting" ).serialize();
- var url = OC.Router.generate('apptemplate_ajax_setsystemvalue');
- $.post(url , post, function(data){
- $('#apptemplate .msg').text('Finished saving: ' + data);
- });
+ $('#somesetting').blur(function(event){
+ event.preventDefault();
+ var post = $( "#somesetting" ).serialize();
+ $.post( OC.filePath('apptemplate', 'ajax', 'seturl.php') , post, function(data){
+ $('#apptemplate .msg').text('Finished saving: ' + data);
});
});
+
+
});
diff --git a/apptemplate/lib/api.php b/apptemplate/lib/api.php
deleted file mode 100644
index fc061b7c4..000000000
--- a/apptemplate/lib/api.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-
-namespace OCA\AppTemplate;
-
-/**
- * This is used to wrap the owncloud static api calls into an object to make the
- * code better abstractable for use in the dependency injection container
- *
- * Extend this to your needs
- */
-class API {
-
- private $appName;
-
- /**
- * @param string $appName: the name of your application
- */
- public function __construct($appName){
- $this->appName = $appName;
- }
-
-
- /**
- * @return the name of your application
- */
- public function getAppName(){
- return $this->appName;
- }
-
-
- /**
- * @return: the user id of the current user
- */
- public function getUserId(){
- return \OCP\USER::getUser();
- }
-
-
- /**
- * Sets the current navigation entry to the currently running app
- */
- public function activateNavigationEntry(){
- \OCP\App::setActiveNavigationEntry($this->appName);
- }
-
-
- /**
- * Adds a new javascript file
- * @param string $scriptName: the name of the javascript in js/
- * without the suffix
- */
- public function addScript($scriptName){
- \OCP\Util::addScript($this->appName, $scriptName);
- }
-
-
- /**
- * Adds a new css file
- * @param string $styleName: the name of the css file in css/
- * without the suffix
- */
- public function addStyle($styleName){
- \OCP\Util::addStyle($this->appName, $styleName);
- }
-
-
- /**
- * @brief shorthand for addScript for files in the 3rdparty directory
- * @param string $name: the name of the file without the suffix
- */
- public function add3rdPartyScript($name){
- \OCP\Util::addScript($this->appName . '/3rdparty', $name);
- }
-
-
- /**
- * @brief shorthand for addStyle for files in the 3rdparty directory
- * @param string $name: the name of the file without the suffix
- */
- public function add3rdPartyStyle($name){
- \OCP\Util::addStyle($this->appName . '/3rdparty', $name);
- }
-
- /**
- * Looks up a systemwide defined value
- * @param string $key: the key of the value, under which it was saved
- * @return the saved value
- */
- public function getSystemValue($key){
- return \OCP\Config::getSystemValue($key, '');
- }
-
-
- /**
- * Sets a new systemwide value
- * @param string $key: the key of the value, under which will be saved
- * @param $value: the value that should be stored
- */
- public function setSystemValue($key, $value){
- return \OCP\Config::setSystemValue($key, $value);
- }
-
-
- /**
- * Shortcut for setting a user defined value
- * @param $key the key under which the value is being stored
- * @param $value the value that you want to store
- */
- public function setUserValue($key, $value){
- \OCP\Config::setUserValue($this->getUserId(), $this->appName, $key, $value);
- }
-
-
- /**
- * Shortcut for getting a user defined value
- * @param $key the key under which the value is being stored
- */
- public function getUserValue($key){
- return \OCP\Config::getUserValue($this->getUserId(), $this->appName, $key);
- }
-
-
- /**
- * Returns the translation object
- * @return the translation object
- */
- public function getTrans(){
- return \OC_L10N::get($this->appName);
- }
-
-
-} \ No newline at end of file
diff --git a/apptemplate/lib/controller.php b/apptemplate/lib/controller.php
deleted file mode 100644
index 84bc593fd..000000000
--- a/apptemplate/lib/controller.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-class Controller {
-
- protected $api;
- protected $appName;
-
- private $request;
-
- /**
- * @param API $api: an api wrapper instance
- * @param Request $request: an instance of the request
- */
- public function __construct($api, $request){
- $this->api = $api;
- $this->request = $request;
- $this->appName = $api->getAppName();
- }
-
-
- /**
- * @brief lets you access post and get parameters by the index
- * @param string $key: the key which you want to access in the $_POST or
- * $_GET array. If both arrays store things under the same
- * key, return the value in $_POST
- * @return: the content of the array
- */
- protected function params($key){
- $postValue = $this->request->getPOST($key);
- $getValue = $this->request->getGET($key);
-
- if($postValue !== null){
- return $postValue;
- }
-
- if($getValue !== null){
- return $getValue;
- }
-
- }
-
-} \ No newline at end of file
diff --git a/apptemplate/lib/request.php b/apptemplate/lib/request.php
deleted file mode 100644
index 82f6fbaa7..000000000
--- a/apptemplate/lib/request.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-
-namespace OCA\AppTemplate;
-
-/**
- * Encapsulates $_GET and $_POST arrays for better testability
- */
-class Request {
-
- private $get;
- private $post;
-
- /**
- * @param array $get: the $_GET array
- * @param array $post: the $_POST array
- */
- public function __construct($get=array(), $post=array()) {
- $this->get = $get;
- $this->post = $post;
- }
-
-
- /**
- * Returns the get value or the default if not found
- * @param string $key: the array key that should be looked up
- * @param string $default: if the key is not found, return this value
- * @return the value of the stored array
- */
- public function getGET($key, $default=null){
- if(isset($this->get[$key])){
- return $this->get[$key];
- } else {
- return $default;
- }
- }
-
-
- /**
- * Returns the get value or the default if not found
- * @param string $key: the array key that should be looked up
- * @param string $default: if the key is not found, return this value
- * @return the value of the stored array
- */
- public function getPOST($key, $default=null){
- if(isset($this->post[$key])){
- return $this->post[$key];
- } else {
- return $default;
- }
- }
-
-}
diff --git a/apptemplate/lib/response.php b/apptemplate/lib/response.php
deleted file mode 100644
index 90e4b1b3c..000000000
--- a/apptemplate/lib/response.php
+++ /dev/null
@@ -1,158 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-
-namespace OCA\AppTemplate;
-
-interface Response {
- function render();
-}
-
-/**
- * Response for a normal template
- */
-class TemplateResponse implements Response {
-
- private $templateName;
- private $params;
- private $appName;
- private $renderAs;
-
- /**
- * @param string $appName: the name of your app
- * @param string $templateName: the name of the template
- */
- public function __construct($appName, $templateName) {
- $this->templateName = $templateName;
- $this->appName = $appName;
- $this->params = array();
- $this->renderAs = 'user';
- }
-
-
- /**
- * @brief sets template parameters
- * @param array $params: an array with key => value structure which sets template
- * variables
- */
- public function setParams($params){
- $this->params = $params;
- }
-
-
- /**
- * @brief sets the template page
- * @param string $renderAs: admin, user or blank: admin renders the page on
- * the admin settings page, user renders a normal
- * owncloud page, blank renders the template alone
- */
- public function renderAs($renderAs='user'){
- $this->renderAs = $renderAs;
- }
-
-
- /**
- * Returns the rendered html
- * @return the rendered html
- */
- public function render(){
- if($this->renderAs === 'blank'){
- $template = new \OCP\Template($this->appName, $this->templateName);
- } else {
- $template = new \OCP\Template($this->appName, $this->templateName,
- $this->renderAs);
- }
-
- foreach($this->params as $key => $value){
- $template->assign($key, $value, false);
- }
-
- return $template->fetchPage();
- }
-
-}
-
-
-/**
- * A renderer for JSON calls
- */
-class JSONResponse implements Response {
-
- private $name;
- private $data;
- private $appName;
-
- /**
- * @param string $appName: the name of your app
- */
- public function __construct($appName) {
- $this->appName = $appName;
- $this->data = array();
- $this->error = false;
- }
-
- /**
- * @brief sets values in the data json array
- * @param array $params: an array with key => value structure which will be
- * transformed to JSON
- */
- public function setParams($params){
- $this->data['data'] = $params;
- }
-
-
- /**
- * @brief in case we want to render an error message, also logs into the
- * owncloud log
- * @param string $message: the error message
- * @param string $file: the file where the error occured, use __FILE__ in
- * the file where you call it
- */
- public function setErrorMessage($msg, $file){
- $this->error = true;
- $this->data['msg'] = $msg;
- \OCP\Util::writeLog($this->appName, $file . ': ' . $msg, \OCP\Util::ERROR);
- }
-
-
- /**
- * Returns the rendered json
- * @return the rendered json
- */
- public function render(){
-
- ob_start();
-
- if($this->error){
- \OCP\JSON::error($this->data);
- } else {
- \OCP\JSON::success($this->data);
- }
-
- $result = ob_get_contents();
- ob_end_clean();
-
- return $result;
- }
-
-} \ No newline at end of file
diff --git a/apptemplate/lib/security.php b/apptemplate/lib/security.php
deleted file mode 100644
index c16702450..000000000
--- a/apptemplate/lib/security.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-
-/**
-* ownCloud - App Template Example
-*
-* @author Bernhard Posselt
-* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\AppTemplate;
-
-
-/**
- * This class is a simple object with getters and setters and allows
- * finegrained controll over security checks
- * All security checks are enabled by default
- */
-class Security {
-
- private $csrfCheck;
- private $loggedInCheck;
- private $appEnabledCheck;
- private $isAdminCheck;
- private $appName;
-
- /**
- * @param string $appName: the name of the app
- */
- public function __construct($appName){
- $this->appName = $appName;
-
- // enable all checks by default
- $this->csrfCheck = true;
- $this->loggedInCheck = true;
- $this->appEnabledCheck = true;
- $this->isAdminCheck = true;
- }
-
-
- public function setCSRFCheck($csrfCheck){
- $this->csrfCheck = $csrfCheck;
- }
-
- public function setLoggedInCheck($loggedInCheck){
- $this->loggedInCheck = $loggedInCheck;
- }
-
- public function setAppEnabledCheck($appEnabledCheck){
- $this->appEnabledCheck = $appEnabledCheck;
- }
-
- public function setIsAdminCheck($isAdminCheck){
- $this->isAdminCheck = $isAdminCheck;
- }
-
-
- /**
- * Runs all security checks
- */
- public function runChecks() {
-
- if($this->loggedInCheck){
- \OCP\JSON::checkLoggedIn();
- }
-
- if($this->appEnabledCheck){
- \OCP\JSON::checkAppEnabled($this->appName);
- }
-
- if($this->isAdminCheck){
- \OCP\JSON::checkAdminUser();
- }
-
- }
-
-
- /**
- * Runs all the security checks for AJAX requests
- */
- public function runAjaxChecks(){
- if($this->csrfCheck){
- \OCP\JSON::callCheck();
- }
-
- if($this->loggedInCheck){
- \OCP\JSON::checkLoggedIn();
- }
-
- if($this->appEnabledCheck){
- \OCP\JSON::checkAppEnabled($this->appName);
- }
-
- if($this->isAdminCheck){
- \OCP\JSON::checkAdminUser();
- }
-
- }
-
-
-} \ No newline at end of file
diff --git a/apptemplate/settings.php b/apptemplate/settings.php
new file mode 100644
index 000000000..04aaca651
--- /dev/null
+++ b/apptemplate/settings.php
@@ -0,0 +1,11 @@
+<?php
+
+OCP\User::checkAdminUser();
+
+OCP\Util::addScript( "apptemplate", "admin" );
+
+$tmpl = new OCP\Template( 'apptemplate', 'settings');
+
+$tmpl->assign('url', OCP\Config::getSystemValue( "somesetting", '' ));
+
+return $tmpl->fetchPage();
diff --git a/apptemplate/templates/main.php b/apptemplate/templates/main.php
index d084cd91f..8052fbe83 100644
--- a/apptemplate/templates/main.php
+++ b/apptemplate/templates/main.php
@@ -1,3 +1,3 @@
<h1>This is an example app template</h1>
-<?php p($l->t('Some Setting')); ?>: "<?php p($_['somesetting']); ?>"
+<?php echo $l->t('Some Setting');?>: "<?php echo $_['somesetting']; ?>"
diff --git a/apptemplate/templates/settings.php b/apptemplate/templates/settings.php
index 0a434db95..687abdadd 100644
--- a/apptemplate/templates/settings.php
+++ b/apptemplate/templates/settings.php
@@ -1,7 +1,7 @@
<form id="apptemplate">
<fieldset class="personalblock">
<strong>App Template</strong><br />
- <input type="text" name="somesetting" id="somesetting" value="<?php p($_['url']); ?>" placeholder="<?php p($l->t('Some Setting'));?>" />
+ <input type="text" name="somesetting" id="somesetting" value="<?php echo $_['url']; ?>" placeholder="<?php echo $l->t('Some Setting');?>" />
<br />
<span class="msg"></span>
</fieldset>