Extension/EmailTag
Zur Navigation springen
Zur Suche springen
Extension
{{Extension
|name=EmailTag
|purpose=Protects email addresses from spam using
Source Code 2021
<?php
/**
* Copyright (C) 2021 Dr. Jesper Zedlitz
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* @package MediaWiki
* @subpackage Extensions
* @author Dr. Jesper Zedlitz <jesper at zedlitz dot de>
* @copyright © 2022 Dr. Jesper Zedlitz
*/
if (!defined('MEDIAWIKI')) die();
/* email tag */
$wgExtensionFunctions[] = 'wfEmailTag';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'EmailTag',
'author' => 'Jesper Zedlitz',
'version' => '0.1',
'url' => ''
);
function wfEmailTag() {
global $wgParser;
$wgParser->setHook( "email", "wfEmailTagDoit" );
}
function wfEmailTagDoit($text="") {
$size=4;
$fontwidth = imagefontwidth($size);
$fontheight = imagefontheight($size);
$width = strlen($text) * $fontwidth + 4;
$height = $fontheight + 2;
$im = @imagecreatetruecolor ($width, $height) or exit;
$trans = imagecolorallocate ($im, 255,255,255); /* must be black! */
$color = imagecolorallocate ($im, 1,1,1); /* nearly black ;) */
imagefill ( $im, 0, 0, $trans );
imagestring($im, $size, 2, 0, $text, $color);
ob_start();
imagepng($im);
$image_data = ob_get_contents();
ob_end_clean();
imageDestroy($im);
$png = base64_encode($image_data);
$text = "<img src=\"data:image/png;base64,$png\" alt=\"some mail\" />";
return $text;
}