Created
November 6, 2018 00:26
-
-
Save ru2fac/a713cdcaa7915f543bbe350546641dbe to your computer and use it in GitHub Desktop.
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
<?php | |
if ($mode == 'new') { | |
if (strpos(trim($resource->pagetitle), ' ') === false) { | |
$url = 'https://www.youtube.com/watch?v=' . $resource->pagetitle; | |
$html = file_get_contents($url); | |
$dom = new DomDocument(); | |
$dom->loadHTML('<?xml version="1.0" encoding="UTF-8"?>'. $html); | |
if ($title = $dom->getElementById('eow-title')) { | |
$modx->log(1, $resource->pagetitle); | |
$video_id = $resource->pagetitle; | |
$resource->set('pagetitle', $title->nodeValue); | |
$resource->set('template', 18); | |
$resource->setTVValue('video', $video_id); | |
$resource->save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Теперь, чтобы добавить видео на сайт, создаём новый ресурс, в заголовок которого вставляем ID видео с Youtube. Плагин вытащит название этого видео, а ID сохранит в соответствующем ТВ.
Взято тут: https://ilyaut.ru/cheats/getting-the-title-of-a-youtube-video/