php封装的smartyBC类完整实例

本文实例讲述了php封装的smartyBC类。分享给大家供大家参考,具体如下:

<?php
/**
 * Project:   Smarty: the PHP compiling template engine
 * File:    SmartyBC.class.php
 * SVN:     $Id: $
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * For questions, help, comments, discussion, etc., please join the
 * Smarty mailing list. Send a blank e-mail to
 * smarty-discussion-subscribe@googlegroups.com
 *
 * @link   http://www.smarty.net/
 * @copyright 2008 New Digital Group, Inc.
 * @author  Monte Ohrt <monte at ohrt dot com>
 * @author  Uwe Tews
 * @author  Rodney Rehm
 * @package  Smarty
 */
/**
 * @ignore
 */
require_once(dirname(__FILE__) . '/Smarty.class.php');
/**
 * Smarty Backward Compatability Wrapper Class
 *
 * @package Smarty
 */
class SmartyBC extends Smarty
{
  /**
   * Smarty 2 BC
   *
   * @var string
   */
  public $_version = self::SMARTY_VERSION;
  /**
   * Initialize new SmartyBC object
   *
   * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
   */
  public function __construct(array $options = array())
  {
    parent::__construct($options);
    // register {php} tag
    $this->registerPlugin('block', 'php', 'smarty_php_tag');
  }
  /**
   * wrapper for assign_by_ref
   *
   * @param string $tpl_var the template variable name
   * @param mixed &$value the referenced value to assign
   */
  public function assign_by_ref($tpl_var, &$value)
  {
    $this->assignByRef($tpl_var, $value);
  }
  /**
   * wrapper for append_by_ref
   *
   * @param string $tpl_var the template variable name
   * @param mixed  &$value the referenced value to append
   * @param boolean $merge  flag if array elements shall be merged
   */
  public function append_by_ref($tpl_var, &$value, $merge = false)
  {
    $this->appendByRef($tpl_var, $value, $merge);
  }
  /**
   * clear the given assigned template variable.
   *
   * @param string $tpl_var the template variable to clear
   */
  public function clear_assign($tpl_var)
  {
    $this->clearAssign($tpl_var);
  }
  /**
   * Registers custom function to be used in templates
   *
   * @param string $function   the name of the template function
   * @param string $function_impl the name of the PHP function to register
   * @param bool  $cacheable
   * @param mixed $cache_attrs
   */
  public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
  {
    $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
  }
  /**
   * Unregisters custom function
   *
   * @param string $function name of template function
   */
  public function unregister_function($function)
  {
    $this->unregisterPlugin('function', $function);
  }
  /**
   * Registers object to be used in templates
   *
   * @param string $object   name of template object
   * @param object $object_impl the referenced PHP object to register
   * @param array  $allowed   list of allowed methods (empty = all)
   * @param boolean $smarty_args smarty argument format, else traditional
   * @param array  $block_methods list of methods that are block format
   *
   * @throws SmartyException
   * @internal param array $block_functs list of methods that are block format
   */
  public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
  {
    settype($allowed, 'array');
    settype($smarty_args, 'boolean');
    $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
  }
  /**
   * Unregisters object
   *
   * @param string $object name of template object
   */
  public function unregister_object($object)
  {
    $this->unregisterObject($object);
  }
  /**
   * Registers block function to be used in templates
   *
   * @param string $block   name of template block
   * @param string $block_impl PHP function to register
   * @param bool  $cacheable
   * @param mixed $cache_attrs
   */
  public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
  {
    $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
  }
  /**
   * Unregisters block function
   *
   * @param string $block name of template function
   */
  public function unregister_block($block)
  {
    $this->unregisterPlugin('block', $block);
  }
  /**
   * Registers compiler function
   *
   * @param string $function   name of template function
   * @param string $function_impl name of PHP function to register
   * @param bool  $cacheable
   */
  public function register_compiler_function($function, $function_impl, $cacheable = true)
  {
    $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
  }
  /**
   * Unregisters compiler function
   *
   * @param string $function name of template function
   */
  public function unregister_compiler_function($function)
  {
    $this->unregisterPlugin('compiler', $function);
  }
  /**
   * Registers modifier to be used in templates
   *
   * @param string $modifier   name of template modifier
   * @param string $modifier_impl name of PHP function to register
   */
  public function register_modifier($modifier, $modifier_impl)
  {
    $this->registerPlugin('modifier', $modifier, $modifier_impl);
  }
  /**
   * Unregisters modifier
   *
   * @param string $modifier name of template modifier
   */
  public function unregister_modifier($modifier)
  {
    $this->unregisterPlugin('modifier', $modifier);
  }
  /**
   * Registers a resource to fetch a template
   *
   * @param string $type   name of resource
   * @param array $functions array of functions to handle resource
   */
  public function register_resource($type, $functions)
  {
    $this->registerResource($type, $functions);
  }
  /**
   * Unregisters a resource
   *
   * @param string $type name of resource
   */
  public function unregister_resource($type)
  {
    $this->unregisterResource($type);
  }
  /**
   * Registers a prefilter function to apply
   * to a template before compiling
   *
   * @param callable $function
   */
  public function register_prefilter($function)
  {
    $this->registerFilter('pre', $function);
  }
  /**
   * Unregisters a prefilter function
   *
   * @param callable $function
   */
  public function unregister_prefilter($function)
  {
    $this->unregisterFilter('pre', $function);
  }
  /**
   * Registers a postfilter function to apply
   * to a compiled template after compilation
   *
   * @param callable $function
   */
  public function register_postfilter($function)
  {
    $this->registerFilter('post', $function);
  }
  /**
   * Unregisters a postfilter function
   *
   * @param callable $function
   */
  public function unregister_postfilter($function)
  {
    $this->unregisterFilter('post', $function);
  }
  /**
   * Registers an output filter function to apply
   * to a template output
   *
   * @param callable $function
   */
  public function register_outputfilter($function)
  {
    $this->registerFilter('output', $function);
  }
  /**
   * Unregisters an outputfilter function
   *
   * @param callable $function
   */
  public function unregister_outputfilter($function)
  {
    $this->unregisterFilter('output', $function);
  }
  /**
   * load a filter of specified type and name
   *
   * @param string $type filter type
   * @param string $name filter name
   */
  public function load_filter($type, $name)
  {
    $this->loadFilter($type, $name);
  }
  /**
   * clear cached content for the given template and cache id
   *
   * @param string $tpl_file  name of template file
   * @param string $cache_id  name of cache_id
   * @param string $compile_id name of compile_id
   * @param string $exp_time  expiration time
   *
   * @return boolean
   */
  public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
  {
    return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
  }
  /**
   * clear the entire contents of cache (all templates)
   *
   * @param string $exp_time expire time
   *
   * @return boolean
   */
  public function clear_all_cache($exp_time = null)
  {
    return $this->clearCache(null, null, null, $exp_time);
  }
  /**
   * test to see if valid cache exists for this template
   *
   * @param string $tpl_file name of template file
   * @param string $cache_id
   * @param string $compile_id
   *
   * @return boolean
   */
  public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
  {
    return $this->isCached($tpl_file, $cache_id, $compile_id);
  }
  /**
   * clear all the assigned template variables.
   */
  public function clear_all_assign()
  {
    $this->clearAllAssign();
  }
  /**
   * clears compiled version of specified template resource,
   * or all compiled template files if one is not specified.
   * This function is for advanced use only, not normally needed.
   *
   * @param string $tpl_file
   * @param string $compile_id
   * @param string $exp_time
   *
   * @return boolean results of {@link smarty_core_rm_auto()}
   */
  public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
  {
    return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
  }
  /**
   * Checks whether requested template exists.
   *
   * @param string $tpl_file
   *
   * @return boolean
   */
  public function template_exists($tpl_file)
  {
    return $this->templateExists($tpl_file);
  }
  /**
   * Returns an array containing template variables
   *
   * @param string $name
   *
   * @return array
   */
  public function get_template_vars($name = null)
  {
    return $this->getTemplateVars($name);
  }
  /**
   * Returns an array containing config variables
   *
   * @param string $name
   *
   * @return array
   */
  public function get_config_vars($name = null)
  {
    return $this->getConfigVars($name);
  }
  /**
   * load configuration values
   *
   * @param string $file
   * @param string $section
   * @param string $scope
   */
  public function config_load($file, $section = null, $scope = 'global')
  {
    $this->ConfigLoad($file, $section, $scope);
  }
  /**
   * return a reference to a registered object
   *
   * @param string $name
   *
   * @return object
   */
  public function get_registered_object($name)
  {
    return $this->getRegisteredObject($name);
  }
  /**
   * clear configuration values
   *
   * @param string $var
   */
  public function clear_config($var = null)
  {
    $this->clearConfig($var);
  }
  /**
   * trigger Smarty error
   *
   * @param string $error_msg
   * @param integer $error_type
   */
  public function trigger_error($error_msg, $error_type = E_USER_WARNING)
  {
    trigger_error("Smarty error: $error_msg", $error_type);
  }
}
/**
 * Smarty {php}{/php} block function
 *
 * @param array  $params  parameter list
 * @param string $content contents of the block
 * @param object $template template object
 * @param boolean &$repeat repeat flag
 *
 * @return string content re-formatted
 */
function smarty_php_tag($params, $content, $template, &$repeat)
{
  eval($content);
  return '';
}

更多关于Smarty相关内容感兴趣的读者可查看本站专题:《smarty模板入门基础教程》、《PHP模板技术总结》、《PHP基于pdo操作数据库技巧总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于smarty模板的PHP程序设计有所帮助。

(0)

相关推荐

  • php实现的Captcha验证码类实例

    本文实例讲述了php实现的Captcha验证码类,在php程序设计中有着极其广泛的应用.分享给大家供大家参考.具体方法如下: 验证码类文件如下: <?php /** Captcha 验证码类 * Date: 2011-02-19 * Author: fdipzone */ class Captcha{ //class start private $sname = ''; public function __construct($sname=''){ // $sname captcha sessi

  • PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题)

    smtp.php <?phpclass smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_ho

  • php封装的page分页类完整实例

    本文实例讲述了php封装的page分页类.分享给大家供大家参考,具体如下: 类文件: <?php //分页工具类 class Page{ /* * 获取分页字符串 * @param1 string $uri,分页要请求的脚本url * @param3 int $counts,总记录数 * @param4 int $length,每页显示的记录数 * @param5 int $page = 1,当前页码 * @return string,带有a标签的,可以点击发起请求的字符串 */ public

  • php封装的单文件(图片)上传类完整实例

    本文实例讲述了php封装的单文件(图片)上传类.分享给大家供大家参考,具体如下: <?php //封装php中的单文件(图片)上传类 /* //参数1:$file 文件数组 5个属性值 name,type,size,tmp,error //参数2:文件保存的路径$path //参数3:文件上传允许的类型 $allow数组 $allow=array('image/jpeg','image/jpg','image/png','image/gif') //参数4: 允许文件上传的最大大小 $size

  • PHP 动态随机生成验证码类代码

    下面是效果图,这个效果图是没有开启干扰码的效果图 下面是类代码 复制代码 代码如下: <?php /************************************************ //FILE:ImageCode //DONE:生成动态验证码类 //DATE"2010-3-31 //Author:www.5dkx.com 5D开心博客 *********************************************************************

  • php封装的表单验证类完整实例

    本文实例讲述了php封装的表单验证类.分享给大家供大家参考,具体如下: <?php //封装一个表单验证类 //中文验证.邮箱验证.电话号码.手机.QQ.身份证.(由字母.数字.下划线组成,不能以数字开头) header('content-type:text/html;charset=utf-8'); class Form{ /* //中文验证的方法 //参数:$str,$num1,$num2 //返回值:匹配成功返回匹配的次数 */ public function checkChina($st

  • PHP 基于文件头的文件类型验证类函数

    我这里写了一个验证类,是通过文件头来判断文件格式.(也不是百分之百安全,如果用户伪造了文件头,也能通过验证) 复制代码 代码如下: <?php /** * 检证文件类型类 * * @author Silver */ class FileTypeValidation { // 文件类型,不同的头信息 private static $_fileFormats = Array( 'jp2' => '0000000C6A502020',<br/> '3gp' => '00000020

  • php基于单例模式封装mysql类完整实例

    本文实例讲述了php基于单例模式封装mysql类.分享给大家供大家参考,具体如下: 类: <?php header("content-type:text/html;charset=utf-8"); //封装一个类 /* 掌握满足单例模式的必要条件 (1)私有的构造方法-为了防止在类外使用new关键字实例化对象 (2)私有的成员属性-为了防止在类外引入这个存放对象的属性 (3)私有的克隆方法-为了防止在类外通过clone成生另一个对象 (4)公有的静态方法-为了让用户进行实例化对象

  • 一个漂亮的php验证码类(分享)

    直接上代码: 复制代码 代码如下: //验证码类class ValidateCode { private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';//随机因子 private $code;//验证码 private $codelen = 4;//验证码长度 private $width = 130;//宽度 private $height = 50;//高度 private $img;//图形资源句柄 pri

  • PHP验证码类代码( 最新修改,完全定制化! )

    Authnum.class.php 下载 复制代码 代码如下: <?php session_start(); class Authnum { //图片对象.宽度.高度.验证码长度 private $im; private $im_width; private $im_height; private $len; //随机字符串.y轴坐标值.随机颜色 private $randnum; private $y; private $randcolor; //背景色的红绿蓝,默认是浅灰色 public $

  • PHP代码实现表单数据验证类

    下面通过一段PHP代码实现表单数据验证类,具体介绍如下: 非常好用方便的表单数据验证类 <?php //验证类 class Fun{ function isEmpty($val) { if (!is_string($val)) return false; //是否是字符串类型 if (empty($val)) return false; //是否已设定 if ($val=='') return false; //是否为空 return true; } /* -------------------

  • 生成随机字符串和验证码的类的PHP实例

    网上有很多的php随机数与验证码的代码与文章,真正适用的没有几个. 索性自己搞一个吧. 开始本节的php教程 吧,以下代码的实现,主要做到可以很好区分一个get_code(),另一个create_check_image(),输出图像直接调用后面的,session()取验证码时直接get_code()就ok,顺带提下使用session时必须将session_star()放在最前面. 代码如下: 复制代码 代码如下: <?phpclass RandCheckCode{        /*函数名称:g

  • php表单敏感字符过滤类

    本文实例讲述了php表单敏感字符过滤类及其用法.分享给大家供大家参考.具体分析如下: 复制代码 代码如下: /** * 表单生成验证文件 */ $_form = new formHtmlFind(); class formHtmlFind{         /**          * 输出表单函数          * $formKey  表单键          * $infoArray 更新时的原始信息数组          */           public function for

  • php常用表单验证类用法实例

    本文实例讲述了php常用表单验证类用法.分享给大家供大家参考.具体如下: <?php /** * 页面作用:常用表单验证类 * 作 者:欣然随风 * QQ:276624915 */ class class_post { //验证是否为指定长度的字母/数字组合 function fun_text1($num1,$num2,$str) { Return (preg_match("/^[a-zA-Z0-9]{".$num1.",".$num2."}$/&q

  • PHP学习笔记 用户注册模块用户类以及验证码类

    所以,把第一章,可重用类的代码贴出来,便于以后查阅以及供给有需要的朋友. :User类,包括读取和设置数据库,以及保存更改交互 复制代码 代码如下: <?php class User{ private $uid; private $fields; public function __construct(){ $this->uid=null; $this->fields=array('username'=>'','password'=>'','emailAddr'=>''

随机推荐