# 2022-12-22 Initial version based on Petko Yotov's code snippet at https://www.pmwiki.org/wiki/Cookbook/LinkTel-Talk */ DEFINE ('AUTOTELNAME', 'AutoTel'); if (substr(__NAMESPACE__, -3) === 'new') { $AutoTelNew = 'new'; # empty string for production version, 'new' for development version } # if (boolval($DisableRecipe[AUTOTELNAME]) === true) return; # set debug flag \SDV($AutoTelDebug, false); # set default debug setting if not defined in an configuration file $AutoTel_debugon = boolval ($AutoTelDebug); # if on writes input and output to web page # Version date $RecipeInfo[AUTOTELNAME]['Version'] = '2022-12-22' . $AutoTelNew; # PmWiki version numbering is done by date # recipe version page variable $FmtPV['$AutoTelVersion'] = "'" . __NAMESPACE__ . " version {$RecipeInfo[AUTOTELNAME]['Version']}'"; // return version as a custom page variable # declare $AutoTel for (:if enabled AutoTel:) recipe installation check $AutoTel = true; # enabled ## ## get configuration defaults \SDV($AutoTelConfig, array( 'CountryCodeDefault' => '+64', 'AreaCodeDefault' => '4', )); # # the following characters cannot be immediately before a telephone number # telephone number cannot start in the middle of a number DEFINE ('IGNOREPREFIX', '# not preceded by [, :, =, #, apos, quote, 0-9, or 0-9 followed by a space (?links', $MarkupPatternLand, __NAMESPACE__ . '\AutoTelFmt'); ## ## $MarkupPatternMobile = '/' . IGNOREPREFIX # optional country code followed by optional visual separator . COUNTRYCODE . VISUALSEPARATOR . '?' # area code mobile, optionally in (parenthesis), followed by mandatory visual separator . '[\\(]?' . AREACODE_MOBILE . '(?:[\\)]?|[\\)]?' . VISUALSEPARATOR . ')' . SUBSCRIBERNUMBER_MOBILE . IGNORESUFFIX . '/xi'; ## for mobile, requires area code and subscriber number (must be second call) Markup('autotel_mobile', '>links', $MarkupPatternMobile, __NAMESPACE__ . '\AutoTelFmt'); # return; # finished recipe setup # function AutoTelFmt($m) { # process telephone number when detected global $AutoTelConfig; $ccode = @$m[1]? $m[1] : $AutoTelConfig['CountryCodeDefault']; # add country code if unset $acode = @$m[2]? $m[2] : $AutoTelConfig['AreaCodeDefault']; # area code if unset if(!@$m[1]) $acode = preg_replace('/^0/','',$acode); # trim area code leading zero $remspace = array (' ', ' ', '-', '‑'); # remove embedded separators $subnr = str_replace ($remspace, '', $m[3]); # add visual separator $subnr = substr_replace ($subnr, '-', intdiv (strlen ($subnr), 2), 0); # build dialable number with visual separators $telval = "$ccode($acode)$subnr"; $remsep = array (' ', '-'); # separators to be replaced $replsep = array (' ', '‑'); # non-breaking space and hyphen $displaynr = str_replace ($remsep, $replsep, $m[0]); $disptitle = \XL('Dial') . ' ' . $telval; return Keep("$displaynr"); }