Skip to content

Instantly share code, notes, and snippets.

@ddavaham
Created April 8, 2018 16:50
Show Gist options
  • Save ddavaham/29e13e115fe541e0fe7a3ebf797a6313 to your computer and use it in GitHub Desktop.
Save ddavaham/29e13e115fe541e0fe7a3ebf797a6313 to your computer and use it in GitHub Desktop.
$tidy = tidy_parse_string($testString, [
'doctype' => "omit",
'show-body-only' => true
]);
$dom->loadHtml($tidy->value, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
foreach ($dom->getElementsByTagName('font') as $anchor) {
if ($anchor->hasAttribute('size')) {
$anchor->removeAttribute('size');
}
if ($anchor->hasAttribute('color')) {
$anchor->removeAttribute('color');
}
}
$domAnchors = $dom->getElementsByTagName('a');
foreach ($domAnchors as $anchor) {
$href = explode(':', $anchor->getAttribute('href'));
if (!in_array($href[0], ['showinfo', 'fitting', 'killReport'])) {
continue;
}
$type = $href[0];
$anchor->setAttribute('target', "_blank");
if ($type === "showinfo") {
$target = $href[1];
$target = explode("//", $href[1]);
$targetType = (int)$target[0];
$targetId = (int)$target[1];
if ($targetType == 3) {
$info = Region::find($targetId);
if (is_null($info)) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "region/{$targetId}");
} else {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.dotlanUrl'). "map/". $info->nameDotlanFormat());
}
continue;
}
if ($targetType == 4) {
$info = Constellation::find($targetId);
if (is_null($info)) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "/constellation/{$targetId}");
} else {
$info->load('region');
$anchor->setAttribute('href', config('base.dotlanUrl'). "map/". $info->region->nameDotlanFormat() . "/{$info->name}");
}
continue;
}
if ($targetType == 5) {
$info = $this->dataCont->getSystem($targetId);
$status = $info->status;
$payload = $info->payload;
if (!$status) {
if ($payload->code >= 400 && $payload->code < 500) {
activity(__METHOD__)->withProperties($payload)->log($payload->message);
}
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "system/{$targetId}");
} else {
$payload->load('constellation.region');
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.dotlanUrl'). "map/". $payload->constellation->region->nameDotlanFormat()."/".$payload->name);
}
continue;
}
$targetTypeData = $this->dataCont->getType($targetType);
$status = $targetTypeData->status;
$payload = $targetTypeData->payload;
if (!$status) {
continue;
}
$targetGroup = $payload->group_id;
if ($targetGroup == 1) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "character/{$targetId}/");
continue;
}
if ($targetGroup == 2) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "corporation/{$targetId}/");
continue;
}
if ($targetGroup == 15) {
$station = $this->dataCont->getStation($targetId);
$status = $station->status;
$payload = $station->payload;
if (!$status) {
if ($payload->code >= 400 && $payload->code < 500) {
activity(__METHOD__)->withProperties($payload)->log($payload->message);
}
continue;
}
if (in_array($targetType, [21646,21644,21642,21645])) {
$payload->load('system');
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.dotlanUrl'). "outpost/". $payload->system->name);
} else {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.dotlanUrl'). "station/". $payload->nameDotlanFormat());
}
continue;
}
if ($targetGroup == 19) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "faction/{$targetId}/");
continue;
}
if ($targetGroup == 32) {
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl'). "alliance/{$targetId}/");
continue;
}
}
if ($type === "killReport") {
$killId = $href[1];
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.kmUrl')."kill/{$killId}/");
continue;
}
if ($type === "fitting") {
unset($href[0]);
$dna = implode(':', $href);
$anchor->removeAttribute('href');
$anchor->setAttribute('href', config('base.osmiumUrl') . "loadout/dna/{$dna}");
continue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment