PageRenderTime 76ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/EngineHelpers.php

https://github.com/poitch/dokin
PHP | 114 lines | 58 code | 12 blank | 44 comment | 9 complexity | 78fba99a244ab59cafb3513094307055 MD5 | raw file
  1. <?php
  2. /**
  3. *****************************************************************************
  4. ** Copyright (c) 2007-2010 Jerome Poichet <jerome@frencaze.com>
  5. **
  6. ** This software is supplied to you by Jerome Poichet in consideration of
  7. ** your agreement to the following terms, and your use, installation,
  8. ** modification or redistribution of this software constitutes acceptance of
  9. ** these terms. If you do not agree with these terms, please do not use,
  10. ** install, modify or redistribute this software.
  11. **
  12. ** In consideration of your agreement to abide by the following terms, and
  13. ** subject to these terms, Jerome Poichet grants you a personal, non-exclusive
  14. ** license, to use, reproduce, modify and redistribute the software, with or
  15. ** without modifications, in source and/or binary forms; provided that if you
  16. ** redistribute the software in its entirety and without modifications, you
  17. ** must retain this notice and the following text and disclaimers in all such
  18. ** redistributions of the software, and that in all cases attribution of
  19. ** Jerome Poichet as the original author of the source code shall be included
  20. ** in all such resulting software products or distributions.
  21. **
  22. ** Neither the name, trademarks, service marks or logos of Jerome Poichet may
  23. ** be used to endorse or promote products derived from the software without
  24. ** specific prior written permission from Jerome Poichet. Except as expressly
  25. ** stated in this notice, no other rights or licenses, express or implied, are
  26. ** granted by Jerome Poichet herein, including but not limited to any patent
  27. ** rights that may be infringed by your derivative works or by other works in
  28. ** which the software may be incorporated.
  29. **
  30. ** The software is provided by Jerome Poichet on an "AS IS" basis.
  31. ** JEROME POICHET MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT
  32. ** LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND
  33. ** FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE SOFTWARE OR ITS USE AND
  34. ** OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
  35. **
  36. ** IN NO EVENT SHALL JEROME POICHET BE LIABLE FOR ANY SPECIAL, INDIRECT,
  37. ** INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38. ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  39. ** OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
  40. ** MODIFICATION AND/OR DISTRIBUTION OF THE SOFTWARE, HOWEVER CAUSED AND
  41. ** WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT
  42. ** LIABILITY OR OTHERWISE, EVEN IF JEROME POICHET HAS BEEN ADVISED OF THE
  43. ** POSSIBILITY OF SUCH DAMAGE.
  44. *****************************************************************************
  45. **/
  46. require_once DOKIN_DIR.'Controller.php';
  47. require_once DOKIN_DIR.'Config.php';
  48. function template($path, $hData = array())
  49. {
  50. global $sEngineDebug,$sControllerDebug;
  51. $sTemplatePath = 'app/templates/'.$path;
  52. if (!file_exists($sTemplatePath)) {
  53. throw new Exception('template '.$path.' not found');
  54. }
  55. $oController = Controller::get_instance();
  56. if ($oController) {
  57. extract($oController->get());
  58. }
  59. if (is_array($hData) && sizeof($hData)) {
  60. extract($hData);
  61. }
  62. include($sTemplatePath);
  63. }
  64. function include_content()
  65. {
  66. global $_content_template;
  67. template($_content_template);
  68. }
  69. function render_partial($sTemplate,$hData)
  70. {
  71. if (is_array($hData) && sizeof($hData)) {
  72. extract($hData);
  73. }
  74. $sTemplatePath = 'app/templates/'.$sTemplate;
  75. if (!file_exists($sTemplatePath)) {
  76. throw new Exception('template '.$path.' not found');
  77. }
  78. ob_start();
  79. include($sTemplatePath);
  80. $sContent = ob_get_contents();
  81. ob_end_clean();
  82. return $sContent;
  83. }
  84. function set_cookie($key, $value, $life = NULL)
  85. {
  86. $aServerAddress = explode('.', $_SERVER['SERVER_NAME']);
  87. $sDomain = '.'.$aServerAddress[count($aServerAddress)-2].'.'.$aServerAddress[count($aServerAddress)-1];
  88. if ($life !== NULL) {
  89. $time = time() + $life;
  90. } else {
  91. $time = NULL;
  92. }
  93. setcookie($key, $value, $time, '/', $sDomain);
  94. }
  95. function uuid()
  96. {
  97. return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  98. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  99. mt_rand( 0, 0x0fff ) | 0x4000,
  100. mt_rand( 0, 0x3fff ) | 0x8000,
  101. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
  102. }