[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(){
|
---|
[75] | 32 | global $XPressME;
|
---|
| 33 | return $XPressME->is_theme_sidebar_disp;
|
---|
[32] | 34 | }
|
---|
| 35 |
|
---|
| 36 | function xpress_left_arrow_post_link($show = false)
|
---|
| 37 | {
|
---|
[75] | 38 | global $XPressME;
|
---|
[33] | 39 | $ret = '';
|
---|
| 40 |
|
---|
[75] | 41 | if($XPressME->is_left_postnavi_old){
|
---|
| 42 | $link_title = $XPressME->old_post_link_text;
|
---|
[32] | 43 | ob_start();
|
---|
[75] | 44 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 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 {
|
---|
[75] | 51 | $link_title = $XPressME->newer_post_link_text;
|
---|
[32] | 52 | ob_start();
|
---|
[75] | 53 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 54 | next_post_link('« %link');
|
---|
| 55 | else
|
---|
| 56 | next_post_link('« %link',$link_title);
|
---|
| 57 | $ret = ob_get_contents();
|
---|
| 58 | ob_end_clean();
|
---|
| 59 | }
|
---|
[33] | 60 |
|
---|
[75] | 61 | if ($XPressME->is_postnavi_title_disp){
|
---|
[33] | 62 | $on_mouse_show = $link_title;
|
---|
| 63 | } else {
|
---|
[75] | 64 | if($XPressME->is_left_postnavi_old){
|
---|
[33] | 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);
|
---|
[32] | 80 |
|
---|
| 81 | if (empty($show))
|
---|
| 82 | return $ret;
|
---|
| 83 | else
|
---|
[51] | 84 | echo $ret;
|
---|
[32] | 85 | }
|
---|
| 86 |
|
---|
| 87 | function xpress_right_arrow_post_link($show = false)
|
---|
| 88 | {
|
---|
[75] | 89 | global $XPressME;
|
---|
[32] | 90 | $ret = '';
|
---|
| 91 |
|
---|
[75] | 92 | if($XPressME->is_left_postnavi_old){
|
---|
| 93 | $link_title = $XPressME->newer_post_link_text;
|
---|
[32] | 94 | ob_start();
|
---|
[75] | 95 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 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 {
|
---|
[75] | 102 | $link_title = $XPressME->old_post_link_text;
|
---|
[32] | 103 | ob_start();
|
---|
[75] | 104 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 105 | previous_post_link('%link »');
|
---|
| 106 | else
|
---|
| 107 | previous_post_link('%link »',$link_title);
|
---|
| 108 | $ret = ob_get_contents();
|
---|
| 109 | ob_end_clean();
|
---|
| 110 | }
|
---|
[33] | 111 |
|
---|
[75] | 112 | if ($XPressME->is_postnavi_title_disp){
|
---|
[33] | 113 | $on_mouse_show = $link_title;
|
---|
| 114 | } else {
|
---|
[75] | 115 | if($XPressME->is_left_postnavi_old){
|
---|
[33] | 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);
|
---|
[32] | 131 |
|
---|
| 132 | if (empty($show))
|
---|
| 133 | return $ret;
|
---|
| 134 | else
|
---|
| 135 | echo $ret;
|
---|
| 136 | }
|
---|
[143] | 137 | // page link
|
---|
| 138 | function xpress_left_arrow_posts_link($show = false)
|
---|
| 139 | {
|
---|
| 140 | global $XPressME;
|
---|
| 141 | $ret = '';
|
---|
| 142 |
|
---|
| 143 | if($XPressME->is_left_page_navi_old){
|
---|
| 144 | $link_title = $XPressME->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 = $XPressME->newer_page_link_text;
|
---|
| 151 | ob_start();
|
---|
| 152 | previous_posts_link("« $link_title");
|
---|
| 153 | $ret = ob_get_contents();
|
---|
| 154 | ob_end_clean();
|
---|
| 155 | }
|
---|
[51] | 156 |
|
---|
[143] | 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 $XPressME;
|
---|
| 166 | $ret = '';
|
---|
| 167 |
|
---|
| 168 | if($XPressME->is_left_page_navi_old){
|
---|
| 169 | $link_title = $XPressME->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 = $XPressME->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 |
|
---|
[51] | 189 | function xpress_is_author_view_count(){
|
---|
[75] | 190 | global $XPressME;
|
---|
| 191 | return $XPressME->is_author_view_count;
|
---|
[51] | 192 | }
|
---|
| 193 |
|
---|
[46] | 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 |
|
---|
[51] | 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) {
|
---|
[56] | 209 | global $xoops_db,$wpdb;
|
---|
[51] | 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])){
|
---|
[56] | 221 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
|
---|
[54] | 222 | $post_views = $xoops_db->get_var($sql);
|
---|
| 223 | if (!$post_views) {
|
---|
[51] | 224 | $post_cache_views[$post_id] = 0;
|
---|
| 225 | }else{
|
---|
[54] | 226 | $post_cache_views[$post_id] = $post_views;
|
---|
[51] | 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) {
|
---|
[96] | 247 | global $xoops_db,$wpdb;
|
---|
[51] | 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 |
|
---|
[96] | 257 | $views_db = get_wp_prefix() . 'views';
|
---|
[51] | 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";
|
---|
[96] | 268 | $post_views_found = $xoops_db->get_var($sql);
|
---|
| 269 | if($post_views_found){
|
---|
[51] | 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 | }
|
---|
[96] | 274 | $xoops_db->query($sql);
|
---|
[51] | 275 | return true;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
[57] | 278 | function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
|
---|
| 279 | {
|
---|
| 280 | $content = get_the_content();
|
---|
| 281 | if($excerpt_size > 0) {
|
---|
[51] | 282 |
|
---|
[57] | 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 |
|
---|
[140] | 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 | {
|
---|
[141] | 317 | $output = __('Main', 'xpressme');
|
---|
[140] | 318 | if (is_category())
|
---|
[141] | 319 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
[140] | 320 | if (is_tag())
|
---|
[141] | 321 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
[140] | 322 | if (is_day())
|
---|
[141] | 323 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
[140] | 324 | if (is_month())
|
---|
[141] | 325 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
[140] | 326 | if (is_year())
|
---|
[141] | 327 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
[140] | 328 | if (is_author())
|
---|
[141] | 329 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
[140] | 330 | if (is_search())
|
---|
[143] | 331 | $output = sprintf(__('Search Results of word ‘%s’', 'xpressme'), get_search_query());
|
---|
[140] | 332 |
|
---|
| 333 | if ($display)
|
---|
| 334 | echo $output;
|
---|
| 335 | else
|
---|
| 336 | return $output;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
[32] | 339 | ?> |
---|