Beispiel #1
0
 /**
  * api - get count
  *
  * @param array $getParams
  * @return array
  */
 public function getCount($getParams = null)
 {
     if ($this->name != 'category') {
         return array('state' => 'error', 'message' => '잘못된 객체로 접근했습니다.');
     }
     // set original parameter
     $originalParam = array('table' => Spawn::getTableName($this->name));
     // get data
     $data = Spawn::count(Util::extendArray($originalParam, $getParams));
     // return data
     return array('state' => 'success', 'data' => (int) $data);
 }
Beispiel #2
0
    if ($post['thumnail_image']) {
        // load file module
        if (file_exists(__GOOSE_PWD__ . $article_json['thumnail']['url'])) {
            unlink(__GOOSE_PWD__ . $article_json['thumnail']['url']);
        }
        // upload
        $thumnailUrl = uploadThumnail($_POST['thumnail_image']);
        // set json
        $new_article_json['thumnail']['srl'] = $thumnail_srl;
        $new_article_json['thumnail']['url'] = $thumnailUrl;
        $thumnailUploaded = true;
    }
    // 썸네일 이미지는 있고, 썸네일 이미지가 새로 만들어지지 않을때
    if ($article_json['thumnail']['srl'] && !$thumnailUploaded) {
        // get article item data
        $filesCount = Spawn::count(array('table' => Spawn::getTableName('file'), 'where' => 'article_srl=' . (int) $post['article_srl'] . ' and srl=' . (int) $article_json['thumnail']['srl']));
        if (!$filesCount) {
            // delete thumnail file
            if (file_exists(__GOOSE_PWD__ . $article_json['thumnail']['url'])) {
                unlink(__GOOSE_PWD__ . $article_json['thumnail']['url']);
            }
            // set json
            $new_article_json['thumnail'] = array('srl' => '0', 'url' => '', 'coords' => '');
        }
    }
    // convert array to json
    $json_result = Util::arrayToJson($new_article_json, true);
    // update article
    $result = Spawn::update(array('table' => Spawn::getTableName('article'), 'where' => 'srl=' . (int) $article_srl, 'data' => array("json='{$json_result}'")));
}
// return
Beispiel #3
0
require_once __GOOSE_PWD__ . 'data/config.php';
// create and connect database
$this->goose->createSpawn();
$this->goose->spawn->connect($dbConfig);
$this->goose->spawn->prefix = $table_prefix;
// set admin
$this->goose->isAdmin = true;
// install modules
$arr = array('user', 'nest', 'app', 'json', 'file', 'article', 'category');
foreach ($arr as $k => $v) {
    $result = $this->installModule($v);
    echo "<p>Create table - " . $result['message'] . "</p>";
}
// add admin user
$result = Spawn::insert(array('table' => Spawn::getTableName('user'), 'data' => array('srl' => null, 'email' => $_POST['email'], 'name' => $_POST['name'], 'pw' => md5($_POST['password']), 'level' => $_POST['adminLevel'], 'regdate' => date("YmdHis"))));
echo "<p>Add admin user - " . ($result == 'success' ? 'Complete' : "ERROR : {$result}") . "</p>";
// add basic navigation on json table
$cnt = Spawn::count(array('table' => Spawn::getTableName('json'), 'where' => "name='Goose Navigation'"));
if (!$cnt) {
    $data = Util::checkUserFile(__GOOSE_PWD__ . 'core/misc/navigationTree.json');
    $data = Util::openFile($data);
    $data = Util::jsonToArray($data, true, true);
    $data = Util::arrayToJson($data, true);
    $result = Spawn::insert(array('table' => __dbPrefix__ . 'json', 'data' => array('srl' => null, 'name' => 'Goose Navigation', 'json' => $data, 'regdate' => date("YmdHis"))));
} else {
    $result = '"Goose Navigation" Data already exists.';
}
echo "<p>Add json data - " . ($result == 'success' ? 'Complete' : "ERROR : {$result}") . "</p>";
echo "<hr/>";
echo "<h1>END INSTALL</h1>";
echo "<nav><a href=\"" . __GOOSE_ROOT__ . "\">Go to intro page</a></nav>";
Beispiel #4
0
<?php

if (!defined('__GOOSE__')) {
    exit;
}
// check user
if (!$this->isAdmin) {
    return array('state' => 'error', 'action' => 'back', 'message' => '권한이 없습니다.');
}
// check post
$errorValue = Util::checkExistValue($post, array('id', 'name'));
if ($errorValue) {
    return array('state' => 'error', 'action' => 'back', 'message' => "[{$errorValue}]값이 없습니다.");
}
// id값 중복검사
$app = Spawn::item(array('table' => Spawn::getTableName($this->name), 'field' => 'id', 'where' => "srl=" . (int) $post['app_srl']));
if ($app['id'] != $post['id']) {
    $cnt = Spawn::count(array('table' => Spawn::getTableName($this->name), 'where' => "id='{$post['id']}'"));
    if ($cnt > 0) {
        return array('state' => 'error', 'action' => 'back', 'message' => '"' . $post['id'] . '"이름의 id가 이미 존재합니다.');
    }
}
// update data
$result = Spawn::update(array('table' => Spawn::getTableName($this->name), 'where' => 'srl=' . (int) $post['app_srl'], 'data' => array("id='{$post['id']}'", "name='{$post['name']}'")));
if ($result != 'success') {
    return array('state' => 'error', 'action' => 'back', 'message' => 'Fail execution database');
}
// redirect url
return array('state' => 'success', 'action' => 'redirect', 'url' => __GOOSE_ROOT__ . $this->name . '/index/');
 /**
  * Index
  *
  * @param array $options : {
  *
  * }
  * @return array
  */
 public function index($options)
 {
     $result = ['nest' => null, 'category' => null, 'articles' => null, 'pageNavigation' => null, 'nextpage' => null];
     $print = explode(',', $options['print_data']);
     // get nests
     if ($options['nest_id']) {
         $result['nest'] = Spawn::item(['table' => Spawn::getTableName('nest'), 'where' => 'id=\'' . $options['nest_id'] . '\'', 'debug' => false]);
         $result['nest'] = $result['nest'] ? $result['nest'] : null;
         if (isset($result['nest']['srl'])) {
             $result['nest']['json'] = Util::jsonToArray($result['nest']['json'], false, true);
         } else {
             return ['state' => 'error', 'message' => 'not found nest data'];
         }
         // get categories list
         if ($result['nest']['json']['useCategory'] && $this->searchKeyInArray($print, 'category')) {
             $result['category'] = Spawn::items(['table' => Spawn::getTableName('category'), 'where' => 'nest_srl=' . (int) $result['nest']['srl'], 'field' => 'srl,name', 'order' => 'turn', 'sort' => 'asc']);
             $cnt_all = Spawn::count(['table' => Spawn::getTableName('article'), 'where' => 'app_srl=' . $options['app_srl'] . ' and nest_srl=' . (int) $result['nest']['srl']]);
             if (count($result['category'])) {
                 $check_active = false;
                 $index = [['srl' => 0, 'name' => 'All', 'count' => $cnt_all, 'active' => false]];
                 foreach ($result['category'] as $k => $v) {
                     $cnt = $cnt_all > 0 ? Spawn::count(['table' => Spawn::getTableName('article'), 'where' => 'category_srl=' . (int) $v['srl']]) : 0;
                     if ($options['category_srl'] == (int) $v['srl']) {
                         $check_active = true;
                     }
                     $index[] = ['srl' => (int) $v['srl'], 'name' => $v['name'], 'count' => $cnt, 'active' => $options['category_srl'] == (int) $v['srl']];
                 }
                 if (!$check_active) {
                     $index[0]['active'] = true;
                 }
                 $result['category'] = $index;
             }
         }
     }
     // get articles
     // init paginate
     require_once __GOOSE_PWD__ . 'core/classes/Paginate.class.php';
     $options['page'] = $options['page'] > 1 ? $options['page'] : 1;
     $count = $options['count'];
     $scale = $options['pageScale'];
     $params = ['keyword' => $_GET['keyword'] ? $_GET['keyword'] : ''];
     $nest_srl = $options['nest_id'] ? isset($result['nest']['srl']) ? $result['nest']['srl'] : -1 : null;
     $where = 'app_srl=' . $options['app_srl'];
     $where .= $nest_srl ? ' and nest_srl=' . $nest_srl : '';
     $where .= $options['category_srl'] ? ' and category_srl=' . (int) $options['category_srl'] : '';
     $where .= $_GET['keyword'] ? ' and (title LIKE "%' . $_GET['keyword'] . '%" or content LIKE "%' . $_GET['keyword'] . '%")' : '';
     // get total article
     $total = Spawn::count(['table' => Spawn::getTableName('article'), 'where' => $where]);
     // set paginate instance
     $paginate = new Paginate($total, $_GET['page'], $params, $count, $scale);
     // set limit
     $limit = $paginate->offset . ',' . $paginate->size;
     // get articles
     $result['articles'] = Spawn::items(['table' => Spawn::getTableName('article'), 'field' => 'srl,nest_srl,category_srl,hit,json,regdate,title', 'where' => $where, 'limit' => $limit, 'sort' => 'desc', 'order' => 'srl']);
     // adjustment articles
     if ($this->searchKeyInArray($print, 'article')) {
         foreach ($result['articles'] as $k => $v) {
             if (isset($v['regdate'])) {
                 $result['articles'][$k]['regdate'] = Util::convertDate($v['regdate']);
             }
             if (isset($v['modate'])) {
                 $result['articles'][$k]['modate'] = Util::convertDate($v['modate']);
             }
             if (isset($v['category_srl'])) {
                 $category = Spawn::item(['table' => Spawn::getTableName('category'), 'where' => 'srl=' . (int) $v['category_srl']]);
                 $result['articles'][$k]['category_name'] = isset($category['name']) ? $category['name'] : '';
             }
             $result['articles'][$k]['json'] = Util::jsonToArray($v['json'], false, true);
         }
     }
     // set paginate
     if ($this->searchKeyInArray($print, 'nav_paginate')) {
         $result['pageNavigation'] = $paginate->createNavigationToObject();
     }
     // set nextpage
     if ($this->searchKeyInArray($print, 'nav_more')) {
         $nextPaginate = new Paginate($total, $options['page'] + 1, $params, $count, $scale);
         $limit = $nextPaginate->offset . ',' . $nextPaginate->size;
         $nextArticles = Spawn::items(['table' => Spawn::getTableName('article'), 'field' => 'srl', 'where' => $where, 'limit' => $limit, 'sort' => 'desc', 'order' => 'srl']);
         $result['nextpage'] = count($nextArticles) ? $options['page'] + 1 : null;
     }
     $result['nest'] = $this->searchKeyInArray($print, 'nest') ? $result['nest'] : null;
     $result['articles'] = $this->searchKeyInArray($print, 'article') ? $result['articles'] : null;
     $result['state'] = 'success';
     return $result;
 }
Beispiel #6
0
<?php

if (!defined('__GOOSE__')) {
    exit;
}
// check user
if (!$this->isAdmin) {
    return array('state' => 'error', 'action' => 'back', 'message' => '권한이 없습니다.');
}
// check post
$errorValue = Util::checkExistValue($post, array('name', 'id', 'json'));
if ($errorValue) {
    return array('state' => 'error', 'action' => 'back', 'message' => "[{$errorValue}]값이 없습니다.");
}
// 아이디값 중복 확인
$cnt = Spawn::count(array('table' => Spawn::getTableName('nest'), 'where' => "id='{$post['id']}'"));
if ($cnt > 0) {
    return array('state' => 'error', 'action' => 'back', 'message' => 'id가 이미 존재합니다.');
}
// insert data
$result = Spawn::insert(array('table' => Spawn::getTableName('nest'), 'data' => array('srl' => null, 'app_srl' => (int) $post['app_srl'], 'id' => $post['id'], 'name' => $post['name'], 'json' => $post['json'], 'regdate' => date('YmdHis'))));
if ($result != 'success') {
    return array('state' => 'error', 'action' => 'back', 'message' => 'Fail execution database');
}
// redirect url
$params = $_SESSION['app_srl'] ? $_SESSION['app_srl'] : '';
return array('state' => 'success', 'action' => 'redirect', 'url' => __GOOSE_ROOT__ . 'nest/index/' . $params);
Beispiel #7
0
 /**
  * api - get data
  * 데이터를 얻어오는 역할을 하는 메서드
  *
  * @param string $method
  * @param array $get parameter
  * @return array
  */
 private function api_get($method, $get)
 {
     if (!$this->auth($get['api_key'])) {
         return array('state' => 'error', 'message' => '올바른 api_key값이 아닙니다.');
     }
     // check mod value
     if (!$get['mod']) {
         return array('state' => 'error', 'message' => 'mod값이 없습니다.');
     }
     // set table
     $get['table'] = $get['table'] ? $get['table'] : $get['mod'];
     // get module
     $activeMod = Module::load($get['mod']);
     // get allow field
     if (!count($activeMod->set['allowApi']['read'])) {
         return array('state' => 'error', 'message' => '해당모듈에 허용하는 필드에 접근할 수 없습니다.');
     }
     // set parameters
     $params = $this->parameterToArray($get, $activeMod->set['allowApi']['read'][$get['table']]);
     switch ($method) {
         // get count
         case 'count':
             $result = Spawn::count(array('table' => Spawn::getTableName($params['table']), 'where' => $params['where'] ? $params['where'] : null));
             return array('state' => 'success', 'data' => $result);
             break;
             // get single item
         // get single item
         case 'single':
             $result = Spawn::item(array('table' => Spawn::getTableName($params['table']), 'field' => $params['field'], 'where' => $params['where'], 'debug' => false));
             if (!$result) {
                 $result = array();
             }
             return array('state' => 'success', 'data' => $result);
             break;
             // get multiple items
         // get multiple items
         case 'multi':
             $total = Spawn::count(array('table' => Spawn::getTableName($params['table']), 'where' => $params['where']));
             if ($total > 0) {
                 require_once __GOOSE_PWD__ . 'core/classes/Paginate.class.php';
                 $params['page'] = $params['page'] > 1 ? $params['page'] : 1;
                 $params['limit'] = $params['limit'] ? $params['limit'] : $this->set['defaultPagePerCount'];
                 $params['sort'] = $params['sort'] ? $params['sort'] : $params['order'] ? "desc" : "";
                 $paginate = new Paginate($total, $params['page'], array(), $params['limit'], 1);
                 $result = Spawn::items(array('table' => Spawn::getTableName($params['table']), 'field' => $params['field'], 'where' => $params['where'], 'order' => $params['order'], 'sort' => $params['sort'], 'limit' => array($paginate->offset, $paginate->size), 'debug' => false));
             } else {
                 $result = array();
             }
             return array('state' => 'success', 'data' => $result);
             break;
             // no method
         // no method
         default:
             return array('state' => 'error', 'message' => 'method값이 없습니다.');
             break;
     }
 }