ManiaLib 1.0b1 API Reference

Source for file UserAgentCheckFilter.class.php

Documentation is available at UserAgentCheckFilter.class.php

  1. <?php
  2. /**
  3.  * @author Maxime Raoust
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  * @subpackage MVC_DefaultFilters
  7.  */
  8.  
  9. /**
  10.  * User agent checker
  11.  * Forces GameBox user agent, redirects to trackmania.com otherwise
  12.  * @package ManiaLib
  13.  * @subpackage MVC_DefaultFilters
  14.  */
  15. {
  16.     /**
  17.      * @ignore
  18.      */
  19.     protected static $callback array('UserAgentCheckFilter''defaultHTMLView');
  20.     
  21.     /**
  22.      * Sets the callback when someone tries to access the Manialink from outside the game.
  23.      * The callback prints some HTML and returns void.
  24.      */
  25.     static function setCallback($callback)
  26.     {
  27.         self::$callback $callback;
  28.     }
  29.     
  30. /**
  31.      * This is the default HTML view when someone tries to access the Manialink from outside the game.
  32.      * You can override this default behaviour by changing the callback with UserAgentCheckFilter::setCallback()
  33.      */
  34.     static function defaultHTMLView(
  35.     {
  36.         $APP_MANIALINK APP_MANIALINK;
  37.                 echo <<<HTML
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40.     <head>
  41.         <title>$APP_MANIALINK</title>
  42.         <style type="text/css">
  43.         
  44.             body {
  45.                 background: #333333;
  46.                 color: #eeeeee;
  47.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  48.                 font-size: 12px;
  49.                 line-height: 15px;
  50.             }
  51.             
  52.             #frame {
  53.                 width: 500px;
  54.                 margin: 25px auto;
  55.                 padding: 25px;
  56.                 border: 1px #cccccc solid;
  57.                 -moz-border-radius: 10px;
  58.                 -webkit-border-radius: 10px;
  59.             }
  60.             
  61.             h1 {
  62.                 color: #ffff00;
  63.                 text-align: center;
  64.             }
  65.             
  66.             p {
  67.                 text-align: justify;
  68.             }
  69.             
  70.             a, a:visited {
  71.                 color: #ffff00;
  72.                 text-decoration: underline;
  73.             }
  74.             
  75.             a:hover, a:active {
  76.                 color: orange;
  77.             }
  78.         </style>
  79.     </head>
  80.     <body>
  81.         <div id="frame">
  82.             <h1>$APP_MANIALINK</h1>
  83.             <p>
  84.             The page your are trying to access is a Manialink for TrackMania. 
  85.             You can only view it using the in-game browser.
  86.             <p>
  87.             
  88.             <p>
  89.             To access it, <a href="tmtp:///:$APP_MANIALINK">click here</a> or 
  90.             launch TrackMania Forever and go to the <b>$APP_MANIALINK</b> Manialink.
  91.             </p>
  92.             
  93.             <p>
  94.             TrackMania is a series of fast-paced racing video games in which you 
  95.             drive at mind-blowing speeds on fun and spectacular tracks in solo 
  96.             and multi player modes. Several in-game editors allow for track 
  97.             building, car painting or video editing.
  98.             </p>
  99.             
  100.             <p>
  101.             For more information, please visit <a href="http://www.trackmania.com">www.trackmania.com</a>
  102.             </p>
  103.         </div>
  104.     </body>
  105. </html>                
  106. HTML;
  107.     }
  108.     
  109.     /**
  110.      * @ignore
  111.      */
  112.     function preFilter()
  113.     {
  114.         if(APP_DEBUG_LEVEL == 0)
  115.         {
  116.             if(!array_key_exists('HTTP_USER_AGENT'$_SERVER|| $_SERVER['HTTP_USER_AGENT'!= 'GameBox')
  117.             {
  118.                 call_user_func(self::$callback);
  119.                 exit;
  120.             }
  121.         }
  122.     }
  123.     
  124.     /**
  125.      * @ignore
  126.      */
  127.     function postFilter({}
  128. }
  129.  
  130. ?>