/** * Gets the browser path for the image and filter to apply. * * @param string $path * @param string $filter * @param array $runtimeConfig * * @return \Twig_Markup */ public function filter($path, $filter, array $runtimeConfig = array()) { return new \Twig_Markup( $this->cacheManager->getBrowserPath($path, $filter, $runtimeConfig), 'utf8' ); }
/** * @param UserInterface $user * @param string $filter * @param array $runtimeConfig * * @return null|string */ public function getUserAvartar(UserInterface $user = null, $filter = '70x70', array $runtimeConfig = array()) { if (!$user) { return; } if ($avatar = $user->getProfilePicture()) { if (preg_match('/\\/\\//', $avatar)) { return $avatar; } if (empty($runtimeConfig)) { $runtimeConfig = array('thumbnail' => array("size" => explode('x', $filter), "mode" => 'inset')); } /** * We must to define `sizing` filter first! * eg. * * liip_imagine: * filter_sets: * sizing: * data_loader: cmf_media_doctrine_phpcr * filters: * thumbnail: { size: [200, 200], mode: inset } */ return $this->cacheManager->getBrowserPath($avatar, 'sizing', $runtimeConfig); } return; }
public function reverseConvert($object) { if (is_string($object)) { return $this->cacheManager->getBrowserPath($object, 'user_photo_review'); } return $this->defaultAvatar; }
/** * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { // getSubscribedEvents doesn't seem to support parent classes if (!$event->getObject() instanceof MediaInterface) { return; } $provider = $this->pool->getProvider($event->getObject()->getProvider()); if ($provider->getName() == 'image') { $reference = $provider->getThumb($event->getObject()); $groups = $event->getContext()->attributes->get('groups'); if (!$groups instanceof None && in_array('detail', $groups->get())) { $filters = array_keys($this->filterConfig->all()); } else { $filters = ['medialibrary']; } $variants = []; foreach ($filters as $filter) { if ($event->getObject()->getContentType() == 'image/svg+xml') { $variants[$filter] = $provider->getUrl($event->getObject()); } else { $variants[$filter] = $this->cacheManager->getBrowserPath($reference, $filter); } } $event->getVisitor()->addData('images', $variants); } $event->getVisitor()->addData('original', $provider->getUrl($event->getObject())); }
/** * @param File $file * * @return string|null */ private function getThumbnail(File $file) { $ext = $this->getExtension($file); if (!in_array($ext, self::IMAGE_EXTENSIONS)) { return; } return $this->cache_manager->getBrowserPath($file->getName(), $this->filter_name); }
public function filter($file, $filter, array $runtimeConfig = []) { if (is_object($file)) { return new \Twig_Markup($this->fileService->getFilteredPath($file, $filter), 'utf8'); } else { return new \Twig_Markup($this->cacheManager->getBrowserPath($file, $filter, $runtimeConfig), 'utf8'); } }
/** * {@inheritdoc} */ public function convertItem($user) { $result = parent::convertItem($user); $result['avatar'] = null; $imagePath = $this->getPropertyValue('imagePath', $user); if ($imagePath) { $result['avatar'] = $this->cacheManager->getBrowserPath($imagePath, self::IMAGINE_AVATAR_FILTER); } return $result; }
/** * Gets the browser path for the image and filter to apply. * * @param string $path * @param string $filter * @param array $runtimeConfig * * @return \Twig_Markup */ public function filter($path, $filter, array $runtimeConfig = array()) { if ($path instanceof ImageInterface) { $path = $path->getPath(); } if (empty($path)) { return $this->imageHolderPath . '/' . $this->getFilterDimension($filter); } return new \Twig_Markup($this->cacheManager->getBrowserPath($path, $filter, $runtimeConfig), 'utf8'); }
/** * Finds first available image for listing purposes * * @param Content $content * * @return string */ public function getCoverImage(Content $content) { $key = $content->getCoverImageCacheKey(); if (!($image = $this->cache->fetch($key))) { $image = $content->getCoverImage(); if ($image) { $image = $this->imageCacheManager->getBrowserPath($image, 'medialibrary'); } $this->cache->save($key, $image, 86400); } return $image; }
/** * Serialize a single file. * * @param AbstractFile $File * * @return array */ public function serialize(AbstractFile $file) { $fileFile = $file->getFile(); $data = ['id' => $file->getId(), 'name' => $file->getFileName(), 'path' => $this->vich->asset($file, 'file'), 'size' => $this->formatSize(is_null($fileFile) ? $file->getFileSize() : $fileFile->getSize()), 'mime' => is_null($fileFile) ? $file->getMimeType() : $fileFile->getMimeType()]; if ($file->isImage()) { $fileName = $this->vich->asset($file, 'file'); $data['thumb'] = $this->imagine->getBrowserPath($fileName, 'tgmedia_thumbnail'); } else { $data['type'] = $file->getExtension(); } return $data; }
/** * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $object = $event->getObject(); // getSubscribedEvents doesn't seem to support parent classes if (!$object instanceof Content) { return; } if (false !== ($coverImage = $this->getCoverImage($object))) { $coverImage = $this->cacheManager->getBrowserPath($coverImage, 'medialibrary'); $event->getVisitor()->addData('coverImage', $coverImage); } $event->getVisitor()->addData('path', $this->router->generate('_content', ['slug' => $object->getSlug()])); }
/** * @param ActivityInterface $object * @return null|array */ public function reverseConvert($object) { if ($object instanceof ActivityInterface) { // Retrieve user for activity $user = $object->getUser(); if ($user instanceof UserInterface) { $photo = $this->defaultAvatar; if (is_string($user->getPhoto())) { $photo = $this->cacheManager->getBrowserPath($user->getPhoto(), 'user_photo_review'); } return ['id' => $user->getId(), 'firstName' => $user->getFirstName(), 'middleName' => $user->getMiddleName(), 'lastName' => $user->getLastName(), 'photo' => $photo]; } } return null; }
public function testDefaultResolverUsedIfNoneSet() { $resolver = $this->getMockResolver(); $resolver->expects($this->once())->method('getBrowserPath')->with('cats.jpeg', 'thumbnail', true); $config = $this->getMockFilterConfiguration(); $config->expects($this->once())->method('get')->with('thumbnail')->will($this->returnValue(array('size' => array(180, 180), 'mode' => 'outbound', 'cache' => null))); $cacheManager = new CacheManager($config, $this->getMockRouter(), $this->fixturesDir . '/assets', 'default'); $cacheManager->addResolver('default', $resolver); $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail', true); }
/** * @param string $operationId * @return string * @throws \Exception */ public function execute($operationId) { /** @var NewsItem $newsItem */ $newsItem = $this->em->getRepository('CampaignChainOperationLinkedInBundle:NewsItem')->findOneByOperation($operationId); if (!$newsItem) { throw new \Exception('No news item found for an operation with ID: ' . $operationId); } //have images? $images = $this->em->getRepository('CampaignChainHookImageBundle:Image')->getImagesForOperation($newsItem->getOperation()); // if the message does not contain a url, we need to skip the content block if (is_null($newsItem->getLinkUrl())) { // LinkedIn accepts an image link only if we also provided a submitted URL. if ($images) { throw new \Exception('To include an image, you must also provide a URL in the text message.'); return self::STATUS_WARNING; } $content = ['comment' => $newsItem->getMessage(), 'visibility' => ['code' => 'anyone']]; } else { /* * process urls and add tracking * important: both the urls in the message and submitted url field must be identical */ $newsItem->setLinkUrl($this->ctaService->processCTAs($newsItem->getLinkUrl(), $newsItem->getOperation())->getContent()); $newsItem->setMessage($this->ctaService->processCTAs($newsItem->getMessage(), $newsItem->getOperation())->getContent()); $content = ['comment' => $newsItem->getMessage(), 'content' => ['title' => $newsItem->getLinkTitle(), 'description' => $newsItem->getLinkDescription(), 'submitted-url' => $newsItem->getLinkUrl()], 'visibility' => ['code' => 'anyone']]; if ($images) { //Linkedin can handle only 1 image $content['content']['submitted-image-url'] = $this->cacheManager->getBrowserPath($images[0]->getPath(), "campaignchain_linkedin_news_item"); } } $activity = $newsItem->getOperation()->getActivity(); $locationModuleIdentifier = $activity->getLocation()->getLocationModule()->getIdentifier(); $isCompanyPageShare = 'campaignchain-linkedin-page' == $locationModuleIdentifier; $connection = $this->client->getConnectionByActivity($activity); if ($isCompanyPageShare) { $response = $connection->shareOnCompanyPage($activity, $content); } else { $response = $connection->shareOnUserPage($content); } $newsItem->setUrl($response['updateUrl']); $newsItem->setUpdateKey($response['updateKey']); // Set Operation to closed. $newsItem->getOperation()->setStatus(Action::STATUS_CLOSED); $location = $newsItem->getOperation()->getLocations()[0]; $location->setIdentifier($response['updateKey']); $location->setUrl($response['updateUrl']); $location->setName($newsItem->getOperation()->getName()); $location->setStatus(Medium::STATUS_ACTIVE); // Schedule data collection for report $this->reportShareNewsItem->schedule($newsItem->getOperation()); $this->em->flush(); $this->message = 'The message "' . $newsItem->getMessage() . '" with the ID "' . $newsItem->getUpdateKey() . '" has been posted on LinkedIn. See it on LinkedIn: <a href="' . $newsItem->getUrl() . '">' . $newsItem->getUrl() . '</a>'; return self::STATUS_OK; }
/** * {@inheritdoc} */ public function getBrowserPath($path, $filter, array $runtimeConfig = array(), $resolver = null) { $info = pathinfo($path); $url = parent::getBrowserPath($path, $filter, $runtimeConfig, $resolver); $newPath = parse_url($url, PHP_URL_PATH); $newInfo = pathinfo($newPath); if ($info['extension'] != $newInfo['extension']) { $query = parse_url($url, PHP_URL_QUERY); $url .= ($query ? '&' : '?') . 'originalExtension=' . $info['extension']; } return $url; }
/** * {@inheritdoc} */ public function getUrls() { if (is_null($this->urls) || $this->refresh === true) { $this->urls = []; $this->refresh = false; foreach ($this->options['images'] as $image) { $filterName = $this->mappingService->getImagineFilterName($this->className, $this->fieldName, $this->layout, $image); $this->urls[] = $this->cacheManager->getBrowserPath($this->sources[$image['index']], $filterName); } } return $this->urls; }
public function testFilterActionUrlGeneratedAndReturnIfResolverReturnNullOnGetBrowserPath() { $resolver = $this->createResolverMock(); $resolver->expects($this->once())->method('isStored')->with('cats.jpeg', 'thumbnail')->will($this->returnValue(false)); $resolver->expects($this->never())->method('resolve'); $config = $this->createFilterConfigurationMock(); $config->expects($this->atLeastOnce())->method('get')->with('thumbnail')->will($this->returnValue(array('size' => array(180, 180), 'mode' => 'outbound', 'cache' => null))); $router = $this->createRouterMock(); $router->expects($this->once())->method('generate')->will($this->returnValue('/media/cache/thumbnail/cats.jpeg')); $cacheManager = new CacheManager($config, $router, new Signer('secret'), $this->createEventDispatcherMock()); $cacheManager->addResolver('default', $resolver); $actualBrowserPath = $cacheManager->getBrowserPath('cats.jpeg', 'thumbnail'); $this->assertEquals('/media/cache/thumbnail/cats.jpeg', $actualBrowserPath); }
/** * {@inheritdoc} */ public function getImage(string $path, string $filter, array $config = []) : string { return $this->cacheManager->getBrowserPath($path, $filter, $config); }
/** * @param string $operationId * @return string * @throws \Exception */ public function execute($operationId) { /** @var StatusBase $status */ $status = $this->em->getRepository('CampaignChainOperationFacebookBundle:StatusBase')->findOneByOperation($operationId); if (!$status) { throw new \Exception('No Facebook status found for an operation with ID: ' . $operationId); } // Check whether the message can be posted in the Location. $isExecutable = $this->validator->isExecutableByLocation($status, $status->getOperation()->getStartDate()); if ($isExecutable['status'] == false) { throw new JobException($isExecutable['message'], ErrorCode::OPERATION_NOT_EXECUTABLE_IN_LOCATION); } /* * If it is a campaign or parent campaign with an interval (e.g. * repeating campaign), we make sure that every URL will be shortened to * avoid a duplicate status message error. */ $options = array(); if ($status->getOperation()->getActivity()->getCampaign()->getInterval() || $status->getOperation()->getActivity()->getCampaign()->getParent() && $status->getOperation()->getActivity()->getCampaign()->getParent()->getInterval()) { $options['shorten_all_unique'] = true; } /* * Process URLs in message and save the new message text, now including * the replaced URLs with the Tracking ID attached for call to action * tracking. */ $status->setMessage($this->cta->processCTAs($status->getMessage(), $status->getOperation(), $options)->getContent()); /** @var \Facebook $connection */ $connection = $this->client->connectByActivity($status->getOperation()->getActivity()); if (!$connection) { throw new JobException('Cannot connect to Facebook REST API for Location "' . $status->getOperation()->getActivity()->getLocation()->getUrl() . '"', ErrorCode::CONNECTION_TO_REST_API_FAILED); } $paramsMsg = array(); /* * If an image was attached, we'll first upload the photo to Facebook * and then use the Facebook object ID of the picture in the message. */ $images = $this->em->getRepository('CampaignChainHookImageBundle:Image')->getImagesForOperation($status->getOperation()); if ($images) { $paramsImg = array(); $paramsImg['caption'] = $status->getMessage(); // Avoid that feed shows "... added a new photo" entry automtically. $paramsImg['no_story'] = 1; //Facebook handles only 1 image $paramsImg['url'] = $this->cacheManager->getBrowserPath($images[0]->getPath(), "campaignchain_facebook_photo"); try { $responseImg = $connection->api('/' . $status->getFacebookLocation()->getIdentifier() . '/photos', 'POST', $paramsImg); $paramsMsg['object_attachment'] = $responseImg['id']; } catch (\Exception $e) { throw new ExternalApiException($e->getMessage() . '. Parameters of REST API call: ' . json_encode($paramsImg), $e->getCode(), $e); } } if ($status instanceof UserStatus) { $privacy = array('value' => $status->getPrivacy()); $paramsMsg['privacy'] = json_encode($privacy); } $paramsMsg['message'] = $status->getMessage(); try { $responseMsg = $connection->api('/' . $status->getFacebookLocation()->getIdentifier() . '/feed', 'POST', $paramsMsg); } catch (\Exception $e) { throw new ExternalApiException($e->getMessage() . '. Parameters of REST API call: ' . json_encode($paramsMsg), $e->getCode(), $e); } $connection->destroySession(); // Set URL to published status message on Facebook $statusURL = 'https://www.facebook.com/' . str_replace('_', '/posts/', $responseMsg['id']); $status->setUrl($statusURL); $status->setPostId($responseMsg['id']); // Set Operation to closed. $status->getOperation()->setStatus(Action::STATUS_CLOSED); $location = $status->getOperation()->getLocations()[0]; $location->setIdentifier($responseMsg['id']); $location->setUrl($statusURL); $location->setName($status->getOperation()->getName()); $location->setStatus(Medium::STATUS_ACTIVE); // Schedule data collection for report $this->report->schedule($status->getOperation()); $this->em->flush(); $this->message = 'The message "' . $paramsMsg['message'] . '" with the ID "' . $responseMsg['id'] . '" has been posted on Facebook'; if ($status instanceof UserStatus) { $this->message .= ' with privacy setting "' . $privacy['value'] . '"'; } $this->message .= '. See it on Facebook: <a href="' . $statusURL . '">' . $statusURL . '</a>'; return self::STATUS_OK; }
/** * Generate thumbs section * with LiipImageService * * @param CacheManager $liipManager * @return $this */ public function generateThumbs(CacheManager $liipManager) { $path = $this->getPath(false); $this->thumbs = array('preview' => $liipManager->getBrowserPath($path, 'preview'), 'category' => $liipManager->getBrowserPath($path, 'category')); return $this; }
/** * Gets the browser path for the image and filter to apply. * * @param string $path * @param string $filter * @param boolean $absolute * * @return string */ public function filter($path, $filter, $absolute = false) { return $this->cacheManager->getBrowserPath($path, $filter, $absolute); }
/** * {@inheritdoc} */ public function getUrl($key) { return $this->imagine->getBrowserPath($key, 'original'); }
/** * Get the URL where the given file can be reached * * We are using the imagine bundle to create a public * url for the images, independent where are they stored * * @param string $file * @param string $filter * @return string */ public function getPublicUrl($file, $filter = "auto_rotate") { return $this->cacheManager->getBrowserPath($file, $filter); }
/** * Gets the browser path for the image and filter to apply. * * @param string $path * @param string $filter * @param array $runtimeConfig * * @return \Twig_Markup */ public function filter($path, $filter, array $runtimeConfig = array()) { return $this->cacheManager->getBrowserPath($path, $filter, $runtimeConfig); }
/** * {@inheritdoc} */ public function getImage($path, $filter, array $config = []) { return $this->manager->getBrowserPath($path, $filter, $config); }
/** * {@inheritdoc} */ public function imageFilter($path, $filter, array $runtimeConfig = [], $resolver = null) { return $this->cacheManager->getBrowserPath($path, $filter, $runtimeConfig, $resolver); }