public static function getMessages($errorlevel) { $_this = UserMessage::getInstance(); $ret = array(); foreach ($_this->messages as $message => $level) { if ($level == $errorlevel) { $ret[] = $message; } } return $ret; }
define("ERRORLEVEL_NONE", 0); define("ERRORLEVEL_FATAL", 1); // errors that prevent from running the tests define("ERRORLEVEL_CRITICAL", 2); // security threats or inacceptable errors define("ERRORLEVEL_WARNING", 3); define("ERRORLEVEL_SUCCESS", 4); define("ERRORLEVEL_INFO", 5); define("TC_CONTACT_MAIL", "*****@*****.**"); define("TC_CONTACT_NAME", "Guillaume Baudhuin"); date_default_timezone_set('UTC'); global $g_creationDate; $g_creationDate = time(); if (!defined("USE_DB")) { define("USE_DB", true); } // True to save validation history in database. False to avoid history saving, but keep all other functionalities // **************************************************************************** // Init // **************************************************************************** if (USE_DB) { include_once TC_ROOTDIR . '/DB/History.php'; } include_once TC_INCDIR . '/Route.php'; include_once TC_INCDIR . '/I18N.php'; // initialize I18N $i18n = I18N::getInstance(); // initialize usermessages include_once TC_INCDIR . '/UserMessage.php'; $userMessage = UserMessage::getInstance();
/** * Generate a hash, move or copy the archive and return a ThemeInfo object **/ public static function prepareThemeInfo($src_path, $src_name, $src_type, $isUpload = false) { $src_size = filesize($src_path); if (!($src_size > 100 || strpos($src_path, '/unittests/') !== false)) { $userMessage = UserMessage::getInstance(); $userMessage->enqueueMessage(__('Files under 100 bytes are not accepted. Operation canceled.'), ERRORLEVEL_CRITICAL); return null; } $hash_md5 = md5_file($src_path); $sha1_file = sha1_file($src_path); $hash_alpha = base_convert($hash_md5, 16, 36); // shorten hash to shorten urls (better looking, less bandwidth) while (strlen($hash_alpha) < 25) { $hash_alpha = '0' . $hash_alpha; } $zipfilepath = self::hashToPathUpload($hash_alpha); if ($isUpload) { move_uploaded_file($src_path, $zipfilepath); } else { copy($src_path, $zipfilepath); } // copy the file (overwrites if already existing) try { $zip = new \ZipArchive(); $path = TC_ROOTDIR . '/../themecheck_vault/unzip'; if (!file_exists($path)) { trigger_error('Directory TC_ROOTDIR/../themecheck_vault/unzip does not exist', E_USER_ERROR); } $unzippath = $path . '/' . $hash_alpha . "/"; $res = $zip->open($zipfilepath); if ($res === TRUE) { if (file_exists($unzippath)) { ListDirectoryFiles::recursiveRemoveDir($unzippath); } // needed to avoid keeping old files that don't exist anymore in the new archive $zip->extractTo($unzippath); $zip->close(); } else { UserMessage::enqueue(__("File could not be unzipped."), ERRORLEVEL_FATAL); } } catch (Exception $e) { UserMessage::enqueue(__("Archive extraction failed. The following exception occured : ") . $e->getMessage(), ERRORLEVEL_FATAL); } // create a theme info $themeInfo = new ThemeInfo($hash_alpha); $themeInfo->hash_md5 = $hash_md5; $themeInfo->hash_sha1 = $sha1_file; $r = $themeInfo->initFromUnzippedArchive($unzippath, $src_name, $src_type, $src_size); if (!empty($themeInfo->parentName)) { $history = new History(); $fewInfo = $history->getFewInfoFromName($themeInfo->parentName); if (!empty($fewInfo["id"])) { $themeInfo->parentId = intval($fewInfo["id"]); } $themeInfo->parentNameSanitized = $fewInfo["namesanitized"]; $themeInfo->parentThemeType = $fewInfo["themetype"]; } if (!$r) { return null; } return $themeInfo; }
private function renderRulesSet($themeInfo, $validationResults) { ?> <div class="row" style="color:#888;font-weight:normal;margin:30px 0 0 0;background:#F8F8F8;border-radius: 3px;"> <div class="col-md-8 text-center" style=""> <br/> <?php $userMessage = UserMessage::getInstance(); echo UserMessage::getInstance()->getMessagesHtml(); $img = 'shieldperfect240.png'; $color = 'a6af11'; $text = sprintf(__('Validation score : %s%%'), intval($themeInfo->score)); if ($themeInfo->score < 100.0) { if ($themeInfo->score > 95) { $img = "shieldgreen240.png"; $color = 'cbd715'; } else { if ($themeInfo->score > 80) { $img = "shieldorange240.png"; $color = 'ff8214'; } else { $img = "shieldred240.png"; $color = 'ff1427'; } } if ($themeInfo->criticalCount > 0) { $text = sprintf(__('Validation score : %s%% (%s critical alerts)'), intval($themeInfo->score), $themeInfo->criticalCount); } else { $text = sprintf(__('Validation score : %s%%'), intval($themeInfo->score)); } } ?> <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; ?> ;"> <?php if ($themeInfo->score < 100.0) { echo intval($themeInfo->score); } ?> </div> </div> <?php echo '<p "color:#' . $color . '">' . __("validation score") . ' : ' . intval($themeInfo->score) . ' %</p>'; echo '<p>' . sprintf(__("%s critical alerts. %s warnings."), $themeInfo->criticalCount, $themeInfo->warningsCount) . '</p>'; if (!isset($_POST["donotstore"]) && UserMessage::getCount(ERRORLEVEL_FATAL) == 0) { ?> <br/><br/> <?php echo __("Share this page with the following link :"); ?> <p> <?php echo '<a href="' . $this->samepage_i18n[I18N::getCurLang()] . '">' . $this->samepage_i18n[I18N::getCurLang()] . '</a>'; ?> </p> <?php echo __("Display this score on your website with the following HTML code that links to this page :"); ?> <p style="color:red"><i>( corrected 2014-06-09 )</i></p> <pre style="font-size:11px;width:70%;margin:auto;"><?php echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?lang=' . I18N::getCurLang() . '&id=' . $themeInfo->hash . '&size=big" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:240px; width:200px;" allowTransparency="true"></iframe>'); ?> </pre> <button class="btn" data-toggle="collapse" data-target="#moreembedoptions" style="height:20px;padding:1px;font-size:12px">more options</button> <div id="moreembedoptions" class="collapse"> <?php displayShield($themeInfo, I18N::getCurLang(), 80, '#', TC_HTTPDOMAIN . '/'); ?> <?php echo __("Medium size icon (default) :"); ?> <pre style="font-size:11px;width:70%;margin:auto;"><?php echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?id=' . $themeInfo->hash . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px; width:67px;" allowTransparency="true"></iframe>'); ?> </pre> <?php displayShield($themeInfo, I18N::getCurLang(), 40, '#', TC_HTTPDOMAIN . '/'); ?> <?php echo __("Small size icon :"); ?> <pre style="font-size:11px;width:70%;margin:auto;"><?php echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?id=' . $themeInfo->hash . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px; width:40px;" allowTransparency="true"></iframe>'); ?> </pre> <?php echo htmlspecialchars(__("You can switch language with <strong>lang</strong> parameter in iframe's url. So far <strong>fr</strong> and <strong>en</strong> are supported. Default value is <strong>en</strong>.")); ?> <pre style="font-size:11px;width:70%;margin:auto;"><?php echo htmlspecialchars('<iframe src="' . TC_HTTPDOMAIN . '/score.php?lang=' . I18N::getCurLang() . '&id=' . $themeInfo->hash . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:80px; width:67px;" allowTransparency="true"></iframe>'); ?> </pre> </div> <br/> <?php } else { echo '<br>' . __("These results were not saved on themecheck.org servers and will be lost when you quit this page."); } ?> </div> <div class="col-md-4" style="border-radius: 3px;background:#444; overflow:hidden; font-size:12px"> <?php $characteristics = array(); $characteristics[] = array(__("Theme name"), htmlspecialchars($themeInfo->name)); if ($themeInfo->themetype == TT_WORDPRESS) { if (empty($themeInfo->cmsVersion)) { $characteristics[] = array(__("Theme type"), __("Wordpress theme")); } else { $characteristics[] = array(__("Theme type"), __("Wordpress theme") . ' ' . $themeInfo->cmsVersion); } } else { if ($themeInfo->themetype == TT_WORDPRESS_CHILD) { if (empty($themeInfo->cmsVersion)) { $characteristics[] = array(__("Theme type"), __("Wordpress child theme")); } else { $characteristics[] = array(__("Theme type"), __("Wordpress child theme") . ' ' . $themeInfo->cmsVersion); } if (!empty($themeInfo->parentName)) { $url = TC_HTTPDOMAIN . '/' . Route::getInstance()->assemble(array("lang" => I18N::getCurLang(), "phpfile" => "results", "namesanitized" => $themeInfo->parentNameSanitized, "themetype" => $themeInfo->parentThemeType)); $characteristics[] = array(__("Parent theme name"), "<a href='" . $url . "'>" . htmlspecialchars($themeInfo->parentName) . "</a>"); } } else { if ($themeInfo->themetype == TT_JOOMLA) { if (empty($themeInfo->cmsVersion)) { $characteristics[] = array(__("Theme type"), __("Joomla template")); } else { $characteristics[] = array(__("Theme type"), __("Joomla template") . ' ' . $themeInfo->cmsVersion); } } } } $characteristics[] = array(__("File name"), htmlspecialchars($themeInfo->zipfilename, defined('ENT_HTML5') ? ENT_QUOTES | ENT_HTML5 : ENT_QUOTES)); $characteristics[] = array(__("File size"), $themeInfo->zipfilesize . ' ' . __('bytes')); $characteristics[] = array(__("MD5"), strtolower($themeInfo->hash_md5)); $characteristics[] = array(__("SHA1"), strtolower($themeInfo->hash_sha1)); if (empty($themeInfo->licenseUri)) { if (!empty($themeInfo->licenseText)) { $characteristics[] = array(__("License"), ThemeInfo::getLicenseName($themeInfo->license) . '<br>' . htmlspecialchars($themeInfo->licenseText)); } else { $characteristics[] = array(__("License"), ThemeInfo::getLicenseName($themeInfo->license)); } } else { if (!empty($themeInfo->licenseText)) { $characteristics[] = array(__("License"), '<a href="' . $themeInfo->licenseUri . '" rel="nofollow">' . ThemeInfo::getLicenseName($themeInfo->license) . '</a>' . '<br>' . htmlspecialchars($themeInfo->licenseText)); } else { $characteristics[] = array(__("License"), '<a href="' . $themeInfo->licenseUri . '" rel="nofollow">' . ThemeInfo::getLicenseName($themeInfo->license) . '</a>'); } } $characteristics[] = array(__("Files included"), htmlspecialchars($themeInfo->filesIncluded, defined('ENT_HTML5') ? ENT_QUOTES | ENT_HTML5 : ENT_QUOTES)); if (!empty($themeInfo->themeUri)) { if (strpos($themeInfo->themeUri, 'themeforest.net') !== false) { $characteristics[] = array(__("Theme URI"), '<a href="' . $themeInfo->themeUri . '?ref=peol">' . htmlspecialchars($themeInfo->themeUri) . '</a>'); } else { $characteristics[] = array(__("Theme URI"), '<a href="' . $themeInfo->themeUri . '">' . htmlspecialchars($themeInfo->themeUri) . '</a>'); } } if (!empty($themeInfo->version)) { $characteristics[] = array(__("Version"), htmlspecialchars($themeInfo->version)); } if (!empty($themeInfo->authorUri)) { $characteristics[] = array(__("Author URI"), '<a href="' . $themeInfo->authorUri . '">' . htmlspecialchars($themeInfo->authorUri) . '</a>'); } if (!empty($themeInfo->tags)) { $characteristics[] = array(__("Tags"), htmlspecialchars($themeInfo->tags)); } if (!empty($themeInfo->layout)) { if ($themeInfo->layout == 1) { $characteristics[] = array(__("Layout"), __("Fixed")); } else { if ($themeInfo->layout == 2) { $characteristics[] = array(__("Layout"), __("Fluid")); } else { if ($themeInfo->layout == 3) { $characteristics[] = array(__("Layout"), __("Responsive")); } } } } if (!empty($themeInfo->copyright)) { $characteristics[] = array(__("Copyright"), htmlspecialchars($themeInfo->copyright)); } if (!empty($themeInfo->creationDate)) { $characteristics[] = array(__("Creation date"), date("Y-m-d", $themeInfo->creationDate)); } if (!empty($themeInfo->modificationDate)) { $characteristics[] = array(__("Last file update"), date("Y-m-d", $themeInfo->modificationDate)); } if (!empty($themeInfo->validationDate)) { $characteristics[] = array(__("Last validation"), date("Y-m-d H:i", $themeInfo->validationDate)); } foreach ($characteristics as $c) { echo '<p style="text-transform:uppercase;margin:0;margin-top:10px;">' . $c[0] . '</p><span style="color:#CCC">' . $c[1] . '</span>'; } ?> </div> </div> <?php echo '<div class="row"><div class="col-md-12">'; if (count($validationResults->check_critical) > 0) { echo '<h2 style="line-height:100px;color:#D00;">' . __("Critical alerts") . '</h2>'; echo '<ol>'; foreach ($validationResults->check_critical as $check) { echo '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { echo '<p style="color:#c94b4b;">' . implode('<br/>', $check->messages) . '</p>'; } } echo '</ol>'; } if (count($validationResults->check_warnings) > 0) { echo '<h2 style="line-height:100px;color:#eea43a;">' . __("Warnings") . '</h2>'; echo '<ol>'; foreach ($validationResults->check_warnings as $check) { echo '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { echo '<p style="color:#eea43a;">' . implode('<br/>', $check->messages) . '</p>'; } } echo '</ol>'; } if (count($validationResults->check_info) > 0) { echo '<h2 style="line-height:100px;color:#00b6e3;">' . __("Info") . '</h2>'; echo '<ol>'; foreach ($validationResults->check_info as $check) { echo '<h4 style="color:#666;margin-top:40px;"><li>' . $check->title . ' : ' . $check->hint . '</li></h4>'; if (!empty($check->messages)) { echo '<p style="color:#00b6e3;">' . implode('<br/>', $check->messages) . '</p>'; } } echo '</ol>'; } echo '</div></div>'; }