Changeset 16359
- Timestamp:
- 05/09/08 18:59:44 (5 months ago)
- Files:
-
- trunk/midcom/org.maemo.socialnews/config/config.inc (modified) (1 diff)
- trunk/midcom/org.maemo.socialnews/config/manifest.inc (modified) (1 diff)
- trunk/midcom/org.maemo.socialnews/documentation/CHANGES (modified) (1 diff)
- trunk/midcom/org.maemo.socialnews/handler/index.php (modified) (2 diffs)
- trunk/midcom/org.maemo.socialnews/locale/default.en.txt (modified) (2 diffs)
- trunk/midcom/org.maemo.socialnews/locale/default.fi.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/org.maemo.socialnews/config/config.inc
r15991 r16359 9 9 'frontpage_show_main_items' => 3, 10 10 'frontpage_show_abstract_length' => 1000, 11 'frontpage_show_abstract_length_words' => 0, 12 'frontpage_allowed_tags' => '<p><a><img><b><i><strong><pre><ul><li><br>', 11 13 12 14 'frontpage_show_secondary_items' => 7, trunk/midcom/org.maemo.socialnews/config/manifest.inc
r15057 r16359 1 1 'name' => 'org.maemo.socialnews', 2 2 'purecode' => false, 3 'version' => ' 0.1.0beta1',3 'version' => '1.1.5beta1', 4 4 'state' => 'beta', 5 5 'privileges' => array(), trunk/midcom/org.maemo.socialnews/documentation/CHANGES
r11826 r16359 7 7 which might even break existing functionality. 8 8 - All items marked with "+" represent completely new features. 9 10 2008-05-09 rambo 11 + svn merge -r 16354:16358 ../branch-28 12 (RSS feed for latest items, Add more intelligent word count truncater) 9 13 10 14 2007-08-29 bergie trunk/midcom/org.maemo.socialnews/handler/index.php
r15486 r16359 147 147 } 148 148 149 private function word_count_truncater(&$content, &$url) 150 { 151 // Normalize newlines to \n 152 $content = preg_replace("/\n\r|\r\n|\r/", "\n", $content); 153 $content = strip_tags($content, $this->_config->get('frontpage_allowed_tags')); 154 155 $word_limit = $this->_config->get('frontpage_show_abstract_length_words'); 156 // Naive but works 157 $words = count(preg_split('/\b/', strip_tags($content))); 158 if ($words <= $word_limit) 159 { 160 return $content; 161 } 162 163 // The difficult part starts here 164 // In stead of trying parse the HTML tree to get N words while correctly closing all tags we get first paragraph 165 166 $content_matches = array(); 167 if (preg_match("%((^\s+.*?)|(^.*?))(</p>|(\n\s*){2,}|(<br\s*/?>\s*){2,}|\w+\s*<p>)%ms", $content, $content_matches)) 168 { 169 // We found usable "first paragraph", or so we think... 170 $first_paragraph =& $content_matches[1]; 171 172 } 173 else if (strpos($content, "\n")) 174 { 175 //This post doesn't have sensible paragraphs, use raw substr from first newline... 176 $first_paragraph = substr($content, 0, strpos($content, "\n")); 177 } 178 179 if (isset($first_paragraph)) 180 { 181 $first_paragraph_words = count(preg_split('/\b/', strip_tags($first_paragraph))); 182 // Check that our "first paragraph" is of sane size 183 if ($first_paragraph_words <= $word_limit) 184 { 185 $remaining_words = $words - $first_paragraph_words; 186 $ret = $first_paragraph; 187 if ($remaining_words < 1) 188 { 189 return $ret; 190 } 191 $ret .= "<div class='entry-truncated'><a href='{$url}'>" . sprintf($this->_l10n->get('click to read %d more words'), $remaining_words) . "</a></div>\n"; 192 return $ret; 193 } 194 } 195 196 // Fallback, show only "xxx words, click here to read" 197 $ret = "<div class='entry-truncated'><a href='{$url}'>" . sprintf($this->_l10n->get('click to read %d words'), $words) . "</a></div>\n"; 198 return $ret; 199 } 200 149 201 private function generate_caption($data, $getCnt) 150 202 { … … 221 273 if (empty($article->abstract)) 222 274 { 223 $article->abstract = $this->generate_caption($article->content, $this->_config->get('frontpage_show_abstract_length')); 275 if ($this->_config->get('frontpage_show_abstract_length_words') > 0) 276 { 277 $article->abstract = $this->word_count_truncater($article->content, $article->url); 278 } 279 else 280 { 281 $article->abstract = $this->generate_caption($article->content, $this->_config->get('frontpage_show_abstract_length')); 282 } 224 283 } 225 284 else 226 285 { 227 $article->abstract = $this->generate_caption($article->abstract, $this->_config->get('frontpage_show_abstract_length')); 286 if ($this->_config->get('frontpage_show_abstract_length_words') > 0) 287 { 288 $article->abstract = $this->word_count_truncater($article->abstract, $article->url); 289 } 290 else 291 { 292 $article->abstract = $this->generate_caption($article->abstract, $this->_config->get('frontpage_show_abstract_length')); 293 } 228 294 } 229 295 trunk/midcom/org.maemo.socialnews/locale/default.en.txt
r14144 r16359 20 20 ---STRINGEND 21 21 22 ---STRING click to read %d more words 23 Click to read %d more words 24 ---STRINGEND 25 22 26 ---STRING item %s has been registered for score recalculation 23 27 Item %s has been registered for score recalculation. … … 32 36 ---STRINGEND 33 37 38 ---STRING click to read %d words 39 Click to read %d words 40 ---STRINGEND 41 trunk/midcom/org.maemo.socialnews/locale/default.fi.txt
r14144 r16359 3 3 ---CVS $Id$ 4 4 ---LANGUAGE fi 5 6 ---STRING %s to %s by %s with score %d 7 %s kansioon %s, kirjoittanut %s %d pisteellÀ. 8 ---STRINGEND 5 9 6 10 ---STRING %s to %s with score %d … … 14 18 ---STRING best of %s 15 19 %s:n parhaat 20 ---STRINGEND 21 22 ---STRING click to read %d more words 23 Napsauta lukeaksesi %d sanaa lisÀÀ 16 24 ---STRINGEND 17 25 … … 28 36 ---STRINGEND 29 37 30 ---STRING %s to %s by %s with score %d31 %s kansioon %s, kirjoittanut %s %d pisteellÀ. 38 ---STRING click to read %d words 39 Napsauta lukeaksesi %d sanaa 32 40 ---STRINGEND 33 41
