Making WordPress.org

Changeset 5502


Ignore:
Timestamp:
05/21/2017 01:51:02 PM (7 years ago)
Author:
ocean90
Message:

Translate: Avoid PHP notices if a translation set doesn't exist.

Also add a few missing esc_url() calls and a custom 404 template with a link back to the homepage.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/locale-project.php

    r4996 r5502  
    7777                            printf(
    7878                                '<li><a href="%s">%s <span>%s</span></a>',
    79                                 gp_url_project( $sub_project->path, gp_url_join( $locale->slug, $set_slug ) ),
     79                                esc_url( gp_url_project( $sub_project->path, gp_url_join( $locale->slug, $set_slug ) ) ),
    8080                                $sub_project->name,
    8181                                $sub_project_status->percent_complete . '%'
     
    8888                            printf(
    8989                                '<li><a href="%s">%s <span>%s</span></a>',
    90                                 gp_url_project( $_sub_project->path, gp_url_join( $locale->slug, $set_slug ) ),
     90                                esc_url( gp_url_project( $_sub_project->path, gp_url_join( $locale->slug, $set_slug ) ) ),
    9191                                $_sub_project->name,
    9292                                $status->percent_complete . '%'
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/locale-projects.php

    r4996 r5502  
    6969            printf(
    7070                '<li><a href="%s"%s>%s</a></li>',
    71                 gp_url_join( '/locale', $locale_slug, $set_slug, $top_level_project->slug ),
     71                esc_url( gp_url_join( '/locale', $locale_slug, $set_slug, $top_level_project->slug ) ),
    7272                ( $top_level_project->path == $project_path ) ? ' class="current"' : '',
    7373                $top_level_project->name
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-plugins-contributors.php

    r4512 r5502  
    3232                <li><span>Contributors</span>
    3333                    <ul>
    34                         <li><a href="<?php echo gp_url_project( $project ); ?>">Projects</a></li>
    35                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'language-packs' ); ?>">Language Packs</a></li>
     34                        <li><a href="<?php echo esc_url( gp_url_project( $project ) ); ?>">Projects</a></li>
     35                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ) ), 'language-packs' ); ?>">Language Packs</a></li>
    3636                    </ul>
    3737                </li>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-plugins-language-packs.php

    r2660 r5502  
    3131                <li><span>Language Packs</span>
    3232                    <ul>
    33                         <li><a href="<?php echo gp_url_project( $project ); ?>">Projects</a></li>
    34                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'contributors' ); ?>">Contributors</a></li>
     33                        <li><a href="<?php echo esc_url( gp_url_project( $project ) ); ?>">Projects</a></li>
     34                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ) ), 'contributors' ); ?>">Contributors</a></li>
    3535                    </ul>
    3636                </li>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-plugins.php

    r4513 r5502  
    3737                <li><span>Projects</span>
    3838                    <ul>
    39                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'contributors' ); ?>">Contributors</a></li>
    40                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'language-packs' ); ?>">Language Packs</a></li>
     39                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ) ), 'contributors' ); ?>">Contributors</a></li>
     40                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ) ), 'language-packs' ); ?>">Language Packs</a></li>
    4141                    </ul>
    4242                </li>
     
    9090                <tr>
    9191                    <th title="<?php echo esc_attr( $gp_locale->wp_locale ); ?>">
    92                         <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>">
     92                        <a href="<?php echo esc_url( gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ) ); ?>">
    9393                            <?php echo esc_html( $gp_locale->english_name ); ?>
    9494                        </a>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-themes-contributors.php

    r2864 r5502  
    3232                <li><span>Contributors</span>
    3333                    <ul>
    34                         <li><a href="<?php echo gp_url_project( $project ); ?>">Projects</a></li>
    35                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'language-packs' ); ?>">Language Packs</a></li>
     34                        <li><a href="<?php echo esc_url( gp_url_project( $project ) ); ?>">Projects</a></li>
     35                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ) ), 'language-packs' ); ?>">Language Packs</a></li>
    3636                    </ul>
    3737                </li>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-themes-language-packs.php

    r2864 r5502  
    3131                <li><span>Language Packs</span>
    3232                    <ul>
    33                         <li><a href="<?php echo gp_url_project( $project ); ?>">Projects</a></li>
    34                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'contributors' ); ?>">Contributors</a></li>
     33                        <li><a href="<?php echo esc_url( gp_url_project( $project ) ); ?>">Projects</a></li>
     34                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ), 'contributors' ) ); ?>">Contributors</a></li>
    3535                    </ul>
    3636                </li>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/projects-wp-themes.php

    r4187 r5502  
    3434                <li><span>Projects</span>
    3535                    <ul>
    36                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'contributors' ); ?>">Contributors</a></li>
    37                         <li><a href="<?php echo gp_url_join( gp_url_project( $project ), 'language-packs' ); ?>">Language Packs</a></li>
     36                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ), 'contributors' ) ); ?>">Contributors</a></li>
     37                        <li><a href="<?php echo esc_url( gp_url_join( gp_url_project( $project ), 'language-packs' ) ); ?>">Language Packs</a></li>
    3838                    </ul>
    3939                </li>
     
    8181                <tr>
    8282                    <th title="<?php echo esc_attr( $gp_locale->wp_locale ); ?>">
    83                         <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>">
     83                        <a href="<?php echo esc_url( gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ) ); ?>">
    8484                            <?php echo esc_html( $gp_locale->english_name ); ?>
    8585                        </a>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-overview.php

    r4179 r5502  
    4343                <tr>
    4444                    <th title="<?php echo esc_attr( $gp_locale->english_name ); ?>">
    45                         <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug ) ); ?>">
     45                        <a href="<?php echo esc_url( gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug ) ) ); ?>">
    4646                            <?php echo esc_html( $gp_locale->wp_locale ); ?>
    4747                        </a>
     
    6363                                }
    6464                                $percent_class = 'percent' . $percent_class;
    65                                 echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="'. esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . $projecturl . '">' . number_format( $percent ) . '</a></td>';
     65                                echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="'. esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . esc_url( $projecturl ) . '">' . number_format( $percent ) . '</a></td>';
    6666                            } else {
    6767                                $percent_class = 'percent' . (int) ( $percent / 10 ) * 10;
    68                                 echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="' . esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . $projecturl . '">' . $percent . '%</a></td>';
     68                                echo '<td data-column-title="' . esc_attr( $project_name ) . '" data-sort-value="' . esc_attr( $percent ) . '" class="' . $percent_class .'"><a href="' . esc_url( $projecturl ) . '">' . $percent . '%</a></td>';
    6969                            }
    7070
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php

    r4996 r5502  
    1717class Locale extends GP_Route {
    1818
     19    private $cache_group = 'wporg-translate';
     20
    1921    /**
    2022     * Adapter for the rosetta roles plugin.
     
    4951        $locale = GP_Locales::by_slug( $locale_slug );
    5052        if ( ! $locale ) {
     53            return $this->die_with_404();
     54        }
     55
     56        if ( ! $this->translation_set_slug_exists( $locale, $set_slug ) ) {
    5157            return $this->die_with_404();
    5258        }
     
    8894        }
    8995
    90 
    9196        $paged_sub_projects = $this->get_paged_active_sub_projects(
    9297            $project,
     
    136141        $can_create_locale_glossary = GP::$permission->current_user_can( 'admin' );
    137142        $locale_glossary_translation_set = GP::$translation_set->by_project_id_slug_and_locale( 0, $set_slug, $locale_slug );
    138         $locale_glossary = GP::$glossary->by_set_id( $locale_glossary_translation_set->id );
     143        $locale_glossary = false;
     144        if ( $locale_glossary_translation_set ) {
     145            $locale_glossary = GP::$glossary->by_set_id( $locale_glossary_translation_set->id );
     146        }
    139147
    140148        $this->tmpl( 'locale-projects', get_defined_vars() );
     
    152160        $locale = GP_Locales::by_slug( $locale_slug );
    153161        if ( ! $locale ) {
     162            return $this->die_with_404();
     163        }
     164
     165        if ( ! $this->translation_set_slug_exists( $locale, $set_slug ) ) {
    154166            return $this->die_with_404();
    155167        }
     
    198210
    199211        $this->tmpl( 'locale-project', get_defined_vars() );
     212    }
     213
     214    /**
     215     * Whether a translation set slug exists for a locale.
     216     *
     217     * @param \GP_Locale $locale The locale.
     218     * @param string     $slug   The slug of a translation set.
     219     * @return bool True if slug exists, false if not.
     220     */
     221    private function translation_set_slug_exists( $locale, $slug ) {
     222        $cache_key = "translation_set_slugs:{$locale->slug}";
     223        $slugs = wp_cache_get( $cache_key, $this->cache_group );
     224
     225        if ( false === $slugs ) {
     226            global $wpdb;
     227            $slugs = $wpdb->get_col( $wpdb->prepare(
     228                "SELECT DISTINCT(slug) FROM {$wpdb->gp_translation_sets} WHERE locale = %s",
     229                $locale->slug
     230            ) );
     231
     232            wp_cache_set( $cache_key, $slugs, $this->cache_group, DAY_IN_SECONDS );
     233        }
     234
     235        return in_array( $slug, $slugs, true );
    200236    }
    201237
Note: See TracChangeset for help on using the changeset viewer.