Making WordPress.org

Ticket #2350: 2350.1.diff

File 2350.1.diff, 7.8 KB (added by Ipstenu, 8 years ago)

First pass at more tools

  • wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php

     
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
    33
     4use WordPressdotorg\Plugin_Directory\Tools;
     5
    46/**
    57 * The Plugin Review metabox.
    68 *
     
    79 * @package WordPressdotorg\Plugin_Directory\Admin\Metabox
    810 */
    911class Review_Tools {
    10         static function display() {
     12
     13        static function display() {             
    1114                $post = get_post();
     15                $author = get_user_by( 'id', $post->post_author );
     16                $slug = $post->post_name;
     17                $author_plugins = get_posts( array(
     18                        'author'       => $author->ID,
     19                        'post_type'    => 'plugin',
     20                        'post__not_in' => array( $post->ID ),
     21                ) );
     22                $author_commit  = Tools::get_users_write_access_plugins( $author );
    1223
    1324                foreach ( get_attached_media( 'application/zip', $post ) as $zip_file ) {
    1425                        $zip_url = wp_get_attachment_url( $zip_file->ID );
     
    1728                                sprintf( '<a href="%s">%s</a>', esc_url( $zip_url ), esc_html( $zip_url ) )
    1829                        );
    1930                }
     31               
     32                if ( $post->post_status == 'draft' || $post->post_status == 'pending' ) {
     33                       
     34                        $flagged = array(
     35                                'low' => array (),
     36                                'med' => array (),
     37                                'high' => array (),
     38                        );
     39                                               
     40                        echo "<p><strong>Flagged!</strong>";
     41               
     42                        $reserved_slugs = array (
     43                                // Commonly abused/misused terms
     44                                'wordpress', 'woocommerce', 'google', 'youtube', 'twitter', 'facebook', 'yoast', 'jetpack',
     45                        );
    2046
    21                 echo "<ul>
    22                         <li><a href='https://plugins.trac.wordpress.org/log/{$post->post_name}/'>" . __( 'Development Log', 'wporg-plugins' ) . "</a></li>
    23                         <li><a href='https://plugins.svn.wordpress.org/{$post->post_name}/'>" . __( 'Subversion Repository', 'wporg-plugins' ) . "</a></li>
    24                         <li><a href='https://plugins.trac.wordpress.org/browser/{$post->post_name}/'>" . __( 'Browse in Trac', 'wporg-plugins' ) . '</a></li>
    25                 </ul>';
     47                        $restricted_slugs = array (
     48                                // High-value plugin genres due to their popularity, often abused by spammers
     49                                'gallery', 'lightbox', 'sitemap', 'bookmark', 'social', 'cookie', 'slide', 'seo',
     50                                // Plugins we generally don't allow
     51                                'autoblog', 'auto-blog', 'booking', 'plugin', 'spinning', 'framework',
     52                        );
     53               
     54                        // String length checks
     55                        if ( strlen($slug) < '5' ) array_push( $flagged['med'], __( 'slug is less than 5 characters', 'wporg-plugins' ) );
     56                        if ( strlen($slug) > '50' ) array_push( $flagged['med'], __( 'slug is more than 50 characters', 'wporg-plugins' ) );
     57                       
     58                        // Check if any term in the restricted/reserved is in the plugin slug
     59                        $slug_string = str_replace('-', ' ', $slug );
     60                        $slug_restricted = $slug_reserved = array() ;
     61                        foreach ( $restricted_slugs as $badslug ) {
     62                                if ( stristr($slug_string, $badslug ) !== FALSE ) array_push( $slug_restricted, $badslug );
     63                        }
     64                        foreach ( $reserved_slugs as $badslug ) {
     65                                if ( stristr($slug_string, $badslug ) !== FALSE ) array_push( $slug_reserved , $badslug );
     66                        }
     67                        if ( !empty( $slug_restricted ) )
     68                                array_push( $flagged['med'], __( 'plugin slug contains restricted term(s): ', 'wporg-plugins' ) . implode( ', ', $slug_restricted ) );
     69                        if ( !empty( $slug_reserved ) )
     70                                array_push( $flagged['high'], __( 'plugin slug contains reserved term(s): ', 'wporg-plugins' ) . implode( ', ', $slug_reserved ) );
     71                       
     72                        // Check slug usage
     73                        $plugin_api_usage = '1000'; // this is a placeholder until we figure out how to do this.
     74                        if ( $plugin_api_usage >= '5000' ) {
     75                                array_push( $flagged['high'], __( 'slug used by more than 5000 users', 'wporg-plugins' ) );
     76                        } elseif ( $plugin_api_usage >= '1000' ) {
     77                                array_push( $flagged['med'], __( 'slug used by 1000-5000 users', 'wporg-plugins' ) );
     78                        } elseif ( $plugin_api_usage >= '500' ) {
     79                                array_push( $flagged['low'], __( 'slug used by 500-1000 users', 'wporg-plugins' ) );
     80                        }
    2681
     82                        // User account was registered less than 2 weeks ago (but longer than 3 days) (user is still fairly new)
     83                        $twoweeksago  = time() - (2 * 7 * 24 * 60 * 60);
     84                        $threedaysago = time() - (3 * 1 * 24 * 60 * 60);
     85                        if ( strtotime($author->user_registered) > $twoweeksago && strtotime($author->user_registered) < $threedaysago )  array_push( $flagged['low'], __( 'account registered less than 2 weeks ago', 'wporg-plugins' ) );
     86                        if ( strtotime($author->user_registered) > $threedaysago ) array_push( $flagged['low'], __( 'account registered less than 3 days ago', 'wporg-plugins' ) );
     87
     88                        // Username ends in numbers
     89                        if ( is_numeric(substr($author->user_login, -1, 1) ) ) array_push( $flagged['low'], __( 'username ends in numbers', 'wporg-plugins' ) );
     90                       
     91                        // User has no URL
     92                        if ( empty( $author->user_url ) ) array_push( $flagged['low'], __( 'account has no URL', 'wporg-plugins' ) );
     93                       
     94                        // URL matches the weird list
     95                        $weird_urls = array (
     96                                'blogger', 'blogspot', 'example.com', 'weebly', 'squarespace', 'medium.com', 'yahoo.com',
     97                                'mail.com', 'example.org',
     98                        );
     99                        foreach ( $weird_urls as $url ) {
     100                                if ( stripos( $author->user_url , $url ) !== false )
     101                                        array_push( $flagged['med'], __( 'account URL contains ', 'wporg-plugins' ) . $url );
     102                                if ( stripos( $author->user_email , $url ) !== false )
     103                                        array_push( $flagged['med'], __( 'account email contains ', 'wporg-plugins' ) . $url );
     104                        }
     105               
     106                        // Reserved slugs are also often abused domain names (trademark law sucks)
     107                        foreach ( $reserved_slugs as $url ) {
     108                                if ( stripos( $author->user_url , $url ) !== false )
     109                                        array_push( $flagged['high'], __( 'account URL contains ', 'wporg-plugins' ) . $url );
     110                                if ( stripos( $author->user_email , $url ) !== false )
     111                                        array_push( $flagged['med'], __( 'account email contains ', 'wporg-plugins' ) . $url );
     112                        }
     113
     114                        // User Behavior
     115                        // If FORUM ROLE is blocked
     116                        if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     117                                $user = new \WP_User( $post->post_author, '', WPORG_SUPPORT_FORUMS_BLOGID );
     118                                if ( ! empty( $user->allcaps['bbp_blocked'] ) )
     119                                        array_push( $flagged['high'], __( 'user is blocked', 'wporg-plugins' ) );       
     120                        }
     121                       
     122                        // No plugins
     123                        if ( empty( $author_commit ) && empty( $author_plugins ) )
     124                                array_push( $flagged['low'], __( 'user has no plugins', 'wporg-plugins' ) );
     125
     126                        // Echo flag results (everyone pretty much has at least one)
     127                        echo "<ul class=\"plugin-flagged\">";
     128                        $noflag = 0;
     129                        foreach ( $flagged as $flag => $reasons ) {
     130                                if (count($reasons) > '0') {
     131                                        $allreasons = array();
     132                                        echo "<li class=\"plugin-flagged-".$flag."\"><strong>".strtoupper($flag)." (".count($reasons)."):</strong> ";
     133                                        foreach( $reasons as $reason) {
     134                                                $allreasons[] = $reason;
     135                                        }
     136                                        echo implode( '; ', $allreasons ) . "</li>";
     137                                } else {
     138                                        $noflag++;
     139                                }
     140                        }
     141                       
     142                        if ($noflag == '3' ) {
     143                                ?><li><?php _e( 'Nothing flagged! You found Matt!', 'wporg-plugins' ); ?></li><?php
     144                        }
     145                       
     146                        echo "</ul>";
     147
     148                } else {
     149                        echo "<ul>
     150                                <li><a href='https://plugins.trac.wordpress.org/log/{$post->post_name}/'>" . __( 'Development Log', 'wporg-plugins' ) . "</a></li>
     151                                <li><a href='https://plugins.svn.wordpress.org/{$post->post_name}/'>" . __( 'Subversion Repository', 'wporg-plugins' ) . "</a></li>
     152                                <li><a href='https://plugins.trac.wordpress.org/browser/{$post->post_name}/'>" . __( 'Browse in Trac', 'wporg-plugins' ) . '</a></li>
     153                        </ul>';
     154                }
     155
    27156                add_filter( 'wp_comment_reply', function( $string ) use ( $post ) {
    28157                        $author = get_user_by( 'id', $post->post_author );
    29158                        ?>
     
    35164                        </form>
    36165                        <?php
    37166                        return $string;
    38                 } );
     167                }
     168                );
    39169        }
    40 }
    41170
     171}
     172 No newline at end of file