├── README.TXT ├── action-buildcertificate.inc ├── action-certificates.inc ├── action-config.inc ├── action-downloadcertificate.inc ├── action-downloadconfigfile.inc ├── action-newcertificate.inc ├── action-status.inc ├── action-viewcertificate.inc ├── config.inc ├── config.inc.sample ├── configs └── colors.conf ├── downloads └── readme.txt ├── favicon.ico ├── img ├── 1x1.gif └── OpenVPN-small.gif ├── include ├── Smarty │ ├── Config_File.class.php │ ├── Smarty.class.php │ ├── Smarty_Compiler.class.php │ ├── debug.tpl │ ├── index.html │ ├── internals │ │ ├── core.assemble_plugin_filepath.php │ │ ├── core.assign_smarty_interface.php │ │ ├── core.create_dir_structure.php │ │ ├── core.display_debug_console.php │ │ ├── core.get_include_path.php │ │ ├── core.get_microtime.php │ │ ├── core.get_php_resource.php │ │ ├── core.is_secure.php │ │ ├── core.is_trusted.php │ │ ├── core.load_plugins.php │ │ ├── core.load_resource_plugin.php │ │ ├── core.process_cached_inserts.php │ │ ├── core.process_compiled_include.php │ │ ├── core.read_cache_file.php │ │ ├── core.rm_auto.php │ │ ├── core.rmdir.php │ │ ├── core.run_insert_handler.php │ │ ├── core.smarty_include_php.php │ │ ├── core.write_cache_file.php │ │ ├── core.write_compiled_include.php │ │ ├── core.write_compiled_resource.php │ │ └── core.write_file.php │ └── plugins │ │ ├── block.textformat.php │ │ ├── compiler.assign.php │ │ ├── function.assign_debug_info.php │ │ ├── function.config_load.php │ │ ├── function.counter.php │ │ ├── function.cycle.php │ │ ├── function.debug.php │ │ ├── function.eval.php │ │ ├── function.fetch.php │ │ ├── function.html_checkboxes.php │ │ ├── function.html_image.php │ │ ├── function.html_options.php │ │ ├── function.html_radios.php │ │ ├── function.html_select_date.php │ │ ├── function.html_select_time.php │ │ ├── function.html_table.php │ │ ├── function.mailto.php │ │ ├── function.math.php │ │ ├── function.popup.php │ │ ├── function.popup_init.php │ │ ├── index.html │ │ ├── modifier.capitalize.php │ │ ├── modifier.cat.php │ │ ├── modifier.count_characters.php │ │ ├── modifier.count_paragraphs.php │ │ ├── modifier.count_sentences.php │ │ ├── modifier.count_words.php │ │ ├── modifier.date_format.php │ │ ├── modifier.debug_print_var.php │ │ ├── modifier.default.php │ │ ├── modifier.escape.php │ │ ├── modifier.indent.php │ │ ├── modifier.lower.php │ │ ├── modifier.nl2br.php │ │ ├── modifier.regex_replace.php │ │ ├── modifier.replace.php │ │ ├── modifier.spacify.php │ │ ├── modifier.string_format.php │ │ ├── modifier.strip.php │ │ ├── modifier.strip_tags.php │ │ ├── modifier.truncate.php │ │ ├── modifier.upper.php │ │ ├── modifier.wordwrap.php │ │ ├── outputfilter.trimwhitespace.php │ │ ├── resource.userdb.php │ │ ├── resource.var.php │ │ ├── shared.escape_special_chars.php │ │ └── shared.make_timestamp.php ├── functions.inc ├── openssl-functions.inc ├── openvpn-functions.inc └── zip.lib.php ├── index.php ├── info.php ├── plugins └── systemcheck │ ├── action.inc │ ├── action.tpl │ ├── config.inc │ ├── left.tpl │ └── status.tpl ├── templates ├── action-certificates.tpl ├── action-config.tpl ├── action-error.tpl ├── action-newcertificate.tpl ├── action-status.tpl ├── action-viewcertificate.tpl ├── header.tpl ├── left-menu.tpl ├── left-status.tpl ├── menu.tpl └── page.tpl └── templates_c └── dummy /action-buildcertificate.inc: -------------------------------------------------------------------------------- 1 | $PUTcountryName, 28 | 'stateOrProvinceName' => $PUTstateOrProvinceName, 29 | 'localityName' => $PUTlocalityName, 30 | 'organizationName' => $PUTorganizationName, 31 | 'organizationalUnitName' => $PUTorganizationalUnitName, 32 | 'commonName' => $PUTcommonName, 33 | 'emailAddress' => $PUTemailAddress, 34 | 'password' => $PUTpassword 35 | ), 36 | $PUTvalidity 37 | ); 38 | 39 | if ($Result != FALSE) 40 | { 41 | # header ('Location: '. $_SERVER["PHP_SELF"] .'?Action=ViewCertificate&id='. $Result); 42 | html_postredir ($_SERVER["PHP_SELF"] .'?Action=ViewCertificate&id='. $Result); 43 | } 44 | else 45 | { 46 | echo '
'. $Debug .'
'; 47 | } 48 | ?> 49 | -------------------------------------------------------------------------------- /action-certificates.inc: -------------------------------------------------------------------------------- 1 | assign ('Company_Name', $config['Company_Name']); 23 | $smarty->assign ('Company_Logo', $config['Company_Logo']); 24 | $smarty->assign ('URL_Home_Page', $config['URL_Home_Page']); 25 | $smarty->assign ('title', 'OpenVPN Web GUI : OpenSSL certificates [refreshes every minute]'); 26 | $smarty->assign ('refresh', '60'); 27 | 28 | // Status Bar 29 | $smarty->assign ('Server', $openvpn['Server']); 30 | $smarty->assign ('Seconds_Ago', time () - $openvpn['Server']['Time']); 31 | $smarty->assign ('Certificates', $openssl['Database']); 32 | 33 | // Action 34 | $smarty->assign ('action', 'CERTIFICATES'); 35 | 36 | // Action-Specific 37 | if (isset ($openvpn['Client'])) 38 | $smarty->assign ('Client', $openvpn['Client']); 39 | 40 | // Display 41 | $smarty->assign ('PluginPath', $config['PluginsAbsolutePath']); 42 | $smarty->assign ('Plugins', $config['Plugins']); 43 | $smarty->assign ('Page', 'action-certificates.tpl'); 44 | $smarty->display ('page.tpl'); 45 | //print_r ($GLOBALS); 46 | ?> 47 | -------------------------------------------------------------------------------- /action-config.inc: -------------------------------------------------------------------------------- 1 | assign ('Company_Name', $config['Company_Name']); 22 | $smarty->assign ('Company_Logo', $config['Company_Logo']); 23 | $smarty->assign ('URL_Home_Page', $config['URL_Home_Page']); 24 | $smarty->assign ('title', 'OpenVPN Web GUI : server configuration'); 25 | 26 | // Status Bar 27 | $smarty->assign ('Server', $openvpn['Server']); 28 | $smarty->assign ('Seconds_Ago', time () - $openvpn['Server']['Time']); 29 | 30 | // Action 31 | $smarty->assign ('action', 'CONFIG'); 32 | 33 | // Action-Specific 34 | if (isset ($openvpn['Client'])) 35 | $smarty->assign ('Client', $openvpn['Client']); 36 | if (isset ($openssl['Server'])) 37 | $smarty->assign ('Openssl', $openssl['Server']); 38 | if (isset ($openssl['Database'])) 39 | $smarty->assign ('Certificates', $openssl['Database']); 40 | 41 | // Display 42 | $smarty->assign ('PluginPath', $config['PluginsAbsolutePath']); 43 | $smarty->assign ('Plugins', $config['Plugins']); 44 | $smarty->assign ('Page', 'action-config.tpl'); 45 | $smarty->display ('page.tpl'); 46 | //html_dump ('$config', $config); 47 | ?> 48 | -------------------------------------------------------------------------------- /action-downloadcertificate.inc: -------------------------------------------------------------------------------- 1 | addFile (implode ('', file ($File2zip)), $File2name); 46 | } 47 | } 48 | 49 | // Should we add TA/CA files? 50 | if ($config['Download']['ZIP']['.ca']) { 51 | if (is_file ($config['openssl']['CA']['pub'])) { 52 | $zipData->addFile (implode ('', file ($config['openssl']['CA']['pub'])), 'ca.crt'); 53 | } 54 | } 55 | if ($config['Download']['ZIP']['.ta']) { 56 | if (is_file ($config['openssl']['TA']['pub'])) { 57 | $zipData->addFile (implode ('', file ($config['openssl']['TA']['pub'])), 'ta.key'); 58 | } 59 | } 60 | 61 | // Check and see if we should fix a config file 62 | if ($config['Download']['ZIP']['Config_Generic']) { 63 | if (is_file ($config['Download']['ZIP']['Config_Generici_Loc'])) { 64 | $zipData->addFile (openvpn_config_replace(implode ('', file ($config['Download']['ZIP']['Config_Generici_Loc'])), str_replace_spaces($tmpArray['CN'])), basename($config['Download']['ZIP']['Config_Generici_Loc'])); 65 | } 66 | } 67 | 68 | 69 | // Add the extra files 70 | foreach ($config['Download']['ZIP']['Others'] as $File2zip) 71 | { 72 | if (is_file ('downloads/'. $File2zip)) 73 | $zipData->addFile (implode ('', file ('downloads/'. $File2zip)), $File2zip); 74 | } 75 | 76 | // Flush the ZIP file to the client 77 | html_download_data ($zipData -> file (), str_replace_spaces($tmpArray['CN']) .'_OVPN.zip'); 78 | } 79 | else 80 | { 81 | $sCertificateFile = openssl_get_filename (str_replace_spaces($tmpArray['CN']), $sExt); 82 | if (!$sCertificateFile) { 83 | html_error ("Can't find requested file " . str_replace_spaces($tmpArray['CN'])); 84 | } 85 | 86 | // Download 87 | html_download ($sCertificateFile, str_replace_spaces($tmpArray['CN']) . $sExt); 88 | //html_dump ('$GLOBALS', $GLOBALS); 89 | 90 | //html_error($openssl['Database'][4]['CN']); 91 | //$tmpArray = openssl_get_database_contents($GETidDEC[0]); 92 | //html_error(tmpArray['CN']); 93 | } 94 | 95 | ?> 96 | -------------------------------------------------------------------------------- /action-downloadconfigfile.inc: -------------------------------------------------------------------------------- 1 | Probably it should not be read by anybode except it's owner?"); 63 | else 64 | html_error ("The file '$sFile' does not exist."); 65 | else 66 | html_error ('Wrong ID. Stop hacking.'); 67 | } 68 | else 69 | html_error ('The ID is not defined. Stop hacking.'); 70 | ?> 71 | -------------------------------------------------------------------------------- /action-newcertificate.inc: -------------------------------------------------------------------------------- 1 | assign ('Company_Name', $config['Company_Name']); 23 | $smarty->assign ('Company_Logo', $config['Company_Logo']); 24 | $smarty->assign ('URL_Home_Page', $config['URL_Home_Page']); 25 | $smarty->assign ('title', 'OpenVPN Web GUI : New OpenSSL certificate'); 26 | 27 | // Status Bar 28 | $smarty->assign ('Server', $openvpn['Server']); 29 | $smarty->assign ('Seconds_Ago', time () - $openvpn['Server']['Time']); 30 | 31 | // Action 32 | $smarty->assign ('action', 'CERTIFICATES'); 33 | $smarty->assign ('subaction', 'NEW'); 34 | 35 | // Action-Specific 36 | $smarty->assign ('Default', $config['openssl']['default']); 37 | 38 | // Display 39 | $smarty->assign ('PluginPath', $config['PluginsAbsolutePath']); 40 | $smarty->assign ('Plugins', $config['Plugins']); 41 | $smarty->assign ('Page', 'action-newcertificate.tpl'); 42 | $smarty->display ('page.tpl'); 43 | ?> 44 | -------------------------------------------------------------------------------- /action-status.inc: -------------------------------------------------------------------------------- 1 | assign ('Company_Name', $config['Company_Name']); 19 | $smarty->assign ('Company_Logo', $config['Company_Logo']); 20 | $smarty->assign ('URL_Home_Page', $config['URL_Home_Page']); 21 | $smarty->assign ('title', 'OpenVPN Web GUI : server status [refreshes every minute]'); 22 | $smarty->assign ('refresh', '60'); 23 | 24 | // Status Bar 25 | $smarty->assign ('Server', $openvpn['Server']); 26 | $smarty->assign ('Seconds_Ago', time () - $openvpn['Server']['Time']); 27 | 28 | // Action 29 | $smarty->assign ('action', 'STATUS'); 30 | 31 | // Action-Specific 32 | if (isset ($openvpn['Client'])) 33 | $smarty->assign ('Client', $openvpn['Client']); 34 | 35 | // Display 36 | $smarty->assign ('PluginPath', $config['PluginsAbsolutePath']); 37 | $smarty->assign ('Plugins', $config['Plugins']); 38 | $smarty->assign ('Page', 'action-status.tpl'); 39 | $smarty->display ('page.tpl'); 40 | ?> 41 | -------------------------------------------------------------------------------- /action-viewcertificate.inc: -------------------------------------------------------------------------------- 1 | assign ('Company_Name', $config['Company_Name']); 23 | $smarty->assign ('Company_Logo', $config['Company_Logo']); 24 | $smarty->assign ('URL_Home_Page', $config['URL_Home_Page']); 25 | $smarty->assign ('title', 'OpenVPN Web GUI : OpenSSL certificate'); 26 | 27 | // Status Bar 28 | $smarty->assign ('Server', $openvpn['Server']); 29 | $smarty->assign ('Seconds_Ago', time () - $openvpn['Server']['Time']); 30 | $smarty->assign ('Certificates', $openssl['Database']); 31 | 32 | // Action 33 | $smarty->assign ('action', 'CERTIFICATES'); 34 | $smarty->assign ('subaction', 'VIEW'); 35 | 36 | // Action-Specific 37 | 38 | $GETidDEC = $_GET['id']; 39 | 40 | $tmpArray = openssl_get_database_contents($GETidDEC); 41 | 42 | $tmpArray['ExpDate'] = str_openssldata_to_string ($tmpArray['ExpDate']); 43 | $tmpArray['RevDate'] = str_openssldata_to_string ($tmpArray['RevDate']); 44 | $smarty->assign ('Certificate', $tmpArray); 45 | $smarty->assign ('CertificateFileCRT', openssl_get_filename(str_replace_spaces ($tmpArray['CN']), '.crt')); 46 | $smarty->assign ('CertificateFileKEY', openssl_get_filename(str_replace_spaces ($tmpArray['CN']), '.key')); 47 | $smarty->assign ('CertificateFileCSR', openssl_get_filename(str_replace_spaces ($tmpArray['CN']), '.csr')); 48 | $smarty->assign ('Password', openssl_read_password($GETidDEC, $config['openssl']['passworddb'])); 49 | // Display 50 | $smarty->assign ('PluginPath', $config['PluginsAbsolutePath']); 51 | $smarty->assign ('Plugins', $config['Plugins']); 52 | $smarty->assign ('Page', 'action-viewcertificate.tpl'); 53 | $smarty->display ('page.tpl'); 54 | ?> 55 | -------------------------------------------------------------------------------- /config.inc: -------------------------------------------------------------------------------- 1 | '/etc/openvpn/easy-rsa/2.0/openssl.cnf'); 66 | //'encrypt_key' => 0); 67 | // Change: password database location 68 | $config['openssl']['passworddb'] = $config['openssl']['folder'] .'passwords.db'; 69 | // NEW OPENSSL CERTIFICATE DEFAULTS _________ 70 | 71 | // Change all of them as it is done in your easy-rsa/vars 72 | $config['openssl']['default']['expiration'] = 3560; 73 | $config['openssl']['default']['countryName'] = 'US'; 74 | $config['openssl']['default']['stateOrProvinceName'] = 'Indiana'; 75 | $config['openssl']['default']['localityName'] = 'Indianapolis'; 76 | $config['openssl']['default']['organizationName'] = 'Company Name'; 77 | $config['openssl']['default']['organizationalUnitName'] = 'Please type in plant location'; 78 | $config['openssl']['default']['commonName'] = 'John Doe'; 79 | $config['openssl']['default']['emailAddress'] = '@domain.com'; 80 | $config['openssl']['default']['password'] = ''; 81 | ?> 82 | -------------------------------------------------------------------------------- /config.inc.sample: -------------------------------------------------------------------------------- 1 | '/etc/openvpn/user/easy-rsa/openssl.cnf'); 66 | //'encrypt_key' => 0); 67 | // Change: password database location 68 | $config['openssl']['passworddb'] = $config['openssl']['folder'] .'passwords.db'; 69 | // NEW OPENSSL CERTIFICATE DEFAULTS _________ 70 | 71 | // Change all of them as it is done in your easy-rsa/vars 72 | $config['openssl']['default']['expiration'] = 3560; 73 | $config['openssl']['default']['countryName'] = 'US'; 74 | $config['openssl']['default']['stateOrProvinceName'] = 'Indiana'; 75 | $config['openssl']['default']['localityName'] = 'Indianapolis'; 76 | $config['openssl']['default']['organizationName'] = 'Company Name'; 77 | $config['openssl']['default']['organizationalUnitName'] = 'Please type in plant location'; 78 | $config['openssl']['default']['commonName'] = 'John Doe'; 79 | $config['openssl']['default']['emailAddress'] = '@domain.com'; 80 | $config['openssl']['default']['password'] = ''; 81 | ?> 82 | -------------------------------------------------------------------------------- /configs/colors.conf: -------------------------------------------------------------------------------- 1 | # Global Smarty Variables 2 | confBodyBgColor = "#E0E0E0" 3 | confBodyLinkColor = "#000000" 4 | confBodyALinkColor = "#000000" 5 | confBodyVLinkColor = "#000000" 6 | 7 | confHeaderBgColor = "#C3C7B7" 8 | 9 | confBorderColor = "#97875E" 10 | confFieldViewColor = "#F1EFE9" 11 | 12 | -------------------------------------------------------------------------------- /downloads/readme.txt: -------------------------------------------------------------------------------- 1 | This is an example of the readme.txt file. 2 | 3 | Feel free to fill it with your own content. 4 | 5 | Please remeber, that this file will be read by your clients, 6 | so be polite with them, and as descriptive, as possible. 7 | Your clients are your assets. Keep them happy. 8 | 9 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberorg/openvpn-web-gui/7ee82abc63b7a9b554b37bd0e2ae0016f3188f7a/favicon.ico -------------------------------------------------------------------------------- /img/1x1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberorg/openvpn-web-gui/7ee82abc63b7a9b554b37bd0e2ae0016f3188f7a/img/1x1.gif -------------------------------------------------------------------------------- /img/OpenVPN-small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberorg/openvpn-web-gui/7ee82abc63b7a9b554b37bd0e2ae0016f3188f7a/img/OpenVPN-small.gif -------------------------------------------------------------------------------- /include/Smarty/debug.tpl: -------------------------------------------------------------------------------- 1 | {* Smarty *} 2 | 3 | {* debug.tpl, last updated version 2.0.1 *} 4 | 5 | {assign_debug_info} 6 | 7 | {if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"} 8 | 9 | 10 | 11 | {section name=templates loop=$_debug_tpls} 12 | 13 | {sectionelse} 14 | 15 | {/section} 16 | 17 | {section name=vars loop=$_debug_keys} 18 | 19 | {sectionelse} 20 | 21 | {/section} 22 | 23 | {section name=config_vars loop=$_debug_config_keys} 24 | 25 | {sectionelse} 26 | 27 | {/section} 28 |
Smarty Debug Console
included templates & config files (load time in seconds):
{section name=indent loop=$_debug_tpls[templates].depth}   {/section}{$_debug_tpls[templates].filename|escape:html}{if isset($_debug_tpls[templates].exec_time)} ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}{/if}
no templates included
assigned template variables:
{ldelim}${$_debug_keys[vars]}{rdelim}{$_debug_vals[vars]|@debug_print_var}
no template variables assigned
assigned config file variables (outer template scope):
{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}{$_debug_config_vals[config_vars]|@debug_print_var}
no config vars assigned
29 | 30 | {else} 31 | 64 | {/if} 65 | -------------------------------------------------------------------------------- /include/Smarty/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cyberorg/openvpn-web-gui/7ee82abc63b7a9b554b37bd0e2ae0016f3188f7a/include/Smarty/index.html -------------------------------------------------------------------------------- /include/Smarty/internals/core.assemble_plugin_filepath.php: -------------------------------------------------------------------------------- 1 | plugins_dir as $_plugin_dir) { 26 | 27 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; 28 | 29 | // see if path is relative 30 | if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { 31 | $_relative_paths[] = $_plugin_dir; 32 | // relative path, see if it is in the SMARTY_DIR 33 | if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { 34 | $_return = SMARTY_DIR . $_plugin_filepath; 35 | break; 36 | } 37 | } 38 | // try relative to cwd (or absolute) 39 | if (@is_readable($_plugin_filepath)) { 40 | $_return = $_plugin_filepath; 41 | break; 42 | } 43 | } 44 | 45 | if($_return === false) { 46 | // still not found, try PHP include_path 47 | if(isset($_relative_paths)) { 48 | foreach ((array)$_relative_paths as $_plugin_dir) { 49 | 50 | $_plugin_filepath = $_plugin_dir . DIRECTORY_SEPARATOR . $_plugin_filename; 51 | 52 | $_params = array('file_path' => $_plugin_filepath); 53 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); 54 | if(smarty_core_get_include_path($_params, $smarty)) { 55 | $_return = $_params['new_file_path']; 56 | break; 57 | } 58 | } 59 | } 60 | } 61 | $_filepaths_cache[$_plugin_filename] = $_return; 62 | return $_return; 63 | } 64 | 65 | /* vim: set expandtab: */ 66 | 67 | ?> 68 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.assign_smarty_interface.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: assign_smarty_interface
13 | * Purpose: assign the $smarty interface variable 14 | * @param array Format: null 15 | * @param Smarty 16 | */ 17 | function smarty_core_assign_smarty_interface($params, &$smarty) 18 | { 19 | if (isset($smarty->_smarty_vars) && isset($smarty->_smarty_vars['request'])) { 20 | return; 21 | } 22 | 23 | $_globals_map = array('g' => 'HTTP_GET_VARS', 24 | 'p' => 'HTTP_POST_VARS', 25 | 'c' => 'HTTP_COOKIE_VARS', 26 | 's' => 'HTTP_SERVER_VARS', 27 | 'e' => 'HTTP_ENV_VARS'); 28 | 29 | $_smarty_vars_request = array(); 30 | 31 | foreach (preg_split('!!', strtolower($smarty->request_vars_order)) as $_c) { 32 | if (isset($_globals_map[$_c])) { 33 | $_smarty_vars_request = array_merge($_smarty_vars_request, $GLOBALS[$_globals_map[$_c]]); 34 | } 35 | } 36 | $_smarty_vars_request = @array_merge($_smarty_vars_request, $GLOBALS['HTTP_SESSION_VARS']); 37 | 38 | $smarty->_smarty_vars['request'] = $_smarty_vars_request; 39 | } 40 | 41 | /* vim: set expandtab: */ 42 | 43 | ?> 44 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.create_dir_structure.php: -------------------------------------------------------------------------------- 1 | _dir_perms) && !is_dir($_new_dir)) { 69 | $smarty->trigger_error("problem creating directory '" . $_new_dir . "'"); 70 | return false; 71 | } 72 | $_new_dir .= '/'; 73 | } 74 | } 75 | } 76 | 77 | /* vim: set expandtab: */ 78 | 79 | ?> 80 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.display_debug_console.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: display_debug_console
13 | * Purpose: display the javascript debug console window 14 | * @param array Format: null 15 | * @param Smarty 16 | */ 17 | function smarty_core_display_debug_console($params, &$smarty) 18 | { 19 | // we must force compile the debug template in case the environment 20 | // changed between separate applications. 21 | 22 | if(empty($smarty->debug_tpl)) { 23 | // set path to debug template from SMARTY_DIR 24 | $smarty->debug_tpl = SMARTY_DIR . 'debug.tpl'; 25 | if($smarty->security && is_file($smarty->debug_tpl)) { 26 | $smarty->secure_dir[] = realpath($smarty->debug_tpl); 27 | } 28 | $smarty->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl'; 29 | } 30 | 31 | $_ldelim_orig = $smarty->left_delimiter; 32 | $_rdelim_orig = $smarty->right_delimiter; 33 | 34 | $smarty->left_delimiter = '{'; 35 | $smarty->right_delimiter = '}'; 36 | 37 | $_compile_id_orig = $smarty->_compile_id; 38 | $smarty->_compile_id = null; 39 | 40 | $_compile_path = $smarty->_get_compile_path($smarty->debug_tpl); 41 | if ($smarty->_compile_resource($smarty->debug_tpl, $_compile_path)) 42 | { 43 | ob_start(); 44 | $smarty->_include($_compile_path); 45 | $_results = ob_get_contents(); 46 | ob_end_clean(); 47 | } else { 48 | $_results = ''; 49 | } 50 | 51 | $smarty->_compile_id = $_compile_id_orig; 52 | 53 | $smarty->left_delimiter = $_ldelim_orig; 54 | $smarty->right_delimiter = $_rdelim_orig; 55 | 56 | return $_results; 57 | } 58 | 59 | /* vim: set expandtab: */ 60 | 61 | ?> 62 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.get_include_path.php: -------------------------------------------------------------------------------- 1 | 45 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.get_microtime.php: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.get_php_resource.php: -------------------------------------------------------------------------------- 1 | trusted_dir; 22 | $smarty->_parse_resource_name($params, $smarty); 23 | 24 | /* 25 | * Find out if the resource exists. 26 | */ 27 | 28 | if ($params['resource_type'] == 'file') { 29 | $_readable = false; 30 | if(file_exists($params['resource_name']) && is_readable($params['resource_name'])) { 31 | $_readable = true; 32 | } else { 33 | // test for file in include_path 34 | $_params = array('file_path' => $params['resource_name']); 35 | require_once(SMARTY_CORE_DIR . 'core.get_include_path.php'); 36 | if(smarty_core_get_include_path($_params, $smarty)) { 37 | $_include_path = $_params['new_file_path']; 38 | $_readable = true; 39 | } 40 | } 41 | } else if ($params['resource_type'] != 'file') { 42 | $_template_source = null; 43 | $_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0]) 44 | && call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0], 45 | array($params['resource_name'], &$_template_source, &$smarty)); 46 | } 47 | 48 | /* 49 | * Set the error function, depending on which class calls us. 50 | */ 51 | if (method_exists($smarty, '_syntax_error')) { 52 | $_error_funcc = '_syntax_error'; 53 | } else { 54 | $_error_funcc = 'trigger_error'; 55 | } 56 | 57 | if ($_readable) { 58 | if ($smarty->security) { 59 | require_once(SMARTY_CORE_DIR . 'core.is_trusted.php'); 60 | if (!smarty_core_is_trusted($params, $smarty)) { 61 | $smarty->$_error_funcc('(secure mode) ' . $params['resource_type'] . ':' . $params['resource_name'] . ' is not trusted'); 62 | return false; 63 | } 64 | } 65 | } else { 66 | $smarty->$_error_funcc($params['resource_type'] . ':' . $params['resource_name'] . ' is not readable'); 67 | return false; 68 | } 69 | 70 | if ($params['resource_type'] == 'file') { 71 | $params['php_resource'] = $params['resource_name']; 72 | } else { 73 | $params['php_resource'] = $_template_source; 74 | } 75 | return true; 76 | } 77 | 78 | /* vim: set expandtab: */ 79 | 80 | ?> 81 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.is_secure.php: -------------------------------------------------------------------------------- 1 | security || $smarty->security_settings['INCLUDE_ANY']) { 21 | return true; 22 | } 23 | 24 | if ($params['resource_type'] == 'file') { 25 | $_rp = realpath($params['resource_name']); 26 | if (isset($params['resource_base_path'])) { 27 | foreach ((array)$params['resource_base_path'] as $curr_dir) { 28 | if ( ($_cd = realpath($curr_dir)) !== false && 29 | strncmp($_rp, $_cd, strlen($_cd)) == 0 && 30 | substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) { 31 | return true; 32 | } 33 | } 34 | } 35 | if (!empty($smarty->secure_dir)) { 36 | foreach ((array)$smarty->secure_dir as $curr_dir) { 37 | if ( ($_cd = realpath($curr_dir)) !== false) { 38 | if($_cd == $_rp) { 39 | return true; 40 | } elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && 41 | substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) { 42 | return true; 43 | } 44 | } 45 | } 46 | } 47 | } else { 48 | // resource is not on local file system 49 | return call_user_func_array( 50 | $smarty->_plugins['resource'][$params['resource_type']][0][2], 51 | array($params['resource_name'], &$smarty)); 52 | } 53 | 54 | return false; 55 | } 56 | 57 | /* vim: set expandtab: */ 58 | 59 | ?> 60 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.is_trusted.php: -------------------------------------------------------------------------------- 1 | trusted_dir)) { 23 | $_rp = realpath($params['resource_name']); 24 | foreach ((array)$smarty->trusted_dir as $curr_dir) { 25 | if (!empty($curr_dir) && is_readable ($curr_dir)) { 26 | $_cd = realpath($curr_dir); 27 | if (strncmp($_rp, $_cd, strlen($_cd)) == 0 28 | && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) { 29 | $_smarty_trusted = true; 30 | break; 31 | } 32 | } 33 | } 34 | } 35 | 36 | } else { 37 | // resource is not on local file system 38 | $_smarty_trusted = call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][3], 39 | array($params['resource_name'], $smarty)); 40 | } 41 | 42 | return $_smarty_trusted; 43 | } 44 | 45 | /* vim: set expandtab: */ 46 | 47 | ?> 48 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.load_plugins.php: -------------------------------------------------------------------------------- 1 | _plugins[$_type][$_name]; 22 | 23 | /* 24 | * We do not load plugin more than once for each instance of Smarty. 25 | * The following code checks for that. The plugin can also be 26 | * registered dynamically at runtime, in which case template file 27 | * and line number will be unknown, so we fill them in. 28 | * 29 | * The final element of the info array is a flag that indicates 30 | * whether the dynamically registered plugin function has been 31 | * checked for existence yet or not. 32 | */ 33 | if (isset($_plugin)) { 34 | if (empty($_plugin[3])) { 35 | if (!is_callable($_plugin[0])) { 36 | $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__); 37 | } else { 38 | $_plugin[1] = $_tpl_file; 39 | $_plugin[2] = $_tpl_line; 40 | $_plugin[3] = true; 41 | if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */ 42 | } 43 | } 44 | continue; 45 | } else if ($_type == 'insert') { 46 | /* 47 | * For backwards compatibility, we check for insert functions in 48 | * the symbol table before trying to load them as a plugin. 49 | */ 50 | $_plugin_func = 'insert_' . $_name; 51 | if (function_exists($_plugin_func)) { 52 | $_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false); 53 | continue; 54 | } 55 | } 56 | 57 | $_plugin_file = $smarty->_get_plugin_filepath($_type, $_name); 58 | 59 | if (! $_found = ($_plugin_file != false)) { 60 | $_message = "could not load plugin file '$_type.$_name.php'\n"; 61 | } 62 | 63 | /* 64 | * If plugin file is found, it -must- provide the properly named 65 | * plugin function. In case it doesn't, simply output the error and 66 | * do not fall back on any other method. 67 | */ 68 | if ($_found) { 69 | include_once $_plugin_file; 70 | 71 | $_plugin_func = 'smarty_' . $_type . '_' . $_name; 72 | if (!function_exists($_plugin_func)) { 73 | $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__); 74 | continue; 75 | } 76 | } 77 | /* 78 | * In case of insert plugins, their code may be loaded later via 79 | * 'script' attribute. 80 | */ 81 | else if ($_type == 'insert' && $_delayed_loading) { 82 | $_plugin_func = 'smarty_' . $_type . '_' . $_name; 83 | $_found = true; 84 | } 85 | 86 | /* 87 | * Plugin specific processing and error checking. 88 | */ 89 | if (!$_found) { 90 | if ($_type == 'modifier') { 91 | /* 92 | * In case modifier falls back on using PHP functions 93 | * directly, we only allow those specified in the security 94 | * context. 95 | */ 96 | if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) { 97 | $_message = "(secure mode) modifier '$_name' is not allowed"; 98 | } else { 99 | if (!function_exists($_name)) { 100 | $_message = "modifier '$_name' is not implemented"; 101 | } else { 102 | $_plugin_func = $_name; 103 | $_found = true; 104 | } 105 | } 106 | } else if ($_type == 'function') { 107 | /* 108 | * This is a catch-all situation. 109 | */ 110 | $_message = "unknown tag - '$_name'"; 111 | } 112 | } 113 | 114 | if ($_found) { 115 | $smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true); 116 | } else { 117 | // output error 118 | $smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__); 119 | } 120 | } 121 | } 122 | 123 | /* vim: set expandtab: */ 124 | 125 | ?> 126 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.load_resource_plugin.php: -------------------------------------------------------------------------------- 1 | _plugins['resource'][$params['type']]; 26 | if (isset($_plugin)) { 27 | if (!$_plugin[1] && count($_plugin[0])) { 28 | $_plugin[1] = true; 29 | foreach ($_plugin[0] as $_plugin_func) { 30 | if (!is_callable($_plugin_func)) { 31 | $_plugin[1] = false; 32 | break; 33 | } 34 | } 35 | } 36 | 37 | if (!$_plugin[1]) { 38 | $smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__); 39 | } 40 | 41 | return; 42 | } 43 | 44 | $_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']); 45 | $_found = ($_plugin_file != false); 46 | 47 | if ($_found) { /* 48 | * If the plugin file is found, it -must- provide the properly named 49 | * plugin functions. 50 | */ 51 | include_once($_plugin_file); 52 | 53 | /* 54 | * Locate functions that we require the plugin to provide. 55 | */ 56 | $_resource_ops = array('source', 'timestamp', 'secure', 'trusted'); 57 | $_resource_funcs = array(); 58 | foreach ($_resource_ops as $_op) { 59 | $_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op; 60 | if (!function_exists($_plugin_func)) { 61 | $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__); 62 | return; 63 | } else { 64 | $_resource_funcs[] = $_plugin_func; 65 | } 66 | } 67 | 68 | $smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true); 69 | } 70 | } 71 | 72 | /* vim: set expandtab: */ 73 | 74 | ?> 75 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.process_cached_inserts.php: -------------------------------------------------------------------------------- 1 | _smarty_md5.'{insert_cache (.*)}'.$smarty->_smarty_md5.'!Uis', 17 | $params['results'], $match); 18 | list($cached_inserts, $insert_args) = $match; 19 | 20 | for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { 21 | if ($smarty->debugging) { 22 | $_params = array(); 23 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 24 | $debug_start_time = smarty_core_get_microtime($_params, $smarty); 25 | } 26 | 27 | $args = unserialize($insert_args[$i]); 28 | $name = $args['name']; 29 | 30 | if (isset($args['script'])) { 31 | $_params = array('resource_name' => $smarty->_dequote($args['script'])); 32 | require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); 33 | if(!smarty_core_get_php_resource($_params, $smarty)) { 34 | return false; 35 | } 36 | $resource_type = $_params['resource_type']; 37 | $php_resource = $_params['php_resource']; 38 | 39 | 40 | if ($resource_type == 'file') { 41 | $smarty->_include($php_resource, true); 42 | } else { 43 | $smarty->_eval($php_resource); 44 | } 45 | } 46 | 47 | $function_name = $smarty->_plugins['insert'][$name][0]; 48 | if (empty($args['assign'])) { 49 | $replace = $function_name($args, $smarty); 50 | } else { 51 | $smarty->assign($args['assign'], $function_name($args, $smarty)); 52 | $replace = ''; 53 | } 54 | 55 | $params['results'] = substr_replace($params['results'], $replace, strpos($params['results'], $cached_inserts[$i]), strlen($cached_inserts[$i])); 56 | if ($smarty->debugging) { 57 | $_params = array(); 58 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 59 | $smarty->_smarty_debug_info[] = array('type' => 'insert', 60 | 'filename' => 'insert_'.$name, 61 | 'depth' => $smarty->_inclusion_depth, 62 | 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $debug_start_time); 63 | } 64 | } 65 | 66 | return $params['results']; 67 | } 68 | 69 | /* vim: set expandtab: */ 70 | 71 | ?> 72 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.process_compiled_include.php: -------------------------------------------------------------------------------- 1 | _cache_including; 20 | $smarty->_cache_including = true; 21 | 22 | $_return = $params['results']; 23 | 24 | foreach ($smarty->_cache_info['cache_serials'] as $_include_file_path=>$_cache_serial) { 25 | $smarty->_include($_include_file_path, true); 26 | } 27 | 28 | foreach ($smarty->_cache_serials as $_include_file_path=>$_cache_serial) { 29 | $_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s', 30 | array(&$smarty, '_process_compiled_include_callback'), 31 | $_return); 32 | } 33 | $smarty->_cache_including = $_cache_including; 34 | return $_return; 35 | } 36 | 37 | ?> 38 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.read_cache_file.php: -------------------------------------------------------------------------------- 1 | force_compile) { 26 | // force compile enabled, always regenerate 27 | return false; 28 | } 29 | 30 | if (isset($content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']])) { 31 | list($params['results'], $smarty->_cache_info) = $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']]; 32 | return true; 33 | } 34 | 35 | if (!empty($smarty->cache_handler_func)) { 36 | // use cache_handler function 37 | call_user_func_array($smarty->cache_handler_func, 38 | array('read', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null)); 39 | } else { 40 | // use local cache file 41 | $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']); 42 | $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id); 43 | $params['results'] = $smarty->_read_file($_cache_file); 44 | } 45 | 46 | if (empty($params['results'])) { 47 | // nothing to parse (error?), regenerate cache 48 | return false; 49 | } 50 | 51 | $_contents = $params['results']; 52 | $_info_start = strpos($_contents, "\n") + 1; 53 | $_info_len = (int)substr($_contents, 0, $_info_start - 1); 54 | $_cache_info = unserialize(substr($_contents, $_info_start, $_info_len)); 55 | $params['results'] = substr($_contents, $_info_start + $_info_len); 56 | 57 | if ($smarty->caching == 2 && isset ($_cache_info['expires'])){ 58 | // caching by expiration time 59 | if ($_cache_info['expires'] > -1 && (time() > $_cache_info['expires'])) { 60 | // cache expired, regenerate 61 | return false; 62 | } 63 | } else { 64 | // caching by lifetime 65 | if ($smarty->cache_lifetime > -1 && (time() - $_cache_info['timestamp'] > $smarty->cache_lifetime)) { 66 | // cache expired, regenerate 67 | return false; 68 | } 69 | } 70 | 71 | if ($smarty->compile_check) { 72 | $_params = array('get_source' => false, 'quiet'=>true); 73 | foreach (array_keys($_cache_info['template']) as $_template_dep) { 74 | $_params['resource_name'] = $_template_dep; 75 | if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) { 76 | // template file has changed, regenerate cache 77 | return false; 78 | } 79 | } 80 | 81 | if (isset($_cache_info['config'])) { 82 | $_params = array('resource_base_path' => $smarty->config_dir, 'get_source' => false, 'quiet'=>true); 83 | foreach (array_keys($_cache_info['config']) as $_config_dep) { 84 | $_params['resource_name'] = $_config_dep; 85 | if (!$smarty->_fetch_resource_info($_params) || $_cache_info['timestamp'] < $_params['resource_timestamp']) { 86 | // config file has changed, regenerate cache 87 | return false; 88 | } 89 | } 90 | } 91 | } 92 | 93 | $content_cache[$params['tpl_file'].','.$params['cache_id'].','.$params['compile_id']] = array($params['results'], $_cache_info); 94 | 95 | $smarty->_cache_info = $_cache_info; 96 | return true; 97 | } 98 | 99 | /* vim: set expandtab: */ 100 | 101 | ?> 102 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.rm_auto.php: -------------------------------------------------------------------------------- 1 | $params['auto_base'], 28 | 'level' => 0, 29 | 'exp_time' => $params['exp_time'] 30 | ); 31 | require_once(SMARTY_CORE_DIR . 'core.rmdir.php'); 32 | $_res = smarty_core_rmdir($_params, $smarty); 33 | } else { 34 | $_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']); 35 | 36 | if(isset($params['auto_source'])) { 37 | if (isset($params['extensions'])) { 38 | $_res = false; 39 | foreach ((array)$params['extensions'] as $_extension) 40 | $_res |= $smarty->_unlink($_tname.$_extension, $params['exp_time']); 41 | } else { 42 | $_res = $smarty->_unlink($_tname, $params['exp_time']); 43 | } 44 | } elseif ($smarty->use_sub_dirs) { 45 | $_params = array( 46 | 'dirname' => $_tname, 47 | 'level' => 1, 48 | 'exp_time' => $params['exp_time'] 49 | ); 50 | require_once(SMARTY_CORE_DIR . 'core.rmdir.php'); 51 | $_res = smarty_core_rmdir($_params, $smarty); 52 | } else { 53 | // remove matching file names 54 | $_handle = opendir($params['auto_base']); 55 | $_res = true; 56 | while (false !== ($_filename = readdir($_handle))) { 57 | if($_filename == '.' || $_filename == '..') { 58 | continue; 59 | } elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) { 60 | $_res &= (bool)$smarty->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']); 61 | } 62 | } 63 | } 64 | } 65 | 66 | return $_res; 67 | } 68 | 69 | /* vim: set expandtab: */ 70 | 71 | ?> 72 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.rmdir.php: -------------------------------------------------------------------------------- 1 | keep root) 10 | * WARNING: no tests, it will try to remove what you tell it! 11 | * 12 | * @param string $dirname 13 | * @param integer $level 14 | * @param integer $exp_time 15 | * @return boolean 16 | */ 17 | 18 | // $dirname, $level = 1, $exp_time = null 19 | 20 | function smarty_core_rmdir($params, &$smarty) 21 | { 22 | if(!isset($params['level'])) { $params['level'] = 1; } 23 | if(!isset($params['exp_time'])) { $params['exp_time'] = null; } 24 | 25 | if($_handle = @opendir($params['dirname'])) { 26 | 27 | while (false !== ($_entry = readdir($_handle))) { 28 | if ($_entry != '.' && $_entry != '..') { 29 | if (@is_dir($params['dirname'] . DIRECTORY_SEPARATOR . $_entry)) { 30 | $_params = array( 31 | 'dirname' => $params['dirname'] . DIRECTORY_SEPARATOR . $_entry, 32 | 'level' => $params['level'] + 1, 33 | 'exp_time' => $params['exp_time'] 34 | ); 35 | smarty_core_rmdir($_params, $smarty); 36 | } 37 | else { 38 | $smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']); 39 | } 40 | } 41 | } 42 | closedir($_handle); 43 | } 44 | 45 | if ($params['level']) { 46 | return @rmdir($params['dirname']); 47 | } 48 | return (bool)$_handle; 49 | 50 | } 51 | 52 | /* vim: set expandtab: */ 53 | 54 | ?> 55 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.run_insert_handler.php: -------------------------------------------------------------------------------- 1 | debugging) { 19 | $_params = array(); 20 | $_debug_start_time = smarty_core_get_microtime($_params, $smarty); 21 | } 22 | 23 | if ($smarty->caching) { 24 | $_arg_string = serialize($params['args']); 25 | $_name = $params['args']['name']; 26 | if (!isset($smarty->_cache_info['insert_tags'][$_name])) { 27 | $smarty->_cache_info['insert_tags'][$_name] = array('insert', 28 | $_name, 29 | $smarty->_plugins['insert'][$_name][1], 30 | $smarty->_plugins['insert'][$_name][2], 31 | !empty($params['args']['script']) ? true : false); 32 | } 33 | return $smarty->_smarty_md5."{insert_cache $_arg_string}".$smarty->_smarty_md5; 34 | } else { 35 | if (isset($params['args']['script'])) { 36 | $_params = array('resource_name' => $smarty->_dequote($params['args']['script'])); 37 | require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); 38 | if(!smarty_core_get_php_resource($_params, $smarty)) { 39 | return false; 40 | } 41 | 42 | if ($_params['resource_type'] == 'file') { 43 | $smarty->_include($_params['php_resource'], true); 44 | } else { 45 | $smarty->_eval($_params['php_resource']); 46 | } 47 | unset($params['args']['script']); 48 | } 49 | 50 | $_funcname = $smarty->_plugins['insert'][$params['args']['name']][0]; 51 | $_content = $_funcname($params['args'], $smarty); 52 | if ($smarty->debugging) { 53 | $_params = array(); 54 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 55 | $smarty->_smarty_debug_info[] = array('type' => 'insert', 56 | 'filename' => 'insert_'.$params['args']['name'], 57 | 'depth' => $smarty->_inclusion_depth, 58 | 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time); 59 | } 60 | 61 | if (!empty($params['args']["assign"])) { 62 | $smarty->assign($params['args']["assign"], $_content); 63 | } else { 64 | return $_content; 65 | } 66 | } 67 | } 68 | 69 | /* vim: set expandtab: */ 70 | 71 | ?> 72 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.smarty_include_php.php: -------------------------------------------------------------------------------- 1 | $params['smarty_file']); 24 | require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php'); 25 | smarty_core_get_php_resource($_params, $smarty); 26 | $_smarty_resource_type = $_params['resource_type']; 27 | $_smarty_php_resource = $_params['php_resource']; 28 | 29 | if (!empty($params['smarty_assign'])) { 30 | ob_start(); 31 | if ($_smarty_resource_type == 'file') { 32 | $smarty->_include($_smarty_php_resource, $params['smarty_once'], $params['smarty_include_vars']); 33 | } else { 34 | $smarty->_eval($_smarty_php_resource, $params['smarty_include_vars']); 35 | } 36 | $smarty->assign($params['smarty_assign'], ob_get_contents()); 37 | ob_end_clean(); 38 | } else { 39 | if ($_smarty_resource_type == 'file') { 40 | $smarty->_include($_smarty_php_resource, $params['smarty_once'], $params['smarty_include_vars']); 41 | } else { 42 | $smarty->_eval($_smarty_php_resource, $params['smarty_include_vars']); 43 | } 44 | } 45 | } 46 | 47 | 48 | /* vim: set expandtab: */ 49 | 50 | ?> 51 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.write_cache_file.php: -------------------------------------------------------------------------------- 1 | _cache_info['timestamp'] = time(); 26 | if ($smarty->cache_lifetime > -1){ 27 | // expiration set 28 | $smarty->_cache_info['expires'] = $smarty->_cache_info['timestamp'] + $smarty->cache_lifetime; 29 | } else { 30 | // cache will never expire 31 | $smarty->_cache_info['expires'] = -1; 32 | } 33 | 34 | // collapse nocache.../nocache-tags 35 | if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) { 36 | // remove everything between every pair of outermost noache.../nocache-tags 37 | // and replace it by a single nocache-tag 38 | // this new nocache-tag will be replaced by dynamic contents in 39 | // smarty_core_process_compiled_includes() on a cache-read 40 | 41 | $match_count = count($match[0]); 42 | $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE); 43 | 44 | $level = 0; 45 | $j = 0; 46 | for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) { 47 | if ($results[$i] == $match[0][$j]) { 48 | // nocache tag 49 | if ($match[1][$j]) { // closing tag 50 | $level--; 51 | unset($results[$i]); 52 | } else { // opening tag 53 | if ($level++ > 0) unset($results[$i]); 54 | } 55 | $j++; 56 | } elseif ($level > 0) { 57 | unset($results[$i]); 58 | } 59 | } 60 | $params['results'] = implode('', $results); 61 | } 62 | $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials; 63 | 64 | // prepend the cache header info into cache file 65 | $_cache_info = serialize($smarty->_cache_info); 66 | $params['results'] = strlen($_cache_info) . "\n" . $_cache_info . $params['results']; 67 | 68 | if (!empty($smarty->cache_handler_func)) { 69 | // use cache_handler function 70 | call_user_func_array($smarty->cache_handler_func, 71 | array('write', &$smarty, &$params['results'], $params['tpl_file'], $params['cache_id'], $params['compile_id'], null)); 72 | } else { 73 | // use local cache file 74 | 75 | if(!@is_writable($smarty->cache_dir)) { 76 | // cache_dir not writable, see if it exists 77 | if(!@is_dir($smarty->cache_dir)) { 78 | $smarty->trigger_error('the $cache_dir \'' . $smarty->cache_dir . '\' does not exist, or is not a directory.', E_USER_ERROR); 79 | return false; 80 | } 81 | $smarty->trigger_error('unable to write to $cache_dir \'' . realpath($smarty->cache_dir) . '\'. Be sure $cache_dir is writable by the web server user.', E_USER_ERROR); 82 | return false; 83 | } 84 | 85 | $_auto_id = $smarty->_get_auto_id($params['cache_id'], $params['compile_id']); 86 | $_cache_file = $smarty->_get_auto_filename($smarty->cache_dir, $params['tpl_file'], $_auto_id); 87 | $_params = array('filename' => $_cache_file, 'contents' => $params['results'], 'create_dirs' => true); 88 | require_once(SMARTY_CORE_DIR . 'core.write_file.php'); 89 | smarty_core_write_file($_params, $smarty); 90 | return true; 91 | } 92 | } 93 | 94 | /* vim: set expandtab: */ 95 | 96 | ?> 97 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.write_compiled_include.php: -------------------------------------------------------------------------------- 1 | caching && \!\$this->_cache_including\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\'; \};'; 19 | $_tag_end = 'if \(\$this->caching && \!\$this->_cache_including\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\'; \};'; 20 | 21 | preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us', 22 | $params['compiled_content'], $_match_source, PREG_SET_ORDER); 23 | 24 | // no nocache-parts found: done 25 | if (count($_match_source)==0) return; 26 | 27 | // convert the matched php-code to functions 28 | $_include_compiled = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; 29 | $_include_compiled .= " compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */\n\n"; 30 | 31 | $_compile_path = $params['include_file_path']; 32 | 33 | $smarty->_cache_serials[$_compile_path] = $params['cache_serial']; 34 | $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>"; 35 | 36 | $_include_compiled .= $params['plugins_code']; 37 | $_include_compiled .= "= 5.0) ? '_smarty' : 'this'; 40 | for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) { 41 | $_match =& $_match_source[$_i]; 42 | $source = $_match[4]; 43 | if ($this_varname == '_smarty') { 44 | /* rename $this to $_smarty in the sourcecode */ 45 | $tokens = token_get_all('\n"; 81 | 82 | $_params = array('filename' => $_compile_path, 83 | 'contents' => $_include_compiled, 'create_dirs' => true); 84 | 85 | require_once(SMARTY_CORE_DIR . 'core.write_file.php'); 86 | smarty_core_write_file($_params, $smarty); 87 | return true; 88 | } 89 | 90 | 91 | ?> 92 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.write_compiled_resource.php: -------------------------------------------------------------------------------- 1 | compile_dir)) { 18 | // compile_dir not writable, see if it exists 19 | if(!@is_dir($smarty->compile_dir)) { 20 | $smarty->trigger_error('the $compile_dir \'' . $smarty->compile_dir . '\' does not exist, or is not a directory.', E_USER_ERROR); 21 | return false; 22 | } 23 | $smarty->trigger_error('unable to write to $compile_dir \'' . realpath($smarty->compile_dir) . '\'. Be sure $compile_dir is writable by the web server user.', E_USER_ERROR); 24 | return false; 25 | } 26 | 27 | $_params = array('filename' => $params['compile_path'], 'contents' => $params['compiled_content'], 'create_dirs' => true); 28 | require_once(SMARTY_CORE_DIR . 'core.write_file.php'); 29 | smarty_core_write_file($_params, $smarty); 30 | return true; 31 | } 32 | 33 | /* vim: set expandtab: */ 34 | 35 | ?> 36 | -------------------------------------------------------------------------------- /include/Smarty/internals/core.write_file.php: -------------------------------------------------------------------------------- 1 | $_dirname); 22 | require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php'); 23 | smarty_core_create_dir_structure($_params, $smarty); 24 | } 25 | 26 | // write to tmp file, then rename it to avoid 27 | // file locking race condition 28 | $_tmp_file = tempnam($_dirname, 'wrt'); 29 | 30 | if (!($fd = @fopen($_tmp_file, 'wb'))) { 31 | $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt'); 32 | if (!($fd = @fopen($_tmp_file, 'wb'))) { 33 | $smarty->trigger_error("problem writing temporary file '$_tmp_file'"); 34 | return false; 35 | } 36 | } 37 | 38 | fwrite($fd, $params['contents']); 39 | fclose($fd); 40 | 41 | // Delete the file if it allready exists (this is needed on Win, 42 | // because it cannot overwrite files with rename() 43 | if (file_exists($params['filename'])) { 44 | @unlink($params['filename']); 45 | } 46 | @rename($_tmp_file, $params['filename']); 47 | @chmod($params['filename'], $smarty->_file_perms); 48 | 49 | return true; 50 | } 51 | 52 | /* vim: set expandtab: */ 53 | 54 | ?> 55 | -------------------------------------------------------------------------------- /include/Smarty/plugins/block.textformat.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: textformat
13 | * Purpose: format text a certain way with preset styles 14 | * or custom wrap/indent settings
15 | * @link http://smarty.php.net/manual/en/language.function.textformat.php {textformat} 16 | * (Smarty online manual) 17 | * @param array 18 | *
 19 |  * Params:   style: string (email)
 20 |  *           indent: integer (0)
 21 |  *           wrap: integer (80)
 22 |  *           wrap_char string ("\n")
 23 |  *           indent_char: string (" ")
 24 |  *           wrap_boundary: boolean (true)
 25 |  * 
26 | * @author Monte Ohrt 27 | * @param string contents of the block 28 | * @param Smarty clever simulation of a method 29 | * @return string string $content re-formatted 30 | */ 31 | function smarty_block_textformat($params, $content, &$smarty) 32 | { 33 | if (is_null($content)) { 34 | return; 35 | } 36 | 37 | $style = null; 38 | $indent = 0; 39 | $indent_first = 0; 40 | $indent_char = ' '; 41 | $wrap = 80; 42 | $wrap_char = "\n"; 43 | $wrap_cut = false; 44 | $assign = null; 45 | 46 | foreach ($params as $_key => $_val) { 47 | switch ($_key) { 48 | case 'style': 49 | case 'indent_char': 50 | case 'wrap_char': 51 | case 'assign': 52 | $$_key = (string)$_val; 53 | break; 54 | 55 | case 'indent': 56 | case 'indent_first': 57 | case 'wrap': 58 | $$_key = (int)$_val; 59 | break; 60 | 61 | case 'wrap_cut': 62 | $$_key = (bool)$_val; 63 | break; 64 | 65 | default: 66 | $smarty->trigger_error("textformat: unknown attribute '$_key'"); 67 | } 68 | } 69 | 70 | if ($style == 'email') { 71 | $wrap = 72; 72 | } 73 | 74 | // split into paragraphs 75 | $_paragraphs = preg_split('![\r\n][\r\n]!',$content); 76 | $_output = ''; 77 | 78 | for($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { 79 | if ($_paragraphs[$_x] == '') { 80 | continue; 81 | } 82 | // convert mult. spaces & special chars to single space 83 | $_paragraphs[$_x] = preg_replace(array('!\s+!','!(^\s+)|(\s+$)!'), array(' ',''), $_paragraphs[$_x]); 84 | // indent first line 85 | if($indent_first > 0) { 86 | $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x]; 87 | } 88 | // wordwrap sentences 89 | $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); 90 | // indent lines 91 | if($indent > 0) { 92 | $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]); 93 | } 94 | } 95 | $_output = implode($wrap_char . $wrap_char, $_paragraphs); 96 | 97 | return $assign ? $smarty->assign($assign, $_output) : $_output; 98 | 99 | } 100 | 101 | /* vim: set expandtab: */ 102 | 103 | ?> 104 | -------------------------------------------------------------------------------- /include/Smarty/plugins/compiler.assign.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: assign
13 | * Purpose: assign a value to a template variable 14 | * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign} 15 | * (Smarty online manual) 16 | * @author Monte Ohrt (initial author) 17 | * @auther messju mohr (conversion to compiler function) 18 | * @param string containing var-attribute and value-attribute 19 | * @param Smarty_Compiler 20 | */ 21 | function smarty_compiler_assign($tag_attrs, &$compiler) 22 | { 23 | $_params = $compiler->_parse_attrs($tag_attrs); 24 | 25 | if (!isset($_params['var'])) { 26 | $compiler->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING); 27 | return; 28 | } 29 | 30 | if (!isset($_params['value'])) { 31 | $compiler->_syntax_error("assign: missing 'value' parameter", E_USER_WARNING); 32 | return; 33 | } 34 | 35 | return "\$this->assign({$_params['var']}, {$_params['value']});"; 36 | } 37 | 38 | /* vim: set expandtab: */ 39 | 40 | ?> 41 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.assign_debug_info.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: assign_debug_info
13 | * Purpose: assign debug info to the template
14 | * @author Monte Ohrt 15 | * @param array unused in this plugin, this plugin uses {@link Smarty::$_config}, 16 | * {@link Smarty::$_tpl_vars} and {@link Smarty::$_smarty_debug_info} 17 | * @param Smarty 18 | */ 19 | function smarty_function_assign_debug_info($params, &$smarty) 20 | { 21 | $assigned_vars = $smarty->_tpl_vars; 22 | ksort($assigned_vars); 23 | if (@is_array($smarty->_config[0])) { 24 | $config_vars = $smarty->_config[0]; 25 | ksort($config_vars); 26 | $smarty->assign("_debug_config_keys", array_keys($config_vars)); 27 | $smarty->assign("_debug_config_vals", array_values($config_vars)); 28 | } 29 | 30 | $included_templates = $smarty->_smarty_debug_info; 31 | 32 | $smarty->assign("_debug_keys", array_keys($assigned_vars)); 33 | $smarty->assign("_debug_vals", array_values($assigned_vars)); 34 | 35 | $smarty->assign("_debug_tpls", $included_templates); 36 | } 37 | 38 | /* vim: set expandtab: */ 39 | 40 | ?> 41 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.config_load.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: config_load
13 | * Purpose: load config file vars 14 | * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load} 15 | * (Smarty online manual) 16 | * @author Monte Ohrt 17 | * @author messju mohr (added use of resources) 18 | * @param array Format: 19 | *
 20 |  * array('file' => required config file name,
 21 |  *       'section' => optional config file section to load
 22 |  *       'scope' => local/parent/global
 23 |  *       'global' => overrides scope, setting to parent if true)
 24 |  * 
25 | * @param Smarty 26 | */ 27 | function smarty_function_config_load($params, &$smarty) 28 | { 29 | if ($smarty->debugging) { 30 | $_params = array(); 31 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 32 | $_debug_start_time = smarty_core_get_microtime($_params, $smarty); 33 | } 34 | 35 | $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null; 36 | $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null; 37 | $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global'; 38 | $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false; 39 | 40 | if (!isset($_file) || strlen($_file) == 0) { 41 | $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__); 42 | } 43 | 44 | if (isset($_scope)) { 45 | if ($_scope != 'local' && 46 | $_scope != 'parent' && 47 | $_scope != 'global') { 48 | $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__); 49 | } 50 | } else { 51 | if ($_global) { 52 | $_scope = 'parent'; 53 | } else { 54 | $_scope = 'local'; 55 | } 56 | } 57 | 58 | $_params = array('resource_name' => $_file, 59 | 'resource_base_path' => $smarty->config_dir, 60 | 'get_source' => false); 61 | $smarty->_parse_resource_name($_params); 62 | $_file_path = $_params['resource_type'] . ':' . $_params['resource_name']; 63 | if (isset($_section)) 64 | $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section); 65 | else 66 | $_compile_file = $smarty->_get_compile_path($_file_path); 67 | 68 | if($smarty->force_compile || !file_exists($_compile_file)) { 69 | $_compile = true; 70 | } elseif ($smarty->compile_check) { 71 | $_params = array('resource_name' => $_file, 72 | 'resource_base_path' => $smarty->config_dir, 73 | 'get_source' => false); 74 | $_compile = $smarty->_fetch_resource_info($_params) && 75 | $_params['resource_timestamp'] > filemtime($_compile_file); 76 | } else { 77 | $_compile = false; 78 | } 79 | 80 | if($_compile) { 81 | // compile config file 82 | if(!is_object($smarty->_conf_obj)) { 83 | require_once SMARTY_DIR . $smarty->config_class . '.class.php'; 84 | $smarty->_conf_obj = new $smarty->config_class(); 85 | $smarty->_conf_obj->overwrite = $smarty->config_overwrite; 86 | $smarty->_conf_obj->booleanize = $smarty->config_booleanize; 87 | $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden; 88 | $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines; 89 | } 90 | 91 | $_params = array('resource_name' => $_file, 92 | 'resource_base_path' => $smarty->config_dir, 93 | $_params['get_source'] = true); 94 | if (!$smarty->_fetch_resource_info($_params)) { 95 | return; 96 | } 97 | $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']); 98 | $_config_vars = array_merge($smarty->_conf_obj->get($_file), 99 | $smarty->_conf_obj->get($_file, $_section)); 100 | if(function_exists('var_export')) { 101 | $_output = ''; 102 | } else { 103 | $_output = ''\\\'', '\\'=>'\\\\')) . '\'); ?>'; 104 | } 105 | $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp'])); 106 | require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); 107 | smarty_core_write_compiled_resource($_params, $smarty); 108 | } else { 109 | include($_compile_file); 110 | } 111 | 112 | if ($smarty->caching) { 113 | $smarty->_cache_info['config'][$_file] = true; 114 | } 115 | 116 | $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars); 117 | $smarty->_config[0]['files'][$_file] = true; 118 | 119 | if ($_scope == 'parent') { 120 | $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars); 121 | $smarty->_config[1]['files'][$_file] = true; 122 | } else if ($_scope == 'global') { 123 | for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) { 124 | $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars); 125 | $smarty->_config[$i]['files'][$_file] = true; 126 | } 127 | } 128 | 129 | if ($smarty->debugging) { 130 | $_params = array(); 131 | require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); 132 | $smarty->_smarty_debug_info[] = array('type' => 'config', 133 | 'filename' => $_file.' ['.$_section.'] '.$_scope, 134 | 'depth' => $smarty->_inclusion_depth, 135 | 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time); 136 | } 137 | 138 | } 139 | 140 | /* vim: set expandtab: */ 141 | 142 | ?> 143 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.counter.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: counter
14 | * Purpose: print out a counter value 15 | * @author Monte Ohrt 16 | * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} 17 | * (Smarty online manual) 18 | * @param array parameters 19 | * @param Smarty 20 | * @return string|null 21 | */ 22 | function smarty_function_counter($params, &$smarty) 23 | { 24 | static $counters = array(); 25 | 26 | $name = (isset($params['name'])) ? $params['name'] : 'default'; 27 | if (!isset($counters[$name])) { 28 | $counters[$name] = array( 29 | 'start'=>1, 30 | 'skip'=>1, 31 | 'direction'=>'up', 32 | 'count'=>1 33 | ); 34 | } 35 | $counter =& $counters[$name]; 36 | 37 | if (isset($params['start'])) { 38 | $counter['start'] = $counter['count'] = (int)$params['start']; 39 | } 40 | 41 | if (!empty($params['assign'])) { 42 | $counter['assign'] = $params['assign']; 43 | } 44 | 45 | if (isset($counter['assign'])) { 46 | $smarty->assign($counter['assign'], $counter['count']); 47 | } 48 | 49 | if (isset($params['print'])) { 50 | $print = (bool)$params['print']; 51 | } else { 52 | $print = empty($counter['assign']); 53 | } 54 | 55 | if ($print) { 56 | $retval = $counter['count']; 57 | } else { 58 | $retval = null; 59 | } 60 | 61 | if (isset($params['skip'])) { 62 | $counter['skip'] = $params['skip']; 63 | } 64 | 65 | if (isset($params['direction'])) { 66 | $counter['direction'] = $params['direction']; 67 | } 68 | 69 | if ($counter['direction'] == "down") 70 | $counter['count'] -= $counter['skip']; 71 | else 72 | $counter['count'] += $counter['skip']; 73 | 74 | return $retval; 75 | 76 | } 77 | 78 | /* vim: set expandtab: */ 79 | 80 | ?> 81 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.cycle.php: -------------------------------------------------------------------------------- 1 | 12 | * Name: cycle
13 | * Date: May 3, 2002
14 | * Purpose: cycle through given values
15 | * Input: 16 | * - name = name of cycle (optional) 17 | * - values = comma separated list of values to cycle, 18 | * or an array of values to cycle 19 | * (this can be left out for subsequent calls) 20 | * - reset = boolean - resets given var to true 21 | * - print = boolean - print var or not. default is true 22 | * - advance = boolean - whether or not to advance the cycle 23 | * - delimiter = the value delimiter, default is "," 24 | * - assign = boolean, assigns to template var instead of 25 | * printed. 26 | * 27 | * Examples:
28 | *
 29 |  * {cycle values="#eeeeee,#d0d0d0d"}
 30 |  * {cycle name=row values="one,two,three" reset=true}
 31 |  * {cycle name=row}
 32 |  * 
33 | * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} 34 | * (Smarty online manual) 35 | * @author Monte Ohrt 36 | * @author credit to Mark Priatel 37 | * @author credit to Gerard 38 | * @author credit to Jason Sweat 39 | * @version 1.3 40 | * @param array 41 | * @param Smarty 42 | * @return string|null 43 | */ 44 | function smarty_function_cycle($params, &$smarty) 45 | { 46 | static $cycle_vars; 47 | 48 | $name = (empty($params['name'])) ? 'default' : $params['name']; 49 | $print = (isset($params['print'])) ? (bool)$params['print'] : true; 50 | $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; 51 | $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; 52 | 53 | if (!in_array('values', array_keys($params))) { 54 | if(!isset($cycle_vars[$name]['values'])) { 55 | $smarty->trigger_error("cycle: missing 'values' parameter"); 56 | return; 57 | } 58 | } else { 59 | if(isset($cycle_vars[$name]['values']) 60 | && $cycle_vars[$name]['values'] != $params['values'] ) { 61 | $cycle_vars[$name]['index'] = 0; 62 | } 63 | $cycle_vars[$name]['values'] = $params['values']; 64 | } 65 | 66 | $cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ','; 67 | 68 | if(is_array($cycle_vars[$name]['values'])) { 69 | $cycle_array = $cycle_vars[$name]['values']; 70 | } else { 71 | $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); 72 | } 73 | 74 | if(!isset($cycle_vars[$name]['index']) || $reset ) { 75 | $cycle_vars[$name]['index'] = 0; 76 | } 77 | 78 | if (isset($params['assign'])) { 79 | $print = false; 80 | $smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); 81 | } 82 | 83 | if($print) { 84 | $retval = $cycle_array[$cycle_vars[$name]['index']]; 85 | } else { 86 | $retval = null; 87 | } 88 | 89 | if($advance) { 90 | if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) { 91 | $cycle_vars[$name]['index'] = 0; 92 | } else { 93 | $cycle_vars[$name]['index']++; 94 | } 95 | } 96 | 97 | return $retval; 98 | } 99 | 100 | /* vim: set expandtab: */ 101 | 102 | ?> 103 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.debug.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: debug
14 | * Date: July 1, 2002
15 | * Purpose: popup debug window 16 | * @link http://smarty.php.net/manual/en/language.function.debug.php {debug} 17 | * (Smarty online manual) 18 | * @author Monte Ohrt 19 | * @version 1.0 20 | * @param array 21 | * @param Smarty 22 | * @return string output from {@link Smarty::_generate_debug_output()} 23 | */ 24 | function smarty_function_debug($params, &$smarty) 25 | { 26 | if (isset($params['output'])) { 27 | $smarty->assign('_smarty_debug_output', $params['output']); 28 | } 29 | require_once(SMARTY_CORE_DIR . 'core.display_debug_console.php'); 30 | return smarty_core_display_debug_console(null, $smarty); 31 | } 32 | 33 | /* vim: set expandtab: */ 34 | 35 | ?> 36 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.eval.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: eval
14 | * Purpose: evaluate a template variable as a template
15 | * @link http://smarty.php.net/manual/en/language.function.eval.php {eval} 16 | * (Smarty online manual) 17 | * @author Monte Ohrt 18 | * @param array 19 | * @param Smarty 20 | */ 21 | function smarty_function_eval($params, &$smarty) 22 | { 23 | 24 | if (!isset($params['var'])) { 25 | $smarty->trigger_error("eval: missing 'var' parameter"); 26 | return; 27 | } 28 | 29 | if($params['var'] == '') { 30 | return; 31 | } 32 | 33 | $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled); 34 | 35 | ob_start(); 36 | $smarty->_eval('?>' . $_var_compiled); 37 | $_contents = ob_get_contents(); 38 | ob_end_clean(); 39 | 40 | if (!empty($params['assign'])) { 41 | $smarty->assign($params['assign'], $_contents); 42 | } else { 43 | return $_contents; 44 | } 45 | } 46 | 47 | /* vim: set expandtab: */ 48 | 49 | ?> 50 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.html_checkboxes.php: -------------------------------------------------------------------------------- 1 | 13 | * Type: function
14 | * Name: html_checkboxes
15 | * Date: 24.Feb.2003
16 | * Purpose: Prints out a list of checkbox input types
17 | * Input:
18 | * - name (optional) - string default "checkbox" 19 | * - values (required) - array 20 | * - options (optional) - associative array 21 | * - checked (optional) - array default not set 22 | * - separator (optional) - ie
or   23 | * - output (optional) - the output next to each checkbox 24 | * - assign (optional) - assign the output as an array to this variable 25 | * Examples: 26 | *
 27 |  * {html_checkboxes values=$ids output=$names}
 28 |  * {html_checkboxes values=$ids name='box' separator='
' output=$names} 29 | * {html_checkboxes values=$ids checked=$checked separator='
' output=$names} 30 | *
31 | * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} 32 | * (Smarty online manual) 33 | * @author Christopher Kvarme 34 | * @author credits to Monte Ohrt 35 | * @version 1.0 36 | * @param array 37 | * @param Smarty 38 | * @return string 39 | * @uses smarty_function_escape_special_chars() 40 | */ 41 | function smarty_function_html_checkboxes($params, &$smarty) 42 | { 43 | require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 44 | 45 | $name = 'checkbox'; 46 | $values = null; 47 | $options = null; 48 | $selected = null; 49 | $separator = ''; 50 | $labels = true; 51 | $output = null; 52 | 53 | $extra = ''; 54 | 55 | foreach($params as $_key => $_val) { 56 | switch($_key) { 57 | case 'name': 58 | case 'separator': 59 | $$_key = $_val; 60 | break; 61 | 62 | case 'labels': 63 | $$_key = (bool)$_val; 64 | break; 65 | 66 | case 'options': 67 | $$_key = (array)$_val; 68 | break; 69 | 70 | case 'values': 71 | case 'output': 72 | $$_key = array_values((array)$_val); 73 | break; 74 | 75 | case 'checked': 76 | case 'selected': 77 | $selected = array_map('strval', array_values((array)$_val)); 78 | break; 79 | 80 | case 'checkboxes': 81 | $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); 82 | $options = (array)$_val; 83 | break; 84 | 85 | case 'assign': 86 | break; 87 | 88 | default: 89 | if(!is_array($_val)) { 90 | $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 91 | } else { 92 | $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 93 | } 94 | break; 95 | } 96 | } 97 | 98 | if (!isset($options) && !isset($values)) 99 | return ''; /* raise error here? */ 100 | 101 | settype($selected, 'array'); 102 | $_html_result = array(); 103 | 104 | if (isset($options)) { 105 | 106 | foreach ($options as $_key=>$_val) 107 | $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 108 | 109 | 110 | } else { 111 | foreach ($values as $_i=>$_key) { 112 | $_val = isset($output[$_i]) ? $output[$_i] : ''; 113 | $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels); 114 | } 115 | 116 | } 117 | 118 | if(!empty($params['assign'])) { 119 | $smarty->assign($params['assign'], $_html_result); 120 | } else { 121 | return implode("\n",$_html_result); 122 | } 123 | 124 | } 125 | 126 | function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) { 127 | $_output = ''; 128 | if ($labels) $_output .= ''; 138 | $_output .= $separator; 139 | 140 | return $_output; 141 | } 142 | 143 | ?> 144 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.html_image.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: html_image
14 | * Date: Feb 24, 2003
15 | * Purpose: format HTML tags for the image
16 | * Input:
17 | * - file = file (and path) of image (required) 18 | * - height = image height (optional, default actual height) 19 | * - width = image width (optional, default actual width) 20 | * - basedir = base directory for absolute paths, default 21 | * is environment variable DOCUMENT_ROOT 22 | * - path_prefix = prefix for path output (optional, default empty) 23 | * 24 | * Examples: {html_image file="/images/masthead.gif"} 25 | * Output: 26 | * @link http://smarty.php.net/manual/en/language.function.html.image.php {html_image} 27 | * (Smarty online manual) 28 | * @author Monte Ohrt 29 | * @author credits to Duda - wrote first image function 30 | * in repository, helped with lots of functionality 31 | * @version 1.0 32 | * @param array 33 | * @param Smarty 34 | * @return string 35 | * @uses smarty_function_escape_special_chars() 36 | */ 37 | function smarty_function_html_image($params, &$smarty) 38 | { 39 | require_once $smarty->_get_plugin_filepath('shared','escape_special_chars'); 40 | 41 | $alt = ''; 42 | $file = ''; 43 | $height = ''; 44 | $width = ''; 45 | $extra = ''; 46 | $prefix = ''; 47 | $suffix = ''; 48 | $path_prefix = ''; 49 | $server_vars = ($smarty->request_use_auto_globals) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 50 | $basedir = isset($server_vars['DOCUMENT_ROOT']) ? $server_vars['DOCUMENT_ROOT'] : ''; 51 | foreach($params as $_key => $_val) { 52 | switch($_key) { 53 | case 'file': 54 | case 'height': 55 | case 'width': 56 | case 'dpi': 57 | case 'path_prefix': 58 | case 'basedir': 59 | $$_key = $_val; 60 | break; 61 | 62 | case 'alt': 63 | if(!is_array($_val)) { 64 | $$_key = smarty_function_escape_special_chars($_val); 65 | } else { 66 | $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 67 | } 68 | break; 69 | 70 | case 'link': 71 | case 'href': 72 | $prefix = ''; 73 | $suffix = ''; 74 | break; 75 | 76 | default: 77 | if(!is_array($_val)) { 78 | $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; 79 | } else { 80 | $smarty->trigger_error("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE); 81 | } 82 | break; 83 | } 84 | } 85 | 86 | if (empty($file)) { 87 | $smarty->trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE); 88 | return; 89 | } 90 | 91 | if (substr($file,0,1) == '/') { 92 | $_image_path = $basedir . $file; 93 | } else { 94 | $_image_path = $file; 95 | } 96 | 97 | if(!isset($params['width']) || !isset($params['height'])) { 98 | if(!$_image_data = @getimagesize($_image_path)) { 99 | if(!file_exists($_image_path)) { 100 | $smarty->trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE); 101 | return; 102 | } else if(!is_readable($_image_path)) { 103 | $smarty->trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE); 104 | return; 105 | } else { 106 | $smarty->trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE); 107 | return; 108 | } 109 | } 110 | if ($smarty->security && 111 | ($_params = array('resource_type' => 'file', 'resource_name' => $_image_path)) && 112 | (require_once(SMARTY_CORE_DIR . 'core.is_secure.php')) && 113 | (!smarty_core_is_secure($_params, $smarty)) ) { 114 | $smarty->trigger_error("html_image: (secure) '$_image_path' not in secure directory", E_USER_NOTICE); 115 | } 116 | 117 | if(!isset($params['width'])) { 118 | $width = $_image_data[0]; 119 | } 120 | if(!isset($params['height'])) { 121 | $height = $_image_data[1]; 122 | } 123 | 124 | } 125 | 126 | if(isset($params['dpi'])) { 127 | if(strstr($server_vars['HTTP_USER_AGENT'], 'Mac')) { 128 | $dpi_default = 72; 129 | } else { 130 | $dpi_default = 96; 131 | } 132 | $_resize = $dpi_default/$params['dpi']; 133 | $width = round($width * $_resize); 134 | $height = round($height * $_resize); 135 | } 136 | 137 | return $prefix . ''.$alt.'' . $suffix; 138 | } 139 | 140 | /* vim: set expandtab: */ 141 | 142 | ?> 143 | -------------------------------------------------------------------------------- /include/Smarty/plugins/function.html_options.php: -------------------------------------------------------------------------------- 1 | 13 | * Name: html_options
14 | * Input:
15 | * - name (optional) - string default "select" 16 | * - values (required if no options supplied) - array 17 | * - options (required if no values supplied) - associative array 18 | * - selected (optional) - string default not set 19 | * - output (required if not options supplied) - array 20 | * Purpose: Prints the list of