FFan丶Blog / ICMS / / icms7文章内随机图片(利用icms广告系统)

icms7文章内随机图片(利用icms广告系统)

分类:ICMS 发布时间:2025-02-12 15:29:38来源:FFan丶Blog
1.打开文章内广告 后台>系统>应用管理>钩子管理>文章系统方法修改为正文插入广告 2.修改广告系统文件 /app/plugin/plugin_textad.class.php 修改...

1.打开文章内广告

后台>系统>应用管理>钩子管理>文章系统方法修改为正文插入广告

2.修改广告系统文件

/app/plugin/plugin_textad.class.php

修改

$ad = '<script>if(typeof showBodyUI==="function")showBodyUI("body.' . $i . '");</script>';

$dir = 'style/img/'; // 本地图库路径

$files = scandir( $dir );

// 过滤掉 '.' 和 '..',只保留图片文件

$images = array_filter( $files, function ( $file )use( $dir ) {

  // 只保留图片文件类型(jpg, jpeg, png, gif)

  return in_array( pathinfo( $file, PATHINFO_EXTENSION ), [ 'jpg', 'jpeg', 'png', 'gif' ] );

} );

// 获取协议部分(http 或 https)

$protocol = ( !empty( $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] !== 'off' || $_SERVER[ 'SERVER_PORT' ] == 443 ) ? "https://" : "http://";

// 获取主机名部分(www.example.com)

$host = $_SERVER[ 'HTTP_HOST' ];

// 拼接协议和主机名得到基本域名

$baseDomain = $protocol . $host;

// 确保有图片文件

if ( !empty( $images ) ) {

  // 从数组中随机选择一张图片

  $randomImage = $images[ array_rand( $images ) ];

  // 构造新的 HTML 代码,替换为随机图片

  $ad = '<p>' . '<img src="' . $baseDomain . '/' . $dir . $randomImage . '">' . '</p>';

} else {

  // 如果没有图片文件,给出提示

  $ad = '<p>No images.</p>';

}

上一篇:{Hash@ID} 伪静态

下一篇:ICMS8部分标签

猜你喜欢

  • 有些时候我们会遇到这样的困难:我们原本不想被搜索引擎收录的网站后台地址却被搜索引擎“无情”的收录,这样只要在Google里输入一个“后台、管理site:www.pengfan.org”,自己的后台地址就会显露无疑,因此网站安全性也无从谈起。遇到这样的情况时,我们如何阻止搜索引擎收录我们不想被收录的文件呢?

    SEO2020-01-15
  • 根目录新建.htaccess文件 DirectoryIndex index.html index.php

    SEO2020-01-15
  • 以下是以 m.二级域名绑定到子目录/m/为例的.htaccess代码. <IfModule mod_rewrite.c>

    SEO2020-01-15
  • 根目录新建.htaccess文件 RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\\. RewriteCond %{HTTP_HOST} !^$

    SEO2020-01-15
  • 一、PC站所有页面跳转同一手机页面 function is_mobile() { var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|

    部分JS效果2020-01-15