1<?php 2/** 3 * DokuWiki Plugin sfauth (Action Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Dominik Eckelmann, Andreas Gohr 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if(!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 15 16require_once DOKU_PLUGIN . 'action.php'; 17 18class action_plugin_sfauth extends DokuWiki_Action_Plugin { 19 20 public function register(Doku_Event_Handler $controller) { 21 $controller->register_hook('HTML_LOGINFORM_OUTPUT', 'AFTER', $this, 'handle_html_loginform_output'); 22 $controller->register_hook('AUTH_LOGIN_CHECK', 'AFTER', $this, 'handle_login'); 23 } 24 25 public function handle_html_loginform_output(Doku_Event &$event, $param) { 26 global $auth; 27 if(!($auth instanceof auth_plugin_sfauth)) { 28 return; 29 } 30 31 $this->displayLogin(); 32 } 33 34 /** 35 * Displays the Salesforce Login Button 36 * 37 * Note: We always use the main instance to start the oauth workflow because it doesn't matter. Salesforce 38 * will use the redirect URI configured in the instance of the user that logged in and that will contain the 39 * correct instance number for all subsequent API calls. this way we only need one login button 40 */ 41 protected function displayLogin() { 42 global $ID; 43 echo '<div class="sfauth">'; 44 if($this->getConf('consumer key')) { 45 echo '<a href="'.wl($ID, array('do' => 'login', 'u' => 'sf', 'p' => 'sf', 'sf' => '1')).'" class="sf">'; 46 echo $this->getLang('login'); 47 echo '</a> '; 48 } 49 echo '</div>'; 50 } 51 52 /** 53 * Redirect to the page that initially started the auth process 54 * 55 * @param Doku_Event $event 56 * @param $param 57 */ 58 public function handle_login(Doku_Event &$event, $param) { 59 if($_SERVER['REMOTE_USER'] && isset($_SESSION['sfauth_id'])) { 60 $id = $_SESSION['sfauth_id']; 61 unset($_SESSION['sfauth_id']); 62 send_redirect(wl($id, '', true, '&')); 63 } 64 } 65} 66 67// vim:ts=4:sw=4:et: 68