Пример #1
0
 /**
  * The main public method to embed elements. Notice that it echoes rather
  * than returns, because it's meant to be used simply by calling and spitting
  * out the needed code...
  *
  * @return none
  */
 public static function embedElement($element_id, $access_method = 'direct', $location = false, $geo = false)
 {
     // fire up the platform sans-direct-request to catch any GET/POST info sent
     // in to the page
     CASHSystem::startSession();
     $cash_page_request = new CASHRequest(null);
     $initial_page_request = $cash_page_request->sessionGet('initial_page_request', 'script');
     if ($initial_page_request && isset($initial_page_request['request']['element_id'])) {
         // now test that the initial POST/GET was targeted for this element:
         if ($initial_page_request['request']['element_id'] == $element_id) {
             $status_uid = $initial_page_request['response']['status_uid'];
             $original_request = $initial_page_request['request'];
             $original_response = $initial_page_request['response'];
         } else {
             $status_uid = false;
             $original_request = false;
             $original_response = false;
         }
     } else {
         $status_uid = false;
         $original_request = false;
         $original_response = false;
     }
     $cash_body_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getmarkup', 'id' => $element_id, 'status_uid' => $status_uid, 'original_request' => $original_request, 'original_response' => $original_response, 'access_method' => $access_method, 'location' => $location, 'geo' => $geo));
     if ($cash_body_request->response['status_uid'] == 'element_getmarkup_400') {
         // there was no element found. so you know...punt
         echo '<div class="cashmusic error">Element #' . $element_id . ' could not be found.</div>';
     }
     if (is_string($cash_body_request->response['payload'])) {
         // element found and happy. spit it out.
         echo $cash_body_request->response['payload'];
     }
     if ($cash_body_request->sessionGet('initialized_element_' . $element_id, 'script')) {
         // second half of a wrapper element — fringe case
         if (ob_get_level()) {
             ob_flush();
         }
     }
     unset($cash_page_request);
     unset($cash_body_request);
 }
Пример #2
0
 function testWhatever()
 {
     $request = new CASHRequest();
     // test script-scope sesstion values:
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz', 'script');
     $value = $request->sessionGet('foobar', 'script');
     $this->assertEqual($value, 'baz');
     $request->sessionClear('foobar', 'script');
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz', 'script');
     $request->sessionClearAll();
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     // test persistent-scope sesstion values:
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz');
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     // fail without startSession()
     $session = CASHSystem::startSession();
     $this->assertTrue($session);
     echo 'Session started: ' . json_encode($session) . "\n";
     $request->sessionSet('foobar', 'baz');
     $value = $request->sessionGet('foobar');
     $this->assertEqual($value, 'baz');
     $request->sessionClear('foobar');
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz');
     $request->sessionClearAll();
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
 }