00001 <?php
00002
00003
00004 lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/net/requestgenerator.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/dao/articlecategory.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00010
00017 class TemplateUtils
00018 {
00019
00020 var $_blogInfo;
00021 var $_rg;
00022 var $_mode;
00023
00028 function TemplateUtils( $blogInfo )
00029 {
00030
00031 $this->_blogInfo = $blogInfo;
00032 }
00033
00040 function htmlTranslate( $string )
00041 {
00042 return htmlspecialchars( $string );
00043 }
00044
00053 function addShowMoreLink( $post, $maxWords, $linkText )
00054 {
00055 $textFilter = new TextFilter();
00056 $result = $textFilter->cutText( $post->getText(), $maxWords );
00057 $config =& Config::getConfig();
00058 if( $result != $post->getText()) {
00059 $rg =& RequestGenerator::getRequestGenerator();
00060 $rg->addParameter( "op", "ViewArticle" );
00061 $rg->addParameter( "articleId", $post->getId());
00062 $rg->addParameter( "blogId", $this->_blogInfo->getId());
00063 $indexPage = $config->getValue( "script_name", "index.php" );
00064 $showMoreLink = " <a href=\"$indexPage".$rg->getRequest()."\">".$linkText."</a>";
00065 $result .= $showMoreLink;
00066 }
00067
00068 return $result;
00069 }
00070
00077 function cutString( $string, $n )
00078 {
00079 return substr( $string, 0, $n );
00080 }
00081
00088 function getLinks( $string )
00089 {
00090 $regexp = "|<a href=\"(.+)\">(.+)</a>|U";
00091 $result = Array();
00092
00093 if( preg_match_all( $regexp, $string, $out, PREG_PATTERN_ORDER )) {
00094 foreach( $out[1] as $link ) {
00095 array_push( $result, $link );
00096 }
00097 }
00098
00099 return $result;
00100 }
00101 }
00102 ?>