Skip to content

Instantly share code, notes, and snippets.

@cergey-obr
Created July 11, 2014 06:30
Show Gist options
  • Save cergey-obr/9d03238ce9a89bd8cf33 to your computer and use it in GitHub Desktop.
Save cergey-obr/9d03238ce9a89bd8cf33 to your computer and use it in GitHub Desktop.
Получение превьюшки для видео $id - id видео $field - название поля
public function getYoutubePreview($id, $field) {
$hierarchy = umiHierarchy::getInstance();
$video = $hierarchy->getElement($id);
if ($video instanceof umiHierarchyElement) {
if ($video->$field instanceof umiImageFile) { // если изображение уже записано
return substr($video->$field->getFilePath(), 1);
} else { // если поле пустое
$link = $video->youtube;
if ($youtube_id = $this->getYouTubeIdFromURL($link)) { // получаем изображение с сервера youtube
$photo = $this->getYouTubeImg($youtube_id);
$video->setValue($field, '.'.$photo);
$video->commit();
return $photo;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment