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 $XPressME;
|
---|
33 | return $XPressME->is_theme_sidebar_disp;
|
---|
34 | }
|
---|
35 |
|
---|
36 | function xpress_left_arrow_post_link($show = false)
|
---|
37 | {
|
---|
38 | global $XPressME;
|
---|
39 | $ret = '';
|
---|
40 |
|
---|
41 | if($XPressME->is_left_postnavi_old){
|
---|
42 | $link_title = $XPressME->old_post_link_text;
|
---|
43 | ob_start();
|
---|
44 | if ($XPressME->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 = $XPressME->newer_post_link_text;
|
---|
52 | ob_start();
|
---|
53 | if ($XPressME->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 ($XPressME->is_postnavi_title_disp){
|
---|
62 | $on_mouse_show = $link_title;
|
---|
63 | } else {
|
---|
64 | if($XPressME->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 $XPressME;
|
---|
90 | $ret = '';
|
---|
91 |
|
---|
92 | if($XPressME->is_left_postnavi_old){
|
---|
93 | $link_title = $XPressME->newer_post_link_text;
|
---|
94 | ob_start();
|
---|
95 | if ($XPressME->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 = $XPressME->old_post_link_text;
|
---|
103 | ob_start();
|
---|
104 | if ($XPressME->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 ($XPressME->is_postnavi_title_disp){
|
---|
113 | $on_mouse_show = $link_title;
|
---|
114 | } else {
|
---|
115 | if($XPressME->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 |
|
---|
138 | function xpress_is_author_view_count(){
|
---|
139 | global $XPressME;
|
---|
140 | return $XPressME->is_author_view_count;
|
---|
141 | }
|
---|
142 |
|
---|
143 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
144 | {
|
---|
145 | if (function_exists('mb_substr')){
|
---|
146 | $str2 = mb_substr( $str , $start , $length);
|
---|
147 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
148 | } else {
|
---|
149 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | // views count
|
---|
155 | // Set and retrieves post views given a post ID or post object.
|
---|
156 | // Retrieves post views given a post ID or post object.
|
---|
157 | function xpress_post_views_count($post_id=0,$format= '',$show = true) {
|
---|
158 | global $xoops_db,$wpdb;
|
---|
159 |
|
---|
160 | static $post_cache_views;
|
---|
161 |
|
---|
162 | if ( empty($post_id) ) {
|
---|
163 | if ( isset($GLOBALS['post']) )
|
---|
164 | $post_id = $GLOBALS['post']->ID;
|
---|
165 | }
|
---|
166 |
|
---|
167 | $post_id = intval($post_id);
|
---|
168 | if($post_id==0) return null;
|
---|
169 | if(!isset($post_cache_views[$post_id])){
|
---|
170 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
|
---|
171 | $post_views = $xoops_db->get_var($sql);
|
---|
172 | if (!$post_views) {
|
---|
173 | $post_cache_views[$post_id] = 0;
|
---|
174 | }else{
|
---|
175 | $post_cache_views[$post_id] = $post_views;
|
---|
176 | }
|
---|
177 | }
|
---|
178 | $v_count = intval($post_cache_views[$post_id]);
|
---|
179 |
|
---|
180 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
181 |
|
---|
182 | $ret = sprintf($format,$v_count);
|
---|
183 |
|
---|
184 | if ($show) echo $ret; else return $ret;
|
---|
185 | }
|
---|
186 |
|
---|
187 | function set_post_views_count(&$content) {
|
---|
188 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
189 | post_views_counting();
|
---|
190 | }
|
---|
191 | return $content;
|
---|
192 | }
|
---|
193 |
|
---|
194 | // Set post views given a post ID or post object.
|
---|
195 | function post_views_counting($post_id = 0) {
|
---|
196 | global $xoops_db,$wpdb;
|
---|
197 | global $table_prefix;
|
---|
198 | static $views;
|
---|
199 |
|
---|
200 | $post_id = intval($post_id);
|
---|
201 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
202 | $post_id = $GLOBALS['post']->ID;
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | $views_db = get_wp_prefix() . 'views';
|
---|
207 |
|
---|
208 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
209 |
|
---|
210 | if(!xpress_is_author_view_count()){
|
---|
211 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
212 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
213 | if ($current_user_id ==$post_author_id) return null;
|
---|
214 | }
|
---|
215 |
|
---|
216 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
|
---|
217 | $post_views_found = $xoops_db->get_var($sql);
|
---|
218 | if($post_views_found){
|
---|
219 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
|
---|
220 | }else{
|
---|
221 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
222 | }
|
---|
223 | $xoops_db->query($sql);
|
---|
224 | return true;
|
---|
225 | }
|
---|
226 |
|
---|
227 | function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
|
---|
228 | {
|
---|
229 | $content = get_the_content();
|
---|
230 | if($excerpt_size > 0) {
|
---|
231 |
|
---|
232 | $content = apply_filters('the_excerpt_rss', $content);
|
---|
233 | $content = strip_tags($content);
|
---|
234 |
|
---|
235 | if (mb_strlen($content) > $excerpt_size){
|
---|
236 | $content = mb_substr($content, 0, $excerpt_size);
|
---|
237 | $content .= '... ';
|
---|
238 | if (!empty($more_link_text)) $content .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
|
---|
239 | }
|
---|
240 | }
|
---|
241 | if(empty($show)) return $content;
|
---|
242 | echo $content;
|
---|
243 | }
|
---|
244 |
|
---|
245 | function is_xpress_contributor()
|
---|
246 | {
|
---|
247 | global $current_user;
|
---|
248 | get_currentuserinfo();
|
---|
249 | if ($current_user->user_level > 3)
|
---|
250 | return true;
|
---|
251 | else
|
---|
252 | return false;
|
---|
253 | }
|
---|
254 |
|
---|
255 | function xpress_post_new_link($link_title,$display = true)
|
---|
256 | {
|
---|
257 | $output = '<a href="'. get_xpress_url() . '/wp-admin/post-new.php' . '">' . $link_title . '</a>';
|
---|
258 | if ($display)
|
---|
259 | echo $output;
|
---|
260 | else
|
---|
261 | return $output;
|
---|
262 | }
|
---|
263 |
|
---|
264 | function xpress_conditional_title($display = true)
|
---|
265 | {
|
---|
266 | $output = __('Main', 'xpress');
|
---|
267 | if (is_category())
|
---|
268 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpress'), single_cat_title('', false));
|
---|
269 | if (is_tag())
|
---|
270 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpress'), single_tag_title('', false) );
|
---|
271 | if (is_day())
|
---|
272 | $output = sprintf(_c('Archive for %s|Daily archive page', 'xpress'), get_the_time(__('F jS, Y', 'xpress')));
|
---|
273 | if (is_month())
|
---|
274 | $output = sprintf(_c('Archive for %s|Monthly archive page', 'xpress'), get_the_time(__('F, Y', 'xpress')));
|
---|
275 | if (is_year())
|
---|
276 | $output = sprintf(_c('Archive for %s|Yearly archive page', 'xpress'), get_the_time(__('Y', 'xpress')));
|
---|
277 | if (is_author())
|
---|
278 | $output = get_author_name( get_query_var('author')); __('Author Archive', 'xpress');
|
---|
279 | if (is_search())
|
---|
280 | $output = __('Search Results', 'xpress');
|
---|
281 |
|
---|
282 | if ($display)
|
---|
283 | echo $output;
|
---|
284 | else
|
---|
285 | return $output;
|
---|
286 | }
|
---|
287 |
|
---|
288 | ?> |
---|