<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[6543] sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php: Plugins: Add basic set of plugin checks</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/6543">6543</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/6543","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>obenland</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-02-05 19:23:06 +0000 (Mon, 05 Feb 2018)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Plugins: Add basic set of plugin checks

Props Ipstenu.
Fixes <a href="http://meta.trac.wordpress.org/ticket/2350">#2350</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclassreviewtoolsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginsplugindirectoryadminmetaboxclassreviewtoolsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php    2018-02-05 17:03:18 UTC (rev 6542)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php      2018-02-05 19:23:06 UTC (rev 6543)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,4 +1,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * The Plugin Review metabox.
+ *
+ * @package WordPressdotorg\Plugin_Directory\Admin\Metabox
+ */
+
</ins><span class="cx" style="display: block; padding: 0 10px"> namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> use WordPressdotorg\Plugin_Directory\Tools;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,45 +15,230 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @package WordPressdotorg\Plugin_Directory\Admin\Metabox
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> class Review_Tools {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        static function display() {
-               $post = get_post();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * Contains all flags.
+        *
+        * @var array
+        */
+       public static $flagged = [
+               'low'  => [],
+               'med'  => [],
+               'high' => [],
+       ];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        /**
+        * List of commonly abused/misused terms.
+        *
+        * @var array
+        */
+       public static $reserved_slugs = [
+               'wordpress',
+               'woocommerce',
+               'google',
+               'youtube',
+               'twitter',
+               'facebook',
+               'yoast',
+               'jetpack',
+       ];
+
+       /**
+        * List of restricted plugin slugs.
+        *
+        * @var array
+        */
+       public static $restricted_slugs = [
+               // High-value plugin genres due to their popularity, often abused by spammers.
+               'gallery',
+               'lightbox',
+               'sitemap',
+               'bookmark',
+               'social',
+               'cookie',
+               'slide',
+               'seo',
+
+               // Plugins we generally don't allow.
+               'autoblog',
+               'auto-blog',
+               'booking',
+               'plugin',
+               'spinning',
+               'framework',
+       ];
+
+       /**
+        * List of suspicious URLs.
+        *
+        * @var array
+        */
+       public static $weird_urls = [
+               'blogger',
+               'blogspot',
+               'example.com',
+               'weebly',
+               'squarespace',
+               'medium.com',
+               'yahoo.com',
+               'mail.com',
+               'example.org',
+       ];
+
+       /**
+        * Displays links to plugin assets and automated flags.
+        */
+       public static function display() {
+               $post   = get_post();
+               $author = get_user_by( 'id', $post->post_author );
+               $slug   = $post->post_name;
+
+               $author_commit = Tools::get_users_write_access_plugins( $author );
+               // phpcs:ignore WordPress.VIP.RestrictedFunctions.get_posts_get_posts
+               $author_plugins = get_posts( [
+                       'author'           => $author->ID,
+                       'post_type'        => 'plugin',
+                       'post__not_in'     => [ $post->ID ],
+                       'suppress_filters' => false,
+               ] );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $zip_files = array();
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( get_attached_media( 'application/zip', $post ) as $zip_file ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $zip_files[ $zip_file->post_date ] = array( wp_get_attachment_url( $zip_file->ID ), $zip_file );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                uksort( $zip_files, function( $a, $b ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         uksort( $zip_files, function ( $a, $b ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return strtotime( $a ) < strtotime( $b );
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $zip_url = get_post_meta( $post->ID, '_submitted_zip', true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $zip_url = get_post_meta( $post->ID, '_submitted_zip', true );
+               if ( $zip_url ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Back-compat only.
</span><span class="cx" style="display: block; padding: 0 10px">                        $zip_files['User provided URL'] = array( $zip_url, null );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                echo '<p><strong>Zip files:</strong></p>';
+               echo '<ul class="plugin-zip-files">';
</ins><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $zip_files as $zip_date => $zip ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        list( $zip_url, $zip_file ) = $zip;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $zip_size                   = ( is_object( $zip_file ) ? size_format( filesize( get_attached_file( $zip_file->ID ) ), 1 ) : __( 'unknown size', 'wporg-plugins' ) );
-                       printf(
-                               '<p>' . __( '<strong>Zip file:</strong> %s', 'wporg-plugins' ) . '</p>',
-                               sprintf( '%s <a href="%s">%s</a> (%s)', esc_html( $zip_date ), esc_url( $zip_url ), esc_html( $zip_url ), esc_html( $zip_size ) )
-                       );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $zip_size                   = is_object( $zip_file ) ? size_format( filesize( get_attached_file( $zip_file->ID ) ), 1 ) : 'unknown size';
+
+                       printf( '<li>%s <a href="%s">%s</a> (%s)</li>', esc_html( $zip_date ), esc_url( $zip_url ), esc_html( $zip_url ), esc_html( $zip_size ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                echo '</ul>';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( 'new' !== $post->post_status && 'pending' !== $post->post_status ) {
-                       echo "<ul>
-                               <li><a href='https://plugins.trac.wordpress.org/log/{$post->post_name}/'>" . __( 'Development Log', 'wporg-plugins' ) . "</a></li>
-                               <li><a href='https://plugins.svn.wordpress.org/{$post->post_name}/'>" . __( 'Subversion Repository', 'wporg-plugins' ) . "</a></li>
-                               <li><a href='https://plugins.trac.wordpress.org/browser/{$post->post_name}/'>" . __( 'Browse in Trac', 'wporg-plugins' ) . '</a></li>
-                       </ul>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( in_array( $post->post_status, [ 'draft', 'pending' ], true ) ) {
+                       $slug_restricted = [];
+                       $slug_reserved   = [];
+
+                       // String length checks.
+                       if ( strlen( $slug ) < 5 ) {
+                               array_push( self::$flagged['med'], 'slug is less than 5 characters' );
+                       }
+                       if ( strlen( $slug ) > 50 ) {
+                               array_push( self::$flagged['med'], 'slug is more than 50 characters' );
+                       }
+
+                       // Check if any term in the restricted/reserved is in the plugin slug.
+                       $slug_string = str_replace( '-', ' ', $slug );
+
+                       foreach ( self::$restricted_slugs as $bad_slug ) {
+                               if ( false !== stristr( $slug_string, $bad_slug ) ) {
+                                       array_push( $slug_restricted, $bad_slug );
+                               }
+                       }
+                       foreach ( self::$reserved_slugs as $bad_slug ) {
+                               if ( false !== stristr( $slug_string, $bad_slug ) ) {
+                                       array_push( $slug_reserved, $bad_slug );
+                               }
+                       }
+                       if ( ! empty( $slug_restricted ) ) {
+                               array_push( self::$flagged['med'], 'plugin slug contains restricted term(s): ' . implode( ', ', $slug_restricted ) );
+                       }
+                       if ( ! empty( $slug_reserved ) ) {
+                               array_push( self::$flagged['high'], 'plugin slug contains reserved term(s): ' . implode( ', ', $slug_reserved ) );
+                       }
+
+                       // Check slug usage.
+                       $plugin_api_usage = intval( get_post_meta( $post->ID, 'active_installs', true ) );
+                       if ( $plugin_api_usage >= '5000' ) {
+                               array_push( self::$flagged['high'], 'slug used by more than 5000 users' );
+                       } elseif ( $plugin_api_usage >= '1000' ) {
+                               array_push( self::$flagged['med'], 'slug used by 1000-5000 users' );
+                       } elseif ( $plugin_api_usage >= '500' ) {
+                               array_push( self::$flagged['low'], 'slug used by 500-1000 users' );
+                       }
+
+                       // User account was registered less than 2 weeks ago (but longer than 3 days) (user is still fairly new).
+                       $two_weeks_ago  = time() - ( 2 * WEEK_IN_SECONDS );
+                       $three_days_ago = time() - ( 3 * DAY_IN_SECONDS );
+                       if ( strtotime( $author->user_registered ) > $two_weeks_ago && strtotime( $author->user_registered ) < $three_days_ago ) {
+                               array_push( self::$flagged['low'], 'account registered less than 2 weeks ago' );
+                       }
+                       if ( strtotime( $author->user_registered ) > $three_days_ago ) {
+                               array_push( self::$flagged['low'], 'account registered less than 3 days ago' );
+                       }
+
+                       // Username ends in numbers.
+                       if ( is_numeric( substr( $author->user_login, - 1, 1 ) ) ) {
+                               array_push( self::$flagged['low'], 'username ends in numbers' );
+                       }
+
+                       // User has no URL.
+                       if ( empty( $author->user_url ) ) {
+                               array_push( self::$flagged['low'], 'account has no URL' );
+                       }
+
+                       foreach ( self::$weird_urls as $url ) {
+                               if ( false !== stripos( $author->user_url, $url ) ) {
+                                       array_push( self::$flagged['med'], 'account URL contains ' . $url );
+                               }
+                               if ( false !== stripos( $author->user_email, $url ) ) {
+                                       array_push( self::$flagged['med'], 'account email contains ' . $url );
+                               }
+                       }
+
+                       // Reserved slugs are also often abused domain names (trademark law sucks).
+                       foreach ( self::$reserved_slugs as $url ) {
+                               if ( false !== stripos( $author->user_url, $url ) ) {
+                                       array_push( self::$flagged['high'], 'account URL contains ' . $url );
+                               }
+                               if ( false !== stripos( $author->user_email, $url ) ) {
+                                       array_push( self::$flagged['med'], 'account email contains ' . $url );
+                               }
+                       }
+
+                       // User Behavior.
+                       // If FORUM ROLE is blocked.
+                       if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
+                               $user = new \WP_User( $post->post_author, '', WPORG_SUPPORT_FORUMS_BLOGID );
+                               if ( ! empty( $user->allcaps['bbp_blocked'] ) ) {
+                                       array_push( self::$flagged['high'], 'user is blocked' );
+                               }
+                       }
+
+                       // No plugins.
+                       if ( empty( $author_commit ) && empty( $author_plugins ) ) {
+                               array_push( self::$flagged['low'], 'user has no plugins' );
+                       }
+
+                       // Echo flag results (everyone pretty much has at least one).
+                       echo '<ul class="plugin-flagged">';
+                       foreach ( self::$flagged as $flag => $reasons ) {
+                               if ( count( $reasons ) ) {
+                                       echo '<li class="plugin-flagged-' . esc_attr( $flag ) . '"><strong>' . esc_html( strtoupper( $flag ) ) . ' (' . esc_html( count( $reasons ) ) . '):</strong> ' . esc_html( implode( '; ', $reasons ) ) . '</li>';
+                               }
+                       }
+                       echo '</ul>';
+               } else {
+                       ?>
+                       <ul>
+                               <li><a href='https://plugins.trac.wordpress.org/log/<?php echo esc_attr( $post->post_name ); ?>/'>Development Log</a></li>
+                               <li><a href='https://plugins.svn.wordpress.org/<?php echo esc_attr( $post->post_name ); ?>/'>Subversion Repository</a></li>
+                               <li><a href='https://plugins.trac.wordpress.org/browser/<?php echo esc_attr( $post->post_name ); ?>/'>Browse in Trac</a></li>
+                       </ul>
+                       <?php
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $post->post_excerpt && in_array( $post->post_status, array( 'new', 'pending', 'approved' ) ) ) {
-                       echo '<p>' . strip_tags( $post->post_excerpt ) . '</p>';
-               }
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_filter( 'wp_comment_reply', function( $string ) use ( $post ) {
-                       $author = get_user_by( 'id', $post->post_author );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_filter( 'wp_comment_reply', function ( $string ) use ( $post, $author ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $committers = Tools::get_plugin_committers( $post->post_name );
</span><span class="cx" style="display: block; padding: 0 10px">                        $committers = array_map( function ( $user_login ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                return get_user_by( 'login', $user_login );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,11 +260,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        ?>
</span><span class="cx" style="display: block; padding: 0 10px">                        <form id="contact-author" class="contact-author" method="POST" action="https://supportpress.wordpress.org/plugins/thread-new.php">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <input type="hidden" name="to_email" value="<?php echo esc_attr( $author->user_email ); ?>" />
-                               <input type="hidden" name="to_name" value="<?php echo esc_attr( $author->display_name ); ?>" />
-                               <input type="hidden" name="cc" value="<?php echo esc_attr( $cc_emails ); ?>" />
-                               <input type="hidden" name="subject" value="<?php echo esc_attr( $subject ); ?>" />
-                               <button class="button button-primary" type="submit"><?php _e( 'Contact plugin author', 'wporg-plugins' ); ?></button>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <input type="hidden" name="to_email" value="<?php echo esc_attr( $author->user_email ); ?>"/>
+                               <input type="hidden" name="to_name" value="<?php echo esc_attr( $author->display_name ); ?>"/>
+                               <input type="hidden" name="cc" value="<?php echo esc_attr( $cc_emails ); ?>"/>
+                               <input type="hidden" name="subject" value="<?php echo esc_attr( $subject ); ?>"/>
+                               <button class="button button-primary" type="submit">Contact plugin author</button>
</ins><span class="cx" style="display: block; padding: 0 10px">                         </form>
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,4 +272,3 @@
</span><span class="cx" style="display: block; padding: 0 10px">                } );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del></span></pre>
</div>
</div>

</body>
</html>