SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/admin/file_add_dragdrop_form.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. use Sprout\Helpers\Csrf;
  17. use Sprout\Helpers\Enc;
  18. use Sprout\Helpers\File;
  19. use Sprout\Helpers\FileConstants;
  20. use Sprout\Helpers\Form;
  21.  
  22.  
  23. Form::setData($data);
  24. Form::setErrors($errors);
  25. ?>
  26.  
  27.  
  28. <?php if (!empty($image_too_large)): ?>
  29. <script type="text/javascript">
  30. $(document).ready(function(){
  31. $(".file-upload__item__feedback__response--error").closest('.file-upload__item').addClass("file-upload__item--completed");
  32. });
  33. </script>
  34. <div class="file-upload__item__feedback__response file-upload__item__feedback__response--error">
  35. <p class="file-upload__item__feedback__error__text">This image is too large</p>
  36. <p class="file-upload__item__feedback__error__text">
  37. You may wish to use
  38. <a target="_blank" href="http://www.karmabunny.com.au/our_work/open_source/resiz_o_tron">Resize-o-Tron</a>
  39. to shrink this image to a suitable size.
  40. </p>
  41. </div>
  42. <?php return; ?>
  43. <?php endif; ?>
  44.  
  45.  
  46. <form action="admin/call/file/ajaxDragdropSave" method="post">
  47. <?= Csrf::token(); ?>
  48. <input type="hidden" name="tmp_file" value="<?php echo Enc::html($tmp_file); ?>">
  49. <input type="hidden" name="orig_name" value="<?php echo Enc::html($orig_file['name']); ?>">
  50.  
  51. <div class="columns">
  52. <div class="column column-10">
  53. <!-- Form fields column -->
  54.  
  55. <div class="-clearfix">
  56. <div class="col col--one-half">
  57. <?php
  58. Form::nextFieldDetails('Name', true);
  59. echo Form::text('name');
  60. ?>
  61. </div>
  62.  
  63. <div class="col col--one-half">
  64. <?php
  65. Form::nextFieldDetails('Category', true);
  66. echo Form::dropdown('category_id', [], $categories);
  67. ?>
  68. </div>
  69. </div>
  70.  
  71. <div class="-clearfix">
  72. <?php if ($data['type'] == FileConstants::TYPE_DOCUMENT): ?>
  73. <div class="col col--one-half">
  74. <?php
  75. Form::nextFieldDetails('Date published', false);
  76. echo Form::datepicker('date_published');
  77. ?>
  78. </div>
  79. <?php endif; ?>
  80.  
  81. <div class="col col--one-half">
  82. <?php
  83. Form::nextFieldDetails('Author', false);
  84. echo Form::autocomplete('author', [], ['url' => 'admin/call/file/ajaxAuthorLookup', 'save_id' => false]);
  85. ?>
  86. </div>
  87.  
  88. <?php if ($data['type'] == FileConstants::TYPE_DOCUMENT and !empty($document_types)): ?>
  89. <div class="col col--one-half">
  90. <?php
  91. Form::nextFieldDetails('Document type', false);
  92. echo Form::dropdown('document_type', [], $document_types);
  93. ?>
  94. </div>
  95. <?php endif; ?>
  96.  
  97. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?>
  98. <div class="col col--one-half">
  99. <?php
  100. Form::nextFieldDetails('Embed author credit in image', false);
  101. echo Form::dropdown('embed_author', [], [1 => 'Yes', 0 => 'No']);
  102. ?>
  103. </div>
  104. <?php endif; ?>
  105. </div>
  106.  
  107. <?php if ($data['type'] == FileConstants::TYPE_IMAGE and !empty($shrink_original)): ?>
  108. <?php
  109. Form::nextFieldDetails('This image is very large. Is it a specifically cropped banner?', false);
  110. echo Form::dropdown('shrink_original', [], [
  111. 1 => 'No, this is a normal photo or other image',
  112. 0 => 'Yes, this is a banner image, cropped to specific dimensions',
  113. ]);
  114. ?>
  115. <?php endif; ?>
  116.  
  117. <p>
  118. <button type="submit" class="button button-green icon-after icon-save">Save</button>
  119. <button class="file-upload__item__remove" type="button"><span class="file-upload__item__remove__text">Remove</span></button>
  120. </p>
  121.  
  122. <!-- END form fields column -->
  123. </div>
  124. <div class="column column-2">
  125. <!-- Preview column -->
  126.  
  127. <div class="field-element">
  128. <div class="field-label"><?php echo Enc::html(FileConstants::$type_names[$data['type']]); ?></div>
  129. <div class="field-input">
  130. <?php
  131. if (!empty($shrunk_img)) {
  132. echo Enc::html($shrunk_img['original_width']), ' &times; ', Enc::html($shrunk_img['original_height']);
  133. } else {
  134. echo File::humanSize($size_bytes);
  135. }
  136. ?>
  137. </div>
  138. </div>
  139.  
  140. <?php
  141. if (!empty($shrunk_img)) {
  142. echo '<img class="file-upload__preview-img" src="data:image/png;base64,', Enc::html($shrunk_img['encoded_thumbnail']), '">';
  143. }
  144. ?>
  145.  
  146. <?php if ($data['type'] == FileConstants::TYPE_SOUND): ?>
  147. <audio class="file-upload__preview-sound" src="admin/call/file/downloadTemp/<?= Enc::html($tmp_file); ?>"
  148. style="width: 100%;" controls
  149. ></audio>
  150. <?php endif; ?>
  151.  
  152. <?php if ($data['type'] == FileConstants::TYPE_VIDEO): ?>
  153. <video class="file-upload__preview-video" src="admin/call/file/downloadTemp/<?= Enc::html($tmp_file); ?>"
  154. style="width: 100%;" controls
  155. ></video>
  156. <?php endif; ?>
  157.  
  158. <!-- END preview column -->
  159. </div>
  160. </div>
  161.  
  162. <script type="text/javascript">
  163. $(document).find('input[name="tmp_file"][value="<?= Enc::html($tmp_file); ?>"]').closest('.file-upload__item').find('.file-upload__item__remove').first().remove();
  164. </script>
  165. </form>
  166.