diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
commit | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch) | |
tree | dae4c7c47532380eac3ae641db99122fc77c93dc /application/PageBuilder.php | |
parent | 83faedadff76c5bdca036f39f13943f63b27e164 (diff) | |
parent | 1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff) | |
download | Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip |
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'application/PageBuilder.php')
-rw-r--r-- | application/PageBuilder.php | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 468f144b..2ca95832 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php | |||
@@ -1,6 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use Shaarli\Config\ConfigManager; | 3 | use Shaarli\Config\ConfigManager; |
4 | use Shaarli\Thumbnailer; | ||
4 | 5 | ||
5 | /** | 6 | /** |
6 | * This class is in charge of building the final page. | 7 | * This class is in charge of building the final page. |
@@ -22,24 +23,41 @@ class PageBuilder | |||
22 | protected $conf; | 23 | protected $conf; |
23 | 24 | ||
24 | /** | 25 | /** |
26 | * @var array $_SESSION | ||
27 | */ | ||
28 | protected $session; | ||
29 | |||
30 | /** | ||
25 | * @var LinkDB $linkDB instance. | 31 | * @var LinkDB $linkDB instance. |
26 | */ | 32 | */ |
27 | protected $linkDB; | 33 | protected $linkDB; |
28 | 34 | ||
29 | /** | 35 | /** |
36 | * @var null|string XSRF token | ||
37 | */ | ||
38 | protected $token; | ||
39 | |||
40 | /** @var bool $isLoggedIn Whether the user is logged in **/ | ||
41 | protected $isLoggedIn = false; | ||
42 | |||
43 | /** | ||
30 | * PageBuilder constructor. | 44 | * PageBuilder constructor. |
31 | * $tpl is initialized at false for lazy loading. | 45 | * $tpl is initialized at false for lazy loading. |
32 | * | 46 | * |
33 | * @param ConfigManager $conf Configuration Manager instance (reference). | 47 | * @param ConfigManager $conf Configuration Manager instance (reference). |
34 | * @param LinkDB $linkDB instance. | 48 | * @param array $session $_SESSION array |
35 | * @param string $token Session token | 49 | * @param LinkDB $linkDB instance. |
50 | * @param string $token Session token | ||
51 | * @param bool $isLoggedIn | ||
36 | */ | 52 | */ |
37 | public function __construct(&$conf, $linkDB = null, $token = null) | 53 | public function __construct(&$conf, $session, $linkDB = null, $token = null, $isLoggedIn = false) |
38 | { | 54 | { |
39 | $this->tpl = false; | 55 | $this->tpl = false; |
40 | $this->conf = $conf; | 56 | $this->conf = $conf; |
57 | $this->session = $session; | ||
41 | $this->linkDB = $linkDB; | 58 | $this->linkDB = $linkDB; |
42 | $this->token = $token; | 59 | $this->token = $token; |
60 | $this->isLoggedIn = $isLoggedIn; | ||
43 | } | 61 | } |
44 | 62 | ||
45 | /** | 63 | /** |
@@ -55,18 +73,18 @@ class PageBuilder | |||
55 | $this->conf->get('resource.update_check'), | 73 | $this->conf->get('resource.update_check'), |
56 | $this->conf->get('updates.check_updates_interval'), | 74 | $this->conf->get('updates.check_updates_interval'), |
57 | $this->conf->get('updates.check_updates'), | 75 | $this->conf->get('updates.check_updates'), |
58 | isLoggedIn(), | 76 | $this->isLoggedIn, |
59 | $this->conf->get('updates.check_updates_branch') | 77 | $this->conf->get('updates.check_updates_branch') |
60 | ); | 78 | ); |
61 | $this->tpl->assign('newVersion', escape($version)); | 79 | $this->tpl->assign('newVersion', escape($version)); |
62 | $this->tpl->assign('versionError', ''); | 80 | $this->tpl->assign('versionError', ''); |
63 | |||
64 | } catch (Exception $exc) { | 81 | } catch (Exception $exc) { |
65 | logm($this->conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); | 82 | logm($this->conf->get('resource.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage()); |
66 | $this->tpl->assign('newVersion', ''); | 83 | $this->tpl->assign('newVersion', ''); |
67 | $this->tpl->assign('versionError', escape($exc->getMessage())); | 84 | $this->tpl->assign('versionError', escape($exc->getMessage())); |
68 | } | 85 | } |
69 | 86 | ||
87 | $this->tpl->assign('is_logged_in', $this->isLoggedIn); | ||
70 | $this->tpl->assign('feedurl', escape(index_url($_SERVER))); | 88 | $this->tpl->assign('feedurl', escape(index_url($_SERVER))); |
71 | $searchcrits = ''; // Search criteria | 89 | $searchcrits = ''; // Search criteria |
72 | if (!empty($_GET['searchtags'])) { | 90 | if (!empty($_GET['searchtags'])) { |
@@ -82,8 +100,9 @@ class PageBuilder | |||
82 | 'version_hash', | 100 | 'version_hash', |
83 | ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt')) | 101 | ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt')) |
84 | ); | 102 | ); |
85 | $this->tpl->assign('scripturl', index_url($_SERVER)); | 103 | $this->tpl->assign('index_url', index_url($_SERVER)); |
86 | $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? | 104 | $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; |
105 | $this->tpl->assign('visibility', $visibility); | ||
87 | $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); | 106 | $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); |
88 | $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); | 107 | $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); |
89 | if ($this->conf->exists('general.header_link')) { | 108 | if ($this->conf->exists('general.header_link')) { |
@@ -99,6 +118,19 @@ class PageBuilder | |||
99 | if ($this->linkDB !== null) { | 118 | if ($this->linkDB !== null) { |
100 | $this->tpl->assign('tags', $this->linkDB->linksCountPerTag()); | 119 | $this->tpl->assign('tags', $this->linkDB->linksCountPerTag()); |
101 | } | 120 | } |
121 | |||
122 | $this->tpl->assign( | ||
123 | 'thumbnails_enabled', | ||
124 | $this->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE | ||
125 | ); | ||
126 | $this->tpl->assign('thumbnails_width', $this->conf->get('thumbnails.width')); | ||
127 | $this->tpl->assign('thumbnails_height', $this->conf->get('thumbnails.height')); | ||
128 | |||
129 | if (! empty($_SESSION['warnings'])) { | ||
130 | $this->tpl->assign('global_warnings', $_SESSION['warnings']); | ||
131 | unset($_SESSION['warnings']); | ||
132 | } | ||
133 | |||
102 | // To be removed with a proper theme configuration. | 134 | // To be removed with a proper theme configuration. |
103 | $this->tpl->assign('conf', $this->conf); | 135 | $this->tpl->assign('conf', $this->conf); |
104 | } | 136 | } |
@@ -130,7 +162,7 @@ class PageBuilder | |||
130 | $this->initialize(); | 162 | $this->initialize(); |
131 | } | 163 | } |
132 | 164 | ||
133 | if (empty($data) || !is_array($data)){ | 165 | if (empty($data) || !is_array($data)) { |
134 | return false; | 166 | return false; |
135 | } | 167 | } |
136 | 168 | ||