]>
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();
32 $conf = ConfigManager
::getInstance();
35 $version = ApplicationUtils
::checkUpdate(
37 $conf->get('config.UPDATECHECK_FILENAME'),
38 $conf->get('config.UPDATECHECK_INTERVAL'),
39 $conf->get('config.ENABLE_UPDATECHECK'),
41 $conf->get('config.UPDATECHECK_BRANCH')
43 $this->tpl
->assign('newVersion', escape($version));
44 $this->tpl
->assign('versionError', '');
46 } catch (Exception
$exc) {
47 logm($conf->get('config.LOG_FILE'), $_SERVER['REMOTE_ADDR'], $exc->getMessage());
48 $this->tpl
->assign('newVersion', '');
49 $this->tpl
->assign('versionError', escape($exc->getMessage()));
52 $this->tpl
->assign('feedurl', escape(index_url($_SERVER)));
53 $searchcrits = ''; // Search criteria
54 if (!empty($_GET['searchtags'])) {
55 $searchcrits .= '&searchtags=' . urlencode($_GET['searchtags']);
57 if (!empty($_GET['searchterm'])) {
58 $searchcrits .= '&searchterm=' . urlencode($_GET['searchterm']);
60 $this->tpl
->assign('searchcrits', $searchcrits);
61 $this->tpl
->assign('source', index_url($_SERVER));
62 $this->tpl
->assign('version', shaarli_version
);
63 $this->tpl
->assign('scripturl', index_url($_SERVER));
64 $this->tpl
->assign('pagetitle', 'Shaarli');
65 $this->tpl
->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
66 if ($conf->exists('title')) {
67 $this->tpl
->assign('pagetitle', $conf->get('title'));
69 if ($conf->exists('titleLink')) {
70 $this->tpl
->assign('titleLink', $conf->get('titleLink'));
72 if ($conf->exists('pagetitle')) {
73 $this->tpl
->assign('pagetitle', $conf->get('pagetitle'));
75 $this->tpl
->assign('shaarlititle', $conf->get('title', 'Shaarli'));
76 $this->tpl
->assign('openshaarli', $conf->get('config.OPEN_SHAARLI', false));
77 $this->tpl
->assign('showatom', $conf->get('config.SHOW_ATOM', false));
79 if (!empty($GLOBALS['plugin_errors'])) {
80 $this->tpl
->assign('plugin_errors', $GLOBALS['plugin_errors']);
85 * The following assign() method is basically the same as RainTPL (except lazy loading)
87 * @param string $placeholder Template placeholder.
88 * @param mixed $value Value to assign.
90 public function assign($placeholder, $value)
92 // Lazy initialization
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 // Lazy initialization
109 if ($this->tpl
=== false) {
113 if (empty($data) || !is_array($data)){
117 foreach ($data as $key => $value) {
118 $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 // Lazy initialization
131 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');