News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1233619646:v:use_geshi-1:v:type-php

Started by SleePy, Feb 03, 2009, 12:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

// Try to see if we can't find the previous version.
function upgrade_previous_version($version)
{
   // A Release Canidate?
   if (strpos($version, 'rc') !== false)
   {
      // It is something like rc2-1 (rc2.1)
      if ((substr($version, -2, 1) == '-' || substr($version, -2, 1) == '.') && substr($version, -1, 1) == 1)
         return substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         return substr($version, 0, -1) . (substr($version, -1, 1) - 1);
   }
   // Maybe a Beta?
   elseif (strpos($version, 'b') !== false || strpos($version, 'beta') !== false)
   {
      // A weird case.
      if (substr($version, -5, 4) == '-fix')
         return substr($version, 0, -5);
      // It is something like b1.1 (b1-1)
      if (substr($version, -2, 1) == '-' || substr($version, -2, 1) == '.')
         return substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         return substr($version, 0, -1) . (substr($version, -1, 1) - 1);
   }
   // Hopefully just a normal upgrade.
   else
      return substr($version, 0, -1) . (substr($version, -1, 1) - 1);
}
No siggy! :D

SleePy

// Try to see if we can't find the previous version.
function upgrade_previous_version($version)
{
   // We love periods.
   $version = str_replace('-', '.', $version);

   // A Release Canidate?
   if (strpos($version, 'rc') !== false)
   {
      // A weird case?
      if (substr($version, -5) == 'rc2.2')
         $string = substr($version, 0, -2);
      // It is something like rc2-1 (rc2.1)
      elseif (substr($version, -2, 1) == '.' && substr($version, -1, 1) == 1)
         $string = substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         $string = substr($version, 0, -1) . (substr($version, -1, 1) - 1);

      return strtr($string, array(
         '.rc' => ' RC'
      ));
   }
   // Maybe a Beta?
   elseif (strpos($version, 'b') !== false || strpos($version, 'beta') !== false)
   {
      // A weird case.
      if (substr($version, -5, 4) == '.fix')
         $string = substr($version, 0, -5);
      // It is something like b1.1 (b1-1)
      elseif (substr($version, -2, 1) == '.')
         $string = substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         $string = substr($version, 0, -1) . (substr($version, -1, 1) - 1);

      return strtr($string, array(
         '.b' => ' Beta '
      ));
   }
   // Hopefully just a normal upgrade.
   elseif (substr($version, -2, 2) > 9)
      return substr($version, 0, -2) . (substr($version, -2, 2) - 1);
   else
      return substr($version, 0, -1) . (substr($version, -1, 1) - 1);
}
No siggy! :D

SleePy

// Try to see if we can't find the previous version.
function upgrade_previous_version($version)
{
   // We love periods.
   $version = str_replace('-', '.', $version);

   // A Release Candidate?
   if (strpos($version, 'rc') !== false)
   {
      // A weird case?
      if (substr($version, -5) == 'rc2.2')
         $string = substr($version, 0, -2);
      // It is something like rc2-1 (rc2.1)
      elseif (substr($version, -2, 1) == '.' && substr($version, -1, 1) == 1)
         $string = substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         $string = substr($version, 0, -1) . (substr($version, -1, 1) - 1);

      return strtr($string, array(
         '.rc' => ' RC'
      ));
   }
   // Maybe a Beta?
   elseif (strpos($version, 'b') !== false || strpos($version, 'beta') !== false)
   {
      // A weird case.
      if (substr($version, -5, 4) == '.fix')
         $string = substr($version, 0, -5);
      // It is something like b1.1 (b1-1)
      elseif (substr($version, -2, 1) == '.')
         $string = substr($version, 0, -2);
      // Alright, maybe just a normal version?
      elseif (substr($version, -1, 1) > 1)
         $string = substr($version, 0, -1) . (substr($version, -1, 1) - 1);

      return strtr($string, array(
         '.b' => ' Beta '
      ));
   }
   // Hopefully just a normal upgrade.
   elseif (substr($version, -2, 2) > 9)
      return substr($version, 0, -2) . (substr($version, -2, 2) - 1);
   else
      return substr($version, 0, -1) . (substr($version, -1, 1) - 1);
}
No siggy! :D