Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
 1: <?php
 2: /**
 3:  * Smarty plugin
 4:  * This plugin is only for Smarty2 BC
 5:  *
 6:  * @package    Smarty
 7:  * @subpackage PluginsFunction
 8:  */
 9: 
10: /**
11:  * Smarty {math} function plugin
12:  * Type:     function<br>
13:  * Name:     math<br>
14:  * Purpose:  handle math computations in template
15:  *
16:  * @link     http://www.smarty.net/manual/en/language.function.math.php {math}
17:  *           (Smarty online manual)
18:  * @author   Monte Ohrt <monte at ohrt dot com>
19:  *
20:  * @param array                    $params   parameters
21:  * @param Smarty_Internal_Template $template template object
22:  *
23:  * @return string|null
24:  */
25: function smarty_function_math($params, $template)
26: {
27:     static $_allowed_funcs = array(
28:         'int'  => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
29:         'log'  => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true,
30:         'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true
31:     );
32:     // be sure equation parameter is present
33:     if (empty($params['equation'])) {
34:         trigger_error("math: missing equation parameter", E_USER_WARNING);
35: 
36:         return;
37:     }
38: 
39:     $equation = $params['equation'];
40: 
41:     // make sure parenthesis are balanced
42:     if (substr_count($equation, "(") != substr_count($equation, ")")) {
43:         trigger_error("math: unbalanced parenthesis", E_USER_WARNING);
44: 
45:         return;
46:     }
47: 
48:     // match all vars in equation, make sure all are passed
49:     preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
50: 
51:     foreach ($match[1] as $curr_var) {
52:         if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) {
53:             trigger_error("math: function call $curr_var not allowed", E_USER_WARNING);
54: 
55:             return;
56:         }
57:     }
58: 
59:     foreach ($params as $key => $val) {
60:         if ($key != "equation" && $key != "format" && $key != "assign") {
61:             // make sure value is not empty
62:             if (strlen($val) == 0) {
63:                 trigger_error("math: parameter $key is empty", E_USER_WARNING);
64: 
65:                 return;
66:             }
67:             if (!is_numeric($val)) {
68:                 trigger_error("math: parameter $key: is not numeric", E_USER_WARNING);
69: 
70:                 return;
71:             }
72:             $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
73:         }
74:     }
75:     $smarty_math_result = null;
76:     eval("\$smarty_math_result = " . $equation . ";");
77: 
78:     if (empty($params['format'])) {
79:         if (empty($params['assign'])) {
80:             return $smarty_math_result;
81:         } else {
82:             $template->assign($params['assign'], $smarty_math_result);
83:         }
84:     } else {
85:         if (empty($params['assign'])) {
86:             printf($params['format'], $smarty_math_result);
87:         } else {
88:             $template->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
89:         }
90:     }
91: }
92: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen