/** * Parse the given file for apprentices and mentors. * * @param string $file Path to the File to parse. * * @return array */ public function parse($file) { $return = array('mentors' => array(), 'apprentices' => array()); $content = file_Get_contents($file); $content = str_Replace('<local-time', '<span tag="local-time"', $content); $content = str_Replace('</local-time', '</span', $content); $content = str_Replace('<time', '<span tag="time"', $content); $content = str_Replace('</time', '</span', $content); $this->dom = new \DomDocument('1.0', 'UTF-8'); $this->dom->strictErrorChecking = false; libxml_use_internal_errors(true); $this->dom->loadHTML('<?xml encoding="UTF-8" ?>' . $content); libxml_use_internal_errors(false); $xpathMentors = new \DOMXPath($this->dom); $mentors = $xpathMentors->query('//a[@id="user-content-mentors-currently-accepting-an-apprentice"]/../following-sibling::ul[1]/li'); foreach ($mentors as $mentor) { $user = $this->parseUser($mentor); if (!$user) { continue; } $user['type'] = 'mentor'; $return['mentors'][] = $user; } $xpathApprentices = new \DOMXPath($this->dom); $apprentices = $xpathApprentices->query('//a[@id="user-content-apprentices-currently-accepting-mentors"]/../following-sibling::ul[1]/li'); foreach ($apprentices as $apprentice) { $user = $this->parseUser($apprentice); if (!$user) { continue; } $user['type'] = 'apprentice'; $return['apprentices'][] = $user; } return $return; }
/** * Creates the date elements used throughout the GRAMPS XML file. * The function will parse the date record and determine the type of date * (regular, range). * * @param DOMObject $eParent - The parent element the date should be attached to * @param string $dateRec - the entire GEDCOM date record to be parsed * @param int $level - the level the date record was found on in the GEDCOM * @param int $done - whether the method is called from the GrampsExport($done=1) or a sub-class */ function create_date($eParent, $dateRec, $level) { if (empty($dateRec)) { return; } $date = new GedcomDate(get_gedcom_value("DATE", $level, $dateRec, '', false)); //checks to see if there's is a 2nd date value and creates the daterange element if (!empty($date->qual2)) { $eDateRange = $this->dom->createElement("daterange"); $eDateRange = $eParent->appendChild($eDateRange); //sets the start date $eDateRange->setAttribute("start", $this->create_date_value($date->MinDate())); //sets the stop date $eDateRange->setAttribute("stop", $this->create_date_value($date->MaxDate())); } else { //if there's no dateRange, this creates the normal dateval Element $eDateVal = $this->dom->createElement("dateval"); $eDateVal = $eParent->appendChild($eDateVal); //checks for the Type attribute values switch ($date->qual1) { case 'bef': $eDateVal->setAttribute("type", "before"); break; case 'aft': $eDateVal->setAttribute("type", "after"); break; case 'abt': $eDateVal->setAttribute("type", "about"); break; } //sets the date value $eDateVal->setAttribute("val", $this->create_date_value($date->MinDate())); } }