Location: PHPKode > scripts > Path wrapper > pat_path_wrapper.class.php
<?php
/**********************************************************************************
 *
 *  pat_path_wrapper.class.php
 *
 *  Class initially written for Php Admin Tools (http://pat.sourceforge.net)
 *
 *  license      : LGPL  (http://www.gnu.org)
 *  author       : Jean Philippe Giot <hide@address.com>
 *  version      : 1.0
 *  release date : 
 *  
 **********************************************************************************
 *
 *  MANUAL
 *
 *  this class is a small template class made for handling small strings like paths
 *  with parameters linked to a specific time (like in backup process)
 *  you can specify your own keywords
 *
 *
 *  syntax : wrap($path2wrap,$wrappers,$specifictime=0)
 *
 *  $path2wrap        string    string to wrap
 *  $wrappers         array     excange key with value
 *  $specifictime     int       time for date function. if none current is used 
 *
 *
 *  note that keywords with two letters begining by a d will be wrapped to their equivalent 
 *  by date function
 *
 *  for example (if let to default) {dY} will be replaced by 2003
 *
 *  you can customise delimiters to change way it work
 *
 *  for example if begin is '%' and end is ''
 *
 *  this will work : %dY will be replaced by 2003
 *
 ************************************************************************************/



class path_wrapper
{
   
    var $delimiter_begin = '{';
    
    var $delimiter_end   = '}';
    
    function wrap($path2wrap,$wrappers,$specifictime=0)
    {
        $this->create_date_wrapper_array($specifictime);
        
        // we merge the two arrays we need to wrap
        $_int_wrappers = array_merge($wrappers,$this->date_wrapper);
        
        // for each keyword in wrapper, we substitue it's value
        foreach ($_int_wrappers as $key => $value)
        {
            $str2search = $this->delimiter_begin.$key.$this->delimiter_end;
            $path2wrap = str_replace ($str2search,$value,$path2wrap);
        } 
        
        return $path2wrap;
    }    


    function create_date_wrapper_array($time)
    {
        if (0 == $time) $time = time();
        
        if ( ($time == $this->latest_date_export) && ($time != 0)) return true;
        
        $this->latest_date_export = $time;
        
        $this->date_wrapper['da'] = date('a',$time); // "am" or "pm" 

        $this->date_wrapper['dA'] = date('A',$time); // "AM" or "PM" 

        $this->date_wrapper['dB'] = date('B',$time); // Swatch Internet time 

        $this->date_wrapper['dd'] = date('d',$time); // day of the month, 2 digits with leading zeros; i.e. "01" to "31" 

        $this->date_wrapper['dD'] = date('D',$time); // day of the week, textual, 3 letters; e.g. "Fri" 

        $this->date_wrapper['dF'] = date('F',$time); // month, textual, long; e.g. "January" 

        $this->date_wrapper['dg'] = date('g',$time); // hour, 12-hour format without leading zeros; i.e. "1" to "12" 

        $this->date_wrapper['dG'] = date('G',$time); // hour, 24-hour format without leading zeros; i.e. "0" to "23" 

        $this->date_wrapper['dh'] = date('h',$time); // hour, 12-hour format; i.e. "01" to "12" 

        $this->date_wrapper['dH'] = date('H',$time); // hour, 24-hour format; i.e. "00" to "23" 

        $this->date_wrapper['di'] = date('i',$time); // minutes; i.e. "00" to "59" 

        $this->date_wrapper['dI'] = date('I',$time); // (capital i) - "1" if Daylight Savings Time, "0" otherwise. 

        $this->date_wrapper['dj'] = date('j',$time); // day of the month without leading zeros; i.e. "1" to "31" 

        $this->date_wrapper['dl'] = date('l',$time); // (lowercase 'L') - day of the week, textual, long; e.g. "Friday" 

        $this->date_wrapper['dL'] = date('L',$time); // boolean for whether it is a leap year; i.e. "0" or "1" 

        $this->date_wrapper['dm'] = date('m',$time); // month; i.e. "01" to "12" 

        $this->date_wrapper['dM'] = date('M',$time); // month, textual, 3 letters; e.g. "Jan" 

        $this->date_wrapper['dn'] = date('n',$time); // month without leading zeros; i.e. "1" to "12" 

        $this->date_wrapper['dO'] = date('O',$time); // Difference to Greenwich time in hours; e.g. "+0200" 

        $this->date_wrapper['dr'] = date('r',$time); // RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" (added in PHP 4.0.4) 

        $this->date_wrapper['ds'] = date('s',$time); // seconds; i.e. "00" to "59" 

        $this->date_wrapper['dS'] = date('S',$time); // English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th" 

        $this->date_wrapper['dt'] = date('t',$time); // number of days in the given month; i.e. "28" to "31" 

        $this->date_wrapper['dT'] = date('T',$time); // Timezone setting of this machine; e.g. "EST" or "MDT" 

        $this->date_wrapper['dU'] = date('U',$time); // seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 

        $this->date_wrapper['dw'] = date('w',$time); // day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday) 

        $this->date_wrapper['dW'] = date('W',$time); // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) 

        $this->date_wrapper['dY'] = date('Y',$time); // year, 4 digits; e.g. "1999" 

        $this->date_wrapper['dy'] = date('y',$time); // year, 2 digits; e.g. "99" 

        $this->date_wrapper['dz'] = date('z',$time); // day of the year; i.e. "0" to "365" 

        $this->date_wrapper['dZ'] = date('Z',$time); // timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. 
        
        
        // PAT spacific
        // ISO format date
        $this->date_wrapper['do'] = date('Y',$time).'-'.date('m',$time).'-'.date('d',$time);
        
        return true;
    }
    

}
Return current item: Path wrapper