예제 #1
0
 public function printStackTrace()
 {
     $exception = is_null($this->wrappedException) ? $this : $this->wrappedException;
     $message = $exception->getMessage();
     $response = coreContext::getInstance()->getResponse();
     $response->setStatusCode(500);
     // clean current output buffer
     while (@ob_end_clean()) {
     }
     ob_start(coreConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
     header('HTTP/1.1 500 Internal Server Error');
     header('Content-Type: text/plain');
     if ($message !== '') {
         header('RTK-Error: ' . $message);
     }
     // during development, send back ajax request for debugging
     if (coreConfig::get('sf_debug')) {
         try {
             $request = coreContext::getInstance()->getRequest();
             $sJson = $request->getParameter('json');
             $oJson = null;
             if ($sJson !== null) {
                 $oJson = coreJson::decode($sJson);
             }
             echo 'Json data = ' . "\n" . ($oJson !== null ? print_r($oJson, true) : $sJson);
         } catch (Exception $e) {
             echo 'rtkAjaxException - no Json found, $_POST = ' . "\n" . print_r($_POST, true);
         }
     }
     exit(1);
 }
예제 #2
0
 /**
  * 
  * 
  * @return object $this (allows chaining calls)
  */
 private function bind(uiSelectTableBinding $bindObj)
 {
     // check
     if (!$bindObj instanceof uiSelectTableBinding) {
         throw new coreException('Binding parameter not of required class');
     }
     // get configuration as object, or convert from JSON if string
     $config = $bindObj->getConfig();
     if (is_string($config)) {
         // read config as a json string
         $config = coreJson::decode($config);
     }
     //DBG::printr($config);exit;
     // overwrite default settings with config values
     if (isset($config->settings)) {
         $this->configureSettings($config->settings);
     } else {
         throw new coreException(__CLASS__ . '::bind() Config "settings" missing');
     }
     // setup some default values for columns
     $this->columns =& $config->columns;
     foreach ($this->columns as $colDef) {
         assert('isset($colDef->colData) || isset($colDef->colDisplay)');
         // columns are not editable by default
         if (!isset($colDef->editable)) {
             $colDef->editable = false;
         }
         // sort on raw or display data if sort column is not explicitly set
         if (!isset($colDef->colSort)) {
             $colDef->colSort = isset($colDef->colData) ? $colDef->colData : null;
         }
     }
     //DBG::printr($this->settings);exit;
 }
예제 #3
0
파일: actions.php 프로젝트: nikitakit/RevTK
 protected function reviewAction($request)
 {
     $db = $this->getContext()->getDatabase();
     $options = array('fn_get_flashcard' => array('rtkLabs', 'getFlashcardData'));
     if ($request->getMethod() !== coreRequest::POST) {
         $options['items'] = rtkLabs::iVocabShuffleBegin();
         $this->uiFR = new uiFlashcardReview($options);
     } else {
         // handle Ajax requests
         $oJson = coreJson::decode($request->getParameter('json', '{}'));
         if (!empty($oJson)) {
             $flashcardReview = new uiFlashcardReview($options);
             return $this->renderText($flashcardReview->handleJsonRequest($oJson));
         }
         throw new rtkAjaxException('Empty JSON Request.');
     }
 }
예제 #4
0
파일: actions.php 프로젝트: nikitakit/RevTK
 public function executeJsontest()
 {
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json');
     $o = array('foo' => 'bar');
     return $this->renderText(coreJson::encode($o));
 }
예제 #5
0
 /**
  * Handles JSON request and returns a JSON response
  * 
  * @param object  JSON request as a native php object (stdClass)
  * 
  * @return        JSON response as a string
  */
 public function handleJsonRequest($oJson)
 {
     $oResponse = new stdClass();
     // get flashcard data
     if (isset($oJson->get) && is_array($oJson->get)) {
         $get_cards = array();
         // do not accept too large prefetch (tampering with ajax request on client)
         if (count($oJson->get) > self::MAX_PREFETCH) {
             $oJson->get = array_slice($oJson->get, 0, self::MAX_PREFETCH);
         }
         foreach ($oJson->get as $id) {
             $cardData = call_user_func($this->options->fn_get_flashcard, $id);
             if ($cardData === null) {
                 throw new rtkAjaxException('Could not fetch item "' . $id . '" in JSON request');
             }
             $get_cards[] = $cardData;
         }
         if (count($get_cards)) {
             $oResponse->get = $get_cards;
         }
     }
     // update flashcard reviews
     if (isset($oJson->put) && is_array($oJson->put)) {
         $putSuccess = 0;
         if (isset($this->options->fn_put_flashcard)) {
             foreach ($oJson->put as $oAnswer) {
                 if (!call_user_func($this->options->fn_put_flashcard, $oAnswer->id, $oAnswer)) {
                     // must stop at first error, cf. client side code (js) clearing of cached answers
                     break;
                 }
                 $putSuccess++;
             }
         }
         $oResponse->put = $putSuccess;
     }
     return coreJson::encode($oResponse);
 }
예제 #6
0
파일: actions.php 프로젝트: kc5nra/RevTK
 /**
  * Ajax handler for Shared Stories component.
  * 
  * uid & sid identify the story to vote/report/copy.
  * 
  * Post:
  * 
  *   request     "star": star story
  *               "report": report story
  *               "copy": copy story
  *   uid         User id of the Story's author
  *   sid         Story id (framenum)
  * 
  * @return 
  */
 public function executeAjax($request)
 {
     if ($request->getMethod() === coreRequest::GET) {
         // reload component
         $framenum = $request->getParameter('framenum', false);
         if (!BaseValidators::validateInteger($framenum)) {
             throw new rtkAjaxException('Bad request.');
         }
         $kanjiData = (object) KanjisPeer::getKanjiById($framenum);
         return $this->renderComponent('study', 'SharedStories', array('framenum' => $framenum, 'kanjiData' => $kanjiData));
     } else {
         $sRequest = $request->getParameter('request', '');
         $sUid = $request->getParameter('uid');
         $sSid = $request->getParameter('sid');
         if (!preg_match('/^(star|report|copy)$/', $sRequest) || !BaseValidators::validateInteger($sUid) || !BaseValidators::validateInteger($sSid)) {
             throw new rtkAjaxException('Badrequest');
         }
         if ($sRequest === 'copy') {
             // get unformatted story with original tags for copy story feature
             $oStory = StoriesPeer::getStory($sUid, $sSid);
             if ($oStory) {
                 $oJSON = new stdClass();
                 $oJSON->text = $oStory->text;
                 return $this->renderText(coreJson::encode($oJSON));
             }
         } elseif ($sRequest === 'star') {
             $oJSON = StoryVotesPeer::starStory($this->getUser()->getUserId(), $sUid, $sSid);
             return $this->renderText(coreJson::encode($oJSON));
         } elseif ($sRequest === 'report') {
             $oJSON = StoryVotesPeer::reportStory($this->getUser()->getUserId(), $sUid, $sSid);
             return $this->renderText(coreJson::encode($oJSON));
         }
     }
     throw new rtkAjaxException('Badrequest');
 }
예제 #7
0
		<div class="clear"></div>
	</div>

	<div class="filters">
		<?php 
$links = array(array('Simple', '#', array('class' => 'uiFilterStd-s')), array('Full', '#', array('class' => 'uiFilterStd-f')));
echo ui_filter_std('View:', $links, array('class' => 'mode-toggle', 'active' => 0));
?>
	</div>

	<div class="clear"></div>

<div class="svg-outer-div">
	<div class="svg-inner-div"></div>
	<div class="mode-toggle mode-simple">
		<a href="#" class="mode-simple">Simple</a>
	</div>
</div>

<?php 
use_helper('Form');
echo input_hidden_tag('json', coreJson::encode($chart_data), array('class' => 'json'));
?>

<script>
var chartdata = <?php 
echo coreJson::encode($chart_data);
?>
;
</script>
예제 #8
0
파일: actions.php 프로젝트: kc5nra/RevTK
 /**
  * Kanji Flashcard review page with uiFlashcardReview
  * 
  * GET request = review page
  * 
  * 	 type = 'expired'|'untested'|'relearned'|'fresh'
  *   box  = 'all'|[1-5]
  *   filt = ''|'rtk1'|'rtk3'
  *   
  * POST request = ajax request during review
  * 
  * @param object $request
  */
 protected function reviewAction($request)
 {
     $reviewBox = $request->getParameter('box', 'all');
     $reviewType = $request->getParameter('type', 'expired');
     $reviewFilt = $request->getParameter('filt', '');
     $reviewMerge = $request->getParameter('merge') ? true : false;
     // validate
     $this->forward404Unless(preg_match('/^(all|[1-9]+)$/', $reviewBox));
     $this->forward404Unless(preg_match('/^(expired|untested|relearned|fresh)$/', $reviewType));
     $this->forward404Unless($reviewFilt == '' || preg_match('/(rtk1|rtk3)/', $reviewFilt));
     // pick title
     $this->setReviewTitle($reviewType, $reviewFilt);
     //
     $sAjaxUrl = $this->getController()->genUrl('@review');
     $options = array('partial_name' => 'review/ReviewKanji', 'ajax_url' => $sAjaxUrl, 'ts_start' => ReviewsPeer::getLocalizedTimestamp(), 'fn_get_flashcard' => array('KanjisPeer', 'getFlashcardData'), 'fn_put_flashcard' => array('ReviewsPeer', 'putFlashcardData'));
     if ($request->getMethod() !== coreRequest::POST) {
         $options['items'] = ReviewsPeer::getFlashcards($reviewBox, $reviewType, $reviewFilt, $reviewMerge);
         $this->uiFR = new uiFlashcardReview($options);
     } else {
         /*
         			if (rand(1,10) < 3)
         			{
         				sleep(6);
         			}*/
         // handle Ajax request (or throws exception)
         $oJson = coreJson::decode($request->getParameter('json', '{}'));
         if (!empty($oJson)) {
             $flashcardReview = new uiFlashcardReview($options);
             return $this->renderText($flashcardReview->handleJsonRequest($oJson));
         }
         throw new rtkAjaxException('Empty JSON Request.');
     }
     return coreView::SUCCESS;
 }