/** * hit update * 조회수 올리기 * * @Param {Number} $srl : article_srl * @Return void */ function hitUpdate($srl) { // 내부 아이피라면 조회수를 올리지 않는다. if (preg_match("/(192.168)/", $_SERVER['REMOTE_ADDR'])) { return false; } // get article data $article = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'field' => 'srl,hit', 'where' => 'srl=' . $srl]); // check article data if (!count($article)) { return false; } if (!isset($_COOKIE['hit-' . $article['srl']])) { // set cookie setcookie('hit-' . $article['srl'], 1, time() + 3600 * 24); // update db $article['hit'] += 1; $result = core\Spawn::update(['table' => core\Spawn::getTableName('Article'), 'where' => 'srl=' . $article['srl'], 'data' => ['hit=' . $article['hit']]]); } }
exit; } @error_reporting(E_ALL ^ E_NOTICE); if (is_bool(DEBUG) && DEBUG) { @define(__StartTime__, array_sum(explode(' ', microtime()))); } // is localhost define('__IS_LOCAL__', preg_match("/(192.168)/", $_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] == "::1" ? true : false); // load program files require_once __GOOSE_LIB__; // load functions require_once 'lib/func.php'; // get preferences try { // get preference data $tmp = core\Spawn::item(['table' => core\Spawn::getTableName('JSON'), 'field' => 'json', 'where' => 'srl=' . (int) $srl_json_pref])['json']; if (!$tmp) { throw new Exception('not found preference data'); } // set preference $pref = new stdClass(); $pref->string = $tmp; $pref->json = core\Util::jsonToArray($tmp, null, true); } catch (\Exception $e) { echo $e->getMessage(); core\Goose::end(); } // init router $router = core\Module::load('Router'); $router->route->setBasePath(__ROOT__); require_once 'lib/map.php';
/** * Up like * * @param array $options * @return object */ public function upLike($options) { if (!$this->checkAuthHeader($options['header_key'])) { return core\Util::makeObject(['state' => 'error', 'message' => 'Path not allowed']); } if (!$options['article_srl']) { return core\Util::makeObject(['state' => 'error', 'message' => 'not found article_srl']); } $article = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'where' => 'srl=' . $options['article_srl'], 'field' => 'srl,json', 'jsonField' => ['json']]); if (!isset($article['json'])) { return core\Util::makeObject(['state' => 'error', 'message' => 'not found article data']); } $like = isset($article['json']['like']) ? (int) $article['json']['like'] : 0; $article['json']['like'] = $like + 1; $json = core\Util::arrayToJson($article['json'], true); $result = core\Spawn::update(['table' => core\Spawn::getTableName('Article'), 'data' => ['json=\'' . $json . '\''], 'where' => 'srl=' . (int) $options['article_srl']]); return $result == 'success' ? core\Util::makeObject(['state' => 'success', 'message' => 'update complete']) : core\Util::makeObject(['state' => 'error', 'message' => 'fail update complete']); }
break; } hitUpdate($_GET['srl']); // get article $repo['article'] = core\Spawn::item(['table' => core\Spawn::getTableName('Article'), 'where' => 'srl=' . (int) $_GET['srl'], 'jsonField' => ['json']]); // get files $repo['files'] = core\Spawn::items(['table' => core\Spawn::getTableName('File'), 'where' => 'article_srl=' . (int) $_GET['srl']]); // set output $output = ['srl' => $repo['article']['srl'], 'img' => __GOOSE_URL__ . '/' . $repo['file']['loc'], 'title' => $repo['article']['title']]; break; // article - view index // article - view index case 'viewIndex': $articles = core\Spawn::items(['table' => core\Spawn::getTableName('Article'), 'field' => 'srl,title', 'where' => 'nest_srl=' . $nest_srl]); foreach ($articles as $k => $v) { $file = core\Spawn::item(['table' => core\Spawn::getTableName('File'), 'field' => 'loc', 'where' => 'article_srl=' . $v['srl']]); $output['result'][] = ['srl' => $v['srl'], 'img' => __GOOSE_URL__ . '/' . $file['loc'], 'title' => $v['title']]; } break; // article - update hit count // article - update hit count case 'updateHit': hitUpdate($_GET['srl']); $output = ["state" => "success"]; break; // article - index // article - index default: $_GET['page'] = (int) $_GET['page'] > 1 ? (int) $_GET['page'] : 1; // get count $count = core\Spawn::count(['table' => core\Spawn::getTableName('Article'), 'where' => 'nest_srl=' . $nest_srl]);