dvadf
File manager - Edit - /home/theblueo/tv/wp-includes/pomo/lib/file.tar
Back
BaseController.php 0000666 00000010714 15214153354 0010205 0 ustar 00 <?php /** * Base class for a file resource belonging to a bundle * Root > List > Bundle > Resource */ abstract class Loco_admin_file_BaseController extends Loco_admin_bundle_BaseController { /** * Check file is valid or return error * @return string rendered error */ protected function getFileError( Loco_fs_File $file = null ){ // file must exist for editing if( is_null($file) || ! $file->exists() ){ return $this->view( 'admin/errors/file-missing', array() ); } if( $file->isDirectory() ){ $this->set('info', Loco_mvc_FileParams::create($file) ); return $this->view( 'admin/errors/file-isdir', array() ); } /*/ just warn if file isn't writeable if( ! $file->writable() ){ $message = __("This file isn't writeable. Click the 'File info' tab for help setting the right permissions",'loco'); Loco_error_AdminNotices::add( new Loco_error_Warning($message) ); // <- TODO add contextual help link }*/ return ''; } /** * {@inheritdoc} */ public function init(){ parent::init(); // views at this level are always related to a file // file is permitted to be missing during this execution. $path = $this->get('path'); if( ! $path ){ throw new Loco_error_Exception('path argument required'); } $file = new Loco_fs_LocaleFile( $path ); $file->normalize( loco_constant('WP_CONTENT_DIR') ); // POT file has no locale $ext = $file->extension(); if( 'pot' === $ext ){ $locale = null; } // else file may have a locale suffix (unless invalid, such as "default.po") else { $locale = $file->getLocale(); if( $locale->isValid() ){ $locale->fetchName( new Loco_api_WordPressTranslations ) or $locale->buildName(); } else { $locale = null; } } $this->set('file', $file ); $this->set('filetype', strtoupper($ext) ); $this->set('title', $file->basename() ); $this->set('locale', $locale ); // navigate up to root from this bundle sub view $bundle = $this->getBundle(); $breadcrumb = Loco_admin_Navigation::createBreadcrumb( $bundle ); $this->set( 'breadcrumb', $breadcrumb ); // navigate between sub view siblings for this resource $tabs = new Loco_admin_Navigation; $this->set( 'tabs', $tabs ); $actions = array ( 'file-edit' => __('Editor','loco'), 'file-view' => __('Source','loco'), 'file-info' => __('File info','loco'), 'file-delete' => __('Delete','loco'), ); $suffix = $this->get('action'); $prefix = $this->get('type'); foreach( $actions as $action => $name ){ $href = Loco_mvc_AdminRouter::generate( $prefix.'-'.$action, $_GET ); $tabs->add( $name, $href, $action === $suffix ); } // Provide common language creation link if project scope is is valid try { $project = $this->getProject(); $args = array( 'bundle' => $bundle->getHandle(), 'domain' => $project->getId() ); $this->set( 'msginit', new Loco_mvc_ViewParams( array ( 'href' => Loco_mvc_AdminRouter::generate( $prefix.'-msginit', $args ), 'text' => __('New language','loco'), ) ) ); } catch( Exception $e ){ } } /** * {@inheritdoc} */ public function view( $tpl, array $args = array() ){ if( $breadcrumb = $this->get('breadcrumb') ){ // Add project name into breadcrumb if not the same as bundle name try { $project = $this->getProject(); if( $project->getName() !== $this->getBundle()->getName() ){ $breadcrumb->add( $project->getName() ); } } catch( Loco_error_Exception $e ){ // ignore missing project in breadcrumb } // Always add page title as final breadcrumb element $title = $this->get('title') or $title = 'Untitled'; $breadcrumb->add( $title ); } return parent::view( $tpl, $args ); } } DeleteController.php 0000666 00000011751 15214153354 0010537 0 ustar 00 <?php /** * File delete function */ class Loco_admin_file_DeleteController extends Loco_admin_file_BaseController { /** * Expand single path to all files that will be deleted * @return array */ private function expandFiles( Loco_fs_File $file ){ $files = array( $file ); $ext = $file->extension(); // if( 'po' === $ext ){ $sibling = $file->cloneExtension('mo'); if( $sibling->exists() ){ $files[] = $sibling; } } else if( 'mo' === $ext ){ $sibling = $file->cloneExtension('po'); if( $sibling->exists() ){ $files[] = $sibling; } } else if( 'pot' !== $ext ){ throw new Loco_error_Exception( sprintf('Refusing to delete a %s file', strtoupper($ext) ) ); } // add backups of all files (although there should be none for MO files) foreach( array_values($files) as $file ){ $backups = new Loco_fs_Revisions($file); foreach( $backups->getPaths() as $path ){ $files[] = new Loco_fs_File($path); } } return $files; } /** * {@inheritdoc} * public function getHelpTabs(){ return array ( __('Overview','default') => $this->view('tab-file-delete'), ); }*/ /** * {@inheritdoc} */ public function init(){ parent::init(); $file = $this->get('file'); // set up form for delete confirmation if( $file->exists() && ! $file->isDirectory() ){ // nonce action will be specific to file for extra security // TODO could also add file MD5 to avoid deletion after changes made. $path = $file->getPath(); $action = 'delete:'.$path; // set up view now in case of late failure $fields = new Loco_mvc_HiddenFields( array() ); $fields->setNonce( $action ); $this->set( 'hidden', $fields ); // attempt delete if valid nonce posted back if( $this->checkNonce($action) ){ $api = new Loco_api_WordPressFileSystem; // delete dependant files, so that master always exists if any others fail $files = array_reverse( $this->expandFiles($file) ); try { /* @var $trash Loco_fs_File */ foreach( $files as $trash ){ $api->authorizeDelete($trash); $trash->unlink(); } // flash message for display after redirect try { $n = count( $files ); Loco_data_Session::get()->flash('success', sprintf( _n('File deleted','%u files deleted',$n,'loco'),$n) ); Loco_data_Session::close(); } catch( Exception $e ){ // tollerate session failure } // redirect to bundle overview $href = Loco_mvc_AdminRouter::generate( $this->get('type').'-view', array( 'bundle' => $this->get('bundle') ) ); if( wp_redirect($href) ){ exit; } } catch( Loco_error_Exception $e ){ Loco_error_AdminNotices::add( $e ); } } } $bundle = $this->getBundle(); $this->set('title', sprintf( __('Delete %s','loco'), $file->basename() ).' ‹ '.$bundle->getName() ); } /** * {@inheritdoc} */ public function render(){ $file = $this->get('file'); if( $fail = $this->getFileError($file) ){ return $fail; } $files = $this->expandFiles( $file ); $info = Loco_mvc_FileParams::create($file); $this->set( 'info', $info ); $this->set( 'title', sprintf( __('Delete %s','loco'), $info->name ) ); $locked = $file->deletable() ? 0 : 1; // warn about additional files that will be deleted along with this if( $deps = array_slice($files,1) ){ $count = count($deps); $this->set('warn', sprintf( _n( 'One dependant file will also be deleted', '%u dependant files will also be deleted', $count, 'loco' ), $count ) ); $infos = array(); foreach( $deps as $depfile ){ $infos[] = Loco_mvc_FileParams::create( $depfile ); if( is_int($locked) && ! $depfile->deletable() ){ ++$locked; } } $this->set('deps', $infos ); } $this->set( 'locked', $locked ); if( $locked ){ $this->prepareFsConnect( 'delete', $this->get('path') ); } $this->enqueueScript('delete'); return $this->view('admin/file/delete'); } } EditController.php 0000666 00000020023 15214153354 0010212 0 ustar 00 <?php /** * PO editor view */ class Loco_admin_file_EditController extends Loco_admin_file_BaseController { /** * {@inheritdoc} */ public function init(){ parent::init(); $this->enqueueStyle('editor'); // $file = $this->get('file'); $bundle = $this->getBundle(); // translators: %1$s is the file name, %2$s is the bundle name $this->set('title', sprintf( __('Editing %1$s in %2$s','loco'), $file->basename(), $bundle ) ); } /** * {@inheritdoc} */ public function getHelpTabs(){ return array ( __('Overview','default') => $this->view('tab-file-edit'), ); } /** * {@inheritdoc} */ public function render(){ // file must exist for editing $file = $this->get('file'); if( $fail = $this->getFileError($file) ){ return $fail; } // editor will be rendered $this->enqueueScript('editor'); // Parse file data into JavaScript for editor try { $this->set('modified', $file->modified() ); $data = Loco_gettext_Data::load( $file ); } catch( Exception $e ){ Loco_error_AdminNotices::add( Loco_error_Exception::convert($e) ); $data = Loco_gettext_Data::dummy(); } // Pre-populate PO headers with data that JavaScript doesn't have access to if( $locale = $this->get('locale') ){ $data->localize( $locale ); $lname = $locale->getName() or $lname = (string) $locale; $this->set( 'localeName', $lname ); } // default is to permit editing of any file $readonly = false; // Establish if file belongs to a configured project try { $bundle = $this->getBundle(); $project = $this->getProject(); } // Fine if not, this just means sync isn't possible. catch( Loco_error_Exception $e ){ Loco_error_AdminNotices::debug( sprintf("Sync is disabled because this file doesn't relate to a known set of translations", $bundle ) ); $project = null; } // Establish PO/POT edit mode if( $locale ){ // alternative POT file may be forced by PO headers $head = $data->getHeaders(); if( $head->has('X-Loco-Template') ){ $potfile = new Loco_fs_File($head['X-Loco-Template']); $potfile->normalize( $bundle->getDirectoryPath() ); } // no way to get configured POT if invalid project else if( is_null($project) ){ $potfile = null; } // else use project-configured template, assuming there is one else if( $potfile = $project->getPot() ){ // Handle situation where project defines a localised file as the official template if( $potfile->equal($file) ){ $locale = null; $potfile = null; } } if( $potfile ){ // Validate template file as long as it exists if( $potfile->exists() ){ $potdata = Loco_gettext_Data::load( $potfile ); if( ! $potdata->equalSource($data) ){ Loco_error_AdminNotices::debug( sprintf( __("Translations don't match template. Run sync to update from %s",'loco'), $potfile->basename() ) ); } } // else template doesn't exist, so sync will be done to source code else { // Loco_error_AdminNotices::debug( sprintf( __('Template file not found (%s)','loco'), $potfile->basename() ) ); $potfile = null; } } } // notify if template is locked (save and sync will be disabled) if( is_null($locale) && $project && $project->isPotLocked() ){ Loco_error_AdminNotices::warn('Template is protected from updates by the bundle configuration'); $readonly = true; } // back end expects paths relative to wp-content $wp_content = loco_constant('WP_CONTENT_DIR'); $this->set( 'js', new Loco_mvc_ViewParams( array( 'podata' => $data->jsonSerialize(), 'locale' => $locale ? $locale->jsonSerialize() : null, 'potpath' => $locale && $potfile ? $potfile->getRelativePath($wp_content) : null, 'popath' => $this->get('path'), 'readonly' => $readonly, 'project' => $project ? array ( 'bundle' => $bundle->getId(), 'domain' => $project->getId(), ) : null, 'nonces' => $readonly ? null : array ( 'save' => wp_create_nonce('save'), 'sync' => wp_create_nonce('sync'), 'fsConnect' => wp_create_nonce('fsConnect'), ), ) ) ); $this->set( 'ui', new Loco_mvc_ViewParams( array( // Translators: button for adding a new string when manually editing a POT file 'add' => _x('Add','Editor','loco'), // Translators: button for removing a string when manually editing a POT file 'del' => _x('Remove','Editor','loco'), 'help' => __('Help','loco'), // Translators: Button that saves translations to disk 'save' => _x('Save','Editor','loco'), // Translators: Button that runs in-editor sync/operation 'sync' => _x('Sync','Editor','loco'), // Translators: Button that reloads current screen 'revert' => _x('Revert','Editor','loco'), // Translators: Button that toggles a translation's Fuzzy flag 'fuzzy' => _x('Fuzzy','Editor','loco'), // Translators: Button for downloading a PO, MO or POT file 'download' => _x('Download','Editor','loco'), // Translators: Placeholder text for text filter above editor 'filter' => __('Filter translations','loco'), // Translators: Button that toggles invisible characters 'invs' => _x('Toggle invisibles','Editor','loco'), // Translators: Button that toggles between "code" and regular text editing modes 'code' => _x('Toggle code view','Editor','loco'), ) ) ); // Download form params $hidden = new Loco_mvc_HiddenFields( array( 'path' => '', 'source' => '', 'route' => 'download', 'action' => 'loco_download', ) ); $this->set( 'dlFields', $hidden->setNonce('download') ); $this->set( 'dlAction', admin_url('admin-ajax.php','relative') ); // validate file system writableness for all operations involved in save $writable = $file->writable(); // Check in advance if MO file can be compiled in this directory if( $writable ){ $dummy = $file->cloneExtension('mo'); if( ! ( $dummy->exists() ? $dummy->writable() : $dummy->creatable() ) ){ $writable = false; } // Check in advance if backups will work in this directory else if( Loco_data_Settings::get()->num_backups ){ $dummy = new Loco_fs_File( $file->dirname().'/does-not-exist.po~' ); if( ! $dummy->creatable() ){ $writable = false; } } } // File system connect if any operations likely to fail if( ! $writable ){ $this->prepareFsConnect( 'connect', $this->get('path') ); } // set simpler title for breadcrumb $this->set('title', $file->basename() ); // ok to render editor as either po or pot $tpl = $locale ? 'po' : 'pot'; return $this->view( 'admin/file/edit-'.$tpl, array() ); } } ViewController.php 0000666 00000005622 15214153354 0010247 0 ustar 00 <?php /** * File view / source formatted view. */ class Loco_admin_file_ViewController extends Loco_admin_file_BaseController { /** * {@inheritdoc} */ public function init(){ parent::init(); $this->enqueueStyle('poview'); // $file = $this->get('file'); $bundle = $this->getBundle(); $this->set( 'title', 'Source of '.$file->basename().' ‹ '.$bundle->getName() ); } /** * {@inheritdoc} */ public function getHelpTabs(){ return array ( __('Overview','default') => $this->view('tab-file-view'), ); } /** * {@inheritdoc} */ public function render(){ // file must exist for editing $file = $this->get('file'); $name = $file->basename(); $type = strtolower( $file->extension() ); $this->set('title', $name ); if( $fail = $this->getFileError($file) ){ return $fail; } // Establish if file belongs to a configured project try { $bundle = $this->getBundle(); $project = $this->getProject(); } catch( Exception $e ){ $project = null; } // Parse data before rendering, so we know it's a valid Gettext format try { $this->set('modified', $file->modified() ); $data = Loco_gettext_Data::load( $file ); $this->set( 'meta', Loco_gettext_Metadata::create($file, $data) ); } catch( Exception $e ){ Loco_error_AdminNotices::add( Loco_error_Exception::convert($e) ); } // binary MO will be hex-formated in template if( 'mo' === $type ){ $this->set('bin', $file->getContents() ); return $this->view('admin/file/view-mo' ); } // else is a PO or POT file $this->enqueueScript('poview');//->enqueueScript('min/highlight'); $lines = preg_split('/\\R/u', loco_ensure_utf8( $file->getContents() ) ); $this->set( 'lines', $lines ); // ajax parameters required for pulling reference sources $this->set('js', new Loco_mvc_ViewParams( array ( 'popath' => $this->get('path'), 'nonces' => array( 'fsReference' => wp_create_nonce('fsReference'), ), 'project' => $bundle ? array ( 'bundle' => $bundle->getId(), 'domain' => $project ? $project->getId() : '', ) : null, ) ) ); // treat as PO if file name has locale if( $locale = $this->get('locale') ){ $lname = $locale->getName() or $lname = (string) $locale; $this->set( 'localeName', $lname ); return $this->view('admin/file/view-po' ); } // else view as POT return $this->view('admin/file/view-pot' ); } } InfoController.php 0000666 00000015457 15214153354 0010237 0 ustar 00 <?php /** * File info / management view. */ class Loco_admin_file_InfoController extends Loco_admin_file_BaseController { /** * {@inheritdoc} */ public function init(){ parent::init(); $this->enqueueStyle('fileinfo'); // $file = $this->get('file'); $bundle = $this->getBundle(); $this->set('title', $file->basename().' ‹ '.$bundle->getName() ); } /** * {@inheritdoc} */ public function getHelpTabs(){ return array ( __('Overview','default') => $this->view('tab-file-info'), ); } /** * {@inheritdoc} */ public function render(){ $file = $this->get('file'); $name = $file->basename(); $this->set('title', $name ); if( $fail = $this->getFileError($file) ){ return $fail; } $ext = strtolower( $file->extension() ); $path = $file->getPath(); // file info $info = Loco_mvc_FileParams::create( $file ); $this->set('file', $info ); $info['type'] = strtoupper($ext); if( $file->exists() ){ $info['existant'] = true; $info['writable'] = $file->writable(); $info['deletable'] = $file->deletable(); $info['mtime'] = $file->modified(); } // location info $dir = new Loco_fs_LocaleDirectory( $file->dirname() ); $info = Loco_mvc_FileParams::create( $dir ); $this->set('dir', $info ); $info['type'] = $dir->getTypeId(); if( $dir->exists() && $dir->isDirectory() ){ $info['existant'] = true; $info['writable'] = $dir->writable(); } // get the name of the webserver for information purposes $this->set('httpd', Loco_compat_PosixExtension::getHttpdUser() ); // unknown file template if required $locale = null; $tpl = 'admin/file/info-other'; // we should know the project the file belongs to, but permitting orphans for debugging try { $project = $this->getProject(); $template = $project->getPot(); $isTemplate = $template && $file->equal($template); $this->set('isTemplate', $isTemplate ); } catch( Loco_error_Exception $e ){ $isTemplate = false; $template = null; } // file will be Gettext most likely if( 'pot' === $ext || 'po' === $ext || 'mo' === $ext ){ // treat as templte until locale verified $tpl = 'admin/file/info-pot'; // don't attempt to pull locale of template file if( 'pot' !== $ext && ! $isTemplate ){ $locale = $file->getLocale(); $code = (string) $locale; if( $locale->isValid() ){ $api = new Loco_api_WordPressTranslations; $locale->fetchName( $api ); $this->set( 'locale', new Loco_mvc_ViewParams( array( 'code' => $code, 'name' => $locale->getName(), 'icon' => $locale->getIcon(), 'lang' => $locale->lang, ) ) ); // find PO/MO counter parts if( 'po' === $ext ){ $tpl = 'admin/file/info-po'; $sibling = $file->cloneExtension('mo'); } else { $tpl = 'admin/file/info-mo'; $sibling = $file->cloneExtension('po'); } $info = Loco_mvc_FileParams::create($sibling); $this->set( 'sibling', $info ); if( $sibling->exists() ){ $info['existant'] = true; $info['writable'] = $sibling->writable(); } } } // Do full parse to get stats and headers try { $data = Loco_gettext_Data::load($file); $head = $data->getHeaders(); $author = $head->trimmed('Last-Translator') or $author = __('Unknown author','loco'); $this->set( 'author', $author ); // date headers may not be same as file modification time (files copied to server etc..) $podate = $head->trimmed( $locale ? 'PO-Revision-Date' : 'POT-Creation-Date' ); $potime = Loco_gettext_Data::parseDate($podate) or $potime = $file->modified(); $this->set('potime', $potime ); // access to meta stats, normally cached on listing pages $meta = Loco_gettext_Metadata::create($file,$data); $this->set( 'meta', $meta ); // allow PO header to specify alternative template for sync if( $head->has('X-Loco-Template') ){ $altpot = new Loco_fs_File($head['X-Loco-Template']); $altpot->normalize( $this->getBundle()->getDirectoryPath() ); if( $altpot->exists() && ( ! $template || ! $template->equal($altpot) ) ){ $this->set('altpot', true ); $template = $altpot; } } // missing or invalid headers are tollerated but developers should be notified if( ! count($head) ){ Loco_error_AdminNotices::debug(__('File does not have a valid header','loco')); } // establish whether PO is in sync with POT if( $template && ! $isTemplate && 'po' === $ext && $template->exists() ){ try { $this->set('potfile', new Loco_mvc_FileParams( array( 'synced' => Loco_gettext_Data::load($template)->equalSource($data), ), $template ) ); } catch( Exception $e ){ // ignore invalid template in this context } } // language sanity check. Developer warning if file name disagrees with PO header if( $locale && ( $value = $head['Language'] ) ){ $check = (string) Loco_Locale::parse($value); if( $check !== $code ){ Loco_error_AdminNotices::debug( sprintf( __('Language header is "%s" but file name contains "%s"','loco'), $value, $code ) ); } } } catch( Exception $e ){ $this->set('error', $e->getMessage() ); $tpl = 'admin/file/info-other'; } } return $this->view( $tpl ); } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.0.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings