PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/web/concrete/tools/files/import.php

https://bitbucket.org/hudsonite/concrete5
PHP | 317 lines | 254 code | 56 blank | 7 comment | 17 complexity | 8689f858e791f1910d53575346fbeb8f MD5 | raw file
  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. $u = new User();
  4. $ch = Loader::helper('concrete/file');
  5. $h = Loader::helper('concrete/interface');
  6. $form = Loader::helper('form');
  7. $fp = FilePermissions::getGlobal();
  8. if (!$fp->canAddFiles()) {
  9. die(t("Unable to add files."));
  10. }
  11. $types = $fp->getAllowedFileExtensions();
  12. $searchInstance = Loader::helper('text')->entities($_REQUEST['searchInstance']);
  13. $ocID = 0;
  14. if (Loader::helper('validation/numbers')->integer($_REQUEST['ocID'])) {
  15. $ocID = $_REQUEST['ocID'];
  16. }
  17. $types = $ch->serializeUploadFileExtensions($types);
  18. $valt = Loader::helper('validation/token');
  19. ?>
  20. <div class="ccm-ui">
  21. <ul class="tabs" id="ccm-file-import-tabs">
  22. <li class="active"><a href="javascript:void(0)" id="ccm-file-add-multiple"><?=t('Upload Multiple')?></a></li>
  23. <li><a href="javascript:void(0)" id="ccm-file-add-incoming"><?=t('Add Incoming')?></a></li>
  24. <li><a href="javascript:void(0)" id="ccm-file-add-remote"><?=t('Add Remote Files')?></a></li>
  25. </ul>
  26. <script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.js"></script>
  27. <script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.handlers.js"></script>
  28. <script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.fileprogress.js"></script>
  29. <script type="text/javascript" src="<?=ASSETS_URL_JAVASCRIPT?>/swfupload/swfupload.queue.js"></script>
  30. <script type="text/javascript">
  31. var ccm_fiActiveTab = "ccm-file-add-multiple";
  32. $("#ccm-file-import-tabs a").click(function() {
  33. $("li.active").removeClass('active');
  34. var activesection = ccm_fiActiveTab.substring(13);
  35. var wind = $(this).parentsUntil('.ui-dialog').parent();
  36. var bp = wind.find('.ui-dialog-buttonpane');
  37. $("#dialog-buttons-" + activesection).html(bp.html());
  38. $("#" + ccm_fiActiveTab + "-tab").hide();
  39. ccm_fiActiveTab = $(this).attr('id');
  40. if (ccm_fiActiveTab != 'ccm-file-add-multiple') {
  41. $('#ccm-file-add-multiple-outer').css('visibility', 'hidden');
  42. } else {
  43. $('#ccm-file-add-multiple-outer').css('visibility', 'visible');
  44. }
  45. $(this).parent().addClass("active");
  46. $("#" + ccm_fiActiveTab + "-tab").show();
  47. var section = $(this).attr('id').substring(13);
  48. var buttons = $("#dialog-buttons-" + section);
  49. bp.html(buttons.html());
  50. });
  51. </script>
  52. <div style="position: absolute; top: 107px; right: 15px;" id="ccm-file-add-multiple-outer"><span id="ccm-file-add-multiple-spanButtonPlaceHolder"></span></div>
  53. <div id="ccm-file-add-multiple-tab">
  54. <div style="float: right">
  55. <div class="help-block" style="margin-top: 11px">
  56. <?=t('Upload Max: %s.', ini_get('upload_max_filesize'))?>
  57. <?=t('Post Max: %s', ini_get('post_max_size'))?>
  58. </div>
  59. </div>
  60. <h3><?php echo t('Upload Multiple Files')?></h3>
  61. <?
  62. $umf = ini_get('upload_max_filesize');
  63. $umf = str_ireplace(array('M', 'K', 'G'), array(' MB', 'KB', ' GB'), $umf);
  64. ?>
  65. <script type="text/javascript">
  66. var swfu;
  67. $(function() {
  68. $("#ccm-file-manager-multiple-remote").submit(function() {
  69. $(this).attr('target', ccm_alProcessorTarget);
  70. });
  71. $("#ccm-file-manager-multiple-incoming").submit(function() {
  72. $(this).attr('target', ccm_alProcessorTarget);
  73. });
  74. swfu = new SWFUpload({
  75. flash_url : "<?=ASSETS_URL_FLASH?>/swfupload/swfupload.swf",
  76. upload_url : "<?=REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/multiple",
  77. post_params: {'ccm-session' : "<?php echo session_id(); ?>",'searchInstance': '<?=$searchInstance?>', 'ocID' : '<?=$ocID?>', 'ccm_token' : '<?=$valt->generate("upload")?>'},
  78. file_size_limit : "<?=$umf?>",
  79. /* file_types : "<?=$types?>", */
  80. button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
  81. file_types_description : "<?php echo t('All Files') ?>",
  82. file_upload_limit : 100,
  83. button_cursor: SWFUpload.CURSOR.HAND,
  84. file_queue_limit : 0,
  85. custom_settings : {
  86. progressTarget : "ccm-file-add-multiple-list",
  87. cancelButtonId : "ccm-file-add-multiple-btnCancel"
  88. },
  89. debug: false,
  90. // Button settings
  91. button_image_url: "<?=ASSETS_URL_IMAGES?>/icons/add_file_swfupload.png", // Relative to the Flash file
  92. button_width: "80",
  93. button_text: '<span class="uploadButtonText"><?=t('Add Files')?><\/span>',
  94. button_height: "16",
  95. button_text_left_padding: 18,
  96. button_text_style: ".uploadButtonText {background-color: #eee; font-family: Helvetica Neue, Helvetica, Arial}",
  97. button_placeholder_id: "ccm-file-add-multiple-spanButtonPlaceHolder",
  98. // The event handler functions are defined in handlers.js
  99. // wrapped function with apply are so c5 can do anything special it needs to
  100. // some functions needed to be overridden completly
  101. file_queued_handler : function (file) {
  102. fileQueued.apply(this,[file]);
  103. },
  104. file_queue_error_handler : fileQueueError,
  105. file_dialog_complete_handler : function(numFilesSelected, numFilesQueued){
  106. try {
  107. if (numFilesSelected > 0) {
  108. document.getElementById(this.customSettings.cancelButtonId).disabled = false;
  109. }
  110. //this.startUpload();
  111. } catch (ex) {
  112. this.debug(ex);
  113. }
  114. },
  115. upload_start_handler : uploadStart,
  116. upload_progress_handler : function(file, bytesLoaded, bytesTotal){
  117. try {
  118. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  119. var progress = new FileProgress(file, this.customSettings.progressTarget);
  120. progress.setProgress(percent);
  121. progress.setStatus("<?php echo t('Uploading...')?> ("+percent+"%)");
  122. } catch (ex) {
  123. this.debug(ex);
  124. }
  125. },
  126. upload_error_handler : uploadError,
  127. upload_success_handler : function(file, serverData){
  128. try {
  129. eval('serverData = '+serverData);
  130. var progress = new FileProgress(file, this.customSettings.progressTarget);
  131. if (serverData['error'] == true) {
  132. progress.setError(serverData['message']);
  133. } else {
  134. progress.setComplete();
  135. }
  136. progress.toggleCancel(false);
  137. if(serverData['id']){
  138. if(!this.highlight){this.highlight = [];}
  139. this.highlight.push(serverData['id']);
  140. if(ccm_uploadedFiles && serverData['id']!='undefined') ccm_uploadedFiles.push(serverData['id']);
  141. }
  142. } catch (ex) {
  143. this.debug(ex);
  144. }
  145. },
  146. upload_complete_handler : uploadComplete,
  147. queue_complete_handler : function(file){
  148. // queueComplete() from swfupload.handlers.js
  149. if (ccm_uploadedFiles.length > 0) {
  150. queueComplete();
  151. jQuery.fn.dialog.closeTop();
  152. setTimeout(function() {
  153. ccm_filesUploadedDialog('<?=$searchInstance?>');
  154. }, 100);
  155. }
  156. }
  157. });
  158. });
  159. </script>
  160. <style type="text/css">
  161. </style>
  162. <form id="form1" action="<?=DISPATCHER_FILENAME?>" method="post" enctype="multipart/form-data">
  163. <table border="0" width="100%" cellspacing="0" cellpadding="0" id="ccm-file-add-multiple-list" class="table table-striped">
  164. <tr>
  165. <th colspan="2"><?=t('Upload Queue');?></th>
  166. </tr>
  167. </table>
  168. <div class="ccm-spacer">&nbsp;</div><br/>
  169. <!--
  170. <div>
  171. <div id="ccm-file-add-multiple-results-wrapper">
  172. <div style="width: 100px; float: right; text-align: right"></div>
  173. <div id="ccm-file-add-multiple-results">0 <?=t('Files Uploaded');?></div>
  174. <div class="ccm-spacer">&nbsp;</div>
  175. </div>
  176. </div>
  177. <br style="clear:left;"/> //-->
  178. <div class="dialog-buttons">
  179. <?
  180. print $h->button_js(t('Start Uploads'), 'swfu.startUpload()', 'right', 'primary');
  181. print $h->button_js(t('Cancel'), 'swfu.cancelQueue()', 'left', null,array('id'=>'ccm-file-add-multiple-btnCancel', 'disabled' => 1));
  182. ?>
  183. </div>
  184. <? // don't ask why we have to this. it's because we're swapping out buttons with the tabs. Ugh. ?>
  185. <div style="display: none" id="dialog-buttons-multiple">
  186. <?
  187. print $h->button_js(t('Start Uploads'), 'swfu.startUpload()', 'right', 'primary');
  188. print $h->button_js(t('Cancel'), 'swfu.cancelQueue()', 'left', null,array('id'=>'ccm-file-add-multiple-btnCancel', 'disabled' => 1));
  189. ?>
  190. </div>
  191. <div style="display: none" id="dialog-buttons-incoming">
  192. <?
  193. print $form->submit('submit', t('Import Files'), array('onclick' => "jQuery.fn.dialog.showLoader();$('#ccm-file-manager-multiple-incoming').submit()", 'class' => 'primary ccm-button-right'));
  194. ?>
  195. </div>
  196. <div id="dialog-buttons-remote" style="display: none">
  197. <?
  198. print $form->submit('submit', t('Import Files'), array('onclick' => "jQuery.fn.dialog.showLoader();$('#ccm-file-manager-multiple-remote').submit()", 'class' => 'primary ccm-button-right'));
  199. ?>
  200. </div>
  201. </form>
  202. <div class="ccm-spacer">&nbsp;</div>
  203. <br/>
  204. </div>
  205. <?php
  206. $valt = Loader::helper('validation/token');
  207. $fh = Loader::helper('validation/file');
  208. Loader::library('file/types');
  209. $incoming_contents = $ch->getIncomingDirectoryContents();
  210. ?>
  211. <div id="ccm-file-add-incoming-tab" style="display: none">
  212. <h3><?=t('Add from Incoming Directory')?></h3>
  213. <?php if(!empty($incoming_contents)) { ?>
  214. <form id="ccm-file-manager-multiple-incoming" method="post" action="<?=REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/incoming">
  215. <input type="hidden" name="searchInstance" value="<?=$searchInstance?>" />
  216. <input type="hidden" name="ocID" value="<?=$ocID?>" />
  217. <table id="incoming_file_table" class="table table-bordered" width="100%" cellpadding="0" cellspacing="0">
  218. <tr>
  219. <th width="10%" valign="middle" class="center theader"><input type="checkbox" id="check_all_imports" name="check_all_imports" onclick="ccm_alSelectMultipleIncomingFiles(this);" value="" /></th>
  220. <th width="20%" valign="middle" class="center theader"></th>
  221. <th width="45%" valign="middle" class="theader"><?=t('Filename')?></th>
  222. <th width="25%" valign="middle" class="center theader"><?=t('Size')?></th>
  223. </tr>
  224. <?php foreach($incoming_contents as $filenum=>$file_array) {
  225. $ft = FileTypeList::getType($file_array['name']);
  226. ?>
  227. <tr>
  228. <td width="10%" valign="middle" class="center">
  229. <?php if($fh->extension($file_array['name'])) { ?>
  230. <input type="checkbox" name="send_file<?=$filenum?>" class="ccm-file-select-incoming" value="<?=$file_array['name']?>" />
  231. <?php } ?>
  232. </td>
  233. <td width="20%" valign="middle" class="center"><?=$ft->getThumbnail(1)?></td>
  234. <td width="45%" valign="middle"><?=$file_array['name']?></td>
  235. <td width="25%" valign="middle" class="center"><?=$file_array['size']?><?=t('Kb')?></td>
  236. </tr>
  237. <?php } ?>
  238. </table>
  239. <input type="checkbox" name="removeFilesAfterPost" value="1" />
  240. <?=t('Remove files from incoming/ directory.')?>
  241. <?=$valt->output('import_incoming');?>
  242. </form>
  243. <?php } else { ?>
  244. <?=t('No files found in %s', DIR_FILES_INCOMING)?>
  245. <?php } ?>
  246. </div>
  247. <div id="ccm-file-add-remote-tab" style="display: none">
  248. <h3><?=t('Add From Remote URL')?></h3>
  249. <form method="POST" id="ccm-file-manager-multiple-remote" action="<?=REL_DIR_FILES_TOOLS_REQUIRED?>/files/importers/remote">
  250. <input type="hidden" name="searchInstance" value="<?=$searchInstance?>" />
  251. <input type="hidden" name="ocID" value="<?=$ocID?>" />
  252. <p><?=t('Enter URL to valid file(s)')?></p>
  253. <?=$valt->output('import_remote');?>
  254. <?=$form->text('url_upload_1', array('style' => 'width:455px'))?><br/><br/>
  255. <?=$form->text('url_upload_2', array('style' => 'width:455px'))?><br/><br/>
  256. <?=$form->text('url_upload_3', array('style' => 'width:455px'))?><br/><br/>
  257. <?=$form->text('url_upload_4', array('style' => 'width:455px'))?><br/><br/>
  258. <?=$form->text('url_upload_5', array('style' => 'width:455px'))?><br/>
  259. </form>
  260. </div>
  261. </div>