checkDemoMode() public static method

TODO Yuck! Why does this return a boolean as a frickin' string?! Was I drunk?
public static checkDemoMode ( )
 /**
  * @param $postData array everything from the form post. The Generator is used in 3 different
  * contexts: for in-page generation, new tab/window or for prompting download of the data.
  */
 public function __construct($postData)
 {
     $this->exportTarget = $postData["gdExportTarget"];
     // inPage, newTab or promptDownload
     if ($this->exportTarget == "inPage") {
         $this->batchSize = $postData["gdBatchSize"];
         $this->batchNum = $postData["gdCurrentBatchNum"];
     } else {
         $this->batchSize = $postData["gdNumRowsToGenerate"];
         $this->batchNum = 1;
     }
     $this->numResults = $postData["gdNumRowsToGenerate"];
     if (Core::checkDemoMode() && !Core::checkIsLoggedIn()) {
         $maxDemoModeRows = Core::getMaxDemoModeRows();
         if ($this->numResults > $maxDemoModeRows) {
             $this->numResults = $maxDemoModeRows;
         }
     }
     // always apply the max generated rows limitation. Technically this value could be lower than
     // the $maxDemoModeRows value above, but it's extremely unlikely & an acceptable restriction
     $maxGeneratedRows = Core::getMaxGeneratedRows();
     if ($this->numResults > $maxGeneratedRows) {
         $this->numResults = $maxGeneratedRows;
     }
     $this->countries = isset($postData["gdCountries"]) ? $postData["gdCountries"] : array();
     $this->dataTypes = DataTypePluginHelper::getDataTypeHash(Core::$dataTypePlugins);
     $this->postData = $postData;
     if (isset($postData["configurationID"])) {
         $this->configurationID = $postData["configurationID"];
     }
     // make a note of whether this batch is the first / last. This is useful information for the
     // Export Types to know whether to output special content at the top or bottom
     $this->isFirstBatch = $this->batchNum == 1;
     $this->isLastBatch = $this->batchNum * $this->batchSize >= $this->numResults;
     $this->currentBatchFirstRow = ($this->batchNum - 1) * $this->batchSize + 1;
     $this->currentBatchLastRow = $this->currentBatchFirstRow + $this->batchSize > $this->numResults ? $this->numResults : $this->currentBatchFirstRow + $this->batchSize - 1;
     // figure out what we're going to need to generate
     $this->createDataSetTemplate($postData);
     // now we farm out the work of data generation to the selected Export Type
     $exportTypes = Core::$exportTypePlugins;
     $selectedExportType = null;
     foreach ($exportTypes as $currExportType) {
         if ($currExportType->getFolder() != $postData["gdExportType"]) {
             continue;
         }
         $this->exportType = $currExportType;
         break;
     }
     // set the value of isCompressionRequired
     if ($postData["gdExportTarget"] == "promptDownload" && $postData["gdExportTarget_promptDownload_zip"] == "doZip") {
         $this->isCompressionRequired = true;
     }
 }
 /**
  * Used to generate the main index and install pages.
  * @param string $template the path from the GD root to the template
  * @param array $pageVars
  * @param string $action "display" displays the result (default) or "return" to return the value
  * @return mixed
  */
 public static function displayPage($template, $pageVars = array(), $action = "display")
 {
     // check the compile directory has the write permissions
     if (!is_writable(Core::$smarty->compile_dir) && is_readable(Core::$smarty->compile_dir)) {
         Templates::displaySeriousError("The <b>/cache</b> folder isn't writable. This folder is used by Smarty to generate temporary files for speedy page loads. You'll need to update that folder's permissions to allow read and write permissions (777 on unix/mac).");
         exit;
     }
     // check that the user is running a recent enough version of PHP. This is needed for json_encode,
     // json_decode and for Smarty 3
     $minimumPHPVersion = Core::getMinimumPHPVersion();
     $currentVersion = PHP_VERSION;
     if (version_compare($currentVersion, $minimumPHPVersion) < 0) {
         Templates::displaySeriousError("Sorry, you need to be running PHP <b>{$minimumPHPVersion}</b> or later. You're currently running <b>{$currentVersion}</b>.");
         exit;
     }
     // check the environment has mysqli
     if (!function_exists("mysqli_connect")) {
         Templates::displaySeriousError("Sorry, you must have the <b>mysqli</b> PHP extension installed in order to use this script.");
         exit;
     }
     Core::$smarty->assign("L", Core::$language->getCurrentLanguageStrings());
     Core::$smarty->assign("currLang", Core::$language->getCurrentLanguageFile());
     Core::$smarty->assign("queryString", $_SERVER["QUERY_STRING"]);
     // this sucks. Needs to cache the DB value
     $theme = isset($pageVars["theme"]) ? $pageVars["theme"] : Settings::getSetting("theme");
     Core::$smarty->assign("theme", $theme);
     Core::$smarty->assign("inDemoMode", Core::checkDemoMode());
     Core::$smarty->assign("allowThemes", Core::$allowThemes);
     // now add the custom variables for this template, as defined in $page_vars
     foreach ($pageVars as $key => $value) {
         Core::$smarty->assign($key, $value);
     }
     // "success" and "message" are special
     if (!isset($pageVars["success"])) {
         Core::$smarty->assign("success", null);
     }
     if (!isset($pageVars["message"])) {
         Core::$smarty->assign("message", null);
     }
     try {
         $templatePath = realpath(__DIR__ . "/../../{$template}");
         if ($action == "display") {
             Core::$smarty->display($templatePath);
         } else {
             return Core::$smarty->fetch($templatePath);
         }
     } catch (Exception $e) {
         Templates::displaySeriousError("Smarty encountered a problem writing to the /cache folder. The (probably indecipherable) error message returned is:", $e);
         exit;
     }
 }
 /**
  * @param array $postdata everything from the form post. The Generator is used in 3 different
  * contexts: for in-page generation, new tab/window or for prompting download of the data.
  */
 public function __construct($postData)
 {
     $this->exportTarget = $postData["gdExportTarget"];
     // inPage, newTab or promptDownload
     if ($this->exportTarget == "inPage") {
         $this->batchSize = $postData["gdBatchSize"];
         $this->batchNum = $postData["gdCurrentBatchNum"];
     } else {
         $this->batchSize = $postData["gdNumRowsToGenerate"];
         $this->batchNum = 1;
     }
     $this->numResults = $postData["gdNumRowsToGenerate"];
     if (Core::checkDemoMode()) {
         if ($this->numResults > 500) {
             $this->numResults = 500;
         }
     }
     $this->countries = isset($postData["gdCountries"]) ? $postData["gdCountries"] : array();
     $this->dataTypes = DataTypePluginHelper::getDataTypeHash(Core::$dataTypePlugins);
     $this->postData = $postData;
     if (isset($postData["configurationID"])) {
         $this->configurationID = $postData["configurationID"];
     }
     // make a note of whether this batch is the first / last. This is useful information for the
     // Export Types to know whether to output special content at the top or bottom
     $this->isFirstBatch = $this->batchNum == 1;
     $this->isLastBatch = $this->batchNum * $this->batchSize >= $this->numResults;
     $this->currentBatchFirstRow = ($this->batchNum - 1) * $this->batchSize + 1;
     $this->currentBatchLastRow = $this->currentBatchFirstRow + $this->batchSize > $this->numResults ? $this->numResults : $this->currentBatchFirstRow + $this->batchSize - 1;
     // figure out what we're going to need to generate
     $this->createDataSetTemplate($postData);
     // now we farm out the work of data generation to the selected Export Type
     $exportTypes = Core::$exportTypePlugins;
     $selectedExportType = null;
     foreach ($exportTypes as $currExportType) {
         if ($currExportType->getFolder() != $postData["gdExportType"]) {
             continue;
         }
         $this->exportType = $currExportType;
         break;
     }
 }
示例#4
0
			DATA_TYPE: 'data-type',
			EXPORT_TYPE: 'export-type',
			CORE: 'core'
		},

		EXPORT_TYPE_SETTINGS_BLIND_SPEED: 500,

		GENERATE_IN_PAGE_BATCH_SIZE: 100,

		MAX_GENERATED_ROWS: <?php 
echo Core::getMaxGeneratedRows();
?>
,

		DEMO_MODE: <?php 
echo Core::checkDemoMode();
?>
,

		THEME: "<?php 
Settings::safeDisplaySetting("theme");
?>
",

		/**
		 * Contains all Core events.
		 */
		EVENT: {
            APP_START: 'app-start',
			RESULT_TYPE: {
				CHANGE: "event-result-type-change"
 /**
  * Helper to see if we're in demo mode, and limit the number of rows that can be generated.
  */
 private function applyRowsGeneratedLimit()
 {
     if (Core::checkDemoMode() && !Core::checkIsLoggedIn()) {
         $maxDemoModeRows = Core::getMaxDemoModeRows();
         if ($this->numResults > $maxDemoModeRows) {
             $this->numResults = $maxDemoModeRows;
         }
     }
     // always apply the max generated rows limitation. Technically this value could be lower than
     // the $maxDemoModeRows value above, but it's extremely unlikely & an acceptable restriction
     $maxGeneratedRows = Core::getMaxGeneratedRows();
     if ($this->numResults > $maxGeneratedRows) {
         $this->numResults = $maxGeneratedRows;
     }
 }