UserPage

Last update: 2007-07-15

When a user registers with the wiki, this plugin will add their name to a given page.

Source code

Copyright (C) 2007 Tom N Harris This plugin is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

action.php
<?php
/**
 * Create a page with the names of registered users.
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @author     Tom N Harris <tnharris [at] whoopdedo.org>
 */
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
/**
 * All DokuWiki plugins to extend the actions
 * need to inherit from this class
 */
class action_plugin_userpage extends DokuWiki_Action_Plugin {
 
    var $first_act = '';
 
    /**
     * return some info
     */
    function getInfo(){
      return array(
        'author' => 'Tom N Harris',
        'email'  => 'tnharris [at] whoopdedo.org',
        'date'   => 'Fri, 15 Jul 2007',
        'name'   => 'UserPage Plugin',
        'desc'   => 'Create a page with the names of registered users.',
        'url'    => 'http://whoopdedo.org/doku/wiki/userpage',
      );
    }
 
    function register(&$controller) {
      $controller->register_hook('ACTION_ACT_PREPROCESS','BEFORE', $this, 'preprocess_event', NULL);
      $controller->register_hook('ACTION_ACT_PREPROCESS','AFTER', $this, 'postprocess_event', NULL);
    }
 
    /**
     * handle user request
     */
    function preprocess_event(&$event, $param) {
      $this->first_act = $event->data;
    }
    function postprocess_event(&$event, $param) {
      require_once(DOKU_INC.'inc/common.php');
      require_once(DOKU_INC.'inc/pageutils.php');
      global $conf;
      if ($this->first_act == 'register' && $event->data == 'login') {
        $id = $this->getConf('id');
        $ns = getNS($id);
        if(!$ns) $ns = $id;
        $user_id = $this->getConf('userid');
        if (empty($user_id)) {
          $user_id = $ns.':'.$_POST['login'];
          $user_ns = $ns;
        } else {
          $user_id = str_replace('@USER@',$_POST['login'],$user_id);
          $user_ns = getNS($user_id);
        }
        $user_id = cleanID($user_id);
        if ($this->getConf('userns')){
          $user_ns = $user_id;
          $user_id = $user_ns.':'.$conf['start'];
        }
        $tpl_found = false;
        if (!@file_exists(wikiFN($user_id)) && $this->getConf('createpage')) {
          $user_tpl = dirname(wikiFN($user_id)).'/_template.txt';
          $tpl_found = @file_exists($user_tpl);
          if (!$tpl_found){
            $user_tpl = dirname(wikiFN($id)).'/_userpage.txt';
            $tpl_found = @file_exists($user_tpl);
            if (!$tpl_found){
              $user_tpl = dirname(wikiFN($id)).'/_template.txt';
              $tpl_found = @file_exists($user_tpl);
            }
          }
          if ($tpl_found) {
            $user_tpl = io_readFile($user_tpl);
            $user_tpl = str_replace('@ID@',$user_id,$user_tpl);
            $user_tpl = str_replace('@NS@',$user_ns,$user_tpl);
            $user_tpl = str_replace('@PAGE@',noNS($user_id),$user_tpl);
            $user_tpl = str_replace('@USER@',$_POST['login'],$user_tpl);
            $user_tpl = str_replace('@NAME@',str_replace('%','%%',$_POST['fullname']),$user_tpl);
            $user_tpl = str_replace('@MAIL@',str_replace('%','%%',$_POST['email']),$user_tpl);
            $user_tpl = str_replace('@DATE@',$conf['dformat'],$user_tpl);
            // we need the callback to work around strftime's char limit
            $user_tpl = preg_replace_callback('/%./',create_function('$m','return strftime($m[0]);'),$user_tpl);
            saveWikiText($user_id, $user_tpl, 'UserPage Plugin', true);
          }
        }
        $tpl = $this->getConf('template');
        $tr = array('\\n'=>"\n", '\\t'=>"\t", '\\\''=>"'", '\\\\'=>"\\");
        $tpl = strtr($tpl, $tr);
        $text = rawWiki($id);
        $tpl = str_replace('@ID@',$user_id,$tpl);
        $tpl = str_replace('@USER@',$_POST['login'],$tpl);
        $tpl = str_replace('@NAME@',$_POST['fullname'],$tpl);
        $tpl = str_replace('@EMAIL@',$_POST['email'],$tpl);
        $text .= $tpl;
        saveWikiText($id, $text, 'UserPage Plugin', true);
      }
    }
 
}