public function test_data_call()
 {
     $this->assertSame('my-call', \V1\APIRequest::data_call('data-call'));
     $this->assertSame(false, \V1\APIRequest::data_call('fake', false));
 }
Ejemplo n.º 2
0
 /**
  * Parse the HTML data
  * 
  * @param array $template		The array of template data from the Data Call call script
  * @param array $api_responses	The array of responses we ran with the Data Call
  * @param bool $return_html		Set to true to return only HTML, not the array of parsed template data
  * 
  * @return mixed The array of parsed template data, or a string of HTML body contents if $return_html is true
  */
 protected static function process_template(array $template, array $api_responses, $return_html = false)
 {
     // Fill out our variables if we have some. (Kind of pointless not to.)
     if (!empty($template['variables'])) {
         $variables = array();
         foreach ($template['variables'] as $variable => $value_location) {
             $variables[$variable] = null;
             // Check if it resolves.
             if (($value = \Arr::get($api_responses, $value_location, 'BAH_NO_VALUE')) !== 'BAH_NO_VALUE') {
                 // Add the value to the variable so we can replace it.
                 if (is_numeric($value) || is_string($value) || is_null($value)) {
                     $variables[$variable] = (string) $value;
                 }
                 // Boolean doesn't like to get cast to a string properly.
                 if (is_bool($value)) {
                     $variables[$variable] = $value === false ? 'false' : 'true';
                 }
             }
         }
         // We don't return these.
         unset($template['variables']);
         // Replace the variables in the template.
         if (!empty($variables)) {
             $template = str_replace(array_keys($variables), array_values($variables), $template);
         }
     }
     $account_data = \V1\Model\Account::get_account();
     /**
      * Add our link back on free accounts, or account who wish to show a link back. While free accounts
      * could just decide not to show the body, they cannot configure their own Data Calls to place body
      * content in "css" or "js". Anyone can just preg_replace() away the linkback, but in general,
      * free accounts will show our link back.
      */
     if (!empty($template['body']) && ($account_data['access_level'] === 1 || $account_data['link_back'] === 1)) {
         $template['body'] .= \View::forge('linkback', array('color' => \V1\APIRequest::data_call('linkback-color', 'dark')), false)->render();
     }
     // We'll parse the template for them.
     if ($return_html === true) {
         $html = null;
         // CSS should be in <style> tags.
         $html .= !empty($template['css']) ? $template['css'] . '<body>' : null;
         // HTML body
         $html .= !empty($template['body']) ? $template['body'] : null;
         // JS comes at the end to keep things speedy.
         $html .= !empty($template['js']) ? $template['js'] : null;
         return $html;
     }
     // Send the template data sectioned out for use.
     return $template;
 }