public static function render_view($view, $data)
 {
     $view = new ILabMediaToolView(ILAB_VIEW_DIR . '/' . $view);
     return $view->render($data);
 }
 /**
  * Render the edit ui
  */
 public function displayEditUI($is_partial = 0)
 {
     $image_id = esc_html(parse_req('image_id'));
     $current_preset = esc_html(parse_req('preset'));
     $partial = parse_req('partial', $is_partial);
     $size = esc_html(parse_req('size', 'full'));
     $meta = wp_get_attachment_metadata($image_id);
     $attrs = wp_get_attachment_image_src($image_id, $size);
     list($full_src, $full_width, $full_height, $full_cropped) = $attrs;
     $imgix_settings = [];
     $presets = get_option('ilab-imgix-presets');
     $sizePresets = get_option('ilab-imgix-size-presets');
     $presetsUI = $this->buildPresetsUI($image_id, $size);
     if ($current_preset && $presets && isset($presets[$current_preset])) {
         $imgix_settings = $presets[$current_preset]['settings'];
         $full_src = $this->buildImgixImage($image_id, $size, $imgix_settings)[0];
     } else {
         if ($size == 'full') {
             if (!$imgix_settings) {
                 if (isset($meta['imgix-params'])) {
                     $imgix_settings = $meta['imgix-params'];
                 }
             }
         } else {
             if (isset($meta['imgix-size-params'][$size])) {
                 $imgix_settings = $meta['imgix-size-params'][$size];
             } else {
                 if ($presets && $sizePresets && isset($sizePresets[$size]) && isset($presets[$sizePresets[$size]])) {
                     $imgix_settings = $presets[$sizePresets[$size]]['settings'];
                     if (!$current_preset) {
                         $current_preset = $sizePresets[$size];
                     }
                 }
             }
             if (!$imgix_settings && isset($meta['imgix-params'])) {
                 $imgix_settings = $meta['imgix-params'];
             }
         }
     }
     foreach ($this->paramPropsByType['media-chooser'] as $key => $info) {
         if (isset($imgix_settings[$key]) && !empty($imgix_settings[$key])) {
             $media_id = $imgix_settings[$key];
             $imgix_settings[$key . '_url'] = wp_get_attachment_url($media_id);
         }
     }
     if (current_user_can('edit_post', $image_id)) {
         if (!$partial) {
             echo ILabMediaToolView::render_view('imgix/ilab-imgix-ui.php', ['partial' => $partial, 'image_id' => $image_id, 'modal_id' => gen_uuid(8), 'size' => $size, 'sizes' => ilab_get_image_sizes(), 'meta' => $meta, 'full_width' => $full_width, 'full_height' => $full_height, 'tool' => $this, 'settings' => $imgix_settings, 'src' => $full_src, 'presets' => $presetsUI, 'currentPreset' => $current_preset, 'params' => $this->toolInfo['settings']['params'], 'paramProps' => $this->paramProps]);
         } else {
             json_response(['status' => 'ok', 'image_id' => $image_id, 'size' => $size, 'settings' => $imgix_settings, 'src' => $full_src, 'presets' => $presetsUI, 'currentPreset' => $current_preset, 'paramProps' => $this->paramProps]);
         }
     }
     die;
 }
 /**
  * Render the crop ui
  */
 public function displayCropUI()
 {
     $sizes = ilab_get_image_sizes();
     $image_id = esc_html($_GET['post']);
     $size = esc_html($_GET['size']);
     $meta = wp_get_attachment_metadata($image_id);
     $attrs = wp_get_attachment_image_src($image_id, 'full');
     list($full_src, $full_width, $full_height, $full_cropped) = $attrs;
     $orientation = $full_width < $full_height ? 'landscape' : 'portrait';
     $sizeInfo = $sizes[$size];
     $crop_width = $sizeInfo['width'];
     $crop_height = $sizeInfo['height'];
     $ratio = $crop_width / $crop_height;
     $crop_exists = !empty($meta['sizes'][$size]['file']);
     $crop_attrs = !$crop_exists ? null : wp_get_attachment_image_src($image_id, $size);
     $cropped_src = null;
     $cropped_width = null;
     $cropped_height = null;
     if ($crop_attrs) {
         list($cropped_src, $cropped_width, $cropped_height, $cropped_cropped) = $crop_attrs;
     }
     if (!$cropped_src) {
         $forcedCropAttrs = wp_get_attachment_image_src($image_id, $size);
         if ($forcedCropAttrs && count($forcedCropAttrs) > 2) {
             $cropped_src = $forcedCropAttrs[0];
             $cropped_width = $forcedCropAttrs[1];
             $cropped_height = $forcedCropAttrs[2];
         }
     }
     $partial = isset($_GET['partial']) && $_GET['partial'] == '1';
     $prev_crop_x = null;
     $prev_crop_y = null;
     $prev_crop_w = null;
     $prev_crop_h = null;
     if (isset($meta['sizes'][$size]['crop'])) {
         $prev_crop_x = $meta['sizes'][$size]['crop']['x'];
         $prev_crop_y = $meta['sizes'][$size]['crop']['y'];
         $prev_crop_w = $meta['sizes'][$size]['crop']['w'];
         $prev_crop_h = $meta['sizes'][$size]['crop']['h'];
     }
     $data = ['partial' => $partial, 'image_id' => $image_id, 'modal_id' => gen_uuid(8), 'size' => $size, 'sizes' => $sizes, 'meta' => $meta, 'full_width' => $full_width, 'full_height' => $full_height, 'orientation' => $orientation, 'crop_width' => $crop_width, 'crop_height' => $crop_height, 'crop_exists' => $cropped_src != null, 'crop_attrs' => $crop_attrs, 'ratio' => $ratio, 'tool' => $this, 'size' => $size, 'cropped_src' => $cropped_src, 'cropped_width' => $cropped_width, 'cropped_height' => $cropped_height, 'prev_crop_x' => $prev_crop_x, 'prev_crop_y' => $prev_crop_y, 'prev_crop_width' => $prev_crop_w, 'prev_crop_height' => $prev_crop_h, 'src' => $full_src];
     if (current_user_can('edit_post', $image_id)) {
         if (!$partial) {
             echo ILabMediaToolView::render_view('crop/ilab-crop-ui.php', $data);
         } else {
             json_response(['status' => 'ok', 'image_id' => $image_id, 'size' => $size, 'size_title' => ucwords(str_replace('-', ' ', $size)), 'min_width' => $crop_width, 'min_height' => $crop_height, 'aspect_ratio' => $ratio, 'prev_crop_x' => $prev_crop_x !== null ? (int) $prev_crop_x : null, 'prev_crop_y' => $prev_crop_y !== null ? (int) $prev_crop_y : null, 'prev_crop_width' => $prev_crop_w !== null ? (int) $prev_crop_w : null, 'prev_crop_height' => $prev_crop_h !== null ? (int) $prev_crop_h : null, 'cropped_src' => $cropped_src, 'cropped_width' => $cropped_width, 'cropped_height' => $cropped_height]);
         }
     }
     die;
 }