/
submit.php
288 lines (247 loc) · 10.6 KB
/
submit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/**
# ######################################################################
# Project: PHPLinkDirectory: Version 2.1.2
#
# **********************************************************************
# Copyright (C) 2004-2006 NetCreated, Inc. (http://www.netcreated.com/)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# **********************************************************************
#
# For questions, help, comments, discussion, etc., please join the
# PHP Link Directory Forum http://www.phplinkdirectory.com/forum/
#
# @link http://www.phplinkdirectory.com/
# @copyright 2004-2006 NetCreated, Inc. (http://www.netcreated.com/)
# Portions copyright 2012-2013 Bruce Clement (http://www.clement.co.nz/)
# @projectManager David DuVal <david@david-duval.com>
# @package PHPLinkDirectory
# ######################################################################
*/
require_once 'init.php';
/* @var $tpl SmartyBC */
# Load reCaptcha
require_once 'libs/recaptcha/recaptchalib.php';
require_once 'libs/plugins/SmartyPluginsInterface.inc';
//Make an additional check if client is allowed to post/submit
//[Spam] protection
require_once 'include/check_post_rules.php';
$post_rules_unauthorized = check_post_rules($_POST);
//Evaluate payment options
$price = array ();
if (PAY_ENABLE == '1' && PAYPAL_ACCOUNT != '')
{
if (FTR_ENABLE == '1' && PAY_FEATURED > 0)
{
$price['featured'] = PAY_FEATURED;
}
if (PAY_NORMAL > 0)
{
$price['normal'] = PAY_NORMAL;
if (PAY_ENABLE_FREE)
{
$price['free'] = 0;
}
}
if (FTR_ENABLE == 1 && PAY_FEATURED_PLUS > 0)
$price['featured_plus'] = PAY_FEATURED_PLUS;
if (PAY_NORMAL_PLUS > 0)
$price['normal_plus'] = PAY_NORMAL_PLUS;
if (PAY_RECPR > -1)
{
$price['reciprocal'] = PAY_RECPR;
}
if (isset ($_REQUEST['LINK_TYPE']))
{
$link_type = $_REQUEST['LINK_TYPE'];
switch ($link_type)
{
case 'reciprocal' :
$recpr_required = 1;
break;
case 'free' :
$recpr_required = REQUIRE_RECIPROCAL;
break;
default :
$recpr_required = 0;
break;
}
}
else
{
$link_type = 'reciprocal';
$recpr_required = REQUIRE_RECIPROCAL;
}
$_SESSION['SmartyValidate']['submit_link']['validators'][6]['empty'] = ($recpr_required ? 0 : 1);
$_SESSION['SmartyValidate']['submit_link']['validators'][7]['empty'] = ($recpr_required ? 0 : 1);
}
else
{
$recpr_required = REQUIRE_RECIPROCAL;
$price['reciprocal'] = 0;
if( ! $recpr_required ) {
$price[ 'free' ] = 0;
}
$link_type = $recpr_required ? 'reciprocal' : 'free';
}
$tpl->assign('price', $price);
$tpl->assign('recpr_required', $recpr_required);
//Determine category
$CategoryID = (!empty($_REQUEST['c']) && preg_match ('`^[\d]+$`', $_REQUEST['c']) ? intval ($_REQUEST['c']) :
(!empty ($_SERVER['HTTP_REFERER']) ? get_category($_SERVER['HTTP_REFERER']) : 0));
$CategoryID = ($CategoryID > 0 ? $CategoryID : 0); //Make sure the category ID is valid
if (empty ($_REQUEST['submit']))
{
if (!empty ($_SERVER['HTTP_REFERER']))
$_SESSION['return'] = $_SERVER['HTTP_REFERER'];
$data = array ();
$data['CATEGORY_ID'] = $CategoryID;
$data['RECPR_REQUIRED'] = $recpr_required;
SmartyValidate :: disconnect();
SmartyValidate :: connect($tpl);
SmartyValidate::set_form('submit_link');
SmartyValidate :: register_form('submit_link', true);
SmartyValidate :: register_criteria('ValidateWithPlugins' , 'SmartyValidateByPlugin', 'submit_link');
SmartyValidate :: register_criteria('isValueUnique' , 'validate_unique' , 'submit_link');
SmartyValidate :: register_criteria('isUrlUnique' , 'validateUrlUnique' , 'submit_link');
SmartyValidate :: register_criteria('isNotEqual' , 'validate_not_equal' , 'submit_link');
SmartyValidate :: register_criteria('isURLOnline' , 'validate_url_online', 'submit_link');
SmartyValidate :: register_criteria('isRecprDomain' , 'validate_recpr_link_dom', 'submit_link');
SmartyValidate :: register_criteria('isRecprOnline' , 'validate_recpr_link', 'submit_link');
SmartyValidate :: register_criteria('isCaptchaValid', 'validate_captcha' , 'submit_link');
SmartyValidate :: register_validator('v_TITLE' , 'TITLE', 'notEmpty' , false, false, 'trim', 'submit_link');
SmartyValidate :: register_validator('v_TITLE_U' , 'TITLE:link::CATEGORY_ID'.$EditUnique, 'isValueUnique', false, false, null, 'submit_link');
SmartyValidate :: register_validator('v_URL' , 'URL', 'isURL' , false, false, 'trim', 'submit_link');
SmartyValidate :: register_validator('v_URL_ONLINE' , 'URL', 'isURLOnline' , false, false, null , 'submit_link');
SmartyValidate :: register_validator('v_URL_U' , 'URL:link'.(ALLOW_MULTIPLE ? '::CATEGORY_ID' : ':'), 'isUrlUnique', false, false, null, 'submit_link');
SmartyValidate :: register_validator('v_CATEGORY_ID' , 'CATEGORY_ID:0' , 'isNotEqual', false, false, null, 'submit_link');
SmartyValidate :: register_validator('v_RECPR_URL' , 'RECPR_URL' , 'isURL' , ($recpr_required ? false : true), false, 'trim', 'submit_link');
SmartyValidate :: register_validator('v_RECPR_ONLINE' , 'RECPR_URL' , 'isURLOnline' , ($recpr_required ? false : true), false, null, 'submit_link');
SmartyValidate :: register_validator('v_RECPR_LINK' , 'RECPR_URL' , 'isRecprOnline' , ($recpr_required ? false : true), false, null, 'submit_link');
SmartyValidate :: register_validator('v_RECPR_DOMAIN' , 'RECPR_URL' , 'isRecprDomain' , ($recpr_required ? false : true), false, null, 'submit_link');
SmartyValidate :: register_validator('v_OWNER_NAME' , 'OWNER_NAME' , 'notEmpty' , false, false, 'trim', 'submit_link');
SmartyValidate :: register_validator('v_OWNER_EMAIL', 'OWNER_EMAIL' , 'isEmail' , false, false, 'trim', 'submit_link');
if (count ($price) > 0)
SmartyValidate :: register_validator('v_LINK_TYPE' , 'LINK_TYPE' , 'notEmpty' , false, false, 'trim', 'submit_link');
// Deeplink URL Validation
for($dl=1; $dl<=5; $dl++)
SmartyValidate :: register_validator('v_DEEPLINK_URL' . $dl, 'URL' . $dl, 'isURL' , true, false, 'trim', 'submit_link');
}
else
{
SmartyValidate :: connect($tpl);
SmartyValidate::set_form('submit_link');
$data = get_table_data('link', true);
$data['STATUS'] = 1;
$data['IPADDRESS'] = get_client_ip();
$data['VALID'] = 1;
$data['LINK_TYPE'] = $link_type;
$data['RECPR_REQUIRED'] = $recpr_required;
if ($recpr_required)
{
$data['RECPR_VALID'] = 1;
$data['RECPR_LAST_CHECKED'] = gmdate ('Y-m-d H:i:s');
}
$data['LAST_CHECKED'] = gmdate ('Y-m-d H:i:s');
$data['DATE_ADDED'] = gmdate ('Y-m-d H:i:s');
$data['DATE_MODIFIED'] = gmdate ('Y-m-d H:i:s');
if (strlen (trim ($data['URL'])) > 0 && !preg_match ('#^http[s]?:\/\/#i', $data['URL']))
$data['URL'] = "http://".$data['URL'];
if (strlen (trim ($data['RECPR_URL'])) > 0 && !preg_match ('#^http[s]?:\/\/#i', $data['RECPR_URL']))
$data['RECPR_URL'] = "http://".$data['RECPR_URL'];
/*if (VISUAL_CONFIRM == 1 && !empty ($_POST['CAPTCHA']))
$data = array_merge ($data, array ('CAPTCHA' => $_POST['CAPTCHA']));*/
if (VISUAL_CONFIRM > 0 ) {
$rc_resp = validateReCaptcha();
if($rc_resp === true)
$tpl->assign('reCaptchaError', 1);
else
$tpl->assign('reCaptchaError', $rc_resp);
} else {
$rc_resp = true;
}
if (SmartyValidate :: is_valid($data, 'submit_link') && ($rc_resp === true))
{
if (ENABLE_PAGERANK)
{
require_once 'include/pagerank.php';
$data['PAGERANK'] = get_page_rank($data['URL']);
if (!empty ($data['RECPR_URL']))
{
$data['RECPR_PAGERANK'] = get_page_rank($data['RECPR_URL']);
}
}
$id = $db->GenID($tables['link']['name'].'_SEQ');
$data['ID'] = (!empty ($id) ? intval ($id) : '');
$data['LINK_TYPE'] = $link_type_int[$link_type];
switch ($link_type)
{
case 'free':
$data['NOFOLLOW'] = 1;
break;
case 'featured': case 'featured_plus':
$data['FEATURED'] = 1;
break;
}
$data['OWNER_NOTIF'] = ($price[$link_type] > 0 ? 0 : 1 );
$data['PAYED'] = ($price[$link_type] > 0 ? 0 : -1);
if ($db->Replace($tables['link']['name'], $data, 'ID', true) > 0)
{
$tpl->assign('posted', true);
send_submit_notifications($data);
if ($price[$link_type] > 0)
{
//Move to payment page
@ header("Location: payment.php?id=".$data['ID']);
@ exit;
}
else
{
unset ($data);
}
}
else
{
$tpl->assign('error', true);
$tpl->assign('sqlError', $db->ErrorMsg());
}
}
}
unset ($_SESSION['CAPTCHA']);
function validateReCaptcha()
{
$reCaptchaResp = recaptcha_check_answer(RECAPTCHA_PRIVATE_KEY ,$_SERVER['REMOTE_ADDR'] ,$_POST['recaptcha_challenge_field'],$_POST['recaptcha_response_field']);
if ($reCaptchaResp->is_valid)
return true;
else
return $reCaptchaResp->error;
}
$path = array ();
$path[] = array ('ID' => '0', 'TITLE' => _L(SITE_NAME), 'TITLE_URL' => DOC_ROOT, 'DESCRIPTION' => SITE_DESC);
$path[] = array ('ID' => '0', 'TITLE' => _L('Submit Link'), 'TITLE_URL' => '', 'DESCRIPTION' => _L('Submit a new link to the directory '));
$tpl->assign('path', $path);
$categs = get_categs_tree(0);
$tpl->assign('categs', $categs);
$tpl->assign($data);
$tpl->assign('LINK_TYPE', $link_type);
/* Top level Categories */
$topcats = $db->GetAll("SELECT * FROM `{$tables['category']['name']}` WHERE `STATUS` = 2 AND `PARENT_ID` = 0 ORDER BY `TITLE`");
$tpl->assign('topcats', $topcats);
//Clean whitespace
$tpl->loadFilter('output', 'trimwhitespace');
//Make output
$tpl->display('submit.tpl', $id);
?>