Ejemplo n.º 1
0
function do_print($formatter, $options)
{
    global $DBInfo;
    $options['css_url'] = $DBInfo->url_prefix . "/css/print.css";
    $formatter->nonexists = 'always';
    $dum = false;
    $formatter->pi = $formatter->page->get_instructions($dum);
    $title = $formatter->pi['#title'];
    $formatter->send_header("", $options);
    kbd_handler();
    print "<div id='printHeader'>";
    print "<h2>{$title}</h2>";
    print "</div>";
    print "<div id='wikiContent'>";
    $formatter->external_on = 1;
    $formatter->send_page('', array('fixpath' => 1));
    print "</div></div>";
    print "<div id='printFooter'>";
    print sprintf(_("Retrieved from %s"), qualifiedUrl($formatter->link_url($formatter->page->name))) . '<br/>';
    if ($mtime = $formatter->page->mtime()) {
        $lastedit = date("Y-m-d", $mtime);
        $lasttime = date("H:i:s", $mtime);
        print sprintf(_("last modified %s %s"), $lastedit, $lasttime);
    }
    print "</div></body></html>";
    return;
}
Ejemplo n.º 2
0
function do_notitle($formatter, $options)
{
    global $DBInfo;
    $formatter->sister_on = 0;
    #$options['css_url']=$DBInfo->url_prefix."/css/print.css";
    $formatter->send_header("", $options);
    #print "<div id='printHeader'>";
    #print "<h2>$options[page]</h2>";
    #print "</div>";
    kbd_handler();
    print "<div id='wikiContent'>";
    $formatter->external_on = 1;
    $formatter->send_page();
    print "</div></div>";
    print "</body></html>";
    return;
}
Ejemplo n.º 3
0
    function send_header($header = "", $options = array())
    {
        global $DBInfo;
        $plain = 0;
        $media = 'media="screen"';
        if (isset($options['action'][0]) and $options['action'] == 'print') {
            $media = '';
        }
        if (empty($options['is_robot']) && isset($this->pi['#redirect'][0]) && !empty($options['pi'])) {
            $options['value'] = $this->pi['#redirect'];
            $options['redirect'] = 1;
            $this->pi['#redirect'] = '';
            do_goto($this, $options);
            return true;
        }
        $header = !empty($header) ? $header : (!empty($options['header']) ? $options['header'] : null);
        if (!empty($header)) {
            foreach ((array) $header as $head) {
                $this->header($head);
                if (preg_match("/^content\\-type: text\\//i", $head)) {
                    $plain = 1;
                }
            }
        }
        $mtime = isset($options['mtime']) ? $options['mtime'] : $this->page->mtime();
        if ($mtime > 0) {
            $modified = $mtime > 0 ? gmdate('Y-m-d\\TH:i:s', $mtime) . '+00:00' : null;
            $lastmod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
            $meta_lastmod = '<meta http-equiv="last-modified" content="' . $lastmod . '" />' . "\n";
        }
        if (is_static_action($options) or !empty($DBInfo->use_conditional_get) and !empty($mtime) and empty($options['nolastmod']) and $this->page->is_static) {
            $this->header('Last-Modified: ' . $lastmod);
            $etag = $this->page->etag($options);
            if (!empty($options['etag'])) {
                $this->header('ETag: "' . $options['etag'] . '"');
            } else {
                $this->header('ETag: "' . $etag . '"');
            }
        }
        // custom headers
        if (!empty($DBInfo->site_headers)) {
            foreach ((array) $DBInfo->site_headers as $head) {
                $this->header($head);
            }
        }
        $content_type = isset($DBInfo->content_type[0]) ? $DBInfo->content_type : 'text/html';
        $force_charset = '';
        if (!empty($DBInfo->force_charset)) {
            $force_charset = '; charset=' . $DBInfo->charset;
        }
        if (!$plain) {
            $this->header('Content-type: ' . $content_type . $force_charset);
        }
        if (!empty($options['action_mode']) and $options['action_mode'] == 'ajax') {
            return true;
        }
        # disabled
        #$this->header("Vary: Accept-Encoding, Cookie");
        #if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') and function_exists('ob_gzhandler')) {
        #  ob_start('ob_gzhandler');
        #  $etag.= '.gzip';
        #}
        if (!empty($options['metatags'])) {
            $metatags = $options['metatags'];
        } else {
            $metatags = $DBInfo->metatags;
        }
        if (!empty($options['noindex']) || !empty($this->pi['#noindex']) || (!empty($mtime) and !empty($DBInfo->delayindex) and time() - $mtime < $DBInfo->delayindex)) {
            // delay indexing like as dokuwiki
            if (preg_match("/<meta\\s+name=('|\")?robots\\1[^>]+>/i", $metatags)) {
                $metatags = preg_replace("/<meta\\s+name=('|\")?robots\\1[^>]+>/i", '<meta name="robots" content="noindex,nofollow" />', $metatags);
            } else {
                $metatags .= '<meta name="robots" content="noindex,nofollow" />' . "\n";
            }
        }
        if (isset($DBInfo->metatags_extra)) {
            $metatags .= $DBInfo->metatags_extra;
        }
        $js = !empty($DBInfo->js) ? $DBInfo->js : '';
        if (!$plain) {
            if (isset($options['trail'])) {
                $this->set_trailer($options['trail'], $this->page->name);
            } else {
                if ($DBInfo->origin) {
                    $this->set_origin($this->page->name);
                }
            }
            # find upper page
            $up_separator = '/';
            if (!empty($this->use_namespace)) {
                $up_separator .= '|\\:';
            }
            $pos = 0;
            preg_match('@(' . $up_separator . ')@', $this->page->name, $sep);
            # NameSpace/SubPage or NameSpace:SubNameSpacePage
            if (isset($sep[1])) {
                $pos = strrpos($this->page->name, $sep[1]);
            }
            if ($pos > 0) {
                $upper = substr($this->page->urlname, 0, $pos);
            } else {
                if ($this->group) {
                    $upper = _urlencode(substr($this->page->name, strlen($this->group)));
                }
            }
            // setup keywords
            $keywords = '';
            if (!empty($this->pi['#keywords'])) {
                $keywords = _html_escape($this->pi['#keywords']);
            } else {
                $keys = array();
                $dummy = strip_tags($this->page->title);
                $keys = explode(' ', $dummy);
                $keys[] = $dummy;
                $keys = array_unique($keys);
                $keywords = implode(', ', $keys);
            }
            // add redirects as keywords
            if (!empty($DBInfo->use_redirects_as_keywords)) {
                $r = new Cache_Text('redirects');
                $redirects = $r->fetch($this->page->name);
                if ($redirects !== false) {
                    sort($redirects);
                    $keywords .= ', ' . _html_escape(implode(', ', $redirects));
                }
            }
            // add site specific keywords
            if (!empty($DBInfo->site_keywords)) {
                $keywords .= ', ' . $DBInfo->site_keywords;
            }
            $keywords = "<meta name=\"keywords\" content=\"{$keywords}\" />\n";
            # find sub pages
            if (empty($options['action']) and !empty($DBInfo->use_subindex)) {
                $scache = new Cache_text('subpages');
                if (!($subs = $scache->exists($this->page->name))) {
                    if (($p = strrpos($this->page->name, '/')) !== false) {
                        $rule = _preg_search_escape(substr($this->page->name, 0, $p));
                    } else {
                        $rule = _preg_search_escape($this->page->name);
                    }
                    $subs = $DBInfo->getLikePages('^' . $rule . '\\/', 1);
                    if ($subs) {
                        $scache->update($this->page->name, 1);
                    }
                }
                if (!empty($subs)) {
                    $subindices = '';
                    if (empty($DBInfo->use_ajax)) {
                        $subindices = '<div>' . $this->macro_repl('PageList', '', array('subdir' => 1)) . '</div>';
                        $btncls = 'class="close"';
                    } else {
                        $btncls = '';
                    }
                    $this->subindex = "<fieldset id='wikiSubIndex'>" . "<legend title='[+]' {$btncls} onclick='javascript:toggleSubIndex(\"wikiSubIndex\")'></legend>" . $subindices . "</fieldset>\n";
                }
            }
            if (!empty($options['.title'])) {
                $options['title'] = $options['.title'];
            } else {
                if (empty($options['title'])) {
                    $options['title'] = !empty($this->pi['#title']) ? $this->pi['#title'] : $this->page->title;
                    $options['title'] = _html_escape($options['title']);
                } else {
                    $options['title'] = strip_tags($options['title']);
                }
            }
            $theme_type = !empty($this->_newtheme) ? $this->_newtheme : '';
            if (empty($options['css_url'])) {
                $options['css_url'] = $DBInfo->css_url;
            }
            if (empty($this->pi['#nodtd']) and !isset($options['retstr']) and $theme_type != 2) {
                if (!empty($this->html5)) {
                    if (is_string($this->html5)) {
                        echo $this->html5;
                    } else {
                        echo '<!DOCTYPE html>', "\n", '<html xmlns="http://www.w3.org/1999/xhtml">', "\n";
                    }
                } else {
                    echo $DBInfo->doctype;
                }
            }
            if ($theme_type == 2 or isset($options['retstr'])) {
                ob_start();
            } else {
                echo "<head>\n";
            }
            echo '<meta http-equiv="Content-Type" content="' . $content_type . ';charset=' . $DBInfo->charset . "\" />\n";
            echo <<<JSHEAD
<script type="text/javascript">
/*<![CDATA[*/
_url_prefix="{$DBInfo->url_prefix}";
/*]]>*/
</script>
JSHEAD;
            echo $metatags, $js, "\n";
            echo $this->get_javascripts();
            echo $keywords;
            if (!empty($meta_lastmod)) {
                echo $meta_lastmod;
            }
            $sitename = !empty($DBInfo->title_sitename) ? $DBInfo->title_sitename : $DBInfo->sitename;
            if (!empty($DBInfo->title_msgstr)) {
                $site_title = sprintf($DBInfo->title_msgstr, $sitename, $options['title']);
            } else {
                $site_title = $options['title'] . ' - ' . $sitename;
            }
            // set OpenGraph information
            $act = !empty($options['action']) ? strtolower($options['action']) : 'show';
            $is_show = $act == 'show';
            $is_frontpage = $this->page->name == get_frontpage($DBInfo->lang);
            if (!$is_frontpage && !empty($DBInfo->frontpages) && in_array($this->page->name, $DBInfo->frontpages)) {
                $is_frontpage = true;
            }
            if (!empty($DBInfo->canonical_url)) {
                if (($p = strpos($DBInfo->canonical_url, '%s')) !== false) {
                    $page_url = sprintf($DBInfo->canonical_url, $this->page->urlname);
                } else {
                    $page_url = $DBInfo->canonical_url . $this->page->urlname;
                }
            } else {
                $page_url = qualifiedUrl($this->link_url($this->page->urlname));
            }
            if ($is_show && $this->page->exists()) {
                $oc = new Cache_text('opengraph');
                if ($this->refresh || ($val = $oc->fetch($this->page->name, $this->page->mtime())) === false) {
                    $val = array('description' => '', 'image' => '');
                    if (!empty($this->pi['#redirect'])) {
                        $desc = '#redirect ' . $this->pi['#redirect'];
                    } else {
                        $raw = $this->page->_get_raw_body();
                        if (!empty($this->pi['#description'])) {
                            $desc = $this->pi['#description'];
                        } else {
                            $cut_size = 2000;
                            if (!empty($DBInfo->get_description_cut_size)) {
                                $cut_size = $DBInfo->get_description_cut_size;
                            }
                            $cut = mb_strcut($raw, 0, $cut_size, $DBInfo->charset);
                            $desc = get_description($cut);
                            if ($desc !== false) {
                                $desc = mb_strcut($desc, 0, 200, $DBInfo->charset) . '...';
                            } else {
                                $desc = $this->page->name;
                            }
                        }
                    }
                    $val['description'] = _html_escape($desc);
                    if (!empty($this->pi['#image'])) {
                        if (preg_match('@^(ftp|https?)://@', $this->pi['#image'])) {
                            $page_image = $this->pi['#image'];
                        } else {
                            if (preg_match('@^attachment:("[^"]+"|[^\\s]+)@/', $this->pi['#image'], $m)) {
                                $image = $this->macro_repl('attachment', $m[1], array('link_url' => 1));
                                if ($image[0] != 'a') {
                                    $page_image = $image;
                                }
                            }
                        }
                    }
                    if (empty($page_image)) {
                        // extract the first image
                        $punct = '<>"\'}\\]\\|\\!';
                        if (preg_match_all('@(?<=\\b)((?:attachment:(?:"[^' . $punct . ']+"|[^\\s' . $punct . '?]+)|' . '(?:https?|ftp)://(?:[^\\s' . $punct . ']+)\\.(?:png|jpe?g|gif)))@', $raw, $m)) {
                            foreach ($m[1] as $img) {
                                if ($img[0] == 'a') {
                                    $img = substr($img, 11);
                                    // strip attachment:
                                    $image = $this->macro_repl('attachment', $img, array('link_url' => 1));
                                    if ($image[0] != 'a' && preg_match('@\\.(png|jpe?g|gif)$@i', $image)) {
                                        $page_image = $image;
                                        break;
                                    }
                                } else {
                                    $page_image = $img;
                                    break;
                                }
                            }
                        }
                    }
                    if (empty($page_image) && $is_frontpage) {
                        $val['image'] = qualifiedUrl($DBInfo->logo_img);
                    } else {
                        if (!empty($page_image)) {
                            $val['image'] = $page_image;
                        }
                    }
                    $oc->update($this->page->name, $val, time());
                }
                if (empty($this->no_ogp)) {
                    // for OpenGraph
                    echo '<meta property="og:url" content="' . $page_url . '" />', "\n";
                    echo '<meta property="og:site_name" content="' . $sitename . '" />', "\n";
                    echo '<meta property="og:title" content="' . $options['title'] . '" />', "\n";
                    if ($is_frontpage) {
                        echo '<meta property="og:type" content="website" />', "\n";
                    } else {
                        echo '<meta property="og:type" content="article" />', "\n";
                    }
                    if (!empty($val['image'])) {
                        echo '<meta property="og:image" content="', $val['image'], '" />', "\n";
                    }
                    if (!empty($val['description'])) {
                        echo '<meta property="og:description" content="' . $val['description'] . '" />', "\n";
                    }
                }
                // twitter card
                echo '<meta name="twitter:card" content="summary" />', "\n";
                if (!empty($DBInfo->twitter_id)) {
                    echo '<meta name="twitter:site" content="', $DBInfo->twitter_id, '">', "\n";
                }
                echo '<meta name="twitter:domain" content="', $sitename, '" />', "\n";
                echo '<meta name="twitter:title" content="', $options['title'], '">', "\n";
                echo '<meta name="twitter:url" content="', $page_url, '">', "\n";
                if (!empty($val['description'])) {
                    echo '<meta name="twitter:description" content="' . $val['description'] . '" />', "\n";
                }
                if (!empty($val['image'])) {
                    echo '<meta name="twitter:image:src" content="', $val['image'], '" />', "\n";
                }
                // support google sitelinks serachbox
                if (!empty($DBInfo->use_google_sitelinks)) {
                    if ($is_frontpage) {
                        if (!empty($DBInfo->canonical_url)) {
                            $site_url = $DBInfo->canonical_url;
                        } else {
                            $site_url = qualifiedUrl($this->link_url(''));
                        }
                        echo <<<SITELINK
<script type='application/ld+json'>
{"@context":"http://schema.org",
 "@type":"WebSite",
 "url":"{$site_url}",
 "name":"{$sitename}",
 "potentialAction":{
  "@type":"SearchAction",
  "target":"{$site_url}?goto={search_term}",
  "query-input":"required name=search_term"
 }
}
</script>

SITELINK;
                    }
                }
                echo <<<SCHEMA
<script type='application/ld+json'>
{"@context":"http://schema.org",
 "@type":"WebPage",
 "url":"{$page_url}",
 "dateModified":"{$modified}",
 "name":"{$options['title']}"
}
</script>

SCHEMA;
                if (!empty($val['description'])) {
                    echo '<meta name="description" content="' . $val['description'] . '" />', "\n";
                }
            }
            echo '  <title>', $site_title, "</title>\n";
            echo '  <link rel="canonical" href="', $page_url, '" />', "\n";
            # echo '<meta property="og:title" content="'.$options['title'].'" />',"\n";
            if (!empty($upper)) {
                echo '  <link rel="Up" href="', $this->link_url($upper), "\" />\n";
            }
            $raw_url = $this->link_url($this->page->urlname, "?action=raw");
            $print_url = $this->link_url($this->page->urlname, "?action=print");
            echo '  <link rel="Alternate" title="Wiki Markup" href="', $raw_url, "\" />\n";
            echo '  <link rel="Alternate" media="print" title="Print View" href="', $print_url, "\" />\n";
            $css_html = '';
            if ($options['css_url']) {
                $stamp = '?' . filemtime(__FILE__);
                $css_url = _html_escape($options['css_url']);
                $css_html = '  <link rel="stylesheet" type="text/css" ' . $media . ' href="' . $css_url . "\" />\n";
                if (!empty($DBInfo->custom_css) && file_exists($DBInfo->custom_css)) {
                    $css_html .= '  <link rel="stylesheet" media="screen" type="text/css" href="' . $DBInfo->url_prefix . '/' . $DBInfo->custom_css . "{$stamp}\" />\n";
                } else {
                    if (file_exists('./css/_user.css')) {
                        $css_html .= '  <link rel="stylesheet" media="screen" type="text/css" href="' . $DBInfo->url_prefix . "/css/_user.css{$stamp}\" />\n";
                    }
                }
            }
            echo kbd_handler(!empty($options['prefix']) ? $options['prefix'] : '');
            if (isset($this->_newtheme) and $this->_newtheme == 2 or isset($options['retstr'])) {
                $ret = ob_get_contents();
                ob_end_clean();
                if (isset($options['retstr'])) {
                    $options['retstr'] = $ret;
                }
                $this->header_html = $ret;
                $this->css_html = $css_html;
            } else {
                echo $css_html;
                echo "</head>\n";
            }
        }
        return true;
    }