Changeset 5502 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php
- Timestamp:
- 05/21/2017 01:51:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php
r4996 r5502 17 17 class Locale extends GP_Route { 18 18 19 private $cache_group = 'wporg-translate'; 20 19 21 /** 20 22 * Adapter for the rosetta roles plugin. … … 49 51 $locale = GP_Locales::by_slug( $locale_slug ); 50 52 if ( ! $locale ) { 53 return $this->die_with_404(); 54 } 55 56 if ( ! $this->translation_set_slug_exists( $locale, $set_slug ) ) { 51 57 return $this->die_with_404(); 52 58 } … … 88 94 } 89 95 90 91 96 $paged_sub_projects = $this->get_paged_active_sub_projects( 92 97 $project, … … 136 141 $can_create_locale_glossary = GP::$permission->current_user_can( 'admin' ); 137 142 $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 } 139 147 140 148 $this->tmpl( 'locale-projects', get_defined_vars() ); … … 152 160 $locale = GP_Locales::by_slug( $locale_slug ); 153 161 if ( ! $locale ) { 162 return $this->die_with_404(); 163 } 164 165 if ( ! $this->translation_set_slug_exists( $locale, $set_slug ) ) { 154 166 return $this->die_with_404(); 155 167 } … … 198 210 199 211 $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 ); 200 236 } 201 237
Note: See TracChangeset
for help on using the changeset viewer.