From 98e4c7e26d4ecb496a2fea24a4073bafebf0162f Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Sun, 3 Mar 2013 20:12:42 -0500 Subject: [PATCH] New addon: Default Features - allow admin to turn some Additional Features on by default for new users. --- defaultfeatures/README | 7 ++++ defaultfeatures/defaultfeatures.php | 57 ++++++++++++++++++++++++++ defaultfeatures/view/admin.tpl | 9 ++++ defaultfeatures/view/smarty3/admin.tpl | 14 +++++++ 4 files changed, 87 insertions(+) create mode 100644 defaultfeatures/README create mode 100755 defaultfeatures/defaultfeatures.php create mode 100644 defaultfeatures/view/admin.tpl create mode 100644 defaultfeatures/view/smarty3/admin.tpl diff --git a/defaultfeatures/README b/defaultfeatures/README new file mode 100644 index 000000000..cc45cbf6a --- /dev/null +++ b/defaultfeatures/README @@ -0,0 +1,7 @@ +Default Features Plugin + +This plugin allows the site admin to choose which Additional Features + are on by default for newly created users on the site. The defaults + apply to all new users upon registration, but do not impact a user's + ability to turn features on/off once their account has been created. +These default settings do not impact existing users. diff --git a/defaultfeatures/defaultfeatures.php b/defaultfeatures/defaultfeatures.php new file mode 100755 index 000000000..ad6a18161 --- /dev/null +++ b/defaultfeatures/defaultfeatures.php @@ -0,0 +1,57 @@ + $fdata) { + foreach(array_slice($fdata,1) as $f) { + set_pconfig($newuid,'feature',$f[0],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0")); + } + } +} + +function defaultfeatures_plugin_admin_post (&$a) { + check_form_security_token_redirectOnErr('/admin/plugins/defaultfeatures', 'admin_themes'); + foreach($_POST as $k => $v) { + if(strpos($k,'feature_') === 0) { + set_config('defaultfeatures',substr($k,8),((intval($v)) ? 1 : 0)); + } + } + info( t('Features updated') . EOL); +} + +function defaultfeatures_plugin_admin (&$a, &$o) { + $t = get_markup_template( "admin.tpl", "addon/defaultfeatures/" ); + $arr = array(); + $features = get_features(); + foreach($features as $fname => $fdata) { + $arr[$fname] = array(); + $arr[$fname][0] = $fdata[0]; + foreach(array_slice($fdata,1) as $f) { + $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0"),$f[2],array(t('Off'),t('On'))); + } + } + + //logger("Features: " . print_r($arr,true)); + + $o = replace_macros($t, array( + '$submit' => t('Submit'), + '$features' => $arr + )); +} diff --git a/defaultfeatures/view/admin.tpl b/defaultfeatures/view/admin.tpl new file mode 100644 index 000000000..e7793d3da --- /dev/null +++ b/defaultfeatures/view/admin.tpl @@ -0,0 +1,9 @@ + +{{ for $features as $f }} +

$f.0

+ +{{ for $f.1 as $fcat }} + {{ inc field_yesno.tpl with $field=$fcat }}{{endinc}} +{{ endfor }} +{{ endfor }} +
diff --git a/defaultfeatures/view/smarty3/admin.tpl b/defaultfeatures/view/smarty3/admin.tpl new file mode 100644 index 000000000..3fbda3846 --- /dev/null +++ b/defaultfeatures/view/smarty3/admin.tpl @@ -0,0 +1,14 @@ +{{* + * AUTOMATICALLY GENERATED TEMPLATE + * DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN + * + *}} + +{{foreach $features as $f}} +

{{$f.0}}

+ +{{foreach $f.1 as $fcat}} + {{include file="field_yesno.tpl" field=$fcat}} +{{/foreach}} +{{/foreach}} +