homepage Welcome to WebmasterWorld Guest from 54.196.194.204
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Joomla Change headdata
glimbeek




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

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.

 

coopster




msg:4271143
 5:47 pm on Feb 23, 2011 (gmt 0)

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;
?>

glimbeek




msg:4271367
 7:02 am on Feb 24, 2011 (gmt 0)

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'"?

g1smd




msg:4271376
 7:23 am on Feb 24, 2011 (gmt 0)

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.

glimbeek




msg:4271378
 7:28 am on Feb 24, 2011 (gmt 0)

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 ;)

g1smd




msg:4271477
 2:23 pm on Feb 24, 2011 (gmt 0)

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

You're the SEO.

glimbeek




msg:4271480
 2:37 pm on Feb 24, 2011 (gmt 0)

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.

coopster




msg:4271698
 7:18 pm on Feb 24, 2011 (gmt 0)

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

$protocol = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved