[32] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | function xpress_credit($show = false)
|
---|
| 4 | {
|
---|
| 5 | global $xoopsModule,$wp_version;
|
---|
| 6 |
|
---|
| 7 | $ret = '<a href="http://www.toemon.com"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xoopsModule->getInfo('version'),$xoopsModule->getInfo('codename')) .'</a>';
|
---|
| 8 | if (strstr($wp_version,'ME')){
|
---|
| 9 | $ret .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
| 10 | } else {
|
---|
| 11 | $ret .= '(included <a href="http://ja.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | if (empty($show))
|
---|
| 15 | return $ret;
|
---|
| 16 | else
|
---|
| 17 | echo $ret;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | function xpress_convert_time($show = false)
|
---|
| 21 | {
|
---|
| 22 | $ret = timer_stop(0) .'sec. ';
|
---|
| 23 | if (empty($show))
|
---|
| 24 | return $ret;
|
---|
| 25 | else
|
---|
| 26 | echo $ret;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | function xpress_is_theme_sidebar_disp(){
|
---|
[75] | 30 | global $XPressME;
|
---|
| 31 | return $XPressME->is_theme_sidebar_disp;
|
---|
[32] | 32 | }
|
---|
| 33 |
|
---|
| 34 | function xpress_left_arrow_post_link($show = false)
|
---|
| 35 | {
|
---|
[75] | 36 | global $XPressME;
|
---|
[33] | 37 | $ret = '';
|
---|
| 38 |
|
---|
[75] | 39 | if($XPressME->is_left_postnavi_old){
|
---|
| 40 | $link_title = $XPressME->old_post_link_text;
|
---|
[32] | 41 | ob_start();
|
---|
[75] | 42 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 43 | previous_post_link('« %link');
|
---|
| 44 | else
|
---|
| 45 | previous_post_link('« %link',$link_title);
|
---|
| 46 | $ret = ob_get_contents();
|
---|
| 47 | ob_end_clean();
|
---|
| 48 | } else {
|
---|
[75] | 49 | $link_title = $XPressME->newer_post_link_text;
|
---|
[32] | 50 | ob_start();
|
---|
[75] | 51 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 52 | next_post_link('« %link');
|
---|
| 53 | else
|
---|
| 54 | next_post_link('« %link',$link_title);
|
---|
| 55 | $ret = ob_get_contents();
|
---|
| 56 | ob_end_clean();
|
---|
| 57 | }
|
---|
[33] | 58 |
|
---|
[75] | 59 | if ($XPressME->is_postnavi_title_disp){
|
---|
[33] | 60 | $on_mouse_show = $link_title;
|
---|
| 61 | } else {
|
---|
[75] | 62 | if($XPressME->is_left_postnavi_old){
|
---|
[33] | 63 | ob_start();
|
---|
| 64 | previous_post_link('%link');
|
---|
| 65 | $on_mouse_show = ob_get_contents();
|
---|
| 66 | ob_end_clean();
|
---|
| 67 | } else {
|
---|
| 68 | ob_start();
|
---|
| 69 | next_post_link('%link');
|
---|
| 70 | $on_mouse_show = ob_get_contents();
|
---|
| 71 | ob_end_clean();
|
---|
| 72 | }
|
---|
| 73 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
| 74 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
| 75 | $on_mouse_show = $body_matches[1];
|
---|
| 76 | }
|
---|
| 77 | $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
[32] | 78 |
|
---|
| 79 | if (empty($show))
|
---|
| 80 | return $ret;
|
---|
| 81 | else
|
---|
[51] | 82 | echo $ret;
|
---|
[32] | 83 | }
|
---|
| 84 |
|
---|
| 85 | function xpress_right_arrow_post_link($show = false)
|
---|
| 86 | {
|
---|
[75] | 87 | global $XPressME;
|
---|
[32] | 88 | $ret = '';
|
---|
| 89 |
|
---|
[75] | 90 | if($XPressME->is_left_postnavi_old){
|
---|
| 91 | $link_title = $XPressME->newer_post_link_text;
|
---|
[32] | 92 | ob_start();
|
---|
[75] | 93 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 94 | next_post_link('%link »');
|
---|
| 95 | else
|
---|
| 96 | next_post_link('%link »',$link_title);
|
---|
| 97 | $ret = ob_get_contents();
|
---|
| 98 | ob_end_clean();
|
---|
| 99 | } else {
|
---|
[75] | 100 | $link_title = $XPressME->old_post_link_text;
|
---|
[32] | 101 | ob_start();
|
---|
[75] | 102 | if ($XPressME->is_postnavi_title_disp)
|
---|
[32] | 103 | previous_post_link('%link »');
|
---|
| 104 | else
|
---|
| 105 | previous_post_link('%link »',$link_title);
|
---|
| 106 | $ret = ob_get_contents();
|
---|
| 107 | ob_end_clean();
|
---|
| 108 | }
|
---|
[33] | 109 |
|
---|
[75] | 110 | if ($XPressME->is_postnavi_title_disp){
|
---|
[33] | 111 | $on_mouse_show = $link_title;
|
---|
| 112 | } else {
|
---|
[75] | 113 | if($XPressME->is_left_postnavi_old){
|
---|
[33] | 114 | ob_start();
|
---|
| 115 | next_post_link('%link');
|
---|
| 116 | $on_mouse_show = ob_get_contents();
|
---|
| 117 | ob_end_clean();
|
---|
| 118 | } else {
|
---|
| 119 | ob_start();
|
---|
| 120 | previous_post_link('%link');
|
---|
| 121 | $on_mouse_show = ob_get_contents();
|
---|
| 122 | ob_end_clean();
|
---|
| 123 | }
|
---|
| 124 | $pattern = "<a[^>]*?>(.*)<\/a>";
|
---|
| 125 | preg_match("/".$pattern."/s", $on_mouse_show, $body_matches);
|
---|
| 126 | $on_mouse_show = $body_matches[1];
|
---|
| 127 | }
|
---|
| 128 | $ret = str_replace('">','" title="'.$on_mouse_show . '">' , $ret);
|
---|
[32] | 129 |
|
---|
| 130 | if (empty($show))
|
---|
| 131 | return $ret;
|
---|
| 132 | else
|
---|
| 133 | echo $ret;
|
---|
| 134 | }
|
---|
[51] | 135 |
|
---|
| 136 | function xpress_is_author_view_count(){
|
---|
[75] | 137 | global $XPressME;
|
---|
| 138 | return $XPressME->is_author_view_count;
|
---|
[51] | 139 | }
|
---|
| 140 |
|
---|
[46] | 141 | function xpress_substr($str, $start, $length, $trimmarker = '...')
|
---|
| 142 | {
|
---|
| 143 | if (function_exists('mb_substr')){
|
---|
| 144 | $str2 = mb_substr( $str , $start , $length);
|
---|
| 145 | return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
|
---|
| 146 | } else {
|
---|
| 147 | return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | // xoops db
|
---|
| 151 | function get_xpress_dir_path()
|
---|
| 152 | {
|
---|
| 153 | return ABSPATH;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | function get_xpress_dir_name()
|
---|
| 157 | {
|
---|
| 158 | return basename(ABSPATH);
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | function get_wp_prefix_only()
|
---|
| 162 | {
|
---|
| 163 | $dir_name = get_xpress_dir_name();
|
---|
| 164 | $prefix = $dir_name;
|
---|
| 165 | if ($prefix == 'wordpress') $prefix = 'wp';
|
---|
| 166 |
|
---|
| 167 | $prefix = $prefix . '_';
|
---|
| 168 | return $prefix;
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | function get_xoops_prefix()
|
---|
| 172 | {
|
---|
[56] | 173 | $ret =XOOPS_DB_PREFIX . '_';
|
---|
[46] | 174 | return $ret;
|
---|
| 175 | }
|
---|
[56] | 176 | function get_wp_prefix()
|
---|
| 177 | {
|
---|
| 178 | $prefix = get_xoops_prefix() . get_wp_prefix_only();
|
---|
| 179 | return $prefix;
|
---|
| 180 | }
|
---|
[46] | 181 |
|
---|
| 182 | function get_xpress_modid()
|
---|
| 183 | {
|
---|
| 184 | global $xoops_db;
|
---|
| 185 |
|
---|
| 186 | $modulename = get_xpress_dir_name();
|
---|
| 187 | $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
|
---|
| 188 | $mid = $xoops_db->get_var($sql);
|
---|
| 189 | return $mid;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | function block_cache_refresh()
|
---|
| 193 | {
|
---|
| 194 | global $xoops_db;
|
---|
| 195 | $mid = get_xpress_modid();
|
---|
| 196 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
|
---|
| 197 | $blocks = $xoops_db->get_results($sql);
|
---|
| 198 | $mydirname = get_xpress_dir_name();
|
---|
| 199 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 | foreach($blocks as $block){
|
---|
| 203 | $func_file = $block->func_file;
|
---|
| 204 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
| 205 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
| 206 | $cache_title = str_replace(".php", "", $func_file);
|
---|
| 207 | $blockID = $block->bid;
|
---|
| 208 | $options = explode("|", $block->options);
|
---|
| 209 |
|
---|
| 210 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
| 211 | require_once $block_theme_file;
|
---|
| 212 | $block_render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
[49] | 213 | $xml['block'] = $block_render;
|
---|
| 214 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
|
---|
[46] | 215 | }
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[51] | 218 | // views count
|
---|
| 219 | // Set and retrieves post views given a post ID or post object.
|
---|
| 220 | // Retrieves post views given a post ID or post object.
|
---|
| 221 | function xpress_post_views_count($post_id=0,$format= '',$show = true) {
|
---|
[56] | 222 | global $xoops_db,$wpdb;
|
---|
[51] | 223 |
|
---|
| 224 | static $post_cache_views;
|
---|
| 225 |
|
---|
| 226 | if ( empty($post_id) ) {
|
---|
| 227 | if ( isset($GLOBALS['post']) )
|
---|
| 228 | $post_id = $GLOBALS['post']->ID;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | $post_id = intval($post_id);
|
---|
| 232 | if($post_id==0) return null;
|
---|
| 233 | if(!isset($post_cache_views[$post_id])){
|
---|
[56] | 234 | $sql = "SELECT post_views FROM " . get_wp_prefix() . "views" . " WHERE post_id=$post_id";
|
---|
[54] | 235 | $post_views = $xoops_db->get_var($sql);
|
---|
| 236 | if (!$post_views) {
|
---|
[51] | 237 | $post_cache_views[$post_id] = 0;
|
---|
| 238 | }else{
|
---|
[54] | 239 | $post_cache_views[$post_id] = $post_views;
|
---|
[51] | 240 | }
|
---|
| 241 | }
|
---|
| 242 | $v_count = intval($post_cache_views[$post_id]);
|
---|
| 243 |
|
---|
| 244 | if (empty($format)) $format = __('views :%d','xpressme');
|
---|
| 245 |
|
---|
| 246 | $ret = sprintf($format,$v_count);
|
---|
| 247 |
|
---|
| 248 | if ($show) echo $ret; else return $ret;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | function set_post_views_count(&$content) {
|
---|
| 252 | if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
|
---|
| 253 | post_views_counting();
|
---|
| 254 | }
|
---|
| 255 | return $content;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | // Set post views given a post ID or post object.
|
---|
| 259 | function post_views_counting($post_id = 0) {
|
---|
| 260 | global $table_prefix;
|
---|
| 261 | static $views;
|
---|
| 262 |
|
---|
| 263 | $post_id = intval($post_id);
|
---|
| 264 | if ( empty($post_id) && isset($GLOBALS['post']) ){
|
---|
| 265 | $post_id = $GLOBALS['post']->ID;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | $views_db = $table_prefix . "views";
|
---|
| 270 |
|
---|
| 271 | if($post_id==0 || !empty($views[$post_id])) return null;
|
---|
| 272 |
|
---|
| 273 | if(!xpress_is_author_view_count()){
|
---|
| 274 | $current_user_id = $GLOBALS['current_user']->ID;
|
---|
| 275 | $post_author_id = $GLOBALS['post']->post_author;
|
---|
| 276 | if ($current_user_id ==$post_author_id) return null;
|
---|
| 277 | }
|
---|
| 278 |
|
---|
| 279 | $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id";
|
---|
| 280 | $exist = false;
|
---|
| 281 | if ($result = $GLOBALS["xoopsDB"]->query($sql)) {
|
---|
| 282 | while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){
|
---|
| 283 | $exist = true;
|
---|
| 284 | break;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | if($exist){
|
---|
| 288 | $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id";
|
---|
| 289 | }else{
|
---|
| 290 | $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)";
|
---|
| 291 | }
|
---|
| 292 | if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) {
|
---|
| 293 | $views[$post_id] = 1;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | return true;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[57] | 299 | function xpress_the_content($more_link_text = '',$excerpt_size = 0,$show = true)
|
---|
| 300 | {
|
---|
| 301 | $content = get_the_content();
|
---|
| 302 | if($excerpt_size > 0) {
|
---|
[51] | 303 |
|
---|
[57] | 304 | $content = apply_filters('the_excerpt_rss', $content);
|
---|
| 305 | $content = strip_tags($content);
|
---|
| 306 |
|
---|
| 307 | if (mb_strlen($content) > $excerpt_size){
|
---|
| 308 | $content = mb_substr($content, 0, $excerpt_size);
|
---|
| 309 | $content .= '... ';
|
---|
| 310 | if (!empty($more_link_text)) $content .= '<p align="center"><a href="'. get_permalink() . "\">".$more_link_text .'</a></p>';
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | if(empty($show)) return $content;
|
---|
| 314 | echo $content;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
[32] | 317 | ?> |
---|