Forum icon sc template cleanup - #5425
Conversation
|
Code Climate has analyzed commit d7702e1 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (80% is the threshold). This pull request will bring the total coverage in the repository to 41.8% (-7.1% change). View more on Code Climate. |
241b734 to
4f50dac
Compare
… typo e107_admin/history.php and lan_admin.php carried whitespace-only changes with nothing to do with the forum icons, one of them inside the ADLAN_ERR_3 warning text. Restore both to their base state. IMAGE_nonew_popular separated its shortcode parms with '%' rather than '&', so parse_str() would have read the whole tail as the glyph name.
There was a problem hiding this comment.
@rica-carv You opened #5424 asking whether a template should be reaching into core handlers, nobody answered, and you answered it yourself with this PR. Sorry about the silence on the question; let me answer it properly now, because the instinct is right and the mechanism is not available.
Why {GLYPH} cannot carry this. The constants are not consumed as template text. They are concatenated into PHP strings all over the plugin: forum.php, forum_class.php, forum_viewtopic.php, forum_shortcodes.php and viewforum_shortcodes.php between them use IMAGE_new, IMAGE_nonew, IMAGE_sticky, IMAGE_closed, IMAGE_announce, IMAGE_track and the rest in roughly twenty places, none of which parse what they build.
That matters because the shortcode parser is a single pass:
$ret = preg_replace_callback('#\{([A-Z][^\x02]*?\S)\}#', array(&$this, 'doCode'), (string) $text);preg_replace_callback does not re-scan what it substituted, so a {GLYPH:...} token that a shortcode returns is never expanded. The parseTemplate() you added to sc_icon() covers that one call site. Everywhere else the reader would see the literal text {GLYPH:type=fa-star&size=2x} on the page. It is the same rule that makes a {LAN=...} token returned from a shortcode render as itself.
Where that leaves the design question. The $tp in forum_icons_template.php is not really a template calling a handler, it is a PHP file that happens to live in templates/ and whose whole job is to define() constants. Untangling it means giving those icons a real accessor that the consuming code calls, not a token, which is a bigger change than this PR and one worth agreeing on before writing. Worth reviving #5424 with that framing.
I have pushed a commit for two things that stand on their own regardless of what happens to the approach. IMAGE_nonew_popular separated its parms with % instead of &, so parse_str() would have swallowed the whole tail as the glyph name. And e107_admin/history.php and lan_admin.php carried whitespace-only edits unrelated to forum icons, one of them inside the ADLAN_ERR_3 warning text, so both are back to their base state.
Beyond that I would hold this one. Not a rejection of the idea, just of the route.
|
Sorry, but i got lost somewhere.... So, what's your suggestion to have those glyphs displayed? But if that's the "wrong" approach, what's the right one? |
|
@rica-carv Not lost at all, and the instinct behind the question is a good one. Let me separate the two halves, because I think one of them is right and the other is aiming at the wrong file. Why the token form can't carry
That is why the extra
The icon key at And the shortcode is only one of the consumers. Those constants are read in 59 places across 7 files ( return "<a href='".$url."'>".IMAGE_new.'</a>';Nothing there parses what it builds. Chasing that with 59 The file isn't the kind of template you think it isHere's where I think your instinct is sound and the target is off. You're reading So The thing genuinely worth complaining about is that a theme author who wants to swap one icon has to open a PHP file and edit a function call. That's a fair complaint. It's just not fixed by changing what the constants contain. What I'd actually buildLet the theme file be data, and let core turn data into constants. Roughly: // theme's forum_icons_template.php, no function calls
$FORUM_ICONS = array(
'new' => array('fa-star', 'size=2x'),
'nonew' => array('fa-comment', 'size=2x'),
'new_small' => array('fa-star'),
// ...
);and one loop in core, after the That's a much smaller change than it sounds, and it's the one that actually delivers what you're after. It also gives you somewhere sensible to put the alt/title text, which the FontAwesome branch currently drops on the floor entirely (compare the two halves of the file: the I'll be straight that whether it's worth the churn is @Deltik's call, not mine. If he's up for it I'd say open it as a fresh PR against the icons file alone, and this one can close. Meanwhile, on this PRThe Obrigado for pushing on it. The question was worth asking and I'd rather you asked than quietly dropped it. |


Motivation and Context
Removal of direct acces to core e107 functions, as stated in #5424
Description
Converted all code to shortcodes calls
How Has This Been Tested?
Latest e107 from github
Types of Changes
Checklist