Builds an Imgix URL

@param int $id
@param string|array $size
@param array|null $params
@param bool $skipParams
@param array|null $mergeParams
@param array|null $newSize
@param array|null $newMeta

@return array|bool
160196
private function buildImgixImage($id, $size, $params = null, $skipParams = false, $mergeParams = null, $newSize = null, $newMeta=null) {
		if(is_array($size)) {
			return $this->buildSizedImgixImage($id, $size);
		}

		$mimetype = get_post_mime_type($id);

        if (!$this->renderPDF && ($mimetype == 'application/pdf')) {
            return false;
        }

		$meta = wp_get_attachment_metadata($id);
		if(!$meta || empty($meta)) {
			if(($this->renderPDF && ($mimetype == 'application/pdf')) || ($this->enabledAlternativeFormats && ($mimetype == 'application/vnd.adobe.illustrator'))) {
				$meta = get_post_meta($id, 'ilab_s3_info', true);
			}

			if(!$meta || empty($meta)) {
			    if (!empty($newMeta)) {
			        $meta = $newMeta;
                } else {
				    return false;
                }
			}
		}

		if(!isset($meta['s3'])) {
			if(($this->renderPDF && ($mimetype == 'application/pdf')) || ($this->enabledAlternativeFormats && ($mimetype == 'application/vnd.adobe.illustrator'))) {
				$meta = get_post_meta($id, 'ilab_s3_info', true);
			} else {
				return false;
			}
		}

		$imgix = new UrlBuilder($this->imgixDomains, $this->useHTTPS);

		if($this->signingKey) {
			$imgix->setSignKey($this->signingKey);
		}

		if($size == 'full' && !$newSize) {
			if(!isset($meta['width']) || !isset($meta['height'])) {
				return false;
			}

			if(!$params) {
				if(isset($meta['imgix-params'])) {
					$params = $meta['imgix-params'];
				} else {
					$params = [];
				}
			}

			$params = $this->buildImgixParams($params, $mimetype);
			$params = apply_filters('ilab-imgix-filter-parameters', $params, $size, $id, $meta);

			if(!isset($meta['file'])) {
				return null;
			}

			$imageFile = (isset($meta['s3'])) ? $meta['s3']['key'] : $meta['file'];

			$result = [
				$imgix->createURL(str_replace('%2F', '/', urlencode($imageFile)), ($skipParams) ? [] : $params),
				$meta['width'],
				$meta['height'],
				false
			];

			return $result;
		}

		if($newSize) {
			$sizeInfo = $newSize;
		} else {
			$sizeInfo = ilab_get_image_sizes($size);
		}

		if(!$sizeInfo) {
			return false;
		}

		$metaSize = null;
		if(isset($meta['sizes'][$size])) {
			$metaSize = $meta['sizes'][$size];
		}

		$doCrop = !empty($sizeInfo['crop']);

		if(!$params) {
		    $sizeParams = (!empty($sizeInfo['imgix']) && is_array($sizeInfo['imgix'])) ? $sizeInfo['imgix'] : [];
		    $sizeCropParams = (isset($sizeParams['crop'])) ? $sizeParams['crop'] : [];
		    if (!empty($sizeCropParams)) {
                if (is_string($sizeCropParams)) {
                    $sizeCropParams = explode(',', $sizeCropParams);
                    unset($sizeParams['crop']);
                }

                $doCrop = true;
            }

            // get the settings for this image at this size
			if(isset($meta['imgix-size-params'][$size])) {
				$params = array_merge($sizeParams, $meta['imgix-size-params'][$size]);
			}


			if(!$params || (count($params) == 0)) // see if a preset has been globally assigned to a size and use that
			{
				$presets = get_option('ilab-imgix-presets');
				$sizePresets = get_option('ilab-imgix-size-presets');

				if($presets && $sizePresets && isset($sizePresets[$size]) && isset($presets[$sizePresets[$size]])) {
					$params = array_merge($sizeParams, $presets[$sizePresets[$size]]['settings']);
				}
			}

			// still no parameters?  use any that may have been assigned to the full size image
			if((!$params || (count($params) == 0)) && (isset($meta['imgix-params']))) {
				$params = array_merge($sizeParams, $meta['imgix-params']);
			} else if(!$params) // too bad so sad
			{
				$params = $sizeParams;
			}
		}

		if ($doCrop) {
			$params['w'] = $sizeInfo['width'] ?: $sizeInfo['height'];
			$params['h'] = $sizeInfo['height'] ?: $sizeInfo['width'];
			$params['fit'] = 'crop';

			if($metaSize) {
				$metaSize = $meta['sizes'][$size];
				if(isset($metaSize['crop'])) {
					$metaSize['crop']['x'] = round($metaSize['crop']['x']);
					$metaSize['crop']['y'] = round($metaSize['crop']['y']);
					$metaSize['crop']['w'] = round($metaSize['crop']['w']);
					$metaSize['crop']['h'] = round($metaSize['crop']['h']);
					$params['rect'] = implode(',', $metaSize['crop']);
				}
			}

			// we don't want to scale animated gifs AT ALL on the front end
			if(($mimetype == 'image/gif') && (!is_admin())) {
				$imageW = $meta['width'];
				$imageH = $meta['height'];

				$pw = $params['w'];
				$ph = $params['h'];

				if(($pw > $imageW) || ($ph > $imageH)) {
					$newSize = sizeToFitSize($pw, $ph, $imageW, $imageH);
					$params['w'] = $newSize[0];
					$params['h'] = $newSize[1];
				}
			}

			if (isset($params['focalpoint'])) {
			    unset($params['rect']);

			    if ($params['focalpoint'] == 'entropy') {
				    $params['crop'] = 'entropy';
				    unset($params['fp-x']);
				    unset($params['fp-y']);
				    unset($params['fp-z']);
                } else if ($params['focalpoint'] == 'edges') {
				    $params['crop'] = 'edges';
				    unset($params['fp-x']);
				    unset($params['fp-y']);
				    unset($params['fp-z']);
                } else {
				    $params['crop'] = 'focalpoint';
				    if ($params['focalpoint'] == 'usefaces') {
					    unset($params['fp-x']);
					    unset($params['fp-y']);

					    if (isset($meta['faces'])) {
						    $faceindex = arrayPath($params,'faceindex', 0);
						    if ((count($meta['faces'])>1) && ($faceindex == 0)) {
							    $left = 900000;
							    $top = 900000;
							    $right = 0;
							    $bottom = 0;

							    foreach($meta['faces'] as $face) {
								    $bb = $face['BoundingBox'];
								    $left = min($left, $bb['Left']);
								    $top = min($top, $bb['Top']);
								    $right = max($right, $bb['Left'] + $bb['Width']);
								    $bottom = max($bottom, $bb['Top'] + $bb['Height']);
							    }

							    $params['fp-x'] = $left + (($right - $left) / 2.0);
							    $params['fp-y'] = $top + (($bottom - $top) / 2.0);
						    } else {
							    if ($faceindex == 0) {
								    $faceindex = 1;
							    }

							    $faceindex = min(count($meta['faces'])+1, $faceindex);
							    $bb = $meta['faces'][$faceindex - 1]['BoundingBox'];

							    $params['fp-x'] = $bb['Left'] + ($bb['Width'] / 2.0);
							    $params['fp-y'] = $bb['Top'] + ($bb['Height'] / 2.0);
						    }

					    } else {
						    unset($params['crop']);
						    unset($params['fp-z']);
					    }
				    }
                }
            } else {
				unset($params['fp-x']);
				unset($params['fp-y']);
				unset($params['fp-z']);

                $cropParams = [];

                if (!empty($sizeInfo['crop']) && is_array($sizeInfo['crop'])) {
                    list($cropX, $cropY) = $sizeInfo['crop'];
                    if (!empty($cropX) && ($cropX != 'center')) {
                        $cropParams[] = $cropX;
                    }
                    if (!empty($cropY) && ($cropY != 'center')) {
                        $cropParams[] = $cropY;
                    }
                }

                if (!empty($sizeCropParams)) {
                    $cropParams = array_merge($cropParams, $sizeCropParams);
                }

                if (!empty($cropParams)) {
                    $params['crop'] = implode(",", $cropParams);
                }
            }
		} else {
			$mw = !empty($meta['width']) ? $meta['width'] : 10000;
			$mh = !empty($meta['height']) ? $meta['height'] : 10000;

			$w = !empty($sizeInfo['width']) ? $sizeInfo['width'] : 10000;
			$h = !empty($sizeInfo['height']) ? $sizeInfo['height'] : 10000;

			$newSize = sizeToFitSize($mw, $mh, $w, $h);
			$params['w'] = $newSize[0];
			$params['h'] = $newSize[1];
			$params['fit'] = 'scale';

			unset($params['fp-x']);
			unset($params['fp-y']);
			unset($params['fp-z']);
		}

		unset($params['focalpoint']);
		unset($params['faceindex']);

		if($mergeParams && is_array($mergeParams)) {
			$params = array_merge($params, $mergeParams);
		}

		if($size && !is_array($size)) {
			$params['wpsize'] = $size;
		}

		$params = $this->buildImgixParams($params, $mimetype);
		$params = apply_filters('ilab-imgix-filter-parameters', $params, $size, $id, $meta);

		$imageFile = (isset($meta['s3'])) ? $meta['s3']['key'] : $meta['file'];

		$result = [
			$imgix->createURL(str_replace('%2F', '/', urlencode($imageFile)), $params),
			$params['w'],
			$params['h'],
			true
		];

		return $result;
	}
399940
public function url($id, array $params = array())
    {
        $route = $this->getRoute($id);

        if (!isset($route)) {
            throw new \RuntimeException('Named route not found for id: '.$id);
        }

        $search = array();
        foreach ($params as $key => $value) {
            // try to match ':{key}' fragments and replace it with value
            $search[] = '#:'.preg_quote($key, '#').'\+?(?!\w)#';
        }

        $pattern = preg_replace($search, $params, $route[3]['pattern']);

        // Remove remnants of unpopulated, trailing optional pattern segments, escaped special characters
        return preg_replace('#\(/?:.+\)|\(|\)|\\\\#', '', $pattern);
    }
753934
public function id_to_url($id){
    if ( $file = $this->id_to_real($id) ){
      return $this->real_to_url($file);
    }
    return false;
  }
1278887
public function downloadPreview(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::GET,
            ResourceMethodEnum::DOWNLOAD_PREVIEW,
            $params,
            $id
        );
    }
65666
public function sizeUrl($size)
    {
        if (($this->base['return_format'] === 'array') && isset($this->base['value']['sizes'][$size])) {
            return $this->base['value']['sizes'][$size];
        } elseif ($this->base['return_format'] === 'id') {
            if ($src = wp_get_attachment_image_src($this->id(), $size)) {
                return $src[0];
            }
        }

        return '';
    }
1017739
function buildPhotoURL ($photo, $size = "Medium")
    {
        //receives an array (can use the individual photo data returned
        //from an API call) and returns a URL (doesn't mean that the
        //file size exists)
        $sizes = array(
                "square" => "_s",
                "thumbnail" => "_t",
                "small" => "_m",
                "medium" => "",
                "large" => "_b",
                "original" => "_o"
                );

        $size = strtolower($size);
        if (!array_key_exists($size, $sizes)) {
            $size = "medium";
        }

        if ($size == "original") {
            $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['originalsecret'] . "_o" . "." . $photo['originalformat'];
        } else {
            $url = "http://farm" . $photo['farm'] . ".static.flickr.com/" . $photo['server'] . "/" . $photo['id'] . "_" . $photo['secret'] . $sizes[$size] . ".jpg";
        }
        return $url;
    }
763235
public function createMeta($id, array $arguments)
    {
        $parameters = $this->resolveMetaArguments($arguments);

        return $this->resolveMeta('make', [
            $id,
            $parameters['key'],
            $parameters['value'],
            $parameters['unique'],
        ]);
    }
1234776
public function buildGifJpeg($value, $postId, $size) {
		return $this->buildImgixImage($postId, $size, null, false, ['fmt' => 'pjpg']);
	}
766245
public function detailAction($id = null)
    {
        $media = $this->get('opifer.media.media_manager')->getRepository()->find($id);

        $media = $this->get('jms_serializer')->serialize($media, 'json', SerializationContext::create()->setGroups(['Default', 'detail']));

        return new JsonResponse(json_decode($media, true));
    }
40720
public function thumbnailURL($size = 'large')
    {
        if (!in_array($size, ['large', 'medium', 'small'])) {
            return false;
        }

        $info = $this->parseLink();
        $service = $this->getService();

        if (!$info || !$service) {
            return false;
        }

        if ($service == 'YouTube') {
            if ($size == 'large') {
                $img = 'hqdefault.jpg';
            } elseif ($size == 'medium') {
                $img = 'mqdefault.jpg';
            } else {
                $img = 'default.jpg';
            }
            return 'https://i.ytimg.com/vi/' . $this->VideoID . '/' . $img;
        }

        if ($service == 'Vimeo') {
            $data = $this->getCachedJsonResponse(
                'https://vimeo.com/api/v2/video/' . $this->VideoID . '.json'
            );

            if (!$data) {
                return false;
            }

            if ($size == 'large' && (!empty($data[0]['thumbnail_large']))) {
                return $data[0]['thumbnail_large'];
            } elseif ($size == 'medium' && (!empty($data[0]['thumbnail_medium']))) {
                return $data[0]['thumbnail_medium'];
            } elseif (!empty($data[0]['thumbnail_small'])) {
                return $data[0]['thumbnail_small'];
            }
        }

        return false;
    }
1255623
public function get(int $id, $params = [])
    {
        if ($this->fields) {
            $params['fields'] = implode(',', $this->fields);
        }

        $uriAppend = 'byId/' . $id;
        $response  = $this->handler->handle('GET', false, $uriAppend, $params);

        return $this->make($response, false);
    }
936084
public function copy(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::POST,
            ResourceMethodEnum::COPY,
            $params,
            $id
        );
    }
730022
public function make(string $id, array $parameters = [], bool $createNew = false)
    {
        if (isset($this->alias[$id])) {
            $id = $this->alias[$id];
        }

        if ($createNew || ! isset($this->objects[$id])) {
            $concrete = isset($this->bindings[$id]) ?
                        $this->bindings[$id] :
                        $id;

            $this->objects[$id] = $this->resolve($concrete, $parameters);
        }

        return $this->objects[$id];
    }
1314048
public function make($module, $action = "", $id = null, $params = []) {
        $url = URL_ABSOLUTE . $module;
        if ($action !== "") {
            $url .= '-' . $action;
            if ($id !== null) {
                $url .= '-' . $id;
            }
        }

        $first = true;
        foreach ($params as $i => $param)
        {
            if ($first) {$url .= "?"; $first=false;}
            else {$url .= "&";}
            $url .= $i . "=" . $param;
        }
        return $url;
    }
1360990
public function copyAction(Request $request, $id)
    {
        /** @var PageInterface $page */
        $page = $this->admin->getObject($id);

        if (!$page) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }

        if ($request->getMethod() == 'POST') {
            $pageHelper = $this->container->get('networking_init_cms.helper.page_helper');

	        $pageCopy = false;
            try {
                $pageCopy = $pageHelper->makePageCopy($page);
                $this->admin->createObjectSecurity($pageCopy);
                $status = 'success';
                $message = $this->translate(
                    'message.copy_saved',
                    ['%page%' => $pageCopy]
                );
                $result = 'ok';
                $html = $this->renderView(
                    '@NetworkingInitCms/PageAdmin/page_translation_settings.html.twig',
                    ['object' => $page, 'admin' => $this->admin]
                );
            } catch (\Exception $e) {
                $status = 'error';
                $message = $message = $this->translate(
                    'message.copy_not_saved',
                    ['%page%' => $page, '%url%' => $page->getFullPath()]
                );
                $result = 'error';
                $html = '';
            }

            if ($this->isXmlHttpRequest()) {
                return $this->renderJson(
                    [
                        'result' => $result,
                        'status' => $status,
                        'html' => $html,
                        'message' => $message,
                    ]
                );
            }

            $this->get('session')->getFlashBag()->add(
                'sonata_flash_'.$status,
                $message
            );

            if($pageCopy){
	            $request->getSession()->set('Page.last_edited', $pageCopy->getId());
            }


            return $this->redirect($this->admin->generateUrl('list'));
        }

        return $this->renderWithExtraParams(
            '@NetworkingInitCms/PageAdmin/page_copy.html.twig',
            [
                'language' => \Locale::getDisplayLanguage($page->getLocale()),
                'action' => 'copy',
                'page' => $page,
                'id' => $id,
                'admin' => $this->admin,
            ]
        );
    }
134186
public function show(string $id = null, int $width = 0, int $height = 0, bool $fit = false): StreamedResponse
    {
        return $this->service->show($id, $width, $height, $fit);
    }
548874
public function createForFolder(string $id, array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::POST,
            ResourceMethodEnum::CREATE_FOR_FOLDER,
            $params,
            $id
        );
    }