function smwf_ti_update($tiArticleName) { global $smwgDIIP; require_once $smwgDIIP . "/specials/TermImport/SMW_WIL.php"; $xmlString = smwf_om_GetWikiText('TermImport:' . $tiArticleName); $start = strpos($xmlString, "<ImportSettings>"); $end = strpos($xmlString, "</ImportSettings>") + 17 - $start; $xmlString = substr($xmlString, $start, $end); $simpleXMLElement = new SimpleXMLElement($xmlString); $moduleConfig = $simpleXMLElement->xpath("//ModuleConfiguration"); $moduleConfig = trim($moduleConfig[0]->asXML()); $dataSource = $simpleXMLElement->xpath("//DataSource"); $dataSource = trim($dataSource[0]->asXML()); $mappingPolicy = $simpleXMLElement->xpath("//MappingPolicy"); $mappingPolicy = trim($mappingPolicy[0]->asXML()); $conflictPolicy = $simpleXMLElement->xpath("//ConflictPolicy"); $conflictPolicy = trim($conflictPolicy[0]->asXML()); $inputPolicy = $simpleXMLElement->xpath("//InputPolicy"); $inputPolicy = trim($inputPolicy[0]->asXML()); $importSets = $simpleXMLElement->xpath("//ImportSets"); $importSets = trim($importSets[0]->asXML()); $wil = new WIL(); $terms = $wil->importTerms($moduleConfig, $dataSource, $importSets, $inputPolicy, $mappingPolicy, $conflictPolicy, $tiArticleName, true); if ($terms != wfMsg('smw_ti_import_successful')) { return $terms; } else { return "success"; } }
private function embedEditTermImportData($termImportName) { $html = '<span id="editDataSpan" style="display: none">'; $xmlString = smwf_om_GetWikiText('TermImport:' . $termImportName); $start = strpos($xmlString, "<ImportSettings>"); $end = strpos($xmlString, "</ImportSettings>") + 17 - $start; $xmlString = substr($xmlString, $start, $end); $simpleXMLElement = new SimpleXMLElement($xmlString); $tlId = $simpleXMLElement->xpath("//TLModules/Module/id/text()"); $html .= '<span id="tlId-ed">' . $tlId[0] . '</span>'; $dalId = $simpleXMLElement->xpath("//DALModules/Module/id/text()"); $html .= '<span id="dalId-ed">' . $dalId[0] . '</span>'; $dataSource = $simpleXMLElement->xpath("//DataSource"); $html .= '<span id="dataSource-ed">' . rawurlencode($dataSource[0]->asXML()) . '</span>'; $importSet = $simpleXMLElement->xpath("//ImportSets/ImportSet/Name/text()"); @($html .= '<span id="importSet-ed">' . $importSet[0] . '</span>'); $regex = $simpleXMLElement->xpath("//InputPolicy/terms/regex/text()"); $regex = trim(implode(",", $regex)); $html .= '<span id="regex-ed">' . $regex . '</span>'; $terms = $simpleXMLElement->xpath("//InputPolicy/terms/term/text()"); $terms = trim(implode(",", $terms)); $html .= '<span id="terms-ed">' . $terms . '</span>'; $properties = $simpleXMLElement->xpath("//InputPolicy/properties/property/text()"); $properties = implode(",", $properties); $html .= '<span id="properties-ed">' . $properties . '</span>'; $mappingPolicy = $simpleXMLElement->xpath("//MappingPolicy/page/text()"); $html .= '<span id="mappingPolicy-ed">' . $mappingPolicy[0] . '</span>'; $conflictPolicy = $simpleXMLElement->xpath("//ConflictPolicy/overwriteExistingTerms/text()"); $conflictPolicy = $conflictPolicy[0] == "true" ? "overwrite" : "preserve current versions"; $html .= '<span id="conflictPolicy-ed">' . $conflictPolicy . '</span>'; $html .= '<span id="termImportName-ed">' . $termImportName . '</span>'; $updatePolicy = $simpleXMLElement->xpath("//UpdatePolicy/maxAge/@value"); $updatePolicy = $updatePolicy ? $updatePolicy[0] : "0"; $html .= '<span id="updatePolicy-ed">' . $updatePolicy . '</span>'; $xmlString = @smwf_ti_connectTL($tlId[0]); $xmlString = str_replace('xmlns="http://www.ontoprise.de/smwplus#"', "", $xmlString); $simpleXMLElement = new SimpleXMLElement($xmlString); $tlDesc = $simpleXMLElement->xpath("//TLModules/Module/desc/text()"); $html .= '<span id="tl-desc">' . $tlDesc[0] . '</span>'; $dalDesc = $simpleXMLElement->xpath("//Module[./id/text() = '" . $dalId[0] . "']/desc/text()"); $html .= '<span id="dal-desc">' . $dalDesc[0] . '</span>'; $dals = $simpleXMLElement->xpath("//DALModules/Module/id/text()"); if ($dals != null) { $dals = implode(",", $dals); $html .= '<span id="dalIds">' . $dals . '</span>'; } $html .= "</span>"; return $html; }
private function getNecessaryTermImports() { require_once "SMW_TermImportDefinitionValidator.php"; $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess(); SMWQueryProcessor::processFunctionParams(array("[[TermImport:+]] [[Category:TermImport]]"), $querystring, $params, $printouts); $queryResult = explode("|", SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI)); unset($queryResult[0]); $necessaryTermImports = array(); foreach ($queryResult as $tiArticleName) { $tiArticleName = substr($tiArticleName, 0, strpos($tiArticleName, "]]")); $xmlString = smwf_om_GetWikiText('TermImport:' . $tiArticleName); $start = strpos($xmlString, "<ImportSettings>"); $end = strpos($xmlString, "</ImportSettings>") + 17 - $start; $xmlString = substr($xmlString, $start, $end); SMWQueryProcessor::processFunctionParams(array("[[belongsToTermImport::TermImport:" . $tiArticleName . "]]", "?hasImportDate", "limit=1", "sort=hasImportDate", "order=descending", "format=list", "mainlabel=-", "searchlabel="), $querystring, $params, $printouts); $queryResult = SMWQueryProcessor::getResultFromQueryString($querystring, $params, $printouts, SMW_OUTPUT_WIKI); // timestamp creation depends on property type (page or date) $queryResult = trim(substr($queryResult, strpos($queryResult, "]]") + 2)); if (strpos($queryResult, "[[:") === 0) { //type page $queryResult = trim(substr($queryResult, strpos($queryResult, "|") + 1)); $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "]"))); } else { //type date $queryResult = trim(substr($queryResult, 0, strpos($queryResult, "["))); } $timestamp = strtotime($queryResult); $tiDV = new SMWTermImportDefinitionValidator($xmlString); if (!$tiDV->validate()) { echo "\nThe Term Import definition of " . $tiArticleName . " is invalid.\n"; $title = Title::newFromText("TermImport:" . $tiArticleName); $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_FAILURE, $title); continue; } $simpleXMLElement = new SimpleXMLElement($xmlString); $maxAge = $simpleXMLElement->xpath("//UpdatePolicy/maxAge/@value"); //echo("\ntimestamp: ".$imestamp); if ($maxAge != "") { if ($timestamp == 0 || wfTime() - $timestamp - $maxAge[0]->value * 60 > 0) { echo "\nRun this term import: " . $tiArticleName; $necessaryTermImports[$tiArticleName] = $xmlString; } } else { $title = Title::newFromText("TermImport:" . $tiArticleName); $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_NOT_NECESSARY, $title); } } return $necessaryTermImports; }