Exalead.php 2.06 KB
Newer Older
1
2
3
4
<?php

namespace app\Models\parserSkripte;
use App\Models\Searchengine;
Dominik Hebeler's avatar
Dominik Hebeler committed
5
use Log;
6
7
8
9
10
11
12
13
14
15

class Exalead extends Searchengine 
{
	public $results = [];

	function __construct (\SimpleXMLElement $engine, \App\MetaGer $metager)
	{
		parent::__construct($engine, $metager);
	}

16
	public function loadResults ($result)
17
	{
18
#		die($result);
Dominik Hebeler's avatar
Dominik Hebeler committed
19
20
21
22
23
24
		$result = preg_replace("/\r\n/si", "", $result);
		try {
			$content = simplexml_load_string($result);
		} catch (\Exception $e) {
			abort(500, "$result is not a valid xml string");
		}
25
		
Dominik Hebeler's avatar
Dominik Hebeler committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
		if(!$content)
		{
			return;
		}
		$results = $content;
		$prefix = ""; $namespace = "";
		foreach($results->getDocNamespaces() as $strPrefix => $strNamespace) {
    			if(strlen($strPrefix)==0) {
			        $prefix="a"; //Assign an arbitrary namespace prefix.
			}else {
				$prefix="a";
			}
			$namespace = $strNamespace;
		}
		$results->registerXPathNamespace($prefix,$namespace);
41
42
43
44
45
46
		try{
			$results = $results->xpath("//a:hits/a:Hit");
		} catch(\ErrorException $e)
		{
			return;
		}
Dominik Hebeler's avatar
Dominik Hebeler committed
47
48
		foreach($results as $result)
		{
Dominik Hebeler's avatar
Dominik Hebeler committed
49
50
51
52
53
			try{
				$result->registerXPathNamespace($prefix,$namespace);
				$title = $result->xpath("a:metas/a:Meta[@name='title']/a:MetaString[@name='value']")[0]->__toString();
				$link = $result->xpath("a:metas/a:Meta[@name='url']/a:MetaString[@name='value']")[0]->__toString();
				$anzeigeLink = $link;
54
55
56
57
58
59
60
61
62
				$descr = "";
				if(sizeOf($result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")) === 0 && sizeOf($result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']")) !== 0)
				{
					$tmp = $result->xpath("a:metas/a:Meta[@name='summary']/a:MetaText[@name='value']");
					foreach($tmp as $el)
					{
						$descr .= strip_tags($el->asXML());
					}
				}else
Dominik Hebeler's avatar
Dominik Hebeler committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
					$descr = $result->xpath("a:metas/a:Meta[@name='metadesc']/a:MetaString[@name='value']")[0]->__toString();
				$this->counter++;
				$this->results[] = new \App\Models\Result(
					$this->engine,
					$title,
					$link,
					$anzeigeLink,
					$descr,
					$this->gefVon,
					$this->counter
				);
			}catch(\ErrorException $e)
			{
				continue;
			}
Dominik Hebeler's avatar
Dominik Hebeler committed
78
		}
79
	}
Dominik Hebeler's avatar
Dominik Hebeler committed
80
}