changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / appearance / title_calendar.php
1 <?php
2 #  makes a pages` calendar title more readable,
3 #  replaces the standard _print_title with a _calendar_title
4 #
5 #  Also replaces the titles in page lists by usurping a spot in the list_pages plugin 
6 #  and calling whatever was there before after it has transformed the list.
7 #
8 #  Written by: Andy Fundinger
9 #
10 # the isCalendarId function from calendar.php is necessary starting with this
11 #  version
12 #
13 #-- glue
14 $ewiki_plugins["title_transform"][] = "ewiki_calendar_title_transform";
15 $ewiki_plugins["list_transform"][] = "ewiki_calendar_list_pages";
16
17 @define("EWIKI_NAME_SEP", "_");
18 @define("CALENDAR_NAME_SEP", EWIKI_NAME_SEP);
19 @define("CALENDAR_PAGE_TITLE_REGEX","/^(.*?)".preg_quote(CALENDAR_NAME_SEP) ."\d{8}$/");
20 @define("CALENDAR_PAGE_DATE_PARSE_REGEX", '#(.*)'. preg_quote(CALENDAR_NAME_SEP) .' ?(\d{4})(\d{2})(\d{2})#');
21 $ewiki_t["en"]['CALENDERENTRYFOR']='Calendar entry for ';
22 $ewiki_t["de"]['CALENDERENTRYFOR']='KalenderEintrag für ';
23
24 function ewiki_calendar_list_pages(&$lines) {
25     global $ewiki_plugins;
26
27     for($index=0;$index<count($lines);$index++){
28                              //                                         1         2                                                                                                                                     3
29         $lines[$index]=preg_replace("#(.*>)(.*?".preg_quote(CALENDAR_NAME_SEP) ." ?\d{8})(.*)#e"," \"$1\".ewiki_calendar_page_title('$2').'$3'",$lines[$index]);
30     }
31         
32    return($lines);
33 }
34
35 function ewiki_calendar_title_transform($id, &$title, &$go_action){
36
37     if (ewiki_isCalendarId($id)) {
38         $title=ewiki_calendar_page_title ($id);
39     }
40 }
41
42 #-- title string replacing
43 function ewiki_print_calendar_title(&$html, $id, $data, $action, $split=EWIKI_SPLIT_TITLE) {
44    global $ewiki_title;
45
46    if (ewiki_isCalendarId($id)) {
47      $html=str_replace(">$ewiki_title<", ">".ewiki_calendar_page_title($id,$split)."<", $html);
48    }
49 }
50
51 function ewiki_calendar_page_title ($id='', $split=EWIKI_SPLIT_TITLE) {
52    strlen($id) or ($id = $GLOBALS["ewiki_page"]);
53
54    static $month_names;
55    if (!isset($month_names)) {
56       $month_names = explode(" ", ewiki_t("MONTHS"));
57    }
58
59    if(preg_match(CALENDAR_PAGE_DATE_PARSE_REGEX,$id,$dateParts) ){
60    
61         /*Transform Parent title using plugins */   
62         $parentId=$dateParts[1];
63         
64         $parentTitle=$parentId;
65         if ($ewiki_config["split_title"] || $split) {
66             $parentTitle = ewiki_split_title($parentId);
67         }
68        
69         #-- title mangling
70         if ($pf_a = $ewiki_plugins["title_transform"]) {
71             foreach ($pf_a as $pf) { $pf($parentId, $parentTitle, ''); }
72         }
73         
74         $title=ewiki_t("CALENDERENTRYFOR").$parentTitle.": ". $month_names[$dateParts[3]-1]." ".$dateParts[4].", ".$dateParts[2];
75    }
76    return($title);
77
78 ?>