1<?php
2/**
3 * Dokuwiki Action Plugin: Show Login Page on "Access Denied"
4 *
5 * @author Oliver Geisen <oliver.geisen@kreisbote.de>
6 * @author Klaus Vormweg <klaus.vormweg@gmx.de>
7 */
8
9if(!defined('DOKU_INC')) die();
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'action.php');
12
13class action_plugin_showlogin2 extends DokuWiki_Action_Plugin {
14
15  /**
16   * return some info
17   */
18  function getInfo(){
19    return array(
20      'author' => 'Klaus Vormweg',
21      'email'  => 'klaus.vormweg@gmx.de',
22      'date'   => '2014-02-23',
23      'name'   => 'Show Login 2',
24      'desc'   => 'If access to page is denied, show login form to users not already logged in.',
25      'url'    => 'http://www.tuhh.de/~psvkv/dokuwiki/showlogin2.tar.gz',
26    );
27  }
28
29  /**
30   * Register its handlers with the dokuwiki's event controller
31   */
32  function register(Doku_Event_Handler $controller) {
33    # TPL_CONTENT_DISPLAY is called before and after content of wikipage
34    # is written to output buffer
35    if(!$this->getConf('show_denied')) {
36      $controller->register_hook(
37        'TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'showlogin2'
38      );
39    } else {
40      $controller->register_hook(
41        'TPL_CONTENT_DISPLAY', 'AFTER', $this, 'showlogin2'
42      );
43    }
44  }
45
46  /**
47   * Handle the event
48   */
49  function showlogin2(&$event, $param) {
50    global $ACT;
51    global $ID;
52
53    # add login form to page, only on access denied
54    # and if user is not logged in
55    if (($ACT == 'denied') && (! $_SERVER['REMOTE_USER'])) {
56      if(!$this->getConf('show_denied')) {
57        $event->preventDefault();
58      }
59      html_login();
60    }
61  }
62}
63
64