AvocadoAmber/AvocadoEdition_Light/adm/editor_font_update.php
2024-10-05 06:00:46 +09:00

89 lines
3.2 KiB
PHP

<?php
include_once "./_common.php";
if ($is_admin != 'super') {
alert('최고관리자만 접근 가능합니다.');
}
$w = isset($_POST['w']) ? $_POST['w'] : (isset($_GET['w']) ? $_GET['w'] : '');
if ($w == 'd') {
$font_id = isset($_POST['font_id']) ? intval($_POST['font_id']) : (isset($_GET['font_id']) ? intval($_GET['font_id']) : 0);
if (!$font_id) {
alert('올바른 요청이 아닙니다.');
}
}
if ($w == '') {
$font_css = isset($_POST['font_css']) ? stripslashes(trim($_POST['font_css'])) : '';
$font_name = isset($_POST['font_name']) ? clean_xss_tags(trim($_POST['font_name'])) : '';
EventHandler::triggerEvent("amber.admin.editor_font_update_before", $font_css, $font_name);
if (empty($font_css) || empty($font_name)) {
alert('@font-face CSS 또는 @import URL과 폰트 이름은 필수 입력 항목입니다.');
}
if (strpos($font_css, '@import') !== false) {
if (!preg_match('/@import\s+url\([\'"](.+?)[\'"]\)\s*;/', $font_css, $import_matches)) {
alert('@import URL을 추출할 수 없습니다.');
}
$import_url = $import_matches[1];
$font_url = '@import url(\'' . $import_url . '\');';
$google_css = @file_get_contents($import_url);
if ($google_css === false) {
alert('Google Fonts에서 CSS를 가져올 수 없습니다.');
}
if (!preg_match("/font-family:\s*'(.*?)'/i", $google_css, $family_matches)) {
alert('Google Fonts CSS에서 font-family를 추출할 수 없습니다.');
}
$font_url = addslashes($font_url);
$font_family = clean_xss_tags(trim($family_matches[1]));
$font_weight = 'normal';
$font_style = 'normal';
} else {
// handle @font-face CSS
preg_match("/font-family:\s*['\"](.*?)['\"]/i", $font_css, $family_matches);
preg_match("/src:\s*(.*?);/i", $font_css, $src_matches);
preg_match("/font-weight:\s*(.*?);/i", $font_css, $weight_matches);
preg_match("/font-style:\s*(.*?);/i", $font_css, $style_matches);
$font_family = isset($family_matches[1]) ? clean_xss_tags(trim($family_matches[1])) : '';
$font_url = isset($src_matches[1]) ? addslashes(trim($src_matches[1])) : '';
$font_weight = isset($weight_matches[1]) ? clean_xss_tags(trim($weight_matches[1])) : 'normal';
$font_style = isset($style_matches[1]) ? clean_xss_tags(trim($style_matches[1])) : 'normal';
}
if (empty($font_family) || empty($font_url)) {
alert('CSS에서 font-family와 src를 추출할 수 없습니다.');
}
$sql = "INSERT INTO {$g5['font_table']} SET font_name = '{$font_name}',
font_family = '{$font_family}',
font_url = '{$font_url}',
font_weight = '{$font_weight}',
font_style = '{$font_style}'";
sql_query($sql);
$msg = '폰트가 추가되었습니다.';
EventHandler::triggerEvent("amber.admin.editor_font_update_after", $font_css, $font_name);
} else if ($w == 'd') {
$sql = " DELETE FROM {$g5['font_table']} WHERE font_id = '{$font_id}' ";
sql_query($sql);
$msg = '폰트가 삭제되었습니다.';
EventHandler::triggerEvent("amber.admin.editor_font_update_deleted", $font_id);
}
if ($msg) {
alert($msg);
}
goto_url(clean_relative_paths('./editor_font.php'));