Joomla Hack remove all white space

Your code modifications and patches you want to share with others.
Locked
User avatar
C0nw0nk
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 248
Joined: Tue Jun 15, 2010 1:12 am
Location: United Kingdom, London
Contact:

Joomla Hack remove all white space

Post by C0nw0nk » Sat Mar 19, 2011 6:43 pm

Im woundering were to edit in joomla to change the html output for example

on your website when you right click and view page source it would look like this displaying all the white spaces and gapes / breaks inbetween the html code

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-gb" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="copyright" content="2000, 2002, 2005, 2007 phpBB Group" />
<meta name="keywords" content="Joomla, CMS, content management, PHP, MySQL, free, open, source, forum, website, webhosting" />
<meta name="description" content="Joomla! Discussion Forums" />

<title>Joomla! &bull; Post a new topic</title>
But if you remove the white space it should look like this

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-gb" xml:lang="en-gb">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="en-gb" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="copyright" content="2000, 2002, 2005, 2007 phpBB Group" />
<meta name="keywords" content="Joomla, CMS, content management, PHP, MySQL, free, open, source, forum, website, webhosting" />
<meta name="description" content="Joomla! Discussion Forums" />
<title>Joomla! &bull; Post a new topic</title>
allot smaller and nicer to look at.

Im just cruious if this is possible with joomla :D ?

I think is must be since CorePHP developed a plugin that can do this http://www.corephp.com/joomla-products/jomdefender.html

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44020
Joined: Sat Apr 05, 2008 9:58 pm

Re: Joomla Hack remove all white space

Post by Webdongle » Sat Mar 19, 2011 6:45 pm

Check your editor settings
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
C0nw0nk
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 248
Joined: Tue Jun 15, 2010 1:12 am
Location: United Kingdom, London
Contact:

Re: Joomla Hack remove all white space

Post by C0nw0nk » Sat Mar 19, 2011 7:16 pm

You mean TinyMCE Plugin from my joomla backend ?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44020
Joined: Sat Apr 05, 2008 9:58 pm

Re: Joomla Hack remove all white space

Post by Webdongle » Sat Mar 19, 2011 7:26 pm

I meant the configuration of whatever editor you are using. But I did it for you and found nothing there of relevance.

Found http://extensions.joomla.org/extensions ... erformance in JED
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
C0nw0nk
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 248
Joined: Tue Jun 15, 2010 1:12 am
Location: United Kingdom, London
Contact:

Re: Joomla Hack remove all white space

Post by C0nw0nk » Sat Mar 19, 2011 7:31 pm

I use the NoEditor as its set to in my global configuration.

For now im running jomDefender too for removing the white space but it would be more usefull if i could do it from within joomla's core without having any plugins stripping it all out.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44020
Joined: Sat Apr 05, 2008 9:58 pm

Re: Joomla Hack remove all white space

Post by Webdongle » Sat Mar 19, 2011 7:41 pm

None that I know of or can find in Joomla itself.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

kballou
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 168
Joined: Mon Oct 08, 2007 10:51 pm

Re: Joomla Hack remove all white space

Post by kballou » Sat Apr 02, 2011 3:41 am

C0nw0nk wrote:I think is must be since CorePHP developed a plugin that can do this http://www.corephp.com/joomla-products/jomdefender.html
You all but answered your own question right there. The answer is to create a system plugin. Your plugin should handle the onAfterRender event. Here's some skeleton code:

Code: Select all

jimport('joomla.plugin.plugin');

class plgSystemStripWhiteSpace extends JPlugin
{
    function plgSystemStripWhiteSpace(& $subject, $config)
    {
        parent::__construct($subject, $config);
    }

    function onAfterRender()
    {
        $document =& JFactory::getDocument();
        $doctype = $document->getType();

        if ($doctype !== 'html')
        {
            return;
        }

         $body = JResponse::getBody();
         /* $body is the entire HTML response, starting with the open <html> tag,
             ending with the close tag </html>.  Write your code to strip white space here. */
         JResponse::setBody($body);
    }
}
}

Install your plugin and then enable it from the plugin manager in the administrator back end.

I am curious why you object to using a plugin. That is exactly the purpose of a plugin -- change Joomla!'s behavior without having to modify the core code.

User avatar
kurchania
Joomla! Hero
Joomla! Hero
Posts: 2070
Joined: Mon Sep 21, 2009 6:56 am
Location: indore,india
Contact:

Re: Joomla Hack remove all white space

Post by kurchania » Sat Apr 02, 2011 5:39 am

@C0nw0nk
did you look at the template index.php?its in templates/your_template/index.php
this is the file that generate output of browser.i guess you will find white spaces there.
@kballou
don't you think this system plugin will make your website little bit slow?
abhijeet kurchania
The future depends on what you do today

kballou
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 168
Joined: Mon Oct 08, 2007 10:51 pm

Re: Joomla Hack remove all white space

Post by kballou » Sat Apr 02, 2011 6:07 pm

kurchania wrote:@kballou: don't you think this system plugin will make your website little bit slow?
Depends on what question you're asking. If you're asking whether stripping unnecessary white space will make the site slower, the answer is "most definitely."

I think, however, that you are asking whether implementing this functionality as a plugin will slow down the site. To that, my answer would be "negligiblly so, and probably unmeasurable."

The overhead for a plugin:
1. At application initialization time, the core queries #__plugins (version 1.5) or #__extensions (version 1.6) to find the list of enabled "system" plugins. The core then creates an instance of each plugin object, and the plugin registers with the system event dispatcher. Essentially, the overhead here is having one more class to instantiate and one more plugin to register with the dispatcher.

2. In version 1.5, when an event is triggered, the dispatcher walks the list of observers (plugins). For each plugin, the dispatcher checks whether the plugin handles that even (by looking for a method whose name is that of the event). If the plugin does handle the event, the dispatcher invokes the plugin's handler method. So, the cost of having another plugin is just a check whether that plugin handles a particular event each time the event is triggered.

Version 1.6 avoids this overhead by making a time/space tradeoff. In version 1.6, when an observer registers with the dispatcher, the dispatcher examines the observer to determine which events it handles. The dispatcher maintains a separate array of handlers for each event type. So, when dispatching an event, the dispatcher already knows exactly which plugins are interested and which should be ignored.

3. The cost of string handling in PHP is going to exceed the overhead cost in the first two items by at least a couple orders of magnitude. I can only see two alternatives. One is to trim the whitespace from the assembled response body after the document has been rendered. It seems to me this approach requires some pretty serious regular expression and string substitution processing. The other is to modify every layout template in all the components and modules to remove excess white space. That would make maintenance of the layout templates much more difficult for no good reason, as well as making it hard to debug by looking at the output of the component or module.


Locked

Return to “Core Hacks and Patches”