BxFilesSearchResult.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Files Files
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFilesSearchResult extends BxBaseModTextSearchResult
  12. {
  13. protected $sOrderParamName = 'order';
  14. protected $sBookmarksParamName = 'bookmarks';
  15. protected $sSortingParamName = 'sorting';
  16. protected $sCurrentFolderParamName = 'folder';
  17. protected $sCurrentView;
  18. protected $aSortingOptions;
  19. protected $bFileManagerMode = false;
  20. protected $iFileManagerUploadTo = 0;
  21. protected $sMode = '';
  22. function __construct($sMode = '', $aParams = array())
  23. {
  24. $aParams['unit_views'] = [
  25. 'extended' => 'unit.html',
  26. 'gallery' => 'unit_gallery.html',
  27. 'full' => 'unit_full.html',
  28. 'showcase' => 'unit_showcase.html',
  29. 'table' => 'unit_simple_row.html',
  30. ];
  31. //Enble filemanager (toolbar, table files layout, dynamic menus, folders support) only for author/context blocks.
  32. if (($sMode == 'author' || $sMode == 'context') && !isset($aParams['no_toolbar'])) {
  33. $this->bFileManagerMode = true;
  34. $this->setUnitParams(['show_inline_menu' => true]);
  35. if (!bx_get('unit_view'))
  36. $aParams['unit_view'] = getParam('bx_files_default_layout_mode');
  37. }
  38. $this->sMode = $sMode;
  39. parent::__construct($sMode, $aParams);
  40. $this->sCurrentView = array_flip($aParams['unit_views'])[$this->sUnitTemplate];
  41. $this->aGetParams = array_merge($this->aGetParams, [
  42. $this->sOrderParamName,
  43. $this->sBookmarksParamName,
  44. $this->sSortingParamName,
  45. $this->sUnitViewParamName,
  46. $this->sCurrentFolderParamName,
  47. ]);
  48. $this->aSortingOptions = [
  49. 'name',
  50. 'date',
  51. 'type',
  52. 'author',
  53. ];
  54. $this->aCurrent = array(
  55. 'name' => 'bx_files',
  56. 'module_name' => 'bx_files',
  57. 'object_metatags' => 'bx_files',
  58. 'title' => _t('_bx_files_page_title_browse'),
  59. 'table' => 'bx_files_main',
  60. 'ownFields' => array('id', 'file_id', 'title', 'desc', 'author', 'added', 'type', 'parent_folder_id', 'allow_view_to'),
  61. 'searchFields' => array(),
  62. 'restriction' => array(
  63. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  64. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>'),
  65. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  66. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '='),
  67. 'files_only' => array('value' => 'file', 'field' => 'type', 'operator' => '='),
  68. 'context_filter' => array('value' => '', 'field' => 'allow_view_to', 'operator' => '>'),
  69. 'folder' => array('value' => '', 'field' => 'parent_folder_id', 'operator' => '='),
  70. ),
  71. 'paginate' => array('perPage' => getParam('bx_files_per_page_browse'), 'start' => 0),
  72. 'sorting' => 'last',
  73. 'rss' => array(
  74. 'title' => '',
  75. 'link' => '',
  76. 'image' => '',
  77. 'profile' => 0,
  78. 'fields' => array (
  79. 'Guid' => 'link',
  80. 'Link' => 'link',
  81. 'Title' => 'title',
  82. 'DateTimeUTS' => 'added',
  83. 'Desc' => 'desc',
  84. 'Image' => 'thumb'
  85. ),
  86. ),
  87. 'ident' => 'id',
  88. );
  89. $this->sFilterName = 'bx_files_filter';
  90. $this->oModule = $this->getMain();
  91. $CNF = &$this->oModule->_oConfig->CNF;
  92. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  93. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  94. $oProfileAuthor = null;
  95. switch ($sMode) {
  96. case 'author':
  97. if(!$this->_updateCurrentForAuthor($sMode, $aParams, $oProfileAuthor))
  98. $this->isError = true;
  99. else {
  100. //show only those files/folders which are not posted to some context
  101. $this->aCurrent['restriction']['context_filter']['value'] = 0;
  102. }
  103. break;
  104. case 'context':
  105. if(!$this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor))
  106. $this->isError = true;
  107. break;
  108. case 'favorite':
  109. if(!$this->_updateCurrentForFavorite($sMode, $aParams, $oProfileAuthor))
  110. $this->isError = true;
  111. break;
  112. case 'public':
  113. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  114. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_recent');
  115. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  116. break;
  117. case 'featured':
  118. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  119. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_featured');
  120. $this->aCurrent['restriction']['featured']['value'] = '0';
  121. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  122. $this->aCurrent['sorting'] = 'featured';
  123. break;
  124. case 'popular':
  125. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_POPULAR']);
  126. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_popular');
  127. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  128. $this->aCurrent['sorting'] = 'popular';
  129. break;
  130. case 'top':
  131. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_TOP']);
  132. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_top');
  133. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  134. $this->aCurrent['sorting'] = 'top';
  135. break;
  136. case 'updated':
  137. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_UPDATED']);
  138. $this->aCurrent['title'] = _t('_bx_files_page_title_browse_updated');
  139. $this->aCurrent['rss']['link'] = 'modules/?r=files/rss/' . $sMode;
  140. $this->aCurrent['sorting'] = 'updated';
  141. break;
  142. case '': // search results
  143. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  144. $this->aCurrent['title'] = _t('_bx_files');
  145. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  146. break;
  147. default:
  148. $sMode = '';
  149. $this->isError = true;
  150. }
  151. $this->processReplaceableMarkers($oProfileAuthor);
  152. $this->addConditionsForPrivateContent($CNF, $oProfileAuthor);
  153. $this->addCustomConditions($CNF, $oProfileAuthor, $sMode, $aParams);
  154. //show to a profile author all of his files regardless of CF
  155. if ($sMode == 'author' && $oProfileAuthor && bx_get_logged_profile_id() == $oProfileAuthor->id())
  156. unset($this->aCurrent['restriction']['cf_viewer']);
  157. if ($this->bFileManagerMode) {
  158. $this->addContainerClass('bx-files-with-toolbar');
  159. unset($this->aCurrent['restriction']['files_only']);
  160. if (bx_get($this->sBookmarksParamName))
  161. $this->addConditionsForBookmarks($CNF);
  162. $this->aCurrent['sorting'] = 'name';
  163. if (bx_get($this->sSortingParamName)) $this->aCurrent['sorting'] = bx_get($this->sSortingParamName);
  164. if ($this->aCurrent['sorting'] == 'type')
  165. $this->addConditionsForMimeType($CNF);
  166. $this->removeContainerClass('bx-def-margin-sec-lefttopright-neg');
  167. if (!$this->isError) {
  168. if ($sMode == 'author' && $oProfileAuthor->id() == bx_get_logged_profile_id() || $sMode == 'context')
  169. $this->iFileManagerUploadTo = $oProfileAuthor->id();
  170. }
  171. if ($this->sCurrentView == 'table')
  172. $this->removeContainerClass('bx-def-margin-bottom-neg');
  173. $this->aCurrent['restriction']['folder']['value'] = intval(bx_get($this->sCurrentFolderParamName));
  174. if ($this->aCurrent['restriction']['folder']['value'] < 0) {
  175. //navigate folder top
  176. bx_set($this->sCurrentFolderParamName, $this->oModule->_oDb->getParentFolderId(-$this->aCurrent['restriction']['folder']['value']));
  177. $this->aCurrent['restriction']['folder']['value'] = bx_get($this->sCurrentFolderParamName);
  178. }
  179. //free up one place for folder up item
  180. if ($this->aCurrent['restriction']['folder']['value']) {
  181. $this->aCurrent['paginate']['perPage']--;
  182. }
  183. }
  184. }
  185. protected function addConditionsForBookmarks(&$CNF) {
  186. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join'])) $this->aCurrent['join'] = [];
  187. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], [
  188. 'bookmarks' => [
  189. 'type' => 'INNER',
  190. 'table' => $CNF['TABLE_BOOKMARKS'],
  191. 'mainTable' => $CNF['TABLE_ENTRIES'],
  192. 'mainField' => $CNF['FIELD_ID'],
  193. 'onField' => $CNF['FIELD_BOOKMARKS_ID'],
  194. 'joinFields' => array($CNF['FIELD_BOOKMARKS_PROFILE']),
  195. ],
  196. ]);
  197. $this->aCurrent['restriction']['bookmarks'] = [
  198. 'value' => bx_get_logged_profile_id(),
  199. 'field' => $CNF['FIELD_BOOKMARKS_PROFILE'],
  200. 'operator' => '=',
  201. 'table' => $CNF['TABLE_BOOKMARKS'],
  202. ];
  203. }
  204. protected function addConditionsForMimeType(&$CNF) {
  205. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join'])) $this->aCurrent['join'] = [];
  206. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], [
  207. 'files' => [
  208. 'type' => 'LEFT',
  209. 'table' => $CNF['TABLE_FILES'],
  210. 'mainTable' => $CNF['TABLE_ENTRIES'],
  211. 'mainField' => $CNF['FIELD_ID'],
  212. 'onField' => $CNF['FIELD_ID'],
  213. 'joinFields' => array($CNF['FIELD_MIME_TYPE']),
  214. ],
  215. ]);
  216. }
  217. public function addCustomParts() {
  218. if ($this->_bLiveSearch) return;
  219. if (!$this->bFileManagerMode) return;
  220. $this->oModule->_oTemplate->addCss('main.css');
  221. $aParams = [
  222. 'aRequestParams' => [
  223. 'unit_view_param' => $this->sUnitViewParamName,
  224. 'bookmarks_param' => $this->sBookmarksParamName,
  225. 'sorting_param' => $this->sSortingParamName,
  226. 'keyword_param' => 'keyword',
  227. 'current_folder' => $this->sCurrentFolderParamName,
  228. ],
  229. 'layout' => $this->sCurrentView,
  230. 'bookmarks' => intval(bx_get($this->sBookmarksParamName)),
  231. 'sorting' => $this->aCurrent['sorting'],
  232. 'sorting_options' => $this->aSortingOptions,
  233. 'keyword' => bx_get('keyword') ? bx_get('keyword') : '',
  234. 'current_folder' => $this->aCurrent['restriction']['folder']['value'],
  235. 'current_page' => $this->aCurrent['paginate']['start'],
  236. ];
  237. return $this->getBrowseToolbar($aParams);
  238. }
  239. function getSearchData ()
  240. {
  241. $CNF = &$this->oModule->_oConfig->CNF;
  242. $aData = parent::getSearchData();
  243. if ($this->bFileManagerMode && $this->aCurrent['restriction']['folder']['value']) {
  244. $aData = array_merge([0 => [
  245. $CNF['FIELD_ID'] => '-1',
  246. $CNF['FIELD_FILE_ID'] => '0',
  247. $CNF['FIELD_TITLE'] => '..',
  248. $CNF['FIELD_AUTHOR'] => bx_get_logged_profile_id(),
  249. $CNF['FIELD_ADDED'] => 0,
  250. $CNF['FIELD_ALLOW_VIEW_TO'] => BX_DOL_PG_ALL,
  251. 'type' => 'folder',
  252. ]], $aData);
  253. $this->aCurrent['paginate']['num']++;
  254. }
  255. return $aData;
  256. }
  257. function processing ()
  258. {
  259. $iViewedProfile = 0;
  260. if ($this->_sMode == 'context' && $this->iFileManagerUploadTo) $iViewedProfile = $this->iFileManagerUploadTo;
  261. if ($this->_sMode == 'author' && $this->aCurrent['restriction']['author']['value']) $iViewedProfile = $this->aCurrent['restriction']['author']['value'];
  262. if ($iViewedProfile) {
  263. if (is_array($iViewedProfile)) $iViewedProfile = abs($iViewedProfile[0]);
  264. $oProfile = BxDolProfile::getInstance($iViewedProfile);
  265. if ($oProfile->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED) {
  266. $this->aCurrent['paginate']['num'] = 1;
  267. return MsgBox(_t('_sys_access_denied_to_private_content'));
  268. }
  269. }
  270. $sCode = parent::processing();
  271. if (!$this->aCurrent['paginate']['num'] && $this->bFileManagerMode) {
  272. //to show toolbar in case of empty results
  273. $sCode = $this->displaySearchBox($this->addCustomParts().MsgBox(_t('_Empty')));
  274. }
  275. return $sCode;
  276. }
  277. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  278. {
  279. $aAdditionalParams = [
  280. $this->sUnitViewParamName => $this->sCurrentView,
  281. $this->sBookmarksParamName => intval(bx_get($this->sBookmarksParamName)),
  282. $this->sSortingParamName => $this->aCurrent['sorting'],
  283. $this->sCurrentFolderParamName => $this->aCurrent['restriction']['folder']['value'],
  284. ];
  285. $sPageUrl = $this->getCurrentUrl($aAdditionalParams, false);
  286. $sOnClick = $this->getCurrentOnclick($aAdditionalParams, false);
  287. $oPaginate = new BxTemplPaginate([
  288. 'page_url' => $sPageUrl,
  289. 'on_change_page' => $sOnClick,
  290. 'num' => $this->aCurrent['paginate']['num'],
  291. 'per_page' => $this->aCurrent['paginate']['perPage'],
  292. 'start' => $this->aCurrent['paginate']['start'],
  293. ]);
  294. return $sOnClick ? $oPaginate->getSimplePaginate() : $oPaginate->getPaginate();
  295. }
  296. function getAlterOrder() {
  297. if (in_array($this->aCurrent['sorting'], $this->aSortingOptions)) {
  298. $CNF = &$this->oModule->_oConfig->CNF;
  299. $aSql = array();
  300. switch ($this->aCurrent['sorting']) {
  301. case 'name':
  302. $aSql['order'] = ' ORDER BY `'.$CNF['TABLE_ENTRIES'].'`.`type` DESC, `'.$CNF['TABLE_ENTRIES'].'`.`'.$CNF['FIELD_TITLE'].'` ASC';
  303. break;
  304. case 'date':
  305. $aSql['order'] = ' ORDER BY `'.$CNF['TABLE_ENTRIES'].'`.`type` DESC, `'.$CNF['TABLE_ENTRIES'].'`.`'.$CNF['FIELD_ID'].'` DESC';
  306. break;
  307. case 'author':
  308. $aSql['order'] = ' ORDER BY `'.$CNF['TABLE_ENTRIES'].'`.`type` DESC, `'.$CNF['TABLE_ENTRIES'].'`.`'.$CNF['FIELD_AUTHOR'].'` ASC, `'.$CNF['TABLE_ENTRIES'].'`.`'.$CNF['FIELD_TITLE'].'` ASC';
  309. break;
  310. case 'type':
  311. $aSql['order'] = ' ORDER BY `'.$CNF['TABLE_ENTRIES'].'`.`type` DESC, `'.$CNF['TABLE_FILES'].'`.`'.$CNF['FIELD_MIME_TYPE'].'` ASC, `'.$CNF['TABLE_ENTRIES'].'`.`'.$CNF['FIELD_TITLE'].'` ASC';
  312. break;
  313. }
  314. return $aSql;
  315. } else {
  316. return parent::getAlterOrder();
  317. }
  318. }
  319. protected function getBrowseToolbarControls(&$aParams, $sJsObject) {
  320. $aSortingOptions = [];
  321. if (isset($aParams['sorting_options'])) {
  322. foreach ($aParams['sorting_options'] as $sSorting) {
  323. $aSortingOptions[$sSorting] = _t('_bx_files_toolbar_sorting_' . $sSorting);
  324. }
  325. }
  326. $oForm = new BxTemplFormView([], $this->oModule->_oTemplate);
  327. $aInputSorting = [
  328. 'type' => 'select',
  329. 'name' => 'sorting',
  330. 'value' => $aParams['sorting'],
  331. 'values' => $aSortingOptions,
  332. 'attrs' => [
  333. 'onchange' => $sJsObject.'.setSorting(this.value);',
  334. ],
  335. ];
  336. $aInputFilter = [
  337. 'type' => 'text',
  338. 'name' => 'keyword',
  339. 'value' => $aParams['keyword'],
  340. 'attrs' => [
  341. 'placeholder' => _t('_sys_search_placeholder'),
  342. 'onkeyup' => $sJsObject.'.onChangeFilter(this);',
  343. 'onpaste' => $sJsObject.'.onChangeFilter(this);',
  344. ],
  345. ];
  346. $aUploadButtonParams = [];
  347. $bUploadAllowed = $this->oModule->checkAllowedAdd() == CHECK_ACTION_RESULT_ALLOWED && $this->oModule->serviceIsAllowedAddContentToContext($this->iFileManagerUploadTo);
  348. if ($bUploadAllowed) {
  349. $sUniqId = genRndPwd (8, false);
  350. $oUploader = BxDolUploader::getObjectInstance('bx_files_html5', $this->oModule->_oConfig->CNF['OBJECT_STORAGE'], $sUniqId, $this->oModule->_oTemplate);
  351. $iMaxNestingLevel = intval(getParam($this->oModule->_oConfig->CNF['PARAM_MAX_NESTING_LEVEL']));
  352. $aParamsJs = array_merge($oUploader->getUploaderJsParams(),
  353. [
  354. 'content_id' => 0,
  355. 'storage_private' => '0',
  356. 'acceptedFiles' => '',
  357. 'multiple' => 1,
  358. 'images_transcoder' => 'bx_files_preview',
  359. ]
  360. );
  361. $aParamsBtn = [
  362. 'content_id' => 0,
  363. 'storage_private' => '0',
  364. 'button_template' => 'uploader_button_html5_attach.html'
  365. ];
  366. $aUploadButtonParams = [
  367. 'js_object' => $sJsObject,
  368. 'uploader_code' => $oUploader->getUploaderButton($aParamsBtn) . $oUploader->getUploaderJs('', true, $aParamsJs, true),
  369. 'uploader_js_object' => $oUploader->getNameJsInstanceUploader(),
  370. 'uploader_click_handler' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();',
  371. 'bx_if:create_folder_allowed' => [
  372. 'condition' => $iMaxNestingLevel == 0 || $this->oModule->_oDb->getFolderNestingLevel($this->aCurrent['restriction']['folder']['value']) < $iMaxNestingLevel,
  373. 'content' => [
  374. 'js_object' => $sJsObject,
  375. 'folder_name_message' => _t('_bx_files_txt_folder_name'),
  376. ]
  377. ],
  378. ];
  379. }
  380. $aBulkActions = [];
  381. $aBulkActions[] = ['js_object' => $sJsObject, 'handler' => 'downloadFiles', 'title' => _t('_bx_files_bulk_action_title_download'), 'icon' => 'download'];
  382. if (isLogged()) {
  383. $aBulkActions[] = ['js_object' => $sJsObject, 'handler' => 'bookmarkFiles', 'title' => _t('_bx_files_bulk_action_title_bookmark'), 'icon' => 'star'];
  384. if ($bUploadAllowed) {
  385. $aBulkActions[] = ['js_object' => $sJsObject, 'handler' => 'deleteFiles', 'title' => _t('_bx_files_bulk_action_title_delete'), 'icon' => 'remove'];
  386. $aBulkActions[] = ['js_object' => $sJsObject, 'handler' => 'moveFiles', 'title' => _t('_bx_files_bulk_action_title_move_to'), 'icon' => 'file-export'];
  387. }
  388. }
  389. return [
  390. 'sorting_dropdown' => $oForm->genRowStandard($aInputSorting),
  391. 'filter_box' => $oForm->genRowStandard($aInputFilter),
  392. 'bx_if:upload_visible' => [
  393. 'condition' => $bUploadAllowed,
  394. 'content' => $aUploadButtonParams,
  395. ],
  396. 'bx_if:bookmarks_visible' => [
  397. 'condition' => isLogged(),
  398. 'content' => [
  399. 'js_object' => $sJsObject,
  400. 'bookmark_enabled' => $aParams['bookmarks'] ? 'fas' : 'far',
  401. ],
  402. ],
  403. 'bx_if:table_layout_btn' => [
  404. 'condition' => $aParams['layout'] == 'table',
  405. 'content' => [
  406. 'js_object' => $sJsObject,
  407. 'unit_view_param' => $aParams['aRequestParams']['unit_view_param'],
  408. ],
  409. ],
  410. 'bx_if:gallery_layout_btn' => [
  411. 'condition' => $aParams['layout'] == 'gallery',
  412. 'content' => [
  413. 'js_object' => $sJsObject,
  414. 'unit_view_param' => $aParams['aRequestParams']['unit_view_param'],
  415. ],
  416. ],
  417. 'bx_repeat:sorting_options' => $aSortingOptions,
  418. 'bx_repeat:bulk_actions' => $aBulkActions,
  419. ];
  420. }
  421. protected function getBrowseToolbarBreadcrumbs($sJsObject) {
  422. $aFolderPathTmpl = [];
  423. $aFolderPath = $this->oModule->_oDb->getFolderPath($this->aCurrent['restriction']['folder']['value']);
  424. if ($aFolderPath) {
  425. $aFolderPathTmpl[] = [
  426. 'name' => _t('_bx_files_txt_folder_root'),
  427. 'folder' => '0',
  428. 'js_object' => $sJsObject,
  429. ];
  430. foreach ($aFolderPath as $aEntry) {
  431. $aFolderPathTmpl[] = [
  432. 'name' => strmaxtextlen($aEntry['name'], 20),
  433. 'folder' => $aEntry['folder'],
  434. 'js_object' => $sJsObject,
  435. ];
  436. }
  437. }
  438. return $aFolderPathTmpl;
  439. }
  440. protected function getBrowseToolbar(&$aParams) {
  441. $this->oModule->_oTemplate->addJs('toolbar_tools.js');
  442. $sUniqueIdent = mt_rand();
  443. $aParams['unique_ident'] = $sUniqueIdent;
  444. $aParams['context'] = $this->sMode == 'context' ? $this->iFileManagerUploadTo : '';
  445. $sJsCode = $this->oModule->_oTemplate->getJsCode(['type' => 'toolbar_tools', 'uniq' => $sUniqueIdent], $aParams);
  446. $sJsObject = $this->oModule->_oConfig->getJsObject(['type' => 'toolbar_tools', 'uniq' => $sUniqueIdent]);
  447. $this->setUnitParams(['toolbar_js_object' => $sJsObject]);
  448. $aToolbarControls = $this->getBrowseToolbarControls($aParams, $sJsObject);
  449. return $this->oModule->_oTemplate->parseHtmlByName('files_browser_toolbar.html', array_merge($aToolbarControls, [
  450. 'js_object' => $sJsObject,
  451. 'js_code' => $sJsCode,
  452. 'unique_ident' => $sUniqueIdent,
  453. 'bx_repeat:folder_path' => $this->getBrowseToolbarBreadcrumbs($sJsObject),
  454. 'bx_if:select_all_checkbox' => [
  455. 'condition' => $aParams['layout'] == 'table',
  456. 'content' => [
  457. 'js_object' => $sJsObject,
  458. 'unique_ident' => $sUniqueIdent,
  459. ],
  460. ],
  461. ]));
  462. }
  463. }
  464. /** @} */