-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- HSD8-1340 Clean up files when a media item is deleted (#132) - HSD8-1338 Add twitter embed code validator (#131)
- Loading branch information
Showing
25 changed files
with
315 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Drupal\stanford_media\Plugin\EmbedValidator; | ||
|
||
use Drupal\stanford_media\Plugin\EmbedValidatorBase; | ||
|
||
/** | ||
* Twitter validation. | ||
* | ||
* @EmbedValidator ( | ||
* id = "twitter", | ||
* label = "Twitter" | ||
* ) | ||
*/ | ||
class TwitterValidator extends EmbedValidatorBase { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function isEmbedCodeAllowed(string $code): bool { | ||
$code = self::prepareEmbedCode($code); | ||
return !empty($code); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function prepareEmbedCode(string $code): string { | ||
// Strip out a bunch of stuff we don't care about. | ||
$code = preg_replace("/\r\n|\r|\n/", '', strip_tags($code, '<blockquote> <script> <a> <p>')); | ||
|
||
// The twitter widget script keys off of the class name with twitter- for | ||
// the prefix. Like twitter-tweet, twitter-timline, etc. We need to grab | ||
// the element that has that class and then we will retain everything within | ||
// that element. | ||
preg_match('/<(\w+) .*?class="twitter-(.*?)".*?>/', $code, $twitter_container); | ||
|
||
// There should only be 1 <script> tag with the twitter domain. | ||
preg_match('/<script.*?src="(.*platform\.twitter\.com.*?)".*?>/', $code, $script_matches); | ||
if (!isset($twitter_container[1]) || !isset($script_matches[0])) { | ||
return ''; | ||
} | ||
|
||
// Grab the twitter container that we found earlier. | ||
preg_match('/<' . $twitter_container[1] . '.*?\/' . $twitter_container[1] . '>/', $code, $container); | ||
|
||
// Combine the container with the script element. | ||
return reset($container) . reset($script_matches) . '</script>'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Drupal\stanford_media; | ||
|
||
use Drupal\media\MediaInterface; | ||
|
||
/** | ||
* Interface StanfordMediaInterface. | ||
*/ | ||
interface StanfordMediaInterface { | ||
|
||
/** | ||
* Delete any files associated with this media. | ||
* | ||
* @param \Drupal\media\MediaInterface $media | ||
* Media entity. | ||
*/ | ||
public function deleteMediaFiles(MediaInterface $media):void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.