Mailstream: remove URL parameters when extracting image filenames
[friendica-addons.git/.git] / pageheader / pageheader.php
1 <?php
2 /**
3  * Name: Page Header
4  * Description: Inserts a page header
5  * Version: 1.1
6  * Author: Keith Fernie <http://friendika.me4.it/profile/keith>
7  *         Hauke Altmann <https://snarl.de/profile/tugelblend>
8  * 
9  */
10
11 use Friendica\App;
12 use Friendica\Core\Config;
13 use Friendica\Core\Hook;
14 use Friendica\Core\L10n;
15 use Friendica\Core\Renderer;
16
17 function pageheader_install() {
18     Hook::register('page_content_top', __FILE__, 'pageheader_fetch');
19 }
20
21 function pageheader_addon_admin(App &$a, &$s)
22 {
23         if(! is_site_admin()) {
24                 return;
25         }
26
27     /* Add our stylesheet to the page so we can make our settings look nice */
28         $stylesheetPath = __DIR__ . '/pageheader.css';
29         $a->registerStylesheet($stylesheetPath);
30
31         $words = Config::get('pageheader','text');
32         if(! $words)
33                 $words = '';
34
35         $t = Renderer::getMarkupTemplate('admin.tpl', __DIR__);
36         $s .= Renderer::replaceMacros($t, [
37                 '$title' => L10n::t('"pageheader" Settings'),
38                 '$phwords' => ['pageheader-words', L10n::t('Message'), $words, L10n::t('Message to display on every page on this server (or put a pageheader.html file in your docroot)')],
39                 '$submit' => L10n::t('Save Settings')
40         ]);
41
42         return;
43 }
44
45 function pageheader_addon_admin_post(App $a)
46 {
47         if(!is_site_admin()) {
48                 return;
49         }
50
51         if(!empty($_POST['pageheader-submit'])) {
52                 if (isset($_POST['pageheader-words'])) {
53                         Config::set('pageheader', 'text', trim(strip_tags($_POST['pageheader-words'])));
54                 }
55                 info(L10n::t('pageheader Settings saved.'));
56         }
57 }
58
59 function pageheader_fetch(App $a, &$b)
60 {
61         if(file_exists('pageheader.html')){
62                 $s = file_get_contents('pageheader.html');
63         } else {
64                 $s = Config::get('pageheader', 'text');
65         }
66
67         $stylesheetPath = __DIR__ .'/pageheader.css';
68         $a->registerStylesheet($stylesheetPath);
69     
70     if ($s) {
71         $b .= '<div class="pageheader">' . $s . '</div>';
72     }
73 }