JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
/**
* Handles execution and rendering of HTML admin pages.
*/
class Loco_mvc_AdminRouter extends Loco_hooks_Hookable {
/**
* Current admin page controller
*/
private ?Loco_mvc_AdminController $ctrl = null;
/**
* admin_menu action callback
*/
public function on_admin_menu() {
// lowest capability required to see menu items is "loco_admin"
// currently also the highest (and only) capability
$cap = 'loco_admin';
$user = wp_get_current_user();
// rendering hook for all menu items
$render = [ $this, 'renderPage' ];
// main loco pages, hooking only if user has permission (filtered via AdminHooks)
if( $user->has_cap($cap) ){
$label = __('Loco Translate','loco-translate');
// translators: Page title for plugin home screen
$title = __('Loco, Translation Management','loco-translate');
add_menu_page( $title, $label, $cap, 'loco', $render, 'dashicons-translation' );
// alternative label for first menu item which gets repeated from top level
add_submenu_page( 'loco', $title, __('Home','loco-translate'), $cap, 'loco', $render );
$label = __('Themes','loco-translate');
// translators: Page title for theme translations
$title = __('Theme translations ‹ Loco','loco-translate');
add_submenu_page( 'loco', $title, $label, $cap, 'loco-theme', $render );
$label = __('Plugins', 'loco-translate');
// translators: Page title for plugin translations
$title = __('Plugin translations ‹ Loco','loco-translate');
add_submenu_page( 'loco', $title, $label, $cap, 'loco-plugin', $render );
$label = __('WordPress', 'loco-translate');
// translators: Page title for core WordPress translations
$title = __('Core translations ‹ Loco', 'loco-translate');
add_submenu_page( 'loco', $title, $label, $cap, 'loco-core', $render );
$label = __('Languages', 'loco-translate');
// translators: Page title for installed languages page
$title = __('Languages ‹ Loco', 'loco-translate');
add_submenu_page( 'loco', $title, $label, $cap, 'loco-lang', $render );
// settings page only for users with manage_options permission in addition to Loco access:
if( $user->has_cap('manage_options') ){
$title = __('Plugin settings','loco-translate');
add_submenu_page( 'loco', $title, __('Settings','loco-translate'), 'manage_options', 'loco-config', $render );
}
// but all users need access to user preferences which require standard Loco access permission
else {
$title = __('User options','loco-translate');
add_submenu_page( 'loco', $title, __('Settings','loco-translate'), $cap, 'loco-config-user', $render );
}
// string translation simulator
if( loco_debugging() ){
$label = __('Debug', 'loco-translate');
add_submenu_page( 'loco', $label, $label, $cap, 'loco-debug', $render );
}
}
}
/**
* Early hook as soon as we know what screen will be rendered
* @return void
*/
public function on_current_screen( WP_Screen $screen ){
$this->initPage( $screen, $_GET['action']??'' );
}
/**
* Instantiate admin page controller from current screen.
* This is called early (before renderPage) so controller can listen on other hooks.
*
* @return Loco_mvc_AdminController|null
*/
public function initPage( WP_Screen $screen, string $action = '' ){
$args = [];
$class = '';
// suppress error display when establishing Loco page
$page = self::screenToPage($screen);
if( is_string($page) ){
$class = self::pageToClass( $page, $action, $args );
}
if( '' === $class ){
$this->ctrl = null;
return null;
}
// class should exist, so throw fatal if it doesn't
$this->ctrl = new $class;
if( ! $this->ctrl instanceof Loco_mvc_AdminController ){
throw new Exception( $class.' must inherit Loco_mvc_AdminController');
}
// transfer flash messages from session to admin notice buffer
try {
$session = Loco_data_Session::get();
while( $message = $session->flash('success') ){
Loco_error_AdminNotices::success( $message );
}
}
catch( Exception $e ){
Loco_error_AdminNotices::debug( $e->getMessage() );
}
// Initialise controller with query string + route arguments.
// External $_GET is filtered through the controller's allowedParams; trusted routing args
// (_route, type, action) are passed separately so they can't be spoofed or stripped.
// note that $_GET is not being stripped of slashes added by WordPress.
$args['action'] = $action;
try {
$this->ctrl->_init( $_GET, $args );
do_action('loco_admin_init', $this->ctrl );
}
// catch errors during controller setup
catch( Loco_error_Exception $e ){
$this->ctrl = new Loco_admin_ErrorController;
// can't afford an error during an error
try {
$this->ctrl->_init( [], [ 'error' => $e ] );
}
catch( Throwable $_e ){
Loco_error_AdminNotices::debug( $_e->getMessage() );
Loco_error_AdminNotices::add($e);
}
}
// WP emoji replacement doesn't inherit .wp-exclude-emoji so we'd have to add it to hundreds of elements.
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
return $this->ctrl;
}
/**
* Convert WordPress internal WPScreen $id into route prefix for an admin page controller
*/
private static function screenToPage( WP_Screen $screen ):?string {
// Hooked menu slug is either "toplevel_page_loco" or "{title}_page_loco-{page}"
// Sanitized {title} prefix is not reliable as it may be localized. instead just checking for "_page_loco"
$id = $screen->id;
$start = strpos($id,'_page_loco');
if( is_int($start) ){
return substr( $id, $start+11 )?:'';
}
// null indicates not one of our pages if token not found (empty string means root page)
return null;
}
/**
* Get unvalidated controller class for given route parameters
* Abstracted from initPage so we can validate routes in self::generate
*/
private static function pageToClass( string $page, string $action, array &$args ):string {
$routes = [
'' => 'Root',
'debug' => 'Debug',
// site-wide plugin configurations
'config' => 'config_Settings',
'config-apis' => 'config_Apis',
'config-user' => 'config_Prefs',
'config-debug' => 'config_Debug',
'config-version' => 'config_Version',
// bundle type listings
'theme' => 'list_Themes',
'plugin' => 'list_Plugins',
'core' => 'list_Core',
'lang' => 'list_Locales',
// bundle level views
'{type}-view' => 'bundle_View',
'{type}-conf' => 'bundle_Conf',
'{type}-setup' => 'bundle_Setup',
'lang-view' => 'bundle_Locale',
// file initialization
'{type}-msginit' => 'init_InitPo',
'{type}-xgettext' => 'init_InitPot',
'{type}-upload' => 'init_Upload',
// file resource views
'{type}-file-view' => 'file_View',
'{type}-file-edit' => 'file_Edit',
'{type}-file-info' => 'file_Info',
'{type}-file-head' => 'file_Head',
'{type}-file-diff' => 'file_Diff',
'{type}-file-move' => 'file_Move',
'{type}-file-delete' => 'file_Delete',
// test routes that don't actually exist
'test-no-class' => 'test_NonExistentClass',
];
if( ! $page ){
$page = $action;
}
else if( $action ){
$page .= '-'. $action;
}
$args['_route'] = $page;
// tokenize path arguments
if( $page && preg_match('/^(plugin|theme|core)-/', $page, $r ) ){
$args['type'] = $r[1];
$page = substr_replace( $page, '{type}', 0, strlen($r[1]) );
}
if( isset($routes[$page]) ){
return 'Loco_admin_'.$routes[$page].'Controller';
}
// debug routing failures:
// throw new Exception( sprintf('Failed to get page class from $page=%s',$page) );
return '';
}
/**
* Main entry point for admin menu callback, establishes page and hands off to controller
* @return void
*/
public function renderPage(){
try {
// show deferred failure from initPage
if( ! $this->ctrl ){
throw new Loco_error_Exception( __('Page not found','loco-translate') );
}
// display loco admin page
echo $this->ctrl->render();
}
catch( Exception $e ){
$ctrl = new Loco_admin_ErrorController;
try {
$ctrl->_init( [] );
}
catch( Exception $_e ){
// avoid errors during error rendering
Loco_error_AdminNotices::debug( $_e->getMessage() );
}
echo $ctrl->renderError($e);
}
// ensure session always shutdown cleanly after render
Loco_data_Session::close();
do_action('loco_admin_shutdown');
}
/**
* Generate a routable link to Loco admin page
*/
public static function generate( string $route, array $args = [] ):string {
$url = null;
$action = '';
// empty action targets plugin root
if( ! $route || 'loco' === $route ){
$page = 'loco';
}
// support direct usage of page hooks
else if( 'loco-' === substr($route,0,5) && menu_page_url($route,false) ){
$page = $route;
}
// else split action into admin page (e.g. "loco-themes") and sub-action (e.g. "view-theme")
else {
$page = 'loco';
$path = explode( '-', $route );
if( $sub = array_shift($path) ){
$page .= '-'.$sub;
if( $path ){
$action = implode('-',$path);
}
}
}
// sanitize extended route in debug mode only
if( loco_debugging() ){
$defaults = [];
$class = self::pageToClass( substr($page,5)?:'', $action, $defaults );
Loco_mvc_AdminController::validateClass( $class, array_diff_key($args,$defaults) );
}
// if url found, it should contain the page
if( $url ){
unset( $args['page'] );
}
// else start with base URL
else {
$url = admin_url('admin.php');
$args['page'] = $page;
}
// add action if found
if( '' !== $action ){
$args['action'] = $action;
}
// else ensure not set in args, as it's reserved
else {
unset( $args['action'] );
}
// append all arguments to base URL
if( $query = http_build_query($args) ){
$sep = false === strpos($url, '?') ? '?' : '&';
$url .= $sep.$query;
}
return $url;
}
}