예제 #1
0
 public function prepare()
 {
     $routeParts = Route::getInstance()->match();
     // There are 2 types of results to display
     // 1 - Display an already evaluated file which results were stored on the server. Just need the id. e.g : results?id=162804c3c358267d3a16855686ab1887
     // 2 - Unknown file. Need $_FILES and $_POST["filetype"]
     if (isset($routeParts["ut"])) {
         $path_item = TC_ROOTDIR . '/include/unittests/';
         $filename = urldecode($routeParts["ut"]);
         if (!(substr($filename, -4) == ".zip" && file_exists($path_item . $filename))) {
             echo $path_item . $filename . ' does not exist. Cannot continue';
             die;
         }
         $themeInfo = FileValidator::prepareThemeInfo($path_item . $filename, $filename, 'application/zip', false);
         $this->fileValidator = new FileValidator($themeInfo);
         $this->fileValidator->validate();
         $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
     } else {
         if (isset($routeParts["hash"])) {
             $hash = $routeParts["hash"];
             $this->fileValidator = FileValidator::unserialize($hash);
             $themeInfo = $this->fileValidator->themeInfo;
             $checkfiles = scandir(TC_INCDIR . '/Checks');
             $youngestCheckTimestamp = 0;
             foreach ($checkfiles as $f) {
                 if ($f == '.' || $f == '..') {
                     continue;
                 }
                 $m = filemtime(TC_INCDIR . '/Checks/' . $f);
                 if ($youngestCheckTimestamp < $m) {
                     $youngestCheckTimestamp = $m;
                 }
             }
             if ($this->fileValidator->themeInfo->validationDate < $youngestCheckTimestamp) {
                 $this->fileValidator->validate();
                 if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0) {
                     // serialize only if no fatal errors
                     $this->fileValidator->serialize(true);
                 }
             }
             $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
         } else {
             if (count($_FILES) > 0 && isset($_FILES["file"]) && !empty($_FILES["file"]["name"])) {
                 if (TC_ENVIRONMENT == "dev" || isset($_SESSION['token_' . $_POST['token']])) {
                     unset($_SESSION['token_' . $_POST['token']]);
                     $themeInfo = FileValidator::upload();
                     if ($themeInfo) {
                         $this->fileValidator = new FileValidator($themeInfo);
                         $this->fileValidator->validate();
                         if (isset($_POST["donotstore"]) || UserMessage::getCount(ERRORLEVEL_FATAL) > 0) {
                             $this->fileValidator->clean();
                         } else {
                             $this->fileValidator->serialize(true);
                         }
                         $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang());
                         if (isset($_POST["donotstore"])) {
                             $this->inlinescripts[] = "ga('send', 'event', 'theme', 'submit', 'not stored');";
                         } else {
                             $this->inlinescripts[] = "ga('send', 'event', 'theme', 'submit', 'stored');";
                         }
                     }
                 } else {
                     UserMessage::enqueue(__("Unvalid form"), ERRORLEVEL_FATAL);
                 }
             } else {
                 UserMessage::enqueue(__("No file uploaded."), ERRORLEVEL_FATAL);
                 $this->meta["title"] = __("No file uploaded");
                 $this->meta["description"] = __("No file uploaded");
                 return;
             }
         }
     }
     if (!empty($themeInfo)) {
         if ($themeInfo->themetype == TT_JOOMLA) {
             $this->meta["title"] = sprintf(__("%s%% : Joomla template %s"), htmlspecialchars($themeInfo->score), htmlspecialchars($themeInfo->name));
             $this->meta["description"] = sprintf(__("Security and code quality score of Joomla template %s."), htmlspecialchars($themeInfo->name));
         } else {
             $this->meta["title"] = sprintf(__("%s%% : Wordpress theme %s"), htmlspecialchars($themeInfo->score), htmlspecialchars($themeInfo->name));
             $this->meta["description"] = sprintf(__("Security and code quality score of Wordpress theme %s."), htmlspecialchars($themeInfo->name));
         }
         if ($themeInfo->score < 100.0) {
             if ($themeInfo->score > 95) {
                 $this->meta["favicon"] = "favicon100";
             } else {
                 if ($themeInfo->score > 80) {
                     $this->meta["favicon"] = "favicon95";
                 } else {
                     $this->meta["favicon"] = "favicon80";
                 }
             }
         }
     } else {
         $this->meta["title"] = __("Check results");
         $this->meta["description"] = __("Security and code quality score");
     }
     global $ExistingLangs;
     foreach ($ExistingLangs as $l) {
         if ($this->fileValidator) {
             $themeInfo = $this->fileValidator->themeInfo;
             if (!empty($themeInfo) && $themeInfo->serializable && USE_DB) {
                 $this->samepage_i18n[$l] = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => $l, "phpfile" => "results", "hash" => $themeInfo->hash));
             } else {
                 $this->samepage_i18n[$l] = null;
             }
         } else {
             $this->samepage_i18n[$l] = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => $l, "phpfile" => "results"));
         }
     }
 }