From a388c59e487607b6e86c5b82a99605275e5f13d4 Mon Sep 17 00:00:00 2001 From: Phil Burton Date: Tue, 11 Jun 2019 15:20:45 +0100 Subject: Remove bad handling of truncation --- scripts/run.php | 3 +-- src/Etym.php | 33 +-------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/scripts/run.php b/scripts/run.php index 59af4be..5ee1c05 100644 --- a/scripts/run.php +++ b/scripts/run.php @@ -6,9 +6,8 @@ use App\Etym; $baseURL = "http://www.etymonline.com/word/"; $htmlNode = "section[class^='word__defination']"; -$pasteCmd = "../pastebinit -b http://p.of.je"; -$etym = new Etym($baseURL, $htmlNode, $pasteCmd); +$etym = new Etym($baseURL, $htmlNode); $result = $etym->getDefinition(); echo $result . PHP_EOL; diff --git a/src/Etym.php b/src/Etym.php index 8be0a99..39514f8 100644 --- a/src/Etym.php +++ b/src/Etym.php @@ -24,7 +24,7 @@ class Etym * @param string $pasteCmd * @author Phil Burton */ - public function __construct(string $baseURL, string $domSearch, string $pasteCmd) + public function __construct(string $baseURL, string $domSearch) { $this->baseURL = $baseURL; $this->domSearch = $domSearch; @@ -53,7 +53,6 @@ class Etym } $definition = $this->cleanUpHtml($html[0]->innerHtml()); - $definition = $this->handleTruncation($input, $definition, $targetURL); // echo $definition . "\n"; return $definition; @@ -103,34 +102,4 @@ class Etym return $clear; } - - /** - * Handle when string is too long - * - * @param string $input - * @param string $definition - * @param string $url - * @return string - * @author Phil Burton - */ - protected function handleTruncation(string $input, string $definition, string $url): string - { - $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 | " . $this->pasteCmd; - $pasteBinLink = exec($pasteBinCmd); - $truncated = substr($truncated, 0, $MAX_CHARACTERS) . "... [More info at $pasteBinLink]"; - } - - return $truncated; - } } -- cgit v1.2.3