diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-06-09 20:04:02 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-06-11 09:30:56 +0200 |
commit | 278d9ee2836df7d805845077f26f8cecd16f0f4f (patch) | |
tree | 9155cab8890074e83b54efaa649bfa74885d3ab5 /application/PageBuilder.php | |
parent | 7f179985b497053c59338667fe49c390aa626ab7 (diff) | |
download | Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.gz Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.tar.zst Shaarli-278d9ee2836df7d805845077f26f8cecd16f0f4f.zip |
ConfigManager no longer uses singleton pattern
Diffstat (limited to 'application/PageBuilder.php')
-rw-r--r-- | application/PageBuilder.php | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 04454865..843cc0dc 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php | |||
@@ -15,12 +15,20 @@ class PageBuilder | |||
15 | private $tpl; | 15 | private $tpl; |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * @var ConfigManager $conf Configuration Manager instance. | ||
19 | */ | ||
20 | protected $conf; | ||
21 | |||
22 | /** | ||
18 | * PageBuilder constructor. | 23 | * PageBuilder constructor. |
19 | * $tpl is initialized at false for lazy loading. | 24 | * $tpl is initialized at false for lazy loading. |
25 | * | ||
26 | * @param ConfigManager $conf Configuration Manager instance (reference). | ||
20 | */ | 27 | */ |
21 | function __construct() | 28 | function __construct(&$conf) |
22 | { | 29 | { |
23 | $this->tpl = false; | 30 | $this->tpl = false; |
31 | $this->conf = $conf; | ||
24 | } | 32 | } |
25 | 33 | ||
26 | /** | 34 | /** |
@@ -29,22 +37,21 @@ class PageBuilder | |||
29 | private function initialize() | 37 | private function initialize() |
30 | { | 38 | { |
31 | $this->tpl = new RainTPL(); | 39 | $this->tpl = new RainTPL(); |
32 | $conf = ConfigManager::getInstance(); | ||
33 | 40 | ||
34 | try { | 41 | try { |
35 | $version = ApplicationUtils::checkUpdate( | 42 | $version = ApplicationUtils::checkUpdate( |
36 | shaarli_version, | 43 | shaarli_version, |
37 | $conf->get('path.update_check'), | 44 | $this->conf->get('path.update_check'), |
38 | $conf->get('general.check_updates_interval'), | 45 | $this->conf->get('general.check_updates_interval'), |
39 | $conf->get('general.check_updates'), | 46 | $this->conf->get('general.check_updates'), |
40 | isLoggedIn(), | 47 | isLoggedIn(), |
41 | $conf->get('general.check_updates_branch') | 48 | $this->conf->get('general.check_updates_branch') |
42 | ); | 49 | ); |
43 | $this->tpl->assign('newVersion', escape($version)); | 50 | $this->tpl->assign('newVersion', escape($version)); |
44 | $this->tpl->assign('versionError', ''); | 51 | $this->tpl->assign('versionError', ''); |
45 | 52 | ||
46 | } catch (Exception $exc) { | 53 | } catch (Exception $exc) { |
47 | logm($conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); | 54 | logm($this->conf->get('path.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); |
48 | $this->tpl->assign('newVersion', ''); | 55 | $this->tpl->assign('newVersion', ''); |
49 | $this->tpl->assign('versionError', escape($exc->getMessage())); | 56 | $this->tpl->assign('versionError', escape($exc->getMessage())); |
50 | } | 57 | } |
@@ -63,19 +70,19 @@ class PageBuilder | |||
63 | $this->tpl->assign('scripturl', index_url($_SERVER)); | 70 | $this->tpl->assign('scripturl', index_url($_SERVER)); |
64 | $this->tpl->assign('pagetitle', 'Shaarli'); | 71 | $this->tpl->assign('pagetitle', 'Shaarli'); |
65 | $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? | 72 | $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? |
66 | if ($conf->exists('general.title')) { | 73 | if ($this->conf->exists('general.title')) { |
67 | $this->tpl->assign('pagetitle', $conf->get('general.title')); | 74 | $this->tpl->assign('pagetitle', $this->conf->get('general.title')); |
68 | } | 75 | } |
69 | if ($conf->exists('general.header_link')) { | 76 | if ($this->conf->exists('general.header_link')) { |
70 | $this->tpl->assign('titleLink', $conf->get('general.header_link')); | 77 | $this->tpl->assign('titleLink', $this->conf->get('general.header_link')); |
71 | } | 78 | } |
72 | if ($conf->exists('pagetitle')) { | 79 | if ($this->conf->exists('pagetitle')) { |
73 | $this->tpl->assign('pagetitle', $conf->get('pagetitle')); | 80 | $this->tpl->assign('pagetitle', $this->conf->get('pagetitle')); |
74 | } | 81 | } |
75 | $this->tpl->assign('shaarlititle', $conf->get('title', 'Shaarli')); | 82 | $this->tpl->assign('shaarlititle', $this->conf->get('title', 'Shaarli')); |
76 | $this->tpl->assign('openshaarli', $conf->get('extras.open_shaarli', false)); | 83 | $this->tpl->assign('openshaarli', $this->conf->get('extras.open_shaarli', false)); |
77 | $this->tpl->assign('showatom', $conf->get('extras.show_atom', false)); | 84 | $this->tpl->assign('showatom', $this->conf->get('extras.show_atom', false)); |
78 | $this->tpl->assign('hide_timestamps', $conf->get('extras.hide_timestamps', false)); | 85 | $this->tpl->assign('hide_timestamps', $this->conf->get('extras.hide_timestamps', false)); |
79 | if (!empty($GLOBALS['plugin_errors'])) { | 86 | if (!empty($GLOBALS['plugin_errors'])) { |
80 | $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); | 87 | $this->tpl->assign('plugin_errors', $GLOBALS['plugin_errors']); |
81 | } | 88 | } |
@@ -89,7 +96,6 @@ class PageBuilder | |||
89 | */ | 96 | */ |
90 | public function assign($placeholder, $value) | 97 | public function assign($placeholder, $value) |
91 | { | 98 | { |
92 | // Lazy initialization | ||
93 | if ($this->tpl === false) { | 99 | if ($this->tpl === false) { |
94 | $this->initialize(); | 100 | $this->initialize(); |
95 | } | 101 | } |
@@ -105,7 +111,6 @@ class PageBuilder | |||
105 | */ | 111 | */ |
106 | public function assignAll($data) | 112 | public function assignAll($data) |
107 | { | 113 | { |
108 | // Lazy initialization | ||
109 | if ($this->tpl === false) { | 114 | if ($this->tpl === false) { |
110 | $this->initialize(); | 115 | $this->initialize(); |
111 | } | 116 | } |
@@ -117,6 +122,7 @@ class PageBuilder | |||
117 | foreach ($data as $key => $value) { | 122 | foreach ($data as $key => $value) { |
118 | $this->assign($key, $value); | 123 | $this->assign($key, $value); |
119 | } | 124 | } |
125 | return true; | ||
120 | } | 126 | } |
121 | 127 | ||
122 | /** | 128 | /** |
@@ -127,10 +133,10 @@ class PageBuilder | |||
127 | */ | 133 | */ |
128 | public function renderPage($page) | 134 | public function renderPage($page) |
129 | { | 135 | { |
130 | // Lazy initialization | 136 | if ($this->tpl === false) { |
131 | if ($this->tpl===false) { | ||
132 | $this->initialize(); | 137 | $this->initialize(); |
133 | } | 138 | } |
139 | |||
134 | $this->tpl->draw($page); | 140 | $this->tpl->draw($page); |
135 | } | 141 | } |
136 | 142 | ||