Merge pull request #118 from fabrixxm/admin

Admin work
This commit is contained in:
Friendika 2011-06-18 00:17:36 -07:00
commit cf9f23fb74
7 changed files with 82 additions and 30 deletions

View file

@ -20,7 +20,7 @@ function poormancron_uninstall() {
function poormancron_hook($a,&$b) { function poormancron_hook(&$a,&$b) {
$now = time(); $now = time();
$lastupdate = get_config('poormancron', 'lastupdate'); $lastupdate = get_config('poormancron', 'lastupdate');
@ -31,7 +31,7 @@ function poormancron_hook($a,&$b) {
} }
} }
function poormancron_procrun($a, $argv) { function poormancron_procrun(&$a, $argv) {
logger("poormancron procrun ".implode(", ",$argv)); logger("poormancron procrun ".implode(", ",$argv));
array_shift($argv); array_shift($argv);
$argc = count($argv); $argc = count($argv);
@ -43,5 +43,4 @@ function poormancron_procrun($a, $argv) {
} }
?> ?>

3
addon/twitter/admin.tpl Normal file
View file

@ -0,0 +1,3 @@
{{ inc field_input.tpl with $field=$consumerkey }}{{ endinc }}
{{ inc field_input.tpl with $field=$consumersecret }}{{ endinc }}
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div>

View file

@ -47,6 +47,7 @@ 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");
} }
@ -56,6 +57,7 @@ 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) {
@ -240,4 +242,19 @@ function twitter_post_hook(&$a,&$b) {
} }
} }
} }
function plugin_admin_post(&$a){
$consumerkey = ((x($_POST,'consumerkey')) ? notags(trim($_POST['consumerkey'])) : '');
$consumersecret = ((x($_POST,'consumersecret')) ? notags(trim($_POST['consumersecret'])): '');
set_config('twitter','consumerkey',$consumerkey);
set_config('twitter','consumersecret',$consumersecret);
info( t('Settings updated.'). EOL );
}
function plugin_admin(&$a, &$o){
$t = file_get_contents( dirname(__file__). "/admin.tpl" );
$o = replace_macros($t, array(
'$submit' => t('Submit'),
// name, label, value, help, [extra values]
'$consumerkey' => array('consumerkey', t('Consumer key'), get_config('twitter', 'consumerkey' ), ''),
'$consumersecret' => array('consumersecret', t('Consumer secret'), get_config('twitter', 'consumersecret' ), '')
));
}

View file

@ -16,7 +16,8 @@
case PREG_BAD_UTF8_ERROR: die('PREG_BAD_UTF8_ERROR'); break; case PREG_BAD_UTF8_ERROR: die('PREG_BAD_UTF8_ERROR'); break;
case PREG_BAD_UTF8_OFFSET_ERROR: die('PREG_BAD_UTF8_OFFSET_ERROR'); break; case PREG_BAD_UTF8_OFFSET_ERROR: die('PREG_BAD_UTF8_OFFSET_ERROR'); break;
default: default:
die("Unknown preg error."); //die("Unknown preg error.");
return;
} }
} }

View file

@ -25,6 +25,17 @@ function admin_post(&$a){
case 'users': case 'users':
admin_page_users_post($a); admin_page_users_post($a);
break; break;
case 'plugins':
if ($a->argc > 2 &&
is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
@include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
if(function_exists('plugin_admin_post')) {
plugin_admin_post($a);
}
}
goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
return; // NOTREACHED
break;
case 'logs': case 'logs':
admin_page_logs_post($a); admin_page_logs_post($a);
break; break;
@ -59,6 +70,8 @@ function admin_content(&$a) {
foreach ($r as $h){ foreach ($r as $h){
$plugin = explode("/",$h['file']); $plugin = $plugin[1]; $plugin = explode("/",$h['file']); $plugin = $plugin[1];
$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
$a->plugins_admin[] = $plugin;
} }
$aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs"); $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
@ -164,11 +177,10 @@ function admin_page_site_post(&$a){
$global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : ''); $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
$global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : ''); $global_search_url = ((x($_POST,'directory_search_url'))? notags(trim($_POST['directory_search_url'])) : '');
$no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False); $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
$no_openid = ((x($_POST,'no_openid')) ? True : False); $no_openid = !((x($_POST,'no_openid')) ? True : False);
$no_gravatar = ((x($_POST,'no_gravatar')) ? True : False); $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
$no_regfullname = ((x($_POST,'no_regfullname')) ? True : False); $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
$no_utf = ((x($_POST,'no_utf')) ? True : False); $no_utf = !((x($_POST,'no_utf')) ? True : False);
$rino_enc = ((x($_POST,'rino_enc')) ? True : False);
$verifyssl = ((x($_POST,'verifyssl')) ? True : False); $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
$proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : ''); $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
$proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : ''); $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
@ -210,13 +222,13 @@ function admin_page_site_post(&$a){
set_config('system','no_gravatar', $no_gravatar); set_config('system','no_gravatar', $no_gravatar);
set_config('system','no_regfullname', $no_regfullname); set_config('system','no_regfullname', $no_regfullname);
set_config('system','proxy', $no_utf); set_config('system','proxy', $no_utf);
set_config('system','rino_encrypt', $rino_enc);
set_config('system','verifyssl', $verifyssl); set_config('system','verifyssl', $verifyssl);
set_config('system','proxyuser', $proxyuser); set_config('system','proxyuser', $proxyuser);
set_config('system','proxy', $proxy); set_config('system','proxy', $proxy);
set_config('system','curl_timeout', $timeout); set_config('system','curl_timeout', $timeout);
info( t('Site settings updated.') . EOL);
goaway($a->get_baseurl() . '/admin/site' ); goaway($a->get_baseurl() . '/admin/site' );
return; // NOTREACHED return; // NOTREACHED
@ -269,8 +281,12 @@ function admin_page_site(&$a) {
'$title' => t('Administration'), '$title' => t('Administration'),
'$page' => t('Site'), '$page' => t('Site'),
'$submit' => t('Submit'), '$submit' => t('Submit'),
'$baseurl' => $a->get_baseurl(), '$registration' => t('Registration'),
'$upload' => t('File upload'),
'$corporate' => t('Corporate/Edu'),
'$advanced' => t('Advanced'),
'$baseurl' => $a->get_baseurl(),
// name, label, value, help string, extra data... // name, label, value, help string, extra data...
'$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""), '$sitename' => array('sitename', t("Site name"), $a->config['sitename'], ""),
'$banner' => array('banner', t("Banner/Logo"), $banner, ""), '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
@ -290,12 +306,11 @@ function admin_page_site(&$a) {
'$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), "Disallow users to register additional accounts for use as pages."), '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), "Disallow users to register additional accounts for use as pages."),
'$no_openid' => array('no_openid', t("No OpenID support"), get_config('system','no_openid'), "Disable OpenID support for registration and logins."), '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
'$no_gravatar' => array('no_gravatar', t("No Gravatar support"), get_config('system','no_gravatar'), ""), '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
'$no_regfullname' => array('no_regfullname', t("No fullname check"), get_config('system','no_regfullname'), "If unchecked, force users to registrate with a space between his firsname and lastname in Full name, as an antispam measure"), '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), "Force users to registrate with a space between his firsname and lastname in Full name, as an antispam measure"),
'$no_utf' => array('no_utf', t("No UTF-8 Regular expressions"), get_config('system','proxy'), "Default is false (meaning UTF8 regular expressions are supported and working)"), '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','proxy'), "Use PHP UTF8 regular expressions"),
'$rino_enc' => array('rino_enc', t("Enable Rino encrypt"), get_config('system','rino_encrypt'),""),
'$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), "If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites."), '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), "If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites."),
'$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""), '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
'$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
@ -323,7 +338,7 @@ function admin_page_users_post(&$a){
intval( $uid ) intval( $uid )
); );
} }
notice( sprintf( tt("%s user blocked", "%s users blocked", count($users)), count($users)) ); notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
} }
if (x($_POST,'page_users_delete')){ if (x($_POST,'page_users_delete')){
require_once("include/Contact.php"); require_once("include/Contact.php");
@ -371,6 +386,7 @@ function admin_page_users(&$a){
intval( 1-$user[0]['blocked'] ), intval( 1-$user[0]['blocked'] ),
intval( $uid ) intval( $uid )
); );
notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
}; break; }; break;
} }
goaway($a->get_baseurl() . '/admin/users' ); goaway($a->get_baseurl() . '/admin/users' );
@ -392,12 +408,12 @@ function admin_page_users(&$a){
$a->set_pager_itemspage(100); $a->set_pager_itemspage(100);
} }
$users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro` , `lastitem`.`changed` AS `lastitem_date` $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro` , `lastitem`.`lastitem_date`
FROM ( FROM (
SELECT `item`.`changed` , `item`.`uid` SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
FROM `item` FROM `item`
GROUP BY `uid` WHERE `item`.`type` = 'wall'
ORDER BY `item`.`changed` GROUP BY `item`.`uid`
) AS `lastitem` , `user` ) AS `lastitem` , `user`
LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid` LEFT JOIN `contact` ON `user`.`uid` = `contact`.`uid`
WHERE `user`.`verified` =1 WHERE `user`.`verified` =1
@ -481,9 +497,11 @@ function admin_page_plugins(&$a){
if ($idx){ if ($idx){
unset($a->plugins[$idx]); unset($a->plugins[$idx]);
uninstall_plugin($plugin); uninstall_plugin($plugin);
info( sprintf( t("Plugin %s disabled."), $plugin ) );
} else { } else {
$a->plugins[] = $plugin; $a->plugins[] = $plugin;
install_plugin($plugin); install_plugin($plugin);
info( sprintf( t("Plugin %s enabled."), $plugin ) );
} }
set_config("system","addon", implode(", ",$a->plugins)); set_config("system","addon", implode(", ",$a->plugins));
goaway($a->get_baseurl() . '/admin/plugins' ); goaway($a->get_baseurl() . '/admin/plugins' );
@ -506,11 +524,17 @@ function admin_page_plugins(&$a){
$readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>"; $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
} }
$admin_form="";
if (in_array($plugin, $a->plugins_admin)){
call_hooks('plugin_admin', $admin_form);
}
$t = get_markup_template("admin_plugins_details.tpl"); $t = get_markup_template("admin_plugins_details.tpl");
return replace_macros($t, array( return replace_macros($t, array(
'$title' => t('Administration'), '$title' => t('Administration'),
'$page' => t('Plugins'), '$page' => t('Plugins'),
'$toggle' => t('Toggle'), '$toggle' => t('Toggle'),
'$settings' => t('Settings'),
'$baseurl' => $a->get_baseurl(), '$baseurl' => $a->get_baseurl(),
'$plugin' => $plugin, '$plugin' => $plugin,
@ -518,6 +542,8 @@ function admin_page_plugins(&$a){
'$action' => $action, '$action' => $action,
'$info' => get_plugin_info($plugin), '$info' => get_plugin_info($plugin),
'$admin_form' => $admin_form,
'$readme' => $readme '$readme' => $readme
)); ));
} }
@ -570,6 +596,7 @@ function admin_page_logs_post(&$a) {
} }
info( t("Log settings updated.") );
goaway($a->get_baseurl() . '/admin/logs' ); goaway($a->get_baseurl() . '/admin/logs' );
return; // NOTREACHED return; // NOTREACHED
} }

View file

@ -11,6 +11,12 @@
</p> </p>
{{ if $admin_form }}
<h3>$settings</h3>
<form method="post" action="$baseurl/admin/plugins/$plugin/">
$admin_form
</form>
{{ endif }}
{{ if $readme }} {{ if $readme }}
<h3>Readme</h3> <h3>Readme</h3>

View file

@ -10,7 +10,7 @@
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div> <div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
<h3>Registration</h3> <h3>$registration</h3>
{{ inc field_input.tpl with $field=$register_text }}{{ endinc }} {{ inc field_input.tpl with $field=$register_text }}{{ endinc }}
{{ inc field_select.tpl with $field=$register_policy }}{{ endinc }} {{ inc field_select.tpl with $field=$register_policy }}{{ endinc }}
@ -18,14 +18,13 @@
{{ inc field_checkbox.tpl with $field=$no_openid }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$no_openid }}{{ endinc }}
{{ inc field_checkbox.tpl with $field=$no_gravatar }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$no_gravatar }}{{ endinc }}
{{ inc field_checkbox.tpl with $field=$no_regfullname }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$no_regfullname }}{{ endinc }}
{{ inc field_checkbox.tpl with $field=$no_utf }}{{ endinc }}
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div> <div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
<h3>Upload</h3> <h3>$upload</h3>
{{ inc field_input.tpl with $field=$maximagesize }}{{ endinc }} {{ inc field_input.tpl with $field=$maximagesize }}{{ endinc }}
<h3>Corporate/Edu</h3> <h3>$corporate</h3>
{{ inc field_input.tpl with $field=$allowed_sites }}{{ endinc }} {{ inc field_input.tpl with $field=$allowed_sites }}{{ endinc }}
{{ inc field_input.tpl with $field=$allowed_email }}{{ endinc }} {{ inc field_input.tpl with $field=$allowed_email }}{{ endinc }}
{{ inc field_checkbox.tpl with $field=$block_public }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$block_public }}{{ endinc }}
@ -35,8 +34,8 @@
<div class="submit"><input type="submit" name="page_site" value="$submit" /></div> <div class="submit"><input type="submit" name="page_site" value="$submit" /></div>
<h3>Advanced</h3> <h3>$advanced</h3>
{{ inc field_checkbox.tpl with $field=$rino_enc }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$no_utf }}{{ endinc }}
{{ inc field_checkbox.tpl with $field=$verifyssl }}{{ endinc }} {{ inc field_checkbox.tpl with $field=$verifyssl }}{{ endinc }}
{{ inc field_input.tpl with $field=$proxy }}{{ endinc }} {{ inc field_input.tpl with $field=$proxy }}{{ endinc }}
{{ inc field_input.tpl with $field=$proxyuser }}{{ endinc }} {{ inc field_input.tpl with $field=$proxyuser }}{{ endinc }}