PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/core/library/X/VlcShares/Plugins/Controls.php

http://vlc-shares.googlecode.com/
PHP | 314 lines | 194 code | 49 blank | 71 comment | 18 complexity | 7d5f5a74d5ed0e73e3f48f57774a2784 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. require_once 'X/VlcShares.php';
  3. require_once 'X/VlcShares/Plugins/Abstract.php';
  4. require_once 'Zend/Controller/Action.php';
  5. require_once 'Zend/Config.php';
  6. /**
  7. * Add button to controls page
  8. *
  9. * Configs:
  10. *
  11. * - show Pause/Resume button
  12. * pauseresume.enabled = false
  13. *
  14. * - show Stop button
  15. * stop.enabled = true
  16. *
  17. * - show Forward minutes (type Search) button
  18. * forwardrelative.enabled = false
  19. *
  20. * - show Back minutes (type Search) button
  21. * backrelative.enabled = false
  22. *
  23. * - show Seek button (type Search) button
  24. * seek.enabled = true
  25. *
  26. * - show buttons from the previous version of plugin (+/- 5, 30...)
  27. * oldstylecontrols.enabled = false
  28. *
  29. * @author ximarx
  30. *
  31. */
  32. class X_VlcShares_Plugins_Controls extends X_VlcShares_Plugins_Abstract {
  33. public function __construct() {
  34. $this->setPriority('getControlItems')
  35. ->setPriority('execute')
  36. ->setPriority('getIndexManageLinks')
  37. ->setPriority('getStreamItems');
  38. }
  39. /**
  40. * Add pause/resume, stop, forward, rewind, shift buttons
  41. * @param X_Streamer_Engine $engine streamer engine
  42. * @param Zend_Controller_Action $controller the controller who handle the request
  43. * @return X_Page_ItemList_PItem
  44. */
  45. public function getControlItems(X_Streamer_Engine $engine, Zend_Controller_Action $controller) {
  46. $urlHelper = $controller->getHelper('url');
  47. $return = new X_Page_ItemList_PItem();
  48. if ( $this->config('stop.enabled', true)) {
  49. // stop
  50. $item = new X_Page_Item_PItem('controls-stop', X_Env::_('p_controls_stop'));
  51. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  52. ->setIcon('/images/icons/stop.png')
  53. ->setLink(array(
  54. 'controller' => 'controls',
  55. 'action' => 'execute',
  56. 'a' => 'stop',
  57. 'pid' => $this->getId(),
  58. ), 'default', false);
  59. $return->append($item);
  60. }
  61. if ( $engine instanceof X_Streamer_Engine_Vlc ) {
  62. if ( $this->config('pauseresume.enabled', false)) {
  63. // pause/resume
  64. $item = new X_Page_Item_PItem('controls-pauseresume', X_Env::_('p_controls_pauseresume'));
  65. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  66. ->setIcon('/images/icons/pause.png')
  67. ->setLink(array(
  68. 'controller' => 'controls',
  69. 'action' => 'execute',
  70. 'a' => 'pause',
  71. 'pid' => $this->getId(),
  72. ), 'default', false);
  73. $return->append($item);
  74. }
  75. if ( $this->config('forwardrelative.enabled', false)) {
  76. // forward relative
  77. $item = new X_Page_Item_PItem('controls-forwardcustom', X_Env::_('p_controls_forwardcustom'));
  78. $item->setType(X_Page_Item_PItem::TYPE_REQUEST)
  79. ->setIcon('/images/icons/forward.png')
  80. ->setDescription(X_Env::_('p_controls_forwardcustom_desc'))
  81. ->setLink(array(
  82. 'controller' => 'controls',
  83. 'action' => 'execute',
  84. 'a' => 'forward',
  85. 'pid' => $this->getId(),
  86. 'param' => '' // this will replaced by wiimc....
  87. ), 'default', false);
  88. $return->append($item);
  89. }
  90. if ( $this->config('backrelative.enabled', false)) {
  91. // rewind relative
  92. $item = new X_Page_Item_PItem('controls-backcustom', X_Env::_('p_controls_backcustom'));
  93. $item->setType(X_Page_Item_PItem::TYPE_REQUEST)
  94. ->setIcon('/images/icons/back.png')
  95. ->setDescription(X_Env::_('p_controls_backcustom_desc'))
  96. ->setLink(array(
  97. 'controller' => 'controls',
  98. 'action' => 'execute',
  99. 'a' => 'back',
  100. 'pid' => $this->getId(),
  101. 'param' => '' // this will replaced by wiimc....
  102. ), 'default', false);
  103. $return->append($item);
  104. }
  105. if ( $this->config('seek.enabled', true)) {
  106. // seek to time
  107. $item = new X_Page_Item_PItem('controls-seek', X_Env::_('p_controls_seektominute'));
  108. $item->setType(X_Page_Item_PItem::TYPE_REQUEST)
  109. ->setIcon('/images/icons/seek.png')
  110. ->setDescription(X_Env::_('p_controls_seektominute_desc'))
  111. ->setLink(array(
  112. 'controller' => 'controls',
  113. 'action' => 'execute',
  114. 'a' => 'seek',
  115. 'pid' => $this->getId(),
  116. 'param' => '' // this will replaced by wiimc....
  117. ), 'default', false);
  118. $return->append($item);
  119. }
  120. if ( $this->config('oldstylecontrols.enabled', false) ) {
  121. $item = new X_Page_Item_PItem('controls-back5', X_Env::_('p_controls_back_5'));
  122. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  123. ->setIcon('/images/icons/back.png')
  124. ->setLink(array(
  125. 'controller' => 'controls',
  126. 'action' => 'execute',
  127. 'a' => 'back',
  128. 'pid' => $this->getId(),
  129. 'param' => '5' // this will replaced by wiimc....
  130. ), 'default', false);
  131. $return->append($item);
  132. $item = new X_Page_Item_PItem('controls-forward5', X_Env::_('p_controls_forward_5'));
  133. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  134. ->setIcon('/images/icons/forward.png')
  135. ->setLink(array(
  136. 'controller' => 'controls',
  137. 'action' => 'execute',
  138. 'a' => 'forward',
  139. 'pid' => $this->getId(),
  140. 'param' => '5' // this will replaced by wiimc....
  141. ), 'default', false);
  142. $return->append($item);
  143. $item = new X_Page_Item_PItem('controls-back30', X_Env::_('p_controls_back_30'));
  144. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  145. ->setIcon('/images/icons/back.png')
  146. ->setLink(array(
  147. 'controller' => 'controls',
  148. 'action' => 'execute',
  149. 'a' => 'back',
  150. 'pid' => $this->getId(),
  151. 'param' => '30' // this will replaced by wiimc....
  152. ), 'default', false);
  153. $return->append($item);
  154. $item = new X_Page_Item_PItem('controls-forward30', X_Env::_('p_controls_forward_30'));
  155. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  156. ->setIcon('/images/icons/forward.png')
  157. ->setLink(array(
  158. 'controller' => 'controls',
  159. 'action' => 'execute',
  160. 'a' => 'forward',
  161. 'pid' => $this->getId(),
  162. 'param' => '30' // this will replaced by wiimc....
  163. ), 'default', false);
  164. $return->append($item);
  165. }
  166. }
  167. return $return;
  168. }
  169. /**
  170. * Execute the action
  171. *
  172. * @param X_Streamer_Engine $vlc
  173. * @param string $pid
  174. * @param string $action
  175. * @param Zend_Controller_Action $controller the controller who handle the request
  176. */
  177. public function execute(X_Streamer_Engine $engine, $pid, $action, Zend_Controller_Action $controller) {
  178. // the trigger isn't for this plugin
  179. if ( $this->getId() != $pid ) return;
  180. X_Debug::i("Plugin triggered for action {$action}");
  181. $param = $controller->getRequest()->getParam('param', null);
  182. if ( method_exists($this, "_action_$action") ) {
  183. $method = "_action_$action";
  184. if ( $action === 'stop' ) {
  185. $this->$method($engine, $param);
  186. } else {
  187. if ( $engine instanceof X_Streamer_Engine_Vlc ) {
  188. $this->$method($engine->getVlcWrapper(), $param);
  189. }
  190. }
  191. } else {
  192. X_Debug::e("Invalid action $action");
  193. }
  194. }
  195. /**
  196. * Add the link for -manage-output-
  197. * @param Zend_Controller_Action $this
  198. * @return array The format of the array should be:
  199. * array(
  200. * array(
  201. * 'title' => ITEM TITLE,
  202. * 'label' => ITEM LABEL,
  203. * 'link' => HREF,
  204. * 'highlight' => true|false,
  205. * 'icon' => ICON_HREF,
  206. * 'subinfos' => array(INFO, INFO, INFO)
  207. * ), ...
  208. * )
  209. */
  210. public function getIndexManageLinks(Zend_Controller_Action $controller) {
  211. $link = new X_Page_Item_ManageLink($this->getId(), X_Env::_('p_controls_mlink'));
  212. $link->setTitle(X_Env::_('p_controls_managetitle'))
  213. ->setIcon('/images/icons/controls.png')
  214. ->setLink(array(
  215. 'controller' => 'config',
  216. 'action' => 'index',
  217. 'key' => 'controls'
  218. ), 'default', true);
  219. return new X_Page_ItemList_ManageLink(array($link));
  220. }
  221. /**
  222. * Add the go-to-control-page
  223. *
  224. * @param X_Streamer_Engine $engine selected streamer engine
  225. * @param string $uri
  226. * @param string $provider id of the plugin that should handle request
  227. * @param string $location to stream
  228. * @param Zend_Controller_Action $controller the controller who handle the request
  229. * @return X_Page_ItemList_PItem
  230. */
  231. public function getStreamItems(X_Streamer_Engine $engine, $uri, $provider, $location, Zend_Controller_Action $controller) {
  232. $urlHelper = $controller->getHelper('url');
  233. $item = new X_Page_Item_PItem($this->getId(), X_Env::_('p_controls_gotocontrols'));
  234. $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  235. ->setIcon('/images/icons/controls.png')
  236. ->setLink(array(
  237. 'controller' => 'controls',
  238. 'action' => 'control',
  239. ), 'default', false);
  240. return new X_Page_ItemList_PItem(array($item));
  241. }
  242. private function _action_stop(X_Streamer_Engine $engine, $param) {
  243. X_Streamer::i()->stop();
  244. }
  245. private function _action_seek(X_Vlc $vlc, $param) {
  246. $time = ((int) $param) * 60;
  247. $totalTime = $vlc->getTotalTime();
  248. if ( $time >= 0 && $time <= $totalTime) {
  249. $vlc->seek($time);
  250. } else {
  251. X_Debug::w("Time value out of range: $time vs $totalTime");
  252. }
  253. }
  254. private function _action_forward(X_Vlc $vlc, $param) {
  255. $time = ((int) $param) * 60;
  256. $vlc->seek($time, true);
  257. }
  258. private function _action_back(X_Vlc $vlc, $param) {
  259. $time = abs(((int) $param) * 60) * -1;
  260. $vlc->seek($time, true);
  261. }
  262. private function _action_pause(X_Vlc $vlc, $param) {
  263. $vlc->pause();
  264. }
  265. }