Source for file response.php

Documentation is available at response.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  Response
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. JLog::add('JResponse is deprecated.'JLog::WARNING'deprecated');
  13.  
  14. /**
  15.  * JResponse Class.
  16.  *
  17.  * This class serves to provide the Joomla Platform with a common interface to access
  18.  * response variables.  This includes header and body.
  19.  *
  20.  * @package     Joomla.Legacy
  21.  * @subpackage  Response
  22.  * @since       11.1
  23.  * @deprecated  4.0  Use JApplicationWeb instead
  24.  */
  25. class JResponse
  26. {
  27.     /**
  28.      * @var    array  Body
  29.      * @since  11.1
  30.      * @deprecated  4.0
  31.      */
  32.     protected static $body array();
  33.  
  34.     /**
  35.      * @var    boolean  Cachable
  36.      * @since  11.1
  37.      * @deprecated  4.0
  38.      */
  39.     protected static $cachable false;
  40.  
  41.     /**
  42.      * @var    array  Headers
  43.      * @since  11.1
  44.      * @deprecated  4.0
  45.      */
  46.     protected static $headers array();
  47.  
  48.     /**
  49.      * Set/get cachable state for the response.
  50.      *
  51.      * If $allow is set, sets the cachable state of the response.  Always returns current state.
  52.      *
  53.      * @param   boolean  $allow  True to allow browser caching.
  54.      *
  55.      * @return  boolean  True if browser caching should be allowed
  56.      *
  57.      * @since   11.1
  58.      * @deprecated  4.0  Use JApplicationWeb::allowCache() instead
  59.      */
  60.     public static function allowCache($allow null)
  61.     {
  62.         return JFactory::getApplication()->allowCache($allow);
  63.     }
  64.  
  65.     /**
  66.      * Set a header.
  67.      *
  68.      * If $replace is true, replaces any headers already defined with that $name.
  69.      *
  70.      * @param   string   $name     The name of the header to set.
  71.      * @param   string   $value    The value of the header to set.
  72.      * @param   boolean  $replace  True to replace any existing headers by name.
  73.      *
  74.      * @return  void 
  75.      *
  76.      * @since   11.1
  77.      * @deprecated  4.0  Use JApplicationWeb::setHeader() instead
  78.      */
  79.     public static function setHeader($name$value$replace false)
  80.     {
  81.         JFactory::getApplication()->setHeader($name$value$replace);
  82.     }
  83.  
  84.     /**
  85.      * Return array of headers.
  86.      *
  87.      * @return  array 
  88.      *
  89.      * @since   11.1
  90.      * @deprecated  4.0  Use JApplicationWeb::getHeaders() instead
  91.      */
  92.     public static function getHeaders()
  93.     {
  94.         return JFactory::getApplication()->getHeaders();
  95.     }
  96.  
  97.     /**
  98.      * Clear headers.
  99.      *
  100.      * @return  void 
  101.      *
  102.      * @since   11.1
  103.      * @deprecated  4.0  Use JApplicationWeb::clearHeaders() instead
  104.      */
  105.     public static function clearHeaders()
  106.     {
  107.         JFactory::getApplication()->clearHeaders();
  108.     }
  109.  
  110.     /**
  111.      * Send all headers.
  112.      *
  113.      * @return  void 
  114.      *
  115.      * @since   11.1
  116.      * @deprecated  4.0  Use JApplicationWeb::sendHeaders() instead
  117.      */
  118.     public static function sendHeaders()
  119.     {
  120.         JFactory::getApplication()->sendHeaders();
  121.     }
  122.  
  123.     /**
  124.      * Set body content.
  125.      *
  126.      * If body content already defined, this will replace it.
  127.      *
  128.      * @param   string  $content  The content to set to the response body.
  129.      *
  130.      * @return  void 
  131.      *
  132.      * @since   11.1
  133.      * @deprecated  4.0  Use JApplicationWeb::setBody() instead
  134.      */
  135.     public static function setBody($content)
  136.     {
  137.         JFactory::getApplication()->setBody($content);
  138.     }
  139.  
  140.     /**
  141.      * Prepend content to the body content
  142.      *
  143.      * @param   string  $content  The content to prepend to the response body.
  144.      *
  145.      * @return  void 
  146.      *
  147.      * @since   11.1
  148.      * @deprecated  4.0  Use JApplicationWeb::prependBody() instead
  149.      */
  150.     public static function prependBody($content)
  151.     {
  152.         JFactory::getApplication()->prependBody($content);
  153.     }
  154.  
  155.     /**
  156.      * Append content to the body content
  157.      *
  158.      * @param   string  $content  The content to append to the response body.
  159.      *
  160.      * @return  void 
  161.      *
  162.      * @since   11.1
  163.      * @deprecated  4.0  Use JApplicationWeb::appendBody() instead
  164.      */
  165.     public static function appendBody($content)
  166.     {
  167.         JFactory::getApplication()->appendBody($content);
  168.     }
  169.  
  170.     /**
  171.      * Return the body content
  172.      *
  173.      * @param   boolean  $toArray  Whether or not to return the body content as an array of strings or as a single string; defaults to false.
  174.      *
  175.      * @return  string  array
  176.      *
  177.      * @since   11.1
  178.      * @deprecated  4.0  Use JApplicationWeb::getBody() instead
  179.      */
  180.     public static function getBody($toArray false)
  181.     {
  182.         return JFactory::getApplication()->getBody($toArray);
  183.     }
  184.  
  185.     /**
  186.      * Sends all headers prior to returning the string
  187.      *
  188.      * @param   boolean  $compress  If true, compress the data
  189.      *
  190.      * @return  string 
  191.      *
  192.      * @since   11.1
  193.      * @deprecated  4.0  Use JApplicationCms::toString() instead
  194.      */
  195.     public static function toString($compress false)
  196.     {
  197.         return JFactory::getApplication()->toString($compress);
  198.     }
  199.  
  200.     /**
  201.      * Compress the data
  202.      *
  203.      * Checks the accept encoding of the browser and compresses the data before
  204.      * sending it to the client.
  205.      *
  206.      * @param   string  $data  Content to compress for output.
  207.      *
  208.      * @return  string  compressed data
  209.      *
  210.      * @note    Replaces _compress method in 11.1
  211.      * @since   11.1
  212.      * @deprecated  4.0  Use JApplicationWeb::compress() instead
  213.      */
  214.     protected static function compress($data)
  215.     {
  216.         $encoding self::clientEncoding();
  217.  
  218.         if (!$encoding)
  219.         {
  220.             return $data;
  221.         }
  222.  
  223.         if (!extension_loaded('zlib'|| ini_get('zlib.output_compression'))
  224.         {
  225.             return $data;
  226.         }
  227.  
  228.         if (headers_sent())
  229.         {
  230.             return $data;
  231.         }
  232.  
  233.         if (connection_status(!== 0)
  234.         {
  235.             return $data;
  236.         }
  237.  
  238.         // Ideal level
  239.         $level 4;
  240.  
  241.         /*
  242.         $size        = strlen($data);
  243.         $crc        = crc32($data);
  244.  
  245.         $gzdata        = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
  246.         $gzdata        .= gzcompress($data, $level);
  247.  
  248.         $gzdata    = substr($gzdata, 0, strlen($gzdata) - 4);
  249.         $gzdata    .= pack("V",$crc) . pack("V", $size);
  250.         */
  251.  
  252.         $gzdata gzencode($data$level);
  253.  
  254.         self::setHeader('Content-Encoding'$encoding);
  255.  
  256.         // Header will be removed at 4.0
  257.         if (JFactory::getConfig()->get('MetaVersion'0&& defined('JVERSION'))
  258.         {
  259.             self::setHeader('X-Content-Encoded-By''Joomla! ' JVERSION);
  260.         }
  261.  
  262.         return $gzdata;
  263.     }
  264.  
  265.     /**
  266.      * Check, whether client supports compressed data
  267.      *
  268.      * @return  boolean 
  269.      *
  270.      * @since   11.1
  271.      * @note    Replaces _clientEncoding method from 11.1
  272.      * @deprecated  4.0  Use JApplicationWebClient instead
  273.      */
  274.     protected static function clientEncoding()
  275.     {
  276.         if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
  277.         {
  278.             return false;
  279.         }
  280.  
  281.         $encoding false;
  282.  
  283.         if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING']'gzip'))
  284.         {
  285.             $encoding 'gzip';
  286.         }
  287.  
  288.         if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING']'x-gzip'))
  289.         {
  290.             $encoding 'x-gzip';
  291.         }
  292.  
  293.         return $encoding;
  294.     }
  295. }

Documentation generated on Tue, 19 Nov 2013 15:11:53 +0100 by phpDocumentor 1.4.3