Exemple #1
0
 /**
  * 输出头部元数据
  *
  * @access public
  * @param string $rule 规则
  * @return void
  */
 public function header($rule = NULL)
 {
     $rules = array();
     $allows = array('description' => htmlspecialchars($this->_description), 'keywords' => htmlspecialchars($this->_keywords), 'generator' => $this->options->generator, 'template' => $this->options->theme, 'pingback' => '', 'xmlrpc' => '', 'wlw' => '', 'rss2' => $this->_feedUrl, 'rss1' => $this->_feedRssUrl, 'antiSpam' => 1, 'atom' => $this->_feedAtomUrl);
     /** 头部是否输出聚合 */
     $allowFeed = !$this->is('single') || $this->allow('feed') || $this->_makeSinglePageAsFrontPage;
     if (!empty($rule)) {
         parse_str($rule, $rules);
         $allows = array_merge($allows, $rules);
     }
     $allows = $this->pluginHandle()->headerOptions($allows, $this);
     $header = '';
     if (!empty($allows['description'])) {
         $header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
     }
     if (!empty($allows['keywords'])) {
         $header .= '<meta name="keywords" content="' . $allows['keywords'] . '" />' . "\n";
     }
     if (!empty($allows['generator'])) {
         $header .= '<meta name="generator" content="' . $allows['generator'] . '" />' . "\n";
     }
     if (!empty($allows['template'])) {
         $header .= '<meta name="template" content="' . $allows['template'] . '" />' . "\n";
     }
     if (!empty($allows['pingback'])) {
         $header .= '<link rel="pingback" href="' . $allows['pingback'] . '" />' . "\n";
     }
     if (!empty($allows['xmlrpc'])) {
         $header .= '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . $allows['xmlrpc'] . '" />' . "\n";
     }
     if (!empty($allows['wlw'])) {
         $header .= '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' . $allows['wlw'] . '" />' . "\n";
     }
     if (!empty($allows['rss2']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="' . $allows['rss2'] . '" />' . "\n";
     }
     if (!empty($allows['rss1']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="' . $allows['rss1'] . '" />' . "\n";
     }
     if (!empty($allows['atom']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/atom+xml" title="ATOM 1.0" href="' . $allows['atom'] . '" />' . "\n";
     }
     /** 反垃圾设置 */
     if ($this->options->commentsAntiSpam && $this->is('single')) {
         if ('' != $allows['antiSpam']) {
             if (1 == $allows['antiSpam']) {
                 $header .= "<script type=\"text/javascript\">\n(function () {\n    var event = document.addEventListener ? {\n        add: 'addEventListener',\n        focus: 'focus',\n        load: 'DOMContentLoaded'\n    } : {\n        add: 'attachEvent',\n        focus: 'onfocus',\n        load: 'onload'\n    };\n\n    document[event.add](event.load, function () {\n        var r = document.getElementById('{$this->respondId}');\n\n        if (null != r) {\n            var forms = r.getElementsByTagName('form');\n            if (forms.length > 0) {\n                var f = forms[0], textarea = f.getElementsByTagName('textarea')[0], added = false;\n\n                if (null != textarea && 'text' == textarea.name) {\n                    textarea[event.add](event.focus, function () {\n                        if (!added) {\n                            var input = document.createElement('input');\n                            input.type = 'hidden';\n                            input.name = '_';\n                            input.value = " . Typecho_Common::shuffleScriptVar($this->security->getToken($this->request->getRequestUrl())) . "\n\n                            f.appendChild(input);\n                            added = true;\n                        }\n                    });\n                }\n            }\n        }\n    });\n})();\n</script>";
             } else {
                 $header .= '<script src="' . $allows['antiSpam'] . '" type="text/javascript"></script>';
             }
         }
     }
     /** 输出header */
     echo $header;
     /** 插件支持 */
     $this->pluginHandle()->header($header, $this);
 }
Exemple #2
0
 /**
  * 输出头部元数据
  *
  * @access public
  * @param string $rule 规则
  * @return void
  */
 public function header($rule = NULL)
 {
     $rules = array();
     $allows = array('description' => htmlspecialchars($this->_description), 'keywords' => htmlspecialchars($this->_keywords), 'generator' => $this->options->generator, 'template' => $this->options->theme, 'pingback' => $this->options->xmlRpcUrl, 'xmlrpc' => $this->options->xmlRpcUrl . '?rsd', 'wlw' => $this->options->xmlRpcUrl . '?wlw', 'rss2' => $this->_feedUrl, 'rss1' => $this->_feedRssUrl, 'commentReply' => 1, 'antiSpam' => 1, 'atom' => $this->_feedAtomUrl);
     /** 头部是否输出聚合 */
     $allowFeed = !$this->is('single') || $this->allow('feed') || $this->_makeSinglePageAsFrontPage;
     if (!empty($rule)) {
         parse_str($rule, $rules);
         $allows = array_merge($allows, $rules);
     }
     $allows = $this->pluginHandle()->headerOptions($allows, $this);
     $header = '';
     if (!empty($allows['description'])) {
         $header .= '<meta name="description" content="' . $allows['description'] . '" />' . "\n";
     }
     if (!empty($allows['keywords'])) {
         $header .= '<meta name="keywords" content="' . $allows['keywords'] . '" />' . "\n";
     }
     if (!empty($allows['generator'])) {
         $header .= '<meta name="generator" content="' . $allows['generator'] . '" />' . "\n";
     }
     if (!empty($allows['template'])) {
         $header .= '<meta name="template" content="' . $allows['template'] . '" />' . "\n";
     }
     if (!empty($allows['pingback'])) {
         $header .= '<link rel="pingback" href="' . $allows['pingback'] . '" />' . "\n";
     }
     if (!empty($allows['xmlrpc'])) {
         $header .= '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . $allows['xmlrpc'] . '" />' . "\n";
     }
     if (!empty($allows['wlw'])) {
         $header .= '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' . $allows['wlw'] . '" />' . "\n";
     }
     if (!empty($allows['rss2']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="' . $allows['rss2'] . '" />' . "\n";
     }
     if (!empty($allows['rss1']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="' . $allows['rss1'] . '" />' . "\n";
     }
     if (!empty($allows['atom']) && $allowFeed) {
         $header .= '<link rel="alternate" type="application/atom+xml" title="ATOM 1.0" href="' . $allows['atom'] . '" />' . "\n";
     }
     if ($this->options->commentsThreaded && $this->is('single')) {
         if ('' != $allows['commentReply']) {
             if (1 == $allows['commentReply']) {
                 $header .= "<script type=\"text/javascript\">\n(function () {\n    window.TypechoComment = {\n        dom : function (id) {\n            return document.getElementById(id);\n        },\n    \n        create : function (tag, attr) {\n            var el = document.createElement(tag);\n        \n            for (var key in attr) {\n                el.setAttribute(key, attr[key]);\n            }\n        \n            return el;\n        },\n\n        reply : function (cid, coid) {\n            var comment = this.dom(cid), parent = comment.parentNode,\n                response = this.dom('" . $this->respondId . "'), input = this.dom('comment-parent'),\n                form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],\n                textarea = response.getElementsByTagName('textarea')[0];\n\n            if (null == input) {\n                input = this.create('input', {\n                    'type' : 'hidden',\n                    'name' : 'parent',\n                    'id'   : 'comment-parent'\n                });\n\n                form.appendChild(input);\n            }\n\n            input.setAttribute('value', coid);\n\n            if (null == this.dom('comment-form-place-holder')) {\n                var holder = this.create('div', {\n                    'id' : 'comment-form-place-holder'\n                });\n\n                response.parentNode.insertBefore(holder, response);\n            }\n\n            comment.appendChild(response);\n            this.dom('cancel-comment-reply-link').style.display = '';\n\n            if (null != textarea && 'text' == textarea.name) {\n                textarea.focus();\n            }\n\n            return false;\n        },\n\n        cancelReply : function () {\n            var response = this.dom('{$this->respondId}'),\n            holder = this.dom('comment-form-place-holder'), input = this.dom('comment-parent');\n\n            if (null != input) {\n                input.parentNode.removeChild(input);\n            }\n\n            if (null == holder) {\n                return true;\n            }\n\n            this.dom('cancel-comment-reply-link').style.display = 'none';\n            holder.parentNode.insertBefore(response, holder);\n            return false;\n        }\n    };\n})();\n</script>\n";
             } else {
                 $header .= '<script src="' . $allows['commentReply'] . '" type="text/javascript"></script>';
             }
         }
     }
     /** 反垃圾设置 */
     if ($this->options->commentsAntiSpam && $this->is('single')) {
         if ('' != $allows['antiSpam']) {
             if (1 == $allows['antiSpam']) {
                 $header .= "<script type=\"text/javascript\">\n(function () {\n    var event = document.addEventListener ? {\n        add: 'addEventListener',\n        focus: 'focus',\n        load: 'DOMContentLoaded'\n    } : {\n        add: 'attachEvent',\n        focus: 'onfocus',\n        load: 'onload'\n    };\n\n    document[event.add](event.load, function () {\n        var r = document.getElementById('{$this->respondId}');\n\n        if (null != r) {\n            var forms = r.getElementsByTagName('form');\n            if (forms.length > 0) {\n                var f = forms[0], textarea = f.getElementsByTagName('textarea')[0], added = false;\n\n                if (null != textarea && 'text' == textarea.name) {\n                    textarea[event.add](event.focus, function () {\n                        if (!added) {\n                            var input = document.createElement('input');\n                            input.type = 'hidden';\n                            input.name = '_';\n                            input.value = " . Typecho_Common::shuffleScriptVar($this->security->getToken($this->request->getRequestUrl())) . "\n\n                            f.appendChild(input);\n                            added = true;\n                        }\n                    });\n                }\n            }\n        }\n    });\n})();\n</script>";
             } else {
                 $header .= '<script src="' . $allows['antiSpam'] . '" type="text/javascript"></script>';
             }
         }
     }
     /** 插件支持 */
     $this->pluginHandle()->header($header, $this);
     /** 输出header */
     echo $header;
 }
Exemple #3
0
function getAntiSpam($archive)
{
    if (!$archive->is('single') || !$archive->allowComment || !$archive->widget('Widget_Options')->commentsAntiSpam) {
        return;
    }
    $script = "(function () {\n    var event = document.addEventListener ? {\n        add: 'addEventListener',\n        focus: 'focus',\n    } : {\n        add: 'attachEvent',\n        focus: 'onfocus',\n    };\n\n    var r = document.getElementById('{$archive->respondId}');\n\n\tif (null != r) {\n\t\tvar forms = r.getElementsByTagName('form');\n\t\tif (forms.length > 0) {\n\t\t\tvar f = forms[0], textarea = f.getElementsByTagName('textarea')[0], added = false;\n\n\t\t\tif (null != textarea && 'text' == textarea.name) {\n\t\t\t\ttextarea[event.add](event.focus, function () {\n\t\t\t\t\tif (!added) {\n\t\t\t\t\t\tvar input = document.createElement('input');\n\t\t\t\t\t\tinput.type = 'hidden';\n\t\t\t\t\t\tinput.name = '_';\n\t\t\t\t\t\tinput.value = " . Typecho_Common::shuffleScriptVar($archive->widget('Widget_Security')->getToken($archive->request->getRequestUrl())) . "\n\t\t\t\t\t\tf.appendChild(input);\n\t\t\t\t\t\tadded = true;\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n})();";
    return $script;
}