/** * login transaction */ private function loginTransaction() { $user = Spawn::item(array('table' => Spawn::getTableName('user'), 'where' => "email='{$_POST['email']}'")); if ($user && $user['pw'] === md5($_POST['password'])) { $_SESSION['goose_name'] = $user['name']; $_SESSION['goose_email'] = $user['email']; $_SESSION['goose_level'] = $user['level']; $url = strpos($_POST['redir'], 'auth/login') ? __GOOSE_ROOT__ : $_POST['redir']; Util::redirect($url); Goose::end(); } else { Util::back('로그인정보가 맞지 않습니다.'); } Goose::end(); }
/** * upload file db update * tempFiles 테이블에 있는 임시파일들 목록을 files 테이블에 옮기고, 썸네일으로 사용하는 첨부파일 번호를 리턴한다. * * @param array $post $_POST * @param int $art_srl 글을 등록하고 바로 가져온 srl번호 * @param int $thum_srl 썸네일 srl번호 * @return int 바뀐 썸네일 srl번호 */ function fileUpload($post, $art_srl, $thum_srl) { $thumnail_srl = null; if ($post['addQueue']) { $queue = explode(',', $post['addQueue']); foreach ($queue as $k => $v) { if (!$v) { continue; } $tmpFile = Spawn::item(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); if (count($tmpFile)) { // insert file $result = Spawn::insert(array('table' => Spawn::getTableName('file'), 'data' => array('srl' => null, 'article_srl' => $art_srl, 'name' => $tmpFile['name'], 'loc' => $tmpFile['loc'], 'type' => $tmpFile['type'], 'size' => $tmpFile['size'], 'regdate' => date("YmdHis")))); // set thumnail srl if ($tmpFile['srl'] == $thum_srl) { $thumnail_srl = Spawn::getLastIdx(); } // remove tmp file $result = Spawn::delete(array('table' => Spawn::getTableName('file_tmp'), 'where' => 'srl=' . (int) $v)); } } } return $thumnail_srl ? $thumnail_srl : $thum_srl; }
/** * get data item * * @param array $getParam * @return array|null */ public function getItem($getParam = array()) { if ($this->name != 'category') { return array('state' => 'error', 'message' => '잘못된 객체로 접근했습니다.'); } // set original parameter $originalParam = array('table' => Spawn::getTableName($this->name)); // get data $data = Spawn::item(Util::extendArray($originalParam, $getParam)); // check data if (!$data) { return array('state' => 'error', 'message' => '데이터가 없습니다.'); } // return data return array('state' => 'success', 'data' => $data); }
<?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/');
@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__; require_once 'lib/func.php'; // get preferences try { $tmp = Spawn::item(['table' => Spawn::getTableName('json'), 'field' => 'json', 'where' => 'srl=' . (int) $srl_json_pref])['json']; if (!$tmp) { throw new Exception('not found preference data'); } $pref = new Object(['string' => $tmp, 'json' => Util::jsonToArray($tmp, true, true)]); // get gnb $tmp = Spawn::item(['table' => Spawn::getTableName('json'), 'field' => 'json', 'where' => 'srl=' . (int) $pref->json['srl']['json_gnb']])['json']; if (!$tmp) { throw new Exception('not found global navigation data'); } $gnb = new Object(['string' => $tmp, 'json' => Util::jsonToArray($tmp, true, true)]); } catch (Exception $e) { echo $e->getMessage(); Goose::end(); } // init router $router = Module::load('router'); $router->route->setBasePath(__ROOT__); require_once 'lib/map.php'; $router->match = $router->route->match(); // route action if ($router->match) {
/** * get data item * * @param array $getParam * @return array|null */ public function getItem($getParam = array()) { if ($this->name != 'nest') { return array('state' => 'error', 'message' => '잘못된 객체로 접근했습니다.'); } // set original parameter $originalParam = array('table' => Spawn::getTableName($this->name)); // get data $data = Spawn::item(Util::extendArray($originalParam, $getParam)); // check data if (!$data) { return array('state' => 'error', 'message' => '데이터가 없습니다.'); } // convert json data if (is_array($data) && $data['json']) { $data['json'] = Util::jsonToArray($data['json'], null, true); } // return data return array('state' => 'success', 'data' => $data); }
/** * Up like * * @param array $options : [ * article_srl * header_key * ] * @return array */ public function upLike($options) { if (!$this->checkAuthHeader($options['header_key'])) { return ['state' => 'error', 'message' => 'Path not allowed']; } if (!$options['article_srl']) { return ['state' => 'error', 'message' => 'not found article_srl']; } $article = Spawn::item(['table' => Spawn::getTableName('article'), 'where' => 'srl=' . $options['article_srl'], 'field' => 'srl,json']); if (!isset($article['json'])) { return ['state' => 'error', 'message' => 'not found article data']; } $article['json'] = Util::jsonToArray($article['json'], null, true); $like = isset($article['json']['like']) ? (int) $article['json']['like'] : 0; $article['json']['like'] = $like + 1; $json = Util::arrayToJson($article['json'], true); $result = Spawn::update(['table' => Spawn::getTableName('article'), 'data' => ['json=\'' . $json . '\''], 'where' => 'srl=' . (int) $options['article_srl']]); return $result == 'success' ? ['state' => 'success', 'message' => 'update complete'] : ['state' => 'error', 'message' => 'fail update complete']; }
/** * 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; } }