function _encryptfapi_decrypt_element in Encrypt Form API 7.2
Helper function to recursively process an element for decryption.
Parameters
$element: The element to process.
1 call to _encryptfapi_decrypt_element()
- encryptfapi_form_alter in ./
encryptfapi.module - Implements hook_form_alter().
File
- ./
encryptfapi.module, line 129 - Main module file for Encrypt Form API.
Code
function _encryptfapi_decrypt_element(&$element) {
$element_types =& drupal_static(__FUNCTION__);
if (!isset($element_types)) {
$element_types = _encryptfapi_supported_element_types();
}
foreach (element_children($element) as $key) {
$child =& $element[$key];
if (is_array($child)) {
_encryptfapi_decrypt_element($child);
}
// If the element is not marked for encryption or if it's not a type
// supported by this module, skip it.
if (!isset($child['#encrypt']) || $child['#encrypt'] != TRUE || !in_array($child['#type'], $element_types)) {
continue;
}
// If the value is empty, skip it.
if (empty($child['#default_value'])) {
// If the field accepts multiple values, make sure that the value is
// an array.
if ($child['#type'] == 'checkboxes') {
$child['#default_value'] = array();
}
continue;
}
// If the element has already been decrypted, skip it.
if (isset($child['#decrypted']) && $child['#decrypted'] == TRUE) {
continue;
}
// If the value does not appear to be encrypted, skip it.
$unserialized = @unserialize($child['#default_value']);
if ($unserialized === FALSE || !isset($unserialized['method']) || !isset($unserialized['key_provider'])) {
continue;
}
$child['#default_value'] = decrypt($child['#default_value']);
// If the decrypted text is serialized, unserialize it.
$unserialized = @unserialize($child['#default_value']);
if ($unserialized !== FALSE) {
$child['#default_value'] = $unserialized;
}
$child['#decrypted'] = TRUE;
}
}