/** * Renderize the view. * * @return null */ public function render(Post $post) { ?> <!-- JQUERY UI --> <link type="text/css" rel="stylesheet" href="<?php echo APP_PATH; ?> /css/jquery-ui.min.css"> <link type="text/css" rel="stylesheet" href="<?php echo APP_PATH; ?> /css/jquery-ui.theme.min.css"> <script type="text/javascript" src="<?php echo APP_PATH; ?> /js/jquery-ui.min.js"></script> <script type="text/javascript"> $(function(){ $("#date").datepicker({dateFormat: "yy-mm-dd"}); }); </script> <p> <?php echo REQUIRED_FIELDS_TEXT; ?> </p> <form action="<?php echo $this->generateURL('post', 'edit', $post->getIdPost()); ?> " method="post"> <fieldset> <div class="row"> <div class="col-md-6"> <div> <label for="title"> Título <small>(*)</small> </label> <input name="title" type="text" required value="<?php echo $post->getTitle(); ?> " /> </div> <div> <label for="headline"> Copete <small>(*)</small> </label> <textarea name="headline" required><?php echo $post->getHeadline(); ?> </textarea> </div> <div> <label for="date"> Fecha <small>(*)</small> </label> <input id="date" name="date" type="text" required value="<?php echo $post->getDate(); ?> " /> </div> <div> <label for="body"> Cuerpo <small>(*)</small> </label> <textarea name="body" required><?php echo $post->getBody(); ?> </textarea> </div> </div> <div class="col-md-6"> <div> <label for="source"> Fuente <small>(*)</small> </label> <input name="source" type="text" value="<?php echo $post->getSource(); ?> " required /> </div> <div> <label for="category"> Categoría <small>(*)</small> </label> <select name="category" required> <option value=""> Seleccionar </option> <?php if ($post->getCategory() === "Noticia") { ?> <option value="Noticia" selected> Noticia </option> <option value="Evento"> Evento </option> <?php } else { ?> <option value="Noticia"> Noticia </option> <option value="Evento" selected> Evento </option> <?php } ?> </select> </div> <div> <label for="status"> Estado <small>(*)</small> </label> <select name="status" required> <option value=""> Seleccionar </option> <?php if ($post->getStatus() === "DESTACADO") { ?> <option value="DESTACADO" selected> Destacado </option> <option value="NO DESTACADO"> No Destacado </option> <?php } else { ?> <option value="DESTACADO"> Destacado </option> <option value="NO DESTACADO" selected> No Destacado </option> <?php } ?> </select> </div> <div> <input type="submit" value="Modificar" /> </div> </div> </div> </fieldset> </form> <?php }
public function process($ctrl) { OW::getCacheManager()->clean(array(PostDao::CACHE_TAG_POST_COUNT)); $service = PostService::getInstance(); /* @var $postDao PostService */ $data = $this->getValues(); $data['title'] = UTIL_HtmlTag::stripJs($data['title']); $postIsNotPublished = $this->post->getStatus() == 2; $text = UTIL_HtmlTag::sanitize($data['post']); /* @var $post Post */ $this->post->setTitle($data['title']); $this->post->setPost($text); $this->post->setIsDraft($_POST['command'] == 'draft'); $isCreate = empty($this->post->id); if ($isCreate) { $this->post->setTimestamp(time()); //Required to make #698 and #822 work together if ($_POST['command'] == 'draft') { $this->post->setIsDraft(2); } BOL_AuthorizationService::getInstance()->trackAction('blogs', 'add_blog'); } else { //If post is not new and saved as draft, remove their item from newsfeed if ($_POST['command'] == 'draft') { OW::getEventManager()->trigger(new OW_Event('feed.delete_item', array('entityType' => 'blog-post', 'entityId' => $this->post->id))); } else { if ($postIsNotPublished) { // Update timestamp if post was published for the first time $this->post->setTimestamp(time()); } } } $service->save($this->post); $tags = array(); if (intval($this->post->getId()) > 0) { $tags = $data['tf']; foreach ($tags as $id => $tag) { $tags[$id] = UTIL_HtmlTag::stripTags($tag); } } $tagService = BOL_TagService::getInstance(); $tagService->updateEntityTags($this->post->getId(), 'blog-post', $tags); if ($this->post->isDraft()) { $tagService->setEntityStatus('blog-post', $this->post->getId(), false); if ($isCreate) { OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_draft_success_msg')); } else { OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_draft_success_msg')); } } else { $tagService->setEntityStatus('blog-post', $this->post->getId(), true); //Newsfeed $event = new OW_Event('feed.action', array('pluginKey' => 'blogs', 'entityType' => 'blog-post', 'entityId' => $this->post->getId(), 'userId' => $this->post->getAuthorId())); OW::getEventManager()->trigger($event); if ($isCreate) { OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'create_success_msg')); OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_ADD, array('postId' => $this->post->getId()))); } else { OW::getFeedback()->info(OW::getLanguage()->text('blogs', 'edit_success_msg')); OW::getEventManager()->trigger(new OW_Event(PostService::EVENT_AFTER_EDIT, array('postId' => $this->post->getId()))); } $ctrl->redirect(OW::getRouter()->urlForRoute('post', array('id' => $this->post->getId()))); } }
/** * Modify a post saved in the database. * * @param Post $post * @return integer */ public function editPost(Post $post) { $sql = "UPDATE post \n\t\t\tSET id_post = '" . $post->getIdPost() . "', title = '" . replaceCharacters($post->getTitle()) . "', headline = '" . replaceCharacters($post->getHeadline()) . "', date = '" . $post->getDate() . "', body = '" . $this->formatBody(replaceCharacters($post->getBody())) . "', source = '" . replaceCharacters($post->getSource()) . "', category = '" . $post->getCategory() . "', status = '" . $post->getStatus() . "' WHERE id_post = '" . $post->getIdPost() . "'"; return DB::query($sql); }