Making WordPress.org


Ignore:
Timestamp:
08/31/2016 04:58:29 PM (10 years ago)
Author:
jmdodd
Message:

Support Forums: Move logic into parent class, and display-specific functions into child compat classes.

Theme and plugin views share many behaviors; to avoid trying to keep both updated, this moves taxonomy registration, tests for loading actions and filters, view registration, rewrite rules, and general display logic into the general directory compat class.

Constants, helper functions, and unique display methods have been separated into their respective plugin or theme compat class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-theme-directory-compat.php

    r3846 r3892  
    77        const COMPAT = 'theme';
    88
    9         var $slug = '';
    10         var $theme = '';
     9        var $slug  = false;
     10        var $theme = null;
    1111
    1212        function compat() {
    1313                return self::COMPAT;
     14        }
     15
     16        function compat_title() {
     17                return __( 'Theme Support', 'wporg-forums' );
    1418        }
    1519
    … …  
    3539
    3640        public function __construct() {
    37                 if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && get_current_blog_id() == WPORG_SUPPORT_FORUMS_BLOGID ) {
    38                         // We have to add the custom view before bbPress runs its own action
    39                         // on parse_query at priority 2.
    40                         add_action( 'parse_query', array( $this, 'parse_query' ), 1 );
    41 
    42                         // Add parent class hooks.
    43                         add_action( 'plugins_loaded', array( $this, 'init' ) );
    44                 }
     41                $this->init();
    4542        }
    4643
    … …  
    5451                }
    5552
    56                 $theme = $this->get_theme_data( $slug );
     53                $theme = $this->get_object( $slug );
    5754                if ( ! $theme ) {
    5855                        return;
    5956                } else {
    60                         $this->slug  = $slug;
    61                         $this->theme = $theme;
     57                        $this->slug         = $slug;
     58                        $this->theme        = $theme;
     59                        $this->authors      = $this->get_authors( $slug );
     60                        $this->contributors = $this->get_contributors( $slug );
    6261                }
    63 
    64                 // Add theme support view.
    65                 bbp_register_view(
    66                         self::COMPAT,
    67                         __( 'Theme Support', 'wporg-forums' ),
    68                         array(
    69                                 'post_parent'   => Plugin::THEMES_FORUM_ID,
    70                                 'tax_query'     => array( array(
    71                                         'taxonomy'  => $this->taxonomy(),
    72                                         'field'     => 'slug',
    73                                         'terms'     => $slug,
    74                                 ) ),
    75                                 'orderby'       => '',
    76                                 'show_stickies' => false,
    77                         )
    78                 );
    79 
    80                 // Add theme review view.
    81                 bbp_register_view(
    82                         'reviews',
    83                         __( 'Reviews', 'wporg-forums' ),
    84                         array(
    85                                 'post_parent'   => Plugin::REVIEWS_FORUM_ID,
    86                                 'tax_query'     => array( array(
    87                                         'taxonomy'  => $this->taxonomy(),
    88                                         'field'     => 'slug',
    89                                         'terms'     => $slug,
    90                                 ) ),
    91                                 'orderby'       => '',
    92                                 'show_stickies' => false,
    93                         )
    94                 );
    9562        }
    9663
    97         public function get_theme_data( $slug = '' ) {
    98                 global $wpdb;
     64        public function do_view_sidebar() {
     65                ?>
     66                <div>
     67                        <h3><?php _e( 'Browse Themes', 'wporg-forums' ); ?></h3>
    9968
    100                 if ( ! empty( $this->theme ) ) {
    101                         return $this->theme;
    102                 }
     69                        <ul class="theme-submenu">
     70                                <li class="view"><a href="//wordpress.org/themes/"><?php _e( 'Featured', 'wporg-forums' ); ?></a></li>
     71                                <li class="view"><a href="//wordpress.org/themes/browse/popular/"><?php _e( 'Most Popular', 'wporg-forums' ); ?></a></li>
     72                                <li class="view"><a href="//wordpress.org/themes/browse/new/"><?php _e( 'Latest', 'wporg-forums' ); ?></a></li>
     73                                <li class="view"><a href="/themes/getting-started/"><?php _e( 'Theme Authors', 'wporg-forums' ); ?></a></li>
     74                                <li class="view"><a href="/themes/commercial/"><?php _e( 'Commercial', 'wporg-forums' ); ?></a></li>
     75                        </ul>
     76                </div>
    10377
    104                 $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}%d_posts WHERE post_name = %s AND post_type = 'repopackage' LIMIT 1", WPORG_THEME_DIRECTORY_BLOGID, $slug );
    105                 $row = $wpdb->get_row( $sql );
    106                 if ( ! $row ) {
    107                         return false;
    108                 } else {
    109                         $theme = $row;
    110                         $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}%d_postmeta WHERE post_id = %d AND meta_key NOT LIKE %s", WPORG_THEME_DIRECTORY_BLOGID, $row->ID, '_trac_ticket_%' );
    111                         $results = $wpdb->get_results( $sql );
    112                         if( $results ) {
    113                                 foreach ( $results as $row ) {
    114                                         if ( ! isset( $theme->{$row->meta_key} ) ) {
    115                                                 $theme->{$row->meta_key} = maybe_unserialize( $row->meta_value );
    116                                         }
    117                                 }
    118                         }
    119                 }
    120                 return $theme;
     78                <div>
     79                        <h3><?php _e( 'Search Themes', 'wporg-forums' ); ?></h3>
     80
     81                        <form id="side-search" method="get" action="//wordpress.org/themes/search.php">
     82                        <div>
     83                                <input type="text" class="text" name="q" value="" />
     84                                <input type="submit" class="button" value="<?php _e( 'Search', 'wporg-forums' ); ?>" />
     85                        </div>
     86                        </form>
     87                </div>
     88                <?php
     89        }
     90
     91        public function do_topic_sidebar() {
     92                $theme   = sprintf( '<a href="//wordpress.org/plugins/%s/">%s</a>', esc_attr( $this->slug() ), esc_html( $this->theme->post_title ) );
     93                $support = sprintf( '<a href="//wordpress.org/support/plugin/%s/">Support Threads</a>', esc_attr( $this->slug() ) );
     94                $reviews = sprintf( '<a href="//wordpress.org/support/plugin/%s/reviews/">Reviews</a>', esc_attr( $this->slug() ) );
     95                ?>
     96                <div>
     97                        <h3>About this Theme</h3>
     98                        <ul>
     99                                <li><?php echo $theme; ?></li>
     100                                <li><?php echo $support; ?></li>
     101                                <li><?php echo $reviews; ?></li>
     102                        </ul>
     103                </div>
     104                <?php
     105        }
     106
     107
     108        /**
     109         * Return a custom view header string so that get_breadcrumbs will display it.
     110         */
     111        public function get_view_header() {
     112                $slug        = esc_attr( $this->slug );
     113                $description = esc_html__( 'Description', 'wporg-forums' );
     114                $support     = esc_html__( 'Support', 'wporg-forums' );
     115                $reviews     = esc_html__( 'Reviews', 'wporg-forums' );
     116
     117                $header = <<<EOT
     118                <ul id="sections">
     119                        <li class="section-description">
     120                                <a href="//wordpress.org/themes/{$slug}/">{$description}</a>
     121                        </li>
     122                        <li class="section-support">
     123                                <a href="//wordpress.org/support/theme/{$slug}/">{$support}</a>
     124                        <li>
     125                        <li class="section-reviews">
     126                                <a href="//wordpress.org/support/theme/{$slug}/reviews/">{$reviews}</a>
     127                        </li>
     128                        </ul>
     129EOT;
     130                return $header;
    121131        }
    122132}
Note: See TracChangeset for help on using the changeset viewer.