Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 10:25:45 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155529 Posts in 21713 Topics by 7737 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Topics als Event-Calendar "gebrauchen"  (Read 1226 times)
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« on: November 26, 2009, 10:47:21 PM »

Neulich gab es schon was hier im Forum.
Jemand hat das Topics als Event-Calendar gebraucht.

War schon lustig, weil ich zu der selben Zeit das gleiche ausgearbeitet habe und dann John (PC Wacht) noch ein Calendar Droplet gepostet hat.

Da kam mir 1 und 1 durch den Kopf geschoßen, ein wenig (mehr) Hilfe von einem erfahrenen Programmierer (Bianka) und schon war ein Calendar Droplet zur Zusammenarbeit mit dem Topics Modul fertig.

Ich poste das Droplet so, wie ich es selbst verwende.
Man sollte es für seine Zwecke über das CSS File im Template Stylen.

Code:
<?php
        
global $wb$database;                
        
$days            = array();
        
$day_name_length 2
        
$month_href      NULL;
        
$first_day       1// 0 = Sun, 1 = Mon, 2 = Tue, etc.
        
$time time();        
        
$oldlocale setlocale(LC_TIMENULL); //save current locale
        //setlocale(LC_TIME, 'de_DE');        
        
        
if (!isset($year))  {$year  date('Y'time()); };
        if (!isset(
$month)) {$month date('n'time()); };
        if (isset(
$offset)) { $month += $offset; }

// --------------| check offset for this month
    
        
$thismonth date('m',time());
        if (!isset(
$offset) or $offset == 0)
            {
            
$today date('j',$time); 
        }
            
/* 
--------------| get entries from Topics 
*/
        
$first_of_month mktime(0,0,0,$month,1,$year); 
        
$lastday        strftime"%d"mktime(000, ($month+1), 0$year) );
        
$last_of_month  mktime(23,59,59,$month,$lastday,$year);
        
$where          = ( isset( $section_id ) && is_numeric$section_id ) )
                        ? 
"AND section_id = '$section_id'"
                        
NULL
        
        
$sql "SELECT published_when, link, title FROM ".TABLE_PREFIX."mod_topics 
                WHERE published_when BETWEEN 
$first_of_month AND $last_of_month $where";    
        
$result $database->query($sql);
    
//    $day == $today ? $classes = "today-linked" : $classes = "linked-day"; 

/*
        ---------------------------| define STATIC LINKS
*/
        //LINKS
        
$static_links = array(
        
//    0 =>WB_URL.PAGES_DIRECTORY.'/montag'.PAGE_EXTENSION,
            
=>WB_URL.PAGES_DIRECTORY.'/dienstag'.PAGE_EXTENSION,
            
=> WB_URL.PAGES_DIRECTORY.'/mittwoch'.PAGE_EXTENSION,
            
=> WB_URL.PAGES_DIRECTORY.'/freitag'.PAGE_EXTENSION);
        
        
//TITLES (title attribute)            
        
$static_links_title = array(
        
//    0 => 'montag-title', 
            
=> 'dienstag-title'
            
=> 'mittwoch-title',
            
=> 'feitag-title');        
        
/* 
--------------| LINKS generated by Topics dates
*/
        
if ( $result->numRows() > ) {
            while( 
$row $result->fetchRow() ) {
                
$day  date'j'$row['published_when'] );
                
$topic_link WB_URL.PAGES_DIRECTORY.'/topics/'.$row['link'].PAGE_EXTENSION;    
                
$days[$day] = array(NULL,NULL,'<a class="vtip" href="'.$topic_link.'" title="'.$row['title'].'">'.$day.'</a>');            
                }
            }    
        
        
$first_of_month gmmktime(0,0,0,$month,1,$year); 
        
$day_names = array(); //generate all the day names according to the current locale 
            
for($n=0,$t=(3+$first_day)*86400$n<7$n++,$t+=86400//January 4, 1970 was a Sunday 
            
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); //%A means full textual day name 
              
        // reset locale
        
setlocale(LC_TIME$oldlocale);
        
        list(
$month$year$month_name$weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month)); 
        
$weekday = ($weekday $first_day) % 7//adjust for $first_day 
        
$title   htmlentities(ucfirst($month_name)).' <span>'.$year.'</span>';  
        
//note that some locales don't capitalize month and day names 
        
        
// -----------------------| Begin calendar
        
$calendar '<table class="calendar">'."\n"
           
'<caption class="calendar-month">'.$title."</caption>\n<tr>"
        
        if(
$day_name_length){ //if the day names should be shown ($day_name_length > 0) 
           //if day_name_length is >3, the full name of the day will be printed 
           
foreach($day_names as $d
                  
$calendar .= '<th class="vtip" title="'.htmlentities($d).'">'.htmlentities($day_name_length substr($d,0,$day_name_length) : $d).'</th>'
                   
$calendar .= "</tr>\n<tr>"
        }         
    
// -----------------------| initial 'empty' days 
        
if($weekday 0$calendar .= '<td class="emptydays" colspan="'.$weekday.'">&nbsp;</td>'
        for(
$day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month$day++,$weekday++){ 
           if(
$weekday == 7){ 
              
$weekday   0//start a new week 
              
$calendar .= "</tr>\n<tr>"
           }            
           
// -----------------------| TOPICS LINKS 
           
if(isset($days[$day]) and is_array($days[$day])){ 
              @list(
$link$hmm$content) = $days[$day]; 
              if(
is_null($content))  $content  $day
              if (
$link) { 
                  
$calendar .=     '<td '.($day == $today ' class="today-linked">' ' class="linked-day">'). 
                                      
'<a class="vtip" href="'.htmlspecialchars($link).'">
                                           <span'
.($day == $today ' class="today static">' ' class="linked-day">').$content.'</span>
                                      </a>
                                  </td>'

              }
              else {
                
$calendar .=     '<td'.($day == $today ' class="today-linked">' ' class="linked-day">').'
                                      <span'
.($day == $today ' class="today topic-link">' ' class="linked-day">').$content.'</span>
                                  </td>'

              }                                         
           } 
        
// -----------------------| STATIC LINKS 
           
elseif ( isset( $static_links[$weekday] )) {    
           
               
$calendar .= '<td'.($day == $today ' class="today static">' ' class="linked-day static">'). 
                                   
'<a class="vtip" href="'.htmlspecialchars($static_links[$weekday]).'" title="'.htmlspecialchars($static_links_title[$weekday]).'">
                                       <span'
.($day == $today ' class="today static">' ' class="linked-day static">').$day.'</span>
                                   </a>
                               </td>'

           }
           
// -----------------------| Days w/o Links
           
else {
               if(
$day == $today) { 
                  
$calendar .=     '<td class="today vtip" title="Heute findet keine Veranstaltung statt"><span class="today">'.$day.'</span></td>'
              }
              else {
                  
$calendar .=     '<td>'.$day.'</td>'
              }  
           } 
        }     
// ----------------------- | remaining 'empty' days 
        
if($weekday != 7$calendar .= '<td class="emptydays" colspan="'.(7-$weekday).'">&nbsp;</td>'

        return 
$calendar."</tr>\n</table>\n"

Zusätzlich gibts die Möglichkeit, statische Links zu setzen (ist oben ausgezeichnet/gekennzeichnet).
Ach ja, wenn es an einem Tag zwei Topics gibt, gewinnt der, der zuerst in der DB geschrieben wurde.


Viel Spaß damit, wer es gebrauchen kann.
Stefek

« Last Edit: November 26, 2009, 11:19:46 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 #1 on: December 23, 2009, 03:28:19 PM »

Für die selbe WB Installation, wo ich den obigen Kalender in Kombination mit TOPICS verwende, wollte ich die Möglichkeit haben, dass
Ereignisse, die abgelaufen sind, automatisch in eine andere Seite von Typ Topics verschoben werden.

Ich machte einen kleinen PHP Schnippsel mit einer SQL Query, die sämtliche Einträge des Topicsmoduls auf Datum hin überprüft (published_when), und jene, die die Anzeigefrist überschritten haben, werden ins "Archiv" befördert.

So sieht das ganze aus:
Code:
<?php
/*
-----------------------------------------------------------------------------| Move Topics into Archive Snippet
*/
global $database$wb;
//Set pageID AND sectionID of your topics archive page (where you want your outdated topics move to)
$pid '9';
$sid '11';

// set the date WHEN the outdated topics has to move at least
$frist date (time()-60*60*2); // minus 2 Stunden (zwei Stunden nach dem Datumswechsel, also um 2 Uhr morgens, des nächsten Tages(?)

// select events older then current date...
   
$selectEvents $database->query("SELECT * FROM ".TABLE_PREFIX."mod_topics WHERE published_when < ".$frist );           
      while (
$eventSelection $selectEvents->fetchRow()) {
// ... and move them into archive (pID & sID)
  
$database->query("UPDATE ".TABLE_PREFIX."mod_topics SET page_id=".$pid." WHERE published_when < ".$frist );
  
$database->query("UPDATE ".TABLE_PREFIX."mod_topics SET section_id=".$sid." WHERE published_when < ".$frist );
 }
/*
-----------------------------------------------------------------------------| end: Move Topics into Archive Snippet
*/     

Wenn jemand das nachbauen will, unbedingt vorher alles auf XAMPP oder dem Portable testen.
Die
$pid = '9';
und
$sid = '11';
sind bei mir die PageID und SectionID der Topics Seite "Archive".
Hier müßt ihr es an die PID/SID Eures "Archivs" anpassen.

$frist = date (time()-60*60*2);
Dies ist zuständig für die Frist. 60Sekunden mal 60 = 1Stunde mal 2 = 2Stunden.
Im obigen Beispiel wird das Topic also 2Stunden nach Mitternacht des Folgetages verschoben.

Gruß,
Stefek

Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #2 on: January 29, 2010, 01:28:03 PM »

Hi Stefek,

Where do you put the code from seccond post ? If I use it on a droplet on front page I get error - no return value..

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #3 on: January 29, 2010, 01:36:27 PM »

I am using it as php snippet in a CODE Section wink

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #4 on: January 29, 2010, 02:18:41 PM »

Just tested it, you can add a line at the bottom: return ""; (return nothing) and use it as a droplet.

Then you can use that droplet for example in a Topics footer Smiley
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #5 on: January 29, 2010, 02:28:52 PM »

Thanks Ivan.
Good idea.

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!