Project Website | Online Demo | Forum |
It is currently Fri Nov 24, 2017 8:25 pm

All times are UTC + 1 hour [ DST ]





Post new topic Reply to topic  [ 10 posts ] 
  Print view Previous topic | Next topic 
Author Message
 Post subject: PHP 4 rewrite.
PostPosted: Wed Aug 30, 2006 8:27 pm 
I was wondering if you could give me a list of the files written in PHP 5. I would like to configure this to work with PHP 4. Thanks.


Top
  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 12:16 am 
Offline
Site Admin
User avatar

Joined: Tue Mar 07, 2006 7:34 pm
Posts: 331
Thank you for your offer. There seems to be demand for a PHP 4 version.

I have no overview where exactly we used PHP 5 features. We decided to use PHP 5 in the first place, and spent no thoughts in PHP 4. Some issues I can think of:
  • We used class constructors of PHP 5 type. These should be convertible.
  • At some places we used class inheritance. If I remember right, there have also been some changes to this topic from PHP 4 to 5, but I think they are convertible, too.
  • I have no code in mind where we used brand-new functions (except the hack in Date.php, and this should be backwards-compatible)
The two most challenging areas are
  • Calling conventions (call by value as standard in PHP 4 vs. call by reference in PHP 5). I could imagine these are hard to spot and debug. The workaround would be to add some &'s to the function declaration
  • We have quite some use of exceptions in our code. I cannot think of any generic and useful replacement of these in PHP 4


Another issue would be how to synchronize the two development paths (for future versions).

_________________
BADGER finance lead backend developer and site admin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 12:53 am 
I'll see what I can do about possible work arounds. The script is easy to understand, not too complex, so I don't think there should be a problem. I've been working on a script that will allow synch between PHP 4 and PHP 5 releases. I doubt very seriously that PHP 4 will remain forever on servers that are using it now, as it is starting to get quite old. I use both PHP 4 and PHP 5 compatible Adobe installations on my home server, so I am sure I can orchestrate this.

While it may take some time, it will be well worth it for those who need this software but do not have the right technology.


Top
  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 4:40 am 
This look right to you?


Code:
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
//
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Baba Buehler, Pierre-Alain Joye              |
// +----------------------------------------------------------------------+
// | This source file is subject to the New BSD license, That is bundled  |
// | with this package in the file LICENSE, and is available through      |
// | the world-wide-web at                                                |
// | http://www.opensource.org/licenses/bsd-license.php                   |
// | If you did not receive a copy of the new BSDlicense and are unable   |
// | to obtain it through the world-wide-web, please send a note to       |
// | pear-dev@lists.php.net so we can mail you a copy immediately.        |
// +----------------------------------------------------------------------+
// | Author: Baba Buehler <baba@babaz.com>                                |
// |         Pierre-Alain Joye <pajoye@php.net>                           |
// +----------------------------------------------------------------------+

/**
* Generic date handling class for PEAR
*
* Generic date handling class for PEAR.  Attempts to be time zone aware
* through the Date::TimeZone class.  Supports several operations from
* Date::Calc on Date objects.
*
* @category   Date and Time
* @package    Date
* @author     Baba Buehler <baba@babaz.com>
* @author     Pierre-Alain Joye <pajoye@php.net>
* @copyright  1997-2005 The PHP Group
* @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
* @version    CVS: $Id: Date.php,v 1.35 2005/11/15 00:16:38 pajoye Exp $
* @link       http://pear.php.net/package/Date
*/

/**@#+
* Include supporting classes
*/
require_once 'Date/TimeZone.php';
require_once 'Date/Calc.php';
require_once 'Date/Span.php';
/**@#-*/

/**@#+
* Output formats.  Pass this to getDate().
*/
/**
* "YYYY-MM-DD"
*/
define('DATE_FORMAT_ISO_NOTIME', 6);
/**
* "YYYY-MM-DD HH:MM:SS"
*/
define('DATE_FORMAT_ISO', 1);
/**
* "YYYYMMSSTHHMMSS(Z|(+/-)HHMM)?"
*/
define('DATE_FORMAT_ISO_BASIC', 2);
/**
* "YYYY-MM-SSTHH:MM:SS(Z|(+/-)HH:MM)?"
*/
define('DATE_FORMAT_ISO_EXTENDED', 3);
/**
* "YYYY-MM-SSTHH:MM:SS(.S*)?(Z|(+/-)HH:MM)?"
*/
define('DATE_FORMAT_ISO_EXTENDED_MICROTIME', 6);
/**
* "YYYYMMDDHHMMSS"
*/
define('DATE_FORMAT_TIMESTAMP', 4);
/**
* long int, seconds since the unix epoch
*/
define('DATE_FORMAT_UNIXTIME', 5);
/**@#-*/

/**
* Generic date handling class for PEAR
*
* Generic date handling class for PEAR.  Attempts to be time zone aware
* through the Date::TimeZone class.  Supports several operations from
* Date::Calc on Date objects.
*
* @author     Baba Buehler <baba@babaz.com>
* @author     Pierre-Alain Joye <pajoye@php.net>
* @copyright  1997-2005 The PHP Group
* @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
* @version    Release: 1.4.6
* @link       http://pear.php.net/package/Date
*/
class Date
{
    /**
     * the year
     * @var int
     */
    var $year;
    /**
     * the month
     * @var int
     */
    var $month;
    /**
     * the day
     * @var int
     */
    var $day;
    /**
     * the hour
     * @var int
     */
    var $hour;
    /**
     * the minute
     * @var int
     */
    var $minute;
    /**
     * the second
     * @var int
     */
    var $second;
    /**
     * the parts of a second
     * @var float
     */
    var $partsecond;

    /**
     * timezone for this date
     * @var object Date_TimeZone
     */
    var $tz;

    /**
     * define the default weekday abbreviation length
     * used by ::format()
     * @var int
     */
    var $getWeekdayAbbrnameLength = 3;


    /**
     * Constructor
     *
     * Creates a new Date Object initialized to the current date/time in the
     * system-default timezone by default.  A date optionally
     * passed in may be in the ISO 8601, TIMESTAMP or UNIXTIME format,
     * or another Date object.  If no date is passed, the current date/time
     * is used.
     *
     * @access public
     * @see setDate()
     * @param mixed $date optional - date/time to initialize
     * @param boolean $formatted true if $date is formatted according to UserSettings, false otherwise.
     * @return object Date the new Date object
     */
    function Date($date = null, $formatted = false)
    {
        global $us;

        $this->tz = Date_TimeZone::getDefault();
        if (is_null($date)) {
            $this->setDate(date("Y-m-d H:i:s"));
        } elseif (is_a($date, 'Date')) {
            $this->copy($date);
        } else {
            if ($formatted) {
                $formatString = $us->getProperty('badgerDateFormat');

                $dayPos = strpos($formatString, 'dd');
                $monthPos = strpos($formatString, 'mm');
                $yearPos = strpos($formatString, 'yyyy');

                $day = substr($date, $dayPos, 2);
                $month = substr($date, $monthPos, 2);
                $year = substr($date, $yearPos, 4);

                $date = "$year-$month-$day";
            }


            $this->setDate($date);
        }
    }

    /**
     * Set the fields of a Date object based on the input date and format
     *
     * Set the fields of a Date object based on the input date and format,
     * which is specified by the DATE_FORMAT_* constants.
     *
     * @access public
     * @param string $date input date
     * @param int $format Optional format constant (DATE_FORMAT_*) of the input date.
     *                    This parameter isn't really needed anymore, but you could
     *                    use it to force DATE_FORMAT_UNIXTIME.
     */
    function setDate($date, $format = DATE_FORMAT_ISO)
    {

        if (
            preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i', $date, $regs)
            && $format != DATE_FORMAT_UNIXTIME) {
            // DATE_FORMAT_ISO, ISO_BASIC, ISO_EXTENDED, and TIMESTAMP
            // These formats are extremely close to each other.  This regex
            // is very loose and accepts almost any butchered format you could
            // throw at it.  e.g. 2003-10-07 19:45:15 and 2003-10071945:15
            // are the same thing in the eyes of this regex, even though the
            // latter is not a valid ISO 8601 date.
            $this->year       = $regs[1];
            $this->month      = $regs[2];
            $this->day        = $regs[3];
            $this->hour       = isset($regs[5])?$regs[5]:0;
            $this->minute     = isset($regs[6])?$regs[6]:0;
            $this->second     = isset($regs[7])?$regs[7]:0;
            $this->partsecond = isset($regs[8])?(float)$regs[8]:(float)0;

            // if an offset is defined, convert time to UTC
            // Date currently can't set a timezone only by offset,
            // so it has to store it as UTC
            if (isset($regs[9])) {
                $this->toUTCbyOffset($regs[9]);
            }
        } elseif (is_numeric($date)) {
            // UNIXTIME
            $this->setDate(date("Y-m-d H:i:s", $date));
        } else {
            // unknown format
            $this->year       = 0;
            $this->month      = 1;
            $this->day        = 1;
            $this->hour       = 0;
            $this->minute     = 0;
            $this->second     = 0;
            $this->partsecond = (float)0;
        }
    }

    /**
     * Get a string (or other) representation of this date
     *
     * Get a string (or other) representation of this date in the
     * format specified by the DATE_FORMAT_* constants.
     *
     * @access public
     * @param int $format format constant (DATE_FORMAT_*) of the output date
     * @return string the date in the requested format
     */
    function getDate($format = DATE_FORMAT_ISO_NOTIME)
    {
        switch ($format) {
        case DATE_FORMAT_ISO_NOTIME:
            return $this->format("%Y-%m-%d");
            break;
        case DATE_FORMAT_ISO:
            return $this->format("%Y-%m-%d %T");
            break;
        case DATE_FORMAT_ISO_BASIC:
            $format = "%Y%m%dT%H%M%S";
            if ($this->tz->getID() == 'UTC') {
                $format .= "Z";
            }
            return $this->format($format);
            break;
        case DATE_FORMAT_ISO_EXTENDED:
            $format = "%Y-%m-%dT%H:%M:%S";
            if ($this->tz->getID() == 'UTC') {
                $format .= "Z";
            }
            return $this->format($format);
            break;
        case DATE_FORMAT_ISO_EXTENDED_MICROTIME:
            $format = "%Y-%m-%dT%H:%M:%s";
            if ($this->tz->getID() == 'UTC') {
                $format .= "Z";
            }
            return $this->format($format);
            break;
        case DATE_FORMAT_TIMESTAMP:
            return $this->format("%Y%m%d%H%M%S");
            break;
        case DATE_FORMAT_UNIXTIME:
            return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
            break;
        }
    }

    /**
     * Copy values from another Date object
     *
     * Makes this Date a copy of another Date object.
     *
     * @access public
     * @param object Date $date Date to copy from
     */
    function copy($date)
    {
        $this->year = $date->year;
        $this->month = $date->month;
        $this->day = $date->day;
        $this->hour = $date->hour;
        $this->minute = $date->minute;
        $this->second = $date->second;
        $this->tz = $date->tz;
    }

    /**
     * Returns the date formatted according to UserSettings.
     *
     * @return string The date formatted according to UserSettings.
     */
    public function getFormatted() {
        global $us;

        $formatString = $us->getProperty('badgerDateFormat');

        $formatString = str_replace(
            array ('dd', 'mm', 'yyyy', 'yy'),
            array ('%d', '%m', '%Y', '%y'),
            $formatString
        );

        return $this->format($formatString);
    }

    /**
     *  Date pretty printing, similar to strftime()
     *
     *  Formats the date in the given format, much like
     *  strftime().  Most strftime() options are supported.<br><br>
     *
     *  formatting options:<br><br>
     *
     *  <code>%a  </code>  abbreviated weekday name (Sun, Mon, Tue) <br>
     *  <code>%A  </code>  full weekday name (Sunday, Monday, Tuesday) <br>
     *  <code>%b  </code>  abbreviated month name (Jan, Feb, Mar) <br>
     *  <code>%B  </code>  full month name (January, February, March) <br>
     *  <code>%C  </code>  century number (the year divided by 100 and truncated to an integer, range 00 to 99) <br>
     *  <code>%d  </code>  day of month (range 00 to 31) <br>
     *  <code>%D  </code>  same as "%m/%d/%y" <br>
     *  <code>%e  </code>  day of month, single digit (range 0 to 31) <br>
     *  <code>%E  </code>  number of days since unspecified epoch (integer, Date_Calc::dateToDays()) <br>
     *  <code>%H  </code>  hour as decimal number (00 to 23) <br>
     *  <code>%I  </code>  hour as decimal number on 12-hour clock (01 to 12) <br>
     *  <code>%j  </code>  day of year (range 001 to 366) <br>
     *  <code>%m  </code>  month as decimal number (range 01 to 12) <br>
     *  <code>%M  </code>  minute as a decimal number (00 to 59) <br>
     *  <code>%n  </code>  newline character (\n) <br>
     *  <code>%O  </code>  dst-corrected timezone offset expressed as "+/-HH:MM" <br>
     *  <code>%o  </code>  raw timezone offset expressed as "+/-HH:MM" <br>
     *  <code>%p  </code>  either 'am' or 'pm' depending on the time <br>
     *  <code>%P  </code>  either 'AM' or 'PM' depending on the time <br>
     *  <code>%r  </code>  time in am/pm notation, same as "%I:%M:%S %p" <br>
     *  <code>%R  </code>  time in 24-hour notation, same as "%H:%M" <br>
     *  <code>%s  </code>  seconds including the decimal representation smaller than one second <br>
     *  <code>%S  </code>  seconds as a decimal number (00 to 59) <br>
     *  <code>%t  </code>  tab character (\t) <br>
     *  <code>%T  </code>  current time, same as "%H:%M:%S" <br>
     *  <code>%w  </code>  weekday as decimal (0 = Sunday) <br>
     *  <code>%U  </code>  week number of current year, first sunday as first week <br>
     *  <code>%y  </code>  year as decimal (range 00 to 99) <br>
     *  <code>%Y  </code>  year as decimal including century (range 0000 to 9999) <br>
     *  <code>%%  </code>  literal '%' <br>
     * <br>
     *
     * @access public
     * @param string format the format string for returned date/time
     * @return string date/time in given format
     */
    function format($format)
    {
        $output = "";

        for($strpos = 0; $strpos < strlen($format); $strpos++) {
            $char = substr($format,$strpos,1);
            if ($char == "%") {
                $nextchar = substr($format,$strpos + 1,1);
                switch ($nextchar) {
                case "a":
                    $output .= Date_Calc::getWeekdayAbbrname($this->day,$this->month,$this->year, $this->getWeekdayAbbrnameLength);
                    break;
                case "A":
                    $output .= Date_Calc::getWeekdayFullname($this->day,$this->month,$this->year);
                    break;
                case "b":
                    $output .= Date_Calc::getMonthAbbrname($this->month);
                    break;
                case "B":
                    $output .= Date_Calc::getMonthFullname($this->month);
                    break;
                case "C":
                    $output .= sprintf("%02d",intval($this->year/100));
                    break;
                case "d":
                    $output .= sprintf("%02d",$this->day);
                    break;
                case "D":
                    $output .= sprintf("%02d/%02d/%02d",$this->month,$this->day,$this->year);
                    break;
                case "e":
                    $output .= $this->day * 1; // get rid of leading zero
                    break;
                case "E":
                    $output .= Date_Calc::dateToDays($this->day,$this->month,$this->year);
                    break;
                case "H":
                    $output .= sprintf("%02d", $this->hour);
                    break;
                case 'h':
                    $output .= sprintf("%d", $this->hour);
                    break;
                case "I":
                    $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                    $output .= sprintf("%02d", $hour==0 ? 12 : $hour);
                    break;
                case "i":
                    $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                    $output .= sprintf("%d", $hour==0 ? 12 : $hour);
                    break;
                case "j":
                    $output .= Date_Calc::julianDate($this->day,$this->month,$this->year);
                    break;
                case "m":
                    $output .= sprintf("%02d",$this->month);
                    break;
                case "M":
                    $output .= sprintf("%02d",$this->minute);
                    break;
                case "n":
                    $output .= "\n";
                    break;
                case "O":
                    $offms = $this->tz->getOffset($this);
                    $direction = $offms >= 0 ? "+" : "-";
                    $offmins = abs($offms) / 1000 / 60;
                    $hours = $offmins / 60;
                    $minutes = $offmins % 60;
                    $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
                    break;
                case "o":
                    $offms = $this->tz->getRawOffset($this);
                    $direction = $offms >= 0 ? "+" : "-";
                    $offmins = abs($offms) / 1000 / 60;
                    $hours = $offmins / 60;
                    $minutes = $offmins % 60;
                    $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
                    break;
                case "p":
                    $output .= $this->hour >= 12 ? "pm" : "am";
                    break;
                case "P":
                    $output .= $this->hour >= 12 ? "PM" : "AM";
                    break;
                case "r":
                    $hour = ($this->hour + 1) > 12 ? $this->hour - 12 : $this->hour;
                    $output .= sprintf("%02d:%02d:%02d %s", $hour==0 ?  12 : $hour, $this->minute, $this->second, $this->hour >= 12 ? "PM" : "AM");
                    break;
                case "R":
                    $output .= sprintf("%02d:%02d", $this->hour, $this->minute);
                    break;
                case "s":
                    $output .= str_replace(',', '.', sprintf("%09f", (float)((float)$this->second + $this->partsecond)));
                    break;
                case "S":
                    $output .= sprintf("%02d", $this->second);
                    break;
                case "t":
                    $output .= "\t";
                    break;
                case "T":
                    $output .= sprintf("%02d:%02d:%02d", $this->hour, $this->minute, $this->second);
                    break;
                case "w":
                    $output .= Date_Calc::dayOfWeek($this->day,$this->month,$this->year);
                    break;
                case "U":
                    $output .= Date_Calc::weekOfYear($this->day,$this->month,$this->year);
                    break;
                case "y":
                    $output .= substr($this->year,2,2);
                    break;
                case "Y":
                    $output .= $this->year;
                    break;
                case "Z":
                    $output .= $this->tz->inDaylightTime($this) ? $this->tz->getDSTShortName() : $this->tz->getShortName();
                    break;
                case "%":
                    $output .= "%";
                    break;
                default:
                    $output .= $char.$nextchar;
                }
                $strpos++;
            } else {
                $output .= $char;
            }
        }
        return $output;

    }

    /**
     * Get this date/time in Unix time() format
     *
     * Get a representation of this date in Unix time() format.  This may only be
     * valid for dates from 1970 to ~2038.
     *
     * @access public
     * @return int number of seconds since the unix epoch
     */
    function getTime()
    {
        return $this->getDate(DATE_FORMAT_UNIXTIME);
    }

    /**
     * Sets the time zone of this Date
     *
     * Sets the time zone of this date with the given
     * Date_TimeZone object.  Does not alter the date/time,
     * only assigns a new time zone.  For conversion, use
     * convertTZ().
     *
     * @access public
     * @param object Date_TimeZone $tz the Date_TimeZone object to use, if called
     * with a paramater that is not a Date_TimeZone object, will fall through to
     * setTZbyID().
     */
    function setTZ($tz)
    {
        if(is_a($tz, 'Date_Timezone')) {
            $this->tz = $tz;
        } else {
            $this->setTZbyID($tz);
        }
    }
    ?>


Top
  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 9:35 am 
Offline
Site Admin
User avatar

Joined: Tue Mar 07, 2006 7:34 pm
Posts: 331
This looks good. I think there is an easy way to test if it's correct: It just needs to work (-: Of course you can test this only when you have ported a serious part of the code.

One hint: Have a look at the files in modules/moduleTests. They are never used in BADGER, they are just relicts of our development phase, but may become handy for you.

Another question: Would you like to check in your development efforts in our code repository? We could give you access to our Subversion directory and create a branch.

_________________
BADGER finance lead backend developer and site admin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 5:26 pm 
That would be great, thanks. That way I can keep everyone updated pretty easily without having to post in the forum. Though I'll probably keep posting in here anyway just because. 8)


Top
  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 5:42 pm 
Offline
Site Admin
User avatar

Joined: Tue Mar 07, 2006 7:34 pm
Posts: 331
Great!

Please get an accout at http://developer.berlios.de/ (we used this Sourceforge clone because at the time we started, SF didn't offer Subversion) and send me your login name to enikao (a t) badger-finance.org. Do you know subversion?

_________________
BADGER finance lead backend developer and site admin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 7:06 pm 
All I know is that it is meant to replace CVS. Other than that, I have yet to explore its functionality. :shock:


Top
  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 8:57 pm 
Offline
Site Admin
User avatar

Joined: Tue Mar 07, 2006 7:34 pm
Posts: 331
I never used CVS, so I cannot really compare these two. Feel free to ask me about Subversion, I'll do the best I can when answering. Besides, there is plenty of information on the net.

I created a branch of BADGER at https://svn.berlios.de/svnroot/repos/ba ... nches/php4 (SVN actually works over HTTP, which is quite useful in secured networks). In theory, this URL together with your login (when I added you to the developer list) should be sufficient.

_________________
BADGER finance lead backend developer and site admin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 3:24 pm 
Offline
User avatar

Joined: Thu Mar 09, 2006 12:20 am
Posts: 423
Location: Frankfurt a. M., Germany
Just wondering, are there any news in this area ?

_________________
cheers,
Holger (project coordinator)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron




Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style supported by CodeMiles Team.