| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: |
|
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: |
|
| 21: | abstract class Smarty_Resource
|
| 22: | {
|
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | public static $sysplugins = array(
|
| 29: | 'file' => 'smarty_internal_resource_file.php',
|
| 30: | 'string' => 'smarty_internal_resource_string.php',
|
| 31: | 'extends' => 'smarty_internal_resource_extends.php',
|
| 32: | 'stream' => 'smarty_internal_resource_stream.php',
|
| 33: | 'eval' => 'smarty_internal_resource_eval.php',
|
| 34: | 'php' => 'smarty_internal_resource_php.php'
|
| 35: | );
|
| 36: |
|
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: |
|
| 42: | public $uncompiled = false;
|
| 43: |
|
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: |
|
| 49: | public $recompiled = false;
|
| 50: |
|
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: |
|
| 56: | public $hasCompiledHandler = false;
|
| 57: |
|
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: |
|
| 67: | public static function load(Smarty $smarty, $type)
|
| 68: | {
|
| 69: |
|
| 70: | if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) {
|
| 71: | return $smarty->_cache[ 'resource_handlers' ][ $type ];
|
| 72: | }
|
| 73: |
|
| 74: | if (isset($smarty->registered_resources[ $type ])) {
|
| 75: | return $smarty->_cache[ 'resource_handlers' ][ $type ] =
|
| 76: | $smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
|
| 77: | $smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
|
| 78: | }
|
| 79: |
|
| 80: | if (isset(self::$sysplugins[ $type ])) {
|
| 81: | $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
|
| 82: | return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
| 83: | }
|
| 84: |
|
| 85: | $_resource_class = 'Smarty_Resource_' . ucfirst($type);
|
| 86: | if ($smarty->loadPlugin($_resource_class)) {
|
| 87: | if (class_exists($_resource_class, false)) {
|
| 88: | return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
| 89: | } else {
|
| 90: | $smarty->registerResource(
|
| 91: | $type,
|
| 92: | array(
|
| 93: | "smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
|
| 94: | "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"
|
| 95: | )
|
| 96: | );
|
| 97: |
|
| 98: | return self::load($smarty, $type);
|
| 99: | }
|
| 100: | }
|
| 101: |
|
| 102: | $_known_stream = stream_get_wrappers();
|
| 103: | if (in_array($type, $_known_stream)) {
|
| 104: |
|
| 105: | if (is_object($smarty->security_policy)) {
|
| 106: | $smarty->security_policy->isTrustedStream($type);
|
| 107: | }
|
| 108: | return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream();
|
| 109: | }
|
| 110: |
|
| 111: |
|
| 112: | throw new SmartyException("Unknown resource type '{$type}'");
|
| 113: | }
|
| 114: |
|
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: |
|
| 125: | public static function parseResourceName($resource_name, $default_resource)
|
| 126: | {
|
| 127: | if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
|
| 128: | $type = $match[ 1 ];
|
| 129: | $name = substr($resource_name, strlen($match[ 0 ]));
|
| 130: | } else {
|
| 131: |
|
| 132: |
|
| 133: | $type = $default_resource;
|
| 134: | $name = $resource_name;
|
| 135: | }
|
| 136: | return array($name, $type);
|
| 137: | }
|
| 138: |
|
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: |
|
| 149: | public static function getUniqueTemplateName($obj, $template_resource)
|
| 150: | {
|
| 151: | $smarty = $obj->_getSmartyObj();
|
| 152: | list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
| 153: |
|
| 154: | $resource = Smarty_Resource::load($smarty, $type);
|
| 155: |
|
| 156: | $_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/');
|
| 157: | if ($obj->_isTplObj() && $_file_is_dotted
|
| 158: | && ($obj->source->type === 'file' || $obj->parent->source->type === 'extends')
|
| 159: | ) {
|
| 160: | $name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DIRECTORY_SEPARATOR . $name);
|
| 161: | }
|
| 162: | return $resource->buildUniqueResourceName($smarty, $name);
|
| 163: | }
|
| 164: |
|
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | |
| 171: | |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: |
|
| 177: | public static function source(
|
| 178: | Smarty_Internal_Template $_template = null,
|
| 179: | Smarty $smarty = null,
|
| 180: | $template_resource = null
|
| 181: | ) {
|
| 182: | return Smarty_Template_Source::load($_template, $smarty, $template_resource);
|
| 183: | }
|
| 184: |
|
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | |
| 191: | |
| 192: |
|
| 193: | abstract public function getContent(Smarty_Template_Source $source);
|
| 194: |
|
| 195: | |
| 196: | |
| 197: | |
| 198: | |
| 199: | |
| 200: |
|
| 201: | abstract public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null);
|
| 202: |
|
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: |
|
| 208: | public function populateTimestamp(Smarty_Template_Source $source)
|
| 209: | {
|
| 210: |
|
| 211: | }
|
| 212: |
|
| 213: | |
| 214: | |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: |
|
| 222: | public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
| 223: | {
|
| 224: | if ($isConfig) {
|
| 225: | if (!isset($smarty->_joined_config_dir)) {
|
| 226: | $smarty->getTemplateDir(null, true);
|
| 227: | }
|
| 228: | return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
|
| 229: | } else {
|
| 230: | if (!isset($smarty->_joined_template_dir)) {
|
| 231: | $smarty->getTemplateDir();
|
| 232: | }
|
| 233: | return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
|
| 234: | }
|
| 235: | }
|
| 236: |
|
| 237: | |
| 238: | |
| 239: | |
| 240: | |
| 241: | |
| 242: |
|
| 243: | |
| 244: | |
| 245: | |
| 246: | |
| 247: | |
| 248: | |
| 249: |
|
| 250: | public function getBasename(Smarty_Template_Source $source)
|
| 251: | {
|
| 252: | return basename(preg_replace('![^\w]+!', '_', $source->name));
|
| 253: | }
|
| 254: |
|
| 255: | |
| 256: | |
| 257: |
|
| 258: | public function checkTimestamps()
|
| 259: | {
|
| 260: | return true;
|
| 261: | }
|
| 262: | }
|
| 263: | |