Skip to content

Commit

Permalink
Merge pull request WordPress#65 from khacoder/feature/no-auto-generate
Browse files Browse the repository at this point in the history
No Auto Generated Themes
  • Loading branch information
jrfnl committed Dec 19, 2016
2 parents c6b6170 + 6f693ad commit 13e9146
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
92 changes: 92 additions & 0 deletions WordPress/Sniffs/Theme/NoAutoGenerateSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* WordPress Coding Standard.
*
* @package WPCS\WordPressCodingStandards
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
* @license https://opensource.org/licenses/MIT MIT
*/

/**
* Check for auto generated themes.
*
* @package WPCS\WordPressCodingStandards
*
* @since 0.xx.0
*/
class WordPress_Sniffs_Theme_NoAutoGenerateSniff implements PHP_CodeSniffer_Sniff {

/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'CSS',
);

/**
* A list of strings found in the generated themes.
*
* @var array
*/
protected $generated_themes = array(
'artisteer', // Artisteer.
'themler', // Themler.
'lubith', // Lubith.
'templatetoaster', // TemplateToaster.
'wpthemegenerator', // WP Theme Generator.
'pinegrow', // Pinegrow.
);

/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
$tokens = PHP_CodeSniffer_Tokens::$stringTokens;
$tokens[] = T_STRING;
$tokens[] = T_INLINE_HTML;
$tokens[] = T_COMMENT;
$tokens[] = T_DOC_COMMENT_STRING;
return $tokens;
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {

$tokens = $phpcsFile->getTokens();
$token = $tokens[ $stackPtr ];
$content = trim( $token['content'] );

// No need to check an empty string.
if ( '' === $content ) {
return;
}

foreach ( $this->generated_themes as $generated_theme ) {
// The check can have false positives like artisteers but chances of that in a valid theme is low.
if ( false === strpos( strtolower( $content ), $generated_theme ) ) {
continue;
}
$phpcsFile->addError(
'Auto generated themes are not allowed in the theme directory. Found: %s',
$stackPtr,
'AutoGeneratedFound',
array( $generated_theme )
);
}

}

}
23 changes: 23 additions & 0 deletions WordPress/Tests/Theme/NoAutoGenerateUnitTest.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
{
Theme URI:http://TemplateToaster.com
Author:TemplateToaster
Author URI:http://TemplateToaster.com
}
*/
/*
Theme URI: http://www.themler.com/wordpress-themes
Description: Themler-generated theme
*/
/*
Theme URI: http://www.WpThemeGenerator.com/
Author: WpThemeGenerator
Author URI:www.WpThemeGenerator.com
*/
/* OK. */
/*
Theme Name: Twenty Seventeen
Theme URI: http://example.com
Author: WordPress.org
Author URI: example.com/author
*/
35 changes: 35 additions & 0 deletions WordPress/Tests/Theme/NoAutoGenerateUnitTest.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

<p>Lubith</p>
<!-- saved from url=(0045)http://docs.pinegrow.com/editing/code-editing -->
<?php
/**
* This theme was generated with Lubith - The Wordpress Theme Generator: http://www.lubith.com
*/
$shortname = "artisteer";
function themler_shortcode_login_link() {}
/**
* @package templatetoaster
*/
/* funcion que verifica si el dominio es wpthemegenerator */
function is_wpthemegenerator(){
if( $_SERVER['HTTP_HOST'] === 'www.wpthemegenerator.com' ){
return true;
} else {
return false;
}
}
/*
* Resource files included by Pinegrow.
*/

// OK.

/*
* Pine tress grow everywhere.
*/

/**
* This theme template was built in a toaster by artists
*/

function wp_vs_them() {}
68 changes: 68 additions & 0 deletions WordPress/Tests/Theme/NoAutoGenerateUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Unit test class for WordPress Coding Standard.
*
* @package WPCS\WordPressCodingStandards
* @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
* @license https://opensource.org/licenses/MIT MIT
*/

/**
* Unit test class for the Theme_NoAutoGenerate sniff.
*
* @package WPCS\WordPressCodingStandards
* @since 0.xx.0
*/
class WordPress_Tests_Theme_NoAutoGenerateUnitTest extends AbstractSniffUnitTest {

/**
* Returns the lines where errors should occur.
*
* @param string $testFile The name of the file being tested.
*
* @return array <int line number> => <int number of errors>
*/
public function getErrorList( $testFile = '' ) {
switch ( $testFile ) {
case 'NoAutoGenerateUnitTest.inc':
return array(
2 => 1,
3 => 1,
6 => 1,
8 => 1,
9 => 1,
11 => 1,
13 => 1,
14 => 1,
15 => 1,
22 => 1,
);
break;
case 'NoAutoGenerateUnitTest.css':
return array(
3 => 1,
4 => 1,
5 => 1,
9 => 1,
10 => 1,
13 => 1,
14 => 1,
15 => 1,
);
break;
default:
return array();
break;
}
}

/**
* Returns the lines where warnings should occur.
*
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
}

} // End class.

0 comments on commit 13e9146

Please sign in to comment.