Welcome, Guest. Please login or register.
Did you miss your activation email?
May 23, 2012, 07:13:30 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155439 Posts in 21702 Topics by 7732 Members
Latest Member: Smacki
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: New Modul/Code-snipped: c_date  (Read 3294 times)
aldus

Offline Offline

Posts: 1238


« on: August 20, 2008, 02:49:03 PM »

Hello

Hm - at first: i apologize for my english.

The situation: every formated datestring produce via "date()" comes out
in english - regardless the setting of "setLocale", even if you want german
monthnames, or france, netherland ones.
Ok - strftime comes up within fine language specific formats, using "setLocale"
to specify the language. But the language_keys are differnd on differ server: e.g.
german could specify via "de_DE", "de@euro", "ger", "g" and so on.
Could be the hell on earth, even if the languagesettings are working local but differ
on the client-server.

The modul is build to make it easier to handel the situation if you want your own
date-format, e.g. "11. März 2009" instead of "03.11.09" or "2009-03-11", even in (nearly) all
supported languages of WB, and maybe also "dialects" like "de_AT" and/or "de_CH" ...

This (first public) alpha/beta Version 0.3.0 comes up as an easy to install/deinstall modul;
simple install it as a modul. After that you can use some (public) functions thru an
instance even in the frontend, e.g. inside a template, or the backend, inside a modul or other
core-files.

The documentation is in (my bad) english at all but comes up within a quick-start at this time, other
languages will follow, by clicking "about modules" and using the link following after "Doc" in the last line.

Some examples:
Code:
<?php
//    setting the format
$d->format="%A, %d. %B %Y";

// This will return the date-string in the given format.
//    e.g. below: 11. März 1966
$d->transform ("11/03/1966");

// This will return the current time in the format.
$d->toHTML();

//    This also
$d->toHTML TIME() );

//    This will set a new Language, e.g. italy.
$d->setLanguage ( array ("it_IT""italiy""it_IT@euro") );

//    This will change all dates in a given string (pass by reference!).
$d->parse_string ("At 30.01.1998 the new book of Mr. Unknown comes ...");

//    Testing a given language-key agains the locales and optional use them.
//    Returns a list with all matches.
$all $d->test_locale("de_AT"true);

foreach (
$all as $tempKey) echo "< br />".$tempKey// will result in:

de_AT
de_AT
.ISO8859-1
de_AT
.ISO8859-15
de_AT
.UTF-8
?>


The following example comes from my modifications on "admin/pages/modify"
Code:
<?php

// Convert the unix ts for modified_when to human a readable form
if($results_array['modified_when'] != 0) {
    
/**
    *    Modify by Dietrich Roland Pehlke - aldus
    *
    *    @ersion    0.1.0
    *    @date    2008-08-19
    *
    *    Testing the use of x_cDate in the backend
    */
    
$temp_path WB_PATH."/modules/x_cdate/include.php";
    if (
file_exists($temp_path)) {
        require_once(
$temp_path);
        
        
$d = new c_date();
        
        
$d->set_wb_langLANGUAGE );
        
        
$d->format="<br />%A, %d. <font style='color:#900;'>%B</font> %Y -%H:%I:%S<br />";
        
        
$modified_ts $d->toHTML$results_array['modified_when']+TIMEZONE );
        
    } else {
        
$modified_ts gmdate(TIME_FORMAT.', '.DATE_FORMAT$results_array['modified_when']+TIMEZONE);
    }
} else {
    
$modified_ts 'Unknown';
}
?>


and for a frontend-example i've used a "Code2" Page:

Code:
<?php
$d 
= new c_date();

/**
*    Changing the current format
*/
$d->format="%A, %d. <font style='color:#900;'><i>%B</i></font> %Y<br />";

echo 
$d->toHTML() ;

echo 
$d->transform("11/03/1966");
echo 
$d->transform("11.03.1966") ;
echo 
$d->transform("03-11-1966"'m-d-y') ;
echo 
$d->transform("1966-03-11"'y m D') ;
echo 
$d->transform("1966/03/11"'ymd') ;
echo 
$d->transform("03/11/66"CDATE_USE_MDY) ;

echo 
$d->set_wb_lang("EN");
echo 
$d->toHTML() ;

$str "<br><br>On 11.03.1998 Mr. Unkown has shown his new book »Anastasitica« inside his office.<br>";
$str .= "And on 03.06.2008 we will read it!<br />";

$d->parse_string($str);

echo 
$str;

$a $d->test_locale("de_AT"false);
foreach (
$a as $t) echo "<br />".$t;

echo 
"<br /><br />".$d->transform("11.01.66");
?>


If there are any problems while installing or any questions about the class, feel
free to drop a note or leave a comment here.

Regards
Aldus
« Last Edit: August 20, 2008, 03:22:46 PM by aldus » Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: August 20, 2008, 07:10:19 PM »

Hello Aldus,
Thanks for this Module.
It's beautyfull and one I really allways needed in websitebaker.

Based on your demos and explanations I created a snipped to include this inside the NEWS Module.
I'm sure there is some semantic lags in it, but it works just fine so far.

The snippet is as follows:
Open the view.php in your news directory /modules/news/view.php

around line 177 find the folowing:


                                
// Workout date and time of last modified post
                
$post_date gmdate(DATE_FORMAT$post['posted_when']+TIMEZONE);
                
$post_time gmdate(TIME_FORMAT$post['posted_when']+TIMEZONE);

and replace with this lines:
                // MODIFICATION to alternate the Date Output in the frontend
                // using cDate Module by Aldus -->
        
                // Workout date and time of last modified post
                
$temp_path WB_PATH."/modules/x_cdate/include.php";
                    if (
file_exists($temp_path)) {
        require_once(
$temp_path);        
        
$d = new c_date();
        
$d->set_wb_langLANGUAGE );        
        
$d->format="<font style='color:#900;'>%a, %d. %b %Y </font>"//put your HTML/CSS alteration of the output in this line            
                
$post_date $d->toHTML$post['posted_when']+TIMEZONE );}
                else
                { 
$post_date gmdate(DATE_FORMAT$post['posted_when']+TIMEZONE); }
                
                
// <-- end of MODIFICATION    

It works just fine even if the c_date module isn't installed.
(in this case it will work as default).

Have fun!

Thanks again,
Stefek
« Last Edit: August 28, 2008, 02:35:44 PM by Stefek » Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #2 on: August 28, 2008, 06:40:41 PM »

Hello Community!

TUTORIAL

Today a small turorial for a "Wordpress-like" calendar date display in the GUESTBOOK
(similar to my previous tutorial for the news).




You will need to have Aldus c_date Module from the first post of this thread.


The steps to do are as follows:


0) Excuse my english.  cool

1) Open the view.php of your guestbook directory

2)  Around line 184 find the following:
 // A:    Get the enty date and time
        
$entry_date gmdate(DATE_FORMAT$entry['posted_when']+TIMEZONE);
        
$entry_time gmdate(TIME_FORMAT$entry['posted_when']+TIMEZONE);

3) Replace with this (but without the <?php --- ?>):

Code:
<?php

                 
// A:    Get the entry date and time
        // MODIFICATION by Stefek to alternate the Date Output in the frontend
        // using cDate Module by Aldus -->
        // Workout date and time of last modified post
            
$temp_path WB_PATH."/modules/x_cdate/include.php";
            if (
file_exists($temp_path)) {
            require_once(
$temp_path);
            
$d = new c_date();
            
$d->set_wb_langLANGUAGE );
            
////put your HTML/CSS alteration of the output into the next line
            
$d->format="<div class='calender'><br /><span class='m'>%B<br /></span><span class='d'>%d<br /></span><span class='y'>%Y</span></div>";
            
$entry_date $d->toHTML$entry['posted_when']+TIMEZONE );}
                else
            { 
$entry_date gmdate(DATE_FORMAT$entry['posted_when']+TIMEZONE); }
                    
            
$entry_time gmdate(TIME_FORMAT$entry['posted_when']+TIMEZONE);    
                    
/*$entry_date = gmdate(DATE_FORMAT, $entry['posted_when']+TIMEZONE);
   $entry_time = gmdate(TIME_FORMAT, $entry['posted_when']+TIMEZONE); */
?>



4) Style your output as you want it.
you can use every style you like. Just replace it in this line:
$d->format="<div class='calender'><br /><span class='m'>%B<br />
</span><span class='d'>%d<br /></span><span class='y'>%Y</span></div>"
;
and adjust your CSS to your needs.

5) Surf around the web and browse some wordpress templates for inspiration.
With this small module you can realize the same things the WP guys do.

6) See a working demo made with Aldus Module and WB
www.funfabrikbowl.d e (Site in developement).

7) Enjoy!

8 ) Find another great applications of this Module/Snippet!

Best Regards,
Stefek

« Last Edit: January 07, 2009, 04:19:32 PM by Stefek » Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #3 on: November 21, 2008, 12:55:11 PM »

Hello,

one important addition to those using the german hoster "Strato".

In order to get the x_cDate Snippet working you will need this two lines of Code in your .htaccess (WB ROOT DIRECTORY) file:

Code:
Directoryindex index.php , index.htm, index.html
AddType application/x-httpd-php5 .php .php4 .php3 .php5

Thanks for the hint, Aldus.

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!