Ramon wrote:FI-DD.. You might wanna update this plugin to
- Code: Select all
<?php
/*
Plugin Name: Short.ShortStory
Plugin URI: http://cutenews.ru
Description: Adds a {tag} to the templates to show n characters of the Short Story.
Version: 1.0
Author: FI-DD
Author URI: http://english.cutenews.ru/forum/profile.php?mode=viewprofile&u=2
*/
add_filter('news-entry', 'shortShortStory');
function shortShortStory($output) {
global $row, $output;
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);
$short_tmp = strip_tags($row['short']);
$row['short'] = $short_tmp;
$output = preg_replace('/{sShortStory\|(\d+)}/i', strlen($row['short']) > $temp[1] ? substr($row['short'], 0, $temp[1]).'...' : $row['short'], $output);
$output = run_filters('news-entry-content', $output);
return $output;
}
add_filter('template-variables-active', 'shortShortStoryTemplate');
add_filter('template-variables-full', 'shortShortStoryTemplate');
function shortShortStoryTemplate($template) {
$template['{sShortStory|n}'] = 'Shortens the Short Story to "My short story ..." (n = number of characters)';
return $template;
}
?>
This way it gets rid of all HTML before counting. So it won't ever screw up your page
marcusmagalhaes wrote:the short story is even counting the numbers of images link (<img width="70" height="53" border="0" align="left" alt="" style="width: 70px; height: 53px;" src="/XXXX/XXX/XXX/XXX/XXX/ic_camara.gif" />), can we exclude the images link from the count?
<?php
/*
Plugin Name: Short.ShortStory
Plugin URI: http://cutenews.ru
Description: Adds a {tag} to the templates to show n characters of the Short Story.
Version: 1.0
Author: FI-DD
Author URI: http://english.cutenews.ru/forum/profile.php?mode=viewprofile&u=2
*/
add_filter('news-entry', 'shortShortStory');
function shortShortStory($output) {
global $row, $output;
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);
$short_tmp = ereg_replace("/<([^<>]*)>/", "", $row['short']);
$output = preg_replace('/\<img(.*?)\>/si', '', $output);
$output = preg_replace('/{sShortStory\|(\d+)}/i', strlen($row['short']) > $temp[1] ? substr($row['short'], 0, $temp[1]).'...' : $row['short'], $output);
$output = run_filters('news-entry-content', $output);
return $output;
}
add_filter('template-variables-active', 'shortShortStoryTemplate');
add_filter('template-variables-full', 'shortShortStoryTemplate');
function shortShortStoryTemplate($template)
{
$template['{sShortStory|n}'] = 'Shortens the Short Story to "My short story ..." (n = number of characters)';
return $template;
}
?><?php
/*
Plugin Name: Short.ShortStory
Plugin URI: http://cutenews.ru
Description: Adds a {tag} to the templates to show n characters of the Short Story.
Version: 1.0
Author: FI-DD
Author URI: http://english.cutenews.ru/forum/profile.php?mode=viewprofile&u=2
*/
add_filter('news-entry', 'shortShortStory');
function strip_tags_content($text) {
$htmlstrip = preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text); // Strips the HTML
$bbstrip = preg_replace('#\[(.*?)\](.*?)\[/(.*?)\]#si', '', $htmlstrip); // Strips BBCode, you need to strip it cause bbcode will turn into html and therefore - if not taken care of - could potentially screw your page up
return $bbstrip;
}
function shortShortStory($output) {
global $row, $output;
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);
$short_tmp = strip_tags_content($row['short']);
$long = strlen($row['short']);
$short = strlen($short_tmp);
$add = $long - $short;
$temp[1] = $temp[1] + $add;
$output = preg_replace('/{sShortStory\|(\d+)}/i', strlen($row['short']) > $temp[1] ? substr($row['short'], 0, $temp[1]).'...' : $row['short'], $output);
$output = run_filters('news-entry-content', $output);
return $output;
}
add_filter('template-variables-active', 'shortShortStoryTemplate');
add_filter('template-variables-full', 'shortShortStoryTemplate');
function shortShortStoryTemplate($template) {
$template['{sShortStory|n}'] = 'Shortens the Short Story to "My short story ..." (n = number of characters)';
return $template;
}
/* NOTE: Function is still incomplete. {nl} should somehow be accounted for. If you got multiple
paragraphs you use more space then when you don't. Somehow that should matter, but it does'nt yet.
To make it complete it should count the number of {nl} in $bbstrip and then multiply that amount
with a - yet to determine - agreeable amount of charactars(depends on the amount of charactars that fit in one line).
That amount needs to be deducted from $temp[1].
LOL the only person who probably understands what i'm saying is FI-DD, so cheers mate :P I can't figure it out
she is al yours.
*/
?>
<div class="no_image"><img><p>Your news article...</p></div>.no_image img{ display:none; }Hawk wrote:Nice and simple solution theresmart use of a css
manu wrote:thank you to help me !
I don't know how I can to use this plugin ....
Return to Additional Downloads
Users browsing this forum: No registered users and 0 guests