PageRenderTime 25ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/joomla/plugins/system/regularlabs/helpers/quickpage.php

https://gitlab.com/ricardosanchez/prueba
PHP | 183 lines | 126 code | 37 blank | 20 comment | 15 complexity | f2249f3c7c22bf278529cb7007edfd7b MD5 | raw file
  1. <?php
  2. /**
  3. * @package Regular Labs Library
  4. * @version 16.11.9943
  5. *
  6. * @author Peter van Westen <info@regularlabs.com>
  7. * @link http://www.regularlabs.com
  8. * @copyright Copyright © 2016 Regular Labs All Rights Reserved
  9. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  10. */
  11. defined('_JEXEC') or die;
  12. require_once JPATH_LIBRARIES . '/regularlabs/helpers/functions.php';
  13. /**
  14. * Regular Labs Quick Page stuff (rl_qp=1 in url)
  15. */
  16. class PlgSystemRegularLabsQuickPageHelper
  17. {
  18. function render()
  19. {
  20. $url = JFactory::getApplication()->input->getString('url', '');
  21. if ($url)
  22. {
  23. echo RLFunctions::getByUrl($url);
  24. die;
  25. }
  26. $allowed = array(
  27. 'administrator/components/com_dbreplacer/ajax.php',
  28. 'administrator/modules/mod_addtomenu/popup.php',
  29. 'media/rereplacer/images/popup.php',
  30. 'plugins/editors-xtd/articlesanywhere/popup.php',
  31. 'plugins/editors-xtd/conditionalcontent/popup.php',
  32. 'plugins/editors-xtd/contenttemplater/data.php',
  33. 'plugins/editors-xtd/contenttemplater/popup.php',
  34. 'plugins/editors-xtd/dummycontent/popup.php',
  35. 'plugins/editors-xtd/modals/popup.php',
  36. 'plugins/editors-xtd/modulesanywhere/popup.php',
  37. 'plugins/editors-xtd/sliders/data.php',
  38. 'plugins/editors-xtd/sliders/popup.php',
  39. 'plugins/editors-xtd/snippets/popup.php',
  40. 'plugins/editors-xtd/sourcerer/popup.php',
  41. 'plugins/editors-xtd/tabs/data.php',
  42. 'plugins/editors-xtd/tabs/popup.php',
  43. 'plugins/editors-xtd/tooltips/popup.php',
  44. );
  45. $file = JFactory::getApplication()->input->getString('file', '');
  46. $folder = JFactory::getApplication()->input->getString('folder', '');
  47. if ($folder)
  48. {
  49. $file = implode('/', explode('.', $folder)) . '/' . $file;
  50. }
  51. if (!$file || in_array($file, $allowed) === false)
  52. {
  53. die;
  54. }
  55. jimport('joomla.filesystem.file');
  56. if (JFactory::getApplication()->isSite())
  57. {
  58. JFactory::getApplication()->setTemplate('../administrator/templates/isis');
  59. }
  60. $_REQUEST['tmpl'] = 'component';
  61. JFactory::getApplication()->input->set('option', 'com_content');
  62. switch (JFactory::getApplication()->input->getCmd('format', 'html'))
  63. {
  64. case 'json' :
  65. $format = 'application/json';
  66. break;
  67. default:
  68. case 'html' :
  69. $format = 'text/html';
  70. break;
  71. }
  72. header('Content-Type: ' . $format . '; charset=utf-8');
  73. JHtml::_('bootstrap.framework');
  74. JFactory::getDocument()->addScript(JUri::root(true) . '/administrator/templates/isis/js/template.js');
  75. JFactory::getDocument()->addStyleSheet(JUri::root(true) . '/administrator/templates/isis/css/template.css');
  76. RLFunctions::stylesheet('regularlabs/popup.min.css');
  77. $file = JPATH_SITE . '/' . $file;
  78. $html = '';
  79. if (JFile::exists($file))
  80. {
  81. ob_start();
  82. include $file;
  83. $html = ob_get_contents();
  84. ob_end_clean();
  85. }
  86. JFactory::getDocument()->setBuffer($html, 'component');
  87. $app = new RLApplication();
  88. $app->render();
  89. $html = JFactory::getApplication()->toString(JFactory::getApplication()->getCfg('gzip'));
  90. $html = preg_replace('#\s*<' . 'link [^>]*href="[^"]*templates/system/[^"]*\.css[^"]*"[^>]*( /)?>#s', '', $html);
  91. $html = preg_replace('#(<' . 'body [^>]*class=")#s', '\1reglab-popup ', $html);
  92. $html = str_replace('<' . 'body>', '<' . 'body class="reglab-popup"', $html);
  93. echo $html;
  94. die;
  95. }
  96. }
  97. class RLApplication
  98. {
  99. public function render()
  100. {
  101. $app = JFactory::getApplication();
  102. $document = JFactory::getDocument();
  103. $app->loadDocument($document);
  104. $params = array(
  105. 'template' => $app->get('theme'),
  106. 'file' => $app->get('themeFile', 'index.php'),
  107. 'params' => $app->get('themeParams'),
  108. 'directory' => self::getThemesDirectory(),
  109. );
  110. // Parse the document.
  111. $document->parse($params);
  112. // Trigger the onBeforeRender event.
  113. JPluginHelper::importPlugin('system');
  114. $app->triggerEvent('onBeforeRender');
  115. $caching = false;
  116. if ($app->isSite() && $app->get('caching') && $app->get('caching', 2) == 2 && !JFactory::getUser()->get('id'))
  117. {
  118. $caching = true;
  119. }
  120. // Render the document.
  121. $data = $document->render($caching, $params);
  122. // Set the application output data.
  123. $app->setBody($data);
  124. // Trigger the onAfterRender event.
  125. $app->triggerEvent('onAfterRender');
  126. // Mark afterRender in the profiler.
  127. // Causes issues, so commented out.
  128. // JDEBUG ? $app->profiler->mark('afterRender') : null;
  129. }
  130. static function getThemesDirectory()
  131. {
  132. if (JFactory::getApplication()->get('themes.base'))
  133. {
  134. return JFactory::getApplication()->get('themes.base');
  135. }
  136. if (defined('JPATH_THEMES'))
  137. {
  138. return JPATH_THEMES;
  139. }
  140. if (defined('JPATH_BASE'))
  141. {
  142. return JPATH_BASE . '/themes';
  143. }
  144. return __DIR__ . '/themes';
  145. }
  146. }