diff --git a/webtools/addons/public/htdocs/addon.php b/webtools/addons/public/htdocs/addon.php index 5ce9db91501b..add08752a667 100644 --- a/webtools/addons/public/htdocs/addon.php +++ b/webtools/addons/public/htdocs/addon.php @@ -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']); diff --git a/webtools/addons/public/htdocs/author.php b/webtools/addons/public/htdocs/author.php index faf93e57e728..417d6bb3f2f8 100644 --- a/webtools/addons/public/htdocs/author.php +++ b/webtools/addons/public/htdocs/author.php @@ -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. diff --git a/webtools/addons/public/htdocs/comments.php b/webtools/addons/public/htdocs/comments.php index 0bfabce7fb0f..c70eeb49bec5 100644 --- a/webtools/addons/public/htdocs/comments.php +++ b/webtools/addons/public/htdocs/comments.php @@ -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'); diff --git a/webtools/addons/public/htdocs/faq.php b/webtools/addons/public/htdocs/faq.php index 95b004065fc9..79cf23974f7d 100644 --- a/webtools/addons/public/htdocs/faq.php +++ b/webtools/addons/public/htdocs/faq.php @@ -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'; ?> diff --git a/webtools/addons/public/htdocs/history.php b/webtools/addons/public/htdocs/history.php index 97919ca9105c..9b30bdcf3165 100644 --- a/webtools/addons/public/htdocs/history.php +++ b/webtools/addons/public/htdocs/history.php @@ -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(); diff --git a/webtools/addons/public/htdocs/index.php b/webtools/addons/public/htdocs/index.php index 392b0b5edb64..5a63fb8dce96 100644 --- a/webtools/addons/public/htdocs/index.php +++ b/webtools/addons/public/htdocs/index.php @@ -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) ); - - ?> diff --git a/webtools/addons/public/htdocs/policy.php b/webtools/addons/public/htdocs/policy.php index 00f4d915b1a0..997a62c366eb 100644 --- a/webtools/addons/public/htdocs/policy.php +++ b/webtools/addons/public/htdocs/policy.php @@ -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( diff --git a/webtools/addons/public/htdocs/previews.php b/webtools/addons/public/htdocs/previews.php index 53e91a197cce..f61a7a1e7c81 100644 --- a/webtools/addons/public/htdocs/previews.php +++ b/webtools/addons/public/htdocs/previews.php @@ -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(); diff --git a/webtools/addons/public/htdocs/ratecomment.php b/webtools/addons/public/htdocs/ratecomment.php index bd0255a806f9..10e0ed81ecee 100644 --- a/webtools/addons/public/htdocs/ratecomment.php +++ b/webtools/addons/public/htdocs/ratecomment.php @@ -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.'); diff --git a/webtools/addons/public/htdocs/search-engines.php b/webtools/addons/public/htdocs/search-engines.php index 3e8e72db0a7c..6aa053dd9bba 100644 --- a/webtools/addons/public/htdocs/search-engines.php +++ b/webtools/addons/public/htdocs/search-engines.php @@ -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'; ?> diff --git a/webtools/addons/public/htdocs/search.php b/webtools/addons/public/htdocs/search.php index 5dc1786f768a..c7dcae9cab02 100644 --- a/webtools/addons/public/htdocs/search.php +++ b/webtools/addons/public/htdocs/search.php @@ -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'; ?> diff --git a/webtools/addons/public/inc/finish.php b/webtools/addons/public/inc/finish.php index b154eba9fd90..64d1d6ef61ab 100644 --- a/webtools/addons/public/inc/finish.php +++ b/webtools/addons/public/inc/finish.php @@ -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'); ?> diff --git a/webtools/addons/public/inc/init.php b/webtools/addons/public/inc/init.php index 7b8019414bce..94157b8e12be 100644 --- a/webtools/addons/public/inc/init.php +++ b/webtools/addons/public/inc/init.php @@ -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; } } - - ?>