SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Widgets/AudioWidget.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\File;
  17. use Sprout\Helpers\FileConstants;
  18. use Sprout\Helpers\Form;
  19. use Sprout\Helpers\View;
  20.  
  21.  
  22. /**
  23. * Basically just a test widget
  24. **/
  25. class AudioWidget extends Widget
  26. {
  27. protected $friendly_name = "Audio player";
  28. protected $friendly_desc = "Places an audio player on the page";
  29.  
  30.  
  31. /**
  32.   * Return the front-end view of this widget
  33.   *
  34.   * @param int $orientation The orientation of the widget.
  35.   **/
  36. public function render($orientation)
  37. {
  38. $this->settings['filename'] = trim($this->settings['filename']);
  39. if ($this->settings['filename'] == '') return;
  40.  
  41. $view = new View('sprout/audio_player');
  42. $view->filename = File::url($this->settings['filename']);
  43.  
  44. return $view->render();
  45. }
  46.  
  47.  
  48. /**
  49.   * Return the settings form for this widget
  50.   **/
  51. public function getSettingsForm()
  52. {
  53. Form::nextFieldDetails('Audio file', true);
  54. return Form::fileselector('filename', [], ['filter' => FileConstants::TYPE_SOUND, 'required' => true]);
  55. }
  56.  
  57. }
  58.