Chevereto - 首页加入上传图片总数量统计

折腾记录
1004 0

Nginx URL rewriting规则:

# Context limits
client_max_body_size 20M;

# Disable access to sensitive files
location ~* (app|content|lib)/.*\.(po|php|lock|sql)$ {
deny all;
}

# Image not found replacement
location ~ \.(jpe?g|png|gif|webp)$ {
log_not_found off;
error_page 404 /content/images/system/default/404.gif;
}

# CORS header (avoids font rendering issues)
location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$ {
add_header Access-Control-Allow-Origin "*";
}

# Pretty URLs
location / {
index index.php;
try_files $uri $uri/ /index.php$is_args$query_string;
}

Chevereto - 首页加入上传图片总数量统计

第一种方法

在文件/app/themes/Peafowl/views/index.php 合适位置加入以下代码:

<div id="home-cover" data-content="follow-scroll-opacity">
        <?php G\Render\include_theme_file('snippets/homepage_cover_slideshow'); ?>
        <div id="home-cover-content" class="c20 fluid-column center-box padding-left-10 padding-right-10">
                <?php CHV\Render\show_banner('home_before_title', (function_exists('get_list') ? get_list()->sfw : true)); ?>
                <h1><?php echo CHV\getSetting('homepage_title_html') ?: _s('Upload and share your images.'); ?></h1>
     <h1>本站共托管 <?php
$stats = CHV\Stat::getTotals();
echo $stats['images'] > 999999 ? $stats['images'] : number_format($stats['images']); // Will output the total n° images
?> 张图片</h1>

第二种方法

1、新建文件--保存为 count.php

<?php
error_reporting(0);
$con = mysql_connect("localhost", "数据库用户名", "数据库密码");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$db_selected = mysql_select_db("tu",$con);
$sql = "SELECT * FROM chv_images";
$result = mysql_query($sql,$con);
echo mysql_num_rows($result);
mysql_close($con);
?>

2、放在 app/themes/Peafowl/views/index.php 文件中的合适位置

<?php
$data = file_get_contents('https://网站域名/count.php');
?>
<p>本站已托管图片 <?php echo $data ?> 张</p>

修改上传界面默认为嵌入代码

修改文件位置 app/routes/route.image.php

$tabs = [
            [
                'label' => _s('About'),
                'id' => 'tab-about',
                
            ],
        ];
        if (CHV\isShowEmbedContent()) {
            $tabs[] = [
                'label' => _s('Embed codes'),
                'id' => 'tab-codes',
                'current' => true,
            ];
        }

修改选择图片后的获取代码 文件位置 /app/themes/Peafowl/snippets/embed.php 大约在第5-21行

global $embed_tpl, $embed_unapproved_tpl;
$embed_tpl = [
    'links' => [
        'label' => _s('Links'),
        'options' => [
            'direct-links' => [
                'label' => _s('Direct links'),//直接源文件 作为第一位
                'template' => '%URL%',
                'size' => 'full',
            ],
            'viewer-links' => [
                'label' => _s('Viewer links'),
                'template' => '%URL_SHORT%',
                'size' => 'viewer',
            ],
        ],
    ],
https://blog.fxb.cc/51.html
最后更新 2021-12-15
评论 ( 0 )
问:壹 + 贰 = ?
OωO
隐私评论