/** * * @param $pic_id * @param bool $onlyEXIF parse only exif if needed */ function __construct($pic_id, $onlyEXIF = false) { //get the path and other data about the image $this->image = flagdb::find_image($pic_id); $this->image = apply_filters('flag_find_image_meta', $this->image); if (!file_exists($this->image->imagePath)) { return false; } $this->size = @getimagesize($this->image->imagePath, $metadata); if ($this->size && is_array($metadata)) { // get exif - data if (is_callable('exif_read_data')) { $this->exif_data = @exif_read_data($this->image->imagePath, 0, true); } // stop here if we didn't need other meta data if ($onlyEXIF) { return true; } // get the iptc data - should be in APP13 if (is_callable('iptcparse')) { $this->iptc_data = @iptcparse($metadata["APP13"]); } // get the xmp data in a XML format if (is_callable('xml_parser_create')) { $this->xmp_data = $this->extract_XMP($this->image->imagePath); } return true; } return false; }
function flagCreateNewThumb() { global $wpdb; // check for correct capability if (!is_user_logged_in()) { die('-1'); } // check for correct FlAG capability if (!current_user_can('FlAG Manage gallery')) { die('-1'); } require_once dirname(dirname(__FILE__)) . '/flag-config.php'; include_once flagGallery::graphic_library(); $flag_options = get_option('flag_options'); $id = (int) $_POST['id']; $picture = flagdb::find_image($id); $x = round($_POST['x'] * $_POST['rr'], 0); $y = round($_POST['y'] * $_POST['rr'], 0); $w = round($_POST['w'] * $_POST['rr'], 0); $h = round($_POST['h'] * $_POST['rr'], 0); $thumb = new flag_Thumbnail($picture->imagePath, TRUE); $thumb->crop($x, $y, $w, $h); if ($flag_options['thumbFix']) { if ($thumb->currentDimensions['height'] > $thumb->currentDimensions['width']) { $thumb->resize($flag_options['thumbWidth'], 0); } else { $thumb->resize(0, $flag_options['thumbHeight']); } } else { $thumb->resize($flag_options['thumbWidth'], $flag_options['thumbHeight']); } if ($thumb->save($picture->thumbPath, 100)) { //read the new sizes $new_size = @getimagesize($picture->thumbPath); $size['width'] = $new_size[0]; $size['height'] = $new_size[1]; // add them to the database flagdb::update_image_meta($picture->pid, array('thumbnail' => $size)); echo "OK"; } else { header('HTTP/1.1 500 Internal Server Error'); echo "KO"; } exit; }
function ewww_image_optimizer_defer() { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); global $ewww_defer; $ewww_defer = false; $deferred_attachments = get_option('ewww_image_optimizer_defer_attachments'); if (empty($deferred_attachments)) { return; } $start_time = time(); $delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay'); foreach ($deferred_attachments as $image) { list($type, $id) = explode(',', $image, 2); switch ($type) { case 'media': ewwwio_debug_message("processing deferred {$type}: {$id}"); $meta = wp_get_attachment_metadata($id, true); // do the optimization for the current attachment (including resizes) $meta = ewww_image_optimizer_resize_from_meta_data($meta, $id, false); // update the metadata for the current attachment wp_update_attachment_metadata($id, $meta); break; case 'nextgen2': ewwwio_debug_message("processing deferred {$type}: {$id}"); // creating the 'registry' object for working with nextgen $registry = C_Component_Registry::get_instance(); // creating a database storage object from the 'registry' object $storage = $registry->get_utility('I_Gallery_Storage'); // get an image object $ngg_image = $storage->object->_image_mapper->find($id); ewwwngg::ewww_added_new_image($ngg_image, $storage); break; case 'nextcellent': ewwwio_debug_message("processing deferred {$type}: {$id}"); ewwwngg::ewww_ngg_optimize($id); break; case 'flag': ewwwio_debug_message("processing deferred {$type}: {$id}"); $flag_image = flagdb::find_image($id); ewwwflag::ewww_added_new_image($flag_image); break; case 'file': ewwwio_debug_message("processing deferred {$type}: {$id}"); ewww_image_optimizer($id); break; default: ewwwio_debug_message("unknown type in deferrred queue: {$type}, {$id}"); } ewww_image_optimizer_remove_deferred_attachment($image); $elapsed_time = time() - $start_time; ewwwio_debug_message("time elapsed during deferred opt: {$elapsed_time}"); global $ewww_exceed; if (!empty($ewww_exceed)) { ewwwio_debug_message('Deferred opt aborted, license exceeded'); die; } ewww_image_optimizer_debug_log(); if (!empty($delay)) { sleep($delay); } // prevent running longer than an hour if ($elapsed_time > 3600) { return; } } ewwwio_memory(__FUNCTION__); return; }
/** * Copy some metadata into the image description (if avialable) * * @class flagAdmin * @param array|int $imagesIds * @return bool */ static function copy_MetaData($imagesIds) { global $wpdb; /** @var $meta */ require_once FLAG_ABSPATH . 'lib/meta.php'; require_once FLAG_ABSPATH . 'lib/image.php'; if (!is_array($imagesIds)) { $imagesIds = array($imagesIds); } foreach ($imagesIds as $imageID) { $image = flagdb::find_image($imageID); if (!$image->error) { /** @var $makedescription * @var $timestamp */ require_once FLAG_ABSPATH . 'admin/grab_meta.php'; // get the title $alttext = empty($alttext) ? $image->alttext : $meta['title']; if ($alttext) { $alttext = '<font size="16"><b>' . $alttext . "</b></font>\n"; } // get the caption / description field $description = empty($description) ? $image->description : $meta['caption']; if ($description) { $description = $description . "<br>\n"; } // get the file date/time from exif $makedescription = $alttext . $description . $makedescription; // update database $result = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->flagpictures} SET alttext = %s, description = %s, imagedate = %s WHERE pid = %d", '', $makedescription, $timestamp, $image->pid)); if ($result === false) { return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not update data base)', 'flag') . '</strong>'; } } else { return ' <strong>' . $image->filename . ' ' . __('(Error : Couldn\'t not find image)', 'flag') . '</strong>'; } // error check } return '1'; }
Credits: jCrop : Kelly Hallman <*****@*****.**> | http://deepliquid.com/content/Jcrop.html **/ require_once dirname(dirname(__FILE__)) . '/flag-config.php'; require_once FLAG_ABSPATH . '/lib/image.php'; if (!is_user_logged_in()) { die(__('Cheatin’ uh?')); } if (!current_user_can('FlAG Manage gallery')) { die(__('Cheatin’ uh?')); } global $wpdb; $id = (int) $_GET['id']; // let's get the image data $picture = flagdb::find_image($id); include_once flagGallery::graphic_library(); $flag_options = get_option('flag_options'); $thumb = new flag_Thumbnail($picture->imagePath, TRUE); $thumb->resize(350, 350); // we need the new dimension $resizedPreviewInfo = $thumb->newDimensions; $thumb->destruct(); $preview_image = FLAG_URLPATH . 'flagshow.php?pid=' . $picture->pid . '&width=350&height=350'; $imageInfo = @getimagesize($picture->imagePath); $rr = round($imageInfo[0] / $resizedPreviewInfo['newWidth'], 2); $WidthHtmlPrev = $flag_options['thumbWidth']; $HeightHtmlPrev = $flag_options['thumbHeight']; if ($flag_options['thumbFix'] == 1) { $WidthHtmlPrev = $flag_options['thumbWidth']; $HeightHtmlPrev = $flag_options['thumbHeight'];
// Load wp-config if (!defined('ABSPATH')) { require_once dirname(__FILE__) . '/flag-config.php'; } // reference thumbnail class include_once flagGallery::graphic_library(); include_once 'lib/core.php'; // get the plugin options $flag_options = get_option('flag_options'); // Some parameters from the URL if (!isset($_GET['pid'])) { exit; } $pictureID = intval($_GET['pid']); if (!$pictureID) { exit; } // let's get the image data $picture = flagdb::find_image($pictureID); if (!is_object($picture)) { exit; } $thumb = new flag_Thumbnail($picture->imagePath); // Resize if necessary if (!empty($_GET['width']) || !empty($_GET['height'])) { $thumb->resize(intval($_GET['width']), intval($_GET['height'])); } // Show thumbnail $thumb->show(); $thumb->destruct(); exit;
function media_upload_flag_form() { global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $flag; media_upload_header(); $post_id = intval($_REQUEST['post_id']); $galleryID = 0; $total = 1; $picarray = false; $form_action_url = site_url("wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=flag&post_id={$post_id}", 'admin'); // Get number of images in gallery if (isset($_REQUEST['select_gal']) && $_REQUEST['select_gal']) { $galleryID = (int) $_REQUEST['select_gal']; $total = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}'"); } // Build navigation $_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 1; if ($_GET['paged'] < 1) { $_GET['paged'] = 1; } $start = ($_GET['paged'] - 1) * 10; if ($start < 1) { $start = 0; } // Get the images if ($galleryID != 0) { $picarray = $wpdb->get_col("SELECT pid FROM {$wpdb->flagpictures} WHERE galleryid = '{$galleryID}' AND exclude != 1 ORDER BY {$flag->options['galSort']} {$flag->options['galSortDir']} LIMIT {$start}, 10 "); } ?> <form id="filter" action="" method="get"> <input type="hidden" name="type" value="<?php echo esc_attr($GLOBALS['type']); ?> " /> <input type="hidden" name="tab" value="<?php echo esc_attr($GLOBALS['tab']); ?> " /> <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?> " /> <div class="tablenav"> <?php $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'total' => ceil($total / 10), 'current' => $_GET['paged'])); if ($page_links) { echo "<div class='tablenav-pages'>{$page_links}</div>"; } ?> <div class="alignleft actions"> <select id="select_gal" name="select_gal" style="width:200px;">; <option value="0" <?php selected('0', $galleryID); ?> ><?php _e('No gallery', "flag"); ?> </option> <?php // Show gallery selection $gallerylist = $wpdb->get_results("SELECT * FROM {$wpdb->flaggallery} ORDER BY gid ASC"); if (is_array($gallerylist)) { foreach ($gallerylist as $gallery) { $selected = $gallery->gid == $galleryID ? ' selected="selected"' : ""; echo '<option value="' . $gallery->gid . '"' . $selected . ' >' . $gallery->title . '</option>' . "\n"; } } ?> </select> <input type="submit" id="show-gallery" value="<?php _e('Select »', 'flag'); ?> " class="button-secondary" /> </div> <br style="clear:both;" /> </div> </form> <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?> " class="media-upload-form" id="library-form"> <?php wp_nonce_field('flag-media-form'); ?> <script type="text/javascript"> <!-- jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); updateMediaForm(); } }); --> </script> <div id="media-items"> <?php if (is_array($picarray)) { foreach ($picarray as $picid) { //TODO:Reduce SQL Queries $picture = flagdb::find_image($picid); ?> <div id='media-item-<?php echo $picid; ?> ' class='media-item preloaded'> <div class='filename'></div> <a class='toggle describe-toggle-on' href='#'><?php _e('Show', "flag"); ?> </a> <a class='toggle describe-toggle-off' href='#'><?php _e('Hide', "flag"); ?> </a> <div class='filename new'><?php echo empty($picture->alttext) ? wp_html_excerpt($picture->filename, 60) : stripslashes(wp_html_excerpt($picture->alttext, 60)); ?> </div> <table class='slidetoggle describe startclosed'><tbody> <tr> <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr($picture->alttext); ?> ' src='<?php echo esc_attr($picture->thumbURL); ?> '/></td> <td><?php _e('Image ID:', "flag"); echo $picid; ?> </td> </tr> <tr><td><?php echo esc_attr($picture->filename); ?> </td></tr> <tr><td><?php echo esc_html(stripslashes($picture->alttext)); ?> </td></tr> <tr><td> </td></tr> <tr> <td class="label"><label for="image[<?php echo $picid; ?> ][alttext]"><?php _e('Alt/Title text', "flag"); ?> </label></td> <td class="field"><input id="image[<?php echo $picid; ?> ][alttext]" name="image[<?php echo $picid; ?> ][alttext]" value="<?php echo esc_html(stripslashes($picture->alttext)); ?> " type="text"/></td> </tr> <tr> <td class="label"><label for="image[<?php echo $picid; ?> ][description]"><?php _e("Description", "flag"); ?> </label></td> <td class="field"><textarea name="image[<?php echo $picid; ?> ][description]" id="image[<?php echo $picid; ?> ][description]"><?php echo esc_html(stripslashes($picture->description)); ?> </textarea></td> </tr> <tr class="align"> <td class="label"><label for="image[<?php echo $picid; ?> ][align]"><?php _e("Alignment"); ?> </label></td> <td class="field"> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-none-<?php echo $picid; ?> " checked="checked" value="none" type="radio" /> <label for="image-align-none-<?php echo $picid; ?> " class="align image-align-none-label"><?php _e("None"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-left-<?php echo $picid; ?> " value="left" type="radio" /> <label for="image-align-left-<?php echo $picid; ?> " class="align image-align-left-label"><?php _e("Left"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-center-<?php echo $picid; ?> " value="center" type="radio" /> <label for="image-align-center-<?php echo $picid; ?> " class="align image-align-center-label"><?php _e("Center"); ?> </label> <input name="image[<?php echo $picid; ?> ][align]" id="image-align-right-<?php echo $picid; ?> " value="right" type="radio" /> <label for="image-align-right-<?php echo $picid; ?> " class="align image-align-right-label"><?php _e("Right"); ?> </label> </td> </tr> <tr class="image-size"> <th class="label"><label for="image[<?php echo $picid; ?> ][size]"><span class="alignleft"><?php _e("Size"); ?> </span></label> </th> <td class="field"> <input name="image[<?php echo $picid; ?> ][size]" id="image-size-thumb-<?php echo $picid; ?> " type="radio" checked="checked" value="thumbnail" /> <label for="image-size-thumb-<?php echo $picid; ?> "><?php _e("Thumbnail"); ?> </label> <input name="image[<?php echo $picid; ?> ][size]" id="image-size-full-<?php echo $picid; ?> " type="radio" value="full" /> <label for="image-size-full-<?php echo $picid; ?> "><?php _e("Full size"); ?> </label> </td> </tr> <tr class="submit"> <td> <input type="hidden" name="image[<?php echo $picid; ?> ][thumb]" value="<?php echo $picture->thumbURL; ?> " /> <input type="hidden" name="image[<?php echo $picid; ?> ][url]" value="<?php echo $picture->imageURL; ?> " /> </td> <td class="savesend"><button type="submit" class="button" value="1" name="send[<?php echo $picid; ?> ]"><?php echo esc_attr(__('Insert into Post')); ?> </button></td> </tr> </tbody></table> </div> <?php } } ?> </div> <p class="ml-submit"> <input type="submit" class="button savebutton" name="save" value="<?php _e('Save all changes', 'flag'); ?> " /> </p> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?> " /> <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?> " /> </form> <?php }
function ewww_image_optimizer_defer() { ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>'); global $ewww_defer; $ewww_defer = false; $deferred_attachments = get_option('ewww_image_optimizer_defer_attachments'); foreach ($deferred_attachments as $image) { list($type, $id) = explode(',', $image, 2); switch ($type) { case 'media': ewwwio_debug_message("processing deferred {$type}: {$id}"); $meta = wp_get_attachment_metadata($id, true); // do the optimization for the current attachment (including resizes) $meta = ewww_image_optimizer_resize_from_meta_data($meta, $id, false); // update the metadata for the current attachment wp_update_attachment_metadata($id, $meta); break; case 'nextgen2': ewwwio_debug_message("processing deferred {$type}: {$id}"); // creating the 'registry' object for working with nextgen $registry = C_Component_Registry::get_instance(); // creating a database storage object from the 'registry' object $storage = $registry->get_utility('I_Gallery_Storage'); // get an image object $ngg_image = $storage->object->_image_mapper->find($id); ewwwngg::ewww_added_new_image($ngg_image, $storage); break; // case 'nextgen1': // ewwwio_debug_message( "processing deferred $type: $id" ); // break; // case 'nextgen1': // ewwwio_debug_message( "processing deferred $type: $id" ); // break; case 'nextcellent': ewwwio_debug_message("processing deferred {$type}: {$id}"); ewwwngg::ewww_ngg_optimize($id); break; case 'flag': ewwwio_debug_message("processing deferred {$type}: {$id}"); $flag_image = flagdb::find_image($id); ewwwflag::ewww_added_new_image($flag_image); break; case 'file': ewwwio_debug_message("processing deferred {$type}: {$id}"); ewww_image_optimizer($id); break; default: ewwwio_debug_message("unknown type in deferrred queue: {$type}, {$id}"); } ewww_image_optimizer_remove_deferred_attachment($image); ewww_image_optimizer_debug_log(); } ewwwio_memory(__FUNCTION__); return; }