Support Forum

Duplicate code in class

LH Lee H
Lee H
Member

In sp-topic-view-class.php

Within sp_topicview_query(), lines 270-296

The “Is this post to be edited” code is repeated. The second instance goes a bit further and adds edit history.

                    # Is this post to be edited? 
                    if ($sfvars['displaymode'] == 'edit' && $sfvars['postedit'] == $r->post_id) { 
                        $t[$tidx]->editmode                        = 1; 
                        $t[$tidx]->editpost_id                    = $r->post_id; 
                        $t[$tidx]->editpost_content                = sp_filter_content_edit($r->post_content); 
                        $t[$tidx]->posts[$pidx]->editmode        = 1; 
                    } 
 
                    # Add edit history 
                    if ($r->post_edit) { 
                        $edits = unserialize($r->post_edit); 
                        $eidx = 0; 
                        foreach ($edits as $e) { 
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->by = $e['by']; 
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->at = $e['at']; 
                            $eidx++; 
                        } 
                    } 
 
                    # Is this post to be edited? 
                    if ($sfvars['displaymode'] == 'edit' && $sfvars['postedit'] == $r->post_id) { 
                        $t[$tidx]->editmode                        = 1; 
                        $t[$tidx]->editpost_id                    = $r->post_id; 
                        $t[$tidx]->editpost_content                = sp_filter_content_edit($r->post_content); 
                        $t[$tidx]->editpost_history                = $r->post_edit; 
                        $t[$tidx]->posts[$pidx]->editmode        = 1; 
                    }

5 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

Gosh – thanks Lee. Looks like a copy and paste job that wasn’t cleaned up in the rush.
Good find and I will cleanse it immediately.

LH Lee H
Lee H
Member

@YS

I just came from snooping the svn and noticed you commented out the second instance. I was thinking it was the first instance that should be commented out as the second one, and the code right above handle edit history?

YS Yellow Swordfish
Yellow Swordfish
Member

The database column is called ‘post_edits’ and in the first cut of the code (the bit I commented out) I was passing that column. But is is a serialized array and I wanted to explode it to a normal array and format it along the way which is what the bit in the middle does. I then pass it as ‘edits’ instead of ‘post_edits’. I could pass both but it seems redundant.

Reckon I copied the block – pasted it above – removed the post_edits line and then wrote the new piece below. Just forgot to remove the old block.

But… that is why the code is commented out and not removed. Just in case I am wrong… 🙂

LH Lee H
Lee H
Member

Thanks for the explanation! I only questioned as I’m trying to learn and understand. I’ve learned a lot from you guys and appreciate the patience and the time you’ve given me 🙂