首页
wjlink
视频
投稿
直播
壁纸
更多
留言
统计
LINK
Search
1
Python 爬取YouTube某个频道下的所有视频信息
178 阅读
2
宝塔面板绑定域名套上cloudflare – 实现cdn访问拯救你的IP
128 阅读
3
Paypal外区账户/国际版绑大陆手机号注册教程
102 阅读
4
windows 使用 FFmpeg 按大小或时间来批量分割视频
85 阅读
5
苹果CMS(MACCMS)如何在标题中随机插入关键词
84 阅读
技術類
自媒体
調查
问卷调查
美國站
英國站
注册丨登录
Search
标签搜索
wordpress
V2Ray
vps
苹果cms
面板
php
宝塔
ipfs
DD
脚本
语言
上传
判断
Youtube
cdn
ip
AI
HTML
1
2
Hou
累计撰写
67
篇文章
累计收到
0
条评论
今日撰写
0
篇文章
️
首页
分类
技術類
自媒体
調查
问卷调查
美國站
英國站
页面
wjlink
视频
投稿
直播
壁纸
留言
统计
LINK
登录丨注册
搜索到
67
篇与
的结果
2024-11-08
费提供图片CDN加速,永久缓存! 外链图片解决方案.
图片发到微博上用微博做图床主打的是一个省存储费用和带宽费用,缺点就是不可控,微博一直都在做防盗链升级,直接访问图片链接返回 403,本文记录最新可用的微博图床解决方案。PS. 如果有一天实在无法使用微博做图床,微信公众号也是一种选择。{mtitle title="方案一:baidu"/}加速域名:{alert type="info"}image.baidu.com{/alert}外链路径格式{alert type="info"}https://image.baidu.com/search/down?url=图片地址{/alert}其中 url 参数指定的图片地址为完整的微博图片地址,即包含 https 协议前缀。示例{alert type="success"}https://image.baidu.com/search/down?url=https://www.gengre.men/GENGRE.MEN_.png{/alert}图片展示:(没有展示即该方法已失效) 已知的缺点存在个别地区可能无法正常展示图片,比如我进入西藏境内访问这些图片时就无法正常展示,一度以为是微博又升级了,全局代理时是正常的。使用大多数浏览器直接访问这个链接会是下载图片的提示,而不是直接显示出图片。{mtitle title="方案二:WordPress"/}WordPress 携手 Jetpack 免费提供图片 CDN 加速,国内访问速度还行加速域名:{alert type="info"}i0.wp.comi1.wp.comi2.wp.comi3.wp.com{/alert}外链路径格式{alert type="info"}https://i0.wp.com/不带https协议前缀的图片URL{/alert}url 后面直接添加不包含 https 协议前缀的微博图片地址。支持的文件格式包括:gif、png、webp、jpeg 和 jpg示例{alert type="success"}https://i0.wp.com/www.gengre.men/GENGRE.MEN_.png{/alert}图片展示:(没有展示即该方法已失效)功能特点:开源:https://code.trac.wordpress.org/browser/photon站点加速器利用多级缓存,包括全球分布的 CDN,以确保尽可能快地提供图像,国内访问的是香港节点。支持 URL 参数调整图片,参数使用文档:https://developer.wordpress.com/docs/site-accelerator/site-accelerator-api/URL 参数: 参数 描述 参考 w 宽度(px) w=50 h 高度(px) h=50 crop 裁剪图像 x,y,w,h (defaults to %) crop=5,10,20,40 resize 调整大小并裁剪到给定尺寸 (px) resize=250,300 fit 保持纵横比 (px) fit=100,100 lb 添加边框,颜色代码是可选的(默认为黑色) lb=300,250,1A4E9F ulb 删除边框(自动检测边框颜色) ulb=true filter 应用各种 imagefilter() 滤镜 filter=grayscale brightness 调整亮度 brightness=100 contrast 调整对比度 contrast=50 colorize 调整色调 colorize=255,0,0 smooth 平滑过度图像 smooth=2 zoom size images for high pixel ratio devices zoom=2 quality 设置 JPEG 图像的质量 quality=50 strip 从 JPEG 图像中删除元数据 strip=all 示例:{alert type="info"}https://i0.wp.com/www.gengre.men/GENGRE.MEN_.png?lb=300,250,1A4E9F{/alert}图片展示:(没有展示即该方法已失效)已知的缺点加速图片"永久"有效,无法删除缓存!不支持替换图片。不支持加速大于 55M 的图片。缩放参数被限制在 1 到 10 之间。路径参数调整图片会导致 GIF 动画失效。在某些情况下,官方会压缩原始图片进行存储。{mtitle title="方案三:cdnjson"/}加速域名:{alert type="info"}cdn.cdnjson.com{/alert}外链路径格式{alert type="info"}https://cdn.cdnjson.com/不带https协议前缀的图片URL{/alert}示例{alert type="success"}https://cdn.cdnjson.com/www.gengre.men/GENGRE.MEN_.png{/alert}图片展示:(没有展示即该方法已失效)已知的缺点可以用,但国内访问较慢{mtitle title="方案四:ipfsscan"/}加速域名:{alert type="info"}cdn.ipfsscan.io/weibo/{/alert}外链路径格式{alert type="info"}https://cdn.ipfsscan.io/weibo/去掉微博图片链接中域名部分后的链接{/alert}示例{alert type="success"}https://cdn.ipfsscan.io/weibo/large/488c829bgw1es31sl8s7rg2091066gqc.gif{/alert}图片展示:(没有展示即该方法已失效){mtitle title="方案五:Weserv.nl"/}加速域名:{alert type="info"}images.weserv.nl{/alert}外链路径格式{alert type="info"}https://images.weserv.nl/?url=图片地址{/alert}示例{alert type="success"}https://images.weserv.nl/?url=https://www.gengre.men/GENGRE.MEN_.png{/alert}图片展示:(没有展示即该方法已失效)
2024年11月08日
17 阅读
0 评论
0 点赞
2024-11-08
为网站添加网页加载动画
网页加载的时候先显示一个动画,等加载完成后,再显示网页,这样做过度比较自然。用户体验感比较好。原理原理是,给网页顶部放一个元素,元素占满全屏,加载完成后,再通过JS移除这个元素即可。简单在网页顶部写个代码,一个div,作为容器,然后设置样式,给占满全屏。<style> .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; } </style> <div class="loading-animations" id="loading-warp"></div>接下来,监听网页事件,加载完成后,给移除他,或者设置样式display为none。网页加载完成事件有window.onload,但是这个要覆盖其他的方法,所以使用监听器最好 window.addEventListener('load', function () { let loader = document.getElementById("loading-warp"); loader.style.display = "none" });效果如下:看得出来,比较生硬。并且没有任何东西,就是全屏展示,然后等待网页加载完消失。这个时候,修改一下样式。给网页添加一个渐变效果,在消失的时候,缓慢消失。修改上面的style,加入了一个transition动画,和opacity透明度。默认为1 .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; transition: 1s; opacity: 1; } .loading-animations-out { opacity: 0; } 等网页加载完成后,给元素添加上loading-animations-out类,就可以实现渐变消失。消失以后,等待1秒,将元素移除即可。 window.addEventListener('load', function () { let loader = document.getElementById("loading-warp"); loader.className = "loading-animations loading-animations-out";//使用渐隐的方法淡出loading page setTimeout(() => { loader.style.display = "none" }, 1000); });那么,实现效果会这样进阶都这么做了,那么再搞个加载图就完事大吉了。不过对于前端来说,使用图片,会再一次请求服务器。用户第一次访问的时候,图片可能加载不出来。所以,使用svg输出内容,或者使用css动画,最合适。既然CSS动画了,那就看一个网站吧:https://labs.danielcardoso.net/load-awesome/animations.html网站包含了很多CSS加载动画,html内容和css内容都贴出来了。甚至还有不同样式和大小的代码接下来,再修改代码内容。主要在样式里面,将元素容器设置为flex,垂直居中。(选了一个简单的动画,不然代码有点多。)<style> .loading-animations { background: #666; position: fixed; left: 0; right: 0; top: 0; bottom: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; transition: 1s; opacity: 1; } .la-ball-clip-rotate, .la-ball-clip-rotate > div { position: relative; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } .la-ball-clip-rotate { display: block; font-size: 0; color: #fff; } .la-ball-clip-rotate.la-dark { color: #333; } .la-ball-clip-rotate > div { display: inline-block; float: none; background-color: currentColor; border: 0 solid currentColor; } .la-ball-clip-rotate { width: 32px; height: 32px; } .la-ball-clip-rotate > div { width: 32px; height: 32px; background: transparent; border-width: 2px; border-bottom-color: transparent; border-radius: 100%; -webkit-animation: ball-clip-rotate .75s linear infinite; -moz-animation: ball-clip-rotate .75s linear infinite; -o-animation: ball-clip-rotate .75s linear infinite; animation: ball-clip-rotate .75s linear infinite; } .la-ball-clip-rotate.la-sm { width: 16px; height: 16px; } .la-ball-clip-rotate.la-sm > div { width: 16px; height: 16px; border-width: 1px; } .la-ball-clip-rotate.la-2x { width: 64px; height: 64px; } .la-ball-clip-rotate.la-2x > div { width: 64px; height: 64px; border-width: 4px; } .la-ball-clip-rotate.la-3x { width: 96px; height: 96px; } .la-ball-clip-rotate.la-3x > div { width: 96px; height: 96px; border-width: 6px; } /* * Animation */ @-webkit-keyframes ball-clip-rotate { 0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); } 50% { -webkit-transform: rotate(180deg); transform: rotate(180deg); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } } @-moz-keyframes ball-clip-rotate { 0% { -moz-transform: rotate(0deg); transform: rotate(0deg); } 50% { -moz-transform: rotate(180deg); transform: rotate(180deg); } 100% { -moz-transform: rotate(360deg); transform: rotate(360deg); } } @-o-keyframes ball-clip-rotate { 0% { -o-transform: rotate(0deg); transform: rotate(0deg); } 50% { -o-transform: rotate(180deg); transform: rotate(180deg); } 100% { -o-transform: rotate(360deg); transform: rotate(360deg); } } @keyframes ball-clip-rotate { 0% { -webkit-transform: rotate(0deg); -moz-transform: rotate(0deg); -o-transform: rotate(0deg); transform: rotate(0deg); } 50% { -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); transform: rotate(180deg); } 100% { -webkit-transform: rotate(360deg); -moz-transform: rotate(360deg); -o-transform: rotate(360deg); transform: rotate(360deg); } } </style> <div class="loading-animations" id="loading-warp"> <div class="la-ball-clip-rotate"> <div></div> </div> </div>这样,效果就比较不错了。当然,还有很多优化的,例如背景颜色,加载样式大小什么的。转载于:https://www.lovestu.com/loading-animation.html
2024年11月08日
17 阅读
0 评论
0 点赞
2024-09-07
WordPress火车头发布接口标准版Locoy.php(支持4.7至最新5.1.X)
首先,感谢作者Lily编写的代码,即便劣币驱逐良币的今天,这个版本的wordpress发布接口仍然算得上最经典之作。1、将Locoy.php文件放在WP站点的根目录,自行修改其中的发布密码2、模块文件导入方法:在采集任务中导入“Wordpress免登陆-发布接口.wpm”发布模块文件,或将文件拷贝到火车头的\Module\ 目录下。如果第二步看不懂,是因为你火车采集水平太LOW,好好百度一下,相信很快能掌握发布模块的正确使用方法。3、模块重点参数列表:post_title 必选 标题 post_content 必选 内容 tag 可选 标签 post_category 可选 分类 post_date 可选 时间 post_excerpt 可选 摘要 post_author 可选 作者 category_description 可选 分类信息 post_cate_meta[name] 可选 自定义分类信息 post_meta[name] 可选 自定义字段 post_type 可选 文章类型 默认为'post' post_taxonomy 可选 自定义分类方式 post_format 可选 文章形式 4、Locoy部分代码,重点区域:<?php /* WordPress免登录发布接口,支持最新Wordpress4.8.2 版本号: T3 适用于火车头采集器7.6-9.6 === 由小男孩伪原创友情提供:http://xiaoboy.CN === 更新说明 T3: 2017.11.03 1、优化了验证标题重复 2、优化了附件、图片、缩略图的上传和生成 T2: 2017.10.23 1、增加了对多个分类方式的发布参数(post_taxonomy_list),使用方法请参考功能特性 2、修复BUG: 分类名称如果含有数字会导致分类错误 T1:2017.10.12 1、旧版发布接口重新设计,新版本号为T1,以后不再对旧版升级维护.旧版本支持3.X-4.8.2 2、修复BUG:当规则中没有发布模块中某个参数时会导致发布数据异常(会显示db:标签名) 3、优化strtoarray函数 ■ 功能特性: 分类(category): 1、分类支持分类名和分类ID, 系统自动判断 2、多分类处理(多个分类请用逗号隔开) 3、自动创建分类,如果网站内没有这个分类,会自动创建分类。 4、自动创建父分类, 适用于想要设置父分类并且网站中不存在. 使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_parent_cate 5、添加分类描述 使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 category_description 标签: 1、多标签处理(多个标签请用逗号隔开) 作者: 1、多作者处理, 可设置多个作者随机发布文章, 发布参数中指定post_author 2、自定义作者功能,如果提交的数据为用户名的话,会自动检测系统是否存在该用户,如果已存在则以该用户发布,不存在则自动新建用户(接口以针对中文用户名进行了处理) 图片和缩略图: 1、Web图片上传,无需FTP上传 2、自动设置【标签:内容】的第一张图片为文章的特色图片. 3、支持自定定义缩略图(特色图像) 使用方法: WEB发布模块/高级功能/文件上传设置/ 增加 缩略图所在的标签,表单名为: thumb递增数字 3、标准的php.ini单次最大文件上传数为20个, 如果发布的内容附件超过20个,将会出错. 如果遇到此问题请更改php.ini的max_file_uploads 参数 . 或者更换上传方式为FTP 时间和预约发布: 1、正确的时间格式为2017-10-01 23:45:55或者2017-10-01 23:45 2、自动处理服务器时间与博客时间的时区差异 3、随机时间安排与预约发布功能: 可以设定发布时间以及启用预约发布功能. 启用预约发布后,如果POST过来的数据包涵时间,则以时间为准立即发布,反之则以接口文件配置时间发布。 评论: 1、发布评论,支持评论时间、评论作者、评论内容, 需要在火车头->Web发布模块/内容发布参数/ ->新增 comment、commentdate、commentauthor三个参数,分别对应评论内容、评论时间、评论作者. 三个参数缺一不可 其它: 1、标题重复判断, 打开参数配置中的$checkTitle,即可判断标题是否重复,对于重复结果不予发布. 2、发布文章后自动ping,需要再后台设置->撰写->更新服务 填入ping地址 3、'pending review' 更新文章状态pending(审核) 为 publish(所有人可见) 自定义字段 1、使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_meta['字段名'] 自定义文章类型(post_type) 1、使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_type 自定义文章形式(post_format) 1、使用此功能需要修改配置参数 $postformat=true;并在火车头->Web发布模块/内容发布参数/->新增发布参数post_format, 标签内容必须为: 图像: post-format-image 视频: post-format-video 自定义分类(taxonomy): 1、使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_taxonomy, 使用taxonomy之后, 文章只能发布在taxonomy所属的分类下, 分类名称或者ID请填写在分类category 自定义分类--多个分类--(taxonomy): 1、使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_taxonomy_list[taxonomy_name], 使用后可以将文章归属到多个自定义分类下, 多个term必须使用|||隔开 自定义分类信息(add_term_meta) 1、使用方法: WEB发布模块/高级功能/内容发布参数/ -> 增加 post_cate_meta['meta_key'], 标签内容可以为文本或者数组,数组必须参照格式: key$$value|||key$$value|||key$$value 模块参数列表: post_title 必选 标题 post_content 必选 内容 tag 可选 标签 post_category 可选 分类 post_date 可选 时间 post_excerpt 可选 摘要 post_author 可选 作者 category_description 可选 分类信息 post_cate_meta[name] 可选 自定义分类信息 post_meta[name] 可选 自定义字段 post_type 可选 文章类型 默认为'post' post_taxonomy 可选 自定义分类方式 post_format 可选 文章形式 */ //-------------------配置参数开始,根据需要修改------------------------- $post_author_default = 1; //默认作者的id,默认为admin(这里是作者ID号码,并非作者名) $post_status = 'publish'; //立即发布 pending 审核 draft 草稿箱 $time_interval = '1'; //发布时间间隔,单位为秒 。可设置随机数值表达式,如12345 * rand(0,17),设置为负数可将发布时间设置为当前时间减去这里设置的时间 $post_next = 'now'; //now:发布时间=当前时间+间隔时间值 //next: 发布时间=最后一篇时间+间隔时间值 $post_ping = false; //发布后是否执行ping $translate_slug = false; //是否将中文标题转换为MD5值,如需开启请设置为true或MD5值长度,建议设置为大于10,小于33的数字。 $secretWord = 'qq654321114'; //接口密码,如果需要密码,则设为$secretWord='你的密码'; $checkTitle = true; //检测标题是否重复 $audiosql = true; //是否添加媒体资源 $postformat = true; //开启文章形式 //-------------------配置参数结束,以下请勿修改------------------------- //开始 if (isset($_GET['action'])) { $hm_action = $_GET['action']; } else { die("操作被禁止>"); } $post = $_POST; include_once "./wp-config.php"; if ($post_ping) require_once("./wp-includes/comment.php"); if ($hm_action == "list") { hm_print_catogary_list(); }elseif($hm_action == "update") { hm_publish_pending_post(); }elseif($hm_action == "save") { //检查通讯密码 if (isset($secretWord) && ($secretWord != false)) { if (!isset($_GET['secret']) || $_GET['secret'] != $secretWord) { die('接口密码错误,请修改配置文件或者修改发布参数,保持两者统一。'); } } extract($post); //判断标题是否为空 if ($post_title == '[标签:标题]' || $post_title == '') { die('标题为空'); } //if ($post['post_meta']['down_url']=='[标签:下载地址]'||$post['post_meta']['down_url']=='') {die('下载地址为空');} //检查标题是否重复 if ($checkTitle) { $post_title = trim(hm_strip_slashes($post_title)); $sql = "SELECT `ID` FROM $wpdb->posts WHERE `post_title` = '$post_title'"; $t_row = $wpdb -> query($sql); if ($t_row) { die('标题重复,发布成功'); }; } //判断标题是否为空 if ($post_content == '[标签:内容]' || $post_content == '') { die('内容为空'); } //检查自定义文章类型 if (empty($post_type) || strpos($post_type, '[') || strpos($post_type, ']')) { $post_type = 'post'; } //检查自定义分类目录 if (empty($post_taxonomy) || strpos($post_taxonomy, '[') || strpos($post_taxonomy, ']')) { $post_taxonomy = 'category'; } //检查分类描述是否未设置 if (empty($category_description) || strpos($category_description, '[') || strpos($category_description, ']')) { $category_description = ''; } //检查自定义字段 if (array_key_exists('post_meta', $post)) { $post_meta = $post['post_meta']; } //检查自定义分类信息 if (array_key_exists('post_cate_meta', $post)) { $post_cate_meta = $post['post_cate_meta']; } //检查发布时间 if (!isset($post_date) || strlen($post_date) < 8) $post_date = false; //检查作者 if (empty($post_author)) { $post_author = $post_author_default; } else { $post_author = hm_add_author($post_author); } $post_content = fileHandle('fujian', $post_content); //echo $post_content; fileHandle('thumb'); hm_do_save_post(array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_category' => $post_category, 'post_excerpt' => $post_excerpt, 'post_type' => $post_type, 'post_taxonomy' => $post_taxonomy, 'tags_input' => $tag, 'post_date' => $post_date, 'post_author' => $post_author, 'fujianid' => $fujianid ) ); echo '发布成功'; } else { echo '非法操作['.$hm_action.']'; } //附件处理 //$filename 附件名称 //$content 标签内容,为空返回首张图片ID function fileHandle($filesnames, $content = null) { global $thumbid, $audiosql; if (!empty($_FILES[$filesnames.'0']['name'])) { require_once('./wp-load.php'); require_once('./wp-admin/includes/file.php'); require_once('./wp-admin/includes/image.php'); $i = 0; while (isset($_FILES[$filesnames.$i])) { $fujian[$i] = $_FILES[$filesnames.$i]; $filename = $fujian[$i]['name']; //print_r ($fujian[$i]); $fileExt = array_pop(explode(".", $filename)); //附件保存格式【时间】 $upFileTime = date("YmdHis"); //更改上传文件的文件名为时间+随机数+后缀 $fujian[$i]['name'] = $upFileTime."-".uniqid().".".$fileExt; $uploaded_file = wp_handle_upload($fujian[$i], array('test_form' => false)); //print_r ($uploaded_file); $content = str_replace("\'".$filename."\'", "\"".$uploaded_file['url']."\"", $content); $content = str_replace($filename, $uploaded_file['url'], $content); //echo $content; if (isset($uploaded_file['error'])) { echo "文件上传失败"; wp_die($uploaded_file['error']); } $file = $uploaded_file['file']; $new_file = iconv('GBK', 'UTF-8', $file); $url = iconv('GBK', 'UTF-8', $uploaded_file['url']); $type = $uploaded_file['type']; $attachment = array( 'guid' => $url, 'post_mime_type' => $type, 'post_title' => $filename, 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, $new_file); if ($audiosql) { if (strpos($fujian[$i]['type'], 'audio') !== false) { $newcontent = ''; $content = str_replace($url, $newcontent, $content); } } if (strpos($fujian[$i]['type'], 'image') !== false) { if (empty($thumbid) || $filesnames == 'thumb') $thumbid = $attach_id; $attach_data = wp_generate_attachment_metadata($attach_id, $file); $attach_data['file'] = iconv('GBK', 'UTF-8', $attach_data['file']); foreach($attach_data['sizes'] as $key => $sizes) { $sizes['file'] = iconv('GBK', 'UTF-8', $sizes['file']); $attach_data['sizes'][$key]['file'] = $sizes['file']; } wp_update_attachment_metadata($attach_id, $attach_data); } $i++; } } return $content; } function hm_tranlate($text) { global $translate_slug; $pattern = '/[^\x00-\x80]/'; if (preg_match($pattern, $text)) { $htmlret = substr(md5($text), 0, $translate_slug); } else { $htmlret = $text; } return $htmlret; } function hm_print_catogary_list() { $cats = get_categories("hierarchical=0&hide_empty=0"); foreach((array) $cats as $cat) { echo '<<<'.$cat -> cat_ID.'--'.$cat -> cat_name.'>>>'; } } function hm_get_post_time($post_next = "normal") { global $time_interval; global $wpdb; $time_difference = absint(get_option('gmt_offset')) * 3600; $tm_now = time() + $time_difference; if ($post_next == 'now') { $tm = time() + $time_difference; } else { //if ($post_next=='next') $tm = time() + $time_difference; $posts = $wpdb -> get_results("SELECT post_date FROM $wpdb->posts ORDER BY post_date DESC limit 0,1"); foreach($posts as $post) { $tm = strtotime($post -> post_date); } } return $tm + $time_interval; } function hm_publish_pending_post() { global $wpdb; $tm_now = time() + absint(get_option('gmt_offset')) * 3600; $now_date = date("Y-m-d H:i:s", $tm_now); $wpdb -> get_results("UPDATE $wpdb->posts set `post_status`='publish' WHERE `post_status`='pending' and `post_date`<'$now_date'"); } function hm_add_category($post_category, $post_taxonomy = 'category') { if (!function_exists('wp_insert_category')) { include_once "./wp-admin/includes/taxonomy.php"; } global $wpdb, $post_cate_meta, $post_parent_cate, $category_description; $post_category_new = array(); $post_category_list = array_unique(explode(",", $post_category)); foreach($post_category_list as $category) { $cat_ID = $category; if (!isInteger($cat_ID) || $cat_ID < 1) { $category = $wpdb -> escape($category); $term = get_term_by('name', $category, $post_taxonomy, 'ARRAY_A'); $cat_ID = $term['term_id']; if ($cat_ID == 0) { //检查父分类是否存在和创建父分类->start if (!empty($post_parent_cate) && $post_parent_cate != '[标签:父分类]') { $parent = intval($post_parent_cate); if ($parent == 0) { $post_parent_cate = $wpdb -> escape($post_parent_cate); $term = get_term_by('name', $post_parent_cate, $post_taxonomy, 'ARRAY_A'); $cat_ID = $term['term_id']; if ($parent == 0) { $parent = wp_insert_category(array('cat_name' => $post_parent_cate, 'taxonomy' => $post_taxonomy)); } } $cat_ID = wp_insert_category(array('cat_name' => $category, 'category_description' => $category_description, 'category_parent' => $parent, 'taxonomy' => $post_taxonomy)); } else { $cat_ID = wp_insert_category(array('cat_name' => $category, 'category_description' => $category_description, 'taxonomy' => $post_taxonomy)); } //检查父分类是否存在和创建父分类->end //定义分类信息->start if (!empty($post_cate_meta)) { foreach(array_unique(array_filter($post_cate_meta)) as $key => $value) { $value = strtoarray($value); add_term_meta($cat_ID, $key, $value); } } //定义分类信息->end } } array_push($post_category_new, $cat_ID); } return $post_category_new; } function add_category($post_category, $post_taxonomy = 'category') { if (!function_exists('wp_insert_category')) { include_once "./wp-admin/includes/taxonomy.php"; } global $wpdb; $post_category_new = array(); $post_category_list = array_unique(explode(",", $post_category)); foreach($post_category_list as $category) { $cat_ID = $category; if (!isInteger($cat_ID) || $cat_ID < 1) { $category = $wpdb -> escape($category); $term = get_term_by('name', $category, $post_taxonomy, 'ARRAY_A'); $cat_ID = $term['term_id']; if ($cat_ID == 0) { $cat_ID = wp_insert_category(array('cat_name' => $category, 'taxonomy' => $post_taxonomy)); } } array_push($post_category_new, $cat_ID); } return $post_category_new; } function isInteger($value) { return is_numeric($value) && is_int($value + 0); } function hm_add_author($post_author) { global $wpdb, $post_author_default; $User_ID = intval($post_author); if ($User_ID == 0) { $pattern = '/[^\x00-\x80]/'; if (preg_match($pattern, $post_author)) { $LoginName = substr(md5($post_author), 0, 10); } else { $LoginName = $post_author; } $User_ID = $wpdb -> get_col("SELECT ID FROM $wpdb->users WHERE user_login = '$LoginName' ORDER BY ID"); $User_ID = $User_ID[0]; if (empty($User_ID)) { $website = 'http://'.$_SERVER['HTTP_HOST']; $userdata = array( 'user_login' => "$LoginName", 'first_name' => $post_author, 'user_nicename' => $post_author, 'display_name' => $post_author, 'nickname' => $post_author, 'user_url' => $website, 'role' => 'contributor', 'user_pass' => NULL ); $User_ID = wp_insert_user($userdata); } $post_author = $User_ID; } else { $post_author = $post_author_default; } return $post_author; } function hm_strip_slashes($str) { if (get_magic_quotes_gpc()) { return stripslashes($str); } else { return $str; } } function checkDatetime($str) { $date = strtotime($str); if ($date > 31500000) { return true; } else { return false; } } function formatdate($date) { $d = date('Y-m-d'); if (strpos($date, 'today') !== false) { return str_replace('today at', $d, $date); } if (strpos($date, 'Today') !== false) { return str_replace('Today at', $d, $date); } $dd = date('Y-m-d', time() - 84600); if (strpos($date, 'yesterday') !== false) { return str_replace('yesterday at', $d, $date); } if (strpos($date, 'Yesterday') !== false) { return str_replace('yesterday at', $d, $date); } } //字符串转换为数组 //字符串的格式必须为 //$str = 'eo_description$$seo_description|||seo_keywords$$seo_keywords|||seo_title$$seo_title'; function strtoarray($str) { if (strpos($str, '|||') !== false) { $str = explode('|||', $str); if (strpos($str[0], '$$') !== false) { foreach($str as $k => $v) { $v = explode('$$', $v); $r[$v[0]] = $v[1]; } $str = $r; } } return $str; } function hm_do_save_post($post_detail) { global $post, $post_author, $post_ping, $post_status, $translate_slug, $post_next, $post_meta, $comment, $commentdate, $commentauthor, $wpdb, $postformat, $post_format, $post_taxonomy_list, $thumbid; extract($post_detail); $post_title = trim(hm_strip_slashes($post_title)); $post_name = $post_title; if ($translate_slug) $post_name = hm_tranlate($post_name); $post_name = sanitize_title($post_name); if (strlen($post_name) < 2) $post_name = ""; $post_content = hm_strip_slashes($post_content); //echo $post_content; $tags_input = str_replace("|||", ",", $tags_input); if (isset($post_date) && $post_date && checkDatetime($post_date)) { $tm = strtotime($post_date); $time_difference = absint(get_option('gmt_offset')) * 3600; $post_date = date("Y-m-d H:i:s", $tm); $post_date_gmt = gmdate('Y-m-d H:i:s', $tm - $time_difference); } else { $tm = hm_get_post_time($post_next); $time_difference = absint(get_option('gmt_offset')) * 3600; $post_date = date("Y-m-d H:i:s", $tm); $post_date_gmt = gmdate('Y-m-d H:i:s', $tm - $time_difference); if ($post_status == 'next') $post_status = 'publish'; } $post_category = hm_add_category($post_category, $post_taxonomy); $post_data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_type', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_name', 'tags_input'); $post_data = add_magic_quotes($post_data); $postID = wp_insert_post($post_data); //设置文章显示类型format @preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $post_content, $match); //print_r ($match); if (count($match[2]) >= 3) { set_post_format($postID, 'image'); for ($i = 0; $i < 3; $i++) { add_post_meta($postID, "mult_img".$i, $match[2][$i], true); } } else { set_post_format($postID, 'gallery'); } fileHandle($match[2][0]); //设定缩略图 set_post_thumbnail($postID, $thumbid); //自定义分类方式(taxonomy) if ($post_taxonomy != 'category' && !empty($post_taxonomy)) { wp_set_object_terms($postID, $post_category, $post_taxonomy); } //多个自定义分类方式(taxonomy) if (!empty($post_taxonomy_list)) { foreach($post_taxonomy_list as $k => $v) { $v = strtoarray($v); if (is_array($v)) { foreach($v as $kk => $vv) { $vv = add_category($vv, $k); wp_set_object_terms($postID, $vv, $k); } } else { $v = add_category($v, $k); wp_set_object_terms($postID, $v, $k); } } } //归档文章形式->start if (!empty($post_format) && $postformat == true) { if ($post_format == 'post-format-image' || $post_format == 'post-format-video') { wp_set_post_terms($postID, $post_format, 'post_format'); } } //归档文章形式->end //发布自定义栏目 if (!empty($post_meta)) { foreach($post_meta as $key => $value) { $ret = add_post_meta($postID, $key, $value, true); if (!$ret) { delete_post_meta($postID, $key); add_post_meta($postID, $key, $value, true); } } } //发布评论->start if (!empty($comment)) { //格式化评论内容 $comment = str_replace(array("\r\n", "\r", "\n"), "", $comment); $arraycomment = explode('|||', $comment); //格式化评论时间 $commentdate = str_replace(array("\r\n", "\r", "\n"), "", $commentdate); $arraycommentdate = explode('|||', $commentdate); //格式化评论作者 $commentauthor = str_replace(' ', '', $commentauthor); $commentauthor = str_replace(array("\r\n", "\r", "\n"), "", $commentauthor); $arraycommentauthor = explode('|||', $commentauthor); //评论计数 $comment_count = count($arraycomment) - 1; //更新文章评论数 $wpdb -> get_results("UPDATE $wpdb->posts set `comment_count` = $comment_count WHERE `ID` = $postID"); //写入评论 foreach($arraycommentauthor as $k => $v) { //判断评论时间 if ($v != '') { $format = "Y-m-d H:i:s"; $d = formatdate($arraycommentdate[$k]); $d = strtotime($d); if ($d != '') { $date = date($format, $d); $gmtdate = gmdate($format, $d); } else { $date = date($format); $gmtdate = gmdate($format); } //写入数据库 $res = $wpdb -> get_results("INSERT INTO $wpdb->comments (`comment_post_ID`,`comment_author`,`comment_date`,`comment_date_gmt`,`comment_content`,`user_id`) VALUES ($postID,'$v','$date','$gmtdate','$arraycomment[$k]',1)"); } } } //发布评论->end // 自定PING,需要再网站后台设置->撰写->更新服务器 下面填写PING地址 if ($post_ping) generic_ping(); }
2024年09月07日
81 阅读
0 评论
0 点赞
2024-09-05
CSS实现固定的布局
有间隔,间隔相等,为15px无论删除增加 div.item 都不会影响排版实现方式随意 第一种:<style> * { box-sizing: border-box; } .box { display: grid; gap: 15px; grid-template-columns: repeat(2, 1fr); width: 30%; margin: 0 auto; border: 1px solid #ff6800; padding: 15px; } .item { height: 150px; background: coral; } .item:nth-child(3n) { grid-column: 1 / 3; } </style> <div class="box"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>第二种:<style> * { box-sizing: border-box; } .box { width: 30%; margin: 0 auto; display: flex; flex-wrap: wrap; border: 1px solid #ff6800; padding: 7.5px; } .item { background-color: #ff6800; height: 150px; width: 50%; border: 7.5px solid #ffff } .item:nth-child(3n) { width: 100%; } </style> <div class="box"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>
2024年09月05日
27 阅读
0 评论
0 点赞
2024-09-05
国内外短信接码平台合集
https://ch.freephonenum.comhttps://smsreceivefree.comhttps://zh.mytrashmobile.comhttps://www.receive-sms-online.infohttps://receiveasms.comhttps://sms-online.co/receive-free-smshttps://receive-sms.comhttp://receivefreesms.com/https://www.receivesmsonline.net/https://www.freeonlinephone.org/https://us-phone-number.comhttps://temporary-phone-number.comhttps://www.receivesms.co/https://www.smstibo.com/PingMe 免费接码平台: https://pingme.tel/receive-sms-online-cn/http://receivefreesms.net/http://receivesmsonline.in/https://sms-receive.net/https://www.receivesms.net/https://www.yaysms.com/国内免费接码平台超级云短信: http://www.bfkdim.com/隐私短信:https://www.yinsiduanxin.com云短信: https://www.materialtools.com/在线短信:http://www.smszk.com/游客短信:https://www.visitorsms.com/cn免费接码:https://www.becmd.com/接码平台:http://www.114sim.com/ http://zg.114sim.com/云短信:https://yunduanxin.net/免费接码:http://z-sms.com/掠影网络:https://zusms.com/receiving-sms免费接码:https://www.shejiinn.com/云接码:https://yunjiema.net云验证码:https://www.cnwml.com免费接码:https://www.mffac.com接码科技免费平台:http://jiema.tech/sms/接码号:https://jiemahao.com免费接码: https://mianfeijiema.com/小鸟接码平台: http://www.xnsms.com/zero接码平台: https://xinghai.party/LotHelper: https://www.lothelper.com/cn免费接码平台: http://www.zsrq.net/国外收费接码平台https://5sim.net便宜国家:俄罗斯( Russia )罗马尼亚( Romania )菲律宾( Philippines )蒙古( Mongolia )拉脱维亚( Latvia )哈萨克斯坦( Kazakhstan )以色列( Israel )哥伦比亚( Colombia )http://smspva.com 这家起步就是0.1$,也就是最便宜7毛起步https://www.jindousms.com/ 国人开的国外号码接码平台,不做国内业务TG群https://meiguojiema.com 又一个国人开的国外接码,主要美国和加拿大号码https://www.smsjiema.com/ 美国实体卡号码,可以注册GVhttps://www.textverified.com/ 2刀起充,接码也挺贵的https://autofications.com/ 不算贵也不算便宜,最低$0.5一个码国内收费接码平台不确定什么时候会跑路,用多少充多少米粒接码:http://www.yyyung.cn:9000/ 【2元起充】小米平台: http://mili02.com:9000/ 两个是一样的,账号通用可可码 : http://www.hfsxf.com/666验证码平台: http://www.666yzm.com/梦码平台:https://www.5151mma.com/ 【1元起充】接码科技:http://sim.vividly.cn/app/login.php?q= 【1元起充,但要求账号余额大于10元才能使用接码】路虎接码平台: http://www.luhujiema.com/短信验证码接码平台 :http://www.zhbmz.com 【起充不限】飞享平台:http://feixiang.taixingwds.com/可可验证:http://www.hfsxf.com/oszc.html乌龟码短信验证码平台: http://wuguima.cn/致敬先烈:http://www.myzjxl.com/新码: http://www.xinma1.com:10001/zc.html信鸽: http://html.reyne.cn/考拉云: http://www.kaolama.com/斑码: http://www.banma1024.net/reg/?wafcloud=1 【10元起充】魔卡接码平台: http://92moka.com/爱码接码平台: http://www.aimajiema.com/乐可可接码平台: http://lekeke.92zyb.com/番茄接码: http://ifanqie.cc/迅捷验证码平台: http://xunjie.taixingwds.com/蓝狐数据共享平台: http://xiangjiuer.cn/码大师: http://mds.js.sdmpay.com/赵云接码平台: http://www.17lift.com/神码: http://202.79.167.29/新爱码:http://aima.taixingwds.com
2024年09月05日
22 阅读
0 评论
0 点赞
2024-09-05
windows 使用 FFmpeg 按大小或时间来批量分割视频
{card-list}{card-list-item}1. 安装 FFmpeg首先,确保您已经安装了 FFmpeg 并将其添加到系统的环境变量中。{/card-list-item}{card-list-item}2. 编写批处理文件 (split_videos.bat)将以下代码保存为 split_videos.bat 文件:@echo off setlocal enabledelayedexpansion REM 输入目录(存放要分割的视频文件) set "input_directory=C:\path\to\your\videos" REM 输出目录(存放分割后的视频文件) set "output_directory=C:\path\to\output" REM 每个分割文件的最大大小(例如:1000M 表示 1000MB) set max_size=1000M REM 每个时间片段的长度(以秒为单位) set segment_time=600 REM 创建输出目录(如果不存在) if not exist "%output_directory%" mkdir "%output_directory%" REM 遍历输入目录中的所有视频文件 for %%f in ("%input_directory%\*.mp4" "%input_directory%\*.avi" "%input_directory%\*.mov" "%input_directory%\*.mkv") do ( REM 获取文件名和扩展名 set "filename=%%~nf" set "extension=%%~xf" REM 输出文件名 set "output_file=%output_directory%\!filename!_part%%03d!extension!" REM 执行 FFmpeg 按大小分割视频,结合时间片段 ffmpeg -i "%%f" -c copy -map 0 -segment_time %segment_time% -f segment -reset_timestamps 1 -fs %max_size% "!output_file!" ) echo 视频分割完成! pause {/card-list-item}{card-list-item}3. 关键点解释setlocal enabledelayedexpansion:启用了延迟变量扩展。这意味着在批处理中,变量如 !filename! 将在每次迭代时正确地解析。这是为了确保在循环体内的变量能够正确扩展并传递给 ffmpeg。使用 ! 而不是 % 来引用变量:在 for 循环中,我们使用 !filename! 而不是 %filename% 来引用变量。这是因为延迟扩展模式确保了变量在每次循环中都能正确地使用当前文件名。"%output_directory%\!filename!_part%%03d!extension!":确保输出文件名模式是正确的格式,能够支持多个文件的分割。{/card-list-item}{card-list-item}4. 测试手动单个视频测试,视频文件夹cmdffmpeg -i "1.mp4" -c copy -map 0 -segment_time 600 -f segment -reset_timestamps 1 -fs 1000M "output_part%03d.mp4"{/card-list}
2024年09月05日
85 阅读
0 评论
0 点赞
2024-08-23
您的账号已停用:Google谷歌账号被停用,如何申请解封?附最新保姆级教程
有群友说他的Google账户被停用了如何申请解封呢。出现了下图的情况接下来就跟着步骤自己申请解封,成功几率对半吧,如果不行在申请一次。 以此为例,教下大家如何解封。先来解释下账号为什么会被停用?这里面可能有三种情况:1、使用的代理节点频繁切换,或者你用的代理节点被过多人使用,其它人也可能使用了谷歌服务,谷歌后台检测出同一个IP登录了多个账号,认为你的账号与某些可疑账号存在关联。2、一个账号登录多个设备,或一个设备登录多个账号,切换频繁。谷歌后台判定可能有多个账号被群控,或是账号信息被泄露。3、违反了Google的其他政策,比如入侵或盗用账号、违反产品政策发送广告、儿童不适宜内容、创建虚假身份欺骗用户、骚扰或是威胁、发布垃圾内容、滥用多个账号等等。那么,停用后会出现什么情况?最直观的表现是你的账号无法登录 Google 服务。登录账号之后,系统会显示错误信息,或是进行账号安全锁定,或是需要你账号认证是否是本人在操作等情况。详见上图。另外,你还有可能收到来自 Google 的电子邮件或短信,告诉您Google号已被停用。当然,这种邮件提醒待遇我还没遇到过。接下来,说说如何解决。登录你的账号,按提示写申诉理由进行恢复,同时填写一个其它邮箱的地址,用于接受谷歌的审核信息。以上操作很简单,难点在于申诉理由怎么写?我直接给个模板,大家对照着抄即可。内容为英文,因为谷歌审核人员能读懂英语,但不一定认识汉语。模板1:Regarding the suspension of my Google account, I was taken aback by this development. I consistently follow policies and require access reinstatement promptly. Your swift help in resolving this matter is eagerly awaited. Thank you for your attention to this issue.模板2:I was shocked to learn that my Google account has been suspended. I consistently follow all of Google's rules and regulations and am unsure why this action was taken. Reinstating my account is vital for both professional and personal reasons. I kindly request a review of the suspension and the restoration of my account access. I am more than willing to assist and ensure compliance moving forward. Thank you for your attention to this matter.模板3:My Google account has been suspended, and I acknowledge any potential policy violations that led to this action. I apologize for any errors and commit to upholding all guidelines moving forward. I respectfully request a review for the reinstatement of my account. Thank you for your consideration.模板4:I've learned that my Google account was suspended, likely due to policy violations. I apologize for any breaches and assure you of my dedication to upholding all guidelines in the future. I respectfully request a review of my account for possible reinstatement. Thank you for your understanding.上面的申诉理由已经打磨了很多遍,成功率很高,大家直接使用即可。申诉提交之后,页面会有这样的提示。
2024年08月23日
16 阅读
0 评论
0 点赞
2024-08-20
aos.js是一款强大的网页滚动元素添加入场动画插件
AOS.js(Animate On Scroll Library) 是一款强大而轻便的JavaScript插件,用于在网页滚动时添加动画效果,从而增强用户的互动体验。这种动画效果可以让元素在进入可视区域时以动画的形式显示,增加页面的吸引力和现代感。AOS.js非常容易集成到任何网站中,并与Bootstrap等框架兼容。安装AOS.js有几种方法可以将AOS.js添加到您的项目中:直接从CDN下载: <!-- AOS CSS --> <link type="text/css" rel="stylesheet" href="../css/aos.2.3.4.css"> <!-- AOS JavaScript --> <script type="text/javascript" src="../js/aos.2.3.4.js"></script>使用NPM或Yarn:npm install aos --save或yarn add aos如何使用AOS.js一旦安装了AOS.js,您只需在您的HTML元素中添加data-aos属性即可。然后在您的JavaScript中初始化库:<!DOCTYPE html> <html lang="en"> <head> <!-- AOS CSS --> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/aos.2.3.4.css"> </head> <body> <div data-aos="fade-up"> <!-- 内部内容 --> 元素内容 </div> <!-- AOS JavaScript --> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/aos.2.3.4.js"></script> <script> AOS.init(); </script> <!-- 页面的其他脚本和内容 --> </body> </html>AOS入场动画方式种类:fade: 元素逐渐显现或消失。fade-up: 元素向上滚动并逐渐显现。fade-up-right: 元素向右上方滚动并逐渐显现。fade-up-left: 元素向左上方滚动并逐渐显现。fade-down: 元素向下滚动并逐渐显现。fade-down-right: 元素向右下方滚动并逐渐显现。fade-down-left: 元素向左下方滚动并逐渐显现。fade-left: 元素向左滚动并逐渐显现。fade-right: 元素向右滚动并逐渐显现。flip-up: 元素向上翻转并逐渐显现。flip-down: 元素向下翻转并逐渐显现。flip-left: 元素向左翻转并逐渐显现。flip-right: 元素向右翻转并逐渐显现。zoom-in: 元素逐渐放大。zoom-out: 元素逐渐缩小。rotate: 元素逐渐旋转。slide-up: 元素向上滑动并逐渐显现。slide-down: 元素向下滑动并逐渐显现。slide-left: 元素向左滑动并逐渐显现slide-right: 元素向右滑动并逐渐显现。AOS配置选项可以在AOS.init()中设置:duration:动画持续时间,以毫秒为单位。delay:动画延迟时间,以毫秒为单位。once:设置为true时,动画只播放一次(不会在再次滚动时重复出现)。AOS.init({ duration: 1200, delay: 200, once: false, // 是否只播放一次动画 });您还可以为单个元素定义不同的动画效果和配置:<div data-aos="fade-up" data-aos-delay="200" data-aos-duration="1000"> <!-- 内部内容 --> </div>在上面的例子中,当元素滚动到视口中时,将会以从下向上淡入的形式,持续1秒钟(1000毫秒),并在开始动画前延迟200毫秒。兼容性提示AOS.js适用于所有现代浏览器,包括Chrome,Firefox,Safari,Edge等。但需要注意的是,一些较旧的浏览器,如Internet Explorer,可能不完全支持。
2024年08月20日
37 阅读
0 评论
0 点赞
2024-03-01
js图片懒加载
js代码//图片懒加载 window.onload = function() { var Joe = document.getElementById('imgid'); var imgs = Joe.getElementsByTagName('img'); for (var i = 0; i < imgs.length; i++) { (function(curImg) { var tempImg = null; tempImg = document.createElement('img'); console.log(curImg); tempImg.src = curImg.dataset.src; tempImg.onload = function(e) { curImg.src = tempImg.src; curImg.style.filter = 'blur(0px)'; } })(imgs[i]); } }html代码<div id="imgid"><img class="lazyload" src="logo.jpg" data-src="图片地址" alt="" style="width: 100%" /></div>
2024年03月01日
45 阅读
0 评论
0 点赞
2024-03-01
Typecho 添加GZIP及HTML代码压缩功能记录(转载)
使用站长工具时,经常会看到网址是否开启Gzip功能,开启后网页大小能压缩百分之七八十以上。于是乎想给我的小破站也给加上,毕竟博主穷,用的便宜的虚拟主机,月流量有限(其实够用,但是我得有这功能!!!)。于是乎就请教了下万能的度娘,加上博主单身数十年修炼的ctrl+c ,ctrl+v大法。功能基本实现,方法概况如下:主题文件functions.php 添加 html 压缩功能函数;主题文件functions.php 添加压缩功能开关;主题文件footer.php 添加压缩功能钩子;程序文件index.php 添加GZIP功能代码;搞定,So easy !!!反正吹牛不犯法……添加压缩功能函数代码在主题文件functions.php末尾加上如下代码://html压缩 /*** <?php $html_source = ob_get_contents(); ob_clean(); print compressHtml($html_source); ob_end_flush(); ?> **/ function compressHtml($html_source) { $chunks = preg_split('/(<!--<nocompress>-->.*?<!--<\/nocompress>-->|<nocompress>.*?<\/nocompress>|<pre.*?\/pre>|<textarea.*?\/textarea>|<script.*?\/script>)/msi', $html_source, -1, PREG_SPLIT_DELIM_CAPTURE); $compress = ''; foreach ($chunks as $c) { if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') { $c = substr($c, 19, strlen($c) - 19 - 20); $compress .= $c; continue; } else if (strtolower(substr($c, 0, 12)) == '<nocompress>') { $c = substr($c, 12, strlen($c) - 12 - 13); $compress .= $c; continue; } else if (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') { $compress .= $c; continue; } else if (strtolower(substr($c, 0, 7)) == '<script' && strpos($c, '//') != false && (strpos($c, "\r") !== false || strpos($c, "\n") !== false)) { $tmps = preg_split('/(\r|\n)/ms', $c, -1, PREG_SPLIT_NO_EMPTY); $c = ''; foreach ($tmps as $tmp) { if (strpos($tmp, '//') !== false) { if (substr(trim($tmp), 0, 2) == '//') { continue; } $chars = preg_split('//', $tmp, -1, PREG_SPLIT_NO_EMPTY); $is_quot = $is_apos = false; foreach ($chars as $key => $char) { if ($char == '"' && $chars[$key - 1] != '\\' && !$is_apos) { $is_quot = !$is_quot; } else if ($char == '\'' && $chars[$key - 1] != '\\' && !$is_quot) { $is_apos = !$is_apos; } else if ($char == '/' && $chars[$key + 1] == '/' && !$is_quot && !$is_apos) { $tmp = substr($tmp, 0, $key); break; } } } $c .= $tmp; } } $c = preg_replace('/[\\n\\r\\t]+/', ' ', $c); $c = preg_replace('/\\s{2,}/', ' ', $c); $c = preg_replace('/>\\s</', '> <', $c); $c = preg_replace('/\\/\\*.*?\\*\\//i', '', $c); $c = preg_replace('/<!--[^!]*-->/', '', $c); $compress .= $c; } return $compress; } 前台调用方法,后面会用到,如果不想整个功能开关,可以直接在 footer.php 文件末尾添加:<?php $html_source = ob_get_contents(); ob_clean(); print compressHtml($html_source); ob_end_flush(); ?>添加压缩功能开关在主题文件 functions.php 文件中 function themeConfig($form) {} 中添加以下代码: // html压缩 $themecompress = new Typecho_Widget_Helper_Form_Element_Select('themecompress',array('0'=>'不开启','1'=>'开启'),'0','HTML压缩功能','是否开启HTML压缩功能,缩减页面代码'); $form->addInput($themecompress); 前台添加压缩功能钩子在主题文件 footer.php 文件最末尾添加以下代码:<!-- html代码压缩 --> <?php if ($this->options->themecompress == '1'):?> <?php error_reporting(0); $html_source = ob_get_contents(); ob_clean(); print compressHtml($html_source); ob_end_flush(); ?> <?php endif; ?> 为什么一定要加个开关呢?主要是有以下几个原因:方便自己修改主题代码时,随时F12查看自己的前端网页code;有的主题作者代码书写不规范,经常会漏标点啥的,开启html压缩功能可能会导致错误,这时就可以在主题设置中随时关闭压缩功能,然后再去修BUG了。功能补充在网站根目录 index.php 文件最前头添加以下代码(开启Gzip,貌似对有些辣鸡主机不适用……):/** GZIP开启 */ ob_start('ob_gzhandler'); 注意是网站根目录,不是主题目录!注意是网站根目录,不是主题目录!注意是网站根目录,不是主题目录!压缩功能效果 图:gzip+html压缩效果.png效果是有的,但上图总感觉很虚……可自行 F12 本站查看,基本能压缩一半以上是没问题的。建议操作前做好备份!以防万一,虽然不会有万一,但是博主是渣男不会对你负责滴……著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。作者:荒野孤灯文章:Typecho 添加GZIP及HTML代码压缩功能记录链接:https://www.80srz.com/posts/1110.html
2024年03月01日
25 阅读
0 评论
0 点赞
1
2
...
7