Antivirus
03-26-2009, 12:20 AM
I have a plugin I am using in two different locations, however it essentially does the exact same thing for each location with the exception that it pulls data from a different array to set the DM.
global $sc_typeset;
if ($sc_typeset == 'sc_typetask' OR $sc_typeset == 'sc_typeevent')
{
if (THIS_SCRIPT == 'newthread')
{
$dataman->set('sc_typeset', $post['sc_typeset']);
$dataman->setr('dateline_from', $post['dateline_from']);
$dataman->setr('dateline_to', $post['dateline_to']);
$dataman->setr('sc_description', $post['sc_description']);
$dataman->setr('sc_location', $post['sc_location']);
}
if (THIS_SCRIPT == 'editpost')
{
$dataman->set('sc_typeset', $edit['sc_typeset']);
$dataman->setr('dateline_from', $edit['dateline_from']);
$dataman->setr('dateline_to', $edit['dateline_to']);
$dataman->setr('sc_description', $edit['sc_description']);
$dataman->setr('sc_location', $edit['sc_location']);
}
}
As you can see, it's somewhat redundant. I want to include this same plugin code in both hook locations ('newpost_process' & 'editpost_update_process') and simply use a conditional to determine which array to pass to the DM. I was thinking on something like this:
if (THIS_SCRIPT == 'newthread')
{
// use the $newpost array
}
else if (THIS_SCRIPT == 'editpost')
{
// use the $edit array
}
So basically, what I am asking is if anyone can think of a shorter way to write this than I am currently using?
Thanks!
global $sc_typeset;
if ($sc_typeset == 'sc_typetask' OR $sc_typeset == 'sc_typeevent')
{
if (THIS_SCRIPT == 'newthread')
{
$dataman->set('sc_typeset', $post['sc_typeset']);
$dataman->setr('dateline_from', $post['dateline_from']);
$dataman->setr('dateline_to', $post['dateline_to']);
$dataman->setr('sc_description', $post['sc_description']);
$dataman->setr('sc_location', $post['sc_location']);
}
if (THIS_SCRIPT == 'editpost')
{
$dataman->set('sc_typeset', $edit['sc_typeset']);
$dataman->setr('dateline_from', $edit['dateline_from']);
$dataman->setr('dateline_to', $edit['dateline_to']);
$dataman->setr('sc_description', $edit['sc_description']);
$dataman->setr('sc_location', $edit['sc_location']);
}
}
As you can see, it's somewhat redundant. I want to include this same plugin code in both hook locations ('newpost_process' & 'editpost_update_process') and simply use a conditional to determine which array to pass to the DM. I was thinking on something like this:
if (THIS_SCRIPT == 'newthread')
{
// use the $newpost array
}
else if (THIS_SCRIPT == 'editpost')
{
// use the $edit array
}
So basically, what I am asking is if anyone can think of a shorter way to write this than I am currently using?
Thanks!