]> git.mxchange.org Git - friendica-addons.git/blob - defaultfeatures/defaultfeatures.php
Merge remote-tracking branch 'upstream/master'
[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  */
8
9 function defaultfeatures_install() {
10     register_hook('register_account', 'addon/defaultfeatures/defaultfeatures.php', 'defaultfeatures_register');
11     logger("installed defaultfeatures plugin");
12 }
13
14 function defaultfeatures_uninstall() {
15     unregister_hook('register_account', 'addon/defaultfeatures/defaultfeatures.php', 'defaultfeatures_register');
16     logger("uninstalled defaultfeatures plugin");
17 }
18
19 function defaultfeatures_register($a, $newuid) {
20     $arr = array();
21     $features = get_features();
22     foreach($features as $fname => $fdata) {
23             foreach(array_slice($fdata,1) as $f) {
24                     set_pconfig($newuid,'feature',$f[0],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0"));
25             }
26     }
27 }
28
29 function defaultfeatures_plugin_admin_post (&$a) {
30     check_form_security_token_redirectOnErr('/admin/plugins/defaultfeatures', 'defaultfeaturessave');
31     foreach($_POST as $k => $v) {
32             if(strpos($k,'feature_') === 0) {
33                     set_config('defaultfeatures',substr($k,8),((intval($v)) ? 1 : 0));
34             }
35     }
36     info( t('Features updated') . EOL);
37 }
38
39 function defaultfeatures_plugin_admin (&$a, &$o) {
40     $t = get_markup_template( "admin.tpl", "addon/defaultfeatures/" );
41     $token = get_form_security_token("defaultfeaturessave");
42     $arr = array();
43     $features = get_features();
44     foreach($features as $fname => $fdata) {
45             $arr[$fname] = array();
46             $arr[$fname][0] = $fdata[0];
47             foreach(array_slice($fdata,1) as $f) {
48                     $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(get_config('defaultfeatures',$f[0]))) ? "1" : "0"),$f[2],array(t('Off'),t('On')));
49             }
50     }
51
52     //logger("Features: " . print_r($arr,true));
53
54     $o = replace_macros($t, array(
55         '$submit' => t('Save Settings'),
56         '$features' => $arr,
57         '$form_security_token' => $token
58     ));
59 }