2018-08-31 18:50:29 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Parses post markup in order to use specified spee.ch url for assets
|
|
|
|
*
|
|
|
|
* @package LBRYPress
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LBRY_Speech_Parser
|
|
|
|
{
|
2018-10-28 13:21:22 -05:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-24 13:49:46 -05:00
|
|
|
|
2018-10-28 13:21:22 -05:00
|
|
|
public function speech_image_srcset($sources, $size_array, $image_src, $image_meta, $attachment_id)
|
2018-10-24 13:49:46 -05:00
|
|
|
{
|
2018-10-28 13:21:22 -05:00
|
|
|
$time_start = microtime(true);
|
|
|
|
|
|
|
|
$new_sources = $sources;
|
|
|
|
$sizes = $image_meta['sizes'];
|
|
|
|
|
|
|
|
foreach ($sources as $width => $source) {
|
|
|
|
$speech_url = $this->find_speech_url($sizes, $width);
|
|
|
|
|
|
|
|
if ($speech_url) {
|
|
|
|
$new_sources[$width]['url'] = $speech_url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$time_end = microtime(true);
|
|
|
|
|
|
|
|
$time = ($time_end - $time_start) * 1000;
|
|
|
|
error_log("srcset in $time milliseconds");
|
|
|
|
return $new_sources;
|
2018-10-24 13:49:46 -05:00
|
|
|
}
|
|
|
|
|
2018-10-28 13:21:22 -05:00
|
|
|
private function find_speech_url($sizes, $width)
|
2018-08-31 18:50:29 -05:00
|
|
|
{
|
2018-10-28 13:21:22 -05:00
|
|
|
foreach ($sizes as $key => $size) {
|
|
|
|
if ($size['width'] == $width && key_exists('speech_asset_url', $size)) {
|
|
|
|
return $size['speech_asset_url'];
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 19:34:11 -05:00
|
|
|
|
2018-10-28 13:21:22 -05:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-13 19:34:11 -05:00
|
|
|
|
2018-10-28 13:21:22 -05:00
|
|
|
public function microtime_float()
|
|
|
|
{
|
|
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
|
|
return ((float)$usec + (float)$sec);
|
2018-08-31 18:50:29 -05:00
|
|
|
}
|
|
|
|
}
|