1*346619c6SAndreas Gohr<?php 2*346619c6SAndreas Gohr/** 3*346619c6SAndreas Gohr * DokuWiki Plugin quicksubscribe (Action Component) 4*346619c6SAndreas Gohr * 5*346619c6SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6*346619c6SAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 7*346619c6SAndreas Gohr */ 8*346619c6SAndreas Gohr 9*346619c6SAndreas Gohr// must be run within Dokuwiki 10*346619c6SAndreas Gohrif(!defined('DOKU_INC')) die(); 11*346619c6SAndreas Gohr 12*346619c6SAndreas Gohrclass action_plugin_quicksubscribe extends DokuWiki_Action_Plugin { 13*346619c6SAndreas Gohr 14*346619c6SAndreas Gohr function register(&$controller) { 15*346619c6SAndreas Gohr $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown'); 16*346619c6SAndreas Gohr } 17*346619c6SAndreas Gohr 18*346619c6SAndreas Gohr function handle_ajax_call_unknown(&$event, $param) { 19*346619c6SAndreas Gohr if($event->data != 'plugin_quicksubscribe') return; 20*346619c6SAndreas Gohr $event->preventDefault(); 21*346619c6SAndreas Gohr $event->stopPropagation(); 22*346619c6SAndreas Gohr 23*346619c6SAndreas Gohr global $INPUT; 24*346619c6SAndreas Gohr 25*346619c6SAndreas Gohr $ns = cleanID($INPUT->str('ns')) . ':'; // we only handle namespaces 26*346619c6SAndreas Gohr $do = $INPUT->str('do'); 27*346619c6SAndreas Gohr 28*346619c6SAndreas Gohr $ok = false; 29*346619c6SAndreas Gohr $msg = ''; 30*346619c6SAndreas Gohr 31*346619c6SAndreas Gohr $sub = new Subscription(); 32*346619c6SAndreas Gohr 33*346619c6SAndreas Gohr if($do == 'subscribe') { 34*346619c6SAndreas Gohr // new subscriptions 35*346619c6SAndreas Gohr $ok = $sub->add($ns, $_SERVER['REMOTE_USER'], 'list'); 36*346619c6SAndreas Gohr if($ok) { 37*346619c6SAndreas Gohr $msg = sprintf($this->getLang('sub_succ'), $this->prettyid($ns)); 38*346619c6SAndreas Gohr } else { 39*346619c6SAndreas Gohr $msg = sprintf($this->getLang('sub_fail'), $this->prettyid($ns)); 40*346619c6SAndreas Gohr } 41*346619c6SAndreas Gohr } elseif($do == 'unsubscribe') { 42*346619c6SAndreas Gohr // subscription removal 43*346619c6SAndreas Gohr $ok = $sub->remove($ns, $_SERVER['REMOTE_USER']); 44*346619c6SAndreas Gohr if($ok) { 45*346619c6SAndreas Gohr $msg = sprintf($this->getLang('unsub_succ'), $this->prettyid($ns)); 46*346619c6SAndreas Gohr } else { 47*346619c6SAndreas Gohr $msg = sprintf($this->getLang('unsub_fail'), $this->prettyid($ns)); 48*346619c6SAndreas Gohr } 49*346619c6SAndreas Gohr } 50*346619c6SAndreas Gohr 51*346619c6SAndreas Gohr if(!$ok) http_status(400); 52*346619c6SAndreas Gohr echo '<p>' . $msg . '</p>'; 53*346619c6SAndreas Gohr } 54*346619c6SAndreas Gohr 55*346619c6SAndreas Gohr private function prettyid($ns) { 56*346619c6SAndreas Gohr $ns = cleanID($ns); 57*346619c6SAndreas Gohr return $ns ? ($ns . ':*') : '*'; 58*346619c6SAndreas Gohr } 59*346619c6SAndreas Gohr} 60*346619c6SAndreas Gohr 61*346619c6SAndreas Gohr// vim:ts=4:sw=4:et:enc=utf-8: 62