Extension:AsteriskDialNumber

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
AsteriskDialNumber

Release status: unmaintained

Implementation Tag, User identity
Description Embeds any number in in an html tag (with current username) so that it can inititate a phone call through an Asterisk PBX
Author(s) Peter Steinbach (stony999talk)
Latest version 0.1 (2008-02-12)
Database changes No
License No license specified
Download see code below
Example <tel>012345678</tel>
Parameters
  • $url_pbx
Tags
<tel>

Translate the AsteriskDialNumber extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

The AsteriskDialNumber extension embeds any number in in an html tag (with current username) so that it can inititate a phone call through an Asterisk PBX.

The purpose of this extension is for intranet use. When a user is logged in with his username then a script on the Asterisk PBX can assign this username to a phone no. The asterisk PBX is then able to make a call from the phone no of the caller to the number between the <tel> tags.

This way you can easily build up a phone directory with click to dial functions. (Example: We have modified the SQL2Wiki extension in a way that all numbers starting will e.g. "0" and a certain length will automatically be wrapped with these tags. Thus you can extract your phone directory from your (MySQL) database and have click2dial for all numbers)

Usage[edit | edit source]

Enable <tel> Tag in MediaWiki page e.g <tel>01234 5678</tel>. For all logged in users this will generate a link to a Asterisk callback function via HTML, eg.

  <a href="http://your_asterisk_server.com/callback.php?user=MyName&dial=012345678">01234 5678 (call directly)</a>

All users who are not logged in, only see the plain number as shown between the tags.

The callback function on the asterisk server has to lookup the username, get the callback no of the logged and has to call this callback no. After picking up the phone the destination number shall be dialed. (there are several solutions available for that, e.g. in the Trixbox edition).

Installation[edit | edit source]

  • Copy the code into a file and extract the file(s) in a directory called AsteriskDialNumber in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/AsteriskDialNumber/AsteriskDialNumber.php";
$url_pbx="http://your_asterisk_server.com/callback.php"; // Please change the URL for your Asterisk server.
  • Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

Configuration[edit | edit source]

Please change the URL for your Asterisk server.

User rights[edit | edit source]

You can use it at your own risk. Please take care that you do not open free calls for registered users who are not allowed to. This extension therefore should only be used in an intranet environment.

Code[edit | edit source]

<?php
// enable tel Tag in MediaWiki page e.g <tel>0800 123456</tel>
// For all logged in users this will generate a link to a Asterisk callback function
// This callback function (e.g. on the asterisk server has to lookup the username of the logged in user and assign it to a callback no.
// After picking up the phone of the user the destination number shall be dialed.

# Confirm MW environment
if (defined('MEDIAWIKI')) {

    # Credits
   $wgExtensionCredits['parserhook'][] = array(
    'name'=>'Asterisk Telefone Callback Tag',
    'author'=>'Peter Steinbach',
    'url'=>'https://www.mediawiki.org/wiki/Extension:AsteriskDialNumber',
    'description'=>'Provides a callback URL to Asterisk PBX.',
    'version'=>'0.1'
);

# Register Extension initializer
$wgExtensionFunctions[] = "wfTelephoneExtension";

# Extension initializer
function wfTelephoneExtension() {
    global $wgParser, $wgMessageCache;
    $wgParser->setHook( "tel", "rendertelTag" );
    $wgMessageCache->addMessage('teltag-bad-id', 'Invalid tel no supplied: [$1]');
}

/**
 * Very simple check if string is not an IP address (V4)
*/

  function is_no_ip($int_ip)
  {
      $arr = split("[\.]", $int_ip);
      if (count($arr)==4) {
        return false;
      }else{
        return true;
      }
  }
/**
 * Callback function for calling.
 * @param String $input Text between open and close tags - contains the phone number
 * @param Array $params Array of tag attributes. (unused)
 * @param Parser $parser Instance of Parser performing the parse.
 */

function rendertelTag( $input, $params, &$parser ) {

    $url_pbx="http://your_asterisk_server.com/callback.php";

    # Check for 'nr' parameter and ensure it has a valid value
   $org_nr = $input; // for later use
    # allow only digits 0..9
   $nr = preg_replace('/[^0-9]/', '', $input);
    if ($nr==null || $nr=="") {
        return '<div class="errorbox">'.wfMsgForContent('teltag-bad-id', $nr).'</div>';
    }
    # get login name of current user
   $name = $GLOBALS['wgUser']->mName;
    $parser->disableCache(); # Mark this content as uncacheable
   # Build URL and if user is logged in, otherwise only return the phone number
   if ($name &&  is_no_ip($name)){
        $url1 = $url_pbx . "?user=$name&dial=$nr";
        return "<a href=\"$url1\">$org_nr (call directly)</a>";
    } else {
        return $org_nr;
    }
}

}