Commit 7f77ce20 authored by karl's avatar karl
Browse files

Einstellungen funktionieren

parents 41c853f7 a7ae2d12
update:
update(144.76.113.134):
tags:
- 144.76.113.134
only:
- tags
- triggers
before_script:
# Abhängigkeiten überprüfen
- which virtualbox
- which vagrant
- which composer
- which git
- which php
- which php7.0
script:
# Pfad zum neu geklonten Repo
- path=`pwd`
- cd ~/
- $path/deploy/checkServerStatus.sh "$path"
- cd ~/MetaGer
- git pull "$path"
\ No newline at end of file
- if [ -d MetaGer_neu ]; then rm -rf MetaGer_neu;fi
- git clone "$path" MetaGer_neu
- cd MetaGer_neu
- composer update
- chmod -R 777 storage
- chmod -R 777 bootstrap/cache
- scp metager@metager3.de:~/.env .
- scp metager@metager3.de:~/sumas.xml config/
- scp metager@metager3.de:~/sumasEn.xml config/
- chmod 777 config/sumas.xml config/sumasEn.xml
- cd ~/
- rm -rf MetaGer
- mv MetaGer_neu MetaGer
update(metager3.de):
tags:
- metager3
only:
- tags
- triggers
before_script:
# Abhängigkeiten überprüfen
- which composer
- which git
- which php7.0
script:
# Pfad zum neu geklonten Repo
- path=`pwd`
- cd ~/
- if [ -d MetaGer_neu ]; then rm -rf MetaGer_neu;fi
- git clone "$path" MetaGer_neu
- cd MetaGer_neu
- composer update
- chmod -R 777 storage
- chmod -R 777 bootstrap/cache
- scp metager@metager3.de:~/.env .
- scp metager@metager3.de:~/sumas.xml config/
- scp metager@metager3.de:~/sumasEn.xml config/
- chmod 777 config/sumas.xml config/sumasEn.xml
- cd ~/
- rm -rf MetaGer
- mv MetaGer_neu MetaGer
\ No newline at end of file
......@@ -13,9 +13,9 @@ use App\MetaGer;
class MetaGerSearch extends Controller
{
public function test(Request $request, MetaGer $metager)
public function search(Request $request, MetaGer $metager)
{
$time = microtime();
# Mit gelieferte Formulardaten parsen und abspeichern:
$metager->parseFormData($request);
if($metager->getFokus() !== "bilder" )
......@@ -24,28 +24,119 @@ class MetaGerSearch extends Controller
$metager->checkSpecialSearches($request);
}
# Alle Suchmaschinen erstellen
$metager->createSearchEngines($request);
# Alle Ergebnisse vor der Zusammenführung ranken:
$metager->rankAll();
# Ergebnisse der Suchmaschinen kombinieren:
$metager->combineResults();
$metager->removeInvalids();
# Die Ausgabe erstellen:
return $metager->createView();
}
public function search(Request $request)
public function quicktips(Request $request)
{
$searchengines = Search::loadSearchEngines($request);
$results = new Results($searchengines);
$q = $request->input('q', '');
# Zunächst den Spruch
$spruecheFile = storage_path() . "/app/public/sprueche.txt";
if( file_exists($spruecheFile) )
{
$sprueche = file($spruecheFile);
$spruch = $sprueche[array_rand($sprueche)];
}
# Die manuellen Quicktips:
$file = storage_path() . "/app/public/qtdata.csv";
$mquicktips = [];
if( file_exists($file) && $q !== '')
{
$file = fopen($file, 'r');
while (($line = fgetcsv($file)) !== FALSE) {
$words = array_slice($line,3);
$isIn = FALSE;
foreach($words as $word){
$word = strtolower($word);
if(strpos($q, $word) !== FALSE){
$isIn = TRUE;
break;
}
}
if($isIn === TRUE){
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
$quicktip["descr"] = $line[2];
$mquicktips[] = $quicktip;
}
}
fclose($file);
}
# Wikipedia Quicktip
$quicktips = [];
$url = "http://de.wikipedia.org/w/api.php?action=query&titles=".urlencode(implode("_",array_diff(explode(" ",$q),array("wikipedia"))))."&prop=info|extracts|categories&inprop=url|displaytitle&exintro&exsentences=3&format=json";
$decodedResponse = json_decode($this->get($url), true);
foreach($decodedResponse["query"]["pages"] as $result)
{
if( isset($result['displaytitle']) && isset($result['fullurl']) && isset($result['extract']) )
{
$quicktip = [];
$quicktip["title"] = $result['displaytitle'];
$quicktip["URL"] = $result['fullurl'];
$quicktip["descr"] = strip_tags($result['extract']);
$quicktips[] = $quicktip;
}
}
$mquicktips = array_merge($mquicktips, $quicktips);
# Uns Natürlich das wussten Sie schon:
$file = storage_path() . "/app/public/tips.txt";
if( file_exists($file) )
{
$tips = file($file);
$tip = $tips[array_rand($tips)];
$mquicktips[] = ['title' => 'Wussten Sie schon?', 'descr' => $tip, 'URL' => '/tips'];
}
# Uns die Werbelinks:
$file = storage_path() . "/app/public/ads.txt";
if( file_exists($file) )
{
$ads = json_decode(file_get_contents($file), true);
$ad = $ads[array_rand($ads)];
$mquicktips[] = ['title' => $ad['title'], 'descr' => $ad['descr'], 'URL' => $ad['URL']];
}
return print_r( $viewResults, TRUE);
return view('quicktip')
->with('spruch', $spruch)
->with('mqs', $mquicktips);
}
public function tips()
{
$file = storage_path() . "/app/public/tips.txt";
$tips = [];
if( file_exists($file) )
{
$tips = file($file);
}
return view('tips')
->with('title', 'MetaGer - Tipps & Tricks')
->with('tips', $tips);
}
function get($url) {
return file_get_contents($url);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class StartpageController extends Controller
{
......@@ -12,12 +13,35 @@ class StartpageController extends Controller
* @param int $id
* @return Response
*/
public function loadStartPage($locale = "de")
/* public function loadStartPage($locale = "de")
{
\App::setLocale($locale);
return view('index', [
'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen',
'homeIcon']);
} */
public function loadStartPage(Request $request)
{
$focusPages = [];
foreach($request->all() as $key => $value)
{
if($value === 'on' && $key != 'param_sprueche' && $key != 'param_tab')
{
$focusPages[] = str_replace('param_', '', $key);
}
}
return view('index')
->with('title', trans('titles.index'))
->with('homeIcon')
->with('focus', $request->input('focus', 'web'))
->with('lang', $request->input('param_lang', 'all'))
->with('resultCount', $request->input('param_resultCount', '20'))
->with('time', $request->input('param_time', '1000'))
->with('sprueche', $request->input('param_sprueche', 'off'))
->with('tab', $request->input('param_sprueche', 'off'))
->with('focusPages', $focusPages);
}
public function loadPage($subpage)
......
......@@ -15,6 +15,7 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Fideloper\Proxy\TrustProxies::class,
];
/**
......
......@@ -14,54 +14,54 @@
Route::group(['prefix' => LaravelLocalization::setLocale()], function()
{
/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
Route::get('/', function()
/* Route::get('/', function()
{
return view('index', [
'title' => 'MetaGer: Sicher suchen & finden, Privatsphäre schützen',
'title' => trans('titles.index'),
'homeIcon']);
});
}); */
Route::get('/', 'StartpageController@loadStartPage');
Route::get('impressum', function()
{
return view('impressum')
->with('title', 'Impressum - MetaGer')
->with('title', trans('titles.impressum'))
->with('css', 'impressum.css');
});
Route::get('about', function()
{
return view('about')
->with('title', 'Über Uns - MetaGer')
->with('title', trans('titles.about'))
->with('css', 'about.css');
});
Route::get('team', function()
{
return view('team.team')
->with('title', 'Team - MetaGer')
->with('title', trans('titles.team'))
->with('css', 'team.css');
});
Route::get('team/pubkey-wsb', function()
{
return view('team.pubkey-wsb')
->with('title', 'Team - MetaGer');
->with('title', trans('titles.team'));
});
Route::get('kontakt', function()
{
return view('kontakt.kontakt')
->with('title', 'Kontakt - MetaGer')
->with('title', trans('titles.kontakt'))
->with('css', 'kontakt.css')
->with('js', ['openpgp.min.js','kontakt.js']);
});
Route::post('kontakt', 'MailController@contactMail');
Route::get('meta/meta.ger3', 'MetaGerSearch@search');
Route::get('spende', function()
{
return view('spende')
->with('title', 'Spenden - MetaGer')
->with('title', trans('titles.spende'))
->with('css', 'donation.css');
});
Route::post('spende', 'MailController@donation');
......@@ -69,19 +69,24 @@
Route::get('datenschutz', function()
{
return view('datenschutz')
->with('title', 'Datenschutz und Privatsphäre - MetaGer')
->with('title', trans('titles.datenschutz'))
->with('css', 'privacy.css');
});
Route::get('hilfe', function()
{
return view('hilfe')
->with('title', 'Hilfe - MetaGer')
->with('title', trans('titles.hilfe'))
->with('css', 'help.css');
});
Route::get('meta/meta.ger3', 'MetaGerSearch@test');
Route::get('widget', function()
{
return view('widget')
->with('title', trans('titles.widget'))
->with('css', 'widget.css');
});
Route::get('settings', function()
{
return view('settings')
......@@ -89,4 +94,10 @@
->with('css', 'settings.css')
->with('js', ['settings.js']);
});
Route::get('meta/meta.ger3', 'MetaGerSearch@search');
Route::get('qt', 'MetaGerSearch@quicktips');
Route::get('tips', 'MetaGerSearch@tips');
});
......@@ -3,10 +3,14 @@ namespace App;
use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;
use App\Models\SocketRocket;
use App;
use Storage;
use Log;
use App\lib\TextLanguageDetect\TextLanguageDetect;
use App\lib\TextLanguageDetect\LanguageDetect\TextLanguageDetectException;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
#use \Illuminate\Pagination\Paginator;
class MetaGer
{
......@@ -25,8 +29,10 @@ class MetaGer
protected $stopWords = [];
protected $engines = [];
protected $results = [];
protected $ads = [];
protected $warnings = [];
protected $errors = [];
protected $addedHosts = [];
# Daten über die Abfrage
protected $ip;
protected $language;
......@@ -39,9 +45,11 @@ class MetaGer
protected $domainsBlacklisted = [];
protected $urlsBlacklisted = [];
protected $url;
protected $languageDetect;
function __construct()
{
$this->time = microtime();
define('CRLF', "\r\n");
define('BUFFER_LENGTH', 8192);
if( file_exists(config_path() . "/blacklistDomains.txt") && file_exists(config_path() . "/blacklistUrl.txt") )
......@@ -55,29 +63,135 @@ class MetaGer
{
Log::warning("Achtung: Eine, oder mehrere Blacklist Dateien, konnten nicht geöffnet werden");
}
$this->languageDetect = new TextLanguageDetect();
$this->languageDetect->setNameMode("2");
}
public function rankAll ()
{
foreach( $this->engines as $engine )
{
$engine->rank($this);
}
}
public function createView()
{
$viewResults = [];
# Wir extrahieren alle notwendigen Variablen und geben Sie an unseren View:
foreach($this->results as $result)
{
$viewResults[] = get_object_vars($result);
}
return view('metager3')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('warnings', $this->warnings)
->with('errors', $this->errors);
switch ($this->out) {
case 'results':
return view('metager3results')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this);
break;
default:
return view('metager3')
->with('results', $viewResults)
->with('eingabe', $this->eingabe)
->with('mobile', $this->mobile)
->with('warnings', $this->warnings)
->with('errors', $this->errors)
->with('metager', $this);
break;
}
}
public function removeInvalids ()
{
$results = [];
foreach($this->results as $result)
{
if($result->isValid($this))
$results[] = $result;
}
#$this->results = $results;
}
public function combineResults ()
{
foreach($this->engines as $engine)
{
$this->results = array_merge($this->results, $engine->results);
foreach($engine->results as $result)
{
if($result->valid)
$this->results[] = $result;
}
foreach($engine->ads as $ad)
{
$this->ads[] = $ad;
}
}
uasort($this->results, function($a, $b){
if($a->getRank() == $b->getRank())
return 0;
return ($a->getRank() < $b->getRank()) ? 1 : -1;
});
# Validate Results
$newResults = [];
foreach($this->results as $result)
{
if($result->isValid($this))
$newResults[] = $result;
}
$this->results = $newResults;
$counter = 0;
$firstRank = 0;
foreach($this->results as $result)
{
if($counter === 0)
$firstRank = $result->rank;
$counter++;
$result->number = $counter;
$confidence = 0;
if($firstRank > 0)
$confidence = $result->rank/$firstRank;
else
$confidence = 0;
if($confidence > 0.65)
$result->color = "#FF4000";
elseif($confidence > 0.4)
$result->color = "#FF0080";
elseif($confidence > 0.2)
$result->color = "#C000C0";
else
$result->color = "#000000";
}
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$offset= $currentPage-1;
//Create a new Laravel collection from the array data
$collection = new Collection($this->results);
//Define how many items we want to be visible in each page
$perPage = $this->resultCount;
//Slice the collection to get the items to display in current page
$currentPageSearchResults = $collection->slice($offset * $perPage, $perPage)->all();
//Create our paginator and pass it to the view
$paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
$paginatedSearchResults->setPath('/meta/meta.ger3');
foreach($this->request->all() as $key => $value)
{
$paginatedSearchResults->addQuery($key, $value);
}
$this->results = $paginatedSearchResults;
}
public function createSearchEngines (Request $request)
......@@ -94,15 +208,24 @@ class MetaGer
if($this->fokus === "angepasst")
{
$sumas = $xml->xpath("suma");
/**$maxSumas = 30;
$count = 0;
foreach($sumas as $suma)
{
if($maxSumas === $count)
break;
$enabledSearchengines[] = $suma;
$count++;
}**/
foreach($sumas as $suma)
{
if($request->has($suma["service"])
#|| ( $this->fokus !== "bilder"
# && ($suma["name"]->__toString() === "qualigo"
# || $suma["name"]->__toString() === "similar_product_ads"
# || ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
# )
# )
|| ( $this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
#|| 1 === 1 #Todo: entfernen
){
......@@ -122,12 +245,12 @@ class MetaGer
foreach($sumas as $suma){
$types = explode(",",$suma["type"]);
if(in_array($this->fokus, $types)
#|| ( $this->fokus !== "bilder"
# && ($suma["name"]->__toString() === "qualigo"
# || $suma["name"]->__toString() === "similar_product_ads"
# || ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
# )
# )
|| ( $this->fokus !== "bilder"
&& ($suma["name"]->__toString() === "qualigo"
|| $suma["name"]->__toString() === "similar_product_ads"
|| ( !$overtureEnabled && $suma["name"]->__toString() === "overtureAds" )
)
)
){
if(!(isset($suma['disabled']) && $suma['disabled']->__toString() === "1"))
{
......@@ -140,7 +263,7 @@ class MetaGer
}
}
}
if( ( $this->fokus !== "bilder" && sizeof($enabledSearchengines) <= 3 ) || ( $this->fokus === "bilder" && sizeof($enabledSearchengines) === 0) )
{
$this->errors[] = "Achtung: Sie haben in ihren Einstellungen keine Suchmaschine ausgewählt.";
......@@ -149,21 +272,42 @@ class MetaGer
$engines = [];
foreach($enabledSearchengines as $engine){
if(strlen($this->site) > 0 && (!isset($engine["hasSiteSearch"]) || $engine["hasSiteSearch"]->__toString() !== "1"))
{
continue;
}
# Wenn diese Suchmaschine gar nicht eingeschaltet sein soll
$path = "App\Models\parserSkripte\\" . ucfirst($engine["package"]->__toString());
$time = microtime();
$tmp = new $path($engine, $this);