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