PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/theme-check/tags/20101226.1/main.php

https://github.com/brandonburke/WordPress-Plugin-Baseline
PHP | 147 lines | 127 code | 16 blank | 4 comment | 22 complexity | abfdc7be20d63d709c923ffa67c0988a MD5 | raw file
  1. <?php
  2. function check_main( $theme ) {
  3. global $themechecks;
  4. $files = listdir( WP_CONTENT_DIR . '/themes/' . $theme );
  5. $data = get_theme_data( WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
  6. if ( $files ) {
  7. foreach( $files as $key => $filename ) {
  8. if ( substr( $filename, -4 ) == '.php' ) {
  9. $php[$filename] = php_strip_whitespace( $filename );
  10. }
  11. else if ( substr( $filename, -4 ) == '.css' ) {
  12. $css[$filename] = file_get_contents( $filename );
  13. }
  14. else {
  15. $other[$filename] = file_get_contents( $filename );
  16. }
  17. }
  18. // run the checks
  19. $failed = !run_themechecks($php, $css, $other);
  20. ?>
  21. <style type="text/css">
  22. .tc-box {
  23. padding:10px 0;
  24. border-top:1px solid #ccc;
  25. border-bottom: 1px solid #ccc;
  26. }
  27. .tc-warning, .tc-required, .tc-fail {
  28. color:red;
  29. }
  30. .tc-recommended, .tc-pass {
  31. color: green;
  32. }
  33. .tc-info {
  34. color: blue;
  35. }
  36. .tc-grep span {
  37. background: yellow;
  38. }
  39. .tc-data {
  40. float: left;
  41. width: 80px;
  42. }
  43. .tc-success {
  44. }
  45. </style>
  46. <?php
  47. global $checkcount;
  48. tc_form();
  49. // second loop, to display the errors
  50. echo '<strong>Theme Info:</strong>';
  51. echo '<br /><span class="tc-data">Title</span>:' . $data[ 'Title' ];
  52. echo '<br /><span class="tc-data">Version</span>:' . $data[ 'Version' ];
  53. echo '<br /><span class="tc-data">Author</span>:' . $data[ 'Author' ];
  54. echo '<br /><span class="tc-data">Description</span>:' . $data[ 'Description' ];
  55. if ( $data[ 'Template' ] ) echo '<br />This is a child theme. The parent theme is: ' . $data[ 'Template' ];
  56. $plugins = get_plugins( '/theme-check' );
  57. $version = explode( '.', $plugins['theme-check.php']['Version'] );
  58. echo '<br /><br />Running <strong>' . $checkcount . '</strong> tests against <strong>' . $data[ 'Title' ] . '</strong> using Guidelines Version: <strong>'. $version[0] . '</strong> Plugin revision: <strong>'. $version[1] .'</strong><br />';
  59. $results = display_themechecks();
  60. $success = true;
  61. if (strpos( $results, 'WARNING') !== false) $success = false;
  62. if (strpos( $results, 'REQUIRED') !== false) $success = false;
  63. if ( $success === false ) {
  64. echo '<h3>One or more errors were found for ' . $data[ 'Title' ] . '.</h3>';
  65. } else {
  66. echo '<h2>' . $data[ 'Title' ] . ' passed the tests</h2>';
  67. tc_success();
  68. }
  69. if ( !defined( 'WP_DEBUG' ) || WP_DEBUG == false ) echo '<div class="updated"><span class="tc-fail">WARNING</span> <strong>WP_DEBUG is not enabled!</strong> Please test your theme with <a href="http://codex.wordpress.org/Editing_wp-config.php">debug enabled</a> before you upload!</div>';
  70. echo '<div class="tc-box">';
  71. echo '<ul class="tc-result">';
  72. echo $results;
  73. echo '</ul></div>';
  74. }
  75. }
  76. function listdir( $start_dir='.' ) {
  77. $files = array();
  78. if ( is_dir( $start_dir ) ) {
  79. $fh = opendir( $start_dir );
  80. while ( ( $file = readdir( $fh ) ) !== false ) {
  81. # loop through the files, skipping . and .., and recursing if necessary
  82. if ( strcmp( $file, '.' )==0 || strcmp( $file, '..' )==0 ) continue;
  83. $filepath = $start_dir . '/' . $file;
  84. if ( is_dir( $filepath ) )
  85. $files = array_merge( $files, listdir( $filepath ) );
  86. else
  87. array_push( $files, $filepath );
  88. }
  89. closedir( $fh );
  90. } else {
  91. # false if the function was called with an invalid non-directory argument
  92. $files = false;
  93. }
  94. return $files;
  95. }
  96. function tc_success() {
  97. echo '<div class="tc-success">Now your theme has passed the basic tests you need to check it properly using the test data before you upload to the WordPress Themes Directory.<br />
  98. <br />
  99. Make sure to review the guidelines at <a href="http://codex.wordpress.org/Theme_Review">Theme Review</a> before uploading a Theme.
  100. <h3>Codex Links</h3>
  101. <p>
  102. <a href="http://codex.wordpress.org/Theme_Development">Theme Development</a><br />
  103. <a href="http://wordpress.org/support/forum/5">Themes and Templates forum</a><br />
  104. <a href="http://codex.wordpress.org/Theme_Unit_Test">Theme Unit Tests</a>
  105. </p>
  106. <h3>Contact</h3>
  107. <p>Theme-Check is maintained by <a href="http://profiles.wordpress.org/users/pross/">Pross</a> and <a href="http://profiles.wordpress.org/users/otto42/">Otto42</a><br />
  108. If you think you have found a bug please report it in the <a href="http://wordpress.org/tags/theme-check?forum_id=10">forums</a> or create a <a href="https://github.com/Pross/theme-check/issues">ticket on Github</a>.
  109. </p>
  110. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  111. <input type="hidden" name="cmd" value="_s-xclick">
  112. <input type="hidden" name="hosted_button_id" value="2V7F4QYMWMBL6">
  113. <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  114. <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
  115. </form>
  116. </div>
  117. ';
  118. }
  119. function tc_form() {
  120. $themes = get_themes();
  121. echo '<form action="themes.php?page=themecheck" method="POST">';
  122. echo '<select name="themename">';
  123. foreach($themes as $name => $location) {
  124. echo '<option ';
  125. if ( basename(TEMPLATEPATH) === $location['Template'] ) echo 'selected ';
  126. echo 'value="' . $location['Template'] . '">' . $name . '</option>';
  127. }
  128. echo '</select>';
  129. echo '<input type="submit" value="Check it!" />';
  130. echo '</form>';
  131. }