PluginProbe
AL Pack / trunk
AL Pack vtrunk
1.3.13 trunk 1.0.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.11 1.3.12
alpack / templates / admin-ads.php

admin-ads.php in AL Pack trunk, at templates/admin-ads.php

424 lines 17.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 $is_activated = presslearn_plugin()->is_plugin_activated();
7
8 if (!$is_activated) {
9 wp_redirect(admin_url('admin.php?page=presslearn-settings'));
10 exit;
11 }
12
13 if (!function_exists('WP_Filesystem')) {
14 require_once ABSPATH . 'wp-admin/includes/file.php';
15 }
16
17 $filesystem_initialized = WP_Filesystem();
18 if (!$filesystem_initialized) {
19 $filesystem_error = true;
20 }
21
22 $settings_updated = false;
23 $save_error = false;
24 $existing_content = '';
25 $robots_settings_updated = false;
26 $robots_save_error = false;
27 $robots_existing_content = '';
28 $naver_upload_success = false;
29 $google_upload_success = false;
30 $upload_error = false;
31
32 if (isset($_POST['save_ads_txt_content'])) {
33 check_admin_referer('presslearn_save_ads_txt_nonce');
34
35 if (current_user_can('manage_options') && $filesystem_initialized) {
36 global $wp_filesystem;
37
38 $content = isset($_POST['ads_txt_content']) ? wp_unslash($_POST['ads_txt_content']) : '';
39 $content = sanitize_textarea_field($content);
40
41 if (preg_match('/<[^>]*>/', $content) ||
42 stripos($content, 'javascript:') !== false ||
43 stripos($content, 'data:') !== false) {
44 $save_error = true;
45 }
46 elseif (strlen($content) > 1024 * 1024) {
47 $save_error = true;
48 } else {
49 $ads_txt_path = ABSPATH . 'ads.txt';
50
51 if ($wp_filesystem->put_contents($ads_txt_path, $content, FS_CHMOD_FILE)) {
52 $settings_updated = true;
53 } else {
54 $save_error = true;
55 }
56 }
57
58 $robots_content = isset($_POST['robots_txt_content']) ? wp_unslash($_POST['robots_txt_content']) : '';
59 $robots_content = sanitize_textarea_field($robots_content);
60
61 if (preg_match('/<[^>]*>/', $robots_content) ||
62 stripos($robots_content, 'javascript:') !== false ||
63 stripos($robots_content, 'data:') !== false) {
64 $robots_save_error = true;
65 }
66 elseif (strlen($robots_content) > 1024 * 1024) {
67 $robots_save_error = true;
68 } else {
69 $robots_txt_path = ABSPATH . 'robots.txt';
70
71 if ($wp_filesystem->put_contents($robots_txt_path, $robots_content, FS_CHMOD_FILE)) {
72 $robots_settings_updated = true;
73 } else {
74 $robots_save_error = true;
75 }
76 }
77 } else {
78 $save_error = true;
79 $robots_save_error = true;
80 }
81 }
82
83 if (isset($_POST['upload_naver_verification'])) {
84 check_admin_referer('presslearn_save_ads_txt_nonce');
85
86 if (current_user_can('manage_options') && $filesystem_initialized) {
87 if (isset($_FILES['naver_verification_file']) && $_FILES['naver_verification_file']['error'] === UPLOAD_ERR_OK) {
88 $file = $_FILES['naver_verification_file'];
89 $filename = sanitize_file_name($file['name']);
90
91 if (preg_match('/^naver[a-z0-9]+\.html$/i', $filename) && $file['size'] <= 1024 * 1024) {
92 global $wp_filesystem;
93 $target_path = ABSPATH . $filename;
94
95 $file_content = file_get_contents($file['tmp_name']);
96 if ($file_content !== false && $wp_filesystem->put_contents($target_path, $file_content, FS_CHMOD_FILE)) {
97 $naver_upload_success = true;
98 } else {
99 $upload_error = true;
100 }
101 } else {
102 $upload_error = true;
103 }
104 } else {
105 $upload_error = true;
106 }
107 } else {
108 $upload_error = true;
109 }
110 }
111
112 if (isset($_POST['upload_google_verification'])) {
113 check_admin_referer('presslearn_save_ads_txt_nonce');
114
115 if (current_user_can('manage_options') && $filesystem_initialized) {
116 if (isset($_FILES['google_verification_file']) && $_FILES['google_verification_file']['error'] === UPLOAD_ERR_OK) {
117 $file = $_FILES['google_verification_file'];
118 $filename = sanitize_file_name($file['name']);
119
120 if (preg_match('/^google[a-z0-9]+\.html$/i', $filename) && $file['size'] <= 1024 * 1024) {
121 global $wp_filesystem;
122 $target_path = ABSPATH . $filename;
123
124 $file_content = file_get_contents($file['tmp_name']);
125 if ($file_content !== false && $wp_filesystem->put_contents($target_path, $file_content, FS_CHMOD_FILE)) {
126 $google_upload_success = true;
127 } else {
128 $upload_error = true;
129 }
130 } else {
131 $upload_error = true;
132 }
133 } else {
134 $upload_error = true;
135 }
136 } else {
137 $upload_error = true;
138 }
139 }
140
141 if ($filesystem_initialized) {
142 global $wp_filesystem;
143 $ads_txt_path = ABSPATH . 'ads.txt';
144
145 if ($wp_filesystem->exists($ads_txt_path)) {
146 $existing_content = $wp_filesystem->get_contents($ads_txt_path);
147 if ($existing_content === false) {
148 $existing_content = '';
149 } else {
150 if (strlen($existing_content) > 1024 * 1024) {
151 $existing_content = '';
152 }
153 }
154 }
155 } else {
156 $existing_content = '';
157 }
158
159 if ($filesystem_initialized) {
160 global $wp_filesystem;
161 $robots_txt_path = ABSPATH . 'robots.txt';
162
163 if ($wp_filesystem->exists($robots_txt_path)) {
164 $robots_existing_content = $wp_filesystem->get_contents($robots_txt_path);
165 if ($robots_existing_content === false) {
166 $robots_existing_content = '';
167 } else {
168 if (strlen($robots_existing_content) > 1024 * 1024) {
169 $robots_existing_content = '';
170 }
171 }
172 }
173 } else {
174 $robots_existing_content = '';
175 }
176
177 $naver_verification_exists = false;
178 $google_verification_exists = false;
179 $naver_verification_file = '';
180 $google_verification_file = '';
181
182 if ($filesystem_initialized) {
183 global $wp_filesystem;
184
185 $files = $wp_filesystem->dirlist(ABSPATH);
186 if ($files) {
187 foreach ($files as $file) {
188 if (preg_match('/^naver[a-z0-9]+\.html$/i', $file['name'])) {
189 $naver_verification_exists = true;
190 $naver_verification_file = $file['name'];
191 break;
192 }
193 }
194
195 foreach ($files as $file) {
196 if (preg_match('/^google[a-z0-9]+\.html$/i', $file['name'])) {
197 $google_verification_exists = true;
198 $google_verification_file = $file['name'];
199 break;
200 }
201 }
202 }
203 }
204
205 $ads_txt_url = home_url('/ads.txt');
206 $file_exists = !empty($existing_content);
207 $robots_txt_url = home_url('/robots.txt');
208 $robots_file_exists = !empty($robots_existing_content);
209 ?>
210
211 <div class="presslearn-header">
212 <div class="presslearn-header-logo">
213 <img src="<?php echo esc_url(PRESSLEARN_PLUGIN_URL); ?>assets/images/logo.png" alt="PressLearn Logo">
214 <h1>Ads 매니저</h1>
215 </div>
216 <div class="presslearn-header-status">
217 <div class="presslearn-header-status-item status-activate">
218 <p>기능이 활성화 되었습니다.</p>
219 </div>
220 </div>
221 </div>
222
223 <div class="wrap">
224 <div class="presslearn-breadcrumbs-wrap">
225 <div class="presslearn-breadcrumbs">
226 <span>대시보드</span>
227 <span class="divider">/</span>
228 <span class="active">Ads 매니저</span>
229 </div>
230 </div>
231
232 <?php if (isset($filesystem_error)): ?>
233 <div class="notice notice-error inline">
234 <p>파일 시스�
235 �에 접근할 수 없습니다. 서버 권한을 확인해주세요.</p>
236 </div>
237 <?php endif; ?>
238
239 <?php if ($settings_updated || $robots_settings_updated): ?>
240 <div class="notice notice-success inline">
241 <p>파일이 성공적으로 저장되었습니다.</p>
242 </div>
243 <?php endif; ?>
244
245 <?php if ($save_error || $robots_save_error): ?>
246 <div class="notice notice-error inline">
247 <p>파일 저장에 실패했습니다. 파일 권한을 확인해주세요.</p>
248 </div>
249 <?php endif; ?>
250
251 <?php if ($naver_upload_success): ?>
252 <div class="notice notice-success inline">
253 <p>네이버 서치 어드바이저 인증 파일이 성공적으로 �
254 로드되었습니다</p>
255 </div>
256 <?php endif; ?>
257
258 <?php if ($google_upload_success): ?>
259 <div class="notice notice-success inline">
260 <p>구글 서치 콘솔 인증 파일이 성공적으로 �
261 로드되었습니다.</p>
262 </div>
263 <?php endif; ?>
264
265 <?php if ($upload_error): ?>
266 <div class="notice notice-error inline">
267 <p>파일 �
268 로드에 실패했습니다. 파일 형식과 크기를 확인해주세요.</p>
269 </div>
270 <?php endif; ?>
271
272 <div class="presslearn-card">
273 <div class="presslearn-card-header">
274 <h2>Ads 매니저</h2>
275 <p>Google AdSense 기타 광고 네트워크 인증을 위한 ads.txt 파일을 관리합니다.</p>
276 </div>
277 <div class="presslearn-card-body">
278 <form method="post" action="" enctype="multipart/form-data" id="ads-manager-form">
279 <?php wp_nonce_field('presslearn_save_ads_txt_nonce'); ?>
280
281 <div class="presslearn-card-body-row">
282 <div class="presslearn-card-body-row-item grid-left">
283 <h3>현재 파일 상태</h3>
284 </div>
285 <div class="presslearn-card-body-row-item grid-right">
286 <div style="margin-bottom: 8px;">
287 <?php if ($file_exists): ?>
288 <span class="dashicons dashicons-yes-alt" style="color: #46b450; margin-right: 8px;"></span>
289 <strong>ads.txt 파일이 존재합니다</strong>
290 <?php else: ?>
291 <span class="dashicons dashicons-marker" style="color: #dc3232; margin-right: 8px;"></span>
292 <strong>ads.txt 파일이 존재하지 않습니다</strong>
293 <?php endif; ?>
294 </div>
295 <div>
296 <?php if ($robots_file_exists): ?>
297 <span class="dashicons dashicons-yes-alt" style="color: #46b450; margin-right: 8px;"></span>
298 <strong>robots.txt 파일이 존재합니다</strong>
299 <?php else: ?>
300 <span class="dashicons dashicons-marker" style="color: #dc3232; margin-right: 8px;"></span>
301 <strong>robots.txt 파일이 존재하지 않습니다</strong>
302 <?php endif; ?>
303 </div>
304 </div>
305 </div>
306
307 <div class="presslearn-card-body-row">
308 <div class="presslearn-card-body-row-item grid-left">
309 <h3>ads.txt 파일 내용</h3>
310 </div>
311 <div class="presslearn-card-body-row-item grid-right">
312 <textarea
313 name="ads_txt_content"
314 id="ads_txt_content"
315 rows="10"
316 class="large-text code"
317 style="width: 100%; font-family: Consolas, Monaco, monospace; font-size: 13px;"
318 placeholder="google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0&#10;example.com, 12345, DIRECT"
319 <?php echo !$filesystem_initialized ? 'disabled' : ''; ?>
320 ><?php echo esc_textarea($existing_content); ?></textarea>
321 </div>
322 </div>
323
324 <div class="presslearn-card-body-row">
325 <div class="presslearn-card-body-row-item grid-left">
326 <h3>robots.txt 파일 내용</h3>
327 </div>
328 <div class="presslearn-card-body-row-item grid-right">
329 <textarea
330 name="robots_txt_content"
331 id="robots_txt_content"
332 rows="10"
333 class="large-text code"
334 style="width: 100%; font-family: Consolas, Monaco, monospace; font-size: 13px;"
335 placeholder="User-agent: *&#10;Disallow: /wp-admin/&#10;Allow: /wp-admin/admin-ajax.php"
336 <?php echo !$filesystem_initialized ? 'disabled' : ''; ?>
337 ><?php echo esc_textarea($robots_existing_content); ?></textarea>
338 <button type="button" class="point-btn" id="set-default-robots" style="margin-top: 10px;">기본 설정</button>
339 </div>
340 </div>
341
342 <div class="presslearn-card-body-row">
343 <div class="presslearn-card-body-row-item grid-left">
344 <h3>네이버 서치 어드바이저 인증 �
345 로드</h3>
346 </div>
347 <div class="presslearn-card-body-row-item grid-right">
348 <?php if (!$naver_verification_exists && $filesystem_initialized): ?>
349 <input type="file" name="naver_verification_file" accept=".html" style="margin-bottom: 10px; width: 100%;">
350 <button type="submit" name="upload_naver_verification" value="1" class="point-btn">파일 �
351 로드</button>
352 <?php else: ?>
353 <button type="button" class="point-btn" disabled style="opacity: 0.6;">
354 <?php echo $naver_verification_exists ? '�
355 로드됨' : '사용 불가'; ?>
356 </button>
357 <?php endif; ?>
358 <?php if ($naver_verification_exists): ?>
359 <p style="color: #46b450; font-size: 13px; margin-top: 5px;">
360 <span class="dashicons dashicons-yes-alt"></span>
361 <?php echo esc_html($naver_verification_file); ?> �
362 로드됨
363 </p>
364 <?php endif; ?>
365 </div>
366 </div>
367
368 <div class="presslearn-card-body-row">
369 <div class="presslearn-card-body-row-item grid-left">
370 <h3>구글 서치 콘솔 인증 �
371 로드</h3>
372 </div>
373 <div class="presslearn-card-body-row-item grid-right">
374 <?php if (!$google_verification_exists && $filesystem_initialized): ?>
375 <input type="file" name="google_verification_file" accept=".html" style="margin-bottom: 10px; width: 100%;">
376 <button type="submit" name="upload_google_verification" value="1" class="point-btn">파일 �
377 로드</button>
378 <?php else: ?>
379 <button type="button" class="point-btn" disabled style="opacity: 0.6;">
380 <?php echo $google_verification_exists ? '�
381 로드됨' : '사용 불가'; ?>
382 </button>
383 <?php endif; ?>
384 <?php if ($google_verification_exists): ?>
385 <p style="color: #46b450; font-size: 13px; margin-top: 5px;">
386 <span class="dashicons dashicons-yes-alt"></span>
387 <?php echo esc_html($google_verification_file); ?> �
388 로드됨
389 </p>
390 <?php endif; ?>
391 </div>
392 </div>
393 </form>
394 </div>
395 <div class="presslearn-card-footer">
396 <div class="presslearn-card-footer-item grid-left">
397 <span class="tip_button">robots.txt 파일은 Rank Math SEO 플러그인이 있어도, 우선 순위�
398 니다.</span>
399 </div>
400 <div class="presslearn-card-footer-item grid-right">
401 <?php if ($filesystem_initialized): ?>
402 <button type="submit" name="save_ads_txt_content" value="1" class="point-btn" form="ads-manager-form">저장하기</button>
403 <?php else: ?>
404 <button type="button" class="point-btn" disabled style="opacity: 0.6;">저장하기</button>
405 <?php endif; ?>
406 </div>
407 </div>
408 </div>
409 </div>
410
411 <script>
412 jQuery(document).ready(function($) {
413 $('#set-default-robots').on('click', function(e) {
414 e.preventDefault();
415
416 var defaultContent = 'User-agent: *\n\n';
417 defaultContent += 'Disallow: /wp-admin/\n';
418 defaultContent += 'Allow: /wp-admin/admin-ajax.php\n\n';
419 defaultContent += 'Sitemap: <?php echo esc_js(home_url('/sitemap_index.xml')); ?>';
420
421 $('#robots_txt_content').val(defaultContent);
422 });
423 });
424 </script>