[ PHPXref.com ] [ Generated: Sun Jul 20 16:35:25 2008 ] [ bBlog 0.7.6 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/bblog/bBlog_plugins/ -> modifier.readmore.php (source)

   1  <?php
   2  // modifier.readmore.php
   3  function smarty_modifier_readmore($text, $postid, $readmoretext="read more",$wordcount=true) {
   4  
   5      $PREG_TAG = '/<!--\s*(\/?read\s*more:?[^-]*)\s*-->/';
   6      $PREG_READMORE_START = '/^read\s*more/';
   7      $PREG_READMORE_END = '/^\s*\/read\s*more\s*/';    
   8  
   9      global $bBlog;
  10      $link = $bBlog->_get_entry_permalink($postid);
  11  
  12      $textar = preg_split($PREG_TAG,$text,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
  13      $text = "";
  14  
  15      $cuttingout = false;
  16      $i = -1;
  17  
  18      foreach ( $textar as $textbit ) {
  19        $i++;
  20        $textbit = trim($textbit);
  21  
  22        if ( preg_match($PREG_READMORE_START,$textbit) ) {
  23  
  24          // check for nested cuts
  25          if($cuttingout)
  26            continue;
  27  
  28          $text .= '<a href="'.$link.'">';
  29          // fix default string
  30          if( !strpos($textbit,':') ) {
  31            $text .= $readmoretext;
  32          } else {
  33            $text .= substr($textbit,strpos($textbit,':')+1);
  34          }
  35          $text .= '</a>';
  36      
  37          // print wordcount
  38          if($wordcount) {
  39            $text .= '&nbsp;<em>('.count(explode(' ',$textar[$i+1])).' words)</em>';
  40          }
  41  
  42          $cuttingout = true;
  43          continue;
  44        }
  45        else if ( preg_match($PREG_READMORE_END,$textbit) ) {
  46          $cuttingout = false;
  47          continue;
  48        }
  49        else if (!$cuttingout) {
  50          $text.=$textbit;
  51        }
  52  
  53      } // end foreach
  54  
  55    return $text;
  56  }
  57  
  58  function identify_modifier_readmore () {
  59    return array (
  60      'name'           =>'readmore',
  61      'type'           =>'smarty_modifier',
  62      'nicename'       =>'Read More',
  63      'description'    =>'Chops a post short with a readmore link',
  64      'authors'        =>'Tim Lucas <t.lucas-toolmantim.com>',
  65      'licence'        =>'GPL',
  66      'help'         =>'Usage:<br>
  67  <p>Use the readmore modifier on the {$post.body} tag, to cut off text at the HTML
  68  comment &lt;!-- readmore --&gt; .</p>
  69  <p>There are 4 parameters, <strong>post id</strong> (number), <strong>default text</strong> (string), 
  70  <strong>word count</strong> (true/false) and <strong>word count text</strong> (string).</p>
  71  <p><i>postid</i> is the id of the post (used to create the link) - required.</p>
  72  <p><i>default text</i> is the default text used for the readmore link (default is "Read more") - optional.</p>
  73  <p><i>word count</i> is a toggle to print the word count of the cutout text - optional.</p>
  74  <p><i>word count text</i> allows you to localise the word count (default is "words") - optional.</p>
  75  <p>You can cut sections of text by using &lt;!-- readmore --&gt; in conjuction
  76  with &lt!-- /readmore --&gt;.
  77  <p><strong>Example template usage:</strong></p>
  78  <p>{$post.body|readmore:$post.postid}</p>
  79  <p>{$post.body|readmore:$post.postid:"Read more..."}</p>
  80  <p>{$post.body|readmore:$post.postid:"Read more...":false}</p>
  81  <p>{$post.body|readmore:$post.postid:"keep on reading":true:"whispers"}</p>
  82  <p><strong>Example post usage:</strong></p>
  83  <p><i>Cutting the post off and using the default readmore text</i>:</p>
  84  <p>My amazing story<br/>
  85  &lt;!-- readmore --&gt;<br/>
  86  of my amazing story... it\'s amaaazing</p>
  87  <p><i>Cutting a section of text out and replacing with own text link</i>:</p>
  88  <p>My amazing story<br/>
  89  &lt;!-- readmore: read it now! --&gt;<br/>
  90  This is my hidden story<br/>
  91  &lt;!-- /readmore --&gt;<br/>
  92  And back to the post again.</p>');
  93  }
  94  
  95  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]