Пример #1
0
function count_files($no = 0, $pref = '')
{
    // 0:DATA, 1:TB, 2:Referer, 3: DIFF, 4:BKUP, 5:CTR
    static $dir = array(DATA_DIR, TRACKBACK_DIR, REFERER_DIR, DIFF_DIR, BACKUP_DIR, COUNTER_DIR);
    static $ext = array('.txt', '.txt', '.ref', '.txt', BACKUP_EXT, '.count');
    // コンテンツ管理者以上は、全てのファイルを対象にする
    if (!auth::check_role('role_adm_contents')) {
        $pages = get_existpages($dir[$no], $ext[$no]);
    } else {
        // 自分が閲覧できるページ数のみ戻す
        $pages = auth::get_existpages($dir[$no], $ext[$no]);
    }
    // 条件なし
    if (empty($pref)) {
        return count($pages);
    }
    // 指定文書のカウント
    $i = 0;
    foreach ($pages as $page) {
        if (strpos($page, $pref) === 0) {
            $i++;
        }
    }
    return $i;
}
Пример #2
0
 /**
  * Block Plugin Main Function
  */
 function convert()
 {
     sonots::init_myerror();
     do {
         // try
         $args = func_get_args();
         $argline = csv_implode(',', $args);
         $argoptions = PluginSonotsOption::parse_option_line($argline);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = $this->check_options($options, $unknowns, $this->conf_options);
         if (sonots::mycatch()) {
             break;
         }
         if (isset($options['tag'])) {
             $plugin_tag = new PluginSonotsTag();
             $pages = $plugin_tag->get_taggedpages($options['tag']);
         } elseif (isset($options['prefix'])) {
             $pages = sonots::get_existpages($options['prefix']);
         } else {
             $pages = get_existpages();
         }
         $pagelist = $this->pagelist($pages, $options, $argoptions);
         $navipages = $this->get_navipages($pagelist, $options);
         $html = $this->display_navi($navipages, $options['look'], $options['border'], $this->conf['printcss']);
         return $html;
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return '<p>#' . $this->plugin . '(): ' . sonots::mycatch() . '</p>';
     }
 }
Пример #3
0
function plugin_deleted_action()
{
    global $vars;
    global $_deleted_plugin_title, $_deleted_plugin_title_withfilename;
    $dir = isset($vars['dir']) ? $vars['dir'] : 'backup';
    $withfilename = isset($vars['file']);
    $_DIR['diff']['dir'] = DIFF_DIR;
    $_DIR['diff']['ext'] = '.txt';
    $_DIR['backup']['dir'] = BACKUP_DIR;
    $_DIR['backup']['ext'] = BACKUP_EXT;
    // .gz or .txt
    //$_DIR['cache' ]['dir'] = CACHE_DIR; // No way to delete them via web browser now
    //$_DIR['cache' ]['ext'] = '.ref';
    //$_DIR['cache' ]['ext'] = '.rel';
    if (!isset($_DIR[$dir])) {
        return array('msg' => 'Deleted plugin', 'body' => 'No such setting: Choose backup or diff');
    }
    $deleted_pages = array_diff(get_existpages($_DIR[$dir]['dir'], $_DIR[$dir]['ext']), get_existpages());
    if ($withfilename) {
        $retval['msg'] = $_deleted_plugin_title_withfilename;
    } else {
        $retval['msg'] = $_deleted_plugin_title;
    }
    $retval['body'] = page_list($deleted_pages, $dir, $withfilename);
    return $retval;
}
Пример #4
0
function plugin_ls_convert()
{
    global $vars;
    $with_title = FALSE;
    if (func_num_args()) {
        $args = func_get_args();
        $with_title = in_array('title', $args);
    }
    $prefix = $vars['page'] . '/';
    $pages = array();
    foreach (get_existpages() as $page) {
        if (strpos($page, $prefix) === 0) {
            $pages[] = $page;
        }
    }
    natcasesort($pages);
    $ls = array();
    foreach ($pages as $page) {
        $comment = '';
        if ($with_title) {
            list($comment) = get_source($page);
            // 見出しの固有ID部を削除
            $comment = preg_replace('/^(\\*{1,3}.*)\\[#[A-Za-z][\\w-]+\\](.*)$/', '$1$2', $comment);
            $comment = '- ' . ereg_replace('^[-*]+', '', $comment);
        }
        $ls[] = "-[[{$page}]] {$comment}";
    }
    return convert_html($ls);
}
Пример #5
0
function plugin_tb_action()
{
    global $trackback, $vars;
    if ($trackback && isset($vars['url'])) {
        // Receive and save a TrackBack Ping (both GET and POST)
        $url = $vars['url'];
        $tb_id = isset($vars['tb_id']) ? $vars['tb_id'] : '';
        list($error, $message) = plugin_tb_save($url, $tb_id);
        // Output the response
        plugin_tb_output_response($error, $message);
        exit;
    } else {
        if ($trackback && isset($vars['__mode']) && isset($vars['tb_id'])) {
            // Show TrackBacks received (and exit)
            switch ($vars['__mode']) {
                case 'rss':
                    plugin_tb_output_rsslist($vars['tb_id']);
                    break;
                case 'view':
                    plugin_tb_output_htmllist($vars['tb_id']);
                    break;
            }
            exit;
        } else {
            // Show List of pages that TrackBacks reached
            $pages = get_existpages(TRACKBACK_DIR, '.txt');
            if (!empty($pages)) {
                return array('msg' => 'Trackback list', 'body' => page_list($pages, 'read', false));
            } else {
                return array('msg' => '', 'body' => '');
            }
        }
    }
}
Пример #6
0
function plugin_ls2_show_lists($prefix, &$params)
{
    global $_ls2_err_nopages;
    $pages = array();
    if ($prefix != '') {
        foreach (get_existpages() as $_page) {
            if (strpos($_page, $prefix) === 0) {
                $pages[] = $_page;
            }
        }
    } else {
        $pages = get_existpages();
    }
    natcasesort($pages);
    if ($params['reverse']) {
        $pages = array_reverse($pages);
    }
    foreach ($pages as $page) {
        $params['page_ ' . $page] = 0;
    }
    if (empty($pages)) {
        return str_replace('$1', htmlsc($prefix), $_ls2_err_nopages);
    } else {
        $params['result'] = $params['saved'] = array();
        foreach ($pages as $page) {
            plugin_ls2_get_headings($page, $params, 1);
        }
        return join("\n", $params['result']) . join("\n", $params['saved']);
    }
}
Пример #7
0
function build_directory_list($roots, $option)
{
    global $WikiName, $BracketName, $script;
    $existingPages = get_existpages();
    foreach ($roots as $root) {
        $matched = false;
        foreach ($existingPages as $page) {
            $page = strip_bracket($page);
            //			if (preg_match("/^$root.*$/", $page)){
            if (strpos($page, $root) === 0) {
                if ($option['directory only'] && strrpos($page, "/") >= strlen($root)) {
                    $page = substr($page, 0, strrpos($page, "/"));
                    $list["directory"][] = $page;
                } else {
                    $list["directory"][] = $page;
                }
                while (strrpos($page, "/") >= strlen($root)) {
                    $page = substr($page, 0, strrpos($page, "/"));
                    $list["directory"][] = $page;
                }
                $matched = true;
            }
        }
        if (!$matched) {
            $list["directory"][] = $root;
            $warnings[] = "<font color=\"red\">#{$root} は該当するページがありません。</font>\n\t\t\t(<a href=\"{$script}?" . rawurlencode($root) . "\">作成</a>)<br>\n";
        }
    }
    $list["directory"] = array_unique($list["directory"]);
    natcasesort($list["directory"]);
    if (!$option["quiet"]) {
        $list["warning"] = $warnings;
    }
    return $list;
}
Пример #8
0
function plugin_yetlist_action()
{
    global $non_list;
    global $whatsdeleted;
    $qm = get_qm();
    $retval = array('msg' => $qm->m['plg_yetlist']['title'], 'body' => '');
    // Diff
    $pages = array_diff(get_existpages(CACHE_DIR, '.ref'), get_existpages());
    if (empty($pages)) {
        $retval['body'] = $qm->m['plg_yetlist']['err_notexist'];
        return $retval;
    }
    $empty = TRUE;
    // Load .ref files and Output
    $script = get_script_uri();
    $refer_regex = '/' . $non_list . '|^' . preg_quote($whatsdeleted, '/') . '$/S';
    asort($pages, SORT_STRING);
    foreach ($pages as $file => $page) {
        $refer = array();
        foreach (file(CACHE_DIR . $file) as $line) {
            list($_page) = explode("\t", rtrim($line));
            $refer[] = $_page;
        }
        // Diff
        $refer = array_diff($refer, preg_grep($refer_regex, $refer));
        if (!empty($refer)) {
            $empty = FALSE;
            $refer = array_unique($refer);
            sort($refer, SORT_STRING);
            $r_refer = '';
            $link_refs = array();
            foreach ($refer as $_refer) {
                $r_refer = rawurlencode($_refer);
                $link_refs[] = '<a href="' . $script . '?' . $r_refer . '">' . htmlspecialchars($_refer) . '</a>';
            }
            $link_ref = join(' ', $link_refs);
            unset($link_refs);
            $s_page = htmlspecialchars($page);
            if (PKWK_READONLY) {
                $href = $s_page;
            } else {
                // Dangling link
                $href = '<span class="noexists">' . $s_page . '<a href="' . $script . '?cmd=edit&amp;page=' . rawurlencode($page) . '&amp;refer=' . $r_refer . '">' . $qm->m['fmt_symbol_noexists'] . '</a></span>';
            }
            $retval['body'] .= '<li>' . $href . ' <em>(' . $link_ref . ')</em></li>' . "\n";
        }
    }
    if ($empty) {
        $retval['body'] = $qm->m['plg_yetlist']['err_notexist'];
        return $retval;
    }
    if ($retval['body'] != '') {
        $retval['body'] = '<ul>' . "\n" . $retval['body'] . '</ul>' . "\n";
    }
    return $retval;
}
Пример #9
0
function plugin_list_getlist($withfilename = false)
{
    global $non_list, $whatsnew;
    $pages = array_diff(get_existpages(), array($whatsnew));
    if (!$withfilename) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    if (empty($pages)) {
        return '';
    }
    return page_list($pages, 'read', $withfilename);
}
Пример #10
0
 /**
  * Get filtered pages
  *
  * @param string $filter regular expression
  * @param string $page 
  * @return array pages
  */
 function get_filtered_pages($filter, $page)
 {
     if ($page != '') {
         return array($page);
     }
     $pages = get_existpages();
     //auth::get_existpages();
     if ($filter != '') {
         $filter = '/' . str_replace('/', '\\/', $filter) . '/';
         foreach ($pages as $file => $apage) {
             if (!preg_match($filter, $apage)) {
                 unset($pages[$file]);
             }
         }
     }
     return $pages;
 }
Пример #11
0
function plugin_list_getlist($withfilename = FALSE)
{
    global $non_list, $whatsnew, $style_name;
    $pages = array_diff(get_existpages(), array($whatsnew));
    if (!$withfilename) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    if (empty($pages)) {
        return '';
    }
    if (ss_admin_check()) {
        $style_name = '..';
        return plugin_list_create_html(plugin_list_array($pages), $withfilename);
    } else {
        return page_list($pages, 'read', $withfilename);
    }
}
Пример #12
0
function plugin_random_action()
{
    global $vars;
    $pattern = strip_bracket($vars['refer']) . '/';
    $pages = array();
    foreach (get_existpages() as $_page) {
        if (strpos($_page, $pattern) === 0) {
            $pages[$_page] = strip_bracket($_page);
        }
    }
    srand((double) microtime() * 1000000);
    $page = array_rand($pages);
    if ($page != '') {
        $vars['refer'] = $page;
    }
    return array('body' => '', 'msg' => '');
}
Пример #13
0
function plugin_referer_action()
{
    global $vars, $referer;
    $qm = get_qm();
    // Setting: Off
    if (!$referer) {
        return array('msg' => '', 'body' => '');
    }
    if (isset($vars['page']) && is_page($vars['page'])) {
        $sort = empty($vars['sort']) ? '0d' : $vars['sort'];
        return array('msg' => $qm->m['plg_referer']['title'], 'body' => plugin_referer_body($vars['page'], $sort));
    }
    $pages = get_existpages(TRACKBACK_DIR, '.ref');
    if (empty($pages)) {
        return array('msg' => '', 'body' => '');
    } else {
        return array('msg' => $qm->m['plg_referer']['title_list'], 'body' => page_list($pages, 'referer', FALSE));
    }
}
Пример #14
0
function plugin_referer_action()
{
    global $vars, $referer;
    global $_referer_msg;
    // Setting: Off
    if (!$referer) {
        return array('msg' => '', 'body' => '');
    }
    if (isset($vars['page']) && is_page($vars['page'])) {
        $sort = empty($vars['sort']) ? '0d' : $vars['sort'];
        return array('msg' => $_referer_msg['msg_H0_Refer'], 'body' => plugin_referer_body($vars['page'], $sort));
    }
    $pages = get_existpages(TRACKBACK_DIR, '.ref');
    if (empty($pages)) {
        return array('msg' => '', 'body' => '');
    } else {
        return array('msg' => 'referer list', 'body' => page_list($pages, 'referer', false));
    }
}
Пример #15
0
 /**
  * Generate the specific meta infomration to pages
  *
  * @access public
  * @param string $metakey meta information name
  * @param array $args if arguments required to set meta information
  * @version $Id: v 1.0 2008-06-07 07:23:17Z sonots $
  */
 function gen_metas($metakey, $args = array())
 {
     switch ($metakey) {
         case 'leaf':
             // tree can't be constructed item by item
             $leafs = sonots::get_tree(get_existpages());
             foreach ($this->metapages as $i => $val) {
                 $page = $this->metapages[$i]->page;
                 $this->metapages[$i]->leaf = $leafs[$page];
             }
             break;
         default:
             // others can be
             $metapages =& $this->metapages;
             foreach ($metapages as $i => $val) {
                 call_user_func_array(array(&$metapages[$i], 'gen_' . $metakey), $args);
             }
             break;
     }
 }
Пример #16
0
function plugin_touchgraph_ref()
{
    foreach (get_existpages() as $page) {
        if (check_non_list($page)) {
            continue;
        }
        $file = CACHE_DIR . encode($page) . '.ref';
        if (file_exists($file)) {
            echo $page;
            foreach (file($file) as $line) {
                list($name) = explode("\t", $line);
                if (check_non_list($name)) {
                    continue;
                }
                echo ' ', $name;
            }
            echo "\n";
        }
    }
}
Пример #17
0
function plugin_grepall_grep()
{
    global $vars, $defaultpage;
    $page = isset($vars['page']) ? $vars['page'] : $defultpage;
    $filter = isset($vars['filter']) ? $vars['filter'] : '';
    $grep = isset($vars['grep']) ? $vars['grep'] : '';
    // page lists
    if ($page !== '') {
        if (!is_page($page)) {
            $body = '<p>' . htmlspecialchars($page) . ' does not exist.</p>';
            return $body;
        }
        $pages = (array) $page;
    } else {
        $pages = get_existpages();
        if ($filter !== '') {
            $pages = preg_grep('/' . preg_quote($filter, '/') . '/', $pages);
        }
    }
    // grep
    $body = '';
    foreach ($pages as $page) {
        if (!check_readable($page)) {
            $body = '<p>' . htmlspecialchars($page) . ' is not readable.</p>';
            return $body;
        }
        $lines = get_source($page);
        $lines = preg_grep('/' . preg_quote($grep, '/') . '/', $lines);
        if (empty($lines)) {
            continue;
        }
        $contents = '';
        foreach ($lines as $i => $line) {
            $contents .= sprintf('%04d:', $i) . htmlspecialchars($line);
        }
        $body .= make_pagelink($page) . '<br />' . "\n";
        $body .= '<pre>' . htmlspecialchars($contents) . '</pre>';
    }
    return $body;
}
Пример #18
0
function tb_id2page($tb_id)
{
    static $pages, $cache = array();
    if (isset($cache[$tb_id])) {
        return $cache[$tb_id];
    }
    if (!isset($pages)) {
        $pages = get_existpages();
    }
    foreach ($pages as $page) {
        $_tb_id = tb_get_id($page);
        $cache[$_tb_id] = $page;
        unset($pages[$page]);
        if ($tb_id == $_tb_id) {
            return $cache[$tb_id];
        }
        // Found
    }
    $cache[$tb_id] = FALSE;
    return $cache[$tb_id];
    // Not found
}
Пример #19
0
function plugin_deleted_action()
{
    global $vars;
    $qm = get_qm();
    $dir = isset($vars['dir']) ? $vars['dir'] : 'backup';
    $withfilename = isset($vars['file']);
    $_DIR['diff']['dir'] = DIFF_DIR;
    $_DIR['diff']['ext'] = '.txt';
    $_DIR['backup']['dir'] = BACKUP_DIR;
    $_DIR['backup']['ext'] = BACKUP_EXT;
    // .gz or .txt
    if (!isset($_DIR[$dir])) {
        return array('msg' => $qm->m['plg_deleted']['title_err'], 'body' => $qm->m['plg_deleted']['err_no_setting']);
    }
    $deleted_pages = array_diff(get_existpages($_DIR[$dir]['dir'], $_DIR[$dir]['ext']), get_existpages());
    if ($withfilename) {
        $retval['msg'] = $qm->m['plg_deleted']['title_withfilename'];
    } else {
        $retval['msg'] = $qm->m['plg_deleted']['title'];
    }
    $retval['body'] = page_list($deleted_pages, $dir, $withfilename);
    return $retval;
}
Пример #20
0
 /**
  * Action Plugin Main Function
  */
 function action()
 {
     sonots::init_myerror();
     do {
         // try
         global $vars;
         $argoptions = PluginSonotsOption::parse_uri_option_line($vars);
         $argoptions = array_intersect_key($argoptions, $this->conf_options);
         list($options, $unknowns) = PluginSonotsOption::evaluate_options($argoptions, $this->conf_options);
         $options = $this->check_options($options, array(), $this->conf_options);
         if (sonots::mycatch()) {
             break;
         }
         $pages = get_existpages();
         $title = $this->plugin;
         $html = $this->pagelist($pages, $options, $argoptions);
         return array('msg' => $title, 'body' => $html);
     } while (false);
     if (sonots::mycatch()) {
         // catch
         return array('msg' => $this->plugin, 'body' => '<p>' . sonots::mycatch() . '</p>');
     }
 }
Пример #21
0
function plugin_gcounter_init_gcounter()
{
    if (is_page(PLUGIN_GCOUNTER_PAGE)) {
        return;
    }
    if (!exist_plugin('counter')) {
        return;
    }
    $pages = get_existpages();
    $gtotal = $gtoday = $gyesterday = 0;
    $gdate = $gip = '';
    foreach ($pages as $file => $page) {
        $counter = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX;
        $lines = file($counter);
        $lines = array_map('rtrim', $lines);
        $total = $lines[0];
        $date = $lines[1];
        $today = $lines[2];
        $yesterday = $lines[3];
        $ip = $lines[4];
        $gtotal += $total;
        // Ignore today, yesterday because they must take into account
        // $date (when is today), but will be deleted tomorrow.
        // date and ip are also not important.
    }
    $counter = COUNTER_DIR . encode(PLUGIN_GCOUNTER_PAGE) . PLUGIN_COUNTER_SUFFIX;
    $source = "{$gtotal}\n{$gdate}\n{$gtoday}\n{$gyesterday}\n{$gip}\n";
    if (!($fp = fopen($counter, "w"))) {
        return FALSE;
    }
    if (!fwrite($fp, $source)) {
        return FALSE;
    }
    fclose($fp);
    page_write(PLUGIN_GCOUNTER_PAGE, "Log Page for Global Counter\n#counter");
}
Пример #22
0
function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list;
    global $_msg_andresult, $_msg_orresult, $_msg_notfoundresult;
    global $search_auth, $show_passage;
    $retval = array();
    $b_type = $type == 'AND';
    // AND:TRUE OR:FALSE
    $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($keys as $key => $value) {
        $keys[$key] = '/' . $value . '/S';
    }
    $pages = get_existpages();
    // Avoid
    if ($base != '') {
        $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages);
    }
    if (!$search_non_list) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    $pages = array_flip($pages);
    unset($pages[$whatsnew]);
    $count = count($pages);
    foreach (array_keys($pages) as $page) {
        $b_match = FALSE;
        // Search for page name
        if (!$non_format) {
            foreach ($keys as $key) {
                $b_match = preg_match($key, $page);
                if ($b_type xor $b_match) {
                    break;
                }
                // OR
            }
            if ($b_match) {
                continue;
            }
        }
        // Search auth for page contents
        if ($search_auth && !check_readable($page, false, false)) {
            unset($pages[$page]);
            --$count;
        }
        // Search for page contents
        foreach ($keys as $key) {
            $b_match = preg_match($key, get_source($page, TRUE, TRUE));
            if ($b_type xor $b_match) {
                break;
            }
            // OR
        }
        if ($b_match) {
            continue;
        }
        unset($pages[$page]);
        // Miss
    }
    if ($non_format) {
        return array_keys($pages);
    }
    $r_word = rawurlencode($word);
    $s_word = htmlspecialchars($word);
    if (empty($pages)) {
        return str_replace('$1', $s_word, $_msg_notfoundresult);
    }
    ksort($pages);
    $retval = '<ul>' . "\n";
    foreach (array_keys($pages) as $page) {
        $r_page = rawurlencode($page);
        $s_page = htmlspecialchars($page);
        $passage = $show_passage ? ' ' . get_passage(get_filetime($page)) : '';
        $retval .= ' <li><a href="' . $script . '?cmd=read&amp;page=' . $r_page . '&amp;word=' . $r_word . '">' . $s_page . '</a>' . $passage . '</li>' . "\n";
    }
    $retval .= '</ul>' . "\n";
    $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', $count, $b_type ? $_msg_andresult : $_msg_orresult)));
    return $retval;
}
Пример #23
0
function plugin_guiedit_edit_form($page, $postdata, $digest = FALSE, $b_template = TRUE)
{
    global $vars;
    global $load_template_func, $whatsnew;
    global $_button;
    global $notimeupdate;
    global $js_tags, $link_tags, $js_blocks;
    global $guiedit_use_fck;
    $script = get_script_uri();
    // Newly generate $digest or not
    if ($digest === FALSE) {
        $digest = md5(get_source($page, TRUE, TRUE));
    }
    $s_id = isset($vars['id']) ? Utility::htmlsc($vars['id']) : '';
    if (!$guiedit_use_fck) {
        $body = edit_form($page, $postdata, $digest, $b_template);
        $pattern = "/(<input\\s+type=\"hidden\"\\s+name=\"cmd\"\\s+value=\")edit(\"\\s*\\/?>)/";
        $replace = "\$1guiedit\$2\n" . '  <input type="hidden" name="id"     value="' . $s_id . '" />' . '  <input type="hidden" name="text"     value="1" />';
        $body = preg_replace($pattern, $replace, $body);
        return $body;
    }
    //	require_once(GUIEDIT_CONF_PATH . 'guiedit.ini.php');
    //	フォームの値の設定
    $s_digest = Utility::htmlsc($digest);
    $s_page = Utility::htmlsc($page);
    $s_original = Utility::htmlsc($vars['original']);
    $s_ticket = md5(MUTIME);
    if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) {
        // BugTrack/95 fix Problem: browser RSS request with session
        $_SESSION[$s_ticket] = md5(get_ticket() . $digest);
        $_SESSION['origin' . $s_ticket] = md5(get_ticket() . str_replace("\r", '', $s_original));
    }
    // テンプレート
    $template = '';
    if ($load_template_func) {
        global $guiedit_non_list;
        $pages = array();
        foreach (get_existpages() as $_page) {
            if ($_page == $whatsnew || check_non_list($_page)) {
                continue;
            }
            foreach ($guiedit_non_list as $key) {
                $pos = strpos($_page . '/', $key . '/');
                if ($pos !== FALSE && $pos == 0) {
                    continue 2;
                }
            }
            $_s_page = Utility::htmlsc($_page);
            $pages[$_page] = '		<option value="' . $_s_page . '">' . $_s_page . '</option>';
        }
        ksort($pages);
        $s_pages = join("\n", $pages);
        $template = <<<EOD
<select name="template_page">
\t<option value="">-- {$_button['template']} --</option>
{$s_pages}
</select>
<br />
EOD;
    }
    // チェックボックス「タイムスタンプを変更しない」
    $add_notimestamp = '';
    if ($notimeupdate != 0) {
        $checked_time = isset($vars['notimestamp']) ? ' checked="checked"' : '';
        // if ($notimeupdate == 2) {
        if ($notimeupdate == 2 && Auth::check_role('role_contents_admin')) {
            $add_notimestamp = '   ' . '<input type="password" name="pass" size="12" />' . "\n";
        }
        $add_notimestamp = '<input type="checkbox" name="notimestamp" ' . 'id="_edit_form_notimestamp" value="true"' . $checked_time . ' />' . "\n" . '   ' . '<label for="_edit_form_notimestamp"><span class="small">' . $_button['notchangetimestamp'] . '</span></label>' . "\n" . $add_notimestamp . '&nbsp;';
    }
    //	フォーム
    $body = <<<EOD
<div id="guiedit">
\t<form id="guiedit_form" action="{$script}" method="post" style="margin-bottom:0px;">
\t{$template}
\t\t<input type="hidden" name="cmd"    value="guiedit" />
\t\t<input type="hidden" name="page"   value="{$s_page}" />
\t\t<input type="hidden" name="digest" value="{$s_digest}" />
\t\t<input type="hidden" name="ticket" value="{$s_ticket}" />
\t\t<input type="hidden" name="id"     value="{$s_id}" />
\t\t<textarea name="original" rows="1" cols="1" style="display:none">{$s_original}</textarea>
\t\t<textarea name="msg" id="editor"></textarea>
\t\t<div class="pull-left">
\t\t<button type="submit" name="write"   accesskey="s" class="btn btn-primary">{$_button['update']}</button>
\t\t<button type="button" name="preview" accesskey="p" class="btn btn-secondary">{$_button['preview']}</button>
\t\t{$add_notimestamp}
\t\t</div>
\t</form>
\t<form action="{$script}" method="post">
\t\t<input type="hidden" name="cmd"    value="guiedit" />
\t\t<input type="hidden" name="page"   value="{$s_page}" />
\t\t<input type="submit" name="cancel" value="{$_button['cancel']}" class="btn btn-warning" accesskey="c" />
\t</form>
</div>
EOD;
    $js_tags[] = array('type' => 'text/javascript', 'src' => COMMON_URI . 'js/ckeditor/ckeditor.js', 'defer' => 'defer');
    $js_tags[] = array('type' => 'text/javascript', 'src' => COMMON_URI . 'js/ckeditor/adapters/jquery.js', 'defer' => 'defer');
    $js_tags[] = array('type' => 'text/javascript', 'src' => COMMON_URI . 'js/plugin/guiedit/guiedit.js', 'defer' => 'defer');
    return $body;
}
Пример #24
0
 function get_pages()
 {
     $pages = array();
     if ($this->options['page'] != '') {
         $pages = array($this->options['page']);
     } else {
         $pages = get_existpages();
         if ($this->options['prefix'] != '') {
             foreach ($pages as $i => $page) {
                 if (strpos($page, $this->options['prefix']) !== 0) {
                     unset($pages[$i]);
                 }
             }
         }
     }
     return $pages;
 }
Пример #25
0
function plugin_navi_convert()
{
    global $vars, $script, $head_tags;
    global $_navi_prev, $_navi_next, $_navi_up, $_navi_home;
    static $navi = array();
    $current = $vars['page'];
    $reverse = FALSE;
    if (func_num_args()) {
        list($home, $reverse) = array_pad(func_get_args(), 2, '');
        // strip_bracket() is not necessary but compatible
        $home = get_fullname(strip_bracket($home), $current);
        $is_home = $home == $current;
        if (!is_page($home)) {
            return '#navi(contents-page-name): No such page: ' . htmlspecialchars($home) . '<br />';
        } else {
            if (!$is_home && !preg_match('/^' . preg_quote($home, '/') . '/', $current)) {
                return '#navi(' . htmlspecialchars($home) . '): Not a child page like: ' . htmlspecialchars($home . '/' . basename($current)) . '<br />';
            }
        }
        $reverse = strtolower($reverse) == 'reverse';
    } else {
        $home = $vars['page'];
        $is_home = TRUE;
        // $home == $current
    }
    $pages = array();
    $footer = isset($navi[$home]);
    // The first time: FALSE, the second: TRUE
    if (!$footer) {
        $navi[$home] = array('up' => '', 'prev' => '', 'prev1' => '', 'next' => '', 'next1' => '', 'home' => '', 'home1' => '');
        $pages = preg_grep('/^' . preg_quote($home, '/') . '($|\\/)/', get_existpages());
        if (PLUGIN_NAVI_EXCLUSIVE_REGEX != '') {
            // If old PHP could use preg_grep(,,PREG_GREP_INVERT)...
            $pages = array_diff($pages, preg_grep(PLUGIN_NAVI_EXCLUSIVE_REGEX, $pages));
        }
        $pages[] = $current;
        // Sentinel :)
        $pages = array_unique($pages);
        natcasesort($pages);
        if ($reverse) {
            $pages = array_reverse($pages);
        }
        $prev = $home;
        foreach ($pages as $page) {
            if ($page == $current) {
                break;
            }
            $prev = $page;
        }
        $next = current($pages);
        $pos = strrpos($current, '/');
        $up = '';
        if ($pos > 0) {
            $up = substr($current, 0, $pos);
            $navi[$home]['up'] = make_pagelink($up, $_navi_up);
        }
        if (!$is_home) {
            $navi[$home]['prev'] = make_pagelink($prev);
            $navi[$home]['prev1'] = make_pagelink($prev, $_navi_prev);
        }
        if ($next != '') {
            $navi[$home]['next'] = make_pagelink($next);
            $navi[$home]['next1'] = make_pagelink($next, $_navi_next);
        }
        $navi[$home]['home'] = make_pagelink($home);
        $navi[$home]['home1'] = make_pagelink($home, $_navi_home);
        // Generate <link> tag: start next prev(previous) parent(up)
        // Not implemented: contents(toc) search first(begin) last(end)
        if (PLUGIN_NAVI_LINK_TAGS) {
            foreach (array('start' => $home, 'next' => $next, 'prev' => $prev, 'up' => $up) as $rel => $_page) {
                if ($_page != '') {
                    $s_page = htmlspecialchars($_page);
                    $r_page = rawurlencode($_page);
                    $head_tags[] = ' <link rel="' . $rel . '" href="' . $script . '?' . $r_page . '" title="' . $s_page . '" />';
                }
            }
        }
    }
    $ret = '';
    if ($is_home) {
        // Show contents
        $count = count($pages);
        if ($count == 0) {
            return '#navi(contents-page-name): You already view the result<br />';
        } else {
            if ($count == 1) {
                // Sentinel only: Show usage and warning
                $home = htmlspecialchars($home);
                $ret .= '#navi(' . $home . '): No child page like: ' . $home . '/Foo';
            } else {
                $ret .= '<ul>';
                foreach ($pages as $page) {
                    if ($page != $home) {
                        $ret .= ' <li>' . make_pagelink($page) . '</li>';
                    }
                }
                $ret .= '</ul>';
            }
        }
    } else {
        if (!$footer) {
            // Header
            $ret = <<<EOD
<ul class="navi">
 <li class="navi_left">{$navi[$home]['prev1']}</li>
 <li class="navi_right">{$navi[$home]['next1']}</li>
 <li class="navi_none">{$navi[$home]['home']}</li>
</ul>
<hr class="full_hr" />
EOD;
        } else {
            // Footer
            $ret = <<<EOD
<hr class="full_hr" />
<ul class="navi">
 <li class="navi_left">{$navi[$home]['prev1']}<br />{$navi[$home]['prev']}</li>
 <li class="navi_right">{$navi[$home]['next1']}<br />{$navi[$home]['next']}</li>
 <li class="navi_none">{$navi[$home]['home1']}<br />{$navi[$home]['up']}</li>
</ul>
EOD;
        }
    }
    return $ret;
}
Пример #26
0
function plugin_search2_do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
{
    global $script, $whatsnew, $non_list, $search_non_list, $foot_explain;
    global $search_auth, $show_passage, $username, $vars;
    $qm = get_qm();
    $retval = array();
    $b_type = $type == 'AND';
    // AND:TRUE OR:FALSE
    mb_language('Japanese');
    $word = mb_convert_encoding($word, SOURCE_ENCODING, "UTF-8,EUC-JP,SJIS,ASCII,JIS");
    $word = mb_ereg_replace(" ", " ", $word);
    $keys = get_search_words(preg_split('/\\s+/', $word, -1, PREG_SPLIT_NO_EMPTY));
    foreach ($keys as $key => $value) {
        $keys[$key] = '/' . $value . '/S';
    }
    $pages = get_existpages();
    // Avoid
    if ($base != '') {
        $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages);
    }
    if (!$search_non_list) {
        $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
    }
    $pages = array_flip($pages);
    unset($pages[$whatsnew]);
    $count = count($pages);
    // Search for page contents
    global $ignore_plugin, $strip_plugin, $strip_plugin_inline;
    $titles = array();
    $head10s = array();
    // 一時的に認証を外す
    $user_name = null;
    if (isset($_SESSION['usr'])) {
        $user_name = $_SESSION['usr'];
        unset($_SESSION['usr']);
    }
    foreach (array_keys($pages) as $page) {
        $vars['page'] = $page;
        $b_match = FALSE;
        // Search auth for page contents
        if (!check_readable($page, false, false, TRUE)) {
            unset($pages[$page]);
            continue;
        }
        $lines = get_source($page, TRUE, FALSE);
        //--- 検索専用のデータの作成、更新 ---
        $srh_fname = CACHE_DIR . encode($page) . '_search.txt';
        if (!file_exists($srh_fname) || filemtime($srh_fname) < filemtime(get_filename($page))) {
            $p_title = $page;
            $p_heads = '';
            foreach ($lines as $k => $l) {
                if (preg_match($ignore_plugin, $l)) {
                    // 省く
                    $lines = array();
                    break;
                }
                if (preg_match($strip_plugin, $l, $ms)) {
                    // 省く
                    unset($lines[$k]);
                }
                if (preg_match('/^TITLE:(.*)/', $l, $ms)) {
                    $p_title = trim($ms[1]);
                    if ($p_title !== $page) {
                        $p_title = $p_title . ' ' . $page;
                    }
                    unset($lines[$k]);
                }
                if (preg_match('/^(?:!|(\\*){1,3})(.*)\\[#\\w+\\]\\s?/', $l, $ms)) {
                    $p_heads .= trim($ms[2]) . ' ';
                    unset($lines[$k]);
                }
            }
            $lines = preg_replace($strip_plugin_inline, '', $lines);
            // 省く
            $html = convert_html($lines);
            $html = preg_replace('/<(script|style)[^>]*>.*?<\\/\\1>/i', '', $html);
            $html = preg_replace('/<img\\b[^>]*alt="(.*?)"[^>]*>/i', '\\1', $html);
            $p_body = trim(strip_tags($html));
            foreach ($foot_explain as $id => $note) {
                $p_body .= "\n" . strip_tags($note);
            }
            $foot_explain = array();
            $p_body = count($lines) > 0 ? $p_title . "\n" . $p_heads . "\n" . $p_body : '';
            file_put_contents($srh_fname, $p_body);
        } else {
            $fp = fopen($srh_fname, "r");
            flock($fp, LOCK_SH);
            $lines = file($srh_fname);
            flock($fp, LOCK_UN);
            fclose($fp);
            $p_title = trim($lines[0]);
            unset($lines[0]);
            $p_heads = trim($lines[1]);
            unset($lines[1]);
            $p_body = implode('', $lines);
        }
        //////////////////////////////////////////////
        //
        //  検索スタート!
        //
        ///////////////////////////////////////////////
        $match_title = 0;
        $match_heads = 0;
        $match_body = 0;
        //--- ページタイトル検索 ---
        $point = 0;
        $ok = false;
        if (!$non_format) {
            foreach ($keys as $key) {
                $b_match = preg_match($key, $p_title);
                if (!$b_match) {
                    $ok = false;
                    break;
                } else {
                    $ok = true;
                    $point += 15;
                }
            }
            if ($ok) {
                $match_title = $point;
            }
        }
        //--- ヘッダー検索 ---
        $point = 0;
        $ok = false;
        foreach ($keys as $key) {
            $b_match = preg_match_all($key, $p_title, $ms);
            if (!$b_match) {
                $ok = false;
                break;
            } else {
                $ok = true;
                $point += 10;
            }
        }
        if ($ok) {
            $match_heads = $point;
        }
        //--- コンテンツ検索 ---
        foreach ($keys as $key) {
            $b_match = preg_match_all($key, $p_body, $ms);
            if (!$b_match) {
                $ok = false;
                break;
            } else {
                $ok = true;
                $point += count($ms[0]);
            }
        }
        if ($ok) {
            $match_body = $point;
        }
        //検索結果
        $total = $match_title + $match_heads + $match_body;
        if ($total == 0) {
            unset($pages[$page]);
            // Miss
        } else {
            $pages[$page] = $total;
            $titles[$page] = $p_title;
            $head10s[$page] = mb_substr($p_body, 0, 60 * 3);
        }
    }
    if ($user_name !== null) {
        $_SESSION['usr'] = $user_name;
    }
    $vars['page'] = '';
    //注釈の削除
    $foot_explain = array();
    if ($non_format) {
        return array_keys($pages);
    }
    $r_word = rawurlencode($word);
    $s_word = h($word);
    if (empty($pages)) {
        return str_replace('$1', $s_word, '$1 を含むページは見つかりませんでした。');
    }
    arsort($pages);
    $retval = '<div class="container-fluid"><div class="list-group">' . "\n";
    foreach ($pages as $page => $v) {
        $title = $titles[$page];
        if ($title !== $page) {
            $rpos = strrpos($title, $page);
            if ($rpos !== FALSE) {
                $title = trim(substr($title, 0, $rpos));
            }
            $title = $title . ' - ' . $page;
        }
        $r_page = rawurlencode($page);
        $tmp_li = '  <div class="list-group-item" style="border-style:none;"><a class="list-group-item-heading" href="' . $script . '?cmd=read&amp;page=' . $r_page . '&amp;word=' . $r_word . '" style="font-weight:bold;">' . h($title) . '</a><p class="list-group-item-text text-muted" style="margin: 5px 0;">' . $head10s[$page] . '</p></div>' . "\n";
        $retval .= $tmp_li;
    }
    $retval .= '</div><p>' . "\n";
    $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), str_replace('$3', $count, $b_type ? '$1 のすべてを含むページは <strong>$3</strong> ページ中、 <strong>$2</strong> ページ見つかりました。' : '$1 のいずれかを含むページは <strong>$3</strong> ページ中、 <strong>$2</strong> ページ見つかりました。')));
    $retval .= '</p></div>';
    return $retval;
}
Пример #27
0
function plugin_bugtrack_list_convert()
{
    global $script, $vars, $_plugin_bugtrack;
    $page = $vars['page'];
    if (func_num_args()) {
        list($_page) = func_get_args();
        $_page = get_fullname(strip_bracket($_page), $page);
        if (is_pagename($_page)) {
            $page = $_page;
        }
    }
    $data = array();
    $pattern = $page . '/';
    $pattern_len = strlen($pattern);
    foreach (get_existpages() as $page) {
        if (strpos($page, $pattern) === 0 && is_numeric(substr($page, $pattern_len))) {
            array_push($data, plugin_bugtrack_list_pageinfo($page));
        }
    }
    $count_list = count($_plugin_bugtrack['state_list']);
    $table = array();
    for ($i = 0; $i <= $count_list + 1; ++$i) {
        $table[$i] = array();
    }
    foreach ($data as $line) {
        list($page, $no, $summary, $name, $priority, $state, $category) = $line;
        foreach (array('summary', 'name', 'priority', 'state', 'category') as $item) {
            ${$item} = htmlsc(${$item});
        }
        $page_link = make_pagelink($page);
        $state_no = array_search($state, $_plugin_bugtrack['state_sort']);
        if ($state_no === NULL || $state_no === FALSE) {
            $state_no = $count_list;
        }
        $bgcolor = htmlsc($_plugin_bugtrack['state_bgcolor'][$state_no]);
        $row = <<<EOD
 <tr>
  <td style="background-color:{$bgcolor}">{$page_link}</td>
  <td style="background-color:{$bgcolor}">{$state}</td>
  <td style="background-color:{$bgcolor}">{$priority}</td>
  <td style="background-color:{$bgcolor}">{$category}</td>
  <td style="background-color:{$bgcolor}">{$name}</td>
  <td style="background-color:{$bgcolor}">{$summary}</td>
 </tr>
EOD;
        $table[$state_no][$no] = $row;
    }
    $table_html = ' <tr>' . "\n";
    $bgcolor = htmlsc($_plugin_bugtrack['header_bgcolor']);
    foreach (array('pagename', 'state', 'priority', 'category', 'name', 'summary') as $item) {
        $table_html .= '  <th style="background-color:' . $bgcolor . '">' . htmlsc($_plugin_bugtrack[$item]) . '</th>' . "\n";
    }
    $table_html .= ' </tr>' . "\n";
    for ($i = 0; $i <= $count_list; ++$i) {
        ksort($table[$i], SORT_NUMERIC);
        $table_html .= join("\n", $table[$i]);
    }
    return '<table border="1" width="100%">' . "\n" . $table_html . "\n" . '</table>';
}
Пример #28
0
function plugin_qhmsetting_counter_form($error = '')
{
    global $script, $vars;
    global $other_plugins;
    $hlp_counter = '';
    //reset
    $message = '';
    if (isset($vars['reset'])) {
        $page = decode(basename($vars['reset'], '.count'));
        $message = h($page) . 'のアクセスカウントをリセットしました。';
        $_SESSION['flash_msg'] = $message;
        file_put_contents('counter/' . $vars['reset'], '');
        redirect($script . '?cmd=qhmsetting&phase=counter&mode=form');
        exit;
    }
    $list = get_existpages('counter', '.count');
    $body = '
<style type="text/css">
ul {
list-style-type:none;
padding-left: 0;
}
ul li {
margin-bottom: 4px;
}
.admin input[type=button] {
background-color: #2981e4;
font-size: 12px;
padding: 4px 3px;
}
.admin input[type=button]:hover {
background-color: #2575cf;
}
</style>
';
    $body .= '<ul>';
    foreach ($list as $fname => $pname) {
        $url = $script . '?' . rawurlencode($pname);
        $reset_url = $script . '?cmd=qhmsetting&amp;phase=counter&amp;mode=form&amp;reset=' . rawurlencode($fname);
        $body .= '<li><input type="button" value="リセット" onclick="javascript:location.href=\'' . $reset_url . '\'" class="btn btn-primary" ><a href="' . $url . '"> ' . $pname . '</a> </li>' . "\n";
    }
    $body .= '</ul>';
    return $body;
}
Пример #29
0
function plugin_new_inline()
{
    global $vars, $_plugin_new_elapses;
    $retval = '';
    $args = func_get_args();
    $date = strip_autolink(array_pop($args));
    // {date} always exists
    if ($date !== '') {
        // Show 'New!' message by the time of the $date string
        if (func_num_args() > 2) {
            return '&new([nodate]){date};';
        }
        $timestamp = strtotime($date);
        if ($timestamp === -1) {
            return '&new([nodate]){date}: Invalid date string;';
        }
        $timestamp -= ZONETIME;
        $retval = in_array('nodate', $args) ? '' : htmlsc($date);
    } else {
        // Show 'New!' message by the timestamp of the page
        if (func_num_args() > 3) {
            return '&new(pagename[,nolink]);';
        }
        $name = strip_bracket(!empty($args) ? array_shift($args) : $vars['page']);
        $page = get_fullname($name, $vars['page']);
        $nolink = in_array('nolink', $args);
        if (substr($page, -1) == '/') {
            // Check multiple pages started with "$page"
            $timestamp = 0;
            $regex = '/^' . preg_quote($page, '/') . '/';
            foreach (preg_grep($regex, get_existpages()) as $page) {
                // Get the latest pagename and its timestamp
                $_timestamp = get_filetime($page);
                if ($timestamp < $_timestamp) {
                    $timestamp = $_timestamp;
                    $retval = $nolink ? '' : make_pagelink($page);
                }
            }
            if ($timestamp == 0) {
                return '&new(pagename/[,nolink]): No such pages;';
            }
        } else {
            // Check a page
            if (is_page($page)) {
                $timestamp = get_filetime($page);
                $retval = $nolink ? '' : make_pagelink($page, $name);
            } else {
                return '&new(pagename[,nolink]): No such page;';
            }
        }
    }
    // Add 'New!' string by the elapsed time
    $erapse = UTIME - $timestamp;
    foreach ($_plugin_new_elapses as $limit => $tag) {
        if ($erapse <= $limit) {
            $retval .= sprintf($tag, get_passage($timestamp));
            break;
        }
    }
    if ($date !== '') {
        // Show a date string
        return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);
    } else {
        // Show a page name
        return $retval;
    }
}
Пример #30
0
 /**
  * get readings of pages
  *
  * PukiWiki API Extension
  *
  * arguments $pages version of lib/file.php get_reading
  *
  * @access public
  * @static
  * @param mixed $pages array of pages or a pagename
  *   if not given, get readings of all existing pages
  * @return array readings
  * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $
  */
 function get_readings($pages = array())
 {
     global $pagereading_enable, $pagereading_kanji2kana_converter;
     global $pagereading_kanji2kana_encoding, $pagereading_chasen_path;
     global $pagereading_kakasi_path, $pagereading_config_page;
     global $pagereading_config_dict;
     $pages = (array) $pages;
     if (empty($pages)) {
         $pages = get_existpages();
     }
     $readings = array();
     foreach ($pages as $page) {
         $readings[$page] = '';
     }
     $deletedPage = false;
     $matches = array();
     foreach (get_source($pagereading_config_page) as $line) {
         $line = chop($line);
         if (preg_match('/^-\\[\\[([^]]+)\\]\\]\\s+(.+)$/', $line, $matches)) {
             if (isset($readings[$matches[1]])) {
                 // This page is not clear how to be pronounced
                 $readings[$matches[1]] = $matches[2];
             } else {
                 // This page seems deleted
                 $deletedPage = true;
             }
         }
     }
     // If enabled ChaSen/KAKASI execution
     if ($pagereading_enable) {
         // Check there's non-clear-pronouncing page
         $unknownPage = false;
         foreach ($readings as $page => $reading) {
             if ($reading == '') {
                 $unknownPage = true;
                 break;
             }
         }
         // Execute ChaSen/KAKASI, and get annotation
         if ($unknownPage) {
             switch (strtolower($pagereading_kanji2kana_converter)) {
                 case 'chasen':
                     if (!file_exists($pagereading_chasen_path)) {
                         die_message('ChaSen not found: ' . $pagereading_chasen_path);
                     }
                     $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
                     $fp = fopen($tmpfname, 'w') or die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         fputs($fp, mb_convert_encoding($page . "\n", $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
                     }
                     fclose($fp);
                     $chasen = "{$pagereading_chasen_path} -F %y {$tmpfname}";
                     $fp = popen($chasen, 'r');
                     if ($fp === false) {
                         unlink($tmpfname);
                         die_message('ChaSen execution failed: ' . $chasen);
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $line = fgets($fp);
                         $line = mb_convert_encoding($line, SOURCE_ENCODING, $pagereading_kanji2kana_encoding);
                         $line = chop($line);
                         $readings[$page] = $line;
                     }
                     pclose($fp);
                     unlink($tmpfname) or die_message('Temporary file can not be removed: ' . $tmpfname);
                     break;
                 case 'kakasi':
                     /*FALLTHROUGH*/
                 /*FALLTHROUGH*/
                 case 'kakashi':
                     if (!file_exists($pagereading_kakasi_path)) {
                         die_message('KAKASI not found: ' . $pagereading_kakasi_path);
                     }
                     $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
                     $fp = fopen($tmpfname, 'w') or die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         fputs($fp, mb_convert_encoding($page . "\n", $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
                     }
                     fclose($fp);
                     $kakasi = "{$pagereading_kakasi_path} -kK -HK -JK < {$tmpfname}";
                     $fp = popen($kakasi, 'r');
                     if ($fp === false) {
                         unlink($tmpfname);
                         die_message('KAKASI execution failed: ' . $kakasi);
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $line = fgets($fp);
                         $line = mb_convert_encoding($line, SOURCE_ENCODING, $pagereading_kanji2kana_encoding);
                         $line = chop($line);
                         $readings[$page] = $line;
                     }
                     pclose($fp);
                     unlink($tmpfname) or die_message('Temporary file can not be removed: ' . $tmpfname);
                     break;
                 case 'none':
                     $patterns = $replacements = $matches = array();
                     foreach (get_source($pagereading_config_dict) as $line) {
                         $line = chop($line);
                         if (preg_match('|^ /([^/]+)/,\\s*(.+)$|', $line, $matches)) {
                             $patterns[] = $matches[1];
                             $replacements[] = $matches[2];
                         }
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $readings[$page] = $page;
                         foreach ($patterns as $no => $pattern) {
                             $readings[$page] = mb_convert_kana(mb_ereg_replace($pattern, $replacements[$no], $readings[$page]), 'aKCV');
                         }
                     }
                     break;
                 default:
                     die_message('Unknown kanji-kana converter: ' . $pagereading_kanji2kana_converter . '.');
                     break;
             }
         }
         if ($unknownPage || $deletedPage) {
             asort($readings);
             // Sort by pronouncing(alphabetical/reading) order
             $body = '';
             foreach ($readings as $page => $reading) {
                 $body .= '-[[' . $page . ']] ' . $reading . "\n";
             }
             page_write($pagereading_config_page, $body);
         }
     }
     // Pages that are not prounouncing-clear, return pagenames of themselves
     foreach ($pages as $page) {
         if ($readings[$page] == '') {
             $readings[$page] = $page;
         }
     }
     return $readings;
 }