public function ajax_updatenext() { $time_start = microtime(true); $response["error"] = "none"; $response["file"] = "none"; $response["nextId"] = null; if (!empty($_POST["id"])) { $id = intval($_POST["id"]); if ($id < 1) { $i = 1; } $history = new History(); $themeInfo = $history->getFewInfo($id); if (!empty($themeInfo)) { $unzippath = TC_VAULTDIR . '/unzip/' . $themeInfo["hash"] . "/"; if (file_exists($unzippath)) { $nextId = $history->getNextId($themeInfo["id"]); $response["nextId"] = $nextId; $themeInfo = $history->loadThemeFromHash($themeInfo["hash"]); // need an objet and not an array $r = $themeInfo->initFromUnzippedArchive($unzippath, $themeInfo->zipfilename, $themeInfo->zipmimetype, $themeInfo->zipfilesize); // merchant... $this->fileValidator = new FileValidator($themeInfo); $this->fileValidator->validate(); if (UserMessage::getCount(ERRORLEVEL_FATAL) > 0) { $response["error"] = "fatal error:\n"; foreach (UserMessage::getMessages(ERRORLEVEL_FATAL) as $m) { $response["error"] .= "\n" . $m; } } else { if ($this->fileValidator->serialize(true)) { if (UserMessage::getCount(ERRORLEVEL_FATAL) > 0) { // at least one error occured while serializing (no thumbnail...) $response["error"] = "fatal error, could not serialize validation results:\n"; foreach (UserMessage::getMessages(ERRORLEVEL_FATAL) as $m) { $response["error"] .= "\n" . $m; } foreach (UserMessage::getMessages(ERRORLEVEL_CRITICAL) as $m) { $response["error"] .= "\n" . $m; } } else { $this->validationResults = $this->fileValidator->getValidationResults(I18N::getCurLang()); $themeInfo = $this->fileValidator->themeInfo; $response["name"] = $themeInfo->name; } } else { // at least one error occured while serializing (no thumbnail...) if (UserMessage::getCount(ERRORLEVEL_CRITICAL) > 0) { $response["error"] = "could not serialize validation results"; } foreach (UserMessage::getMessages(ERRORLEVEL_CRITICAL) as $m) { $response["error"] .= "\n" . $m; } } } } else { $response["error"] .= "No zip file " . $unzippath; } } else { if (UserMessage::getCount(ERRORLEVEL_FATAL) > 0) { // at least one error occured while serializing (no thumbnail...) $response["error"] = "could not execute validation:\n"; foreach (UserMessage::getMessages(ERRORLEVEL_FATAL) as $m) { $response["error"] .= "\n" . $m; } foreach (UserMessage::getMessages(ERRORLEVEL_CRITICAL) as $m) { $response["error"] .= "\n" . $m; } } else { $response["error"] = "could not execute validation (unknown error)."; } } } $time_end = microtime(true); $time = $time_end - $time_start; $response["duration"] = $time; //ob_clean(); header('Content-Type: application/json'); echo json_encode($response); }
public function ajax_sample() { $time_start = microtime(true); $response["error"] = "none"; $response["html"] = ""; $themeid = 1; if (isset($_POST["themeid"])) { $themeid = intval($_POST["themeid"]); } if ($themeid < 1) { $themeid = 1; } $checkid = $_POST["checkid"]; if (USE_DB) { $history = new History(); $themInfo = $history->getFewInfo($themeid); $hash = $themInfo["hash"]; $fileValidator = FileValidator::unserialize($hash); $fileValidator->validate($checkid); //if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0) // serialize only if no fatal errors $validationResults = $fileValidator->getValidationResults(I18N::getCurLang()); if (count($validationResults->check_critical) > 0 || count($validationResults->check_warnings) > 0 || count($validationResults->check_info) > 0) { $url = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => "en", "phpfile" => "results", "hash" => $hash)); $html = '<h2 style="color:#D00;">' . $themInfo["name"] . '<a href="' . $url . '" target="_blank" style="font-size:14px;margin-left:6px"><span class="glyphicon glyphicon-new-window"></span></a>' . '</h2>'; } if (count($validationResults->check_critical) > 0) { //$html .= '<h2 style="line-height:100px;color:#D00;">'.__("Critical alerts").'</h2>'; $html .= '<ol>'; foreach ($validationResults->check_critical as $check) { $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { $html .= '<p style="color:#c94b4b;">' . implode('<br/>', $check->messages) . '</p>'; } } $html .= '</ol>'; } if (count($validationResults->check_warnings) > 0) { //$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>'; $html .= '<ol>'; foreach ($validationResults->check_warnings as $check) { $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { $html .= '<p style="color:#eea43a;">' . implode('<br/>', $check->messages) . '</p>'; } } $html .= '</ol>'; } if (count($validationResults->check_info) > 0) { //$html .= '<h2 style="line-height:100px;color:#eea43a;">'.__("Warnings").'</h2>'; $html .= '<ol>'; foreach ($validationResults->check_info as $check) { $html .= '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { $html .= '<p style="color:#00b6e3;">' . implode('<br/>', $check->messages) . '</p>'; } } $html .= '</ol>'; } $response["html"] = $html; $prevId = $history->getPrevId($themeid); if (!empty($prevId)) { $themInfoNext = $history->getFewInfo($prevId); $response["next_id"] = $prevId; $response["next_name"] = $themInfoNext["name"]; } else { $response["next_id"] = null; $response["next_name"] = null; } } $time_end = microtime(true); $time = $time_end - $time_start; $response["duration"] = $time; //ob_clean(); header('Content-Type: application/json'); echo json_encode($response); }
/** * Restore check results from a JSON file. **/ public static function unserialize($hash) { if (!USE_DB) { return null; } $directory = ThemeInfo::getReportDirectory($hash); if (!file_exists($directory)) { return null; } $history = new History(); $themeInfo = $history->loadThemeFromHash($hash); if (empty($themeInfo)) { return null; } $fileValidator = new FileValidator($themeInfo); global $ExistingLangs; foreach ($ExistingLangs as $l) { $_validationResults = ValidationResults::unserialize($hash, $l); if (empty($_validationResults)) { continue; } $fileValidator->validationResults[$l] = $_validationResults; } if (!empty($themeInfo->parentId)) { $fewInfo = $history->getFewInfo($themeInfo->parentId); if (!empty($fewInfo["id"])) { $themeInfo->parentNameSanitized = $fewInfo["namesanitized"]; } $themeInfo->parentThemeType = $fewInfo["themetype"]; } if ($themeInfo->isThemeForest) { $fileValidator->generateThemeForestReport(); } return $fileValidator; }
public function render() { if (UserMessage::getCount(ERRORLEVEL_FATAL) == 0 && $this->fileValidator) { ?> <div class="container"> <br/> <?php $themeInfo = $this->fileValidator->themeInfo; ?> <div class="row text-center"> <div><img style="box-shadow: 0 0 20px #DDD;" src="<?php echo TC_HTTPDOMAIN . '/' . $themeInfo->hash . '/thumbnail.png'; ?> "></div> <h1><?php printf(__("Validation results for <strong>%s</strong>"), htmlspecialchars($themeInfo->zipfilename, defined('ENT_HTML5') ? ENT_QUOTES | ENT_HTML5 : ENT_QUOTES)); ?> </h1> </div> <?php if ($this->fileValidator->themeInfo->isThemeForest) { ?> <ul class="nav nav-tabs"> <li class="active"><a href="#standard" data-toggle="tab"><?php echo __("Themecheck rules") . " : "; $score = $this->fileValidator->themeInfo->score; $color = 'ff1427'; if ($score > 95) { $color = 'cbd715'; } else { if ($score > 80) { $color = 'ff8214'; } } echo '<span style="color:#' . $color . '">' . intval($score) . ' %</span>'; ?> </a></li> <li><a href="#themeforest" data-toggle="tab"><?php echo __("Themeforest rules") . " : "; $score = $this->fileValidator->themeInfo_themeforest->score; $color = 'ff1427'; if ($score > 95) { $color = 'cbd715'; } else { if ($score > 80) { $color = 'ff8214'; } } echo '<span style="color:#' . $color . '">' . intval($score) . ' %</span>'; ?> </a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="standard"><?php $this->renderRulesSet($this->fileValidator->themeInfo, $this->validationResults); ?> </div> <div class="tab-pane" id="themeforest"><br/><?php echo __('This is a ThemeForest theme. Since Themeforest items are all checked by a human before they appear on their website, ThemeForest verification rules are more permissive than themecheck's and can give a better verification score ( <a href="http://support.envato.com/index.php?/Knowledgebase/Article/View/472/85/wordpress-theme-submission-requirements" rel="nofollow">Themeforest requirements</a> ).'); $this->renderRulesSet($this->fileValidator->themeInfo_themeforest, $this->fileValidator->getValidationResultsThemeForest(I18N::getCurLang())); ?> </div> </div> <?php } else { $this->renderRulesSet($this->fileValidator->themeInfo, $this->validationResults); } ?> </div> <div class="container"> <div id="disqus_thread" style="margin-top:60px"></div> <script type="text/javascript"> /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = 'themecheck'; // required: replace example with your forum shortname var disqus_url = '<?php echo $this->samepage_i18n[I18N::getCurLang()]; ?> '; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink" rel="nofollow">comments powered by <span class="logo-disqus">Disqus</span></a> <?php if (USE_DB) { echo '<hr>'; echo '<h2 style="line-height:100px;color:#888">' . __("Other files checked around the same date") . '</h2>'; $history = new History(); $id = intval($history->getIdFromHash($themeInfo->hash)); for ($i = 1; $i > -4; $i--) { if ($i == 0) { $i--; } // not the current one $r = $history->getFewInfo($id + $i); if ($r !== false) { $html = ''; $namesanitized = $r['namesanitized']; $themetype = $r['themetype']; $score = $r['score']; $themetype_text = sprintf(__("Wordpress %s theme"), $r['cmsVersion']); if ($themetype == TT_JOOMLA) { $themetype_text = sprintf(__("Joomla %s template"), $r['cmsVersion']); } $url = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "results", "namesanitized" => $namesanitized, "themetype" => $themetype)); $html .= '<div style="width:220px;height:220px;display:inline-block;text-align:center;margin:10px 32px">'; $html .= '<a href="' . $url . '" ><img style="box-shadow: 0 0 20px #DDD;" src="' . TC_HTTPDOMAIN . '/' . $r['hash'] . '/thumbnail.png"></a>'; $html .= '<div style="width:220px;height:40px;margin:3px 0 0 0;text-align:left;line-height:18px;padding:0 7px;overflow:hidden;white-space:nowrap;font-size : 12px;">'; $html .= '<div style="width:33px;height:40px;float:right;">'; $html .= getShield($r, I18N::getCurLang(), 40, $url, TC_HTTPDOMAIN . '/'); $html .= '</div>'; $html .= htmlspecialchars($r['name']) . '<br/><span style="font-size : 12px; color:#AAA;">' . $themetype_text . '</span>'; $html .= '</div>'; $html .= '</div>'; echo $html; } } // $themetype = $r['themetype']; // $score = $r['score']; } } else { if (UserMessage::getCount(ERRORLEVEL_FATAL) > 0) { ?> <div class="container"> <br/> <div class="row text-center"> <h1><?php printf(__("Validation results")); ?> </h1> </div> <div class="row text-center" style="color:#888;font-weight:normal;margin:30px 0 0 0;background:#F8F8F8;border-radius: 3px;"> <br/> <?php $img = 'shieldred240.png'; $color = 'ff1418'; $text = __("Validation score : 0 %"); ?> <div class="shield1" style="width:201px;height:240px;background-image:url(<?php echo TC_HTTPDOMAIN; ?> /img/<?php echo $img; ?> );" title="<?php echo $text; ?> "> <div class="shield2" style="color:#<?php echo $color; ?> ;">0</div> </div> <?php echo '<p "color:#' . $color . '">' . __("Validation score : 0 %") . '</p>'; $userMessage = UserMessage::getInstance(); echo '<div style="margin:5% 10%">' . __("Fatal error") . '<br>' . UserMessage::getInstance()->getMessagesHtml() . '</div>'; ?> <p><?php echo '<a href="' . TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "index.php")) . '">' . __("Go to home page to submit a new version") . '</a>'; ?> </p> <br/> </div> <?php } else { $userMessage = UserMessage::getInstance(); echo '<div class="container">' . UserMessage::getInstance()->getMessagesHtml() . '</div>'; ?> <div class="jumbotron"> <div class="container"> <h1><?php echo __('Please send us a theme to check.'); ?> </h1> <p><?php echo '<a href="' . TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "index.php")) . '">' . __("Go to home page") . '</a> '; ?> </p> </div> </div> <div class="container"> <br/> <?php } } ?> </div> <!-- /container --> <?php }