Commit 2393a628 authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '1098-add-interface-to-test-adgoal-responses' into 'development'

Resolve "Add interface to test adgoal responses"

Closes #1098

See merge request !1812
parents 4042fb10 be7348c8
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use stdClass;
use Cache;
use Illuminate\Support\Facades\Redis;
class AdgoalTestController extends Controller
{
public function index(Request $request){
return view('admin.adgoal')
->with('title', "Admin Adgoal - MetaGer");
}
public function post(Request $request){
$urls = explode("\r\n", $request->input("urls"));
// Bring it in a form that's similar to metager results
$mgUrls = array();
foreach($urls as $url){
$result = new stdClass();
$result->link = $url;
$result->new = true;
$mgUrls[] = $result;
}
$resultHash = \App\Models\Adgoal::startAdgoal($mgUrls);
Cache::forget($resultHash);
$startTime = microtime(true);
$answer = null;
while (microtime(true) - $startTime < 5) {
$answer = Cache::get($resultHash);
if ($answer === null) {
usleep(50 * 1000);
} else {
break;
}
}
if(!empty($answer)){
$answer = json_decode($answer, true);
$answer = json_encode($answer, JSON_PRETTY_PRINT);
}
return view("admin.adgoal")
->with('title', 'Admin Adgoal - MetaGer')
->with('urls', $request->input("urls"))
->with('answer', $answer);
}
public function generateUrls(Request $request){
$eingabe = $request->input('eingabe');
if(empty($eingabe)){
return redirect('admin/adgoal');
}
$url = route('resultpage', ["eingabe" => $eingabe, "out" => "api", "key" => env("mainz_key")]);
$hash = md5($url);
$mission = [
"resulthash" => $hash,
"url" => $url,
"useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
"username" => null,
"password" => null,
"cacheDuration" => 60,
"name" => "AdgoalGen",
];
$mission = json_encode($mission);
Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
$results = Redis::brpop($hash, 10);
$linklist = array();
if(!empty($results) && is_array($results) && sizeof($results) === 2){
$results = $results[1];
$results = \simplexml_load_string($results);
foreach($results->entry as $entry){
$linklist[] = $entry->link["href"]->__toString();
}
}
return view("admin.adgoal")
->with('title', 'Admin Adgoal - MetaGer')
->with('urls', implode("\r\n", $linklist));
}
}
@extends('layouts.subPages')
@section('title', $title )
@section('content')
<div id="adgoal", class="card-heavy">
<h1>Adgoal Test Interface</h1>
<p>Auf dieser Seite kannst du URLs eingeben, welche bei Adgoal auf Affliate Links überprüft werden sollen.</p>
<p>Eine URL pro Zeile</p>
<form action="{{route("adgoal-generate")}}" method="post">
<textarea name="urls" id="urls" style="width: 100%;" rows="10" >@if(!empty($urls)){{$urls}}@endif</textarea>
<p style="padding-top: 16px;"><input type="submit" value="Generieren"></p>
</form>
</div>
@if(!empty($answer))
<div class="card-heavy">
<h1>Antwort</h1>
<pre style="background-color: black; padding: 8px; color: white; border: 1px solid grey;">
{{$answer}}
</pre>
</div>
@endif
<div class="card-heavy">
<h1>Generate URLs from search query</h1>
<form action="{{route("adgoal-urls")}}" method="post">
<input type="text" name="eingabe" placeholder="Sucheingabe">
<input type="submit" value="OK">
</form>
</div>
@endsection
......@@ -212,6 +212,9 @@ Route::group(
Route::post('service-desk', 'ServiceDesk@webhook');
Route::get('stress', 'Stresstest@index');
Route::get('stress/verify', 'Stresstest@index')->middleware('browserverification', 'humanverification');
Route::get('adgoal', 'AdgoalTestController@index')->name("adgoal-index");
Route::post('adgoal', 'AdgoalTestController@post')->name("adgoal-generate");
Route::post('adgoal/generate-urls', 'AdgoalTestController@generateUrls')->name("adgoal-urls");
});
Route::get('settings', function () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment