1<?php 2/** 3 * unsplashdoku action plugin: set background using Unsplash Source https://source.unsplash.com 4 * 5 * @author Milosz Galazka <milosz@sleeplessbeastie.eu> 6 */ 7 8if(!defined('DOKU_INC')) die(); 9 10 11class action_plugin_unsplashdoku extends DokuWiki_Action_Plugin { 12 13 /** 14 * Register its handlers with the DokuWiki's event controller 15 */ 16 public function register(Doku_Event_Handler $controller) { 17 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_addcss'); 18 } 19 20 /** 21 * Inject CSS into page 22 */ 23 public function _addcss(Doku_Event $event, $param) { 24 $enabled = $this->getConf('enabled'); 25 26 if ($enabled == 1) { 27 $selection = $this->getConf('selection'); 28 if ( !empty($this->getConf('keyword'))) { 29 $keyword = '?' . $this->getConf('keyword'); 30 } else { 31 $keyword = ''; 32 } 33 34 $background_image = 'background-image: ' . 'url(https://source.unsplash.com/' . $selection . '/' . $keyword . ');'; 35 36 if ( !empty($this->getConf('background_color'))) { 37 $background_color = 'background-color: ' . $this->getConf('background_color') . ' !important;'; 38 } else { 39 $background_color = ''; 40 } 41 42 if ( !empty($this->getConf('background_blend'))) { 43 $background_blend = 'background-blend-mode: ' . $this->getConf('background_blend') . ';'; 44 } else { 45 $background_blend = ''; 46 } 47 48 $html_style = 'html { height: 100%; }'; 49 50 $body_style = 'body { ' . 'min-height: 100%; ' . $background_image . ' background-size: cover; ' . $background_color . ' ' . $background_blend . ' }'; 51 $event->data['style'][] = array('type' => 'text/css', '_data' => $html_style . ' ' . $body_style); 52 } 53 } 54} 55