TeraWurflAdmin
[ class tree: TeraWurflAdmin ] [ index: TeraWurflAdmin ] [ all elements ]

Source for file generatePatch.php

Documentation is available at generatePatch.php

  1. <?php
  2. /**
  3.  * Tera_WURFL - PHP MySQL driven WURFL
  4.  * 
  5.  * Tera-WURFL was written by Steve Kamerman, and is based on the
  6.  * Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
  7.  * This version uses a MySQL database to store the entire WURFL file, multiple patch
  8.  * files, and a persistent caching mechanism to provide extreme performance increases.
  9.  * 
  10.  * @package TeraWurflAdmin
  11.  * @author Steve Kamerman <stevekamerman AT gmail.com>
  12.  * @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
  13.  * @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
  14.  */
  15. require_once realpath(dirname(__FILE__).'/../TeraWurfl.php');
  16.  
  17. try {
  18.     $tw new TeraWurfl();
  19. }catch(Exception $e){
  20.     
  21. }
  22.  
  23. $patch_changed false;
  24. $custom_patch $tw->rootdir.TeraWurflConfig::$DATADIR."custom_web_patch.xml";
  25. $custom_patch_user_agents $tw->rootdir.TeraWurflConfig::$DATADIR."custom_web_patch_uas.txt";
  26.  
  27. if(isset($_POST['action']&& $_POST['action']=='generate_patch'){
  28.     $patch_data "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<wurfl_patch>\n\t<devices>";
  29.     $i 0;
  30.     $rawdata $_POST['data'];
  31.     if(get_magic_quotes_gpc()){$rawdata=stripslashes($rawdata);}
  32.     $rawdata preg_replace('/[\r\n]+/',"\n",$rawdata);
  33.     $data explode("\n",$rawdata);
  34.     foreach($data as $line){
  35.         $line trim($line);
  36.         if($line == "")continue;
  37.         $patch_data .= "\n\t\t".'<device user_agent="'.htmlspecialchars($line).'" fall_back="generic_web_browser" id="terawurfl_generic_web_browser'.$i++.'"/>';
  38.     }
  39.     $patch_data .= "\n\t</devices>\n</wurfl_patch>";
  40.     file_put_contents($custom_patch_user_agents,$rawdata);
  41.     file_put_contents($custom_patch,$patch_data);
  42.     $patch_changed true;
  43. }
  44.  
  45. ?>
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  47. <html xmlns="http://www.w3.org/1999/xhtml">
  48. <head>
  49.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  50.     <title>Tera-WURFL Custom Patch Generator</title>
  51.     <link href="style.css" rel="stylesheet" type="text/css" />
  52. </head>
  53. <body>
  54. <table width="100%">
  55.     <tr><td>
  56.     <div align="center" class="titlediv">
  57.     <p>Tera-WURFL Custom Patch Generator<br/>
  58.         <span class="version">Version <?php echo $tw->release_branch." ".$tw->release_version?></span></p>
  59.     </div>
  60.     <?php if($patch_changed){?><div align="center" class="noticediv" style="width: 100%">Custom patch file saved.  <a href="#patch">View patch file</a></div><?php }?>
  61.     </td></tr>
  62.     <tr><td>
  63.     <table width="100%" border="0" cellspacing="0" cellpadding="0">
  64.         <tr><th>Enter your non-mobile user agents below</th></tr>
  65.     </table>
  66.     </td></tr>
  67.     <tr><td class="lightrow">Enter your non-mobile user agents below, one per line, and press <strong>Generate Patch File</strong>.  These user agents will be compiled into the Tera-WURFL custom patch file <strong><?php echo $custom_patch?></strong>. After you submit the changes, go to the <a href="index.php">Tera-WURFL Administration Page</a> and update your WURFL database to load the new patch file.</td></tr>
  68.     <tr>
  69.         <td><form action="generatePatch.php" method="post">
  70.         <input type="hidden" name="action" value="generate_patch" />
  71.         <textarea name="data" rows="25" cols="97" style="width: 100%;"><?php echo file_get_contents($custom_patch_user_agents);?></textarea>
  72.         <br/><center><input type="submit" value="Generate Patch File" name="submit" /></center>
  73.         </form></td>
  74.     </tr>
  75. </table>
  76. <pre><a name="patch"></a><?php if($patch_changed){echo htmlspecialchars(file_get_contents($custom_patch));}?></pre>
  77. </body>
  78. </html>

Documentation generated on Sun, 19 Sep 2010 00:15:50 +0000 by phpDocumentor 1.4.3