From d25387f0b597923ff4e8b7b71943c84279535c72 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 8 Jul 2013 14:16:52 +0200 Subject: [PATCH] Disable caching check on Smarty globals This will ensure data is available for those pages relying on global data. A better step might be to load template specific data always on the pages that require the data instead of relying on global data to be available. Fixes #309 --- public/include/smarty_globals.inc.php | 216 +++++++++++++------------- 1 file changed, 106 insertions(+), 110 deletions(-) diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 0f1e2896..8f543699 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -2,121 +2,117 @@ // Make sure we are called from index.php if (!defined('SECURITY')) - die('Hacking attempt'); + die('Hacking attempt'); // Globally available variables $debug->append('Global smarty variables', 3); -if (!$smarty->isCached('master.tpl', md5(serialize($_REQUEST)))) { - $debug->append('No cached page detected, loading smarty globals', 3); - // Defaults to get rid of PHP Notice warnings - $dDifficulty = 1; - $aRoundShares = 1; +$debug->append('No cached page detected, loading smarty globals', 3); +// Defaults to get rid of PHP Notice warnings +$dDifficulty = 1; +$aRoundShares = 1; - // Only run these if the user is logged in - if (@$_SESSION['AUTHENTICATED']) { - $aRoundShares = $statistics->getRoundShares(); - if ($bitcoin->can_connect() === true) { - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - } +// Only run these if the user is logged in +if (@$_SESSION['AUTHENTICATED']) { + $aRoundShares = $statistics->getRoundShares(); + if ($bitcoin->can_connect() === true) { + $dDifficulty = $bitcoin->query('getdifficulty'); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; } - // Always fetch this since we need for ministats header - $bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; - - // Fetch some data - $iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); - $iCurrentPoolHashrate = $statistics->getCurrentHashrate(); - $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); - - // Avoid confusion, ensure our nethash isn't higher than poolhash - if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; - - // Global data for Smarty - $aGlobal = array( - 'slogan' => $config['website']['slogan'], - 'websitename' => $config['website']['name'], - 'hashrate' => $iCurrentPoolHashrate, - 'nethashrate' => $dNetworkHashrate, - 'sharerate' => $iCurrentPoolShareRate, - 'workers' => $iCurrentActiveWorkers, - 'roundshares' => $aRoundShares, - 'fees' => $config['fees'], - 'confirmations' => $config['confirmations'], - 'reward' => $config['reward'], - 'price' => $setting->getValue('price'), - 'blockexplorer' => $config['blockexplorer'], - 'chaininfo' => $config['chaininfo'], - 'config' => array( - 'website' => array( 'title' => $config['website']['title'] ), - 'price' => array( 'currency' => $config['price']['currency'] ), - 'targetdiff' => $config['difficulty'], - 'currency' => $config['currency'], - 'txfee' => $config['txfee'], - 'payout_system' => $config['payout_system'], - 'ap_threshold' => array( - 'min' => $config['ap_threshold']['min'], - 'max' => $config['ap_threshold']['max'] - ) - ) - ); - - // Special calculations for PPS Values based on reward_type setting and/or available blocks - if ($config['reward_type'] != 'block') { - $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } else { - // Try to find the last block value and use that for future payouts, revert to fixed reward if none found - if ($aLastBlock = $block->getLast()) { - $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } else { - $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); - } - } - - // We don't want these session infos cached - if (@$_SESSION['USERDATA']['id']) { - $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); - $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); - - // Other userdata that we can cache savely - $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); - $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); - - switch ($config['payout_system']) { - case 'pps': - break; - default: - // Some estimations - if (@$aRoundShares['valid'] > 0) { - $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); - $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); - $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); - $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); - } else { - $aGlobal['userdata']['est_block'] = 0; - $aGlobal['userdata']['est_fee'] = 0; - $aGlobal['userdata']['est_donation'] = 0; - $aGlobal['userdata']['est_payout'] = 0; - } - break; - } - - // Site-wide notifications, based on user events - if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); - if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) - $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); - } - - if ($setting->getValue('maintenance')) - $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); - - // Make it available in Smarty - $smarty->assign('PATH', 'site_assets/' . THEME); - $smarty->assign('GLOBAL', $aGlobal); -} else { - $debug->append('We found a cached page, not loaded smarty globals', 3); } +// Always fetch this since we need for ministats header +$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; + +// Fetch some data +$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers(); +$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); +$iCurrentPoolShareRate = $statistics->getCurrentShareRate(); + +// Avoid confusion, ensure our nethash isn't higher than poolhash +if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate; + +// Global data for Smarty +$aGlobal = array( + 'slogan' => $config['website']['slogan'], + 'websitename' => $config['website']['name'], + 'hashrate' => $iCurrentPoolHashrate, + 'nethashrate' => $dNetworkHashrate, + 'sharerate' => $iCurrentPoolShareRate, + 'workers' => $iCurrentActiveWorkers, + 'roundshares' => $aRoundShares, + 'fees' => $config['fees'], + 'confirmations' => $config['confirmations'], + 'reward' => $config['reward'], + 'price' => $setting->getValue('price'), + 'blockexplorer' => $config['blockexplorer'], + 'chaininfo' => $config['chaininfo'], + 'config' => array( + 'website' => array( 'title' => $config['website']['title'] ), + 'price' => array( 'currency' => $config['price']['currency'] ), + 'targetdiff' => $config['difficulty'], + 'currency' => $config['currency'], + 'txfee' => $config['txfee'], + 'payout_system' => $config['payout_system'], + 'ap_threshold' => array( + 'min' => $config['ap_threshold']['min'], + 'max' => $config['ap_threshold']['max'] + ) + ) +); + +// Special calculations for PPS Values based on reward_type setting and/or available blocks +if ($config['reward_type'] != 'block') { + $aGlobal['ppsvalue'] = number_format(round(50 / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); +} else { + // Try to find the last block value and use that for future payouts, revert to fixed reward if none found + if ($aLastBlock = $block->getLast()) { + $aGlobal['ppsvalue'] = number_format(round($aLastBlock['amount'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } else { + $aGlobal['ppsvalue'] = number_format(round($config['reward'] / (pow(2,32) * $dDifficulty) * pow(2, $config['difficulty']), 12) ,12); + } +} + +// We don't want these session infos cached +if (@$_SESSION['USERDATA']['id']) { + $aGlobal['userdata'] = $_SESSION['USERDATA']['id'] ? $user->getUserData($_SESSION['USERDATA']['id']) : array(); + $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA']['id']); + + // Other userdata that we can cache savely + $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); + $aGlobal['userdata']['sharerate'] = $statistics->getUserSharerate($_SESSION['USERDATA']['id']); + + switch ($config['payout_system']) { + case 'pps': + break; + default: + // Some estimations + if (@$aRoundShares['valid'] > 0) { + $aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (float)$config['reward'], 8); + $aGlobal['userdata']['est_fee'] = round(((float)$config['fees'] / 100) * (float)$aGlobal['userdata']['est_block'], 8); + $aGlobal['userdata']['est_donation'] = round((( (float)$aGlobal['userdata']['donate_percent'] / 100) * ((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_fee'])), 8); + $aGlobal['userdata']['est_payout'] = round((float)$aGlobal['userdata']['est_block'] - (float)$aGlobal['userdata']['est_donation'] - (float)$aGlobal['userdata']['est_fee'], 8); + } else { + $aGlobal['userdata']['est_block'] = 0; + $aGlobal['userdata']['est_fee'] = 0; + $aGlobal['userdata']['est_donation'] = 0; + $aGlobal['userdata']['est_payout'] = 0; + } + break; + } + + // Site-wide notifications, based on user events + if ($aGlobal['userdata']['balance']['confirmed'] >= $config['ap_threshold']['max']) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have exceeded your accounts balance. Please transfer some ' . $config['currency'] . "!", 'TYPE' => 'errormsg'); + if ($user->getUserFailed($_SESSION['USERDATA']['id']) > 0) + $_SESSION['POPUP'][] = array('CONTENT' => 'You have ' . $user->getUserFailed($_SESSION['USERDATA']['id']) . ' failed login attempts! Reset Counter', 'TYPE' => 'errormsg'); +} + +if ($setting->getValue('maintenance')) + $_SESSION['POPUP'][] = array('CONTENT' => 'This pool is currently in maintenance mode.', 'TYPE' => 'warning'); + +// Make it available in Smarty +$smarty->assign('PATH', 'site_assets/' . THEME); +$smarty->assign('GLOBAL', $aGlobal); ?>