PHP研发案例:zblog插件研发之E58归类目录
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">是不是觉得文煞好久<span style="color: black;">无</span>更新<span style="color: black;">文案</span>了,<span style="color: black;">近期</span>在<span style="color: black;">科研</span>一个zblog插件。E58<span style="color: black;">归类</span>目录是一款zblog<span style="color: black;">归类</span>目录插件,<span style="color: black;">能够</span>让你的zblog网站瞬间变成一款支持<span style="color: black;">归类</span>目录的小插件!其实很久就想做一款zblog for php款的<span style="color: black;">归类</span>目录插件,让一个zblog博客网站支持网址提交的导航站总觉得是一个<span style="color: black;">特别有</span>用的东西,但是<span style="color: black;">因为</span><span style="color: black;">始终</span>上班之余身心疲累,懒得去折腾,<span style="color: black;">近期</span><span style="color: black;">最终</span>下定决心来完成</span>它<span style="color: black;">。</span><span style="color: black;">前后花了十天<span style="color: black;">上下</span>,虽然代码不多,<span style="color: black;">然则</span>从构思到代码的完成,<span style="color: black;">仅有</span>工作之余的个</span>把<span style="color: black;">小时的时间来做这些事情。</span><span style="color: black;">每一部分代码的编写、<span style="color: black;">检测</span>和<span style="color: black;">实质</span>功效的测试,都是牺牲了自己业余<span style="color: black;">休憩</span>的时间,<span style="color: black;">不外</span>总算还是完<span style="color: black;">成为了</span>,<span style="color: black;">期盼</span>能够有人需要。</span>至于<span style="color: black;">插件的不足之处,<span style="color: black;">期盼</span>大家在</span><strong style="color: blue;"><span style="color: black;">本文后面‘阅读原文’页面进行留言反馈</span></strong><span style="color: black;">!</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">插件<span style="color: black;">研发</span>过程中<span style="color: black;">亦</span>是一件<span style="color: black;">特别有</span>趣的事情,今天不<span style="color: black;">晓得</span>写啥内容,就为<span style="color: black;">大众</span>分享部分插件的代码吧:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">1、这是给zblog添加自定义导航的代码:</strong></p><span style="color: black;"><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">global_e58_dir_Nav</span><span style="color: black;">(&$template)</span> </span>{</span><span style="color: black;"> <span style="color: black;">global</span> $zbp;</span><span style="color: black;">$navbar = $zbp->modulesbyfilename[<span style="color: black;">navbar</span>]->Content;</span><span style="color: black;"> $navbar .= <span style="color: black;"><li><a href="#" onclick="openPopup()">网站提交</a></li></span>;</span><span style="color: black;"> $zbp->modulesbyfilename[<span style="color: black;">navbar</span>]->Content = $navbar.PHP_EOL;</span><span style="color: black;">}</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">不外</span>在<span style="color: black;">运用</span>该代码之前,需要在插件开头添加插件钩子:</p>
<span style="color: black;"><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">ActivePlugin_e58_dir</span>() </span>{</span><span style="color: black;">......</span><span style="color: black;"> Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewPost_Template</span>, <span style="color: black;">e58_dir_Main</span>);</span><span style="color: black;">Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewList_Template</span>, <span style="color: black;">global_e58_dir_Nav</span>);</span><span style="color: black;"> Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewPost_Template</span>, <span style="color: black;">global_e58_dir_Nav</span>);</span><span style="color: black;"> Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewSearch_Template</span>, <span style="color: black;">global_e58_dir_Nav</span>);</span><span style="color: black;"> Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewComments_Template</span>, <span style="color: black;">global_e58_dir_Nav</span>);</span><span style="color: black;"> Add_Filter_Plugin(<span style="color: black;">Filter_Plugin_ViewComment_Template</span>, <span style="color: black;">global_e58_dir_Nav</span>);</span><span style="color: black;">}</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面的代码分别在列表页、<span style="color: black;">文案</span>页、搜索页、评论页都添加了插件自定义的导航链接。我觉得新手在<span style="color: black;">研发</span>zblog插件的时候,或许会用得上!</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">2、分享一个自定义的<span style="color: black;">转</span>代码</strong></p><span style="color: black;"><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">e58_dir_jump</span><span style="color: black;">($url, $str)</span> </span>{</span><span style="color: black;"> <span style="color: black;">global</span> $zbp;</span><span style="color: black;"> <span style="color: black;">if</span>($url == <span style="color: black;">0</span>) {</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;"><script language="javascript"></span>;</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;">if (confirm("</span> . $str . <span style="color: black;">")) {</span>;</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;"> history.back();</span>;</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;">}</span>;</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;"></script></span>;</span><span style="color: black;"> <span style="color: black;">return</span>;</span><span style="color: black;"> } <span style="color: black;">else</span> <span style="color: black;">if</span> ($url == ) {</span><span style="color: black;"> $url = $zbp->host;</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;"><script language="javascript">alert("</span> . $str . <span style="color: black;">"); top.location.href="</span> . $url . <span style="color: black;">";</script></span>;</span><span style="color: black;"> } <span style="color: black;">else</span> {</span><span style="color: black;"> <span style="color: black;">echo</span> <span style="color: black;"><script language="javascript">alert("</span> . $str . <span style="color: black;">"); top.location.href="</span> . $url . <span style="color: black;">";</script></span>;</span><span style="color: black;"> }</span><span style="color: black;">}</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">该类需要传入两个值,分别是$url和$str,<span style="color: black;">倘若</span>传入一个空值,就返回zblog首页,<span style="color: black;">倘若</span>传入0就返回上一页,<span style="color: black;">倘若</span>传入指定的url,则<span style="color: black;">转</span>到该url。$str是提示词,<span style="color: black;">转</span>之前<span style="color: black;">通知</span>操作者的信息。当然这是一个<span style="color: black;">非常</span>简易的<span style="color: black;">转</span>功能。效果:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/fm7RnX9X5QTkenNwl54eSb14aScrKXqxB9ia3mYSpBqk9NxhNhZib57Rh2etsEVtaUic1Wg3Aib4vbkHUlpHH5GPXg/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">3、再分享一个生成验证码的代码吧</strong></p><span style="color: black;"><span style="color: black;"><span style="color: black;">class</span> <span style="color: black;">Captcha</span> </span>{</span><span style="color: black;"> <span style="color: black;">private</span> $width;</span><span style="color: black;"> <span style="color: black;">private</span> $height;</span><span style="color: black;"> <span style="color: black;">private</span> $code;</span><span style="color: black;"> <span style="color: black;">private</span> $image;</span><span style="color: black;"> <span style="color: black;">public</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">__construct</span><span style="color: black;">($width =<span style="color: black;">120</span>, $height = <span style="color: black;">40</span>)</span> </span>{</span><span style="color: black;"> <span style="color: black;">$this</span>->width = $width;</span><span style="color: black;"> <span style="color: black;">$this</span>->height = $height;</span><span style="color: black;"> <span style="color: black;">$this</span>->code = <span style="color: black;">$this</span>->generateCode();</span><span style="color: black;"> <span style="color: black;">$this</span>->image = <span style="color: black;">$this</span>->createImage();</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">public</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">getCode</span><span style="color: black;">()</span> </span>{</span><span style="color: black;"> <span style="color: black;">return</span> <span style="color: black;">$this</span>->code;</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">public</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">showImage</span><span style="color: black;">()</span> </span>{</span><span style="color: black;"> header(<span style="color: black;">Content-Type: image/png</span>);</span><span style="color: black;"> imagepng(<span style="color: black;">$this</span>->image);</span><span style="color: black;"> imagedestroy(<span style="color: black;">$this</span>->image);</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">private</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">generateCode</span><span style="color: black;">()</span> </span>{</span><span style="color: black;"> <span style="color: black;">global</span> $zbp;</span><span style="color: black;"> $charset = <span style="color: black;">"1234567890abcdefghijkmnpqrstuvwxyz"</span>;</span><span style="color: black;"> $code = substr(str_shuffle($charset), <span style="color: black;">0</span>, <span style="color: black;">6</span>);</span><span style="color: black;"> $zbp->Config(<span style="color: black;">e58_dir</span>)->dircode = $code;</span><span style="color: black;"> $zbp->SaveConfig(<span style="color: black;">e58_dir</span>);</span><span style="color: black;"> <span style="color: black;">return</span> $code;</span><span style="color: black;"> }</span><span style="color: black;"> <span style="color: black;">private</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">createImage</span><span style="color: black;">()</span> </span>{</span><span style="color: black;"> $image = imagecreate(<span style="color: black;">$this</span>->width, <span style="color: black;">$this</span>->height);</span><span style="color: black;">$bac<span style="color: black;">公斤</span>round = imagecolorallocate($image,<span style="color: black;">255</span>, <span style="color: black;">255</span>, <span style="color: black;">255</span>);</span><span style="color: black;"> $textColor = imagecolorallocate($image, <span style="color: black;">0</span>, <span style="color: black;">0</span>, <span style="color: black;">0</span>);</span><span style="color: black;"> <span style="color: black;">for</span> ($i = <span style="color: black;">0</span>; $i < <span style="color: black;">200</span>; $i++) {</span><span style="color: black;"> $x = rand(<span style="color: black;">0</span>, <span style="color: black;">$this</span>->width - <span style="color: black;">1</span>);</span><span style="color: black;"> $y = rand(<span style="color: black;">0</span>, <span style="color: black;">$this</span>->height - <span style="color: black;">1</span>);</span><span style="color: black;"> imagesetpixel($image, $x, $y, $textColor);</span><span style="color: black;"> }</span><span style="color: black;"> imagestring($image, <span style="color: black;">5</span>, <span style="color: black;">$this</span>->width / <span style="color: black;">2</span> - <span style="color: black;">30</span>, <span style="color: black;">$this</span>->height / <span style="color: black;">2</span> - <span style="color: black;">8</span>, <span style="color: black;">$this</span>->code, $textColor);</span><span style="color: black;"> <span style="color: black;">return</span>$image;</span><span style="color: black;"> }</span><span style="color: black;">}</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在该插件<span style="color: black;">研发</span>的时候,我<span style="color: black;">无</span><span style="color: black;">运用</span>zblog内置的验证码,<span style="color: black;">由于</span>内置验证码<span style="color: black;">体积</span>写有时候分不清楚,而我<span style="color: black;">运用</span>了这个自定义的验证码,<span style="color: black;">重点</span>是去除了字母‘l’和‘o’,<span style="color: black;">重点</span>是怕数字1和字母l、数字0和字母o肉眼分辨不清楚。<span style="color: black;">同期</span><span style="color: black;">所有</span><span style="color: black;">运用</span>小写字母和数字,在<span style="color: black;">保准</span>安全的<span style="color: black;">同期</span>,兼顾一下<span style="color: black;">运用</span>体验!免得别人辛辛苦苦填写的内容<span style="color: black;">由于</span>一个验证码的失误而<span style="color: black;">没法</span>提交。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">好了,插件代码分享到此为止,可见都是我前期在php教程专辑中<span style="color: black;">说到</span>过的知识,<span style="color: black;">此刻</span>用来<span style="color: black;">研发</span>zblog插件,<span style="color: black;">一样</span>是可行的。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">插件名<span style="color: black;">叫作</span>:</strong>E58<span style="color: black;">归类</span>目录</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">插件最新版本:</strong>V.1.0 bate</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">适配版本:</strong>Zblog for php 1.7.3</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">PHP版本:</strong>5.3-7.4</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">插件功能介绍:</strong>本插件支持zblog网站提交网站信息,并<span style="color: black;">经过</span><span style="color: black;">文案</span>页面进行展示;本插件<span style="color: black;">经过</span>api接口获取<span style="color: black;">关联</span>SEO信息!支持免登录提交!后台设置获取SEO信息的开关,可任意<span style="color: black;">运用</span>!</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/fm7RnX9X5QTkenNwl54eSb14aScrKXqxpmPI45QeW9qVct3tE1oY55sVia5yQLT22407riaZ3bhGFXHpnajq8Rgg/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/fm7RnX9X5QTkenNwl54eSb14aScrKXqxokhMxU6aHiciaufGmHsia0xTvpMtsTicH6jH0T3UN1iaIFxFwxYKaibc1DDQ/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/fm7RnX9X5QTkenNwl54eSb14aScrKXqxVl8smlzWKibbmMLCB6gfkfOX8Igq8GK2eUQdTv2j5Plkp1XLO5VhdYw/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/fm7RnX9X5QTkenNwl54eSb14aScrKXqxU9mPBuPVCrO4QbTvgn0ul6XSMBKziaEJH9EpZNdXjjEN1jZdRUKFgibg/640?wx_fmt=png&from=appmsg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
外链发布论坛学习网络优化SEO。
页:
[1]