1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # This file a plugin of DotClear. |
---|
4 | # Copyright (c) Marc Vachette. All rights |
---|
5 | # reserved. |
---|
6 | # |
---|
7 | #Subscription2 is free software; you can redistribute it and/or modify |
---|
8 | # it under the terms of the Creative Commons License "Attribution" |
---|
9 | # see the page http://creativecommons.org/licenses/by/2.0/ for more information |
---|
10 | # |
---|
11 | # Subscription is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # Creative Commons License for more details. |
---|
15 | # |
---|
16 | # ***** END LICENSE BLOCK ***** |
---|
17 | |
---|
18 | |
---|
19 | $core->url->register('subscription','subscribe','^subscribe(/(.*))?$',array('urlSubscription','create')); |
---|
20 | |
---|
21 | $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates'); |
---|
22 | |
---|
23 | $core->tpl->addBlock('SubscriptionIf',array('tplSubscription','SubscriptionIf')); |
---|
24 | |
---|
25 | $core->tpl->addValue('SubscriptionURL',array('tplSubscription','SubscriptionURL')); |
---|
26 | $core->tpl->addValue('SubscriptionMsgSuccess',array('tplSubscription','SubscriptionMsgSuccess')); |
---|
27 | $core->tpl->addValue('SubscriptionMsgError',array('tplSubscription','SubscriptionMsgError')); |
---|
28 | $core->tpl->addValue('SubscriptionDomainName',array('tplSubscription','SubscriptionDomainName')); |
---|
29 | $core->tpl->addValue('SubscriptionPageTitle',array('tplSubscription','SubscriptionPageTitle')); |
---|
30 | $core->tpl->addValue('SubscriptionFormCaption',array('tplSubscription','SubscriptionFormCaption')); |
---|
31 | $core->tpl->addValue('SubscriptionName',array('tplSubscription','SubscriptionName')); |
---|
32 | $core->tpl->addValue('SubscriptionEmail',array('tplSubscription','SubscriptionEmail')); |
---|
33 | $core->tpl->addValue('SubscriptionLogin',array('tplSubscription','SubscriptionLogin')); |
---|
34 | $core->tpl->addValue('SubscriptionBlogName',array('tplSubscription','SubscriptionBlogName')); |
---|
35 | $core->tpl->addValue('SubscriptionBlogUrl',array('tplSubscription','SubscriptionBlogUrl')); |
---|
36 | |
---|
37 | |
---|
38 | class urlSubscription extends dcUrlHandlers { |
---|
39 | |
---|
40 | public static function getDomainName() { |
---|
41 | return $_SERVER['HTTP_HOST']; |
---|
42 | } |
---|
43 | |
---|
44 | public static function create($args) |
---|
45 | { |
---|
46 | global $core, $_ctx; |
---|
47 | |
---|
48 | if (!$core->blog->settings->blogs_folder_path) { |
---|
49 | self::p404(); |
---|
50 | exit; |
---|
51 | } |
---|
52 | |
---|
53 | $_ctx->subscription = new ArrayObject(array( |
---|
54 | 'name' => '', |
---|
55 | 'mail' => '', |
---|
56 | 'login' => '', |
---|
57 | 'password' => '', |
---|
58 | 'password_confirm' => '', |
---|
59 | 'blog_name' => '', |
---|
60 | 'blog_url' => '', |
---|
61 | 'created' => false, |
---|
62 | 'error' => false, |
---|
63 | 'error_msg' => '' |
---|
64 | )); |
---|
65 | |
---|
66 | $create_msg = |
---|
67 | isset($_POST['s_name']) && isset($_POST['s_mail']) && isset($_POST['s_login']) && |
---|
68 | isset($_POST['s_password']) && isset($_POST['s_password_confirm']) && |
---|
69 | isset($_POST['s_blog_name']) && isset($_POST['s_blog_url']); |
---|
70 | |
---|
71 | if ($args == 'created') |
---|
72 | { |
---|
73 | $_ctx->subscription['created'] = true; |
---|
74 | } |
---|
75 | elseif ($create_msg) |
---|
76 | { |
---|
77 | # Spam trap |
---|
78 | if (!empty($_POST['f_mail'])) { |
---|
79 | http::head(412,'Precondition Failed'); |
---|
80 | header('Content-Type: text/plain'); |
---|
81 | echo "So Long, and Thanks For All the Fish"; |
---|
82 | exit; |
---|
83 | } |
---|
84 | |
---|
85 | try |
---|
86 | { |
---|
87 | # Checks provided fields |
---|
88 | if (empty($_POST['s_name'])) { |
---|
89 | throw new Exception(__('You must provide a name.')); |
---|
90 | } |
---|
91 | |
---|
92 | if (!text::isEmail($_POST['s_mail'])) { |
---|
93 | throw new Exception(__('You must provide a valid email address.')); |
---|
94 | } |
---|
95 | |
---|
96 | if (empty($_POST['s_login'])) { |
---|
97 | throw new Exception(__('You must provide a login.')); |
---|
98 | } |
---|
99 | |
---|
100 | if (empty($_POST['s_password'])) { |
---|
101 | throw new Exception(__('You must provide a password.')); |
---|
102 | } |
---|
103 | |
---|
104 | if ($_POST['s_password_confirm'] !== $_POST['s_password']) { |
---|
105 | throw new Exception(__("Passwords don't match")); |
---|
106 | } |
---|
107 | |
---|
108 | if (empty($_POST['s_blog_name'])) { |
---|
109 | throw new Exception(__('You must provide a name for you blog.')); |
---|
110 | } |
---|
111 | |
---|
112 | if (empty($_POST['s_blog_url'])) { |
---|
113 | throw new Exception(__('You must provide an url for your blog.')); |
---|
114 | } |
---|
115 | |
---|
116 | $_ctx->subscription['name'] = preg_replace('/[\n\r]/','',$_POST['s_name']); |
---|
117 | $_ctx->subscription['mail'] = preg_replace('/[\n\r]/','',$_POST['s_mail']); |
---|
118 | $_ctx->subscription['login'] = preg_replace('/[\n\r]/','',$_POST['s_login']); |
---|
119 | $_ctx->subscription['password'] = preg_replace('/[\n\r]/','',$_POST['s_password']); |
---|
120 | $_ctx->subscription['password_confirm'] = preg_replace('/[\n\r]/','',$_POST['s_password_confirm']); |
---|
121 | $_ctx->subscription['blog_name'] = preg_replace('/[\n\r]/','',$_POST['s_blog_name']); |
---|
122 | $_ctx->subscription['blog_url'] = preg_replace('/[\n\r]/','',$_POST['s_blog_url']); |
---|
123 | |
---|
124 | Subscription::subscribe($_ctx->subscription); |
---|
125 | |
---|
126 | http::redirect($core->blog->url.$core->url->getBase('subscription2').'/created'); |
---|
127 | } |
---|
128 | catch (Exception $e) |
---|
129 | { |
---|
130 | $_ctx->subscription['error'] = true; |
---|
131 | $_ctx->subscription['error_msg'] = $e->getMessage(); |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|
135 | |
---|
136 | self::serveDocument('new_blog.html'); |
---|
137 | exit; |
---|
138 | } |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | class tplSubscription |
---|
143 | { |
---|
144 | public static function SubscriptionIf($attr,$content) |
---|
145 | { |
---|
146 | $if = array(); |
---|
147 | |
---|
148 | $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; |
---|
149 | |
---|
150 | if (isset($attr['created'])) { |
---|
151 | $sign = (boolean) $attr['created'] ? '' : '!'; |
---|
152 | $if[] = $sign."\$_ctx->subscription['created']"; |
---|
153 | } |
---|
154 | |
---|
155 | if (isset($attr['error'])) { |
---|
156 | $sign = (boolean) $attr['error'] ? '' : '!'; |
---|
157 | $if[] = $sign."\$_ctx->subscription['error']"; |
---|
158 | } |
---|
159 | |
---|
160 | if (!empty($if)) { |
---|
161 | return '<?php if('.implode(' '.$operator.' ',$if).') : ?>'.$content.'<?php endif; ?>'; |
---|
162 | } else { |
---|
163 | return $content; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | public static function SubscriptionURL($attr) |
---|
168 | { |
---|
169 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
170 | return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getBase("subscription")').'; ?>'; |
---|
171 | } |
---|
172 | |
---|
173 | public static function SubscriptionMsgSuccess($attr) |
---|
174 | { |
---|
175 | /*return '<?php echo $core->blog->settings->cm_msg_success; ?>';*/ |
---|
176 | return '<?php echo "Yeah !"; ?>'; |
---|
177 | } |
---|
178 | |
---|
179 | public static function SubscriptionMsgError($attr) |
---|
180 | { |
---|
181 | //TODO : message d'erreur depuis la conf |
---|
182 | return '<?php echo html::escapeHTML($_ctx->subscription["error_msg"]); ?>'; |
---|
183 | /*return '<?php echo sprintf($core->blog->settings->subscription2_msg_error,html::escapeHTML($_ctx->subscription["error_msg"])); ?>';*/ |
---|
184 | } |
---|
185 | |
---|
186 | public static function SubscriptionDomainName() { |
---|
187 | $domain_name = urlSubscription::getDomainName(); |
---|
188 | return "<?php echo '$domain_name'; ?>"; |
---|
189 | } |
---|
190 | |
---|
191 | public static function SubscriptionPageTitle($attr) |
---|
192 | { |
---|
193 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
194 | return '<?php echo '.sprintf($f,'$core->blog->settings->subscription_page_title').'; ?>'; |
---|
195 | } |
---|
196 | |
---|
197 | public static function SubscriptionFormCaption($attr) |
---|
198 | { |
---|
199 | //TODO : titre du formulaire depuis la conf |
---|
200 | //$f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
201 | /*return '<?php echo '.sprintf($f,'$core->blog->settings->subscription_page_title').'; ?>';*/ |
---|
202 | } |
---|
203 | |
---|
204 | public static function SubscriptionName($attr) |
---|
205 | { |
---|
206 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
207 | return '<?php echo '.sprintf($f,'$_ctx->subscription["name"]').'; ?>'; |
---|
208 | } |
---|
209 | |
---|
210 | public static function SubscriptionEmail($attr) |
---|
211 | { |
---|
212 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
213 | return '<?php echo '.sprintf($f,'$_ctx->subscription["mail"]').'; ?>'; |
---|
214 | } |
---|
215 | |
---|
216 | public static function SubscriptionLogin($attr) |
---|
217 | { |
---|
218 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
219 | return '<?php echo '.sprintf($f,'$_ctx->subscription["login"]').'; ?>'; |
---|
220 | } |
---|
221 | |
---|
222 | public static function SubscriptionBlogName($attr) |
---|
223 | { |
---|
224 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
225 | return '<?php echo '.sprintf($f,'$_ctx->subscription["blog_name"]').'; ?>'; |
---|
226 | } |
---|
227 | |
---|
228 | public static function SubscriptionBlogUrl($attr) |
---|
229 | { |
---|
230 | $f = $GLOBALS['core']->tpl->getFilters($attr); |
---|
231 | return '<?php echo '.sprintf($f,'$_ctx->subscription["blog_url"]').'; ?>'; |
---|
232 | } |
---|
233 | |
---|
234 | |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | ?> |
---|