Welcome to WebmasterWorld Guest from 23.20.223.88

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Joomla Change headdata

     
10:14 am on Feb 21, 2011 (gmt 0)

5+ Year Member



Hi,

I'm trying to dynamically change parts of an array.

This is the array:
Array ( [/components/com_jcomments/js/jcomments-v2.1.js?v=7] => text/javascript [/components/com_jcomments/libraries/joomlatune/ajax.js?v=3] => text/javascript [/media/system/js/mootools.js] => text/javascript [/media/system/js/caption.js] => text/javascript )


It's a Joomla! 1.5.x website.
The I get the array by using the following code:
$headerstuff  = $this->getHeadData(); 
$scripts = $headerstuff['scripts'];
print_r ($scripts);


I want to change parts of the array because the array is used to display the following code:
 <link rel="stylesheet" href="/components/com_jcomments/tpl/custom/style.css?v=12" type="text/css" />
<script type="text/javascript" src="/components/com_jcomments/js/jcomments-v2.1.js?v=7"></script>
<script type="text/javascript" src="/components/com_jcomments/libraries/joomlatune/ajax.js?v=3"></script>

<script type="text/javascript" src="/media/system/js/mootools.js"></script>
<script type="text/javascript" src="/media/system/js/caption.js"></script>


I want to change this into:
 <link rel="stylesheet" href="http://www.mydomain.com/components/com_jcomments/tpl/custom/style.css?v=12" type="text/css" />
<script type="text/javascript" src="http://www.mydomain.com/components/com_jcomments/js/jcomments-v2.1.js?v=7"></script>
<script type="text/javascript" src="http://www.mydomain.com/components/com_jcomments/libraries/joomlatune/ajax.js?v=3"></script>

<script type="text/javascript" src="http://www.mydomain.com/media/system/js/mootools.js"></script>
<script type="text/javascript" src="http://www.mydomain.com/media/system/js/caption.js"></script>


I've been trying several things and I found a 1001 pages that tell me how to "unset" certain bits of the array, for instance [eboga.org ]. I found [pastebin.com...] but I can't get that to work either.

I just can't figure out how to dynamically "add" the domain to the file location. I either end up over writing the "text/javascript" bit with the domain or I end up with just one edited line and all the other lines are removed from the array.

Any help or any pointers into the right direction would be greatly appreciated.
5:47 pm on Feb 23, 2011 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



So basically you are attempting to convert the urls to absolute urls including the scheme and domain? Do you have a function defined yet? If all the keys are always going to be relative paths you could create a new array with absolute paths. Something like this ...
<?php 
$array = array(
'/components/com_jcomments/js/jcomments-v2.1.js?v=7' => 'text/javascript',
'/components/com_jcomments/libraries/joomlatune/ajax.js?v=3' => 'text/javascript',
'/media/system/js/mootools.js' => 'text/javascript',
'/media/system/js/caption.js' => 'text/javascript'
);
$newArray = array();
$protocol = 'http://';
$domain = $_SERVER['SERVER_NAME'];
$base = "{$protocol}{$domain}";
foreach($array as $k => $v) {
$newArray["{$base}{$k}"] = $v;
}
$array = $newArray; // replace the original
// have a look now:
print '<pre>';
print_r($array);
print '</pre>';
exit;
?>
7:02 am on Feb 24, 2011 (gmt 0)

5+ Year Member



Hi Coopster,

Thank you for your reply.
I ended up using something like that. I extended it a little because I wanted to do the same for style sheets.

What should I do if I want to unset 1 script, for instance "'/components/com_jcomments/libraries/joomlatune/ajax.js?v=3'"?
7:23 am on Feb 24, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Why do you want to include the protocol and domain?

By including the HTTP scheme as a fixed value, users will get "mixed security warnings" when logged in and using HTTPS.

Make sure you add a non-www to www 301 redirect to the site's .htaccess file.
7:28 am on Feb 24, 2011 (gmt 0)

5+ Year Member



Hi g1smd,

Way ahead of ya ;)
We never use HTTPS on this website and we most likely never will and yes we do have a non-www to www 301 redirect.

And I don't really want it, management does ;)
2:23 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



What management wants and what management gets are two different things.

You're the SEO.
2:37 pm on Feb 24, 2011 (gmt 0)

5+ Year Member



Ha,

you tell em that. But no, the client gets what he/she is asking for. Anyway that's not the point.

I'd still like to figure out how to unset a certain script when I want to. Right now I'm doing it the other way around, unsetting everything and then adding the right scripts by hand. It works, but it's a nasty hack.
7:18 pm on Feb 24, 2011 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



protocol is a real easy workaround, you can do that dynamically too.

$protocol = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
 

Featured Threads

Hot Threads This Week

Hot Threads This Month