123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace OC\Template;
- use OCP\Defaults;
- use Throwable;
- class Base {
- private $template;
- private $vars;
-
- private $l10n;
-
- private $theme;
-
- public function __construct($template, $requestToken, $l10n, $theme) {
- $this->vars = [];
- $this->vars['requesttoken'] = $requestToken;
- $this->l10n = $l10n;
- $this->template = $template;
- $this->theme = $theme;
- }
-
- protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
-
- if ($app_dir !== false && file_exists($app_dir.'/templates/')) {
- return [
- $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
- $app_dir.'/templates/',
- ];
- }
- return [
- $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
- $serverRoot.'/'.$app.'/templates/',
- ];
- }
-
- protected function getCoreTemplateDirs($theme, $serverRoot) {
- return [
- $serverRoot.'/themes/'.$theme.'/core/templates/',
- $serverRoot.'/core/templates/',
- ];
- }
-
- public function assign($key, $value) {
- $this->vars[$key] = $value;
- return true;
- }
-
- public function append($key, $value) {
- if (array_key_exists($key, $this->vars)) {
- $this->vars[$key][] = $value;
- } else {
- $this->vars[$key] = [ $value ];
- }
- }
-
- public function printPage() {
- $data = $this->fetchPage();
- if ($data === false) {
- return false;
- } else {
- print $data;
- return true;
- }
- }
-
- public function fetchPage($additionalParams = null) {
- return $this->load($this->template, $additionalParams);
- }
-
- protected function load($file, $additionalParams = null) {
-
- $_ = $this->vars;
- $l = $this->l10n;
- $theme = $this->theme;
- if (!is_null($additionalParams)) {
- $_ = array_merge($additionalParams, $this->vars);
- foreach ($_ as $var => $value) {
- if (!isset(${$var})) {
- ${$var} = $value;
- }
- }
- }
-
- ob_start();
- try {
- include $file;
- $data = ob_get_contents();
- } catch (\Exception $e) {
- @ob_end_clean();
- throw $e;
- }
- @ob_end_clean();
-
- return $data;
- }
- }
|