public function testOPS($path = null) { $this->_saveMeta(); if ($path == null) { $path = $this->packagepath; } $mimetypepath = $path . '/' . $this->getMimetypeFilename(); // filename of mimetype file $metapath = $path . '/META-INF'; $result = array(); $result[0] = 'fail'; $result[1] = 'error message'; if (is_dir($metapath)) { // dir exists if ($container = file_get_contents($metapath . '/container.xml')) { // found container file $contdoc = new DomDocument(); if ($cd = $contdoc->loadXML($container)) { // loaded container xml $fp = $contdoc->getElementsByTagName('rootfiles')->item(0)->getElementsByTagName('rootfile')->item(0)->getAttribute('full-path'); if ($fullp = $this->_getRelPathWithOpf($fp)) { // found full path to opf file $p = strlen($fullp[0]) > 0 ? "{$path}/{$fullp['0']}" : "{$path}"; $op = "{$p}/{$fullp['1']}"; $this->logerr($op, 2); if (file_exists($op)) { // found opf file $opf = new DomDocument('1.0', 'utf-8'); $opf->preserveWhiteSpace = FALSE; $opf->loadXML(file_get_contents($op)); $package = $opf->getElementsByTagName('package')->item(0); $meta = $package->getElementsByTagName('metadata')->item(0); $mani = $package->getElementsByTagName('manifest')->item(0); $spine = $package->getElementsByTagName('spine')->item(0); if ($meta && $mani && $spine) { $tocatt = $spine->getAttribute('toc'); $opfXP = new DomXpath($opf); $opfXP->registerNamespace("opfns", $this->opfNS); $opfXP->registerNamespace("dc", $this->dcNS); $tocitem = $opfXP->evaluate('//*[@id="' . $tocatt . '"]'); if ($tocitem->length > 0) { if (file_exists($p . '/' . $tocitem->item(0)->getAttribute('href'))) { $result[0] = 'pass'; $result[1] = array('opf' => $fp); //foreach($mani->getElementsByTagName('item') as $item) { // $href = $item->getAttribute('href'); //} } else { $result[1] = "ncx file not found:" . $p . '/' . $tocitem->item(0)->getAttribute('href') . "\n"; } } else { $result[1] = "no item with ncx id found\n"; } } else { $result[1] = "one of the three required opf nodes is missing\n"; } } else { $result[1] = "opf not found\n"; } } else { $result[1] = "full path to opf not found\n"; } } else { $result[1] = "container file not loaded\n"; } } else { $result[1] = "container file not found\n"; } } else { $result[1] = "meta-inf dir no exist\n"; } return $result; }