XMF Cookbook
Search…
Manage Metadata
The Xmf\Metagen class provides methods to extract and summarize content.
While metadata may be best when manually entered, some helpful suggestions through automation could make that process a little smoother.

SEO Slugs

Using a human meaningful phrase instead of raw id variables in a URL is a common SEO strategy. Most content has a title, and Xmf\Metagen has an easy way to turn that title into a slug:
1
$title = 'xmf - the XOOPS Module Framework';
2
echo Metagen::generateSeoTitle($title);
Copied!
The output:
xmf-xoops-module-framework

Generate Keyword Lists

Given a block of text, Metagen::generateKeywords() can extract the most commonly used significant words. Here we feed it the lyrics of "Mary Had a Little Lamb," asking for a list of four words.
1
$data = file_get_contents('mary-had-a-little-lamb.txt');
2
$keywords = \Xmf\Metagen::generateKeywords($data, 4);
3
echo implode(', ', $keywords);
Copied!
The output:
mary, lamb, school, play

Generate a Teaser

Grabbing the lead sentences from a block of text for use as a description is easy. Call Xmf\Metagen::generateDescription() with your text and the number of words you want:
1
$data = file_get_contents('mary-had-a-little-lamb.txt');
2
$description = \Xmf\Metagen::generateDescription($data, 40);
3
echo $description;
Copied!
The output:
Mary had a little lamb, Little lamb, little lamb, Mary had a little lamb, Its fleece was white as snow And everywhere that Mary went, Mary went, Mary went, Everywhere that Mary went The lamb was sure to go...

Generate a Search Summary

When displaying search results, it is convenient for the user to see a short bit of context that surrounds where the search terms were found in the content. Examining this context helps guide the user to the most relevant results.
Here, we request a summary of about 40 characters, centered around our chosen keyword(s), in this case 'school'. The text breaks on natural boundaries.
1
$data = file_get_contents('mary-had-a-little-lamb.txt');
2
$summary = \Xmf\Metagen::getSearchSummary($data, 'school', 40);
3
echo $summary;
Copied!
The output:
...He followed her to school one day...
Last modified 3yr ago