Last active
August 29, 2015 13:56
-
-
Save mckelvey/9262848 to your computer and use it in GitHub Desktop.
This tiny LiveWhale application module limits the length of the summary to 90 words.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$_LW->REGISTERED_APPS['short_summary']=array( | |
'title'=>'Short Summary', | |
'handlers'=>array('onWidgetFormat'), | |
); | |
class LiveWhaleApplicationShortSummary { | |
public function onWidgetFormat($type, $handler, $variables) { // alter widget variables | |
global $_LW; | |
if ($type === 'news' && $handler === 'onDisplay' && !empty($variables['summary'])) { // find news widgets | |
$variables['short_summary'] = preg_replace('~\.*\s*</p>[^<]*<p>\s*(\.\.\.</p>)\s*$~imsU', '$1', $_LW->setFormatSummarize($variables['summary'], 90)); // set short summary | |
// unset($variables['summary']); // uncomment this to remove the summary | |
} | |
return $variables; // and return the variables | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$_LW->REGISTERED_APPS['summary']=array( | |
'title'=>'Summary', | |
'handlers'=>array('onWidgetFormat'), | |
); | |
class LiveWhaleApplicationSummary { | |
public function onWidgetFormat($type, $handler, $variables) { // alter widget variables | |
global $_LW; | |
if ($type === 'news' && $handler === 'onDisplay' && !empty($variables['summary'])) { // find news widgets | |
$variables['summary'] = preg_replace('~\.*\s*</p>[^<]*<p>\s*(\.\.\.</p>)\s*$~imsU', '$1', $_LW->setFormatSummarize($variables['summary'], 90)); // set short summary | |
} | |
return $variables; // and return the variables | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use one of the two example modules above or mix and match to meet your needs.
Short Summary it additive when the summary is present in the results. (The summary format variable is not always included, but you can change that by adding it to the default widget format.) Uncomment the unset to remove the summary otherwise.
Summary replaces the summary from the get go.