public function init()
 {
     $this->view->start_time = microtime(true);
     $db_static = Zend_Registry::get('db_static');
     $this->view->metadata = Zend_Registry::get('metadata');
     $this->view->config = Zend_Registry::get('config');
     $this->view->self_root = Zend_Registry::get('self_root');
     $this->view->self = $this->view->self_root . $this->view->page;
     $this->view->request_uri = getenv('REQUEST_URI');
     $this->view->client = Zend_Registry::get('client');
     $this->view->controller_name = Zend_Registry::get('controller_name');
     $this->view->action = $this->getRequest()->getActionName();
     $this->view->request_id = 0;
     $this->view->uid = 0;
     $request_data = $this->getRequestData();
     // [ADD] by Puttipong Nakapat to allow bypass signature system for DEBUG purpose.
     //if($request_data["status"] != 200) {
     //	$this->sendResponse($request_data);
     //}
     // Specify name of controller that does not require login to connect.
     if (!in_array($this->view->controller_name, array('account', 'info', 'stat'))) {
         if (!isset($request_data["data"]["token"])) {
             $data = array("data" => null, "status" => 305, "status_msg" => "[BaseController] Input Wrong Format");
             $this->sendResponse($data);
         } else {
             try {
                 $uid = GameManager::getUidByToken($request_data["data"]["token"]);
                 if ($uid == 0) {
                     $data = array("data" => null, "status" => 302, "status_msg" => "[BaseController] Session Not Found");
                     $this->sendResponse($data);
                 }
                 $users = new Users();
                 $me = $users->init($uid);
                 $authorize = $me->_data["authorize"];
                 if ($me->_data['status'] == "banned") {
                     $data = array("data" => null, "status" => 601, "status_msg" => "[BaseController] Account was banned");
                     $this->sendResponse($data);
                 }
                 if (!$db_static->fetchRow("select * from db_controller where name=? and {$authorize}='yes'", $this->view->controller_name)) {
                     $data = array("data" => null, "status" => 404, "status_msg" => "[BaseController] API Not Found");
                     $this->sendResponse($data);
                 }
                 $this->view->uid = $me->_data["uid"];
                 //$this->rewriteCreatureMax($me);
                 Zend_Registry::set('me', $me);
             } catch (Exception $e) {
                 $data = array("data" => null, "status" => 500, "status_msg" => "[BaseController] Internal Server Error:" . $e);
                 $this->sendResponse($data);
             }
         }
     }
     //checking
     $this->view->request_data = $request_data;
 }
 private function extractInfo($inResult, $inCommand, $inToken)
 {
     $db_share = Zend_Registry::get('db_share');
     $info = array();
     if ($inCommand == 'news') {
         foreach ($inResult as $row) {
             array_push($info, array('news_id' => $row['news_id'], 'author_id' => 0, 'author_name' => '', 'date' => $row['date'], 'title' => $this->view->dict[$row['codename'] . '.TITLE'], 'brief' => $this->view->dict[$row['codename'] . '.BRIEF'], 'detail' => $this->view->dict[$row['codename'] . '.DETAIL']));
         }
     } elseif ($inCommand == 'articles') {
         foreach ($inResult as $row) {
             array_push($info, array('articles_id' => $row['articles_id'], 'author_id' => 0, 'author_name' => '', 'date' => $row['date'], 'title' => $this->view->dict[$row['codename'] . '.TITLE'], 'brief' => $this->view->dict[$row['codename'] . '.BRIEF'], 'detail' => $this->view->dict[$row['codename'] . '.DETAIL']));
         }
     } elseif ($inCommand == 'campaign') {
         $uid = GameManager::getUidByToken($inToken);
         foreach ($inResult as $row) {
             $recent_signatures = array();
             if ($result_signatures = $db_share->fetchAll('SELECT * FROM signatures WHERE enable=? AND campaign_id=? ORDER BY date DESC, time DESC LIMIT 30', array('yes', $row['campaign_id']))) {
                 foreach ($result_signatures as $c) {
                     array_push($recent_signatures, array('campaign_id' => $c['campaign_id'], 'uid' => $c['uid'], 'username' => $c['username'], 'first_name' => $c['first_name'], 'last_name' => $c['last_name'], 'date' => $c['date'], 'time' => $c['time']));
                 }
             }
             $comments = array();
             if ($result_comment = $db_share->fetchAll('SELECT * FROM comments WHERE enable=? AND campaign_id=? ORDER BY date DESC, time DESC LIMIT 30', array('yes', $row['campaign_id']))) {
                 foreach ($result_comment as $c) {
                     array_push($comments, array('campaign_id' => $c['campaign_id'], 'uid' => $c['uid'], 'username' => $c['username'], 'display_name' => $c['display_name'], 'display_comment' => $c['display_comment'], 'date' => $c['date'], 'time' => $c['time']));
                 }
             }
             $timeline = array();
             if ($result_timeline = $db_share->fetchAll('SELECT * FROM timeline WHERE enable=? AND campaign_id=? ORDER BY date DESC, time DESC, id DESC LIMIT 30', array('yes', $row['campaign_id']))) {
                 foreach ($result_timeline as $c) {
                     array_push($timeline, array('campaign_id' => $c['campaign_id'], 'uid' => $c['uid'], 'username' => $c['username'], 'display_name' => $c['display_name'], 'display_content' => $this->view->dict[$c['display_content'] . '.DETAIL'], 'date' => $c['date'], 'time' => $c['time'], 'icon' => $c['icon'], 'icon_color' => $c['icon_color'], 'image' => $c['image'], 'image_url' => $c['image_url']));
                 }
             }
             $letters = array();
             $disparage_name = explode('|', $row['disparage_name']);
             $disparage_letter = explode('|', $row['disparage_letter']);
             foreach ($disparage_letter as $j => $l) {
                 if ($l != 'none') {
                     array_push($letters, array('name' => $disparage_name[$j], 'content' => $this->view->dict[$l]));
                 }
             }
             $already_support = false;
             if ($uid) {
                 $users = new Users();
                 $me = $users->init($uid);
                 $already_support = ($record = $me->_db_channel->fetchRow('SELECT id FROM signatures WHERE campaign_id=? AND uid=? LIMIT 1', array($row['campaign_id'], $uid))) ? true : false;
             }
             array_push($info, array('campaign_id' => $row['campaign_id'], 'author_id' => 0, 'author_name' => '', 'date' => $row['date'], 'title' => $this->view->dict[$row['codename'] . '.TITLE'], 'brief' => $this->view->dict[$row['codename'] . '.BRIEF'], 'detail' => $this->view->dict[$row['codename'] . '.DETAIL'], 'copied_head' => $this->view->dict[$row['codename'] . '.COPIED_HEAD'], 'copied_full' => $this->view->dict[$row['codename'] . '.COPIED_FULL'], 'target' => $row['target'], 'signatures' => $row['signatures'], 'recent_signatures' => $recent_signatures, 'comments' => $comments, 'letters' => $letters, 'timeline' => $timeline, 'already_support' => $already_support));
         }
     }
     return $info;
 }
 public function infoAction()
 {
     $request_data = $this->view->request_data["data"];
     $token = isset($request_data['token']) ? $request_data['token'] : "";
     try {
         $uid = GameManager::getUidByToken($token);
         $me = GameManager::getUserObject($uid);
         $response = array("data" => $me->_data, "status" => ReturnStatus::SUCCESS, "status_msg" => "Success");
         parent::sendResponse($response);
     } catch (Exception $e) {
         $data = array("data" => null, "status" => ReturnStatus::INTERNAL_SERVER_ERROR, "status_msg" => "Internal Server Error:" . $e);
         parent::sendResponse($data);
     }
 }