Safe Mods

Discussion forum for MOD Writers regarding MOD Development.
User avatar
michaelo
Registered User
Posts: 1292
Joined: Thu Jun 13, 2002 3:49 am
Location: Dublin, Ireland
Name: Michael O'Toole
Contact:

Safe Mods

Post by michaelo » Mon Jun 04, 2007 6:21 am

Not sure if this is the correct place to post this but it can be moved...

I am hoping to convince mod designers to produce Safe mods by suggesting methods and rules to be followed. I would hope we could start some discussion in this regard...

What is a Safe mod?
Any mod that can be installed without adverse effect to the phpBB3 should the mod become obsolete or contain bugs...
Any mod that can be enabled and disabled using some method such as ACP without effecting the phpBB core...

All mods should supply a method (hopefully the same method for all) to disable and enable mods.
All mods should supply an install, uninstall and update function to process the necessary sql...
All mods should supply; Author, Version, Support Link, Mod Image, Mod Abstract etc...

Advantages:
Goes without saying but! Consider this; Your mod is found to have a bug or perhaps a security issue...
You have to fix it quick or take the site down... If you simply disable it, the site could continue as normal and you would have the necessary time to make repairs...

What's involved?
In php code: Simply use the if switch, for example... if(MYMOD) { process my code } else { process core code }
In HTML code: Again use the switch <!-- IF MYMOD --> do this <!-- ENDIF --> or <!-- IF MYMOD --> do this <!-- ELSE --> do that <!-- ENDIF -->
If a mod contains a long or complex code segment... Use... $result = process_my_mod_function(x,y,z);

Never use: Replace with, or Replace into, unless the edit can be processed by the core code for example...
HTML example...

Code: Select all

This...
<p><a href="{U_ADM_INDEX}">{L_ADMIN_INDEX}</a> &bull; <a href="{U_INDEX}">{L_FORUM_INDEX}</a></p>
Can safely be replaced with...
<p><a href="{U_ADM_INDEX}">{L_ADMIN_INDEX}</a> &bull; <a href="{U_INDEX}">{L_FORUM_INDEX}</a><!-- IF STARGATE -->&bull; <a href="{U_PORTAL}">{L_PORTAL}</a><!-- ENDIF --></p>   
 
I don't have a php example yet, as I have never found it necessary to use replace with or replace into in any php code but no doubt it will be necessary someday. If it is the rules above will allow safe modding...

Following these rules would allow all mods to be incorporated into a basis plug-in manager for phpBB3...

This post also serves as a precursor to the Stargate Portal (aka Kiss Portal / Integramod Portal) which was build with all the above rules being enforced... the proof being, you can disable the portal and your site will perform perfectly as a default phpBB3 RC1 installation.
The Stargate Portal will be posted later in the appropriate forum as Beta 0.0.7... Mike
Last edited by michaelo on Mon Jun 04, 2007 8:47 am, edited 2 times in total.
Contributions: Mods & Styles Extensions
(site is down): Kiss Portal Engine

User avatar
smithy_dll
Former Team Member
Posts: 7630
Joined: Tue Jan 08, 2002 6:27 am
Location: Australia
Name: Lachlan Smith
Contact:

Re: [Beta] Safe Mods

Post by smithy_dll » Mon Jun 04, 2007 8:13 am

Moved to MOD Writers Discussion,

You can axe the topic prefix.

User avatar
michaelo
Registered User
Posts: 1292
Joined: Thu Jun 13, 2002 3:49 am
Location: Dublin, Ireland
Name: Michael O'Toole
Contact:

Re: [Beta] Safe Mods

Post by michaelo » Mon Jun 04, 2007 8:42 am

Sorry about that... just notice that forum now...
Contributions: Mods & Styles Extensions
(site is down): Kiss Portal Engine

User avatar
MHobbit
Former Team Member
Posts: 4761
Joined: Thu Mar 18, 2004 5:32 pm
Location: There and Back Again

Re: Safe Mods

Post by MHobbit » Mon Jun 04, 2007 10:33 pm

"Safe" MODs are ones that follow all of the phpBB coding guidelines and pass the MOD Team validation. :-P
Former phpBB MOD Team member
No private support is offered.
"There’s too many things to get done, and I’m running out of days..."

User avatar
michaelo
Registered User
Posts: 1292
Joined: Thu Jun 13, 2002 3:49 am
Location: Dublin, Ireland
Name: Michael O'Toole
Contact:

Re: Safe Mods

Post by michaelo » Tue Jun 05, 2007 2:49 am

The reality is, the majority of mods for phpBB2, and those being discussed for phpBB3 do not conform to what one would refer to as Safe... In the past five years I have installed hundreds of validated and non validated modifications... and while many would be considered Safe, the majority, if memory serves, would not...

One would imaging the proposed MODX only processed what we refer to as Safe mods? wrong... It will process any code you give it... It allows the replacement of core code and the replace into... both of which deform core code... It would be simple enough to add two rules to guide the mod developer as to what form the replacement code should take... It makes no mention of conditional processing, perhaps the most powerful tool for Safe mods and without question the single biggest omission...

Mods installed with this tool without the additional rules and guidelines (as proposed previously), will continue to allow defacing of the core... I'm not knocking MODX, I am simple saying without structured guidelines the tool its self is not enough...

Conditional processing:
Conditional processing will allow mods to be disabled without affecting the phpBB core code. If a mod cannot be disabled as in for example, a mod containing a security problem, it is not Safe... (poorly worded but you get the point). In addition conditional processing of both php and html code makes for easier to read and leads to more reliable code...

This discussion is valid for both phpBB2 and phpBB3, hence the modx reference...
Contributions: Mods & Styles Extensions
(site is down): Kiss Portal Engine

ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Safe Mods

Post by ToonArmy » Tue Jun 05, 2007 3:32 am

Making every mod put a conditional statement around its code is very inefficient and will also be a lot messier.
Chris SmithGitHub

User avatar
michaelo
Registered User
Posts: 1292
Joined: Thu Jun 13, 2002 3:49 am
Location: Dublin, Ireland
Name: Michael O'Toole
Contact:

Re: Safe Mods

Post by michaelo » Tue Jun 05, 2007 5:20 am

The advantages far out way any disadvantage, and only add a few lines of code. The majority of mods only edit one or two files... so adding at most two lines per edit... Also consider the number of lines some mods add in as comments... If the mod uses conditional processing it will have a some type of reference tag, MY_MOD_NAME for example... and relocated the numerous comments in MY_MOD_NAME.ref the saving in time and edits would be far greater than required for the conditional statements... Adding if( MY_MOD) { do this...} else {do core} isn't asking too much...
Contributions: Mods & Styles Extensions
(site is down): Kiss Portal Engine

ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Safe Mods

Post by ToonArmy » Tue Jun 05, 2007 12:47 pm

Let me demonstrate what a bad idea this is, lets assume two different mods add something to the middle of an array. I don't care for the motives etc. they just do.

Under your proposal you would produce something like this with one mod.

Code: Select all

if (MOD_ONE)
{
$xyz = array('1', '2', 'mod1', '3');
}
else
{
$xyz = array('1', '2', '3');
}
Lame example I know but it serves to illustrate my point.

So Mod number two comes along, with a similar edit.

Code: Select all

if (MOD_TWO)
{
$xyz = array('1', 'mod2', '2', '3');
}
else
{
$xyz = array('1', '2', '3');
}
Now if we install both these mods what are we do do.

Code: Select all

if (MOD_ONE && MOD_TWO)
{
$xyz = array('1', 'mod2', '2', 'mod1', '3');
}
else if (MOD_ONE)
{
$xyz = array('1', '2', 'mod1', '3');
}
else if (MOD_TWO)
{
$xyz = array('1', 'mod2', '2', '3');
}
else
{
$xyz = array('1', '2', '3');
}
What a mess!

Now what happens if phpBB come along and go 'Oh ****' we forgot an element off the end of that array. The user has to apply the change to every single bit of code, by hand because patch files won't work.
Chris SmithGitHub

CorniI
Registered User
Posts: 38
Joined: Tue Apr 03, 2007 1:45 pm
Location: Germany

Re: Safe Mods

Post by CorniI » Tue Jun 05, 2007 1:05 pm

And I see a 2nd Problem: All the code (Mod code and phpBB Code) got parsed, so parsing need longer, bigger opcode, more memory needed,.... A solution (I would like it) if we would have a php-Preprocessor (Yeah, php hypertext preprocessor preprocessor^^) which determine on localhost if the Mod is enabled, and then get you the preprocessed source. To disable the Mod, just preprocess with disabled Mod and upload the changed Files. cool, eh? Someone here who likes to code it :P
CorniI

barrycarlyon
Registered User
Posts: 851
Joined: Wed Mar 29, 2006 3:46 pm
Location: Manchester
Name: Barry Carlyon
Contact:

Re: Safe Mods

Post by barrycarlyon » Tue Jun 05, 2007 1:10 pm

silly idea, is that not what backups are?

And if you diable a mod you installed a while ago, might it not affect newer installed mods?

its the same issue of modding a modded board, as some mods search for text/code which has now been modded and cant find it.

Disable a mod = killing another mod = breaking your board
Barry Carlyon

CorniI
Registered User
Posts: 38
Joined: Tue Apr 03, 2007 1:45 pm
Location: Germany

Re: Safe Mods

Post by CorniI » Tue Jun 05, 2007 3:03 pm

barrycarlyon wrote: Disable a mod = killing another mod = breaking your board
The same is if you restore a backup and yoou installed a newer Mod which has changes in the restored Files...

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Safe Mods

Post by christhatsme » Tue Jun 05, 2007 3:43 pm

Also if the MOD causes a parse error, then disabling the MOD with an if statement will do nothing.... it will still be parsed and throw an error.

Also one MOD could easily break another, which has already been said, got beaten to the punch!

Along with all the usless extra code bogging down load times ;)
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

User avatar
michaelo
Registered User
Posts: 1292
Joined: Thu Jun 13, 2002 3:49 am
Location: Dublin, Ireland
Name: Michael O'Toole
Contact:

Re: Safe Mods

Post by michaelo » Wed Jun 06, 2007 12:06 pm

christhatsme...

"Also if the MOD causes a parse error"... you fix it! Why would you install a mod with errors in the first place...
"then disabling the MOD with an if statement will do nothing" neither will not disabling it... This argument does not hold water...

Each mod does a specific job, the chances of a mod modifying another mod are small but should this happen you would simply disable both mods...
It might be prudent to disallow mod that modified mods... of simply use if(MODX && MODY)... here each mod is dependant on the other, i.e. disabling one will disable the other...

ToonArmy...
In the case of arrays... you would simply append or insert an element into an existing array if required...
you would never touch existing code so update would never be effected...

Example #1 code...

Code: Select all

function insert_element($array = '', $position = '' , $elements= '')
{
    if ($position == '' || $array == '' || $elements == '' || $position < 1 || $position > count ($array)+1)
    {
        echo $this->error_l."insert".$this->error_r;
    }
    else
    {
        $left = array_slice ($array, 0, $position-1);
        $right = array_slice ($array, $position-1);
        $insert = explode ('\,', $elements);
        $array = array_merge ($left, $insert, $right);
        unset($left, $right, $insert);
    }

unset ($position, $elements);
return $array;
}     
Example #2 code...

Code: Select all

function array_insert(&$array, $insert, $position = -1) 
{
     $position = ($position == -1) ? (count($array)) : $position ;
     if($position != (count($array))) 
     {
          $ta = $array;
          for($i = $position; $i < (count($array)); $i++) 
      {
               if(!isset($array[$i])) 
           {
                    die(print_r($array, 1)."\r\nInvalid array: All keys must be numerical and in sequence.");
               }
               $tmp[$i+1] = $array[$i];
               unset($ta[$i]);
          }
          $ta[$position] = $insert;
          $array = $ta + $tmp;
          //print_r($array);
     } else {
          $array[$position] = $insert;         
     }
         
     ksort($array);
     return true;
}
  
Giving:

$xyz = array('1', '2', '3'); // standard phpBB core code never touched!

if(MOD1)
$xyz = insert_element($xyz, 2 , MOD_ELEMENT_FOR_1);

if(MOD2)
$xyz = insert_element($xyz, 1 , MOD_ELEMENT_FOR_2);
Contributions: Mods & Styles Extensions
(site is down): Kiss Portal Engine

ToonArmy
Former Team Member
Posts: 4608
Joined: Sat Mar 06, 2004 5:29 pm
Location: Worcestershire, UK
Name: Chris Smith
Contact:

Re: Safe Mods

Post by ToonArmy » Wed Jun 06, 2007 12:42 pm

I was only giving an example, there are other ideas I can think of which you would not be able to do what you have suggested. Me next point would be that this is highly inefficient along with all the conditional switching.
Chris SmithGitHub

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: Safe Mods

Post by christhatsme » Wed Jun 06, 2007 1:13 pm

michaelo wrote:christhatsme...

"Also if the MOD causes a parse error"... you fix it! Why would you install a mod with errors in the first place...
"then disabling the MOD with an if statement will do nothing" neither will not disabling it... This argument does not hold water...

Each mod does a specific job, the chances of a mod modifying another mod are small but should this happen you would simply disable both mods...
It might be prudent to disallow mod that modified mods... of simply use if(MODX && MODY)... here each mod is dependant on the other, i.e. disabling one will disable the other...

ToonArmy...
In the case of arrays... you would simply append or insert an element into an existing array if required...
you would never touch existing code so update would never be effected...

Example #1 code...

Code: Select all

function insert_element($array = '', $position = '' , $elements= '')
{
    if ($position == '' || $array == '' || $elements == '' || $position < 1 || $position > count ($array)+1)
    {
        echo $this->error_l."insert".$this->error_r;
    }
    else
    {
        $left = array_slice ($array, 0, $position-1);
        $right = array_slice ($array, $position-1);
        $insert = explode ('\,', $elements);
        $array = array_merge ($left, $insert, $right);
        unset($left, $right, $insert);
    }

unset ($position, $elements);
return $array;
}     
Example #2 code...

Code: Select all

function array_insert(&$array, $insert, $position = -1) 
{
     $position = ($position == -1) ? (count($array)) : $position ;
     if($position != (count($array))) 
     {
          $ta = $array;
          for($i = $position; $i < (count($array)); $i++) 
      {
               if(!isset($array[$i])) 
           {
                    die(print_r($array, 1)."\r\nInvalid array: All keys must be numerical and in sequence.");
               }
               $tmp[$i+1] = $array[$i];
               unset($ta[$i]);
          }
          $ta[$position] = $insert;
          $array = $ta + $tmp;
          //print_r($array);
     } else {
          $array[$position] = $insert;         
     }
         
     ksort($array);
     return true;
}
  
Giving:

$xyz = array('1', '2', '3'); // standard phpBB core code never touched!

if(MOD1)
$xyz = insert_element($xyz, 2 , MOD_ELEMENT_FOR_1);

if(MOD2)
$xyz = insert_element($xyz, 1 , MOD_ELEMENT_FOR_2);
It is a counter arguement, you say you can disable it if there is an error..

As for the arrays it makes it too complicated, my opinion is that this would not be taken up by many writers as it is a faf, and isn't really that useful..

If you want to unisntall a MOD, you just follow the instructions backward
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

Locked

Return to “[3.0.x] MOD Writers Discussion”