コード例 #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
ファイル: index.php プロジェクト: dev-goose/app-first-gallery
    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';
コード例 #3
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']);
 }
コード例 #4
0
ファイル: item.php プロジェクト: dev-goose/PhotoExhibition
    // 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]);
        if ($count) {
            // set paginate
            $paginate = new core\Paginate($count, $_GET['page'], [], $defaultItemCount, 10);
            // get article data
            $repo['articles'] = core\Spawn::items(['table' => core\Spawn::getTableName('Article'), 'where' => 'nest_srl=' . $nest_srl, 'limit' => [$paginate->offset, $paginate->size], 'order' => 'srl', 'sort' => 'asc', 'jsonField' => ['json']]);
            // set output data
            foreach ($repo['articles'] as $k => $v) {
                $item = ['srl' => $v['srl'], 'img' => __GOOSE_URL__ . '/' . $v['json']['thumbnail']['url'], 'title' => $v['title']];
                $output['result'][] = $item;
            }
            $next_page = $_GET['page'] + 1;
            $next_paginate = new core\Paginate($count, $next_page, [], $defaultItemCount, 10);
            $repo['next_article_count'] = core\Spawn::items(['table' => core\Spawn::getTableName('Article'), 'field' => 'srl', 'where' => 'nest_srl=' . $nest_srl, 'limit' => [$next_paginate->offset, $next_paginate->size]]);
            $output['next'] = 0 < count($repo['next_article_count']) ? true : false;
        }
        break;
}
// print output
echo json_encode($output);
core\Goose::end();