WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: aldus on August 20, 2008, 03:49:03 PM

Title: New Modul/Code-snipped: c_date
Post by: aldus on August 20, 2008, 03: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: [Select]
<?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: [Select]
<?php

// Convert the unix ts for modified_when to human a readable form
if($results_array[&#39;modified_when&#39;] != 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=&#39;color:#900;&#39;>%B</font> %Y -%H:%I:%S<br />";
        
        
$modified_ts $d->toHTML$results_array[&#39;modified_when&#39;]+TIMEZONE );
        
    
} else {
        
$modified_ts gmdate(TIME_FORMAT.&#39;, &#39;.DATE_FORMAT, $results_array[&#39;modified_when&#39;]+TIMEZONE);
    
}
} else {
    
$modified_ts = &#39;Unknown&#39;;
}
?>


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

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

/**
*    Changing the current format
*/
$d->format="%A, %d. <font style=&#39;color:#900;&#39;><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", &#39;m-d-y&#39;) ;
echo $d->transform("1966-03-11", &#39;y m D&#39;) ;
echo $d->transform("1966/03/11", &#39;ymd&#39;) ;
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

[gelöscht durch Administrator]
Title: Re: New Modul/Code-snipped: c_date
Post by: Stefek on August 20, 2008, 08: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_lang( LANGUAGE );        
        $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
Title: Re: New Modul/Code-snipped: c_date
Post by: Stefek on August 28, 2008, 07: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.  8-)

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: [Select]
<?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.


7) Enjoy!

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

Best Regards,
Stefek

Title: Re: New Modul/Code-snipped: c_date
Post by: Stefek 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: [Select]
Directoryindex index.php , index.htm, index.html
AddType application/x-httpd-php5 .php .php4 .php3 .php5

Thanks for the hint, Aldus.

Regards,
Stefek
Title: Re: New Modul/Code-snipped: c_date
Post by: chris85 on May 04, 2013, 02:12:55 PM
Hello everybody,

first I want to thank you guys for your work! It makes life so much easier for us all :)

Unfortunately I had really a bit trouble with umlauts like ä, ö or ü. I have my whole website with utf-8 charset but couldn't figure out why there are still these annoying questionmarks and no umlauts.
If you wan't to get rid of the questionmark placeholder caused by the wrong charset, you have to open up the include.php file of the x cdate module and find the following:

Code: [Select]
de_DE
and replace it with this:

Code: [Select]
de_DE.UTF-8
That's it! Really easy, when you know what is needed to be done, but can be really annoying if you don't. So I thought it would be a good addition to the tutorial here.

By the way, I found this hint on http://tobi.weinhorst.de/2008/08/08/umlaute-nach-strftime-kaputt/ (http://tobi.weinhorst.de/2008/08/08/umlaute-nach-strftime-kaputt/).

Hope this will help anybody with the same problem.
Title: Re: New Modul/Code-snipped: c_date
Post by: Kant on May 04, 2013, 03:24:46 PM
Thank you for that one - totaly forgot the utf-8 thing ;-)

Alternative for the editing the module include.php you can also use
the public function/method 'test_locale' to get a linea list of valid keys for
your language. Keep in mind, that the utf-8 one is mostly the last one, so
we have reverse the result-array first. (see line 6)
E.g.
Code: [Select]
<?php

/*   1 */ $oDate = new c_date();
/*   2 */
/*   3 */ $all $oDate->test_locale"de_DE" );
/*   4 */
/*   5 */ $oDate->setLanguage(
/*   6 */ array_reverse($all)
/*   7 */ );
/*   8 */ $oDate->format"%d %B %Y";
/*   9 */
/*  10 */ echo $oDate->toHTMLtime()-( 60*60*24*60) );

?>


or simple add the key direct
E.g.
Code: [Select]
<?php

/*   1 */ $oDate = new c_date();
/*   2 */
/*   3 */ $oDate->setLanguage( array (
/*   4 */ 'de_DE.UTF-8',
/*   5 */ 'de_DE',
/*   6 */ 'de_DE@euro'
/*   7 */ )
/*   8 */ );
/*   9 */ $oDate->format"%d %B %Y";
/*  10 */
/*  11 */ echo $oDate->transform"11.03.1966" );

?>


if you are using e.g. france, norway, polisch, etc.

As for a testing i add a version 0.4.2

Kind regards