Page 1 of 2
SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 9:53 am
by satollo
Search engine look for meta tag, even if some say no. Specially, they look for meta description, may be just to show a short description in the result page.
I'm not able to write a plugin, now, but in my site I use this simple logic: I extract the first document paragraph and I use it a meta description and, for keywords, I extract all the words marked as bold (with b o strong tags). But one can use the em tag to identify the keywords or others.
This help to have meta information without write it in special field (which is time consuming)
It's simple to create such a plugin?
Satollo
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 11:42 am
by garvinhicking
Hi!
I could write you such a plugin, if you give me your current code you use to extract the metafields!
Best regards,
Garvin
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 11:55 am
by satollo
To extract the description this is a piece of code (very simple):
function extract_description($text)
{
$x = strpos($text, '<p>');
if ($x === false) return '';
$y = strpos($text, '</p>');
if ($y === false) return '';
$title = substr($text, $x+3, $y-($x+3));
$title = strip_tags($title);
return $title;
}
this is the code I use in my custom CMS. For the keywords:
function extract_keywords($text)
{
preg_match_all('/<strong>([^>]*)<\/strong>/si', $text, $match);
preg_match_all('/<b>([^>]*)<\/b>/si', $text, $match2);
return array_merge($match[1], $match2[1]);
}
this one return an array with all the "pieces of text" within b or strong tag. It's not perfect because it doesn't conseder tags with class or others attributes, but can be improved.
To join the keywords:
$keywords = join(",", extract_keywords($text));
code that can be added to the prevous function. Probably is better to apply an "strip_tags" to each keyword.
Satollo
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 12:57 pm
by garvinhicking
Hi!
Great, that's a good suggestion. I just built a plugin to do this. It also allows you to define meta-tags per entry, and only if those are not set it will fetch them using your functions.
Have a try:
http://nopaste.php-q.net/223644
It's a lot more complex because of those overriding meta-tags per entry. if that wasn't required, the plugin would be reduced to half the size.
Best regards
Garvin
Posted: Wed Jul 05, 2006 12:59 pm
by Harald Weingaertner
Great idea! Can we all use this plugin somehow?
Posted: Wed Jul 05, 2006 1:14 pm
by garvinhicking
Hi!
Sure, it got committed to Spartacus and will be there in a few days. I'll also announce it on the blog.
Regards,
Garvin
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 1:56 pm
by satollo
It works great!
Now we can add some configuration, like the maximum number of characters/words to use for a description, or the html tags to use to identify the keywords, and so on!
Thank you very much!
By Satollo.
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 2:03 pm
by satollo
Just a note: I get this warning:
Warning: implode(): Bad arguments. in /home/mhd-01/
www.naturalmentedonna.com/htdocs/diario ... tadesc.php on line 154
only on blog index (
http://www.naturalmentedonna.com/diario). Can you check it?
Thank you, Satollo!
Re: SEO plugin: a simple idea
Posted: Wed Jul 05, 2006 2:47 pm
by garvinhicking
Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
Re: SEO plugin: a simple idea
Posted: Thu Jul 06, 2006 1:51 pm
by satollo
garvinhicking wrote:Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
ok, give me some time, i write down more generic functions. do i have to post them here?
Re: SEO plugin: a simple idea
Posted: Thu Jul 06, 2006 9:16 pm
by Gamersea
garvinhicking wrote:Hi!
The foreach bug I fixed here:
http://nopaste.php-q.net/223670
For the configuration: Maybe you can help me there? You could modify the code to use substitution placeholders and then I tell how you to make them configurable.
Best regards,
Garvin
Will that also be fixed for the spartacus?
Re: SEO plugin: a simple idea
Posted: Thu Jul 06, 2006 11:21 pm
by satollo
This function
function extract_keywords($text, $tag_names="b,strong")
{
$tags = split(",", $tag_names);
$tags_count = count($tags);
$result = array();
for ($i=0; $i<$tags_count; $i++)
{
preg_match_all('/<' . $tags[$i] . '>([^>]*)<\/' . $tags[$i] . '>/si', $text, $match);
$results = array_merge($results, $match[1]);
}
return $results;
}
can be used to make the html tag to consider as a second parameter. I think it's easy to make the plugin configurable with a list of tag comma separated.
Re: SEO plugin: a simple idea
Posted: Fri Jul 07, 2006 11:54 am
by garvinhicking
Hi!
Thanks for that patch! I made it configurable and committed it to the plugin.
The new version will be found here in a few minutes:
http://php-blog.cvs.sourceforge.net/php ... t_metadesc
Best regards,
Garvin
Posted: Sat Jul 08, 2006 10:48 am
by Gamersea
It's not update in the spartacus yet... and I can't manually edit the file so my host have to do it....

Posted: Sat Jul 08, 2006 5:00 pm
by Gamersea
There is a small bug if you don't fill in any description or I have update the serendipity_event_metadesc.php file wrong.
bug:
Warning: implode(): Bad arguments. in /You/may/not/see this directory/html/plugins/serendipity_event_metadesc/serendipity_event_metadesc.php on line 109
Edit however I don't know that much of it (yet) but the problem is in this rule:
Code: Select all
$meta_keywords = implode(',', $this->extract_keywords($GLOBALS['entry'][0]['body']));