*/ if (!defined('DOKU_INC')) { die(); } /** * Action class for authphpbb3 plugin. */ class action_plugin_authphpbb3 extends DokuWiki_Action_Plugin { /** * Registers a callback function for a given event. * * @param Doku_Event_Handler $controller. */ public function register(Doku_Event_Handler $controller) { $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'BEFORE', $this, 'handle_login_form'); $controller->register_hook('COMMON_USER_LINK', 'AFTER', $this, 'handle_user_link'); } /** * Replaces the DokuWiki form by the phpBB login form. * * @param Doku_Event $event Event. * @param object $param Parameters. */ public function handle_login_form(&$event, $param) { global $auth; global $ID; $use_inline_css = $this->getConf('phpbb_inline_style'); $inline_css1 = ''; $inline_css2 = ''; $phpbb_url = ''; $cache = null; $elem = ''; $pos = 0; if (!is_a($auth, 'auth_plugin_authphpbb3')) { return; } $phpbb_url = $auth->get_phpbb_url(); if ($phpbb_url === false) { return ; } $phpbb_url = rtrim($phpbb_url, '/'); // Form's PHP script. $event->data->params['action'] = $phpbb_url . '/ucp.php?mode=login'; // Username field. $inline_css1 = ($use_inline_css ? ' style="padding-right:10px"' : ''); $elem = '
'; $pos = $event->data->findElementByAttribute('name', 'u'); if ($pos === false) { return ; } $event->data->replaceElement($pos, null); $event->data->insertElement($pos, $elem); // Password field. $inline_css1 = ($use_inline_css ? ' style="padding-right:10px"' : ''); $elem = '
'; $pos = $event->data->findElementByAttribute('name', 'p'); if ($pos === false) { return ; } $event->data->replaceElement($pos, null); $event->data->insertElement($pos, $elem); // Remember me check box. $inline_css1 = ($use_inline_css ? ' style="margin-left:20%;margin-bottom:10px;"' : ''); $inline_css2 = ($use_inline_css ? ' style="padding-left:5px"' : ''); $elem = ''; $pos = $event->data->findElementByAttribute('name', 'r'); if ($pos === false) { return ; } $event->data->replaceElement($pos, null); $event->data->insertElement($pos, $elem); // View online check box. $inline_css1 = ($use_inline_css ? ' style="margin-left:20%;margin-bottom:10px;"' : ''); $inline_css2 = ($use_inline_css ? ' style="padding-left:5px"' : ''); $elem = ''; $event->data->insertElement($pos + 1, $elem); // Log in button. $elem = ''; $pos = $event->data->findElementByType('button'); if ($pos === false) { return ; } $event->data->replaceElement($pos, null); $event->data->insertElement($pos, $elem); // Hidden field for redirection. $elem = ''; $event->data->insertElement($pos - 1, $elem); // Forum URL. $event->data->addElement('

' . sprintf($this->getLang('login_bottom_text'), $phpbb_url) . '

'); } /** * Adds a link to phpBB profile on all users' names. * * @param Doku_Event $event Event. * @param object $param Parameters. */ public function handle_user_link(&$event, $param) { global $auth, $conf; $profile = '%s'; if (!is_a($auth, 'auth_plugin_authphpbb3')) { return; } if (($conf['showuseras'] !== 'username_link') || $event->data['textonly']) { return ; } if (empty($event->data['name'])) { $event->data['name'] = $event->data['username']; } $data = $auth->getUserData($event->data['username']); if (is_array($data) && array_key_exists('phpbb_profile', $data) && array_key_exists('name', $data) && !empty($data['phpbb_profile']) && !empty($data['name'])) { $profile = sprintf($profile, $data['phpbb_profile'], $data['name']); } else { $profile = sprintf($profile, '#', $event->data['name']); } $event->data = array( 'username' => $event->data['username'], 'name' => $event->data['name'], 'link' => $event->data['link'], 'userlink' => $profile, 'textonly' => $event->data['textonly'] ); } }