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

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

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

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
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

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
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

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
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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?)
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

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
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

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
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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

Regards,
serotonic
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by Timbalu »

Really? Quel dommage! ;-)
serotonic
Regular
Posts: 89
Joined: Wed Feb 08, 2006 6:06 pm

Re: metadesc: extract issues (p vs. div, classes & ids)

Post by serotonic »

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