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
1da3d4e6
Commit
1da3d4e6
authored
Feb 05, 2019
by
Dominik Hebeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an image search to MetaGer
parent
c7a8030e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
134 additions
and
11 deletions
+134
-11
app/Jobs/Searcher.php
app/Jobs/Searcher.php
+10
-2
app/MetaGer.php
app/MetaGer.php
+4
-1
app/Models/Searchengine.php
app/Models/Searchengine.php
+3
-1
app/Models/parserSkripte/BingBilder.php
app/Models/parserSkripte/BingBilder.php
+77
-0
resources/less/metager/pages/resultpage/result-page.less
resources/less/metager/pages/resultpage/result-page.less
+28
-2
resources/views/parts/foki.blade.php
resources/views/parts/foki.blade.php
+5
-0
resources/views/resultpages/results_images.blade.php
resources/views/resultpages/results_images.blade.php
+7
-5
No files found.
app/Jobs/Searcher.php
View file @
1da3d4e6
...
...
@@ -12,7 +12,7 @@ class Searcher implements ShouldQueue
{
use
InteractsWithQueue
,
Queueable
,
SerializesModels
;
protected
$name
,
$ch
,
$pid
,
$counter
,
$lastTime
,
$connectionInfo
,
$user
,
$password
;
protected
$name
,
$ch
,
$pid
,
$counter
,
$lastTime
,
$connectionInfo
,
$user
,
$password
,
$headers
;
# Each Searcher will shutdown after a specified time(s) or number of requests
protected
$MAX_REQUESTS
=
100
;
# This value should always be below the retry_after value in config/queue.php
...
...
@@ -32,7 +32,7 @@ class Searcher implements ShouldQueue
* keep-alive requests.
* @return void
*/
public
function
__construct
(
$name
,
$user
=
null
,
$password
=
null
)
public
function
__construct
(
$name
,
$user
=
null
,
$password
=
null
,
$headers
=
null
)
{
$this
->
name
=
$name
;
$this
->
pid
=
getmypid
();
...
...
@@ -40,6 +40,7 @@ class Searcher implements ShouldQueue
$this
->
startTime
=
microtime
(
true
);
$this
->
user
=
$user
;
$this
->
password
=
$password
;
$this
->
headers
=
$headers
;
// Submit this worker to the Redis System
Redis
::
expire
(
$this
->
name
,
5
);
}
...
...
@@ -201,6 +202,13 @@ class Searcher implements ShouldQueue
curl_setopt
(
$ch
,
CURLOPT_USERPWD
,
$this
->
user
.
":"
.
$this
->
password
);
}
if
(
$this
->
headers
!==
null
)
{
# Headers are in the Form:
# <key>:<value>;<key>:<value>
$headerArray
=
explode
(
";"
,
$this
->
headers
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$headerArray
);
}
return
$ch
;
}
}
app/MetaGer.php
View file @
1da3d4e6
...
...
@@ -131,7 +131,10 @@ class MetaGer
->
with
(
'errors'
,
$this
->
errors
)
->
with
(
'apiAuthorized'
,
$this
->
apiAuthorized
)
->
with
(
'metager'
,
$this
)
->
with
(
'browser'
,
(
new
Agent
())
->
browser
());
->
with
(
'browser'
,
(
new
Agent
())
->
browser
())
->
with
(
'quicktips'
,
$quicktipResults
)
->
with
(
'focus'
,
$this
->
fokus
)
->
with
(
'resultcount'
,
count
(
$this
->
results
));
}
}
else
{
switch
(
$this
->
out
)
{
...
...
app/Models/Searchengine.php
View file @
1da3d4e6
...
...
@@ -34,6 +34,8 @@ abstract class Searchengine
private
$user
;
# Username für HTTP-Auth (falls angegeben)
private
$password
;
# Passwort für HTTP-Auth (falls angegeben)
private
$headers
;
# Headers to add
public
$fp
;
# Wird für Artefakte benötigt
public
$socketNumber
=
null
;
# Wird für Artefakte benötigt
public
$counter
=
0
;
# Wird eventuell für Artefakte benötigt
...
...
@@ -174,7 +176,7 @@ abstract class Searchengine
}
if
(
$needSearcher
&&
Redis
::
get
(
$this
->
name
)
!==
"locked"
)
{
Redis
::
set
(
$this
->
name
,
"locked"
);
$this
->
dispatch
(
new
Searcher
(
$this
->
name
,
$this
->
user
,
$this
->
password
));
$this
->
dispatch
(
new
Searcher
(
$this
->
name
,
$this
->
user
,
$this
->
password
,
$this
->
headers
));
}
}
}
...
...
app/Models/parserSkripte/BingBilder.php
0 → 100644
View file @
1da3d4e6
<?php
namespace
app\Models\parserSkripte
;
use
App\Models\Searchengine
;
use
Log
;
class
BingBilder
extends
Searchengine
{
public
$results
=
[];
public
function
__construct
(
\
SimpleXMLElement
$engine
,
\
App\MetaGer
$metager
)
{
parent
::
__construct
(
$engine
,
$metager
);
}
public
function
loadResults
(
$result
)
{
try
{
$results
=
json_decode
(
$result
);
$results
=
$results
->
value
;
foreach
(
$results
as
$result
)
{
$title
=
$result
->
name
;
$link
=
$result
->
hostPageUrl
;
$anzeigeLink
=
$link
;
$descr
=
""
;
$image
=
$result
->
thumbnailUrl
;
$this
->
counter
++
;
$this
->
results
[]
=
new
\
App\Models\Result
(
$this
->
engine
,
$title
,
$link
,
$anzeigeLink
,
$descr
,
$this
->
displayName
,
$this
->
homepage
,
$this
->
counter
,
[
'image'
=>
$image
]
);
}
}
catch
(
\
Exception
$e
)
{
Log
::
error
(
"A problem occurred parsing results from
$this->name
:"
);
Log
::
error
(
$e
->
getMessage
());
return
;
}
}
public
function
getNext
(
\
App\MetaGer
$metager
,
$result
)
{
try
{
$results
=
json_decode
(
$result
);
$totalMatches
=
$results
->
totalEstimatedMatches
;
$nextOffset
=
$results
->
nextOffset
;
if
(
$nextOffset
>=
$totalMatches
)
{
return
;
}
$next
=
new
BingBilder
(
simplexml_load_string
(
$this
->
engine
),
$metager
);
if
(
\
str_contains
(
$next
->
getString
,
"&offset="
))
{
$next
->
getString
=
preg_replace
(
"/&offset=.*/si"
,
""
,
$next
->
getString
);
}
$next
->
getString
.
=
"&offset="
.
$nextOffset
;
$next
->
hash
=
md5
(
$next
->
host
.
$next
->
getString
.
$next
->
port
.
$next
->
name
);
$this
->
next
=
$next
;
}
catch
(
\
Exception
$e
)
{
Log
::
error
(
"A problem occurred parsing results from
$this->name
:"
);
Log
::
error
(
$e
->
getMessage
());
return
;
}
}
}
resources/less/metager/pages/resultpage/result-page.less
View file @
1da3d4e6
...
...
@@ -208,9 +208,35 @@ a {
}
.image-container {
margin: 10px auto;
display: flex;
flex-wrap: wrap;
flex-flow: row wrap;
> div.image {
flex: auto;
margin: 8px;
text-align: center;
> a > div {
display: inline-block;
background-color: white;
text-align: center;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
> img {
max-width: 150px;
}
@media(max-width: 370px){
> img {
max-width: 100%;
}
}
> div {
font-size: 12px;
color: #777;
}
}
> a > div:hover {
box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);
}
}
}
/* Placeholder für ladende Tabs */
...
...
resources/views/parts/foki.blade.php
View file @
1da3d4e6
...
...
@@ -3,6 +3,11 @@
<
a
href
=
"@if(
$metager->getFokus
() === "
web
")#@else
{
!!$metager->generateSearchLink('web')!!
}
@endif"
target
=
"_self"
tabindex
=
"2"
>@
lang
(
'index.foki.web'
)
</
a
>
</
div
>
@
endif
@
if
(
array_has
(
$metager
->
getAvailableFoki
(),
"bilder"
))
<
div
id
=
"bilder"
@
if
(
$metager
->
getFokus
()
===
"bilder"
)
class
=
"active"
@
endif
>
<
a
href
=
"@if(
$metager->getFokus
() === "
bilder
")#@else
{
!!$metager->generateSearchLink('bilder')!!
}
@endif"
target
=
"_self"
tabindex
=
"2"
>@
lang
(
'index.foki.bilder'
)
</
a
>
</
div
>
@
endif
@
if
(
array_has
(
$metager
->
getAvailableFoki
(),
"nachrichten"
))
<
div
id
=
"nachrichten"
@
if
(
$metager
->
getFokus
()
===
"nachrichten"
)
class
=
"active"
@
endif
>
<
a
href
=
"@if(
$metager->getFokus
() === "
nachrichten
")#@else
{
!!$metager->generateSearchLink('nachrichten')!!
}
@endif"
target
=
"_self"
tabindex
=
"3"
>@
lang
(
'index.foki.nachrichten'
)
</
a
>
...
...
resources/views/resultpages/results_images.blade.php
View file @
1da3d4e6
...
...
@@ -2,11 +2,13 @@
@
include
(
'parts.warnings'
)
<
div
id
=
"container"
class
=
"image-container"
>
@
foreach
(
$metager
->
getResults
()
as
$result
)
<
div
class
=
"item image-item"
>
<
div
class
=
"img"
>
<
a
href
=
"{{
$result->link
}}"
target
=
"{{
$metager->getNewtab
() }}"
><
img
src
=
"{{
$metager->getImageProxyLink
(
$result->image
) }}"
width
=
"150px"
alt
=
""
rel
=
"noopener"
/></
a
>
<
span
class
=
"label label-default hostlabel"
>
{{
strip_tags
(
$result
->
gefVon
)
}}
</
span
>
</
div
>
<
div
class
=
"image"
>
<
a
href
=
"{{
$result->link
}}"
target
=
"_blank"
>
<
div
title
=
"{{
$result->titel
}}"
>
<
img
src
=
"{{
$metager->getImageProxyLink
(
$result->image
)}}"
alt
=
"{{
$result->titel
}}"
/>
<
div
>
{{
$result
->
gefVon
}}
</
div
>
</
div
>
</
a
>
</
div
>
@
endforeach
</
div
>
...
...
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