/** * Step up * * @param Doku_Event $event */ public function handle_ajax(Doku_Event $event) { if ($event->data != 'plugin_move_progress') { return; } $event->preventDefault(); $event->stopPropagation(); global $INPUT; global $USERINFO; if (!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); exit; } $return = array('error' => '', 'complete' => false, 'progress' => 0); /** @var helper_plugin_move_plan $plan */ $plan = plugin_load('helper', 'move_plan'); if (!$plan->isCommited()) { // There is no plan. Something went wrong $return['complete'] = true; } else { $todo = $plan->nextStep($INPUT->bool('skip')); $return['progress'] = $plan->getProgress(); $return['error'] = $plan->getLastError(); if ($todo === 0) { $return['complete'] = true; } } $json = new JSON(); header('Content-Type: application/json'); echo $json->encode($return); }
/** * @param Doku_Event $event event object by reference * @param array $param empty array as passed to register_hook() */ function handle_ajax_call(Doku_Event $event, $param) { /** @var DokuWiki_Auth_Plugin $auth */ global $auth; if ($event->data != 'blogtng__comment_preview') { return; } $event->preventDefault(); $event->stopPropagation(); require_once DOKU_PLUGIN . 'blogtng/helper/comments.php'; $comment = new blogtng_comment(); $comment->data['text'] = $_REQUEST['text']; $comment->data['name'] = $_REQUEST['name']; $comment->data['mail'] = $_REQUEST['mail']; $comment->data['web'] = isset($_REQUEST['web']) ? $_REQUEST['web'] : ''; $comment->data['cid'] = 'preview'; $comment->data['created'] = time(); $comment->data['status'] = 'visible'; if (!$comment->data['name'] && $_SERVER['REMOTE_USER']) { if ($auth and $info = $auth->getUserData($_SERVER['REMOTE_USER'])) { $comment->data['name'] = $info['name']; $comment->data['mail'] = $info['mail']; } } $comment->output($_REQUEST['tplname']); }
/** * @param Doku_Event$event * @param $param */ public function ajax(Doku_Event $event, $param) { if ($event->data !== 'bureaucracy_user_field') { return; } $event->stopPropagation(); $event->preventDefault(); $search = $_REQUEST['search']; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; $users = array(); foreach ($auth->retrieveUsers() as $username => $data) { if ($search === '' || stripos($username, $search) === 0 || stripos($data['name'], $search) !== false) { // Full name $users[$username] = $data['name']; } if (count($users) === 10) { break; } } if (count($users) === 1 && key($users) === $search) { $users = array(); } require_once DOKU_INC . 'inc/JSON.php'; $json = new JSON(); echo $json->encode($users); }
public function onAjaxCallUnknown(\Doku_Event $event, $action) { if ($event->data != 'yk') { return; } // skip if not our plugin $do = $this->G['INPUT']->post->str('action', ''); if ($action !== $do) { return; // not match. skip this, continue with another } $event->preventDefault(); // what does it do? $event->stopPropagation(); //our hooker found, skip others $pageId = $this->G['INPUT']->post->str('id', ''); $pageNewId = $this->G['INPUT']->post->str('new_page_id', null); $json = new \stdClass(); $json->error = false; try { $this->logger(strtoupper($do), 'PAGE ' . $pageId); $json->result = $this->doAction($pageId, $pageNewId); $this->logger('SUCCESS'); } catch (\Exception $e) { $json->error = date('H:i:s') . ' ' . $e->getMessage(); $this->logger('ERROR', $e->getMessage()); } //header('Content-Type: application/json'); echo json_encode($json); }
/** * Create the detail info for a single plugin * * @param Doku_Event $event * @param $param */ public function info(Doku_Event &$event, $param) { global $USERINFO; global $INPUT; if ($event->data != 'plugin_extension') { return; } $event->preventDefault(); $event->stopPropagation(); if (empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); echo 'Forbidden'; exit; } header('Content-Type: text/html; charset=utf-8'); $ext = $INPUT->str('ext'); if (!$ext) { echo 'no extension given'; return; } /** @var helper_plugin_extension_extension $extension */ $extension = plugin_load('helper', 'extension_extension'); $extension->setExtension($ext); /** @var helper_plugin_extension_list $list */ $list = plugin_load('helper', 'extension_list'); echo $list->make_info($extension); }
/** * [Custom event handler which performs action] * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_auth_user_change(Doku_Event &$event, $param) { if ($event->data['type'] !== 'create') { return; } $domains = array_map(function ($domain) { return trim($domain); }, explode(';', $this->getConf('_domainWhiteList'))); $email = $event->data['params'][3]; $checks = array(in_array(trim(substr(strrchr($email, "@"), 1)), $domains), (bool) preg_match($this->getConf('_emailRegex', '/@/'), $email)); if ($this->getConf('checksAnd', true)) { $status = array_reduce($checks, function ($a, $b) { return $a && $b; }, true); } else { $status = array_reduce($checks, function ($a, $b) { return $a || $b; }, false); } if (!$status) { $event->preventDefault(); $event->stopPropagation(); $event->result = false; msg($this->getConf('_domainlistErrorMEssage'), -1); } }
/** * Rename a single page */ public function handle_ajax(Doku_Event $event) { if ($event->data != 'plugin_move_rename') { return; } $event->preventDefault(); $event->stopPropagation(); global $MSG; global $INPUT; $src = cleanID($INPUT->str('id')); $dst = cleanID($INPUT->str('newid')); /** @var helper_plugin_move_op $MoveOperator */ $MoveOperator = plugin_load('helper', 'move_op'); $JSON = new JSON(); header('Content-Type: application/json'); if ($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) { // all went well, redirect echo $JSON->encode(array('redirect_url' => wl($dst, '', true, '&'))); } else { if (isset($MSG[0])) { $error = $MSG[0]; // first error } else { $error = $this->getLang('cantrename'); } echo $JSON->encode(array('error' => $error)); } }
/** * Load a whole schema as fields * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return bool */ public function handle_schema(Doku_Event $event, $param) { $args = $event->data['args']; if ($args[0] != 'struct_schema') { return false; } $event->preventDefault(); $event->stopPropagation(); /** @var helper_plugin_bureaucracy_field $helper */ $helper = plugin_load('helper', 'bureaucracy_field'); $helper->initialize($args); $schema = new Schema($helper->opt['label']); if (!$schema->getId()) { msg('This schema does not exist', -1); return false; } foreach ($schema->getColumns(false) as $column) { /** @var helper_plugin_struct_field $field */ $field = plugin_load('helper', 'struct_field'); // we don't initialize the field but set the appropriate values $field->opt = $helper->opt; // copy all the settings to each field $field->opt['label'] = $column->getFullQualifiedLabel(); $field->column = $column; $event->data['fields'][] = $field; } return true; }
/** * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_ajax_call_unknown(Doku_Event &$event, $param) { if ($event->data !== 'tagapi_list') { return; } $event->stopPropagation(); $event->preventDefault(); if ($this->tagplugin = $this->loadHelper('tag')) { $tags = $this->tagplugin->tagOccurrences(array(), NULL, true); $a = print_r($tags, true); // file_put_contents(DOKU_INC . 'tags.txt', $a); } else { $tags = array(); } // sort tags by name ($tags is in the form $tag => $count) ksort($tags); echo '{"tags":['; $firstelement = true; foreach (array_keys($tags) as $tag) { if ($firstelement) { $firstelement = false; } else { echo ','; } echo '{"name":"' . $this->tagToName($tag) . '","id":"' . $tag . '"}'; } echo ']}'; }
/** * Gets the thumbnail * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_do_action(Doku_Event &$event, $param) { if ($event->data !== 'obsaudioupload_frame_thumbnail') { return; } //no other ajax call handlers needed $event->stopPropagation(); $event->preventDefault(); // get the url of the image to make into a thumbnail $url = $GLOBALS['INPUT']->str('img'); $imageInfo = getimagesize($url); // 0=width, 1=height, 2=format if ($imageInfo[2] == IMG_PNG) { $img = imagecreatefrompng($url); } else { $img = imagecreatefromjpeg($url); } $newHeight = 50; $newWidth = (int) ($imageInfo[0] * $newHeight / $imageInfo[1]); $newImg = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($newImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imageInfo[0], $imageInfo[1]); // output header('Content-Type: application/jpeg'); imagejpeg($newImg, null, 60); exit; }
/** * [Custom event handler which performs action] * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_action_act_preprocess(Doku_Event &$event, $param) { if ($event->data != 'pageproperties') { return; } $event->preventDefault(); $event->stopPropagation(); return true; }
/** * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_register_action(Doku_Event &$event, $param) { if ($event->data !== 'register') { return; } //no other action handlers needed $event->stopPropagation(); $event->preventDefault(); $this->override_html_register(); }
/** * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_ajax_call_unknown(Doku_Event &$event, $param) { if ($event->data !== 'iwiki_list') { return; } $event->stopPropagation(); $event->preventDefault(); $a = getInterwiki(); ksort($a); echo json_encode($a); }
/** * Ajax handler */ function _ajax_call(Doku_Event $event, $param) { if ($event->data !== 'plugin_textvar') { return; } $event->stopPropagation(); $event->preventDefault(); $json = new JSON(); $data = array('%SERVER_ADDR%' => $_SERVER['SERVER_ADDR'], '%REMOTE_ADDR%' => $_SERVER['REMOTE_ADDR']); header('Content-Type: application/json'); echo $json->encode($data); }
/** * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_ajax_call(Doku_Event &$event, $param) { // do we have a handler defined for this call? if (empty($this->handlers[$event->data])) { return; } //no other ajax call handlers needed $event->stopPropagation(); $event->preventDefault(); $handler = $this->handlers[$event->data]; $handler[0]->{$handler}[1]($event); }
/** * Analyze the next chunk of data * * @param Doku_Event $event * @param $param */ function handle_run(&$event, $param) { echo "logfile analysis started.\n"; /** @var $log helper_plugin_statdisplay_log */ $log = plugin_load('helper', 'statdisplay_log'); $lines = $log->parseLogData(); // did we do any work? if ($lines) { $event->preventDefault(); $event->stopPropagation(); } echo "logfile analysis finished analyzing {$lines} lines.\n"; }
public function handle_ajax_call_unknown(Doku_Event &$event, $param) { if ($event->data != 'plugin_imgpaste') { return; } global $lang; // get data global $INPUT; $data = $INPUT->post->str('data'); list($type, $data) = explode(';', $data); if (!$data) { $this->fail(400, $this->getLang('e_nodata')); } // process data encoding $type = strtolower(substr($type, 5)); // strip 'data:' prefix $data = substr($data, 7); // strip 'base64,' prefix $data = base64_decode($data); // check for supported mime type $mimetypes = array_flip(getMimeTypes()); if (!isset($mimetypes[$type])) { $this->fail(415, $lang['uploadwrong']); } // prepare file names $tempname = $this->storetemp($data); $filename = $this->getConf('filename'); $filename = str_replace(array('@NS@', '@ID@', '@USER@'), array(getNS($INPUT->post->str('id')), $INPUT->post->str('id'), $_SERVER['REMOTE_USER']), $filename); $filename = strftime($filename); $filename .= '.' . $mimetypes[$type]; $filename = cleanID($filename); // check ACLs $auth = auth_quickaclcheck($filename); if ($auth < AUTH_UPLOAD) { $this->fail(403, $lang['uploadfail']); } // do the actual saving $result = media_save(array('name' => $tempname, 'mime' => $type, 'ext' => $mimetypes[$type]), $filename, false, $auth, 'copy'); if (is_array($result)) { $this->fail(500, $result[0]); } //Still here? We had a successful upload $this->clean(); header('Content-Type: application/json'); $json = new JSON(); echo $json->encode(array('message' => $lang['uploadsucc'], 'id' => $result)); $event->preventDefault(); $event->stopPropagation(); }
/** * [Custom event handler which performs action] * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_ajax_call_unknown(Doku_Event &$event, $param) { if ($event->data != 'rating') { return; } $event->preventDefault(); $event->stopPropagation(); global $ID; $ID = getID(); // let the other handler do it $this->handle_vote($event, $param); /** @var helper_plugin_rating $hlp */ $hlp = plugin_load('helper', 'rating'); $hlp->tpl(true); }
/** * Handle section edit buttons, prevents section buttons inside the wrap plugin from being rendered * * @param Doku_Event $event The event object * @param array $args Parameters for the event */ public function handle_secedit_button($event, $args) { // counter of the number of currently opened wraps static $wraps = 0; $data = $event->data; if ($data['target'] == 'plugin_wrap_start') { ++$wraps; } elseif ($data['target'] == 'plugin_wrap_end') { --$wraps; } elseif ($wraps > 0 && $data['target'] == 'section') { $event->preventDefault(); $event->stopPropagation(); $event->result = ''; } }
/** * Reconfigure config for a given type * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] */ public function handle_ajax(Doku_Event $event, $param) { if ($event->data != 'plugin_struct_config') { return; } $event->preventDefault(); $event->stopPropagation(); global $INPUT; $conf = json_decode($INPUT->str('conf'), true); /** @var AbstractBaseType $type */ $class = 'dokuwiki\\plugin\\struct\\types\\' . $INPUT->str('type', 'Text'); $type = new $class($conf); header('Content-Type: text/plain'); // we need the encoded string, not decoded by jQuery echo json_encode($type->getConfig()); }
/** * Preview Comments * * @author Michael Klier <*****@*****.**> */ function handle_ajax_call(Doku_Event &$event, $params) { if ($event->data != 'discussion_preview') { return; } $event->preventDefault(); $event->stopPropagation(); print p_locale_xhtml('preview'); print '<div class="comment_preview">'; if (!$_SERVER['REMOTE_USER'] && !$this->getConf('allowguests')) { print p_locale_xhtml('denied'); } else { print $this->_render($_REQUEST['comment']); } print '</div>'; }
/** * Check for pages changes and eventually purge cache. * * @author Samuele Tognini <*****@*****.**> * * @param Doku_Event $event * @param mixed $param not defined */ function _purgecache(&$event, $param) { global $ID; global $conf; /** @var cache_parser $cache */ $cache =& $event->data; if (!isset($cache->page)) { return; } //purge only xhtml cache if ($cache->mode != "xhtml") { return; } //Check if it is an pagequery page if (!p_get_metadata($ID, 'pagequery')) { return; } $aclcache = $this->getConf('aclcache'); if ($conf['useacl']) { $newkey = false; if ($aclcache == 'user') { //Cache per user if ($_SERVER['REMOTE_USER']) { $newkey = $_SERVER['REMOTE_USER']; } } else { if ($aclcache == 'groups') { //Cache per groups global $INFO; if ($INFO['userinfo']['grps']) { $newkey = implode('#', $INFO['userinfo']['grps']); } } } if ($newkey) { $cache->key .= "#" . $newkey; $cache->cache = getCacheName($cache->key, $cache->ext); } } //Check if a page is more recent than purgefile. if (@filemtime($cache->cache) < @filemtime($conf['cachedir'] . '/purgefile')) { $event->preventDefault(); $event->stopPropagation(); $event->result = false; } }
/** * @param Doku_Event $event * @param array $param */ function hide(Doku_Event &$event, $param) { if (!$this->hlp->isActive()) { return; } if (!$this->hlp->isHiddenForUser()) { return; } global $ACT; if (!in_array($ACT, array('show', 'edit', 'source', 'diff'))) { return; } $ACT = 'denied'; $event->preventDefault(); $event->stopPropagation(); print p_locale_xhtml('denied'); }
/** * This is the main function, call at every action. * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_action_act_preprocess(Doku_Event &$event, $param) { // first check if it's a texit event if ($event->data != "texit" && $event->data != "texitns") { return false; } // check user's rights if (auth_quickaclcheck(getID()) < AUTH_READ) { return false; } $this->loadConfig(); // we need to get the usual plugin config $pdfurl = $this->generate_pdf($event->data); $this->redirect_to_pdf($pdfurl); $event->preventDefault(); $event->stopPropagation(); exit; }
/** * Create the detail info for a single plugin * * @param Doku_Event $event * @param $param */ public function info(Doku_Event &$event, $param) { global $USERINFO; global $INPUT; if ($event->data != 'plugin_extension') { return; } $event->preventDefault(); $event->stopPropagation(); if (empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) { http_status(403); echo 'Forbidden'; exit; } $ext = $INPUT->str('ext'); if (!$ext) { http_status(400); echo 'no extension given'; return; } /** @var helper_plugin_extension_extension $extension */ $extension = plugin_load('helper', 'extension_extension'); $extension->setExtension($ext); $act = $INPUT->str('act'); switch ($act) { case 'enable': case 'disable': $json = new JSON(); $extension->{$act}(); //enables/disables $reverse = $act == 'disable' ? 'enable' : 'disable'; $return = array('state' => $act . 'd', 'reverse' => $reverse, 'label' => $extension->getLang('btn_' . $reverse)); header('Content-Type: application/json'); echo $json->encode($return); break; case 'info': default: /** @var helper_plugin_extension_list $list */ $list = plugin_load('helper', 'extension_list'); header('Content-Type: text/html; charset=utf-8'); echo $list->make_info($extension); } }
/** * [Custom event handler which performs action] * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_mail_message_send(Doku_Event &$event, $param) { require_once __DIR__ . '/loader.php'; // prepare the message /** @var Mailer $mailer Our Mailer with all the data */ $mailer = $event->data['mail']; $body = $mailer->dump(); // this also prepares all internal variables of the mailer $rcpt = $event->data['to'] . ',' . $event->data['cc'] . ',' . $event->data['bcc']; $from = $event->data['from']; $message = new \splitbrain\dokuwiki\plugin\smtp\Message($from, $rcpt, $body); // prepare the SMTP communication lib $logger = new \splitbrain\dokuwiki\plugin\smtp\Logger(); $smtp = new \Tx\Mailer\SMTP($logger); $smtp->setServer($this->getConf('smtp_host'), $this->getConf('smtp_port'), $this->getConf('smtp_ssl')); if ($this->getConf('auth_user')) { $smtp->setAuth($this->getConf('auth_user'), $this->getConf('auth_pass')); } $smtp->setEhlo(helper_plugin_smtp::getEHLO($this->getConf('localdomain'))); // send the message try { $smtp->send($message); $ok = true; } catch (Exception $e) { msg('There was an unexpected problem communicating with SMTP: ' . $e->getMessage(), -1); $ok = false; } // give debugging help on error if (!$ok && $this->getConf('debug')) { $log = array(); foreach ($logger->getLog() as $line) { $log[] = trim($line[1]); } $log = trim(join("\n", $log)); msg('SMTP log:<br /><pre>' . hsc($log) . '</pre><b>Above may contain passwords - do not post online!</b>', -1); } // finish event handling $event->preventDefault(); $event->stopPropagation(); $event->result = $ok; $event->data['success'] = $ok; }
/** * Gets the S3 bucket config * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * @return void */ public function handle_do_action(Doku_Event &$event, $param) { if ($event->data !== 'obsaudioupload_signature_request') { return; } //no other ajax call handlers needed $event->stopPropagation(); $event->preventDefault(); // read the config file $config = json_decode(file_get_contents('/usr/share/httpd/.ssh/door43bucket.conf')); // get the input $raw = file_get_contents('php://input'); // output header('Content-Type: application/json'); $policy = base64_encode(utf8_encode($raw)); $signature = base64_encode(hash_hmac('sha1', $policy, $config->secretKey, true)); $return = '{"policy": "' . $policy . '", "signature": "' . $signature . '"}'; echo $return; exit; }
function _autosubmit(Doku_Event &$event, $param) { //Do we have to send the data now if (!$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit()) { return; } //Actually send it $status = $this->helper->sendData($this->helper->gatherAsString()); if ($status !== '') { //If an error occured, log it io_saveFile($this->helper->autosubmitErrorFile, $status); } else { //If the data has been sent successfully, previous log of errors are useless @unlink($this->helper->autosubmitErrorFile); //Update the last time we sent data touch($this->helper->autosubmitFile); } $event->stopPropagation(); $event->preventDefault(); }
/** * Pass Ajax call to a type * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] */ public function handle_ajax(Doku_Event $event, $param) { if ($event->data != 'plugin_struct') { return; } $event->preventDefault(); $event->stopPropagation(); global $conf; header('Content-Type: application/json'); try { $result = $this->executeTypeAjax(); } catch (StructException $e) { $result = array('error' => $e->getMessage() . ' ' . basename($e->getFile()) . ':' . $e->getLine()); if ($conf['allowdebug']) { $result['stacktrace'] = $e->getTraceAsString(); } http_status(500); } $json = new JSON(); echo $json->encode($result); }
/** * AJAX call handler for ACL plugin * * @param Doku_Event $event event object by reference * @param mixed $param empty * @return void */ public function handle_ajax_call_acl(Doku_Event &$event, $param) { if ($event->data !== 'plugin_acl') { return; } $event->stopPropagation(); $event->preventDefault(); global $ID; global $INPUT; if (!auth_isadmin()) { echo 'for admins only'; return; } if (!checkSecurityToken()) { echo 'CRSF Attack'; return; } $ID = getID(); /** @var $acl admin_plugin_acl */ $acl = plugin_load('admin', 'acl'); $acl->handle(); $ajax = $INPUT->str('ajax'); header('Content-Type: text/html; charset=utf-8'); if ($ajax == 'info') { $acl->_html_info(); } elseif ($ajax == 'tree') { $ns = $INPUT->str('ns'); if ($ns == '*') { $ns = ''; } $ns = cleanID($ns); $lvl = count(explode(':', $ns)); $ns = utf8_encodeFN(str_replace(':', '/', $ns)); $data = $acl->_get_tree($ns, $ns); foreach (array_keys($data) as $item) { $data[$item]['level'] = $lvl + 1; } echo html_buildlist($data, 'acl', array($acl, '_html_list_acl'), array($acl, '_html_li_acl')); } }