| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: |
|
| 12: | class Smarty_Internal_Method_LoadPlugin
|
| 13: | {
|
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | public $plugin_files = array();
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | public function loadPlugin(Smarty $smarty, $plugin_name, $check)
|
| 34: | {
|
| 35: |
|
| 36: | if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) {
|
| 37: | return true;
|
| 38: | }
|
| 39: | if (!preg_match('#^smarty_((internal)|([^_]+))_(.+)$#i', $plugin_name, $match)) {
|
| 40: | throw new SmartyException("plugin {$plugin_name} is not a valid name format");
|
| 41: | }
|
| 42: | if (!empty($match[ 2 ])) {
|
| 43: | $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php';
|
| 44: | if (isset($this->plugin_files[ $file ])) {
|
| 45: | if ($this->plugin_files[ $file ] !== false) {
|
| 46: | return $this->plugin_files[ $file ];
|
| 47: | } else {
|
| 48: | return false;
|
| 49: | }
|
| 50: | } else {
|
| 51: | if (is_file($file)) {
|
| 52: | $this->plugin_files[ $file ] = $file;
|
| 53: | include_once $file;
|
| 54: | return $file;
|
| 55: | } else {
|
| 56: | $this->plugin_files[ $file ] = false;
|
| 57: | return false;
|
| 58: | }
|
| 59: | }
|
| 60: | }
|
| 61: |
|
| 62: | $_plugin_filename = "{$match[1]}.{$match[4]}.php";
|
| 63: | $_lower_filename = strtolower($_plugin_filename);
|
| 64: | if (isset($this->plugin_files)) {
|
| 65: | if (isset($this->plugin_files[ 'plugins_dir' ][ $_lower_filename ])) {
|
| 66: | if (!$smarty->use_include_path || $this->plugin_files[ 'plugins_dir' ][ $_lower_filename ] !== false) {
|
| 67: | return $this->plugin_files[ 'plugins_dir' ][ $_lower_filename ];
|
| 68: | }
|
| 69: | }
|
| 70: | if (!$smarty->use_include_path || $smarty->ext->_getIncludePath->isNewIncludePath($smarty)) {
|
| 71: | unset($this->plugin_files[ 'include_path' ]);
|
| 72: | } else {
|
| 73: | if (isset($this->plugin_files[ 'include_path' ][ $_lower_filename ])) {
|
| 74: | return $this->plugin_files[ 'include_path' ][ $_lower_filename ];
|
| 75: | }
|
| 76: | }
|
| 77: | }
|
| 78: | $_file_names = array($_plugin_filename);
|
| 79: | if ($_lower_filename !== $_plugin_filename) {
|
| 80: | $_file_names[] = $_lower_filename;
|
| 81: | }
|
| 82: | $_p_dirs = $smarty->getPluginsDir();
|
| 83: | if (!isset($this->plugin_files[ 'plugins_dir' ][ $_lower_filename ])) {
|
| 84: |
|
| 85: | foreach ($_p_dirs as $_plugin_dir) {
|
| 86: | foreach ($_file_names as $name) {
|
| 87: | $file = $_plugin_dir . $name;
|
| 88: | if (is_file($file)) {
|
| 89: | $this->plugin_files[ 'plugins_dir' ][ $_lower_filename ] = $file;
|
| 90: | include_once $file;
|
| 91: | return $file;
|
| 92: | }
|
| 93: | $this->plugin_files[ 'plugins_dir' ][ $_lower_filename ] = false;
|
| 94: | }
|
| 95: | }
|
| 96: | }
|
| 97: | if ($smarty->use_include_path) {
|
| 98: | foreach ($_file_names as $_file_name) {
|
| 99: |
|
| 100: | $file = $smarty->ext->_getIncludePath->getIncludePath($_p_dirs, $_file_name, $smarty);
|
| 101: | $this->plugin_files[ 'include_path' ][ $_lower_filename ] = $file;
|
| 102: | if ($file !== false) {
|
| 103: | include_once $file;
|
| 104: | return $file;
|
| 105: | }
|
| 106: | }
|
| 107: | }
|
| 108: |
|
| 109: | return false;
|
| 110: | }
|
| 111: | }
|
| 112: | |