Recent Changes - Search:

add Cookbook page

hide

Cookbook


hide

Topics


show

Changed

Visitor's book Site map pmwiki-2.3.32

Auto Tel

To do
  • change skiwi
  • remove this comment

AutoTelnew version 2024-02-20new

Summary: A recipe to automatically detect and markup telephone numbers
Version: 2022-02-20
Prerequisites: PmWiki 2.3.17; PHP 8
Status: Alpha
Maintainer: skiwi
Licence: GPL3#
Categories: Links, Markup, Media, Mobile
Users: (view / edit)
Discussion: AutoTel-Talk

Questions answered by this recipe

How can I make the telephone and mobile phone numbers on my wiki dialable?

Description

This recipe automatically detects service, mobile, and land phone numbers. These phone numbers are for a New Zealand context, but if the demand is there it can be upgraded for other countries. The telephone numbers are wrapped in an anchor element using the "tel:" URI scheme. This enables calling by clicking on the link where supported by a device.

The tel: number in the link is formatted with the hyphen visual separator before area code and subscriber number. The user supplied text is displayed unchanged, but spaces and hyphens are converted to their non-breaking equivalents to avoid the number wrapping.

To recognise a telephone number a visual indicator or separator is required. These include:

  • the "+" of the country code followed by a one to three digit country code
  • optional (parenthesis) around the area code
  • a single visual separator before or after the area code, or in the subscriber number
  • a visual separator is a single space or hyphen

Land and mobile numbers have a different syntax

  • country code and area code are optional for land numbers
  • area code is mandatory for mobile numbers

This recipe is based on Petko Yotov's code snippet from Cookbook:LinkTel-Talk tarted up a bit to improve the matching and delivered in a recipe format. Note it still have a few false positives, but no known false negatives.

Installation

include_once($FarmD/cookbook/autotel.php);

Usage

No changes are required to PmWiki pages, however to improve matching and to reduce false positives some telephone number reformatting may be required.

To limit the scope of this recipe install it as a group or page recipe.

The recipe provides a page variable {$AutoTelVersion} which contains the current version, and page variable {$AutoTel} for a (:if enabled AutoTel:) recipe installation check.

The recipe may create false positive matches of telephone numbers. If this is the case Cookbook:LinkTel may be a better match for your requirements.

Limited configuration can be performed from the config file.

AutoTelConfig = array(
    'CountryCodeDefault' => '+64',
    'AreaCodeDefault' => '4',
    'LongDistancePrefixDefault' => '0');

The following string can be internationalised:

  • Dial

Details

To attempt to constrain the automatic detection of telephone numbers

  • telephone numbers cannot be prefixed by
    colon, [, =, #, ), apos, quote, or 0-9; or 0-9 or ) followed by a space
  • telephone numbers cannot be suffixed by
    0-9; or 0-9 followed by a space

Service number

A service number, e.g. 0800 123 456 or 0508 765 4321, is composed as follows:

a service code, optionally in (parenthesis)
a mandatory visual separator or bracket
a subscriber number, the mobile subscriber number pattern is used

Mobile number

A mobile number, e.g. 012 345 6789, is composed as follows:

optional country code, e.g. +64 or (+64)
area code mobile, optionally in (parenthesis)
a mandatory visual separator
a subscriber number, the mobile subscriber number pattern is used

Land line number

A land line number, e.g. 01 234 5678, is composed as follows:

and optional country code and area code
a subscriber number, the land line subscriver number pattern is used

Change log / Release notes

2024-02-20 Updates to improve rexex matching, and to documentation 2023-12-29 Updates to improve regex matching 2022-12-22 Initial version based on Petko Yotov's code snippet at Cookbook:LinkTel-Talk

See also

tahi Page last modified on 2024 Feb 18 10:09

Edit - History - Recent Changes - WikiHelp - Search - email page as link -> mailto:?Subject="KiwiWiki: Auto Tel"&Body=