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