summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burton <phil@d3r.com>2019-06-11 15:20:45 +0100
committerPhil Burton <phil@d3r.com>2019-06-11 15:20:45 +0100
commita388c59e487607b6e86c5b82a99605275e5f13d4 (patch)
tree836057cf20f2b07bbc54ff7c11378f59a6e06de3
parentd8ffff6171b433b4e0a1b0849c060c9e1051734f (diff)
Remove bad handling of truncation
-rw-r--r--scripts/run.php3
-rw-r--r--src/Etym.php33
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 <phil@pgburton.com>
*/
- 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 <phil@pgburton.com>
- */
- 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;
- }
}