Skip to content
GitLab
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
160261c1
Commit
160261c1
authored
Jan 23, 2018
by
Karl Hasselbring
Browse files
Quicktips Model angelegt und theoretisch in MetaGer.php eingefügt
parent
50ebc8ff
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/MetaGer.php
View file @
160261c1
...
...
@@ -570,8 +570,7 @@ class MetaGer
foreach
(
$engines
as
$engine
)
{
$engine
->
startSearch
(
$this
);
}
// Derzeit deaktiviert, da es die eigene Suche gibt
// $this->adjustFocus($sumas, $enabledSearchengines);
$quicktips
=
new
\
App\Models\Quicktips
(
$this
->
q
,
$this
->
lang
,
$this
->
getTime
(),
$this
->
getHashCode
());
/* Wir warten auf die Antwort der Suchmaschinen
* Die Verbindung steht zu diesem Zeitpunkt und auch unsere Requests wurden schon gesendet.
...
...
app/Models/Quicktip.php
0 → 100644
View file @
160261c1
<?php
namespace
App\Models
;
class
Quicktip
{
private
$type
;
private
$title
;
private
$link
;
private
$descr
;
private
$details
;
# Erstellt ein neues Ergebnis
public
function
__construct
(
$type
,
$title
,
$link
,
$descr
,
$details
)
{
$this
->
type
=
$type
;
$this
->
title
=
$title
;
$this
->
link
=
$link
;
$this
->
descr
=
$descr
;
$this
->
details
=
$details
;
}
}
class
Quicktip_Detail
{
private
$title
;
private
$link
;
private
$descr
;
public
function
__construct
(
$title
,
$link
,
$descr
)
{
$this
->
title
=
$title
;
$this
->
link
=
$link
;
$this
->
descr
=
$descr
;
}
}
app/Models/Quicktips.php
0 → 100644
View file @
160261c1
<?php
namespace
App\Models
;
class
Quicktips
{
use
DispatchesJobs
;
const
QUICKTIP_URL
=
"https://quicktips.metager3.de/quicktips.xml"
;
const
QUICKTIP_NAME
=
"quicktips"
;
public
function
__construct
(
$search
,
$locale
,
$max_time
,
$resultHash
)
{
$this
->
startSearch
(
$search
,
$locale
,
$max_time
,
$resultHash
);
}
public
function
startSearch
(
$search
,
$locale
,
$max_time
,
$resultHash
)
{
$full_url
=
QUICKTIP_URL
.
"?search="
.
$search
.
"&locale="
.
$locale
;
$hash
=
md5
(
$full_url
);
if
(
Cache
::
has
(
$hash
))
{
$cached
=
true
;
$this
->
retrieveResults
();
}
else
{
// ???
Redis
::
hset
(
"search."
.
$resultHash
,
QUICKTIP_NAME
,
"waiting"
);
// Queue this search
$mission
=
$resultHash
.
";"
.
$url
.
";"
.
$max_time
;
Redis
::
rpush
(
QUICKTIP_NAME
.
".queue"
,
$mission
);
// Check the current status of Searchers for QUICKTIP_NAME
$needSearcher
=
false
;
$searcherData
=
Redis
::
hgetall
(
QUICKTIP_NAME
.
".stats"
);
// Create additional Searchers for QUICKTIP_NAME if necessary
if
(
sizeof
(
$searcherData
)
===
0
)
{
$needSearcher
=
true
;
}
else
{
$median
=
0
;
foreach
(
$searcherData
as
$pid
=>
$data
)
{
$data
=
explode
(
";"
,
$data
);
$median
+=
floatval
(
$data
[
1
]);
}
$median
/=
sizeof
(
$searcherData
);
if
(
$median
<
.1
)
{
$needSearcher
=
true
;
}
}
if
(
$needSearcher
&&
Redis
::
get
(
QUICKTIP_NAME
)
!==
"locked"
)
{
Redis
::
set
(
QUICKTIP_NAME
,
"locked"
);
$this
->
dispatch
(
new
Searcher
(
QUICKTIP_NAME
));
}
}
}
public
function
retrieveResults
(
$hash
,
$resultHash
)
{
$body
=
""
;
if
(
Cache
::
has
(
$hash
))
{
$body
=
Cache
::
get
(
$hash
);
}
elseif
(
Redis
::
hexists
(
'search.'
.
$resultHash
,
QUICKTIP_NAME
))
{
$body
=
Redis
::
hget
(
'search.'
.
$resultHash
,
QUICKTIP_NAME
);
Redis
::
hdel
(
'search.'
.
$resultHash
,
QUICKTIP_NAME
);
Cache
::
put
(
$hash
,
$body
,
$cacheDuration
);
}
if
(
$body
!==
""
)
{
return
$this
->
loadResults
(
$body
);
}
else
{
return
false
;
}
}
public
function
loadResults
(
$quicktips_raw
)
{
$quicktips_raw
=
preg_replace
(
"/
\r\n
/si"
,
""
,
$quicktips_raw
);
try
{
$content
=
simplexml_load_string
(
$quicktips_raw
);
if
(
!
$content
)
{
return
;
}
$quicktips
=
[];
$quicktips_xpath
=
$content
->
xpath
(
'feed/entry'
);
foreach
(
$quicktips_xpath
as
$quicktip_xml
)
{
$type
=
$quicktip_xml
->
{
"mg:type"
}
->
__toString
();
$title
=
$quicktip_xml
->
{
"title"
}
->
__toString
();
$link
=
$quicktip_xml
->
{
"link"
}
->
__toString
();
$descr
=
$quicktip_xml
->
{
"content"
}
->
__toString
();
$details
=
[];
foreach
(
$quicktip_xml
->
{
"mg:details"
}
->
{
"entry"
}
as
$detail_xml
)
{
$details_title
=
$detail_xml
->
{
"title"
}
->
__toString
();
$details_link
=
$detail_xml
->
{
"url"
}
->
__toString
();
$details_descr
=
$detail_xml
->
{
"text"
}
->
__toString
();
$details
[]
=
new
\
App\Models\Detail
(
$details_title
,
$details_link
,
$details_descr
);
}
$quicktips
[]
=
new
\
App\Models\Quicktip
(
$type
,
$title
,
$link
,
$descr
,
$details
);
}
return
$quicktips
;
}
catch
(
\
Exception
$e
)
{
Log
::
error
(
"A problem occurred parsing quicktips"
);
return
[];
}
}
}
resources/views/layouts/quicktip.blade.php
0 → 100644
View file @
160261c1
@
if
(
sizeof
(
$quicktip
->
details
)
>
0
)
<
details
>
<
summary
class
=
"quicktip-summary"
>
<
h1
>
@
if
(
isset
(
$quicktip
->
link
))
<
a
href
=
"{{
$quicktip->link
}}"
>
{{
$quicktip
->
title
}}
</
a
>
@
else
{{
$quicktip
->
title
}}
@
endif
</
h1
>
<
p
>
{{
$quicktip
->
descr
}}
</
p
>
@
if
</
summary
>
@
foreach
(
$quicktip
->
details
as
$detail
)
<
div
class
=
"quicktip-detail"
>
<
h2
>
@
if
(
isset
(
$detail
->
link
))
<
a
href
=
"{{
$detail->link
}}"
>
{{
$detail
->
title
}}
</
a
>
@
else
{{
$detail
->
title
}}
@
endif
</
h2
>
<
p
>
{{
$detail
->
descr
}}
</
p
>
</
div
>
@
endforeach
</
details
>
@
else
<
summary
class
=
"quicktip-summary"
>
<
h1
>
@
if
(
isset
(
$quicktip
->
link
))
<
a
href
=
"{{
$quicktip->link
}}"
>
{{
$quicktip
->
title
}}
</
a
>
@
else
{{
$quicktip
->
title
}}
@
endif
</
h1
>
@
if
</
summary
>
@
endif
\ No newline at end of file
resources/views/quicktips.blade.php
0 → 100644
View file @
160261c1
@
foreach
(
$quicktips
as
$quicktip
)
<
div
class
=
"quicktip"
type
=
"{{
$quicktip->type
}}"
>
@
include
(
'layouts.quicktip'
,
[
'quicktip'
=>
$quicktip
])
</
div
>
@
endforeach
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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