帝国CMS灵活调用个性化的多图片集插件

帝国CMS论坛受管制,强制关闭了,很多技术贴内容无法搜到,之前没养成随手记的习惯,导致现在诸多的不便...
ECMS的图集效果不太理想,一直在用的一个可以灵活调用的多图集功能插件。

1、功能代码

将下面的代码,复制到你的userfun.php中(文件位置:/e/class/userfun.php)

function user_PhotoMorepic($tempid){
    global $navinfor,$public_r;
    $morepic=$navinfor['morepic'];
    $rexp="\r\n";
    $fexp="::::::";
    $rstr="";
    $sdh="";
    $w_morepic="";
    $rr=explode($rexp,$morepic);
    $count=count($rr);
    $num=$count;
    
    //取得模板
    $tr=sys_ReturnBqTemp($tempid);
    if(empty($tr['tempid']))
    {return "";}
    $listtemp=str_replace('[!--news.url--]',$public_r[newsurl],$tr[temptext]);
    $subnews=$tr[subnews];
    $listvar=str_replace('[!--news.url--]',$public_r[newsurl],$tr[listvar]);
    $rownum=$tr[rownum];
    $formatdate=$tr[showdate];
    if(empty($rownum))
    {$rownum=1;}
    
    //列表
    $list_exp="[!--empirenews.listtemp--]";
    $list_r=explode($list_exp,$listtemp);
    $listtext=$list_r[1];
    $no=1;
    $changerow=1;
    
    for($i=0;$i<$count;$i++)
    {
        $fr=explode($fexp,$rr[$i]);
        $smallpic=$fr[0]?$fr[0]:$public_r[newsurl]."e/data/images/notimg.gif";    //小图
        $bigpic=$fr[1]?$fr[1]:$public_r[newsurl]."e/data/images/notimg.gif";    //大图
        if(empty($bigpic))
        {
            $bigpic=$smallpic;
        }
        $picname=htmlspecialchars($fr[2]);    //名称
        $val[picname]=$picname;
        $val[bigpic]=$bigpic;
        $val[smallpic]=$smallpic;
        /////////////////
        $strF=",picname,bigpic,smallpic,";
        $repvar=user_ReplaceShowpicsVars($listvar,$strF,$val,$no);
        $listtext=str_replace("<!--list.var".$changerow."-->",$repvar,$listtext);
        $changerow+=1;
        //超过行数
        if($changerow>$rownum)
        {
        $changerow=1;
        $string.=$listtext;
        $listtext=$list_r[1];
        }
        $no++;
    }
   $string=$list_r[0].$string.$list_r[2];
    echo $string;
}

function user_ReplaceShowpicsVars($listtemp,$strF,$val,$no){
$fr=explode(',',$strF);
$fcount=count($fr)-1;;
for($i=1;$i<$fcount;$i++)
{
$f=$fr[$i];
$value=$val[$f];
$listtemp=str_replace('[!--'.$f.'--]',$value,$listtemp);
}
$listtemp=str_replace('[!--no.num--]',$no,$listtemp);

return $listtemp;
}

2、添加标签

标签名:图集
标签符号:pichd
函数名:user_PhotoMorepic
标签格式:[pichd]tempid[/pichd]
(tempid为模板标签id)

3、标签模板

页面模板内容:
列表头[!--empirenews.listtemp--]列表内容[!--empirenews.listtemp--]列表尾

列表内容模板(list.var)
[!--picname--] 图片说明(标题)
[!--smallpic--] 小图
[!--bigpic--] 大图
[!--no.num--] 序号

内容模板
[pichd]标签模板id[/pichd]

本文转自:https://nipang.cn/ecms-PhotoMorepic.html

帝国CMS全站电脑端自动调整手机端动态静态代码

帝国CMS7.2版推出了完善的多访问终端功能,让网站多种移动访问端制作更加方便。7.5版中多访问端升级:支持在主端后台刷新生成各访问端静态页面,多访问端用静态模式下使用更方便。

1、页面头部。JS代码在body前面加上以下HTML源代码
PC端部分代码(判断是否是手机端跳转至手机页面地址)

<script data-fixed="true">
  !function(){
    function params(u, p){
      var m = new RegExp("(?:&|/?)"+p+"=([^&$]+)").exec(u);
      return m ? m[1] : '';
    }
    if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == true && params(location.search, "from") != "mobile"){
      location.href = 'https://m.tzzs.net/';
    }
  }();
</script>

手机端部分代码(判断是否是PC端跳转至PC页面地址)

<script data-fixed="true">
  !function(){
    if(/iphone|ios|android|ipod/i.test(navigator.userAgent.toLowerCase()) == false){
      location.href = 'https://www.tzzs.net/';
    }
  }();
</script>

2、列表页

动态页:http://m.tzzs.net/e/action/ListInfo/?classid=[!--self.classid--]
静态页:http://m.tzzs.net<?$r['classid']=$GLOBALS[navclassid];$classurl=sys_ReturnBqClassname($r,9);echo $classurl;?>

3、内容页

动态页:http://m.tzzs.net/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]
静态页:http://m.tzzs.net[!--titleurl--]

效果演示站点:https://www.tztjfc.com/

本文转自:https://nipang.cn/ecms-pc-mobile.html

帝国CMS灵动标签获取通用子栏目数据,及获取同级父栏目下相同名称栏目列表页的数据

具体案例网站栏目共有4级,其中一个工作室栏目下面有9个总科室,下级再分36个小室,每个科室又有18个独立的终极栏目。
有个共性就是:每个科室的18个终极栏目,栏目的名称都是一样的。
工作室首页、列表、内容页的模板结构都是一模一样的,调用对应的科室栏目下不同的数据。
为了避免出现36个首页模板、36个栏目列表页模板、36个...
就需要使用灵动标签,获取通用子栏目数据,及获取同级父栏目下相同名称栏目列表页的数据。

下面整理下实现方法:
封面模板,工作室首页模板:

[e:loop={"select classid, classname, classpath from phome_enewsclass where bclassid='$GLOBALS[navclassid]' and classname='研究课题'",5,24,0,0,0}] [ecmsinfo]$bqr[classid],6,46,0,0,2,0[/ecmsinfo] [/e:loop]

子栏目名称调用:

<?=$class_r[$bqr[classid]]['classname']?>

子栏目链接调用:

<?=$class_r[$bqr[classid]]['classpath']?>

终极栏目列表,获取同父栏目下的同级栏目的数据:

<?php $bclassid=$class_r[$GLOBALS[navclassid]][bclassid]; ?> [e:loop={"select classid, classname, classpath from phome_enewsclass where bclassid='$bclassid' and classname='精品课件'",5,24,0,0,0}] [ecmsinfo]$bqr[classid],6,46,0,0,2,0[/ecmsinfo] [/e:loop]

列表里面用[!--bclass.id--],放在灵动标签内没有作用,定义了一个变量才获取到上级id

另外,在论坛请教了一下,如何获得父目录的父目录名称:

<?php $bclassid=$class_r[$GLOBALS[navclassid]][bclassid]; $bbclassid=$class_r[$bclassid][bclassid]; echo $class_r[$bbclassid][classname]; ?>

本文转自:https://nipang.cn/ecms_skills.html

帝国CMS将正文内容img图片标签里alt值默认设为文章标题

需求:我们在发布内容时,希望内容中的图片都能给alt加上内容,这样对SEO友好,还可能从搜索引擎图片搜索那里带来一些流量,如果人工加,效率低。
问题:正文内容中的图片是和其他文字存在一起,没法用模板标签单独读取出来。
思路:新建一个函数,用于自动替换正文IMG里的ALT内容。
方法:在 e/class/userfun.php 里面增加:

//替换正文IMG里的ALT内容
function user_imgalt($mid,$f,$isadd,$isq,$value,$cs){
$title=$_POST['title'];
$htmls=$value;
$pattern = "/<img[^>]+>/"; 
preg_match_all($pattern, $htmls, $matches); 
for ($i=0; $i<=count($matches[0]); $i++) {
  preg_match_all("/alt=\".+?\"/",$matches[0][$i],$altimg); 
    $t_alt=count($altimg[0]);
    if($t_alt==0){
        $htmls=str_replace("<img","<img alt=\"{$title}\"",$htmls);
    }
}   
    return $htmls;
}

然后在后台系统设置-数据表模型-字段管理里面 编辑 newstext字段,增加如下:
ecms-newstext-imgalt.jpg

本文转自:http://www.dongchuanmin.com/archives/216.html

帝国CMS调用栏目别名的两种方法

第一种:在最终栏目调用

<?=$class_r[$GLOBALS[navclassid]][bname]?>

第二种:万能的,哪里都行,应为是直接查询数据库输出的!

<?php 
$cr=$empire->fetch1("select bname from phome_enewsclass where 
classid='".$GLOBALS[navclassid]."' limit 1"); 
echo $cr['bname']; 
?>

使用时,注意上面的表名是否与你的表名对得上,另外classid后面栏目ID,以上案例.$GLOBALS[navclassid].表示获取当前栏目ID。

帝国CMS列表模板list.var使用程序代码

1、增加模板时list.var模板需要勾选“使用程序代码”选项。
2、直接添加PHP代码,不需要加<??>程序开始和结束标记。
3、字段值数组变量为$r,对应的字段变量为$r[字段名],如:标题字段变量就是$r[title]。另外编号变量为$no。
这只是读取当前主表字段,如果是附表,要用副表或者其他表的字段值,要先用SQL取
4、将最终模板内容赋给$listtemp变量。

list.var模板范例:

例子1:如果信息没有设置标题图片就显示指定的图片。

if(empty($r[titlepic]))
{
    $r[titlepic]='/images/img.gif';
}
$listtemp='<li><a href="[!--titleurl--]"><img src="[!--titlepic--]"></a></li>';

说明:$r[titlepic]为标题图片字段变量。$listtemp为模板内容变量。

例子2:如果信息是今天发布的就显示“NEW”图片标识。

$newimg='';
if(time()-$r[newstime]<=1*24*3600)
{
    $newimg='<img src="NEW图片地址" border="0">';
}
$listtemp='<li><a href="[!--titleurl--]">[!--title--]</a> '.$newimg.'</li>';

说明:$r[newstime]为发布时间字段变量。$listtemp为模板内容变量。

例子3:调用投稿用户的公司名称。

$userr=$empire->fetch1("select company from {$dbtbpre}enewsmemberadd where userid='$r[userid]' limit 1");
$listtemp='<li><a href="[!--titleurl--]">[!--title--]</a> <span>公司名称:'.$userr[company].'</span></li>';

说明:$r[userid]为发布者用户ID字段变量。$listtemp为模板内容变量。

其他说明:
如果$listtemp引用模板内容是用单引号,那么里面使用单引号前面要加,例如:$listtemp='<img src=\'[!--titlepic--]\'>';
相反如果引用模板内容是用双引号,那么里面使用双引号前面也要加,例如:$listtemp="<img src=\"[!--titlepic--]\">";