/** * Adds the file $src as a picture file without adding it to the content. * Returns name of the file in the document for reference. * * @param string $src * @return string */ function addFileAsPicture($src) { $name = ''; if (file_exists($src)) { list($ext, $mime) = mimetype($src); $name = 'Pictures/' . md5($src) . '.' . $ext; $this->addFile($name, $mime, io_readfile($src, false)); } return $name; }
/** * Return DokuWiki's version (split up in date and type) * * @author Andreas Gohr <*****@*****.**> */ function getVersionData() { $version = array(); //import version string if (@file_exists(DOKU_INC . 'VERSION')) { //official release $version['date'] = trim(io_readfile(DOKU_INC . 'VERSION')); $version['type'] = 'Release'; } elseif (is_dir(DOKU_INC . '.git')) { $version['type'] = 'Git'; $version['date'] = 'unknown'; $inventory = DOKU_INC . '.git/logs/HEAD'; if (is_file($inventory)) { $sz = filesize($inventory); $seek = max(0, $sz - 2000); // read from back of the file $fh = fopen($inventory, 'rb'); fseek($fh, $seek); $chunk = fread($fh, 2000); fclose($fh); $chunk = trim($chunk); $chunk = @array_pop(explode("\n", $chunk)); //last log line $chunk = @array_shift(explode("\t", $chunk)); //strip commit msg $chunk = explode(" ", $chunk); array_pop($chunk); //strip timezone $date = date('Y-m-d', array_pop($chunk)); if ($date) { $version['date'] = $date; } } } else { global $updateVersion; $version['date'] = 'update version ' . $updateVersion; $version['type'] = 'snapshot?'; } return $version; }
/** * Return DokuWikis version * * @author Andreas Gohr <*****@*****.**> */ function getVersion() { //import version string if (@file_exists('VERSION')) { //official release return 'Release ' . trim(io_readfile(DOKU_INC . '/VERSION')); } elseif (is_dir('_darcs')) { //darcs checkout - read last 2000 bytes of inventory $sz = filesize('_darcs/inventory'); $seek = max(0, $sz - 2000); $fh = fopen('_darcs/inventory', 'rb'); fseek($fh, $seek); $chunk = fread($fh, 2000); fclose($fh); $inv = preg_grep('#\\*\\*\\d{14}[\\]$]#', explode("\n", $chunk)); $cur = array_pop($inv); preg_match('#\\*\\*(\\d{4})(\\d{2})(\\d{2})#', $cur, $matches); return 'Darcs ' . $matches[1] . '-' . $matches[2] . '-' . $matches[3]; } else { return 'snapshot?'; } }
/** * Return DokuWiki's version (split up in date and type) * * @author Andreas Gohr <*****@*****.**> */ function getVersionData() { $version = array(); //import version string if (@file_exists(DOKU_INC . 'VERSION')) { //official release $version['date'] = trim(io_readfile(DOKU_INC . 'VERSION')); $version['type'] = 'Release'; return $version; } elseif (is_dir(DOKU_INC . '_darcs')) { if (is_file(DOKU_INC . '_darcs/inventory')) { $inventory = DOKU_INC . '_darcs/inventory'; } elseif (is_file(DOKU_INC . '_darcs/hashed_inventory')) { $inventory = DOKU_INC . '_darcs/hashed_inventory'; } else { $version['date'] = 'unknown'; $version['type'] = 'Darcs'; return $version; } //darcs checkout - read last 2000 bytes of inventory $sz = filesize($inventory); $seek = max(0, $sz - 2000); $fh = fopen($inventory, 'rb'); fseek($fh, $seek); $chunk = fread($fh, 2000); fclose($fh); preg_match_all('#\\*\\*(\\d{4})(\\d{2})(\\d{2})\\d{6}(?:\\]|$)#m', $chunk, $matches, PREG_SET_ORDER); $version['date'] = implode('-', array_slice(array_pop($matches), 1)); $version['type'] = 'Darcs'; return $version; } else { $version['date'] = 'unknown'; $version['type'] = 'snapshot?'; return $version; } }
/** * Returns the render instructions for a file * * Uses and creates a serialized cache file * * @author Andreas Gohr <*****@*****.**> */ function p_cached_instructions($file, $cacheonly = false, $id = '') { global $conf; $cache = new cache_instructions($id, $file); if ($cacheonly || $cache->useCache()) { return $cache->retrieveCache(); } else { if (@file_exists($file)) { // no cache - do some work $ins = p_get_instructions(io_readfile($file)); $cache->storeCache($ins); return $ins; } } return NULL; }
/** * @param string $src * @param $width * @param $height * @param $align * @param $title * @param $style * @param $returnonly */ function _odtAddImage($src, $width = NULL, $height = NULL, $align = NULL, $title = NULL, $style = NULL, $returnonly = false) { $doc = ''; if (file_exists($src)) { list($ext, $mime) = mimetype($src); $name = 'Pictures/' . md5($src) . '.' . $ext; $this->docHandler->addFile($name, $mime, io_readfile($src, false)); } else { $name = $src; } // make sure width and height are available if (!$width || !$height) { list($width, $height) = $this->_odtGetImageSize($src, $width, $height); } else { // Adjust values for ODT $width = $this->adjustXLengthValueForODT($width); $height = $this->adjustYLengthValueForODT($height); } if ($align) { $anchor = 'paragraph'; } else { $anchor = 'as-char'; } if (!$style or !array_key_exists($style, $this->autostyles)) { $style = $this->styleset->getStyleName('media ' . $align); } if ($title) { $doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . ' Legend" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '">'; $doc .= '<draw:text-box>'; $doc .= '<text:p text:style-name="' . $this->styleset->getStyleName('legend center') . '">'; } $doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . '" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '" svg:height="' . $height . '" >'; $doc .= '<draw:image xlink:href="' . $this->_xmlEntities($name) . '" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'; $doc .= '</draw:frame>'; if ($title) { $doc .= $this->_xmlEntities($title) . '</text:p></draw:text-box></draw:frame>'; } if ($returnonly) { return $doc; } else { $this->doc .= $doc; } }
/** * Send a new password * * This function handles both phases of the password reset: * * - handling the first request of password reset * - validating the password reset auth token * * @author Benoit Chesneau <*****@*****.**> * @author Chris Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> * * @return bool true on success, false on any error */ function act_resendpwd() { global $lang; global $conf; global $auth; if (!actionOK('resendpwd')) { return false; } if (!$auth) { return false; } // should not be able to get here without modPass being possible... if (!$auth->canDo('modPass')) { msg($lang['resendna'], -1); return false; } $token = preg_replace('/[^a-f0-9]+/', '', $_REQUEST['pwauth']); if ($token) { // we're in token phase $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; if (!@file_exists($tfile)) { msg($lang['resendpwdbadauth'], -1); return false; } $user = io_readfile($tfile); @unlink($tfile); $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } $pass = auth_pwgen(); if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } if (auth_sendPassword($user, $pass)) { msg($lang['resendpwdsuccess'], 1); } else { msg($lang['regmailfail'], -1); } return true; } else { // we're in request phase if (!$_POST['save']) { return false; } if (empty($_POST['login'])) { msg($lang['resendpwdmissing'], -1); return false; } else { $user = trim($auth->cleanUser($_POST['login'])); } $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } // generate auth token $token = md5(auth_cookiesalt() . $user); //secret but user based $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; $url = wl('', array('do' => 'resendpwd', 'pwauth' => $token), true, '&'); io_saveFile($tfile, $user); $text = rawLocale('pwconfirm'); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@FULLNAME@', $userinfo['name'], $text); $text = str_replace('@LOGIN@', $user, $text); $text = str_replace('@TITLE@', $conf['title'], $text); $text = str_replace('@CONFIRM@', $url, $text); if (mail_send($userinfo['name'] . ' <' . $userinfo['mail'] . '>', $lang['regpwmail'], $text, $conf['mailfrom'])) { msg($lang['resendpwdconfirm'], 1); } else { msg($lang['regmailfail'], -1); } return true; } return false; // never reached }
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ function _notify($comment, &$subscribers) { global $conf; global $ID; global $INFO; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $from = $conf['mailfrom']; $from = str_replace('@USER@', $_SERVER['REMOTE_USER'], $from); $from = str_replace('@NAME@', $INFO['userinfo']['name'], $from); $from = str_replace('@MAIL@', $INFO['userinfo']['mail'], $from); $search = array('@PAGE@', '@TITLE@', '@DATE@', '@NAME@', '@TEXT@', '@COMMENTURL@', '@UNSUBSCRIBE@', '@DOKUWIKIURL@'); // prepare email body if ($conf['notify'] || $conf['subscribers']) { $replace = array($ID, $conf['title'], dformat($comment['date']['created'], $conf['dformat']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment_' . $comment['cid'], wl($ID, 'do=unsubscribe', true, '&'), DOKU_URL); $body = str_replace($search, $replace, $notify_text); } // send mail to notify address if ($conf['notify']) { $to = $conf['notify']; mail_send($to, $subject_notify, $body, $from, '', ''); } // notify page subscribers if ($conf['subscribers']) { $to = ''; // put all recipients in bcc field $data = array('id' => $ID, 'addresslist' => '', 'self' => false); trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; mail_send($to, $subject_notify, $body, $from, '', $bcc); } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $to = $mail; if ($data['active']) { $replace = array($ID, $conf['title'], dformat($comment['date']['created'], $conf['dformat']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment_' . $comment['cid'], wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'), DOKU_URL); $body = str_replace($search, $replace, $notify_text); mail_send($to, $subject_notify, $body, $from); } elseif (!$data['active'] && !$data['confirmsent']) { $search = array('@PAGE@', '@TITLE@', '@SUBSCRIBE@', '@DOKUWIKIURL@'); $replace = array($ID, $conf['title'], wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'), DOKU_URL); $body = str_replace($search, $replace, $confirm_text); mail_send($to, $subject_subscribe, $body, $from); $subscribers[$mail]['confirmsent'] = true; } } } }
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * @param array $subscribers data of the subscribers * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ protected function _notify($comment, &$subscribers) { global $conf; global $ID; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $mailer = new Mailer(); if (empty($_SERVER['REMOTE_USER'])) { $mailer->from($conf['mailfromnobody']); } $replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DATE' => dformat($comment['date']['created'], $conf['dformat']), 'NAME' => $comment['user']['name'], 'TEXT' => $comment['raw'], 'COMMENTURL' => wl($ID, '', true) . '#comment_' . $comment['cid'], 'UNSUBSCRIBE' => wl($ID, 'do=subscribe', true, '&'), 'DOKUWIKIURL' => DOKU_URL); $confirm_replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); // send mail to notify address if ($conf['notify']) { $mailer->bcc($conf['notify']); $mailer->send(); } // send email to moderators if ($this->getConf('moderatorsnotify')) { $mods = trim($this->getConf('moderatorgroups')); if (!empty($mods)) { global $auth; // create a clean mods list $mods = explode(',', $mods); $mods = array_map('trim', $mods); $mods = array_unique($mods); $mods = array_filter($mods); // search for moderators users foreach ($mods as $mod) { if (!$auth->isCaseSensitive()) { $mod = utf8_strtolower($mod); } // create a clean mailing list $dests = array(); if ($mod[0] == '@') { foreach ($auth->retrieveUsers(0, 0, array('grps' => $auth->cleanGroup(substr($mod, 1)))) as $user) { if (!empty($user['mail'])) { array_push($dests, $user['mail']); } } } else { $userdata = $auth->getUserData($auth->cleanUser($mod)); if (!empty($userdata['mail'])) { array_push($dests, $userdata['mail']); } } $dests = array_unique($dests); // notify the users $mailer->bcc(implode(',', $dests)); $mailer->send(); } } } // notify page subscribers if (actionOK('subscribe')) { $data = array('id' => $ID, 'addresslist' => '', 'self' => false); if (class_exists('Subscription')) { /* Introduced in DokuWiki 2013-05-10 */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, array(new Subscription(), 'notifyaddresses')); } else { /* Old, deprecated default handler */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); } $to = $data['addresslist']; if (!empty($to)) { $mailer->bcc($to); $mailer->send(); } } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $mailer->bcc($mail); if ($data['active']) { $replace['UNSUBSCRIBE'] = wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); $mailer->send(); } elseif (!$data['active'] && !$data['confirmsent']) { $confirm_replace['SUBSCRIBE'] = wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_subscribe); $mailer->setBody($confirm_text, $confirm_replace); $mailer->send(); $subscribers[$mail]['confirmsent'] = true; } } } }
/** * Send a new password * * This function handles both phases of the password reset: * * - handling the first request of password reset * - validating the password reset auth token * * @author Benoit Chesneau <*****@*****.**> * @author Chris Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> * * @return bool true on success, false on any error */ function act_resendpwd() { global $lang; global $conf; global $auth; if (!actionOK('resendpwd')) { msg($lang['resendna'], -1); return false; } $token = preg_replace('/[^a-f0-9]+/', '', $_REQUEST['pwauth']); if ($token) { // we're in token phase - get user info from token $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; if (!@file_exists($tfile)) { msg($lang['resendpwdbadauth'], -1); unset($_REQUEST['pwauth']); return false; } // token is only valid for 3 days if (time() - filemtime($tfile) > 3 * 60 * 60 * 24) { msg($lang['resendpwdbadauth'], -1); unset($_REQUEST['pwauth']); @unlink($tfile); return false; } $user = io_readfile($tfile); $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } if (!$conf['autopasswd']) { // we let the user choose a password // password given correctly? if (!isset($_REQUEST['pass']) || $_REQUEST['pass'] == '') { return false; } if ($_REQUEST['pass'] != $_REQUEST['passchk']) { msg($lang['regbadpass'], -1); return false; } $pass = $_REQUEST['pass']; if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } } else { // autogenerate the password and send by mail $pass = auth_pwgen(); if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } if (auth_sendPassword($user, $pass)) { msg($lang['resendpwdsuccess'], 1); } else { msg($lang['regmailfail'], -1); } } @unlink($tfile); return true; } else { // we're in request phase if (!$_POST['save']) { return false; } if (empty($_POST['login'])) { msg($lang['resendpwdmissing'], -1); return false; } else { $user = trim($auth->cleanUser($_POST['login'])); } $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } // generate auth token $token = md5(auth_cookiesalt() . $user); //secret but user based $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; $url = wl('', array('do' => 'resendpwd', 'pwauth' => $token), true, '&'); io_saveFile($tfile, $user); $text = rawLocale('pwconfirm'); $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); $text = str_replace('@FULLNAME@', $userinfo['name'], $text); $text = str_replace('@LOGIN@', $user, $text); $text = str_replace('@TITLE@', $conf['title'], $text); $text = str_replace('@CONFIRM@', $url, $text); if (empty($conf['mailprefix'])) { $subject = $lang['regpwmail']; } else { $subject = '[' . $conf['mailprefix'] . '] ' . $lang['regpwmail']; } if (mail_send($userinfo['name'] . ' <' . $userinfo['mail'] . '>', $subject, $text, $conf['mailfrom'])) { msg($lang['resendpwdconfirm'], 1); } else { msg($lang['regmailfail'], -1); } return true; } return false; // never reached }
function _odtAddImage($src, $width = NULL, $height = NULL, $align = NULL, $title = NULL, $style = NULL) { if (file_exists($src)) { list($ext, $mime) = mimetype($src); $name = 'Pictures/' . md5($src) . '.' . $ext; if (!$this->manifest[$name]) { $this->manifest[$name] = $mime; $this->ZIP->add_File(io_readfile($src, false), $name, 0); } } else { $name = $src; } // make sure width and height are available if (!$width || !$height) { list($width, $height) = $this->_odtGetImageSize($src, $width, $height); } if ($align) { $anchor = 'paragraph'; } else { $anchor = 'as-char'; } if (!$style or !array_key_exists($style, $this->autostyles)) { $style = 'media' . $align; } if ($title) { $this->doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . ' Legend" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '">'; $this->doc .= '<draw:text-box>'; $this->doc .= '<text:p text:style-name="legendcenter">'; } $this->doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . '" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '" svg:height="' . $height . '" >'; $this->doc .= '<draw:image xlink:href="' . $this->_xmlEntities($name) . '" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'; $this->doc .= '</draw:frame>'; if ($title) { $this->doc .= $this->_xmlEntities($title) . '</text:p></draw:text-box></draw:frame>'; } }
function _odtAddImage($src, $width = NULL, $height = NULL, $align = NULL, $title = NULL, $style = NULL) { list($ext, $mime) = mimetype($src); $name = 'Pictures/' . md5($src) . '.' . $ext; if (!$this->manifest[$name]) { $this->manifest[$name] = $mime; $this->ZIP->add_File(io_readfile($src, false), $name, 0); } // make sure width and height is available // FIXME we don't have the dimension of an external file // (except it's cached, but this is not the default) there seems // to be no way to specify "use original image" in ODF - thus // a hardcoded default size of 200 pixel here if (!$width || !$height) { $info = getimagesize($src); if (!$width) { $width = $info[0]; $height = $info[1]; } else { $height = round($width * $info[1] / $info[0]); } } // convert from pixel to centimeters $width = $width / 96.0 * 2.54; $height = $height / 96.0 * 2.54; // Don't be wider than the page if ($width >= 17) { // FIXME : this assumes A4 page format with 2cm margins $width = $width . 'cm" style:rel-width="100%'; $height = $height . 'cm" style:rel-height="scale'; } else { $width = $width . 'cm'; $height = $height . 'cm'; } if ($align) { $anchor = 'paragraph'; } else { $anchor = 'as-char'; } if (!$style or !array_key_exists($style, $this->autostyles)) { $style = 'media' . $align; } if ($title) { $this->doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . ' Legend" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '">'; $this->doc .= '<draw:text-box>'; $this->doc .= '<text:p text:style-name="legendcenter">'; } $this->doc .= '<draw:frame draw:style-name="' . $style . '" draw:name="' . $this->_xmlEntities($title) . '" text:anchor-type="' . $anchor . '" draw:z-index="0" svg:width="' . $width . '" svg:height="' . $height . '" >'; $this->doc .= '<draw:image xlink:href="' . $this->_xmlEntities($name) . '" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>'; $this->doc .= '</draw:frame>'; if ($title) { $this->doc .= $this->_xmlEntities($title) . '</text:p></draw:text-box></draw:frame>'; } }
/** * Get plain text of the wikipage */ function _get_TEXT() { global $ID; $basePage = $ID; // check for perrmissions of type and base pages if (auth_quickaclcheck($basePage) < 1) { return false; } //get filename of the page $filename = wikiFN($basePage); $TEXT = io_readfile($filename); return $TEXT; }
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * @param array $subscribers data of the subscribers * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ function _notify($comment, &$subscribers) { global $conf; global $ID; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $mailer = new Mailer(); if (empty($_SERVER['REMOTE_USER'])) { $mailer->from($conf['mailfromnobody']); } $replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DATE' => dformat($comment['date']['created'], $conf['dformat']), 'NAME' => $comment['user']['name'], 'TEXT' => $comment['raw'], 'COMMENTURL' => wl($ID, '', true) . '#comment_' . $comment['cid'], 'UNSUBSCRIBE' => wl($ID, 'do=subscribe', true, '&'), 'DOKUWIKIURL' => DOKU_URL); $confirm_replace = array('PAGE' => $ID, 'TITLE' => $conf['title'], 'DOKUWIKIURL' => DOKU_URL); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); // send mail to notify address if ($conf['notify']) { $mailer->bcc($conf['notify']); $mailer->send(); } // notify page subscribers if (actionOK('subscribe')) { $data = array('id' => $ID, 'addresslist' => '', 'self' => false); if (class_exists('Subscription')) { /* Introduced in DokuWiki 2013-05-10 */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, array(new Subscription(), 'notifyaddresses')); } else { /* Old, deprecated default handler */ trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); } $to = $data['addresslist']; if (!empty($to)) { $mailer->bcc($to); $mailer->send(); } } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $mailer->bcc($mail); if ($data['active']) { $replace['UNSUBSCRIBE'] = wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_notify); $mailer->setBody($notify_text, $replace); $mailer->send(); } elseif (!$data['active'] && !$data['confirmsent']) { $confirm_replace['SUBSCRIBE'] = wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'); $mailer->subject($subject_subscribe); $mailer->setBody($confirm_text, $confirm_replace); $mailer->send(); $subscribers[$mail]['confirmsent'] = true; } } } }
/** * fulltext search helper * searches a text file with a given regular expression * no ACL checks are performed. This have to be done by * the caller if necessary. * * @param array $data reference to array for results * @param string $base base directory * @param string $file file name to search in * @param string $reg regular expression to search for * @param array $words words that should be marked in the results * * @author Andreas Gohr <*****@*****.**> * @author Matthias Grimm <*****@*****.**> * * @deprecated - fulltext indexer is used instead */ function search_regex(&$data, $base, $file, $reg, $words) { //get text $text = io_readfile($base . '/' . $file); //lowercase text (u modifier does not help with case) $lctext = utf8_strtolower($text); //do the fulltext search $matches = array(); if ($cnt = preg_match_all('#' . $reg . '#usi', $lctext, $matches)) { //this is not the best way for snippet generation but the fastest I could find $q = $words[0]; //use first word for snippet creation $p = utf8_strpos($lctext, $q); $f = $p - 100; $l = utf8_strlen($q) + 200; if ($f < 0) { $f = 0; } $snippet = '<span class="search_sep"> ... </span>' . htmlspecialchars(utf8_substr($text, $f, $l)) . '<span class="search_sep"> ... </span>'; $mark = '(' . join('|', $words) . ')'; $snippet = preg_replace('#' . $mark . '#si', '<strong class="search_hit">\\1</strong>', $snippet); $data[] = array('id' => pathID($file), 'count' => preg_match_all('#' . $mark . '#usi', $lctext, $matches), 'poswords' => join(' ', $words), 'snippet' => $snippet); } return true; }
/** * Main process of the action plugin. * Process base wiki page text and type text to generate fusion wiki page. */ function _weaki_headers($filenames){ $rawTypeFile = io_readfile($filenames[type]); $rawBaseFile = io_readfile($filenames[base]); $linesBaseFile = explode("\n", $rawBaseFile); $type_headers = $this->_get_type_headers($rawTypeFile); // get match and not match base lines $NotMatchBaseLines[] = "\n====== WeakType not match data ======"; $found_line_base_h_level = 10;// always lowest type header for comparision foreach($linesBaseFile as $lineBase){ // cut off weaktype activation line if (strtolower($lineBase) == '[weaktype]') $lineBase = ''; $line_base_h_level = $this -> _get_header_level($lineBase); // if header and header level below previous founded one if (($lineBase[0] == '=') && ($line_base_h_level <= $found_line_base_h_level)){ $found = False; foreach($type_headers as $type_header){ $typeTitleH = $type_header[0]; $typeLevelH = $type_header[1]; $markupTypeH = $this -> _get_header_markup($typeTitleH, $typeLevelH); $baseTitleH = trim($lineBase, " ="); if($baseTitleH == $typeTitleH){ $MatchBaseLines[] = $this->_get_header_markup($baseTitleH, $typeLevelH); $found = True; $found_line_base_h_level = $line_base_h_level; break; } } if(!$found ) $NotMatchBaseLines[] = $lineBase; }else{ if($found){ $MatchBaseLines[] = $lineBase; }else{ $NotMatchBaseLines[] = $lineBase; } } } //second pass: reptint match data and add not match type headers foreach($type_headers as $key1 => $type_header){ $typeTitleH = $type_header[0]; $typeLevelH = $type_header[1]; $markupTypeH = $this -> _get_header_markup($typeTitleH, $typeLevelH); $found_type_h_level = $typeLevelH; $found = False; $foundH = False; foreach($MatchBaseLines as $MatchBaseLine){ $MatchBaseLine_levelh = $this -> _get_header_level($MatchBaseLine); if (($MatchBaseLine[0] == '=') && ($MatchBaseLine_levelh <= $found_type_h_level)){ if($markupTypeH == $MatchBaseLine){ $MatchBaseLines2[] = $MatchBaseLine; $found = True; $foundH = True; $found_type_h_level = $MatchBaseLine_levelh; }else{ $found = False; } }else{ if($found) $MatchBaseLines2[] = $MatchBaseLine; } } if(!$foundH) $MatchBaseLines2[] = $markupTypeH; } $text = implode("\n", $MatchBaseLines2); $text .= implode("\n", $NotMatchBaseLines); return $text; }
/** * Send a new password * * This function handles both phases of the password reset: * * - handling the first request of password reset * - validating the password reset auth token * * @author Benoit Chesneau <*****@*****.**> * @author Chris Smith <*****@*****.**> * @author Andreas Gohr <*****@*****.**> * * @return bool true on success, false on any error */ function act_resendpwd() { global $lang; global $conf; /* @var auth_basic $auth */ global $auth; /* @var Input $INPUT */ global $INPUT; if (!actionOK('resendpwd')) { msg($lang['resendna'], -1); return false; } $token = preg_replace('/[^a-f0-9]+/', '', $INPUT->str('pwauth')); if ($token) { // we're in token phase - get user info from token $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; if (!@file_exists($tfile)) { msg($lang['resendpwdbadauth'], -1); $INPUT->remove('pwauth'); return false; } // token is only valid for 3 days if (time() - filemtime($tfile) > 3 * 60 * 60 * 24) { msg($lang['resendpwdbadauth'], -1); $INPUT->remove('pwauth'); @unlink($tfile); return false; } $user = io_readfile($tfile); $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } if (!$conf['autopasswd']) { // we let the user choose a password $pass = $INPUT->str('pass'); // password given correctly? if (!$pass) { return false; } if ($pass != $INPUT->str('passchk')) { msg($lang['regbadpass'], -1); return false; } // change it if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } } else { // autogenerate the password and send by mail $pass = auth_pwgen(); if (!$auth->triggerUserMod('modify', array($user, array('pass' => $pass)))) { msg('error modifying user data', -1); return false; } if (auth_sendPassword($user, $pass)) { msg($lang['resendpwdsuccess'], 1); } else { msg($lang['regmailfail'], -1); } } @unlink($tfile); return true; } else { // we're in request phase if (!$INPUT->post->bool('save')) { return false; } if (!$INPUT->post->str('login')) { msg($lang['resendpwdmissing'], -1); return false; } else { $user = trim($auth->cleanUser($INPUT->post->str('login'))); } $userinfo = $auth->getUserData($user); if (!$userinfo['mail']) { msg($lang['resendpwdnouser'], -1); return false; } // generate auth token $token = md5(auth_cookiesalt() . $user); //secret but user based $tfile = $conf['cachedir'] . '/' . $token[0] . '/' . $token . '.pwauth'; $url = wl('', array('do' => 'resendpwd', 'pwauth' => $token), true, '&'); io_saveFile($tfile, $user); $text = rawLocale('pwconfirm'); $trep = array('FULLNAME' => $userinfo['name'], 'LOGIN' => $user, 'CONFIRM' => $url); $mail = new Mailer(); $mail->to($userinfo['name'] . ' <' . $userinfo['mail'] . '>'); $mail->subject($lang['regpwmail']); $mail->setBody($text, $trep); if ($mail->send()) { msg($lang['resendpwdconfirm'], 1); } else { msg($lang['regmailfail'], -1); } return true; } // never reached }
/** * Sends a notify mail on new comment * * @param array $comment data array of the new comment * * @author Andreas Gohr <*****@*****.**> * @author Esther Brunner <*****@*****.**> */ function _notify($comment, &$subscribers) { global $conf; global $ID; global $INFO; $notify_text = io_readfile($this->localfn('subscribermail')); $confirm_text = io_readfile($this->localfn('confirmsubscribe')); $subject_notify = '[' . $conf['title'] . '] ' . $this->getLang('mail_newcomment'); $subject_subscribe = '[' . $conf['title'] . '] ' . $this->getLang('subscribe'); $from = $conf['mailfrom']; $from = str_replace('@USER@', $_SERVER['REMOTE_USER'], $from); $from = str_replace('@NAME@', $INFO['userinfo']['name'], $from); $from = str_replace('@MAIL@', $INFO['userinfo']['mail'], $from); $search = array('@PAGE@', '@TITLE@', '@DATE@', '@NAME@', '@TEXT@', '@COMMENTURL@', '@UNSUBSCRIBE@', '@DOKUWIKIURL@'); // notify page subscribers if ($conf['subscribers'] || $conf['notify']) { $list = explode(',', subscription_addresslist($ID)); $to = $conf['notify']; $bcc = implode(',', $list); $replace = array($ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment_' . $comment['cid'], wl($ID, 'do=unsubscribe', true, '&'), DOKU_URL); $body = str_replace($search, $replace, $notify_text); mail_send($to, $subject_notify, $body, $from, '', $bcc); } // notify comment subscribers if (!empty($subscribers)) { foreach ($subscribers as $mail => $data) { $to = $mail; if ($data['active']) { $replace = array($ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment_' . $comment['cid'], wl($ID, 'do=discussion_unsubscribe&hash=' . $data['hash'], true, '&'), DOKU_URL); $body = str_replace($search, $replace, $notify_text); mail_send($to, $subject_notify, $body, $from); } elseif (!$data['active'] && !$data['confirmsent']) { $search = array('@PAGE@', '@TITLE@', '@SUBSCRIBE@', '@DOKUWIKIURL@'); $replace = array($ID, $conf['title'], wl($ID, 'do=discussion_confirmsubscribe&hash=' . $data['hash'], true, '&'), DOKU_URL); $body = str_replace($search, $replace, $confirm_text); mail_send($to, $subject_subscribe, $body, $from); $subscribers[$mail]['confirmsent'] = true; } } } }