aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-04-14 09:22:38 +0200
committerFabio Comuni <fabrix.xm@gmail.com>2011-04-14 09:22:38 +0200
commit0afef6b17e622d1fabd0f499ac206e8924278dfb (patch)
tree41266ee82eaa60335a38b9509692eb0ef4b5a724 /include
parentf70dd1ee927ab57afd4382552e32fef86f277be3 (diff)
downloadvolse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.tar.gz
volse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.tar.bz2
volse-hubzilla-0afef6b17e622d1fabd0f499ac206e8924278dfb.zip
arrays and simple conditional blocks in template, template for nav, load templates from themes
Diffstat (limited to 'include')
-rw-r--r--include/nav.php61
-rw-r--r--include/template_processor.php50
2 files changed, 80 insertions, 31 deletions
diff --git a/include/nav.php b/include/nav.php
index fa4b0a5cc..2ead5c07e 100644
--- a/include/nav.php
+++ b/include/nav.php
@@ -16,7 +16,6 @@ function nav(&$a) {
*/
$a->page['nav'] .= '<div id="panel" style="display: none;"></div>' ;
- $a->page['nav'] .= lang_selector();
/**
*
@@ -28,24 +27,23 @@ function nav(&$a) {
$myident = ((is_array($a->user) && isset($a->user['nickname'])) ? $a->user['nickname'] . '@' : '');
- $a->page['nav'] .= '<div id="site-location">' . $myident . substr($a->get_baseurl(),strpos($a->get_baseurl(),'//') + 2 ) . '</div>';
+ $sitelocation = $myident . substr($a->get_baseurl(),strpos($a->get_baseurl(),'//') + 2 );
+ // nav links: array of array('href', 'text', 'extra css classes')
+ $nav = Array();
+
/**
* Display login or logout
*/
if(local_user()) {
- $a->page['nav'] .= '<a id="nav-logout-link" class="nav-link" href="logout">' . t('Logout') . "</a>\r\n";
+ $nav['logout'] = Array('logout',t('Logout'), "");
}
else {
- $a->page['nav'] .= '<a id="nav-login-link" class="nav-login-link';
- if ($a->module == 'login') { $a->page['nav'] .= ' nav-selected'; }
-
- $a->page['nav'] .= '" href="login">' . t('Login') . "</a>\r\n";
+ $nav['login'] = Array('login',t('Login'), ($a->module == 'login'?'nav-selected':''));
}
- $a->page['nav'] .= "<span id=\"nav-link-wrapper\" >\r\n";
/**
* "Home" should also take you home from an authenticated remote profile connection
@@ -54,23 +52,23 @@ function nav(&$a) {
$homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
if(($a->module != 'home') && (! (local_user())))
- $a->page['nav'] .= '<a id="nav-home-link" class="nav-commlink" href="' . $homelink . '">' . t('Home') . "</a>\r\n";
+ $nav['home'] = array($homelink, t('Home'), "");
if(($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user()))
- $a->page['nav'] .= '<a id="nav-register-link" class="nav-commlink" href="register" >'
- . t('Register') . "</a>\r\n";
+ $nav['register'] = array('register',t('Register'), "");
$help_url = $a->get_baseurl() . '/help';
if(! get_config('system','hide-help'))
- $a->page['nav'] .= '<a id="nav-help-link" class="nav-link" target="friendika-help" href="' . $help_url . '">' . t('Help') . "</a>\r\n";
+ $nav['help'] = array($help_url, t('Help'), "");
+
if(strlen($a->apps)) {
- $a->page['nav'] .= '<a id="nav-apps-link" class="nav-link" href="apps">' . t('Apps') . "</a>\r\n";
+ $nav['apps'] = array('apps', t('Apps'), "");
}
- $a->page['nav'] .= '<a id="nav-search-link" class="nav-link" href="search">' . t('Search') . "</a>\r\n";
+ $nav['search'] = array('search', t('Search'), "");
$gdirpath = 'directory';
@@ -80,7 +78,7 @@ function nav(&$a) {
$gdirpath = $gdir;
}
- $a->page['nav'] .= '<a id="nav-directory-link" class="nav-link" href="' . $gdirpath . '">' . t('Directory') . "</a>\r\n";
+ $nav['directory'] = array($gdirpath, t('Directory'), "");
/**
*
@@ -90,36 +88,30 @@ function nav(&$a) {
if(local_user()) {
- $a->page['nav'] .= '<a id="nav-network-link" class="nav-commlink" href="network">' . t('Network')
- . '</a><span id="net-update" class="nav-ajax-left"></span>' . "\r\n";
+ $nav['network'] = array('network', t('Network'), "");
+
+ $nav['home'] = array('profile/' . $a->user['nickname'], t('Home'), "");
- $a->page['nav'] .= '<a id="nav-home-link" class="nav-commlink" href="profile/' . $a->user['nickname'] . '">'
- . t('Home') . '</a><span id="home-update" class="nav-ajax-left"></span>' . "\r\n";
/* only show friend requests for normal pages. Other page types have automatic friendship. */
if($_SESSION['page_flags'] == PAGE_NORMAL) {
- $a->page['nav'] .= '<a id="nav-notify-link" class="nav-commlink" href="notifications">' . t('Notifications')
- . '</a><span id="notify-update" class="nav-ajax-left"></span>' . "\r\n";
+ $nav['notifications'] = array('notifications', t('Notifications'), "");
}
- $a->page['nav'] .= '<a id="nav-messages-link" class="nav-commlink" href="message">' . t('Messages')
- . '</a><span id="mail-update" class="nav-ajax-left"></span>' . "\r\n";
+ $nav['messages'] = array('message', t('Messages'), "");
if(is_array($a->identities) && count($a->identities) > 1) {
- $a->page['nav'] .= '<a id="nav-manage-link" class="nav-commlink" href="manage">' . t('Manage') . '</a>' . "\r\n";
+ $nav['manage'] = array('manage', t('Manage'), "");
}
- $a->page['nav'] .= '<a id="nav-settings-link" class="nav-link" href="settings">' . t('Settings') . "</a>\r\n";
-
- $a->page['nav'] .= '<a id="nav-profiles-link" class="nav-link" href="profiles">' . t('Profiles') . "</a>\r\n";
-
- $a->page['nav'] .= '<a id="nav-contacts-link" class="nav-link" href="contacts">' . t('Contacts') . "</a>\r\n";
+ $nav['settings'] = array('settings', t('Settings'),"");
+ $nav['profiles'] = array('profiles', t('Profiles'),"");
+ $nav['contacts'] = array('contacts', t('Contacts'),"");
}
- $a->page['nav'] .= "</span>\r\n<span id=\"nav-end\"></span>\r\n";
/**
*
@@ -133,7 +125,14 @@ function nav(&$a) {
$banner .= '<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>';
- $a->page['nav'] .= '<span id="banner">' . $banner . '</span>';
+ $tpl = load_view_file('view/nav.tpl');
+
+ $a->page['nav'] .= replace_macros($tpl, array(
+ '$langselector' => lang_selector(),
+ '$sitelocation' => $sitelocation,
+ '$nav' => $nav,
+ '$banner' => $banner,
+ ));
call_hooks('page_header', $a->page['nav']);
diff --git a/include/template_processor.php b/include/template_processor.php
new file mode 100644
index 000000000..f6d0264df
--- /dev/null
+++ b/include/template_processor.php
@@ -0,0 +1,50 @@
+<?php
+
+
+ class Template {
+ var $s;
+ var $r;
+ var $search;
+ var $replace;
+
+ private function _build_replace($r, $prefix){
+
+ if(is_array($r) && count($r)) {
+ foreach ($r as $k => $v ) {
+ if (is_array($v))
+ $this->_build_replace($v, "$prefix$k.");
+
+ $this->search[] = $prefix . $k;
+ $this->replace[] = $v;
+ }
+ }
+ }
+
+ private function _replcb_if($m){
+ //echo "<pre>"; var_dump($m);
+ $keys = explode(".",$m[1]);
+ $val = $this->r;
+ foreach($keys as $k) {
+ $val = $val[$k];
+ }
+
+ //echo $val;
+ return ($val?$m[2]:"");
+ }
+
+ public function replace($s, $r) {
+ $this->s = $s;
+ $this->r = $r;
+ $this->search = array();
+ $this->replace = array();
+
+ $this->_build_replace($r, "");
+
+
+ $s = preg_replace_callback("|{{ *if *([^ }]*) *}}([^{]*){{ *endif *}}|", array($this, "_replcb_if"), $s);
+
+ return str_replace($this->search,$this->replace,$s);
+ }
+
+ }
+ $t = new Template;