]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/PageBuilder.php
4 * This class is in charge of building the final page.
5 * (This is basically a wrapper around RainTPL which pre-fills some fields.)
6 * $p = new PageBuilder();
7 * $p->assign('myfield','myvalue');
8 * $p->renderPage('mytemplate');
13 * @var RainTPL RainTPL instance.
18 * @var ConfigManager $conf Configuration Manager instance.
23 * PageBuilder constructor.
24 * $tpl is initialized at false for lazy loading.
26 * @param ConfigManager $conf Configuration Manager instance (reference).
28 function __construct(&$conf)
35 * Initialize all default tpl tags.
37 private function initialize()
39 $this->tpl
= new RainTPL();
42 $version = ApplicationUtils
::checkUpdate(
44 $this->conf
->get('resource.update_check'),
45 $this->conf
->get('updates.check_updates_interval'),
46 $this->conf
->get('updates.check_updates'),
48 $this->conf
->get('updates.check_updates_branch')
50 $this->tpl
->assign('newVersion', escape($version));
51 $this->tpl
->assign('versionError', '');
53 } catch (Exception
$exc) {
54 logm($this->conf
->get('resource.log'), $_SERVER['REMOTE_ADDR'], $exc->getMessage());
55 $this->tpl
->assign('newVersion', '');
56 $this->tpl
->assign('versionError', escape($exc->getMessage()));
59 $this->tpl
->assign('feedurl', escape(index_url($_SERVER)));
60 $searchcrits = ''; // Search criteria
61 if (!empty($_GET['searchtags'])) {
62 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
64 if (!empty($_GET['searchterm'])) {
65 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
67 $this->tpl
->assign('searchcrits', $searchcrits);
68 $this->tpl
->assign('source', index_url($_SERVER));
69 $this->tpl
->assign('version', shaarli_version
);
70 $this->tpl
->assign('scripturl', index_url($_SERVER));
71 $this->tpl
->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
72 $this->tpl
->assign('pagetitle', $this->conf
->get('general.title', 'Shaarli'));
73 if ($this->conf
->exists('general.header_link')) {
74 $this->tpl
->assign('titleLink', $this->conf
->get('general.header_link'));
76 $this->tpl
->assign('shaarlititle', $this->conf
->get('general.title', 'Shaarli'));
77 $this->tpl
->assign('openshaarli', $this->conf
->get('security.open_shaarli', false));
78 $this->tpl
->assign('showatom', $this->conf
->get('feed.show_atom', false));
79 $this->tpl
->assign('hide_timestamps', $this->conf
->get('privacy.hide_timestamps', false));
80 $this->tpl
->assign('token', getToken($this->conf
));
81 // To be removed with a proper theme configuration.
82 $this->tpl
->assign('conf', $this->conf
);
86 * The following assign() method is basically the same as RainTPL (except lazy loading)
88 * @param string $placeholder Template placeholder.
89 * @param mixed $value Value to assign.
91 public function assign($placeholder, $value)
93 if ($this->tpl
=== false) {
96 $this->tpl
->assign($placeholder, $value);
100 * Assign an array of data to the template builder.
102 * @param array $data Data to assign.
104 * @return false if invalid data.
106 public function assignAll($data)
108 if ($this->tpl
=== false) {
112 if (empty($data) || !is_array($data)){
116 foreach ($data as $key => $value) {
117 $this->assign($key, $value);
123 * Render a specific page (using a template file).
124 * e.g. $pb->renderPage('picwall');
126 * @param string $page Template filename (without extension).
128 public function renderPage($page)
130 if ($this->tpl
=== false) {
134 $this->tpl
->draw($page);
138 * Render a 404 page (uses the template : tpl/404.tpl)
139 * usage : $PAGE->render404('The link was deleted')
141 * @param string $message A messate to display what is not found
143 public function render404($message = 'The page you are trying to reach does not exist or has been deleted.')
145 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
146 $this->tpl
->assign('error_message', $message);
147 $this->renderPage('404');