Script.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * This class is designed to include canned scripts into a website.
  4. *
  5. * @author Ironpilot
  6. * @copyright Copywrite (c) 2011, STAPLE CODE
  7. *
  8. * This file is part of the STAPLE Framework.
  9. *
  10. * The STAPLE Framework is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by the
  12. * Free Software Foundation, either version 3 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * The STAPLE Framework is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  18. * more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with the STAPLE Framework. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. class Staple_Script
  24. {
  25. const JQUERY_CURRENT = '2.0.1';
  26. const JQUERYUI_CURRENT = '1.10.3';
  27. public static function jQuery($version = NULL, Staple_Layout $layout = NULL)
  28. {
  29. if(Staple_Request::isSecure())
  30. {
  31. $protocol = 'https://';
  32. }
  33. else
  34. {
  35. $protocol = 'http://';
  36. }
  37. if(isset($version))
  38. {
  39. $script = $protocol.'ajax.googleapis.com/ajax/libs/jquery/'.basename($version).'/jquery.min.js';
  40. }
  41. else
  42. {
  43. $script = $protocol.'ajax.googleapis.com/ajax/libs/jquery/'.self::JQUERY_CURRENT.'/jquery.min.js';
  44. }
  45. if($layout instanceof Staple_Layout)
  46. {
  47. $layout->addScript($script);
  48. }
  49. return $script;
  50. }
  51. public static function jQueryUI($version = NULL, Staple_Layout $layout = NULL)
  52. {
  53. if(Staple_Request::isSecure())
  54. {
  55. $protocol = 'https://';
  56. }
  57. else
  58. {
  59. $protocol = 'http://';
  60. }
  61. if(isset($version))
  62. {
  63. $script = $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/'.basename($version).'/jquery-ui.min.js';
  64. }
  65. else
  66. {
  67. $script = $protocol.'ajax.googleapis.com/ajax/libs/jqueryui/'.self::JQUERYUI_CURRENT.'/jquery-ui.min.js';
  68. }
  69. if($layout instanceof Staple_Layout)
  70. {
  71. $layout->addScript($script);
  72. }
  73. return $script;
  74. }
  75. public static function GoogleMaps(Staple_Layout $layout,$sensor = false)
  76. {
  77. $sensor = (bool)$sensor;
  78. $layout->addScript('http://maps.google.com/maps/api/js?sensor='.$sensor);
  79. }
  80. }
  81. ?>