SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Widgets/VideoWidget.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Widgets;
  15.  
  16. use Sprout\Helpers\EmbedVideo;
  17. use Sprout\Helpers\Form;
  18.  
  19.  
  20. /**
  21. * Basically just a test widget
  22. **/
  23. class VideoWidget extends Widget
  24. {
  25. protected $friendly_name = "Video player";
  26. protected $friendly_desc = 'A video player for videos hosted on YouTube or Vimeo';
  27. protected $default_settings = [
  28. 'width' => 600,
  29. 'height' => 340,
  30. ];
  31.  
  32.  
  33. /**
  34.   * Set values for any missing settings fields
  35.   **/
  36. public function cleanupSettings()
  37. {
  38. if (!isset($this->settings['video_id'])) $this->settings['video_id'] = '';
  39. if (!isset($this->settings['title'])) $this->settings['title'] = '';
  40. if (!isset($this->settings['width'])) $this->settings['width'] = 600;
  41. if (!isset($this->settings['height'])) $this->settings['height'] = 340;
  42. }
  43.  
  44.  
  45. /**
  46.   * Return the front-end view of this widget
  47.   *
  48.   * @param int $orientation The orientation of the widget.
  49.   **/
  50. public function render($orientation)
  51. {
  52. $options = array(
  53. 'title' => $this->settings['title'],
  54. );
  55.  
  56. return EmbedVideo::renderEmbed(
  57. $this->settings['video_id'],
  58. $this->settings['width'],
  59. $this->settings['height'],
  60. $options
  61. );
  62. }
  63.  
  64.  
  65. /**
  66.   * Return the settings form for this widget
  67.   **/
  68. public function getSettingsForm()
  69. {
  70. $out = '';
  71.  
  72. Form::nextFieldDetails('Video URL', true);
  73. $out .= Form::text('video_id');
  74.  
  75. Form::nextFieldDetails('Video title', true);
  76. $out .= Form::text('title');
  77.  
  78. Form::nextFieldDetails('Width', true);
  79. $out .= Form::text('width');
  80.  
  81. Form::nextFieldDetails('Height', true);
  82. $out .= Form::text('height');
  83.  
  84. return $out;
  85. }
  86.  
  87. }
  88.