/** * View * * @param array $options * @return object */ public function view($options) { if (!$options['article_srl']) { core\Util::makeObject(['state' => 'error', 'message' => 'not found article_srl']); } // get article data $article = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'where' => 'srl=' . $options['article_srl'], 'jsonField' => ['json']]); if (!$article) { core\Util::makeObject(['state' => 'error', 'message' => 'not found article data']); } $article['regdate'] = core\Util::convertDate($article['regdate']); $article['modate'] = core\Util::convertDate($article['modate']); // set content type switch ($options['contentType']) { case 'markdown': // load parsedown require_once __GOOSE_PWD__ . 'vendor/Parsedown/Parsedown.class.php'; $parsedown = new Parsedown(); // convert markdown $article['content'] = '<div class="markdown-body">' . $parsedown->text($article['content']) . '</div>'; break; case 'text': $article['content'] = nl2br(htmlspecialchars($article['content'])); break; default: break; } // set prev,next item $print_data = explode(',', $options['print_data']); $str = ''; $str .= $this->searchKeyInArray($print_data, 'nest') ? 'nest_srl=' . (int) $article['nest_srl'] : ''; $str .= $this->searchKeyInArray($print_data, 'category') && $article['category_srl'] ? ' and category_srl=' . (int) $article['category_srl'] : ''; $str .= $str ? ' and ' : ' app_srl=' . $options['app_srl'] . ' and '; $prevItem = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'field' => 'srl', 'where' => $str . 'srl<' . (int) $article['srl'], 'order' => 'srl', 'sort' => 'desc', 'limit' => 1]); $nextItem = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'field' => 'srl', 'where' => $str . 'srl>' . (int) $article['srl'], 'order' => 'srl', 'limit' => 1]); // get nest data $nest = core\Spawn::item(['table' => core\Spawn::getTableName('Nest'), 'field' => 'srl,name,id,json', 'where' => 'srl=' . (int) $article['nest_srl'], 'jsonField' => ['json']]); // get category $category = $article['category_srl'] ? core\Spawn::item(['table' => core\Spawn::getTablename('Category'), 'field' => 'name', 'where' => 'srl=' . (int) $article['category_srl']]) : null; return core\Util::makeObject(['state' => 'success', 'article' => $article, 'nest' => $nest, 'category' => $category, 'prev_srl' => isset($prevItem['srl']) ? (int) $prevItem['srl'] : null, 'next_srl' => isset($nextItem['srl']) ? (int) $nextItem['srl'] : null, 'checkUpdateHit' => $options['updateHit'] ? $this->updateHit((int) $article['hit'], (int) $article['srl']) : null]); }