Skip to content

Instantly share code, notes, and snippets.

@webbingstudio
Last active May 15, 2018 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbingstudio/39df7a19df26889c45cb71f0ef156f57 to your computer and use it in GitHub Desktop.
Save webbingstudio/39df7a19df26889c45cb71f0ef156f57 to your computer and use it in GitHub Desktop.
a-blog cmsのエントリー位置リストの距離表示を最適化する校正オプション ref: https://qiita.com/webbingstudio@github/items/e8482ce9429350684656
class ACMS_User_Corrector
{
/**
* distance
* 数値を距離に変換する
*
* @param string $txt - 校正オプションが適用されている文字列
* @return string - 校正後の文字列
*/
public static function distance($txt, $args = array())
{
// 例 {var}[distance(2)]
// {var}は強制的に数値に変換される
// 1000未満の場合は単位がm
// 1000以上の場合は単位がkm
// 引数: 丸める小数点の位、指定なしの場合は1
$round = isset($args[0]) ? (int)$args[0] : (int)1;
if ( (float)$txt >= 1000 ) {
return round( ( (float)$txt / 1000 ) , $round ) . 'km';
} else {
return $txt . 'm';
}
}
}
class ACMS_User_Corrector
{
// ここに校正オプションを書くと追加される
}
{geo_distance}[distance]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment