dedecms 函数扩展之:随机连接

问题背景:

在一个 kw.txt 里面用 “–”分割的 地址和关键字,形如

https://www.google.com–谷歌
https://www.github.com–git

现在模板里面随机调用5个这样的连接

{dede:rndkw runphp=’yes’}
@me = rndkw();
{/dede:rndkw}

在 \include\helpers\extend.helper.php 增加如下

 

if ( ! function_exists('rndkw'))
{
    function rndkw($str) { 
        
       
        
        $kw=file(getcwd() . DIRECTORY_SEPARATOR ."kw.txt");
         
        shuffle($kw);
        $s="";
        for($i=0;$i<5;$i++)
        {
            list($ah,$aw) = explode("--",$kw[$i]);
            $s .= "

".trim($aw)."

"; } return $s; } }

dedecms文章分页后的随机推荐文章在每个分页都相同改为不相同随机的方法

问题背景:

dedecms 发布文章,特别是图片的时候一般会分很多页,模板里面可能设置了随机推荐的其他图片,但是同一个文章的每个分页的这个随机推荐是一样的,如何改为不同?

问题解决:

模板里面一般是这类随机

{dede:arclist row=10 orderby=rand}
<li><a href=”[field:arcurl/]”>[field:title/]</a></li>
{/dede:arclist}

造成每个页面的随机都一样的原因就是 这个模板片段是只在处理一个文章的时候分析一次模板,如果每个分页再生成前再次分析下模板,理论上就再次扫描了一次,从而再次随机运行了一次代码。

方案:

include\arc.archives.class.php 的  MakeHtml 函数

在大概 410行,增加   $this->ParseTempletsFirst();

 

dedecms的GetPageTitlesST函数

include\arc.archives.class.php 里面 GetPageTitlesST 函数,在页面调用是

{dede:pagetitle style=’XXXX’ /}

那么就可以根据style来修改GetPageTitlesST 函数,使之能适用多种情况,比如

{dede:pagetitle style=’subtile_title’ /}

就需要走增加

if($styleName==’subtile_title’)
{
return  $this->SplitTitles[$pageNo-1] . “_” . $this->Fields[“title”] ;
}else{
return $this->Fields[“title”] ;
}

发文章的时候用

#p#第几页的标题#e#

 

 

PS:

可能UTF8的,这个函数有点问题,

最后的 #没能去掉,可以考虑用 sub_str($string,0,-1)消掉

php的win版本的一点编译解释

和本文一样的内容 是 这里

vc09 = Visual Studio 2008
vc10 = Visual Studio 2010
vc11 = Visual Studio 2012 2012
vc12 = Visual Studio 2013 2013
vc14 = Visual Studio 2015 2015
vc15 = Visual Studio 2017

VC11, VC14 & VC15
More recent versions of PHP are built with VC11, VC14 or VC15 (Visual Studio 2012, 2015 or 2017 compiler respectively) and include improvements in performance and stability.

– The VC11 builds require to have the Visual C++ Redistributable for Visual Studio 2012 x86 or x64 installed

– The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed

– The VC15 builds require to have the Visual C++ Redistributable for Visual Studio 2017 x64 or x86 installed

TS and NTS
TS refers to multithread capable builds. NTS refers to single thread only builds. Use case for TS binaries involves interaction with a multithreaded SAPI and PHP loaded as a module into a web server. For NTS binaries the widespread use case is interaction with a web server through the FastCGI protocol, utilizing no multithreading (but also for example CLI).

发表在 PHP

大淘客cms增强版

增强版本增强功能:
1)多级cache,缓解大量文件在cache目录下的列表困难
2)增加远程服务器状态检测,当远程服务器无法获取数据,自动从本地缓存获取老数据,如果没有老数据就显示默认页面

dataokecms1
dataokecms2

php的curl函数打开https时候的问题,特别是502问题或者微信的40001获取不到token问题

sslcurl 学习下载点这里

关于php在使用curl打开https情况下,经常出现502错误,那一般是curl函数要设置一些 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

上面的代码供参考。

下面这个图的错误,也是如此
weixin-payment-error

Discuz用户上传头像提示can not write to the data tmp folder。

Discuz用户上传头像提示can not write to the data tmp folder。 142513516573d35eadf807

解决方法:

通过chrome 的F12功能发现,上传图片调用 uc_server/control/user.php里面的函数 onuploadavatar,返回值是 -4,通过查找 -4的来源,

avatar1

得到 getimagesize 函数出错,返回false,

那么写一点调试代码就能看到问题所在了

avatar2

图中红圈是调试语句,根据这个的错误提示,就会发现是apache无权限读取上传的临时文件,根据提示修改apache的配置文件里面的 php_admin_value open_basedir XXXXX
通过注释掉此语句,或者修改到合适的目录使得可以读取上传文件的临时目录就可以解决此问题了。

php-fpm slowlog 配合检查慢php语句

php-fpm的 slowlog 功能打开后,在log文件里面就会有相关文件的相关行慢语句,

discuz经常由于plugin里面的curl功能导致慢,比如 function_filesock.php文件里面的 _dfsockopen 函数调用curl_exec ,如果所请求的地址出现问题,那么调用此函数的功能就会出现卡顿,通过记录下所对应的url,通过file_put_contents 把请求记录一下,然后分析哪些地址是造成慢的原因,从而可以采取策略暂时屏蔽之。

id

ecshop 默认第一个配送支付方式的选中

<!– {foreach from=$shipping_list key=shippingkey item=shipping} 循环配送方式 –>

<input name=”shipping” type=”radio” value=”{$shipping.shipping_id}” {if $order.shipping_id eq $shipping.shipping_id || $shippingkey eq 0 }checked=”true”{/if}   supportCod=”{$shipping.support_cod}” insure=”{$shipping.insure}” onclick=”selectShipping(this)” />

<!– {/foreach} 循环配送方式 –>

注意里面的   key=shippingkey item=shipping 和  $shippingkey eq 0 ,理解了php的数组key=>value 就明白了

 

paymentcheckdefault

文件夹空和不含子文件夹的函数php

检查某个文件夹是否是空文件夹,和检查某个文件夹是否不含子文件夹的函数

empptydir-leafdir

function dir_contains_children($dir) {
    $result = false;
    if($dh = opendir($dir)) {
        while(!$result && ($file = readdir($dh)) !== false) {
            $result = $file !== "." && $file !== ".." ;
        }

        closedir($dh);
    }

    return $result;
}

function dir_contains_children_dirs($dir) {
  $result = false;
    if($dh = opendir($dir)) {
       while (!$result && ($file = readdir($dh))) {
         $result = $file !== "." && $file !== ".." && is_dir($dir.'/'.$file);
       }
       closedir($dh);
    }

  return $result;
}

TXT下载

模板自定义函数导致dede更新出现500错误

dedecms 模板里面使用的自定义函数,如果此模板在一个原始官方的dedecms下运行,会因为函数未定义而导致出现500错误,
一般这类函数定义在 include/common.inc.php ,所以需要做相应的移植或者采用老版本的common.inc.php
因为 在include/dedetag.class.php 里面dede执行模板里面的php代码的时候采用eval调用,图中红线部分

dedeeval