Dominique De Cooman
Gepubliceerd op Dominique De Cooman (https://dominiquedecooman.com)

Home > Hoe kunt u e-mail en andere tekst verduisteren door middel van signwriter en een cck formatter

Dominique De Cooman
woensdag, August 11, 2010 - 14:19

Hier is een voorbeeld hoe u e-mailadressen kunt verduisteren (of andere tekst) door http://drupal.org/project/signwriter [1] in een formatter te gebruiken. U kunt het op het cck field overview als een formatter gebruiken (of in display suite).

<?php
//cck formatters
/**
 * Implementation of hook_field_formatter_info(),.
 */
function your_module_field_formatter_info() {
  return array(
    
'text_as_image' => array(
      
'label' => t('Text as image'),
      
'field types' => array('email', 'text'),
      
'multiple values' => CONTENT_HANDLE_MODULE,
    ),
  );
}

/**
 * Implementation of hook_theme().
 */
function your_module_theme() {
  
$theme_functions['your_module_formatter_text_as_image'] = array (
    
'arguments' => array('element' => NULL),
  );

  return 
$theme_functions;
}

/**
 * Themes an image from text
 */
function theme_your_module_formatter_text_as_image($element) {
  
// Set up signwriter profile    
  
$profile->fontfile = drupal_get_path('module', 'signwriter'). '/Arial.TTF';//See this issue why its like this (<a href="http://drupal.org/node/606670">http://drupal.org/node/606670</a>)
  
$profile->fontsize = 10;
  
$profile->foreground = '000000';
  
$profile->background = 'ffffff';
  
$profile->maxwidth = 600;
  
$profile->transparent = true;
  
$profile->imagetype = 'png';
  
$profile->disable_span = true;
  
  
$string_to_obscure = $element[0]['#item']['safe']; 
    
  
$text= signwriter_title_convert($string_to_obscure, $profile);
  
//Some extra logic if it is an email    
  
$output = preg_replace('/alt="[0-9a-zA-Z!@#\$%^&\*~\-\.\+\_\/=\?\|\{\}}]+"/','alt="Email Address"',$text);
    
  return 
$output;
}
?>

De code in de formatter is afkomstig uit het volgende voorbeeld
http://dominiquedecooman.com/bookmark/obscure-email-adresses-drupal-usin... [2]


Bron-URL: https://dominiquedecooman.com/nl/hoe-kunt-u-e-mail-en-andere-tekst-verduisteren-door-middel-van-signwriter-en-een-cck-formatter

Links
[1] http://drupal.org/project/signwriter
[2] http://dominiquedecooman.com/bookmark/obscure-email-adresses-drupal-using-signwriter