Skip to content

Instantly share code, notes, and snippets.

@mckelvey
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckelvey/9262848 to your computer and use it in GitHub Desktop.
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.
<?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
}
}
?>
<?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
}
}
?>
@mckelvey
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment