Commit 8159ab3f authored by Dominik Hebeler's avatar Dominik Hebeler

Alle logischen Inhalte der search.pl nach php überführt

parent 710d5077
......@@ -4,90 +4,41 @@ namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\MetaGer\Forwarder;
use App\MetaGer\Results;
#use App\MetaGer\Forwarder;
#use App\MetaGer\Results;
#use App\MetaGer\Search;
use App;
use App\MetaGer\Search;
use App\MetaGer;
class MetaGerSearch extends Controller
{
/**
* Select a free Server to forward the Request to:
*
* @param int $id
* @return Response
*/
public function forwardToServer()
{
return Forwarder::getFreeServer();
return var_dump($serversArray);
return $cfg['redis']['password'];
#return view('index', [ 'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen']);
public function test(Request $request, MetaGer $metager)
{
# Mit gelieferte Formulardaten parsen und abspeichern:
$metager->parseFormData($request);
# Nach Spezialsuchen überprüfen:
$metager->checkSpecialSearches($request);
# Alle Suchmaschinen erstellen
$metager->createSearchEngines($request);
# Ergebnisse der Suchmaschinen kombinieren:
$metager->combineResults();
# Die Ausgabe erstellen:
return $metager->createView();
}
public function search(Request $request)
{
# Zunächst überprüfen wir die eingegebenen Einstellungen:
# FOKUS
$fokus = $request->input('focus', 'web');
$fokus = trans('fokiNames.'.$fokus);
if(strpos($fokus,".")){
$fokus = trans('fokiNames.web');
}
define("FOKUS", $fokus);
# SUMA-FILE
if(App::isLocale("en")){
define("SUMA_FILE", config_path() . "/sumasEn.xml");
}else{
define("SUMA_FILE", config_path() . "/sumas.xml");
}
if(!file_exists(SUMA_FILE)){
die("Suma-File konnte nicht gefunden werden");
}
# Sucheingabe:
$eingabe = trim($request->input('eingabe', ''));
if(strlen($eingabe) === 0){
return 'Achtung: Sie haben keinen Suchbegriff eingegeben. Sie können ihre Suchbegriffe oben eingeben und es erneut versuchen.';
}else{
define("Q", $eingabe);
}
# IP:
if( isset($_SERVER['HTTP_FROM']) )
{
define("IP", $_SERVER['HTTP_FROM']);
}else
{
define("IP", "127.0.0.1");
}
# Language:
if( isset($_SERVER['HTTP_LANGUAGE']) )
{
define("LANGUAGE", $_SERVER['HTTP_LANGUAGE']);
}else
{
define("LANGUAGE", "");
}
# Category
define("CATEGORY", $request->input('category', ''));
# Request Times:
define("TIME", $request->input('time', 1));
$searchengines = Search::loadSearchEngines($request);
$results = new Results($searchengines);
$viewResults = [];
# Wir extrahieren alle notwendigen Variablen und geben Sie an unseren View:
foreach($results->results as $result)
{
$viewResults[] = get_object_vars($result);
}
return view('metager3')
->with('results', $viewResults);
return print_r( $viewResults, TRUE);
}
......
......@@ -79,5 +79,5 @@
->with('css', 'help.css');
});
Route::get('meta/meta.ger3', 'MetaGerSearch@search');
Route::get('meta/meta.ger3', 'MetaGerSearch@test');
});
\ No newline at end of file
This diff is collapsed.
<?php
namespace App\MetaGer;
namespace App\Models;
class Result
{
function __construct ( $titel, $link, $anzeigeLink , $descr )
function __construct ( $titel, $link, $anzeigeLink , $descr, $gefVon )
{
$this->titel = trim($titel);
$this->link = trim($link);
$this->anzeigeLink = trim($anzeigeLink);
$this->descr = trim($descr);
$this->gefVon = trim($gefVon);
}
}
\ No newline at end of file
......@@ -14,44 +14,7 @@ class Results
$this->results = $this->loadResults($engines);
}
private function loadResults($engines)
{
# Das Laden der Ergebnisse besteht aus 2 Elementaren Schritten:
# 1. GET-Requests abarbeiten
# 2. Ergebnisse parsen
# Wir initialisieren Multi Curl
$mh = curl_multi_init();
# Fügen die Curl Handles der Suchmaschinen hinzu
foreach($engines as $engine)
{
$engine->addCurlHandle($mh);
}
# Nun führen wir die Get-Requests aus und warten auf alle Ergebnisse:
$running = null;
do
{
curL_multi_exec($mh, $running);
}while($running);
# Und beenden noch alle Handles
foreach($engines as $engine)
{
$engine->removeCurlHandle($mh);
}
# Und auch den Multicurl-Handle:
curl_multi_close($mh);
# Jetzt müssen wir die Suchmaschinen nur noch alle Ergebnisse in den Speicher laden lassen:
foreach($engines as $engine)
{
$engine->loadResults();
return $engine->results;
}
}
private function get($getStrings){
# Nimmt ein array aus getStrings entgegen und liefert ein Array aus Antworten zurück:
......
<?php
namespace App\MetaGer;
use Request;
namespace App\Models;
abstract class Searchengine
{
protected $ch; # Curl Handle zum erhalten der Ergebnisse
function __construct(\SimpleXMLElement $engine)
function __construct(\SimpleXMLElement $engine, $mh, $query, $time)
{
foreach($engine->attributes() as $key => $value){
$this->$key = $value->__toString();
......@@ -22,10 +21,12 @@ abstract class Searchengine
$this->useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
}
$this->ch = curl_init($this->generateGetString());
$this->ch = curl_init($this->generateGetString($query));
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT , TIME);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT , $time);
$this->addCurlHandle($mh);
}
public abstract function loadResults();
......@@ -40,7 +41,7 @@ abstract class Searchengine
curl_multi_remove_handle($mh, $this->ch);
}
private function generateGetString()
private function generateGetString($query)
{
$getString = "";
# Protokoll:
......@@ -65,7 +66,7 @@ abstract class Searchengine
if( strpos($getString, "<<QUERY>>") )
{
$getString = str_replace("<<QUERY>>", $this->urlEncode(Q), $getString);
$getString = str_replace("<<QUERY>>", $this->urlEncode($query), $getString);
}
if( strpos($getString, "<<IP>>") )
......
<?php
namespace app\MetaGer\parserSkripte;
use App\MetaGer\Searchengine;
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
class Fastbot extends Searchengine
{
public $results = [];
function __construct (\SimpleXMLElement $engine)
function __construct (\SimpleXMLElement $engine, $mh, $query, $time)
{
parent::__construct($engine);
parent::__construct($engine, $mh, $query, $time);
}
public function loadResults ()
......@@ -24,11 +24,12 @@ class Fastbot extends Searchengine
$link = $result[1];
$link = substr($link, strpos($link, "href=\"") + 6);
$link = substr($link, 0, strpos($link, "\""));
$this->results[] = new \App\MetaGer\Result(
$this->results[] = new \App\Models\Result(
trim(strip_tags($result[1])),
$link,
$result[3],
$result[2]
$result[2],
"<a href=\"http://www.fastbot.de\">fastbot</a>"
);
}
......
<?php
namespace app\Models\parserSkripte;
use App\Models\Searchengine;
use App\Models\Result;
class Onenewspagegermany extends Searchengine
{
public $results = [];
function __construct (\SimpleXMLElement $engine, $mh, $query, $time)
{
parent::__construct($engine, $mh, $query, $time);
}
public function loadResults ()
{
$result = curl_multi_getcontent($this->ch);
foreach( explode("\n", $result) as $line )
{
$line = trim($line);
if( strlen($line) > 0 ){
# Hier bekommen wir jedes einzelne Ergebnis
$result = explode("|", $line);
$this->results[] = new Result(
trim(strip_tags($result[0])),
$result[2],
$result[2],
$result[1],
"<a href=\"http://www.newsdeutschland.com/videos.htm\">newsdeutschland.com</a>"
);
}
}
}
}
\ No newline at end of file
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\MetaGer;
class MetaGerProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(MetaGer::class, function($app) {
return new MetaGer();
});
}
}
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "78c5a9e749a72f3904e42c8e327605d9",
"content-hash": "0c9fdb698d482f8c9df582568e514b26",
"hash": "ac43207ede0f63c9fafc0f63d04346ae",
"content-hash": "db9cfe1e3caebe3afb5890033afb9452",
"packages": [
{
"name": "classpreloader/classpreloader",
......@@ -419,6 +419,63 @@
],
"time": "2015-04-20 18:58:01"
},
{
"name": "jenssegers/agent",
"version": "v2.3.3",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/agent.git",
"reference": "3068d6372a4677af84014a53d5a212cfa74492c1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jenssegers/agent/zipball/3068d6372a4677af84014a53d5a212cfa74492c1",
"reference": "3068d6372a4677af84014a53d5a212cfa74492c1",
"shasum": ""
},
"require": {
"illuminate/support": "^4.0|^5.0",
"mobiledetect/mobiledetectlib": "^2.7.6",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"satooshi/php-coveralls": "^0.6"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Jenssegers\\Agent\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect",
"homepage": "https://github.com/jenssegers/agent",
"keywords": [
"Agent",
"browser",
"laravel",
"mobile",
"platform",
"user agent",
"useragent"
],
"time": "2016-03-08 13:47:22"
},
{
"name": "jeremeamia/SuperClosure",
"version": "2.2.0",
......@@ -737,6 +794,60 @@
],
"time": "2016-01-08 07:14:49"
},
{
"name": "mobiledetect/mobiledetectlib",
"version": "2.8.22",
"source": {
"type": "git",
"url": "https://github.com/serbanghita/Mobile-Detect.git",
"reference": "53cddae0c272a478b24a4b5fb60d0f838caf70b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/53cddae0c272a478b24a4b5fb60d0f838caf70b6",
"reference": "53cddae0c272a478b24a4b5fb60d0f838caf70b6",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master",
"johnkary/phpunit-speedtrap": "~1.0@dev",
"phpunit/phpunit": "*"
},
"type": "library",
"autoload": {
"classmap": [
"Mobile_Detect.php"
],
"psr-0": {
"Detection": "namespaced/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://mobiledetect.net",
"role": "Developer"
}
],
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"keywords": [
"detect mobile devices",
"mobile",
"mobile detect",
"mobile detector",
"php mobile detect"
],
"time": "2016-04-24 09:47:16"
},
{
"name": "monolog/monolog",
"version": "1.19.0",
......
......@@ -156,6 +156,8 @@ return [
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
App\Providers\MetaGerProvider::class,
Jenssegers\Agent\AgentServiceProvider::class,
],
......@@ -202,7 +204,8 @@ return [
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class,
'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class,
'Agent' => Jenssegers\Agent\Facades\Agent::class,
],
];
......@@ -30,7 +30,7 @@
<li class="pull-right">
<form method="get" action="/meta/meta.ger3" enctype="multipart/form-data" accept-charset="UTF-8" class="form" id="submitForm">
<div class="input-group">
<input autocomplete="off" class="form-control" form="submitForm" id="eingabeTop" name="eingabe" placeholder="Suchbegriffe erweitern/verändern, oder völlig neue Suche:" tabindex="1" type="text" value="test" />
<input autocomplete="off" class="form-control" form="submitForm" id="eingabeTop" name="eingabe" placeholder="Suchbegriffe erweitern/verändern, oder völlig neue Suche:" tabindex="1" type="text" value="{{ $eingabe }}" />
<div class="input-group-addon">
<button type='submit' form="submitForm" id='search'><span class="glyphicon glyphicon-search"></span>
</button>
......@@ -59,6 +59,24 @@
</ul>
<div class="tab-content container-fluid">
<div class="tab-pane active" data-focus="web" id="web" role="tabpanel">
@if( sizeof($errors) > 0 )
<div class="alert alert-danger">
<ul>
@foreach($errors as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@if( sizeof($warnings) > 0)
<div class="alert alert-warning">
<ul>
@foreach($warnings as $warning)
<li>{{ $warning }}</li>
@endforeach
</ul>
</div>
@endif
<div class="row">
<div class="col-md-8">
@yield('results')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment