root/trunk/php/lib/function.MTCommentFields.php @ 2

Revision 2, 7.7 kB (checked in by hachi, 3 years ago)

Merge mt internal repo to public repo.

  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2function smarty_function_MTCommentFields($args, &$ctx) {
3    // TODO: new tag
4    $blog = $ctx->stash('blog');
5
6    if (!($blog['blog_allow_reg_comments'] || $blog['blog_allow_unreg_comments'])) {
7        return '';
8    }
9
10    $cfg =& $ctx->mt->config;
11    require_once "function.MTCGIPath.php";
12    $path = smarty_function_MTCGIPath($args, $ctx);
13    $comment_script = $cfg['CommentScript'];
14    $e =& $ctx->stash('entry');
15    if (!$e) {
16        return $ctx->error('No entry available');
17    }
18    $entry_id = $e['entry_id'];
19
20    $signon_url = $cfg['SignOnURL'];
21
22    $allow_comment_html_note = (($blog['blog_allow_comment_html'])
23                                   ? $ctx->mt->translate("(You may use HTML tags for style)") : "");
24    $needs_email = $blog['blog_require_comment_emails'] ? "&amp;need_email=1" : "";
25    $registration_required = ($blog['blog_allow_reg_comments']
26                                 && !$blog['blog_allow_unreg_comments']);
27    $registration_allowed = $blog['blog_allow_reg_comments'];
28    $unregistered_allowed = $blog['blog_allow_unreg_comments'];
29
30    $static_arg = $args['static'] ? "static=1" : "static=0";
31    $static_field = ($args['static'] || !isset($args['static']))
32                        ? ('<input type="hidden" name="static" value="1" />')
33                        : ('<input type="hidden" name="static" value="0" />');
34
35    $typekey_version = $cfg['TypeKeyVersion'];
36
37    $comment_author = "";
38    $comment_email = "";
39    $comment_text = "";
40    $comment_url = "";
41    if ($args['preview']) {
42        $ctx->localize(array('tag'));
43        $ctx->stash('tag', 'Preview');
44        require_once("MTUtil.php");
45        $comment_author = encode_html($ctx->tag('CommentAuthor')) || "";
46        $comment_email = encode_html($ctx->tag('CommentEmail')) || "";
47        $comment_text = encode_html($ctx->tag('CommentBody',array('convert_breaks'=>0))) || "";
48        $comment_url = encode_html($ctx->tag('CommentURL')) || "";
49        $ctx->restore(array('tag'));
50    }
51
52    global $_typekeytoken_cache;
53    $blog = $ctx->stash('blog');
54    $blog_id = $blog['blog_id'];
55    $token = 0;
56    if (isset($_typekeytoken_cache[$blog_id])) {
57        $token = $_typekeytoken_cache[$blog_id];
58    } else {
59        $token = $blog['blog_remote_auth_token'];
60        if ($token) {
61            $_typekeytoken_cache[$blog_id] = $token;
62        }
63    }
64
65    $rem_auth_token = $token;
66    if (!$rem_auth_token && $registration_required) {
67        return $ctx->error("To enable comment registration, you need to add a TypeKey token "
68            . "in your weblog config or author profile.");
69    }
70
71    $tk_version = $cfg['TypeKeyVersion'];
72
73    if ($registration_required) {
74#return MT->translate_templatized(<<HTML);
75        $tmpl = <<<HTML
76<div id="thanks">
77<p><MT_TRANS phrase="Thanks for signing in,">
78<script>document.write(getCookie("commenter_name"))</script>.
79<MT_TRANS phrase="Now you can comment."> (<a href="$path$comment_script?__mode=handle_sign_in&amp;$static_arg&amp;entry_id=$entry_id&amp;logout=1"><MT_TRANS phrase="sign out"></a>)</p>
80
81<MT_TRANS phrase="(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)">
82
83<form method="post" action="$path$comment_script" name="comments_form" onsubmit="if (this.bakecookie[0].checked) rememberMe(this)">
84$static_field
85<input type="hidden" name="entry_id" value="$entry_id" />
86
87<p><label for="url">URL:</label><br />
88<input tabindex="1" type="text" name="url" id="url" value="$comment_url" />
89
90<MT_TRANS phrase="Remember me?">
91<input type="radio" id="remember" name="bakecookie" /><label for="bakecookie"><label for="remember"><MT_TRANS phrase="Yes"></label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget"><MT_TRANS phrase="No"></label><br style="clear: both;" /></p>
92
93<p><label for="text"><MT_TRANS phrase="Comments:"></label><br />
94<textarea tabindex="2" id="text" name="text" rows="10" cols="50" id="text">$comment_text</textarea></p>
95
96<div align="center">
97<input type="submit" name="preview" value="&nbsp;<MT_TRANS phrase="Preview">&nbsp;" />
98<input style="font-weight: bold;" type="submit" name="post" value="&nbsp;<MT_TRANS phrase="Post">&nbsp;" />
99</div>
100
101</form>
102</div>
103
104<script type="text/javascript">
105<!--   
106if (getCookie("commenter_name")) {
107    document.getElementById('thanks').style.display = 'block';
108} else {
109    document.write('<MT_TRANS phrase="You are not signed in. You need to be registered to comment on this site." escape="singlequotes"> <a href="$signon_url$needs_email&amp;t=$rem_auth_token&amp;v=$tk_version&amp;_return=$path$comment_script%3f__mode=handle_sign_in%26$static_arg%26entry_id=$entry_id"><MT_TRANS phrase="Sign in" escape="singlequotes"></a>');
110    document.getElementById('thanks').style.display = 'none';
111}// --></script>
112HTML;
113        return $ctx->mt->translate_templatized($tmpl);
114    } else {
115        $result = "";
116        if ($rem_auth_token) {
117            $tmpl = <<<HTML
118<script type="text/javascript">
119<!--
120if (getCookie("commenter_name")) {
121    document.write('<MT_TRANS phrase="Thanks for signing in," escape="singlequotes"> ', getCookie("commenter_name"), '<MT_TRANS phrase=". Now you can comment." escape="singlequotes"> (<a href="$path$comment_script?__mode=handle_sign_in&amp;$static_arg&amp;entry_id=$entry_id&amp;logout=1"><MT_TRANS phrase="sign out" escape="singlequotes"></a>)');
122} else {
123    document.write('<MT_TRANS phrase="If you have a TypeKey identity, you can " escape="singlequotes"><a href="$signon_url$needs_email&amp;t=$rem_auth_token&amp;v=$tk_version&amp;_return=$path$comment_script%3f__mode=handle_sign_in%26$static_arg%26entry_id=$entry_id"> <MT_TRANS phrase="sign in" escape="singlequotes"></a> <MT_TRANS phrase="to use it here." escape="singlequotes">');}
124// -->
125</script>
126HTML;
127            $result .= $ctx->mt->translate_templatized($tmpl);
128        }
129        $tmpl = <<<HTML
130<form method="post" action="$path$comment_script" name="comments_form" onsubmit="if (this.bakecookie[0].checked) rememberMe(this)">$static_field
131<input type="hidden" name="entry_id" value="$entry_id" />
132<div id="name_email">
133<p><label for="author"><MT_TRANS phrase="Name:"></label><br />
134<input tabindex="1" name="author" id="author" value="$comment_author" /></p>
135
136<p><label for="email"><MT_TRANS phrase="Email Address:"></label><br />
137<input tabindex="2" name="email" id="email" value="$comment_email" /></p>
138</div>
139HTML;
140        if ($rem_auth_token) {
141            $tmpl = <<<HTML
142<script type="text/javascript">
143<!--
144if (getCookie("commenter_name")) {
145    document.getElementById('name_email').style.display = 'none';
146}
147// -->
148</script>
149HTML;
150            $result .= $ctx->mt->translate_templatized($tmpl);
151        }
152        $tmpl = <<<HTML
153<p><label for="url"><MT_TRANS phrase="URL:"></label><br />
154<input tabindex="3" type="text" name="url" id="url" value="$comment_url" />
155
156<MT_TRANS phrase="Remember me?">
157<input type="radio" id="remember" name="bakecookie" /><label for="remember"><MT_TRANS phrase="Yes"></label><input type="radio" id="forget" name="bakecookie" onclick="forgetMe(this.form)" value="Forget Info" style="margin-left: 15px;" /><label for="forget"><MT_TRANS phrase="No"></label><br style="clear: both;" /></p>
158
159<p><label for="text"><MT_TRANS phrase="Comments:"></label> $allow_comment_html_note<br />
160<textarea tabindex="4" name="text" rows="10" cols="50" id="text">$comment_text</textarea></p>
161
162<div align="center">
163<input type="submit" name="preview" value="&nbsp;<MT_TRANS phrase="Preview">&nbsp;" />
164<input style="font-weight: bold;" type="submit" name="post" value="&nbsp;<MT_TRANS phrase="Post">&nbsp;" />
165</div>
166
167</form>
168
169HTML;
170        $result .= $ctx->mt->translate_templatized($tmpl);
171        return $result;
172    }
173}
174?>
Note: See TracBrowser for help on using the browser.