/** * Loads up *specific* theme layout, does NOT include a fallback like `from_files()` * in order to respect the cascade. */ public static function from_specific_files($data, $cascade, $storage_key = false) { $new_data = apply_filters('upfront_override_layout_data', $data, $cascade); if (empty($new_data)) { return false; } $data = $new_data; // We need to apply global regions that saved in db $regions = array(); $regions_added = array(); foreach ($data['regions'] as $region) { if ($region['scope'] != 'local') { $applied_scope = self::_apply_scoped_region($region); foreach ($applied_scope as $applied_data) { if (!in_array($applied_data['name'], $regions_added)) { $regions[] = $applied_data; $regions_added[] = $applied_data['name']; } } continue; } $regions[] = $region; } $data['regions'] = $regions; $data['properties'] = self::get_layout_properties(); $data['layout'] = self::$cascade; // Do not do this is in builder mode since it will duplicate slider images. Alternative // is to fix augment_regions to not re-import images every time page reloads. if (!function_exists('upfront_exporter_is_running') || !upfront_exporter_is_running()) { $data = apply_filters('upfront_augment_theme_layout', $data); } return self::from_php($data, $storage_key); }
function get_image_sizes() { $data = stripslashes_deep($_POST); $item_id = !empty($data['item_id']) ? $data['item_id'] : false; if (!$item_id) { $this->_out(new Upfront_JsonResponse_Error(Upfront_UimageView::_get_l10n('invalid_id'))); } $ids = json_decode($item_id); if (is_null($ids) || !is_array($ids)) { $this->_out(new Upfront_JsonResponse_Error(Upfront_UimageView::_get_l10n('invalid_id'))); } $custom_size = isset($data['customSize']) && is_array($data['customSize']); // Try to find images from slider in database. if (function_exists('upfront_exporter_is_running') && upfront_exporter_is_running()) { // Convert image theme paths to image ids $image_ids = array(); foreach ($ids as $id) { // Leave integers alone! if (is_numeric($id)) { $image_ids[] = $id; continue; } // Check if it really is image path if (!is_string($id) || strpos($id, 'images/') === false) { continue; } $image_filename = str_replace('/images/', '', $id); $image_id = $this->get_image_id_by_filename($image_filename); if (!is_null($image_id)) { $image_ids[] = $image_id; } } $ids = $image_ids; if (empty($ids)) { $this->_out(new Upfront_JsonResponse_Error(Upfront_UimageView::_get_l10n('Images have not been found in local WordPress.'))); } } $images = array(); $intermediate_sizes = get_intermediate_image_sizes(); $intermediate_sizes[] = 'full'; foreach ($ids as $id) { $sizes = array(); foreach ($intermediate_sizes as $size) { $image = wp_get_attachment_image_src($id, $size); if ($image) { $sizes[$size] = $image; } } if ($custom_size) { $image_custom_size = $this->calculate_image_resize_data($data['customSize'], array('width' => $sizes['full'][1], 'height' => $sizes['full'][2])); $image_custom_size['id'] = $id; if (!empty($data['element_id'])) { $image_custom_size['element_id'] = $data['element_id']; } $sizes['custom'] = $this->resize_image($image_custom_size); $sizes['custom']['editdata'] = $image_custom_size; } else { $sizes['custom'] = $custom_size ? $data['customSize'] : array(); } if (sizeof($sizes) != 0) { $images[$id] = $sizes; } } if (sizeof($images) == 0) { $this->_out(new Upfront_JsonResponse_Error(Upfront_UimageView::_get_l10n('no_id'))); } $result = array('given' => sizeof($ids), 'returned' => sizeof($ids), 'images' => $images); return $this->_out(new Upfront_JsonResponse_Success($result)); }