diff --git a/examples/basic-docx-parser/index.php b/examples/basic-docx-parser/index.php new file mode 100644 index 00000000..f4339d08 --- /dev/null +++ b/examples/basic-docx-parser/index.php @@ -0,0 +1,115 @@ +find('w|r') as $qr) { + echo format($qr); + } + + echo '
'; + } +} catch (Exception $e) { + die($e->getMessage()); +} + +/** + * Get the node text and apply basic formatting, if necessary + * + * @param DOMQuery $qp + * + * @return string + * @throws ParseException + * @throws Exception + */ +function format(DOMQuery $qp): string +{ + $text = $qp->find('w|t')->text() . ' '; + + $text = checkUnderline($qp) ? sprintf('%s', $text) : $text; + $text = checkBold($qp) ? sprintf('%s', $text) : $text; + + return $text; +} + +/** + * Look for the node to determine if the text is bolded + * + * @param DOMQuery $qp + * + * @return bool + * @throws ParseException + * @throws Exception + */ +function checkBold(DOMQuery $qp): bool +{ + return (bool) $qp->children('w|rPr') + ->children('w|b') + ->count(); +} + +/** + * Look for the node to determine if the text is underlined + * + * @param DOMQuery $qp + * + * @return bool + * @throws ParseException + * @throws Exception + */ +function checkUnderline(DOMQuery $qp): bool +{ + return (bool) $qp->children('w|rPr') + ->children('w|u') + ->count(); +} + +/** + * Extract the text from a docx file + * + * @param string $archiveFile The path to the .docx file to extract information from + * @return string + */ +function docx2text(string $archiveFile): string +{ + $dataFile = 'word/document.xml'; + + if (!class_exists('ZipArchive', false)) { + throw new RuntimeException('ZipArchive extension must be enabled to parse .docx files'); + } + + $zip = new ZipArchive(); + // Open received archive file + if (true !== $zip->open($archiveFile)) { + throw new RuntimeException('Could not open the file using ZipArchive: ' . $zip->getStatusString()); + } + + $data = ''; + // Search for the docx data file + if (($index = $zip->locateName($dataFile)) !== false) { + $data = $zip->getFromIndex($index); + } + + // Close zip to prevent memory leak + $zip->close(); + + return $data; +} diff --git a/examples/basic-docx-parser/output.xml b/examples/basic-docx-parser/output.xml new file mode 100644 index 00000000..d7341169 --- /dev/null +++ b/examples/basic-docx-parser/output.xml @@ -0,0 +1,2035 @@ + + + + + + + + + + + + + + + + + + + + + + Computer Forensics Class Syllabus + + + + + + + + + - + + + + + + + + + + Fall + + + + + + + + + + 2009 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Course No.: + + + + + + + + + Comp 340-001 / + + + + + + + + Comp 488-004 + + + + + + + + + + + + + + + + + + + + + + + + + + + INSTRUCTOR: + + + + + + + + + + + + + + + + + Scott Jones + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Email + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sjone18@luc.edu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Work Phone + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 312-915-7987 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Office Location + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 512D Lewis Tower + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Office Hours + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6PM to 7PM Wednesdays or by appt. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OFFICIAL TEXT: + + + + + + + + + + + + + + + + + + + + + + + “Computer Evidence Collection and Preservation Second Edition” + + + + + + + + + + + + + + + + + by + + + + + + + + Christopher L.T. Brown, ISBN-10: 1-58450-699-7 + + + + + + + + + + + + + + + + + + + + + + + + + The schedule of class readings is officially as follows: + + + + + + + + + + + + + + + + + + + + + + + + + Week + + + + + + + + + + + + + + + Date + + + + + + + + + + + + + + + Book Chapter To Read + + + + + + + + + + + + + + + + ------------------------ + + + + + + + ----------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + 8/26 + + + + + + + + + + + + + + N/A – Class Intro + + + + + + + + + + + + + + + + + + + + + 9/2 + + + + + + + + + + + + + + + Chapters 1 & 2 + + + + + + + + + + + + + + + + + + + + + 9/9 + + + + + + + + + + + + + + + Chapters 3 & 4 + + + + + + + + + + + + + + + + + + + + + 9/16 + + + + + + + + Chapters 5 & 6 + + + + + + + + + + + + + + + + + + + + + 9/23 + + + + + + + + Chapters 7 & 8 + + + + + + + + + + + + + + + + + + + + + 9/30 + + + + + + + + Chapters 9 & 10 + + + + + + + + + + + + + + + + + + + + + 10/7 + + + + + + + + Chapters 11 & 12 + + + + + + + + + + + + + + + + + + + + + 10/14 + + + + + + + + Chapters 13 & 14 + + + + + + + + + + + + + + + + + + + + + 10/21 + + + + + + + + Chapters 15, 16, & 17 + + + + + + + + + + + + + + + + + + + + + 10/28 + + + + + + + + In-class projects + + + + + + + + + + + + + + + + + + + + + 11/4 + + + + + + + + In-class projects + + + + + + + + + + + + + + + + + + + + + 11/11 + + + + + + + + In-class projects + + + + + + + + + + + + + + + + + + + + + 11/18 + + + + + + + + In-class projects + + + + + + + + + + + + + + + + + + + + + 11/25 + + + + + + + + In-class projects + + + + + + + * + + + + + + + + + + + + + + + + + + + + + 12/2 + + + + + + + + In-class projects + + + + + + + + + + + + + + + + + + + + + 12/9 + + + + + + + + In-class projects + + + + + + + * + + + + + + + + + + + + + + + + + + + + + 12/16 + + + + + + + + In-class projects + + + + + + + * + + + + + + + + + + + + + + + + + + + + + + + + + + + Class readings and assignments may change as needed. + + + + + + + 12/9/09 is generally designated a rest/study day in the academic calendar, so class may not be + meeting. 12/16/09 is the final Wednesday within this semester and the tentative date for the final + exam. This may be changed with short notice by the school as needed. + + + + + + + + To the extent that a given date for class is cancelled by the school for any reason, that week’s reading will be bumped back accordingly. + + + + + + + + + + + + + + + + + + + + + + + + + As newsworthy events become available, we may supplement our classroom discussions accordingly. I + encourage all students to pay attention to news stories on television or the Internet related to + computer forensics and computer technology in general. + + + + + + + + + + + + + + + + + + + + + + + + + + + + IN-CLASS PROJECTS: + + + + + + + + Starting in week four, this class will begin to conduct in-class work using real-world computer + forensics hardware and/or software. In order to accomplish this, I highly recommend that each + student bring two or more USB thumb drives to class. I recommend that the smaller of the two be + around 512 MB in size and the larger one be at least 2 GB in size. + + + + + + + + + + + + + + + + + + + + + + + + + + + + QUIZZES & TESTS: + + + + + + + + All quizzes and tests will be administered via Blackboard. Without prior arrangements I will not + accept make up quizzes or tests. Emergencies require that I receive an email in a timely fashion (24 + hour period) telling me your name, the date you missed class, and explaining to me why I should + allow you to take the quiz or test late. By default my answer will be no. If I allow you to retake + the quiz or test, I reserve the right to deduct points accordingly for your lateness. + + + + + + + + I reserve the right to give pop quizzes at any time. + + + + + + + + + + + + + + + + + + + + + + + + + + + GROUPWORK: + + + + + + + + + + + + + + + Each student will be sharing a laptop computer with at least one other student each week. I may + also require students + + + + + + + + to work in larger groups for specific tasks/projects. I reserve the right to ask specific students to swap groups if/when I find that students are not intermingling adequately. In the real world, you do not always get to choose with whom you work, and this class strives to provide real world examples and experience. + + + + + + + + + + + + + + + + + + + + + + + + + + + GOALS: + + + + + + + + + + + + + + + There are a few specific goals for which this class will strive. + + + + + + + + + + + + + + + + + GOAL 1 – by mid-term, every student will have created at least one or more forensic images + + + + + + + + + + + + + + + + + GOAL 2 – every student understands how to create basic forensic images + + + + + + + + + + + + + + + + + GOAL 3 – every student understands the fundamental theories underlying computer forensics + + + + + + + + + + + + + + + + + GOAL 4 – every student will gain basic skills desired presently by employers for IT staff + + + + + + + + + + + + + + + + + + + + + + + + + + + GRADE SCALE: + + + + + + + + Every student EARNS their own grade. The grading scale is as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + 92+ + + + + + + + + + + + + + + + A + + + + + + + + + + + + + + + + + 91 + + + + + + + + + + + + + + + A- + + + + + + + + + + + + + + + + + 90 + + + + + + + + + + + + + + + B+ + + + + + + + + + + + + + + + + + 89 – 84 + + + + + + + + + + + + + + + B + + + + + + + + + + + + + + + + + 83 + + + + + + + + + + + + + + + B- + + + + + + + + + + + + + + + + + 82 + + + + + + + + + + + + + + + C+ + + + + + + + + + + + + + + + + + 81 + + + + + + + -75 + + + + + + + + + + + + + + + C + + + + + + + + + + + + + + + + + 74 + + + + + + + + + + + + + + + C- + + + + + + + + + + + + + + + + + 73 + + + + + + + + + + + + + + + D+ + + + + + + + + + + + + + + + + + 72-67 + + + + + + + + + + + + + + + D + + + + + + + + + + + + + + + + + 66 + + + + + + + + + + + + + + + D- + + + + + + + + + + + + + + + + + 65 or less + + + + + + + + F + + + + + + + + + + + + + + + + + + + + + + + + + + + Instructor Comments: + + + + + + + + There are no dumb questions, only unasked ones. If you do not understand something it is your + responsibility to let me know. Please ask questions in class, during breaks, after class, and even + via email if you like. I will assume you understand and m + + + + + + + + ove on if you do not inform me otherwise + + + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + I welcome feedback from my students. Please feel free to send an email to the above LUC email address. No class-related emails at any other address will be accepted. + + + + + + + + + + \ No newline at end of file diff --git a/examples/test.docx b/examples/basic-docx-parser/test.docx similarity index 100% rename from examples/test.docx rename to examples/basic-docx-parser/test.docx diff --git a/examples/basic-manipulation-filter-and-retrieval/index.php b/examples/basic-manipulation-filter-and-retrieval/index.php index 6584822d..48983897 100644 --- a/examples/basic-manipulation-filter-and-retrieval/index.php +++ b/examples/basic-manipulation-filter-and-retrieval/index.php @@ -21,47 +21,6 @@ EOF; -echo '

Basic HTML Usage

'; -echo 'The following HTML chunk will get parsed, traverse, filtered, and manipulated:'; -echo '
' . htmlspecialchars($html) . '
'; - -echo '

Example 1

'; -echo 'Add the attribute class="cell" to all <td> elements:'; - -echo '
';
-
-echo htmlspecialchars(
-	html5qp($html, 'td')
-		->attr('class', 'cell')
-		->top() // return to  tag
-		->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
-);
-
-echo '
'; - -echo '

Example 2

'; -echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
'; - -echo html5qp($html) - ->find('#row2 > td:nth-child(2)') - ->text(); - -echo ''; - -echo '

Example 3

'; -echo 'Append another row to the HTML and output the results:'; -echo '
';
-
-echo htmlspecialchars(
-	html5qp($html, 'tr:last')
-		->after("\n\n\t\n\t\tseven\n\t\teight\n\t\tnine\n\t")
-		->top() // return to  tag
-		->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
-);
-
-echo '
'; - - /* * XML Example */ @@ -86,42 +45,87 @@ EOF; -echo '

Basic XML Usage

'; -echo 'The following XML will get parsed, traverse, filtered, and manipulated:'; -echo '
' . htmlspecialchars($xml) . '
'; +try { + echo '

Basic HTML Usage

'; + echo 'The following HTML chunk will get parsed, traverse, filtered, and manipulated:'; + echo '
' . htmlspecialchars($html) . '
'; + + echo '

Example 1

'; + echo 'Add the attribute class="cell" to all <td> elements:'; + + echo '
';
+
+	echo htmlspecialchars(
+		html5qp($html, 'td')
+			->attr('class', 'cell')
+			->top() // return to  tag
+			->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+	);
+
+	echo '
'; + + echo '

Example 2

'; + echo 'Use html5qp($html)->find(\'#row2 > td:nth-child(2)\')->text(); to display the contents of the second <td> in the second <tr>:
'; + + echo html5qp($html) + ->find('#row2 > td:nth-child(2)') + ->text(); + + echo ''; + + echo '

Example 3

'; + echo 'Append another row to the HTML and output the results:'; + echo '
';
+
+	echo htmlspecialchars(
+		html5qp($html, 'tr:last')
+			->after("\n\n\t\n\t\tseven\n\t\teight\n\t\tnine\n\t")
+			->top() // return to  tag
+			->innerHTML5() // get mark-up without . Use ->html5() to return a valid HTML document (Doctype and all)
+	);
+
+	echo '
'; + + echo '

Basic XML Usage

'; + echo 'The following XML will get parsed, traverse, filtered, and manipulated:'; + echo '
' . htmlspecialchars($xml) . '
'; -echo '

Example 1

'; -echo 'Add the attribute class="item" to all <desc> elements:'; + echo '

Example 1

'; + echo 'Add the attribute class="item" to all <desc> elements:'; -echo '
';
+	echo '
';
 
-echo htmlspecialchars(
-	qp($xml, 'desc')
-		->attr('class', 'item')
-		->top() // return to the  tag
-		->xml() // output a valid XML document. Use ->innerXML() to get the contents of  instead.
-);
+	echo htmlspecialchars(
+		qp($xml, 'desc')
+			->attr('class', 'item')
+			->top() // return to the  tag
+			->xml() // output a valid XML document. Use ->innerXML() to get the contents of  instead.
+	);
 
-echo '
'; + echo '
'; -echo '

Example 2

'; -echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
'; + echo '

Example 2

'; + echo 'Use qp($xml)->find(\'categories > category:nth-child(3) desc\')->text(); to display the contents of the third <desc>:
'; -echo qp($xml) - ->find('categories > category:nth-child(3) desc') - ->text(); + echo qp($xml) + ->find('categories > category:nth-child(3) desc') + ->text(); -echo ''; + echo '
'; -echo '

Example 3

'; -echo 'Append another category to the XML and output the results:'; -echo '
';
+	echo '

Example 3

'; + echo 'Append another category to the XML and output the results:'; + echo '
';
 
-echo htmlspecialchars(
-	qp($xml, 'category:last')
-		->after("\n\n\t\n\t\tThe appended node...\n\t")
-		->top()
-		->xml()
-);
+	echo htmlspecialchars(
+		qp($xml, 'category:last')
+			->after("\n\n\t\n\t\tThe appended node...\n\t")
+			->top()
+			->xml()
+	);
 
-echo '
'; + echo '
'; +} catch (\QueryPath\Exception $e) { + // Handle QueryPath exceptions + die($e->getMessage()); +} diff --git a/examples/dirty_html.php b/examples/dirty_html.php deleted file mode 100644 index 391c47bf..00000000 --- a/examples/dirty_html.php +++ /dev/null @@ -1,19 +0,0 @@ -Urban Dictionary Random Word Generator'; - -$page = rand(0, 288); -$qp = htmlqp('http://www.urbandictionary.com/?page=' . $page, '#home'); - -$rand = rand(0, 7); -print $qp->find('.word')->eq($rand)->text() . '
'; -print $qp->top()->find('.definition')->eq($rand)->text(); diff --git a/examples/docx.php b/examples/docx.php deleted file mode 100644 index 6b872a29..00000000 --- a/examples/docx.php +++ /dev/null @@ -1,117 +0,0 @@ -branch(); - print format($qr->find('w|r:first'), 'w|r:first') . ' '; - $qp->find('w|r:first'); - while ($qp->next('w|r')->html() != null) { - $qr = $qp->branch(); - print format($qr->find('w|r'), 'w|r') . ' '; - // print $qp->text(); - } - print '
'; -} - -/** - * - * @param QueryPath $qp - * @param String $findSelector - * - * @return String - */ -function format($qp, $findSelector = null) -{ - - // Create a new branch for printing later. - $qr = $qp->branch(); - - $text = ""; - - $text = $qr->find($findSelector)->find('w|t')->text(); - - $text = (checkUnderline($qp->branch())) ? '' . $text . '' : $text; - $text = (checkBold($qp->branch())) ? '' . $text . '' : $text; - - return $text; -} - -/** - * - * @param QueryPath $qp - * - * @return String - */ -function checkBold($qp) -{ - $qp->children("w|rPr"); - - return ($qp->children('w|b')->html()) ? true : false; -} - -/** - * - * @param QueryPath $qp - * - * @return String - */ -function checkUnderline($qp) -{ - $qp->children("w|rPr"); - - return ($qp->children('w|u')->html()) ? true : false; -} - - -function docx2text($filename) -{ - return readZippedXML($filename, "word/document.xml"); -} - -function readZippedXML($archiveFile, $dataFile) -{ - if (! class_exists('ZipArchive', false)) { - return "ZipArchive Class Doesn't Exist."; - } - // Create new ZIP archive - $zip = new ZipArchive(); - // Open received archive file - if (true === $zip->open($archiveFile)) { - // If done, search for the data file in the archive - if (($index = $zip->locateName($dataFile)) !== false) { - // If found, read it to the string - $data = $zip->getFromIndex($index); - // Close archive file - $zip->close(); - // Load XML from a string - // Skip errors and warnings - return $data; - // $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); - // // Return data without XML formatting tags - // return strip_tags($xml->saveXML()); - } - $zip->close(); - } - - // In case of failure return empty string - return $zip->getStatusString(); -} diff --git a/examples/docx_document.xml b/examples/docx_document.xml deleted file mode 100644 index fcf8614f..00000000 --- a/examples/docx_document.xml +++ /dev/null @@ -1,3914 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - I. Para - - - - - - - - - : - - - - - - - - - - - - - - - - - - - - - - - 1. In order to + infinitive (Hago ejercicos - - - - - - - - - - para - - - - - - - - rebajar) (Tomo la medicina - - - - - - - - - - para - - - - - - - - sentirme mejor) - - - - - - - - - - - - - - - - - - - - - - - - - 2. For = destined for, to be given to (Todo mi amor es - - - - - - - - - - - para - - - - - - - - - ti) - - - - - - - - - - - - - - - - - - - - - - - 3. For = by deadline, specified future time (La tarea es - - - - - - - - - - para - - - - - - - - el lunes) - - - - - - - - - - - - - - - - - - - - - - - (Es - - - - - - - - - - para - - - - - - - - las cinco de la tarde) - - - - - - - - - - - - - - - - - - - - - - - - - 4. For = toward in the direction of (destination) (Sarah salió - - - - - - - - - - - para - - - - - - - - - España) - - - - - - - - - - - - - - - - - - - - - - - (Manolo Salió - - - - - - - - - - para - - - - - - - - el campo) - - - - - - - - - - - - - - - - - - - - - - - - - 5. For = to be used for (purpose of an object) (La taza es - - - - - - - - - - - para - - - - - - - - - el café) - - - - - - - - - - - - - - - - - - - - - - - (El dinero es - - - - - - - - - - para - - - - - - - - la matricula) - - - - - - - - - - - - - - - - - - - - - - - 6. For = as compared with others, in relation to others ( - - - - - - - - - - - Para - - - - - - - - mí, el español es fácil) ( - - - - - - - - - - Para - - - - - - - - ser extranjero, habla muy bien el inglés) - - - - - - - - - - - - - - - - - - - - - - - - - 7. For = in the employ - - - - - - - - ment - - - - - - - - of (Trabajan - - - - - - - - - - para - - - - - - - - el gobierno) (Nosotros trabajamos - - - - - - - - - - para - - - - - - - - la universidad) - - - - - - - - - - - - - - - - - - - - - - - - - - - II - - - - - - - - - - . Por: - - - - - - - - - - - - - - - - - - - - - - - 1. By means of (voy a España - - - - - - - - - - por - - - - - - - - avión) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2. Through, along ( Camino por el parque) (Paseo - - - - - - - - - - por - - - - - - - - la ciudad) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3. Duration of time, time of day, (Trabajo - - - - - - - - - - por - - - - - - - - la noche, trabajo - - - - - - - - - - por - - - - - - - - cinco horas) - - - - - - - - - - - - - - - - - - - - - - - (Voy a Perú - - - - - - - - - - por - - - - - - - - un año) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4. Because of, due to (Estoy nervioso - - - - - - - - - - por - - - - - - - - la entrevista) (Megan tiene tos - - - - - - - - - - por - - - - - - - - el resfriado) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5. For = in Exchange for (Te cambio mi BMW - - - - - - - - - - por - - - - - - - - tu Mercedes) - - - - - - - - - - - - - - - - - - - - - - - (Compré un CD - - - - - - - - - - por - - - - - - - - 10 dólares) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 6. For = for the sake of, on behalf of (Lo hago - - - - - - - - - - - por - - - - - - - - - ti) (Trabajo - - - - - - - - - - - por - - - - - - - - - los niños) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 7. To do something for someone else (a favor) (Esta semana, Juan va a trabajar - - - - - - - - - - por - - - - - - - - María) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Por is also used with some “fixed expressions” (Know them) - - - - - - - - - - - - - - - - - - - - - - - - - - - - Por Dios - - - - - - - - - (for heaven’s sake) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Por ejemplo - - - - - - - - (for example) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Por ahí, por allí - - - - - - - - - - (around there) - - - - - - - - - - - - - - - - - - - - - - - - - - - Por eso - - - - - - - - - (that’s why) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Por cierto - - - - - - - - - (by the way) - - - - - - - - - - - - - - - - - - - - - - - - - Por favor - - - - - - - - (please) - - - - - - - - - - - - - - - - - - - - - - - - - Por fin - - - - - - - - (finally) - - - - - - - - - - - - - - - - - - - - - - - - - Por lo general - - - - - - - - (in general, generally) - - - - - - - - - - - - - - - - - - - - - - - - - Por lo menos - - - - - - - - (at least) - - - - - - - - - - - - - - - - - - - - - - - - - - - Por primera/última vez - - - - - - - - - (for the first/last time) - - - - - - - - - - - - - - - - - - - - - - - - - Por si acaso - - - - - - - - (just in case) - - - - - - - - - - - - - - - - - - - - - - - - - Por supuesto - - - - - - - - (of course) - - - - - - - - - - - - - - - - - - - - - - - - - Por todas partes - - - - - - - - (everywhere) - - - - - - - - - - - - - - - - - - - - - - - - - Por ahora - - - - - - - - (for now) - - - - - - - - - - - - - - - - - - - - - - - - - Por lo visto - - - - - - - - (apparently) - - - - - - - - - - - - - - - - - - - - - - - - - Por último - - - - - - - - (finally) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - A. - - - - - - - - - - - - - - - - - - - - Por y Para 1- - - - - - - - - - Un viaje a Costa Rica-Write por or para in the lines below, depending on the context. - - - - - - - - - - - - - - - - - - - - - - - - - Ellos hicieron un viaje a Costa Rica ______________ - (1)cinco semanas. Viajaron ______________(2) avión y cuando - llegaron al país, tomaron unos taxis______________(3) ir a su - hotel.____________(4) ser viajeros en un país extranjero, - tenían mucho miedo al principio del viaje. Cuando llegaron al - hotel, entraron _____________(5) las puertas principales y - subieron ______________(6) el elevador para llegar a sus - propias habitaciones. Estaban emocionados de ir a este nuevo - país____________(7) conocer sus lugares turisticos. - ____________(8) disfrutar del lugar, ellos salían a los discos - ___________(9) las noches. Después de entrar en las - discos___________(10) bailar, podían comprar bebidas caras. - Casi siempre cuesta menos de dos dólares_____________(11) una - cerveza. Pero hay muchas otras cosas que hicieron durante su - visita. Ellos no fueron allá solamente ___________(12) - festejar. Hay muchas cosas diferentes en Costa Rica que no hay - en los Estados Unidos.__________(13) ejemplo, el paisaje es - algo que no se puede encontrar en todas partes del mundo. La - mayoría de los estudiantes gozaron su viaje y les - - - - - - - - - - - - - - - - - - gustaría ir__________(14) Latinoamérica otra vez. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - B. Por y Para 2- - - - - - - - - Complete los siguientes diálogos y oraciones utilizando por - o para: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1. Carla, Kyra y Melissa salieron__________Pepe’s ayer. Van - a Pepe’s _________coche y luego de ir a Pepe’s irán a pa - - - - - - - - s - - - - - - - - ear _________toda la ciudad. Va a ser una buena experiencia - ________las tres. - - - - - - - - - - - - - - - - - - - - - - - 2. Mi hermano Miguel quiere estudiar __________ser doctor. - ________eso, trabaja _________mi madre que es médica. Trabaja - _________las mañanas y __________las tardes. Trabaja - _________muchas horas - - - - - - - - - - - - - - - - _________obtener más experiencia. - - - - - - - - - - - - - - - - - - - - - - - 3. ________lo general, Joel es una persona muy amable. - ________ejemplo, la semana pasado nos trajo donas y galletas. - - - - - - - - - - - - - - - - - - - - - - - - 4. El cuadro de Guernica fue pintado ________Pablo Picasso. - Lo pintó _______representar las atrocidades de la guerra. - - - - - - - - - - - - - - - - - - - - - - - - 5. Asia, Angie y Erica iban a dar un paseo __________el - parque pero lo cancelaron _________el mal tiempo (bad weather) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - C. - - - - - - - - - - - - - Pretérito e Imperfecto - - - - - - - - - - - - - - - - - - - - - - - Gloria Fernández, the graduate student who spends many hours daily in front of the computer, wants to tell her friend Kathy about her visit to the doctor, so she sends her an e-mail. The main frame, however, is acting up, and some of the verbs have been deleted. Help Kathy complete the message by providing the missing verbs in the appropriate tense—either the preterite or the imperfect. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - correo_para_kathy@abc.edu - - - - - - - - - - - - - - - - - - - - - Tema: Mi visita al doctor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Querida Kathy: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Ayer fui al doctor porque no (sentirse) __________________ - - - - - - - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - bien: me (doler) __________________ - - - - - - - - - - - - 2 - - - - - - - - - - - - - - - - - - - - - - la cabeza y (tener) __________________ - - - - - - - - - - - - 3 - - - - - - - - - - - - - - - - - - - - - - los ojos irritados. Primero, el doctor me (tomar) - _______________ - - - - - - - - - - - - 4 - - - - - - - - - - - - - - - - - - - - - - la temperatura, pero no (tener) ____________ - - - - - - - - - - - - 5 - - - - - - - - - - - - - - - - - - - - - - fiebre. Después me (examinar) _______________ - - - - - - - - - - - - 6 - - - - - - - - - - - - - - - - - - - - - - los ojos y me (preguntar) __________________ - - - - - - - - - - - - 7 - - - - - - - - - - - - - - - - - - - - - - si (trabajar) __________________ - - - - - - - - - - - - 8 - - - - - - - - - - - - - - - - - - - - - - mucho con la computadora; yo le (decir) __________________ - - - - - - - - - - - - - 9 - - - - - - - - - - - - - - - - - - - - - - que sí. Entonces él me (recomendar) __________________ - - - - - - - - - - - - - 10 - - - - - - - - - - - - - - - - - - - - - - que tomara - - - - - - - - - - - - - - - - - - - - - - - descansos y relajara - - - - - - - - - - - - - - - - - - - - - - - los ojos, porque las computadoras son malas para la vista. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - D. - - - - - - - - - - - - - Unplanned/Unexpected Events - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Pamela is at work and her friend Susana arrives late. She has had a horrible morning. Pamela discusses Susana’s horrible morning with her coworkers during her lunch break. - - - - - - - - - - - Following the model, use the cues and the verbs in parentheses to write complete sentences with - - - - - - - - - - - - - se - - - - - - - - - - - describing Susana’s actions. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MODELO - - - - - - - - - - - : - - - - - - - - - - - - When she tells them that Susana forgot her keys in her - house, she says - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (olvidar) - - - - - - - - - - - - A Susana se le olvidaron las llaves en su casa. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1. - - - - - - - - - - - - When she tells them that Susana lost her cellular phone, - she says: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (perder) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2. - - - - - - - - - - - - When she tells them that Susana ‘s car ran out of gas she - says: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (acabar) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3. - - - - - - - - - - - - When she tells them that Susana’s glasses broke, she says: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (romper)_______________________________________________________________________ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4. - - - - - - - - - - - - When she tells them that Susana left her documents at home, - she says: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (quedar) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5. - - - - - - - - - - - - When she tells them that Susana dropped her coffee, she - says: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (caer) - _________________________________________________________________________ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - E - - - - - - - - - - - - - . Los Adverbios- - - - - - - - - - - - Change the adjectives in parentheses to adverbs. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - La doctora le dice a Pablo que todo va a ir bien: - - - - - - - - - - - - - - - - - - - - - Señor Ortiz, su salud está - - - - - - - - - - - - (perfecto) ________________ - - - - - - - - - - - - 1 - - - - - - - - - - - bien. Su peso está bajando (rápida) ________________ - - - - - - - - - - - - 2 - - - - - - - - - - - de 220 libras a 180 y parece que hace ejercicios - (frecuente) ________________ - - - - - - - - - - - - 3. - - - - - - - - - - - Necesita una dieta (total) ________________ - - - - - - - - - - - - 4 - - - - - - - - - - - baja en grasas para mantener su peso. Además, quiero que - escuche mis consejos (cuidadoso) ________________ - - - - - - - - - - - - 5 - - - - - - - - - - - y espero que vaya a casa más (tranquilo) - - - - - - - - - - - _______________________________. - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/examples/http-stream-xml-namespaces-and-linked-data/index.php b/examples/http-stream-xml-namespaces-and-linked-data/index.php index 5bd51974..3cd3c128 100644 --- a/examples/http-stream-xml-namespaces-and-linked-data/index.php +++ b/examples/http-stream-xml-namespaces-and-linked-data/index.php @@ -50,28 +50,33 @@ // Create a stream context that will tell QueryPath how to load the file. $context = stream_context_create($options); -// Fetch the URL and select all rdf:Description elements. -// (Note that | is the CSS 3 equiv of colons for namespacing.) -// To add the context, we pass it in as an option to QueryPath. -$qp = qp($url, 'rdf|Description', ['context' => $context]); +try { + // Fetch the URL and select all rdf:Description elements. + // (Note that | is the CSS 3 equiv of colons for namespacing.) + // To add the context, we pass it in as an option to QueryPath. + $qp = qp($url, 'rdf|Description', ['context' => $context]); -printf('There are %d descriptions in this record.
' . PHP_EOL, $qp->count()); + printf('There are %d descriptions in this record.
' . PHP_EOL, $qp->count()); -// Here, we use foaf|* to select all elements in the FOAF namespace. -printf('There are %d DBO items in this record.

' . PHP_EOL, $qp->top()->find('dbo|*')->count()); + // Here, we use foaf|* to select all elements in the FOAF namespace. + printf('There are %d DBO items in this record.

' . PHP_EOL, $qp->top()->find('dbo|*')->count()); -// Standard pseudo-classes that are not HTML specific can be used on namespaced elements, too. -echo 'About (RDFS): ' . $qp->top()->find('rdfs|label:first-of-type')->text() . '
' . PHP_EOL; -echo 'About (FOAF): ' . $qp->top()->find('foaf|name:first-of-type')->text() . '
' . PHP_EOL; + // Standard pseudo-classes that are not HTML specific can be used on namespaced elements, too. + echo 'About (RDFS): ' . $qp->top()->find('rdfs|label:first-of-type')->text() . '
' . PHP_EOL; + echo 'About (FOAF): ' . $qp->top()->find('foaf|name:first-of-type')->text() . '
' . PHP_EOL; -// Namespaced attributes can be retrieved using the same sort of delimiting. -echo PHP_EOL . '
Comment:
' . PHP_EOL; -echo $qp->top()->find('rdfs|comment[xml|lang="en"]')->text(); -echo '
' . PHP_EOL; + // Namespaced attributes can be retrieved using the same sort of delimiting. + echo PHP_EOL . '
Comment:
' . PHP_EOL; + echo $qp->top()->find('rdfs|comment[xml|lang="en"]')->text(); + echo '
' . PHP_EOL; -$qp->top(); + $qp->top(); -echo PHP_EOL . '
Other Sites:
' . PHP_EOL; -foreach ($qp as $item) { - echo $item->attr('rdf:about') . '
' . PHP_EOL; + echo PHP_EOL . '
Other Sites:
' . PHP_EOL; + foreach ($qp as $item) { + echo $item->attr('rdf:about') . '
' . PHP_EOL; + } +} catch (\QueryPath\Exception $e) { + // Handle QueryPath exceptions + die($e->getMessage()); } diff --git a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php index 76443cfa..6ca1b7e0 100644 --- a/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php +++ b/examples/parsing-xml-from-url-and-dynamically-generating-html/index.php @@ -2,8 +2,7 @@ /** * Load XML from a URL, parse the data, and output into a HTML template * - * @author Original: Emily Brand - * @author Updated by: Jake Jackson + * @author Emily Brand * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license. * * @internal IMPORTANT: if you don't trust the source of the data being loaded make sure to sanitize the output @@ -26,30 +25,31 @@ function addClasses(string $name): string return '' . htmlentities($name) . '
'; } -// The document skeleton -$qp = html5qp(__DIR__ . '/template.html', 'body'); +try { + // The document skeleton + $qp = html5qp(__DIR__ . '/template.html', 'body'); -$key = $_GET['key'] ?? ''; + $key = $_GET['key'] ?? ''; -// Only display jQuery methods from these categories -$categories = [ - 'traversing/tree-traversal' => 'Tree Traversal', - 'selectors/child-filter-selectors' => 'Child Filter', - 'selectors/attribute-selectors' => 'Attribute', - 'selectors/content-filter-selector' => 'Content Filter', - 'selectors/basic-filter-selectors' => 'Basic Filter', - 'selectors/hierarchy-selectors' => 'Hierarchy', - 'selectors/basic-css-selectors' => 'Basic', - 'traversing/filtering' => 'Filtering', - 'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing', - 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside', - 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside', - 'manipulation/style-properties' => 'Style Properties', -]; + // Only display jQuery methods from these categories + $categories = [ + 'traversing/tree-traversal' => 'Tree Traversal', + 'selectors/child-filter-selectors' => 'Child Filter', + 'selectors/attribute-selectors' => 'Attribute', + 'selectors/content-filter-selector' => 'Content Filter', + 'selectors/basic-filter-selectors' => 'Basic Filter', + 'selectors/hierarchy-selectors' => 'Hierarchy', + 'selectors/basic-css-selectors' => 'Basic', + 'traversing/filtering' => 'Filtering', + 'traversing/miscellaneous-traversal' => 'Miscellaneous Traversing', + 'manipulation/dom-insertion-outside' => 'DOM Insertion, Outside', + 'manipulation/dom-insertion-inside' => 'DOM Insertion, Inside', + 'manipulation/style-properties' => 'Style Properties', + ]; + + $jquery = []; -$jquery = []; -try { // Search through the xml file to find all entries of jQuery entities foreach (qp('https://api.jquery.com/resources/api.xml', 'entry') as $entry) { foreach ($entry->find('category') as $item) { @@ -89,5 +89,6 @@ function addClasses(string $name): string // Write the document $qp->writeHTML5(); } catch (\QueryPath\Exception $e) { + // Handle QueryPath exceptions die($e->getMessage()); } diff --git a/examples/remote-filter-and-retrieval/index.php b/examples/remote-filter-and-retrieval/index.php new file mode 100644 index 00000000..44b4205f --- /dev/null +++ b/examples/remote-filter-and-retrieval/index.php @@ -0,0 +1,46 @@ +Urban Dictionary Random Word Generator'; + +try { + $page = random_int(0, 288); + $word = random_int(0, 7); + + // Load a random page from the Urban Dictionary + $qp = html5qp('https://www.urbandictionary.com/?page=' . $page); + + // Select a random word/definition out of the 7 shown on the loaded page + // Get the Word + printf( + '

Word: %s

', + $qp->find('.word') + ->eq($word) + ->text() + ); + + $qp->top(); + + // Get the definition + echo 'Definition: ' . + $qp->find('.meaning') + ->eq($word) + ->text(); +} catch (\QueryPath\Exception $e) { + // Handle QueryPath exceptions + die($e->getMessage()); +} catch (Exception $e) { + // Handle the random_int() exception + die($e->getMessage()); +}