Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.13 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_DEPRECIATED)
  4.  
  5. /**
  6.  * SPAW Editor v.2 Utility classes
  7.  *
  8.  * @package spaw2
  9.  * @subpackage Util  
  10.  * @author Alan Mendelevich <alan@solmetra.lt>
  11.  * @copyright UAB Solmetra
  12.  */
  13.  
  14. /**
  15.  * Variable access class
  16.  *
  17.  * Returns values of variable from global arrays independent of PHP version and settings
  18.  * @package spaw2
  19.  * @subpackage Util
  20.  */
  21. class SpawVars
  22. {
  23.   /**
  24.    * Returns GET variable value
  25.    * @param string $var_name variable name
  26.    * @param string $empty_value value to return if variable is empty
  27.    * @returns string
  28.    * @static  
  29.    */              
  30.   function getGetVar($var_name, $empty_value='')
  31.   {
  32.     global $HTTP_GET_VARS;
  33.     if (!empty($_GET[$var_name]))
  34.       return $_GET[$var_name];
  35.     elseif (!empty($HTTP_GET_VARS[$var_name]))
  36.       return $HTTP_GET_VARS[$var_name];
  37.     else
  38.       return $empty_value;
  39.   }
  40.  
  41.   /**
  42.    * Returns POST variable value
  43.    * @param string $var_name variable name
  44.    * @param string $empty_value value to return if variable is empty
  45.    * @returns string
  46.    * @static
  47.    */      
  48.   function getPostVar($var_name, $empty_value='')
  49.   {
  50.     global $HTTP_POST_VARS;
  51.     if (!empty($_POST[$var_name]))
  52.       return $_POST[$var_name];
  53.     else if (!empty($HTTP_POST_VARS[$var_name]))
  54.       return $HTTP_POST_VARS[$var_name];
  55.     else
  56.       return $empty_value;
  57.   }
  58.  
  59.   /**
  60.    * Returns FILES variable value
  61.    * @param string $var_name variable name
  62.    * @param string $empty_value value to return if variable is empty
  63.    * @returns mixed
  64.    * @static
  65.    */      
  66.   function getFilesVar($var_name, $empty_value='')
  67.   {
  68.     global $HTTP_POST_FILES;
  69.     if (!empty($_FILES[$var_name]))
  70.       return $_FILES[$var_name];
  71.     else if (!empty($HTTP_POST_FILES[$var_name]))
  72.       return $HTTP_POST_FILES[$var_name];
  73.     else
  74.       return $empty_value;
  75.   }
  76.  
  77.   /**
  78.    * Returns SERVER variable value
  79.    * @param string $var_name variable name
  80.    * @param string $empty_value value to return if variable is empty
  81.    * @returns string
  82.    * @static
  83.    */      
  84.   function getServerVar($var_name, $empty_value='')
  85.   {
  86.     global $HTTP_SERVER_VARS;
  87.     if (!empty($_SERVER[$var_name]))
  88.       return $_SERVER[$var_name];
  89.     else if (!empty($HTTP_SERVER_VARS[$var_name]))
  90.       return $HTTP_SERVER_VARS[$var_name];
  91.     else
  92.       return $empty_value;
  93.   }
  94.  
  95.   /**
  96.    * Returns SESSION variable value
  97.    * @param string $var_name variable name
  98.    * @param string $empty_value value to return if variable is empty
  99.    * @returns string
  100.    * @static
  101.    */      
  102.   function getSessionVar($var_name, $empty_value='')
  103.   {
  104.     global $HTTP_SESSION_VARS;
  105.     if (!empty($_SESSION[$var_name]))
  106.       return $_SESSION[$var_name];
  107.     else if (!empty($HTTP_SESSION_VARS[$var_name]))
  108.       return $HTTP_SESSION_VARS[$var_name];
  109.     else
  110.       return $empty_value;
  111.   }
  112.  
  113.   /**
  114.    * Sets SESSION variable value
  115.    * @param string $var_name variable name
  116.    * @param string $value value to set
  117.    * @static
  118.    */      
  119.   function setSessionVar($var_name, $value='')
  120.   {
  121.     global $HTTP_SESSION_VARS;
  122.     if (isset($_SESSION))
  123.       $_SESSION[$var_name] = $value;
  124.     else if (isset($HTTP_SESSION_VARS))
  125.       $HTTP_SESSION_VARS[$var_name] = $value;
  126.   }
  127.  
  128.   /**
  129.    * Strips slashes from variable if magic_quotes is on
  130.    * @param string $var variable
  131.    * @returns string
  132.    * @static  
  133.    */              
  134.   function stripSlashes($var)
  135.   {
  136.     if (get_magic_quotes_gpc()) {
  137.       return stripslashes($var);
  138.     }
  139.     return $var;
  140.   }
  141.  
  142. }    
  143.  
  144. /**
  145.  * Usupported browser
  146.  */
  147. define("SPAW_AGENT_UNSUPPORTED", 0);
  148. /**
  149.  * Microsoft Internet Explorer for Windows version 5.5 or higher
  150.  */
  151. define("SPAW_AGENT_IE", 15);
  152. /**
  153.  * Gecko based browser with engine built on 2003-03-12 or later
  154.  */
  155. define("SPAW_AGENT_GECKO", 240);
  156. /**
  157.  * Opera 9 or higher
  158.  */
  159. define("SPAW_AGENT_OPERA", 3840);
  160. /**
  161.  * Safari 3 or higher
  162.  */
  163. define("SPAW_AGENT_SAFARI", 61440);
  164. /**
  165.  * All supported browsers
  166.  */
  167. define("SPAW_AGENT_ALL", 65535);
  168.  
  169. /**
  170.  * Provides itformation about current user agent (browser)
  171.  * @package spaw2
  172.  * @subpackage Util
  173.  */  
  174. class SpawAgent
  175. {
  176.   /**
  177.    * Returns constant representing user agent (browser) in SPAW terms
  178.    * @returns integer
  179.    * @static
  180.    * @see SPAW_AGENT_UNSUPPORTED, SPAW_AGENT_IE, SPAW_AGENT_GECKO          
  181.    */    
  182.   function getAgent()
  183.   {
  184.     $result = SPAW_AGENT_UNSUPPORTED;
  185.     $browser = SpawVars::GetServerVar('HTTP_USER_AGENT');
  186.     //echo $browser;
  187.     // check if msie
  188.     if (eregi("MSIE[^;]*",$browser,$msie))
  189.     {
  190.       // get version
  191.       if (eregi("[0-9]+\.[0-9]+",$msie[0],$version))
  192.       {
  193.         // check version
  194.         if ((float)$version[0]>=5.5)
  195.         {
  196.           // finally check if it's not opera impersonating ie
  197.           if (!eregi("opera",$browser))
  198.           {
  199.             $result = SPAW_AGENT_IE;
  200.           }
  201.         }
  202.       }
  203.     }
  204.     elseif (ereg("Gecko/([0-9]*)",$browser,$build))
  205.     {
  206.       // build date of Mozilla version 1.3 is 20030312
  207.       if ($build[1] > "20030312")
  208.         $result = SPAW_AGENT_GECKO;
  209.     }
  210.     elseif (eregi("Opera/([0-9]*)", $browser, $opera))
  211.     {
  212.       if ((float)$opera[1] >= 9)
  213.         $result = SPAW_AGENT_OPERA;
  214.     }
  215.     elseif (eregi("Safari/([0-9]*)", $browser, $safari))
  216.     {
  217.       // safari build 500 or higher (safari 3 or newer)
  218.       if ((float)$safari[1] >= 500)
  219.         $result = SPAW_AGENT_SAFARI;
  220.     }
  221.     return $result;
  222.   }
  223.  
  224.   /**
  225.    * Returns string representation of current user agent to be used as part of file extension or dir name
  226.    * @returns string  
  227.    * @static
  228.    */        
  229.   function getAgentName()
  230.   {
  231.     $result = '';
  232.     switch(SpawAgent::getAgent())
  233.     {
  234.       case SPAW_AGENT_IE:
  235.         $result = 'ie';
  236.         break;
  237.       case SPAW_AGENT_GECKO:
  238.         $result = 'gecko';
  239.         break;
  240.       case SPAW_AGENT_OPERA:
  241.         $result = 'opera';
  242.         break;
  243.       case SPAW_AGENT_SAFARI:
  244.         $result = 'safari';
  245.         break;
  246.       default:
  247.         $result = '';
  248.         break;
  249.     }
  250.     return $result;
  251.   }
  252. }
  253.  
  254. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement