PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/shashin/Admin/Display/mediaPhotos.php

https://bitbucket.org/zachisit/zachis.it-m
PHP | 232 lines | 209 code | 23 blank | 0 comment | 10 complexity | ef0a310e07bfd4671a954a37a1cf2ee1 MD5 | raw file
  1. <script type="text/javascript">
  2. jQuery(document).ready(function($) {
  3. function shashinLoadPhotos() {
  4. $('#shashinMediaMenuLoading').show();
  5. var adminAjaxUrl = '<?php echo admin_url("admin-ajax.php"); ?>';
  6. var filterRoot = $('#shashinMediaMenuFilter').get();
  7. var albumId = $('#shashinFilterAlbum', filterRoot).val();
  8. var order = $('#shashinFilterOrder', filterRoot).val();
  9. var reverse = $('#shashinFilterReverse', filterRoot).attr('checked') ? 'y' : 'n';
  10. var page = shashinGetCurrentPage();
  11. var dataToSend = {
  12. action: 'shashinGetPhotosForMediaMenu',
  13. shashinAlbumId: albumId,
  14. shashinOrder: order,
  15. shashinReverse: reverse,
  16. shashinPage: page
  17. };
  18. $.post(adminAjaxUrl, dataToSend, function(dataReceived) {
  19. $('#shashinMediaMenuPhotoGrid img').remove();
  20. $('#shashinMediaMenuNav span').text(dataReceived['page'] + '/' + dataReceived['totalPages']);
  21. for (i in dataReceived['photos']) {
  22. var imgTag = shashinWriteImgTag(
  23. 'shashinMediaMenuThumb_' + dataReceived['photos'][i]['id'],
  24. dataReceived['photos'][i]['contentUrl'] + '?imgmax=72&crop=1',
  25. dataReceived['photos'][i]['description'],
  26. 72,
  27. 72
  28. );
  29. $('#shashinMediaMenuPhotoGrid').append(imgTag);
  30. }
  31. $('#shashinMediaMenuLoading').hide();
  32. }, 'json');
  33. }
  34. function shashinWriteImgTag(id, src, description, width, height) {
  35. return '<img id="' + id + '"'
  36. + ' src="' + src + '"'
  37. + ' alt="' + description + '"'
  38. + ' title="' + description + '"'
  39. + ' width="' + width + '"'
  40. + ' height="' + height + '" />';
  41. }
  42. function shashinGetCurrentPage() {
  43. var page = $('#shashinMediaMenuNav span').text().split('/');
  44. page[0] = parseFloat(page[0]);
  45. page[1] = parseFloat(page[1]);
  46. return page[0];
  47. }
  48. function shashinGetTotalPages() {
  49. var page = $('#shashinMediaMenuNav span').text().split('/');
  50. page[0] = parseFloat(page[0]);
  51. page[1] = parseFloat(page[1]);
  52. return page[1];
  53. }
  54. $('#shashinMediaMenuSelectedPhotos img').live('click', function() {
  55. $(this).remove();
  56. })
  57. $('#shashinMediaMenuPhotoGrid img').live('mouseover', function(e) {
  58. var offset = $('#shashinMediaMenuPhotoGrid').offset();
  59. offset.left = offset.left + 2;
  60. offset.top = offset.top + 2;
  61. if (e.clientX < (offset.left + 304)) offset.left = offset.left + 304;
  62. var imgSrc = $(this).attr('src').replace('?imgmax=72&crop=1', '?imgmax=288'); // for Picasa
  63. imgSrc = imgSrc.replace('/mini/', '/thumb/'); // for Twitpic
  64. var imgTag = shashinWriteImgTag(
  65. 'shashinMediaMenuThumbPreview_' + $(this).attr('id').replace('shashinMediaMenuThumb_', ''),
  66. imgSrc,
  67. $(this).attr('alt')
  68. )
  69. $('#shashinMediaMenuPhotoPreview')
  70. .html(imgTag)
  71. .css('top', offset.top)
  72. .css('left', offset.left)
  73. .show();
  74. })
  75. $('#shashinMediaMenuPhotoGrid img').live('mouseout', function() {
  76. $('#shashinMediaMenuPhotoPreview').hide();
  77. });
  78. $('#shashinMediaMenuPhotoGrid img').live('click', function() {
  79. var imgTag = shashinWriteImgTag(
  80. 'shashinMediaMenuThumbSelected_' + $(this).attr('id').replace('shashinMediaMenuThumb_', ''),
  81. $(this).attr('src'),
  82. $(this).attr('alt'),
  83. $(this).attr('width'),
  84. $(this).attr('height')
  85. )
  86. $('#shashinMediaMenuSelectedPhotos').append(imgTag);
  87. });
  88. $('#shashinInsertShortcode').click(function() {
  89. var selectedIds = new Array;
  90. $('#shashinMediaMenuSelectedPhotos img').each(function() {
  91. selectedIds.push($(this).attr('id').replace('shashinMediaMenuThumbSelected_',''));
  92. });
  93. if (selectedIds.length == 0) return alert('<?php _e('No photos selected', 'shashin') ?>');
  94. parent.send_to_editor('[shashin type="photo"'
  95. + ' id="' + selectedIds.join(',') + '"'
  96. + ' size="' + $('#shashinSize').val() + '"'
  97. + ' columns="' + $('#shashinColumns').val() + '"'
  98. + ' order="user"'
  99. + (($('#shashinCaption').val() == 'y') ? (' caption="' + $('#shashinCaption').val() + '"') : '')
  100. + (($('#shashinPosition').val() == '') ? '' : (' position="' + $('#shashinPosition').val() + '"'))
  101. + (($('#shashinCrop').val() == 'y') ? (' crop="' + $('#shashinCrop').val() + '"') : '')
  102. + ']'
  103. );
  104. });
  105. $('#shashinFilterUpdate').click(function() {
  106. shashinLoadPhotos();
  107. });
  108. $('#shashinPreviousPage').click(function() {
  109. page = shashinGetCurrentPage() - 1;
  110. totalPages = shashinGetTotalPages();
  111. if (page < 1) return;
  112. $('#shashinMediaMenuNav span').text(page + '/' + totalPages);
  113. shashinLoadPhotos();
  114. });
  115. $('#shashinNextPage').click(function() {
  116. page = shashinGetCurrentPage() + 1;
  117. totalPages = shashinGetTotalPages();
  118. if (page > totalPages) return;
  119. $('#shashinMediaMenuNav span').text(page + '/' + totalPages);
  120. shashinLoadPhotos();
  121. });
  122. shashinLoadPhotos();
  123. })
  124. </script>
  125. <form id="shashinMediaMenu" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
  126. <div id="shashinMediaMenuFilter">
  127. <div><?php _e('Album', 'shashin') ?><br />
  128. <select style="width: 100px;" name="shashinFilterAlbum" id="shashinFilterAlbum">
  129. <option value="0"><?php _e('All albums', 'shashin') ?></option>
  130. <?php foreach ($albums as $album): ?>
  131. <option value="<?php echo $album->id ?>"><?php echo $album->title ?></option>
  132. <?php endforeach ?>
  133. </select>
  134. </div>
  135. <div><?php _e('Order', 'shashin') ?><br />
  136. <select style="width: 100px" name="shashinFilterOrder" id="shashinFilterOrder">
  137. <option value="date"><?php _e('Date Taken', 'shashin') ?></option>
  138. <option value="id"><?php _e('Shashin ID', 'shashin') ?></option>
  139. <option value="filename"><?php _e('Filename', 'shashin') ?></option>
  140. <option value="source"><?php _e('Source order', 'shashin') ?></option>
  141. </select>
  142. </div>
  143. <div><?php _e('Reverse<br />order?', 'shashin') ?>
  144. <input type="checkbox" checked="checked" name="shashinFilterReverse" id="shashinFilterReverse" value="1" />
  145. </div>
  146. <div>&nbsp;<br />
  147. <input type="button" class="button" name="shashinFilterUpdate" id="shashinFilterUpdate" value="<?php _e('Update', 'shashin') ?>" />
  148. </div>
  149. <div id="shashinMediaMenuNav"><br />
  150. <input type="button" class="button" name="shashinPreviousPage" id="shashinPreviousPage" value="<?php _e('Previous', 'shashin') ?>" />
  151. <span>1/1</span>
  152. <input type="button" class="button" name="shashinNextPage" id="shashinNextPage" value="<?php _e('Next', 'shashin') ?>" />
  153. </div>
  154. </div>
  155. <div id="shashinMediaMenuLoading">
  156. <?php _e('Loading photos', 'shashin') ?>
  157. <img src="<?php echo $loaderUrl ?>" alt="Loading..." width="220" height="19" />
  158. </div>
  159. <div id="shashinMediaMenuPhotoPreview">&nbsp;</div>
  160. <div id="shashinMediaMenuPhotoGrid"></div>
  161. <div id="shashinMediaMenuSelectedPhotos"><h3><?php _e('Selected photos', 'shashin'); ?></h3></div>
  162. <div id="shashinMediaMenuShortcodeCriteria">
  163. <h3><?php _e('Shortcode attributes', 'shashin') ?></h3>
  164. <table id="shashinMediaMenuShortcodeCriteriaTable">
  165. <tbody>
  166. <tr>
  167. <td><label for="shashinSize"><?php _e('Size', 'shashin') ?></label></td>
  168. <td><select name="shashinSize" id="shashinSize">
  169. <option value="xsmall"><?php _e('X-Small (72px)', 'shashin') ?></option>
  170. <option value="small" selected="selected"><?php _e('Small (150px)', 'shashin') ?></option>
  171. <option value="medium"><?php _e('Medium (300px)', 'shashin') ?></option>
  172. <option value="large"><?php _e('Large (600px)', 'shashin') ?></option>
  173. <option value="xlarge"><?php _e('X-Large (800px)', 'shashin') ?></option>
  174. <option value="max"><?php _e('Max', 'shashin') ?></option>
  175. </select></td>
  176. <td><label for="shashinColumns"><?php _e('Columns', 'shashin') ?></label></td>
  177. <td><select name="shashinColumns" id="shashinColumns">
  178. <option value="max"><?php _e('Max', 'shashin'); ?></option>
  179. <?php for ($i = 1; $i < 16; $i++) {
  180. echo "<option value='$i'>$i</option>" . PHP_EOL;
  181. } ?>
  182. </select></td>
  183. </tr>
  184. <tr>
  185. <td><label for="shashinCaption"><?php _e('Caption', 'shashin') ?></label></td>
  186. <td><select name="shashinCaption" id="shashinCaption">
  187. <option value="n"><?php _e('No', 'shashin'); ?></option>
  188. <option value="y"><?php _e('Yes', 'shashin'); ?></option>
  189. </select></td>
  190. <td><label for="shashinPosition"><?php _e('Position', 'shashin') ?></label></td>
  191. <td><select name="shashinPosition" id="shashinPosition">
  192. <option value="center"><?php _e('Center', 'shashin'); ?></option>
  193. <option value="left"><?php _e('Left', 'shashin'); ?></option>
  194. <option value="right"><?php _e('Right', 'shashin'); ?></option>
  195. <option value=""><?php _e('None', 'shashin'); ?></option>
  196. </select></td>
  197. </tr>
  198. <tr>
  199. <td><label for="shashinCrop"><?php _e('Crop', 'shashin') ?></label></td>
  200. <td><select name="shashinCrop" id="shashinCrop">
  201. <option value="n"><?php _e('No', 'shashin'); ?></option>
  202. <option value="y"><?php _e('Yes', 'shashin'); ?></option>
  203. </select></td>
  204. <td colspan="2"><input type="button" class="button" name="shashinInsertShortcode" id="shashinInsertShortcode" value="<?php _e('Insert shortcode', 'shashin') ?>" /></td>
  205. </tr>
  206. </tbody>
  207. </table>
  208. </div>
  209. </form>