Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
478bbf4c
Commit
478bbf4c
authored
Jun 13, 2017
by
Phil Höfer
Browse files
MetaGer-Key eingebaut
parent
66f7bbbf
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/MetaGer.php
View file @
478bbf4c
...
...
@@ -40,6 +40,8 @@ class MetaGer
protected
$ip
;
protected
$language
;
protected
$agent
;
protected
$apiKey
=
""
;
protected
$apiAuthorized
=
false
;
# Konfigurationseinstellungen:
protected
$sumaFile
;
protected
$mobile
;
...
...
@@ -148,6 +150,7 @@ class MetaGer
->
with
(
'mobile'
,
$this
->
mobile
)
->
with
(
'warnings'
,
$this
->
warnings
)
->
with
(
'errors'
,
$this
->
errors
)
->
with
(
'apiAuthorized'
,
$this
->
apiAuthorized
)
->
with
(
'metager'
,
$this
)
->
with
(
'browser'
,
(
new
Agent
())
->
browser
());
break
;
...
...
@@ -155,6 +158,7 @@ class MetaGer
return
view
(
'metager3resultsrss20'
)
->
with
(
'results'
,
$viewResults
)
->
with
(
'eingabe'
,
$this
->
eingabe
)
->
with
(
'apiAuthorized'
,
$this
->
apiAuthorized
)
->
with
(
'metager'
,
$this
)
->
with
(
'resultcount'
,
sizeof
(
$viewResults
));
break
;
...
...
@@ -190,6 +194,9 @@ class MetaGer
// filter
// augment (boost&adgoal)
// authorize
if
(
$this
->
apiKey
)
{
$this
->
apiAuthorized
=
$this
->
authorize
(
$this
->
apiKey
);
}
// misc (WiP)
if
(
$this
->
fokus
==
"nachrichten"
)
{
$this
->
results
=
array_filter
(
$this
->
results
,
function
(
$v
,
$k
)
{
...
...
@@ -462,6 +469,34 @@ class MetaGer
return
$results
;
}
public
function
authorize
(
$key
)
{
$postdata
=
http_build_query
(
array
(
'dummy'
=>
rand
(),
));
$opts
=
array
(
'http'
=>
array
(
'method'
=>
'POST'
,
'header'
=>
'Content-type: application/x-www-form-urlencoded'
,
'content'
=>
$postdata
,
),
);
$context
=
stream_context_create
(
$opts
);
try
{
$link
=
"https://key.metager3.de/"
.
urlencode
(
$key
)
.
"/request-permission/api-access"
;
$result
=
json_decode
(
file_get_contents
(
$link
,
false
,
$context
));
if
(
$result
->
{
'api-access'
}
==
true
)
{
return
true
;
}
else
{
return
false
;
}
}
catch
(
\
ErrorException
$e
)
{
return
false
;
}
}
/*
* Die Erstellung der Suchmaschinen bis die Ergebnisse da sind mit Unterfunktionen
*/
...
...
@@ -994,6 +1029,9 @@ class MetaGer
}
else
{
$this
->
quicktips
=
true
;
}
$this
->
apiKey
=
$request
->
input
(
'key'
,
''
);
$this
->
out
=
$request
->
input
(
'out'
,
"html"
);
# Standard output format html
if
(
$this
->
out
!==
"html"
&&
$this
->
out
!==
"json"
&&
$this
->
out
!==
"results"
&&
$this
->
out
!==
"results-with-style"
&&
$this
->
out
!==
"result-count"
&&
$this
->
out
!==
"rss20"
&&
$this
->
out
!==
"rich"
)
{
...
...
resources/views/metager3resultsrss20.blade.php
View file @
478bbf4c
...
...
@@ -8,6 +8,7 @@
<opensearch:totalResults>
{{ $resultcount }}
</opensearch:totalResults>
<opensearch:Query
role=
"request"
searchTerms=
"{{ htmlspecialchars($eingabe, ENT_QUOTES) }}"
/>
@if($apiAuthorized)
@foreach($metager->getResults() as $result)
<item>
<title>
{!! htmlspecialchars($result->titel, ENT_XML1, 'UTF-8'); !!}
</title>
...
...
@@ -18,5 +19,6 @@
</description>
</item>
@endforeach
@endif
</channel>
</rss>
resources/views/metager3rich.blade.php
View file @
478bbf4c
...
...
@@ -33,7 +33,7 @@
</details>
<main
class=
"results-container"
>
@foreach($metager->getResults() as $result)
@if($result->number % 7 === 0)
@if($result->number % 7 === 0
&&
!$apiAuthorized
)
@include('layouts.rich.ad', ['result' => $metager->popAd()])
@endif
@include('layouts.rich.result', ['result' => $result])
...
...
Write
Preview
Supports
Markdown
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