コード例 #1
0
 /**
  * Makes sure the given data fits with the given type
  */
 function _cleanData($value, $type)
 {
     $value = trim($value);
     if (!$value) {
         return '';
     }
     if (is_array($type)) {
         if (isset($type['enum']) && !preg_match('/(^|,\\s*)' . preg_quote_cb($value) . '($|\\s*,)/', $type['enum'])) {
             return '';
         }
         $type = $type['type'];
     }
     switch ($type) {
         case 'dt':
             if (preg_match('/^(\\d\\d\\d\\d)-(\\d\\d?)-(\\d\\d?)$/', $value, $m)) {
                 return sprintf('%d-%02d-%02d', $m[1], $m[2], $m[3]);
             }
             return '';
         case 'url':
             if (!preg_match('!^[a-z]+://!i', $value)) {
                 $value = 'http://' . $value;
             }
             return $value;
         case 'mail':
             $email = '';
             $name = '';
             $part = '';
             $parts = preg_split('/\\s+/', $value);
             do {
                 $part = array_shift($parts);
                 if (!$email && mail_isvalid($part)) {
                     $email = strtolower($part);
                     continue;
                 }
                 $name .= $part . ' ';
             } while ($part);
             return trim($email . ' ' . $name);
         case 'page':
         case 'nspage':
             return cleanID($value);
         default:
             return $value;
     }
 }
コード例 #2
0
ファイル: subscription.php プロジェクト: nextghost/dokuwiki
/**
 * Return a string with the email addresses of all the
 * users subscribed to a page
 *
 * This is the default action for COMMON_NOTIFY_ADDRESSLIST.
 *
 * @param array $data Containing $id (the page id), $self (whether the author
 *                    should be notified, $addresslist (current email address
 *                    list)
 *
 * @author Steven Danz <*****@*****.**>
 * @author Adrian Lang <*****@*****.**>
 */
function subscription_addresslist(&$data)
{
    global $conf;
    global $auth;
    $id = $data['id'];
    $self = $data['self'];
    $addresslist = $data['addresslist'];
    if (!$conf['subscribers'] || $auth === null) {
        return '';
    }
    $pres = array('style' => 'every', 'escaped' => true);
    if (!$self && isset($_SERVER['REMOTE_USER'])) {
        $pres['user'] = '******' . preg_quote_cb($_SERVER['REMOTE_USER']) . '(?: |$))\\S+)';
    }
    $subs = subscription_find($id, $pres);
    $emails = array();
    foreach ($subs as $by_targets) {
        foreach ($by_targets as $sub) {
            $info = $auth->getUserData($sub[0]);
            if ($info === false) {
                continue;
            }
            $level = auth_aclcheck($id, $sub[0], $info['grps']);
            if ($level >= AUTH_READ) {
                if (strcasecmp($info['mail'], $conf['notify']) != 0) {
                    $emails[$sub[0]] = $info['mail'];
                }
            }
        }
    }
    $data['addresslist'] = trim($addresslist . ',' . implode(',', $emails), ',');
}
コード例 #3
0
ファイル: actiontemplate.php プロジェクト: rusidea/analitika
 /**
  * Load template(s) for targetpage as given via action field
  *
  * @param string $tpl    template name as given in form
  * @return string parsed templatename
  */
 protected function getActionTargetpages($tpl)
 {
     global $USERINFO;
     global $conf;
     global $ID;
     $runas = $this->getConf('runas');
     if ($tpl == '_') {
         // use namespace template
         if (!isset($this->targetpages[$this->pagename])) {
             $this->targetpages[$this->pagename] = pageTemplate(array($this->pagename));
         }
     } elseif ($tpl !== '!') {
         $tpl = $this->replace($tpl);
         resolve_pageid(getNS($ID), $tpl, $ignored);
         $backup = array();
         if ($runas) {
             // Hack user credentials.
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $template_pages = array();
         //search checks acl (as runas)
         $opts = array('depth' => 0, 'listfiles' => true, 'showhidden' => true);
         search($template_pages, $conf['datadir'], 'search_universal', $opts, str_replace(':', '/', getNS($tpl)));
         foreach ($template_pages as $template_page) {
             $templatepageid = cleanID($template_page['id']);
             // try to replace $tpl path with $this->pagename path in the founded $templatepageid
             // - a single-page template will only match on itself and will be replaced,
             //   other newtargets are pages in same namespace, so aren't changed
             // - a namespace as template will match at the namespaces-part of the path of pages in this namespace
             //   so these newtargets are changed
             // if there exist a single-page and a namespace with name $tpl, both are selected
             $newTargetpageid = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $this->pagename . '$1', $templatepageid);
             if ($newTargetpageid === $templatepageid) {
                 // only a single-page template or page in the namespace template
                 // which matches the $tpl path are changed
                 continue;
             }
             if (!isset($this->targetpages[$newTargetpageid])) {
                 $this->addParsedTargetpage($newTargetpageid, $templatepageid);
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     return $tpl;
 }
コード例 #4
0
 function run($data, $thanks, $argv)
 {
     global $ID;
     global $conf;
     global $USERINFO;
     list($tpl, $pagename, $sep) = $argv;
     if (is_null($sep)) {
         $sep = $conf['sepchar'];
     }
     $runas = $this->getConf('runas');
     $patterns = array();
     $values = array();
     $templates = array();
     // run through fields
     foreach ($data as $opt) {
         $label = $opt->getParam('label');
         $value = $opt->getParam('value');
         // prepare replacements
         if (!is_null($label)) {
             $patterns[$label] = '/(@@|##)' . preg_quote($label, '/') . '(?:\\|([^|]*?))' . (is_null($value) ? '' : '?') . '\\1/si';
             $values[$label] = is_null($value) ? '$2' : $value;
             $patterns[$label . '|'] = '/(@@|##)' . preg_quote($label, '/') . '(?:\\|(.*?))(?:\\|(.*?))\\1/si';
             $values[$label . '|'] = is_null($value) ? '$2' : '$3';
         }
         // handle pagenames
         $pname = $opt->getParam('pagename');
         if (!is_null($pname)) {
             $pagename .= $sep . $pname;
         }
         if (!is_null($opt->getParam('page_tpl')) && !is_null($opt->getParam('page_tgt'))) {
             $page_tpl = $this->replace($patterns, $values, $opt->getParam('page_tpl'));
             if (auth_aclcheck($page_tpl, $runas ? $runas : $_SERVER['REMOTE_USER'], $USERINFO['grps']) >= AUTH_READ) {
                 $templates[$opt->getParam('page_tgt')] = rawWiki($page_tpl);
             }
         }
     }
     $pagename = $this->replace($patterns, $values, $pagename);
     // check pagename
     $pagename = cleanID($pagename);
     if ($pagename === '') {
         throw new Exception($this->getLang('e_pagename'));
     }
     $_templates = array();
     foreach ($templates as $k => $v) {
         $_templates[cleanID("{$pagename}:{$k}")] = $v;
     }
     $templates = $_templates;
     // get templates
     if ($tpl == '_') {
         // use namespace template
         if (!isset($templates[$pagename])) {
             $templates[$pagename] = pageTemplate(array($pagename));
         }
     } elseif ($tpl !== '!') {
         // Namespace link
         require_once DOKU_INC . 'inc/search.php';
         if ($runas) {
             // Hack user credentials.
             global $USERINFO;
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $t_pages = array();
         search($t_pages, $conf['datadir'], 'search_universal', array('depth' => 0, 'listfiles' => true), str_replace(':', '/', getNS($tpl)));
         foreach ($t_pages as $t_page) {
             $t_name = cleanID($t_page['id']);
             $p_name = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $pagename . '$1', $t_name);
             if ($p_name === $t_name) {
                 // When using a single-page template, ignore other pages
                 // in the same namespace.
                 continue;
             }
             if (!isset($templates[$p_name])) {
                 // load page data and do default pattern replacements like
                 // namespace templates do
                 $data = array('id' => $p_name, 'tpl' => rawWiki($t_name), 'doreplace' => true);
                 parsePageTemplate($data);
                 $templates[$p_name] = $data['tpl'];
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             global $USERINFO;
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     if (empty($templates)) {
         throw new Exception(sprintf($this->getLang('e_template'), $tpl));
     }
     // check all target pagenames
     foreach (array_keys($templates) as $pname) {
         // prevent overriding already existing pages
         if (page_exists($pname)) {
             throw new Exception(sprintf($this->getLang('e_pageexists'), html_wikilink($pname)));
         }
         // check auth
         if ($runas) {
             $auth = auth_aclcheck($pname, $runas, array());
         } else {
             $auth = auth_quickaclcheck($pname);
         }
         if ($auth < AUTH_CREATE) {
             throw new Exception($this->getLang('e_denied'));
         }
     }
     foreach ($templates as $pname => $template) {
         // set NSBASE var to make certain dataplugin constructs easier
         $patterns['__nsbase__'] = '/@NSBASE@/';
         $values['__nsbase__'] = noNS(getNS($pname));
         // save page
         saveWikiText($pname, $this->replace($patterns, $values, $template, false), sprintf($this->getLang('summary'), $ID));
     }
     $ret = "<p>{$thanks}</p>";
     // Build result tree
     $pages = array_keys($templates);
     usort($pages, array($this, '_sort'));
     $oldid = $ID;
     $data = array();
     $last_folder = array();
     foreach ($pages as $ID) {
         $lvl = substr_count($ID, ':');
         for ($n = 0; $n < $lvl; ++$n) {
             if (!isset($last_folder[$n]) || strpos($ID, $last_folder[$n]['id']) !== 0) {
                 $last_folder[$n] = array('id' => substr($ID, 0, strpos($ID, ':', ($n > 0 ? strlen($last_folder[$n - 1]['id']) : 0) + 1) + 1), 'level' => $n + 1, 'open' => 1);
                 $data[] = $last_folder[$n];
             }
         }
         $data[] = array('id' => $ID, 'level' => 1 + substr_count($ID, ':'), 'type' => 'f');
     }
     $ret .= html_buildlist($data, 'idx', array($this, 'html_list_index'), 'html_li_index');
     // Add indexer bugs for every just-created page
     $ret .= '<div class="no">';
     ob_start();
     foreach ($pages as $ID) {
         // indexerWebBug uses ID and INFO[exists], but the bureaucracy form
         // page always exists, as does the just-saved page, so INFO[exists]
         // is correct in any case
         tpl_indexerWebBug();
         // the iframe will trigger real rendering of the pages to make sure
         // any used plugins are initialized (eg. the do plugin)
         echo '<iframe src="' . wl($ID, array('do' => 'export_html')) . '" width="1" height="1" style="visibility:hidden"></iframe>';
     }
     $ret .= ob_get_contents();
     ob_end_clean();
     $ID = $oldid;
     $ret .= '</div>';
     return $ret;
 }
コード例 #5
0
 /**
  * @param $fields
  * @param $tpl
  * @param $runas
  * @return string template
  */
 function getTemplates($fields, $tpl, $runas)
 {
     global $USERINFO;
     global $conf;
     if ($tpl == '_') {
         // use namespace template
         if (!isset($this->templates[$this->pagename])) {
             $this->templates[$this->pagename] = pageTemplate(array($this->pagename));
         }
     } elseif ($tpl !== '!') {
         $tpl = $this->replaceDefault($tpl);
         // Namespace link
         if ($runas) {
             // Hack user credentials.
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $t_pages = array();
         search($t_pages, $conf['datadir'], 'search_universal', array('depth' => 0, 'listfiles' => true, 'showhidden' => true), str_replace(':', '/', getNS($tpl)));
         foreach ($t_pages as $t_page) {
             $t_name = cleanID($t_page['id']);
             $p_name = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $this->pagename . '$1', $t_name);
             if ($p_name === $t_name) {
                 // When using a single-page template, ignore other pages
                 // in the same namespace.
                 continue;
             }
             if (!isset($this->templates[$p_name])) {
                 // load page data and do default pattern replacements like
                 // namespace templates do
                 $data = array('id' => $p_name, 'tpl' => rawWiki($t_name), 'doreplace' => true);
                 parsePageTemplate($data);
                 $this->templates[$p_name] = $this->replace(array('__lang__' => $this->patterns['__lang__'], '__trans__' => $this->patterns['__trans__']), array('__lang__' => $this->values['__lang__'], '__trans__' => $this->values['__trans__']), $data['tpl'], false);
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     return $tpl;
 }