Changeset 1174
- Timestamp:
- 02/19/10 13:17:45 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/content/plugins/related_posts/related_posts.php
r857 r1174 154 154 which we need later to show comments and whatnot. */ 155 155 $original_id = $h->post->id; 156 157 /* strip all words less than 4 chars from the title158 and make a space separated string:159 $title = $h->post->title;160 $title_array = explode(' ', $title);161 $new_title = "";162 foreach($title_array as $title_word) {163 if (strlen(trim($title_word)) >= 4) {164 $new_title .= $title_word . " ";165 }166 }*/167 168 // remove hyphens from category safe name169 /*170 if ($h->post->vars['useCategories']) {171 require_once(PLUGINS . 'categories/libs/Category.php');172 $cat = new Category($this->db);173 $cat_safe_name = $cat->getCatSafeName($h->post->vars['category']);174 $category = str_replace("-"," ", $cat_safe_name);175 }*/176 156 177 157 // make the tags a space separated string 178 158 $tags = str_replace(', ', ' ', $h->post->tags); 179 159 $tags = str_replace(',', ' ', $tags); // if no space after commas 180 181 // search terms in a space separated string 182 //$search_terms = trim($new_title) . " " . $tags . " " . $category; 160 $tags = trim($tags); // remove any spaces at the start and end 161 162 // abort of no tags for this post 163 if (!$tags) { echo $this->noRelatedPosts($h); return true; } 183 164 184 165 $search_terms = $tags; … … 199 180 public function showRelatedPosts($h, $search_terms = '', $num_posts = 10) 200 181 { 182 $output = ''; 183 201 184 $results = $this->getRelatedPosts($h, $search_terms, $num_posts); 202 if ($results) 203 { 204 $output = "<h2 id='related_posts_title'>" . $h->lang['related_posts'] . "</h2>"; 205 206 $output .= "<ul class='related_posts'>\n"; 207 foreach ($results as $item) { 208 $h->readPost(0, $item); // needed for the url function 209 $output .= "<li class='related_posts_item'>\n"; 210 if (!isset($item->post_votes_up)) { $item->post_votes_up = ' '; } 211 $output .= "<div class='related_posts_vote vote_color_" . $item->post_status . "'>"; 212 $output .= $item->post_votes_up; 213 $output .= "</div>\n"; 214 $output .= "<div class='related_posts_link related_posts_indent'>\n"; 215 $output .= "<a href='" . $h->url(array('page'=>$item->post_id)) . "' "; 216 $output .= "title='" . $h->lang['related_links_new_tab'] . "'>\n"; 217 $output .= stripslashes(urldecode($item->post_title)); 218 $output .= "</a>"; 219 $output .= "</div>"; 220 $output .= "</li>\n"; 221 } 222 $output .= "</ul>\n"; 185 if (!$results) { 186 // Show "No other posts found with matching tags" 187 return $this->noRelatedPosts($h); 188 } 189 190 $output = "<h2 id='related_posts_title'>" . $h->lang['related_posts'] . "</h2>"; 191 192 $output .= "<ul class='related_posts'>\n"; 193 foreach ($results as $item) { 194 $h->readPost(0, $item); // needed for the url function 195 $output .= "<li class='related_posts_item'>\n"; 196 if (!isset($item->post_votes_up)) { $item->post_votes_up = ' '; } 197 $output .= "<div class='related_posts_vote vote_color_" . $item->post_status . "'>"; 198 $output .= $item->post_votes_up; 199 $output .= "</div>\n"; 200 $output .= "<div class='related_posts_link related_posts_indent'>\n"; 201 $output .= "<a href='" . $h->url(array('page'=>$item->post_id)) . "' "; 202 $output .= "title='" . $h->lang['related_links_new_tab'] . "'>\n"; 203 $output .= stripslashes(urldecode($item->post_title)); 204 $output .= "</a>"; 205 $output .= "</div>"; 206 $output .= "</li>\n"; 223 207 } 224 else 225 { 226 // Show "No other posts found with matching tags" 227 $output = "<div id='related_posts_none'>\n"; 228 $output .= $h->lang['related_links_no_results']; 229 $output .= "</div>\n"; 230 } 208 $output .= "</ul>\n"; 231 209 232 210 return $output; 233 211 } 212 213 214 /** 215 * Message when no related posts found, or no tags present 216 * 217 * @param string $output 218 * return string $output 219 */ 220 public function noRelatedPosts($h, $output = '') 221 { 222 // Commented this out because I doubt anyone will want to see a "No related posts found" message. Handy for testing, though! 223 /* 224 $output .= "<div id='related_posts_none'>\n"; 225 $output .= $h->lang['related_links_no_results']; 226 $output .= "</div>\n"; 227 */ 228 229 return $output; 230 } 231 234 232 235 233 /**
Note: See TracChangeset
for help on using the changeset viewer.