Skip to content

Commit db92672

Browse files
committed
Replace strftime with Intl ICU. Fixes dokuwiki#3573
This uses a class that maps strftime placeholders to the appropriate ICU patterns. I am using the fallback-intl branch here which provides an English-only fallback when the intl extension is not available. Core has only two places where strftime is used: dformat() and the SimplePie feed parser. Both are adjusted with this patch. For the latter a custom Item class had to be registered. For better separation all our FeedParser classes have been moved to the Feed namespace where our FeedCreator classes already reside. Note that this will currently be a degration for users without intl as it will fall back to date and not to the still available strftime.
1 parent 850e662 commit db92672

25 files changed

+833
-15
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"splitbrain/php-cli": "^1.1",
1818
"splitbrain/slika": "^1.0",
1919
"kissifrot/php-ixr": "^1.8",
20-
"splitbrain/php-jsstrip": "^1.0"
20+
"splitbrain/php-jsstrip": "^1.0",
21+
"php81_bc/strftime": "dev-fallback-intl"
2122
},
2223
"config": {
2324
"platform": {

composer.lock

Lines changed: 52 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/FeedParser.php renamed to inc/Feed/FeedParser.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php
22

3-
use SimplePie\SimplePie;
4-
use dokuwiki\FeedParserFile;
3+
namespace dokuwiki\Feed;
4+
55
use SimplePie\File;
6+
use SimplePie\SimplePie;
67

78
/**
89
* We override some methods of the original SimplePie class here
@@ -17,6 +18,7 @@ public function __construct()
1718
parent::__construct();
1819
$this->enable_cache(false);
1920
$this->registry->register(File::class, FeedParserFile::class);
21+
$this->registry->register('Item', FeedParserItem::class);
2022
}
2123

2224
/**

inc/FeedParserFile.php renamed to inc/Feed/FeedParserFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
namespace dokuwiki;
3+
namespace dokuwiki\Feed;
44

5+
use dokuwiki\HTTP\DokuHTTPClient;
56
use SimplePie\File;
67
use SimplePie\SimplePie;
7-
use dokuwiki\HTTP\DokuHTTPClient;
88

99
/**
1010
* Fetch an URL using our own HTTPClient

inc/Feed/FeedParserItem.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace dokuwiki\Feed;
4+
5+
use SimplePie\Item;
6+
use SimplePie\SimplePie;
7+
8+
class FeedParserItem extends Item
9+
{
10+
/**
11+
* replace strftime with PHP81_BC\strftime
12+
* @inheritdoc
13+
*/
14+
public function get_local_date($date_format = '%c')
15+
{
16+
if (!$date_format) {
17+
return $this->sanitize($this->get_date(''), SimplePie::CONSTRUCT_TEXT);
18+
} elseif (($date = $this->get_date('U')) !== null && $date !== false) {
19+
return \PHP81_BC\strftime($date_format, $date);
20+
}
21+
22+
return null;
23+
}
24+
}

inc/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ function dformat($dt = null, $format = '')
15001500
if (!$format) $format = $conf['dformat'];
15011501

15021502
$format = str_replace('%f', datetime_h($dt), $format);
1503-
return strftime($format, $dt);
1503+
return \PHP81_BC\strftime($format, $dt);
15041504
}
15051505

15061506
/**

inc/legacy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ class_alias('\dokuwiki\Extension\CLIPlugin', 'DokuWiki_CLI_Plugin');
1919
class_alias('\dokuwiki\Extension\Plugin', 'DokuWiki_Plugin');
2020
class_alias('\dokuwiki\Extension\RemotePlugin', 'DokuWiki_Remote_Plugin');
2121
class_alias('\dokuwiki\Extension\SyntaxPlugin', 'DokuWiki_Syntax_Plugin');
22+
23+
class_alias('\dokuwiki\Feed\FeedParser', 'FeedParser');

inc/parser/xhtml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use dokuwiki\ChangeLog\MediaChangeLog;
4+
use dokuwiki\Feed\FeedParser;
45
use dokuwiki\File\MediaResolver;
56
use dokuwiki\File\PageResolver;
67
use dokuwiki\Utf8\PhpString;
@@ -1333,7 +1334,6 @@ public function rss($url, $params)
13331334
global $lang;
13341335
global $conf;
13351336

1336-
require_once(DOKU_INC . 'inc/FeedParser.php');
13371337
$feed = new FeedParser();
13381338
$feed->set_feed_url($url);
13391339

vendor/composer/autoload_files.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77

88
return array(
99
'fdc0e9724ddc47859c8bf0c1ea0a623a' => $vendorDir . '/openpsa/universalfeedcreator/lib/constants.php',
10+
'9e71c1459ef1226520e4b26dac3a180d' => $vendorDir . '/php81_bc/strftime/src/php-8.1-strftime.php',
1011
'decc78cc4436b1292c6c0d151b19445c' => $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
1112
);

vendor/composer/autoload_psr4.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'phpseclib3\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
1616
'SimplePie\\' => array($vendorDir . '/simplepie/simplepie/src'),
1717
'ParagonIE\\ConstantTime\\' => array($vendorDir . '/paragonie/constant_time_encoding/src'),
18+
'PHP81_BC\\strftime\\' => array($vendorDir . '/php81_bc/strftime/src'),
1819
'LesserPHP\\tests\\' => array($vendorDir . '/splitbrain/lesserphp/tests'),
1920
'LesserPHP\\' => array($vendorDir . '/splitbrain/lesserphp/src'),
2021
'IXR\\tests\\' => array($vendorDir . '/kissifrot/php-ixr/tests'),

0 commit comments

Comments
 (0)