/** * @author Sergey Pasyuk * @copyright 2009 */ function flag_sortorder($galleryID = 0) { global $wpdb; if ($galleryID == 0) { return; } $galleryID = (int) $galleryID; if (isset($_POST['updateSortorder'])) { check_admin_referer('flag_updatesortorder'); // get variable new sortorder $neworder = array(); foreach ($_POST as $id) { $neworder[] = (int) $id; } $sortindex = 1; foreach ($neworder as $pic_id) { $wpdb->query("UPDATE {$wpdb->flagpictures} SET sortorder = '{$sortindex}' WHERE pid = {$pic_id}"); $sortindex++; } $firstImage = $wpdb->get_var("SELECT pid FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}' ORDER by pid DESC limit 0,1"); if ($firstImage) { $wpdb->query("UPDATE {$wpdb->flaggallery} SET previewpic = '{$firstImage}' WHERE gid = '{$galleryID}'"); } flagGallery::show_message(__('Sort order changed', 'flag')); } // get gallery values $act_gallery = $wpdb->get_row("SELECT * FROM {$wpdb->flaggallery} WHERE gid = '{$galleryID}' "); // set gallery url $act_gallery_url = get_option('siteurl') . "/" . $act_gallery->path . "/"; $act_thumbnail_url = get_option('siteurl') . "/" . $act_gallery->path . flagGallery::create_thumbnail_folder($act_gallery->path, FALSE); // look for presort args $picturelist = $wpdb->get_results("SELECT * FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}' ORDER BY sortorder"); //this is the url without any presort variable $base_url = admin_url() . 'admin.php?page=flag-manage-gallery&mode=sort&gid=' . $galleryID; ?> <script type="text/javascript" src="<?php echo FLAG_URLPATH; ?> admin/js/jquery.tablednd_0_5.js"></script> <script type="text/javascript" src="<?php echo FLAG_URLPATH; ?> admin/js/jquery.tablesorter.js"></script> <div class="flag-wrap"> <h2><?php _e('Sort Gallery', 'flag'); ?> </h2> <form class="alignright" method="POST" action="<?php echo admin_url() . 'admin.php?page=flag-manage-gallery&mode=edit&gid=' . $galleryID; ?> " accept-charset="utf-8"> <div class="alignright tablenav" style="margin-bottom: -36px;"> <input class="button-secondary action" type="submit" name="backToGallery" value="<?php _e('Back to gallery', 'flag'); ?> " /> </div> </form> <form id="sortGallery" method="POST" action="<?php echo $base_url; ?> " accept-charset="utf-8"> <div class="alignleft tablenav"> <?php wp_nonce_field('flag_updatesortorder'); ?> <input class="button-primary action" type="submit" name="updateSortorder" value="<?php _e('Update Sort Order', 'flag'); ?> " /> </div> <br clear="all" /> <script type="text/javascript"> /*<![CDATA[*/ jQuery(document).ready(function($) { // Initialise the table jQuery("#listimages").tableDnD({ onDragClass: "myDragClass", onDrop: function() { jQuery("#listimages tr:even").addClass('alternate'); jQuery("#listimages tr:odd").removeClass('alternate'); } }); $("#flag-listitems").tablesorter({ // pass the headers argument and assing a object headers: { // assign the secound column (we start counting zero) 1: { // disable it by setting the property sorter to false sorter: false } } }); $("#flag-listitems").bind("sortEnd",function() { jQuery("#listimages tr:even").addClass('alternate'); jQuery("#listimages tr:odd").removeClass('alternate'); }); }); /*]]>*/ </script> <table id="flag-listitems" class="widefat fixed flag-table" cellspacing="0" > <thead> <tr> <th class="header" width="30px"><p style="margin-right:-10px;"><?php _e('ID', 'flag'); ?> </p></th> <th width="120"><p><?php _e('Thumb', 'flag'); ?> </p></th> <th class="header"><p><?php _e('Filename', 'flag'); ?> </p></th> <th class="header" width="130"><p><?php _e('Date', 'flag'); ?> </p></th> <th class="header"><p><?php _e('Alt & Title Text', 'flag'); ?> </p></th> </tr> </thead> <tfoot> <tr> <th><p><?php _e('ID', 'flag'); ?> </p></th> <th><p><?php _e('Thumb', 'flag'); ?> </p></th> <th><p><?php _e('Filename', 'flag'); ?> </p></th> <th><p><?php _e('Date', 'flag'); ?> </p></th> <th><p><?php _e('Alt & Title Text', 'flag'); ?> </p></th> </tr> </tfoot> <tbody id="listimages"> <?php if ($picturelist) { $alternate = ''; foreach ($picturelist as $picture) { $pid = (int) $picture->pid; $alternate = $alternate == 'alternate' ? '' : 'alternate'; $date = mysql2date(get_option('date_format'), $picture->imagedate); $time = mysql2date(get_option('time_format'), $picture->imagedate); ?> <tr id="picture-<?php echo $pid; ?> " class="<?php echo $alternate; ?> iedit" valign="top"> <td><strong><?php echo $pid; ?> </strong><input type="hidden" name="sortpid-<?php echo $pid; ?> " value="<?php echo $pid; ?> " /></td> <td><a href="<?php echo $act_gallery_url . $picture->filename; ?> " class="thickbox" title="<?php echo $picture->filename; ?> "> <img class="thumb" src="<?php echo $act_thumbnail_url . "thumbs_" . $picture->filename; ?> " style="width:80px; height:auto;" id="thumb-<?php echo $pid; ?> " /> </a></td> <td><?php echo $picture->filename; ?> </td> <td><?php echo $date; ?> </td> <td><?php echo esc_html(stripslashes($picture->alttext)); ?> </td> </tr> <?php } } else { echo '<tr><td colspan="5" align="center"><strong>' . __('No entries found', 'flag') . '</strong></td></tr>'; } ?> </tbody> </table> <p class="actions"><input type="submit" class="button-primary action" name="updateSortorder" onclick="saveImageOrder()" value="<?php _e('Update Sort Order', 'flag'); ?> " /></p> </form> <br class="clear"/> </div><!-- /#wrap --> <?php }
/** * flagAdmin::import_gallery() * TODO: Check permission of existing thumb folder & images * * @class flagAdmin * @param string $galleryfolder contains relative path * @return void */ static function import_gallery($galleryfolder) { global $wpdb, $user_ID; // get the current user ID get_currentuserinfo(); $created_msg = ''; // remove trailing slash at the end, if somebody use it $galleryfolder = str_replace('../', '', $galleryfolder); $galleryfolder = rtrim($galleryfolder, '/'); $gallerypath = WINABSPATH . $galleryfolder; if (!is_dir($gallerypath)) { flagGallery::show_error(__('Directory', 'flag') . ' <strong>' . esc_html($gallerypath) . '</strong> ' . __('doesn`t exist!', 'flag') . ' ' . __('Or imported folder name contains special characters.', 'flag')); return; } // read list of images $new_imageslist = flagAdmin::scandir($gallerypath); if (empty($new_imageslist)) { flagGallery::show_message(__('Directory', 'flag') . ' <strong>' . esc_html($gallerypath) . '</strong> ' . __('contains no pictures', 'flag')); return; } // check & create thumbnail folder if (!flagGallery::create_thumbnail_folder($gallerypath)) { return; } // take folder name as gallery name $galleryname = basename($galleryfolder); // check for existing gallery folder $gallery_id = $wpdb->get_var($wpdb->prepare("SELECT gid FROM {$wpdb->flaggallery} WHERE path = '%s' ", $galleryfolder)); if (!$gallery_id) { $result = $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->flaggallery} (name, path, title, author) VALUES (%s, %s, %s, %s)", $galleryname, $galleryfolder, $galleryname, $user_ID)); if (!$result) { flagGallery::show_error(__('Database error. Could not add gallery!', 'flag')); return; } $created_msg = _n('Gallery', 'Galleries', 1, 'flag') . ' <strong>' . $galleryname . '</strong> ' . __('successfully created!', 'flag') . '<br />'; $gallery_id = $wpdb->insert_id; // get index_id } // Look for existing image list $old_imageslist = $wpdb->get_col($wpdb->prepare("SELECT filename FROM {$wpdb->flagpictures} WHERE galleryid = %d ", $gallery_id)); // if no images are there, create empty array if ($old_imageslist == NULL) { $old_imageslist = array(); } // check difference $new_images = array_diff($new_imageslist, $old_imageslist); // all images must be valid files foreach ($new_images as $key => $picture) { if (!@getimagesize($gallerypath . '/' . $picture)) { unset($new_images[$key]); @unlink($gallerypath . '/' . $picture); } } // add images to database $image_ids = flagAdmin::add_Images($gallery_id, $new_images); //add the preview image if needed flagAdmin::set_gallery_preview($gallery_id); // now create thumbnails flagAdmin::do_ajax_operation('create_thumbnail', $image_ids, __('Create new thumbnails', 'flag')); //TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX flagGallery::show_message($created_msg . count($image_ids) . __(' picture(s) successfully added', 'flag')); return; }
/** * flagGallery::get_thumbnail_folder() * * @param mixed $gallerypath * @param bool $include_Abspath * @deprecated use create_thumbnail_folder() if needed; * @return string $foldername */ static function get_thumbnail_folder($gallerypath, $include_Abspath = TRUE) { return flagGallery::create_thumbnail_folder($gallerypath, $include_Abspath); }