Пример #1
0
 public function executeJsontest()
 {
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json');
     $o = array('foo' => 'bar');
     return $this->renderText(coreJson::encode($o));
 }
Пример #2
0
 /**
  * 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');
 }
Пример #3
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);
 }
Пример #4
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>