SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/tinymce4/upload.php

  1. <?php
  2. /*
  3.  * kate: tab-width 4; indent-width 4; space-indent on; word-wrap off; word-wrap-column 120;
  4.  * :tabSize=4:indentSize=4:noTabs=true:wrap=false:maxLineLen=120:mode=php:
  5.  *
  6.  * Copyright (C) 2015 Karmabunny Pty Ltd.
  7.  *
  8.  * This file is a part of SproutCMS.
  9.  *
  10.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  11.  * of the GNU General Public License as published by the Free Software Foundation, either
  12.  * version 3 of the License, or (at your option) any later version.
  13.  *
  14.  * For more information, visit <http://getsproutcms.com>.
  15.  */
  16.  
  17. use Sprout\Helpers\Csrf;
  18. use Sprout\Helpers\Enc;
  19. use Sprout\Helpers\Form;
  20. ?>
  21.  
  22. <link href="ROOT/sprout/media/css/admin_layout.css" rel="stylesheet">
  23.  
  24. <?php echo $toolbar; ?>
  25.  
  26. <div class="info">
  27. Upload files using the form below.
  28. </div>
  29.  
  30. <div class="emu-mce-wrapper">
  31. <form action="SITE/admin/call/file/quickUpload" method="post" target="quick-upload" enctype="multipart/form-data" id="mce-upload">
  32. <?= Csrf::token(); ?>
  33.  
  34. <?php Form::nextFieldDetails('File', true); ?>
  35. <?= Form::chunkedUpload('file', [], ['sess_key' => 'admin_quick_upload']); ?>
  36.  
  37.  
  38. <?php Form::nextFieldDetails('Name', true); ?>
  39. <?= Form::text('name'); ?>
  40.  
  41.  
  42. <?php Form::nextFieldDetails('Category', true); ?>
  43. <?= Form::dropdown('category_id', [], $cats); ?>
  44.  
  45. <input class="button" type="submit" value="Upload">
  46. <input type="hidden" name="type" value="<?= Enc::html(@$_GET['type']); ?>">
  47. </form>
  48. </div>
  49.  
  50. <iframe name="quick-upload" id="quick-upload" style="display: none;"></iframe>
  51.  
  52.  
  53.  
  54. <script type="text/javascript">
  55. $(document).ready(function() {
  56. $('#quick-upload').on("load", function() {
  57. var nfo = $('#quick-upload').contents().find('div').text();
  58. if (nfo == '') return;
  59.  
  60. nfo = $.parseJSON(nfo);
  61.  
  62. if (typeof(nfo.error) != 'undefined') {
  63. alert(nfo.error);
  64. return;
  65. }
  66.  
  67. if (nfo.type != <?php echo $f_type; ?>) {
  68. alert('Your file has been uploaded successfully, but is the wrong type for this field.');
  69. return;
  70. }
  71.  
  72. <?php if ($_GET['type'] == 'image'): ?>
  73. window.location = ROOT + 'tinymce4/image_size/' + nfo.id;
  74. <?php else: ?>
  75. TinyMCE4.setUrl(nfo.rel_url);
  76. TinyMCE4.closePopup();
  77. <?php endif; ?>
  78. });
  79.  
  80. $('#mce-upload .emu-mce-upload').change(function() {
  81. if ($('input[name="name"]').val() == '') {
  82. var newname = $(this).val();
  83.  
  84. newname = newname.replace(/[_-]/g, ' '); // underscore to space
  85. newname = newname.replace(/\.[a-z]{3,4}$/i, ''); // remove ext
  86. newname = newname.replace('C:\\fakepath\\', ''); // chrome fake paths
  87. newname = newname.charAt(0).toUpperCase() + newname.slice(1); // Uppercase first
  88.  
  89. $('input[name="name"]').val(newname);
  90. }
  91. });
  92.  
  93. $('#mce-upload select[name="category_id"]').change(function() {
  94. if ($(this).val() == '_new') {
  95. $(this).parent().html('<input name="category_new" class="emu-mce-input">');
  96. $('#mce-upload input[name="category_new"]').select();
  97. }
  98. }).change();
  99. });
  100. </script>
  101.