| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @copyright Copyright (c) 2016 Bjoern Schiessle <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (c) 2016 Lukas Reschke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license GNU AGPL version 3 or any later version | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * it under the terms of the GNU Affero General Public License as | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * published by the Free Software Foundation, either version 3 of the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | namespace OCA\Theming; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use OCP\IConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OCP\IL10N; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCP\IURLGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * Class Template | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * Handle all the values which can be modified by this app | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @package OCA\Theming | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | class Template extends \OC_Defaults { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	/** @var IConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	/** @var  IL10N */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	private $l; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	/** @var IURLGenerator */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	private $urlGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	private $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	private $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private $slogan; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	private $color; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * Template constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 * @param IConfig $config | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * @param IL10N $l | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * @param IURLGenerator $urlGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 * @param \OC_Defaults $defaults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	public function __construct(IConfig $config, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 								IL10N $l, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 								IURLGenerator $urlGenerator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 								\OC_Defaults $defaults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->config = $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$this->l = $l; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->urlGenerator = $urlGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->name = $defaults->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		$this->url = $defaults->getBaseUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$this->slogan = $defaults->getSlogan(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		$this->color = $defaults->getMailHeaderColor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	public function getName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		return $this->config->getAppValue('theming', 'name', $this->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	public function getHTMLName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		return $this->config->getAppValue('theming', 'name', $this->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	public function getTitle() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		return $this->config->getAppValue('theming', 'name', $this->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	public function getEntity() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		return $this->config->getAppValue('theming', 'name', $this->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	public function getBaseUrl() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		return $this->config->getAppValue('theming', 'url', $this->url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 	public function getSlogan() { | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 		return $this->config->getAppValue('theming', 'slogan', $this->slogan); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	public function getShortFooter() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$slogan = $this->getSlogan(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			' rel="noreferrer">' .$this->getEntity() . '</a>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 			($slogan !== '' ? ' – ' . $slogan : ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		return $footer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 * Color that is used for the header as well as for mail headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	public function getMailHeaderColor() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		return $this->config->getAppValue('theming', 'color', $this->color); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	 * Increases the cache buster key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	private function increaseCacheBuster() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		$cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		$this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	 * Update setting in the database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	 * @param string $setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	 * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 	public function set($setting, $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		$this->config->setAppValue('theming', $setting, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		$this->increaseCacheBuster(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 	 * Revert settings to the default value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	 * @param string $setting setting which should be reverted | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	 * @return string default value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	public function undo($setting) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		$this->config->deleteAppValue('theming', $setting); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		$this->increaseCacheBuster(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		switch ($setting) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			case 'name': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 				$returnValue = $this->getEntity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 			case 'url': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 				$returnValue = $this->getBaseUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 			case 'slogan': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 				$returnValue = $this->getSlogan(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			case 'color': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 				$returnValue = $this->getMailHeaderColor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 			default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 				$returnValue = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 				break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 		return $returnValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 167 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 168 |  |  |  |