Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.40 KB | None | 0 0
  1. <?php
  2. // for js translations
  3. t('uploader_hour', 'hour');
  4. t('uploader_hours', 'hours');
  5. t('uploader_minute', 'minute');
  6. t('uploader_minutes', 'minutes');
  7. t('uploader_second', 'second');
  8. t('uploader_seconds', 'seconds');
  9. t('selected', 'selected');
  10. t('selected_image_clear', 'clear');
  11. t('account_file_details_clear_selected', 'Clear Selected');
  12.  
  13. define('MAX_CONCURRENT_THUMBNAIL_REQUESTS', 5);
  14.  
  15. $fid = null;
  16. if (isset($_REQUEST['fid'])) {
  17. $fid = (int) $_REQUEST['fid'];
  18. }
  19. ?>
  20. <script>
  21. var fileUrls = [];
  22. var fileUrlsHtml = [];
  23. var fileUrlsBBCode = [];
  24. var fileDeleteHashes = [];
  25. var fileShortUrls = [];
  26. var fileNames = [];
  27. var uploadPreviewQueuePending = [];
  28. var uploadPreviewQueueProcessing = [];
  29. var statusFlag = 'pending';
  30. var lastEle = null;
  31. var startTime = null;
  32. var fileToEmail = '';
  33. var filePassword = '';
  34. var fileCategory = '';
  35. var fileFolder = '';
  36. var uploadComplete = true;
  37. //icon uploader vars
  38. var iconUrls = [];
  39. var iconUrlsHtml = [];
  40. var iconUrlsBBCode = [];
  41. var iconDeleteHashes = [];
  42. var iconShortUrls = [];
  43. var iconNames = [];
  44. var icon_uploadPreviewQueuePending = [];
  45. var icon_uploadPreviewQueueProcessing = [];
  46. var icon_statusFlag = 'pending';
  47. var icon_lastEle = null;
  48. var icon_startTime = null;
  49. var icon_fileToEmail = '';
  50. var icon_filePassword = '';
  51. var icon_fileCategory = '';
  52. var icon_fileFolder = '';
  53. var icon_uploadComplete = true;
  54. var empty_icon_uploader = null;
  55. var init_icon_uploader = null;
  56. $(document).ready(function () {
  57. document.domain = '<?php echo coreFunctions::removeSubDomain(_CONFIG_CORE_SITE_HOST_URL); ?>';
  58. empty_icon_uploader = $("#iconUploadWrapper");
  59. <?php
  60. if ($showUploads == true) {
  61. // figure out max files
  62. $maxFiles = UserPeer::getMaxUploadsAtOnce($Auth->package_id);
  63.  
  64. // failsafe
  65. if ((int) $maxFiles == 0) {
  66. $maxFiles = 50;
  67. }
  68.  
  69. // if php restrictions are lower than permitted, override
  70. $phpMaxSize = coreFunctions::getPHPMaxUpload();
  71. $maxUploadSizeNonChunking = 0;
  72. if ($phpMaxSize < $maxUploadSize) {
  73. $maxUploadSizeNonChunking = $phpMaxSize;
  74. }
  75. ?>
  76. // figure out if we should use 'chunking'
  77. var maxChunkSize = 0;
  78. var uploaderMaxSize = <?php echo (int) $maxUploadSizeNonChunking; ?>;
  79. <?php if (USE_CHUNKED_UPLOADS == true): ?>
  80. if (browserXHR2Support() == true)
  81. {
  82. maxChunkSize = <?php echo (coreFunctions::getPHPMaxUpload() > CHUNKED_UPLOAD_SIZE ? CHUNKED_UPLOAD_SIZE : coreFunctions::getPHPMaxUpload() - 5000); // in bytes, allow for smaller PHP upload limits ?>;
  83. var uploaderMaxSize = <?php echo $maxUploadSize; ?>;
  84. }
  85. <?php endif; ?>
  86.  
  87. // Initialize the jQuery File Upload widget:
  88. $('#fileUpload #uploader').fileupload({
  89. sequentialUploads: true,
  90. url: '<?php echo crossSiteAction::appendUrl(file::getUploadUrl() . '/core/page/ajax/file_upload_handler.ajax.php?r=' . htmlspecialchars(_CONFIG_SITE_HOST_URL) . '&p=' . htmlspecialchars(_CONFIG_SITE_PROTOCOL)); ?>',
  91. maxFileSize: uploaderMaxSize,
  92. formData: {},
  93. autoUpload: false,
  94. xhrFields: {
  95. withCredentials: true
  96. },
  97. getNumberOfFiles: function () {
  98. return getTotalRows();
  99. },
  100. previewMaxWidth: 160,
  101. previewMaxHeight: 134,
  102. previewCrop: true,
  103. messages: {
  104. maxNumberOfFiles: '<?php echo str_replace("'", "\'", t('file_upload_maximum_number_of_files_exceeded', 'Maximum number of files exceeded')); ?>',
  105. acceptFileTypes: '<?php echo str_replace("'", "\'", t('file_upload_file_type_not_allowed', 'File type not allowed')); ?>',
  106. maxFileSize: '<?php echo str_replace("'", "\'", t('file_upload_file_is_too_large', 'File is too large')); ?>',
  107. minFileSize: '<?php echo str_replace("'", "\'", t('file_upload_file_is_too_small', 'File is too small')); ?>'
  108. },
  109. maxChunkSize: maxChunkSize,
  110. <?php echo COUNT($acceptedFileTypes) ? ('acceptFileTypes: /(\\.|\\/)(' . str_replace(".", "", implode("|", $acceptedFileTypes) . ')$/i,')) : ''; ?> maxNumberOfFiles: <?php echo (int) $maxFiles; ?>
  111. })
  112. .on('fileuploadadd', function (e, data) {
  113. <?php if(COUNT($acceptedFileTypes)): ?>
  114. var acceptFileTypes = /^(<?php echo str_replace(".", "", implode("|", $acceptedFileTypes)); ?>)$/i;
  115. for(i in data.originalFiles)
  116. {
  117. fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
  118. if(!acceptFileTypes.test(fileExtension)) {
  119. alert("<?php echo str_replace("'", "\'", t('file_upload_file_type_not_allowed', 'File type not allowed')); ?> (\""+data.originalFiles[i]['name']+"\")");
  120. return false;
  121. }
  122. }
  123. <?php endif; ?>
  124.  
  125. $('#fileUpload #uploader #fileListingWrapper').removeClass('hidden');
  126. $('#fileUpload #uploader #initialUploadSection').addClass('hidden');
  127. $('#fileUpload #uploader #initialUploadSectionLabel').addClass('hidden');
  128.  
  129. // fix for safari
  130. getTotalRows();
  131. // end safari fix
  132.  
  133. totalRows = getTotalRows() + 1;
  134. updateTotalFilesText(totalRows);
  135. })
  136. .on('fileuploadstart', function (e, data) {
  137. uploadComplete = false;
  138.  
  139. // hide/show sections
  140. $('#fileUpload #addFileRow').addClass('hidden');
  141. $('#fileUpload #processQueueSection').addClass('hidden');
  142. $('#fileUpload #processingQueueSection').removeClass('hidden');
  143.  
  144. // hide cancel icons
  145. $('#fileUpload .cancel').hide();
  146. $('#fileUpload .cancel').click(function () {
  147. return false;
  148. });
  149.  
  150. // show faded overlay on images
  151. $('#fileUpload .previewOverlay').addClass('faded');
  152.  
  153. // set timer
  154. startTime = (new Date()).getTime();
  155. })
  156. .on('fileuploadstop', function (e, data) {
  157. // finished uploading
  158. updateTitleWithProgress(100);
  159. updateProgessText(100, data.total, data.total);
  160. $('#fileUpload #processQueueSection').addClass('hidden');
  161. $('#fileUpload #processingQueueSection').addClass('hidden');
  162. $('#fileUpload #completedSection').removeClass('hidden');
  163.  
  164. // set all remainging pending icons to failed
  165. $('#fileUpload .processingIcon').parent().html('<img src="<?php echo SITE_IMAGE_PATH; ?>/red_error_small.png" width="16" height="16"/>');
  166.  
  167. uploadComplete = true;
  168. sendAdditionalOptions();
  169.  
  170. // setup copy link
  171. setupCopyAllLink();
  172.  
  173. // flag as finished for later on
  174. statusFlag = 'finished';
  175.  
  176. if (typeof (checkShowUploadFinishedWidget) === 'function')
  177. {
  178. checkShowUploadFinishedWidget();
  179. }
  180.  
  181. delay(function() {
  182. $('#hide_modal_btn').click();
  183. }, 1500);
  184. })
  185. .on('fileuploadprogressall', function (e, data) {
  186. // progress bar
  187. var progress = parseInt(data.loaded / data.total * 100, 10);
  188. $('#progress .progress-bar').css(
  189. 'width',
  190. progress + '%'
  191. );
  192.  
  193. // update page title with progress
  194. updateTitleWithProgress(progress);
  195. updateProgessText(progress, data.loaded, data.total);
  196. })
  197. .on('fileuploadsend', function (e, data) {
  198. // show progress ui elements
  199. $(data['context']).find('.previewOverlay .progressText').removeClass('hidden');
  200. $(data['context']).find('.previewOverlay .progress').removeClass('hidden');
  201. })
  202. .on('fileuploadprogress', function (e, data) {
  203. // progress bar
  204. var progress = parseInt(data.loaded / data.total * 100, 10);
  205.  
  206. // update item progress
  207. $(data['context']).find('.previewOverlay .progressText').html(progress + '%');
  208. $(data['context']).find('.previewOverlay .progress .progress-bar').css('width', progress + '%');
  209. })
  210. .on('fileuploaddone', function (e, data) {
  211.  
  212. // hide faded overlay on images
  213. $(data['context']).find('.previewOverlay').removeClass('faded');
  214.  
  215. // keep a copy of the urls globally
  216. fileUrls.push(data['result'][0]['url']);
  217. fileUrlsHtml.push(data['result'][0]['url_html']);
  218. fileUrlsBBCode.push(data['result'][0]['url_bbcode']);
  219. fileDeleteHashes.push(data['result'][0]['delete_hash']);
  220. fileShortUrls.push(data['result'][0]['short_url']);
  221. fileNames.push(data['result'][0]['name']);
  222. console.log(fileNames);
  223. var isSuccess = true;
  224. if (data['result'][0]['error'] != null)
  225. {
  226. isSuccess = false;
  227. }
  228.  
  229. var html = '';
  230. html += '<div class="template-download-img';
  231. if (isSuccess == false)
  232. {
  233. html += ' errorText';
  234. }
  235. html += '" ';
  236. if (isSuccess == true)
  237. {
  238. html += 'onClick="window.open(\'' + data['result'][0]['url'] + '\'); return false;"';
  239. }
  240. html += ' title="'+data['result'][0]['name']+'"';
  241. html += '>';
  242.  
  243. if (isSuccess == true)
  244. {
  245. previewUrl = WEB_ROOT+'/themes/cloudable/images/trans_1x1.gif';
  246. if(data['result'][0]['success_result_html'].length > 0)
  247. {
  248. previewUrl = data['result'][0]['success_result_html'];
  249. }
  250.  
  251. html += "<div id='finalThumbWrapper"+data['result'][0]['file_id']+"'></div>";
  252. queueUploaderPreview('finalThumbWrapper'+data['result'][0]['file_id'], previewUrl, data['result'][0]['file_id']);
  253. }
  254. else
  255. {
  256. // @TODO - replace this with an error icon
  257. html += 'Error uploading: ' + data['result'][0]['name'];
  258. }
  259. html += '</div>';
  260.  
  261. // update screen with success content
  262. $(data['context']).replaceWith(html);
  263. processUploaderPreviewQueue();
  264. })
  265. .on('fileuploadfail', function (e, data) {
  266. // hand deletes
  267. if (data.errorThrown == 'abort')
  268. {
  269. $(data['context']).remove();
  270. return true;
  271. }
  272.  
  273. // update screen with error content, ajax issues
  274. var html = '';
  275. html += '<div class="template-download-img errorText">';
  276. html += '<?php echo t('indexjs_error_server_problem_reservo', 'ERROR: There was a server problem when attempting the upload.'); ?>';
  277. html += '</div>';
  278. $(data['context'])
  279. .replaceWith(html);
  280.  
  281. totalRows = getTotalRows();
  282. if (totalRows > 0)
  283. {
  284. totalRows = totalRows - 1;
  285. }
  286.  
  287. updateTotalFilesText(totalRows);
  288. });
  289.  
  290.  
  291. ///////////////////////////////////////////////////////////////////////////////////
  292. // ICON UPLOADER
  293.  
  294. // Initialize the jQuery Icon Upload widget:
  295.  
  296. $('#iconUpload #icon_uploader').fileupload({
  297. sequentialUploads: true,
  298. url: '<?php echo crossSiteAction::appendUrl(file::getUploadUrl() . '/core/page/ajax/file_upload_handler.ajax.php?r=' . htmlspecialchars(_CONFIG_SITE_HOST_URL) . '&p=' . htmlspecialchars(_CONFIG_SITE_PROTOCOL)); ?>',
  299. maxFileSize: uploaderMaxSize,
  300. formData: {},
  301. autoUpload: false,
  302. xhrFields: {
  303. withCredentials: true
  304. },
  305. getNumberOfFiles: function () {
  306. return getTotalRows();
  307. },
  308. previewMaxWidth: 160,
  309. previewMaxHeight: 134,
  310. previewCrop: true,
  311. messages: {
  312. maxNumberOfFiles: '<?php echo str_replace("'", "\'", t('file_upload_maximum_number_of_files_exceeded', 'Maximum number of files exceeded')); ?>',
  313. acceptFileTypes: '<?php echo str_replace("'", "\'", t('file_upload_file_type_not_allowed', 'File type not allowed')); ?>',
  314. maxFileSize: '<?php echo str_replace("'", "\'", t('file_upload_file_is_too_large', 'File is too large')); ?>',
  315. minFileSize: '<?php echo str_replace("'", "\'", t('file_upload_file_is_too_small', 'File is too small')); ?>'
  316. },
  317. maxChunkSize: maxChunkSize,
  318. <?php echo COUNT($acceptedFileTypes) ? ('acceptFileTypes: /(\\.|\\/)(' . str_replace(".", "", implode("|", $acceptedFileTypes) . ')$/i,')) : ''; ?> maxNumberOfFiles: <?php echo (int) $maxFiles; ?>
  319. })
  320. .on('fileuploadadd', function (e, data) {
  321. <?php if(COUNT($acceptedFileTypes)): ?>
  322. var acceptFileTypes = /^(<?php echo str_replace(".", "", implode("|", $acceptedFileTypes)); ?>)$/i;
  323. console.log(data.originalFiles);
  324. for(i in data.originalFiles)
  325. {
  326. fileExtension = data.originalFiles[i]['name'].substr(data.originalFiles[i]['name'].lastIndexOf('.')+1);
  327. if(!acceptFileTypes.test(fileExtension)) {
  328. alert("<?php echo str_replace("'", "\'", t('file_upload_file_type_not_allowed', 'File type not allowed')); ?> (\""+data.originalFiles[i]['name']+"\")");
  329. return false;
  330. }
  331. }
  332. <?php endif; ?>
  333.  
  334. $('#iconUpload #icon_uploader #iconListingWrapper').removeClass('hidden');
  335. $('#iconUpload #icon_uploader #initialiconUploadSection').addClass('hidden');
  336. $('#iconUpload #icon_uploader #initialoconUploadSectionLabel').addClass('hidden');
  337.  
  338. // fix for safari
  339. getTotalRows();
  340. // end safari fix
  341.  
  342. totalRows = getIconTotalRows() + 1;
  343. updateTotalFilesText(totalRows);
  344. })
  345. .on('fileuploadstart', function (e, data) {
  346. icon_uploadComplete = false;
  347.  
  348. // hide/show sections
  349. $('#iconUpload #addIconRow').addClass('hidden');
  350. $('#iconUpload #icon_processQueueSection').addClass('hidden');
  351. $('#iconUpload #icon_processingQueueSection').removeClass('hidden');
  352.  
  353. // hide cancel icons
  354. $('#iconUpload .cancel').hide();
  355. $('#iconUpload .cancel').click(function () {
  356. return false;
  357. });
  358.  
  359. // show faded overlay on images
  360. $('#iconUpload .previewOverlay').addClass('faded');
  361.  
  362. // set timer
  363. icon_startTime = (new Date()).getTime();
  364. })
  365. .on('fileuploadstop', function (e, data) {
  366. // finished uploading
  367. // updateTitleWithProgress(100);
  368. updateProgessText(100, data.total, data.total);
  369. $('#iconUpload #icon_processQueueSection').addClass('hidden');
  370. $('#iconUpload #icon_processingQueueSection').addClass('hidden');
  371. $('#iconUpload #icon_completedSection').removeClass('hidden');
  372.  
  373. // set all remainging pending icons to failed
  374. $('#iconUpload .processingIcon').parent().html('<img src="<?php echo SITE_IMAGE_PATH; ?>/red_error_small.png" width="16" height="16"/>');
  375.  
  376. icon_uploadComplete = true;
  377. sendAdditionalOptions();
  378.  
  379. // setup copy link
  380. setupCopyAllLink();
  381.  
  382. // flag as finished for later on
  383. icon_statusFlag = 'finished';
  384.  
  385. if (typeof (checkShowUploadFinishedWidget) === 'function')
  386. {
  387. checkShowUploadFinishedWidget();
  388. }
  389.  
  390. delay(function() {
  391. $('#icon_hide_modal_btn').click();
  392. }, 1500);
  393. })
  394. .on('fileuploadprogressall', function (e, data) {
  395. // progress bar
  396. var progress = parseInt(data.loaded / data.total * 100, 10);
  397. $('#icon_progress .progress-bar').css(
  398. 'width',
  399. progress + '%'
  400. );
  401.  
  402. // update page title with progress
  403. // updateTitleWithProgress(progress);
  404. updateProgessText(progress, data.loaded, data.total);
  405. })
  406. .on('fileuploadsend', function (e, data) {
  407. // show progress ui elements
  408. $(data['context']).find('.previewOverlay .progressText').removeClass('hidden');
  409. $(data['context']).find('.previewOverlay .progress').removeClass('hidden');
  410. })
  411. .on('fileuploadprogress', function (e, data) {
  412. // progress bar
  413. var progress = parseInt(data.loaded / data.total * 100, 10);
  414.  
  415. // update item progress
  416. $(data['context']).find('.previewOverlay .progressText').html(progress + '%');
  417. $(data['context']).find('.previewOverlay .progress .progress-bar').css('width', progress + '%');
  418. })
  419. .on('fileuploaddone', function (e, data) {
  420.  
  421. // hide faded overlay on images
  422. $(data['context']).find('.previewOverlay').removeClass('faded');
  423.  
  424. // keep a copy of the urls globally
  425. iconUrls.push(data['result'][0]['url']);
  426. iconUrlsHtml.push(data['result'][0]['url_html']);
  427. iconUrlsBBCode.push(data['result'][0]['url_bbcode']);
  428. iconDeleteHashes.push(data['result'][0]['delete_hash']);
  429. iconShortUrls.push(data['result'][0]['short_url']);
  430. iconNames.push(data['result'][0]['name']);
  431.  
  432. var isSuccess = true;
  433. if (data['result'][0]['error'] != null)
  434. {
  435. isSuccess = false;
  436. }
  437.  
  438. var html = '';
  439. html += '<div class="template-download-img';
  440. if (isSuccess == false)
  441. {
  442. html += ' errorText';
  443. }
  444. html += '" ';
  445. if (isSuccess == true)
  446. {
  447. html += 'onClick="window.open(\'' + data['result'][0]['url'] + '\'); return false;"';
  448. }
  449. html += ' title="'+data['result'][0]['name']+'"';
  450. html += '>';
  451.  
  452. if (isSuccess == true)
  453. {
  454. previewUrl = WEB_ROOT+'/themes/cloudable/images/trans_1x1.gif';
  455. if(data['result'][0]['success_result_html'].length > 0)
  456. {
  457. previewUrl = data['result'][0]['success_result_html'];
  458. }
  459.  
  460. html += "<div id='finalThumbWrapper"+data['result'][0]['file_id']+"'></div>";
  461. queueUploaderPreview('finalThumbWrapper'+data['result'][0]['file_id'], previewUrl, data['result'][0]['file_id']);
  462. }
  463. else
  464. {
  465. // @TODO - replace this with an error icon
  466. html += 'Error uploading: ' + data['result'][0]['name'];
  467. }
  468. html += '</div>';
  469.  
  470. // update screen with success content
  471. $(data['context']).replaceWith(html);
  472. processUploaderPreviewQueue();
  473. })
  474. .on('fileuploadfail', function (e, data) {
  475. // hand deletes
  476. if (data.errorThrown == 'abort')
  477. {
  478. $(data['context']).remove();
  479. return true;
  480. }
  481.  
  482. // update screen with error content, ajax issues
  483. var html = '';
  484. html += '<div class="template-download-img errorText">';
  485. html += '<?php echo t('indexjs_error_server_problem_reservo', 'ERROR: There was a server problem when attempting the upload.'); ?>';
  486. html += '</div>';
  487. $(data['context'])
  488. .replaceWith(html);
  489.  
  490. totalRows = getIconTotalRows();
  491. if (totalRows > 0)
  492. {
  493. totalRows = totalRows - 1;
  494. }
  495.  
  496. updateTotalFilesText(totalRows);
  497. });
  498.  
  499. // Open download dialogs via iframes,
  500. // to prevent aborting current uploads:
  501. $('#fileUpload #uploader #files a:not([target^=_blank])').on('click', function (e) {
  502. e.preventDefault();
  503. $('<iframe style="display:none;"></iframe>')
  504. .prop('src', this.href)
  505. .appendTo('body');
  506. });
  507.  
  508. $('#fileUpload #uploader').bind('fileuploadsubmit', function (e, data) {
  509. // The example input, doesn't have to be part of the upload form:
  510. data.formData = {_sessionid: '<?php echo session_id(); ?>', cTracker: '<?php echo MD5(microtime()); ?>', maxChunkSize: maxChunkSize, folderId: fileFolder};
  511. });
  512. <?php
  513. }
  514. ?>
  515.  
  516. $('.showAdditionalOptionsLink').click(function (e) {
  517. // show panel
  518. showAdditionalOptions();
  519.  
  520. // prevent background clicks
  521. e.preventDefault();
  522.  
  523. return false;
  524. });
  525.  
  526. <?php if ($fid != null): ?>
  527. saveAdditionalOptions(true);
  528. <?php endif; ?>
  529. });
  530.  
  531. function queueUploaderPreview(thumbWrapperId, previewImageUrl, previewImageId)
  532. {
  533. uploadPreviewQueuePending[thumbWrapperId] = [previewImageUrl, previewImageId];
  534. }
  535.  
  536. function processUploaderPreviewQueue()
  537. {
  538. // allow only 4 at once
  539. if(getTotalProcessing() >= <?php echo (int)MAX_CONCURRENT_THUMBNAIL_REQUESTS; ?>)
  540. {
  541. return false;
  542. }
  543.  
  544. for(i in uploadPreviewQueuePending)
  545. {
  546. var filename = $('#'+i).parent().attr('title');
  547. $('#'+i).html("<img src='"+uploadPreviewQueuePending[i][0]+"' id='finalThumb"+uploadPreviewQueuePending[i][1]+"' onLoad=\"showUploadThumbCheck('finalThumb"+uploadPreviewQueuePending[i][1]+"', "+uploadPreviewQueuePending[i][1]+");\"/><div class='filename'>"+filename+"</div>");
  548. uploadPreviewQueueProcessing[i] = uploadPreviewQueuePending[i];
  549. delete uploadPreviewQueuePending[i];
  550. return false;
  551. }
  552. }
  553.  
  554. function getTotalPending()
  555. {
  556. total = 0;
  557. for(i in uploadPreviewQueuePending)
  558. {
  559. total++;
  560. }
  561.  
  562. return total;
  563. }
  564.  
  565. function getTotalProcessing()
  566. {
  567. total = 0;
  568. for(i in uploadPreviewQueueProcessing)
  569. {
  570. total++;
  571. }
  572.  
  573. return total;
  574. }
  575.  
  576. function showUploadThumbCheck(thumbId, itemId)
  577. {
  578. $('#'+thumbId).after("<div class='image-upload-thumb-check' style='display: none;'><i class='glyphicon glyphicon-ok'></i></div>");
  579. $('#'+thumbId).parent().find('.image-upload-thumb-check').fadeIn().delay(1000).fadeOut();
  580.  
  581. // finish uploading
  582. if(getTotalPending() == 0 && getTotalProcessing() == 0)
  583. {
  584. // refresh treeview
  585. if (typeof (checkShowUploadFinishedWidget) === 'function')
  586. {
  587. refreshFolderListing();
  588. }
  589. }
  590.  
  591. // trigger the next
  592. delete uploadPreviewQueueProcessing['finalThumbWrapper'+itemId];
  593. processUploaderPreviewQueue();
  594. }
  595.  
  596. function getPreviewExtension(filename)
  597. {
  598. fileExtension = filename.substr(filename.lastIndexOf('.')+1);
  599. if((fileExtension == 'gif') || (fileExtension == 'mng'))
  600. {
  601. return 'gif';
  602. }
  603.  
  604. return 'jpg';
  605. }
  606.  
  607. function setUploadFolderId(folderId)
  608. {
  609. if (typeof (folderId != "undefined") && ($.isNumeric(folderId)))
  610. {
  611. $('#upload_folder_id').val(folderId);
  612. }
  613. else if ($('#nodeId').val() == '-1')
  614. {
  615. $('#upload_folder_id').val('');
  616. }
  617. else if ($.isNumeric($('#nodeId').val()))
  618. {
  619. $('#upload_folder_id').val($('#nodeId').val());
  620. }
  621. else
  622. {
  623. $('#upload_folder_id').val('');
  624. }
  625. saveAdditionalOptions(true);
  626. }
  627.  
  628. function getSelectedFolderId()
  629. {
  630. return $('#upload_folder_id').val();
  631. }
  632.  
  633. function setupCopyAllLink()
  634. {
  635.  
  636. }
  637.  
  638. function updateProgessText(progress, uploadedBytes, totalBytes)
  639. {
  640. // calculate speed & time left
  641. nowTime = (new Date()).getTime();
  642. loadTime = (nowTime - startTime);
  643. if (loadTime == 0)
  644. {
  645. loadTime = 1;
  646. }
  647. loadTimeInSec = loadTime / 1000;
  648. bytesPerSec = uploadedBytes / loadTimeInSec;
  649.  
  650. textContent = '';
  651. textContent += '<?php echo t('indexjs_progress', 'Progress'); ?>: ' + progress + '%';
  652. textContent += ' ';
  653. textContent += '(' + bytesToSize(uploadedBytes, 2) + ' / ' + bytesToSize(totalBytes, 2) + ')';
  654.  
  655. $("#fileupload-progresstextLeft").html(textContent);
  656.  
  657. rightTextContent = '';
  658. rightTextContent += '<?php echo t('indexjs_speed', 'Speed'); ?>: ' + bytesToSize(bytesPerSec, 2) + '<?php echo t('indexjs_speed_ps', 'ps'); ?>. ';
  659. rightTextContent += '<?php echo t('indexjs_remaining', 'Remaining'); ?>: ' + humanReadableTime((totalBytes / bytesPerSec) - (uploadedBytes / bytesPerSec));
  660.  
  661. $("#fileupload-progresstextRight").html(rightTextContent);
  662.  
  663. // progress widget for file manager
  664. if (typeof (updateProgressWidgetText) === 'function')
  665. {
  666. updateProgressWidgetText(textContent);
  667. }
  668. }
  669.  
  670. function getUrlsAsText()
  671. {
  672. urlStr = '';
  673. for (var i = 0; i < fileUrls.length; i++)
  674. {
  675. urlStr += fileUrls[i] + "\n";
  676. }
  677.  
  678. return urlStr;
  679. }
  680.  
  681. function viewFileLinksPopup()
  682. {
  683. fileUrlText = '';
  684. htmlUrlText = '';
  685. bbCodeUrlText = '';
  686. if (fileUrls.length > 0)
  687. {
  688. for (var i = 0; i < fileUrls.length; i++)
  689. {
  690. fileUrlText += fileUrls[i] + "<br/>";
  691. htmlUrlText += fileUrlsHtml[i] + "&lt;br/&gt;<br/>";
  692. bbCodeUrlText += '[URL='+fileUrls[i]+'][IMG]'+WEB_ROOT+'/plugins/filepreviewer/site/thumb.php?s='+fileShortUrls[i] + "&/"+fileNames[i]+"[/IMG][/URL]<br/>";
  693. }
  694. }
  695.  
  696. $('#popupContentUrls').html(fileUrlText);
  697. $('#popupContentHTMLCode').html(htmlUrlText);
  698. $('#popupContentBBCode').html(bbCodeUrlText);
  699.  
  700. jQuery('#fileLinksModal').modal('show', {backdrop: 'static'}).on('shown.bs.modal');
  701. }
  702.  
  703. function showLinkSection(sectionId, ele)
  704. {
  705. $('.link-section').hide();
  706. $('#' + sectionId).show();
  707. $(ele).parent().children('.active').removeClass('active');
  708. $(ele).addClass('active');
  709. $('.file-links-wrapper .modal-header .modal-title').html($(ele).html());
  710. }
  711.  
  712. function selectAllText(el)
  713. {
  714. if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined")
  715. {
  716. var range = document.createRange();
  717. range.selectNodeContents(el);
  718. var sel = window.getSelection();
  719. sel.removeAllRanges();
  720. sel.addRange(range);
  721. }
  722. else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined")
  723. {
  724. var textRange = document.body.createTextRange();
  725. textRange.moveToElementText(el);
  726. textRange.select();
  727. }
  728. }
  729.  
  730. function updateTitleWithProgress(progress)
  731. {
  732. if (typeof (progress) == "undefined")
  733. {
  734. var progress = 0;
  735. }
  736. if (progress == 0)
  737. {
  738. $(document).attr("title", "<?php echo PAGE_NAME; ?> - <?php echo SITE_CONFIG_SITE_NAME; ?>");
  739. }
  740. else
  741. {
  742. $(document).attr("title", progress + "% <?php echo t('indexjs_uploaded', 'Uploaded'); ?> - <?php echo PAGE_NAME; ?> - <?php echo SITE_CONFIG_SITE_NAME; ?>");
  743. }
  744. }
  745.  
  746. function getTotalRows()
  747. {
  748. totalRows = $('#files .template-upload').length;
  749. if (typeof (totalRows) == "undefined")
  750. {
  751. return 0;
  752. }
  753.  
  754. return totalRows;
  755. }
  756. function getIconTotalRows()
  757. {
  758. totalRows = $('#icons .template-upload').length;
  759. if (typeof (totalRows) == "undefined")
  760. {
  761. return 0;
  762. }
  763.  
  764. return totalRows;
  765. }
  766.  
  767. function updateTotalFilesText(total)
  768. {
  769. // removed for now, might be useful in some form in the future
  770. //$('#uploadButton').html('upload '+total+' files');
  771. }
  772.  
  773. function setRowClasses()
  774. {
  775. // removed for now, might be useful in some form in the future
  776. //$('#files tr').removeClass('even');
  777. //$('#files tr').removeClass('odd');
  778. //$('#files tr:even').addClass('odd');
  779. //$('#files tr:odd').addClass('even');
  780. }
  781.  
  782. function showAdditionalInformation(ele)
  783. {
  784. // block parent clicks from being processed on additional information
  785. $('.sliderContent table').unbind();
  786. $('.sliderContent table').click(function (e) {
  787. e.stopPropagation();
  788. });
  789.  
  790. // make sure we've clicked on a new element
  791. if (lastEle == ele)
  792. {
  793. // close any open sliders
  794. $('.sliderContent').slideUp('fast');
  795. // remove row highlighting
  796. $('.sliderContent').parent().parent().removeClass('rowSelected');
  797. lastEle = null;
  798. return false;
  799. }
  800. lastEle = ele;
  801.  
  802. // close any open sliders
  803. $('.sliderContent').slideUp('fast');
  804.  
  805. // remove row highlighting
  806. $('.sliderContent').parent().parent().removeClass('rowSelected');
  807.  
  808. // select row and popup content
  809. $(ele).addClass('rowSelected');
  810.  
  811. // set the position of the sliderContent div
  812. $(ele).find('.sliderContent').css('left', 0);
  813. $(ele).find('.sliderContent').css('top', ($(ele).offset().top + $(ele).height()) - $('.file-upload-wrapper .modal-content').offset().top);
  814. $(ele).find('.sliderContent').slideDown(400, function () {
  815. });
  816.  
  817. return false;
  818. }
  819.  
  820. function saveFileToFolder(ele)
  821. {
  822. // get variables
  823. shortUrl = $(ele).closest('.sliderContent').children('.shortUrlHidden').val();
  824. folderId = $(ele).val();
  825.  
  826. // send ajax request
  827. var request = $.ajax({
  828. url: "<?php echo CORE_AJAX_WEB_ROOT; ?>/_update_folder.ajax.php",
  829. type: "POST",
  830. data: {shortUrl: shortUrl, folderId: folderId},
  831. dataType: "html"
  832. });
  833. }
  834.  
  835. function showAdditionalOptions(hide)
  836. {
  837. if (typeof (hide) == "undefined")
  838. {
  839. hide = false;
  840. }
  841.  
  842. if (($('#additionalOptionsWrapper').is(":visible")) || (hide == true))
  843. {
  844. $('#additionalOptionsWrapper').slideUp();
  845. }
  846. else
  847. {
  848. $('#additionalOptionsWrapper').slideDown();
  849. }
  850. }
  851.  
  852. function saveAdditionalOptions(hide)
  853. {
  854. if (typeof (hide) == "undefined")
  855. {
  856. hide = false;
  857. }
  858.  
  859. // save values globally
  860. fileToEmail = $('#send_via_email').val();
  861. filePassword = $('#set_password').val();
  862. fileCategory = $('#set_category').val();
  863. fileFolder = $('#upload_folder_id').val();
  864.  
  865. // attempt ajax to save
  866. processAddtionalOptions();
  867.  
  868. // hide
  869. showAdditionalOptions(hide);
  870. }
  871.  
  872. function processAddtionalOptions()
  873. {
  874. // make sure the uploads have completed
  875. if (uploadComplete == false)
  876. {
  877. return false;
  878. }
  879.  
  880. return sendAdditionalOptions();
  881. }
  882.  
  883. function sendAdditionalOptions()
  884. {
  885. // make sure we have some urls
  886. if (fileDeleteHashes.length == 0)
  887. {
  888. return false;
  889. }
  890.  
  891. $.ajax({
  892. type: "POST",
  893. url: "<?php echo WEB_ROOT; ?>/ajax/_update_file_options.ajax.php",
  894. data: {fileToEmail: fileToEmail, filePassword: filePassword, fileCategory: fileCategory, fileDeleteHashes: fileDeleteHashes, fileShortUrls: fileShortUrls, fileFolder: fileFolder}
  895. }).done(function (msg) {
  896. originalFolder = fileFolder;
  897. if(originalFolder == '')
  898. {
  899. originalFolder = '-1';
  900. }
  901. fileToEmail = '';
  902. filePassword = '';
  903. fileCategory = '';
  904. fileFolder = '';
  905. fileDeleteHashes = [];
  906. if (typeof updateStatsViaAjax === "function")
  907. {
  908. //updateStatsViaAjax();
  909. }
  910. if (typeof refreshFileListing === "function")
  911. {
  912. //refreshFileListing();
  913. loadImages(originalFolder);
  914. }
  915.  
  916. });
  917. }
  918. </script>
  919.  
  920. <?php
  921. if ($showUploads == true) {
  922. ?>
  923. <script>
  924. function getIcon(){
  925. icon_statusFlag = "pending";
  926. $("#icons").empty();
  927. $('#iconUpload #icon_uploader #iconListingWrapper').addClass('hidden');
  928. $('#iconUpload #icon_uploader #initialiconUploadSection').removeClass('hidden');
  929. $('#iconUpload #icon_uploader #initialoconUploadSectionLabel').removeClass('hidden');
  930. $('#iconUpload #addIconRow').removeClass('hidden');
  931. $('#iconUpload #icon_processQueueSection').removeClass('hidden');
  932. $('#iconeUpload #icon_processingQueueSection').addClass('hidden');
  933. $('#icon_completedSection').addClass('hidden');
  934. $("#addIconRow").removeClass("hidden");
  935. // console.log("im now re-initializing ");
  936. // $("#iconUploadWrapper").html($("em_iconUploadWrapper").html());
  937. // init_icon_uploader();
  938. showIconUploaderPopup('');
  939. }
  940. function dontAddIcon(){
  941. $("#addFolderIcon input[type='radio']")[0].checked = true;
  942. $("#addFolderIcon input[type='radio']")[1].checked = false;
  943. }
  944. function findUrls(text)
  945. {
  946. var source = (text || '').toString();
  947. var urlArray = [];
  948. var url;
  949. var matchArray;
  950.  
  951. // standardise
  952. source = source.replace("\n\r", "\n");
  953. source = source.replace("\r", "\n");
  954. source = source.replace("\n\n", "\n");
  955.  
  956. // split apart urls
  957. source = source.split("\n");
  958.  
  959. // find urls
  960. var regexToken = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~()_|\s!:,.;'\[\]]*[-A-Z0-9+&@#\/%=~()_'|\s])/ig;
  961.  
  962. // validate urls
  963. for(i in source)
  964. {
  965. url = source[i];
  966. if(url.match(regexToken))
  967. {
  968. urlArray.push(url);
  969. }
  970. }
  971.  
  972. return urlArray;
  973. }
  974.  
  975. var currentUrlItem = 0;
  976. var totalUrlItems = 0;
  977. function urlUploadFiles()
  978. {
  979. // get textarea contents
  980. urlList = $('#urlList').val();
  981. if (urlList.length == 0)
  982. {
  983. alert('<?php echo str_replace("'", "\'", t('please_enter_the_urls_to_start', 'Please enter the urls to start.')); ?>');
  984. return false;
  985. }
  986.  
  987. // get file list as array
  988. urlList = findUrls(urlList);
  989. totalUrlItems = urlList.length;
  990.  
  991. // first check to make sure we have some urls
  992. if (urlList.length == 0)
  993. {
  994. alert('<?php echo str_replace("'", "\'", t('no_valid_urls_found_please_make_sure_any_start_with_http_or_https', 'No valid urls found, please make sure any start with http or https and try again.')); ?>');
  995. return false;
  996. }
  997.  
  998. // make sure the user hasn't entered more than is permitted
  999. if (urlList.length > <?php echo (int) $maxPermittedUrls; ?>)
  1000. {
  1001. alert('<?php echo str_replace("'", "\'", t('you_can_not_add_more_than_x_urls_at_once', 'You can not add more than [[[MAX_URLS]]] urls at once.', array('MAX_URLS' => (int) $maxPermittedUrls))); ?>');
  1002. return false;
  1003. }
  1004.  
  1005. // create table listing
  1006. html = '';
  1007. for (i in urlList)
  1008. {
  1009. html += '<tr id="rowId' + i + '"><td class="cancel"><a href="#" onClick="return false;"><img src="<?php echo SITE_IMAGE_PATH; ?>/processing_small.gif" class="processingIcon" height="16" width="16" alt="<?php echo str_replace("\"", "\\\"", t('processing', 'processing')); ?>"/>';
  1010. html += '</a></td><td class="name" colspan="3">' + urlList[i] + '&nbsp;&nbsp;<span class="progressWrapper"><span class="progressText"></span></span></td></tr>';
  1011. }
  1012. $('#urlUpload #urls').html(html);
  1013.  
  1014. // show file uploader screen
  1015. $('#urlUpload #urlFileListingWrapper').removeClass('hidden');
  1016. $('#urlUpload #urlFileUploader').addClass('hidden');
  1017.  
  1018. // loop over urls and try to retrieve the file
  1019. startRemoteUrlDownload(currentUrlItem);
  1020.  
  1021. }
  1022.  
  1023. function updateUrlProgress(data)
  1024. {
  1025. $.each(data, function (key, value) {
  1026. switch (key)
  1027. {
  1028. case 'progress':
  1029. percentageDone = parseInt(value.loaded / value.total * 100, 10);
  1030.  
  1031. textContent = '';
  1032. textContent += 'Progress: ' + percentageDone + '%';
  1033. textContent += ' ';
  1034. textContent += '(' + bytesToSize(value.loaded, 2) + ' / ' + bytesToSize(value.total, 2) + ')';
  1035.  
  1036. progressText = textContent;
  1037. $('#rowId' + value.rowId + ' .progressText').html(progressText);
  1038. break;
  1039. case 'done':
  1040. handleUrlUploadSuccess(value);
  1041.  
  1042. if ((currentUrlItem + 1) < totalUrlItems)
  1043. {
  1044. currentUrlItem = currentUrlItem + 1;
  1045. startRemoteUrlDownload(currentUrlItem);
  1046. }
  1047. break;
  1048. }
  1049. });
  1050. }
  1051.  
  1052. function startRemoteUrlDownload(index)
  1053. {
  1054. // show progress
  1055. $('#urlUpload .urlFileListingWrapper .processing-button').removeClass('hidden');
  1056.  
  1057. // get file list as array
  1058. urlList = $('#urlList').val();
  1059. urlList = findUrls(urlList);
  1060.  
  1061. // create iframe to track progress
  1062. var iframe = $('<iframe src="javascript:false;" style="display:none;"></iframe>');
  1063. iframe
  1064. .prop('src', '<?php echo crossSiteAction::appendUrl(file::getUploadUrl() . "/core/page/ajax/url_upload_handler.ajax.php"); ?>&rowId=' + index + '&url=' + encodeURIComponent(urlList[index]) + '&folderId=' + fileFolder)
  1065. .appendTo(document.body);
  1066. }
  1067.  
  1068. function handleUrlUploadSuccess(data)
  1069. {
  1070. isSuccess = true;
  1071. if (data.error != null)
  1072. {
  1073. isSuccess = false;
  1074. }
  1075.  
  1076. html = '';
  1077. html += '<tr class="template-download';
  1078. if (isSuccess == false)
  1079. {
  1080. html += ' errorText';
  1081. }
  1082. html += '" onClick="return showAdditionalInformation(this);">'
  1083. if (isSuccess == false)
  1084. {
  1085. // add result html
  1086. html += data.error_result_html;
  1087. }
  1088. else
  1089. {
  1090. // add result html
  1091. html += data.success_result_html;
  1092.  
  1093. // keep a copy of the urls globally
  1094. fileUrls.push(data.url);
  1095. fileUrlsHtml.push(data.url_html);
  1096. fileUrlsBBCode.push(data.url_bbcode);
  1097. fileDeleteHashes.push(data.delete_hash);
  1098. fileShortUrls.push(data.short_url);
  1099. }
  1100.  
  1101. html += '</tr>';
  1102.  
  1103. $('#rowId' + data.rowId).replaceWith(html);
  1104.  
  1105. if (data.rowId == urlList.length - 1)
  1106. {
  1107. // show footer
  1108. $('#urlUpload .urlFileListingWrapper .processing-button').addClass('hidden');
  1109. $('#urlUpload .fileSectionFooterText').removeClass('hidden');
  1110.  
  1111. // set additional options
  1112. sendAdditionalOptions();
  1113.  
  1114. // setup copy link
  1115. setupCopyAllLink();
  1116.  
  1117. delay(function() {
  1118. $('#hide_modal_btn').click();
  1119. }, 1500);
  1120. }
  1121. }
  1122. </script>
  1123. <?php
  1124. }
  1125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement