Feature #8989 » fluid_patch.diff

Christian Winther, 2010-07-22 10:27

View differences:

usr/local/src/typo3/typo3_src-4.4.0/typo3/sysext/fluid/Classes/View/TemplateView.php → fluid/Classes/View/TemplateView.php
37 37
	 */
38 38
	protected $templateParser;
39 39

  
40
	/** 
41
	 * A list of foreign plugins to scan for template, partial and layout files
42
	 * @var array
43
	 */
44
	protected $extensionSearchPaths = array(null);
45

  
40 46
	/**
41 47
	 * Pattern to be resolved for @templateRoot in the other patterns.
42 48
	 * @var string
......
104 110
	protected $layoutPathAndFilename = NULL;
105 111

  
106 112
	public function __construct() {
107
						$this->templateParser = Tx_Fluid_Compatibility_TemplateParserBuilder::build();
108
						$this->objectManager = t3lib_div::makeInstance('Tx_Fluid_Compatibility_ObjectManager');
109
					}
113
		$this->templateParser = Tx_Fluid_Compatibility_TemplateParserBuilder::build();
114
		$this->objectManager = t3lib_div::makeInstance('Tx_Fluid_Compatibility_ObjectManager');
115
	}
110 116
	// Here, the backporter can insert a constructor method, which is needed for Fluid v4.
111 117

  
112 118
	/**
119
	 * Add an extension to be search for resource files
120
	 * 
121
	 * @param string $extension The extension key for the plugin
122
	 * @return void
123
	 * @author Christian Winther <cwin@mocsystems.com>
124
	 */
125
	public function addExtensionSearchPath($extension) {
126
		if (false === array_search($extension, $this->extensionSearchPaths)) {
127
			$this->extensionSearchPaths[] = $extension;
128
		}
129
	}
130

  
131
	/**
113 132
	 * Inject the template parser
114 133
	 *
115 134
	 * @param Tx_Fluid_Core_Parser_TemplateParser $templateParser The template parser
......
411 430
	/**
412 431
	 * Resolves the template root to be used inside other paths.
413 432
	 *
433
	 * @param string|null $extension Resource path for an extension
414 434
	 * @return string Path to template root directory
415 435
	 * @author Sebastian Kurfürst <sebastian@typo3.org>
416 436
	 */
417
	protected function getTemplateRootPath() {
418
		if ($this->templateRootPath !== NULL) {
437
	protected function getTemplateRootPath($extension = null) {
438
		if ($this->templateRootPath !== NULL && is_null($extension)) {
419 439
			return $this->templateRootPath;
420 440
		} else {
421
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->templateRootPathPattern);
441
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($extension ? $extension : $this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->templateRootPathPattern);
422 442
		}
423 443
	}
424 444

  
......
438 458
	/**
439 459
	 * Resolves the partial root to be used inside other paths.
440 460
	 *
461
	 * @param string|null $extension Resource path for an extension
441 462
	 * @return string Path to partial root directory
442 463
	 * @author Bastian Waidelich <bastian@typo3.org>
443 464
	 */
444
	protected function getPartialRootPath() {
445
		if ($this->partialRootPath !== NULL) {
465
	protected function getPartialRootPath($extension = null) {
466
		if ($this->partialRootPath !== NULL && is_null($extension)) {
446 467
			return $this->partialRootPath;
447 468
		} else {
448
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->partialRootPathPattern);
469
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($extension ? $extension : $this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->partialRootPathPattern);
449 470
		}
450 471
	}
451 472

  
......
465 486
	/**
466 487
	 * Resolves the layout root to be used inside other paths.
467 488
	 *
489
	 * @param string|null $extension Resource path for an extension
468 490
	 * @return string Path to layout root directory
469 491
	 * @author Bastian Waidelich <bastian@typo3.org>
470 492
	 */
471
	protected function getLayoutRootPath() {
472
		if ($this->layoutRootPath !== NULL) {
493
	protected function getLayoutRootPath($extension = null) {
494
		if ($this->layoutRootPath !== NULL && is_null($extension)) {
473 495
			return $this->layoutRootPath;
474 496
		} else {
475
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->layoutRootPathPattern);
497
			return str_replace('@packageResourcesPath', t3lib_extMgm::extPath($extension ? $extension : $this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/', $this->layoutRootPathPattern);
476 498
		}
477 499
	}
478 500

  
......
503 525
	 * @return array unix style path
504 526
	 * @author Sebastian Kurfürst <sebastian@typo3.org>
505 527
	 * @author Robert Lemke <robert@typo3.org>
528
	 * @author Christian Winther <cwin@mocsystems.com>
506 529
	 */
507
	protected function expandGenericPathPattern($pattern, $bubbleControllerAndSubpackage, $formatIsOptional) {
508
		$pattern = str_replace('@templateRoot', $this->getTemplateRootPath(), $pattern);
509
		$pattern = str_replace('@partialRoot', $this->getPartialRootPath(), $pattern);
510
		$pattern = str_replace('@layoutRoot', $this->getLayoutRootPath(), $pattern);
511

  
530
	protected function expandGenericPathPattern($pattern, $bubbleControllerAndSubpackage, $formatIsOptional) {	
512 531
		$subPackageKey = '';
513 532
		$controllerName = $this->controllerContext->getRequest()->getControllerName();
514

  
515 533
		$subpackageParts = ($subPackageKey !== '') ? explode(Tx_Fluid_Fluid::NAMESPACE_SEPARATOR, $subPackageKey) : array();
516

  
517 534
		$results = array();
535
		
536
		foreach ($this->extensionSearchPaths as $extension) {
537
			$filepattern = str_replace('@templateRoot', $this->getTemplateRootPath($extension), $pattern);
538
			$filepattern = str_replace('@partialRoot', $this->getPartialRootPath($extension), $filepattern);
539
			$filepattern = str_replace('@layoutRoot', $this->getLayoutRootPath($extension), $filepattern);
540
		
541
			$i = ($controllerName === NULL) ? 0 : -1;
542
			do {
543
				$temporaryPattern = $filepattern;
544
				if ($i < 0) {
545
					$temporaryPattern = str_replace('@controller', $controllerName, $temporaryPattern);
546
				} else {
547
					$temporaryPattern = str_replace('//', '/', str_replace('@controller', '', $temporaryPattern));
548
				}
549
				$temporaryPattern = str_replace('@subpackage', implode('/', ($i<0 ? $subpackageParts : array_slice($subpackageParts, $i))), $temporaryPattern);
518 550

  
519
		$i = ($controllerName === NULL) ? 0 : -1;
520
		do {
521
			$temporaryPattern = $pattern;
522
			if ($i < 0) {
523
				$temporaryPattern = str_replace('@controller', $controllerName, $temporaryPattern);
524
			} else {
525
				$temporaryPattern = str_replace('//', '/', str_replace('@controller', '', $temporaryPattern));
526
			}
527
			$temporaryPattern = str_replace('@subpackage', implode('/', ($i<0 ? $subpackageParts : array_slice($subpackageParts, $i))), $temporaryPattern);
528

  
529
			$results[] = t3lib_div::fixWindowsFilePath(str_replace('@format', $this->controllerContext->getRequest()->getFormat(), $temporaryPattern));
530
			if ($formatIsOptional) {
531
				$results[] =  t3lib_div::fixWindowsFilePath(str_replace('.@format', '', $temporaryPattern));
532
			}
533

  
534
		} while($i++ < count($subpackageParts) && $bubbleControllerAndSubpackage);
551
				$results[] = t3lib_div::fixWindowsFilePath(str_replace('@format', $this->controllerContext->getRequest()->getFormat(), $temporaryPattern));
552
				if ($formatIsOptional) {
553
					$results[] =  t3lib_div::fixWindowsFilePath(str_replace('.@format', '', $temporaryPattern));
554
				}
535 555

  
556
			} while($i++ < count($subpackageParts) && $bubbleControllerAndSubpackage);
557
		}
536 558
		return $results;
537 559
	}
538 560
}
    (1-1/1)