123movies-seo/app/Supports/Markup.php

152 lines
4.8 KiB
PHP

<?php
namespace App\Supports;
use Spatie\SchemaOrg\Movie;
use Spatie\SchemaOrg\Schema;
class Markup {
protected static function MinutesToDuration($s) {
$days = floor($s / 1440);
$s = $s - $days * 1440;
$hours = floor($s / 60);
$s = $s - $hours * 60;
$dur = "PT";
if ($days > 0) {$dur .= $days . "D";}
if ($hours > 0) {$dur .= $hours . "H";}
$dur .= $s . "M";
return $dur;
}
public static function getMovieMarkupData($mov) {
$movie = Schema::movie()
->name($mov->title)
->description($mov->title.' - '.$mov->overview)
->image(img_url('w300', $mov->poster_path, true ))
->url(item($mov)->link)
->duration(self::MinutesToDuration($mov->runtime))
->genre(collect($mov->genres)->pluck('name')->all())
->keywords(collect($mov->keywords->keywords)->implode('name', ','))
->datePublished($mov->release_date);
if (isset($mov->vote_average)) {
$rating = Schema::aggregateRating()
->bestRating(10)
->worstRating(1)
->ratingValue($mov->vote_average)
->ratingCount($mov->vote_count)
->ratingExplanation('Community Rating');
$movie->aggregateRating($rating);
}
$actors = [];
foreach( collect($mov->credits->cast)->take(5) as $cast) {
$actors[]=Schema::person()->name($cast->name)->image(img_url('w185', $cast->profile_path));
}
$movie->actor($actors);
$directors = [];
foreach( collect($mov->credits->crew)->filter(function($value, $key){ return $value->job === 'Director';}) as $cast) {
$directors[]=Schema::person()->name($cast->name);
}
$movie->director($directors);
return $movie->toScript();
}
}
// function dd($v) {
// var_dump($v);
// exit;
// }
function getTvMarkupData($mov) {
// dd($mov);
// dd($mov['keywords']);
if (isset($mov->vote_average)) {
$rating = Schema::aggregateRating()
->bestRating(10)
->worstRating(1)
->ratingValue($mov->vote_average)
->ratingCount($mov->vote_count)
->ratingExplanation('Community Rating');
}
$movie = Schema::tVSeries()
->name($mov->name)
->description($mov->name.' - '.$mov->overview)
->image(img_url('w300', $mov->poster_path, true ))
->url(item($mov)->link)
// ->duration(MinutesToDuration($mov['episode_run_time'][0]))
->genre(collect($mov->genres)->pluck('name')->toArray())
->keywords(collect($mov->keywords->results)->implode('name', ','))
->datePublished($mov->first_air_date)
->numberOfEpisodes($mov->number_of_episodes)
->numberOfSeasons($mov->number_of_seasons)
;
if (isset($rating)) {
$movie->aggregateRating($rating);
}
$actors = [];
foreach( collect($mov->credits->cast)->take(5) as $cast) {
$actors[]=Schema::person()->name($cast->name)->image(img_url('w185', $cast->profile_path));
}
$movie->actor($actors);
$directors = [];
foreach( collect($mov->credits->crew)->filter(function($value, $key){ return $value->job === 'Producer' || $value->job === 'Executive Producer';})->take(5) as $cast) {
$directors[]=Schema::person()->name($cast->name);
}
$movie->creator($directors);
return $movie->toScript();
}
function getTvSeasonMarkupData($mov) {
// dd($mov);
// dd($mov['keywords']);
$rating = Schema::aggregateRating()
->bestRating(10)
->worstRating(1)
->ratingValue($mov['vote_average'])
->ratingCount($mov['vote_count'])
->ratingExplanation('Community Rating');
$movie = Schema::tVSeries()
->name($mov->name)
->description($mov->name.' - '.$mov['overview'])
->image(img_url('w300', $mov['poster_path'], true ))
->url(build_permalink('tv/' . $mov['id'] .'/' .str_slug($mov->name)))
// ->duration(MinutesToDuration($mov['episode_run_time'][0]))
->aggregateRating($rating)
->genre(collect($mov['genres'])->pluck('name')->toArray())
->keywords(collect($mov['keywords']['results'])->implode('name', ','))
->datePublished($mov['first_air_date'])
->numberOfEpisodes($mov['number_of_episodes'])
->numberOfSeasons($mov['number_of_seasons'])
;
$actors = [];
foreach( collect($mov['credits']['cast'])->take(5) as $cast) {
$actors[]=Schema::person()->name($cast['name'])->url(build_permalink('people/'.str_slug($cast['name']).'/'.$cast['id']))->image(img_url('w185', $cast['profile_path']));
}
$movie->actor($actors);
$directors = [];
foreach( collect($mov['credits']['crew'])->filter(function($value, $key){ return $value['job'] === 'Producer' || $value['job'] === 'Executive Producer';})->take(5) as $cast) {
$directors[]=Schema::person()->name($cast['name']);
}
$movie->creator($directors);
return $movie->toScript();
}