I am using the ShURLy module to create short links for nodes. I would like to be able to create the short links when nodes are published, automatically, without having to do the extra steps of clicking on the Bookmarklet which opens a new page where I create the short link by clicking on a button/link.
How can I achieve this?
update
I am using workbench so I added
function my_node_workbench_moderation_transition($node,
$previous_state, $new_state) {
// Generate the short link when it is published.
if ($new_state == 'published' && $previous_state != $new_state) {
$link = my_node_create_short_link($node->nid);
}
}
and the function my_node_create_short_link
with shorten (shorten_url)
function my_node_create_short_link($node_id) {
// Do not create the short link if already exists.
$link = my_node_short_link_get($node_id);
if ($link) {
return $link;
}
else {
$link = shorten_url(url('node/' . $node->nid, array('absolute' => TRUE)));
// Insert the link
my_node_short_link_insert($node->nid;, $link);
cache_set($node->nid;, $link);
return $link;
}
}