SubClosure

{ Don't Repeat Yourself ! }

Just came across a strange behavior in Joomla 3 and component routing.
Found out that the first hypen in a SEF URL is always replaced by a colon.

Joomla assumes all SEF URLs have a structure like this: http://yoursefurl/mymenu/1­-welcome­-to­-joomla
The last part is called the slug and this seems to get messed up if you have hyphens in you url and the first part is not an ID.

The Joomla router will translate the slug segment into 1­:welcome­-to­-joomla, replacing the first hypen with a colon to separate the ID.

You either need to adjust your router and include first an id in your url followed by a hyphen or add

$vars['myitem'] = str_replace(“:”, “-” , $segment[1] ) ;

in your router.

I recently upgraded from Kunena 1.5 to Kunena 3

In Kunena 3 the ID in the SEF URL refers to the topic ID rather then message ID.
This is better for SEO, but old messages links from before the update are not working anymore unless they are the first message in a thread.

By inserting this bit of code into the components/com_kunena/router.php
after line 223 you can replace the message ID with topic ID, if the url contains a message ID rather then topic ID
That makes sure that your old Kunena URL’s still work after the update.

 

$db = JFactory::getDBO() ;

$sql = ‘select * from #__kunena_topics where id = ‘ . intval( $value ) . ‘ limit 1′ ;
$db->setQuery($sql ) ;
$r = $db->loadObject() ;

if(!$r) {
$sql = ‘select * from #__kunena_messages where id = ‘ .intval( $value ) . ‘ limit 1′ ;
$db->setQuery($sql ) ;
$r = $db->loadObject() ;
if($r) {
$value = $r->thread ;
$vars ['mesid'] = $r->id ;
}
}

 

locate the following bit of code in the router.php file – should be at line 223 and insert the above code just after $sefcats = false;

elseif (empty($vars ['id'])) {
// Second number is always topic
$var = 'id';
$vars ['view'] = 'topic';
$sefcats = false;

Install a linux distro via USB:

http://unetbootin.sourceforge.net/  makes it easy to create a bootable usb to install various linux distros

I decided to install debian onto a 32GB usb stick. So first I created a debian netinstall with unetbootin on an old 2GB usb stick, that I had lying around.
I booted from this stick and then plugged my empty 32GB stick into the second USB slot. During the debian installation I choose to have it partition and format the 32GB stick and use it for installation of the base system. Then I had grub installed onto the main hard drive. That works pretty good. I can now fully run debian from usb and disable the hard drive to save power.

A few handy commands:

- vbetool dpms {off/on} – turn display off or on
- pm-suspend – standby

I also installed laptop-mode-tools for power saving.
And then of course apache2, php5, mysql

 

After upgrading to joomla 3, I suddenly got this error.
Seems like the class name of the view class cannot contain uppercase letters anymore, except in the word View.

E.g.

My view class was named like this in joomla 1.5:

PaypalRegisterViewPaypalRegister

I had to change it to all to lowercase except the “V” in view, like so:

paypalregisterViewpaypalregister

Most examples these days use jquery to load jsonp data.
If you want to develop a simple javascript widget then it might not be a good option to include jquery in your code.
In this example I’ll show you how to load html from a server in any domain and display it with a javascript.

It’s actually very simple to load jsonp data without using any javascript libraries.

The trick is to load your data in a script tag like so:

<script type="text/javascript" src="http://subclosure.com/demos/getjsonpdata.php"></script>

The  server  needs to return a json object that is wrapped in a function, e.g.:

callback({"html":"hello jsonp"})

In PHP you can do it easily like this:

echo 'callback(' . json_encode(array('html' => 'hello jsonp')) . ')' ;

Now when this script is loaded into the browser, it will  call the function named callback (you can call this function whatever you like).

You just need to provide a handler for this function call and that’s pretty much it:

<div id = 'mycontent'></div>
<script>
  function callback(jsondata){
     document.getElementById('mycontent').innerHTML = jsondata.html ;
   }
</script>
<script type="text/javascript" src="http://subclosure.com/demos/getjsonpdata.php"></script>

 

Here is a working script example: http://subclosure.com/demos/getjsonp.html

I recently had to set up a new mac for web development.
Its always such a hassle to find it all again and I ended up spending much more time then anticipated.

Here is a quick reference list of what steps I took. Following this list will get you going in under one hour plus all software is free.

 

  1. install cyberduck for transfer and remote synchronization
  2. install xampp for a complete LAMP setup
  3. install eclipse pdt for a great php IDE
  4. install eclipse subclipse plugin for your svn projects
  5. install aptana plugin for all web development
  6. install textwrangler as a general purpose text and code editor with remote support
  7. install firefox with firebug plugin for debugging your html/css/javascript

After that also download some great php libs to include in new php projects:

  1. redbean – database orm
  2. ezql – easy database interface and abstraction
  3. phpmailer – probably the best email lib for php
  4. phpunit – unit testing
  5. simplepie – rss parser and rss creation
  6. php thumbnails – great for image uploads

just rediscovered my good old friend yoxos for downloading customized eclipse packages.
http://eclipsesource.com/en/yoxos/download-yoxos-5/

It allows to save profiles for installing the same eclipse configuration across multiple computers which saves heaps of time.

Safari, Chrome and Firefox work great with the facebook like button.

But to get internet explorer to display it I had to add the facebook namespace to my html tag.

e.g.
<html  xmlns:fb=”http://www.facebook.com/2008/fbml”
xmlns:og=”http://opengraphprotocol.org/schema/” … >

 

Probably one of the first things you would want to do with an openlayers map is adding some interaction.
Amazingly it is difficult to find an easy and quick example on how to do it.

Here is an example on how to move an Openlayer.Marker to the point where a user clicked on the map.

 

var markers = new OpenLayers.Layer.Markers( "Markers" );
marker = new OpenLayers.Marker(lonLat) ;
markers.addMarker(marker);
map.addLayer(markers);

map.events.register("click", map , function(e){
var opx = map.getLayerPxFromViewPortPx(e.xy) ;
marker.map = map ;
marker.moveTo(opx) ;
});


Another example can be found on the openlayers examples page.
I found it a bit overkill though and more difficult to use.

This error occurs on line 915 in Openlayers.js.

If you get this error when using the moveTo method of an OpenLayers.Marker object  set the map on the marker first.

e.g.

mymarker.map = map ;
mymarker.moveTo(opx ) ;

 

 

Get Adobe Flash player