]> git.openstreetmap.org Git - stateofthemap.git/blob - BX_functions.php
Update http -> https img links
[stateofthemap.git] / BX_functions.php
1 <?php
2
3 /**
4  * Function BX_archive
5  * ------------------------------------------------------
6  * This function is based on WP's built-in get_archives()
7  * It outputs the following:
8  *
9  * <h3><a href="link">Month Year</a></h3>
10  * <ul class="postspermonth">
11  *     <li><a href="link">Post title</a> (Comment count)</li>
12  *     [..]
13  * </ul>
14  */
15
16 function BX_archive()
17 {
18         global $month, $wpdb;
19         $now        = current_time('mysql');
20         $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_date <'" . $now . "' AND post_status='publish' AND post_password='' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
21
22         if ($arcresults) {
23                 foreach ($arcresults as $arcresult) {
24                         $url  = get_month_link($arcresult->year, $arcresult->month);
25                 $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
26                 echo get_archives_link($url, $text, '','<h3>','</h3>');
27
28                         $thismonth   = zeroise($arcresult->month,2);
29                         $thisyear = $arcresult->year;
30
31                 $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status FROM " . $wpdb->posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND post_status='publish' AND post_password='' ORDER BY post_date DESC");
32
33                 if ($arcresults2) {
34                         echo "<ul class=\"postspermonth\">\n";
35                 foreach ($arcresults2 as $arcresult2) {
36                         if ($arcresult2->post_date != '0000-00-00 00:00:00') {
37                                 $url       = get_permalink($arcresult2->ID);
38                                 $arc_title = $arcresult2->post_title;
39
40                                 if ($arc_title) $text = strip_tags($arc_title);
41                         else $text = $arcresult2->ID;
42
43                                 echo "<li>".get_archives_link($url, $text, '');
44                                                 $comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID);
45                                                 $comments_count = mysql_num_rows($comments);
46                                                 if ($arcresult2->comment_status == "open" OR $comments_count > 0) echo '&nbsp;('.$comments_count.')';
47                                                 echo "</li>\n";
48                         }
49                 }
50                 echo "</ul>\n";
51                 }
52                 }
53         }
54 }
55
56
57 /**
58  * Function BX_get_recent_posts
59  * ------------------------------------------------------
60  * Outputs an unorderd list of the most recent posts.
61  *
62  * $current_id          this post will be excluded
63  * $limit                       max. number of posts
64  */
65
66 function BX_get_recent_posts($current_id, $limit)
67 {
68         global $wpdb;
69     $posts = $wpdb->get_results("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_status='publish' ORDER BY post_date DESC LIMIT " . $limit);
70     foreach ($posts as $post) {
71         $post_title = stripslashes($post->post_title);
72         $permalink  = get_permalink($post->ID);
73         if ($post->ID != $current_id) echo "<li><a href=\"" . $permalink . "\">" . $post_title . "</a></li>\n";
74     }
75 }
76
77
78 /**
79  * Function BX_get_pages
80  * ------------------------------------------------------
81  * Returns the following of all WP pages:
82  * ID, title, name, (content)
83  *
84  * $withcontent         specifies if the page's content will
85  *                                      also be returned
86  */
87
88 function BX_get_pages($with_content = '')
89 {
90     global $wpdb;
91     $query = "SELECT ID, post_title, post_name FROM " . $wpdb->posts . " WHERE post_type='page' OR post_status='static' ORDER BY menu_order ASC";
92         
93         if ($with_content == "with_content") {
94            $query = "SELECT ID, post_title,post_name, post_content FROM " . $wpdb->posts . " WHERE post_type='page' OR post_status='static' ORDER BY menu_order ASC";
95         }
96         return $wpdb->get_results($query);
97 }
98
99
100 /**
101  * Function BX_excluded_pages()
102  * ------------------------------------------------------
103  * Returns the Blix default pages that are excluded
104  * from the navigation in the sidebar
105  *
106  */
107
108 function BX_excluded_pages()
109 {
110         $pages = BX_get_pages();
111         $exclude = "";
112         if ($pages) {
113                 foreach ($pages as $page) {
114                         $page_id = $page->ID;
115                         $page_name = $page->post_name;
116                         if ($page_name == "archives" || $page_name == "about"  || $page_name == "about_short" || $page_name == "contact") {
117                                 $exclude .= ", ".$page_id;
118                         }
119                 }
120                 $exclude = preg_replace("/^, (.*?)/","\\1",$exclude);
121         }
122         return $exclude;
123 }
124
125
126 /**
127  * Function BX_shift_down_headlines
128  * ------------------------------------------------------
129  * Shifts down the headings by one level (<h5> --> </h6>)
130  * Used for posts in the archive
131  */
132
133 function BX_shift_down_headlines($text)
134 {
135         $text = apply_filters('the_content', $text);
136         $text = preg_replace("/h5>/","h6>",$text);
137         $text = preg_replace("/h4>/","h5>",$text);
138         $text = preg_replace("/h3>/","h4>",$text);
139         echo $text;
140 }
141
142
143 /**
144  * Function BX_remove_p
145  * ------------------------------------------------------
146  * Removes the opening <p> and closing </p> from $text
147  * Used for the short about text on the front page
148  */
149
150 function BX_remove_p($text)
151 {
152         $text = apply_filters('the_content', $text);
153     $text = preg_replace("/^[\t|\n]?<p>(.*)/","\\1",$text); // opening <p>
154     $text = preg_replace("/(.*)<\/p>[\t|\n]$/","\\1",$text); // closing </p>
155     return $text;
156 }
157
158 ?>