Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
open-source
MetaGer
Commits
e0695721
Commit
e0695721
authored
May 11, 2016
by
Dominik Hebeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Einen Teil der Logik von MetaGer habe ich nun nach PHP überführt
parent
dc4b2c9f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
240 additions
and
27 deletions
+240
-27
app/Http/Controllers/MetaGerSearch.php
app/Http/Controllers/MetaGerSearch.php
+48
-2
app/MetaGer/Results.php
app/MetaGer/Results.php
+17
-16
app/MetaGer/Search.php
app/MetaGer/Search.php
+65
-0
app/MetaGer/Searchengine.php
app/MetaGer/Searchengine.php
+102
-0
config/.gitignore
config/.gitignore
+1
-1
config/app.php
config/app.php
+1
-2
resources/lang/en/fokiNames.php
resources/lang/en/fokiNames.php
+6
-6
No files found.
app/Http/Controllers/MetaGerSearch.php
View file @
e0695721
...
...
@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
use
Illuminate\Http\Request
;
use
App\MetaGer\Forwarder
;
use
App\MetaGer\Results
;
use
App
;
use
App\MetaGer\Search
;
class
MetaGerSearch
extends
Controller
{
...
...
@@ -28,8 +30,52 @@ class MetaGerSearch extends Controller
public
function
search
(
Request
$request
)
{
$results
=
new
Results
(
$request
);
return
$results
->
loadSearchEngines
();
# 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'
,
''
));
$searchengines
=
Search
::
loadSearchEngines
(
$request
);
$results
=
new
Results
(
$searchengines
);
return
$results
->
results
;
}
}
\ No newline at end of file
app/MetaGer/Results.php
View file @
e0695721
...
...
@@ -2,30 +2,31 @@
namespace
App\MetaGer
;
use
Illuminate\Http\Request
;
use
File
;
class
Results
{
private
$request
;
private
$fokiNames
=
[];
private
$fokus
;
function
__construct
(
Request
$requ
es
t
)
function
__construct
(
$engin
es
)
{
$this
->
request
=
$request
;
$this
->
fokiNames
[]
=
trans
(
'fokiNames.web'
);
$this
->
fokiNames
[]
=
trans
(
'fokiNames.nachrichten'
);
$this
->
fokiNames
[]
=
trans
(
'fokiNames.wissenschaft'
);
$this
->
fokiNames
[]
=
trans
(
'fokiNames.produktsuche'
);
$this
->
fokiNames
[]
=
trans
(
'fokiNames.bilder'
);
$this
->
fokiNames
[]
=
trans
(
'fokiNames.angepasst'
);
$this
->
results
=
$this
->
loadResults
(
$engines
);
}
p
ublic
function
load
SearchE
ngines
(
)
p
rivate
function
load
Results
(
$e
ngines
)
{
# Wenn keine persönlichen Einstellungen gesetzt sind, dafür aber ein existierender Fokus von uns,
# werden die zu dem Fokus gehörenden Suchmaschinen angeschaltet.
return
$this
->
request
->
input
(
'focus'
,
'test'
);
return
var_dump
(
$this
->
fokiNames
);
# Das Laden der Ergebnisse besteht aus 2 Elementaren Schritten:
# 1. GET-Requests abarbeiten
# 2. Ergebnisse parsen
# 1. GET-Requests abarbeiten
# Wir generiern zunächst alle GET-Strings:
$getStrings
=
[];
foreach
(
$engines
as
$engine
)
{
$getStrings
[]
=
$engine
->
generateGetString
();
}
return
print_r
(
$getStrings
,
TRUE
);
}
}
\ No newline at end of file
app/MetaGer/Search.php
0 → 100644
View file @
e0695721
<?php
namespace
App\MetaGer
;
use
Illuminate\Http\Request
;
use
App\MetaGer\Searchengine
;
class
Search
{
public
static
function
loadSearchEngines
(
Request
$request
)
{
# Überprüfe, welche Sumas eingeschaltet sind
$xml
=
simplexml_load_file
(
SUMA_FILE
);
$enabledSearchengines
=
[];
$overtureEnabled
=
FALSE
;
if
(
FOKUS
===
"angepasst"
)
{
$sumas
=
$xml
->
xpath
(
"suma"
);
foreach
(
$sumas
as
$suma
)
{
if
(
$request
->
has
(
$suma
[
"service"
])
||
(
FOKUS
!==
"bilder"
&&
(
$suma
[
"name"
]
->
__toString
()
===
"qualigo"
||
$suma
[
"name"
]
->
__toString
()
===
"similar_product_ads"
||
(
!
$overtureEnabled
&&
$suma
[
"name"
]
->
__toString
()
===
"overtureAds"
)
)
)
){
if
(
$suma
[
"name"
]
->
__toString
()
===
"overture"
)
{
$overtureEnabled
=
TRUE
;
}
$enabledSearchengines
[]
=
$suma
;
}
}
}
else
{
$sumas
=
$xml
->
xpath
(
"suma"
);
foreach
(
$sumas
as
$suma
){
$types
=
explode
(
","
,
$suma
[
"type"
]);
if
(
in_array
(
FOKUS
,
$types
)
||
(
FOKUS
!==
"bilder"
&&
(
$suma
[
"name"
]
->
__toString
()
===
"qualigo"
||
$suma
[
"name"
]
->
__toString
()
===
"similar_product_ads"
||
(
!
$overtureEnabled
&&
$suma
[
"name"
]
->
__toString
()
===
"overtureAds"
)
)
)
){
if
(
$suma
[
"name"
]
->
__toString
()
===
"overture"
)
{
$overtureEnabled
=
TRUE
;
}
$enabledSearchengines
[]
=
$suma
;
}
}
}
$engines
=
[];
foreach
(
$enabledSearchengines
as
$engine
){
$engines
[]
=
new
Searchengine
(
$engine
);
}
return
$engines
;
}
}
\ No newline at end of file
app/MetaGer/Searchengine.php
0 → 100644
View file @
e0695721
<?php
namespace
App\MetaGer
;
class
Searchengine
{
function
__construct
(
\
SimpleXMLElement
$engine
)
{
foreach
(
$engine
->
attributes
()
as
$key
=>
$value
){
$this
->
$key
=
$value
->
__toString
();
}
# User-Agent definieren:
if
(
isset
(
$_SERVER
[
'HTTP_USER_AGENT'
]))
{
$this
->
useragent
=
$_SERVER
[
'HTTP_USER_AGENT'
];
}
else
{
$this
->
useragent
=
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"
;
}
}
public
function
generateGetString
()
{
$getString
=
""
;
# Protokoll:
if
(
$this
->
port
===
"443"
){
$getString
.
=
"https://"
;
}
else
{
$getString
.
=
"http://"
;
}
# Host:
$getString
.
=
$this
->
host
;
# Port:
$getString
.
=
":"
.
$this
->
port
;
# Skript:
$getString
.
=
$this
->
skript
;
# FormData:
$getString
.
=
"?"
.
$this
->
formData
;
# Wir müssen noch einige Platzhalter in dem GET-String ersetzen:
if
(
strpos
(
$getString
,
"<<USERAGENT>>"
)
){
$getString
=
str_replace
(
"<<USERAGENT>>"
,
$this
->
urlEncode
(
$this
->
useragent
),
$getString
);
}
if
(
strpos
(
$getString
,
"<<QUERY>>"
)
)
{
$getString
=
str_replace
(
"<<QUERY>>"
,
$this
->
urlEncode
(
Q
),
$getString
);
}
if
(
strpos
(
$getString
,
"<<IP>>"
)
)
{
$getString
=
str_replace
(
"<<IP>>"
,
$this
->
urlEncode
(
IP
),
$getString
);
}
if
(
strpos
(
$getString
,
"<<LANGUAGE>>"
)
)
{
$getString
=
str_replace
(
"<<LANGUAGE>>"
,
$this
->
urlEncode
(
LANGUAGE
),
$getString
);
}
if
(
strpos
(
$getString
,
"<<CATEGORY>>"
)
)
{
$getString
=
str_replace
(
"<<CATEGORY>>"
,
$this
->
urlEncode
(
CATEGORY
),
$getString
);
}
return
$getString
;
}
private
function
urlEncode
(
$string
)
{
if
(
isset
(
$this
->
inputEncoding
))
{
return
urlencode
(
mb_convert_encoding
(
$string
,
$this
->
inputEncoding
));
}
else
{
return
urlencode
(
$string
);
}
}
private
function
getOvertureAffilData
()
{
$xfip
=
"
$_SERVER['HTTP_X_FORWARDED_FOR']
"
;
$xfip
=~
s
/^
(
\
d
+
\
.
\
d
+
\
.
\
d
+
)
\
.
\
d
+/
$
1
\
.0
/
;
my
$overt_ip
=
$ENV
{
'HTTP_FROM'
};
my
$overt_xfip
=
$xfip
;
# anonymisierte IPs an Overture:
$overt_ip
=~
s
#(\d+)\.(\d+)\.(\d+)\.\d+#$1\.$2\.$3\.0#;
$overt_xfip
=~
s
#(\d+)\.(\d+)\.(\d+)\.\d+#$1\.$2\.$3\.0#;
$affil_data
.
=
'ip='
.
$overt_ip
;
$affil_data
.
=
'&ua='
.
$self
->
{
useragent
};
if
(
$xfip
)
{
$affil_data
.
=
'&xfip='
.
$overt_xfip
;
}
$affil_data
=
URI
::
Escape
::
uri_escape_utf8
(
$affil_data
);
$affilDataValue
=
$affil_data
;
# Wir benötigen die ServeUrl:
$serveUrl
=
$cgi
->
self_url
();
#URI::Escape::uri_escape_utf8($cgi->self_url());
$serveUrl
=
URI
::
Escape
::
uri_escape_utf8
(
$serveUrl
);
return
"&affilData="
.
$affilDataValue
.
"&serveUrl="
.
$serveUrl
;
}
}
\ No newline at end of file
config/.gitignore
View file @
e0695721
metager.ini
\ No newline at end of file
*.xml
\ No newline at end of file
config/app.php
View file @
e0695721
...
...
@@ -202,8 +202,7 @@ 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
,
],
];
resources/lang/en/fokiNames.php
View file @
e0695721
<?php
return
[
'web'
=>
"web"
,
'nachrichten
'
=>
"news
"
,
'
wissenschaft'
=>
'science
'
,
'
produktsuche'
=>
'shopping
'
,
'
bilder'
=>
'picture
'
,
'
angepasst'
=>
'custom
'
'web'
=>
"web"
,
'n
ews'
=>
"n
achrichten"
,
'
science'
=>
'wissenschaft
'
,
'
shopping'
=>
'produktsuche
'
,
'
picture'
=>
'bilder
'
,
'
custom'
=>
'angepasst
'
];
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment