]>
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 * PageBuilder constructor.
19 * $tpl is initialized at false for lazy loading.
21 function __construct()
27 * Initialize all default tpl tags.
29 private function initialize()
31 $this->tpl
= new RainTPL();
34 $version = ApplicationUtils
::checkUpdate(
36 $GLOBALS['config']['UPDATECHECK_FILENAME'],
37 $GLOBALS['config']['UPDATECHECK_INTERVAL'],
38 $GLOBALS['config']['ENABLE_UPDATECHECK'],
40 $GLOBALS['config']['UPDATECHECK_BRANCH']
42 $this->tpl
->assign('newVersion', escape($version));
43 $this->tpl
->assign('versionError', '');
45 } catch (Exception
$exc) {
46 logm($GLOBALS['config']['LOG_FILE'], $_SERVER['REMOTE_ADDR'], $exc->getMessage());
47 $this->tpl
->assign('newVersion', '');
48 $this->tpl
->assign('versionError', escape($exc->getMessage()));
51 $this->tpl
->assign('feedurl', escape(index_url($_SERVER)));
52 $searchcrits = ''; // Search criteria
53 if (!empty($_GET['searchtags'])) {
54 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
56 if (!empty($_GET['searchterm'])) {
57 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
59 $this->tpl
->assign('searchcrits', $searchcrits);
60 $this->tpl
->assign('source', index_url($_SERVER));
61 $this->tpl
->assign('version', shaarli_version
);
62 $this->tpl
->assign('scripturl', index_url($_SERVER));
63 $this->tpl
->assign('pagetitle', 'Shaarli');
64 $this->tpl
->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
65 if (!empty($GLOBALS['title'])) {
66 $this->tpl
->assign('pagetitle', $GLOBALS['title']);
68 if (!empty($GLOBALS['titleLink'])) {
69 $this->tpl
->assign('titleLink', $GLOBALS['titleLink']);
71 if (!empty($GLOBALS['pagetitle'])) {
72 $this->tpl
->assign('pagetitle', $GLOBALS['pagetitle']);
74 $this->tpl
->assign('shaarlititle', empty($GLOBALS['title']) ? 'Shaarli': $GLOBALS['title']);
75 if (!empty($GLOBALS['plugin_errors'])) {
76 $this->tpl
->assign('plugin_errors', $GLOBALS['plugin_errors']);
81 * The following assign() method is basically the same as RainTPL (except lazy loading)
83 * @param string $placeholder Template placeholder.
84 * @param mixed $value Value to assign.
86 public function assign($placeholder, $value)
88 // Lazy initialization
89 if ($this->tpl
=== false) {
92 $this->tpl
->assign($placeholder, $value);
96 * Assign an array of data to the template builder.
98 * @param array $data Data to assign.
100 * @return false if invalid data.
102 public function assignAll($data)
104 // Lazy initialization
105 if ($this->tpl
=== false) {
109 if (empty($data) || !is_array($data)){
113 foreach ($data as $key => $value) {
114 $this->assign($key, $value);
119 * Render a specific page (using a template file).
120 * e.g. $pb->renderPage('picwall');
122 * @param string $page Template filename (without extension).
124 public function renderPage($page)
126 // Lazy initialization
127 if ($this->tpl
===false) {
130 $this->tpl
->draw($page);
134 * Render a 404 page (uses the template : tpl/404.tpl)
135 * usage : $PAGE->render404('The link was deleted')
137 * @param string $message A messate to display what is not found
139 public function render404($message = 'The page you are trying to reach does not exist or has been deleted.')
141 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
142 $this->tpl
->assign('error_message', $message);
143 $this->renderPage('404');