Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. # if (!interface_exists('OIDPlusFieldExtenders')) throw new Exception('Required interface "OIDPlusFieldExtenders" not found.');
  4. # if (!class_exists('OIDPlus')) throw new Exception('Required class "OIDPlus" not found.');
  5.  
  6. require_once __DIR__ . '/../../core/OIDPlusFieldExtenders.class.php';
  7. require_once __DIR__ . '/../../includes/uuid_utils.inc.php';
  8.  
  9. class UUIDFieldExtender implements OIDPlusFieldExtenders {
  10.         public static function processOID($oid, &$out, &$oidplusobj) {
  11.                 $r = oid_to_uuid($oid);
  12.  
  13.                 if ($r === false) {
  14.                         $uuid_level = 0;
  15.                 } else {
  16.                         if (oid_depth($oid) == 2) {
  17.                                 $uuid_level = 1;
  18.                         } else {
  19.                                 $uuid_level = 2;
  20.                         }
  21.                 }
  22.  
  23.                 # TODO: more configuration values, e.g. to hide namebased UUIDs
  24.  
  25.                 if (($uuid_level == 0) || ($uuid_level == 2) || ($oidplusobj->getConfigValue('namebased_uuids_for_pure_uuids') == '1')) {
  26.                         $out[] = 'namebased-uuid-sha1:'.gen_uuid_sha1_namebased(UUID_NAMEBASED_NS_OID, $oid);
  27.                         $out[] = 'namebased-uuid-md5:'.gen_uuid_md5_namebased(UUID_NAMEBASED_NS_OID, $oid);
  28.                 }
  29.                 if ($uuid_level == 1) {
  30.                         $out[] = 'uuid:'.$r;
  31.                 }
  32.                 if ($uuid_level == 2) {
  33.                         $out[] = 'origin-uuid:'.$r;
  34.                 }
  35.         }
  36. }
  37.  
  38. require_once __DIR__ . '/../../core/2_OIDPlus.class.php';
  39. OIDPlus::registerFieldExtender(new UUIDFieldExtender());
  40.