SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/admin/file_edit.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\Admin;
  18. use Sprout\Helpers\Enc;
  19. use Sprout\Helpers\Fb;
  20. use Sprout\Helpers\File;
  21. use Sprout\Helpers\FileConstants;
  22. use Sprout\Helpers\Form;
  23. use Sprout\Helpers\Needs;
  24. use Sprout\Helpers\Text;
  25.  
  26.  
  27. Form::setData($data);
  28. Form::setErrors($errors);
  29.  
  30. if ($data['type'] == FileConstants::TYPE_IMAGE) {
  31. Needs::fileGroup('sprout/image_edit');
  32. }
  33.  
  34. $abs_url = File::absUrl($data['filename']);
  35. ?>
  36.  
  37. <div class="main-tabs">
  38. <ul>
  39. <li><a href="#main-tabs-details">Details</a></li>
  40. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?>
  41. <li><a href="#main-tabs-manipulate">Manipulate image</a></li>
  42. <li><a href="#main-tabs-focus">Set focal points</a></li>
  43. <?php endif; ?>
  44. <li><a href="#main-tabs-replace">Replace file</a></li>
  45. <li><a href="#main-tabs-cats">Categories</a></li>
  46. </ul>
  47.  
  48. <div id="main-tabs-details">
  49.  
  50. <div class="clear-group">
  51. <div class="col col--one-half">
  52. <?php Form::nextFieldDetails('Name', true); ?>
  53. <?= Form::text('name'); ?>
  54. </div>
  55.  
  56. <div class="col col--one-half">
  57. <?php Form::nextFieldDetails('Author', false); ?>
  58. <?= Form::autocomplete('author', [], ['url' => 'admin/call/file/ajaxAuthorLookup', 'save_id' => false]); ?>
  59. </div>
  60. </div>
  61.  
  62. <?php Form::nextFieldDetails('Description', false); ?>
  63. <?= Form::multiline('description', ['rows' => 5, 'cols' => 40]); ?>
  64.  
  65. <?php if ($data['type'] == FileConstants::TYPE_DOCUMENT): ?>
  66. <div class="clear-group">
  67. <div class="col col--one-half">
  68. <?php
  69. Form::nextFieldDetails('Document type', false);
  70. echo Form::dropdown('document_type', [], $document_types);
  71. ?>
  72. </div>
  73.  
  74. <div class="col col--one-half">
  75. <?php
  76. Form::nextFieldDetails('Date published', false);
  77. echo Form::datepicker('date_published');
  78. ?>
  79. </div>
  80. </div>
  81. <?php endif; ?>
  82.  
  83. <h3>Details</h3>
  84.  
  85. <table class="main-list">
  86. <thead><tr>
  87. <th>Filename</th>
  88. <th>URL</th>
  89. <th>Type</th>
  90. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?><th>Image dimensions</th><?php endif; ?>
  91. </tr></thead>
  92. <tbody><tr>
  93. <td><?= Enc::html($data['filename']); ?></td>
  94. <td><a href="<?= Enc::html($abs_url ); ?>"><?= Enc::html(Text::limitChars($abs_url, 50)); ?></a></td>
  95. <td><?= Enc::html(FileConstants::$type_names[$data['type']]); ?></td>
  96. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?><td><?= Enc::html($img_dimensions); ?></td><?php endif; ?>
  97. </tr></tbody>
  98. </table>
  99.  
  100.  
  101.  
  102.  
  103. <!-- Preview -->
  104. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?>
  105. <h3>Preview</h3>
  106. <p>
  107. <a href="<?php echo Enc::html(File::absUrl($data['filename']));; ?>" target="_blank">
  108. <img src="<?php echo Enc::html(File::resizeUrl($data['filename'], 'r200x0')); ?>" alt="preview">
  109. </a>
  110. </p>
  111.  
  112. <?php if (!empty($sizes) and count($sizes)): ?>
  113. <h3>Available sizes</h3>
  114.  
  115. <table class="main-list">
  116. <thead><tr>
  117. <th>Filename</th>
  118. <th>Size</th>
  119. <th>Dimensions</th>
  120. </tr></thead>
  121. <tbody>
  122. <?php foreach ($sizes as $filename): ?>
  123. <?php
  124. $abs_url = Enc::html(File::absUrl($filename));
  125. $dimensions = File::imageSize($filename);
  126. $size = File::size($filename);
  127. ?>
  128.  
  129. <tr>
  130. <td><a href="', $abs_url, '" target="_blank"><?= Enc::html($filename); ?></a></td>
  131. <td><?= File::humanSize($size); ?></td>
  132. <td><?= Enc::html(sprintf('%u x %u', $dimensions[0], $dimensions[1])); ?></td>
  133. <?php endforeach; ?>
  134. </tbody>
  135. </table>
  136. <?php endif; ?>
  137.  
  138. <?php elseif ($data['type'] == FileConstants::TYPE_DOCUMENT and $data['plaintext']): ?>
  139. <?= Fb::heading('Preview'); ?>
  140. <pre><?php echo Enc::html($preview); ?></pre>
  141. <?php endif; ?>
  142. </div>
  143.  
  144. <?php if ($data['type'] == FileConstants::TYPE_IMAGE): ?>
  145. <div id="main-tabs-manipulate">
  146. <?= Fb::heading('Manipulate image'); ?>
  147.  
  148. <div class="field-element field-element--select">
  149. <div class="field-label -vis-hidden">
  150. <label for="manipulate">Current site</label>
  151. </div>
  152. <div class="field-input">
  153. <select id="manipulate" name="manipulate" data-src="<?= Enc::html($data['filename']); ?>">
  154. <option value="">Select an option</option>
  155. <?php if (function_exists('imagerotate')): ?>
  156. <option value="rotate-90-clockwise">Rotate 90&deg; clockwise</option>
  157. <option value="rotate-90-counterclockwise">Rotate 90&deg; counter-clockwise</option>
  158. <option value="rotate-180">Rotate 180&deg;</option>
  159. <?php endif; ?>
  160.  
  161. <option value="flip-horizontal">Flip horizontal</option>
  162. <option value="flip-vertical">Flip vertical</option>
  163. </select>
  164. </div>
  165. </div>
  166.  
  167. <div class="highlight">
  168.  
  169. <div class="columns">
  170. <div class="column column-6">
  171. <p><strong>Original image:</strong></p>
  172. <img src="<?= Enc::html($original_image); ?>" alt="">
  173. </div>
  174.  
  175. <div class="column column-6">
  176. <p><b>New image:</b></p>
  177. <img src="SITE/admin/call/file/previewTransform/none/<?php echo Enc::html($data['filename']); ?>" alt="" id="manipulate-preview">
  178. </div>
  179. </div>
  180.  
  181. </div>
  182. </div>
  183.  
  184. <div id="main-tabs-focus">
  185. <?= Fb::heading('Set focal points'); ?>
  186.  
  187. <p>Click the position on the image where you want the focal point to be set.</p>
  188. <p>When the image is resized, the resizing will be done so that the focal point is always visible, and as close to the centre as possible.</p>
  189. <p>In most cases, you should only need to set a default focal point, to capture the important part of the
  190. image in all orientations. However, if you need more control, you can choose a different focal points for
  191. any particular orientations. Click an orientation and then click within the image to set a specific focal
  192. point for that orientation.</p>
  193.  
  194. <ul id="focal-point-type-selector">
  195. <li data-type="default" data-active="1">Default</li>
  196. <li data-type="landscape" data-size="300x200">Landscape</li>
  197. <li data-type="portrait" data-size="200x300">Portait</li>
  198. <li data-type="square" data-size="200x200">Square</li>
  199. <li data-type="panorama" data-size="400x100">Panorama</li>
  200. </ul>
  201.  
  202. <div id="focal-point-wrapper"><img id="focal-point-setter" src="<?php echo File::url($data['filename']); ?>"><div id="focal-point-dot"></div></div>
  203.  
  204. <input type="hidden" id="image-focal-points" name="focal_points" value="<?= Enc::html(@$data['focal_points']); ?>">
  205.  
  206. <div id="focal-point-preview" style="display: none;">
  207. <h3>Preview</h3>
  208.  
  209. <p>Please note that this is just an example of the type of orientation, and does not represent how the image will look on your site.</p>
  210.  
  211. <p><span id="focal-point-preview-image"></span></p>
  212. </div>
  213. </div>
  214. <?php endif; ?>
  215.  
  216. <div id="main-tabs-replace">
  217. <?= Fb::heading('Replace file'); ?>
  218.  
  219. <p>Replacement file must be of the type <b><?php echo FileConstants::$type_names[$data['type']]; ?></b>.</p>
  220.  
  221. <?= Form::upload('replace'); ?>
  222. </div>
  223.  
  224. <div id="main-tabs-cats">
  225. <?= Fb::heading('Categories'); ?>
  226. <?= Admin::categorySelection('categories[]', $cats, $data['categories']); ?>
  227. </div>
  228. </div>
  229.  
  230.  
  231. <?php Admin::clearFieldErrors(); ?>
  232.