As Spaced function in UTF-8

Summary:How to fix the broken {$Namespaced}, {$Titlespaced}, {$Groupspaced} when the website is in UTF-8
Maintainer: Petko
Categories: Obsolete

Questions answered by this recipe

How to fix the broken {$Namespaced}, {$Titlespaced}, {$Groupspaced} when the website is in UTF-8? These usefull variables don't work in skins or pagelists, which can be very dissapointing.

Note that these fixes are available in PmWiki core as of version 2.2.0-beta30 (2007-02-09), so if you upgrade, your unicode website should be fine.
See also some other UTF-8 tips.

Description

You can use a custom $AsSpacedFunction.

In your config.php or farmconfig.php add the following code:

 
# you maybe have also one XLPage() call
include_once($FarmD.'/scripts/xlpage-utf-8.php');

# fix a bug in $CaseConversions (for pmwiki-2.2.0-beta16 and older)
$CaseConversions["\xc4\xb1"] = "\x49";
$CaseConversions["\xc5\xbf"] = "\x53";

# the new function
$AsSpacedFunction = 'AsSpacedUTF';
function AsSpacedUTF($text)
{
  global $CaseConversions;
  static $lower, $upper;
  if(!@$CaseConversions) return AsSpaced($text);
  if (!@$lower) {
    $lower = implode('|', array_keys($CaseConversions));
    $upper = implode('|', array_values($CaseConversions));
  }

  $text = preg_replace("/($lower|\\d)($upper)/", '$1 $2', $text);
  $text = preg_replace('/(?<![-\\d])(\\d+( |$))/',' $1',$text);
  return preg_replace("/($upper)(($upper)($lower|\\d))/",
    '$1 $2', $text);
}

# A 'Page not found' variable redefined
$FmtPV['$RequestedPage'] = "'".htmlspecialchars($pagename, ENT_QUOTES)."'";

# a html header (for buggy browsers or when a page is saved to hdd)
$HTMLHeaderFmt['metacontent'] =
    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';

This should make {$Namespaced}, {$Titlespaced} and {$Groupspaced} work in pages, skins and pagelists, and also fix some other inconveniences related to the UTF-8 encoding.


You can vote for this function to be included in the PmWiki Core at PITS.00875.


Other tips

See UTF-8, the section was moved there.

Comments

See Also

Contributors

  • Petko adapted for UTF8 the original AsSpaced function from Pm.