Duplicate Titles / Unique URL Titles
Posted: 05 June 2008 12:53 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  246
Joined  04-12-2008

So with that hook would it instead not just be easier on the system to append the entry_id of the entry you are about to publish to the end of the url_title instead?

In my eyes, this would be the safest way, appending timestamps gives you even uglier URLs anyway and there can’t be two entry_ids with the same value (in one site) i suppose.

Mod Edit: Split from this feature request.

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension

Profile
 
 
Posted: 05 June 2008 02:22 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Yep that’s what I thought. Now if only I had the first inkling of how to do that wink

Cheers,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 05 June 2008 02:25 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  246
Joined  04-12-2008

Hey Mark

Shouldn’t be that hard, try to have a look at “submit_next_entry_start” hook, do a print_r of the $_POST var, i suppose the url_title will be theresomewhere, you could dynamically change that value for starters.

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension

Profile
 
 
Posted: 05 June 2008 02:56 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Will take a look at what you have said there - the print_r I mean. I see that a lot but never totally understand how to use it all and then even when I do see the results from those kinds of things I still don’t know how to go about modifying them on the fly.

Will take a look though. Really don’t think I will get it though.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 05 June 2008 02:57 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  246
Joined  04-12-2008

Hm, let me see, maybe I will have a look at this one too wink

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension

Profile
 
 
Posted: 05 June 2008 03:08 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  246
Joined  04-12-2008

Ok here it goes: if you use the mentioned hook, you can do a simple print_r (see PHP docs, prints out the content of a variable) to see what and how it is passed through the hook.

Array
(
    
[weblog_id] => 1
    [entry_id]
=>
    
[entry_date] => 2008-06-05 11:08 AM
    [expiration_date]
=>
    
[comment_expiration_date] =>
    
[author_id] => 1
    [new_weblog]
=> 1
    [status]
=> open
    [allow_comments]
=> y
    [dst_enabled]
=> y
    [trackback_urls]
=>
    
[title] => A test entry
    [url_title]
=> a_test_entry
    [submit]
=> Submit
    [mode]
=> normal
    [field_id_1]
=>
    
[field_ft_1] => xhtml
    [field_id_2]
=>
    
[field_ft_2] => xhtml
    [field_id_3]
=>
    
[field_ft_3] => xhtml
)

This $_POST array contains an entry

[url_title] => a_test_entry

which means you could start doing changes (e.g. appending the entry_id) to it. To append the entry id, you’d have to use a later hook as here, the entry_id coming from the post is, of course, still empty.

Just giving you some ideas.

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension

Profile
 
 
Posted: 05 June 2008 03:12 AM   [ Ignore ]   [ # 6 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Hiya,

Thanks for that. Still not entirely certain what you did there but I will take a look at this myself and see if I can get my head around it. May take a while though as I am still stuck with a plugin that I am trying to creates (no-one seems to like me in the plugins forum downer ).

Thanks again for the pointers on this though.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 26 June 2008 08:28 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  107
Joined  11-17-2005

Hey Mark,

Did you have any luck with this? I need to do something very similar indeed except add the entry_id to the front of the url_title. I’d be incredibly grateful for any tips you can offer…

Rob

Profile
 
 
Posted: 27 June 2008 02:05 AM   [ Ignore ]   [ # 8 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

My tip would be that I need to get more sleep (hmm actually that’s more a tip for me really! wink ).

Unfortunately other work got in the way of me looking at this one so had to take a back-burner. I may when I get the chance take another look into doing this as I do feel that it is something that is really really needed personally.

Sorry that I don’t have any information other than I slacked out on this one grin

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 02 November 2008 04:08 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  107
Joined  11-17-2005

So I finally tried to get my head around extensions and took a run at this.

It seems to work, but since this is my first run, I’d be very grateful for any tips or improvements anyone can offer:

<?php

class entry_id_in_url_title
{
    
var $settings = array();
    var
$name = 'Entry_id in url_title';
    var
$version = '1.0';
    var
$description = 'Inserts entry_id into url_title when submitting new entry';
    var
$settings_exist = 'n';
    var
$docs_url = '';
    
    
    function
entry_id_in_url_title($settings='')
    
{
        $this
->settings = $settings;
    
}
    
    
function insert_entry_id($entry_id, $data, $ping_message)
    
{    

        
if (array_key_exists('entry_id', $data)) // only perform if this is a new entry (not an update)
        
{
            $new_url_title
= $entry_id.'-'.$data['url_title'];

            
$_POST['url_title'] = $new_url_title; // in case any other extensions are making use of the $_POST data

            // save to the database

            
global $DB, $FNS;

            
$update_data = array('url_title' => $new_url_title);

            
$sql = $DB->update_string('exp_weblog_titles', $update_data, "entry_id = '{$entry_id}'");

            
$DB->query($sql);

            
$FNS->clear_caching('all');
        
}

    }
    
    
function activate_extension()
    
{
        
global $DB;
        
        
$DB->query($DB->insert_string('exp_extensions',
                array(
                
'extension_id'    => '',
                
'class'            => 'entry_id_in_url_title',
                
'method'        => 'insert_entry_id',
                
'hook'            => 'submit_new_entry_end',
                
'settings'        => '',
                
'priority'        => 10,
                
'version'        => $this->version,
                
'enabled'        => 'y'
                
)
            )
        );
        
    
}
        
    
function disable_extension()
    
{
        
global $DB;
        
        
$DB->query("DELETE FROM exp_extensions WHERE class = 'entry_id_in_url_title'");
        
    
}
    
}
?>

Profile
 
 
Posted: 12 November 2008 08:17 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
RankRank
Total Posts:  107
Joined  11-17-2005

I’ve edited the code above to include the clear_caching function at the end. It appears that submit_new_entry_end is called after EE clears the caches upon submitting a new entry. If you use url_titles to link to entries, you risk 404s without this line, since the url_title will have been changed after the caches have been refreshed and pages rebuilt.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64907 Total Logged-in Users: 39
Total Topics: 81852 Total Anonymous Users: 32
Total Replies: 440056 Total Guests: 235
Total Posts: 521908    
Members ( View Memberlist )