Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 278 additions & 68 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/PhpAlly.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public function checkMany($content, $ruleIds = [], $options = [])

foreach ($ruleIds as $ruleId) {
try {
$className = $ruleId;
$className = str_replace(
['VideosEmbeddedOrLinkedNeedCaptions','VideosHaveAutoGeneratedCaptions','VideoCaptionsMatchCourseLanguage'],
'VideoScan',
$ruleId
);
if (!class_exists($className)) {
$report->setError('Rule does not exist.');
continue;
Expand Down
11 changes: 6 additions & 5 deletions src/Rule/BaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,15 @@ public function elementContainsReadableText($element)
return false;
}

public function setIssue($element, $previewElement = null, $metadata = null)
public function setIssue($element, $ruleId = null, $metadata = null)
{
$ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $this->id());

if (!$previewElement) {
$previewElement = $this->previewElement;
if (!isset($ruleId)) {
$ruleId = $this->id();
}

$ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $ruleId);
$previewElement = $this->previewElement;

if ($element) {
$elementClasses = $element->getAttribute('class');
if ($elementClasses && (strpos($elementClasses, 'phpally-ignore') !== false)) {
Expand Down
60 changes: 0 additions & 60 deletions src/Rule/VideoCaptionsMatchCourseLanguage.php

This file was deleted.

130 changes: 130 additions & 0 deletions src/Rule/VideoScan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace CidiLabs\PhpAlly\Rule;

use DOMElement;
use CidiLabs\PhpAlly;
use CidiLabs\PhpAlly\Video\Vimeo;
use CidiLabs\PhpAlly\Video\Youtube;
use CidiLabs\PhpAlly\Video\Kaltura;
use GuzzleHttp\Client;

/**
*
*/
class VideoScan extends BaseRule
{
const FAIL = 0;
const FAILED_CONNECTION = 1;
const SUCCESS = 2;

public $youtube = null;
public $vimeo = null;
public $kaltura = null;

public function id()
{
return self::class;
}

public function check()
{
foreach ($this->getAllElements(array('a', 'embed', 'iframe', 'script')) as $video) {
$attr = ($video->tagName == 'a') ? 'href' : 'src';
if ($video->hasAttribute($attr)) {
// Get URL
$attr_val = $video->getAttribute($attr);
// Get provider (Youtube, Vimeo, or Kaltura class)
$provider = $this->getVideoProvider($attr_val);
// Get caption data
$captionData = $this->getCaptionData($attr_val, $provider);

if(isset($captionData) && isset($provider)) {
$this->checkCaptionsExist($captionData, $provider, $video);
$this->checkCaptionsLanguage($captionData, $provider, $video);
$this->checkCaptionsAutoGenerated($captionData, $provider, $video);
}
}
}

return count($this->issues);
}

// Scan rule functions

// VideosEmbeddedOrLinkedNeedCaptions
public function checkCaptionsExist($captionData, $provider, $video)
{
// Use provider to call
if (method_exists($provider, 'captionsMissing')) {
$captionState = $provider->captionsMissing($captionData);

if ($captionState != self::SUCCESS) {
$this->setIssue($video, 'VideosEmbeddedOrLinkedNeedCaptions');
}
}
}

// VideoCaptionsMatchCourseLanguage
public function checkCaptionsLanguage($captionData, $provider, $video)
{
// Use provider to call
if (method_exists($provider, 'captionsLanguage')) {
$captionState = $provider->captionsLanguage($captionData);

if ($captionState != self::SUCCESS) {
$this->setIssue($video, 'VideoCaptionsMatchCourseLanguage');
}
}
}

// CaptionsAutoGenerated
public function checkCaptionsAutoGenerated($captionData, $provider, $video)
{
// Use provider to call
if (method_exists($provider, 'captionsAutoGenerated')) {
$captionState = $provider->captionsAutoGenerated($captionData);

if ($captionState != self::SUCCESS) {
$this->setIssue($video, 'VideosHaveAutoGeneratedCaptions');
}
}
}

// Helpers

public function getVideoProvider($url)
{
$search_youtube = '/(youtube|youtu.be)/';
$search_vimeo = '/(vimeo)/';
$search_kaltura = '/(kaltura)/';

if (preg_match($search_youtube, $url)) {
if (!isset($this->youtube)) {
$this->youtube = new Youtube(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['youtubeApiKey']);
}
return $this->youtube;
} elseif (preg_match($search_vimeo, $url)) {
if (!isset($this->vimeo)) {
$this->vimeo = new Vimeo(new \GuzzleHttp\Client(['http_errors' => false]), $this->lang, $this->options['vimeoApiKey']);
}
return $this->vimeo;
} else if (preg_match($search_kaltura, $url)) {
if (!isset($this->kaltura)) {
$this->kaltura = new Kaltura($this->lang, $this->options['kalturaApiKey'], $this->options['kalturaUsername']);
}
return $this->kaltura;
}

return null;
}

public function getCaptionData($url, $provider)
{
if (isset($provider)) {
return $provider->getVideoData($url);
}

return null;
}
}
68 changes: 0 additions & 68 deletions src/Rule/VideosEmbeddedOrLinkedNeedCaptions.php

This file was deleted.

51 changes: 0 additions & 51 deletions src/Rule/VideosHaveAutoGeneratedCaptions.php

This file was deleted.

Loading