| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace DERHANSEN\SfEventMgt\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This file is part of the TYPO3 CMS project. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * It is free software; you can redistribute it and/or modify it under | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * the terms of the GNU General Public License, either version 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * of the License, or any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * For the full copyright and license information, please read the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * LICENSE.txt file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * The TYPO3 project - inspiring people to share! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use \TYPO3\CMS\Core\Utility\GeneralUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * FluidStandaloneService - Fallbacks for templatePaths for TYPO3 6.2 LTS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author Torben Hansen <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | class FluidStandaloneService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * The configuration manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @inject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected $configurationManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Returns the template folders for the given part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param string $part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function getTemplateFolders($part = 'template') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $extbaseConfig = $this->configurationManager->getConfiguration( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (!empty($extbaseConfig['view'][$part . 'RootPaths'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $templatePaths = $extbaseConfig['view'][$part . 'RootPaths']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $templatePaths = array_values($templatePaths); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         if (empty($templatePaths)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $path = $extbaseConfig['view'][$part . 'RootPath']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             if (!empty($path)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 $templatePaths = $path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         if (empty($templatePaths)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $templatePaths = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $templatePaths[] = 'EXT:sf_event_mgt/Resources/Private/' . ucfirst($part) . 's/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $absolutePaths = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         foreach ($templatePaths as $templatePath) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $absolutePaths[] = GeneralUtility::getFileAbsFileName($templatePath); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         return $absolutePaths; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * Return path and filename for a file or path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      *        Only the first existing file/path will be returned. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      *        respect *RootPaths and *RootPath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param string $pathAndFilename e.g. Email/Name.html | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @param string $part "template", "partial", "layout" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @return string Filename/path | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     public function getTemplatePath($pathAndFilename, $part = 'template') | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $matches = $this->getTemplatePaths($pathAndFilename, $part); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         return !empty($matches) ? end($matches) : ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * Return path and filename for one or many files/paths. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      *        Only existing files/paths will be returned. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      *        respect *RootPaths and *RootPath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @param string $pathAndFilename Path/filename (Email/Name.html) or path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param string $part "template", "partial", "layout" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @return array All existing matches found | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     protected function getTemplatePaths($pathAndFilename, $part = 'template') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $matches = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $absolutePaths = $this->getTemplateFolders($part); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         foreach ($absolutePaths as $absolutePath) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             if (file_exists($absolutePath . $pathAndFilename)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 $matches[] = $absolutePath . $pathAndFilename; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return $matches; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  | } |