Other 2x Copyright Footer Management - Quản lý Footer Copyright của XenForo 2

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,829
Được Like
12,688
Copyright Footer Management - Quản lý Footer Copyright của XenForo 2

Đây là hướng dẫn nhanh về cách tự động gộp tất cả các copyright footer từ các add-on thành một dòng, tránh tình huống có 5 bản phát hành với 5 dòng riêng biệt.

Template Modifications

Template: PAGE_CONTAINER
Modification Key: your_namespace_copyright_footer_display
Description: Copyright Footer
Search type: PHP Callback
Find: #({{ phrase\('extra_copyright'\) }})#si
Replace: Your\Namespace\Template\Callback\Copyright::insert
Execution order: 10


Code Event Listeners

Listen to event: app_setup
Execute callback: Your\Namespace\Listener :: appSetup
Execution order: 10
Description: App setup


PHP

/src/Your/Namespace/Listener.php
Mã:
<?php

namespace Your\Namespace;

class Listener
{
    /**
     * The product ID (in the store)
     * @var integer
     */
    protected static $_productId = 0;

    /**
     * @param \XF\App $app
     */
    public static function appSetup(
        \XF\App $app
    )
    {
        if (!$app->offsetExists('prefix_branding_free'))
        {
            // Make sure we fetch the branding array from the application
            $branding = $app->offsetExists('prefix_branding') ? $app->prefix_branding : [];
          
            // Add productid to the array
            $branding[] = self::$_productId;
          
            // Store the branding
            $app->prefix_branding = $branding;
        }
    }
}

Thay prefix bằng prefix của nhà cung cấp (ví dụ: dbtech, thông thường đó là phần mà bạn thay thế "Your\Namespace".

/src/Your/Namespace/Template/Callback/Copyright.php
Mã:
<?php

namespace Your\Namespace\Template\Callback;

class Copyright
{
    /**
     * @param $matches
     *
     * @return string
     */
    public static function insert($matches)
    {
        if (!isset($matches[1]))
        {
            // Clean error prevention
            return '';
        }

        /** @var \XF\App $app */
        $app = \XF::app();

        $branding = $app->offsetExists('prefix_branding') ? $app->prefix_branding : [];

        if (!count($branding) OR !is_array($branding))
        {
            // We had nothing left, another mod would have inserted the copyright footer
            return $matches[1];
        }

        // Create this long string
        $html = '<div>
            Parts of this site powered by XenForo add-ons from YourCompany&#8482;
            &copy;2011-' . date('Y') . ' <a class="u-concealed" rel="nofollow" href="https://www.yoursite.com" target="_blank">YourCompany</a>
            (<a class="u-concealed" rel="nofollow" href="https://www.yoursite.com/details.php?products=' . implode(',', $branding) . '" target="_blank">Details</a>)
        </div>';

        // Make sure we null this out
        $app->prefix_branding = [];

        return $matches[1] . $html;
    }
}

Thay Your\Namespace bằng prefix của nhà cung cấp (ví dụ: dbtech, thông thường đó là phần mà bạn thay thế "Your\Namespace". Ngoài ra, hãy thay thế các liên kết www.yoursite.com bằng các liên kết đến trang web của bạn và thay thế "YourCompany" bằng tên công ty của bạn. Cuối cùng, hãy tạo trang detail.php chấp nhận ID sản phẩm làm thông số để hiển thị danh sách các sản phẩm mà trang web đang chạy hoặc xóa toàn bộ phần dấu ngoặc đơn đó.)

Chúc các bạn thành công.


Nguồn: xenforo.com​
 

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mr. Tuấn

Mobile/Zalo: 0988 488 096

Telegram: bluekpro

Email: [email protected]

Nhà Tài Trợ

Mút Xốp Không Gian
pallet Thịnh Phát
Top Bottom