Changeset 16359 for trunk/midcom

Show
Ignore:
Timestamp:
05/09/08 18:59:44 (2 months ago)
Author:
rambo
Message:

forward port r16355 & 16358

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/org.maemo.socialnews/config/config.inc

    r15991 r16359  
    99'frontpage_show_main_items' => 3, 
    1010'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>', 
    1113 
    1214'frontpage_show_secondary_items' => 7, 
  • trunk/midcom/org.maemo.socialnews/config/manifest.inc

    r15057 r16359  
    11'name' => 'org.maemo.socialnews', 
    22'purecode' => false, 
    3 'version' => '0.1.0beta1', 
     3'version' => '1.1.5beta1', 
    44'state' => 'beta', 
    55'privileges' => array(), 
  • trunk/midcom/org.maemo.socialnews/documentation/CHANGES

    r11826 r16359  
    77  which might even break existing functionality. 
    88- All items marked with "+" represent completely new features. 
     9 
     102008-05-09 rambo 
     11  + svn merge -r 16354:16358 ../branch-28 
     12    (RSS feed for latest items, Add more intelligent word count truncater) 
    913 
    10142007-08-29 bergie 
  • trunk/midcom/org.maemo.socialnews/handler/index.php

    r15486 r16359  
    147147    } 
    148148 
     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 
    149201    private function generate_caption($data, $getCnt) 
    150202    { 
     
    221273            if (empty($article->abstract)) 
    222274            { 
    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                } 
    224283            } 
    225284            else 
    226285            { 
    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                } 
    228294            } 
    229295 
  • trunk/midcom/org.maemo.socialnews/locale/default.en.txt

    r14144 r16359  
    2020---STRINGEND 
    2121 
     22---STRING click to read %d more words 
     23Click to read %d more words 
     24---STRINGEND 
     25 
    2226---STRING item %s has been registered for score recalculation 
    2327Item %s has been registered for score recalculation. 
     
    3236---STRINGEND 
    3337 
     38---STRING click to read %d words 
     39Click to read %d words 
     40---STRINGEND 
     41 
  • trunk/midcom/org.maemo.socialnews/locale/default.fi.txt

    r14144 r16359  
    33---CVS $Id$ 
    44---LANGUAGE fi 
     5 
     6---STRING %s to %s by %s with score %d 
     7%s kansioon %s, kirjoittanut %s %d pisteellÀ. 
     8---STRINGEND 
    59 
    610---STRING %s to %s with score %d 
     
    1418---STRING best of %s 
    1519%s:n parhaat 
     20---STRINGEND 
     21 
     22---STRING click to read %d more words 
     23Napsauta lukeaksesi %d sanaa lisÀÀ 
    1624---STRINGEND 
    1725 
     
    2836---STRINGEND 
    2937 
    30 ---STRING %s to %s by %s with score %d 
    31 %s kansioon %s, kirjoittanut %s %d pisteellÀ. 
     38---STRING click to read %d words 
     39Napsauta lukeaksesi %d sanaa 
    3240---STRINGEND 
    3341