Thanks skenow. I also found gd_info() works. In the end I've decided not to do this right now.
The extension to the XoopsObject::getVar() in /kernel/object.php is as follows
function getVar($key, $format = 's')
{
...
case XOBJ_DTYPE_TXTBOX:
switch (strtolower($format)) {
//the next six lines added by Rob Stockley for image conversion
case 'i':
case 'image':
$ts =& MyTextSanitizer::getInstance();
$e_enc = strencode($ts->htmlSpecialChars($ret).'|8');
return '.XOOPS_URL.'/include/swirl.php?data='.$e_enc.'">';
break 1;
case 's':
case 'show':
...
Essentially all I've done is add a new output format for XOBJ_DTYPE_TXTBOX type fields. If you use the format on other types it will be ignored and the default option output instead. Email, ICQ, and MSNM are all TXTBOXes so this seems like enough.
Now all I have to do in /userinfo.php is specify the output format as 'I' like so.
...
$xoopsTpl->assign('lang_icq', _US_ICQ);
$xoopsTpl->assign('user_icq', $thisUser->getVar('user_icq', 'I'));
...
if ($thisUser->getVar('user_viewemail') == 1) {
$xoopsTpl->assign('user_email', $thisUser->getVar('email', 'I'));
} else {
if (is_object($xoopsUser)) {
// All admins will be allowed to see emails, even those that are not allowed to edit users (I think it's ok like this)
if ($xoopsUserIsAdmin || ($xoopsUser->getVar("uid") == $thisUser->getVar("uid"))) {
$xoopsTpl->assign('user_email', $thisUser->getVar('email', 'I'));
...
I commented out all my previous email tags in module.textsanitiser and added the following near the end of xoopsCodeDecode()
$text = preg_replace($patterns, $replacements, $text);
// lastly decode the email tags added by Rob Stockley 25 May 07
$e_pattern = "/[email]([^;<>*()"']*)[/email]/sU";
$e_matches = array();
while (preg_match($e_pattern, $text, $e_matches) != 0) {
$e_enc = strencode($e_matches[1].'|8');
$e_repl = '<img src="'.XOOPS_URL.'/include/swirl.php?data='.$e_enc.'">';
$text = preg_replace($e_pattern, $e_repl, $text, 1);
}
$e_pattern = "/[email=(['"]?)([0-9]*)\1]([^;<>*()"']*)[/email]/sU";
while (preg_match($e_pattern, $text, $e_matches) != 0) {
$e_enc = strencode($e_matches[3].'|'.$e_matches[2]);
$e_repl = '<img src="'.XOOPS_URL.'/include/swirl.php?data='.$e_enc.'">';
$text = preg_replace($e_pattern, $e_repl, $text, 1);
}
return $text;
The beginning of swirl.php has changed a little to cope with the encoding of email adresses.
/* script adapted by Rob Stockley from example published at
* http://nz2.php.net/manual/en/function.imagestring.php
* by brooks dot boyd at gmail dot com
*/
include './functions.php';
if ($_GET['data'] != "") {
$data = explode("|", strdecode($_GET['data']));
$msg = $data[0];
$size = intval($data[1]);
if ($size > 16) $size = 16;
if ($size < 8) $size = 8;
// you need to make sure this font file exists
$font = '/usr/share/fonts/truetype/ttf-bitstream-vera/VeraMono.ttf';
...
Lastly you'll notice that I've referred to a pair of functions named strencode() and strdecode(). These do some pretty basic character based obfuscation so that the html source bears no resemblance to an email address. I tacked them on to the end of /include/functions.php so that they'd be in scope for all.
So anyway this approach has worked for me. I can now display text fields and emails enclosed with xoopsCode tags all as images. The default size for fields is hardcoded while the xoopsCode take a size variable between 8 and 16.
Enjoy,
Rob