WebPlugin.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2012 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. // settings/logic shared by plugins
  24. class WebPlugin
  25. {
  26. static $SAMPLE_HTML = "";
  27. static $GAME_FOLDER = "";
  28. static function readTemplate()
  29. {
  30. $filename = realpath( dirname( $_SERVER[ 'PHP_SELF' ] ) ). "/templates/web/sample_html.tpl";
  31. $fh = fopen($filename, 'r');
  32. $data = fread($fh, filesize($filename));
  33. fclose($fh);
  34. if (!$data)
  35. trigger_error( "WebPlugin::readTemplate() - cannot read HTML template!", E_USER_ERROR );
  36. self::$SAMPLE_HTML = $data;
  37. }
  38. static function processNPPlugin($np)
  39. {
  40. if (!self::$SAMPLE_HTML)
  41. self::readTemplate();
  42. $rootPhpBuildDir = getcwd();
  43. self::$GAME_FOLDER = $rootPhpBuildDir."/game/";
  44. self::$SAMPLE_HTML = str_replace("__MIMETYPE__", $np->MIMETYPE, self::$SAMPLE_HTML);
  45. }
  46. static function processActiveXPlugin($ax)
  47. {
  48. if (!self::$SAMPLE_HTML)
  49. self::readTemplate();
  50. $rootPhpBuildDir = getcwd();
  51. self::$GAME_FOLDER = $rootPhpBuildDir."/game/";
  52. $projID = $ax->WEBGAME_PLUGINNAME.'.'.$ax->WEBGAME_CTRLNAME.'.'.'1';
  53. self::$SAMPLE_HTML = str_replace("__PROJID__", $projID, self::$SAMPLE_HTML);
  54. self::$SAMPLE_HTML = str_replace("__CLSID__", $ax->WEBGAMELIB_UUID, self::$SAMPLE_HTML);
  55. }
  56. static function writeSampleHtml()
  57. {
  58. // no plugins defined
  59. if (!self::$SAMPLE_HTML)
  60. return;
  61. $filename = self::$GAME_FOLDER . "web/sample.html";
  62. $fh = fopen($filename, 'w');
  63. fwrite($fh, self::$SAMPLE_HTML);
  64. fclose($fh);
  65. }
  66. }
  67. ?>