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. // TODO: use oidinfo api phps
  10. // TODO: output warning if OID is illegal!
  11.  
  12. class OIDInfoFieldExtender implements OIDPlusFieldExtenders {
  13.         public static function getURL($oid) {
  14.                 if ($oid[0] == '.') {
  15.                         $oid = substr($oid, 1);
  16.                 }
  17.  
  18.                 return 'http://www.oid-info.com/get/'.$oid;
  19.         }
  20.  
  21.         // currently not used
  22.         public static function oidMayBeCreated($oid) {
  23.                 if ($oid[0] == '.') {
  24.                         $oid = substr($oid, 1);
  25.                 }
  26.  
  27.                 # Ping API
  28.                 $v = @file_get_contents('https://www.viathinksoft.de/~daniel-marschall/oid-repository/ping_oid.php?oid='.$oid);
  29.                 $v = substr($v, 1, 1);
  30.                 if (trim($v) === '1') return true;
  31.                 if (trim($v) === '0') return false;
  32.  
  33.                 // TODO: exception
  34.                 return null;
  35.         }
  36.  
  37.         public static function oidAvailable($oid) {
  38.                 if ($oid[0] == '.') {
  39.                         $oid = substr($oid, 1);
  40.                 }
  41.  
  42.                 # Ping API
  43.                 $v = @file_get_contents('https://www.viathinksoft.de/~daniel-marschall/oid-repository/ping_oid.php?oid='.$oid);
  44.                 $v = substr($v, 0, 1);
  45.                 if (trim($v) === '2') return true; // existing and approved
  46.                 if (trim($v) === '1') return false; // not approved
  47.                 if (trim($v) === '0') return false; // not existing
  48.  
  49.                 # Fallback
  50.                 $url = self::getURL($oid);
  51.                 $responsecode = get_http_response_code($url);
  52.                 return ($responsecode == 200);
  53.         }
  54.  
  55.         public static function processOID($oid, &$out, &$oidplusobj) {
  56.                 if (self::oidAvailable($oid)) {
  57.                         $url = self::getURL($oid);
  58.                         $out[] = "cross-ref:$url";
  59.                 }
  60.         }
  61. }
  62.  
  63. require_once __DIR__ . '/../../core/2_OIDPlus.class.php';
  64. OIDPlus::registerFieldExtender(new OIDInfoFieldExtender());
  65.  
  66. # ---
  67.  
  68. # TODO: -> functions.inc.php
  69. function get_http_response_code($theURL) {
  70.         # http://php.net/manual/de/function.get-headers.php#97684
  71.         $headers = get_headers($theURL);
  72.         return substr($headers[0], 9, 3);
  73. }
  74.