]> git.mxchange.org Git - friendica-addons.git/blob - fortunate/fortunate.php
Review updates
[friendica-addons.git] / fortunate / fortunate.php
1 <?php
2 /**
3  * Name: Fortunate
4  * Description: Add a random fortune cookie at the bottom of every pages. [Requires manual confguration.]
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  */
8 use Friendica\Core\Addon;
9 use Friendica\Util\Network;
10
11 // IMPORTANT: SET THIS to your fortunate server
12
13 define('FORTUNATE_SERVER', 'hostname.com');
14
15 function fortunate_install()
16 {
17         Addon::registerHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
18         if (FORTUNATE_SERVER == 'hostname.com' && is_site_admin()) {
19                 notice('Fortunate addon requires configuration. See README');
20         }
21 }
22
23 function fortunate_uninstall()
24 {
25         Addon::unregisterHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
26 }
27
28
29 function fortunate_fetch(&$a, &$b)
30 {
31         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' 
32                 . $a->get_baseurl() . '/addon/fortunate/fortunate.css' . '" media="all" />' . "\r\n";
33
34         if (FORTUNATE_SERVER != 'hostname.com') {
35                 $s = Network::fetchUrl('http://' . FORTUNATE_SERVER . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand());
36                 $b .= '<div class="fortunate">' . $s . '</div>';
37         }
38 }