Fixed Language files to reflect plugin name
[friendica-addons.git] / krynn / krynn.php
1 <?php
2 /**
3  * Name: Dragonlace Krynn locales
4  * Description: Sample Friendica plugin/addon. Set a random locale from the Dragonlance Realm of Krynn when posting. Based on the krynn frindica addon by Mike Macgirvin and Tony Baldwin
5  * Version: 1.0
6  * Planets Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * Planets Author: Tony Baldwin <https://free-haven.org/profile/tony>
8  * Krynn modifications: Dylan Thiedeke
9  *
10  *"My body was my sacrifice... for my magic. This damage is permanent." - Raistlin Majere
11  */
12
13
14 function krynn_install() {
15
16         /**
17          * 
18          * Our demo plugin will attach in three places.
19          * The first is just prior to storing a local post.
20          *
21          */
22
23         register_hook('post_local', 'addon/krynn/krynn.php', 'krynn_post_hook');
24
25         /**
26          *
27          * Then we'll attach into the plugin settings page, and also the 
28          * settings post hook so that we can create and update
29          * user preferences.
30          *
31          */
32
33         register_hook('plugin_settings', 'addon/krynn/krynn.php', 'krynn_settings');
34         register_hook('plugin_settings_post', 'addon/krynn/krynn.php', 'krynn_settings_post');
35
36         logger("installed krynn");
37 }
38
39
40 function krynn_uninstall() {
41
42         /**
43          *
44          * uninstall unregisters any hooks created with register_hook
45          * during install. It may also delete configuration settings
46          * and any other cleanup.
47          *
48          */
49
50         unregister_hook('post_local',    'addon/krynn/krynn.php', 'krynn_post_hook');
51         unregister_hook('plugin_settings', 'addon/krynn/krynn.php', 'krynn_settings');
52         unregister_hook('plugin_settings_post', 'addon/krynn/krynn.php', 'krynn_settings_post');
53
54
55         logger("removed krynn");
56 }
57
58
59
60 function krynn_post_hook($a, &$item) {
61
62         /**
63          *
64          * An item was posted on the local system.
65          * We are going to look for specific items:
66          *      - A status post by a profile owner
67          *      - The profile owner must have allowed our plugin
68          *
69          */
70
71         logger('krynn invoked');
72
73         if(! local_user())   /* non-zero if this is a logged in user of this system */
74                 return;
75
76         if(local_user() != $item['uid'])    /* Does this person own the post? */
77                 return;
78
79         if($item['parent'])   /* If the item has a parent, this is a comment or something else, not a status post. */
80                 return;
81
82         /* Retrieve our personal config setting */
83
84         $active = get_pconfig(local_user(), 'krynn', 'enable');
85
86         if(! $active)
87                 return;
88
89         /**
90          *
91          * OK, we're allowed to do our stuff.
92          * Here's what we are going to do:
93          * load the list of timezone names, and use that to generate a list of krynn locales.
94          * Then we'll pick one of those at random and put it in the "location" field for the post.
95          *
96          */
97
98         $krynn = array('Ansalon','Abanasinia','Solace','Haven','Gateway','Qualinost','Ankatavaka','Pax Tharkas','Ergoth','Newsea','Straights of Schallsea','Plains of Dust','Tarsis','Barren Hills','Que Shu','Citadel of Light','Solinari','Hedge Maze','Tower of High Sorcery','Inn of the Last Home','Last Heroes Tomb','Academy of Sorcery','Gods Row','Temple of Majere','Temple of Kiri-Jolith','Temple of Mishakal','Temple of Zeboim,','The Trough','Sad Town','Xak Tsaroth','ZHaman','SKullcap',);
99
100         $planet = array_rand($krynn,1);
101         $item['location'] = $krynn[$planet];
102
103         return;
104 }
105
106
107
108
109 /**
110  *
111  * Callback from the settings post function.
112  * $post contains the $_POST array.
113  * We will make sure we've got a valid user account
114  * and if so set our configuration setting for this person.
115  *
116  */
117
118 function krynn_settings_post($a,$post) {
119         if(! local_user())
120                 return;
121         if($_POST['krynn-submit'])
122                 set_pconfig(local_user(),'krynn','enable',intval($_POST['krynn']));
123 }
124
125
126 /**
127  *
128  * Called from the Plugin Setting form. 
129  * Add our own settings info to the page.
130  *
131  */
132
133
134
135 function krynn_settings(&$a,&$s) {
136
137         if(! local_user())
138                 return;
139
140         /* Add our stylesheet to the page so we can make our settings look nice */
141
142         $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/krynn/krynn.css' . '" media="all" />' . "\r\n";
143
144         /* Get the current state of our config variable */
145
146         $enabled = get_pconfig(local_user(),'krynn','enable');
147
148         $checked = (($enabled) ? ' checked="checked" ' : '');
149
150         /* Add some HTML to the existing form */
151
152         $s .= '<div class="settings-block">';
153         $s .= '<h3>' . t('Krynn Settings') . '</h3>';
154         $s .= '<div id="krynn-enable-wrapper">';
155         $s .= '<label id="krynn-enable-label" for="krynn-checkbox">' . t('Enable Krynn Plugin') . '</label>';
156         $s .= '<input id="krynn-checkbox" type="checkbox" name="krynn" value="1" ' . $checked . '/>';
157         $s .= '</div><div class="clear"></div>';
158
159         /* provide a submit button */
160
161         $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="krynn-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';
162
163 }
164
165