Initial Commit of AgileBill Open Source

This commit is contained in:
unknown
2008-11-26 14:50:40 -08:00
parent ae5a0fc25e
commit 02306ccc47
2954 changed files with 410976 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.account.php
* Type: block
* Name: account
* Purpose: display an account field
* -------------------------------------------------------------
*/
function smarty_block_account($params, $resource, &$smarty)
{
$resource = trim($resource);
if ($resource != '')
{
global $C_list;
echo $C_list->account($resource);
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.group.php
* Type: block
* Name: group
* Purpose: display content to authenticated groups only
* -------------------------------------------------------------
*/
function smarty_block_group($params, $resource, &$smarty)
{
if(empty($resource)) return;
@$id = $params["id"];
$do = false;
$db = &DB();
$sql = 'SELECT status,group_avail FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
status = ' . $db->qstr('1') . ' AND
id = ' . $db->qstr($id);
@$result = $db->Execute($sql);
$do = false;
if(@$result->RecordCount() > 0) {
global $C_auth;
@$arr = unserialize($result->fields['group_avail']);
for($i=0; $i<count($arr); $i++)
if($do == false && $C_auth->auth_group_by_id($arr[$i]))
$do = true;
}
if($do) {
echo $resource;
} else {
echo @$params["msg"];
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.htmlarea.php
* Type: block
* Name: htmlarea
* Purpose: display a WYSIWYG html editor form
* -------------------------------------------------------------
*/
function smarty_block_htmlarea($params, $resource, &$smarty)
{
/* passed params:
field = name of the textarea field
width = width ie '100'
height = height ie '200'
*/
if(isset($resource))
{
if(empty($params['width']))
$width = '550';
else
$width = $params['width'];
if(empty($params['height']))
$height = '350';
else
$height = $params['height'];
echo '
<textarea id="'.$params['field'].'" name="'.$params['field'].'">'.$resource.'</textarea>
<script type="text/javascript" defer="1">
var config = new HTMLArea.Config();
config.width = \''.$width .'px\';
config.height = \''.$height .'px\';
config.toolbar = [
[ "fontname", "space",
"fontsize", "space",
"formatblock", "space",
"strikethrough", "subscript", "superscript", "separator",
"copy", "cut", "paste", "space", "undo", "redo" ],
[ "bold", "italic", "underline", "separator",
"justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
"insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
"forecolor", "hilitecolor", "textindicator", "separator",
"inserthorizontalrule", "createlink", "insertimage", "inserttable", "htmlmode"]
];
HTMLArea.replace("'.$params['field'].'", config);
</script>';
}
}
?>

View File

@@ -0,0 +1,23 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.is_auth.php
* Type: block
* Name: is_auth
* Purpose: display content to authenticated groups based on module & method
* -------------------------------------------------------------
*/
function smarty_block_is_auth($params, $resource, &$smarty)
{
if(empty($resource)) return;
global $C_auth;
if(!is_object($C_auth)) return false;
if($C_auth->auth_method_by_name($params["module"], $params["method"]))
echo $resource;
else
echo $params["alt"];
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.is_auth_method.php
* Type: block
* Name: is_auth_method
* Purpose: display content to authenticated groups based on authentication to module/method
* -------------------------------------------------------------
*/
function smarty_block_is_auth_method($params, $resource, &$smarty)
{
if(empty($resource)) return;
if(!empty($params['logged']) && !SESS_LOGGED) return false;
global $C_auth;
if(!is_object($C_auth)) return false;
if($C_auth->auth_method_by_name($params["module"], $params["method"]))
echo $resource;
else if(!empty($params["alt"]))
echo $params["alt"];
}
?>

View File

@@ -0,0 +1,39 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.panel.php
* Type: block
* Name: panel
* Purpose: Creates a div/span element around html / text
* -------------------------------------------------------------
*/
function smarty_block_panel($params, $resource, &$smarty)
{
$type = 'div';
$show = true;
$_ignore['show'] = true;
$_ignore['type'] = true;
$vals='';
foreach($params as $_key => $_val)
if(empty($_ignore["$_key"]))
$vals .= " $_key=\"$_val\"";
else
$$_key = $_val;
$pre = "<{$type}";
if(!$show)
$pre .= " style=\"display:none\"";
$pre .= $vals;
$pre .= ">\r\n";
$pre .= $resource;
$pre .= "\r\n</$type>";
return $pre;
}
?>

View File

@@ -0,0 +1,103 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {textformat}{/textformat} block plugin
*
* Type: block function<br>
* Name: textformat<br>
* Purpose: format text a certain way with preset styles
* or custom wrap/indent settings<br>
* @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
* @param array
* <pre>
* Params: style: string (email)
* indent: integer (0)
* wrap: integer (80)
* wrap_char string ("\n")
* indent_char: string (" ")
* wrap_boundary: boolean (true)
* </pre>
* @author Monte Ohrt <monte at ohrt dot com>
* @param string contents of the block
* @param Smarty clever simulation of a method
* @return string string $content re-formatted
*/
function smarty_block_textformat($params, $content, &$smarty)
{
if (is_null($content)) {
return;
}
$style = null;
$indent = 0;
$indent_first = 0;
$indent_char = ' ';
$wrap = 80;
$wrap_char = "\n";
$wrap_cut = false;
$assign = null;
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'style':
case 'indent_char':
case 'wrap_char':
case 'assign':
$$_key = (string)$_val;
break;
case 'indent':
case 'indent_first':
case 'wrap':
$$_key = (int)$_val;
break;
case 'wrap_cut':
$$_key = (bool)$_val;
break;
default:
$smarty->trigger_error("textformat: unknown attribute '$_key'");
}
}
if ($style == 'email') {
$wrap = 72;
}
// split into paragraphs
$_paragraphs = preg_split('![\r\n][\r\n]!',$content);
$_output = '';
for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) {
if ($_paragraphs[$_x] == '') {
continue;
}
// convert mult. spaces & special chars to single space
$_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]);
// indent first line
if($indent_first > 0) {
$_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x];
}
// wordwrap sentences
$_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut);
// indent lines
if($indent > 0) {
$_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]);
}
}
$_output = implode($wrap_char . $wrap_char, $_paragraphs);
return $assign ? $smarty->assign($assign, $_output) : $_output;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,38 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: block.translate.php
* Type: block
* Name: translate
* Purpose: translate a block of text
* -------------------------------------------------------------
*/
function smarty_block_translate($params, $resource, &$smarty)
{
global $C_translate;
if($params["module"] != '')
{
$module = $params["module"];
}
else
{
$module = 'CORE';
}
while(list ($key, $val) = each ($params))
{
$C_translate->value["$module"]["$key"] = $val;
}
$resource = trim($resource);
if ($resource != '') {
# strip whitespaces from the resouce identifier
echo $C_translate->translate($resource,$module,'');
}
}
?>

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {assign} compiler function plugin
*
* Type: compiler function<br>
* Name: assign<br>
* Purpose: assign a value to a template variable
* @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> (initial author)
* @auther messju mohr <messju at lammfellpuschen dot de> (conversion to compiler function)
* @param string containing var-attribute and value-attribute
* @param Smarty_Compiler
*/
function smarty_compiler_assign($tag_attrs, &$compiler)
{
$_params = $compiler->_parse_attrs($tag_attrs);
if (!isset($_params['var'])) {
$compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING);
return;
}
if (!isset($_params['value'])) {
$compiler->_syntax_error("assign: missing 'value' parameter", E_USER_WARNING);
return;
}
return "\$this->assign({$_params['var']}, {$_params['value']});";
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,19 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: ab_version
* Purpose: display current AB version
* -------------------------------------------------------------
*/
function smarty_function_ab_version($params, &$smarty)
{
include_once(PATH_CORE.'version.inc.php');
$ver = new CORE_version;
$ver->smarty();
}
?>

View File

@@ -0,0 +1,30 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: assign
* Purpose: assign a value to a template variable
* -------------------------------------------------------------
*/
function smarty_function_assign($params, &$smarty)
{
extract($params);
if (empty($var)) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (!in_array('value', array_keys($params))) {
$smarty->trigger_error("assign: missing 'value' parameter");
return;
}
$smarty->assign($var, $value);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {assign_debug_info} function plugin
*
* Type: function<br>
* Name: assign_debug_info<br>
* Purpose: assign debug info to the template<br>
* @author Monte Ohrt <monte at ohrt dot com>
* @param array unused in this plugin, this plugin uses {@link Smarty::$_config},
* {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info}
* @param Smarty
*/
function smarty_function_assign_debug_info($params, &$smarty)
{
$assigned_vars = $smarty->_tpl_vars;
ksort($assigned_vars);
if (@is_array($smarty->_config[0])) {
$config_vars = $smarty->_config[0];
ksort($config_vars);
$smarty->assign("_debug_config_keys", array_keys($config_vars));
$smarty->assign("_debug_config_vals", array_values($config_vars));
}
$included_templates = $smarty->_smarty_debug_info;
$smarty->assign("_debug_keys", array_keys($assigned_vars));
$smarty->assign("_debug_vals", array_values($assigned_vars));
$smarty->assign("_debug_tpls", $included_templates);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,29 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: block
* Purpose: display an agilebill block
* Usage: {block module=? block=?}
* -------------------------------------------------------------
*/
function smarty_function_block($params, &$this)
{
extract($params);
if($module == 'TEMPLATE') {
$this->display('file:' . PATH_THEMES . '' . THEME_NAME . '/' . $smarty->template_dir . '' . $block . '.tpl');
} else {
if(is_file(PATH_THEMES . '' . THEME_NAME . '/blocks/' . $module . '/' . $block . '.tpl'))
$this->display('file:'. PATH_THEMES . '' . THEME_NAME . '/blocks/' . $module . '/' . $block . '.tpl' );
elseif (is_file(PATH_THEMES . '' . DEF_THEME_N . '/blocks/' . $module . '/' . $block . '.tpl'))
$this->display('file:' . PATH_THEMES . '' . DEF_THEME_N . '/blocks/' . $module . '/' . $block . '.tpl');
elseif (is_file(PATH_THEMES . 'default/blocks/' . $module . '/' . $block . '.tpl'))
$this->display('file:' . PATH_THEMES . 'default/blocks/' . $module . '/' . $block . '.tpl');
else
$this->display('file:'. PATH_THEMES . '' . DEF_THEME_N . '/blocks/core/invalid_page.tpl');
}
}
?>

View File

@@ -0,0 +1,142 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {config_load} function plugin
*
* Type: function<br>
* Name: config_load<br>
* Purpose: load config file vars
* @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author messju mohr <messju at lammfellpuschen dot de> (added use of resources)
* @param array Format:
* <pre>
* array('file' => required config file name,
* 'section' => optional config file section to load
* 'scope' => local/parent/global
* 'global' => overrides scope, setting to parent if true)
* </pre>
* @param Smarty
*/
function smarty_function_config_load($params, &$smarty)
{
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$_debug_start_time = smarty_core_get_microtime($_params, $smarty);
}
$_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
$_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
$_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
$_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
if (!isset($_file) || strlen($_file) == 0) {
$smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
}
if (isset($_scope)) {
if ($_scope != 'local' &&
$_scope != 'parent' &&
$_scope != 'global') {
$smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
}
} else {
if ($_global) {
$_scope = 'parent';
} else {
$_scope = 'local';
}
}
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
'get_source' => false);
$smarty->_parse_resource_name($_params);
$_file_path = $_params['resource_type'] . ':' . $_params['resource_name'];
if (isset($_section))
$_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
else
$_compile_file = $smarty->_get_compile_path($_file_path);
if($smarty->force_compile || !file_exists($_compile_file)) {
$_compile = true;
} elseif ($smarty->compile_check) {
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
'get_source' => false);
$_compile = $smarty->_fetch_resource_info($_params) &&
$_params['resource_timestamp'] > filemtime($_compile_file);
} else {
$_compile = false;
}
if($_compile) {
// compile config file
if(!is_object($smarty->_conf_obj)) {
require_once SMARTY_DIR . $smarty->config_class . '.class.php';
$smarty->_conf_obj = new $smarty->config_class();
$smarty->_conf_obj->overwrite = $smarty->config_overwrite;
$smarty->_conf_obj->booleanize = $smarty->config_booleanize;
$smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
$smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
}
$_params = array('resource_name' => $_file,
'resource_base_path' => $smarty->config_dir,
$_params['get_source'] = true);
if (!$smarty->_fetch_resource_info($_params)) {
return;
}
$smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
$_config_vars = array_merge($smarty->_conf_obj->get($_file),
$smarty->_conf_obj->get($_file, $_section));
if(function_exists('var_export')) {
$_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
} else {
$_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
}
$_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp']));
require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
smarty_core_write_compiled_resource($_params, $smarty);
} else {
include($_compile_file);
}
if ($smarty->caching) {
$smarty->_cache_info['config'][$_file] = true;
}
$smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);
$smarty->_config[0]['files'][$_file] = true;
if ($_scope == 'parent') {
$smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);
$smarty->_config[1]['files'][$_file] = true;
} else if ($_scope == 'global') {
for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {
$smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);
$smarty->_config[$i]['files'][$_file] = true;
}
}
if ($smarty->debugging) {
$_params = array();
require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
$smarty->_smarty_debug_info[] = array('type' => 'config',
'filename' => $_file.' ['.$_section.'] '.$_scope,
'depth' => $smarty->_inclusion_depth,
'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,80 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {counter} function plugin
*
* Type: function<br>
* Name: counter<br>
* Purpose: print out a counter value
* @author Monte Ohrt <monte at ohrt dot com>
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
* @param array parameters
* @param Smarty
* @return string|null
*/
function smarty_function_counter($params, &$smarty)
{
static $counters = array();
$name = (isset($params['name'])) ? $params['name'] : 'default';
if (!isset($counters[$name])) {
$counters[$name] = array(
'start'=>1,
'skip'=>1,
'direction'=>'up',
'count'=>1
);
}
$counter =& $counters[$name];
if (isset($params['start'])) {
$counter['start'] = $counter['count'] = (int)$params['start'];
}
if (!empty($params['assign'])) {
$counter['assign'] = $params['assign'];
}
if (isset($counter['assign'])) {
$smarty->assign($counter['assign'], $counter['count']);
}
if (isset($params['print'])) {
$print = (bool)$params['print'];
} else {
$print = empty($counter['assign']);
}
if ($print) {
$retval = $counter['count'];
} else {
$retval = null;
}
if (isset($params['skip'])) {
$counter['skip'] = $params['skip'];
}
if (isset($params['direction'])) {
$counter['direction'] = $params['direction'];
}
if ($counter['direction'] == "down")
$counter['count'] -= $counter['skip'];
else
$counter['count'] += $counter['skip'];
return $retval;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {cycle} function plugin
*
* Type: function<br>
* Name: cycle<br>
* Date: May 3, 2002<br>
* Purpose: cycle through given values<br>
* Input:
* - name = name of cycle (optional)
* - values = comma separated list of values to cycle,
* or an array of values to cycle
* (this can be left out for subsequent calls)
* - reset = boolean - resets given var to true
* - print = boolean - print var or not. default is true
* - advance = boolean - whether or not to advance the cycle
* - delimiter = the value delimiter, default is ","
* - assign = boolean, assigns to template var instead of
* printed.
*
* Examples:<br>
* <pre>
* {cycle values="#eeeeee,#d0d0d0d"}
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
* </pre>
* @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author credit to Mark Priatel <mpriatel@rogers.com>
* @author credit to Gerard <gerard@interfold.com>
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
* @version 1.3
* @param array
* @param Smarty
* @return string|null
*/
function smarty_function_cycle($params, &$smarty)
{
static $cycle_vars;
$name = (empty($params['name'])) ? 'default' : $params['name'];
$print = (isset($params['print'])) ? (bool)$params['print'] : true;
$advance = (isset($params['advance'])) ? (bool)$params['advance'] : true;
$reset = (isset($params['reset'])) ? (bool)$params['reset'] : false;
if (!in_array('values', array_keys($params))) {
if(!isset($cycle_vars[$name]['values'])) {
$smarty->trigger_error("cycle: missing 'values' parameter");
return;
}
} else {
if(isset($cycle_vars[$name]['values'])
&& $cycle_vars[$name]['values'] != $params['values'] ) {
$cycle_vars[$name]['index'] = 0;
}
$cycle_vars[$name]['values'] = $params['values'];
}
$cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ',';
if(is_array($cycle_vars[$name]['values'])) {
$cycle_array = $cycle_vars[$name]['values'];
} else {
$cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
}
if(!isset($cycle_vars[$name]['index']) || $reset ) {
$cycle_vars[$name]['index'] = 0;
}
if (isset($params['assign'])) {
$print = false;
$smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
}
if($print) {
$retval = $cycle_array[$cycle_vars[$name]['index']];
} else {
$retval = null;
}
if($advance) {
if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) {
$cycle_vars[$name]['index'] = 0;
} else {
$cycle_vars[$name]['index']++;
}
}
return $retval;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,16 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.date
* Type: function
* Name: date
* -------------------------------------------------------------
*/
function smarty_function_date($params, &$smarty)
{
extract($params);
echo date(UNIX_DATE_FORMAT,$date);
}
?>

View File

@@ -0,0 +1,18 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.date_time
* Type: function
* Name: date_time
* -------------------------------------------------------------
*/
function smarty_function_date_time($params, &$smarty)
{
extract($params);
echo date(UNIX_DATE_FORMAT,$time);
echo " ";
echo date(DEFAULT_TIME_FORMAT,$time);
}
?>

View File

@@ -0,0 +1,33 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: db_lookup
* Purpose: get a field value from the database for a given id
* -------------------------------------------------------------
*/
function smarty_function_db_lookup($params, &$smarty)
{
extract($params);
if (empty($id)) {
$smarty->trigger_error("db_lookup: attribute 'id' required");
return false;
}
if (empty($table)) {
$smarty->trigger_error("db_lookup: attribute 'table' required");
return false;
}
if (empty($field)) {
$smarty->trigger_error("db_lookup: attribute 'field' required");
return false;
}
$db =& DB();
$rs = $db->Execute(sqlSelect($db, $table, $field, "id=::".$id."::"));
return $rs->fields[0];
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {debug} function plugin
*
* Type: function<br>
* Name: debug<br>
* Date: July 1, 2002<br>
* Purpose: popup debug window
* @link http://smarty.php.net/manual/en/language.function.debug.php {debug}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @param array
* @param Smarty
* @return string output from {@link Smarty::_generate_debug_output()}
*/
function smarty_function_debug($params, &$smarty)
{
if (isset($params['output'])) {
$smarty->assign('_smarty_debug_output', $params['output']);
}
require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php');
return smarty_core_display_debug_console(null, $smarty);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {eval} function plugin
*
* Type: function<br>
* Name: eval<br>
* Purpose: evaluate a template variable as a template<br>
* @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
*/
function smarty_function_eval($params, &$smarty)
{
if (!isset($params['var'])) {
$smarty->trigger_error("eval: missing 'var' parameter");
return;
}
if($params['var'] == '') {
return;
}
$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
ob_start();
$smarty->_eval('?>' . $_var_compiled);
$_contents = ob_get_contents();
ob_end_clean();
if (!empty($params['assign'])) {
$smarty->assign($params['assign'], $_contents);
} else {
return $_contents;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,22 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.exe.php
* Type: function
* Name: exe
* -------------------------------------------------------------
*/
function smarty_function_exe($params, &$smarty)
{
extract($params);
include_once(PATH_CORE.'method.inc.php');
$m = new CORE_method;
if(!empty($noauth))
$m->exe_noauth($module,$method);
else
echo $m->exe($module,$method);
}
?>

View File

@@ -0,0 +1,221 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {fetch} plugin
*
* Type: function<br>
* Name: fetch<br>
* Purpose: fetch file, web or ftp data and display results
* @link http://smarty.php.net/manual/en/language.function.fetch.php {fetch}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string|null if the assign parameter is passed, Smarty assigns the
* result to a template variable
*/
function smarty_function_fetch($params, &$smarty)
{
if (empty($params['file'])) {
$smarty->_trigger_fatal_error("[plugin] parameter 'file' cannot be empty");
return;
}
$content = '';
if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
$_params = array('resource_type' => 'file', 'resource_name' => $params['file']);
require_once(SMARTY_CORE_DIR . 'core.is_secure.php');
if(!smarty_core_is_secure($_params, $smarty)) {
$smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed');
return;
}
// fetch the file
if($fp = @fopen($params['file'],'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
return;
}
} else {
// not a local file
if(preg_match('!^http://!i',$params['file'])) {
// http fetch
if($uri_parts = parse_url($params['file'])) {
// set defaults
$host = $server_name = $uri_parts['host'];
$timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine ".$smarty->_version;
$referer = "";
$uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/';
$uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : '';
$_is_proxy = false;
if(empty($uri_parts['port'])) {
$port = 80;
} else {
$port = $uri_parts['port'];
}
if(!empty($uri_parts['user'])) {
$user = $uri_parts['user'];
}
if(!empty($uri_parts['pass'])) {
$pass = $uri_parts['pass'];
}
// loop through parameters, setup headers
foreach($params as $param_key => $param_value) {
switch($param_key) {
case "file":
case "assign":
case "assign_headers":
break;
case "user":
if(!empty($param_value)) {
$user = $param_value;
}
break;
case "pass":
if(!empty($param_value)) {
$pass = $param_value;
}
break;
case "accept":
if(!empty($param_value)) {
$accept = $param_value;
}
break;
case "header":
if(!empty($param_value)) {
if(!preg_match('![\w\d-]+: .+!',$param_value)) {
$smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'");
return;
} else {
$extra_headers[] = $param_value;
}
}
break;
case "proxy_host":
if(!empty($param_value)) {
$proxy_host = $param_value;
}
break;
case "proxy_port":
if(!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
case "agent":
if(!empty($param_value)) {
$agent = $param_value;
}
break;
case "referer":
if(!empty($param_value)) {
$referer = $param_value;
}
break;
case "timeout":
if(!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return;
}
break;
default:
$smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'");
return;
}
}
if(!empty($proxy_host) && !empty($proxy_port)) {
$_is_proxy = true;
$fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout);
} else {
$fp = fsockopen($server_name,$port,$errno,$errstr,$timeout);
}
if(!$fp) {
$smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)");
return;
} else {
if($_is_proxy) {
fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n");
} else {
fputs($fp, "GET $uri HTTP/1.0\r\n");
}
if(!empty($host)) {
fputs($fp, "Host: $host\r\n");
}
if(!empty($accept)) {
fputs($fp, "Accept: $accept\r\n");
}
if(!empty($agent)) {
fputs($fp, "User-Agent: $agent\r\n");
}
if(!empty($referer)) {
fputs($fp, "Referer: $referer\r\n");
}
if(isset($extra_headers) && is_array($extra_headers)) {
foreach($extra_headers as $curr_header) {
fputs($fp, $curr_header."\r\n");
}
}
if(!empty($user) && !empty($pass)) {
fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n");
}
fputs($fp, "\r\n");
while(!feof($fp)) {
$content .= fgets($fp,4096);
}
fclose($fp);
$csplit = split("\r\n\r\n",$content,2);
$content = $csplit[1];
if(!empty($params['assign_headers'])) {
$smarty->assign($params['assign_headers'],split("\r\n",$csplit[0]));
}
}
} else {
$smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax");
return;
}
} else {
// ftp fetch
if($fp = @fopen($params['file'],'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
return;
}
}
}
if (!empty($params['assign'])) {
$smarty->assign($params['assign'],$content);
} else {
return $content;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,41 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: graph
* Purpose: displays a specific flash graph
* -------------------------------------------------------------
*/
function smarty_function_graph($params, &$this)
{
$width = 500;
$height = 300;
$color = "FFFFFF";
$transparency = true;
extract($params);
if(empty($module) || empty($method)) return false;
include_once (PATH_INCLUDES .'charts/charts.php');
if($title) {
global $C_translate;
$trans = $C_translate->translate($title,$module);
if(!empty($trans)) $title = $trans;
}
if($show === false) $display = 'style="display:none"';
global $VAR;
$vars = '';
foreach($VAR as $a => $b) $vars .= "&{$a}={$b}";
echo "<div id=\"{$id}\" class=\"graph\" $display>";
echo "<h3>$title</h3>";
echo InsertChart ( "includes/charts/charts.swf", "includes/charts/charts_library", URL."ajax.php?do[]={$module}:{$method}{$vars}", $width, $height, $color, $transparency);
echo "</div>";
}
?>

View File

@@ -0,0 +1,20 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: grid_boo
* Purpose: Formats boolean fields to translated true/false value
* -------------------------------------------------------------
*/
function smarty_function_grid_bool($params, &$smarty)
{
extract($params);
if(!empty($bool))
echo translate('true');
else
echo translate('false');
}
?>

View File

@@ -0,0 +1,31 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: grid_column_heading
* Purpose: display grid column heading
* -------------------------------------------------------------
*/
function smarty_function_grid_column_heading($params, &$smarty)
{
extract($params);
if($column == '_checkbox') {
echo '<input type="checkbox" id="'.$module.'_check_main" onclick="'.$module.'_grid.switchCheck(this.checked)" />';
return;
}
echo '<span style="float:right;display:none;overflow:hidden" id="'.$module.'_grid_'.$column.'_asc"><img src="images/asc.gif" alt="ASC" /></span>';
echo '<span style="float:right;display:none;overflow:hidden" id="'.$module.'_grid_'.$column.'_desc"><img src="images/desc.gif" alt="DESC" /></span>';
global $C_translate;
if($column == 'id')
echo '<span class="nobr"><?smarty:translate?>'.$C_translate->translate("id").'<?smarty:/translate?></span>';
else
echo '<span class="nobr"><?smarty:translate module='.$module.'?>'.$C_translate->translate("field_".$column,$module).'<?smarty:/translate?></span>';
}
?>

View File

@@ -0,0 +1,26 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: grid_column_refine
* Purpose: display grid columns for refine search
* -------------------------------------------------------------
*/
function smarty_function_grid_column_refine($params, &$smarty)
{
extract($params);
if(empty($expr)) $expr = 'LIKE';
echo '<input type="hidden" name="'.$module.'[conditions]['.$column.'][exp][]" value="'.$expr.'" />';
echo '<input type="hidden" name="'.$module.'[conditions]['.$column.'][col][]" value="'.$column.'" />';
if($column == 'id')
echo '<input type="text" name="'.$module.'[conditions]['.$column.'][val][]" onclick="this.value=\'\'" size="4" />';
else
echo '<input type="text" name="'.$module.'[conditions]['.$column.'][val][]" onclick="this.value=\'\'" />';
}
?>

View File

@@ -0,0 +1,22 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: grid_paginate
* Purpose: display grid pagination controls
* -------------------------------------------------------------
*/
function smarty_function_grid_paginate($params, &$smarty)
{
extract($params);
global $C_translate;
echo '<input type="button" disabled onclick="'.$module.'_grid.paginateJump(1);" value="'. $C_translate->translate("grid_first") .'" id="'.$module.'_grid_pageinate_first" />';
echo '<input type="button" disabled onclick="'.$module.'_grid.paginateJump(\'prev\');" value="'. $C_translate->translate("grid_prev") .'" id="'.$module.'_grid_pageinate_prev" />';
echo '<input type="text" onchange="'.$module.'_grid.paginateJump(this.value)" onfocus="this.value=\'\'" value="1" size="4" maxlength="4" id="'.$module.'_grid_pageinate_jump" style="padding:3px; width:30px; text-align:center; background-color:#f1f1f1;" />';
echo '<input type="button" disabled onclick="'.$module.'_grid.paginateJump(\'next\');" value="'. $C_translate->translate("grid_next") .'" id="'.$module.'_grid_pageinate_next" />';
echo '<input type="button" disabled onclick="'.$module.'_grid.paginateJump(\'last\');" value="'. $C_translate->translate("grid_last") .'" id="'.$module.'_grid_pageinate_last" />';
}
?>

View File

@@ -0,0 +1,28 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.html_bool
* Type: function
* Name: html_bool
* -------------------------------------------------------------
*/
function smarty_function_html_bool($params, &$smarty)
{
extract($params);
if(empty($id)) $id = $field;
if(empty($value)) $value = '1';
$extra=' ';
if(!empty($onclick)) $extra .= ' onClick="'.$onclick.'" ';
if($default == $value) $extra .= 'checked ';
$ret = '<input type="checkbox" name="'.$field.'" id="'.$id.'" value="'.$value.'"'.$extra.'/>';
return $ret;
}
?>

View File

@@ -0,0 +1,58 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.html_button.php
* Type: function
* Name: html_checkboxes
* Version: 1.0
* -------------------------------------------------------------
*/
function smarty_function_html_button($params, &$smarty)
{
$allowdclick = true;
$name = 'submit';
$module = 'CORE';
foreach($params as $_key => $_val) $$_key = $_val;
# translate name
global $C_translate;
$trans = $C_translate->translate($name, $module);
if(!empty($trans)) $name = $trans;
# allow multiple clicks?
if(!$allowdclick) $action = "this.disabled=true; this.value='". $C_translate->translate('processing') ."';" . $action;
# change state(s)
$t = 0;
if($hide) {
$e = 'Fade';
if(ereg(',', $hide)) $hides = explode(',', $hide); else $hides = Array($hide);
foreach($hides as $element) {
if(ereg('\|', $element)) {
$el = explode('|', $element);
$action .= " new Effect.{$el[2]}('{$el[0]}', {duration: {$el[1]}}); ";
} else {
$action .= " $('{$element}').style.display='none'; ";
}
}
}
if($show) {
$e = 'Appear';
if(ereg(',', $show)) $shows = explode(',', $show); else $shows = Array($show);
foreach($shows as $element) {
if(ereg('\|', $element)) {
$el = explode('|', $element);
$action .= " new Effect.{$el[2]}('{$el[0]}', {duration: {$el[1]}}); ";
} else {
$action .= " $('{$element}').style.display='block'; ";
}
}
}
$html = "<input id=\"{$id}\" type=\"submit\" name=\"{$name}\" value=\"{$name}\" onclick=\"{$action} \">";
return $html;
}
?>

View File

@@ -0,0 +1,143 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_checkboxes} function plugin
*
* File: function.html_checkboxes.php<br>
* Type: function<br>
* Name: html_checkboxes<br>
* Date: 24.Feb.2003<br>
* Purpose: Prints out a list of checkbox input types<br>
* Input:<br>
* - name (optional) - string default "checkbox"
* - values (required) - array
* - options (optional) - associative array
* - checked (optional) - array default not set
* - separator (optional) - ie <br> or &nbsp;
* - output (optional) - the output next to each checkbox
* - assign (optional) - assign the output as an array to this variable
* Examples:
* <pre>
* {html_checkboxes values=$ids output=$names}
* {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
* {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
* </pre>
* @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_checkboxes($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
$name = 'checkbox';
$values = null;
$options = null;
$selected = null;
$separator = '';
$labels = true;
$output = null;
$extra = '';
foreach($params as $_key => $_val) {
switch($_key) {
case 'name':
case 'separator':
$$_key = $_val;
break;
case 'labels':
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'checked':
case 'selected':
$selected = array_map('strval', array_values((array)$_val));
break;
case 'checkboxes':
$smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
$options = (array)$_val;
break;
case 'assign':
break;
default:
if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values))
return ''; /* raise error here? */
settype($selected, 'array');
$_html_result = array();
if (isset($options)) {
foreach ($options as $_key=>$_val)
$_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
} else {
foreach ($values as $_i=>$_key) {
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);
}
}
if(!empty($params['assign'])) {
$smarty->assign($params['assign'], $_html_result);
} else {
return implode("\n",$_html_result);
}
}
function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) {
$_output = '';
if ($labels) $_output .= '<label>';
$_output .= '<input type="checkbox" name="'
. smarty_function_escape_special_chars($name) . '[]" value="'
. smarty_function_escape_special_chars($value) . '"';
if (in_array((string)$value, $selected)) {
$_output .= ' checked="checked"';
}
$_output .= $extra . ' />' . $output;
if ($labels) $_output .= '</label>';
$_output .= $separator;
return $_output;
}
?>

View File

@@ -0,0 +1,28 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.html_date
* Type: function
* Name: html_date
* -------------------------------------------------------------
*/
function smarty_function_html_date($params, &$smarty)
{
extract($params);
if($disabled) return '<input type="text" id="'.$id.'" name="'.$field.'" value="'.$default.'" disabled />';
# set the date to current date if 'now' is set as default
if($default == 'now') $default = date(UNIX_DATE_FORMAT);
if(empty($id)) $id = $field;
if(empty($trigger)) $trigger = $id;
$ret = '<input type="text" id="'.$id.'" name="'.$field.'" value="'.$default.'" />';
$ret .= '<script type="text/javascript"> Calendar.setup({inputField: "'.$id.'", ifFormat: "'.DEFAULT_DATE_FORMAT.'", button: "'.$trigger.'"}); </script> ';
return $ret;
}
?>

View File

@@ -0,0 +1,142 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_image} function plugin
*
* Type: function<br>
* Name: html_image<br>
* Date: Feb 24, 2003<br>
* Purpose: format HTML tags for the image<br>
* Input:<br>
* - file = file (and path) of image (required)
* - height = image height (optional, default actual height)
* - width = image width (optional, default actual width)
* - basedir = base directory for absolute paths, default
* is environment variable DOCUMENT_ROOT
* - path_prefix = prefix for path output (optional, default empty)
*
* Examples: {html_image file="/images/masthead.gif"}
* Output: <img src="/images/masthead.gif" width=400 height=23>
* @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Duda <duda@big.hu> - wrote first image function
* in repository, helped with lots of functionality
* @version 1.0
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_image($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
$alt = '';
$file = '';
$height = '';
$width = '';
$extra = '';
$prefix = '';
$suffix = '';
$path_prefix = '';
$server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
$basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : '';
foreach($params as $_key => $_val) {
switch($_key) {
case 'file':
case 'height':
case 'width':
case 'dpi':
case 'path_prefix':
case 'basedir':
$$_key = $_val;
break;
case 'alt':
if(!is_array($_val)) {
$$_key = smarty_function_escape_special_chars($_val);
} else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
case 'link':
case 'href':
$prefix = '<a href="' . $_val . '">';
$suffix = '</a>';
break;
default:
if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (empty($file)) {
$smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
return;
}
if (substr($file,0,1) == '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
}
if(!isset($params['width']) || !isset($params['height'])) {
if(!$_image_data = @getimagesize($_image_path)) {
if(!file_exists($_image_path)) {
$smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
return;
} else if(!is_readable($_image_path)) {
$smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
return;
} else {
$smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
return;
}
}
if ($smarty->security &&
($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) &&
(require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) &&
(!smarty_core_is_secure($_params, $smarty)) ) {
$smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE);
}
if(!isset($params['width'])) {
$width = $_image_data[0];
}
if(!isset($params['height'])) {
$height = $_image_data[1];
}
}
if(isset($params['dpi'])) {
if(strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) {
$dpi_default = 72;
} else {
$dpi_default = 96;
}
$_resize = $dpi_default/$params['dpi'];
$width = round($width * $_resize);
$height = round($height * $_resize);
}
return $prefix . '<img src="'.$path_prefix.$file.'" alt="'.$alt.'" width="'.$width.'" height="'.$height.'"'.$extra.' />' . $suffix;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,77 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.html_link.php
* Type: function
* Name: html_link
* Version: 1.0
* -------------------------------------------------------------
*/
function smarty_function_html_link($params, &$smarty)
{
$name = 'submit';
$module = 'CORE';
$_ignore['show'] = true;
$_ignore['hide'] = true;
$_ignore['name'] = true;
# Get the values passed...
$vals='';
foreach($params as $_key => $_val)
if(empty($_ignore["$_key"]))
$vals .= " $_key=\"$_val\"";
else
$$_key = $_val;
foreach($params as $_key => $_val) $$_key = $_val;
# change state(s) (hide)
$t = 0;
if($hide) {
$e = 'Fade';
if(ereg(',', $hide)) $hides = explode(',', $hide); else $hides = Array($hide);
foreach($hides as $element) {
if(ereg('\|', $element)) {
$el = explode('|', $element);
$action .= " new Effect.{$el[2]}('{$el[0]}', {duration: {$el[1]}}); ";
} else {
$action .= " $('{$element}').style.display='none'; ";
}
}
}
# change state(s) (show)
if($show) {
$e = 'Appear';
if(ereg(',', $show)) $shows = explode(',', $show); else $shows = Array($show);
foreach($shows as $element) {
if(ereg('\|', $element)) {
$el = explode('|', $element);
$action .= " new Effect.{$el[2]}('{$el[0]}', {duration: {$el[1]}}); ";
} else {
$action .= " $('{$element}').style.display='block'; ";
}
}
}
# translate name
global $C_translate;
$trans = $C_translate->translate($name, $module);
if(!empty($trans)) $name = $trans;
if(empty($link)) $link = "#";
$html = "<a href=\"$link\"";
$html .= $vals;
if($action) $html .= " onclick=\"{$action}\">";
$html .= $name;
$html .= "</a>";
return $html;
}
?>

View File

@@ -0,0 +1,41 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu
* Purpose: Get creates a html menu for associated records
* -------------------------------------------------------------
*/
function smarty_function_html_menu($params, &$smarty)
{
$conditions='';
extract($params);
if(empty($field)) $field = $name;
if(empty($id)) $id = $field;
$db = &DB();
$rs = & $db->Execute( $sql = sqlSelect($db, $assoc_table, "id,".$assoc_field, $conditions, $assoc_field));
#echo $sql;
$return = '<select id="'.$id.'" name="'. $field .'">';
if($default == "all" || $blank) $return .= '<option value="" selected></option>';
if($rs && $rs->RecordCount() > 0)
{
while(!$rs->EOF)
{
$return .= '<option value="' . $rs->fields['id'] . '"';
if($default == $rs->fields['id']) $return .= "selected";
$return .= '>' . $rs->fields["$assoc_field"] . '</option>';
$rs->MoveNext();
}
} else {
if( $default != "all") $return .= '<option value=""></option>';
}
$return .= '</select>';
echo $return;
}
?>

View File

@@ -0,0 +1,80 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_files
* Purpose: Get list of files from the filesystem
* -------------------------------------------------------------
*/
function smarty_function_html_menu_files($params, &$smarty)
{
extract($params);
if(empty($field)) $field = $name;
if(empty($path)) $path = $dir;
if(empty($id)) $id = $field;
if($path == 'product_cat') { $path = PATH_THEMES . '' . DEF_THEME_N . '/blocks/product_cat/'; }
elseif($path == 'product') { $path = PATH_PLUGINS . '/product/'; }
elseif($path == 'theme') { $path = PATH_THEMES; }
elseif($path == 'static_template') { $path = PATH_THEMES . '/default/blocks/static_page/'; $ext = "_template.tpl"; $cap=1; }
elseif($path == 'language') { $path = PATH_LANGUAGE. '/core/'; $ext = "_core.xml"; $cap=1; }
elseif($path == 'whois_plugin') { $path = PATH_PLUGINS . '/whois/'; }
elseif($path == 'provision_plugin') { $path = PATH_PLUGINS . '/provision/'; }
elseif($path == 'affiliate_plugin') { $path = PATH_PLUGINS . '/affiliate/'; }
elseif($path == 'checkout_plugin') { $path = PATH_PLUGINS . '/checkout/'; }
elseif($path == 'voip_did') { $path = PATH_PLUGINS . '/voip_did/'; $ext = ".php"; }
elseif($path == 'invoice_pdf') { $path = PATH_INCLUDES. '/pdf/'; $ext = ".inc.php"; $pre = "pdf_invoice_"; }
$count = 0;
chdir($path);
$dir = opendir($path);
while ($file_name = readdir($dir))
{
$display = true;
if($file_name != '..' && $file_name != '.')
{
if(!empty($ext))
{
$cute = eregi_replace($ext.'$', "", $file_name);
if(!eregi($ext.'$', $file_name)) $display = false;
}
if(!empty($pre))
{
$cute = eregi_replace('^'.$pre, "", $cute);
if(!eregi('^'.$pre, $file_name)) $display = false;
}
if($display)
{
$arr[] = $cute;
$cute = eregi_replace("_"," ",$cute);
$cute = eregi_replace("-"," ",$cute);
if($cap==1) $cute = ucfirst(strtolower($cute));
elseif($cap==2) $cute = ucwords(strtolower($cute));
elseif($cap) $cute = strtoupper($cute);
$arrc[] = $cute;
$count++;
}
}
}
$return = '<select id="'.$id.'" name="'. $field .'" value="'.$default.'">';
if($default == "all")
$return .= '<option value="" selected></option>';
$i = 0;
for($i=0; $i<$count; $i++)
{
$return .= '<option value="' . $arr[$i] . '"';
if($default == $arr[$i])
$return .= "selected";
$return .= '>' . $arrc[$i] . '</option>';
}
if($count==0 && $default != 'all') $return .= '<option value=""></option>';
$return .= '</select>';
echo $return;
}
?>

View File

@@ -0,0 +1,51 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_multi
* Purpose: Get creates a html menu for associated records (multi-select)
* -------------------------------------------------------------
*/
function smarty_function_html_menu_multi($params, &$smarty)
{
$conditions='';
extract($params);
if(empty($field)) $field = $name;
if(empty($id)) $id = $field;
if(empty($size)) $size = '4';
$db = &DB();
$rs = & $db->Execute( $sql = sqlSelect($db, $assoc_table, "id,".$assoc_field, $conditions, $assoc_field));
if(empty($default)) $default = Array('');
elseif (is_array($default)) $default = $default;
elseif (is_numeric($default)) $default[] = $default;
elseif (is_string($default)) $default = unserialize($default);
else $default = Array('');
if($default == "all") $return .= '<option value="" selected></option>';
$i=0;
if($rs && $rs->RecordCount() > 0) {
while(!$rs->EOF) {
$return .= '<option value="' . $rs->fields['id'] . '"';
foreach($default as $def) { if($def == $rs->fields["id"]) $return .= " selected"; break; }
$return .= '>' . $rs->fields["$assoc_field"] . '</option>';
$i++;
$rs->MoveNext();
}
} else {
if( $default != "all") $return .= '<option value=""></option>';
}
$return .= '</select>';
if($i < $size) $size = $i++;
echo '<select id="'.$id.'" name="'. $field .'[]" size="'.$size.'" value="" multiple>' . $return;
}
?>

View File

@@ -0,0 +1,41 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_product_host
* Purpose: Autoselect for all active hosting plans
* -------------------------------------------------------------
*/
function smarty_function_html_menu_product_host($params, &$smarty)
{
$id = $params['id'];
$name = $params['name'];
$default = unserialize($params['default']);
$size = $params['size'];
$exclude = $params['exclude'];
if(empty($id)) $id = $name;
$db = &DB();
$p = AGILE_DB_PREFIX;
$q = "SELECT id,sku FROM {$p}product
WHERE host = 1
AND active = 1
AND price_type = 1
AND id != $exclude
AND site_id = " . DEFAULT_SITE;
$result = $db->Execute($q);
if($result && $result->RecordCount() > 0)
{
echo "<select id=\"$id\" name=\"{$name}[]\" size=\"$size\" multiple>";
while(!$result->EOF) {
$sel='';
foreach($default as $cur) if ($cur == $result->fields['id']) $sel = "selected";
echo "<option value=\"{$result->fields['id']}\"$sel>{$result->fields['sku']}</option>";
$result->MoveNext();
}
echo "</select>";
}
}
?>

View File

@@ -0,0 +1,42 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_product_subscription
* Purpose: Autoselect for all active non-hosting subscriptions
* -------------------------------------------------------------
*/
function smarty_function_html_menu_product_subscription($params, &$smarty)
{
$id = $params['id'];
$name = $params['name'];
$default = unserialize($params['default']);
$size = $params['size'];
$exclude = $params['exclude'];
if(empty($id)) $id = $name;
$db = &DB();
$p = AGILE_DB_PREFIX;
$q = "SELECT id,sku FROM {$p}product
WHERE
( host = 0 OR host IS NULL )
AND active = 1
AND price_type = 1
AND id != $exclude
AND site_id = " . DEFAULT_SITE;
$result = $db->Execute($q);
if($result && $result->RecordCount() > 0)
{
echo "<select id=\"$id\" name=\"{$name}[]\" size=\"$size\" multiple>";
while(!$result->EOF) {
$sel='';
foreach($default as $cur) if ($cur == $result->fields['id']) $sel = "selected";
echo "<option value=\"{$result->fields['id']}\"$sel>{$result->fields['sku']}</option>";
$result->MoveNext();
}
echo "</select>";
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_search_expr
* Purpose: display search form expression menu
* -------------------------------------------------------------
*/
function smarty_function_html_menu_search_expr($params, &$smarty)
{
extract($params);
// Types: exact, date, dateex, number, fulltext, text (default)
switch($type) {
case 'exact':
$options = Array('EQ', 'NULL', 'NNULL');
break;
case 'date':
$options = Array('GTEQ', 'LTEQ', 'GT', 'LT');
break;
case 'dateex':
$options = Array('EQ', 'GTEQ', 'LTEQ', 'GT', 'LT');
break;
case 'number':
$options = Array('EQ', 'GTEQ', 'LTEQ', 'GT', 'LT', 'NULL', 'NNULL');
break;
case 'fulltext':
$options = Array('FT');
break;
case 'text':
$options = Array('LIKE','NLIKE', 'EQ', 'NOT', 'NULL', 'NNULL');
break;
}
if(empty($options)) $options = Array('LIKE','NLIKE', 'EQ', 'NOT', 'NULL', 'NNULL');
$optionsTxt["EQ"] = 'IS EXACT';
$optionsTxt["LIKE"] = 'IS LIKE';
$optionsTxt["NOT"] = 'IS NOT';
$optionsTxt["NLIKE"] = 'IS NOT LIKE';
$optionsTxt["GT"] = 'IS &gt;';
$optionsTxt["LT"] = 'IS &lt;';
$optionsTxt["GTEQ"] = 'IS &gt;=';
$optionsTxt["LTEQ"] = 'IS &lt;=';
$optionsTxt["NULL"] = 'IS NULL';
$optionsTxt["NNULL"] = 'IS NOT NULL';
$optionsTxt["FT"] = 'FULL TEXT';
echo '<select name="'.$module.'[conditions]['.$field.'][exp][]">';
foreach($options as $opt) echo '<option value="'.$opt.'">'.$optionsTxt["$opt"].'</option>';
echo '</select>';
echo '<input type="hidden" name="'.$module.'[conditions]['.$field.'][col][]" value="'.$field.'" />';
}
?>

View File

@@ -0,0 +1,96 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_menu_sub
* Purpose: Creates a html menu for associated records w/sub-record support
* -------------------------------------------------------------
*/
function smarty_function_html_menu_sub($params, &$smarty)
{
$conditions='';
$actions='';
extract($params);
if(empty($field)) $field = $name;
if(empty($id)) $select_id = $field; else $select_id = $id;
if(empty($parent_id)) $parent_id = 'parent_id';
if(!empty($onchange)) $actions .= " onchange=\"$onchange\" ";
$db = &DB();
$result = $db->Execute( sqlSelect($db,$assoc_table,"id,$parent_id,".$assoc_field, $conditions, "$parent_id,$assoc_field"));
# Get current id
if(!empty($VAR['id'])) $cid = ereg_replace(",","", $VAR['id']); else $current = '';
# Loop and put in array
while(!$result->EOF) {
if($result->fields["$parent_id"] == "" || $result->fields["$parent_id"] == 0 || $result->fields["$parent_id"] == $result->fields['id']) {
$arr[0][] = $result->fields;
} else {
$arr["{$result->fields["$parent_id"]}"][] = $result->fields;
}
# get current parent_id
if($cid > 0 && $result->fields['id'] == $cid)
$current = $result->fields["$parent_id"];
$result->MoveNext();
}
$option = '';
$dirpre = ' \\ ';
for($i=0; $i<count($arr[0]); $i++) {
$id = $arr[0][$i]["id"];
if($id == $current) $sel = 'selected'; else $sel = '';
$dir = $dirpre.$dir.$arr[0][$i]["$assoc_field"];
$option .= '<option value="'.$id.'" '.$sel.'>'.$dir.'</option>';
# get the sub-records # (LEVEL 2)
if(isset($arr[$id])) {
for($ii=0; $ii<count($arr[$id]); $ii++) {
$idx = $arr[$id][$ii]["id"];
if($idx == $current) $sel = 'selected'; else $sel = '';
$dir .= $dirpre.$arr[$id][$ii]["$assoc_field"];
$option .= '<option value="'.$idx.'" '.$sel.'>'.$dir.'</option>';
}
# get the sub-records # (LEVEL 3)
if(isset($arr[$idx])) {
for($iii=0; $iii<count($arr[$idx]); $iii++) {
$idx2 = $arr[$idx][$iii]["id"];
if($idx2 == $current) $sel = 'selected'; else $sel = '';
$dir .= $dirpre.$arr[$idx][$iii]["$assoc_field"];
$option .= '<option value="'.$idx2.'" '.$sel.'>'.$dir.'</option>';
}
# get the sub-records # (LEVEL 4)
if(isset($arr[$idx2])) {
for($iiii=0; $iiii<count($arr[$idx2]); $iiii++) {
$idx3 = $arr[$idx2][$iiii]["id"];
if($idx3 == $current) $sel = 'selected'; else $sel = '';
$dir .= $dirpre.$arr[$idx2][$iiii]["$assoc_field"];
$option .= '<option value="'.$idx3.'" '.$sel.'>'.$dir.'</option>';
}
# get the sub-records # (LEVEL 5)
if(isset($arr[$idx3])) {
for($iiiii=0; $iiiii<count($arr[$idx3]); $iiiii++) {
$idx4 = $arr[$idx3][$iiiii]["id"];
if($idx4 == $current) $sel = 'selected'; else $sel = '';
$dir .= $dirpre.$arr[$idx3][$iiiii]["$assoc_field"];
$option .= '<option value="'.$idx4.'" '.$sel.'>'.$dir.'</option>';
}
}
}
}
}
}
echo "<select id=\"$select_id\" name=\"$field\"$actions\>";
echo "<option value=\"0\">\\</option>";
echo $option;
echo '</select>';
}
?>

View File

@@ -0,0 +1,122 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_options} function plugin
*
* Type: function<br>
* Name: html_options<br>
* Input:<br>
* - name (optional) - string default "select"
* - values (required if no options supplied) - array
* - options (required if no values supplied) - associative array
* - selected (optional) - string default not set
* - output (required if not options supplied) - array
* Purpose: Prints the list of <option> tags generated from
* the passed parameters
* @link http://smarty.php.net/manual/en/language.function.html.options.php {html_image}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_options($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
$name = null;
$values = null;
$options = null;
$selected = array();
$output = null;
$extra = '';
foreach($params as $_key => $_val) {
switch($_key) {
case 'name':
$$_key = (string)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'selected':
$$_key = array_map('strval', array_values((array)$_val));
break;
default:
if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_options: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values))
return ''; /* raise error here? */
$_html_result = '';
if (isset($options)) {
foreach ($options as $_key=>$_val)
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
} else {
foreach ($values as $_i=>$_key) {
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected);
}
}
if(!empty($name)) {
$_html_result = '<select name="' . $name . '"' . $extra . '>' . "\n" . $_html_result . '</select>' . "\n";
}
return $_html_result;
}
function smarty_function_html_options_optoutput($key, $value, $selected) {
if(!is_array($value)) {
$_html_result = '<option label="' . smarty_function_escape_special_chars($value) . '" value="' .
smarty_function_escape_special_chars($key) . '"';
if (in_array((string)$key, $selected))
$_html_result .= ' selected="selected"';
$_html_result .= '>' . smarty_function_escape_special_chars($value) . '</option>' . "\n";
} else {
$_html_result = smarty_function_html_options_optgroup($key, $value, $selected);
}
return $_html_result;
}
function smarty_function_html_options_optgroup($key, $values, $selected) {
$optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
foreach ($values as $key => $value) {
$optgroup_html .= smarty_function_html_options_optoutput($key, $value, $selected);
}
$optgroup_html .= "</optgroup>\n";
return $optgroup_html;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,156 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_radios} function plugin
*
* File: function.html_radios.php<br>
* Type: function<br>
* Name: html_radios<br>
* Date: 24.Feb.2003<br>
* Purpose: Prints out a list of radio input types<br>
* Input:<br>
* - name (optional) - string default "radio"
* - values (required) - array
* - options (optional) - associative array
* - checked (optional) - array default not set
* - separator (optional) - ie <br> or &nbsp;
* - output (optional) - the output next to each radio button
* - assign (optional) - assign the output as an array to this variable
* Examples:
* <pre>
* {html_radios values=$ids output=$names}
* {html_radios values=$ids name='box' separator='<br>' output=$names}
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
* </pre>
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
* (Smarty online manual)
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
* @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @param array
* @param Smarty
* @return string
* @uses smarty_function_escape_special_chars()
*/
function smarty_function_html_radios($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
$name = 'radio';
$values = null;
$options = null;
$selected = null;
$separator = '';
$labels = true;
$label_ids = false;
$output = null;
$extra = '';
foreach($params as $_key => $_val) {
switch($_key) {
case 'name':
case 'separator':
$$_key = (string)$_val;
break;
case 'checked':
case 'selected':
if(is_array($_val)) {
$smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
} else {
$selected = (string)$_val;
}
break;
case 'labels':
case 'label_ids':
$$_key = (bool)$_val;
break;
case 'options':
$$_key = (array)$_val;
break;
case 'values':
case 'output':
$$_key = array_values((array)$_val);
break;
case 'radios':
$smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
$options = (array)$_val;
break;
case 'assign':
break;
default:
if(!is_array($_val)) {
$extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';
} else {
$smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if (!isset($options) && !isset($values))
return ''; /* raise error here? */
$_html_result = array();
if (isset($options)) {
foreach ($options as $_key=>$_val)
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
} else {
foreach ($values as $_i=>$_key) {
$_val = isset($output[$_i]) ? $output[$_i] : '';
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids);
}
}
if(!empty($params['assign'])) {
$smarty->assign($params['assign'], $_html_result);
} else {
return implode("\n",$_html_result);
}
}
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids) {
$_output = '';
if ($labels) {
if($label_ids) {
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!', '_', $name . '_' . $value));
$_output .= '<label for="' . $_id . '">';
} else {
$_output .= '<label>';
}
}
$_output .= '<input type="radio" name="'
. smarty_function_escape_special_chars($name) . '" value="'
. smarty_function_escape_special_chars($value) . '"';
if ($labels && $label_ids) $_output .= ' id="' . $_id . '"';
if ((string)$value==$selected) {
$_output .= ' checked="checked"';
}
$_output .= $extra . ' />' . $output;
if ($labels) $_output .= '</label>';
$_output .= $separator;
return $_output;
}
?>

View File

@@ -0,0 +1,49 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_select_account
* Purpose: Autoselect for accounts in AgileBill
* -------------------------------------------------------------
*/
function smarty_function_html_select_account($params, &$smarty)
{
$id = $params['id'];
$name = $params['name'];
$default = $params['default'];
$type = $params['type'];
if(empty($id)) $id = $name."_id";
if(!empty($default)) {
$db = &DB();
$p = AGILE_DB_PREFIX;
$q = "SELECT id,first_name,middle_name,last_name FROM {$p}account
WHERE id = {$default}
AND site_id = " . DEFAULT_SITE;
$result = $db->Execute($q);
if($result->RecordCount() > 0)
$val = $result->fields['first_name'].' '.$result->fields['last_name'];
if(!empty($val)) {
# Get
}
} else {
$val = '';
}
if(empty($val)) {
echo '
<input type="hidden" id="'.$id.'_hidden" name="'.$name.'" value="'.$default.'" />
<input type="text" autocomplete="off" id="'.$id.'" name="account_search" size="35" value="'.$val.'" />
<div class="auto_complete" id="'.$id.'_auto_complete"></div>
<script type="text/javascript">new Ajax.Autocompleter("'.$id.'", "'.$id.'_auto_complete", "ajax.php?do[]=account_admin:autoselect", { })</script>
';
} else {
echo "<a href=\"#\" onClick=\"window.open('?_page=account_admin:view&id={$default}', 'mainFrame', '')\"><u>{$val}</u></a>";
echo "<input value=\"{$default}\" id=\"{$id}\" name=\"{$name}\" type=\"hidden\">";
}
}
?>

View File

@@ -0,0 +1,56 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: html_select_affiliate
* Purpose: Autoselect for affiliate accounts in AgileBill
* -------------------------------------------------------------
*/
function smarty_function_html_select_affiliate($params, &$smarty)
{
$id = $params['id'];
$name = $params['name'];
$default = $params['default'];
$type = $params['type'];
if(empty($id)) $id = $name."_id";
if(!empty($default)) {
$db = &DB();
$p = AGILE_DB_PREFIX;
$q = "SELECT DISTINCT
{$p}affiliate.id,
{$p}account.first_name,
{$p}account.last_name,
{$p}account.username
FROM
{$p}account
LEFT JOIN
{$p}affiliate
ON
{$p}account.id = {$p}affiliate.account_id
WHERE
{$p}affiliate.id = '{$default}' AND
{$p}affiliate.site_id = " . DEFAULT_SITE . " AND
{$p}account.site_id = " . DEFAULT_SITE;
$result = $db->Execute($q);
if($result != false && $result->RecordCount() > 0) $val = $result->fields['first_name'].' '.$result->fields['last_name'];
} else {
$val = '';
}
echo '
<input type="hidden" id="'.$id.'_hidden" name="'.$name.'" value="'.$default.'" />
<input type="text" autocomplete="off" id="'.$id.'" name="affiliate_search" size="35" value="'.$val.'" />
<div class="auto_complete" id="'.$id.'_auto_complete"></div>
<script type="text/javascript">new Ajax.Autocompleter("'.$id.'", "'.$id.'_auto_complete", "ajax.php?do[]=affiliate:autoselect", { })</script>
';
if(!empty($val)) {
// display unselect option
echo '<a href="#" OnClick="document.getElementById(\''.$id.'\').value=\'\'; document.getElementById(\''.$id.'_hidden\').value=\'\'"> - </a>';
}
}
?>

View File

@@ -0,0 +1,323 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_select_date} plugin
*
* Type: function<br>
* Name: html_select_date<br>
* Purpose: Prints the dropdowns for date selection.
*
* ChangeLog:<br>
* - 1.0 initial release
* - 1.1 added support for +/- N syntax for begin
* and end year values. (Monte)
* - 1.2 added support for yyyy-mm-dd syntax for
* time value. (Jan Rosier)
* - 1.3 added support for choosing format for
* month values (Gary Loescher)
* - 1.3.1 added support for choosing format for
* day values (Marcus Bointon)
* - 1.3.2 suppport negative timestamps, force year
* dropdown to include given date unless explicitly set (Monte)
* @link http://smarty.php.net/manual/en/language.function.html.select.date.php {html_select_date}
* (Smarty online manual)
* @version 1.3.2
* @author Andrei Zmievski
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_html_select_date($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
require_once $smarty->_get_plugin_filepath('function','html_options');
/* Default values. */
$prefix = "Date_";
$start_year = strftime("%Y");
$end_year = $start_year;
$display_days = true;
$display_months = true;
$display_years = true;
$month_format = "%B";
/* Write months as numbers by default GL */
$month_value_format = "%m";
$day_format = "%02d";
/* Write day values using this format MB */
$day_value_format = "%d";
$year_as_text = false;
/* Display years in reverse order? Ie. 2000,1999,.... */
$reverse_years = false;
/* Should the select boxes be part of an array when returned from PHP?
e.g. setting it to "birthday", would create "birthday[Day]",
"birthday[Month]" & "birthday[Year]". Can be combined with prefix */
$field_array = null;
/* <select size>'s of the different <select> tags.
If not set, uses default dropdown. */
$day_size = null;
$month_size = null;
$year_size = null;
/* Unparsed attributes common to *ALL* the <select>/<input> tags.
An example might be in the template: all_extra ='class ="foo"'. */
$all_extra = null;
/* Separate attributes for the tags. */
$day_extra = null;
$month_extra = null;
$year_extra = null;
/* Order in which to display the fields.
"D" -> day, "M" -> month, "Y" -> year. */
$field_order = 'MDY';
/* String printed between the different fields. */
$field_separator = "\n";
$time = time();
$all_empty = null;
$day_empty = null;
$month_empty = null;
$year_empty = null;
$extra_attrs = '';
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'prefix':
case 'time':
case 'start_year':
case 'end_year':
case 'month_format':
case 'day_format':
case 'day_value_format':
case 'field_array':
case 'day_size':
case 'month_size':
case 'year_size':
case 'all_extra':
case 'day_extra':
case 'month_extra':
case 'year_extra':
case 'field_order':
case 'field_separator':
case 'month_value_format':
case 'month_empty':
case 'day_empty':
case 'year_empty':
$$_key = (string)$_value;
break;
case 'all_empty':
$$_key = (string)$_value;
$day_empty = $month_empty = $year_empty = $all_empty;
break;
case 'display_days':
case 'display_months':
case 'display_years':
case 'year_as_text':
case 'reverse_years':
$$_key = (bool)$_value;
break;
default:
if(!is_array($_value)) {
$extra_attrs .= ' '.$_key.'="'.smarty_function_escape_special_chars($_value).'"';
} else {
$smarty->trigger_error("html_select_date: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
}
break;
}
}
if(preg_match('!^-\d+$!',$time)) {
// negative timestamp, use date()
$time = date('Y-m-d',$time);
}
// If $time is not in format yyyy-mm-dd
if (!preg_match('/^\d{0,4}-\d{0,2}-\d{0,2}$/', $time)) {
// use smarty_make_timestamp to get an unix timestamp and
// strftime to make yyyy-mm-dd
$time = strftime('%Y-%m-%d', smarty_make_timestamp($time));
}
// Now split this in pieces, which later can be used to set the select
$time = explode("-", $time);
// make syntax "+N" or "-N" work with start_year and end_year
if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) {
if ($match[1] == '+') {
$end_year = strftime('%Y') + $match[2];
} else {
$end_year = strftime('%Y') - $match[2];
}
}
if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) {
if ($match[1] == '+') {
$start_year = strftime('%Y') + $match[2];
} else {
$start_year = strftime('%Y') - $match[2];
}
}
if (strlen($time[0]) > 0) {
if ($start_year > $time[0] && !isset($params['start_year'])) {
// force start year to include given date if not explicitly set
$start_year = $time[0];
}
if($end_year < $time[0] && !isset($params['end_year'])) {
// force end year to include given date if not explicitly set
$end_year = $time[0];
}
}
$field_order = strtoupper($field_order);
$html_result = $month_result = $day_result = $year_result = "";
if ($display_months) {
$month_names = array();
$month_values = array();
if(isset($month_empty)) {
$month_names[''] = $month_empty;
$month_values[''] = '';
}
for ($i = 1; $i <= 12; $i++) {
$month_names[$i] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000));
$month_values[$i] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000));
}
$month_result .= '<select name=';
if (null !== $field_array){
$month_result .= '"' . $field_array . '[' . $prefix . 'Month]"';
} else {
$month_result .= '"' . $prefix . 'Month"';
}
if (null !== $month_size){
$month_result .= ' size="' . $month_size . '"';
}
if (null !== $month_extra){
$month_result .= ' ' . $month_extra;
}
if (null !== $all_extra){
$month_result .= ' ' . $all_extra;
}
$month_result .= $extra_attrs . '>'."\n";
$month_result .= smarty_function_html_options(array('output' => $month_names,
'values' => $month_values,
'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '',
'print_result' => false),
$smarty);
$month_result .= '</select>';
}
if ($display_days) {
$days = array();
if (isset($day_empty)) {
$days[''] = $day_empty;
$day_values[''] = '';
}
for ($i = 1; $i <= 31; $i++) {
$days[] = sprintf($day_format, $i);
$day_values[] = sprintf($day_value_format, $i);
}
$day_result .= '<select name=';
if (null !== $field_array){
$day_result .= '"' . $field_array . '[' . $prefix . 'Day]"';
} else {
$day_result .= '"' . $prefix . 'Day"';
}
if (null !== $day_size){
$day_result .= ' size="' . $day_size . '"';
}
if (null !== $all_extra){
$day_result .= ' ' . $all_extra;
}
if (null !== $day_extra){
$day_result .= ' ' . $day_extra;
}
$day_result .= $extra_attrs . '>'."\n";
$day_result .= smarty_function_html_options(array('output' => $days,
'values' => $day_values,
'selected' => $time[2],
'print_result' => false),
$smarty);
$day_result .= '</select>';
}
if ($display_years) {
if (null !== $field_array){
$year_name = $field_array . '[' . $prefix . 'Year]';
} else {
$year_name = $prefix . 'Year';
}
if ($year_as_text) {
$year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"';
if (null !== $all_extra){
$year_result .= ' ' . $all_extra;
}
if (null !== $year_extra){
$year_result .= ' ' . $year_extra;
}
$year_result .= ' />';
} else {
$years = range((int)$start_year, (int)$end_year);
if ($reverse_years) {
rsort($years, SORT_NUMERIC);
} else {
sort($years, SORT_NUMERIC);
}
$yearvals = $years;
if(isset($year_empty)) {
array_unshift($years, $year_empty);
array_unshift($yearvals, '');
}
$year_result .= '<select name="' . $year_name . '"';
if (null !== $year_size){
$year_result .= ' size="' . $year_size . '"';
}
if (null !== $all_extra){
$year_result .= ' ' . $all_extra;
}
if (null !== $year_extra){
$year_result .= ' ' . $year_extra;
}
$year_result .= $extra_attrs . '>'."\n";
$year_result .= smarty_function_html_options(array('output' => $years,
'values' => $yearvals,
'selected' => $time[0],
'print_result' => false),
$smarty);
$year_result .= '</select>';
}
}
// Loop thru the field_order field
for ($i = 0; $i <= 2; $i++){
$c = substr($field_order, $i, 1);
switch ($c){
case 'D':
$html_result .= $day_result;
break;
case 'M':
$html_result .= $month_result;
break;
case 'Y':
$html_result .= $year_result;
break;
}
// Add the field seperator
if($i != 2) {
$html_result .= $field_separator;
}
}
return $html_result;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,194 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_select_time} function plugin
*
* Type: function<br>
* Name: html_select_time<br>
* Purpose: Prints the dropdowns for time selection
* @link http://smarty.php.net/manual/en/language.function.html.select.time.php {html_select_time}
* (Smarty online manual)
* @author Roberto Berto <roberto@berto.net>
* @credits Monte Ohrt <monte AT ohrt DOT com>
* @param array
* @param Smarty
* @return string
* @uses smarty_make_timestamp()
*/
function smarty_function_html_select_time($params, &$smarty)
{
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
require_once $smarty->_get_plugin_filepath('function','html_options');
/* Default values. */
$prefix = "Time_";
$time = time();
$display_hours = true;
$display_minutes = true;
$display_seconds = true;
$display_meridian = true;
$use_24_hours = true;
$minute_interval = 1;
$second_interval = 1;
/* Should the select boxes be part of an array when returned from PHP?
e.g. setting it to "birthday", would create "birthday[Hour]",
"birthday[Minute]", "birthday[Seconds]" & "birthday[Meridian]".
Can be combined with prefix. */
$field_array = null;
$all_extra = null;
$hour_extra = null;
$minute_extra = null;
$second_extra = null;
$meridian_extra = null;
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'prefix':
case 'time':
case 'field_array':
case 'all_extra':
case 'hour_extra':
case 'minute_extra':
case 'second_extra':
case 'meridian_extra':
$$_key = (string)$_value;
break;
case 'display_hours':
case 'display_minutes':
case 'display_seconds':
case 'display_meridian':
case 'use_24_hours':
$$_key = (bool)$_value;
break;
case 'minute_interval':
case 'second_interval':
$$_key = (int)$_value;
break;
default:
$smarty->trigger_error("[html_select_time] unknown parameter $_key", E_USER_WARNING);
}
}
$time = smarty_make_timestamp($time);
$html_result = '';
if ($display_hours) {
$hours = $use_24_hours ? range(0, 23) : range(1, 12);
$hour_fmt = $use_24_hours ? '%H' : '%I';
for ($i = 0, $for_max = count($hours); $i < $for_max; $i++)
$hours[$i] = sprintf('%02d', $hours[$i]);
$html_result .= '<select name=';
if (null !== $field_array) {
$html_result .= '"' . $field_array . '[' . $prefix . 'Hour]"';
} else {
$html_result .= '"' . $prefix . 'Hour"';
}
if (null !== $hour_extra){
$html_result .= ' ' . $hour_extra;
}
if (null !== $all_extra){
$html_result .= ' ' . $all_extra;
}
$html_result .= '>'."\n";
$html_result .= smarty_function_html_options(array('output' => $hours,
'values' => $hours,
'selected' => strftime($hour_fmt, $time),
'print_result' => false),
$smarty);
$html_result .= "</select>\n";
}
if ($display_minutes) {
$all_minutes = range(0, 59);
for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval)
$minutes[] = sprintf('%02d', $all_minutes[$i]);
$selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval);
$html_result .= '<select name=';
if (null !== $field_array) {
$html_result .= '"' . $field_array . '[' . $prefix . 'Minute]"';
} else {
$html_result .= '"' . $prefix . 'Minute"';
}
if (null !== $minute_extra){
$html_result .= ' ' . $minute_extra;
}
if (null !== $all_extra){
$html_result .= ' ' . $all_extra;
}
$html_result .= '>'."\n";
$html_result .= smarty_function_html_options(array('output' => $minutes,
'values' => $minutes,
'selected' => $selected,
'print_result' => false),
$smarty);
$html_result .= "</select>\n";
}
if ($display_seconds) {
$all_seconds = range(0, 59);
for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval)
$seconds[] = sprintf('%02d', $all_seconds[$i]);
$selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval);
$html_result .= '<select name=';
if (null !== $field_array) {
$html_result .= '"' . $field_array . '[' . $prefix . 'Second]"';
} else {
$html_result .= '"' . $prefix . 'Second"';
}
if (null !== $second_extra){
$html_result .= ' ' . $second_extra;
}
if (null !== $all_extra){
$html_result .= ' ' . $all_extra;
}
$html_result .= '>'."\n";
$html_result .= smarty_function_html_options(array('output' => $seconds,
'values' => $seconds,
'selected' => $selected,
'print_result' => false),
$smarty);
$html_result .= "</select>\n";
}
if ($display_meridian && !$use_24_hours) {
$html_result .= '<select name=';
if (null !== $field_array) {
$html_result .= '"' . $field_array . '[' . $prefix . 'Meridian]"';
} else {
$html_result .= '"' . $prefix . 'Meridian"';
}
if (null !== $meridian_extra){
$html_result .= ' ' . $meridian_extra;
}
if (null !== $all_extra){
$html_result .= ' ' . $all_extra;
}
$html_result .= '>'."\n";
$html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'),
'values' => array('am', 'pm'),
'selected' => strtolower(strftime('%p', $time)),
'print_result' => false),
$smarty);
$html_result .= "</select>\n";
}
return $html_result;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,137 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {html_table} function plugin
*
* Type: function<br>
* Name: html_table<br>
* Date: Feb 17, 2003<br>
* Purpose: make an html table from an array of data<br>
* Input:<br>
* - loop = array to loop through
* - cols = number of columns
* - rows = number of rows
* - table_attr = table attributes
* - tr_attr = table row attributes (arrays are cycled)
* - td_attr = table cell attributes (arrays are cycled)
* - trailpad = value to pad trailing cells with
* - vdir = vertical direction (default: "down", means top-to-bottom)
* - hdir = horizontal direction (default: "right", means left-to-right)
* - inner = inner loop (default "cols": print $loop line by line,
* $loop will be printed column by column otherwise)
*
*
* Examples:
* <pre>
* {table loop=$data}
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
* {table loop=$data cols=4 tr_attr=$colors}
* </pre>
* @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
* (Smarty online manual)
* @param array
* @param Smarty
* @return string
*/
function smarty_function_html_table($params, &$smarty)
{
$table_attr = 'border="1"';
$tr_attr = '';
$td_attr = '';
$cols = 3;
$rows = 3;
$trailpad = '&nbsp;';
$vdir = 'down';
$hdir = 'right';
$inner = 'cols';
if (!isset($params['loop'])) {
$smarty->trigger_error("html_table: missing 'loop' parameter");
return;
}
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'loop':
$$_key = (array)$_value;
break;
case 'cols':
case 'rows':
$$_key = (int)$_value;
break;
case 'table_attr':
case 'trailpad':
case 'hdir':
case 'vdir':
case 'inner':
$$_key = (string)$_value;
break;
case 'tr_attr':
case 'td_attr':
$$_key = $_value;
break;
}
}
$loop_count = count($loop);
if (empty($params['rows'])) {
/* no rows specified */
$rows = ceil($loop_count/$cols);
} elseif (empty($params['cols'])) {
if (!empty($params['rows'])) {
/* no cols specified, but rows */
$cols = ceil($loop_count/$rows);
}
}
$output = "<table $table_attr>\n";
for ($r=0; $r<$rows; $r++) {
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
$rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
for ($c=0; $c<$cols; $c++) {
$x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;
if ($inner!='cols') {
/* shuffle x to loop over rows*/
$x = floor($x/$cols) + ($x%$cols)*$rows;
}
if ($x<$loop_count) {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
} else {
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
}
}
$output .= "</tr>\n";
}
$output .= "</table>\n";
return $output;
}
function smarty_function_html_table_cycle($name, $var, $no) {
if(!is_array($var)) {
$ret = $var;
} else {
$ret = $var[$no % count($var)];
}
return ($ret) ? ' '.$ret : '';
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,39 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.html_textarea.php
* Type: function
* Name: html_textarea
* Version: 1.0
* -------------------------------------------------------------
*/
function smarty_function_html_textarea($params, &$smarty)
{
$action = '';
$cols = '50';
$rows = '4';
foreach($params as $_key => $_val) $$_key = $_val;
if(empty($id)) $id = $name;
if($limit) $onKeyPress = " onKeyPress=\"textarea_check_len('{$id}','{$limit}')\"";
$html = "<textarea id=\"{$id}\" name=\"{$name}\" cols=\"{$cols}\" rows=\"{$rows}\"{$onKeyPress}>{$default}</textarea>";
if($onKeyPress)
{
$html .= "<div>Remaining Characters: <span id=\"{$id}_remain\">{$limit}</span></div> ".
"<script language=\"javascript\">function textarea_check_len(element,limit) { ".
"var len = document.getElementById(element).value.length; ".
"var remain = limit; ".
"if(limit >= len) remain = limit - (len + 1) ; ".
"else remain = 0; ".
"$(element+'_remain').innerHTML = remain; ".
"} textarea_check_len('{$id}','{$limit}'); </script>";
}
return $html;
}
?>

View File

@@ -0,0 +1,21 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.input_text.php
* Type: function
* Name: input_text
* Purpose: display a text form with the proper css & onchange settings
* -------------------------------------------------------------
*/
function smarty_function_input_text($params, &$this)
{
extract($params);
$c_class = $class ? $class : 'form_field';
$s_size = $size ? $size : '12';
$s_id = $id ? $id : $name;
echo "<input type=\"text\" name=\"{$name}\" id=\"{$id}\" class=\"{$c_class}\" value=\"{$value}\" size=\"{$s_size}\" onFocus=\"class_change(this.id,'form_field_focus')\" onBlur=\"class_change(this.id,'form_field')\">";
}
?>

View File

@@ -0,0 +1,163 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {mailto} function plugin
*
* Type: function<br>
* Name: mailto<br>
* Date: May 21, 2002
* Purpose: automate mailto address link creation, and optionally
* encode them.<br>
* Input:<br>
* - address = e-mail address
* - text = (optional) text to display, default is address
* - encode = (optional) can be one of:
* * none : no encoding (default)
* * javascript : encode with javascript
* * javascript_charcode : encode with javascript charcode
* * hex : encode with hexidecimal (no javascript)
* - cc = (optional) address(es) to carbon copy
* - bcc = (optional) address(es) to blind carbon copy
* - subject = (optional) e-mail subject
* - newsgroups = (optional) newsgroup(s) to post to
* - followupto = (optional) address(es) to follow up to
* - extra = (optional) extra tags for the href link
*
* Examples:
* <pre>
* {mailto address="me@domain.com"}
* {mailto address="me@domain.com" encode="javascript"}
* {mailto address="me@domain.com" encode="hex"}
* {mailto address="me@domain.com" subject="Hello to you!"}
* {mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
* {mailto address="me@domain.com" extra='class="mailto"'}
* </pre>
* @link http://smarty.php.net/manual/en/language.function.mailto.php {mailto}
* (Smarty online manual)
* @version 1.2
* @author Monte Ohrt <monte at ohrt dot com>
* @author credits to Jason Sweat (added cc, bcc and subject functionality)
* @param array
* @param Smarty
* @return string
*/
function smarty_function_mailto($params, &$smarty)
{
$extra = '';
if (empty($params['address'])) {
$smarty->trigger_error("mailto: missing 'address' parameter");
return;
} else {
$address = $params['address'];
}
$text = $address;
// netscape and mozilla do not decode %40 (@) in BCC field (bug?)
// so, don't encode it.
$mail_parms = array();
foreach ($params as $var=>$value) {
switch ($var) {
case 'cc':
case 'bcc':
case 'followupto':
if (!empty($value))
$mail_parms[] = $var.'='.str_replace('%40','@',rawurlencode($value));
break;
case 'subject':
case 'newsgroups':
$mail_parms[] = $var.'='.rawurlencode($value);
break;
case 'extra':
case 'text':
$$var = $value;
default:
}
}
$mail_parm_vals = '';
for ($i=0; $i<count($mail_parms); $i++) {
$mail_parm_vals .= (0==$i) ? '?' : '&';
$mail_parm_vals .= $mail_parms[$i];
}
$address .= $mail_parm_vals;
$encode = (empty($params['encode'])) ? 'none' : $params['encode'];
if (!in_array($encode,array('javascript','javascript_charcode','hex','none')) ) {
$smarty->trigger_error("mailto: 'encode' parameter must be none, javascript or hex");
return;
}
if ($encode == 'javascript' ) {
$string = 'document.write(\'<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>\');';
$js_encode = '';
for ($x=0; $x < strlen($string); $x++) {
$js_encode .= '%' . bin2hex($string[$x]);
}
return '<script type="text/javascript">eval(unescape(\''.$js_encode.'\'))</script>';
} elseif ($encode == 'javascript_charcode' ) {
$string = '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
for($x = 0, $y = strlen($string); $x < $y; $x++ ) {
$ord[] = ord($string[$x]);
}
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n";
$_ret .= "<!--\n";
$_ret .= "{document.write(String.fromCharCode(";
$_ret .= implode(',',$ord);
$_ret .= "))";
$_ret .= "}\n";
$_ret .= "//-->\n";
$_ret .= "</script>\n";
return $_ret;
} elseif ($encode == 'hex') {
preg_match('!^(.*)(\?.*)$!',$address,$match);
if(!empty($match[2])) {
$smarty->trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.");
return;
}
$address_encode = '';
for ($x=0; $x < strlen($address); $x++) {
if(preg_match('!\w!',$address[$x])) {
$address_encode .= '%' . bin2hex($address[$x]);
} else {
$address_encode .= $address[$x];
}
}
$text_encode = '';
for ($x=0; $x < strlen($text); $x++) {
$text_encode .= '&#x' . bin2hex($text[$x]).';';
}
$mailto = "&#109;&#97;&#105;&#108;&#116;&#111;&#58;";
return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text_encode.'</a>';
} else {
// no encoding
return '<a href="mailto:'.$address.'" '.$extra.'>'.$text.'</a>';
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,84 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {math} function plugin
*
* Type: function<br>
* Name: math<br>
* Purpose: handle math computations in template<br>
* @link http://smarty.php.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_math($params, &$smarty)
{
// be sure equation parameter is present
if (empty($params['equation'])) {
$smarty->trigger_error("math: missing equation parameter");
return;
}
$equation = $params['equation'];
// make sure parenthesis are balanced
if (substr_count($equation,"(") != substr_count($equation,")")) {
$smarty->trigger_error("math: unbalanced parenthesis");
return;
}
// match all vars in equation, make sure all are passed
preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]+)!",$equation, $match);
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
foreach($match[1] as $curr_var) {
if ($curr_var && !in_array($curr_var, array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
$smarty->trigger_error("math: function call $curr_var not allowed");
return;
}
}
foreach($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val)==0) {
$smarty->trigger_error("math: parameter $key is empty");
return;
}
if (!is_numeric($val)) {
$smarty->trigger_error("math: parameter $key: is not numeric");
return;
}
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}
eval("\$smarty_math_result = ".$equation.";");
if (empty($params['format'])) {
if (empty($params['assign'])) {
return $smarty_math_result;
} else {
$smarty->assign($params['assign'],$smarty_math_result);
}
} else {
if (empty($params['assign'])){
printf($params['format'],$smarty_math_result);
} else {
$smarty->assign($params['assign'],sprintf($params['format'],$smarty_math_result));
}
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,70 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: plugin
* Purpose: Displays & Populates an AB plugin template
* -------------------------------------------------------------
*/
function smarty_function_plugin($params, &$smarty)
{
$conditions='';
extract($params);
if(empty($type)) return;
if(empty($name)) return;
if(empty($name_prefix)) $name_prefix='';
if(!empty($data)) $smarty->assign('plugin', unserialize($data));
// pass any other vars to smarty
foreach($params as $var=>$val) $smarty->assign($var,$val);
// get full template file-path:
switch($type) {
case 'affiliate':
$_tpl = "affiliate:plugin_{$name_prefix}{$name}";
break;
case 'checkout':
$_tpl = "checkout_plugin:plugin_{$name_prefix}{$name}";
break;
case 'db_mapping':
$_tpl = "db_mapping:group_map_{$name_prefix}{$name}";
break;
case 'import':
$_tpl = ""; // todo
break;
case 'product':
$_tpl = "product_plugin:plugin_{$name_prefix}{$name}";
break;
case 'provision':
$_tpl = "host_provision_plugin:plugin_{$name_prefix}{$name}";
break;
case 'registrar':
$_tpl = "host_registrar_plugin:plugin_{$name_prefix}{$name}";
break;
case 'whois':
$_tpl = "host_whois_plugin:plugin_{$name_prefix}{$name}";
break;
case 'voip_did':
$_tpl = "voip_did_plugin:config_{$name_prefix}{$name}";
break;
}
// check if file exists:
$_template_full = PATH_THEMES.DEF_THEME_N."/blocks/". ereg_replace(":", "/", $_tpl).".tpl";
if(!is_file($_template_full)) {
$_template_full = PATH_THEMES."default/blocks/". ereg_replace(":", "/", $_tpl).".tpl";
if(!is_file($_template_full)) {
if($debug) echo "Error loading plugin template: $_template_full";
return;
}
}
// load file
$smarty->display("file:$_template_full");
}
?>

View File

@@ -0,0 +1,119 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {popup} function plugin
*
* Type: function<br>
* Name: popup<br>
* Purpose: make text pop up in windows via overlib
* @link http://smarty.php.net/manual/en/language.function.popup.php {popup}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_popup($params, &$smarty)
{
$append = '';
foreach ($params as $_key=>$_value) {
switch ($_key) {
case 'text':
case 'trigger':
case 'function':
case 'inarray':
$$_key = (string)$_value;
if ($_key == 'function' || $_key == 'inarray')
$append .= ',' . strtoupper($_key) . ",'$_value'";
break;
case 'caption':
case 'closetext':
case 'status':
$append .= ',' . strtoupper($_key) . ",'" . str_replace("'","\'",$_value) . "'";
break;
case 'fgcolor':
case 'bgcolor':
case 'textcolor':
case 'capcolor':
case 'closecolor':
case 'textfont':
case 'captionfont':
case 'closefont':
case 'fgbackground':
case 'bgbackground':
case 'caparray':
case 'capicon':
case 'background':
case 'frame':
$append .= ',' . strtoupper($_key) . ",'$_value'";
break;
case 'textsize':
case 'captionsize':
case 'closesize':
case 'width':
case 'height':
case 'border':
case 'offsetx':
case 'offsety':
case 'snapx':
case 'snapy':
case 'fixx':
case 'fixy':
case 'padx':
case 'pady':
case 'timeout':
case 'delay':
$append .= ',' . strtoupper($_key) . ",$_value";
break;
case 'sticky':
case 'left':
case 'right':
case 'center':
case 'above':
case 'below':
case 'noclose':
case 'autostatus':
case 'autostatuscap':
case 'fullhtml':
case 'hauto':
case 'vauto':
case 'mouseoff':
case 'followmouse':
case 'closeclick':
if ($_value) $append .= ',' . strtoupper($_key);
break;
default:
$smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
}
}
if (empty($text) && !isset($inarray) && empty($function)) {
$smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
return false;
}
if (empty($trigger)) { $trigger = "onmouseover"; }
$retval = $trigger . '="return overlib(\''.preg_replace(array("!'!","![\r\n]!"),array("\'",'\r'),$text).'\'';
$retval .= $append . ');"';
if ($trigger == 'onmouseover')
$retval .= ' onmouseout="nd();"';
return $retval;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,40 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {popup_init} function plugin
*
* Type: function<br>
* Name: popup_init<br>
* Purpose: initialize overlib
* @link http://smarty.php.net/manual/en/language.function.popup.init.php {popup_init}
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array
* @param Smarty
* @return string
*/
function smarty_function_popup_init($params, &$smarty)
{
$zindex = 1000;
if (!empty($params['zindex'])) {
$zindex = $params['zindex'];
}
if (!empty($params['src'])) {
return '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:'.$zindex.';"></div>' . "\n"
. '<script type="text/javascript" language="JavaScript" src="'.$params['src'].'"></script>' . "\n";
} else {
$smarty->trigger_error("popup_init: missing src parameter");
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,17 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.style_hide.php
* Type: function
* Name: style_hide
* Version: 1.0
* Purpose: Hides a div/span element without disabling the view in dreamweaver
* -------------------------------------------------------------
*/
function smarty_function_style_hide($params, &$smarty)
{
return 'style="display:none"';
}
?>

View File

@@ -0,0 +1,29 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: voip_did
* Purpose: get the DID associated with a service id
* -------------------------------------------------------------
*/
function smarty_function_voip_did($params, &$smarty)
{
extract($params);
if (empty($service_id)) {
$smarty->trigger_error("voip_did: attribute 'service_id' required");
return false;
}
$db =& DB();
$rs = $db->Execute(sqlSelect($db, "service", "prod_attr_cart", "id=::".$service_id."::"));
$prod_attr_cart = unserialize($rs->fields['prod_attr_cart']);
if (!empty($prod_attr_cart['station']))
return $prod_attr_cart['station'];
if (!empty($prod_attr_cart['ported']))
return $prod_attr_cart['ported'];
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: voip_did_id
* Purpose: get the voip_did_id associated with a service id
* -------------------------------------------------------------
*/
function smarty_function_voip_did_id($params, &$smarty)
{
extract($params);
if (empty($service_id)) {
$smarty->trigger_error("voip_did_id: attribute 'service_id' required");
return false;
}
$db =& DB();
$rs = $db->Execute(sqlSelect($db, "service", "prod_attr_cart", "id=::".$service_id."::"));
$prod_attr_cart = unserialize($rs->fields['prod_attr_cart']);
$did = "";
if (!empty($prod_attr_cart['station']))
$did = $prod_attr_cart['station'];
if (!empty($prod_attr_cart['ported']))
$did = $prod_attr_cart['ported'];
if(substr($did,0,1) == "1") {
$did = "(did=::".$did.":: OR did=::".substr($did,1)."::)";
} else {
$did = "did=::".$did."::";
}
$rs = $db->Execute($sql=sqlSelect($db, "voip_did", "id", $did));
return $rs->fields[0];
}
?>

View File

@@ -0,0 +1,10 @@
<?php
function smarty_modifier_bool($string, $format="", $default_date=null)
{
if($string)
echo translate("true");
else
echo translate("false");
}
?>

View File

@@ -0,0 +1,43 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty capitalize modifier plugin
*
* Type: modifier<br>
* Name: capitalize<br>
* Purpose: capitalize words in the string
* @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE
* capitalize (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_modifier_capitalize($string, $uc_digits = false)
{
smarty_modifier_capitalize_ucfirst(null, $uc_digits);
return preg_replace_callback('!\b\w+\b!', 'smarty_modifier_capitalize_ucfirst', $string);
}
function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
{
static $_uc_digits = false;
if(isset($uc_digits)) {
$_uc_digits = $uc_digits;
return;
}
if(!preg_match('!\d!',$string[0]) || $_uc_digits)
return ucfirst($string[0]);
else
return $string[0];
}
?>

View File

@@ -0,0 +1,33 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty cat modifier plugin
*
* Type: modifier<br>
* Name: cat<br>
* Date: Feb 24, 2003
* Purpose: catenate a value to a variable
* Input: string to catenate
* Example: {$var|cat:"foo"}
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @param string
* @param string
* @return string
*/
function smarty_modifier_cat($string, $cat)
{
return $string . $cat;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,32 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty count_characters modifier plugin
*
* Type: modifier<br>
* Name: count_characteres<br>
* Purpose: count the number of characters in a text
* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php
* count_characters (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param boolean include whitespace in the character count
* @return integer
*/
function smarty_modifier_count_characters($string, $include_spaces = false)
{
if ($include_spaces)
return(strlen($string));
return preg_match_all("/[^\s]/",$string, $match);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty count_paragraphs modifier plugin
*
* Type: modifier<br>
* Name: count_paragraphs<br>
* Purpose: count the number of paragraphs in a text
* @link http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return integer
*/
function smarty_modifier_count_paragraphs($string)
{
// count \r or \n characters
return count(preg_split('/[\r\n]+/', $string));
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty count_sentences modifier plugin
*
* Type: modifier<br>
* Name: count_sentences
* Purpose: count the number of sentences in a text
* @link http://smarty.php.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return integer
*/
function smarty_modifier_count_sentences($string)
{
// find periods with a word before but not after.
return preg_match_all('/[^\s]\.(?!\w)/', $string, $match);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,33 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty count_words modifier plugin
*
* Type: modifier<br>
* Name: count_words<br>
* Purpose: count the number of words in a text
* @link http://smarty.php.net/manual/en/language.modifier.count.words.php
* count_words (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return integer
*/
function smarty_modifier_count_words($string)
{
// split text by ' ',\r,\n,\f,\t
$split_array = preg_split('/\s+/',$string);
// count matches that contain alphanumerics
$word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);
return count($word_count);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,7 @@
<?php
function smarty_modifier_date($string, $format="%b %e, %Y", $default_date=null)
{
echo timestampToDate($string);
}
?>

View File

@@ -0,0 +1,49 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Include the {@link shared.make_timestamp.php} plugin
*/
require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
/**
* Smarty date_format modifier plugin
*
* Type: modifier<br>
* Name: date_format<br>
* Purpose: format datestamps via strftime<br>
* Input:<br>
* - string: input date string
* - format: strftime format for output
* - default_date: default date if $string is empty
* @link http://smarty.php.net/manual/en/language.modifier.date.format.php
* date_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string
* @param string
* @return string|void
* @uses smarty_make_timestamp()
*/
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
{
if (substr(PHP_OS,0,3) == 'WIN') {
$_win_from = array ('%e', '%T', '%D');
$_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y');
$format = str_replace($_win_from, $_win_to, $format);
}
if($string != '') {
return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date));
} else {
return;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,57 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty debug_print_var modifier plugin
*
* Type: modifier<br>
* Name: debug_print_var<br>
* Purpose: formats variable contents for display in the console
* @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
* debug_print_var (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param array|object
* @param integer
* @param integer
* @return string
*/
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
$_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>');
if (is_array($var)) {
$results = "<b>Array (".count($var).")</b>";
foreach ($var as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> =&gt; $return";
}
} else if (is_object($var)) {
$object_vars = get_object_vars($var);
$results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
foreach ($object_vars as $curr_key => $curr_val) {
$return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
$results .= "<br>".str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
}
} else if (is_resource($var)) {
$results = '<i>'.(string)$var.'</i>';
} else if (empty($var) && $var != "0") {
$results = '<i>empty</i>';
} else {
if (strlen($var) > $length ) {
$results = substr($var, 0, $length-3).'...';
} else {
$results = $var;
}
$results = htmlspecialchars($results);
$results = strtr($results, $_replace);
}
return $results;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,32 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty default modifier plugin
*
* Type: modifier<br>
* Name: default<br>
* Purpose: designate default value for empty variables
* @link http://smarty.php.net/manual/en/language.modifier.default.php
* default (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string
* @return string
*/
function smarty_modifier_default($string, $default = '')
{
if (!isset($string) || $string === '')
return $default;
else
return $string;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,93 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty escape modifier plugin
*
* Type: modifier<br>
* Name: escape<br>
* Purpose: Escape the string according to escapement type
* @link http://smarty.php.net/manual/en/language.modifier.escape.php
* escape (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param html|htmlall|url|quotes|hex|hexentity|javascript
* @return string
*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1')
{
switch ($esc_type) {
case 'html':
return htmlspecialchars($string, ENT_QUOTES, $char_set);
case 'htmlall':
return htmlentities($string, ENT_QUOTES, $char_set);
case 'url':
return rawurlencode($string);
case 'urlpathinfo':
return str_replace('%2F','/',rawurlencode($string));
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex':
// escape every character into hex
$return = '';
for ($x=0; $x < strlen($string); $x++) {
$return .= '%' . bin2hex($string[$x]);
}
return $return;
case 'hexentity':
$return = '';
for ($x=0; $x < strlen($string); $x++) {
$return .= '&#x' . bin2hex($string[$x]) . ';';
}
return $return;
case 'decentity':
$return = '';
for ($x=0; $x < strlen($string); $x++) {
$return .= '&#' . ord($string[$x]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
case 'mail':
// safe way to display e-mail address on a web page
return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$_res = '';
for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if($_ord >= 126){
$_res .= '&#' . $_ord . ';';
}
else {
$_res .= substr($string, $_i, 1);
}
}
return $_res;
default:
return $string;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,28 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty indent modifier plugin
*
* Type: modifier<br>
* Name: indent<br>
* Purpose: indent lines of text
* @link http://smarty.php.net/manual/en/language.modifier.indent.php
* indent (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param integer
* @param string
* @return string
*/
function smarty_modifier_indent($string,$chars=4,$char=" ")
{
return preg_replace('!^!m',str_repeat($char,$chars),$string);
}
?>

View File

@@ -0,0 +1,28 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: linkalize
* Version: 1.0
* Purpose: parse a string and turn text links into clickable links...
* Input: string to catenate
* Example: {$var|linkalize}
* Notes: make sure there is an http:// on all URLs
* -------------------------------------------------------------
*/
function smarty_modifier_linkalize($string)
{
return linkalize($string);
}
function linkalize($text)
{
$text = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $text);
$text = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "<A TARGET=\"_blank\" HREF=\"$1\">$1</A>", $text); //make all URLs links
$text = preg_replace("/[\w-\.]+@(\w+[\w-]+\.){0,3}\w+[\w-]+\.[a-zA-Z]{2,4}\b/i","<ahref=\"mailto:$0\">$0</a>",$text);
return $text;
}
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty lower modifier plugin
*
* Type: modifier<br>
* Name: lower<br>
* Purpose: convert string to lowercase
* @link http://smarty.php.net/manual/en/language.modifier.lower.php
* lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_modifier_lower($string)
{
return strtolower($string);
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty plugin
*
* Type: modifier<br>
* Name: nl2br<br>
* Date: Feb 26, 2003
* Purpose: convert \r\n, \r or \n to <<br>>
* Input:<br>
* - contents = contents to replace
* - preceed_test = if true, includes preceeding break tags
* in replacement
* Example: {$text|nl2br}
* @link http://smarty.php.net/manual/en/language.modifier.nl2br.php
* nl2br (Smarty online manual)
* @version 1.0
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_modifier_nl2br($string)
{
return nl2br($string);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,34 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty regex_replace modifier plugin
*
* Type: modifier<br>
* Name: regex_replace<br>
* Purpose: regular epxression search/replace
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string|array
* @param string|array
* @return string
*/
function smarty_modifier_regex_replace($string, $search, $replace)
{
if (preg_match('!\W(\w+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
/* remove eval-modifier from $search */
$search = substr($search, 0, -strlen($match[1])) . str_replace('e', '', $match[1]);
}
return preg_replace($search, $replace, $string);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,30 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty replace modifier plugin
*
* Type: modifier<br>
* Name: replace<br>
* Purpose: simple search/replace
* @link http://smarty.php.net/manual/en/language.modifier.replace.php
* replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string
* @param string
* @return string
*/
function smarty_modifier_replace($string, $search, $replace)
{
return str_replace($search, $replace, $string);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,854 @@
<?php
#
# SmartyPants - Smart punctuation for web sites
#
# by John Gruber
# <http://daringfireball.net>
#
# PHP port by Michel Fortin
# <http://www.michelf.com/>
#
# Copyright (c) 2003-2004 John Gruber
# Copyright (c) 2004-2005 Michel Fortin
#
global $SmartyPantsPHPVersion, $SmartyPantsSyntaxVersion,
$smartypants_attr, $sp_tags_to_skip;
$SmartyPantsPHPVersion = '1.5.1d'; # Mon 6 Jun 2005
$SmartyPantsSyntaxVersion = '1.5.1'; # Fri 12 Mar 2004
# Configurable variables:
$smartypants_attr = "1"; # Change this to configure.
# 1 => "--" for em-dashes; no en-dash support
# 2 => "---" for em-dashes; "--" for en-dashes
# 3 => "--" for em-dashes; "---" for en-dashes
# See docs for more configuration options.
# Globals:
$sp_tags_to_skip = '<(/?)(?:pre|code|kbd|script|math)[\s>]';
# -- WordPress plugin interface -----------------------------------------------
/*
Plugin Name: SmartyPants
Plugin URI: http://www.michelf.com/projects/php-smartypants/
Description: SmartyPants is a web publishing utility that translates plain ASCII punctuation characters into &#8220;smart&#8221; typographic punctuation HTML entities. This plugin <strong>replace the default WordPress Texturize algorithm</strong> for the content and the title of your posts, the comments body and author name, and everywhere else Texturize normally apply. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>.
Version: 1.5.1c
Author: Michel Fortin
Author URI: http://www.michelf.com/
*/
if (isset($wp_version)) {
# Remove default Texturize filter that would conflict with SmartyPants.
remove_filter('category_description', 'wptexturize');
remove_filter('list_cats', 'wptexturize');
remove_filter('comment_author', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
remove_filter('single_post_title', 'wptexturize');
remove_filter('the_title', 'wptexturize');
remove_filter('the_content', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
# Add SmartyPants filter with priority 10 (same as Texturize).
add_filter('category_description', 'SmartyPants', 10);
add_filter('list_cats', 'SmartyPants', 10);
add_filter('comment_author', 'SmartyPants', 10);
add_filter('comment_text', 'SmartyPants', 10);
add_filter('single_post_title', 'SmartyPants', 10);
add_filter('the_title', 'SmartyPants', 10);
add_filter('the_content', 'SmartyPants', 10);
add_filter('the_excerpt', 'SmartyPants', 10);
}
# -- Smarty Modifier Interface ------------------------------------------------
function smarty_modifier_smartypants($text, $attr = NULL) {
return SmartyPants($text, $attr);
}
function SmartyPants($text, $attr = NULL, $ctx = NULL) {
global $smartypants_attr, $sp_tags_to_skip;
# Paramaters:
$text; # text to be parsed
$attr; # value of the smart_quotes="" attribute
$ctx; # MT context object (unused)
if ($attr == NULL) $attr = $smartypants_attr;
# Options to specify which transformations to make:
$do_stupefy = FALSE;
$convert_quot = 0; # should we translate &quot; entities into normal quotes?
# Parse attributes:
# 0 : do nothing
# 1 : set all
# 2 : set all, using old school en- and em- dash shortcuts
# 3 : set all, using inverted old school en and em- dash shortcuts
#
# q : quotes
# b : backtick quotes (``double'' only)
# B : backtick quotes (``double'' and `single')
# d : dashes
# D : old school dashes
# i : inverted old school dashes
# e : ellipses
# w : convert &quot; entities to " for Dreamweaver users
if ($attr == "0") {
# Do nothing.
return $text;
}
else if ($attr == "1") {
# Do everything, turn all options on.
$do_quotes = 1;
$do_backticks = 1;
$do_dashes = 1;
$do_ellipses = 1;
}
else if ($attr == "2") {
# Do everything, turn all options on, use old school dash shorthand.
$do_quotes = 1;
$do_backticks = 1;
$do_dashes = 2;
$do_ellipses = 1;
}
else if ($attr == "3") {
# Do everything, turn all options on, use inverted old school dash shorthand.
$do_quotes = 1;
$do_backticks = 1;
$do_dashes = 3;
$do_ellipses = 1;
}
else if ($attr == "-1") {
# Special "stupefy" mode.
$do_stupefy = 1;
}
else {
$chars = preg_split('//', $attr);
foreach ($chars as $c){
if ($c == "q") { $do_quotes = 1; }
else if ($c == "b") { $do_backticks = 1; }
else if ($c == "B") { $do_backticks = 2; }
else if ($c == "d") { $do_dashes = 1; }
else if ($c == "D") { $do_dashes = 2; }
else if ($c == "i") { $do_dashes = 3; }
else if ($c == "e") { $do_ellipses = 1; }
else if ($c == "w") { $convert_quot = 1; }
else {
# Unknown attribute option, ignore.
}
}
}
$tokens = _TokenizeHTML($text);
$result = '';
$in_pre = 0; # Keep track of when we're inside <pre> or <code> tags.
$prev_token_last_char = ""; # This is a cheat, used to get some context
# for one-character tokens that consist of
# just a quote char. What we do is remember
# the last character of the previous text
# token, to use as context to curl single-
# character quote tokens correctly.
foreach ($tokens as $cur_token) {
if ($cur_token[0] == "tag") {
# Don't mess with quotes inside tags.
$result .= $cur_token[1];
if (preg_match("@$sp_tags_to_skip@", $cur_token[1], $matches)) {
$in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
}
} else {
$t = $cur_token[1];
$last_char = substr($t, -1); # Remember last char of this token before processing.
if (! $in_pre) {
$t = ProcessEscapes($t);
if ($convert_quot) {
$t = preg_replace('/&quot;/', '"', $t);
}
if ($do_dashes) {
if ($do_dashes == 1) $t = EducateDashes($t);
if ($do_dashes == 2) $t = EducateDashesOldSchool($t);
if ($do_dashes == 3) $t = EducateDashesOldSchoolInverted($t);
}
if ($do_ellipses) $t = EducateEllipses($t);
# Note: backticks need to be processed before quotes.
if ($do_backticks) {
$t = EducateBackticks($t);
if ($do_backticks == 2) $t = EducateSingleBackticks($t);
}
if ($do_quotes) {
if ($t == "'") {
# Special case: single-character ' token
if (preg_match('/\S/', $prev_token_last_char)) {
$t = "&#8217;";
}
else {
$t = "&#8216;";
}
}
else if ($t == '"') {
# Special case: single-character " token
if (preg_match('/\S/', $prev_token_last_char)) {
$t = "&#8221;";
}
else {
$t = "&#8220;";
}
}
else {
# Normal case:
$t = EducateQuotes($t);
}
}
if ($do_stupefy) $t = StupefyEntities($t);
}
$prev_token_last_char = $last_char;
$result .= $t;
}
}
return $result;
}
function SmartQuotes($text, $attr = NULL, $ctx = NULL) {
global $smartypants_attr, $sp_tags_to_skip;
# Paramaters:
$text; # text to be parsed
$attr; # value of the smart_quotes="" attribute
$ctx; # MT context object (unused)
if ($attr == NULL) $attr = $smartypants_attr;
$do_backticks; # should we educate ``backticks'' -style quotes?
if ($attr == 0) {
# do nothing;
return $text;
}
else if ($attr == 2) {
# smarten ``backticks'' -style quotes
$do_backticks = 1;
}
else {
$do_backticks = 0;
}
# Special case to handle quotes at the very end of $text when preceded by
# an HTML tag. Add a space to give the quote education algorithm a bit of
# context, so that it can guess correctly that it's a closing quote:
$add_extra_space = 0;
if (preg_match("/>['\"]\\z/", $text)) {
$add_extra_space = 1; # Remember, so we can trim the extra space later.
$text .= " ";
}
$tokens = _TokenizeHTML($text);
$result = '';
$in_pre = 0; # Keep track of when we're inside <pre> or <code> tags
$prev_token_last_char = ""; # This is a cheat, used to get some context
# for one-character tokens that consist of
# just a quote char. What we do is remember
# the last character of the previous text
# token, to use as context to curl single-
# character quote tokens correctly.
foreach ($tokens as $cur_token) {
if ($cur_token[0] == "tag") {
# Don't mess with quotes inside tags
$result .= $cur_token[1];
if (preg_match("@$sp_tags_to_skip@", $cur_token[1], $matches)) {
$in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
}
} else {
$t = $cur_token[1];
$last_char = substr($t, -1); # Remember last char of this token before processing.
if (! $in_pre) {
$t = ProcessEscapes($t);
if ($do_backticks) {
$t = EducateBackticks($t);
}
if ($t == "'") {
# Special case: single-character ' token
if (preg_match('/\S/', $prev_token_last_char)) {
$t = "&#8217;";
}
else {
$t = "&#8216;";
}
}
else if ($t == '"') {
# Special case: single-character " token
if (preg_match('/\S/', $prev_token_last_char)) {
$t = "&#8221;";
}
else {
$t = "&#8220;";
}
}
else {
# Normal case:
$t = EducateQuotes($t);
}
}
$prev_token_last_char = $last_char;
$result .= $t;
}
}
if ($add_extra_space) {
preg_replace('/ \z/', '', $result); # Trim trailing space if we added one earlier.
}
return $result;
}
function SmartDashes($text, $attr = NULL, $ctx = NULL) {
global $smartypants_attr, $sp_tags_to_skip;
# Paramaters:
$text; # text to be parsed
$attr; # value of the smart_dashes="" attribute
$ctx; # MT context object (unused)
if ($attr == NULL) $attr = $smartypants_attr;
# reference to the subroutine to use for dash education, default to EducateDashes:
$dash_sub_ref = 'EducateDashes';
if ($attr == 0) {
# do nothing;
return $text;
}
else if ($attr == 2) {
# use old smart dash shortcuts, "--" for en, "---" for em
$dash_sub_ref = 'EducateDashesOldSchool';
}
else if ($attr == 3) {
# inverse of 2, "--" for em, "---" for en
$dash_sub_ref = 'EducateDashesOldSchoolInverted';
}
$tokens;
$tokens = _TokenizeHTML($text);
$result = '';
$in_pre = 0; # Keep track of when we're inside <pre> or <code> tags
foreach ($tokens as $cur_token) {
if ($cur_token[0] == "tag") {
# Don't mess with quotes inside tags
$result .= $cur_token[1];
if (preg_match("@$sp_tags_to_skip@", $cur_token[1], $matches)) {
$in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
}
} else {
$t = $cur_token[1];
if (! $in_pre) {
$t = ProcessEscapes($t);
$t = $dash_sub_ref($t);
}
$result .= $t;
}
}
return $result;
}
function SmartEllipses($text, $attr = NULL, $ctx = NULL) {
# Paramaters:
$text; # text to be parsed
$attr; # value of the smart_ellipses="" attribute
$ctx; # MT context object (unused)
if ($attr == NULL) $attr = $smartypants_attr;
if ($attr == 0) {
# do nothing;
return $text;
}
$tokens;
$tokens = _TokenizeHTML($text);
$result = '';
$in_pre = 0; # Keep track of when we're inside <pre> or <code> tags
foreach ($tokens as $cur_token) {
if ($cur_token[0] == "tag") {
# Don't mess with quotes inside tags
$result .= $cur_token[1];
if (preg_match("@$sp_tags_to_skip@", $cur_token[1], $matches)) {
$in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
}
} else {
$t = $cur_token[1];
if (! $in_pre) {
$t = ProcessEscapes($t);
$t = EducateEllipses($t);
}
$result .= $t;
}
}
return $result;
}
function EducateQuotes($_) {
#
# Parameter: String.
#
# Returns: The string, with "educated" curly quote HTML entities.
#
# Example input: "Isn't this fun?"
# Example output: &#8220;Isn&#8217;t this fun?&#8221;
#
# Make our own "punctuation" character class, because the POSIX-style
# [:PUNCT:] is only available in Perl 5.6 or later:
$punct_class = "[!\"#\\$\\%'()*+,-.\\/:;<=>?\\@\\[\\\\\]\\^_`{|}~]";
# Special case if the very first character is a quote
# followed by punctuation at a non-word-break. Close the quotes by brute force:
$_ = preg_replace(
array("/^'(?=$punct_class\\B)/", "/^\"(?=$punct_class\\B)/"),
array('&#8217;', '&#8221;'), $_);
# Special case for double sets of quotes, e.g.:
# <p>He said, "'Quoted' words in a larger quote."</p>
$_ = preg_replace(
array("/\"'(?=\w)/", "/'\"(?=\w)/"),
array('&#8220;&#8216;', '&#8216;&#8220;'), $_);
# Special case for decade abbreviations (the '80s):
$_ = preg_replace("/'(?=\\d{2}s)/", '&#8217;', $_);
$close_class = '[^\ \t\r\n\[\{\(\-]';
$dec_dashes = '&\#8211;|&\#8212;';
# Get most opening single quotes:
$_ = preg_replace("{
(
\\s | # a whitespace char, or
&nbsp; | # a non-breaking space entity, or
-- | # dashes, or
&[mn]dash; | # named dash entities
$dec_dashes | # or decimal entities
&\\#x201[34]; # or hex
)
' # the quote
(?=\\w) # followed by a word character
}x", '\1&#8216;', $_);
# Single closing quotes:
$_ = preg_replace("{
($close_class)?
'
(?(1)| # If $1 captured, then do nothing;
(?=\\s | s\\b) # otherwise, positive lookahead for a whitespace
) # char or an 's' at a word ending position. This
# is a special case to handle something like:
# \"<i>Custer</i>'s Last Stand.\"
}xi", '\1&#8217;', $_);
# Any remaining single quotes should be opening ones:
$_ = str_replace("'", '&#8216;', $_);
# Get most opening double quotes:
$_ = preg_replace("{
(
\\s | # a whitespace char, or
&nbsp; | # a non-breaking space entity, or
-- | # dashes, or
&[mn]dash; | # named dash entities
$dec_dashes | # or decimal entities
&\\#x201[34]; # or hex
)
\" # the quote
(?=\\w) # followed by a word character
}x", '\1&#8220;', $_);
# Double closing quotes:
$_ = preg_replace("{
($close_class)?
\"
(?(1)|(?=\\s)) # If $1 captured, then do nothing;
# if not, then make sure the next char is whitespace.
}x", '\1&#8221;', $_);
# Any remaining quotes should be opening ones.
$_ = str_replace('"', '&#8220;', $_);
return $_;
}
function EducateBackticks($_) {
#
# Parameter: String.
# Returns: The string, with ``backticks'' -style double quotes
# translated into HTML curly quote entities.
#
# Example input: ``Isn't this fun?''
# Example output: &#8220;Isn't this fun?&#8221;
#
$_ = str_replace(array("``", "''",),
array('&#8220;', '&#8221;'), $_);
return $_;
}
function EducateSingleBackticks($_) {
#
# Parameter: String.
# Returns: The string, with `backticks' -style single quotes
# translated into HTML curly quote entities.
#
# Example input: `Isn't this fun?'
# Example output: &#8216;Isn&#8217;t this fun?&#8217;
#
$_ = str_replace(array("`", "'",),
array('&#8216;', '&#8217;'), $_);
return $_;
}
function EducateDashes($_) {
#
# Parameter: String.
#
# Returns: The string, with each instance of "--" translated to
# an em-dash HTML entity.
#
$_ = str_replace('--', '&#8212;', $_);
return $_;
}
function EducateDashesOldSchool($_) {
#
# Parameter: String.
#
# Returns: The string, with each instance of "--" translated to
# an en-dash HTML entity, and each "---" translated to
# an em-dash HTML entity.
#
# em en
$_ = str_replace(array("---", "--",),
array('&#8212;', '&#8211;'), $_);
return $_;
}
function EducateDashesOldSchoolInverted($_) {
#
# Parameter: String.
#
# Returns: The string, with each instance of "--" translated to
# an em-dash HTML entity, and each "---" translated to
# an en-dash HTML entity. Two reasons why: First, unlike the
# en- and em-dash syntax supported by
# EducateDashesOldSchool(), it's compatible with existing
# entries written before SmartyPants 1.1, back when "--" was
# only used for em-dashes. Second, em-dashes are more
# common than en-dashes, and so it sort of makes sense that
# the shortcut should be shorter to type. (Thanks to Aaron
# Swartz for the idea.)
#
# en em
$_ = str_replace(array("---", "--",),
array('&#8211;', '&#8212;'), $_);
return $_;
}
function EducateEllipses($_) {
#
# Parameter: String.
# Returns: The string, with each instance of "..." translated to
# an ellipsis HTML entity. Also converts the case where
# there are spaces between the dots.
#
# Example input: Huh...?
# Example output: Huh&#8230;?
#
$_ = str_replace(array("...", ". . .",), '&#8230;', $_);
return $_;
}
function StupefyEntities($_) {
#
# Parameter: String.
# Returns: The string, with each SmartyPants HTML entity translated to
# its ASCII counterpart.
#
# Example input: &#8220;Hello &#8212; world.&#8221;
# Example output: "Hello -- world."
#
# en-dash em-dash
$_ = str_replace(array('&#8211;', '&#8212;'),
array('-', '--'), $_);
# single quote open close
$_ = str_replace(array('&#8216;', '&#8217;'), "'", $_);
# double quote open close
$_ = str_replace(array('&#8220;', '&#8221;'), '"', $_);
$_ = str_replace('&#8230;', '...', $_); # ellipsis
return $_;
}
function ProcessEscapes($_) {
#
# Parameter: String.
# Returns: The string, with after processing the following backslash
# escape sequences. This is useful if you want to force a "dumb"
# quote or other character to appear.
#
# Escape Value
# ------ -----
# \\ &#92;
# \" &#34;
# \' &#39;
# \. &#46;
# \- &#45;
# \` &#96;
#
$_ = str_replace(
array('\\', '\"', "\'", '\.', '\-', '\`'),
array('&#92;', '&#34;', '&#39;', '&#46;', '&#45;', '&#96;'), $_);
return $_;
}
# _TokenizeHTML is shared between PHP SmartyPants and PHP Markdown.
# We only define it if it is not already defined.
if (!function_exists('_TokenizeHTML')) :
function _TokenizeHTML($str) {
#
# Parameter: String containing HTML markup.
# Returns: An array of the tokens comprising the input
# string. Each token is either a tag (possibly with nested,
# tags contained therein, such as <a href="<MTFoo>">, or a
# run of text between tags. Each element of the array is a
# two-element array; the first is either 'tag' or 'text';
# the second is the actual value.
#
#
# Regular expression derived from the _tokenize() subroutine in
# Brad Choate's MTRegex plugin.
# <http://www.bradchoate.com/past/mtregex.php>
#
$index = 0;
$tokens = array();
$match = '(?s:<!(?:--.*?--\s*)+>)|'. # comment
'(?s:<\?.*?\?>)|'. # processing instruction
# regular tags
'(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)';
$parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($parts as $part) {
if (++$index % 2 && $part != '')
$tokens[] = array('text', $part);
else
$tokens[] = array('tag', $part);
}
return $tokens;
}
endif;
/*
PHP SmartyPants
===============
Description
-----------
This is a PHP translation of the original SmartyPants quote educator written in
Perl by John Gruber.
SmartyPants is a web publishing utility that translates plain ASCII
punctuation characters into "smart" typographic punctuation HTML
entities. SmartyPants can perform the following transformations:
* Straight quotes (`"` and `'`) into "curly" quote HTML entities
* Backticks-style quotes (` ``like this'' `) into "curly" quote HTML
entities
* Dashes (`--` and `---`) into en- and em-dash entities
* Three consecutive dots (`...`) into an ellipsis entity
SmartyPants does not modify characters within `<pre>`, `<code>`, `<kbd>`,
`<script>`, or `<math>` tag blocks. Typically, these tags are used to
display text where smart quotes and other "smart punctuation" would not
be appropriate, such as source code or example markup.
### Backslash Escapes ###
If you need to use literal straight quotes (or plain hyphens and
periods), SmartyPants accepts the following backslash escape sequences
to force non-smart punctuation. It does so by transforming the escape
sequence into a decimal-encoded HTML entity:
Escape Value Character
------ ----- ---------
\\ &#92; \
\" &#34; "
\' &#39; '
\. &#46; .
\- &#45; -
\` &#96; `
This is useful, for example, when you want to use straight quotes as
foot and inch marks: 6'2" tall; a 17" iMac.
Bugs
----
To file bug reports or feature requests (other than topics listed in the
Caveats section above) please send email to:
<michel.fortin@michelf.com>
If the bug involves quotes being curled the wrong way, please send example
text to illustrate.
### Algorithmic Shortcomings ###
One situation in which quotes will get curled the wrong way is when
apostrophes are used at the start of leading contractions. For example:
'Twas the night before Christmas.
In the case above, SmartyPants will turn the apostrophe into an opening
single-quote, when in fact it should be a closing one. I don't think
this problem can be solved in the general case -- every word processor
I've tried gets this wrong as well. In such cases, it's best to use the
proper HTML entity for closing single-quotes (`&#8217;`) by hand.
Version History
---------------
1.5.1d (25 May 2005)
* Corrected a small bug in `_TokenizeHTML` where a Doctype declaration
was not seen as HTML (smart quotes where applied inside).
1.5.1c (13 Dec 2004)
* Changed a regular expression in `_TokenizeHTML` that could lead to
a segmentation fault with PHP 4.3.8 on Linux.
1.5.1b (6 Sep 2004)
* Corrected a problem with quotes immediately following a dash
with no space between: `Text--"quoted text"--text.`
* PHP SmartyPants can now be used as a modifier by the Smarty
template engine. Rename the file to "modifier.smartypants.php"
and put it in your smarty plugins folder.
* Replaced a lot of space characters by tabs, saving about 4 KB.
1.5.1a (30 Jun 2004)
* PHP Markdown and PHP Smartypants now share the same `_TokenizeHTML`
function when loaded simultanously.
* Changed the internals of `_TokenizeHTML` to lower the PHP version
requirement to PHP 4.0.5.
1.5.1 (6 Jun 2004)
* Initial release of PHP SmartyPants, based on version 1.5.1 of the
original SmartyPants written in Perl.
Author
------
John Gruber
<http://daringfireball.net/>
Ported to PHP by Michel Fortin
<http://www.michelf.com/>
Additional Credits
------------------
Portions of this plug-in are based on Brad Choate's nifty MTRegex plug-in.
Brad Choate also contributed a few bits of source code to this plug-in.
Brad Choate is a fine hacker indeed. (<http://bradchoate.com/>)
Jeremy Hedley (<http://antipixel.com/>) and Charles Wiltgen
(<http://playbacktime.com/>) deserve mention for exemplary beta testing.
Copyright and License
---------------------
Copyright (c) 2003 John Gruber
<http://daringfireball.net/>
All rights reserved.
Copyright (c) 2004 Michel Fortin
<http://www.michelf.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name "SmartyPants" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is"
and any express or implied warranties, including, but not limited to, the
implied warranties of merchantability and fitness for a particular purpose
are disclaimed. In no event shall the copyright owner or contributors be
liable for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of
substitute goods or services; loss of use, data, or profits; or business
interruption) however caused and on any theory of liability, whether in
contract, strict liability, or tort (including negligence or otherwise)
arising in any way out of the use of this software, even if advised of the
possibility of such damage.
*/
?>

View File

@@ -0,0 +1,30 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty spacify modifier plugin
*
* Type: modifier<br>
* Name: spacify<br>
* Purpose: add spaces between characters in a string
* @link http://smarty.php.net/manual/en/language.modifier.spacify.php
* spacify (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string
* @return string
*/
function smarty_modifier_spacify($string, $spacify_char = ' ')
{
return implode($spacify_char,
preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY));
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty string_format modifier plugin
*
* Type: modifier<br>
* Name: string_format<br>
* Purpose: format strings via sprintf
* @link http://smarty.php.net/manual/en/language.modifier.string.format.php
* string_format (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param string
* @return string
*/
function smarty_modifier_string_format($string, $format)
{
return sprintf($format, $string);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,33 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty strip modifier plugin
*
* Type: modifier<br>
* Name: strip<br>
* Purpose: Replace all repeated spaces, newlines, tabs
* with a single space or supplied replacement string.<br>
* Example: {$var|strip} {$var|strip:"&nbsp;"}
* Date: September 25th, 2002
* @link http://smarty.php.net/manual/en/language.modifier.strip.php
* strip (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @version 1.0
* @param string
* @param string
* @return string
*/
function smarty_modifier_strip($text, $replace = ' ')
{
return preg_replace('!\s+!', $replace, $text);
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,32 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty strip_tags modifier plugin
*
* Type: modifier<br>
* Name: strip_tags<br>
* Purpose: strip html tags from text
* @link http://smarty.php.net/manual/en/language.modifier.strip.tags.php
* strip_tags (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param boolean
* @return string
*/
function smarty_modifier_strip_tags($string, $replace_with_space = true)
{
if ($replace_with_space)
return preg_replace('!<[^>]*?>!', ' ', $string);
else
return strip_tags($string);
}
/* vim: set expandtab: */
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty truncate modifier plugin
*
* Type: modifier<br>
* Name: truncate<br>
* Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle.
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php
* truncate (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param integer
* @param string
* @param boolean
* @param boolean
* @return string
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...',
$break_words = false, $middle = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= strlen($etc);
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1));
}
if(!$middle) {
return substr($string, 0, $length).$etc;
} else {
return substr($string, 0, $length/2) . $etc . substr($string, -$length/2);
}
} else {
return $string;
}
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,26 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty upper modifier plugin
*
* Type: modifier<br>
* Name: upper<br>
* Purpose: convert string to uppercase
* @link http://smarty.php.net/manual/en/language.modifier.upper.php
* upper (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_modifier_upper($string)
{
return strtoupper($string);
}
?>

View File

@@ -0,0 +1,29 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty wordwrap modifier plugin
*
* Type: modifier<br>
* Name: wordwrap<br>
* Purpose: wrap a string of text at a given length
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php
* wordwrap (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @param integer
* @param string
* @param boolean
* @return string
*/
function smarty_modifier_wordwrap($string,$length=80,$break="\n",$cut=false)
{
return wordwrap($string,$length,$break,$cut);
}
?>

View File

@@ -0,0 +1,75 @@
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty trimwhitespace outputfilter plugin
*
* File: outputfilter.trimwhitespace.php<br>
* Type: outputfilter<br>
* Name: trimwhitespace<br>
* Date: Jan 25, 2003<br>
* Purpose: trim leading white space and blank lines from
* template source after it gets interpreted, cleaning
* up code and saving bandwidth. Does not affect
* <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br>
* Install: Drop into the plugin directory, call
* <code>$smarty->load_filter('output','trimwhitespace');</code>
* from application.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
* @version 1.3
* @param string
* @param Smarty
*/
function smarty_outputfilter_trimwhitespace($source, &$smarty)
{
// Pull out the script blocks
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
$_script_blocks = $match[0];
$source = preg_replace("!<script[^>]+>.*?</script>!is",
'@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks
preg_match_all("!<pre>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0];
$source = preg_replace("!<pre>.*?</pre>!is",
'@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
'@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
// replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
// replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
// replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
return $source;
}
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
$_len = strlen($search_str);
$_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
if (($_pos=strpos($subject, $search_str, $_pos))!==false)
$subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
else
break;
}
?>

View File

@@ -0,0 +1,37 @@
/*
* Smarty plugin
* -------------------------------------------------------------
* File: postfilter.lang.php
* Type: postfilter
* Name: lang
* Version: 1.0
* Date: August 12, 2002
* Purpose: Parses the intermediate tags left by compiler.lang
* and replaces them with the translated strings,
* according to the $compile_id value (language code).
*
* Install: Drop into the plugin directory, call
* $smarty->load_filter('post','lang');
* or
* $smarty->autoload_filters = array('post' => array('lang'));
* from application.
* Author: Alejandro Sarco <ale@sarco.com.ar>
* -------------------------------------------------------------
*/
function smarty_postfilter_lang1($tpl, &$smarty) {
//Include your own respective translation strings here
//include('path/to/your/languages/directory/'.$smarty->compile_id.'/.your_language_file.php');
$offset = 0;
while ( $start = strpos($tpl, '<?php ($lang.', $offset )) {
$end = strpos($tpl, ') ?>', $start );
$rplstr = substr($tpl, $start + 13, $end - ($start + 13));
$tpl = substr_replace($tpl, $lang[$rplstr], $start, $end - ($start - 4));
$offset = $end + 4;
}
return $tpl;
}
?>

View File

@@ -0,0 +1,31 @@
<?php
/**
* Smarty shared plugin
* @package Smarty
* @subpackage plugins
*/
/**
* escape_special_chars common function
*
* Function: smarty_function_escape_special_chars<br>
* Purpose: used by other smarty functions to escape
* special chars except for already escaped ones
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_function_escape_special_chars($string)
{
if(!is_array($string)) {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string);
$string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string);
}
return $string;
}
/* vim: set expandtab: */
?>

View File

@@ -0,0 +1,46 @@
<?php
/**
* Smarty shared plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Function: smarty_make_timestamp<br>
* Purpose: used by other smarty functions to make a timestamp
* from a string.
* @author Monte Ohrt <monte at ohrt dot com>
* @param string
* @return string
*/
function smarty_make_timestamp($string)
{
if(empty($string)) {
// use "now":
$time = time();
} elseif (preg_match('/^\d{14}$/', $string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
$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));
} elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp
$time = (int)$string;
} else {
// strtotime should handle it
$time = strtotime($string);
if ($time == -1 || $time === false) {
// strtotime() was not able to parse $string, use "now":
$time = time();
}
}
return $time;
}
/* vim: set expandtab: */
?>