Add Smartphone class

Fix: mutualized code
This commit is contained in:
Regis Houssin 2010-09-22 08:52:48 +00:00
parent 97ca7bdfab
commit 298c4c6fc7
7 changed files with 115 additions and 59 deletions

View File

@ -33,6 +33,8 @@ class Smartphone {
var $phone; var $phone;
var $theme; var $theme;
var $title;
var $template_dir;
/** /**
* Constructor for class * Constructor for class
@ -52,21 +54,38 @@ class Smartphone {
if (preg_match('/android|blackberry|iphone/i',$this->phone)) if (preg_match('/android|blackberry|iphone/i',$this->phone))
{ {
$this->theme = 'default'; $this->theme = 'default';
$template_dir=DOL_DOCUMENT_ROOT."/theme/phones/smartphone/tpl/"; $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/smartphone/tpl/";
} }
// Special template // Special template
elseif (file_exists(DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone)) elseif (file_exists(DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone))
{ {
$this->theme = 'default'; $this->theme = 'default';
$template_dir=DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone."/tpl/"; $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/".$this->phone."/tpl/";
} }
// Default template // Default template
else else
{ {
$template_dir=DOL_DOCUMENT_ROOT."/theme/phones/others/tpl/"; $this->template_dir=DOL_DOCUMENT_ROOT."/theme/phones/others/tpl/";
} }
return $template_dir;
} }
/**
* Show HTML header
* @param title Web page title
*/
function smartheader()
{
global $conf;
include_once($this->template_dir.'header.tpl.php');
}
/**
* Show HTML footer
*/
function smartfooter()
{
include_once($this->template_dir.'footer.tpl.php');
}
} }

View File

@ -51,11 +51,18 @@ function dol_loginfunction($langs,$conf,$mysoc)
$php_self = $_SERVER['PHP_SELF']; $php_self = $_SERVER['PHP_SELF'];
$php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:''; $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';
// Title
$title='Dolibarr '.DOL_VERSION;
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
// Select templates // Select templates
if (class_exists('Smartphone')) if (class_exists('Smartphone'))
{ {
$template_dir = $smartphone->getTemplateDir(); // Template directory
$smartphone->getTemplateDir();
$smartphone->title = $title;
$template_dir = $smartphone->template_dir;
} }
else else
{ {
@ -88,10 +95,6 @@ function dol_loginfunction($langs,$conf,$mysoc)
$login_background=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png'; $login_background=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png';
} }
// Title
$title='Dolibarr '.DOL_VERSION;
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
$demologin=''; $demologin='';
$demopassword=''; $demopassword='';
if (! empty($dolibarr_main_demo)) if (! empty($dolibarr_main_demo))

View File

@ -0,0 +1,27 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
?>
<!-- BEGIN FOOTER SMARTPHONE TEMPLATE -->
</body>
</html>
<!-- END FOOTER SMARTPHONE TEMPLATE -->

View File

@ -0,0 +1,43 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
header('Cache-Control: Public, must-revalidate');
header("Content-type: text/html; charset=".$conf->file->character_set_client);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- BEGIN HEADER SMARTPHONE TEMPLATE -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $this->title; ?></title>
<meta name="robots" content="noindex,nofollow" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="apple-touch-icon" href="<?php echo DOL_URL_ROOT.'/theme/phones/smartphone/theme/'.$this->theme.'/thumbs/homescreen.png'; ?>" />
<meta name="viewport"content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" />
<link type="text/css" rel="stylesheet" href="<?php echo DOL_URL_ROOT.'/theme/phones/smartphone/theme/'.$this->theme.'/'.$this->theme.'.css.php'; ?>" />
<script type="text/javascript" src="<?php echo DOL_URL_ROOT.'/includes/iwebkit/Framework/javascript/functions.js'; ?>"></script>
</head>
<body>
<!-- END HEADER SMARTPHONE TEMPLATE -->

View File

@ -17,28 +17,10 @@
* *
* $Id$ * $Id$
*/ */
header('Cache-Control: Public, must-revalidate'); $smartphone->smartheader($title);
header("Content-type: text/html; charset=".$conf->file->character_set_client);
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <!-- START LOGIN SMARTPHONE TEMPLATE -->
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- BEGIN PHP TEMPLATE -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title; ?></title>
<meta name="robots" content="noindex,nofollow" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="apple-touch-icon" href="<?php echo $dol_url_root.'/theme/phones/smartphone/theme/'.$smartphone->theme.'/thumbs/homescreen.png'; ?>" />
<meta name="viewport"content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" />
<link type="text/css" rel="stylesheet" href="<?php echo $dol_url_root.'/theme/phones/smartphone/theme/'.$smartphone->theme.'/'.$smartphone->theme.'.css.php'; ?>" />
<script type="text/javascript" src="<?php echo $dol_url_root.'/includes/iwebkit/Framework/javascript/functions.js'; ?>"></script>
</head>
<body>
<div id="topbar"> <div id="topbar">
<div id="title"><?php echo $title; ?></div> <div id="title"><?php echo $title; ?></div>
@ -127,7 +109,6 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client);
</script> </script>
<?php } ?> <?php } ?>
</body> <?php $smartphone->smartfooter(); ?>
</html>
<!-- END PHP TEMPLATE --> <!-- END LOGIN SMARTPHONE TEMPLATE -->

View File

@ -17,27 +17,10 @@
* *
* $Id$ * $Id$
*/ */
header('Cache-Control: Public, must-revalidate'); $smartphone->smartheader($title);
header("Content-type: text/html; charset=".$conf->file->character_set_client);
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" <!-- BEGIN SMARTPHONE TEMPLATE -->
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- BEGIN PHP TEMPLATE -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $langs->trans('Password'); ?></title>
<meta name="robots" content="noindex,nofollow" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport"content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" />
<link type="text/css" rel="stylesheet" href="<?php echo $dol_url_root.'/theme/phones/smartphone/theme/'.$smartphone->theme.'/'.$smartphone->theme.'.css.php'; ?>" />
<script type="text/javascript" src="<?php echo $dol_url_root.'/includes/iwebkit/Framework/javascript/functions.js'; ?>"></script>
</head>
<body>
<div id="topbar"> <div id="topbar">
<div id="title"><?php echo $langs->trans('Password'); ?></div> <div id="title"><?php echo $langs->trans('Password'); ?></div>
@ -112,7 +95,6 @@ header("Content-type: text/html; charset=".$conf->file->character_set_client);
</script> </script>
<?php } ?> <?php } ?>
</body> <?php $smartphone->smartfooter(); ?>
</html>
<!-- END PHP TEMPLATE --> <!-- END SMARTPHONE TEMPLATE -->

View File

@ -143,11 +143,16 @@ $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';
$dol_url_root = DOL_URL_ROOT; $dol_url_root = DOL_URL_ROOT;
// Title
$title='Dolibarr '.DOL_VERSION;
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
// Select templates // Select templates
if (class_exists('Smartphone')) if (class_exists('Smartphone'))
{ {
// Template directory // Template directory
$smartphone->getTemplateDir(); $smartphone->getTemplateDir();
$smartphone->title = $title;
$template_dir = $smartphone->template_dir; $template_dir = $smartphone->template_dir;
} }
else else
@ -177,10 +182,6 @@ else
if (! $_REQUEST["username"]) $focus_element = 'username'; if (! $_REQUEST["username"]) $focus_element = 'username';
else $focus_element = 'password'; else $focus_element = 'password';
// Title
$title='Dolibarr '.DOL_VERSION;
if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;
// Send password button enabled ? // Send password button enabled ?
$disabled='disabled'; $disabled='disabled';
if ($mode == 'dolibarr') $disabled=''; if ($mode == 'dolibarr') $disabled='';