-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplusad.controller.php
More file actions
executable file
·163 lines (142 loc) · 4 KB
/
Copy pathplusad.controller.php
File metadata and controls
executable file
·163 lines (142 loc) · 4 KB
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
<?php
/**
* @class plusadController
* @brief PlusAd module user controller class
*/
class plusadController extends plusad
{
/**
* @brief Initialization
*/
function init()
{
}
/**
* @brief Get whitelist regex pattern
* @return string Regex pattern
*/
function getWhitelistRegex()
{
$whitelist = [];
if($this->module_info->domain_list)
{
$whitelist = explode("\n", str_replace("\r", "", $this->module_info->domain_list));
}
$result = [];
foreach ($whitelist as $domain)
{
$domain = trim($domain);
if(!$domain)
{
continue;
}
$result[] = str_replace('\*', '[-a-zA-Z0-9._]*', preg_quote($domain, '%'));
}
if(!count($result))
{
return '/^$/';
}
return '%^(?:https?:)?//(' . implode('|', $result) . ')%';
}
/**
* @brief Check if the URL matches the whitelist
* @param string $url URL to check
* @return bool Returns true if matched or empty, false otherwise
*/
function matchWhitelist(string $url)
{
if (!$url)
{
return true; // Allow if URL is empty
}
return preg_match($this->getWhitelistRegex(), $url) ? true : false;
}
/**
* @brief Process ad registration
* @return BaseObject|void
*/
function procPlusadwrite()
{
// Get request variables
$args = Context::getRequestVars();
$args->module = 'plusad';
$logged_info = Context::get('logged_info');
$args->member_srl = $logged_info->member_srl;
$args->nick_name = $logged_info->nick_name;
$args->regdate = date('Y-m-d H:i:s');
$args->enddate = date('Y-m-d H:i:s', strtotime('+' . $args->time . 'hours'));
// Calculate points
$minus_point = $args->time * $this->module_info->adpoint; // Time based point
$bold_point = ($args->bold == 'yes') ? $this->module_info->boldpoint : 0; // Bold effect point
$color_point = ($args->color != 'no') ? $this->module_info->colorpoint : 0; // Color effect point
$args->ad_point = $minus_point + $bold_point + $color_point;
// Set ad URL if null
if (!$args->ad_url)
{
$args->ad_url = '';
}
// Check max allowed time (use the maximum of the configured ad times)
$allowed_times = array_filter(array_map(function($t) { return intval(trim($t)); }, explode(',', $this->module_info->adtime)));
$max_allowed_time = max($allowed_times);
if ($args->time > $max_allowed_time)
{
return new BaseObject(-1, '광고 허용시간을 초과하였습니다.');
}
// Check min allowed time
if ($args->time <= 0)
{
return new BaseObject(-1, '잘못된 광고 시간입니다.');
}
// Check whitelist
if (!$this->matchWhitelist($args->ad_url))
{
return new BaseObject(-1, '등록 불가능한 주소입니다');
}
// Check user points
$current_point = $this->getPointBalance($logged_info->member_srl);
if ($args->ad_point > $current_point)
{
return new BaseObject(-1, '포인트가 부족합니다');
}
// Calculate total accumulated points for the user
$point_output = executeQuery('plusad.getadpoint', $args);
$member_point = 0;
if ($point_output->data)
{
foreach ($point_output->data as $val => $point)
{
$member_point = $point;
}
}
$args->total_point = $member_point + $args->ad_point;
// Insert ad into DB
$output = executeQuery("plusad.insert_ad", $args);
if (!$output->toBool())
{
return new BaseObject(-1, '광고 등록에 실패하였습니다.');
}
// Deduct points
$this->changePoint($logged_info->member_srl, $args->ad_point, 'minus');
// Set success message and redirect
$this->setMessage('광고 등록 완료');
$this->setRedirectUrl(Context::get('success_return_url'));
}
/**
* @brief Process ad update
* @return BaseObject|void
*/
function procPlusadUpdate()
{
// Get request variables
$args = Context::getRequestVars();
// Update DB
$output = executeQuery("plusad.update_ad", $args);
if (!$output->toBool())
{
return new BaseObject(-1, '광고 수정에 실패하였습니다.');
}
// Set success message and redirect
$this->setMessage('광고 수정 완료');
$this->setRedirectUrl(getNotEncodedUrl('act', 'dispPlusadlist'));
}
}