예제 #1
0
 /**
  * Creates articles for the terms according to the mapping and conflict policy.
  *
  * @param string $terms
  * 		This XML string contains all terms that the DAL delivered
  * @param string $mappingPolicy
  * 		This XML string contains the name of an article that is a template
  * 		for the articles that will be created.
  * @param string $conflictPolicy
  * 		This XML string specifies, if existing articles will be overwritten.
  * @parameter IWil $wil
  * 		The wiki import layer object
  * @return mixed (boolean, string)
  * 		<true>, if all terms were successfully imported or an
  * 		error message, otherwise.
  *
  */
 private function createArticles($terms, $mappingPolicy, $conflictPolicy, $wil, $termImportName)
 {
     global $smwgDIIP;
     require_once $smwgDIIP . '/specials/TermImport/SMW_XMLParser.php';
     echo "\nStart to create articles";
     $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess();
     $parser = new XMLParser($mappingPolicy);
     $result = $parser->parse();
     if ($result !== TRUE) {
         return $result;
     }
     $mp = $parser->getValuesOfElement(array('MappingPolicy', 'page'));
     if (!is_array($mp) || !$mp[0]) {
         return wfMsg('smw_ti_missing_mp');
     }
     $mp = $mp[0];
     // get the content of the article that contains the mapping policy
     $mp = strip_tags($mp);
     if ($mp == '') {
         return wfMsg('smw_ti_missing_mp', $mp);
     }
     $mp = Title::newFromText($mp);
     $mp = new Article($mp);
     $mp = $mp->getContent();
     $parser = new XMLParser($conflictPolicy);
     $result = $parser->parse();
     if ($result !== TRUE) {
         return $result;
     }
     $cp = $parser->getValuesOfElement(array('ConflictPolicy', 'overwriteExistingTerms'));
     $cp = $cp[0];
     $cp = strtolower($cp) == 'true' ? true : false;
     //echo("\n\n".$terms."\n\n");
     //$file = fopen("d:/result.txt", w);
     //fwrite($file, $terms);
     //fclose($file);
     //echo("\n\n".$terms."\n\n");
     echo "\nCreate xml parser";
     try {
         $parser = new SimpleXMLElement($terms, LIBXML_NOCDATA);
     } catch (Exception $e) {
         return "The XML parser could not be created because: " . $e;
     }
     if (!key_exists("term", $parser)) {
         foreach ($parser->errors as $errors) {
             foreach ($errors->error as $error) {
                 $this->importErrors[] = $error[0];
             }
         }
         return wfMsg('smw_ti_import_successful');
     }
     $numTerms = count($parser->term);
     echo "\nNumber of terms: " . $numTerms . "\n";
     $this->setNumberOfTasks(1);
     $this->addSubTask($numTerms);
     $timeInTitle = $this->getDateString();
     $termImportName = "TermImport:" . $termImportName . "/" . $timeInTitle;
     $noErrors = true;
     foreach ($parser->term as $term) {
         //check if this is a callback term
         if ($term['callback']) {
             $callBackResult = $wil->executeCallBack("" . $term, $mp, $cp, $termImportName);
             $cBRParser = new XMLParser($callBackResult);
             $cBRParser->parse();
             $nextId = 0;
             $nextTitle = 0;
             while ($logMsg = $cBRParser->getElement(array('logMessage', 'id'), $nextId)) {
                 $titleName = $cBRParser->getElement(array('logMessage', 'title'), $nextTitle);
                 $log->addGardeningIssueAboutArticle($this->id, $logMsg['ID'][0]['value'], Title::newFromText($titleName['TITLE'][0]['value']));
             }
             $nextSuccess = 0;
             $callBackSucces = $cBRParser->getElement(array('success'), $nextSuccess);
             if ($callBackSucces['SUCCESS'][0]['value'] == 'false') {
                 //todo: allow callbacks to return eror messages
                 $noErrors = false;
             }
             $this->worked(1);
             continue;
         }
         $caResult = $this->createArticle($term, $mp, $cp, $termImportName);
         $this->worked(1);
         if ($caResult !== true) {
             $noErrors = false;
             $this->importErrors[] = $caResult;
         }
     }
     foreach ($parser->errors as $errors) {
         foreach ($errors->error as $error) {
             $this->importErrors[] = $error[0];
         }
     }
     if ($noErrors) {
         return wfMsg('smw_ti_import_successful');
     } else {
         return wfMsg('smw_ti_import_errors');
     }
 }
예제 #2
0
 public function getTLIDs($tlModules)
 {
     global $smwgDIIP;
     require_once $smwgDIIP . '/specials/TermImport/SMW_XMLParser.php';
     $p = new XMLParser($tlModules);
     $result = $p->parse();
     if ($result == TRUE) {
         $tlmodules = $p->getElement(array('TLModules'));
         $count = count($tlmodules['TLMODULES'][0]['value']['MODULE']);
         for ($i = 0; $i < $count; $i++) {
             $tlid = $tlmodules['TLMODULES'][0]['value']['MODULE'][$i]['value']['ID'][0]['value'];
             $html = "<div class=\"entry\" onMouseOver=\"this.className='entry-over';\"" . " onMouseOut=\"termImportPage.showRightTLM(event, this, '{$tlid}')\" onClick=\"termImportPage.connectTL(event, this, '{$tlid}')\">" . "<a>" . $tlid . "</a>" . "</div>";
         }
     }
     return $html;
 }