]> git.mxchange.org Git - friendica-addons.git/blob - krynn/krynn.php
b45496463f808255431d97daf7bb47ca39422071
[friendica-addons.git] / krynn / krynn.php
1 <?php
2 /**
3  * Name: Dragonlance Krynn locales
4  * Description: Set a random locale from the Dragonlance Realm of Krynn when posting. Based on the planets friendica 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  * Author: Dylan Thiedeke <https://theronin.net/profile/swathe>
9  *
10  *"My body was my sacrifice... for my magic. This damage is permanent." - Raistlin Majere
11  */
12
13 use Friendica\App;
14 use Friendica\Core\Hook;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Renderer;
17 use Friendica\DI;
18
19 function krynn_install() {
20
21         /**
22          *
23          * Our demo addon will attach in three places.
24          * The first is just prior to storing a local post.
25          *
26          */
27
28         Hook::register('post_local', 'addon/krynn/krynn.php', 'krynn_post_hook');
29
30         /**
31          *
32          * Then we'll attach into the addon settings page, and also the
33          * settings post hook so that we can create and update
34          * user preferences.
35          *
36          */
37
38         Hook::register('addon_settings', 'addon/krynn/krynn.php', 'krynn_settings');
39         Hook::register('addon_settings_post', 'addon/krynn/krynn.php', 'krynn_settings_post');
40
41         Logger::notice("installed krynn");
42 }
43
44 function krynn_post_hook(App $a, &$item) {
45
46         /**
47          *
48          * An item was posted on the local system.
49          * We are going to look for specific items:
50          *      - A status post by a profile owner
51          *      - The profile owner must have allowed our addon
52          *
53          */
54
55         if(! local_user())   /* non-zero if this is a logged in user of this system */
56                 return;
57
58         if(local_user() != $item['uid'])    /* Does this person own the post? */
59                 return;
60
61         if($item['parent'])   /* If the item has a parent, this is a comment or something else, not a status post. */
62                 return;
63
64         /* Retrieve our personal config setting */
65
66         $active = DI::pConfig()->get(local_user(), 'krynn', 'enable');
67
68         if(! $active)
69                 return;
70
71         /**
72          *
73          * OK, we're allowed to do our stuff.
74          * Here's what we are going to do:
75          * load the list of timezone names, and use that to generate a list of krynn locales.
76          * Then we'll pick one of those at random and put it in the "location" field for the post.
77          *
78          */
79
80         $krynn = ['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','Saifhum','Karthay','Mithas','Kothas','Silver Dragon Mountain','Silvanesti'];
81
82         $planet = array_rand($krynn,1);
83         $item['location'] = $krynn[$planet];
84
85         return;
86 }
87
88
89
90
91 /**
92  *
93  * Callback from the settings post function.
94  * $post contains the $_POST array.
95  * We will make sure we've got a valid user account
96  * and if so set our configuration setting for this person.
97  *
98  */
99
100 function krynn_settings_post(App $a, $post) {
101         if(! local_user())
102                 return;
103         if($_POST['krynn-submit'])
104                 DI::pConfig()->set(local_user(),'krynn','enable',intval($_POST['krynn']));
105 }
106
107
108 /**
109  *
110  * Called from the addon Setting form.
111  * Add our own settings info to the page.
112  *
113  */
114
115
116
117 function krynn_settings(App &$a, array &$data)
118 {
119         if(! local_user()) {
120                 return;
121         }
122
123         $enabled = DI::pConfig()->get(local_user(),'krynn','enable');
124
125         $t    = Renderer::getMarkupTemplate('settings.tpl', 'addon/krynn/');
126         $html = Renderer::replaceMacros($t, [
127                 '$enabled' => ['krynn', DI::l10n()->t('Enable Krynn Addon'), $enabled],
128         ]);
129
130         $data = [
131                 'addon' => 'krynn',
132                 'title' => DI::l10n()->t('Krynn Settings'),
133                 'html'  => $html,
134         ];
135 }
136
137