]> git.mxchange.org Git - friendica-addons.git/blob - defaultfeatures/defaultfeatures.php
Additional work for PR 3778
[friendica-addons.git] / defaultfeatures / defaultfeatures.php
1 <?php
2 /**
3  * Name: Default Features
4  * Description: Choose which Additional Features are on by default for new users on the site.
5  * Version: 1.0
6  * Author: Michael Johnston
7  * Status: Unsupported
8  */
9
10 function defaultfeatures_install() {
11     register_hook('register_account', 'addon/defaultfeatures/defaultfeatures.php', 'defaultfeatures_register');
12     logger("installed defaultfeatures plugin");
13 }
14
15 function defaultfeatures_uninstall() {
16     unregister_hook('register_account', 'addon/defaultfeatures/defaultfeatures.php', 'defaultfeatures_register');
17     logger("uninstalled defaultfeatures plugin");
18 }
19
20 function defaultfeatures_register($a, $newuid) {
21     $arr = array();
22     $features = get_features();
23     foreach($features as $fname => $fdata) {
24             foreach(array_slice($fdata,1) as $f) {
25                     set_pconfig($newuid,'feature',$f[0],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0"));
26             }
27     }
28 }
29
30 function defaultfeatures_plugin_admin_post (&$a) {
31     check_form_security_token_redirectOnErr('/admin/plugins/defaultfeatures', 'defaultfeaturessave');
32     foreach($_POST as $k => $v) {
33             if(strpos($k,'feature_') === 0) {
34                     set_config('defaultfeatures',substr($k,8),((intval($v)) ? 1 : 0));
35             }
36     }
37     info( t('Features updated') . EOL);
38 }
39
40 function defaultfeatures_plugin_admin (&$a, &$o) {
41     $t = get_markup_template( "admin.tpl", "addon/defaultfeatures/" );
42     $token = get_form_security_token("defaultfeaturessave");
43     $arr = array();
44     $features = get_features();
45     foreach($features as $fname => $fdata) {
46             $arr[$fname] = array();
47             $arr[$fname][0] = $fdata[0];
48             foreach(array_slice($fdata,1) as $f) {
49                     $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0"),$f[2],array(t('Off'),t('On')));
50             }
51     }
52
53     //logger("Features: " . print_r($arr,true));
54
55     $o = replace_macros($t, array(
56         '$submit' => t('Save Settings'),
57         '$features' => $arr,
58         '$form_security_token' => $token
59     ));
60 }