HEX
Server: Apache
System: Linux dev.epsylon.net 3.10.0-1160.144.1.el7.tuxcare.els2.x86_64 #1 SMP Sun Feb 15 11:22:42 UTC 2026 x86_64
User: nexper (1054)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/nexper/www/sites/all/modules/media_gallery/fields_rsi_prevention.inc
<?php

/**
 * Decorates an entity to provide getters/setters.
 *
 * @example
 *
 * $node = new FieldRSIPreventor($node);
 *
 * // This still works,
 * $node->created
 *
 * // Gets the first value of body for LANGUAGE_NONE.
 * $node->getValue('body');
 *
 * // Gets the 2nd value of body in spanish
 * $node->getValue('body', 2, 'esp');
 */ 
class FieldsRSIPreventor {
  private $entity;
  
  function __construct($entity) {
    // Prevent this thing from chaining if people accidentally use it twice.
    if (is_a($entity, 'FieldRSIPreventor')) {
      $entity = $entity->entity;
    }
    $this->entity = $entity;
  }
  
  function getValue($field_name, $delta = 0, $language = LANGUAGE_NONE) {
    if ($item = $this->getItem($field_name, $delta, $language)) {
      return $item['value'];
    }
  }
  
  function getItem($field_name, $delta = 0, $language = LANGUAGE_NONE) {
    if (!isset($this->entity->{$field_name}[$language]) || !isset($this->entity->{$field_name}[$language][$delta])) {
      return FALSE;
    }
    return $this->entity->{$field_name}[$language][$delta];
  }
  
  function __get($key) {
    return $this->entity->{$key};
  }
  
  function __set($key, $value) {
    $this->entity->{$key} = $value;
  }
}

?>