Subversion Repositories oidplus

Rev

Rev 1243 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. namespace ViaThinkSoft\OIDplus;
  21.  
  22. // phpcs:disable PSR1.Files.SideEffects
  23. \defined('INSIDE_OIDPLUS') or die;
  24. // phpcs:enable PSR1.Files.SideEffects
  25.  
  26. class OIDplusObjectTypePluginOid extends OIDplusObjectTypePlugin
  27.         implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6 /* gridGeneratorLinks */
  28. {
  29.  
  30.         /**
  31.          * @return string
  32.          */
  33.         public static function getObjectTypeClassName(): string {
  34.                 return OIDplusOid::class;
  35.         }
  36.  
  37.         /**
  38.          * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6
  39.          * @param OIDplusObject $objParent
  40.          * @return string
  41.          */
  42.         public function gridGeneratorLinks(OIDplusObject $objParent): string {
  43.                 if ($objParent->nodeId() === 'oid:2.25') {
  44.                         return '<br><a href="javascript:OIDplusObjectTypePluginOid.generateRandomUUID(false)">('._L('Generate a random UUID OID').')</a>';
  45.                 } else if ($objParent->isRoot()) {
  46.                         return '<br><a href="javascript:OIDplusObjectTypePluginOid.generateRandomUUID(true)">('._L('Generate a random UUID OID').')</a>'.
  47.                                '<br><a href="https://hosted.oidplus.com/viathinksoft/?goto=oidplus%3Acom.viathinksoft.freeoid" target="_blank">('._L('Request a free OID from ViaThinkSoft').')</a>'.
  48.                                '<br><a href="https://pen.iana.org/pen/PenApplication.page" target="_blank">('._L('Request a free PEN/OID from IANA').')</a>';
  49.                 } else {
  50.                         // No generation for normal OIDs atm. TODO: MAYBE in the future a feature like "next free / sequencial OID"
  51.                         return '';
  52.                 }
  53.         }
  54.  
  55.         /**
  56.          * @param string $static_node_id
  57.          * @param bool $throw_exception
  58.          * @return string
  59.          * @throws OIDplusException
  60.          */
  61.         public static function prefilterQuery(string $static_node_id, bool $throw_exception): string {
  62.                 // Convert WEID to OID
  63.                 // A WEID is just a different notation of an OID.
  64.                 // To allow that people use OID-IP or the GoTo-box with a "weid:" identifier, rewrite it to "oid:", so that the plugin OIDplusObjectTypePluginOid can handle it.
  65.                 if (str_starts_with($static_node_id,'weid:') && class_exists('\Frdl\Weid\WeidOidConverter')) {
  66.                         $ary = explode('$', $static_node_id, 2);
  67.                         $weid = $ary[0];
  68.                         $oid = \Frdl\Weid\WeidOidConverter::weid2oid($weid);
  69.                         if ($oid === false) {
  70.                                 if ($throw_exception) throw new OIDplusException(_L('This is not a valid WEID'));
  71.                         } else {
  72.                                 $ary[0] = $oid;
  73.                                 $static_node_id = 'oid:'.implode('$', $ary);
  74.                         }
  75.                 }
  76.  
  77.                 // Special treatment for OIDs: if someone enters an OID in the goto box,
  78.                 // prepend "oid:"
  79.                 if (sanitizeOID($static_node_id) !== false) {
  80.                         $static_node_id = 'oid:'.$static_node_id;
  81.                 }
  82.  
  83.                 return $static_node_id;
  84.         }
  85.  
  86. }
  87.