Advertisement
Guest User

Untitled

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