1 | <?php
|
---|
2 |
|
---|
3 | function xpress_credit($show = false)
|
---|
4 | {
|
---|
5 | global $wp_version , $xoops_config;
|
---|
6 |
|
---|
7 | $xpress_version = $xoops_config->module_version;
|
---|
8 | $xpress_codename = $xoops_config->module_codename;
|
---|
9 | $ret = '<a href="http://www.toemon.com"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
|
---|
10 | if (strstr($wp_version,'ME')){
|
---|
11 | $ret .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
12 | } else {
|
---|
13 | $ret .= '(included <a href="http://ja.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
14 | }
|
---|
15 |
|
---|
16 | if (empty($show))
|
---|
17 | return $ret;
|
---|
18 | else
|
---|
19 | echo $ret;
|
---|
20 | }
|
---|
21 |
|
---|
22 | function xpress_convert_time($show = false)
|
---|
23 | {
|
---|
24 | $ret = timer_stop(0) .'sec. ';
|
---|
25 | if (empty($show))
|
---|
26 | return $ret;
|
---|
27 | else
|
---|
28 | echo $ret;
|
---|
29 | }
|
---|
30 |
|
---|
31 | function xpress_is_theme_sidebar_disp(){
|
---|
32 | global $xpress_config;
|
---|
33 | return $xpress_config->is_theme_sidebar_disp;
|
---|
34 | }
|
---|
35 |
|
---|
36 | function xpress_left_arrow_post_link($show = false)
|
---|
37 | {
|
---|
38 | global $xpress_config;
|
---|
39 | $ret = '';
|
---|
40 |
|
---|
41 | if($xpress_config->is_left_postnavi_old){
|
---|
42 | $link_title = $xpress_config->old_post_link_text;
|
---|
43 | ob_start();
|
---|
44 | if ($xpress_config->is_postnavi_title_disp)
|
---|
45 | previous_post_link('« %link');
|
---|
46 | else
|
---|
47 | previous_post_link('« %link',$link_title);
|
---|
48 | $ret = ob_get_contents();
|
---|
49 | ob_end_clean();
|
---|
50 | } else {
|
---|
51 | $link_title = $xpress_config->newer_post_link_text;
|
---|
52 | ob_start();
|
---|
53 | if ($xpress_config->is_postnavi_title_disp)
|
---|
54 | next_post_link('« %link');
|
---|
55 | else
|
---|
56 | next_post_link('« %link',$link_title);
|
---|
57 | $ret = ob_get_contents();
|
---|
58 | ob_end_clean();
|
---|
59 | }
|
---|
60 |
|
---|
61 | if ($xpress_config->is_postnavi_title_disp){
|
---|
62 | $on_mouse_show = $link_title;
|
---|
63 | } else {
|
---|
64 | if($xpress_config->is_left_postnavi_old){
|
---|
65 | ob_start();
|
---|
66 | previous_post_link('%link');
|
---|
67 | $on_mouse_show = ob_get_contents();
|
---|
68 | ob_end_clean();
|
---|
69 | } else {
|
---|
70 | ob_start();
|
---|
71 | next_post_link('%link');
|
---|
72 | $on_mouse_show = ob_get_contents();
|
---|
73 | ob_end_clean();
|
---|
74 | }
|
---|
75 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
76 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
77 | $on_mouse_show = $body_matches[1];
|
---|
78 | }
|
---|
79 | $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
80 |
|
---|
81 | if (empty($show))
|
---|
82 | return $ret;
|
---|
83 | else
|
---|
84 | echo $ret;
|
---|
85 | }
|
---|
86 |
|
---|
87 | function xpress_right_arrow_post_link($show = false)
|
---|
88 | {
|
---|
89 | global $xpress_config;
|
---|
90 | $ret = '';
|
---|
91 |
|
---|
92 | if($xpress_config->is_left_postnavi_old){
|
---|
93 | $link_title = $xpress_config->newer_post_link_text;
|
---|
94 | ob_start();
|
---|
95 | if ($xpress_config->is_postnavi_title_disp)
|
---|
96 | next_post_link('%link »');
|
---|
97 | else
|
---|
98 | next_post_link('%link »',$link_title);
|
---|
99 | $ret = ob_get_contents();
|
---|
100 | ob_end_clean();
|
---|
101 | } else {
|
---|
102 | $link_title = $xpress_config->old_post_link_text;
|
---|
103 | ob_start();
|
---|
104 | if ($xpress_config->is_postnavi_title_disp)
|
---|
105 | previous_post_link('%link »');
|
---|
106 | else
|
---|
107 | previous_post_link('%link »',$link_title);
|
---|
108 | $ret = ob_get_contents();
|
---|
109 | ob_end_clean();
|
---|
110 | }
|
---|
111 |
|
---|
112 | if ($xpress_config->is_postnavi_title_disp){
|
---|
113 | $on_mouse_show = $link_title;
|
---|
114 | } else {
|
---|
115 | if($xpress_config->is_left_postnavi_old){
|
---|
116 | ob_start();
|
---|
117 | next_post_link('%link');
|
---|
118 | $on_mouse_show = ob_get_contents();
|
---|
119 | ob_end_clean();
|
---|
120 | } else {
|
---|
121 | ob_start();
|
---|
122 | previous_post_link('%link');
|
---|
123 | $on_mouse_show = ob_get_contents();
|
---|
124 | ob_end_clean();
|
---|
125 | }
|
---|
126 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
127 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
128 | $on_mouse_show = $body_matches[1];
|
---|
129 | }
|
---|
130 | $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
131 |
|
---|
132 | if (empty($show))
|
---|
133 | return $ret;
|
---|
134 | else
|
---|
135 | echo $ret;
|
---|
136 | }
|
---|
137 | // page link
|
---|
138 | function xpress_left_arrow_posts_link($show = false)
|
---|
139 | {
|
---|
140 | global $xpress_config;
|
---|
141 | $ret = '';
|
---|
142 |
|
---|
143 | if($xpress_config->is_left_page_navi_old){
|
---|
144 | $link_title = $xpress_config->old_page_link_text;
|
---|
145 | ob_start();
|
---|
146 | next_posts_link("« $link_title");
|
---|
147 | $ret = ob_get_contents();
|
---|
148 | ob_end_clean();
|
---|
149 | } else {
|
---|
150 | $link_title = $xpress_config->newer_page_link_text;
|
---|
151 | ob_start();
|
---|
152 | previous_posts_link("« $link_title");
|
---|
153 | $ret = ob_get_contents();
|
---|
154 | ob_end_clean();
|
---|
155 | }
|
---|
156 |
|
---|
157 | if (empty($show))
|
---|
158 | return $ret;
|
---|
159 | else
|
---|
160 | echo $ret;
|
---|
161 | }
|
---|
162 |
|
---|
163 | function xpress_right_arrow_posts_link($show = false)
|
---|
164 | {
|
---|
165 | global $xpress_config;
|
---|
166 | $ret = '';
|
---|
167 |
|
---|
168 | if($xpress_config->is_left_page_navi_old){
|
---|
169 | $link_title = $xpress_config->newer_page_link_text;
|
---|
170 | ob_start();
|
---|
171 | previous_posts_link("$link_title »");
|
---|
172 | $ret = ob_get_contents();
|
---|
173 | ob_end_clean();
|
---|
174 | } else {
|
---|
175 | $link_title = $xpress_config->old_page_link_text;
|
---|
176 | ob_start();
|
---|
177 | next_posts_link("$link_title »");
|
---|
178 | $ret = ob_get_contents();
|
---|
179 | ob_end_clean();
|
---|
180 | }
|
---|
181 |
|
---|
182 | if (empty($show))
|
---|
183 | return $ret;
|
---|
184 | else
|
---|
185 | echo $ret;
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 | function xpress_is_author_view_count(){
|
---|
190 | global $xpress_config;
|
---|
191 | return $xpress_config->is_author_view_count;
|
---|
192 | }
|
---|
193 |
|
---|
194 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
195 | {
|
---|
196 | if (function_exists('mb_substr')){
|
---|
197 | $str2 = mb_substr( $str , $start , $length);
|
---|
198 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
199 | } else {
|
---|
200 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | // views count
|
---|
206 | // Set and retrieves post views given a post ID or post object.
|
---|
207 | // Retrieves post views given a post ID or post object.
|
---|
208 | function xpress_post_views_count($post_id=0,$format= '',$show = true) {
|
---|
209 | global $xoops_db,$wpdb;
|
---|
210 |
|
---|
211 | static $post_cache_views;
|
---|
212 |
|
---|
213 | if ( empty($post_id) ) {
|
---|
214 | if ( isset($GLOBALS['post']) )
|
---|
215 | $post_id = $GLOBALS['post']->ID;
|
---|
216 | }
|
---|
217 |
|
---|
218 | $post_id = intval($post_id);
|
---|
219 | if($post_id==0) return null;
|
---|
220 | if(!isset($post_cache_views[$post_id])){
|
---|
221 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
|
---|
222 | $post_views = $xoops_db->get_var($sql);
|
---|
223 | if (!$post_views) {
|
---|
224 | $post_cache_views[$post_id] = 0;
|
---|
225 | }else{
|
---|
226 | $post_cache_views[$post_id] = $post_views;
|
---|
227 | }
|
---|
228 | }
|
---|
229 | $v_count = intval($post_cache_views[$post_id]);
|
---|
230 |
|
---|
231 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
232 |
|
---|
233 | $ret = sprintf($format,$v_count);
|
---|
234 |
|
---|
235 | if ($show) echo $ret; else return $ret;
|
---|
236 | }
|
---|
237 |
|
---|
238 | function set_post_views_count(&$content) {
|
---|
239 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
240 | post_views_counting();
|
---|
241 | }
|
---|
242 | return $content;
|
---|
243 | }
|
---|
244 |
|
---|
245 | // Set post views given a post ID or post object.
|
---|
246 | function post_views_counting($post_id = 0) {
|
---|
247 | global $xoops_db,$wpdb;
|
---|
248 | global $table_prefix;
|
---|
249 | static $views;
|
---|
250 |
|
---|
251 | $post_id = intval($post_id);
|
---|
252 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
253 | $post_id = $GLOBALS['post']->ID;
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | $views_db = get_wp_prefix() . 'views';
|
---|
258 |
|
---|
259 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
260 |
|
---|
261 | if(!xpress_is_author_view_count()){
|
---|
262 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
263 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
264 | if ($current_user_id ==$post_author_id) return null;
|
---|
265 | }
|
---|
266 |
|
---|
267 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
|
---|
268 | $post_views_found = $xoops_db->get_var($sql);
|
---|
269 | if($post_views_found){
|
---|
270 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
|
---|
271 | }else{
|
---|
272 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
273 | }
|
---|
274 | $xoops_db->query($sql);
|
---|
275 | return true;
|
---|
276 | }
|
---|
277 |
|
---|
278 | function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
|
---|
279 | {
|
---|
280 | $content = get_the_content();
|
---|
281 | if($excerpt_size > 0) {
|
---|
282 |
|
---|
283 | $content = apply_filters('the_excerpt_rss', $content);
|
---|
284 | $content = strip_tags($content);
|
---|
285 |
|
---|
286 | if (mb_strlen($content) > $excerpt_size){
|
---|
287 | $content = mb_substr($content, 0, $excerpt_size);
|
---|
288 | $content .= '... ';
|
---|
289 | if (!empty($more_link_text)) $content .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
|
---|
290 | }
|
---|
291 | }
|
---|
292 | if(empty($show)) return $content;
|
---|
293 | echo $content;
|
---|
294 | }
|
---|
295 |
|
---|
296 | function is_xpress_contributor()
|
---|
297 | {
|
---|
298 | global $current_user;
|
---|
299 | get_currentuserinfo();
|
---|
300 | if ($current_user->user_level > 3)
|
---|
301 | return true;
|
---|
302 | else
|
---|
303 | return false;
|
---|
304 | }
|
---|
305 |
|
---|
306 | function xpress_post_new_link($link_title,$display = true)
|
---|
307 | {
|
---|
308 | $output = '<a href="'. get_xpress_url() . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
|
---|
309 | if ($display)
|
---|
310 | echo $output;
|
---|
311 | else
|
---|
312 | return $output;
|
---|
313 | }
|
---|
314 |
|
---|
315 | function xpress_conditional_title($display = true)
|
---|
316 | {
|
---|
317 | $output = __('Main', 'xpressme');
|
---|
318 | if (is_category())
|
---|
319 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
320 | if (is_tag())
|
---|
321 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
322 | if (is_day())
|
---|
323 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
324 | if (is_month())
|
---|
325 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
326 | if (is_year())
|
---|
327 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
328 | if (is_author())
|
---|
329 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
330 | if (is_search())
|
---|
331 | $output = sprintf(__('Search Results of word ‘%s’', 'xpressme'), get_search_query());
|
---|
332 |
|
---|
333 | if ($display)
|
---|
334 | echo $output;
|
---|
335 | else
|
---|
336 | return $output;
|
---|
337 | }
|
---|
338 |
|
---|
339 | ?> |
---|