public function syncAction()
 {
     set_time_limit(0);
     $closure = function ($feedInfo) {
         if (!$feedInfo["fresh"]) {
             // feed start updating event
             $this->startUpdateEventCatcher($feedInfo);
         } else {
             // feed updated event
             $this->endUpdateEventCatcher($feedInfo);
         }
     };
     $result = json_encode($this->grosona->sync($closure));
     $ip = Utility::getIp();
     $time = date(DATE_ATOM);
     $msg = "[{$time}] sync() called. Request:ip='{$ip}', result='{$result}'\n";
     file_put_contents(__DIR__ . "/../../../storage/sync/xdb_" . date("Ymd") . ".txt", $msg, FILE_APPEND | LOCK_EX);
     chmod(__DIR__ . "/../../../storage/sync/xdb_" . date("Ymd") . ".txt", 0660);
     return new Response();
 }
 private static function showPacking($results, $displayMode, $dropMenu, $page, $footer)
 {
     $request = Request::createFromGlobals();
     $queryStr = $request->getQueryString();
     $dm = array();
     $selD = $request->get('d', 't');
     foreach ($displayMode as $name => $text) {
         $newParamStr = Utility::setParam('d', $name, Utility::setParam('p', 1, $queryStr));
         $dm[] = array('sel' => $selD == $name, 'url' => 'show?' . $newParamStr, 'value' => $text);
     }
     $selP = $request->get('p') ? $request->get('p') : 1;
     $navStartP = $selP < 5 ? 0 : $selP - 3;
     $navEndP = $navStartP + 10 >= $page ? $page : $navStartP + 10;
     $nav = array('prev' => 'show?' . Utility::setParam('p', $selP - 1, $queryStr), 'next' => 'show?' . Utility::setParam('p', $selP + 1, $queryStr), 'pages' => array(), 'startP' => $navStartP, 'now' => $selP);
     for ($i = $navStartP; $i < $navEndP; $i++) {
         $nav['pages'][] = 'show?' . Utility::setParam('p', $i + 1, $queryStr);
     }
     $resultNum = $results['count'];
     $topBar = array(array('text' => 'NCKU入口', 'url' => 'http://i.ncku.edu.tw/', 'sel' => false), array('text' => 'XDBrowser', 'url' => '../app.php/', 'sel' => true), array('text' => 'XDPrayer', 'url' => '../app.php/pray', 'sel' => false), array('text' => '使用說明', 'url' => '../app.php/help', 'sel' => false));
     return array('topbar' => $topBar, 'show' => true, 'results' => $results['items'], 'resultInfo' => "約有 {$resultNum} 項結果", 'dmodes' => $dm, 'menuItems' => $dropMenu, 'query' => $request->get('q'), 'nav' => $nav, 'footer' => $footer);
 }