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
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>
10 *"My body was my sacrifice... for my magic. This damage is permanent." - Raistlin Majere
14 use Friendica\Core\Hook;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Renderer;
19 function krynn_install()
22 * Our demo addon will attach in three places.
23 * The first is just prior to storing a local post.
25 Hook::register('post_local', 'addon/krynn/krynn.php', 'krynn_post_hook');
28 * Then we'll attach into the addon settings page, and also the
29 * settings post hook so that we can create and update
32 Hook::register('addon_settings', 'addon/krynn/krynn.php', 'krynn_settings');
33 Hook::register('addon_settings_post', 'addon/krynn/krynn.php', 'krynn_settings_post');
35 Logger::notice("installed krynn");
38 function krynn_post_hook(&$item)
41 * An item was posted on the local system.
42 * We are going to look for specific items:
43 * - A status post by a profile owner
44 * - The profile owner must have allowed our addon
46 if (!DI::userSession()->getLocalUserId()) {
47 /* non-zero if this is a logged in user of this system */
51 if (DI::userSession()->getLocalUserId() != $item['uid']) {
52 /* Does this person own the post? */
56 if ($item['parent']) {
57 /* If the item has a parent, this is a comment or something else, not a status post. */
61 /* Retrieve our personal config setting */
62 $active = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'krynn', 'enable');
70 * OK, we're allowed to do our stuff.
71 * Here's what we are going to do:
72 * load the list of timezone names, and use that to generate a list of krynn locales.
73 * Then we'll pick one of those at random and put it in the "location" field for the post.
77 $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'];
79 $planet = array_rand($krynn,1);
80 $item['location'] = $krynn[$planet];
86 * Callback from the settings post function.
87 * $post contains the $_POST array.
88 * We will make sure we've got a valid user account
89 * and if so set our configuration setting for this person.
91 function krynn_settings_post($post)
93 if (!DI::userSession()->getLocalUserId()) {
97 if ($_POST['krynn-submit']) {
98 DI::pConfig()->set(DI::userSession()->getLocalUserId(),'krynn','enable',intval($_POST['krynn']));
103 * Called from the addon Setting form.
104 * Add our own settings info to the page.
106 function krynn_settings(array &$data)
108 if (!DI::userSession()->getLocalUserId()) {
112 $enabled = DI::pConfig()->get(DI::userSession()->getLocalUserId(),'krynn','enable');
114 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/krynn/');
115 $html = Renderer::replaceMacros($t, [
116 '$enabled' => ['krynn', DI::l10n()->t('Enable Krynn Addon'), $enabled],
121 'title' => DI::l10n()->t('Krynn Settings'),