[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 | }
|
---|
[51] | 137 |
|
---|
| 138 | function xpress_is_author_view_count(){
|
---|
[75] | 139 | global $XPressME;
|
---|
| 140 | return $XPressME->is_author_view_count;
|
---|
[51] | 141 | }
|
---|
| 142 |
|
---|
[46] | 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 |
|
---|
[51] | 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) {
|
---|
[56] | 158 | global $xoops_db,$wpdb;
|
---|
[51] | 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])){
|
---|
[56] | 170 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
|
---|
[54] | 171 | $post_views = $xoops_db->get_var($sql);
|
---|
| 172 | if (!$post_views) {
|
---|
[51] | 173 | $post_cache_views[$post_id] = 0;
|
---|
| 174 | }else{
|
---|
[54] | 175 | $post_cache_views[$post_id] = $post_views;
|
---|
[51] | 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) {
|
---|
[96] | 196 | global $xoops_db,$wpdb;
|
---|
[51] | 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 |
|
---|
[96] | 206 | $views_db = get_wp_prefix() . 'views';
|
---|
[51] | 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";
|
---|
[96] | 217 | $post_views_found = $xoops_db->get_var($sql);
|
---|
| 218 | if($post_views_found){
|
---|
[51] | 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 | }
|
---|
[96] | 223 | $xoops_db->query($sql);
|
---|
[51] | 224 | return true;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
[57] | 227 | function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
|
---|
| 228 | {
|
---|
| 229 | $content = get_the_content();
|
---|
| 230 | if($excerpt_size > 0) {
|
---|
[51] | 231 |
|
---|
[57] | 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 |
|
---|
[140] | 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 | {
|
---|
[141] | 266 | $output = __('Main', 'xpressme');
|
---|
[140] | 267 | if (is_category())
|
---|
[141] | 268 | $output = sprintf(__('Archive for the ‘%s’ Category', 'xpressme'), single_cat_title('', false));
|
---|
[140] | 269 | if (is_tag())
|
---|
[141] | 270 | $output = sprintf(__('Posts Tagged ‘%s’', 'xpressme'), single_tag_title('', false) );
|
---|
[140] | 271 | if (is_day())
|
---|
[141] | 272 | $output = sprintf(__('Archive for %s|Daily archive page', 'xpressme'), get_the_time(__('F jS, Y', 'xpressme')));
|
---|
[140] | 273 | if (is_month())
|
---|
[141] | 274 | $output = sprintf(__('Archive for %s|Monthly archive page', 'xpressme'), get_the_time(__('F, Y', 'xpressme')));
|
---|
[140] | 275 | if (is_year())
|
---|
[141] | 276 | $output = sprintf(__('Archive for %s|Yearly archive page', 'xpressme'), get_the_time(__('Y', 'xpressme')));
|
---|
[140] | 277 | if (is_author())
|
---|
[141] | 278 | $output = sprintf(__('Archive for the ‘%s’ Author', 'xpressme'), get_author_name( get_query_var('author')));
|
---|
[140] | 279 | if (is_search())
|
---|
[141] | 280 | $output = __('Search Results', 'xpressme');
|
---|
[140] | 281 |
|
---|
| 282 | if ($display)
|
---|
| 283 | echo $output;
|
---|
| 284 | else
|
---|
| 285 | return $output;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[32] | 288 | ?> |
---|