]> source.dussan.org Git - nextcloud-server.git/commitdiff
Ability to save an arbitrary number of external sites
authorrok <brejktru@gmail.com>
Fri, 2 Mar 2012 20:32:17 +0000 (21:32 +0100)
committerRobin Appelman <icewind@owncloud.com>
Wed, 7 Mar 2012 13:59:19 +0000 (14:59 +0100)
apps/external/ajax/setsites.php [new file with mode: 0644]
apps/external/ajax/seturls.php [deleted file]
apps/external/appinfo/app.php
apps/external/css/style.css [new file with mode: 0644]
apps/external/index.php
apps/external/js/admin.js
apps/external/lib/external.php [new file with mode: 0644]
apps/external/settings.php
apps/external/templates/settings.php

diff --git a/apps/external/ajax/setsites.php b/apps/external/ajax/setsites.php
new file mode 100644 (file)
index 0000000..0537b7e
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Frank Karlitschek <karlitschek@kde.org>
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../lib/base.php');
+OC_Util::checkAdminUser();
+
+$sites = array();
+for ($i = 0; $i < sizeof($_POST['site_name']); $i++) {
+       if (!empty($_POST['site_name'][$i]) && !empty($_POST['site_url'][$i])) {
+               array_push($sites, array($_POST['site_name'][$i], $_POST['site_url'][$i]));
+       }
+}
+
+if (sizeof($sites) == 0)
+       OC_Appconfig::deleteKey('external', 'sites');
+else
+       OC_Appconfig::setValue('external', 'sites', json_encode($sites));
+
+echo 'true';
+?>
diff --git a/apps/external/ajax/seturls.php b/apps/external/ajax/seturls.php
deleted file mode 100644 (file)
index e994385..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011, Frank Karlitschek <karlitschek@kde.org>
- * This file is licensed under the Affero General Public License version 3 or later.
- * See the COPYING-README file.
- */
-
-require_once('../../../lib/base.php');
-OC_Util::checkAdminUser();
-
-if(isset($_POST['s1name'])) OC_Appconfig::setValue( 'external','site1name', $_POST['s1name'] );
-if(isset($_POST['s1url'])) OC_Appconfig::setValue( 'external','site1url', $_POST['s1url'] );
-if(isset($_POST['s2name'])) OC_Appconfig::setValue( 'external','site2name', $_POST['s2name'] );
-if(isset($_POST['s2url'])) OC_Appconfig::setValue( 'external','site2url', $_POST['s2url'] );
-if(isset($_POST['s3name'])) OC_Appconfig::setValue( 'external','site3name', $_POST['s3name'] );
-if(isset($_POST['s3url'])) OC_Appconfig::setValue( 'external','site3url', $_POST['s3url'] );
-if(isset($_POST['s4name'])) OC_Appconfig::setValue( 'external','site4name', $_POST['s4name'] );
-if(isset($_POST['s4url'])) OC_Appconfig::setValue( 'external','site4url', $_POST['s4url'] );
-if(isset($_POST['s5name'])) OC_Appconfig::setValue( 'external','site5name', $_POST['s5name'] );
-if(isset($_POST['s5url'])) OC_Appconfig::setValue( 'external','site5url', $_POST['s5url'] );
-
-echo 'true';
-
-?>
index 0f536cbf4183d5c6ce0419c2a3584e534fa17da7..74e6d5c94c68c71f8f560b983804ed9260814922 100644 (file)
@@ -1,37 +1,35 @@
 <?php
 
 /**
-* ownCloud - External plugin
-*
-* @author Frank Karlitschek
-* @copyright 2011 Frank Karlitschek karlitschek@kde.org
-* 
-* 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 Lesser General Public 
-* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
-* 
-*/
-
-OC_APP::registerAdmin('external','settings');
-
-OC_App::register( array( 'order' => 70, 'id' => 'external', 'name' => 'External' ));
-
-if(OC_Appconfig::getValue( "external","site1name", '' )<>'')  OC_App::addNavigationEntry( array( 'id' => 'external_index1', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=1', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site1name", '' )));
-
-if(OC_Appconfig::getValue( "external","site2name", '' )<>'')  OC_App::addNavigationEntry( array( 'id' => 'external_index2', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=2', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site2name", '' )));
-
-if(OC_Appconfig::getValue( "external","site3name", '' )<>'')  OC_App::addNavigationEntry( array( 'id' => 'external_index3', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=3', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site3name", '' )));
-
-if(OC_Appconfig::getValue( "external","site4name", '' )<>'')  OC_App::addNavigationEntry( array( 'id' => 'external_index4', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=4', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site4name", '' )));
-
-if(OC_Appconfig::getValue( "external","site5name", '' )<>'')  OC_App::addNavigationEntry( array( 'id' => 'external_index5', 'order' => 80, 'href' => OC_Helper::linkTo( 'external', 'index.php' ).'?id=5', 'icon' => OC_Helper::imagePath( 'external', 'external.png' ), 'name' => OC_Appconfig::getValue( "external","site5name", '' )));
-
+ * ownCloud - External plugin
+ *
+ * @author Frank Karlitschek
+ * @copyright 2011 Frank Karlitschek karlitschek@kde.org
+ * 
+ * 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 Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+OC::$CLASSPATH['OC_External'] = 'apps/external/lib/external.php';
+OC_Util::addStyle( 'external', 'style');
+
+OC_APP::registerAdmin('external', 'settings');
+
+OC_App::register(array('order' => 70, 'id' => 'external', 'name' => 'External'));
+
+$sites = OC_External::getSites();
+for ($i = 0; $i < sizeof($sites); $i++) {
+       OC_App::addNavigationEntry(
+                       array('id' => 'external_index' . ($i + 1), 'order' => 80 + $i, 'href' => OC_Helper::linkTo('external', 'index.php') . '?id=' . ($i + 1), 'icon' => OC_Helper::imagePath('external', 'external.png'), 'name' => $sites[$i][0]));
+}
\ No newline at end of file
diff --git a/apps/external/css/style.css b/apps/external/css/style.css
new file mode 100644 (file)
index 0000000..f891cb4
--- /dev/null
@@ -0,0 +1,14 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
+/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
+
+.site_url {
+    width: 250px;
+}
+
+.delete_button {
+    display: none;
+}
+
+.external_sites {
+    width: 450px;
+}
index 51cdc344bbfbddd4926211ba54e8a5e4a3240d54..1c20f59eaffc9b0e280e1fdef58c776f10d6d842 100644 (file)
@@ -1,42 +1,43 @@
 <?php
 
 /**
-* ownCloud - External plugin
-*
-* @author Frank Karlitschek
-* @copyright 2011 Frank Karlitschek karlitschek@kde.org
-* 
-* 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 Lesser General Public 
-* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
-* 
-*/
-
+ * ownCloud - External plugin
+ *
+ * @author Frank Karlitschek
+ * @copyright 2011 Frank Karlitschek karlitschek@kde.org
+ * 
+ * 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 Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
 require_once('../../lib/base.php');
+require_once('lib/external.php');
 
 OC_Util::checkLoggedIn();
 
-if(isset($_GET['id'])){
+if (isset($_GET['id'])) {
 
-       $id=$_GET['id'];
+       $id = $_GET['id'];
        $id = (int) $id;
 
-       $url=OC_Appconfig::getValue( "external","site".$id."url", '' );
-       OC_App::setActiveNavigationEntry( 'external_index'.$id );
-
-       $tmpl = new OC_Template( 'external', 'frame', 'user' );
-       $tmpl->assign('url',$url);
-       $tmpl->printPage();
+       $sites = OC_External::getSites();
+       if (sizeof($sites) >= $id) {
+               $url = $sites[$id - 1][1];
+               OC_App::setActiveNavigationEntry('external_index' . $id);
 
+               $tmpl = new OC_Template('external', 'frame', 'user');
+               $tmpl->assign('url', $url);
+               $tmpl->printPage();
+       }
 }
-
 ?>
index 6b9b6c67737fe175f2af81b0cb043d348b28e2c0..0caaabd0b96f7af69a5d117babde842185e44061 100644 (file)
@@ -1,67 +1,56 @@
 $(document).ready(function(){
+       newSiteHtml = '<li><input type="text" class="site_name" name="site_name[]" value="" placeholder="Name" />\n\
+    <input type="text" name="site_url[]" class="site_url" value=""  placeholder="URL" />\n\
+<img class="svg action delete_button" src="'+OC.imagePath("core", "actions/delete") +'" title="Remove site" /></li>';
 
-
-
-       $('#s1name').blur(function(event){
+       // Handler functions
+       function addSiteEventHandler(event) {
                event.preventDefault();
-               var post = $( "#s1name" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s1name .msg', data);   });
-       });
+               
+               saveSites();
+       }
 
-       $('#s2name').blur(function(event){
+       function deleteButtonEventHandler(event) {
                event.preventDefault();
-               var post = $( "#s2name" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s2name .msg', data);   });
-       });
 
-       $('#s3name').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s3name" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s3name .msg', data);   });
-       });
+               $(this).tipsy('hide');
+               $(this).parent().remove();
 
-       $('#s4name').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s4name" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s4name .msg', data);   });
-       });
+               saveSites();
+       }
 
-       $('#s5name').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s5name" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s5name .msg', data);   });
-       });
+       function saveSites() {
+               var post = $('#external').serialize();
+               $.post( OC.filePath('external','ajax','setsites.php') , post, function(data) {
+                       // OC.msg.finishedSaving('#site_name .msg', data); 
+               });
+       }
 
-       $('#s1url').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s1url" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s1url .msg', data);   });
-       });
+       function showDeleteButton(event) {
+               $(this).find('img.delete_button').fadeIn(100);
+       } 
 
-       $('#s2url').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s2url" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s2url .msg', data);   });
-       });
+       function hideDeleteButton(event) {
+               $(this).find('img.delete_button').fadeOut(100);
+       }
 
-       $('#s3url').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s3url" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s3url .msg', data);   });
-       });
+       // Initialize events
+       $('input[name^=site_]').change(addSiteEventHandler);
+       $('img.delete_button').click(deleteButtonEventHandler);
+       $('img.delete_button').tipsy();
 
-       $('#s4url').blur(function(event){
-               event.preventDefault();
-               var post = $( "#s4url" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s4url .msg', data);   });
-       });
+       $('#external li').hover(showDeleteButton, hideDeleteButton);
 
-       $('#s5url').blur(function(event){
+       $('#add_external_site').click(function(event) {
                event.preventDefault();
-               var post = $( "#s5url" ).serialize();
-               $.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s5url .msg', data);   });
-       });
+               $('#external ul').append(newSiteHtml);
 
+               $('input.site_url:last').prev('input.site_name').andSelf().change(addSiteEventHandler);
+               $('img.delete_button').click(deleteButtonEventHandler);
+               $('img.delete_button:last').tipsy();
+               $('#external li:last').hover(showDeleteButton, hideDeleteButton);
+               
+       });
 
 });
 
diff --git a/apps/external/lib/external.php b/apps/external/lib/external.php
new file mode 100644 (file)
index 0000000..9dd3232
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * ownCloud - gallery application
+ *
+ * @author Bartek Przybylski
+ * @copyright 2012 Bartek Przybylski bart.p.pl@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 Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+class OC_External {
+
+       public static function getSites() {
+               if (($sites = json_decode(OC_Appconfig::getValue("external", "sites", ''))) != NULL) {
+                       return $sites;  
+               }
+
+               return array();
+       }
+
+}
+
+?>
index 3e0c34251281e6da9ed9009c74bf7de6e54900e8..416c9a5c11f13da7fc21c043cb43e17d65790ff1 100644 (file)
@@ -6,17 +6,5 @@ OC_Util::addScript( "external", "admin" );
 
 $tmpl = new OC_Template( 'external', 'settings');
 
-       $tmpl->assign('s1name',OC_Appconfig::getValue( "external","site1name", '' ));
-       $tmpl->assign('s2name',OC_Appconfig::getValue( "external","site2name", '' ));
-       $tmpl->assign('s3name',OC_Appconfig::getValue( "external","site3name", '' ));
-       $tmpl->assign('s4name',OC_Appconfig::getValue( "external","site4name", '' ));
-       $tmpl->assign('s5name',OC_Appconfig::getValue( "external","site5name", '' ));
-
-       $tmpl->assign('s1url',OC_Appconfig::getValue( "external","site1url", '' ));
-       $tmpl->assign('s2url',OC_Appconfig::getValue( "external","site2url", '' ));
-       $tmpl->assign('s3url',OC_Appconfig::getValue( "external","site3url", '' ));
-       $tmpl->assign('s4url',OC_Appconfig::getValue( "external","site4url", '' ));
-       $tmpl->assign('s5url',OC_Appconfig::getValue( "external","site5url", '' ));
-
 return $tmpl->fetchPage();
 ?>
index a72327d35c81f002356cb1f9f614f92a3a061f5a..a130477d465223e8049ee36ee40d323150eef419 100644 (file)
@@ -1,23 +1,21 @@
 <form id="external">
        <fieldset class="personalblock">
                <strong>External Sites</strong><br />
-               <input type="text" name="s1name" id="s1name" value="<?php echo $_['s1name']; ?>" placeholder="<?php echo $l->t('Name');?>" />
-               <input type="text" name="s1url"  id="s1url"  value="<?php echo $_['s1url']; ?>"  placeholder="<?php echo $l->t('Url');?>" />
-                <br />
-               <input type="text" name="s2name" id="s2name" value="<?php echo $_['s2name']; ?>" placeholder="<?php echo $l->t('Name');?>" />
-               <input type="text" name="s2url"  id="s2url"  value="<?php echo $_['s2url']; ?>"  placeholder="<?php echo $l->t('Url');?>" />
-                <br />
-               <input type="text" name="s3name" id="s3name" value="<?php echo $_['s3name']; ?>" placeholder="<?php echo $l->t('Name');?>" />
-               <input type="text" name="s3url"  id="s3url"  value="<?php echo $_['s3url']; ?>"  placeholder="<?php echo $l->t('Url');?>" />
-                <br />
-               <input type="text" name="s4name" id="s4name" value="<?php echo $_['s4name']; ?>" placeholder="<?php echo $l->t('Name');?>" />
-               <input type="text" name="s4url"  id="s4url"  value="<?php echo $_['s4url']; ?>"  placeholder="<?php echo $l->t('Url');?>" />
-                <br />
-               <input type="text" name="s5name" id="s5name" value="<?php echo $_['s5name']; ?>" placeholder="<?php echo $l->t('Name');?>" />
-               <input type="text" name="s5url"  id="s5url"  value="<?php echo $_['s5url']; ?>"  placeholder="<?php echo $l->t('Url');?>" />
-                <br />
+               <ul class="external_sites">
 
+               <?php
+               $sites = OC_External::getSites();
+               for($i = 0; $i < sizeof($sites); $i++) {
+                       echo '<li><input type="text" name="site_name[]" class="site_name" value="'.$sites[$i][0].'" placeholder="'.$l->t('Name').'" />
+                       <input type="text" class="site_url" name="site_url[]"  value="'.$sites[$i][1].'"  placeholder="'.$l->t('URL').'" />
+                       <img class="svg action delete_button" src="'.image_path("", "actions/delete.svg") .'" title="'.$l->t("Remove site").'" />
+                       </li>';
+               }
+               ?>
 
-<span class="msg"></span>
+               </ul>
+
+        <input type="button" id="add_external_site" value="Add" />
+               <span class="msg"></span>
        </fieldset>
 </form>