コード例 #1
0
ファイル: func.php プロジェクト: dev-goose/PhotoExhibition
/**
 * 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']]]);
    }
}
コード例 #2
0
 /**
  * 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']);
 }