PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/cache/controller/output.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 122 lines | 61 code | 15 blank | 46 comment | 12 complexity | 997738104843c7e2c089118a6de06357 MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Cache
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Joomla Cache output type object
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage Cache
  15. * @since 11.1
  16. */
  17. class JCacheControllerOutput extends JCacheController
  18. {
  19. /**
  20. * @since 11.1
  21. */
  22. protected $_id;
  23. /**
  24. * @since 11.1
  25. */
  26. protected $_group;
  27. /**
  28. * @since 11.1
  29. */
  30. protected $_locktest = null;
  31. /**
  32. * Start the cache
  33. *
  34. * @param string $id The cache data id
  35. * @param string $group The cache data group
  36. *
  37. * @return boolean True if the cache is hit (false else)
  38. *
  39. * @since 11.1
  40. */
  41. public function start($id, $group = null)
  42. {
  43. // If we have data in cache use that.
  44. $data = $this->cache->get($id, $group);
  45. $this->_locktest = new stdClass;
  46. $this->_locktest->locked = null;
  47. $this->_locktest->locklooped = null;
  48. if ($data === false)
  49. {
  50. $this->_locktest = $this->cache->lock($id, $group);
  51. if ($this->_locktest->locked == true && $this->_locktest->locklooped == true)
  52. {
  53. $data = $this->cache->get($id, $group);
  54. }
  55. }
  56. if ($data !== false)
  57. {
  58. $data = unserialize(trim($data));
  59. echo $data;
  60. if ($this->_locktest->locked == true)
  61. {
  62. $this->cache->unlock($id, $group);
  63. }
  64. return true;
  65. }
  66. else
  67. {
  68. // Nothing in cache... let's start the output buffer and start collecting data for next time.
  69. if ($this->_locktest->locked == false)
  70. {
  71. $this->_locktest = $this->cache->lock($id, $group);
  72. }
  73. ob_start();
  74. ob_implicit_flush(false);
  75. // Set id and group placeholders
  76. $this->_id = $id;
  77. $this->_group = $group;
  78. return false;
  79. }
  80. }
  81. /**
  82. * Stop the cache buffer and store the cached data
  83. *
  84. * @return boolean True if cache stored
  85. *
  86. * @since 11.1
  87. */
  88. public function end()
  89. {
  90. // Get data from output buffer and echo it
  91. $data = ob_get_contents();
  92. ob_end_clean();
  93. echo $data;
  94. // Get id and group and reset them placeholders
  95. $id = $this->_id;
  96. $group = $this->_group;
  97. $this->_id = null;
  98. $this->_group = null;
  99. // Get the storage handler and store the cached data
  100. $ret = $this->cache->store(serialize($data), $id, $group);
  101. if ($this->_locktest->locked == true)
  102. {
  103. $this->cache->unlock($id, $group);
  104. }
  105. return $ret;
  106. }
  107. }