Exemplo n.º 1
0
if (is_array($this->SearchResults) && count($this->SearchResults) > 0) {
    foreach ($this->SearchResults as $Key => $Row) {
        $Row = (object) $Row;
        $this->EventArguments['Row'] = $Row;
        ?>
	<li class="Item">
		<?php 
        $this->FireEvent('BeforeItemContent');
        ?>
		<div class="ItemContent">
			<?php 
        echo Anchor(Gdn_Format::Text($Row->Title), $Row->Url, 'Title');
        ?>
			<div class="Message Excerpt"><?php 
        if ($SearchTerm) {
            echo MarkString($SearchTerm, $Row->Summary);
        } else {
            echo $Row->Summary;
        }
        ?>
</div>
         <div class="Item-Footer">
            <?php 
        echo UserPhoto($Row, array('Size' => 'Small')) . ' ' . UserAnchor($Row);
        ?>
            <span class="Meta"><span class="MItem">
               <?php 
        echo Anchor(Gdn_Format::Date($Row->DateInserted, 'html'), $Row->Url);
        if (isset($Row->CategoryID)) {
            $Category = CategoryModel::Categories($Row->CategoryID);
            if ($Category) {
Exemplo n.º 2
0
 function searchExcerpt($PlainText, $SearchTerms, $Length = 200, $Mark = true)
 {
     if (empty($SearchTerms)) {
         return substrWord($PlainText, 0, $Length);
     }
     if (is_string($SearchTerms)) {
         $SearchTerms = preg_split('`[\\s|-]+`i', $SearchTerms);
     }
     // Split the string into lines.
     $Lines = explode("\n", $PlainText);
     // Find the first line that includes a search term.
     foreach ($Lines as $i => &$Line) {
         $Line = trim($Line);
         if (!$Line) {
             continue;
         }
         foreach ($SearchTerms as $Term) {
             if (!$Term) {
                 continue;
             }
             if (($Pos = mb_stripos($Line, $Term)) !== false) {
                 $Line = substrWord($Line, $Term, $Length);
                 if ($Mark) {
                     return MarkString($SearchTerms, $Line);
                 } else {
                     return $Line;
                 }
             }
         }
     }
     // No line was found so return the first non-blank line.
     foreach ($Lines as $Line) {
         if ($Line) {
             return SliceString($Line, $Length);
         }
     }
     return '';
 }
Exemplo n.º 3
0
 function SearchExcerpt($PlainText, $SearchTerms, $Length = 200, $Mark = true)
 {
     if (empty($SearchTerms)) {
         return substrWord($PlainText, 0, $Length);
     }
     if (is_string($SearchTerms)) {
         $SearchTerms = preg_split('`[\\s|-]+`i', $SearchTerms);
     }
     // Split the string into lines.
     $Lines = explode("\n", $PlainText);
     // Find the first line that includes a search term.
     foreach ($Lines as $i => &$Line) {
         $Line = trim($Line);
         if (!$Line) {
             continue;
         }
         foreach ($SearchTerms as $Term) {
             if (!$Term) {
                 continue;
             }
             if (($Pos = mb_stripos($Line, $Term)) !== FALSE) {
                 $Line = substrWord($Line, $Term, $Length);
                 //            if ($Pos + mb_strlen($Term) > $Length) {
                 //               $St = -(strlen($Line) - ($Pos - $Length / 4));
                 //               $Pos2 = strrpos($Line, ' ', $St);
                 //               if ($Pos2 !== FALSE)
                 //                  $Line = '…'.substrWord($Line, $Pos2, $Length, "!!!");
                 //               else
                 //                  $Line = '…!'.mb_substr($Line, $St, $Length);
                 //            } else {
                 //               $Line = substrWord($Line, 0, $Length, '---');
                 //            }
                 return MarkString($SearchTerms, $Line);
             }
         }
     }
     // No line was found so return the first non-blank line.
     foreach ($Lines as $Line) {
         if ($Line) {
             return SliceString($Line, $Length);
         }
     }
 }