| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:35:25 2008 ] | [ bBlog 0.7.6 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 function.calendar.php - calendar plugin 5 */ 6 function identify_function_calendar () { 7 8 $help = ' 9 <p> 10 This plugin displays the calendar module. It uses calendar.html as a template.<BR /> 11 it has two parameter: week_start, which allows you two choose what day is the<BR /> 12 first day a week (default is 1 (Monday). Sunday is 0, Monday is 1, ...) and <BR /> 13 locale, which can be used to force the script to another locale (ie de_DE for<BR /> 14 German, etc.). Default locale is whatever your server has been set to use as <BR /> 15 default. 16 </P>'; 17 18 return array ( 19 'name' => 'calendar', 20 'type' => 'function', 21 'nicename' => 'Calendar', 22 'description' => 'Makes a calendar of the current month', 23 'authors' => 'Tanel Raja', 24 'licence' => 'GPL', 25 'help' => $help 26 ); 27 28 } 29 30 function smarty_function_calendar($params, &$bBlog) { 31 32 $date = getdate(); 33 34 $today = $date["mday"]; 35 $month = $date["mon"]; 36 $year = $date["year"]; 37 38 $new_month = $_GET["month"]; 39 $new_year = $_GET["year"]; 40 41 if ($new_month && $new_year) { 42 $date = getdate(mktime(0, 0, 0, $new_month, 1, $new_year)); 43 $show_month = $date["mon"]; 44 $show_year = $date["year"]; 45 } else { 46 $show_month = $month; 47 $show_year = $year; 48 } 49 50 51 $q = $bBlog->make_post_query( 52 array( 53 "where" => " AND month(FROM_UNIXTIME(posttime)) = $show_month and year(FROM_UNIXTIME(posttime)) = $show_year ", 54 "num"=>"999" 55 ) 56 ); 57 58 $dayindex = array(); 59 global $dayindex; 60 $posts = $bBlog->get_posts($q); 61 if(is_array($posts)) { 62 63 foreach ($posts as $post) { 64 $d = date('j', $post['posttime']); 65 $dayindex[$d][] = array( 66 "id" => $post['post'], 67 "title" => $post['title'], 68 "url" => $bBlog->_get_entry_permalink($post['postid']) 69 ); 70 } 71 72 } 73 74 75 $left_year = $right_year = $show_year; 76 77 $left_month = $show_month - 1; 78 if ($left_month < 1) { 79 $left_month = 12; 80 $left_year--; 81 } 82 $right_month = $show_month + 1; 83 if ($right_month > 12) { 84 $right_month = 1; 85 $right_year++; 86 } 87 88 $bBlog->assign("left", $_SERVER["PHP_SELF"] . "?month=$left_month&year=$left_year"); 89 $bBlog->assign("right", $_SERVER["PHP_SELF"] . "?month=$right_month&year=$right_year"); 90 91 $bBlog->assign("header", strftime("%B %Y", mktime(0, 0, 0, $show_month, 1, $show_year))); 92 93 $first_date = mktime(0, 0, 0, $show_month, 1, $show_year); 94 $date = getdate($first_date); 95 $first_wday = $date["wday"]; 96 $last_date = mktime(0, 0, 0, $show_month + 1, 0, $show_year); 97 $date = getdate($last_date); 98 $last_day = $date["mday"]; 99 100 $wday = ""; 101 // echo($params["locale"]); 102 if ($params["locale"]) 103 @setlocale(LC_TIME, $params["locale"]); 104 $week_start = $params["week_start"]; 105 if ($week_start < 0 || $week_start > 6) { 106 $week_start = 1; 107 } 108 109 for ($counter = $week_start; $counter < $week_start + 7; $counter++) { 110 if ($counter > 6) 111 $wday[] = strftime("%a", mktime(0, 0, 0, 3, $counter - 7, 2004)); 112 else 113 $wday[] = strftime("%a", mktime(0, 0, 0, 3, $counter, 2004)); 114 } 115 116 $bBlog->assign("wday", $wday); 117 118 $week_array = ""; 119 $month_array = ""; 120 121 $pre_counter = $first_wday - $week_start; 122 if ($pre_counter < 0) 123 $pre_counter += 7; 124 125 $day = 1; 126 while(true) { 127 128 $week_array = ""; 129 130 for ($counter = 0; $counter < 7; $counter++) { 131 132 if ($day > $last_day) { 133 $week_array[] = array( 134 0 => false, 135 1 => " ", 136 2 => false 137 ); 138 } else if ($pre_counter > 0) { 139 $week_array[] = array( 140 0 => false, 141 1 => " ", 142 2 => false 143 ); 144 $pre_counter--; 145 } else { 146 getDateLink($day, &$values); 147 148 $week_array[] = array( 149 0 => (($dayindex["$day"])?true:false), 150 1 => $day, 151 2 => (($day == $today && $month == $show_month && $year == $show_year)?true:false) 152 ); 153 $day++; 154 } 155 156 } 157 158 $month_array[] = $week_array; 159 160 if ($day > $last_day) 161 break; 162 163 } 164 165 $bBlog->assign("month", $month_array); 166 $bBlog->assign("values", $values); 167 168 $bBlog->display("calendar.html",FALSE); 169 170 } 171 172 function getDateLink($day, $values) { 173 174 global $dayindex; 175 176 if (!$dayindex[$day]) { 177 return; 178 } else { 179 foreach($dayindex[$day] as $item) { 180 $script .= sprintf("» <a href='%s'>%s</a><br>", $item['url'],$item['title']); 181 } 182 183 $script = str_replace('"', '\"', $script); 184 $values .= "cc[$day]=\"$script\";\n"; 185 186 } 187 } 188 189 ?> 190
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |