⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smarty.addons.php

📁 通达OA官方提供的30源代码,感觉很实在
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php
/*
 * Project:     Smarty: the PHP compiled template engine
 * File:        Smarty.addons.php
 * Author:      Monte Ohrt <monte@ispi.net>
 *              Andrei Zmievski <andrei@php.net>
 * Version:     1.5.2
 * Copyright:   2001 ispi of Lincoln, Inc.
 *
 * 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
 *
 * You may contact the authors of Smarty by e-mail at:
 * monte@ispi.net
 * andrei@php.net
 *
 * Or, write to:
 * Monte Ohrt
 * Directory of Technology, ispi
 * 237 S. 70th suite 220
 * Lincoln, NE 68510
 *
 * The latest version of Smarty can be obtained from:
 * http://www.phpinsider.com
 *
 */


/*============================================*\
  Modifiers
\*============================================*/


/*======================================================================*\
    Function: smarty_mod_escape
    Purpose:  Escape the string according to escapement type
\*======================================================================*/
function smarty_mod_escape($string, $esc_type = 'html')
{
    switch ($esc_type) {
        case 'html':
            return htmlspecialchars($string, ENT_QUOTES);

        case 'url':
            return urlencode($string);

        case 'quotes':
            // escape unescaped single quotes
            return preg_replace("%(?<!\\\\)'%", "\\'", $string);

        default:
            return $string;
    }
}


/*======================================================================*\
    Function: smarty_mod_truncate
    Purpose:  Truncate a string to a certain length if necessary,
              optionally splitting in the middle of a word, and
              appending the $etc string.
\*======================================================================*/
function smarty_mod_truncate($string, $length = 80, $etc = '...', $break_words = false)
{
    if ($length == 0)
        return '';

    if (strlen($string) > $length) {
        $length -= strlen($etc);
        $fragment = substr($string, 0, $length+1);
        if ($break_words)
            $fragment = substr($fragment, 0, -1);
        else
            $fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
        return $fragment.$etc;
    } else
        return $string;
}


/*======================================================================*\
    Function: smarty_mod_spacify
    Purpose:  add spaces between characters in a string
\*======================================================================*/
function smarty_mod_spacify($string, $spacify_char = ' ')
{
    return implode($spacify_char, preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
}

/*======================================================================*\
    Function: smarty_mod_date_format
    Purpose:  format datestamps via strftime
\*======================================================================*/
function smarty_mod_date_format($string, $format="%b %e, %Y")
{
    return strftime($format, smarty_make_timestamp($string));
}

/*======================================================================*\
    Function: smarty_make_timestamp
    Purpose:  used by other smarty functions to make a timestamp
              from a string of characters.
\*======================================================================*/
function smarty_make_timestamp($string)
{
	if(empty($string)) {
		$string = "now";
	}
    $time = strtotime($string);
    if (is_numeric($time) && $time != -1)
        return $time;

    // is mysql timestamp format of YYYYMMDDHHMMSS?
    if (is_numeric($string) && strlen($string) == 14) {
        $time = mktime(substr($string,8,2),substr($string,10,2),substr($string,12,2),
               substr($string,4,2),substr($string,6,2),substr($string,0,4));

        return $time;
    }

    // can't decipher, just return it
    return $string;
}

/*======================================================================*\
    Function: smarty_mod_string_format
    Purpose:  format strings via sprintf
\*======================================================================*/
function smarty_mod_string_format($string, $format)
{
    return sprintf($format, $string);
}

/*======================================================================*\
    Function: smarty_mod_replace
    Purpose:  simple search/replace
\*======================================================================*/
function smarty_mod_replace($string, $search, $replace)
{
    return str_replace($search, $replace, $string);
}

/*======================================================================*\
    Function: smarty_mod_regex_replace
    Purpose:  regular epxression search/replace
\*======================================================================*/
function smarty_mod_regex_replace($string, $search, $replace)
{
    return preg_replace($search, $replace, $string);
}

/*======================================================================*\
    Function: smarty_mod_strip_tags
    Purpose:  strip html tags from text
\*======================================================================*/
function smarty_mod_strip_tags($string, $replace_with_space = true)
{
    if ($replace_with_space)
        return preg_replace('!<[^>]*?>!', ' ', $string);
    else
        return strip_tags($string);
}

/*======================================================================*\
    Function: smarty_mod_default
    Purpose:  designate default text for empty variables
\*======================================================================*/
function smarty_mod_default($string, $default="")
{
    if (empty($string))
        return $default;
    else
        return $string;
}



/*======================================================================*\
    Function: smarty_func_um_welcome_message
    Purpose:  translate system boxes into different languages


\*======================================================================*/


function smarty_func_um_welcome_message($args, &$smarty_obj)
{

    extract($args);
	$config_vars = $smarty_obj->_config[0]["vars"];

	$array_keys = array_keys($args);

    if (empty($var)) {
        $smarty_obj->_trigger_error_msg("um_welcome_message: missing 'var' parameter");
        return;
    }

    if (!in_array('messages',$array_keys )) {
        $smarty_obj->_trigger_error_msg("um_welcome_message: missing 'messages' parameter");
        return;
    }

    if (!in_array('unread', $array_keys)) {
        $smarty_obj->_trigger_error_msg("um_welcome_message: missing 'unread' parameter");
        return;
    }
    if (!in_array('var', $array_keys)) {
        $smarty_obj->_trigger_error_msg("um_welcome_message: missing 'var' parameter");
        return;
    }

    if (!in_array('boxname', $array_keys)) {
        $smarty_obj->_trigger_error_msg("um_welcome_message: missing 'boxname' parameter");
        return;
    }

	$wlcmessage = $config_vars["msg_you_have"]. " <b>$messages</b> ";

	if($messages == 1)
		$wlcmessage .= $config_vars["msg_message"].", ";
	else
		$wlcmessage .= $config_vars["msg_messages"].", ";

	if($unread == 0)
		$wlcmessage .= $config_vars["msg_none_unread"]." ";
	elseif($unread == 1)
		$wlcmessage .= "<b>$unread</b> ". $config_vars["msg_one_unread"]." ";
	else
		$wlcmessage .= "<b>$unread</b> ". $config_vars["msg_more_unread"]." ";

	$wlcmessage .= $config_vars["msg_in_the_folder"]." <b>$boxname</b>";

    $smarty_obj->assign($var, $wlcmessage);
    return true;
}

/*======================================================================*\
    Function: smarty_func_um_translatebox
    Purpose:  translate system boxes into different languages
\*======================================================================*/
function smarty_func_um_translatebox($args, &$smarty_obj)
{

    extract($args);
	$config_vars = $smarty_obj->_config[0]["vars"];

    if (empty($var)) {
        $smarty_obj->_trigger_error_msg("um_translatebox: missing 'var' parameter");
        return;
    }

    if (!in_array('value', array_keys($args))) {
        $smarty_obj->_trigger_error_msg("um_translatebox: missing 'value' parameter");
        return;
    }

	switch(strtolower($value)) {
		case "inbox":
			$value = $config_vars["inbox_extended"];
			break;
		case "sent":
			$value = $config_vars["sent_extended"];
			break;
		case "trash":
			$value = $config_vars["trash_extended"];
			break;
	}

    $smarty_obj->assign($var, $value);
    return true;
}


/*======================================================================*\
    Function: smarty_func_assign
    Purpose:  assign a value to a template variable
\*======================================================================*/
function smarty_func_assign($args, &$smarty_obj)
{
    extract($args);

    if (empty($var)) {
        $smarty_obj->_trigger_error_msg("assign: missing 'var' parameter");
        return;
    }

    if (!in_array('value', array_keys($args))) {
        $smarty_obj->_trigger_error_msg("assign: missing 'value' parameter");
        return;
    }

    $smarty_obj->assign($var, $value);
    return true;
}

/*============================================*\
  Custom tag functions
\*============================================*/

/*======================================================================*\
    Function: smarty_func_html_options
    Purpose:  Prints the list of <option> tags generated from
              the passed parameters
\*======================================================================*/
function smarty_func_html_options()
{
    $print_result = true;

    extract(func_get_arg(0));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -