public function contentAction(OrmManager $orm, Cms $cms, ContentService $contentService, ImageUrlGenerator $imageUrlGenerator, $model, $id, $locale) { $model = $orm->getModel($model); $entry = $model->getById($id); if (!$entry) { $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND); return; } $site = $cms->getCurrentSite($this->request->getBaseUrl(), $locale); $content = $contentService->getContentForEntry($model, $entry, $site->getId(), $locale); if ($content->image) { $transformation = $this->request->getQueryParameter('transformation', 'crop'); $options = array('width' => $this->request->getQueryParameter('width', 100), 'height' => $this->request->getQueryParameter('height', 100)); $content->image = $imageUrlGenerator->generateUrl($content->image, $transformation, $options); } unset($content->data); $this->setJsonView($content); }
/** * Adds the OG meta tags for the provided content * @param \ride\web\cms\orm\ContentProperties $properties * @param \ride\library\cms\content\Content $content * @param \ride\library\image\ImageUrlGenerator $imageUrlGenerator * @return null */ protected function setMetaOg(ContentProperties $contentProperties, $content, ImageUrlGenerator $imageUrlGenerator) { $modelMeta = $this->model->getMeta(); $modelTable = $modelMeta->getModelTable(); // get formats $titleFormat = $contentProperties->getOgTitleFormat(); if (!$titleFormat) { $titleFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TITLE, false); if ($titleFormat == null) { $titleFormat = $this->model->getName() . ' #{id}'; } } $teaserFormat = $contentProperties->getOgTeaserFormat(); if (!$teaserFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_TEASER)) { $teaserFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TEASER); } $imageFormat = $contentProperties->getOgImageFormat(); if (!$imageFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_IMAGE)) { $imageFormat = $modelTable->getFormat(EntryFormatter::FORMAT_IMAGE); } // add meta $entryFormatter = $this->model->getOrmManager()->getEntryFormatter(); $node = $this->properties->getNode(); $node->setMeta($this->locale, 'og:title', $entryFormatter->formatEntry($content->data, $titleFormat)); if ($teaserFormat) { $teaser = $entryFormatter->formatEntry($content->data, $teaserFormat); if ($teaser) { $node->setMeta($this->locale, 'og:description', $teaser); } } if ($imageFormat) { $image = $entryFormatter->formatEntry($content->data, $imageFormat); if ($image) { $node->setMeta($this->locale, 'og:image', $imageUrlGenerator->generateUrl($image)); } } }