If you ever need to fetch information from the Hype WordPress Plugin here you go. Some sample values are in there, but your imaginations can run free with this one:
function preg_match_default($regex, $source, $default = ''){
preg_match($regex, $source, $match);
return $match && $match[1]? $match[1] : $default;
}
function get_hype_infos($hype_upload_id){
global $wpdb;
global $hypeanimations_table_name;
// fetch WP upload directory infos
$upload_dir = wp_upload_dir();
// fetch meta data for Hype upload from DB
$results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$hypeanimations_table_name." WHERE id=%d LIMIT 1",$hype_upload_id));
$result = $results[0];
// vars prepare and construct
$base_url = $upload_dir['baseurl'].'/hypeanimations/'.$hype_upload_id.'/';
$base_dir = esc_url_raw($upload_dir['basedir'].'/hypeanimations/'.$hype_upload_id.'/');
$resource_url = $base_url.$result->nom.'.hyperesources/';
$resource_dir = esc_url_raw($base_dir.$result->nom.'.hyperesources/');
$generated_file = $resource_dir.$result->slug.'_hype_generated_script.js';
$generated_js = file_get_contents($generated_file);
// fetch build from Hype generated file
$build = preg_match_default('/"HYPE_(\d+)/', $generated_js);
$index_file = $base_dir.'index.html';
$index_html = file_get_contents($index_file);
// fetch head from index file
$head_html = preg_match_default('/<!-- copy these lines to your document head: -->([\s\S]*?)<!-- end copy -->/', $index_html);
$body_html = preg_match_default('/<!-- copy these lines to your document: -->([\s\S]*?)<!-- end copy -->/', $index_html);
$meta_viewport = preg_match_default('/(<meta name="viewport"[\s\S]*? \/>)/', $head_html);
// get meta information
preg_match('/style="[\s\S]*?width:(([\d]+)([^;]+));/', $body_html, $match_width);
if ($match_width) {
$width_value = $match_width[1];
$width_number = $match_width[2];
$width_unit = $match_width[3];
}
preg_match('/style="[\s\S]*?height:(([\d]+)([^;]+));/', $body_html, $match_height);
if ($match_height) {
$height_value = $match_height[1];
$height_number = $match_height[2];
$height_unit = $match_height[3];
}
// collect infos and return
return (object) [
'id' => $result->id,
'nom' => $result->nom,
'slug' => $result->slug,
'code' => html_entity_decode($result->code),
'container' => $result->container,
'containerclass' => sanitize_html_class($result->containerclass),
// constructed
'base_url' => $base_url,
'base_dir' => $base_dir,
'resource_url' => $resource_url,
'resource_dir' => $resource_dir,
// fetched
'build' => $build,
'generated_file' => $generated_file,
'generated_js' => $generated_js,
'head_html' => $head_html,
'body_html' => $body_html,
'index_file' => $index_file,
// 'index_html' => $index_html,
'meta_viewport' => $meta_viewport,
'height' => (object) [
'value' => $height_value,
'number' => $height_number,
'unit' => $height_unit,
],
'width' => (object) [
'value' => $width_value,
'number' => $width_number,
'unit' => $width_unit,
],
];
}