2008-06-11 08:29:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Extension - URL widget: email addresses, external url's, clickable telephone numbers
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Extension - URL widget: email addresses, external url's, clickable telephone numbers
|
|
|
|
*
|
|
|
|
* url:
|
|
|
|
* External URL with target _blank (http:// get's added, if there's no protocol)
|
|
|
|
* Uses our redirect.php script, if session is not stored in cookie!
|
|
|
|
*
|
|
|
|
* url-email:
|
|
|
|
* The value is an RFC822 email address or an interger account_id.
|
|
|
|
* If the value is empty or 0, the content of the options field is used instead.
|
|
|
|
* The address get displayed as name with the email as tooltip and a link to compose a mail.
|
|
|
|
*
|
|
|
|
* url-telefon:
|
|
|
|
* Displays a telephone number.
|
|
|
|
* If telephony integration is configured in addressbook, make the phone number a link to allow to call it.
|
|
|
|
* @todo Input validation and normalization of phone numbers
|
|
|
|
*/
|
|
|
|
class url_widget
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* exported methods of this class
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* availible extensions and there names for the editor
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $human_name = array(
|
|
|
|
'url' => 'Url',
|
|
|
|
'url-email' => 'EMail',
|
|
|
|
'url-phone' => 'Phone number',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of the extension
|
|
|
|
*
|
|
|
|
* @param string $ui '' for html
|
|
|
|
*/
|
|
|
|
function __construct($ui)
|
|
|
|
{
|
|
|
|
$this->ui = $ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pearl regular expression for email address
|
|
|
|
*
|
|
|
|
* has to be used case insensitive: /i
|
|
|
|
*/
|
2010-05-06 10:02:32 +02:00
|
|
|
//const EMAIL_PREG = '([a-z0-9][a-z0-9._-]*)?[a-z0-9]@([a-z0-9](|[a-z0-9_-]*[a-z0-9])\.)+[a-z]{2,6}';
|
2010-07-23 14:10:52 +02:00
|
|
|
const EMAIL_PREG = '([a-z0-9][a-z0-9._-]*)?[a-z0-9_-]@([a-z0-9ÄÖÜäöüß](|[a-z0-9ÄÖÜäöüß_-]*[a-z0-9ÄÖÜäöüß])\.)+[a-z]{2,6}';
|
2008-06-11 08:29:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* pre-processing of the extension
|
|
|
|
*
|
|
|
|
* This function is called before the extension gets rendered
|
|
|
|
*
|
|
|
|
* @param string $name form-name of the control
|
|
|
|
* @param mixed &$value value / existing content, can be modified
|
|
|
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
|
|
|
* @param array &$readonlys names of widgets as key, to be made readonly
|
|
|
|
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
|
|
|
* @param object &$tmpl reference to the template we belong too
|
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
|
|
|
{
|
|
|
|
$readonly = $cell['readonly'] || $readonlys;
|
|
|
|
|
2008-11-13 17:50:05 +01:00
|
|
|
switch($cell['type'])
|
2008-06-11 08:29:41 +02:00
|
|
|
{
|
|
|
|
case 'url-email': // size: size,max-size,{2=no validation,1=rfc822 name part allowed, default only email},default if value empty
|
|
|
|
list($size,$max_size,$validation_type,$default) = explode(',',$cell['size'],4); // 4 = allow default to contain commas
|
|
|
|
if (!$value) $value = $default; // use default from size/options if empty
|
|
|
|
$cell['no_lang'] = 1;
|
|
|
|
|
|
|
|
if (!$readonly)
|
|
|
|
{
|
|
|
|
$cell['type'] = 'text';
|
|
|
|
$cell['size'] = $size.','.$max_size.',';
|
|
|
|
if ((int)$validation_type < 2)
|
|
|
|
{
|
|
|
|
$cell['size'] .= $cell['needed'] ? '/^(' : '/^(|'; // if not needed allow empty, as EMAIL_PREG does not
|
|
|
|
$cell['size'] .= self::EMAIL_PREG;
|
|
|
|
if ($validation_type == 1) // allow rfc822 name part too: Ralf Becker <ralf@out.de>
|
|
|
|
{
|
|
|
|
$cell['size'] .= '|[^<]+ ?<'.self::EMAIL_PREG.'>';
|
|
|
|
}
|
2011-06-30 17:19:08 +02:00
|
|
|
$cell['size'] .= ')$/i,email';
|
2008-07-30 13:08:51 +02:00
|
|
|
}
|
2008-06-30 16:30:16 +02:00
|
|
|
#_debug_array($cell);
|
2008-06-11 08:29:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
$rfc822 = $value;
|
2008-07-14 08:29:57 +02:00
|
|
|
if (!(int)$size) $size = 22; // default size for display
|
2008-06-11 08:29:41 +02:00
|
|
|
if (is_numeric($value))
|
|
|
|
{
|
|
|
|
$email = $GLOBALS['egw']->accounts->id2name($value,'account_email');
|
|
|
|
$value = $GLOBALS['egw']->accounts->id2name($value,'account_fullname');
|
|
|
|
$rfc822 = $value.' <'.$email.'>';
|
|
|
|
}
|
|
|
|
elseif (preg_match('/^(.*) ?<(.*)>/',$value,$matches))
|
|
|
|
{
|
|
|
|
$value = $matches[1];
|
|
|
|
$email = $matches[2];
|
|
|
|
}
|
|
|
|
elseif (strpos($email=$value,'@') !== false)
|
|
|
|
{
|
2008-07-30 13:08:51 +02:00
|
|
|
if (strpos($email=$value,'&') !== false)
|
2008-07-14 08:29:57 +02:00
|
|
|
{
|
2008-06-30 16:30:16 +02:00
|
|
|
list($email,$addoptions) = explode('&',$value,2);
|
|
|
|
$rfc822 = $value = $email;
|
|
|
|
}
|
2008-07-14 08:29:57 +02:00
|
|
|
if (strlen($value) > $size) // shorten the name to size-2 plus '...'
|
|
|
|
{
|
|
|
|
$value = substr($value,0,$size-2).'...';
|
2008-06-30 16:30:16 +02:00
|
|
|
}
|
2008-06-11 08:29:41 +02:00
|
|
|
}
|
2008-06-30 16:30:16 +02:00
|
|
|
$link = $this->email2link($email,$rfc822).($addoptions ? '&'.$addoptions : '');
|
2008-06-11 08:29:41 +02:00
|
|
|
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
$cell['size'] = ','.$link.',,,,'.($link[0]=='f'?'700x750':'').($value != $email ? ','.$email : '');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'url': // options: [size[,max-size[,preg]]]
|
2008-06-30 16:30:16 +02:00
|
|
|
list($size,$max_size,$preg) = explode(',',$cell['size'],3); // 3 = allow default to contain commas
|
2008-06-11 08:29:41 +02:00
|
|
|
if (!$readonly)
|
|
|
|
{
|
|
|
|
$cell['type'] = 'text';
|
2011-06-30 17:19:08 +02:00
|
|
|
$cell['size'] = "$size,$max_size,$preg,url";
|
2008-06-11 08:29:41 +02:00
|
|
|
// todo: (optional) validation
|
|
|
|
break;
|
|
|
|
}
|
2008-07-14 08:29:57 +02:00
|
|
|
if (!(int)$size) $size = 24; // default size for display
|
2008-06-11 08:29:41 +02:00
|
|
|
$cell['type'] = 'label';
|
|
|
|
if ($value)
|
|
|
|
{
|
|
|
|
$link = (strpos($value,'://') === false) ? 'http://'.$value : $value;
|
|
|
|
if (!$GLOBALS['egw_info']['server']['usecookies']) // if session-id is in url, use redirect.php to remove it from referrer
|
|
|
|
{
|
|
|
|
$link = $GLOBALS['egw_info']['server']['webserver_url'].'/redirect.php?go='.$link;
|
|
|
|
if ($link[0] == '/') $link = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$link;
|
|
|
|
}
|
|
|
|
$cell['size'] = ','.$link.',,,_blank';
|
|
|
|
}
|
2008-07-14 08:29:57 +02:00
|
|
|
if (substr($value,0,7) == 'http://')
|
|
|
|
{
|
|
|
|
$value = substr($value,7); // cut off http:// in display
|
|
|
|
}
|
|
|
|
if (strlen($value) > $size) // shorten the name to size-2 plus '...'
|
|
|
|
{
|
|
|
|
$value = substr($value,0,$size-2).'...';
|
|
|
|
}
|
2008-06-11 08:29:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'url-phone': // options: [size[,max-size[,preg]]]
|
2008-06-30 16:30:16 +02:00
|
|
|
list($size,$max_size,$preg) = explode(',',$cell['size'],3); // 3 = allow default to contain commas
|
2008-06-11 08:29:41 +02:00
|
|
|
if (!$readonly)
|
|
|
|
{
|
|
|
|
$cell['type'] = 'text';
|
2011-06-30 17:19:08 +02:00
|
|
|
$cell['size'] = "$size,$max_size,$preg,tel";
|
2008-06-11 08:29:41 +02:00
|
|
|
// todo: (optional) validation
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$cell['type'] = 'label';
|
|
|
|
if ($value)
|
|
|
|
{
|
|
|
|
$link = self::phone2link($value);
|
|
|
|
if (!$GLOBALS['egw_info']['server']['usecookies'] && substr($link,0,4) == 'http') // if session-id is in url, use redirect.php to remove it from referrer
|
|
|
|
{
|
|
|
|
$link = $GLOBALS['egw_info']['server']['webserver_url'].'/redirect.php?go='.$link;
|
|
|
|
if ($link[0] == '/') $link = ($_SERVER['HTTPS'] ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$link;
|
|
|
|
}
|
2011-05-30 16:59:40 +02:00
|
|
|
$cell['size'] = ','.$link.($GLOBALS['egw_info']['server']['call_popup']=='none' ? '' : // 'none' = no target
|
|
|
|
',,,calling,'.$GLOBALS['egw_info']['server']['call_popup']);
|
2008-06-11 08:29:41 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return True; // extra Label Ok
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert email-address in compose link
|
|
|
|
*
|
|
|
|
* @todo make the called link configurable in the user prefs, to eg. allow to allways use mailto ...
|
|
|
|
* @param string $email email-addresse
|
|
|
|
* @param string $rfc822 complete rfc822 addresse to use eg. for fmail
|
|
|
|
* @return array/string array with get-params or mailto:$email, or '' or no mail addresse
|
|
|
|
*/
|
|
|
|
static function email2link($email,$rfc822='')
|
|
|
|
{
|
|
|
|
if (!$email || strpos($email,'@') === false) return '';
|
|
|
|
|
|
|
|
if($GLOBALS['egw_info']['user']['apps']['felamimail'])
|
|
|
|
{
|
2008-06-11 09:18:29 +02:00
|
|
|
//return 'felamimail.uicompose.compose&preset[to]='.($rfc822 ? $rfc822 : $email);
|
2008-06-11 08:29:41 +02:00
|
|
|
return 'felamimail.uicompose.compose&send_to='.base64_encode($rfc822 ? $rfc822 : $email);
|
|
|
|
}
|
|
|
|
if($GLOBALS['egw_info']['user']['apps']['email'])
|
|
|
|
{
|
|
|
|
return 'email.uicompose.compose&to='.$email;
|
|
|
|
}
|
|
|
|
return 'mailto:' . $email;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns link to call the given phonenumber
|
|
|
|
*
|
|
|
|
* replaces '%1' with the phonenumber to call, '%u' with the user's account_lid and '%t' with his work-phone-number
|
|
|
|
*
|
|
|
|
* @param string $number phone number
|
|
|
|
* @return string|boolean string with link or false if no no telephony integration configured
|
|
|
|
*/
|
|
|
|
static function phone2link($number)
|
|
|
|
{
|
2010-03-28 15:33:40 +02:00
|
|
|
static $call_link;
|
|
|
|
if (is_null($call_link))
|
2010-03-28 15:27:30 +02:00
|
|
|
{
|
2010-03-28 15:33:40 +02:00
|
|
|
// for iPhone and Android: replace evtl. configured telephony integration link with tel: protocol
|
|
|
|
if (strpos($_SERVER['HTTP_USER_AGENT'],'AppleWebKit') !== false &&
|
|
|
|
(strpos($_SERVER['HTTP_USER_AGENT'],'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'],'Android') !== false))
|
|
|
|
{
|
|
|
|
$call_link = 'tel:%1';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$call_link = (string)$GLOBALS['egw_info']['server']['call_link'];
|
|
|
|
}
|
2010-03-28 15:27:30 +02:00
|
|
|
}
|
2010-03-28 15:33:40 +02:00
|
|
|
if (empty($number) || empty($call_link)) return false;
|
2008-06-11 08:29:41 +02:00
|
|
|
|
|
|
|
static $userphone;
|
2010-03-28 15:27:30 +02:00
|
|
|
if (is_null($userphone) && strpos($call_link,'%t') !== false)
|
2008-06-11 08:29:41 +02:00
|
|
|
{
|
|
|
|
$user = $GLOBALS['egw']->contacts->read('account:'.$GLOBALS['egw_info']['user']['account_id']);
|
|
|
|
$userphone = is_array($user) ? ($user['tel_work'] ? $user['tel_work'] : $user['tel_home']) : false;
|
|
|
|
}
|
2011-03-26 16:57:24 +01:00
|
|
|
$number = preg_replace('/[^0-9+]+/','',str_replace(array('♥','(0)'),'',$number)); // remove number formatting chars messing up the links
|
2008-06-11 08:29:41 +02:00
|
|
|
|
|
|
|
return str_replace(array('%1','%u','%t'),array(urlencode($number),$GLOBALS['egw_info']['user']['account_lid'],$userphone),
|
2010-03-28 15:27:30 +02:00
|
|
|
$call_link);
|
2008-06-11 08:29:41 +02:00
|
|
|
}
|
|
|
|
}
|