short.ShortStory

Download plugins, language packs and stuff.

Postby scottdallas » Thu Jan 10, 2008 12:52 pm

If you allow me, I could "re"make the plugin, to make short the fullstory (the advantadge of this, is that you only have to write one story, the full one, and then it gets "shriked" by the plugin) and post it here.

Of course, your name will be on it.


I suggest making your plugin, adding it to the 'Additional Downloads', describing what it does and why it's useful and seeing if anyone complains that you did :lol: :P In other words, your creativity will not go unnoticed.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

URGENT!!!!!!!

Postby marcusmagalhaes » Wed Feb 27, 2008 1:36 am

Hi Fi-DD

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?
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Postby FI-DD » Wed Feb 27, 2008 7:53 pm

Open the file and find this:
Code: Select all
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);


add below:
Code: Select all
$row['short'] = preg_replace("/<img[^>]+\>/is", "", $row['short']);


P.S.: Please don't send me your questions via PM if you already posted it here.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby alven » Thu Mar 06, 2008 1:18 pm

Super FI-DD nice solution so can we solve this with the plugin Auto short story that Creates short story from the full story?
Thanks in advance.
alven
 
Posts: 126
Joined: Wed Jul 05, 2006 5:21 pm

Postby FI-DD » Thu Mar 06, 2008 8:12 pm

Come on, that's so easy. Did you even try to solve it yourself?

Simply use the code from above and replace $row['short'] with $short_story.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby alven » Thu Mar 06, 2008 10:13 pm

Thanks a lot FI-DD.
alven
 
Posts: 126
Joined: Wed Jul 05, 2006 5:21 pm

Postby marcusmagalhaes » Wed Apr 09, 2008 5:12 pm

not working... the image not show .... I want show image, but not count characters..

FI-DD wrote:Open the file and find this:
Code: Select all
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);


add below:
Code: Select all
$row['short'] = preg_replace("/<img[^>]+\>/is", "", $row['short']);


P.S.: Please don't send me your questions via PM if you already posted it here.
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Postby FI-DD » Wed Apr 09, 2008 5:44 pm

Try this:

Change this:
Code: Select all
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);
   $output = preg_replace('/{sShortStory\|(\d+)}/i', strlen($row['short']) > $temp[1] ? substr($row['short'], 0, $temp[1]).'...' : $row['short'], $output);


to this:
Code: Select all
preg_match('/{sShortStory\|(\d+)}/i', $output, $temp);
   $short_tmp = preg_replace("/<img[^>]+\>/is", "", $row['short']);
   $output = preg_replace('/{sShortStory\|(\d+)}/i', strlen($short_tmp) > $temp[1] ? substr($row['short'], 0, $temp[1]).'...' : $row['short'], $output);
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby marcusmagalhaes » Thu Jun 05, 2008 3:18 pm

not work yet....

I'm try .... but..... not working..

thanks
marcusmagalhaes
 
Posts: 163
Joined: Tue Apr 24, 2007 1:17 pm

Postby nolikewise » Tue Jul 22, 2008 5:52 pm

when you edit e message it does not function but when you add a new one it is okay...

fi-dd have a look pls...
nolikewise
 
Posts: 177
Joined: Mon Dec 17, 2007 8:47 am
Location: Turkiye

Postby FI-DD » Tue Jul 29, 2008 5:43 pm

This plugin is called when the news are shown. Then it truncates the short story to the given number of characters.

So it shouldn't matter whether you add or edit an article.

In your case it could be a cache problem. Clear the cache and try again.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby Ramon » Fri Nov 21, 2008 7:45 pm

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 ;)
Last edited by Ramon on Fri Nov 21, 2008 8:04 pm, edited 1 time in total.
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby FI-DD » Fri Nov 21, 2008 7:53 pm

Done. :)
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby Ramon » Fri Nov 21, 2008 8:05 pm

Updated. There's a php function called strip_tags() who does the job even better :)
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby Ramon » Fri Nov 21, 2008 8:26 pm

lol when i started testing i figured i was'nt so bright as i thought i was. Needed to following changes to do what it is supposed to do.

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']);
      $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;
}
?>


This way it filters html from counting. But since you are nog showing the stripped version on your website you want to add to difference between the length of the stripped content with the non-stripped content. That way it wont break down in the middle of html tag.

---

Edit: Figured it does need more changes.. It wont break down in the middle of a html tag, but it can still break down in the content of an html tag. Which could cause tags not to be closed. I need to change it further lol :P


---

Edit: Found it

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 strip_tags_content($text, $tags = '', $invert = FALSE) {
  preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
  $tags = array_unique($tags[1]);
   
  if(is_array($tags) AND count($tags) > 0) {
    if($invert == FALSE) {
      return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
    }
    else {
      return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
    }
  }
  elseif($invert == FALSE) {
    return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
  }
  return $text;
}
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;
}
?>



------

Edit: Yet another edit needed to make it better. Not only HTML had to be taken care of. Also BB-code needed to be filtered for those who use quick_tags.\

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 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.
*/
?>



---

Beginning to look like this function won't ever work flawless. If your tags are stripped outside the text that is truncated, they will still add to your $temp[1] which will make the truncated text longer then it should be. It should only count the amount of characters stripped in the first $temp[1] characters.
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

PreviousNext

Return to Additional Downloads



Who is online

Users browsing this forum: No registered users and 0 guests