PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/plugin/tools/ScreenArchive.php

https://gitlab.com/slondon/fortissimo
PHP | 302 lines | 238 code | 55 blank | 9 comment | 13 complexity | e1ee25b4e55ff31bec32632c70947343 MD5 | raw file
  1. <?php
  2. require_once 'lib/abstract_regular_screen.php';
  3. require_once 'tools/Common.php';
  4. require_once 'tools/ScreenNavigator.php';
  5. class NodeAr
  6. {
  7. public $id;
  8. public $path;
  9. public $type;
  10. public $name;
  11. public $children;
  12. public function __construct($id, $path_parent, $type, $name)
  13. {
  14. $this->id = $id;
  15. $this->path = '';
  16. if(strlen($id))
  17. {
  18. if(strlen($path_parent))
  19. $this->path = $path_parent . '/' . $id;
  20. else
  21. $this->path = $id;
  22. }
  23. $this->type = $type;
  24. $this->name = $name;
  25. $this->children = NULL;
  26. }
  27. }
  28. class ScreenArchive extends AbstractRegularScreen implements UserInputHandler
  29. {
  30. const ID = 'archive';
  31. private $_node_storage;
  32. public function __construct()
  33. {
  34. parent::__construct(self::ID, self::get_folder_views());
  35. UserInputHandlerRegistry::get_instance()->register_handler($this);
  36. $this->_node_storage = new NodeAr('', '', 'dir', '');
  37. }
  38. public function get_handler_id()
  39. {
  40. return self::ID;
  41. }
  42. public function get_folder_range(MediaURL $media_url, $from_ndx, &$plugin_cookies)
  43. {
  44. $items = $this->_get_items_list($media_url, $from_ndx, $plugin_cookies);
  45. $count = count($items);
  46. return array
  47. (
  48. PluginRegularFolderRange::total => $count,
  49. PluginRegularFolderRange::more_items_available => false,
  50. PluginRegularFolderRange::from_ndx => $from_ndx,
  51. PluginRegularFolderRange::count => $count,
  52. PluginRegularFolderRange::items => $items
  53. );
  54. }
  55. public function get_action_map(MediaURL $media_url, &$plugin_cookies)
  56. {
  57. $act_item = UserInputHandlerRegistry::create_action($this, 'act_item');
  58. $act_item['caption'] = 'act_item';
  59. $actions = array
  60. (
  61. GUI_EVENT_KEY_ENTER => $act_item,
  62. GUI_EVENT_KEY_C_YELLOW => Common::action_changelog($this),
  63. );
  64. $act_info_green = Common::action_info_green($this);
  65. if(!is_null($act_info_green))
  66. $actions[GUI_EVENT_KEY_B_GREEN] = $act_info_green;
  67. return $actions;
  68. }
  69. public function handle_user_input(&$user_input, &$plugin_cookies)
  70. {
  71. if (isset($user_input->control_id))
  72. {
  73. $control_id = $user_input->control_id;
  74. switch ($control_id)
  75. {
  76. case 'changelog': return Common::get_changelog_dialog();
  77. case 'info_green': return Common::get_info_green_dialog();
  78. case 'act_item':
  79. {
  80. $media_url = MediaUrl::decode($user_input->selected_media_url);
  81. $item_type = $media_url->__get('type');
  82. $act_open_folder = array
  83. (
  84. GuiAction::handler_string_id => PLUGIN_OPEN_FOLDER_ACTION_ID,
  85. GuiAction::data => array
  86. (
  87. 'media_url' => $user_input->selected_media_url
  88. ),
  89. );
  90. $action4item = $act_open_folder;
  91. if($item_type === 'audio')
  92. {
  93. $act_play_item = ActionFactory::vod_play();
  94. $action4item = $act_play_item;
  95. }
  96. return ActionFactory::invalidate_folders(
  97. array
  98. (
  99. $user_input->selected_media_url,
  100. # $user_input->parent_media_url
  101. ),
  102. $action4item);
  103. }
  104. }
  105. }
  106. return ActionFactory::invalidate_folders(array());
  107. }
  108. static function get_folder_views()
  109. {
  110. $view_0 = array
  111. (
  112. PluginRegularFolderView::view_params => array
  113. (
  114. ViewParams::num_cols => 1,
  115. ViewParams::num_rows => 10,
  116. # ViewParams::paint_details => true,
  117. # ViewParams::paint_item_info_in_details => true,
  118. # ViewParams::zoom_detailed_icon => true,
  119. # ViewParams::detailed_icon_scale_factor => 1,
  120. # ViewParams::item_detailed_info_text_color => 23,
  121. # ViewParams::item_detailed_info_auto_line_break => true
  122. ),
  123. PluginRegularFolderView::base_view_item_params => array
  124. (
  125. ViewItemParams::item_paint_icon => true,
  126. ViewItemParams::icon_valign => VALIGN_TOP,
  127. ViewItemParams::item_layout => HALIGN_LEFT,
  128. ViewItemParams::icon_dx => 20,
  129. ViewItemParams::icon_sel_dx => 10,
  130. ViewItemParams::icon_keep_aspect_ratio => true,
  131. ViewItemParams::icon_scale_factor => 0.8,
  132. ViewItemParams::icon_sel_scale_factor => 1,
  133. ViewItemParams::item_caption_dx => 80,
  134. ),
  135. PluginRegularFolderView::not_loaded_view_item_params => array
  136. (
  137. ViewItemParams::item_paint_icon => true,
  138. ViewItemParams::item_detailed_icon_path => 'missing://',
  139. ViewItemParams::icon_path => 'gui_skin://osd_icons/wait.aai',
  140. ),
  141. # PluginRegularFolderView::async_icon_loading => true,
  142. PluginRegularFolderView::initial_range => array(),
  143. );
  144. return array($view_0);
  145. }
  146. public function get_vod_info(MediaURL $media_url, &$plugin_cookies)
  147. {
  148. $path = $media_url->__get('path');
  149. $curr_node = $this->_node_storage;
  150. $curr_file = $curr_node->name;
  151. $path_arr = explode('/', $path);
  152. foreach($path_arr as $p)
  153. {
  154. $child = $curr_node->children[$p];
  155. $curr_node = $child;
  156. $curr_file .= '/' . $curr_node->name;
  157. }
  158. $full_path = ScreenSettings::get_store_directory($plugin_cookies);
  159. if(!$full_path)
  160. return array();
  161. $full_path .= '/' . $curr_file;
  162. $file = basename($full_path);
  163. return array
  164. (
  165. PluginVodInfo::name => $file,
  166. PluginVodInfo::description => $file,
  167. PluginVodInfo::poster_url => 'missing://',
  168. PluginVodInfo::series => array
  169. (
  170. array
  171. (
  172. PluginVodSeriesInfo::name => '',
  173. PluginVodSeriesInfo::playback_url => $full_path,
  174. PluginVodSeriesInfo::playback_url_is_stream_url => false
  175. )
  176. )
  177. );
  178. }
  179. ###################################################
  180. private function _get_items_list(MediaURL $media_url, $from_ndx, &$plugin_cookies)
  181. {
  182. $items_dir = array();
  183. $items_file = array();
  184. $path = $media_url->__get('path');
  185. $curr_node = $this->_node_storage;
  186. $curr_file = $curr_node->name;
  187. if(strlen($path))
  188. {
  189. $path_arr = explode('/', $path);
  190. foreach($path_arr as $p)
  191. {
  192. $child = $curr_node->children[$p];
  193. $curr_node = $child;
  194. $curr_file .= '/' . $curr_node->name;
  195. }
  196. }
  197. $full_path = ScreenSettings::get_store_directory($plugin_cookies);
  198. if(!$full_path)
  199. return array();
  200. $full_path .= '/' . $curr_file;
  201. $fd = dir($full_path);
  202. if($fd)
  203. {
  204. while(false !== ($name = $fd->read()))
  205. {
  206. if( $name === "." || $name === ".." )
  207. continue;
  208. $file_path = implode('/', array($full_path, $name));
  209. $type = is_dir($file_path) ? 'dir' : 'audio';
  210. $item = array
  211. (
  212. 'name' => $name,
  213. 'type' => $type,
  214. 'file_path' => $file_path,
  215. );
  216. if($type === 'dir')
  217. $items_dir[$name] = $item;
  218. else
  219. $items_file[$name] = $item;
  220. }
  221. }
  222. ksort($items_dir);
  223. krsort($items_file);
  224. $items = array();
  225. $idx = 0;
  226. $curr_node->children = array();
  227. foreach(array_merge($items_dir, $items_file) as $item)
  228. {
  229. $new_node = new NodeAr($idx, $curr_node->path, $item['type'], $item['name']);
  230. $item_media_url = MediaURL::encode(array('screen_id' => self::ID, 'type' => $type, 'path' => $new_node->{'path'}));
  231. $item = array
  232. (
  233. PluginRegularFolderItem::caption => $item['name'],
  234. PluginRegularFolderItem::media_url => $item_media_url,
  235. PluginRegularFolderItem::view_item_params => array
  236. (
  237. ViewItemParams::icon_path => Common::get_icon4type($type),
  238. ),
  239. );
  240. $curr_node->children[$idx] = $new_node;
  241. $items[] = $item;
  242. $idx++;
  243. }
  244. return $items;
  245. }
  246. }
  247. ?>