The Serendipity Handbook

You can now read the (german) handbook here: PDF - https://github.com/s9y/Book (LaTeX source).

Forum-Information

Before posting about errors, make sure that the answer cannot already be found in our FAQ or by searching this forum!
Posting is restricted to registered users (registering is free and simple!) due to recent spam attacks. When having trouble with this board, contact garvin(-at)s9y(-dot)org.

Board index Plugins metadesc: extract issues (p vs. div, classes & ids)

Creating and modifying plugins.
User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Jan 14, 2011 4:18 pm

Ok - here you are, Serotonic

Code: Select all
if (preg_match_all('/<' . $tags[$i] . '[^>]*>(.*?)<\/' . $tags[$i] . '>/si', $text, $match)) {

will give a result array
Code: Select all
Array
(
    [0] => <a href="http://www.imdb.com/title/tt0972412/">Private Practice</a> – Staffel 3
    [1] => <a href="http://www.imdb.com/title/tt0410975/">Desperate Housewives</a> – Staffel 6
    [2] => <a href="http://www.imdb.com/title/tt0903747/">Breaking Bad</a> – Staffel 2
    [3] => <a href="http://www.imdb.com/title/tt1119644/">Fringe</a> – Staffel 1
    [4] => <a href="http://www.imdb.com/title/tt1520211/">The Walking Dead</a> – Staffel 1
    [5] => Private Practice
    [6] => Private Practice
    [7] => Desperate Housewives
    [8] => Fringe
    [9] => Fringe
    [10] => The Walking Dead
)

we need to strip_tag($string) which is build somewhere else

and change line 182 which looks like

Code: Select all
    $meta_keywords = implode(',', $meta_keywords);


to

Code: Select all
    $meta_keywords = implode(',', $meta_keywords);
   $meta_keywords = strip_tags($meta_keywords);


Happy
Ian

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Fri Jan 14, 2011 4:21 pm

Ian,
thanks a lot! 1. and 2. solved :D
edit: 4. works, too, which is great -- thanks a lot again!

Garvin,
yes I could, and I sure will do so for future entries. I am using this plugin only recently, but am blogging for a quite a while, as you know ;) I don't want to edit hundreds of entries just for the sake of having a description which isn't totally absurd.

Besides that, I simply think that discarding the <p> restriction would improve the plugin for all of its users :)

Regards,
serotonic

User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Jan 14, 2011 5:25 pm

psssssst .... number 3 should be possible too....
replace the function extract_description and try this
Code: Select all
function extract_description($text) {
    $metastring = strip_tags(str_replace('\n',' ',trim($text)));
    if (preg_match('/^.{1,120}\b/s', $metastring, $match)) {
        $metadesc = $match[0];
    }
    return $metadesc;
}
which wont cut words inbetween

... but don't tell anybody. ;-)

Ian

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Fri Jan 14, 2011 5:47 pm

chrchrchr :mrgreen:
Works great, except the fact that it brings back the linebreaks.

(Nevertheless, most of the descriptions make much more sense now. Luv it :D)

User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Jan 14, 2011 6:21 pm

very strange... stripping tags seem to change newlines... now it should work
Code: Select all
function replace_newline($string) {
    return (string)str_replace(array("\r", "\r\n", "\n"), '', $string);
}

function extract_description($text) {
    $metastring = strip_tags(trim($text));
    // strip_tags seem to have changed newlines
    $metastring = $this->replace_newline($metastring);

    if (preg_match('/^.{1,120}\b/s', $metastring, $match)) {
        $metadesc = $match[0];
    }

    return isset($metadesc) ? $metadesc : false;
}


Ian

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Fri Jan 14, 2011 6:37 pm

Indeed, it does. Thanks a lot, Ian, and as we say in serocratic: „Handpusteküsschen!“ :mrgreen:

(What if someone would commit this to cvs, erm, let's say, accidentally?)

User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Fri Jan 14, 2011 6:57 pm

give it a try ;-)
As long as the original developers don't recognize our english training course here...
we need Garvin for commitments, he did not seem happy with that (to specific).

to avoid this 'Staffel 3★★★★★★★☆☆☆Spin-Offs', you can change the '' to ' ' -
but it looks your entries are cached, possibly with 'Erweiterte Eigenschaften...' so these changes will have to wait being published until you submit your entries again....

Ian

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Mon Jan 17, 2011 12:54 pm

Hey Ian,

no, no caching of entries. Why do you think it looks like that?

I've changed the '' to ' ', which seems to generate more than one space:
Code: Select all
content="    Private Practice – Staffel 3  ★★★★★★★☆☆☆    Spin-Offs …
– but I don't think this harms that much ;) Again: Thank you!

Concerning the commitment, I still hope that Don Chambers or Judebert will stumble across this [del]english lesson[/del] thread :mrgreen:

Regards,
serotonic

User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Mon Jan 17, 2011 1:57 pm

Hi Serotonic
serotonic wrote:no, no caching of entries. Why do you think it looks like that?

try
Code: Select all
return (string)str_replace(array("\r", "\r\n", "\n", "\t", "  "), ' ', $string);
this will additionally replace tabs and double spaces with one space.

The output with no spaces is done by [Enter] directly after last char or tag, eg
<p>text</p>[Enter]
text[Enter]
text [Enter]
text.
If we strip and str_replace this, you'll have
texttexttext text.

To get around it, just make sure you have a whitespace before [Enter] the newline.

Ian

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Mon Jan 17, 2011 2:31 pm

… nothing left to be desired :D Thanks, Ian!

Regards,
serotonic

User avatar
Timbalu
Regular
 
Posts: 2547
Joined: Sun May 02, 2004 3:04 pm

Postby Timbalu » Mon Jan 17, 2011 2:38 pm

Really? Quel dommage! ;-)

User avatar
serotonic
Regular
 
Posts: 42
Joined: Wed Feb 08, 2006 7:06 pm

Postby serotonic » Mon Jan 17, 2011 2:57 pm

How would one translate *gacker* into proper english? ;)

Previous


Return to Plugins

Who is online

Users browsing this forum: No registered users and 1 guest

cron