Ability to save an arbitrary number of external sites

This commit is contained in:
rok 2012-03-02 21:32:17 +01:00 committed by Robin Appelman
parent 0a78849391
commit fb88bdba69
9 changed files with 191 additions and 166 deletions

25
apps/external/ajax/setsites.php vendored Normal file
View File

@ -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';
?>

View File

@ -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';
?>

View 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/>.
*
*/
* 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::$CLASSPATH['OC_External'] = 'apps/external/lib/external.php';
OC_Util::addStyle( 'external', 'style');
OC_App::register( array( 'order' => 70, 'id' => 'external', 'name' => 'External' ));
OC_APP::registerAdmin('external', 'settings');
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", '' )));
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]));
}

14
apps/external/css/style.css vendored Normal file
View File

@ -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;
}

View 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();
}
}
?>

View File

@ -1,68 +1,57 @@
$(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){
$(this).tipsy('hide');
$(this).parent().remove();
saveSites();
}
function saveSites() {
var post = $('#external').serialize();
$.post( OC.filePath('external','ajax','setsites.php') , post, function(data) {
// OC.msg.finishedSaving('#site_name .msg', data);
});
}
function showDeleteButton(event) {
$(this).find('img.delete_button').fadeIn(100);
}
function hideDeleteButton(event) {
$(this).find('img.delete_button').fadeOut(100);
}
// Initialize events
$('input[name^=site_]').change(addSiteEventHandler);
$('img.delete_button').click(deleteButtonEventHandler);
$('img.delete_button').tipsy();
$('#external li').hover(showDeleteButton, hideDeleteButton);
$('#add_external_site').click(function(event) {
event.preventDefault();
var post = $( "#s3name" ).serialize();
$.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s3name .msg', data); });
});
$('#external ul').append(newSiteHtml);
$('#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); });
$('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);
});
$('#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); });
});
$('#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); });
});
$('#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); });
});
$('#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); });
});
$('#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); });
});
$('#s5url').blur(function(event){
event.preventDefault();
var post = $( "#s5url" ).serialize();
$.post( OC.filePath('external','ajax','seturls.php') , post, function(data){ OC.msg.finishedSaving('#s5url .msg', data); });
});
});

36
apps/external/lib/external.php vendored Normal file
View File

@ -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();
}
}
?>

View 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();
?>

View 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>