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
6751648b
Commit
6751648b
authored
Feb 24, 2021
by
Dominik Hebeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic Admitad Partnershop working now
parent
e36255ab
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
1 deletion
+132
-1
app/Http/Controllers/MetaGerSearch.php
app/Http/Controllers/MetaGerSearch.php
+7
-0
app/MetaGer.php
app/MetaGer.php
+10
-1
app/Models/Admitad.php
app/Models/Admitad.php
+113
-0
app/Models/Result.php
app/Models/Result.php
+2
-0
No files found.
app/Http/Controllers/MetaGerSearch.php
View file @
6751648b
...
...
@@ -93,6 +93,10 @@ class MetaGerSearch extends Controller
# Ergebnisse der Suchmaschinen kombinieren:
$metager
->
prepareResults
(
$timings
);
$admitad
=
null
;
if
(
!
$metager
->
isApiAuthorized
()
&&
!
$metager
->
isDummy
()){
$admitad
=
new
\
App\Models\Admitad
(
$metager
);
}
$finished
=
true
;
foreach
(
$metager
->
getEngines
()
as
$engine
)
{
...
...
@@ -106,6 +110,7 @@ class MetaGerSearch extends Controller
"metager"
=>
[
"apiAuthorized"
=>
$metager
->
isApiAuthorized
(),
],
"admitad"
=>
$admitad
,
"adgoal"
=>
[
"loaded"
=>
$metager
->
isAdgoalLoaded
(),
"adgoalHash"
=>
$metager
->
getAdgoalHash
(),
...
...
@@ -190,6 +195,7 @@ class MetaGerSearch extends Controller
$engines
=
$cached
[
"engines"
];
$adgoal
=
$cached
[
"adgoal"
];
$admitad
=
$cached
[
"admitad"
];
$mg
=
$cached
[
"metager"
];
$metager
=
new
MetaGer
(
substr
(
$hash
,
strpos
(
$hash
,
"loader_"
)
+
7
));
...
...
@@ -209,6 +215,7 @@ class MetaGerSearch extends Controller
$metager
->
rankAll
();
$metager
->
prepareResults
();
$metager
->
parseAdmitad
(
$admitad
);
$result
=
[
'finished'
=>
true
,
...
...
app/MetaGer.php
View file @
6751648b
...
...
@@ -435,7 +435,9 @@ class MetaGer
}
}
public
function
parseAdmitad
(
\
App\Models\Admitad
&
$admitad
){
$admitad
->
parseAffiliates
(
$this
->
results
);
}
public
function
humanVerification
(
&
$results
)
{
...
...
@@ -1718,6 +1720,9 @@ class MetaGer
$this
->
results
=
$results
;
}
/**
* @return \App\Models\Result[]
*/
public
function
getResults
()
{
return
$this
->
results
;
...
...
@@ -1931,6 +1936,10 @@ class MetaGer
return
$this
->
headerPrinted
;
}
public
function
isDummy
(){
return
$this
->
dummy
;
}
/**
* Used by JS result loader to restore MetaGer Object of previous request
*/
...
...
app/Models/Admitad.php
0 → 100644
View file @
6751648b
<?php
namespace
App\Models
;
use
Cache
;
use
Log
;
use
LaravelLocalization
;
use
Illuminate\Support\Facades\Redis
;
class
Admitad
{
const
VALID_LANGS
=
[
"de"
,
"en"
];
private
$hash
;
/**
* Creates a new Admitad object which will start a request for affiliate links
* based on a result List from MetaGer.
* It will parse the Links of the results and query any affiliate shops.
*
* @param \App\MetaGer $metager
*/
public
function
__construct
(
&
$metager
)
{
$results
=
$metager
->
getResults
();
// Generate a list of URLs
$resultLinks
=
[];
foreach
(
$results
as
$result
){
$resultLinks
[]
=
$result
->
originalLink
;
}
$lang
=
LaravelLocalization
::
getCurrentLocale
();
if
(
!
in_array
(
$lang
,
self
::
VALID_LANGS
)){
$lang
=
"de"
;
}
$requestData
=
[
"lang"
=>
$lang
,
"urls"
=>
$resultLinks
,
];
$requestData
=
json_encode
(
$requestData
);
$this
->
hash
=
md5
(
$requestData
);
$url
=
"https://direct.metager.de/check"
;
$token
=
env
(
"ADMITAD_TOKEN"
,
""
);
// Submit fetch job to worker
$mission
=
[
"resulthash"
=>
$this
->
hash
,
"url"
=>
$url
,
"useragent"
=>
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0"
,
"username"
=>
null
,
"password"
=>
null
,
"headers"
=>
[
"Authorization"
=>
"Bearer
$token
"
],
"cacheDuration"
=>
60
,
"name"
=>
"Admitad"
,
"curlopts"
=>
[
CURLOPT_POST
=>
true
,
CURLOPT_POSTFIELDS
=>
$requestData
]
];
$mission
=
json_encode
(
$mission
);
Redis
::
rpush
(
\
App\MetaGer
::
FETCHQUEUE_KEY
,
$mission
);
}
/**
* Parses the response from Admitad server and converts all Affiliate Links.
*
* @param \App\Models\Result[] $results
*/
public
function
parseAffiliates
(
&
$results
){
$answer
=
Cache
::
get
(
$this
->
hash
);
$answer
=
json_decode
(
$answer
,
true
);
if
(
empty
(
$answer
)
||
!
isset
(
$answer
[
"error"
])
||
$answer
[
"error"
]
||
!
is_array
(
$answer
[
"result"
])){
return
;
}
foreach
(
$answer
[
"result"
]
as
$linkResult
){
$originalUrl
=
$linkResult
[
"originalUrl"
];
$redirUrl
=
$linkResult
[
"redirUrl"
];
$image
=
$linkResult
[
"image"
];
if
(
empty
(
$redirUrl
)){
// No Partnershop
continue
;
}
foreach
(
$results
as
$result
)
{
if
(
$result
->
originalLink
===
$originalUrl
)
{
# Ein Advertiser gefunden
if
(
$result
->
image
!==
""
)
{
$result
->
logo
=
$image
;
}
else
{
$result
->
image
=
$image
;
}
# Den Link hinzufügen:
$result
->
link
=
$redirUrl
;
$result
->
partnershop
=
true
;
$result
->
changed
=
true
;
}
}
}
Log
::
info
(
"tzewst"
);
}
}
app/Models/Result.php
View file @
6751648b
...
...
@@ -9,6 +9,7 @@ class Result
{
public
$provider
;
# Die Engine von der das Suchergebnis kommt
public
$titel
;
# Der Groß Angezeigte Name für das Suchergebnis
public
$originalLink
;
public
$link
;
# Der Link auf die Ergebnisseite
public
$anzeigeLink
;
# Der tatsächlich angezeigte Link (rein optisch)
public
$descr
;
# Die eventuell gekürzte Beschreibung des Suchergebnisses
...
...
@@ -41,6 +42,7 @@ class Result
$this
->
provider
=
$provider
;
$this
->
titel
=
$this
->
sanitizeText
(
strip_tags
(
trim
(
$titel
)));
$this
->
link
=
trim
(
$link
);
$this
->
originalLink
=
trim
(
$link
);
$this
->
anzeigeLink
=
trim
(
$anzeigeLink
);
$this
->
anzeigeLink
=
preg_replace
(
"/(http[s]
{
0,1}:\/\/){0,1}(www\.){0,1
}
/si"
,
""
,
$this
->
anzeigeLink
);
$this
->
descr
=
$this
->
sanitizeText
(
strip_tags
(
trim
(
$descr
),
'<p>'
));
...
...
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