Server IP : 104.21.14.103 / Your IP : 3.144.21.226 Web Server : LiteSpeed System : Linux business53.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : giankuin ( 1871) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/giankuin/thietke365.net/wp-content/plugins/loco-translate/src/admin/init/ |
Upload File : |
<?php /** * File upload initializer. * Uploads a PO file to the bundle and compiles MO. */ class Loco_admin_init_UploadController extends Loco_admin_bundle_BaseController { /** * {@inheritdoc} **/ public function init() { parent::init(); // Use Ajax controller for standard postback if( $this->checkNonce('upload') ){ try { $ctrl = new Loco_ajax_UploadController; $ctrl->_init($_POST); $href = $ctrl->process( Loco_mvc_PostParams::get() ); if( wp_redirect($href) ){ exit; } } catch( Exception $e ){ Loco_error_AdminNotices::add( Loco_error_Exception::convert($e) ); } } // Set page title before render sets inline title $bundle = $this->getBundle(); $this->set('title', __('Upload','loco-translate').' ‹ '.$bundle->getName() ); } /** * {@inheritdoc} */ public function render(){ // file upload requires a properly configured project $bundle = $this->getBundle(); $project = $this->getProject(); $fields = new Loco_mvc_HiddenFields( [ 'path' => '', 'auth' => 'upload', 'type' => $bundle->getType(), 'domain' => $project->getId(), 'bundle' => $bundle->getHandle(), ] ); $fields->setNonce('upload'); $this->set('hidden',$fields); $this->prepareFsConnect('upload',''); // standard bundle navigation with link back to overview $breadcrumb = $this->prepareNavigation(); $breadcrumb->add( __('Upload a translation file','loco-translate') ); $this->set( 'breadcrumb', $breadcrumb ); // we won't know the locale until the file is uploaded, so use a dummy for location choice $locale = new Loco_Locale('zxx'); $filechoice = $this->getProject()->initLocaleFiles($locale); // $locations = []; /* @var Loco_fs_LocaleFile $pofile */ foreach( $filechoice as $pofile ){ // initialize location type (system, etc..) $parent = new Loco_fs_LocaleDirectory( $pofile->dirname() ); $typeId = $parent->getTypeId(); if( ! isset($locations[$typeId]) ){ $locations[$typeId] = new Loco_mvc_ViewParams( [ 'label' => $parent->getTypeLabel($typeId), 'paths' => [], ] ); } $locations[$typeId]['paths'][] = new Loco_mvc_ViewParams( [ 'parent' => Loco_mvc_FileParams::create($parent), 'holder' => str_replace('zxx.po','{locale}</span>.po', $pofile->basename() ), ] ); } // we don't know what the specifics will be until a location is chosen and a file is presented. $this->set('locale',get_locale()); $this->set('locations', $locations ); // file upload will be done via ajax if possible $settings = Loco_data_Settings::get(); $this->set('js',new Loco_mvc_ViewParams( [ 'multipart' => (bool) $settings->ajax_files, 'nonces' => [ 'upload' => $fields->getNonce() ], ] ) ); $this->enqueueScript('upload'); return $this->view('admin/init/upload'); } }