зеркало из https://github.com/mozilla/pjs.git
Fixed up, commented, and implemented multiple caching.
Added global variables: cacheId compileId currentTab clean sql Moved trusted var arrays into init -- since they are always there, and if they are not used it'll just be a null array.
This commit is contained in:
Родитель
93eeb390e6
Коммит
1d9463f585
|
@ -6,19 +6,17 @@
|
|||
* @subpackage docs
|
||||
*/
|
||||
|
||||
startProcessing('addon.tpl');
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// Get the int value of our addon ID.
|
||||
$clean['ID'] = intval($_GET['id']);
|
||||
|
||||
// Since it is guaranteed to be just an int, we can reference it.
|
||||
$sql['ID'] =& $clean['ID'];
|
||||
|
||||
// Set the cachId so we have a unique cache for each AddOn ID.
|
||||
$cacheId = $clean['ID'];
|
||||
|
||||
startProcessing('addon.tpl',$cacheId,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
|
||||
// Create our AddOn object using the ID.
|
||||
$addon = new AddOn($sql['ID']);
|
||||
|
||||
|
|
|
@ -5,17 +5,15 @@
|
|||
* @subpackage docs
|
||||
*/
|
||||
|
||||
startProcessing('author.tpl');
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// Get our addon ID.
|
||||
$clean['UserID'] = intval($_GET['id']);
|
||||
$sql['UserID'] =& $clean['UserID'];
|
||||
|
||||
$cacheId = $clean['UserID'];
|
||||
|
||||
startProcessing('author.tpl',$cacheId,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$user = new User($sql['UserID']);
|
||||
|
||||
// Assign template variables.
|
||||
|
|
|
@ -6,17 +6,15 @@
|
|||
* @subpackage docs
|
||||
*/
|
||||
|
||||
startProcessing('comments.tpl');
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// Get our addon ID.
|
||||
$clean['ID'] = intval($_GET['id']);
|
||||
$sql['ID'] =& $clean['ID'];
|
||||
|
||||
$cacheid = $clean['ID'];
|
||||
|
||||
startProcessing('comments.tpl',$cacheId,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$addon = new AddOn($sql['ID']);
|
||||
$addon->getComments('50');
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @todo FAQ search?
|
||||
*/
|
||||
|
||||
startProcessing('faq.tpl');
|
||||
startProcessing('faq.tpl',null,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$db->query("
|
||||
|
@ -44,7 +44,4 @@ $tpl->assign(
|
|||
'content' => 'faq.tpl',
|
||||
'title' => 'Frequently Asked Questions')
|
||||
);
|
||||
|
||||
// No need to set wrapper, since the left-nav wrapper is default.
|
||||
// $wrapper = 'inc/wrappers/default.tpl';
|
||||
?>
|
||||
|
|
|
@ -10,17 +10,15 @@
|
|||
* @todo do we still want to allow users access to old versions?
|
||||
*/
|
||||
|
||||
startProcessing('history.tpl');
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// Get our addon ID.
|
||||
$clean['ID'] = intval($_GET['id']);
|
||||
$sql['ID'] =& $clean['ID'];
|
||||
|
||||
$cacheId = $clean['ID'];
|
||||
|
||||
startProcessing('history.tpl',$cacheId,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$addon = new AddOn($sql['ID']);
|
||||
$addon->getHistory();
|
||||
|
||||
|
|
|
@ -9,32 +9,31 @@
|
|||
* @todo Get main template spruced up.
|
||||
*/
|
||||
|
||||
startProcessing('index.tpl', 'nonav');
|
||||
require_once('includes.php');
|
||||
$currentTab = 'home';
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
startProcessing('index.tpl', null, $compileId, 'nonav');
|
||||
require_once('includes.php');
|
||||
|
||||
// If app is not set or empty, set it to null for our switch.
|
||||
$_GET['app'] = (!empty($_GET['app'])) ? $_GET['app'] : null;
|
||||
|
||||
// Determine our application.
|
||||
switch( $_GET['app'] ) {
|
||||
case 'Mozilla':
|
||||
case 'mozilla':
|
||||
$clean['app'] = 'Mozilla';
|
||||
break;
|
||||
case 'Thunderbird':
|
||||
case 'thunderbird':
|
||||
$clean['app'] = 'Thunderbird';
|
||||
break;
|
||||
case 'Firefox':
|
||||
case 'firefox':
|
||||
default:
|
||||
$clean['app'] = 'Firefox';
|
||||
break;
|
||||
}
|
||||
|
||||
// $sql['app'] can equal $clean['app'] since it was assigned in a switch().
|
||||
$sql['app'] =& $clean['app'];
|
||||
// We have to ucfirst() it because the DB has caps.
|
||||
$sql['app'] = $clean['app'];
|
||||
|
||||
// Get most popular extensions based on application.
|
||||
$db->query("
|
||||
|
@ -63,10 +62,8 @@ $popularExtensions = $db->record;
|
|||
|
||||
// Assign template variables.
|
||||
$tpl->assign(
|
||||
array( 'popularExtensions' => $popularExtensions,
|
||||
array( 'popularExtensions' => $popularExtensions,
|
||||
'title' => $clean['app'].' Addons',
|
||||
'currentTab' => 'home')
|
||||
'currentTab' => $currentTab)
|
||||
);
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @todo talk to cbeard and rebron about establishing the policy document.
|
||||
*/
|
||||
|
||||
startProcessing('policy.tpl');
|
||||
startProcessing('policy.tpl',null,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$links = array(
|
||||
|
|
|
@ -6,17 +6,13 @@
|
|||
* @subpackage docs
|
||||
*/
|
||||
|
||||
startProcessing('previews.tpl');
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// Get our addon ID.
|
||||
// Get the int value of our addon ID.
|
||||
$clean['ID'] = intval($_GET['id']);
|
||||
$sql['ID'] =& $clean['ID'];
|
||||
|
||||
startProcessing('previews.tpl',$cacheId,$compileId);
|
||||
require_once('includes.php');
|
||||
|
||||
$addon = new AddOn($sql['ID']);
|
||||
$addon->getPreviews();
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@
|
|||
|
||||
require_once('includes.php');
|
||||
|
||||
// Arrays to store clean inputs.
|
||||
$clean = array(); // General array for verified inputs.
|
||||
$sql = array(); // Trusted for SQL.
|
||||
|
||||
// If some of the inputs don't exist, throw an error and exit
|
||||
if (empty($_GET['aid']) || empty($_GET['cid']) || empty($_GET['r'])) {
|
||||
triggerError('Missing required parameter(s). Script cannot continue.');
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
* @todo Get main template spruced up.
|
||||
*/
|
||||
|
||||
startProcessing('search-engines.tpl','nonav');
|
||||
$currentTab = 'search-engines';
|
||||
|
||||
startProcessing('search-engines.tpl',null,$compileId,'nonav');
|
||||
require_once('includes.php');
|
||||
|
||||
// Assign template variables.
|
||||
$tpl->assign(
|
||||
array( 'title' => 'Search Engines',
|
||||
'currentTab' => 'search-engines',
|
||||
'currentTab' => $currentTab,
|
||||
'content' => 'search-engines.tpl')
|
||||
);
|
||||
|
||||
$wrapper = 'inc/wrappers/nonav.tpl';
|
||||
?>
|
||||
|
|
|
@ -12,13 +12,9 @@
|
|||
* @todo fix CSS so the pull-downs look symmetrical before design freaks start crying.
|
||||
*/
|
||||
|
||||
startProcessing('search.tpl','nonav');
|
||||
startProcessing('search.tpl',null,null,'nonav');
|
||||
require_once('includes.php');
|
||||
|
||||
// Array to store clean inputs.
|
||||
$clean = array();
|
||||
$sql = array();
|
||||
|
||||
// Array to store our page information.
|
||||
$page = array();
|
||||
|
||||
|
@ -52,6 +48,8 @@ if (isset($_GET['date'])&&$_GET['date']!='null'&&ctype_alpha($_GET['date'])) {
|
|||
// Application.
|
||||
if (isset($_GET['app'])&&$_GET['app']!='null'&&ctype_alpha($_GET['app'])) {
|
||||
$clean['app'] = $_GET['app'];
|
||||
} elseif ($_GET['app']=='null') {
|
||||
unset($clean['app']);
|
||||
}
|
||||
|
||||
// Query.
|
||||
|
@ -282,7 +280,4 @@ $tpl->assign(
|
|||
'title' => 'Search'
|
||||
)
|
||||
);
|
||||
|
||||
// Set a non-default wrapper.
|
||||
$wrapper = 'inc/wrappers/nonav.tpl';
|
||||
?>
|
||||
|
|
|
@ -6,16 +6,28 @@
|
|||
* @subpackage inc
|
||||
*/
|
||||
|
||||
// If we do not have a pageType, we need to set one.
|
||||
if (empty($pageType)) {
|
||||
$pageType = "default";
|
||||
}
|
||||
|
||||
// Display our page header.
|
||||
$tpl->display('inc/wrappers/' . $pageType . '-header.tpl');
|
||||
//
|
||||
// $currentTab is set in init.php or the calling script,
|
||||
// and corresponds to the selected tab in the header.tpl template.
|
||||
//
|
||||
// $compileId is set in init.php and corresponds to the current app.
|
||||
$tpl->display('inc/wrappers/' . $pageType . '-header.tpl',$currentTab,$compileId);
|
||||
|
||||
// Display page content..
|
||||
$tpl->display($content);
|
||||
// Display page content.
|
||||
//
|
||||
// $cacheId is set in init.php or the colling script. It
|
||||
// is unique for any number of combinations of parameters (GET, typically).
|
||||
//
|
||||
// $compileId is set in init.php and corresponds to the current app.
|
||||
$tpl->display($content,$cacheId,$compileId);
|
||||
|
||||
// Display our page footer.
|
||||
// Display our page footer. We do not pass it a cacheId or compileId
|
||||
// because the footer doesn't change based on parameters.
|
||||
$tpl->display('inc/wrappers/' . $pageType . '-footer.tpl');
|
||||
?>
|
||||
|
|
|
@ -6,18 +6,61 @@
|
|||
* @subpackage docs
|
||||
* @todo find a more elegant way to push in global template data (like $cats)
|
||||
*/
|
||||
// Include config file.
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Require our config, smarty class.
|
||||
*/
|
||||
require_once('config.php');
|
||||
require_once(SMARTY_BASEDIR.'/Smarty.class.php'); // Smarty
|
||||
|
||||
// Set runtime options.
|
||||
|
||||
|
||||
/**
|
||||
* Set runtime options.
|
||||
*/
|
||||
ini_set('display_errors',DISPLAY_ERRORS);
|
||||
ini_set('error_reporting',ERROR_REPORTING);
|
||||
ini_set('magic_quotes_gpc',0);
|
||||
|
||||
$tpl = null;
|
||||
|
||||
// Smarty configuration.
|
||||
|
||||
/**
|
||||
* Set up global variables.
|
||||
*/
|
||||
$tpl = null; // Smarty.
|
||||
$content = null; // Name of .tpl file to be called for content.
|
||||
$pageType = null; // Wrapper type for wrapping content .tpl.
|
||||
$cacheId = null; // Name of the page cache for use with Smarty caching.
|
||||
$currentTab = null; // Name of the currentTab selected in the header.tpl. This is also the cacheId for header.tpl.
|
||||
$compileId = null; // Name of the compileId for use with Smarty caching.
|
||||
$clean = array(); // General array for verified inputs. These variables should not be formatted for a specific medium.
|
||||
$sql = array(); // Trusted for SQL. Items in this array must be trusted through logic or through escaping.
|
||||
|
||||
// If app is not set or empty, set it to null for our switch.
|
||||
$_GET['app'] = (!empty($_GET['app'])) ? $_GET['app'] : null;
|
||||
|
||||
// Determine our application, and set the compileId to match it.
|
||||
// cacheId is set per page, since that is a bit more complicated.
|
||||
switch( $_GET['app'] ) {
|
||||
case 'mozilla':
|
||||
$compileId = 'mozilla';
|
||||
break;
|
||||
case 'thunderbird':
|
||||
$compileId = 'thunderbird';
|
||||
break;
|
||||
case 'firefox':
|
||||
default:
|
||||
$compileId = 'firefox';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Smarty configuration.
|
||||
*/
|
||||
class AMO_Smarty extends Smarty
|
||||
{
|
||||
function AMO_Smarty()
|
||||
|
@ -36,20 +79,33 @@ class AMO_Smarty extends Smarty
|
|||
}
|
||||
}
|
||||
|
||||
function startProcessing($aTplName, $aPageType='default')
|
||||
|
||||
|
||||
/**
|
||||
* Begin template processing. Check to see if page output is cached.
|
||||
* If it is already cached, display cached output.
|
||||
* If it is not cached, continue typical runtime.
|
||||
*
|
||||
* @param string $aTplName name of the template to process
|
||||
* @param string $aCacheId name of the cache to check - this corresponds to other $_GET params
|
||||
* @param string $aCompileId name of the compileId to check - this is $_GET['app']
|
||||
* @param string $aPageType type of the page - nonav, default, etc.
|
||||
*/
|
||||
function startProcessing($aTplName, $aCacheId, $aCompileId, $aPageType='default')
|
||||
{
|
||||
// Global template object.
|
||||
global $tpl, $pageType, $content;
|
||||
// Pass in our global variables.
|
||||
global $tpl, $pageType, $content, $cacheId, $compileId;
|
||||
|
||||
$pageType = $aPageType;
|
||||
$content = $aTplName;
|
||||
$cacheId = $aCacheId;
|
||||
$compileId = $aCompileId;
|
||||
|
||||
$tpl = new AMO_Smarty();
|
||||
|
||||
if ($tpl->is_cached($aTplName)) {
|
||||
if ($tpl->is_cached($aTplName, $aCacheId, $aCompileId)) {
|
||||
require_once('finish.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
Загрузка…
Ссылка в новой задаче