3 * Name: Dragonlance Krynn locales
4 * Description: Set a random locale from the Dragonlance Realm of Krynn when posting. Based on the planets frindica 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 function krynn_install() {
18 * Our demo plugin will attach in three places.
19 * The first is just prior to storing a local post.
23 register_hook('post_local', 'addon/krynn/krynn.php', 'krynn_post_hook');
27 * Then we'll attach into the plugin settings page, and also the
28 * settings post hook so that we can create and update
33 register_hook('plugin_settings', 'addon/krynn/krynn.php', 'krynn_settings');
34 register_hook('plugin_settings_post', 'addon/krynn/krynn.php', 'krynn_settings_post');
36 logger("installed krynn");
40 function krynn_uninstall() {
44 * uninstall unregisters any hooks created with register_hook
45 * during install. It may also delete configuration settings
46 * and any other cleanup.
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');
55 logger("removed krynn");
60 function krynn_post_hook($a, &$item) {
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
71 logger('krynn invoked');
73 if(! local_user()) /* non-zero if this is a logged in user of this system */
76 if(local_user() != $item['uid']) /* Does this person own the post? */
79 if($item['parent']) /* If the item has a parent, this is a comment or something else, not a status post. */
82 /* Retrieve our personal config setting */
84 $active = get_pconfig(local_user(), 'krynn', 'enable');
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.
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','Saifhum','Karthay','Mithas','Kothas','Silver Dragon Mountain','Silvanesti');
100 $planet = array_rand($krynn,1);
101 $item['location'] = $krynn[$planet];
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.
118 function krynn_settings_post($a,$post) {
121 if($_POST['krynn-submit'])
122 set_pconfig(local_user(),'krynn','enable',intval($_POST['krynn']));
128 * Called from the Plugin Setting form.
129 * Add our own settings info to the page.
135 function krynn_settings(&$a,&$s) {
140 /* Add our stylesheet to the page so we can make our settings look nice */
142 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/krynn/krynn.css' . '" media="all" />' . "\r\n";
144 /* Get the current state of our config variable */
146 $enabled = get_pconfig(local_user(),'krynn','enable');
148 $checked = (($enabled) ? ' checked="checked" ' : '');
150 /* Add some HTML to the existing form */
152 $s .= '<span id="settings_krynn_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_krynn_expanded\'); openClose(\'settings_krynn_inflated\');">';
153 $s .= '<h3>' . t('Krynn') . '</h3>';
155 $s .= '<div id="settings_krynn_expanded" class="settings-block" style="display: none;">';
156 $s .= '<span class="fakelink" onclick="openClose(\'settings_krynn_expanded\'); openClose(\'settings_krynn_inflated\');">';
157 $s .= '<h3>' . t('Krynn') . '</h3>';
161 $s .= '<div class="settings-block">';
162 $s .= '<h3>' . t('Krynn Settings') . '</h3>';
163 $s .= '<div id="krynn-enable-wrapper">';
164 $s .= '<label id="krynn-enable-label" for="krynn-checkbox">' . t('Enable Krynn Plugin') . '</label>';
165 $s .= '<input id="krynn-checkbox" type="checkbox" name="krynn" value="1" ' . $checked . '/>';
166 $s .= '</div><div class="clear"></div></div>';
167 /* provide a submit button */
169 $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="krynn-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div></div>';