本文整理汇总了PHP中domDocument::getElementById方法的典型用法代码示例。如果您正苦于以下问题:PHP domDocument::getElementById方法的具体用法?PHP domDocument::getElementById怎么用?PHP domDocument::getElementById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domDocument
的用法示例。
在下文中一共展示了domDocument::getElementById方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContent
public function getContent($params = array())
{
$awsCachePath = CACHEPATH . "/aws.status.cxml";
$data = array();
$neededLocations = array();
$services = array('Amazon Elastic Compute Cloud', 'Amazon Relational Database Service', 'Amazon Simple Storage Service');
$compliance = array('us-east-1' => array('name' => 'NA_block', 'filter' => array('N. Virginia', 'US Standard')), 'us-west-1' => array('name' => 'NA_block', 'filter' => 'N. California'), 'us-west-2' => array('name' => 'NA_block', 'filter' => 'Oregon'), 'sa-east-1' => array('name' => 'SA_block', 'filter' => ''), 'eu-west-1' => array('name' => 'EU_block', 'filter' => ''), 'ap-southeast-1' => array('name' => 'AP_block', 'filter' => 'Singapore'), 'ap-southeast-2' => array('name' => 'AP_block', 'filter' => 'Sydney'), 'ap-northeast-1' => array('name' => 'AP_block', 'filter' => 'Tokyo'));
if (empty($params['locations'])) {
$neededLocations = $this->getUsedLocations();
$params['locations'] = $neededLocations;
} else {
$neededLocations = $params['locations'];
}
if (file_exists($awsCachePath) && time() - filemtime($awsCachePath) < 3600) {
clearstatcache();
$time = filemtime($awsCachePath);
$data = (array) json_decode(file_get_contents($awsCachePath));
} else {
$html = @file_get_contents('http://status.aws.amazon.com');
if ($html) {
$dom = new domDocument();
$dom->validateOnParse = false;
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
foreach ($compliance as $compKey => $compValue) {
$div = $dom->getElementById($compValue['name']);
$tables = $div->getElementsByTagName('table');
$rows = $tables->item(0)->getElementsByTagName('tr');
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
if (preg_match('/(.*)(' . implode('|', $services) . ')(.*)/', $cols->item(1)->nodeValue)) {
$regionFilter = $compValue['filter'];
if (is_array($compValue['filter'])) {
$regionFilter = implode('|', $compValue['filter']);
}
if (preg_match('/(.*)(' . $regionFilter . ')(.*)/', $cols->item(1)->nodeValue)) {
$img = '';
$message = '';
if ($cols->item(0)->getElementsByTagName('img')->item(0)->getAttribute('src') == 'images/status0.gif') {
$img = 'normal.png';
} else {
$img = 'disruption.png';
$message = $cols->item(2)->nodeValue;
}
$data[$compKey][substr(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), 0, strpos(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), ' ('))] = array('img' => $img, 'status' => $cols->item(2)->nodeValue, 'message' => $message);
$data[$compKey]['locations'] = $compKey;
}
}
}
}
file_put_contents($awsCachePath, json_encode($data));
}
}
$retval = array('locations' => json_encode($neededLocations));
foreach ($neededLocations as $value) {
$retval['data'][] = $data[$value];
}
return $retval;
}
示例2: parseLicenseTbl
/**
* parseLicenseTbl
* \brief given a fossology license histogram, parse it into license
* names and Show links.
*
* @returns an array of associative arrays with keys of:
* count, showLink, textOrLink. the values will be the license count
* the url of the Show link and whatever is in the next column. This
* can be text or a link or ?
*
* Sets property noRows.
*
* An empty array if no license histogram on that page,
*
*/
function parseLicenseTbl()
{
/*
* Each table row has 3 td's in it. First is the license count, second
* is the show link and third is the license name.
*/
$dom = new domDocument();
@$dom->loadHTML($this->page);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
$table = $dom->getElementById($this->tableId);
if (empty($table)) {
$this->emptyTable = TRUE;
//print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n";
return $this->hList = array();
}
foreach ($table->childNodes as $tblChildNode) {
$histogram = array();
foreach ($tblChildNode->childNodes as $childNode) {
if ($childNode->nodeName == 'td') {
if (is_numeric($childNode->nodeValue)) {
$histogram['count'] = trim($childNode->nodeValue);
}
if ($childNode->nodeValue == 'Show') {
$anchorList = $childNode->getElementsByTagName('a');
foreach ($anchorList as $anchorEle) {
$histogram['showLink'] = $anchorEle->getAttribute('href');
}
}
if (is_string($childNode->nodeValue)) {
$histogram['textOrLink'] = trim($childNode->nodeValue);
}
}
}
// foreach($tblChildNode
$this->hList[] = $histogram;
$histogram = array();
}
// foreach
// for tables with titles, the first row is empty as no childNodes match
// what we are looking for, remove the first row.
if ($this->title) {
// remove empty 1st entry
unset($this->hList[0]);
}
if (empty($this->hList)) {
$this->noRows = TRUE;
}
}
示例3: substr
function apply_change($cadre, &$cache_cadre_object)
{
global $charset, $opac_parse_html;
if (substr($cadre->build_obj, 0, strlen("cms_module_")) == "cms_module_") {
$id_cadre = substr($cadre->build_obj, strrpos($cadre->build_obj, "_") + 1);
if ($cache_cadre_object[$cadre->build_obj]) {
$obj = $cache_cadre_object[$cadre->build_obj];
} else {
$obj = cms_modules_parser::get_module_class_by_id($id_cadre);
$cache_cadre_object[$cadre->build_obj] = $obj;
}
if ($obj) {
//on va chercher ses entetes...
$this->headers = array_merge($this->headers, $obj->get_headers());
$this->headers = array_unique($this->headers);
//on s'occupe du cadre en lui-même
//on récupère le contenu du cadre
$res = $this->manage_cache_cadres("select", $cadre->build_obj, "html");
if ($res["select"]) {
$html = $res["value"];
} else {
$html = $obj->show_cadre();
if ($opac_parse_html) {
$html = parseHTML($html);
}
//on regarde si une condition n'empeche pas la mise en cache !
if ($obj->check_for_cache()) {
$this->manage_cache_cadres("insert", $cadre->build_obj, "html", $html);
}
}
//ca a peut-être l'air complexe, mais c'est logique...
$tmp_dom = new domDocument();
if ($charset == "utf-8") {
@$tmp_dom->loadHTML("<?xml version='1.0' encoding='{$charset}'>" . $html);
} else {
@$tmp_dom->loadHTML($html);
}
if (!$tmp_dom->getElementById($obj->get_dom_id())) {
$this->setAllId($tmp_dom);
}
if ($this->dom->getElementById($cadre->build_parent)) {
$this->dom->getElementById($cadre->build_parent)->appendChild($this->dom->importNode($tmp_dom->getElementById($obj->get_dom_id()), true));
}
$dom_id = $obj->get_dom_id();
//on rappelle le tout histoire de récupérer les CSS and co...
$this->apply_dom_change($obj->get_dom_id(), $cadre);
}
} else {
$this->apply_dom_change($cadre->build_obj, $cadre);
}
}
示例4: trim
<?php
$xmlstring = '<?xml version="1.0" ?>
<!DOCTYPE books [
<!ATTLIST book id ID #IMPLIED>
]>
<books>
<book id="1">
<title>Book 1</title>
</book>
<book id="2">
<title>Book 2</title>
</book>
</books>';
$dom = new domDocument();
/* load XML from string */
$dom->loadXML($xmlstring);
/* get the node identified by id #2 */
$node = $dom->getElementById("2");
print trim($node->nodeValue);
示例5: download
/**
* MANGAREADER VERSION
* Eg. $obj->download('http://www.mangareader.net/202-13447-1/hatsukoi-limited/chapter-1.html');
* @param string $manga_url
*/
function download($manga_url)
{
$html = file_get_contents($manga_url);
$dom = new domDocument();
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
/* PRIMERO BUSCAMOS EL NOMBRE DEL CAPITULO Y CREAMOS EL NOMBRE DE LA CARPETA */
$headings = $dom->getElementsByTagName('h1');
foreach ($headings as $h1) {
echo "<br>File detected: " . ($dir = str_replace(" ", "-", $h1->nodeValue));
}
/* LUEGO BUSCAMOS LAS PAGINAS */
$div = $dom->getElementById("selectpage");
$pages = $div->nodeValue;
/* FILTRAMOS */
echo "<br>Total pages detected: " . ($pos = substr($pages, -(strlen($pages) - 1 - strrpos($pages, "f"))));
/* BUSCAMOS LA URL DE LA IMAGEN */
$img = $dom->getElementsByTagName('img');
$i = 0;
foreach ($img as $element) {
if ($i == 0) {
//guardamos la url de la imagen
echo "<br>Image detected: " . ($imageurl = $element->getAttribute('src'));
break;
}
$i++;
}
/* AHORA TENEMOS QUE EXTRAER EL NUMERO DE LA PRIMERA IMAGEN, dandole la vuelta, extrayendo valores etc...*/
$img_name = strrev(substr(strrev($img_name = urlParameters(5, $imageurl)), 0, strpos(strrev($img_name = urlParameters(5, $imageurl)), "-")));
echo "<br>Id filtered: " . ($id = substr($img_name, 0, strpos($img_name, ".")));
//le quitamos la extension
/*OWNED :)*/
for ($i = 0; $i < $pos; $i++) {
//http://i14.mangareader.net/hatsukoi-limited/1/hatsukoi-limited-312443.jpg
$url = urlParameters(0, $imageurl) . "/" . urlParameters(1, $imageurl) . "/" . urlParameters(2, $imageurl) . "/" . urlParameters(3, $imageurl) . "/" . urlParameters(4, $imageurl) . "/" . urlParameters(3, $imageurl) . "-" . $id . ".jpg";
$id++;
if (saveImg($url, $i . ".jpg", $dir) == 0) {
$error = 1;
}
set_time_limit(20);
}
}
示例6: substr
function apply_change($cadre, &$cache_cadre_object)
{
global $charset, $opac_parse_html;
if (substr($cadre->build_obj, 0, strlen("cms_module_")) == "cms_module_") {
if ($cadre->empty && $_SESSION["cms_build_activate"]) {
$id_cadre = substr($cadre->build_obj, strrpos($cadre->build_obj, "_") + 1);
$obj = cms_modules_parser::get_module_class_by_id($id_cadre);
if ($obj) {
$query = "select cadre_name from cms_cadres where id_cadre = " . $id_cadre;
$result = pmb_mysql_query($query);
$row = pmb_mysql_fetch_object($result);
$html = "<span id='" . $cadre->build_obj . "' class='cmsNoStyles' type='cms_module_hidden' cadre_style='" . $cadre->build_css . "'><div id='" . $cadre->build_obj . "_conteneur' class='cms_module_hidden' style='display:none'>" . $row->cadre_name . "<div style='" . $cadre->build_css . "'></div></div></pan>";
$tmp_dom = new domDocument();
if ($charset == "utf-8") {
@$tmp_dom->loadHTML("<?xml version='1.0' encoding='{$charset}'>" . $html);
} else {
@$tmp_dom->loadHTML($html);
}
if (!$tmp_dom->getElementById($obj->get_dom_id())) {
$this->setAllId($tmp_dom);
}
if ($this->dom->getElementById($cadre->build_parent)) {
$this->dom->getElementById($cadre->build_parent)->appendChild($this->dom->importNode($tmp_dom->getElementById($obj->get_dom_id()), true));
}
$dom_id = $obj->get_dom_id();
//on rappelle le tout histoire de récupérer les CSS and co...
$this->apply_dom_change($obj->get_dom_id(), $cadre);
}
} else {
if (!$cadre->empty) {
$id_cadre = substr($cadre->build_obj, strrpos($cadre->build_obj, "_") + 1);
if ($cache_cadre_object[$cadre->build_obj]) {
$obj = $cache_cadre_object[$cadre->build_obj];
} else {
$obj = cms_modules_parser::get_module_class_by_id($id_cadre);
$cache_cadre_object[$cadre->build_obj] = $obj;
}
if ($obj) {
//on va chercher ses entetes...
$headers = $obj->get_headers();
$this->headers['add'] = array_merge($this->headers['add'], $headers['add']);
$this->headers['replace'] = array_merge($this->headers['replace'], $headers['replace']);
$this->headers['add'] = array_unique($this->headers['add']);
$this->headers['replace'] = array_unique($this->headers['replace']);
//on s'occupe du cadre en lui-même
//on récupère le contenu du cadre
$res = $this->manage_cache_cadres("select", $cadre->build_obj, "html");
if ($res["select"]) {
$html = $res["value"];
} else {
$html = $obj->show_cadre();
if ($opac_parse_html) {
$html = parseHTML($html);
}
//on regarde si une condition n'empeche pas la mise en cache !
if ($obj->check_for_cache()) {
$this->manage_cache_cadres("insert", $cadre->build_obj, "html", $html);
}
}
//ca a peut-être l'air complexe, mais c'est logique...
$tmp_dom = new domDocument();
if ($charset == "utf-8") {
@$tmp_dom->loadHTML("<?xml version='1.0' encoding='{$charset}'>" . $html);
} else {
@$tmp_dom->loadHTML($html);
}
if (!$tmp_dom->getElementById($obj->get_dom_id())) {
$this->setAllId($tmp_dom);
}
if ($this->dom->getElementById($cadre->build_parent)) {
$this->dom->getElementById($cadre->build_parent)->appendChild($this->dom->importNode($tmp_dom->getElementById($obj->get_dom_id()), true));
}
$dom_id = $obj->get_dom_id();
//on rappelle le tout histoire de récupérer les CSS and co...
$this->apply_dom_change($obj->get_dom_id(), $cadre);
}
}
}
} else {
if ($cadre->build_type == "cadre" && $cadre->empty == 1 && $_SESSION["cms_build_activate"]) {
$html = "<span id='" . $cadre->build_obj . "' class='cmsNoStyles' type='cms_module_hidden' cadre_style='" . $cadre->build_css . "'><div id='" . $cadre->build_obj . "_conteneur' class='cms_module_hidden' style='display:none'>" . $cadre->build_obj . "<div style='" . $cadre->build_css . "'></div></div></pan>";
$tmp_dom = new domDocument();
if ($charset == "utf-8") {
@$tmp_dom->loadHTML("<?xml version='1.0' encoding='{$charset}'>" . $html);
} else {
@$tmp_dom->loadHTML($html);
}
if (!$tmp_dom->getElementById($cadre->build_obj)) {
$this->setAllId($tmp_dom);
}
if ($this->dom->getElementById($cadre->build_parent)) {
$this->dom->getElementById($cadre->build_parent)->appendChild($this->dom->importNode($tmp_dom->getElementById($cadre->build_obj), true));
}
}
$this->apply_dom_change($cadre->build_obj, $cadre);
}
}
示例7: str_replace
************************************************************************************************************************************/
/**
* Usage example: find synonym for a word
*/
define("BASE_URL", "http://encarta.msn.com/encnet/features/dictionary/DictionaryResults.aspx");
echo $_REQUEST["key_word"];
$request_url = BASE_URL . "?lextype=2&search=" . $_REQUEST["key_word"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$output = str_replace("class=\"ResultBody\"", "id=\"ResultBody\"", $output);
/*** a new dom object ***/
$dom = new domDocument();
/*** load the output html into the object ***/
$dom->loadHTML($output);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
$html = $dom->saveXML($dom->getElementById("ResultBody"));
$xml = simplexml_load_string($html);
//print_r($html);
$synonyms = str_replace(":", "", simplexml_import_dom($xml));
$result = $xml->xpath('/span/a/b');
$synonyms .= ", ";
while (list(, $node) = each($result)) {
$synonyms .= $node->asXML() . ", ";
}
echo str_replace("</b>", "", str_replace("<b>", "", $synonyms));
示例8: generateTestReport
//.........这里部分代码省略.........
$table_cell_a->setAttribute('href', $table_cell_a_href);
}
}
$report_results_table = $body->appendChild($report_results_table);
$os_name = array();
$os_name['linux'] = "Linux";
$os_name['win7'] = "Windows 7";
$os_name['xp'] = "Windows XP";
$os_name['osx'] = "Mac OS X";
$os_name['osx10.5'] = "Mac OS X 10.5";
$os_name['iphone'] = "iPhone 0S";
$os_name['android'] = "Android";
$last_run_name = "";
$result_runs = mysql_queryf("SELECT id,name FROM runs WHERE job_id=%s", $job_id);
while ($row_runs = mysql_fetch_array($result_runs)) {
$run_id = $row_runs[0];
$run_name = $row_runs[1];
$result = mysql_queryf("SELECT results,useragents.engine,os,useragents.name,url,runs.id,clients.id FROM run_client,clients,useragents,runs,jobs WHERE (run_client.client_id=clients.id AND clients.useragent_id=useragents.id AND run_client.run_id=runs.id AND runs.job_id=jobs.id AND runs.id=%s)", $run_id);
while ($row = mysql_fetch_array($result)) {
/* prepend a correct DTD otherwise the PHP DOM parser won't work correctly */
$report_html = $dtd_string . gzdecode($row[0]);
$report_html = preg_replace('/<html>/', '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" dir="ltr">', $report_html);
$client_id = $row[6];
$run_id = $row[5];
$test_url = $row[4];
$browser_name = $row[3];
$os = $os_name[$row[2]];
$os_shortname = $row[2];
$engine = $row[1];
if (strlen($os) < 1) {
$os = $row[2];
}
$dom = new domDocument();
$dom->loadHTML($report_html);
$dom->preserveWhiteSpace = false;
$qunit_header = $dom->getElementById('qunit-header');
$qunit_banner = $dom->getElementById('qunit-banner');
$qunit_useragent = $dom->getElementById('qunit-userAgent');
$qunit_tests = $dom->getElementById('qunit-tests');
$qunit_testresult = $dom->getElementById('qunit-testresult');
if ($qunit_testresult == NULL) {
/* happens when test timed out */
continue;
}
$testresults = $qunit_testresult->getElementsByTagName('span');
foreach ($testresults as $testresult) {
$testresult_class = $testresult->getAttribute('class');
if ($testresult_class == "passed") {
$qunit_passed = $testresult->nodeValue;
} else {
if ($testresult_class == "failed") {
$qunit_failed = $testresult->nodeValue;
} else {
if ($testresult_class == "total") {
$qunit_total = $testresult->nodeValue;
}
}
}
}
if ($run_name != $last_run_name) {
$body->appendChild($report->createElement('br'));
$report_qunit_header = $report->importNode($qunit_header, true);
$report_qunit_header_text = $report_qunit_header->nodeValue;
$report_qunit_header->nodeValue = "";
$report_qunit_header_a = $report->createElement('a');
$report_qunit_header_a_anchor = preg_replace('/(.*\\/)(.*)\\.(.*)/', '$2', $test_url);
$report_qunit_header_a->setAttribute('name', $report_qunit_header_a_anchor);
$report_qunit_header_a->setAttribute('href', "#report_top");
$report_qunit_header_a->setAttribute('title', "go back to top");
$report_qunit_header_a->nodeValue = $report_qunit_header_text;
$report_qunit_header->appendChild($report_qunit_header_a);
$report_qunit_header = $body->appendChild($report_qunit_header);
$last_run_name = $run_name;
}
$report_qunit_banner = $report->importNode($qunit_banner, true);
$report_qunit_banner = $body->appendChild($report_qunit_banner);
$report_qunit_useragent = $report->importNode($qunit_useragent, true);
$report_qunit_useragent_browser_icon = $report->createElement('img');
$report_qunit_useragent_browser_icon->setAttribute('style', 'width: 16px; height: 16px;' . 'padding-top: 0px; padding-bottom: 0px;' . 'padding-left: 0px; padding-right: 6px;');
$report_qunit_useragent_browser_icon->setAttribute('src', $resource_path . 'images/' . $engine . '.sm.png');
$report_qunit_useragent_os_icon = $report->createElement('img');
$report_qunit_useragent_os_icon->setAttribute('style', 'width: 16px; height: 16px;' . 'padding-top: 0px; padding-bottom: 0px;' . 'padding-left: 0px; padding-right: 6px;');
$report_qunit_useragent_os_icon->setAttribute('src', $resource_path . 'images/os/' . $os_shortname . '.sm.png');
$report_qunit_useragent_span = $report->createElement('span');
$report_qunit_useragent_span->nodeValue = "{$browser_name} / {$os} - useragent: " . $report_qunit_useragent->nodeValue;
$report_qunit_useragent_span->setAttribute('id', "r" . $run_id . "c" . $client_id);
$report_qunit_useragent_span->setAttribute('title', 'click to expand / collapse');
$report_qunit_useragent->nodeValue = "";
$report_qunit_useragent->appendChild($report_qunit_useragent_browser_icon);
$report_qunit_useragent->appendChild($report_qunit_useragent_os_icon);
$report_qunit_useragent->appendChild($report_qunit_useragent_span);
$report_qunit_useragent = $body->appendChild($report_qunit_useragent);
$report_qunit_tests = $report->importNode($qunit_tests, true);
$report_qunit_tests = $body->appendChild($report_qunit_tests);
$report_qunit_testresult = $report->importNode($qunit_testresult, true);
$report_qunit_testresult = $body->appendChild($report_qunit_testresult);
}
}
return $report;
}
示例9: array
// URL of project list
$url_module_usage_base_url = "http://drupal.org";
$url_module_usage = $url_module_usage_base_url . "/project/usage";
// get the list of all project names
echo "\nLoading project list ... ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_module_usage);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
// Parsing the list in order to get more informations
$projects = array();
$dom = new domDocument();
@$dom->loadHtml($html);
$table = $dom->getElementById("project-usage-all-projects");
$rows = $table->getElementsByTagName("tr");
$cpt = 0;
foreach ($rows as $row) {
$project = $row->getElementsByTagName('a')->item(0);
$project_name = $project->nodeValue;
$url = $url_module_usage_base_url . $project->getAttribute('href');
$pos_slash = strrpos($url, "/");
$project_id = substr($url, $pos_slash + 1);
$projects[] = array("id" => $project_id, "name" => $project_name);
if ($nb_modules_to_scan != 0 && count($projects) == $nb_modules_to_scan) {
break;
}
}
$nb_projects = count($projects);
echo $nb_projects . " projects\n\n";
示例10: date
if ($_POST['cbr'] == 1) {
$url = "http://www.cbr.ru/currency_base/D_print.aspx?date_req=" . date('d.m.Y', time());
}
$html = file_get_contents($url);
//read the file
if ($_POST['cbr'] == 1) {
$pos = utf8_strpos($html, '<div class="header2"');
$html = utf8_substr($html, $pos, utf8_strlen($html));
$message[0] = 'valid';
$message[1] = 'Котировки успешно обновлены';
}
$dom = new domDocument();
@$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
if ($_POST['market'] == 1) {
$block = $dom->getElementById('markets');
$sql_table = '#__parser_market';
}
if ($_POST['currencies'] == 1) {
$block = $dom->getElementById('currencies');
$sql_table = '#__parser_curr';
}
if ($_POST['cbr'] == 1) {
$sql_table = '#__parser_cbr';
}
if ($_POST['market'] == 1 or $_POST['currencies'] == 1) {
$tables = $block->getElementsByTagName('table');
}
if ($_POST['cbr'] == 1) {
$tables = $dom->getElementsByTagName('table');
}
示例11: parseBrowseMenuFiles
function parseBrowseMenuFiles()
{
$dom = new domDocument();
@$dom->loadHTML($this->page);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
$table = $dom->getElementById($this->tableId);
if (empty($table)) {
$this->emptyTable = TRUE;
print "DPLTDB: table is empty, can't find table! with table id of:{$this->tableId}\n";
return $this->browseList = array();
}
foreach ($table->childNodes as $tblChildNode) {
if ($tblChildNode->nodeName == 'tr') {
$childNodes = $tblChildNode->childNodes;
$clen = $childNodes->length;
for ($i = 0; $i < $clen; $i++) {
$node = $childNodes->item($i);
$nn = $node->nodeName;
if ($node->nodeName == 'td') {
$fileName = $node->nodeValue;
$childNodes = $node->childNodes;
$tdclen = $childNodes->length;
for ($i = 0; $i < $tdclen; $i++) {
$tdnode = $childNodes->item($i);
$tdnn = $tdnode->nodeName;
//print "\tname of td-node is:$tdnn\n";
if ($tdnn == '#text') {
$tdNodeValue = $tdnode->nodeValue;
//print "\tDB-td: #text node value is:$tdNodeValue\n";
$fromFS = 'Added from filesystem:';
$fromFile = 'Added by file upload:';
$fromURL = 'Added by URL:';
$matches = 0;
if ($matches = preg_match("/{$fromFile}/", $tdNodeValue, $ffMatch)) {
$fileUploadName = $this->fromFile($tdNodeValue);
$this->getAnchors($node, $fileUploadName);
} else {
if ($matches = preg_match("/{$fromFS}/", $tdNodeValue, $fsMatch)) {
$fsUploadName = $this->fromFS($tdNodeValue);
$this->getAnchors($node, $fsUploadName);
} else {
if ($matches = preg_match("/{$fromURL}/", $tdNodeValue, $urlMatch)) {
$urlUploadName = $this->fromURL($tdNodeValue);
$this->getAnchors($node, $urlUploadName);
}
}
}
}
}
}
}
}
if (!empty($this->anchors)) {
$this->browseList = array_merge($this->browseList, $this->anchors);
$this->anchors = array();
}
}
// foreach
if (empty($this->browseList)) {
$this->noRows = TRUE;
}
//print "at the end of parse, browseList is:\n";print_r($this->browseList) . "\n";
}
示例12: setDefaultValuesOnAutoUpdateSettings
public function setDefaultValuesOnAutoUpdateSettings()
{
$this->initAdminCurlConnection();
curl_setopt($this->curl_connection, CURLOPT_URL, $this->app->getAppUrl() . '/admin/index.php');
$result = curl_exec($this->curl_connection);
/*** a new dom object ***/
$dom = new domDocument();
/*** load the html into the object ***/
$dom->loadHTML($result);
$postdata = null;
// Attempt to get the form on page which saves settings data. If it is not found, this means
// that the current page just needs a simple "Continue"
$adminForm = $dom->getElementById('adminsettings');
if ($adminForm) {
// If we have a setting form to complete, copy all form fields so we
// can issue a post request with the default values
$inputTags = $adminForm->getElementsByTagName('input');
$selectTags = $adminForm->getElementsByTagName('select');
$textareaTags = $adminForm->getElementsByTagName('textarea');
}
$postString = "";
// This loop scrapes all of the input tag values
foreach ($inputTags as $tag) {
if ($tag->hasAttribute('name')) {
$postdata[$tag->getAttribute('name')] = $tag->getAttribute('value');
}
}
foreach ($textareaTags as $tag) {
if ($tag->hasAttribute('name')) {
$value = $tag->getAttribute('value');
if (empty($value)) {
$value = $this->get_inner_html($tag);
}
$postdata[$tag->getAttribute('name')] = $value;
}
}
// This loop scrapes the default selected value in a select tag
foreach ($selectTags as $tag) {
$optionTags = $tag->getElementsByTagName('option');
foreach ($optionTags as $oTag) {
// pick the first option
if (!$postdata[$tag->getAttribute('name')]) {
$postdata[$tag->getAttribute('name')] = $oTag->getAttribute('value');
}
// overwrite the first option if a selected attribute is listed
if ($oTag->hasAttribute('selected')) {
$postdata[$tag->getAttribute('name')] = $oTag->getAttribute('value');
}
}
}
// This loop converts the scraped data into a formatted postdata string
foreach ($postdata as $key => $value) {
$postString .= $seperator . $key . '=' . $value;
$seperator = '&';
}
// Set the post fields and execute the curl request
curl_setopt($this->curl_connection, CURLOPT_POSTFIELDS, $postString);
//set data to be posted
$result = curl_exec($this->curl_connection);
/*** a new dom object ***/
$dom = new domDocument();
/*** load the html into the object ***/
$dom->loadHTML($result);
$formTags = $dom->getElementsByTagName('div');
foreach ($formTags as $tag) {
if ($tag->getAttribute('class') == 'box copyright') {
return true;
}
}
return false;
}