/** * Article detail page * * @return ViewModel */ public function detailAction() { $id = $this->params('id'); $slug = $this->params('slug', ''); $page = $this->params('p', 1); $remain = $this->params('r', ''); if ('' !== $remain) { $this->view()->assign('remain', $remain); } if (empty($id)) { $id = $this->getModel('extended')->slugToId($slug); } $details = Entity::getEntity($id); $details['id'] = $id; $params = array(); if (!$id or $details['time_publish'] > time()) { return $this->jumpTo404(__('Page not found')); } if (empty($details['active'])) { return $this->jumpToException(__('The article requested is not active'), 503); } $module = $this->getModule(); $route = Pi::api('api', $module)->getRouteName(); if (strval($slug) != $details['slug']) { $routeParams = array('time' => date('Ymd', $details['time_publish']), 'id' => $id, 'slug' => $details['slug'], 'p' => $page, 'controller' => 'article', 'action' => 'detail'); if ($remain) { $params['r'] = $remain; } return $this->redirect()->setStatusCode(301)->toRoute($route, array_merge($routeParams, $params)); } foreach ($details['content'] as &$value) { $value['url'] = $this->url($route, array_merge(array('time' => date('Ymd', $details['time_publish']), 'id' => $id, 'slug' => $slug, 'p' => $value['page'], 'controller' => 'article', 'action' => 'detail'), $params)); if (isset($value['title']) and preg_replace('/ /', '', trim($value['title'])) !== '') { $showTitle = true; } else { $value['title'] = ''; } } $details['view'] = $this->url($route, array_merge(array('time' => date('Ymd', $details['time_publish']), 'id' => $id, 'slug' => $slug, 'r' => 0, 'controller' => 'article', 'action' => 'detail'), $params)); $details['remain'] = $this->url($route, array_merge(array('time' => date('Ymd', $details['time_publish']), 'id' => $id, 'slug' => $slug, 'r' => $page, 'controller' => 'article', 'action' => 'detail'), $params)); $config = Pi::config('', $this->getModule()); $this->view()->assign(array('details' => $details, 'page' => $page, 'showTitle' => isset($showTitle) ? $showTitle : null, 'config' => $config, 'module' => $module)); }