From b8724bc4bc73d02b59015e53ce91afeab6490add Mon Sep 17 00:00:00 2001
From: Cameron <cameron@e107coders.org>
Date: Mon, 30 Dec 2013 06:23:12 -0800
Subject: [PATCH] Fixes #465 - Bootstrap3 layout with sidebar panel added. Menu
 Preset added. Bootstrap3 styling tweaks to news menus.

---
 e107_core/templates/header_default.php        |   4 +-
 e107_handlers/menumanager_class.php           |  62 ++++++---
 e107_handlers/theme_handler.php               |   8 +-
 .../blogcalendar_menu/blogcalendar_menu.php   |   6 +-
 e107_plugins/news/other_news_menu.php         |   4 +-
 .../news/templates/news_menu_template.php     |   4 +-
 e107_themes/bootstrap3/style.css              |   2 +-
 e107_themes/bootstrap3/theme.php              | 131 ++++++++----------
 e107_themes/bootstrap3/theme.xml              |  11 ++
 9 files changed, 121 insertions(+), 111 deletions(-)

diff --git a/e107_core/templates/header_default.php b/e107_core/templates/header_default.php
index 729654255..95b033c9e 100644
--- a/e107_core/templates/header_default.php
+++ b/e107_core/templates/header_default.php
@@ -581,8 +581,8 @@ echo "</head>\n";
 		foreach($LAYOUT as $key=>$template)
 		{
 			list($hd,$ft) = explode("{---}",$template);
-			$HEADER[$key] = $hd;
-			$FOOTER[$key] = $ft;	
+			$HEADER[$key] = isset($LAYOUT['_header_']) ? $LAYOUT['_header_'] . $hd : $hd;
+			$FOOTER[$key] = isset($LAYOUT['_footer_']) ? $ft . $LAYOUT['_footer_'] : $ft ;	
 		}	
 		unset($hd,$ft);
 	}
diff --git a/e107_handlers/menumanager_class.php b/e107_handlers/menumanager_class.php
index 8702c738e..06c7eada1 100644
--- a/e107_handlers/menumanager_class.php
+++ b/e107_handlers/menumanager_class.php
@@ -177,8 +177,8 @@ class e_menuManager {
 			foreach($LAYOUT as $key=>$template)
 			{
 				list($hd,$ft) = explode("{---}",$template);
-				$HEADER[$key] = $hd;
-				$FOOTER[$key] = $ft;	
+				$HEADER[$key] = isset($LAYOUT['_header_']) ? $LAYOUT['_header_'] . $hd : $hd;
+				$FOOTER[$key] = isset($LAYOUT['_footer_']) ? $ft . $LAYOUT['_footer_'] : $ft ;		
 			}	
 			unset($hd,$ft);
 		}
@@ -317,6 +317,7 @@ class e_menuManager {
 
 	    if(!$menuAreas = $this->getMenuPreset())
 		{
+			e107::getMessage()->addDebug("No Menu Preset Found");
         	return FALSE;
 		}
 
@@ -668,40 +669,55 @@ class e_menuManager {
 
 	    if(!isset($pref['sitetheme_layouts'][$layout]['menuPresets']))
 		{
+			e107::getMessage()->addDebug(print_a($pref['sitetheme_layouts'],true));
 	    	return FALSE;
 		}
 
 		$temp = $pref['sitetheme_layouts'][$layout]['menuPresets']['area'];
 
+	// print_a($temp);
+		$multiple = isset($temp['menu'][1]);	
+
 		foreach($temp as $key=>$val)
 		{
-			$iD = $val['@attributes']['id'];
-			if(varset($val['menu'][1]))  // More than one menu item under <area> in theme.xml.
+			if($val['id'])
 			{
-				foreach($val['menu'] as $k=>$v)
+				$iD = $val['id'];	
+			}
+		//	$iD = $val['id'];
+			
+			if($key == 'menu')
+			{
+				if($multiple)  // More than one menu item under <area> in theme.xml.
 				{
-				   //	$uclass = (defined(trim($v['@attributes']['perm']))) ? constant(trim($v['@attributes']['userclass'])) : 0;
-					$menuArea[] = array(
-						'menu_location' => $iD,
-						'menu_order'	=> $k,
-						'menu_name'		=> $v['@attributes']['name']."_menu",
-						'menu_class'	=> $this->menuPresetPerms($v['@attributes']['perm'])
-					);
+					foreach($val as $k=>$v)
+					{
+						
+					   //	$uclass = (defined(trim($v['@attributes']['perm']))) ? constant(trim($v['@attributes']['userclass'])) : 0;
+						$menuArea[] = array(
+							'menu_location' => $iD,
+							'menu_order'	=> $k,
+							'menu_name'		=> $v['@attributes']['name']."_menu",
+							'menu_class'	=> $this->menuPresetPerms($v['@attributes']['perm'])
+						);
+					}
+				}
+				else  // Only one menu item under <area> in theme.xml.
+				{
+				  //	$uclass = (defined(trim($val['menu']['@attributes']['userclass']))) ? constant(trim($val['menu']['@attributes']['userclass'])) : 0;
+	                $menuArea[] = array(
+							'menu_location' => $iD,
+							'menu_order'	=> 0,
+							'menu_name'		=> $val['menu']['@attributes']['name']."_menu",
+							'menu_class'	=> $this->menuPresetPerms($v['@attributes']['perm'])
+						);
 				}
 			}
-			else  // Only one menu item under <area> in theme.xml.
-			{
-			  //	$uclass = (defined(trim($val['menu']['@attributes']['userclass']))) ? constant(trim($val['menu']['@attributes']['userclass'])) : 0;
-                $menuArea[] = array(
-						'menu_location' => $iD,
-						'menu_order'	=> 0,
-						'menu_name'		=> $val['menu']['@attributes']['name']."_menu",
-						'menu_class'	=> $this->menuPresetPerms($v['@attributes']['perm'])
-					);
-			}
 		}
+		
+	//	print_a($menuArea);
 
-	    return $menuArea;
+	   return $menuArea;
 
 	}
 
diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php
index 01196d5df..153aa4487 100644
--- a/e107_handlers/theme_handler.php
+++ b/e107_handlers/theme_handler.php
@@ -1263,7 +1263,13 @@ class themeHandler
 							
 							$itext .= "<td>";
 							
-							$itext .= (varset($val['menuPresets'])) ? $this->frm->admin_button("setMenuPreset[".$key."]", "Use Preset") : "";
+							if(varset($val['menuPresets'])) 
+							{
+								$itext .= $this->frm->admin_button("setMenuPreset[".$key."]", "Use Preset");
+							//	$itext .= print_a($val['menuPresets'],true);
+							}
+							
+							
 							$itext .= "</td>
 			
 										</tr>";
diff --git a/e107_plugins/blogcalendar_menu/blogcalendar_menu.php b/e107_plugins/blogcalendar_menu/blogcalendar_menu.php
index 68b87e5b1..84ce98f62 100644
--- a/e107_plugins/blogcalendar_menu/blogcalendar_menu.php
+++ b/e107_plugins/blogcalendar_menu/blogcalendar_menu.php
@@ -162,8 +162,8 @@ if(false === $cached)
 	
 	if(deftrue('BOOTSTRAP')) // v2.x
 	{
-		$month_selector = '<div class="btn-group pull-right"><a class="btn btn-mini " href="#blogCalendar" data-slide="prev">‹</a>  
- 		<a class="btn btn-mini" href="#blogCalendar" data-slide="next">›</a></div>';
+		$month_selector = '<div class="btn-group pull-right"><a class="btn btn-mini btn-default btn-xs " href="#blogCalendar" data-slide="prev">‹</a>  
+ 		<a class="btn btn-mini btn-default btn-xs" href="#blogCalendar" data-slide="next">›</a></div>';
 		 
 		$caption = "<span class='inline-text'>".BLOGCAL_L1." ".$month_selector."</span>";	
 		
@@ -180,7 +180,7 @@ if(false === $cached)
 		
 		$menu .= "</div>";
 		$menu .= "<div class='blogcalendar-archive-link' >
-		<a class='blogcalendar-archive-link btn btn-small' href='$prefix/archive.php'>".BLOGCAL_L2."</a>
+		<a class='blogcalendar-archive-link btn btn-small btn-s btn-default' href='$prefix/archive.php'>".BLOGCAL_L2."</a>
 		</div>
 		</div>";
 		
diff --git a/e107_plugins/news/other_news_menu.php b/e107_plugins/news/other_news_menu.php
index 6a9b27793..50751537e 100644
--- a/e107_plugins/news/other_news_menu.php
+++ b/e107_plugins/news/other_news_menu.php
@@ -39,8 +39,8 @@ if(!$OTHERNEWS_STYLE)
 		define("OTHERNEWS_COLS",false);
 		$template = e107::getTemplate('news', 'news_menu', 'other');
 		
-		$item_selector = '<div class="btn-group pull-right"><a class="btn btn-mini " href="#otherNews" data-slide="prev">‹</a>  
- 		<a class="btn btn-mini" href="#otherNews" data-slide="next">›</a></div>';
+		$item_selector = '<div class="btn-group pull-right"><a class="btn btn-mini btn-xs btn-default" href="#otherNews" data-slide="prev">‹</a>  
+ 		<a class="btn btn-mini btn-xs btn-default" href="#otherNews" data-slide="next">›</a></div>';
 		 
 		$caption = "<span class='inline-text'>".$template['caption']." ".$item_selector."</span>";		
 				
diff --git a/e107_plugins/news/templates/news_menu_template.php b/e107_plugins/news/templates/news_menu_template.php
index a9fc15db9..ec211ad20 100644
--- a/e107_plugins/news/templates/news_menu_template.php
+++ b/e107_plugins/news/templates/news_menu_template.php
@@ -64,7 +64,7 @@ $NEWS_MENU_TEMPLATE['other']['item']		= '<div class="item {ACTIVE}">
 												{NEWSIMAGE}
               									<h3>{NEWSTITLE}</h3>
               									<p>{NEWSSUMMARY}</p>
-              									<p class="text-right"><a class="btn" href="{NEWSURL}">'.LAN_READ_MORE.' &raquo;</a></p>
+              									<p class="text-right"><a class="btn btn-default" href="{NEWSURL}">'.LAN_READ_MORE.' &raquo;</a></p>
             									</div>';									
 $NEWS_MENU_TEMPLATE['other']['end']			= "</div></div>";
 
@@ -82,7 +82,7 @@ $NEWS_MENU_TEMPLATE['other2']['start'] 	= "<ul class='media-list unstyled othern
 $NEWS_MENU_TEMPLATE['other2']['item'] 	= "<li class='media'>
 										<span class='media-object pull-left'>{NEWSIMAGE}</span> 
 										<div class='media-body'><h4>{NEWSTITLELINK}</h4>
-										<p class='text-right'><a class='btn' href='{NEWSURL}'>".LAN_READ_MORE." &raquo;</a></p>
+										<p class='text-right'><a class='btn btn-default' href='{NEWSURL}'>".LAN_READ_MORE." &raquo;</a></p>
 										</div>
 										</li>\n";
 										
diff --git a/e107_themes/bootstrap3/style.css b/e107_themes/bootstrap3/style.css
index 48a5f24a7..e09e84afd 100644
--- a/e107_themes/bootstrap3/style.css
+++ b/e107_themes/bootstrap3/style.css
@@ -1,6 +1,6 @@
 /* Move down content because we have a fixed navbar that is 50px tall */
 body {
-  padding-top: 50px;
+  padding-top: 70px;
   padding-bottom: 20px;
 }
 
diff --git a/e107_themes/bootstrap3/theme.php b/e107_themes/bootstrap3/theme.php
index 7b70aa616..9a5217281 100644
--- a/e107_themes/bootstrap3/theme.php
+++ b/e107_themes/bootstrap3/theme.php
@@ -50,7 +50,7 @@ function tablestyle($caption, $text, $mode='')
 	
 	if($style == 'col-md-4')
 	{
-		echo ' <div class="col-md-4">
+		echo ' <div class="col-xs-12 col-md-4">
           <h2>'.$caption.'</h2>
           '.$text.'
         </div>';
@@ -58,66 +58,31 @@ function tablestyle($caption, $text, $mode='')
 		
 	}
 		
-	
-	if($mode == 'loginbox') // Login Box Style. 
+	if($style == 'menu')
 	{
-		 echo '<div class="well sidebar-nav">
-		 <ul class="nav nav-list"><li class="nav-header">'.$caption.'</li></ul>
-		 
-           '.$text.'
-			
-        </div><!--/.well -->';
-          return;
-	}
-			
-	if($mode == 'login_page')
-	{
-		$type = 'no_caption';	
-	}
+		echo '<div class="panel panel-default">
+	  <div class="panel-heading">'.$caption.'</div>
+	  <div class="panel-body">
+	   '.$text.'
+	  </div>
+	</div>';
+		return;
+		
+	}	
+	
+	echo '<h2>'.$caption.'</h2>
+			<p>
+			'.$text.'
+			</p>';
+					
+	return;
+	
 	
-	switch($type) 
-	{
-		// Default Menu/Side-Panel Style
-		case 'menu' :
-			echo '<div class="well sidebar-nav">
-		 <ul class="nav nav-list"><li class="nav-header">'.$caption.'</li></ul>
-		 
-           '.$text.'
-			
-        </div><!--/.well -->';
-		break;
-		
-		case 'span4' :
-			echo $text; 
-		break;
-		
-		case 'box':
-			echo '
-				<div class="block">
-					<div class="block-text">
-						'.$text.'
-					</div>
-				</div>
-			';
-		break;
-		
-		case 'no_caption':
-			echo $text;
-		break;
 	
-		default: // Main Content Style. 
-			echo '
-				<h2>'.$caption.'</h2>
-					<p>
-						'.$text.'
-					</p>
-				
-			';
-		break;
-	}
 }
 
-$commonHead = '
+// applied before every layout.
+$LAYOUT['_header_'] = '
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
       <div class="container">
         <div class="navbar-header">
@@ -142,7 +107,8 @@ $commonHead = '
 	
 ';
 
-$commonFoot = '  <hr>
+// applied after every layout. 
+$LAYOUT['_footer_'] = '  <hr>
 
       <footer>
        {SITEDISCLAIMER}
@@ -151,13 +117,10 @@ $commonFoot = '  <hr>
 ';
 
 
+
 // $LAYOUT is a combined $HEADER and $FOOTER, automatically split at the point of "{---}"
 
-//TODO make $LAYOUT['_header_'] && $LAYOUT['_footer_']; and auto attach to main layout. 
-
-$LAYOUT['jumbotron_home'] = 
-
-	$commonHead . '
+$LAYOUT['jumbotron_home'] =  '
    
 	{SETSTYLE=default}
 	<div class="container">	
@@ -175,13 +138,11 @@ $LAYOUT['jumbotron_home'] =
 	  {CMENU=jumbotron-menu-3}
       </div>
 
-	'.$commonFoot;
+	';
 
 
 
-$LAYOUT['jumbotron_full'] = 
-
-	$commonHead . '
+$LAYOUT['jumbotron_full'] = '
    
 	{SETSTYLE=default}
 	<div class="container">	
@@ -194,22 +155,38 @@ $LAYOUT['jumbotron_full'] =
    
      
 
-	'.$commonFoot;
-
-
-
-
-
-
-
-
-
-
+	';
+
+
+
+$LAYOUT['jumbotron_sidebar_right'] =  '
+   
+	{SETSTYLE=default}
+	<div class="container">	
+	{ALERTS}
+		<div class="row">
+   			<div class="col-xs-12 col-md-8">	
+   		
+				{---}
+	
+ 			</div>
+        	<div id="sidebar" class="col-xs-12 col-md-4">
+        	{SETSTYLE=menu}
+        		{MENU=1}
+        	</div>
+      </div>
+	
+	</div>
+    <div class="container">
+      
+
+	';
 
 
 
 
 
+/* XXX EVERYTHING BELOW THIS POINT IS UNUSED FOR NOW */
 
 
 
diff --git a/e107_themes/bootstrap3/theme.xml b/e107_themes/bootstrap3/theme.xml
index f2b766fa7..3539b1df2 100644
--- a/e107_themes/bootstrap3/theme.xml
+++ b/e107_themes/bootstrap3/theme.xml
@@ -19,5 +19,16 @@
 			<custompages>FRONTPAGE</custompages>	
 		</layout>
 		<layout name='jumbotron_full' title='Jumbotron (full-width)' default='true' />
+		<layout name='jumbotron_sidebar_right' title='Jumbotron (sidebar-right)' >
+			<custompages>/news</custompages>
+			<menuPresets>
+				<area id='1'>
+					<menu name='other_news' />
+					<menu name='other_news2' />
+					<menu name='news_categories' />
+					<menu name='blogcalendar' />
+				</area>
+			</menuPresets>	
+		</layout>
 	</layouts>
 </e107Theme>
\ No newline at end of file