Changeset 36
- Timestamp:
- 03/14/06 14:54:24 (2 years ago)
- Files:
-
- trunk/public_html/akarru.lib/memes.php (modified) (10 diffs)
- trunk/smarty/templates/memes_grid.tpl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/public_html/akarru.lib/memes.php
r30 r36 44 44 function get_memes($page=0, $sort='', $limit=0, $show_sql=0) 45 45 { 46 $this->memes_count = $this->db->fetch_scalar('select count(*) n from posts p where p.votes >= '.$this->promote_threshold); 46 $this->db->do_query('select SQL_CALC_FOUND_ROWS * from posts p where p.votes >= '.$this->promote_threshold); 47 $this->memes_count = $this->db->fetch_scalar('Select FOUND_ROWS()'); 47 48 if ($this->memes_count <= 0) { 48 49 return array(); … … 51 52 52 53 $sql = 'select p.title,p.is_micro_content,p.content,p.date_posted,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,p.rank, '; 53 $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id,votes as vote_count, co unt(pcom.ID)as comment_count ';54 $sql .= 'from posts p, post_cats pc, users u left join post_comments pcom on pcom.post_id=p.ID';54 $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id,votes as vote_count, comments as comment_count '; 55 $sql .= 'from posts p, post_cats pc, users u '; 55 56 $sql .= 'where pc.ID=p.category and u.ID=p.submitted_user_id and p.votes >= '.$this->promote_threshold; 56 57 $sql .= " group by p.title,p.content,p.date_posted,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username "; … … 62 63 else 63 64 { 64 $sql.=" order by rank desc, vote _countdesc ";65 $sql.=" order by rank desc, votes desc "; 65 66 } 66 67 if($page!=0) … … 81 82 function get_meme($id) 82 83 { 83 $sql = 'select p.title,p.content,p.date_posted,p.date_promo,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, co unt(pcom.ID) as comment_count from posts p, post_cats pc, users u left join post_comments pcom on pcom.post_id=p.IDwhere pc.ID=p.category and u.ID=p.submitted_user_id ';84 $sql = 'select p.title,p.content,p.date_posted,p.date_promo,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, comments as comment_count from posts p, post_cats pc, users u where pc.ID=p.category and u.ID=p.submitted_user_id '; 84 85 $sql .= ' and p.ID='.$id; 85 $sql .= " group by p.title,p.content,p.date_posted,p.category,p.url,p.submitted_user_id,p.ID,pc.cat_title,u.username ";86 86 $result = $this->db->fetch_object($sql); 87 $result->small_gravatar = get_gravatar($bm_url, $ comment->email, 16);87 $result->small_gravatar = get_gravatar($bm_url, $result->email, 16); 88 88 return $result; 89 89 } … … 121 121 { 122 122 $sql = 'select p.title,p.is_micro_content,p.content,p.date_posted,p.rank,p.clicks,p.category,p.url,p.submitted_user_id,p.ID, '; 123 $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count ';123 $sql .= 'pc.cat_title,u.username, u.email, pc.ID as cat_id, p.votes as vote_count, p.comments as comment_count '; 124 124 $sql .= ' from posts p, post_cats pc, users u where pc.ID=p.category and u.ID=p.submitted_user_id '; 125 125 $sql .= ' and p.votes < '.$this->promote_threshold.' '; … … 184 184 } 185 185 186 187 // calculate gravatar and if user voted for this meme 186 188 function filter_result($sql) 187 189 { … … 192 194 { 193 195 $meme->small_gravatar = get_gravatar($bm_url, $meme->email, 16); 196 $meme_id = $meme->ID; 197 $uid = $this->user_id; 198 $meme->voted = $this->db->fetch_scalar("select count(*) from post_votes where post_id = $meme_id and user_id = $uid "); 194 199 $result[] = $meme; 195 200 } … … 413 418 { 414 419 $meme = $this->get_meme($meme_id); 415 $ sql = "select votes from posts where ID = $meme_id ";416 $n v = $this->db->fetch_scalar($sql);420 $nv = $this->db->fetch_scalar("select count(*) from post_votes where post_id = $meme_id "); 421 $nc = $this->db->fetch_scalar("select count(*) from post_comments where post_id = $meme_id "); 417 422 $now = time(); 418 423 $hours_posted = ceil(($now - $meme->date_posted)/3600); … … 434 439 435 440 if ($update_promo_date) { 436 $sql = "update posts set rank = $rank, date_promo = $now where ID = $meme_id"; 441 $sql = "update posts set rank = $rank, date_promo = $now, votes = $nv, comments = $nc where ID = $meme_id"; 442 437 443 } 438 444 else { 439 $sql = "update posts set rank = $rank where ID = $meme_id";445 $sql = "update posts set rank = $rank, votes = $nv, comments = $nc where ID = $meme_id"; 440 446 } 441 447 $this->db->execute($sql); … … 488 494 function promote_all() 489 495 { 490 $sql = 'select p.ID from posts p join post_votes pv on pv.post_id = p.ID group by p.ID';496 $sql = 'select ID from posts '; 491 497 $memes = $this->db->fetch($sql); 492 498 foreach ($memes as $meme) { trunk/smarty/templates/memes_grid.tpl
r26 r36 13 13 {$meme->vote_count} 14 14 </h3> 15 {if $meme->voted <= 0} 15 16 <p>{#votes_label#}</p> 17 {/if} 16 18 <div class="vote-class"> 17 19 {if $logged_in } 20 {if $meme->voted <= 0} 18 21 <a class="vote-class" href="#vote_count_{$meme->ID}" onclick="update_vote_div('vote_count_{$meme->ID}','{$logged_userid}')"> 19 22 <img src="styles/img/meme-votar.png" border="0" alt="{#votes_label#}" /></a> 23 {/if} 20 24 {else} 21 25 <a class="vote-class" href="#vote_count_{$meme->ID}" onclick="update_vote_div('vote_count_{$meme->ID}','0')"><img src="styles/img/meme-votar.png" border="0" alt="{#votes_label#}" /></a>
