Hello, everyone.
I developed a small plugin for a client who’s still on PHP 7.0 and the IT person is being difficult about upgrading to PHP 7.4 want to upgrade.
I have a small Vimeo script that reads out a supplied URL and then returns the parameters (video title, link and thumbnail). It’s not working on the live site, here is my snippet:
<?php
// get fields
$video_url = get_field('vimeo_url'); // example using ACF (works similar)
$url_pieces = explode('/', $video_url);
?>
<?php if( preg_match('/https:\/\/(www\.)*vimeo\.com\/.*/', $video_url) ) { ?>
<?php
// vimeo
$id = $url_pieces[3];
$hash = unserialize( file_get_contents('http://vimeo.com/api/v2/video/' . $id . '.php') );
// this is for testing --- included dump below
echo '<pre>';
var_dump($hash);
echo '</pre>';
$thumbnail = $hash[0]['thumbnail_large'];
?>
<div class="col-sm-3">
<a class="videos-list--item popup-vimeo" href="<?php echo $video_url ?>" style="background-image:url('<?php echo $thumbnail; ?>');" data-lity >
<p class="video-title"><?php the_title(); ?></p>
</a>
</div>
<?php } ?>
And then this is an example of the var dump output generated by the var_dump in the snippet above:
array(1) {
[0]=>
array(23) {
["id"]=>
int(297401184)
["title"]=>
string(13) "Face and Body"
["description"]=>
string(0) ""
["url"]=>
string(27) "https://vimeo.com/297401184"
["upload_date"]=>
string(19) "2018-10-26 17:27:48"
["thumbnail_small"]=>
string(48) "http://i.vimeocdn.com/video/735070657_100x75.jpg"
["thumbnail_medium"]=>
string(49) "http://i.vimeocdn.com/video/735070657_200x150.jpg"
["thumbnail_large"]=>
string(45) "http://i.vimeocdn.com/video/735070657_640.jpg"
["user_id"]=>
int(47140717)
["user_name"]=>
string(27) "Motion Analysis Corporation"
["user_url"]=>
string(32) "https://vimeo.com/motionanalysis"
["user_portrait_small"]=>
string(45) "http://i.vimeocdn.com/portrait/32378470_30x30"
["user_portrait_medium"]=>
string(45) "http://i.vimeocdn.com/portrait/32378470_75x75"
["user_portrait_large"]=>
string(47) "http://i.vimeocdn.com/portrait/32378470_100x100"
["user_portrait_huge"]=>
string(47) "http://i.vimeocdn.com/portrait/32378470_300x300"
["stats_number_of_likes"]=>
int(0)
["stats_number_of_plays"]=>
int(26)
["stats_number_of_comments"]=>
int(0)
["duration"]=>
int(45)
["width"]=>
int(1280)
["height"]=>
int(720)
["tags"]=>
string(9) "Animation"
["embed_privacy"]=>
string(8) "anywhere"
}
}
Have you checked the error log?
I jut did. Nothing is showing. The HTML simply doesn’t display the background image:
<a class="videos-list--item popup-vimeo" href="https://vimeo.com/312001166" style="background-image:url('');" data-lity=""><p class="video-title">Behind the Scenes – Titanfall 2</p>
</a>
I adjusted the script slightly and the same issue.
<?php foreach ($hash as $h) { ?>
<?php $thumbnail = $h['thumbnail_large']; ?>
<div class="col-sm-3">
<a class="videos-list--item popup-vimeo" href="<?php echo $video_url ?>" style="background-image:url('<?php echo $thumbnail; ?>');" data-lity >
<p class="video-title"><?php the_title(); ?></p>
</a>
</div>
I just want to confirm that it can be resolved by upgrading to PHP 7.4?
Is that a statement or a question?
Is this a WordPress site?
It’s a WordPress site. I think I’m going to conclude that they need to update their PHP version. I personally cannot be bothering you with unsupported system.
Thank you for your assistance.
1 Like
I’m sorry no one more knowledgeable had any suggestions, but yes, as you say PHP 7.0 is no longer supported - support stopped 1 Jan 2018, and security fixes ended 1 Jan 2019. PHP 8 will be out by the end of the year.
Can you test the following script using PHP 7.0?
<?php DECLARE(STRICT_TYPES=1);
// REMOVE WHEN ONLINE
error_reporting(-1);
ini_set('display_errors', 'true');
$id = "https://vimeo.com/297401184";
$id = 'https://vimeo.com/312001166';
function the_title( array $hash = [] )
{
return '';
}
// get fields
$video_url = $id; // get_field('vimeo_url'); // example using ACF (works similar)
$url_pieces = explode('/', $video_url);
if( preg_match('/https:\/\/(www\.)*vimeo\.com\/.*/', $video_url) )
{
$id = $url_pieces[3];
$hash = unserialize( file_get_contents('http://vimeo.com/api/v2/video/' . $id . '.php') );
$thumbnail = $hash[0]['thumbnail_large'];
}
?>
<!doctype html><html lang="en">
<head>
<title> title goes here </title>
</head>
<body>
<h1> Title: <?= $id; ?> </h1>
<h2> Thumb: <?= $thumbnail; ?> </h2>
<div style='display: none'>
</div>
<div>
<a
class="videos-list--item popup-vimeo"
href="https://vimeo.com/312001166"
style="
width: 320px; height: auto;
display: inline-block;
min-width:320px; min-height:180px;
padding: 0em;
background-color: red;
background-image:url('<?= $thumbnail; ?>');"
data-lity=""
>
<div class="video-title">
Behind the Scenes – Titanfall 2
</div>
</a>
</div>
<p> <br><br> SPACER <br><br> </p>
<div class="col-sm-3">
<a
class="videos-list--item popup-vimeo"
href="<?php echo $video_url ?>"
style="
display: inline-block;
min-width:640px; min-height:360px;
padding: 0em;
background-color: green;
background-image:url('<?php echo $thumbnail; ?>');
"
data-lity
>
</a>
<p class="video-title">
<?php $hash[0]['title'] # the_title(); ?>
</p>
</div>
<?php echo '<pre>'; var_dump($hash); echo '</pre>';
?>
</body></html>
1 Like
They finally updated to PHP 7.4 and allowed “allow_url_fopen”.
I was also able to view the errors today.
Thank you gents.
2 Likes
system
Closed
October 29, 2020, 5:00pm
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.