Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/loco-translate/lib/data/locales.php
+++ b/loco-translate/lib/data/locales.php
@@ -2,4 +2,4 @@
/**
* Compiled data. Do not edit.
*/
-return ['af'=>[0=>'Afrikaans',1=>'Afrikaans'],'am'=>[0=>'Amharic',1=>'አማርኛ'],'arg'=>[0=>'Aragonese',1=>'Aragonés'],'ar'=>[0=>'Arabic',1=>'العربية'],'ary'=>[0=>'Moroccan Arabic',1=>'العربية المغربية'],'as'=>[0=>'Assamese',1=>'অসমীয়া'],'azb'=>[0=>'South Azerbaijani',1=>'گؤنئی آذربایجان'],'az'=>[0=>'Azerbaijani',1=>'Azərbaycan dili'],'bel'=>[0=>'Belarusian',1=>'Беларуская мова'],'bg_BG'=>[0=>'Bulgarian',1=>'Български'],'bn_BD'=>[0=>'Bengali (Bangladesh)',1=>'বাংলা'],'bo'=>[0=>'Tibetan',1=>'བོད་ཡིག'],'bs_BA'=>[0=>'Bosnian',1=>'Bosanski'],'ca'=>[0=>'Catalan',1=>'Català'],'ceb'=>[0=>'Cebuano',1=>'Cebuano'],'cs_CZ'=>[0=>'Czech',1=>'Čeština'],'cy'=>[0=>'Welsh',1=>'Cymraeg'],'da_DK'=>[0=>'Danish',1=>'Dansk'],'de_AT'=>[0=>'German (Austria)',1=>'Deutsch (Österreich)'],'de_CH'=>[0=>'German (Switzerland)',1=>'Deutsch (Schweiz)'],'de_DE'=>[0=>'German',1=>'Deutsch'],'de_DE_formal'=>[0=>'German (Formal)',1=>'Deutsch (Sie)'],'de_CH_informal'=>[0=>'German (Switzerland, Informal)',1=>'Deutsch (Schweiz, Du)'],'dsb'=>[0=>'Lower Sorbian',1=>'Dolnoserbšćina'],'dzo'=>[0=>'Dzongkha',1=>'རྫོང་ཁ'],'el'=>[0=>'Greek',1=>'Ελληνικά'],'en_NZ'=>[0=>'English (New Zealand)',1=>'English (New Zealand)'],'en_CA'=>[0=>'English (Canada)',1=>'English (Canada)'],'en_GB'=>[0=>'English (UK)',1=>'English (UK)'],'en_AU'=>[0=>'English (Australia)',1=>'English (Australia)'],'en_ZA'=>[0=>'English (South Africa)',1=>'English (South Africa)'],'eo'=>[0=>'Esperanto',1=>'Esperanto'],'es_CL'=>[0=>'Spanish (Chile)',1=>'Español de Chile'],'es_MX'=>[0=>'Spanish (Mexico)',1=>'Español de México'],'es_CO'=>[0=>'Spanish (Colombia)',1=>'Español de Colombia'],'es_CR'=>[0=>'Spanish (Costa Rica)',1=>'Español de Costa Rica'],'es_PE'=>[0=>'Spanish (Peru)',1=>'Español de Perú'],'es_VE'=>[0=>'Spanish (Venezuela)',1=>'Español de Venezuela'],'es_EC'=>[0=>'Spanish (Ecuador)',1=>'Español de Ecuador'],'es_DO'=>[0=>'Spanish (Dominican Republic)',1=>'Español de República Dominicana'],'es_UY'=>[0=>'Spanish (Uruguay)',1=>'Español de Uruguay'],'es_PR'=>[0=>'Spanish (Puerto Rico)',1=>'Español de Puerto Rico'],'es_GT'=>[0=>'Spanish (Guatemala)',1=>'Español de Guatemala'],'es_ES'=>[0=>'Spanish (Spain)',1=>'Español'],'es_AR'=>[0=>'Spanish (Argentina)',1=>'Español de Argentina'],'et'=>[0=>'Estonian',1=>'Eesti'],'eu'=>[0=>'Basque',1=>'Euskara'],'fa_IR'=>[0=>'Persian',1=>'فارسی'],'fa_AF'=>[0=>'Persian (Afghanistan)',1=>'(فارسی (افغانستان'],'fi'=>[0=>'Finnish',1=>'Suomi'],'fr_CA'=>[0=>'French (Canada)',1=>'Français du Canada'],'fr_FR'=>[0=>'French (France)',1=>'Français'],'fr_BE'=>[0=>'French (Belgium)',1=>'Français de Belgique'],'fur'=>[0=>'Friulian',1=>'Friulian'],'fy'=>[0=>'Frisian',1=>'Frysk'],'gd'=>[0=>'Scottish Gaelic',1=>'Gàidhlig'],'gl_ES'=>[0=>'Galician',1=>'Galego'],'gu'=>[0=>'Gujarati',1=>'ગુજરાતી'],'haz'=>[0=>'Hazaragi',1=>'هزاره گی'],'he_IL'=>[0=>'Hebrew',1=>'עִבְרִית'],'hi_IN'=>[0=>'Hindi',1=>'हिन्दी'],'hr'=>[0=>'Croatian',1=>'Hrvatski'],'hsb'=>[0=>'Upper Sorbian',1=>'Hornjoserbšćina'],'hu_HU'=>[0=>'Hungarian',1=>'Magyar'],'hy'=>[0=>'Armenian',1=>'Հայերեն'],'id_ID'=>[0=>'Indonesian',1=>'Bahasa Indonesia'],'is_IS'=>[0=>'Icelandic',1=>'Íslenska'],'it_IT'=>[0=>'Italian',1=>'Italiano'],'ja'=>[0=>'Japanese',1=>'日本語'],'jv_ID'=>[0=>'Javanese',1=>'Basa Jawa'],'ka_GE'=>[0=>'Georgian',1=>'ქართული'],'kab'=>[0=>'Kabyle',1=>'Taqbaylit'],'kk'=>[0=>'Kazakh',1=>'Қазақ тілі'],'km'=>[0=>'Khmer',1=>'ភាសាខ្មែរ'],'kn'=>[0=>'Kannada',1=>'ಕನ್ನಡ'],'ko_KR'=>[0=>'Korean',1=>'한국어'],'ckb'=>[0=>'Kurdish (Sorani)',1=>'كوردی'],'kir'=>[0=>'Kyrgyz',1=>'Кыргызча'],'lo'=>[0=>'Lao',1=>'ພາສາລາວ'],'lt_LT'=>[0=>'Lithuanian',1=>'Lietuvių kalba'],'lv'=>[0=>'Latvian',1=>'Latviešu valoda'],'mk_MK'=>[0=>'Macedonian',1=>'Македонски јазик'],'ml_IN'=>[0=>'Malayalam',1=>'മലയാളം'],'mn'=>[0=>'Mongolian',1=>'Монгол'],'mr'=>[0=>'Marathi',1=>'मराठी'],'ms_MY'=>[0=>'Malay',1=>'Bahasa Melayu'],'my_MM'=>[0=>'Myanmar (Burmese)',1=>'ဗမာစာ'],'nb_NO'=>[0=>'Norwegian (Bokmål)',1=>'Norsk bokmål'],'ne_NP'=>[0=>'Nepali',1=>'नेपाली'],'nl_NL'=>[0=>'Dutch',1=>'Nederlands'],'nl_BE'=>[0=>'Dutch (Belgium)',1=>'Nederlands (België)'],'nl_NL_formal'=>[0=>'Dutch (Formal)',1=>'Nederlands (Formeel)'],'nn_NO'=>[0=>'Norwegian (Nynorsk)',1=>'Norsk nynorsk'],'oci'=>[0=>'Occitan',1=>'Occitan'],'pa_IN'=>[0=>'Panjabi (India)',1=>'ਪੰਜਾਬੀ'],'pl_PL'=>[0=>'Polish',1=>'Polski'],'ps'=>[0=>'Pashto',1=>'پښتو'],'pt_PT_ao90'=>[0=>'Portuguese (Portugal, AO90)',1=>'Português (AO90)'],'pt_PT'=>[0=>'Portuguese (Portugal)',1=>'Português'],'pt_AO'=>[0=>'Portuguese (Angola)',1=>'Português de Angola'],'pt_BR'=>[0=>'Portuguese (Brazil)',1=>'Português do Brasil'],'rhg'=>[0=>'Rohingya',1=>'Ruáinga'],'ro_RO'=>[0=>'Romanian',1=>'Română'],'ru_RU'=>[0=>'Russian',1=>'Русский'],'sah'=>[0=>'Sakha',1=>'Сахалыы'],'snd'=>[0=>'Sindhi',1=>'سنڌي'],'si_LK'=>[0=>'Sinhala',1=>'සිංහල'],'sk_SK'=>[0=>'Slovak',1=>'Slovenčina'],'skr'=>[0=>'Saraiki',1=>'سرائیکی'],'sl_SI'=>[0=>'Slovenian',1=>'Slovenščina'],'sq'=>[0=>'Albanian',1=>'Shqip'],'sr_RS'=>[0=>'Serbian',1=>'Српски језик'],'sv_SE'=>[0=>'Swedish',1=>'Svenska'],'sw'=>[0=>'Swahili',1=>'Kiswahili'],'szl'=>[0=>'Silesian',1=>'Ślōnskŏ gŏdka'],'ta_IN'=>[0=>'Tamil',1=>'தமிழ்'],'ta_LK'=>[0=>'Tamil (Sri Lanka)',1=>'தமிழ்'],'te'=>[0=>'Telugu',1=>'తెలుగు'],'th'=>[0=>'Thai',1=>'ไทย'],'tl'=>[0=>'Tagalog',1=>'Tagalog'],'tr_TR'=>[0=>'Turkish',1=>'Türkçe'],'tt_RU'=>[0=>'Tatar',1=>'Татар теле'],'tah'=>[0=>'Tahitian',1=>'Reo Tahiti'],'ug_CN'=>[0=>'Uighur',1=>'ئۇيغۇرچە'],'uk'=>[0=>'Ukrainian',1=>'Українська'],'ur'=>[0=>'Urdu',1=>'اردو'],'uz_UZ'=>[0=>'Uzbek',1=>'O‘zbekcha'],'vi'=>[0=>'Vietnamese',1=>'Tiếng Việt'],'yor'=>[0=>'Yoruba',1=>'Yorùbá'],'zh_TW'=>[0=>'Chinese (Taiwan)',1=>'繁體中文'],'zh_CN'=>[0=>'Chinese (China)',1=>'简体中文'],'zh_HK'=>[0=>'Chinese (Hong Kong)',1=>'香港中文']];
No newline at end of file
+return ['af'=>[0=>'Afrikaans',1=>'Afrikaans'],'am'=>[0=>'Amharic',1=>'አማርኛ'],'arg'=>[0=>'Aragonese',1=>'Aragonés'],'ar'=>[0=>'Arabic',1=>'العربية'],'ary'=>[0=>'Moroccan Arabic',1=>'العربية المغربية'],'as'=>[0=>'Assamese',1=>'অসমীয়া'],'azb'=>[0=>'South Azerbaijani',1=>'گؤنئی آذربایجان'],'az'=>[0=>'Azerbaijani',1=>'Azərbaycan dili'],'bel'=>[0=>'Belarusian',1=>'Беларуская мова'],'bg_BG'=>[0=>'Bulgarian',1=>'Български'],'bn_BD'=>[0=>'Bengali (Bangladesh)',1=>'বাংলা'],'bo'=>[0=>'Tibetan',1=>'བོད་ཡིག'],'bs_BA'=>[0=>'Bosnian',1=>'Bosanski'],'ca'=>[0=>'Catalan',1=>'Català'],'ceb'=>[0=>'Cebuano',1=>'Cebuano'],'cs_CZ'=>[0=>'Czech',1=>'Čeština'],'cy'=>[0=>'Welsh',1=>'Cymraeg'],'da_DK'=>[0=>'Danish',1=>'Dansk'],'de_AT'=>[0=>'German (Austria)',1=>'Deutsch (Österreich)'],'de_DE'=>[0=>'German',1=>'Deutsch'],'de_DE_formal'=>[0=>'German (Formal)',1=>'Deutsch (Sie)'],'de_CH'=>[0=>'German (Switzerland)',1=>'Deutsch (Schweiz)'],'de_CH_informal'=>[0=>'German (Switzerland, Informal)',1=>'Deutsch (Schweiz, Du)'],'dsb'=>[0=>'Lower Sorbian',1=>'Dolnoserbšćina'],'dzo'=>[0=>'Dzongkha',1=>'རྫོང་ཁ'],'el'=>[0=>'Greek',1=>'Ελληνικά'],'en_NZ'=>[0=>'English (New Zealand)',1=>'English (New Zealand)'],'en_GB'=>[0=>'English (UK)',1=>'English (UK)'],'en_ZA'=>[0=>'English (South Africa)',1=>'English (South Africa)'],'en_AU'=>[0=>'English (Australia)',1=>'English (Australia)'],'en_CA'=>[0=>'English (Canada)',1=>'English (Canada)'],'eo'=>[0=>'Esperanto',1=>'Esperanto'],'es_MX'=>[0=>'Spanish (Mexico)',1=>'Español de México'],'es_ES'=>[0=>'Spanish (Spain)',1=>'Español'],'es_CR'=>[0=>'Spanish (Costa Rica)',1=>'Español de Costa Rica'],'es_AR'=>[0=>'Spanish (Argentina)',1=>'Español de Argentina'],'es_CO'=>[0=>'Spanish (Colombia)',1=>'Español de Colombia'],'es_PE'=>[0=>'Spanish (Peru)',1=>'Español de Perú'],'es_VE'=>[0=>'Spanish (Venezuela)',1=>'Español de Venezuela'],'es_EC'=>[0=>'Spanish (Ecuador)',1=>'Español de Ecuador'],'es_DO'=>[0=>'Spanish (Dominican Republic)',1=>'Español de República Dominicana'],'es_UY'=>[0=>'Spanish (Uruguay)',1=>'Español de Uruguay'],'es_PR'=>[0=>'Spanish (Puerto Rico)',1=>'Español de Puerto Rico'],'es_GT'=>[0=>'Spanish (Guatemala)',1=>'Español de Guatemala'],'es_CL'=>[0=>'Spanish (Chile)',1=>'Español de Chile'],'et'=>[0=>'Estonian',1=>'Eesti'],'eu'=>[0=>'Basque',1=>'Euskara'],'fa_IR'=>[0=>'Persian',1=>'فارسی'],'fa_AF'=>[0=>'Persian (Afghanistan)',1=>'(فارسی (افغانستان'],'fi'=>[0=>'Finnish',1=>'Suomi'],'fr_FR'=>[0=>'French (France)',1=>'Français'],'fr_CA'=>[0=>'French (Canada)',1=>'Français du Canada'],'fr_BE'=>[0=>'French (Belgium)',1=>'Français de Belgique'],'fur'=>[0=>'Friulian',1=>'Friulian'],'fy'=>[0=>'Frisian',1=>'Frysk'],'gd'=>[0=>'Scottish Gaelic',1=>'Gàidhlig'],'gl_ES'=>[0=>'Galician',1=>'Galego'],'gu'=>[0=>'Gujarati',1=>'ગુજરાતી'],'haz'=>[0=>'Hazaragi',1=>'هزاره گی'],'he_IL'=>[0=>'Hebrew',1=>'עִבְרִית'],'hi_IN'=>[0=>'Hindi',1=>'हिन्दी'],'hr'=>[0=>'Croatian',1=>'Hrvatski'],'hsb'=>[0=>'Upper Sorbian',1=>'Hornjoserbšćina'],'hu_HU'=>[0=>'Hungarian',1=>'Magyar'],'hy'=>[0=>'Armenian',1=>'Հայերեն'],'id_ID'=>[0=>'Indonesian',1=>'Bahasa Indonesia'],'is_IS'=>[0=>'Icelandic',1=>'Íslenska'],'it_IT'=>[0=>'Italian',1=>'Italiano'],'ja'=>[0=>'Japanese',1=>'日本語'],'jv_ID'=>[0=>'Javanese',1=>'Basa Jawa'],'ka_GE'=>[0=>'Georgian',1=>'ქართული'],'kab'=>[0=>'Kabyle',1=>'Taqbaylit'],'kk'=>[0=>'Kazakh',1=>'Қазақ тілі'],'km'=>[0=>'Khmer',1=>'ភាសាខ្មែរ'],'kn'=>[0=>'Kannada',1=>'ಕನ್ನಡ'],'ko_KR'=>[0=>'Korean',1=>'한국어'],'ckb'=>[0=>'Kurdish (Sorani)',1=>'كوردی'],'kir'=>[0=>'Kyrgyz',1=>'Кыргызча'],'lo'=>[0=>'Lao',1=>'ພາສາລາວ'],'lt_LT'=>[0=>'Lithuanian',1=>'Lietuvių kalba'],'lv'=>[0=>'Latvian',1=>'Latviešu valoda'],'mk_MK'=>[0=>'Macedonian',1=>'Македонски јазик'],'ml_IN'=>[0=>'Malayalam',1=>'മലയാളം'],'mn'=>[0=>'Mongolian',1=>'Монгол'],'mr'=>[0=>'Marathi',1=>'मराठी'],'ms_MY'=>[0=>'Malay',1=>'Bahasa Melayu'],'my_MM'=>[0=>'Myanmar (Burmese)',1=>'ဗမာစာ'],'nb_NO'=>[0=>'Norwegian (Bokmål)',1=>'Norsk bokmål'],'ne_NP'=>[0=>'Nepali',1=>'नेपाली'],'nl_NL'=>[0=>'Dutch',1=>'Nederlands'],'nl_BE'=>[0=>'Dutch (Belgium)',1=>'Nederlands (België)'],'nl_NL_formal'=>[0=>'Dutch (Formal)',1=>'Nederlands (Formeel)'],'nn_NO'=>[0=>'Norwegian (Nynorsk)',1=>'Norsk nynorsk'],'oci'=>[0=>'Occitan',1=>'Occitan'],'pa_IN'=>[0=>'Panjabi (India)',1=>'ਪੰਜਾਬੀ'],'pl_PL'=>[0=>'Polish',1=>'Polski'],'ps'=>[0=>'Pashto',1=>'پښتو'],'pt_PT'=>[0=>'Portuguese (Portugal)',1=>'Português'],'pt_AO'=>[0=>'Portuguese (Angola)',1=>'Português de Angola'],'pt_PT_ao90'=>[0=>'Portuguese (Portugal, AO90)',1=>'Português (AO90)'],'pt_BR'=>[0=>'Portuguese (Brazil)',1=>'Português do Brasil'],'rhg'=>[0=>'Rohingya',1=>'Ruáinga'],'ro_RO'=>[0=>'Romanian',1=>'Română'],'ru_RU'=>[0=>'Russian',1=>'Русский'],'sah'=>[0=>'Sakha',1=>'Сахалыы'],'snd'=>[0=>'Sindhi',1=>'سنڌي'],'si_LK'=>[0=>'Sinhala',1=>'සිංහල'],'sk_SK'=>[0=>'Slovak',1=>'Slovenčina'],'skr'=>[0=>'Saraiki',1=>'سرائیکی'],'sl_SI'=>[0=>'Slovenian',1=>'Slovenščina'],'sq'=>[0=>'Albanian',1=>'Shqip'],'sr_RS'=>[0=>'Serbian',1=>'Српски језик'],'sv_SE'=>[0=>'Swedish',1=>'Svenska'],'sw'=>[0=>'Swahili',1=>'Kiswahili'],'szl'=>[0=>'Silesian',1=>'Ślōnskŏ gŏdka'],'ta_IN'=>[0=>'Tamil',1=>'தமிழ்'],'ta_LK'=>[0=>'Tamil (Sri Lanka)',1=>'தமிழ்'],'te'=>[0=>'Telugu',1=>'తెలుగు'],'th'=>[0=>'Thai',1=>'ไทย'],'tl'=>[0=>'Tagalog',1=>'Tagalog'],'tr_TR'=>[0=>'Turkish',1=>'Türkçe'],'tt_RU'=>[0=>'Tatar',1=>'Татар теле'],'tah'=>[0=>'Tahitian',1=>'Reo Tahiti'],'ug_CN'=>[0=>'Uighur',1=>'ئۇيغۇرچە'],'uk'=>[0=>'Ukrainian',1=>'Українська'],'ur'=>[0=>'Urdu',1=>'اردو'],'uz_UZ'=>[0=>'Uzbek',1=>'O‘zbekcha'],'vi'=>[0=>'Vietnamese',1=>'Tiếng Việt'],'yor'=>[0=>'Yoruba',1=>'Yorùbá'],'zh_TW'=>[0=>'Chinese (Taiwan)',1=>'繁體中文'],'zh_CN'=>[0=>'Chinese (China)',1=>'简体中文'],'zh_HK'=>[0=>'Chinese (Hong Kong)',1=>'香港中文']];
No newline at end of file
--- a/loco-translate/loco.php
+++ b/loco-translate/loco.php
@@ -4,10 +4,10 @@
Plugin URI: https://wordpress.org/plugins/loco-translate/
Description: Translate themes and plugins directly in WordPress
Author: Tim Whitlock
-Version: 2.8.4
+Version: 2.8.5
Requires at least: 6.6
Requires PHP: 7.4
-Tested up to: 6.9.4
+Tested up to: 7.0
Author URI: https://localise.biz/wordpress/plugin
Text Domain: loco-translate
Domain Path: /languages/
@@ -31,7 +31,7 @@
* Get version of this plugin
*/
function loco_plugin_version(): string {
- return '2.8.4';
+ return '2.8.5';
}
--- a/loco-translate/src/admin/file/InfoController.php
+++ b/loco-translate/src/admin/file/InfoController.php
@@ -47,10 +47,16 @@
$finfo['type'] = strtoupper($ext);
if( $file->exists() ){
$finfo['existent'] = true;
- $finfo['writable'] = $file->writable();
- $finfo['deletable'] = $file->deletable();
$finfo['mtime'] = $file->modified();
- // Notify if file is managed by WordPress
+ try {
+ $file->getWriteContext()->authorize();
+ $finfo['writable'] = $file->writable();
+ $finfo['deletable'] = $file->deletable();
+ }
+ catch( Loco_error_WriteException $e ){
+ $finfo['denied'] = $e->getMessage();
+ }
+ // Notify if the file is managed by WordPress
$api = new Loco_api_WordPressFileSystem;
if( $api->isAutoUpdatable($file) ){
$finfo['autoupdate'] = true;
@@ -64,7 +70,13 @@
$dinfo['type'] = $dir->getTypeId();
if( $dir->exists() && $dir->isDirectory() ){
$dinfo['existent'] = true;
- $dinfo['writable'] = $dir->writable();
+ try {
+ $dir->getWriteContext()->authorize();
+ $dinfo['writable'] = $dir->writable();
+ }
+ catch( Loco_error_WriteException $e ){
+ $dinfo['denied'] = $e->getMessage();
+ }
}
// secure download link
--- a/loco-translate/src/ajax/XgettextController.php
+++ b/loco-translate/src/ajax/XgettextController.php
@@ -22,13 +22,15 @@
throw new Loco_error_Exception('Target is not a directory');
}
- // basename should be posted from front end
+ // basename should be posted from front end. Validate and prevent tampering.
$name = $this->get('name');
- if( ! $name ){
+ if( ! is_string($name) || '' === $name ){
throw new Loco_error_Exception('Front end did not post $name');
}
-
- // POT file should be .pot but we'll allow .po
+ if( basename($name) !== $name ){
+ throw new Loco_error_Exception('Illegal file name');
+ }
+ // POT file should normally be .pot, but we'll allow .po
$potfile = new Loco_fs_File( $target.'/'.$name );
$ext = strtolower( $potfile->fullExtension() );
if( 'pot' !== $ext && 'po' !== $ext ){
@@ -59,7 +61,6 @@
}
// push recent items on file creation
- // TODO push project and locale file
Loco_data_RecentItems::get()->pushBundle( $bundle )->persist();
// put flash message into session to be displayed on redirected page
--- a/loco-translate/src/data/Settings.php
+++ b/loco-translate/src/data/Settings.php
@@ -12,6 +12,7 @@
* @property array $jsx_alias Registered extensions for scanning JavaScript/JSX files (disabled by default)
* @property bool $fs_persist Whether to remember file system credentials in session
* @property int $fs_protect Prevent modification of files in system folders (0:off, 1:warn, 2:block)
+ * @property string $fs_basedir Line break separated list of directory paths (relative to ABSPATH) where *writes* are permitted
* @property int $pot_protect Prevent modification of POT files (0:off, 1:warn, 2:block)
* @property int $pot_expected Whether to allow missing templates and sync to source (0:off, 1:warn, 2:block)
* @property string $max_php_size Skip PHP source files this size or larger
@@ -55,6 +56,7 @@
'jsx_alias' => [],
'fs_persist' => false,
'fs_protect' => 1,
+ 'fs_basedir' => 'wp-content',
'pot_protect' => 1,
'pot_expected' => 1,
'max_php_size' => '100K',
@@ -191,9 +193,8 @@
* Populate ALL settings from raw postdata.
* @param array $data Posted setting values
* @param array|null $filter Optional filter to restrict modifiable values
- * @return Loco_data_Settings
*/
- public function populate( array $data, $filter = null ){
+ public function populate( array $data, ?array $filter = null ):self{
// set all keys present in posted data
foreach( $data as $prop => $value ){
try {
--- a/loco-translate/src/fs/DummyFile.php
+++ b/loco-translate/src/fs/DummyFile.php
@@ -1,37 +1,23 @@
+76
<?php
/**
* Dummy file that just holds content in memory.
- * Use when you don't want to commit data to disk but you need to pass a typed file object
+ * Use when you don't want to commit data to disk, but you need to pass a typed file object
*/
class Loco_fs_DummyFile extends Loco_fs_File {
- /**
- * @var string
- */
- private $contents = '';
+ private string $contents = '';
- /**
- * @var int
- */
- private $mtime = 0;
+ private int $mtime;
- /**
- * @var int
- */
- private $fmode = 0644;
+ private int $fmode = 0644;
- /**
- * @var int
- */
- private $uid = 0;
+ private int $uid = 0;
- /**
- * @var int
- */
- private $gid = 0;
+ private int $gid = 0;
- public function __construct($path){
+ public function __construct( string $path ){
parent::__construct($path);
$this->mtime = time();
}
@@ -56,7 +42,7 @@
/**
* {@inheritdoc}
*/
- public function size(){
+ public function size():int {
return strlen($this->contents);
}
@@ -73,16 +59,15 @@
/**
* {@inheritdoc}
*/
- public function modified(){
+ public function modified():int {
return $this->mtime;
}
/**
* Allow forcing of modified stamp for testing purposes
- * @return Loco_fs_File
*/
- public function touch( $modified ){
+ public function touch( $modified ):self {
$this->mtime = (int) $modified;
return $this;
}
@@ -91,7 +76,7 @@
/**
* {@inheritdoc}
*/
- public function mode(){
+ public function mode():int {
return $this->fmode;
}
@@ -99,8 +84,8 @@
/**
* {@inheritdoc}
*/
- public function chmod( $mode, $recursive = false ){
- $this->fmode = (int) $mode;
+ public function chmod( int $mode, bool $recursive = false ):self {
+ $this->fmode = $mode;
return $this;
}
@@ -108,7 +93,7 @@
/**
* TODO implement in parent
*/
- public function chown( $uid = null, $gid = null ){
+ public function chown( ?int $uid = null, ?int $gid = null ):self {
if( is_int($uid) ){
$this->uid = $uid;
}
@@ -122,7 +107,7 @@
/**
* {@inheritdoc}
*/
- public function copy( $dest ){
+ public function copy( string $dest ):self {
$copy = new Loco_fs_DummyFile($dest);
foreach( get_object_vars($this) as $prop => $value ){
$copy->$prop = $value;
@@ -204,14 +189,14 @@
/**
* @inheritdoc
*/
- public function writable(){
+ public function writable():bool {
return true;
}
/**
* @inheritdoc
*/
- public function authorize(){
+ public function authorize():self {
return $this;
}
--- a/loco-translate/src/fs/File.php
+++ b/loco-translate/src/fs/File.php
@@ -5,42 +5,36 @@
class Loco_fs_File {
/**
- * @var Loco_fs_FileWriter
+ * Write context for the current file path
*/
- private $w;
+ private ?Loco_fs_FileWriter $w = null;
/**
* Path to file
- * @var string
*/
- private $path;
+ private string $path = '';
/**
* Cached pathinfo() data
- * @var array
*/
- private $info;
+ private ?array $info = null;
/**
* Base path which path has been normalized against
- * @var string
*/
- private $base;
+ private ?string $base = null;
/**
* Flag set when current path is relative
- * @var bool
*/
- private $rel;
+ private bool $rel;
/**
* Check if a path is absolute and return fixed slashes for readability
- * @param string $path
* @return string fixed path, or "" if not absolute
*/
- public static function abs( $path ){
- $path = (string) $path;
+ public static function abs( string $path ):string {
if( '' !== $path ){
$chr1 = substr($path,0,1);
// return unmodified path if starts "/"
@@ -63,17 +57,15 @@
/**
* Test if a path looks absolute
*/
- public static function is_abs( $path ){
+ public static function is_abs( string $path ):bool {
return '' !== $path && ( '/' === $path[0] || preg_match('!^\\\\|.:\\!',$path) );
}
/**
* Call PHP is_readable() but suppress E_WARNING when path is outside open_basedir.
- * @param string $path
- * @return bool
*/
- public static function is_readable( $path ){
+ public static function is_readable( string $path ):bool {
if( '' === $path || '.' === $path[0] ){
throw new InvalidArgumentException('Relative paths disallowed');
}
@@ -87,20 +79,16 @@
/**
* Create file with initial, unvalidated path
- * @param string $path
*/
- public function __construct( $path ){
+ public function __construct( string $path ){
$this->setPath( $path );
}
/**
* Internally set path value and flag whether relative or absolute
- * @param string $path
- * @return void
*/
- private function setPath( $path ){
- $path = (string) $path;
+ private function setPath( string $path ):void {
if( $fixed = self::abs($path) ){
$path = $fixed;
$this->rel = false;
@@ -116,9 +104,9 @@
/**
- * @return bool
+ * Return whether currently configure path is absolute
*/
- public function isAbsolute(){
+ public function isAbsolute(): bool {
return ! $this->rel;
}
@@ -257,27 +245,27 @@
/**
- * @return string
+ * Get directory name like dirname()
*/
- public function dirname(){
+ public function dirname():string{
$info = $this->pathinfo();
return $info['dirname'];
}
/**
- * @return string
+ * Get base name like basenaame()
*/
- public function basename(){
+ public function basename():string {
$info = $this->pathinfo();
return $info['basename'];
}
/**
- * @return string
+ * Get file name without extension, like filename()
*/
- public function filename(){
+ public function filename():string {
$info = $this->pathinfo();
return $info['filename'];
}
@@ -285,54 +273,50 @@
/**
* Gets final file extension, e.g. "html" in "foo.php.html"
- * @return string
*/
- public function extension(){
+ public function extension():string {
$info = $this->pathinfo();
return $info['extension'] ?? '';
}
/**
- * Gets full file extension after first dot ("."), e.g. "php.html" in "foo.php.html"
- * @return string
+ * Gets full file extension after first dot separator, e.g. "php.html" in "foo.php.html"
*/
- public function fullExtension(){
+ public function fullExtension():string {
$bits = explode('.',$this->basename(),2);
return array_key_exists(1,$bits) ? $bits[1] : '';
}
/**
- * @return string
+ * Get currently configure path, unmodified
*/
- public function getPath(){
+ public function getPath():string {
return $this->path;
}
/**
* Get file modification time as unix timestamp in seconds
- * @return int
*/
- public function modified(){
- return filemtime( $this->path );
+ public function modified():int {
+ return filemtime($this->path) ?: 0;
}
/**
* Get file size in bytes
- * @return int
*/
- public function size(){
- return filesize( $this->path );
+ public function size():int {
+ return filesize($this->path) ?: 0;
}
/**
- * @return int
+ * Get file mode as integer
*/
- public function mode(){
+ public function mode():int {
if( is_link($this->path) ){
$stat = lstat( $this->path );
$mode = $stat[2];
@@ -348,9 +332,8 @@
* Set file mode
* @param int $mode file mode integer e.g 0664
* @param bool $recursive whether to set recursively (directories)
- * @return Loco_fs_File
*/
- public function chmod( $mode, $recursive = false ){
+ public function chmod( int $mode, bool $recursive = false ):self {
$this->getWriteContext()->chmod( $mode, $recursive );
return $this->clearStat();
}
@@ -358,9 +341,8 @@
/**
* Clear stat cache if any file data has changed
- * @return Loco_fs_File
*/
- public function clearStat(){
+ public function clearStat():self {
$this->info = null;
// PHP 5.3.0 Added optional clear_realpath_cache and filename parameters.
if( version_compare( PHP_VERSION, '5.3.0', '>=' ) ){
@@ -385,9 +367,8 @@
/**
* Check if passed path is equal to ours
* @param string|self $ref
- * @return bool
*/
- public function equal( $ref ){
+ public function equal( $ref ):bool {
return $this->path === (string) $ref;
}
@@ -395,9 +376,8 @@
/**
* Normalize path for string comparison, resolves redundant dots and slashes.
* @param string $base path to prefix
- * @return string
*/
- public function normalize( $base = '' ){
+ public function normalize( string $base = '' ):string {
if( $path = self::abs($base) ){
$base = $path;
}
@@ -425,9 +405,8 @@
/**
* Get real path if file is real, but without altering internal path property.
* Also skips call to realpath() when likely to raise E_WARNING due to open_basedir
- * @return string
*/
- public function getRealPath(){
+ public function getRealPath():string {
if( $this->readable() ){
$path = realpath( $this->getPath() );
if( is_string($path) ){
@@ -435,15 +414,10 @@
}
}
return '';
- }
+ }
- /**
- * @param string $path
- * @param string[] $b
- * @return array
- */
- private static function explode( $path, array $b ){
+ private static function explode( string $path, array $b ):array {
$a = explode( '/', $path );
foreach( $a as $i => $s ){
if( '' === $s ){
@@ -470,7 +444,7 @@
* @param string $base Base path
* @return string path relative to given base
*/
- public function getRelativePath( $base ){
+ public function getRelativePath( string $base ):string {
$path = $this->normalize();
if( self::abs($path) ){
// base may require normalizing
@@ -583,7 +557,7 @@
* @throws Loco_error_WriteException
* @return Loco_fs_File new file
*/
- public function copy( $dest ){
+ public function copy( string $dest ):self {
$copy = clone $this;
$copy->path = $dest;
$copy->clearStat();
@@ -596,9 +570,9 @@
* Move/rename this file for real
* @param Loco_fs_File $dest target file with new path
* @throws Loco_error_WriteException
- * @return Loco_fs_File original file that should no longer exist
+ * @return self original file that should no longer exist
*/
- public function move( Loco_fs_File $dest ){
+ public function move( Loco_fs_File $dest ):self {
$this->getWriteContext()->move($dest);
return $this->clearStat();
}
@@ -607,9 +581,8 @@
/**
* Delete this file for real
* @throws Loco_error_WriteException
- * @return Loco_fs_File
*/
- public function unlink(){
+ public function unlink():self {
$recursive = $this->isDirectory();
$this->getWriteContext()->delete( $recursive );
return $this->clearStat();
@@ -619,9 +592,8 @@
/**
* Copy this object with an alternative file extension
* @param string $ext new extension
- * @return self
*/
- public function cloneExtension( $ext ){
+ public function cloneExtension( string $ext ):self {
return $this->cloneBasename( $this->filename().'.'.ltrim($ext,'.') );
}
@@ -629,9 +601,8 @@
/**
* Copy this object with an alternative name under the same directory
* @param string $name new name
- * @return self
*/
- public function cloneBasename( $name ){
+ public function cloneBasename( string $name ):self {
$file = clone $this;
$file->path = rtrim($file->dirname(),'/').'/'.$name;
$file->info = null;
@@ -641,9 +612,8 @@
/**
* Ensure full parent directory tree exists
- * @return Loco_fs_Directory|null
*/
- public function createParent(){
+ public function createParent():?Loco_fs_Directory {
$dir = $this->getParent();
if( $dir instanceof Loco_fs_Directory && ! $dir->exists() ){
$dir->mkdir();
@@ -668,10 +638,10 @@
* Value is that used by WP_Automatic_Updater::should_update.
* @return string "core", "plugin", "theme" or "translation"
*/
- public function getUpdateType(){
+ public function getUpdateType():string {
// global languages directory root, and canonical subdirectories
$dirpath = (string) ( $this->isDirectory() ? $this : $this->getParent() );
- $sub = Loco_fs_Locations::getGlobal()->rel($dirpath);
+ $sub = Loco_fs_Locations::getLangs()->rel($dirpath);
if( is_string($sub) && '' !== $sub ){
list($root) = explode('/', $sub, 2 );
if( '.' === $root || 'themes' === $root || 'plugins' === $root ){
--- a/loco-translate/src/fs/FileWriter.php
+++ b/loco-translate/src/fs/FileWriter.php
@@ -4,20 +4,14 @@
*/
class Loco_fs_FileWriter {
- /**
- * @var Loco_fs_File
- */
- private $file;
+ private Loco_fs_File $file;
- /**
- * @var WP_Filesystem_Base
- */
- private $fs;
+ private WP_Filesystem_Base $fs;
/**
* @param Loco_fs_File $file
*/
- public function __construct( Loco_fs_File $file ){
+ public function __construct( Loco_fs_File $file ) {
$this->setFile($file);
$this->disconnect();
}
@@ -27,7 +21,7 @@
* @param Loco_fs_File $file
* @return Loco_fs_FileWriter
*/
- public function setFile( Loco_fs_File $file ){
+ public function setFile( Loco_fs_File $file ): self {
$this->file = $file;
return $this;
}
@@ -41,7 +35,7 @@
* @return Loco_fs_FileWriter
* @throws Loco_error_WriteException
*/
- public function connect( WP_Filesystem_Base $fs, $disconnected = true ){
+ public function connect( WP_Filesystem_Base $fs, bool $disconnected = true ): self {
if( $disconnected && ! $fs->connect() ){
$errors = $fs->errors;
if( is_wp_error($errors) ){
@@ -58,9 +52,8 @@
/**
* Revert to direct file system connection
- * @return self
*/
- public function disconnect(){
+ public function disconnect(): self {
$this->fs = Loco_api_WordPressFileSystem::direct();
return $this;
}
@@ -68,9 +61,8 @@
/**
* Get mapped path for use in indirect file system manipulation
- * @return string
*/
- public function getPath(){
+ public function getPath(): string {
return $this->mapPath( $this->file->getPath() );
}
@@ -80,7 +72,7 @@
* @param string $path
* @return string
*/
- private function mapPath( $path ){
+ private function mapPath( string $path ): string {
if( ! $this->isDirect() ){
$base = untrailingslashit( Loco_fs_File::abs(loco_constant('WP_CONTENT_DIR')) );
$snip = strlen($base);
@@ -105,17 +97,17 @@
/**
* Test if a direct (not remote) file system
- * @return bool
*/
- public function isDirect(){
+ public function isDirect(): bool {
return $this->fs instanceof WP_Filesystem_Direct;
}
/**
- * @return bool
+ * Test if the currently configured path is writable via the current file system connector.
+ * Note that this doesn't check the additional security settings handled by authorize()
*/
- public function writable(){
+ public function writable(): bool {
return ! $this->disabled() && $this->fs->is_writable( $this->getPath() );
}
@@ -126,7 +118,7 @@
* @return Loco_fs_FileWriter
* @throws Loco_error_WriteException
*/
- public function chmod( $mode, $recursive = false ){
+ public function chmod( int $mode, bool $recursive = false ): self {
$this->authorize();
if( ! $this->fs->chmod( $this->getPath(), $mode, $recursive ) ){
// translators: %s refers to a file name, for which the chmod operation failed.
@@ -141,7 +133,7 @@
* @return Loco_fs_FileWriter
* @throws Loco_error_WriteException
*/
- public function copy( Loco_fs_File $copy ){
+ public function copy( Loco_fs_File $copy ): self {
$this->authorize();
$source = $this->getPath();
$target = $this->mapPath( $copy->getPath() );
@@ -171,7 +163,7 @@
* @return Loco_fs_FileWriter
* @throws Loco_error_WriteException
*/
- public function move( Loco_fs_File $dest ){
+ public function move( Loco_fs_File $dest ): self {
$orig = $this->file;
try {
// target should have been authorized to create the new file
@@ -179,7 +171,7 @@
$context->setFile($orig);
$context->copy($dest);
// source should have been authorized to delete the original file
- $this->delete(false);
+ $this->delete();
return $this;
}
catch( Loco_error_WriteException $e ){
@@ -194,7 +186,7 @@
* @return self
* @throws Loco_error_WriteException
*/
- public function delete( $recursive = false ){
+ public function delete( bool $recursive = false ): self {
$this->authorize();
if( ! $this->fs->delete( $this->getPath(), $recursive ) ){
// translators: %s refers to a file name, for which a delete operation failed.
@@ -210,7 +202,7 @@
* @return Loco_fs_FileWriter
* @throws Loco_error_WriteException
*/
- public function putContents( $data ){
+ public function putContents( string $data ): self {
$this->authorize();
$file = $this->file;
if( $file->isDirectory() ){
@@ -301,25 +293,29 @@
/**
* Check whether write operations are permitted, or throw
* @throws Loco_error_WriteException
- * @return self
*/
- public function authorize(){
+ public function authorize(): self {
if( $this->disabled() ){
throw new Loco_error_WriteException( __('File modification is disallowed by your WordPress config','loco-translate') );
}
$opts = Loco_data_Settings::get();
- // deny system file changes (fs_protect = 2)
+ // Deny system file changes (fs_protect = 2)
if( 1 < $opts->fs_protect && $this->file->getUpdateType() ){
throw new Loco_error_WriteException( __('Modification of installed files is disallowed by the plugin settings','loco-translate') );
}
- // we may need to examine multiple extensions, or there may be none for directories
+ // Deny writes outside our custom base directories. The current path must be resolvable beneath at least one.
+ $roots = Loco_fs_Locations::getBaseDirs();
+ if( $roots->count() && ! $roots->check( $this->file->getPath() ) ){
+ throw new Loco_error_WriteException( __('File modification disallowed by the plugin settings','loco-translate') );
+ }
+ // We may need to examine multiple extensions, or there may be none for directories
$exts = array_slice( explode('.',strtolower($this->file->basename())), 1 );
if( ! $exts ){
return $this;
}
$ext = array_pop($exts);
- // deny POT modification (pot_protect = 2)
- // this assumes that templates all have .pot extension, which isn't guaranteed. UI should prevent saving of wrongly files like "default.po"
+ // Deny POT modification (pot_protect = 2)
+ // This assumes that templates all have .pot extension, which isn't guaranteed. UI should prevent saving of wrongly files like "default.po"
if( 'pot' === $ext && 1 < $opts->pot_protect ){
throw new Loco_error_WriteException( __( 'Modification of POT (template) files is disallowed by the plugin settings', 'loco-translate' ) );
}
@@ -341,9 +337,8 @@
/**
* Check if file system modification is banned at WordPress level
- * @return bool
*/
- public function disabled(){
+ public function disabled(): bool {
// WordPress >= 4.8
if( function_exists('wp_is_file_mod_allowed') ){
$context = apply_filters( 'loco_file_mod_allowed_context', 'download_language_pack', $this->file );
--- a/loco-translate/src/fs/Locations.php
+++ b/loco-translate/src/fs/Locations.php
@@ -6,66 +6,68 @@
/**
* Singleton of WordPress root directory
- * @var Loco_fs_Locations
*/
- private static $roots;
+ private static ?self $wproot = null;
/**
* Singleton of wp-content directory
- * @var Loco_fs_Locations
*/
- private static $conts;
+ private static ?self $conts = null;
/**
* Singleton of global languages directories
- * @var Loco_fs_Locations
*/
- private static $langs;
+ private static ?self $langs = null;
/**
* Singleton of registered theme paths
- * @var Loco_fs_Locations
*/
- private static $theme;
+ private static ?self $theme = null;
/**
* Singleton of registered plugin locations
- * @var Loco_fs_Locations
- */
- private static $plugin;
+ */
+ private static ?self $plugin = null;
+
+
+ /**
+ * Singleton of configured base directories from settings
+ */
+ private static ?self $jails = null;
/**
* Clear static caches
*/
- public static function clear(){
- self::$roots = null;
+ public static function clear(): void {
+ self::$wproot = null;
self::$conts = null;
self::$langs = null;
self::$theme = null;
self::$plugin = null;
+ self::$jails = null;
}
/**
- * @return Loco_fs_Locations
+ * Get a locations collection containing only the WordPress installation directory
*/
- public static function getRoot(){
- if( ! self::$roots ){
- self::$roots = new Loco_fs_Locations( [
+ public static function getRoot():self {
+ if( ! self::$wproot ){
+ self::$wproot = new Loco_fs_Locations( [
loco_constant('ABSPATH'),
] );
}
- return self::$roots;
+ return self::$wproot;
}
/**
- * @return Loco_fs_Locations
+ * Get a locations collection containing the most likely WordPress content directory
*/
- public static function getContent(){
+ public static function getContent():self{
if( ! self::$conts ){
self::$conts = new Loco_fs_Locations( [
loco_constant('WP_CONTENT_DIR'), // <- defined WP_CONTENT_DIR
@@ -78,17 +80,16 @@
/**
* @deprecated Use getLang
- * @return Loco_fs_Locations
*/
- public static function getGlobal(){
+ public static function getGlobal():self {
return self::getLangs();
}
/**
- * @return Loco_fs_Locations
+ * Get a locations collection containing the WordPress global languages directory
*/
- public static function getLangs(){
+ public static function getLangs():self{
if( ! self::$langs ){
self::$langs = new Loco_fs_Locations( [
loco_constant('WP_LANG_DIR'),
@@ -99,9 +100,9 @@
/**
- * @return Loco_fs_Locations
+ * Get a locations collection containing all directories that may contain themes
*/
- public static function getThemes(){
+ public static function getThemes():self{
if( ! self::$theme ){
$roots = $GLOBALS['wp_theme_directories'] ?? [];
if( ! $roots ){
@@ -114,9 +115,9 @@
/**
- * @return Loco_fs_Locations
+ * Get a locations collection containing all directories that may contain plugins
*/
- public static function getPlugins(){
+ public static function getPlugins():self{
if( ! self::$plugin ){
self::$plugin = new Loco_fs_Locations( [
loco_constant('WPMU_PLUGIN_DIR'),
@@ -128,10 +129,30 @@
/**
+ * Get a locations collection from the fs_basedir plugin setting.s
+ * Absolute paths are used as-is; relative paths are resolved against ABSPATH.
+ */
+ public static function getBaseDirs():self{
+ if( ! self::$jails ){
+ $abspath = loco_constant('ABSPATH');
+ $paths = [];
+ foreach( explode("n", Loco_data_Settings::get()->fs_basedir) as $line ){
+ $line = trim($line);
+ if( '' !== $line ){
+ $paths[] = (new Loco_fs_File($line))->normalize($abspath);
+ }
+ }
+ self::$jails = new Loco_fs_Locations( $paths );
+ }
+ return self::$jails;
+ }
+
+
+ /**
* Create instance from list of locations
*/
public function __construct( array $paths ){
- parent::__construct( [] );
+ parent::__construct();
foreach( $paths as $path ){
$this->add( $path );
}
@@ -142,7 +163,7 @@
* @param string $path normalized absolute path
* @return Loco_fs_Locations
*/
- public function add( $path ){
+ public function add( string $path ): self {
foreach( $this->expand($path) as $path ){
// path must have trailing slash, otherwise "/plugins/foobar" would match "/plugins/foo/"
$this->offsetSet( $path, strlen($path) );
@@ -156,7 +177,7 @@
* @param string $path absolute path
* @return bool whether path matched
*/
- public function check( $path ){
+ public function check( string $path ): bool {
foreach( $this->expand($path) as $path ){
foreach( $this as $prefix => $length ){
if( $prefix === $path || substr($path,0,$length) === $prefix ){
@@ -172,9 +193,9 @@
* Match location and return the relative subpath.
* Note that exact match is returned as "." indicating self
* @param string $path
- * @return string | null
+ * @return string|null
*/
- public function rel( $path ){
+ public function rel( string $path ): ?string {
foreach( $this->expand($path) as $path ){
foreach( $this as $prefix => $length ){
if( $prefix === $path ){
@@ -193,7 +214,7 @@
* Like rel() but returns base directory also
* @return string[]
*/
- public function split( $path ){
+ public function split( string $path ): ?array {
foreach( $this->expand($path) as $path ){
foreach( $this as $prefix => $length ){
if( $prefix === $path ){
@@ -223,10 +244,10 @@
/**
- * @param string $rel
+ * @param string $rel Relative
* @return string[]
*/
- public function expand( $rel ){
+ public function expand( string $rel ):array {
if( '' === $rel ){
//Loco_error_AdminNotices::debug('Expanding empty path to empty array');
return [];
@@ -249,7 +270,7 @@
/**
* @return string[]
*/
- public function apply( $suffix = '' ){
+ public function apply( string $suffix = '' ): array {
$paths = [];
foreach( $this->getArrayCopy() as $prefix => $length ){
$paths[] = $prefix.$suffix;
@@ -258,5 +279,13 @@
}
+ public function __toString(): string {
+ $paths = [];
+ foreach( $this->getArrayCopy() as $prefix => $length ){
+ $paths[] = rtrim($prefix,'/');
+ }
+ return implode(':',$paths);
+ }
+
}
--- a/loco-translate/src/js/Strings.php
+++ b/loco-translate/src/js/Strings.php
@@ -1,15 +1,15 @@
<?php
-/**
- * Auto-generated class, do not edit.
- * The purpose of this is to provide extractable strings that can be compiled at runtime into raw data for exporting to JavaScript.
- */
-class Loco_js_Strings extends Loco_hooks_TranslateBuffer {
-
/**
- * @return array
- */
- public function compile(){
-
+ * Auto-generated class, do not edit.
+ * The purpose of this is to provide extractable strings that can be compiled at runtime into raw data for exporting to JavaScript.
+ */
+ class Loco_js_Strings extends Loco_hooks_TranslateBuffer {
+
+ /**
+ * @return array
+ */
+ public function compile(){
+
// translators: When text filtering reduces to an empty view
__("Nothing matches the text filter",'loco-translate');
@@ -196,7 +196,8 @@
//
__("Mismatching placeholder type; check against source text formatting",'loco-translate');
-
- return $this->flush('loco-translate');
+
+ return $this->flush('loco-translate');
+ }
}
-}
+
No newline at end of file
--- a/loco-translate/src/package/Core.php
+++ b/loco-translate/src/package/Core.php
@@ -94,7 +94,7 @@
$domain = new Loco_package_TextDomain('default');
$domain->setCanonical( true );
// front end subset, has empty name in WP
- // full title is like "4.9.x - Development" but we don't know what version at this point
+ // full title is like "7.0.x - Development" but we don't know what version at this point
list($x,$y) = explode('.',$GLOBALS['wp_version'],3);
$project = $domain->createProject( $bundle, sprintf('%u.%u.x - Development',$x,$y) );
$project->setSlug('')
--- a/loco-translate/src/test/TestCase.php
+++ b/loco-translate/src/test/TestCase.php
@@ -6,13 +6,15 @@
/**
* Buffering output for tests that won't capture output
- * @var Loco_output_Buffer
*/
- private $buffer;
+ private Loco_output_Buffer $buffer;
public function set_up(){
parent::set_up();
+ Loco_data_Settings::get()->populate([
+ 'fs_basedir' => sys_get_temp_dir(),
+ ]);
$this->buffer = Loco_output_Buffer::start();
}
@@ -24,8 +26,7 @@
}
- protected function normalizeHtml( $src ){
-
+ protected function normalizeHtml( string $src ):string {
$dom = new DOMDocument('1.0','UTF-8');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = false;
--- a/loco-translate/src/test/WordPressTestCase.php
+++ b/loco-translate/src/test/WordPressTestCase.php
@@ -138,6 +138,10 @@
if( Loco_error_AdminNotices::destroy() ){
throw new Exception('Refusing to start test with errors in buffer');
}
+ // Set permissive writeable directories for all tests
+ Loco_data_Settings::get()->populate([
+ 'fs_basedir' => dirname(ABSPATH),
+ ])->persist();
}
@@ -178,16 +182,13 @@
/**
* Capture cookie and prevent actual http sending
*/
- public function captureCookie( Loco_data_Cookie $cookie ){
+ public function captureCookie( Loco_data_Cookie $cookie ):bool {
$this->cookies_set[ $cookie->getName() ] = $cookie;
return false;
}
- /**
- * @return Loco_data_Cookie
- */
- public function assertCookieSet( $name, $message = '' ){
+ public function assertCookieSet( string $name, string $message = '' ):Loco_data_Cookie{
$this->assertArrayHasKey( $name, $this->cookies_set, $message );
$cookie = $this->cookies_set[ $name ];
$this->assertInstanceOf( 'Loco_data_Cookie', $cookie, $message );
@@ -223,7 +224,7 @@
* Invoke Ajax controller without full hook set up.
* @return string JSON
*/
- protected function renderAjax(){
+ protected function renderAjax():string {
wp_magic_quotes(); // <- I hate this, but it's what WP does!
$router = new Loco_mvc_AjaxRouter;
$router->on_init();
@@ -254,7 +255,7 @@
/**
* @return Loco_test_WordPressTestCase
*/
- public function disable_file_mods(){
+ public function disable_file_mods():self {
$this->fs_allow = false;
return $this;
}
@@ -276,7 +277,7 @@
* Filters DISALLOW_FILE_MODS for WP < 4.8
* @internal
*/
- public function filter_fs_disallow(){
+ public function filter_fs_disallow():bool {
return ! $this->fs_allow;
}
@@ -286,7 +287,7 @@
* @internal
* @noinspection PhpUnusedParameterInspection
*/
- public function filter_fs_allow_context( $context, ?Loco_fs_File $file = null ){
+ public function filter_fs_allow_context( $context, ?Loco_fs_File $file = null ):string {
return 'loco_test';
}
@@ -446,9 +447,8 @@
/**
* Temporarily set test data root to content directory
- * @return void
*/
- public function enable_test_content_dir(){
+ public function enable_test_content_dir():void {
remove_all_filters('loco_constant_WP_CONTENT_DIR');
add_filter('loco_constant_WP_CONTENT_DIR', [$this,'_filter_wp_content_dir'], 10, 0 );
}
@@ -457,7 +457,7 @@
/**
* @internal
*/
- public function _filter_wp_content_dir(){
+ public function _filter_wp_content_dir():string {
return LOCO_TEST_DATA_ROOT;
}
--- a/loco-translate/tpl/admin/config/debug.php
+++ b/loco-translate/tpl/admin/config/debug.php
@@ -116,6 +116,8 @@
endforeach?>
<dt>PHP open_basedir:</dt>
<dd><?php self::e(ini_get('open_basedir'))?></dd>
+ <dt>Loco basedir restriction:</dt>
+ <dd><?php self::e( Loco_fs_Locations::getBaseDirs() )?></dd>
</dl>
</div>
@@ -125,6 +127,7 @@
<a href="#loco-debug" class="loco-anchor" aria-hidden="true"></a>
</h3>
<dl><?php
+ /* @var Loco_mvc_ViewParams $debug */
foreach( $debug as $key => $value ):?>
<dt>
<?php echo $debug->escape($key)?>:
--- a/loco-translate/tpl/admin/config/settings.php
+++ b/loco-translate/tpl/admin/config/settings.php
@@ -212,6 +212,12 @@
<option value="2"<?php echo 2 === $opts->code_view?' selected':''?>><?php esc_html_e('Allow','loco-translate')?></option>
</select>
</p>
+ <p>
+ <label for="loco--fs-basedir" style="vertical-align: top">
+ <?php esc_html_e('Restricted writeable directories','loco-translate');?>:
+ </label>
+ <textarea name="opts[fs_basedir]" id="loco--fs-basedir" rows="2" class="regular-text"><?php echo esc_html($opts->fs_basedir)?></textarea>
+ </p>
</fieldset>
</td>
</tr>
--- a/loco-translate/tpl/admin/file/info.php
+++ b/loco-translate/tpl/admin/file/info.php
@@ -16,7 +16,17 @@
<p>
<code><?php $file->e('relpath')?></code>
</p>
- </div><?php
+ </div><?php
+ // let security settings override actual writeable state
+ elseif( $file->denied ):?>
+ <div class="panel panel-locked">
+ <h3 class="has-icon">
+ <?php esc_html_e('Write access denied','loco-translate')?>
+ </h3>
+ <p>
+ <?php $file->e('denied')?>.
+ </p>
+ </div><?php
elseif( $file->writable ):?>
<div class="panel panel-success">
<h3 class="has-icon">
@@ -30,6 +40,7 @@
<code><?php $file->ls()?></code>
</p>
</div><?php
+ // else file is unwriteable via PHP, but not denied by security settings.
else:?>
<div class="panel panel-locked">
<h3 class="has-icon">
@@ -48,7 +59,6 @@
</div><?php
endif;
-
if( ! $dir->existent ):?>
<div class="panel panel-error">
<h3 class="has-icon">
@@ -62,7 +72,6 @@
<code><?php $dir->e('relpath')?></code>
</p>
</div><?php
-
elseif( $dir->writable ):?>
<div class="panel panel-success">
<h3 class="has-icon">
@@ -82,11 +91,11 @@
</p><?php
endif;?>
</div><?php
-
- else:?>
+ // indicate that directory is unwriteable via file system, unless file is blocked
+ elseif( ! $file->denied ):?>
<div class="panel panel-locked">
<h3 class="has-icon">
- <?php esc_html_e('Write protected','loco-translate')?>
+ <?php esc_html_e('Write protected directory','loco-translate')?>
</h3>
<p>
<?php esc_html_e("This directory can't be written to directly by the web server",'loco-translate')?>.