/** * @param string $rfcLocation */ private function loadRfc($rfcLocation, $rfcCode) { // Suppress HTML5 errors libxml_use_internal_errors(true); $this->document = new \DOMDocument(); $this->document->loadHTMLFile($rfcLocation); // Turn errors back on libxml_use_internal_errors(false); $this->rfc = new Rfc(); $this->rfc->setCode($rfcCode); $this->rfc->setRawContent($this->document->saveHTML()); }
/** * Collects all translateable strings(from tags with 'trans' attribute) from html templates * * @param string $file absoulute path to file */ function extractFromHtml($file) { $dom = new DomDocument(); $dom->loadHTMLFile($file); $xpath = new DomXPath($dom); $nodes = $xpath->query("//*[@trans]"); foreach ($nodes as $i => $node) { // $info = "<{$node->tagName}> at $file"; $info = ""; if ($node->hasAttribute('context')) { $info = 'Context: ' . $node->getAttribute('context') . '. ' . $info; } if ($node->hasAttribute('placeholder')) { $this->addTranslationStr($node->getAttribute('placeholder'), $info); } if ($node->hasAttribute('title')) { $this->addTranslationStr($node->getAttribute('title'), $info); } if ($node->hasAttribute('data-intro')) { $this->addTranslationStr($node->getAttribute('data-intro'), $info); } if ($node->nodeValue != '' && $node->getAttribute('trans') != 'attr-only') { $this->addTranslationStr($node->nodeValue, $info); } } }
public static function user_id_from_name($user) { $url = Thingiverse::BASE_URL . "/{$user}"; $dom = new DomDocument("1.0"); @$dom->loadHTMLFile($url); // use @ to suppress parser warnings $xp = new DomXpath($dom); $rss_url = $xp->query("//link[@rel=\"alternate\"]")->item(0)->getAttribute("href"); $parts = explode(":", $rss_url); return $parts[2]; }
public static function getTemplateFromFile($file) { $content = new \DomDocument(); if ($file instanceof File) { $content->loadHTMLFile($file->getFileName()); } else { $content->loadHTML($file); } global $renderedPage; $renderedPage = $content; return new static($renderedPage); }
/** * Loads an HTML file * * Parse errors are stored in the global array _dompdf_warnings. * * @param string $file a filename or url to load */ function load_html_file($file) { // Store parsing warnings as messages (this is to prevent output to the // browser if the html is ugly and the dom extension complains, // preventing the pdf from being streamed.) if (!$this->_protocol && !$this->_base_host && !$this->_base_path) { list($this->_protocol, $this->_base_host, $this->_base_path) = explode_url($file); } if (!DOMPDF_ENABLE_REMOTE && ($this->_protocol != "" && $this->_protocol != "file://")) { throw new DOMPDF_Exception("Remote file requested, but DOMPDF_ENABLE_REMOTE is false."); } if ($this->_protocol == "" || $this->_protocol == "file://") { $realfile = dompdf_realpath($file); if (!$file) { throw new DOMPDF_Exception("File '{$file}' not found."); } if (strpos($realfile, DOMPDF_CHROOT) !== 0) { throw new DOMPDF_Exception("Permission denied on {$file}."); } // Exclude dot files (e.g. .htaccess) if (substr(basename($realfile), 0, 1) == ".") { throw new DOMPDF_Exception("Permission denied on {$file}."); } $file = $realfile; } if (!DOMPDF_ENABLE_PHP) { set_error_handler("record_warnings"); $this->_xml->loadHTMLFile($file); restore_error_handler(); } else { $this->load_html(file_get_contents($file)); } }
public function onFullTextSearchClick() { if (!$this->manual) { // TODO: One might think aobut using an external browser or the online docs... $dialog = new \GtkMessageDialog($this->glade->get_widget('mainwindow'), 0, \Gtk::MESSAGE_ERROR, \Gtk::BUTTONS_OK, 'GtkHTML needed'); $dialog->set_markup('For doing full text searches GtkHTML support is required in your PHP configuration.'); $dialog->run(); $dialog->destroy(); return; } $input = trim($this->glade->get_widget('searchentry')->get_text()); if (strlen($input) == 0) { $dialog = new \GtkMessageDialog($this->glade->get_widget('mainwindow'), 0, \Gtk::MESSAGE_ERROR, \Gtk::BUTTONS_OK, 'No input'); $dialog->set_markup('No search term entered'); $dialog->run(); $dialog->destroy(); return; } $results = $this->manual->searchFulltext($input); $store = new \GtkTreeStore(\GObject::TYPE_STRING, \GObject::TYPE_PHP_VALUE); foreach ($results as $title => $found) { $man_container = $store->append(null, array($title, null)); $basenamelen = strlen('phar://' . $found->getArchiveFileName()); echo 'phar://' . $found->getArchiveFileName(), "\n"; foreach ($found as $item) { /** @var $item \SplFileObject */ $doc = \DomDocument::loadHTMLFile($item->getPathname()); $caption = $doc->getElementsByTagName('title')->item(0)->firstChild->wholeText; $store->append($man_container, array($caption, $item)); } } $tree = $this->glade->get_widget('searchtreeview'); $tree->set_model($store); $tree->get_selection()->connect('changed', array($this->mainWindow, 'onSearchResultClick')); /* TODO: Move to view */ $cell_renderer = new \GtkCellRendererText(); $colExt = new \GtkTreeViewColumn('', $cell_renderer, 'text', 0); $tree->append_column($colExt); }
/** * 获取酒店总页数 * @return int $pages 总页数 */ private function _getHotelPages() { $dom = new DomDocument(); @$dom->loadHTMLFile($this->hotelUrl); $page_info = $dom->getElementById("page_info"); if (gettype($page_info) != "object") { return 0; } $div = $page_info->getElementsByTagName('div')->item(0); $a = $div->getElementsByTagName('a'); $numOfa = $a->length; $pages = (int) $a->item($numOfa - 1)->nodeValue; return $pages; }
function updateGoogleCodeIndexes($update = false) { $local_file = basename($_SERVER['PHP_SELF']) == basename(__FILE__); if ($local_file) { $update = true; } $localFileName = 'indexes.xml'; // check each 30 minutes if (!$update && file_exists($localFileName) && time() - filemtime($localFileName) < 60 * 30) { return; } if ($local_file) { echo '<h1>File update : </h1> <br>'; } $dom = new DomDocument(); $output = new DOMDocument(); $output->formatOutput = true; $outputIndexes = $output->createElement("osmand_regions"); $outputIndexes->setAttribute('mapversion', '1'); $output->appendChild($outputIndexes); $st = 0; $num = 200; $count = 0; $mapNodes = array(); /// 1. dlownload indexes from googlecode while ($st != -1) { $dom->loadHTMLFile("http://code.google.com/p/osmand/downloads/list?num=" . $num . "&start=" . $st . "&colspec=Filename+Summary+Uploaded+Size"); $count++; $xpath = new DOMXpath($dom); $xpathI = new DOMXpath($dom); $res = $xpath->query('//td[contains(@class,"col_0")]'); if ($res && $res->length > 0) { foreach ($res as $node) { $indexName = trim($node->nodeValue); $s = $xpathI->query('td[contains(@class,"col_1")]/a[1]', $node->parentNode); if (!$s || $s->length == 0) { continue; } $description = $s->item(0)->nodeValue; $i = strpos($description, "{"); if (!$i) { continue; } $i1 = strpos($description, ":", $i); $i2 = stripos($description, "mb", $i1); if (!$i2) { $i2 = strpos($description, "}", $i1); } $date = trim(substr($description, $i + 1, $i1 - $i - 1)); $size = trim(substr($description, $i1 + 1, $i2 - $i1 - 1)); $description = trim(substr($description, 0, $i)); if ($local_file) { echo $indexName . ' ' . $date . ' ' . $size . ' <br>'; } if (strpos($indexName, "voice.zip") || strpos($indexName, ".obf")) { $ipart = strpos($indexName, "zip-"); $part = 1; $base = $indexName; if ($ipart) { $part = (int) substr($indexName, $ipart + 4); $base = substr($indexName, 0, $ipart + 3); if (isset($mapNodes[$base])) { $out = $mapNodes[$base]; } else { $out = $output->createElement("multiregion"); $out->setAttribute("parts", $part); $mapNodes[$base] = $out; $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $base); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); } if ((int) $out->getAttribute("parts") < $part) { $out->setAttribute("parts", $part); } } else { $out = $output->createElement("region"); $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $indexName); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); $mapNodes[$indexName] = $out; } } } $st += $num; } else { $st = -1; } } /// 2. append local indexes // Open a known directory, and proceed to read its contents loadIndexesFromDir($output, $outputIndexes, 'indexes/', 'region', $mapNodes); loadIndexesFromDir($output, $outputIndexes, 'road-indexes/', 'road_region'); $output->save($localFileName); }
<?php $result = 0; passthru('cd ' . __DIR__ . ' && phpdoc --force', $result); if ($result !== 0) { die("phpdoc command not found."); } libxml_use_internal_errors(true); $dom = new DomDocument(); $dom->loadHTMLFile("./docs/index.html"); $xpath = new DomXpath($dom); // Remove "Global" namespace $result = $xpath->query('//li/a[@href="namespaces/default.html"]'); if ($result->length > 0) { $node = $result->item(0); $node->parentNode->parentNode->removeChild($node->parentNode); } // Remove Packages $result = $xpath->query('//div[@class="well"][2]'); if ($result->length > 0) { $node = $result->item(0); $node->parentNode->removeChild($node); } $dom->saveHTMLFile('./docs/index.html');
function load_stream_from_made_url() { $dom = new DomDocument("1.0"); @$dom->loadHTMLFile($this->url); // use @ to suppress parser warnings // FIXME: check for parse error. set some kind of thing status! $this->parse_thing_mades_from_html_dom($dom); }
<?php $dom = new DomDocument(); /* load HTML document (if it is not valid) */ @$dom->loadHTMLFile("http://" . $_SERVER['SERVER_ADDR'] . dirname($_SERVER['PHP_SELF']) . '/1'); $xp = new DomXpath($dom); /* use XPath to get the title of the */ $res = $xp->query("//title/text()"); echo $res->item(0)->nodeValue;
/* Use internal libxml errors -- turn on in production, off for debugging */ libxml_use_internal_errors(false); /* Createa a new DomDocument object */ $dom = new DomDocument(); // Load the active tournament /* Load the HTML */ // NOTE: need to put the correct URL for the competition here. // PERHAPS?: $dom->loadHTMLFile("http://www2.usfirst.org/2014comp/Events/NJCLI/matchresults.html"); // $dom->loadHTMLFile("http://www2.usfirst.org/2014comp/Events/NJFLA/matchresults.html"); // 2014 // NOTE: Set OUR tournament ID here. $tournament_id = "MTO"; // NOTE: Change FIRST's event id in this URL to select a different tournament. $url = "http://frc-events.firstinspires.org/2016/NJFLA/qualifications"; // 2016 // $url = "http://frc-events.usfirst.org/2015/GALILEO/qualifications"; // 2015 $dom->loadHTMLFile($url); /* Create a new XPath object */ $xpath = new DomXPath($dom); /* Query all <td> nodes containing specified class name */ $nodes = $xpath->query("//table[@class='table table-striped table-hover table-bordered table-condensed text-center']//tr[@class='hidden-xs']//td"); // 2015 UMass // $nodes = $xpath->query("//table[@class='clean']//tr//td"); // 2015 HH // $nodes = $xpath->query("//tr[@style='background-color:#FFFFFF;']//td"); // 2014 // $nodes = $xpath->query("//td"); /* Traverse the DOMNodeList object to output each DomNode's nodeValue */ /* foreach ($nodes as $i => $node) { echo "Node($i): ", $node->nodeValue, "\n"; } */ /* Set HTTP response header to plain text for debugging output */ // header("Content-type: text/plain");
public function parsePredefinedClasses($fileLocation) { $dom = DomDocument::loadHTMLFile($this->docLocation . "/" . $fileLocation); $query = '//*[@class="chunklist chunklist_part"]/li/a'; $xpath = new DOMXPath($dom); $entries = $xpath->query($query); foreach ($entries as $entry) { $sxml = simplexml_import_dom($entry); $className = (string) $sxml; $classLocation = (string) $sxml['href']; $this->classDocs[$className] = $this->parseClassDocFile($classLocation); } }
<?php require '../lib/convert.php'; require '../lib/osm-writer.php'; $dom = new DomDocument(); //@$dom->loadHTMLFile( "/tmp/{$argv[1]}.html" ); echo "Processing {$argv[1]}: "; @$dom->loadHTMLFile("http://www.itoworld.com/product/data/osm_analysis/area?name={$argv[1]}"); echo "fetched "; $missing = $dom->getElementByID('roadsMissingBody'); $missing = simplexml_import_dom($missing); $result = array(); @process_list($result, $missing->table); render_to_osm($result, "ito-fetch/{$argv[1]}.osm"); echo "written\n"; function process_list(&$result, $node) { foreach ($node->tr as $row) { $result[] = process_way($row->td->a); } foreach ($node->i as $row) { process_list($result, $row); } } function process_way($node) { $name = $node[0]; $href = $node['href']; parse_str(preg_replace('@^map_browser\\?@', '', $href), $result); list($left, $top, $right, $bottom) = explode(',', $result['bbox']); $horizontal = ($left + $right) / 2;
<?php $next = true; $url = "http://www.alexa.com/topsites/countries/SE"; $sites_list = array(); $args = getopt("n:"); $number_of_sites = intval($args["n"]); if ($number_of_sites > 500 || $number_of_sites < 0) { $number_of_sites = 20; } while ($next) { $doc = new DomDocument(); @$doc->loadHTMLFile($url); $data = $doc->getElementById('topsites-countries'); $my_data = $data->getElementsByTagName('div'); $xpath = new DOMXpath($doc); $get_websites = $xpath->query('//span[@class="small topsites-label"]'); foreach ($get_websites as $sites) { $sites_list[] = $sites->nodeValue . "\n"; } $is_next = $xpath->query('//a[@class="next"]'); if ($is_next->item(0)) { $url = "http://www.alexa.com" . $is_next->item(0)->getAttribute("href"); } else { $next = NULL; } if (count($sites_list) >= $number_of_sites) { break; } } for ($i = 0; $i < $number_of_sites; $i++) {
<?php header('Content-Type: application/json'); $channel = $_GET['channel']; $id = $_GET['id']; $title = ''; $view = ''; $status = ''; $object = array(); switch ($channel) { case 'talktv': $doc = new DomDocument(); $doc->loadHTMLFile('http://talktv.vn/' . $id); //status $thediv = $doc->getElementById('stream-status-live'); $status = trim($thediv->textContent); if ($status == 'Đang phát') { $status = 'live'; } else { $status = 'offline'; } //view $thediv = $doc->getElementById('player-viewing-count'); $view = trim($thediv->textContent); //title $thediv = $doc->getElementById('broadcast-title'); $title = trim($thediv->textContent); break; case 'youtube': $view = file_get_contents('https://www.youtube.com/live_stats?v=' . $id); //get view
/** * Test for checking html processing. */ public function test_downloadpagehtml() { global $DB; $this->set_test_config(); $this->set_user(0); // Creating a testable assignment. $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); $params['course'] = $this->course1->id; $params['intro'] = '<h3>Heading 1</h3><p>This is test assignment.</p><br>'; $instance = $generator->create_instance($params); $this->cm = get_coursemodule_from_instance('assign', $instance->id); $this->context = context_module::instance($this->cm->id); $this->assign = new testable_assign($this->context, $this->cm, $this->course1); // To get the notebooks of student. $this->set_user(1); // Student submission to onenote. $createsubmission = $this->create_submission_feedback($this->cm, false, false, null, null, null); $this->submission = $this->assign->get_user_submission($this->user1->id, true); $record = $DB->get_record('onenote_assign_pages', array("assign_id" => $this->submission->assignment, "user_id" => $this->submission->userid)); $tempfolder = $this->onenoteapi->create_temp_folder(); $tempfile = join(DIRECTORY_SEPARATOR, array(rtrim($tempfolder, DIRECTORY_SEPARATOR), uniqid('asg_'))) . '.zip'; $info = $this->onenoteapi->download_page($record->submission_student_page_id, $tempfile); $zip = new ZipArchive(); $res = $zip->open($info['path']); if ($res === true) { $zip->extractTo($tempfolder); $zip->close(); } $folder = join(DIRECTORY_SEPARATOR, array(rtrim($tempfolder, DIRECTORY_SEPARATOR), '0')); $pagefile = join(DIRECTORY_SEPARATOR, array(rtrim($folder, DIRECTORY_SEPARATOR), 'page.html')); $htmldom = new DomDocument(); $htmldom->loadHTMLFile($pagefile); $htmldom->preservewhitespace = false; $domclone = new DOMDocument(); $domclone->preservewhitespace = false; $doc = $htmldom->getElementsByTagName("div")->item(0); foreach ($doc->childNodes as $child) { $domclone->appendChild($domclone->importNode($child, true)); } $output = $domclone->saveHTML(); $expectedhtml = '<h3 style="font-size:12pt;color:#5b9bd5;margin-top:11pt;margin-bottom:11pt">'; $expectedhtml .= '<span style="font-family:Helvetica;font-size:13.5pt;color:#333333">Heading 1</span></h3> '; $expectedhtml .= '<p><span style="font-family:Helvetica;font-size:10.5pt;color:#333333">This is test assignment.</span></p> '; $expectedhtml .= '<p><span style="font-family:Helvetica;font-size:10.5pt;color:#333333"> </span></p>'; $output = trim(preg_replace('/\\s+/', ' ', $output)); $this->assertContains($expectedhtml, $output, 'Html does not match'); }
$link = mysql_connect('team102.org:3306', 'team102_webuser', $_SESSION['password']); if (!mysql_select_db('team102_2016', $link)) { echo sprintf('Could not select database, Err: %s', mysql_error()); exit; } /* Use internal libxml errors -- turn on in production, off for debugging */ libxml_use_internal_errors(true); /* Createa a new DomDocument object */ $dom = new DomDocument(); /* Load the HTML */ // $dom->loadHTMLFile("https://my.usfirst.org/myarea/index.lasso?page=teamlist&event_type=FRC&sort_teams=number&year=2015&event=mrcmp"); $FIRSTName = 'NJSKI'; // NJSKI, NJTAB $tournamentID = 'MNT'; // MNT - Montgomery, SEN - Seneca $dom->loadHTMLFile("http://frc-events.firstinspires.org/2016/" . $FIRSTName); /* Create a new XPath object */ $xpath = new DomXPath($dom); /* Query all <td> nodes containing specified class name */ // $nodes = $xpath->query("//tr[@bgcolor='#FFFFFF']//td"); $nodes = $xpath->query("//table[@id='teamtable']//td"); // $nodes = $xpath->query("//td"); /* Set HTTP response header to plain text for debugging output */ header("Content-type: text/plain"); /* Traverse the DOMNodeList object to output each DomNode's nodeValue */ /* foreach ($nodes as $i => $node) { echo "Node($i): ", $node->nodeValue, "\n"; } */ // The first node is the city, stateCountry // Second node is the list of sponsors and the school name
/** * Loads an HTML file * * Parse errors are stored in the global array _dompdf_warnings. * * @param string $file a filename or url to load */ function load_html_file($file) { // Store parsing warnings as messages (this is to prevent output to the // browser if the html is ugly and the dom extension complains, // preventing the pdf from being streamed.) list($this->_protocol, $this->_base_host, $this->_base_path) = explode_url($file); if (!DOMPDF_ENABLE_REMOTE && ($this->_protocol != "" && $this->_protocol != "file://")) { throw new DOMPDF_Exception("Remote file requested, but DOMPDF_ENABLE_REMOTE is false."); } if (!DOMPDF_ENABLE_PHP) { set_error_handler("record_warnings"); $this->_xml->loadHTMLFile($file); restore_error_handler(); } else { $this->load_html(file_get_contents($file)); } }
function updateGoogleCodeIndexes($update = false) { $localFileName = 'indexes.xml'; // check each 30 minutes if (!$update && file_exists($localFileName) && time() - filemtime($localFileName) < 60 * 30) { return; } $dom = new DomDocument(); $output = new DOMDocument(); $output->formatOutput = true; $outputIndexes = $output->createElement("osmand_regions"); $output->appendChild($outputIndexes); $st = 0; $num = 200; $count = 0; $mapNodes = array(); /// 1. dlownload indexes from googlecode while ($st != -1) { $dom->loadHTMLFile("http://code.google.com/p/osmand/downloads/list?num=" . $num . "&start=" . $st . "&colspec=Filename+Summary+Uploaded+Size"); $count++; $xpath = new DOMXpath($dom); $xpathI = new DOMXpath($dom); $res = $xpath->query('//td[contains(@class,"col_0")]'); if ($res && $res->length > 0) { foreach ($res as $node) { $indexName = trim($node->nodeValue); $s = $xpathI->query('td[contains(@class,"col_1")]/a[1]', $node->parentNode); if (!$s || $s->length == 0) { continue; } $description = $s->item(0)->nodeValue; $i = strpos($description, "{"); if (!$i) { continue; } $i1 = strpos($description, ":", $i); $i2 = stripos($description, "mb", $i1); if (!$i2) { $i2 = strpos($description, "}", $i1); } $date = trim(substr($description, $i + 1, $i1 - $i - 1)); $size = trim(substr($description, $i1 + 1, $i2 - $i1 - 1)); $description = trim(substr($description, 0, $i)); if (strpos($indexName, ".voice.zip") || strpos($indexName, "_1.poi.zip") || strpos($indexName, "_1.poi.odb") || strpos($indexName, "_1.obf")) { $ipart = strpos($indexName, "zip-"); $part = 1; $base = $indexName; if ($ipart) { $part = (int) substr($indexName, $ipart + 4); $base = substr($indexName, 0, $ipart + 3); if ($mapNodes[$base]) { $out = $mapNodes[$base]; } else { $out = $output->createElement("multiregion"); $out->setAttribute("parts", $part); $mapNodes[$base] = $out; $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $base); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); } if ((int) $out->getAttribute("parts") < $part) { $out->setAttribute("parts", $part); } } else { $out = $output->createElement("region"); $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $indexName); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); $mapNodes[$indexName] = $out; } } } $st += $num; } else { $st = -1; } } /// 2. append local indexes $local = new DomDocument(); $local->load('local_indexes.xml'); $xpath = new DOMXpath($local); $res = $xpath->query("//*[name() = 'region' or name() = 'multiregion']"); if ($res && $res->length > 0) { foreach ($res as $node) { // TODO fix multiregion is not the same as region for old clients //if($mapNodes[$node->getAttribute("name")]) { // continue; // } $out = $output->createElement($node->nodeName); $out->setAttribute("date", $node->getAttribute("date")); $out->setAttribute("size", $node->getAttribute("size")); $out->setAttribute("name", $node->getAttribute("name")); $out->setAttribute("description", $node->getAttribute("description")); if ($node->getAttribute("parts")) { $out->setAttribute("parts", $node->getAttribute("parts")); } $outputIndexes->appendChild($out); } } $output->save($localFileName); }
function updateGoogleCodeIndexes($update = false) { $localFileName = 'indexes.xml'; // check each 30 minutes if (!$update && file_exists($localFileName) && time() - filemtime($localFileName) < 60 * 30) { return; } $dom = new DomDocument(); $output = new DOMDocument(); $output->formatOutput = true; $outputIndexes = $output->createElement("osmand_regions"); $outputIndexes->setAttribute('mapversion', '1'); $output->appendChild($outputIndexes); $st = 0; $num = 200; $count = 0; $mapNodes = array(); /// 1. dlownload indexes from googlecode while ($st != -1) { $dom->loadHTMLFile("http://code.google.com/p/osmand/downloads/list?num=" . $num . "&start=" . $st . "&colspec=Filename+Summary+Uploaded+Size"); $count++; $xpath = new DOMXpath($dom); $xpathI = new DOMXpath($dom); $res = $xpath->query('//td[contains(@class,"col_0")]'); if ($res && $res->length > 0) { foreach ($res as $node) { $indexName = trim($node->nodeValue); $s = $xpathI->query('td[contains(@class,"col_1")]/a[1]', $node->parentNode); if (!$s || $s->length == 0) { continue; } $description = $s->item(0)->nodeValue; $i = strpos($description, "{"); if (!$i) { continue; } $i1 = strpos($description, ":", $i); $i2 = stripos($description, "mb", $i1); if (!$i2) { $i2 = strpos($description, "}", $i1); } $date = trim(substr($description, $i + 1, $i1 - $i - 1)); $size = trim(substr($description, $i1 + 1, $i2 - $i1 - 1)); $description = trim(substr($description, 0, $i)); if (strpos($indexName, "voice.zip") || strpos($indexName, "_1.poi.zip") || strpos($indexName, "_1.poi.odb") || strpos($indexName, "_1.obf")) { $ipart = strpos($indexName, "zip-"); $part = 1; $base = $indexName; if ($ipart) { $part = (int) substr($indexName, $ipart + 4); $base = substr($indexName, 0, $ipart + 3); if (isset($mapNodes[$base])) { $out = $mapNodes[$base]; } else { $out = $output->createElement("multiregion"); $out->setAttribute("parts", $part); $mapNodes[$base] = $out; $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $base); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); } if ((int) $out->getAttribute("parts") < $part) { $out->setAttribute("parts", $part); } } else { $out = $output->createElement("region"); $out->setAttribute("date", $date); $out->setAttribute("size", $size); $out->setAttribute("name", $indexName); $out->setAttribute("description", $description); $outputIndexes->appendChild($out); $mapNodes[$indexName] = $out; } } } $st += $num; } else { $st = -1; } } /// 2. append local indexes $local = new DomDocument(); // Open a known directory, and proceed to read its contents $dir = 'indexes/'; if (is_dir($dir)) { if ($dh = opendir($dir)) { $zip = new ZipArchive(); while (($file = readdir($dh)) !== false) { $filename = $dir . $file; //"./test112.zip"; //print("processing file:" . $filename . "\n"); if ($zip->open($filename, ZIPARCHIVE::CHECKCONS) !== TRUE) { // echo exit("cannot open <$filename>\n"); // print($filename . " cannot open as zip\n"); continue; } $indexName = $file; $description = $zip->getCommentIndex(0); $stat = $zip->statIndex(0); $date = date('d.m.Y', $stat['mtime']); $size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', ''); $zip->close(); if (isset($mapNodes[$indexName])) { $exdate = DateTime::createFromFormat('d.m.Y', $mapNodes[$indexName]->getAttribute("date")); $localdate = DateTime::createFromFormat('d.m.Y', $date); if ($localdate->getTimestamp() <= $exdate->getTimestamp()) { continue; } $out = $mapNodes[$indexName]; if ($out->getAttribute("parts")) { $outputIndexes->removeChild($out); $out = $output->createElement("region"); $outputIndexes->appendChild($out); } } else { $out = $output->createElement("region"); $outputIndexes->appendChild($out); } $out->setAttribute("date", $date); $out->setAttribute("local", "true"); $out->setAttribute("size", $size); $out->setAttribute("name", $indexName); $out->setAttribute("description", $description); //$mapNodes[$indexName] = $out; } closedir($dh); } } else { print $dir . " not a directory!\n"; } $output->save($localFileName); }
/** * Parses a given HTML file and appends its nodes to the current node * list. * * @param string $file Path to the HTML file to parse * @return DomQuery New instance */ public static function fromHtmlFile($file) { $q = new self(); $doc = new DomDocument(); $level = self::toggleDomErrors(); $doc->loadHTMLFile($file); error_reporting($level); self::populate($doc->documentElement, $q); return $q; }