Exemplo n.º 1
0
 /**
  * Render template admin UI
  *
  * @return  void
  */
 public static function onAfterRender()
 {
     // Make sure our event handler is the last one executed
     if (!defined('JSN_TPLFW_LAST_EXECUTION')) {
         return;
     }
     // Get Joomla application object
     $app = JFactory::getApplication();
     // Detect method to use for getting and setting response body
     if (version_compare(JVERSION, '3.2.0', 'ge')) {
         $get = array($app, 'getBody');
         $set = array($app, 'setBody');
     } else {
         $get = array('JResponse', 'getBody');
         $set = array('JResponse', 'setBody');
     }
     if ($app->isAdmin()) {
         // Alter body tag
         $html = call_user_func($get);
         if (preg_match('/<body[^>]*>/i', $html, $match) and strpos($match[0], 'jsn-master tmpl-' . $app->getTemplate()) === false) {
             if (strpos($match[0], 'class=') === false) {
                 $match[1] = substr($match[0], 0, -1) . ' class=" jsn-master tmpl-' . $app->getTemplate() . ' ">';
             } else {
                 $match[1] = str_replace('class="', 'class=" jsn-master tmpl-' . $app->getTemplate() . ' ', $match[0]);
             }
             $html = str_replace($match[0], $match[1], $html);
         }
         call_user_func($set, $html);
         // Initialize template admin
         if (isset(self::$_templateAdmin) and self::$_templateAdmin instanceof JSNTplTemplateAdmin) {
             self::$_templateAdmin->render();
             // Clean-up Chosen calls if running on Joomla 3.1
             $JVersion = new JVersion();
             if (version_compare($JVersion->getShortVersion(), '3.1', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<link rel="stylesheet" href="[^"]*/media/jui/css/chosen\\.css" type="text/css" />#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/jui/js/chosen\\.jquery\\.min\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+jQuery\\(document\\)\\.ready\\(function \\(\\)\\{[\\r\\n][\\s\\t]+jQuery\\(\'select\'\\)\\.chosen\\(\\{[^\\}]+\\}\\);[\\r\\n][\\s\\t]+\\}\\);#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
             // Clean-up HTML5 fall-back script if running on Joomla 3.2
             if (version_compare($JVersion->getShortVersion(), '3.2', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/system/js/html5fallback(-uncompressed)?\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
         }
         // Execute update checker
         self::checkUpdate();
     } elseif (JSNTplTemplateRecognization::detect()) {
         $document = JFactory::getDocument();
         $config = JFactory::getConfig();
         $html = call_user_func($get);
         // Optimize script tags position
         self::moveScriptTags($html);
         if (isset($document->helper) && $document->helper instanceof JSNTplTemplateHelper && $document->compression > 0) {
             // Verify cache directory
             if (!preg_match('#^(/|\\|[a-z]:)#i', $document->params->get('cacheDirectory'))) {
                 $cachePath = JPATH_ROOT . '/' . rtrim($document->params->get('cacheDirectory'), '\\/');
             } else {
                 $cachePath = rtrim($document->params->get('cacheDirectory'), '\\/');
             }
             if ($config->get('ftp_enable') or is_writable($cachePath)) {
                 // Start compress CSS
                 if ($document->compression == 1 or $document->compression == 2) {
                     $html = preg_replace_callback('/(<link([^>]+)rel=["|\']stylesheet["|\']([^>]*)>\\s*)+/i', array('JSNTplCompressCss', 'compress'), $html);
                 }
                 // Start compress JS
                 if ($document->compression == 1 or $document->compression == 3) {
                     $html = preg_replace_callback('/(<script([^>]+)src=["|\']([^"|\']+)["|\']([^>]*)>\\s*<\\/script>\\s*)+/i', array('JSNTplCompressJs', 'compress'), $html);
                 }
             }
         }
         call_user_func($set, $html);
     }
 }
Exemplo n.º 2
0
 /**
  * Render template admin UI
  *
  * @return  void
  */
 public static function onAfterRender()
 {
     // Make sure our event handler is the last one executed
     if (!defined('JSN_TPLFW_LAST_EXECUTION')) {
         return;
     }
     // Get Joomla application object
     $app = JFactory::getApplication();
     // Detect method to use for getting and setting response body
     if (version_compare(JVERSION, '3.2.0', 'ge')) {
         $get = array($app, 'getBody');
         $set = array($app, 'setBody');
     } else {
         $get = array('JResponse', 'getBody');
         $set = array('JResponse', 'setBody');
     }
     if ($app->isAdmin()) {
         // Alter body tag
         $html = call_user_func($get);
         if (preg_match('/<body[^>]*>/i', $html, $match) and strpos($match[0], 'jsn-master tmpl-' . $app->getTemplate()) === false) {
             if (strpos($match[0], 'class=') === false) {
                 $match[1] = substr($match[0], 0, -1) . ' class=" jsn-master tmpl-' . $app->getTemplate() . ' ">';
             } else {
                 $match[1] = str_replace('class="', 'class=" jsn-master tmpl-' . $app->getTemplate() . ' ', $match[0]);
             }
             $html = str_replace($match[0], $match[1], $html);
         }
         call_user_func($set, $html);
         // Initialize template admin
         if (isset(self::$_templateAdmin) and self::$_templateAdmin instanceof JSNTplTemplateAdmin) {
             self::$_templateAdmin->render();
             // Clean-up Chosen calls if running on Joomla 3.1
             $JVersion = new JVersion();
             if (version_compare($JVersion->getShortVersion(), '3.1', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<link rel="stylesheet" href="[^"]*/media/jui/css/chosen\\.css" type="text/css" />#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/jui/js/chosen\\.jquery\\.min\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 if (preg_match('#[\\r\\n][\\s\\t]+jQuery\\(document\\)\\.ready\\(function \\(\\)\\{[\\r\\n][\\s\\t]+jQuery\\(\'select\'\\)\\.chosen\\(\\{[^\\}]+\\}\\);[\\r\\n][\\s\\t]+\\}\\);#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
             // Clean-up HTML5 fall-back script if running on Joomla 3.2
             if (version_compare($JVersion->getShortVersion(), '3.2', '>=')) {
                 $html = call_user_func($get);
                 if (preg_match('#[\\r\\n][\\s\\t]+<script src="[^"]*/media/system/js/html5fallback(-uncompressed)?\\.js" type="text/javascript"></script>#', $html, $match)) {
                     $html = str_replace($match[0], '', $html);
                 }
                 call_user_func($set, $html);
             }
         }
         // Execute update checker
         self::checkUpdate();
     } elseif (JSNTplTemplateRecognization::detect()) {
         //replace Favicon
         if ($app->isSite()) {
             self::replaceFavicon();
         }
         $document = JFactory::getDocument();
         $config = JFactory::getConfig();
         $html = call_user_func($get);
         // Optimize script tags position
         self::moveScriptTags($html);
         // Fix compatibility with K2 editor's extra fields
         if ($app->input->getCmd('option') == 'com_k2' && $app->input->getCmd('view') == 'item' && $app->input->getCmd('task') == 'edit') {
             $html = str_replace('</body>', '<script type="text/javascript">(function($) { $(document).ready(function() { $("select#catid").trigger("change"); }); })(jQuery);</script></body>', $html);
         }
         // Fix compatibility with MailChimp's mc-validate.js script
         if (preg_match('#<script\\s.*src="[^"]+/downloads.mailchimp.com/js/mc-validate.js"></script>#', $html, $match)) {
             $replace = '<script type="text/javascript">!window.jQuery || (window.JSNTPLFW_jQuery_backup = window.jQuery);</script>' . $match[0] . '<script type="text/javascript">!window.JSNTPLFW_jQuery_backup || (window.jQuery = window.JSNTPLFW_jQuery_backup); delete window.JSNTPLFW_jQuery_backup;</script>';
             $html = str_replace($match[0], $replace, $html);
         }
         call_user_func($set, $html);
     }
 }
Exemplo n.º 3
0
 /**
  * Retrieve initialized instance of template admin object
  *
  * @param   JForm  $context  Current context of template admin.
  *
  * @return  JSNTplTemplateAdmin
  */
 public static function getInstance(JForm $context)
 {
     if (self::$_instance == null || !self::$_instance instanceof JSNTplTemplateAdmin) {
         self::$_instance = new JSNTplTemplateAdmin($context);
     }
     return self::$_instance;
 }