Last active
October 29, 2024 19:42
-
-
Save Nall-chan/108ed6d31c27ab61759b7f706697fcf2 to your computer and use it in GitHub Desktop.
Auto-generate DocComment ipsmodule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ini_set('max_execution_time', 300); // kann schon mal dauern :) | |
| $IPSDoku = array(); | |
| $ModuleURLs=[]; | |
| $dom = new DOMDocument(); | |
| @$dom->loadHTMLFile("https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/module/"); | |
| if ($dom->documentURI == null) | |
| { | |
| die("Die Moduldoku von www.symcon.de konnte nicht geladen werden.\n"); | |
| } | |
| $finder = new DomXPath($dom); | |
| $classname = "sub active "; | |
| $nodes = $finder->query("//ul/li/a[contains(@href, '/de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/module/')]"); | |
| foreach ($nodes as $node) | |
| { | |
| if ($node->nodeValue == 'Module') | |
| continue; | |
| $ModuleURLs[$node->nodeValue]=$node->attributes['href']->value; | |
| } | |
| //$IPSDoku['MAINTAINVARIABLE'] = loadModuleDokuPage('https://www.symcon.de/de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/module/maintainvariable/'); | |
| foreach($ModuleURLs as $name => $url) | |
| { | |
| $IPSDoku[$name] = loadModuleDokuPage("https://www.symcon.de".$url); | |
| } | |
| function loadModuleDokuPage($url) | |
| { | |
| $result = array('link'=> $url); | |
| $dom = new DOMDocument(); | |
| @$dom->loadHTMLFile($url); | |
| if ($dom->documentURI == null) | |
| { | |
| echo " Fehler beim laden der Seite: $url\n"; | |
| return $result; | |
| } | |
| $finder = new DomXPath($dom); | |
| $classname = "functionname"; | |
| $function = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]"); | |
| $result['function'] = $function->item(0)->nodeValue; | |
| $result['params']=[]; | |
| if ($function->length == 1) | |
| { | |
| $start = $function->item(0)->parentNode->childNodes; | |
| $result["resulttyp"] = trim($start->item(0)->textContent); | |
| if ($start->length > 3){ | |
| $result["params"][0]["type"] = trim($start->item(3)->firstChild->nodeValue); | |
| $result["params"][0]["name"] = trim($start->item(4)->firstChild->nodeValue); | |
| $item = $function->item(0)->parentNode; | |
| $paraid=1; | |
| while($item->lastChild->childNodes->length > 1) | |
| { | |
| $item=$item->lastChild; | |
| $result["params"][$paraid]["type"] = trim($item->childNodes->item(1)->firstChild->nodeValue); | |
| $result["params"][$paraid]["name"] = trim($item->childNodes->item(2)->firstChild->nodeValue); | |
| $paraid++; | |
| } | |
| } | |
| } | |
| $finder = new DomXPath($dom); | |
| $classname = "paramList"; | |
| $paramnode = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]"); | |
| if ($paramnode->length == 1) | |
| { | |
| $id=0; | |
| foreach ($paramnode->item(0)->childNodes->item(1)->childNodes as $paramitem) | |
| { | |
| if ($paramitem->nodeType == 3) | |
| continue; | |
| $result['params'][$id]["desc"] = converttags($paramitem->childNodes->item(3)->ownerDocument->saveHTML($paramitem->childNodes->item(3))); | |
| $id++; | |
| } | |
| } | |
| $finder = new DomXPath($dom); | |
| $classname = "function"; | |
| $function = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]"); | |
| if ($function->length == 1) | |
| { | |
| $result['result'] = $function->item(0)->nextSibling->nodeValue; | |
| $result['result'] = converttags($result['result']); | |
| } | |
| $finder = new DomXPath($dom); | |
| $classname = "Beschreibung"; | |
| $description = $finder->query("//*[contains(concat(' ', normalize-space(@id), ' '), '$classname')]"); | |
| if ($description->length == 1) | |
| { | |
| $result['description'] = $description->item(0)->nextSibling->nextSibling->ownerDocument->saveHTML($description->item(0)->nextSibling->nextSibling); | |
| $result['description'] = converttags($result['description']); | |
| } | |
| return $result; | |
| } | |
| $logfile = "__ipsmodulefunktions.php"; | |
| $log = fopen($logfile, "w"); | |
| if (!$log) | |
| { | |
| die("Cannot write to $logfile\n"); | |
| } | |
| $date = date('Y-m-d'); | |
| $header = " | |
| /** @mainpage Reference list of IPSModule methods | |
| * | |
| * This file has been generated using IPSModuleDoku.php | |
| */ | |
| /** | |
| * @file | |
| * @brief generated ipsymcon ipsmodule reference using IPSModuleDoku.php | |
| */ | |
| class IPSModule { | |
| protected \$InstanceID; | |
| "; | |
| fwrite($log, "<?php\r\n"); | |
| fwrite($log, $header . "\r\n"); | |
| foreach ($IPSDoku as $f) | |
| { | |
| fwrite($log, "\r\n/**\r\n"); | |
| fwrite($log, "* " . $f['description'] . "\r\n"); | |
| fwrite($log, "* \r\n"); | |
| fwrite($log, "* @link " . $f['link'] . "\r\n"); | |
| fwrite($log, "* @return " . $f['resulttyp'] . " " . $f['result'] . "\r\n"); | |
| $proto = "function " . $f['function'] . "("; | |
| $param = array(); | |
| foreach ($f['params'] as $id => $p) | |
| { | |
| switch ($p['type']){ | |
| case 'boolean': | |
| $p['type']='bool'; | |
| break; | |
| case 'integer': | |
| $p['type']='int'; | |
| break; | |
| case 'variant': | |
| $p['type']='mixed'; | |
| break; | |
| } | |
| $param[] = $p['type'] .' '. $p['name']; | |
| fwrite($log, "* @param " . $p['type'] .' '. $p['name'] . " " . $p['desc'] . "\r\n"); | |
| } | |
| fwrite($log, "*/\r\n"); | |
| $proto .= implode(', ', $param); | |
| $proto .=") {\r\n\r\n}\r\n"; | |
| fwrite($log, $proto); | |
| } | |
| fwrite($log, "}\r\n"); | |
| fflush($log); | |
| fclose($log); | |
| echo "finished\n"; | |
| function converttags($Data) | |
| { | |
| $Data = preg_replace("/<p>/", "", $Data); | |
| $Data = preg_replace("/<\/p>/", "", $Data); | |
| $Data = preg_replace("#<table>(.*)<\/table>#iusU", "\\1", $Data); | |
| $Data = preg_replace("#<thead>(.*)<\/thead>#iusU", "", $Data); | |
| $Data = preg_replace("#<tbody>(.*)<\/tbody>#iusU", "\\1", $Data); | |
| $Data = preg_replace("#<tr>(.*)<\/tr>#iusU", "<li>\\1</li>", $Data); | |
| $Data = preg_replace("#<strong(.*)>(.*)<\/strong>#iusU", "<b>\\2</b>", $Data); | |
| $Data = preg_replace("#<a (.*)>(.*)<\/a>#iusU", "\\2", $Data); | |
| $Data = preg_replace("#<td>(.*)<\/td>#iusU", "\\1", $Data); | |
| $Data = preg_replace("#<div (.*)>(.*)<\/div>#iusU", "\\2", $Data); | |
| $Data = preg_replace("/<\/td>/", "", $Data); | |
| $Data = preg_replace("/<td>/", "", $Data); | |
| $Data = preg_replace("#<div (.*)>(.*)<\/div>#iusU", "\\2", $Data); | |
| return trim($Data); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment