From b4c43520803e11a62b03e500192f4de9a9c3d960 Mon Sep 17 00:00:00 2001
From: Cameron <e107inc@gmail.com>
Date: Mon, 29 Feb 2016 15:13:32 -0800
Subject: [PATCH] Login page template/shortcode fixes.

---
 .../shortcodes/batch/login_shortcodes.php     | 10 ++-
 e107_core/templates/login_template.php        | 25 +++---
 e107_handlers/e_parse_class.php               |  7 +-
 e107_handlers/shortcode_handler.php           |  4 +
 e107_themes/bootstrap3/style.css              |  3 +
 e107_web/css/backcompat.css                   |  5 +-
 login.php                                     | 88 +++++++------------
 7 files changed, 69 insertions(+), 73 deletions(-)

diff --git a/e107_core/shortcodes/batch/login_shortcodes.php b/e107_core/shortcodes/batch/login_shortcodes.php
index 666e1b9a3..6566ab24e 100644
--- a/e107_core/shortcodes/batch/login_shortcodes.php
+++ b/e107_core/shortcodes/batch/login_shortcodes.php
@@ -95,16 +95,22 @@ class login_shortcodes extends e_shortcode
 	{
 		return LAN_LOGIN_8;	
 	}
+
+	function sc_login_table_rememberme($parm=null)
+	{
+		return e107::getForm()->checkbox('autologin',1,false,LAN_LOGIN_8);
+
+	}
 	
 	function sc_login_table_submit($parm="") //FIXME use $frm
 	{
 		
-		$class = ($parm == 'large') ? "btn-large" : "";		
+		$class = ($parm == 'large') ? "btn-large btn-lg" : "";
 		return "<input class='btn btn-primary ".$class." button' type='submit' name='userlogin' value=\"".LAN_LOGIN_9."\" />";
 	}
 	
 	
-	function sc_login_table_footer_userreg()
+	function sc_login_table_footer_userreg($parm='')
 	{
 		$pref = e107::getPref();
 		
diff --git a/e107_core/templates/login_template.php b/e107_core/templates/login_template.php
index fc56a3fb9..75c3e1aa7 100644
--- a/e107_core/templates/login_template.php
+++ b/e107_core/templates/login_template.php
@@ -2,7 +2,7 @@
 // $Id$
 
 if (!defined('e107_INIT')) { exit; }
-
+/*
 // ##### LOGIN HEADER TABLE -----------------------------------------------------------------------
 if(!isset($LOGIN_TABLE_HEADER)) //FIXME - use {LOGO} . 
 {
@@ -77,14 +77,14 @@ if(!isset($LOGIN_TABLE_FOOTER))
 		</div>
 	</div>";
 }
-// ##### ------------------------------------------------------------------------------------------
+// ##### ------------------------------------------------------------------------------------------*/
 
 
 
 // Starter for v2. - Bootstrap 
 $LOGIN_TEMPLATE['page']['header'] = "
 	<div id='login-template'>
-		<div class='center' style='padding:50px; margin-left:auto; margin-right: auto'>
+		<div class='center'>
 			{LOGO=login}
 		</div>";
 
@@ -102,24 +102,27 @@ $LOGIN_TEMPLATE['page']['body'] = '
 	{
 	  $LOGIN_TEMPLATE['page']['body'] .= "<span>";
 	}
+
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_USERNAME'] = "<div class='form-group'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_PASSWORD'] = "<div class='form-group'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_SECIMG_SECIMG'] = "<div class='form-group'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_SECIMG_TEXTBOC'] = "<div class='form-group'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_REMEMBERME'] = "<div class='form-group checkbox'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_SUBMIT'] = "<div class='form-group'>{---}</div>";
+$LOGIN_WRAPPER['page']['LOGIN_TABLE_FOOTER_USERREG'] = "<div class='form-group'>{---}</div>";
+
 $LOGIN_TEMPLATE['page']['body'] .= '
        {LOGIN_TABLE_USERNAME}
         {LOGIN_TABLE_PASSWORD}
 		{LOGIN_TABLE_SECIMG_SECIMG} {LOGIN_TABLE_SECIMG_TEXTBOC}
-		</span>
-        <label class="checkbox">
-         {LOGIN_TABLE_AUTOLOGIN} {LOGIN_TABLE_AUTOLOGIN_LAN}
-        </label>
+        {LOGIN_TABLE_REMEMBERME}
         {LOGIN_TABLE_SUBMIT=large}
 
  ';
 
 $LOGIN_TEMPLATE['page']['footer'] =  "
 			<div style='margin-bottom:100px; width:70%;margin-right:auto;margin-left:auto'>
-				<div style='text-align:center'><br />
-					{LOGIN_TABLE_FOOTER_USERREG}
-					
-				</div>
+				<div style='text-align:center'>{LOGIN_TABLE_FOOTER_USERREG}</div>
 			</div>
 	</div>";
 	
diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php
index a2b6f2ade..04982cb87 100644
--- a/e107_handlers/e_parse_class.php
+++ b/e107_handlers/e_parse_class.php
@@ -828,13 +828,18 @@ class e_parse extends e_parser
 	 * @param object $eVars - XXX more info needed.
 	 * @return string
 	 */
-	function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = null, $eVars = null)
+	function parseTemplate($text, $parseSCFiles = true, $extraCodes = null, $eVars = null)
 	{
 		if(!empty($extraCodes) && $this->isSimpleParse($extraCodes)) // support for a combined simple and standard template parse. - (eg. used by signup email template.) 
 		{
 			$text = $this->simpleParse($text, $extraCodes, false);
 		}
 
+		if(!is_bool($parseSCFiles))
+		{
+			trigger_error("\$parseSCFiles in parseTemplate() was given incorrect data");
+		}
+
 		return e107::getScParser()->parseCodes($text, $parseSCFiles, $extraCodes, $eVars);
 	}
 
diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php
index 023da9048..25e078e68 100644
--- a/e107_handlers/shortcode_handler.php
+++ b/e107_handlers/shortcode_handler.php
@@ -748,6 +748,8 @@ class e_parse_shortcode
 		
 		if (is_object($extraCodes))
 		{
+
+
 	
 			$this->addedCodes = &$extraCodes;
 			
@@ -1302,6 +1304,8 @@ class e_shortcode
 	 * Sets wrapper id (to be retrieved from the registry while parsing)
 	 * Example e107::getScBatch('contact')->wrapper('contact/form');
 	 * which results in using the $CONTACT_WRAPPER['form'] wrapper in the parsing phase
+	 * Template cannot be loaded via include, only by getTemplate or getCoreTemplate
+	 * e107::getScBatch() must be used also.
 	 */
 	public function wrapper($id = null)
 	{
diff --git a/e107_themes/bootstrap3/style.css b/e107_themes/bootstrap3/style.css
index 51f991aee..31ada6360 100644
--- a/e107_themes/bootstrap3/style.css
+++ b/e107_themes/bootstrap3/style.css
@@ -119,6 +119,9 @@ img.featurebox { border-radius: 5px }
 
 .tab-pane { padding-top:15px }
 
+#login-template { max-width: 330px;  margin-right: auto;  margin-left: auto;     }
+#login-template h2.caption { text-align:center; font-size:120%; opacity:0.8 }
+#login-template .logo { padding-top:50px; margin-left:auto; margin-right: auto }
 /* CUSTOM Responsive Styles */
 
 
diff --git a/e107_web/css/backcompat.css b/e107_web/css/backcompat.css
index bf334ff56..4c4de2ad5 100644
--- a/e107_web/css/backcompat.css
+++ b/e107_web/css/backcompat.css
@@ -18,4 +18,7 @@ a.btn           {  }
 				{ margin-top: 0; background: transparent none no-repeat scroll 0 50%; font-size:150%	}
 
 mark            { text-decoration: underline; color:#FF0000; font-weight:bold; } /* .searchhighlight */
-.list-unstyled  { list-style: outside none none; }
\ No newline at end of file
+.list-unstyled  { list-style: outside none none; }
+
+#login-template { width:60%; max-width:350px; margin-right:auto;margin-left:auto; }
+div.form-group  { padding-top: 5px }
\ No newline at end of file
diff --git a/login.php b/login.php
index 4ef07aff2..6a6ae52c3 100644
--- a/login.php
+++ b/login.php
@@ -20,16 +20,13 @@
 require_once("class2.php");
 include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_'.e_PAGE);
 
-if ((USER || e_LOGIN != e_SELF || empty($pref['user_reg']) ) && e_QUERY !== 'preview' ) // Disable page if user logged in, or some custom e_LOGIN value is used.
+if ((USER || e_LOGIN != e_SELF || empty($pref['user_reg']) ) && e_QUERY !== 'preview' && !getperms('0') ) // Disable page if user logged in, or some custom e_LOGIN value is used.
 {
 	e107::redirect();
 	exit();
 }
 
 define('e_IFRAME',true);
-//$HEADER = '';
-//$FOOTER='';				// Avoids strange displays when debug enabled! (But doesn't completely maintain XHTML formatting)
-
 require_once(HEADERF);
 $use_imagecode = ($pref['logcode'] && extension_loaded("gd"));
 
@@ -47,53 +44,37 @@ if (!USER || getperms('0'))
 	require_once(e_HANDLER.'form_handler.php'); // required for BC
 	$rs = new form; // required for BC
 	
-	
-//	$text = "";
- //   $allowEmailLogin = varset($pref['allowEmailLogin'],0);
- //   $ulabel = array(LAN_LOGIN_1,LAN_LOGIN_28,LAN_LOGIN_29);
-
-//	$LOGIN_USERNAME_LABEL = $ulabel[$allowEmailLogin];
-//	$LOGIN_TABLE_LOGINMESSAGE = LOGINMESSAGE;
-//	$LOGIN_TABLE_USERNAME = "<input class='tbox' type='text' name='username' id='username' size='40' maxlength='100' />";
-//	$LOGIN_TABLE_PASSWORD = "<input class='tbox' type='password' name='userpass' id='userpass' size='40' maxlength='100' />";
-	
-	// if (!USER && e107::getSession()->is('challenge') && varset($pref['password_CHAP'],0)) 
-	// {
-	  // $LOGIN_TABLE_PASSWORD .= "<input type='hidden' name='hashchallenge' id='hashchallenge' value='".e107::getSession()->get('challenge')."' />\n\n";
-	// }
-	
-	
-	
-//	if ($use_imagecode)
-//	{
-//		$LOGIN_TABLE_SECIMG_LAN = LAN_LOGIN_13;
-//		$LOGIN_TABLE_SECIMG_HIDDEN = "<input type='hidden' name='rand_num' value='".$sec_img->random_number."' />";
-	//	$LOGIN_TABLE_SECIMG_SECIMG = $sec_img->r_image();
-//		$LOGIN_TABLE_SECIMG_TEXTBOC = "<input class='tbox' type='text' name='code_verify' size='15' maxlength='20' />";
-//	}
-//	$LOGIN_TABLE_AUTOLOGIN = "<input type='checkbox' name='autologin' value='1' />";
-//	$LOGIN_TABLE_AUTOLOGIN_LAN = LAN_LOGIN_8;
-//	$LOGIN_TABLE_SUBMIT = "<input class='btn btn-primary button' type='submit' name='userlogin' value=\"".LAN_LOGIN_9."\" />";
-
-	if (!isset($LOGIN_TABLE) || !$LOGIN_TABLE)
+	if (empty($LOGIN_TABLE))
 	{
-		if (file_exists(THEME.'templates/login_template.php')) //v2.x path 
+
+		if(deftrue('BOOTSTRAP'))
 		{
-			require_once(THEME.'templates/login_template.php');
+			$LOGIN_TEMPLATE = e107::getCoreTemplate('login');
 		}
-		elseif (file_exists(THEME.'login_template.php'))
+		else // BC Stuff.
 		{
-			require_once(THEME.'login_template.php');
-		}
-		else
-		{
-			require_once(e_CORE."templates/login_template.php");
+
+			if (file_exists(THEME.'templates/login_template.php')) //v2.x path
+			{
+				require_once(THEME.'templates/login_template.php');
+			}
+			elseif (file_exists(THEME.'login_template.php'))
+			{
+				require_once(THEME.'login_template.php');
+			}
+			else
+			{
+				$LOGIN_TEMPLATE = e107::getCoreTemplate('login');
+			}
 		}
 	}
-	
+
+
 	$sc = e107::getScBatch('login');
-	
-	if((deftrue('BOOTSTRAP')) && isset($LOGIN_TEMPLATE['page']))
+	$sc->wrapper('login/page');
+
+
+	if(!empty($LOGIN_TEMPLATE['page']))
 	{
 		$LOGIN_TABLE_HEADER = $LOGIN_TEMPLATE['page']['header'];
 		$LOGIN_TABLE 		= "<form class='form-signin' method='post' action='".e_SELF."' onsubmit='hashLoginPassword(this)' >".$LOGIN_TEMPLATE['page']['body']."</form>";
@@ -102,31 +83,22 @@ if (!USER || getperms('0'))
 	
 	
 	$text = $tp->parseTemplate($LOGIN_TABLE,true, $sc);
-	
-	
-	
-//	$text = preg_replace("/\{(.*?)\}/e", 'varset($\1,"\1")', $LOGIN_TABLE);
-	
+
 	if(getperms('0'))
 	{
 		echo "<div class='alert alert-block alert-error alert-danger center'> You are currently logged in.</div>";	
 	}
 	
-//	echo preg_replace("/\{(.*?)\}/e", 'varset($\1,"\1")', $LOGIN_TABLE_HEADER);
+
 	$login_message = SITENAME; //	$login_message = LAN_LOGIN_3." | ".SITENAME;
 	echo LOGINMESSAGE;
-	echo $tp->parseTemplate($LOGIN_TABLE_HEADER, $sc);
+	echo $tp->parseTemplate($LOGIN_TABLE_HEADER,true, $sc);
 	$ns->tablerender($login_message, $text, 'login_page');
-	echo $tp->parseTemplate($LOGIN_TABLE_FOOTER, $sc);
-	
-	
-	// echo preg_replace("/\{([^ ]*?)\}/e", 'varset($\1,"\1")', $LOGIN_TABLE_FOOTER);
+	echo $tp->parseTemplate($LOGIN_TABLE_FOOTER, true, $sc);
+
 }
 
 require_once(FOOTERF);
 exit;
-//echo "</body></html>";
-
-// $sql->db_Close();
 
 ?>
\ No newline at end of file