Change logic in admin.php to load plugin settings form. Add statusnet settings form.

This commit is contained in:
fabrixxm 2011-06-19 15:43:10 +02:00
parent b650183cd4
commit 001982cac0
4 changed files with 90 additions and 10 deletions

16
addon/statusnet/admin.tpl Normal file
View file

@ -0,0 +1,16 @@
{{ for $sites as $s }}
{{ inc field_input.tpl with $field=$s.sitename }}{{ endinc }}
{{ inc field_input.tpl with $field=$s.apiurl }}{{ endinc }}
{{ inc field_input.tpl with $field=$s.secret }}{{ endinc }}
{{ inc field_input.tpl with $field=$s.key }}{{ endinc }}
{{ if $s.delete }}
{{ inc field_checkbox.tpl with $field=$s.delete }}{{ endinc }}
<hr>
{{ else }}
<p>Fill this form to add a new site</p>
{{ endif }}
{{ endfor }}
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div>

View file

@ -59,7 +59,6 @@ function statusnet_install() {
register_hook('plugin_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post'); register_hook('plugin_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
register_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook'); register_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
register_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets'); register_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
logger("installed statusnet"); logger("installed statusnet");
} }
@ -350,3 +349,66 @@ function statusnet_post_hook(&$a,&$b) {
} }
} }
function statusnet_plugin_admin_post(&$a){
$sites = array();
foreach($_POST['sitename'] as $id=>$sitename){
$sitename=trim($sitename);
$apiurl=trim($_POST['apiurl'][$id]);
$secret=trim($_POST['secret'][$id]);
$key=trim($_POST['key'][$id]);
if ($sitename!="" &&
$apiurl!="" &&
$secret!="" &&
$key!="" &&
!x($_POST['delete'][$id])){
$sites[] = Array(
'sitename' => $sitename,
'apiurl' => $apiurl,
'secret' => $secret,
'key' => $key
);
}
}
$sites = set_config('statusnet','sites', $sites);
}
function statusnet_plugin_admin(&$a, &$o){
$sites = get_config('statusnet','sites');
$sitesform=array();
if (is_array($sites)){
foreach($sites as $id=>$s){
$sitesform[] = Array(
'sitename' => Array("sitename[$id]", "Site name", $s['sitename'], ""),
'apiurl' => Array("apiurl[$id]", "Api url", $s['apiurl'], ""),
'secret' => Array("secret[$id]", "Secret", $s['secret'], ""),
'key' => Array("key[$id]", "Key", $s['key'], ""),
'delete' => Array("delete[$id]", "Delete", False , "Check to delete this preset"),
);
}
}
/* empty form to add new site */
$id++;
$sitesform[] = Array(
'sitename' => Array("sitename[$id]", "Site name", "", ""),
'apiurl' => Array("apiurl[$id]", "Api url", "", ""),
'secret' => Array("secret[$id]", "Secret", "", ""),
'key' => Array("key[$id]", "Key", "", ""),
);
$t = file_get_contents( dirname(__file__). "/admin.tpl" );
$o = replace_macros($t, array(
'$submit' => t('Submit'),
'$sites' => $sitesform,
));
}

View file

@ -47,7 +47,6 @@ function twitter_install() {
register_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post'); register_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
register_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook'); register_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
register_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets'); register_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
register_hook('plugin_admin', 'addon/twitter/twitter.php', 'plugin_admin');
logger("installed twitter"); logger("installed twitter");
} }
@ -57,7 +56,6 @@ function twitter_uninstall() {
unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post'); unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook'); unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets'); unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
unregister_hook('plugin_admin', 'addon/twitter/twitter.php', 'plugin_admin');
} }
function twitter_jot_nets(&$a,&$b) { function twitter_jot_nets(&$a,&$b) {
@ -242,14 +240,15 @@ function twitter_post_hook(&$a,&$b) {
} }
} }
} }
function plugin_admin_post(&$a){
function twitter_plugin_admin_post(&$a){
$consumerkey = ((x($_POST,'consumerkey')) ? notags(trim($_POST['consumerkey'])) : ''); $consumerkey = ((x($_POST,'consumerkey')) ? notags(trim($_POST['consumerkey'])) : '');
$consumersecret = ((x($_POST,'consumersecret')) ? notags(trim($_POST['consumersecret'])): ''); $consumersecret = ((x($_POST,'consumersecret')) ? notags(trim($_POST['consumersecret'])): '');
set_config('twitter','consumerkey',$consumerkey); set_config('twitter','consumerkey',$consumerkey);
set_config('twitter','consumersecret',$consumersecret); set_config('twitter','consumersecret',$consumersecret);
info( t('Settings updated.'). EOL ); info( t('Settings updated.'). EOL );
} }
function plugin_admin(&$a, &$o){ function twitter_plugin_admin(&$a, &$o){
$t = file_get_contents( dirname(__file__). "/admin.tpl" ); $t = file_get_contents( dirname(__file__). "/admin.tpl" );
$o = replace_macros($t, array( $o = replace_macros($t, array(
'$submit' => t('Submit'), '$submit' => t('Submit'),

View file

@ -29,8 +29,9 @@ function admin_post(&$a){
if ($a->argc > 2 && if ($a->argc > 2 &&
is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){ is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
@include_once("addon/".$a->argv[2]."/".$a->argv[2].".php"); @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
if(function_exists('plugin_admin_post')) { if(function_exists($a->argv[2].'_plugin_admin_post')) {
plugin_admin_post($a); $func = $a->argv[2].'_plugin_admin_post';
$func($a);
} }
} }
goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] ); goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
@ -65,10 +66,10 @@ function admin_content(&$a) {
/* get plugins admin page */ /* get plugins admin page */
$r = q("SELECT * FROM `hook` WHERE `hook`='plugin_admin'"); $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
$aside['plugins_admin']=Array(); $aside['plugins_admin']=Array();
foreach ($r as $h){ foreach ($r as $h){
$plugin = explode("/",$h['file']); $plugin = $plugin[1]; $plugin =$h['name'];
$aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin"); $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
// temp plugins with admin // temp plugins with admin
$a->plugins_admin[] = $plugin; $a->plugins_admin[] = $plugin;
@ -526,7 +527,9 @@ function admin_page_plugins(&$a){
$admin_form=""; $admin_form="";
if (in_array($plugin, $a->plugins_admin)){ if (in_array($plugin, $a->plugins_admin)){
call_hooks('plugin_admin', $admin_form); @require_once("addon/$plugin/$plugin.php");
$func = $plugin.'_plugin_admin';
$func($a, $admin_form);
} }
$t = get_markup_template("admin_plugins_details.tpl"); $t = get_markup_template("admin_plugins_details.tpl");