示例#1
0
 /**
  * generates and prints the response based on response type supplied by the frontend.
  *
  * @access  public
  * @return  void
  */
 function return_data()
 {
     // send appropriate headers to avoid caching
     header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Cache-Control: no-cache, must-revalidate');
     header('Pragma: no-cache');
     header('X-Powered-By: CPAINT v' . $this->version . '/PHP v' . phpversion());
     // work only if there is no API version request
     if (!isset($_REQUEST['api_query']) && !isset($_REQUEST['wsdl'])) {
         // trigger generation of response
         switch (trim($this->response_type)) {
             case 'TEXT':
                 header('Content-type: text/plain; charset=' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()));
                 echo cpaint_transformer::toString($this->basenode);
                 break;
             case 'JSON':
                 header('Content-type: text/plain; charset=' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()));
                 echo cpaint_transformer::toJSON($this->basenode);
                 break;
             case 'OBJECT':
             case 'E4X':
             case 'XML':
                 header('Content-type:  text/xml; charset=' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()));
                 echo '<?xml version="1.0" encoding="' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()) . '"?>' . cpaint_transformer::toXML($this->basenode);
                 break;
             default:
                 echo 'ERROR: invalid response type \'' . $this->response_type . '\'';
         }
         // end: switch
     } elseif (isset($_REQUEST['api_query'])) {
         // API version request
         header('Content-type: text/plain; charset=ISO-8859-1');
         echo 'CPAINT v' . $this->version . '/PHP v' . phpversion();
     } elseif ($this->use_wsdl == true && isset($_REQUEST['wsdl'])) {
         if (is_file(dirname(__FILE__) . '/cpaint2.wsdl.php') && is_readable(dirname(__FILE__) . '/cpaint2.wsdl.php')) {
             require_once dirname(__FILE__) . '/cpaint2.wsdl.php';
             if (class_exists('cpaint_wsdl')) {
                 // create new instance of WSDL library
                 $wsdl = new cpaint_wsdl();
                 // build WSDL info
                 header('Content-type: text/xml; charset=UTF-8');
                 echo $wsdl->generate($this->api_functions, $this->api_datatypes);
             } else {
                 header('Content-type: text/plain; charset=ISO-8859-1');
                 echo 'WSDL generator is unavailable';
             }
             // end: if
         } else {
             header('Content-type: text/plain; charset=ISO-8859-1');
             echo 'WSDL generator is unavailable';
         }
         // end: if
     }
     // end: if
 }
示例#2
0
 /**
  * generates and prints the response based on response type supplied by the frontend.
  *
  * @access  public
  * @return  void
  */
 function return_data()
 {
     // delete output buffer
     ob_end_clean();
     // send appropriate headers to avoid caching
     header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Cache-Control: no-cache, must-revalidate');
     header('Pragma: no-cache');
     // work only if there is no API version request
     if (!isset($_GET['api_query']) && !isset($_POST['api_query'])) {
         // trigger generation of response
         switch (trim(strtoupper($this->response_type))) {
             case 'TEXT':
                 header('Content-type: text/plain; charset=' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()));
                 echo cpaint_transformer::toString($this->basenode);
                 break;
             case 'OBJECT':
             case 'XML':
                 header('Content-type:  text/xml; charset=' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()));
                 echo '<?xml version="1.0" encoding="' . cpaint_transformer::find_output_charset($this->basenode->get_encoding()) . '"?>' . cpaint_transformer::toXML($this->basenode);
                 break;
             default:
                 echo 'ERROR: invalid response type \'' . $this->response_type . '\'';
         }
         // end: switch
     } else {
         // API version request
         header('Content-type: text/plain; charset=ISO-8859-1');
         echo 'CPAINT v' . $this->version . '/PHP v' . phpversion();
     }
     // end: if
 }