Skip to content

Commit

Permalink
added try catch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsekaean committed Nov 20, 2018
1 parent ffeca04 commit 057fe98
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/Model/SearchDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,41 @@ public function makeSearchContent()
$origin = $this->Origin();
$searchLink = $origin->getGenerateSearchLink();

$client = new Client();
$res = $client->request('GET', $searchLink);
if($res->getStatusCode() == 200) {
$body = $res->getBody();

$x_path = $origin->config()->get('search_x_path');
if(!$x_path) {
$x_path = self::config()->get('search_x_path');
}

if($x_path) {
$domDoc = new \DOMDocument();
@$domDoc->loadHTML($body);
try {
$client = new Client();
$res = $client->request('GET', $searchLink);
if ($res->getStatusCode() == 200) {
$body = $res->getBody();

$x_path = $origin->config()->get('search_x_path');
if (!$x_path) {
$x_path = self::config()->get('search_x_path');
}

$finder = new \DOMXPath($domDoc);
$nodes = $finder->query("//*[contains(@class, '$x_path')]");
$nodeValues = [];
if($nodes->length) {
foreach ($nodes as $node) {
$nodeValues[] = $node->nodeValue;
if ($x_path) {
$domDoc = new \DOMDocument();
@$domDoc->loadHTML($body);

$finder = new \DOMXPath($domDoc);
$nodes = $finder->query("//*[contains(@class, '$x_path')]");
$nodeValues = [];
if ($nodes->length) {
foreach ($nodes as $node) {
$nodeValues[] = $node->nodeValue;
}
}
$contents = implode("\n\n", $nodeValues);
} else {
$contents = strip_tags($body);
}
$contents = implode("\n\n", $nodeValues);
}
else {
$contents = strip_tags($body);
}

$this->Title = $origin->getTitle();
if($contents) {
$this->Content = $contents;
$this->Title = $origin->getTitle();
if ($contents) {
$this->Content = $contents;
}
$this->write();
}
$this->write();
}
} catch(\Exception $e) {}


}
Expand Down

0 comments on commit 057fe98

Please sign in to comment.