'message' => $valid ? '字体文件有效' : '无效的字体文件格式' ); } private function upload_to_cos($font_path, $font_info) { try { if (!$this->cos_client) { throw new Exception('COS客户端未初始化'); } $cos_key = $this->cos_config['prefix'] . $font_info['font_id'] . '.' . $font_info['format']; // 检查是否已存在 try { $this->cos_client->headObject(array( 'Bucket' => $this->cos_config['bucket'], 'Key' => $cos_key )); return array('success' => true, 'exists' => true); } catch (Exception $e) { // 文件不存在,继续上传 } // 准备标签 $tags = array( 'PostScript名称' => $font_info['postscript_name'], '字体ID' => $font_info['font_id'], '字体名称' => $font_info['font_name'], '字体族名' => $font_info['font_family'], '文件尺寸' => $font_info['file_size'], '格式' => $font_info['format'], '风格' => $font_info['style'] ); // 上传文件 $result = $this->cos_client->putObject(array( 'Bucket' => $this->cos_config['bucket'], 'Key' => $cos_key, 'Body' => fopen($font_path, 'rb'), 'Metadata' => array( 'x-cos-tagging' => $this->format_cos_tags($tags) ) )); return array('success' => true, 'exists' => false); } catch (Exception $e) { error_log('COS upload error: ' . $e->getMessage()); return array('success' => false, 'error' => $e->getMessage()); } } private function insert_to_mysql($font_info) { try { if (!$this->db) { throw new Exception('数据库连接未初始化'); } // 检查是否已存在 $stmt = $this->db->prepare("SELECT COUNT(*) as count FROM fontdata_table WHERE font_id = ?"); if (!$stmt) { throw new Exception('SQL准备失败: ' . $this->db->error); } $stmt->bind_param('s', $font_info['font_id']); $stmt->execute(); $result = $stmt->get_result()->fetch_assoc(); $stmt->close(); if ($result['count'] > 0) { return array('success' => true, 'exists' => true); } // 插入数据 $sql = "INSERT INTO fontdata_table ( fontname, fontfamily, postscript, font_id, fontform, fontstyle, fontsize, usage_count, prioritize ) VALUES (?, ?, ?, ?, ?, ?, ?, 0, ?)"; $stmt = $this->db->prepare($sql); if (!$stmt) { throw new Exception('SQL准备失败: ' . $this->db->error); } $prioritize = rand(1, 100000); $stmt->bind_param('ssssssii', $font_info['font_name'], $font_info['font_family'], $font_info['postscript_name'], $font_info['font_id'], $font_info['format'], $font_info['style'], $font_info['file_size'], $prioritize ); $stmt->execute(); if ($stmt->error) { throw new Exception('SQL执行失败: ' . $stmt->error); } $stmt->close(); return array('success' => true, 'exists' => false); } catch (Exception $e) { error_log('MySQL insert error: ' . $e->getMessage()); return array('success' => false, 'error' => $e->getMessage()); } } private function format_cos_tags($tags) { $formatted = array(); foreach ($tags as $key => $value) { if ($value) { $formatted[] = urlencode($key) . '=' . urlencode($value); } } return implode('&', array_slice($formatted, 0, 10)); // COS最多支持10个标签 } public function __destruct() { if ($this->db) { $this->db->close(); } } } // 初始化插件 function font_validator_init() { global $font_validator; try { $font_validator = new FontValidator(); error_log('FontValidator instance created successfully'); } catch (Exception $e) { error_log('Error creating FontValidator instance: ' . $e->getMessage()); } } add_action('init', 'font_validator_init'); // 插件激活时的处理函数 register_activation_hook(__FILE__, 'font_validator_activate'); function font_validator_activate() { // 创建存储目录 $target_dir = get_option('font_validator_storage_path', FONT_STORAGE_PATH); if (!file_exists($target_dir)) { wp_mkdir_p($target_dir); } // 设置默认选项 add_option('font_validator_storage_cos', 1); add_option('font_validator_storage_mysql', 1); add_option('font_validator_storage_local', 1); add_option('font_validator_max_size', 10); add_option('font_validator_max_files', 10); add_option('font_validator_storage_path', FONT_STORAGE_PATH); // 创建数据库表 global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $table_name = 'fontdata_table'; $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id bigint(20) NOT NULL AUTO_INCREMENT, fontname varchar(255) NOT NULL, fontfamily varchar(255) NOT NULL, postscript varchar(255) NOT NULL, font_id varchar(32) NOT NULL, fontform varchar(10) NOT NULL, fontstyle varchar(50) NOT NULL, fontsize bigint(20) NOT NULL, usage_count int(11) NOT NULL DEFAULT 0, prioritize int(11) NOT NULL, created_at timestamp DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY font_id (font_id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } // 插件停用时的清理函数 register_deactivation_hook(__FILE__, 'font_validator_deactivate'); function font_validator_deactivate() { // 保留存储的字体文件和数据库表,仅清理选项 $options = array( 'font_validator_storage_cos', 'font_validator_storage_mysql', 'font_validator_storage_local', 'font_validator_max_size', 'font_validator_max_files', 'font_validator_storage_path', 'font_validator_cos_secret_id', 'font_validator_cos_secret_key', 'font_validator_cos_region', 'font_validator_cos_bucket' ); foreach ($options as $option) { delete_option($option); } } 纯白色壁纸 相关作品列表 - 第3页 - 星盒网-高质量设计素材模版-高清图片-免费字体下载

#纯白色壁纸

标签为 #纯白色壁纸 的相关作品如下:

更多热门标签

客服

点击联系客服 点击联系客服

在线时间:09:00-18:00

关注微信公众号

关注微信公众号

客服邮箱 xfonts@qq.com
搜索