summaryrefslogtreecommitdiff
path: root/etym.php
diff options
context:
space:
mode:
authorPhil Burton <phil@d3r.com>2019-06-11 14:28:13 +0100
committerPhil Burton <phil@d3r.com>2019-06-11 14:28:13 +0100
commit599cccd293035788793d680f8649ea737228fc56 (patch)
treecb6710e746e14ffae9c949f3c66e4560128a946d /etym.php
parentd00f19145627312125c593f35193f04733b4df4e (diff)
Remove old script
Diffstat (limited to 'etym.php')
-rw-r--r--etym.php85
1 files changed, 0 insertions, 85 deletions
diff --git a/etym.php b/etym.php
deleted file mode 100644
index 08059fd..0000000
--- a/etym.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-
-use PHPHtmlParser\Dom;
-
-$baseURL = "http://www.etymonline.com/word/";
-$htmlNode = "section[class^='word__defination']";
-$pasteCmd = "pastebinit -b http://p.of.je 2>/dev/null";
-
-function readStdin()
-{
- $input = fgets(STDIN);
-
- if ($input === false) {
- echo "No input supplied!\n";
- exit(1);
- }
-
- $input = rtrim($input, "\n");
-
- return $input;
-}
-
-function cleanUpHtml($input)
-{
- // Strip HTML Tags
- $clear = strip_tags($input);
- // Clean up things like &amp;
- $clear = html_entity_decode($clear);
- // Strip out any url-encoded stuff
- $clear = urldecode($clear);
- // Replace Multiple spaces with single space
- $clear = preg_replace('/ +/', ' ', $clear);
- // Trim the string of leading/trailing space
- $clear = trim($clear);
- // Capitalise the first char.
- $clear = ucfirst($clear);
-
- return $clear;
-}
-
-function handleTruncation($input, $definition, $url)
-{
- $truncated = $definition;
-
- $MAX_CHARACTERS = 350;
- if (strlen($truncated) >= $MAX_CHARACTERS) {
- // Create that povjee link.
- // Capitalise the first char of the input.
- $input = ucfirst($input);
- $defAndUrl = "\"$input\"" . "\n\n" . $definition . "\n\n" . "[Original at: $url]";
- $safeDef = escapeshellarg($defAndUrl);
-
- $pasteBinCmd = "echo $safeDef | " . $pasteCmd;
- $pasteBinLink = exec($pasteBinCmd);
-
- $truncated = substr($truncated, 0, $MAX_CHARACTERS) . "... [More info at $pasteBinLink]";
- }
-
- return $truncated;
-}
-
-function getDefinition()
-{
-
- $input = readStdin();
-
- $targetURL = $baseURL . $input;
-
- $dom = new Dom;
- $dom->load($targetURL);
- $html = $dom->find($htmlNode)[0]->innerHtml();
- $node = $html->find($htmlNode, 0);
-
- if ($node === null) {
- echo "No entry found for '$input'!\n";
- exit(2);
- }
-
- $definition = cleanUpHtml($node->innertext);
- $definition = handleTruncation($input, $definition, $targetURL);
-
- echo $definition . "\n";
-}
-
-getDefinition();