Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4079678
FontRepoCompiler.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
FontRepoCompiler.php
View Options
<?php
namespace
UniversalLanguageSelector
;
use
MediaWiki\Output\OutputPage
;
/**
* This class parses font specification ini files to a central list.
*
* @author Niklas Laxström
* @since 2016.04
*/
class
FontRepoCompiler
{
public
function
__construct
(
private
readonly
string
$fsPath
,
private
readonly
string
$webPath
,
)
{
}
public
function
getRepository
():
array
{
$files
=
$this
->
getFilesFromPath
(
$this
->
fsPath
);
$fonts
=
[];
$languages
=
[];
foreach
(
$files
as
$file
)
{
$conf
=
$this
->
parseFile
(
$file
);
$fontPath
=
dirname
(
$file
);
foreach
(
$conf
as
$fontname
=>
$font
)
{
$fontLanguages
=
$this
->
getLanguages
(
$font
);
$this
->
appendLanguages
(
$languages
,
$fontLanguages
,
$fontname
);
$fonts
[
$fontname
]
=
$this
->
getFontInfo
(
$font
,
$fontPath
);
}
}
ksort
(
$languages
);
ksort
(
$fonts
);
return
[
'base'
=>
$this
->
webPath
,
'languages'
=>
$languages
,
'fonts'
=>
$fonts
];
}
/**
* @param string $fspath
* @return array|false
*/
public
function
getFilesFromPath
(
string
$fspath
)
{
return
glob
(
"$fspath/*/font.ini"
);
}
/**
* @param string $filepath
* @return array|false
*/
public
function
parseFile
(
string
$filepath
)
{
return
parse_ini_file
(
$filepath
,
true
);
}
public
function
getLanguages
(
array
$font
):
array
{
if
(
!
isset
(
$font
[
'languages'
]
)
)
{
return
[];
}
$languages
=
explode
(
','
,
$font
[
'languages'
]
);
$languages
=
array_map
(
'trim'
,
$languages
);
return
$languages
;
}
public
function
appendLanguages
(
array
&
$languages
,
array
$fontLanguages
,
string
$fontname
,
):
void
{
foreach
(
$fontLanguages
as
$rcode
)
{
$code
=
str_replace
(
'*'
,
''
,
$rcode
);
if
(
!
isset
(
$languages
[
$code
]
)
)
{
$languages
[
$code
]
=
[
'system'
];
}
if
(
str_contains
(
$rcode
,
'*'
)
)
{
if
(
$languages
[
$code
][
0
]
===
'system'
)
{
unset
(
$languages
[
$code
][
0
]
);
}
array_unshift
(
$languages
[
$code
],
$fontname
);
}
else
{
$languages
[
$code
][]
=
$fontname
;
}
}
}
public
function
getFontInfo
(
array
$font
,
string
$fontpath
,
):
array
{
$info
=
[];
$fontdir
=
basename
(
$fontpath
);
if
(
isset
(
$font
[
'fontweight'
]
)
)
{
$info
[
'fontweight'
]
=
$font
[
'fontweight'
];
}
if
(
isset
(
$font
[
'fontstyle'
]
)
)
{
$info
[
'fontstyle'
]
=
$font
[
'fontstyle'
];
}
foreach
(
[
'woff2'
]
as
$format
)
{
if
(
isset
(
$font
[
$format
]
)
)
{
$info
[
$format
]
=
OutputPage
::
transformFilePath
(
$fontdir
,
$fontpath
,
$font
[
$format
]
);
}
}
// If font formats are not explicitly defined, scan the directory.
if
(
!
isset
(
$info
[
'woff2'
]
)
)
{
foreach
(
glob
(
"$fontpath/*.woff2"
,
GLOB_BRACE
)
as
$fontfile
)
{
$type
=
substr
(
$fontfile
,
strrpos
(
$fontfile
,
'.'
)
+
1
);
$info
[
$type
]
=
OutputPage
::
transformFilePath
(
$fontdir
,
$fontpath
,
basename
(
$fontfile
)
);
}
}
// Font variants
if
(
isset
(
$font
[
'bold'
]
)
)
{
$info
[
'variants'
][
'bold'
]
=
$font
[
'bold'
];
}
if
(
isset
(
$font
[
'bolditalic'
]
)
)
{
$info
[
'variants'
][
'bolditalic'
]
=
$font
[
'bolditalic'
];
}
if
(
isset
(
$font
[
'italic'
]
)
)
{
$info
[
'variants'
][
'italic'
]
=
$font
[
'italic'
];
}
return
$info
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 05:08 (8 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9f/13/1094458fee093984663635102825
Default Alt Text
FontRepoCompiler.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment