/**
  * Action to show the last comments
  * @return null
  */
 public function indexAction()
 {
     $contentFacade = ContentFacade::getInstance();
     $comments = $this->models[CommentModel::NAME]->getLatestComments(5);
     foreach ($comments as $comment) {
         $content = $contentFacade->getContent($comment->objectType, $comment->objectId);
         $comment->title = $content->title;
         $comment->url = $content->url . '#comment' . $comment->id;
     }
     $view = new LastCommentsView($comments);
     $this->response->setView($view);
 }
/**
 * Creates a anchor to the provided data
 * @param string $data The primary key of the content or the data object pf the content
 * @param string $type The name of the content type
 * @return string Parsed string
 */
function smarty_modifier_contentUrl($data, $type = null)
{
    if (!$data) {
        return '';
    }
    if (!$type) {
        return '';
    }
    $contentFacade = ContentFacade::getInstance();
    try {
        return $contentFacade->getUrl($type, $data);
    } catch (Exception $exception) {
        Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
        return '';
    }
}
Example #3
0
 public function initializeContentMappers()
 {
     $request = Zibo::getInstance()->getRequest();
     if (!$request instanceof JoppaRequest) {
         return;
     }
     $contentFacade = ContentFacade::getInstance();
     $contentMappers = $contentFacade->getTypes();
     $nodeModel = ModelManager::getInstance()->getModel(NodeModel::NAME);
     $nodes = $nodeModel->getNodesForWidget('joppa', 'contentDetail');
     foreach ($nodes as $node) {
         $modelName = $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_MODEL_NAME);
         if (in_array($modelName, $contentMappers)) {
             continue;
         }
         $recursiveDepth = $node->widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_RECURSIVE_DEPTH);
         $mapper = new ContentMapper($modelName, $recursiveDepth);
         $contentFacade->setMapper($modelName, $mapper);
         $contentMappers[] = $modelName;
     }
 }
 /**
  * Action to show the preview of the forum
  * @return null
  *
  * @todo what about hidden boards?
  */
 public function indexAction()
 {
     $nodesForum = $this->models[NodeModel::NAME]->getNodesForWidget('joppa', 'forum');
     if (!$nodesForum) {
         return;
     }
     $nodeForum = array_shift($nodesForum);
     $urlForum = $this->request->getBaseUrl() . '/' . $nodeForum->getRoute();
     $numPosts = $this->getNumberOfPosts();
     $posts = $this->models[ForumPostModel::NAME]->getLastPosts($numPosts);
     $contentFacade = ContentFacade::getInstance();
     foreach ($posts as $post) {
         $post->topic->firstPost = $this->models[ForumPostModel::NAME]->getPostsForTopic($post->topic->id, 1, 1);
         $post->url = $contentFacade->getUrl(ForumPostModel::NAME, $post);
         if ($post->author) {
             $post->author->url = $contentFacade->getUrl(ForumProfileModel::NAME, $post->author);
         }
     }
     $view = new ForumPreviewWidgetView($posts, $urlForum);
     $this->response->setView($view);
 }
Example #5
0
 /**
  * Load the registered content types which implement SearchableContentMapper
  * @return null
  */
 private function loadMappers()
 {
     $this->mappers = array();
     $contentFacade = ContentFacade::getInstance();
     $types = $contentFacade->getTypes();
     foreach ($types as $type) {
         $mapper = $contentFacade->getMapper($type);
         if ($mapper instanceof SearchableContentMapper) {
             $this->mappers[$type] = $mapper;
         }
     }
 }
Example #6
0
 public function replyAction($idTopic, $idQuotePost = null)
 {
     $topic = $this->models[ForumTopicModel::NAME]->getTopic($idTopic);
     if (!$topic) {
         $this->setError404();
         return;
     }
     $idProfile = null;
     $profile = $this->getProfile();
     if ($profile) {
         $idProfile = $profile->id;
     }
     if (!$topic->board->isNewPostAllowed($profile)) {
         $this->addError(self::TRANSLATION_ERROR_ALLOW_VIEW, array('object' => $topic->board->name));
         return;
     }
     $contentFacade = ContentFacade::getInstance();
     $post = $this->models[ForumPostModel::NAME]->createData(false);
     $topicPost = $this->models[ForumPostModel::NAME]->getFirstPostForTopic($topic->id);
     $post->subject = 'RE: ' . $topicPost->subject;
     if ($idQuotePost) {
         $quotePost = $this->models[ForumPostModel::NAME]->findById($idQuotePost, 0);
         if ($quotePost) {
             $quotePost->topic = $topic;
             $quoteUrl = $contentFacade->getUrl(ForumPostModel::NAME, $quotePost);
             $post->message = '[quote=' . $quoteUrl . ']' . $quotePost->message . '[/quote]';
         }
     }
     $emoticonParser = $this->models[ForumPostModel::NAME]->getEmoticonParser();
     $form = new ForumPostForm($this->request->getBasePath() . '/' . self::ACTION_REPLY . '/' . $topic->id, $post, $emoticonParser);
     $preview = null;
     if ($form->isSubmitted()) {
         if ($form->isCancelled()) {
             $this->response->setRedirect($this->request->getBasePath() . '/' . self::ACTION_TOPIC . '/' . $topic->id);
             return;
         }
         try {
             $post = $form->getPost();
             if ($form->isSubmitted()) {
                 $post->author = $idProfile;
                 $topic = $this->models[ForumTopicModel::NAME]->replyTopic($topic->id, $post);
                 $post->topic = $topic;
                 $this->response->setRedirect($contentFacade->getUrl(ForumPostModel::NAME, $post));
                 return;
             } elseif ($form->getValue(ForumPostForm::FIELD_PREVIEW)) {
                 $preview = $post;
             }
         } catch (ValidationException $e) {
             $form->setValidationException($e);
         }
     }
     $translator = $this->getTranslator();
     $board = $this->models[ForumBoardModel::NAME]->findById($topicPost->topic->board, 0);
     $category = $this->models[ForumCategoryModel::NAME]->findById($board->category, 0);
     $this->addBreadcrumb($this->request->getBasePath(), $category->name);
     $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_BOARD . '/' . $board->id, $board->name);
     $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_TOPIC . '/' . $topicPost->topic->id, $topicPost->subject);
     $this->addBreadcrumb($this->request->getBasePath() . '/' . self::ACTION_REPLY . '/' . $topicPost->topic->id, $translator->translate(self::TRANSLATION_TOPIC_REPLY));
     $view = new ForumPostFormView($form, self::TRANSLATION_TOPIC_REPLY, $preview, $emoticonParser);
     $this->response->setView($view);
 }
 /**
  * Gets the result from the query
  * @param zibo\library\orm\model\Model $model
  * @param zibo\library\orm\query\ModelQuery $query
  * @param joppa\content\model\ContentProperties $properties
  * @return array Array with Content objects
  */
 private function getResult(ContentProperties $contentProperties, $model, $query)
 {
     $data = $query->queryFirst();
     if (!$data) {
         return $data;
     }
     $meta = $model->getMeta();
     $modelTable = $meta->getModelTable();
     $dataFormatter = $meta->getDataFormatter();
     $titleFormat = $contentProperties->getContentTitleFormat();
     if (!$titleFormat && $modelTable->hasDataFormat(DataFormatter::FORMAT_TITLE)) {
         $titleFormat = $modelTable->getDataFormat(DataFormatter::FORMAT_TITLE)->getFormat();
     }
     $teaserFormat = $contentProperties->getContentTeaserFormat();
     if (!$teaserFormat && $modelTable->hasDataFormat(DataFormatter::FORMAT_TEASER)) {
         $teaserFormat = $modelTable->getDataFormat(DataFormatter::FORMAT_TEASER)->getFormat();
     }
     $imageFormat = $modelTable->getDataFormat(DataFormatter::FORMAT_IMAGE, false);
     if ($imageFormat) {
         $imageFormat = $imageFormat->getFormat();
     }
     $dateFormat = $modelTable->getDataFormat(DataFormatter::FORMAT_DATE, false);
     if ($dateFormat) {
         $dateFormat = $dateFormat->getFormat();
     }
     try {
         $mapper = ContentFacade::getInstance()->getMapper($model->getName());
     } catch (ZiboException $e) {
         $mapper = null;
     }
     $title = $dataFormatter->formatData($data, $titleFormat);
     $url = null;
     $teaser = null;
     $image = null;
     $date = null;
     if ($teaserFormat) {
         $teaser = $dataFormatter->formatData($data, $teaserFormat);
     }
     if ($imageFormat) {
         $image = $dataFormatter->formatData($data, $imageFormat);
     }
     if ($dateFormat) {
         $date = $dataFormatter->formatData($data, $dateFormat);
     }
     if ($mapper) {
         $url = $mapper->getUrl($data);
     }
     $content = new Content($title, $url, $teaser, $image, $date, $data);
     return $content;
 }