videolist.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * @return array
  4. */
  5. function videolist_get_default_platforms() {
  6. static $platforms = array();
  7. if (! $platforms) {
  8. require dirname(__FILE__) . '/Videolist/PlatformInterface.php';
  9. $path = dirname(__FILE__) . '/Videolist/Platform';
  10. foreach (scandir($path) as $filename) {
  11. if (preg_match('/^(\\w+)\\.php$/', $filename, $m)) {
  12. require "$path/$filename";
  13. $class = 'Videolist_Platform_' . $m[1];
  14. $platform = new $class();
  15. if ($platform instanceof Videolist_PlatformInterface) {
  16. /* @var Videolist_PlatformInterface $platform */
  17. $platforms[$platform->getType()][] = $platform;
  18. }
  19. }
  20. }
  21. }
  22. return $platforms;
  23. }
  24. /**
  25. * @param string $url
  26. * @return array [parsed, platform]
  27. */
  28. function videolist_parse_url($url) {
  29. $params = array(
  30. 'url' => $url,
  31. );
  32. $platforms = videolist_get_default_platforms();
  33. $platforms = elgg_trigger_plugin_hook('videolist:prepare', 'platforms', $params, $platforms);
  34. foreach ($platforms as $list) {
  35. foreach ($list as $platform) {
  36. /* @var Videolist_PlatformInterface $platform */
  37. $parsed = $platform->parseUrl($url);
  38. if ($parsed) {
  39. return array($parsed, $platform);
  40. }
  41. }
  42. }
  43. return false;
  44. }