Exemple #1
0
    def show(self):
        # type: () -> None
        filename = Path(cmk.utils.paths.omd_root).joinpath(
            'var/dokuwiki/data/pages/sidebar.txt')

        html.open_form(id_="wiki_search",
                       onsubmit="cmk.sidebar.wiki_search('%s');" %
                       config.omd_site())
        html.input(id_="wiki_search_field", type_="text", name="wikisearch")
        html.icon_button("#",
                         _("Search"),
                         "wikisearch",
                         onclick="cmk.sidebar.wiki_search('%s');" %
                         config.omd_site())
        html.close_form()
        html.div('', id_="wiki_side_clear")

        start_ul = True
        ul_started = False
        try:
            title = None
            for line in filename.open(encoding="utf-8").readlines():
                line = line.strip()
                if line == "":
                    if ul_started:
                        html.end_foldable_container()
                        start_ul = True
                        ul_started = False
                elif line.endswith(":"):
                    title = line[:-1]
                elif line == "----":
                    pass
                    # html.br()

                elif line.startswith("*"):
                    if start_ul:
                        if title:
                            html.begin_foldable_container("wikisnapin",
                                                          title,
                                                          True,
                                                          title,
                                                          indent=True)
                        else:
                            html.open_ul()
                        start_ul = False
                        ul_started = True

                    erg = re.findall(r'\[\[(.*)\]\]', line)
                    if len(erg) == 0:
                        continue
                    erg = erg[0].split('|')
                    if len(erg) > 1:
                        link = erg[0]
                        name = erg[1]
                    else:
                        link = erg[0]
                        name = erg[0]

                    if link.startswith("http://") or link.startswith(
                            "https://"):
                        simplelink(name, link, "_blank")
                    else:
                        erg = name.split(':')
                        if len(erg) > 0:
                            name = erg[-1]
                        else:
                            name = erg[0]
                        bulletlink(
                            name, "/%s/wiki/doku.php?id=%s" %
                            (config.omd_site(), link))

                else:
                    html.write_text(line)

            if ul_started:
                html.close_ul()
        except IOError:
            html.write_html(
                html.render_p(
                    html.render_text(
                        "To get a navigation menu, you have to create a ") +
                    html.render_a("sidebar",
                                  href="/%s/wiki/doku.php?id=%s" %
                                  (config.omd_site(), _("sidebar")),
                                  target="main") +  #
                    html.render_text(" in your wiki first.")))
Exemple #2
0
    def show(self):
        filename = cmk.utils.paths.omd_root + '/var/dokuwiki/data/pages/sidebar.txt'
        html.javascript("""
        function wiki_search()
        {
            var oInput = document.getElementById('wiki_search_field');
            top.frames["main"].location.href =
               "/%s/wiki/doku.php?do=search&id=" + escape(oInput.value);
        }
        """ % config.omd_site())

        html.open_form(id_="wiki_search", onsubmit="wiki_search();")
        html.input(id_="wiki_search_field", type_="text", name="wikisearch")
        html.icon_button("#",
                         _("Search"),
                         "wikisearch",
                         onclick="wiki_search();")
        html.close_form()
        html.div('', id_="wiki_side_clear")

        start_ul = True
        ul_started = False
        try:
            title = None
            for line in file(filename).readlines():
                line = line.strip()
                if line == "":
                    if ul_started:
                        html.end_foldable_container()
                        start_ul = True
                        ul_started = False
                elif line.endswith(":"):
                    title = line[:-1]
                elif line == "----":
                    pass
                    # html.br()

                elif line.startswith("*"):
                    if start_ul:
                        if title:
                            html.begin_foldable_container("wikisnapin",
                                                          title,
                                                          True,
                                                          title,
                                                          indent=True)
                        else:
                            html.open_ul()
                        start_ul = False
                        ul_started = True

                    erg = re.findall(r'\[\[(.*)\]\]', line)
                    if len(erg) == 0:
                        continue
                    erg = erg[0].split('|')
                    if len(erg) > 1:
                        link = erg[0]
                        name = erg[1]
                    else:
                        link = erg[0]
                        name = erg[0]

                    if link.startswith("http://") or link.startswith(
                            "https://"):
                        simplelink(name, link, "_blank")
                    else:
                        erg = name.split(':')
                        if len(erg) > 0:
                            name = erg[-1]
                        else:
                            name = erg[0]
                        bulletlink(
                            name, "/%s/wiki/doku.php?id=%s" %
                            (config.omd_site(), link))

                else:
                    html.write_text(line)

            if ul_started:
                html.close_ul()
        except IOError:
            sidebar = html.render_a("sidebar",
                                    href="/%s/wiki/doku.php?id=%s" %
                                    (config.omd_site(), _("sidebar")),
                                    target="main")
            html.write_html("<p>To get a navigation menu, you have to create a %s in your wiki first.</p>"\
                                                                               % sidebar)