]> git.mxchange.org Git - friendica-addons.git/blob - fortunate/fortunate.php
Addon class
[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
10 // IMPORTANT: SET THIS to your fortunate server
11
12 define ('FORTUNATE_SERVER', 'hostname.com');
13
14 function fortunate_install() {
15         Addon::registerHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
16         if(FORTUNATE_SERVER == 'hostname.com' && is_site_admin()) {
17                 notice('Fortunate plugin requires configuration. See README');
18         }
19 }
20
21 function fortunate_uninstall() {
22         Addon::unregisterHook('page_end', 'addon/fortunate/fortunate.php', 'fortunate_fetch');
23 }
24
25
26 function fortunate_fetch(&$a,&$b) {
27
28         $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' 
29                 . $a->get_baseurl() . '/addon/fortunate/fortunate.css' . '" media="all" />' . "\r\n";
30
31         if(FORTUNATE_SERVER != 'hostname.com') {
32                 $s = fetch_url('http://' . FORTUNATE_SERVER . '/cookie.php?numlines=2&equal=1&rand=' . mt_rand());
33                 $b .= '<div class="fortunate">' . $s . '</div>';
34         }
35 }
36