PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 2.1.6
پارسی دیت – Parsi Date v2.1.6
6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / includes / fixes-get_calendar.php
wp-parsidate / includes Last commit date
admin 10 years ago plugins 11 years ago widget 10 years ago fixes-archive.php 11 years ago fixes-dates.php 11 years ago fixes-get_archives.php 11 years ago fixes-get_calendar.php 11 years ago fixes-misc.php 11 years ago fixes-permalinks.php 11 years ago general.php 10 years ago install.php 11 years ago parsidate.php 11 years ago settings.php 10 years ago
fixes-get_calendar.php
251 lines
1 <?php
2
3 /**
4 * Create Persian Calendar
5 *
6 * @param string $args
7 * @author Mobin Ghasempoor
8 * @author Parsa Kafi
9 * @return string
10 */
11 function wpp_get_calendar($args='')
12 {
13 global $wp_query , $wpdb, $m, $monthnum, $year, $day, $posts;
14
15 $pd = bn_parsidate::getInstance();
16 $jm = $monthnum;
17 if ($m != '') {
18 $m = preg_replace("/[^0-9]/", "", $m);
19 $jy = substr($m, 0, 4);
20 } elseif ($year !== ''){
21 $jy = $year;
22 }
23
24 if($jy>1500)
25 list($jy,$jm,$jd) = $pd->gregorian_to_persian($year,$monthnum,$day);
26
27 if ( !$posts ){
28 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
29 if ( !$gotsome )
30 return;
31 }
32
33 $week_begins = intval(get_option('start_of_week'));
34 $w = isset($_GET['w'])?intval($_GET['w']):'';
35 $is_gregorian= false;
36
37 if ( !empty($jm) && !empty($jy) ){
38 $thismonth = ''.zeroise(intval($jm), 2);
39 $thisyear = ''.intval($jy);
40
41 } elseif ( !empty($w) ) {
42 $thisyear = ''.intval(substr($m, 0, 4));
43 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
44 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
45
46 } elseif ( !empty($m) ) {
47 $thisyear = ''.intval(substr($m, 0, 4));
48 if ( strlen($m) < 6 )
49 $thismonth = '01';
50 else
51 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
52
53 } else {
54 $is_gregorian = true;
55 $thisyear = gmdate('Y', current_time('timestamp')+get_option('gmt_offset') * 3600);
56 $thismonth = gmdate('m', current_time('timestamp')+get_option('gmt_offset') * 3600);
57 $thisday = gmdate('d', current_time('timestamp')+get_option('gmt_offset') * 3600);
58 }
59
60 //print_r($wp_query->query_vars);
61
62 if ($is_gregorian)
63 {
64 list($jthisyear,$jthismonth,$jthisday) = $pd->gregorian_to_persian($thisyear,$thismonth,$thisday);
65 $unixmonth = $pd->gregurian_date('Y-m-d 00:00:00',"$jthisyear-$jthismonth-01");
66 } else {
67 $gdate = $pd->persian_to_gregorian($thisyear,$thismonth,1);
68 $unixmonth = mktime(0, 0 , 0, $gdate[1], 1, $gdate[0]);
69 $jthisyear = $thisyear;
70 $jthismonth = $thismonth;
71 }
72
73 $jnextmonth = $jthismonth + 1;
74 $jnextyear = $jthisyear;
75
76
77 if ($jnextmonth > 12)
78 {
79 $jnextmonth = 1;
80 $jnextyear++;
81 }
82
83 $start = $pd->gregurian_date('Y-m-d 00:00:00',"$jthisyear-$jthismonth-01");
84 $end = $pd->gregurian_date('Y-m-d 23:59:59',"$jnextyear-$jthismonth-".$pd->j_days_in_month[$jthismonth - 1]);
85
86 //echo "Start Date: ".$start.", End Date: ".$end."<br>";
87
88 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
89 FROM $wpdb->posts
90 WHERE post_date < '$start'
91 AND post_type = 'post' AND post_status = 'publish'
92 ORDER BY post_date DESC
93 LIMIT 1");
94 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
95 FROM $wpdb->posts
96 WHERE post_date >= '$end'
97 AND post_type = 'post' AND post_status = 'publish'
98 ORDER BY post_date ASC
99 LIMIT 1");
100
101 $calendar_output = '<table id="wp-calendar" style="direction: rtl" class="widget_calendar">
102 <caption>' . $pd->persian_month_names[(int)$jthismonth ] . ' ' . $pd->persian_date('Y', $unixmonth) . '</caption>
103 <thead>
104 <tr>';
105 $myweek = array();
106 for ( $wdcount=0; $wdcount<=6; $wdcount++ )
107 {$myweek[] = $pd->persian_day_small[($wdcount+$week_begins)%7];}
108
109 foreach ( $myweek as $wd )
110 {$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$wd</th>";}
111
112 $calendar_output .= '
113 </tr>
114 </thead>
115
116 <tfoot>
117 <tr>';
118
119 if($previous){
120 $previous_month = $jthismonth - 1;
121 $previous_year = $jthisyear;
122 if ($previous_month == 0){
123 $previous_month = 12;
124 $previous_year--;
125 }
126
127 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="'.get_month_link($previous_year, $previous_month).
128 '">&laquo; ' . $pd->persian_month_names[$previous_month] . '</a></td>';
129 }else {
130 $calendar_output .= "\n\t\t" . '<td colspan="3" id="prev" class="pad">&nbsp;</td>';
131 }
132
133 $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
134
135 if($next){
136 $next_month = $jthismonth + 1;
137 $next_year = $jthisyear;
138 if ($next_month == 13){
139 $next_month = 1;
140 $next_year ++;
141 }
142 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="'.get_month_link($next_year, $next_month).
143 '">' . $pd->persian_month_names[$next_month]. ' &raquo;</a></td>';
144 }else {
145 $calendar_output .= "\n\t\t" . '<td colspan="3" id="next" class="pad">&nbsp;</td>';
146 }
147
148 $calendar_output .= '
149 </tr>
150 </tfoot>
151
152 <tbody>
153 <tr>';
154
155 //____________________________________________________________________________________________________________________________________
156
157 $sql = "SELECT DISTINCT DAYOFMONTH(post_date),MONTH(post_date),YEAR(post_date)
158 FROM $wpdb->posts
159 WHERE post_date > '$start' AND post_date < '$end'
160 AND post_type = 'post'
161 AND post_status = 'publish'";
162 $dayswithposts = $wpdb->get_results($sql, ARRAY_N);
163
164 if ( $dayswithposts ){
165 foreach ($dayswithposts as $daywith )
166 {$daywithpost[] = $pd->persian_date('j',"$daywith[2]-$daywith[1]-$daywith[0]",'eng');}
167
168 } else {
169 $daywithpost = array();
170 }
171
172 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
173 $ak_title_separator = "\n";
174 else
175 $ak_title_separator = ', ';
176
177 $ak_titles_for_day = array();
178 $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom, MONTH(post_date) as month, YEAR(post_date) as year
179 FROM $wpdb->posts WHERE post_date >= '$start'
180 AND post_date <= '$end'
181 AND post_type = 'post' AND post_status = 'publish'");
182
183 if ( $ak_post_titles )
184 {
185 foreach ($ak_post_titles as $ak_post_title )
186 {/** This filter is documented in wp-includes/post-template.php */
187 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ));
188 $ak_post_title->dom = $pd->persian_date('j',"$ak_post_title->year-$ak_post_title->month-$ak_post_title->dom",'eng');
189
190 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
191 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
192 if ( empty($ak_titles_for_day[$ak_post_title->dom]) ) // first one
193 $ak_titles_for_day[$ak_post_title->dom] = $post_title;
194 else
195 $ak_titles_for_day[$ak_post_title->dom] .= $ak_title_separator . $post_title;
196 }
197 }
198
199 //$pad = calendar_week_mod(date('w',strtotime($unixmonth))-$week_begins);
200
201 $pad = wppd_get_pad($jthisyear."-".$jthismonth);
202 //echo "<br />begin=$week_begins<br />pad=$pad<br />";
203
204 if (0 != $pad)
205 $calendar_output .= "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
206
207 $daysinmonth = intval($pd->persian_date('t', $unixmonth,'eng'));
208
209 for ($day = 1; $day <= $daysinmonth; ++$day)
210 {
211 list($thiyear,$thismonth,$thisday) = $pd->persian_to_gregorian($jthisyear,$jthismonth,$day);
212 if (isset($newrow) && $newrow)
213 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
214 $newrow = false;
215
216 if ($thisday == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)))
217 $calendar_output .= '<td id="today">';
218 else
219 $calendar_output .= '<td>';
220
221 $p_day =(empty($val['sep_datesnum'])?$day:per_number($day));
222
223 if (in_array($day, $daywithpost)) // any posts today?
224 $calendar_output .= '<a href="' . get_day_link($jthisyear, $jthismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$p_day</a>";
225 else
226 $calendar_output .= $p_day;
227 $calendar_output .= '</td>';
228
229 if (6 == calendar_week_mod($pd->gregurian_date('w',"$jthisyear-$jthismonth-$day")-$week_begins))
230 $newrow = true;
231 }
232 $pad = 7 - calendar_week_mod($pd->gregurian_date('w',"$jthisyear-$jthismonth-$day",'eng')-$week_begins);
233 if ($pad != 0 && $pad != 7)
234 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
235
236 echo $calendar_output ."\n\t</tr>\n\t</tbody>\n\t</table>";
237 }
238
239 /**
240 * Get Pad
241 * @author Parsa Kafi
242 * @param string $date
243 * @return int
244 */
245 function wppd_get_pad($date){
246 $pd = bn_parsidate::getInstance();
247 $p = $pd->persian_date("w",$pd->gregurian_date("Y-m-d",$date."-01"),"eng");
248
249 return $p;
250 }
251 ?>