Page 2 of 2
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 3:18 pm
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 3:21 pm
by serotonic
Ian,
thanks a lot! 1. and 2. solved
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 4:25 pm
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 4:47 pm
by serotonic
chrchrchr
Works great, except the fact that it brings back the linebreaks.
(Nevertheless, most of the descriptions make much more sense now. Luv it
)
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 5:21 pm
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 5:37 pm
by serotonic
Indeed, it does. Thanks a lot, Ian, and as we say in serocratic: „Handpusteküsschen!“
(What if someone would commit this to cvs, erm, let's say, accidentally?)
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Fri Jan 14, 2011 5:57 pm
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Mon Jan 17, 2011 11:54 am
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
Regards,
serotonic
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Mon Jan 17, 2011 12:57 pm
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
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Mon Jan 17, 2011 1:31 pm
by serotonic
… nothing left to be desired
Thanks, Ian!
Regards,
serotonic
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Mon Jan 17, 2011 1:38 pm
by Timbalu
Really? Quel dommage!
Re: metadesc: extract issues (p vs. div, classes & ids)
Posted: Mon Jan 17, 2011 1:57 pm
by serotonic
How would one translate
*gacker* into proper english?