Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 989 → Rev 990

/trunk/includes/classes/OIDplusDatabaseConnection.class.php
54,13 → 54,19
return $this->getSlang()->insert_id($this);
}
 
public final function getScalar($sql) {
public final function getTable(string $sql) {
$out = array();
$res = $this->query($sql);
while ($row = $res->fetch_array()) {
$out[] = $row;
}
return $out;
}
 
public final function getScalar(string $sql) {
$res = $this->query($sql);
$row = $res->fetch_array();
if (count($row) == 0) return null;
$keys = array_keys($row);
if (count($keys) == 0) return null;
return $row[$keys[0]];
return $row ? reset($row) : null;
}
 
public final function query(string $sql, /*?array*/ $prepared_args=null): OIDplusQueryResult {
/trunk/plugins/frdl/publicPages/altids/OIDplusPagePublicAltIds.class.php
0,0 → 1,218
<?php
 
/*
* OIDplus 2.0
* Copyright 2022 Daniel Marschall, ViaThinkSoft / Till Wehowski, Frdlweb
*
* Licensed under the MIT License.
*/
 
if (!defined('INSIDE_OIDPLUS')) die();
 
class OIDplusPagePublicAltIds extends OIDplusPagePluginPublic {
 
public function action($actionID, $params) {
 
}
 
public function gui($id, &$out, &$handled) {
 
}
 
public function publicSitemap(&$out) {
 
}
 
public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
return false;
}
 
private function cache_id() {
static $cache_id = null;
if (!is_null($cache_id)) return $cache_id;
$cache_id = 'Create='.OIDplus::db()->getScalar("select max(created) as ts from ###objects where created is not null;");
$cache_id .= '/Update='.OIDplus::db()->getScalar("select max(updated) as ts from ###objects where updated is not null;");
$cache_id .= '/Count='.OIDplus::db()->getScalar("select count(id) as cnt from ###objects;");
$plugin_versions = array();
foreach (OIDplus::getObjectTypePluginsEnabled() as $otp) {
$plugin_versions[] = '/'.$otp->getManifest()->getOid().'='.$otp->getManifest()->getVersion();
}
sort($plugin_versions);
$cache_id .= implode('',$plugin_versions);
return $cache_id;
}
 
public function readAll($noCache = false) {
static $local_cache = null;
 
$cache_file = OIDplus::localpath().'/userdata/cache/frdl_alt_id.ser';
if ($noCache === false) {
// Local cache (to save time for multiple calls during the same HTTP request)
if (!is_null($local_cache)) return $local_cache;
 
// File cache (to save time between HTTP requests)
if (file_exists($cache_file)) {
$cache_data = unserialize(file_get_contents($cache_file));
$cache_id = $cache_data[0];
if ($cache_id == $this->cache_id()) {
return $cache_data[1];
}
}
}
 
$alt_ids = array();
$rev_lookup = array();
 
$res = OIDplus::db()->query("select id from ###objects");
while ($row = $res->fetch_array()) {
$obj = OIDplusObject::parse($row['id']);
if (!$obj) continue; // e.g. if plugin is disabled
$ary = $obj->getAltIds();
foreach ($ary as $a) {
$origin = $obj->nodeId(true);
$alternative = $a->getNamespace() . ':' . $a->getId();
 
if (!isset($alt_ids[$origin])) $alt_ids[$origin] = array();
$alt_ids[$origin][] = $alternative;
 
if (!isset($rev_lookup[$alternative])) $rev_lookup[$alternative] = array();
$rev_lookup[$alternative][] = $origin;
}
}
 
$data = array($alt_ids, $rev_lookup);
 
// File cache (to save time between HTTP requests)
$cache_data = array($this->cache_id(), $data);
@file_put_contents($cache_file, serialize($cache_data));
 
// Local cache (to save time for multiple calls during the same HTTP request)
$local_cache = $data;
 
return $data;
}
 
public function getAlternativesForQuery($id/* 1.3.6.1.4.1.37476.2.5.2.3.7 signature takes just 1 param!? , $noCache = false*/) {
 
static $caches = array();
 
if(/*$noCache === false && */isset($caches[$id]) ){
return $caches[$id];
}
 
list($ns, $altIdRaw) = explode(':', $id, 2);
if($ns === 'weid'){
$id='oid:'.\WeidOidConverter::weid2oid($id);
}
 
list($alt_ids, $rev_lookup) = $this->readAll(false);
 
$res = [
$id,
];
if(isset($rev_lookup[$id])){
$res = array_merge($res, $rev_lookup[$id]);
}
foreach($alt_ids as $original => $altIds){
if($id === $original || in_array($id, $altIds) ){
$res = array_merge($res, $altIds);
$res = array_merge($res, [$original]);
}
}
 
$weid = false;
foreach($res as $alt){
list($ns, $altIdRaw) = explode(':', $alt, 2);
if($ns === 'oid'){
$weid=\WeidOidConverter::oid2weid($altIdRaw);
break;
}
}
 
if ($weid !== false) {
$res[]=$weid;
}
$res = array_unique($res);
 
$caches[$id] = $res;
 
return $res;
}
 
public function implementsFeature($id) {
if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.4') return true; // whois*Attributes
if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.7') return true; // getAlternativesForQuery
return false;
}
 
public function tree_search($request) {
return false;
}
 
public function getCanonical($id){
foreach($this->getAlternativesForQuery($id) as $alt){
list($ns, $altIdRaw) = explode(':', $alt, 2);
if($ns === 'oid'){
return $alt;
}
}
 
return false;
}
 
public function whoisObjectAttributes($id, &$out) {
// Interface 1.3.6.1.4.1.37476.2.5.2.3.4
 
$xmlns = 'oidplus-frdlweb-altids-plugin';
$xmlschema = 'urn:oid:1.3.6.1.4.1.37553.8.1.8.8.53354196964.641310544.1714020422';
$xmlschemauri = OIDplus::webpath(__DIR__.'/altids.xsd',OIDplus::PATH_ABSOLUTE);
 
$handleShown = false;
$canonicalShown = false;
 
foreach($this->getAlternativesForQuery($id) as $alt) {
 
list($ns, $altIdRaw) = explode(':', $alt, 2);
 
if (($canonicalShown === false) && ($ns === 'oid')) {
$canonicalShown=true;
 
$out[] = [
'xmlns' => $xmlns,
'xmlschema' => $xmlschema,
'xmlschemauri' => $xmlschemauri,
'name' => 'canonical-identifier',
'value' => $ns.':'.$altIdRaw,
];
 
}
 
if (($handleShown === false) && ($alt === $id)) {
$handleShown=true;
 
$out[] = [
'xmlns' => $xmlns,
'xmlschema' => $xmlschema,
'xmlschemauri' => $xmlschemauri,
'name' => 'handle-identifier',
'value' => $alt,
];
 
}
 
$out[] = [
'xmlns' => $xmlns,
'xmlschema' => $xmlschema,
'xmlschemauri' => $xmlschemauri,
'name' => 'alternate-identifier',
'value' => $ns.':'.$altIdRaw,
];
 
}
}
 
public function whoisRaAttributes($email, &$out) {
// Interface 1.3.6.1.4.1.37476.2.5.2.3.4
}
 
}
/trunk/plugins/frdl/publicPages/altids/altids.xsd
0,0 → 1,9
<?xml version="1.0"?>
<xs:schema targetNamespace="urn:oid:1.3.6.1.4.1.37553.8.1.8.8.53354196964.641310544.1714020422"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element type="xs:string" name="handle-identifier" />
<xs:element type="xs:string" name="canonical-identifier" />
<xs:element type="xs:string" name="alternate-identifier" />
</xs:schema>
/trunk/plugins/frdl/publicPages/altids/manifest.xml
0,0 → 1,33
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<manifest
xmlns="urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:oid:1.3.6.1.4.1.37476.2.5.2.5.2.1 https://oidplus.viathinksoft.com/oidplus/plugins/manifest_plugin_page.xsd">
 
<type>OIDplusPagePluginPublic</type>
 
<info>
<name>AltIds Tracking and Reverse Lookup</name>
<author>Frdlweb</author>
<license>MIT</license>
<version>1.0</version>
<descriptionHTML>
<![CDATA[
<a href="https://github.com/frdl/oidplus-plugin-alternate-id-tracking" target="_blank">AltIds Tracking and Reverse Lookup</a><br/>
Track/Cache AltIds e.g. to enable reverse look-up of original identifiers by its alternate id.
]]>
</descriptionHTML>
<oid>1.3.6.1.4.1.37553.8.1.8.8.53354196964.641310544</oid>
</info>
 
<php>
<mainclass>OIDplusPagePublicAltIds</mainclass>
</php>
 
<css>
</css>
 
<js>
</js>
</manifest>