Changeset 51 for trunk/wp-content/plugins/xpressme/include
- Timestamp:
- Dec 27, 2008, 5:31:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-content/plugins/xpressme/include/custom_functions.php
r49 r51 80 80 return $ret; 81 81 else 82 echo $ret; 82 echo $ret; 83 83 } 84 84 … … 133 133 echo $ret; 134 134 } 135 136 function xpress_is_author_view_count(){ 137 $config = new XPressME_Class(); 138 return $config->is_author_view_count; 139 } 140 135 141 function xpress_substr($str, $start, $length, $trimmarker = '...') 136 142 { … … 208 214 } 209 215 216 // views count 217 // Set and retrieves post views given a post ID or post object. 218 // Retrieves post views given a post ID or post object. 219 function xpress_post_views_count($post_id=0,$format= '',$show = true) { 220 global $table_prefix; 221 222 static $post_cache_views; 223 224 if ( empty($post_id) ) { 225 if ( isset($GLOBALS['post']) ) 226 $post_id = $GLOBALS['post']->ID; 227 } 228 229 $post_id = intval($post_id); 230 if($post_id==0) return null; 231 if(!isset($post_cache_views[$post_id])){ 232 $sql = "SELECT post_views FROM " . $table_prefix . "views" . " WHERE post_id=$post_id"; 233 if (!$result = $GLOBALS["xoopsDB"]->query($sql)) { 234 $post_cache_views[$post_id] = 0; 235 }else{ 236 $row = $GLOBALS["xoopsDB"]->fetchArray($result); 237 $post_cache_views[$post_id] = $row["post_views"]; 238 } 239 } 240 $v_count = intval($post_cache_views[$post_id]); 241 242 if (empty($format)) $format = __('views :%d','xpressme'); 243 244 $ret = sprintf($format,$v_count); 245 246 if ($show) echo $ret; else return $ret; 247 } 248 249 function set_post_views_count(&$content) { 250 if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){ 251 post_views_counting(); 252 } 253 return $content; 254 } 255 256 // Set post views given a post ID or post object. 257 function post_views_counting($post_id = 0) { 258 global $table_prefix; 259 static $views; 260 261 $post_id = intval($post_id); 262 if ( empty($post_id) && isset($GLOBALS['post']) ){ 263 $post_id = $GLOBALS['post']->ID; 264 } 265 266 267 $views_db = $table_prefix . "views"; 268 269 if($post_id==0 || !empty($views[$post_id])) return null; 270 271 if(!xpress_is_author_view_count()){ 272 $current_user_id = $GLOBALS['current_user']->ID; 273 $post_author_id = $GLOBALS['post']->post_author; 274 if ($current_user_id ==$post_author_id) return null; 275 } 276 277 $sql = "SELECT post_views FROM " . $views_db . " WHERE post_id=$post_id"; 278 $exist = false; 279 if ($result = $GLOBALS["xoopsDB"]->query($sql)) { 280 while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){ 281 $exist = true; 282 break; 283 } 284 } 285 if($exist){ 286 $sql = "UPDATE " . $views_db . " SET post_views=post_views+1 WHERE post_id=$post_id"; 287 }else{ 288 $sql = "INSERT INTO " . $views_db . " (post_id, post_views) VALUES ($post_id, 1)"; 289 } 290 if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) { 291 $views[$post_id] = 1; 292 } 293 294 return true; 295 } 296 297 210 298 ?>
Note: See TracChangeset
for help on using the changeset viewer.