EU

);
}

/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// outputs the content of the widget
//
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( ‘widget_title’, empty( $instance[‘title’] ) ? » : $instance[‘title’], $instance, $this->id_base );

echo $args[‘before_widget’];
if ( $title ) {
echo $args[‘before_title’] . $title . $args[‘after_title’];
}

?>


$title = sanitize_text_field( $instance[‘title’] );
?>



$data[$key] = $value;
}
}
//echo json_encode($data);
if (isset($data[‘Generelt’][‘Neste frist for godkjent EU-kontroll’]) && false) {
$message = $data[‘Generelt’][‘Neste frist for godkjent EU-kontroll’];
} else {
header($_SERVER[‘SERVER_PROTOCOL’].’ 502 Bad Gateway’);
$message = __(‘Vi har problemer med å nå vegvesen.no
Du kan sjekke manuelt her: ‘);
$message .= ‘vegvesen.no‘;
}
} else {
header($_SERVER[‘SERVER_PROTOCOL’].’ 400 Bad Request’);
}

wp_send_json($message);
}

function getUpstreamUrl( $registreringsnummer ) {
return UPSTREAM_URL_BASE . $registreringsnummer;
}

function getDocument( $registreringsnummer ) {
$document = new DOMDocument();

$url = getUpstreamUrl($registreringsnummer);

$document->loadHTMLFile($url);

return $document;
}

function getTables( $document ) {
return getElementsByClassName($document, TABLES_CLASS);
}

function processTable( $table ) {
$arr = array();
$header = trim(getElementsByClassName($table, HEADER_CLASS)->item(0)->textContent);

foreach ($table->getElementsByTagName(‘tr’) as $entry) {
$key = trim($entry->getElementsByTagName(‘th’)->item(0)->textContent);
$value = trim($entry->getElementsByTagName(‘td’)->item(0)->textContent);
$arr[$key] = $value;
}

return array($header => $arr);
}

/* helper functions */
function getElementsByClassName( $dom, $className ) {
switch ( get_class($dom) ) {
case ‘DOMDocument’:
$document = $dom;
$contextNode = null;
break;
case ‘DOMElement’:
$document = $dom->ownerDocument;
$contextNode = $dom;
break;
}

/* ~https://stackoverflow.com/a/6366390 */
$finder = new DOMXPath($document);
$nodes = $finder->query(«.//*[contains(concat(‘ ‘, normalize-space(@class), ‘ ‘), ‘ » . $className . «‘)]», $contextNode);
return $nodes;

return false;
}