在WHMCS中加密smarty tpl模块文件 [英] Encrypting smarty tpl module file in WHMCS

查看:253
本文介绍了在WHMCS中加密smarty tpl模块文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用在WHMCS模块中的ionCube加密tpl文件,而不修改WHMCS smarty.class文件。任何人都知道如何做到这一点?

I am trying to encrypt a tpl file with ionCube in my module in WHMCS without modifying WHMCS smarty.class file. Anyone have any idea how can I do that?

有关更多信息,请参阅 http://www.ioncube.com/sa_encoder.php?page=smarty_patch

For further information see http://www.ioncube.com/sa_encoder.php?page=smarty_patch

推荐答案

当然,您需要使用ionCube Php Encoder,您需要创建项目,添加文件,然后在GUI中的项目设置 - >来源您应该右键单击您的TPL文件,然后选择加密非PHP文件。没有办法可以在没有在IonCube文档中应用Smarty补丁的情况下执行此操作。

Of course you need to have ionCube Php Encoder, you need to create project, add files and then in GUI in Project settings -> Source you should right click on your TPL file and select "Encrypt non-PHP file". There is no way you can do it without applying Smarty patch as in ionCube documentation.

您还可以扩展Smarty类。

You can also extend Smarty class.

对于 Smarty 2 ,代码将很简单:

<?php

class MyTemplate extends Smarty {

// Replacement function for _read_file() in Smarty.class.php to add support
// for reading both ionCube encrypted templates and plain text templates.
// Smarty.class.php must be encoded by the creator of the templates for
// ioncube_read_file() to decode encrypted template files

    function _read_file($filename)
    {
        $res = false;

        if (file_exists($filename)) {
            if (function_exists('ioncube_read_file')) {
                $res = ioncube_read_file($filename);
                if (is_int($res)) $res = false;
            }
            else if ( ($fd = @fopen($filename, 'rb')) ) {
                $res = ($size = filesize($filename)) ? fread($fd, $size) : '';
                fclose($fd);
            }
        }

        return $res;
    }    
}

您应该创建此类的对象以使用修改

and you should create object of this class to use modified code.

对于 Smarty 3 ,这更复杂一些。

您需要创建 MyFileResource 类如下:

<?php
//MyFileResource.php    

class MyFileResource extends Smarty_Internal_Resource_File {

    /**
     * Load template's source from file into current template object
     *
     * @param  Smarty_Template_Source $source source object
     * @return string                 template source
     * @throws SmartyException        if source cannot be loaded
     */
    public function getContent(Smarty_Template_Source $source)
    {       
        if ($source->timestamp) {                                    

            if (file_exists($source->filepath) && function_exists('ioncube_read_file')) {
                $res = ioncube_read_file($source->filepath);
                if (is_int($res)) {
                    $res = false;
                }
                return $res;                  
            }
            else {
                return file_get_contents($source->filepath); 
            }                                
        }

        if ($source instanceof Smarty_Config_Source) {
            throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
        }
        throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
    }

}

在您创建Smarty的地方对象添加一些代码。

And in place where you created Smarty object add some code.

假设您以这种方式创建了Smarty对象:

Assume you created Smarty object this way:

require '../libs/Smarty.class.php';

$smarty = new Smarty;

您应该将其更改为:

require '../libs/Smarty.class.php';

require('MyFileResource.php');

$smarty = new Smarty;

$smarty->registerResource('file', new MyFileResource());

每次从文件中读取模板时,都可以使用MyFileResource类。我没有测试这个代码,但它应该工作。根据您的设置,您可能需要删除所有已编译的模板文件,以便再次重新生成。

This way each time you read templates from files you use your MyFileResource class. I haven't tested this code but it should work. Depending on your settings it's possible you will need to remove all your compiled template files to regenerate them again.

这篇关于在WHMCS中加密smarty tpl模块文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆