XMF Cookbook
  • Introduction
  • XMF Cookbook
  • Basic Ingredients
    • Namespaces
    • Autoloading
    • Debugging
    • Forward Compatibility
  • Recipes
    • Introducing Module Helpers
    • Using the Permission Helper
      • Checking Permissions
      • Managing Item Permissions
    • Using the Session Helper
    • Using JSON Web Tokens
    • Altering Database Tables
    • Migrating a Module's Database
    • Loading Initial Data
    • Module Admin Pages
      • Hide and Seek with Icons
      • Standard Admin Pages
    • Manage Metadata
    • Highlighting Content
  • Reference
    • Assert
      • Assertions
    • Database
      • Migrate
      • TableLoad
      • Tables
        • Getting Started
        • Table Operations
        • Working with Columns
        • Working with Indexes
        • Changing Table Data
        • Interacting with the Work Queue
        • Error Info and Debugging
    • Debug
    • FilterInput
    • Highlighter
    • IPAddress
    • Jwt
      • JsonWebToken
      • KeyFactory
      • TokenFactory
      • TokenReader
    • Key
      • ArrayStorage
      • Basic
      • FileStorage
      • KeyAbstract
      • StorageInterface
    • Language
    • Metagen
      • Extracting Data
      • Applying Data
    • Module
      • Admin
      • Helper
      • Helper
        • AbstractHelper
        • Cache
        • GenericHelper
        • Permission
        • Session
    • ProxyCheck
    • Random
    • Request
    • StopWords
    • Uuid
    • Yaml
  • Credits
  • License:
  • Table of Content
Powered by GitBook
On this page
  • SEO Slugs
  • Generate Keyword Lists
  • Generate a Teaser
  • Generate a Search Summary
  1. Recipes

Manage Metadata

PreviousStandard Admin PagesNextHighlighting Content

Last updated 6 years ago

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:

$title = 'xmf - the XOOPS Module Framework';
echo Metagen::generateSeoTitle($title);

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 "," asking for a list of four words.

$data = file_get_contents('mary-had-a-little-lamb.txt');
$keywords = \Xmf\Metagen::generateKeywords($data, 4);
echo implode(', ', $keywords);

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:

$data = file_get_contents('mary-had-a-little-lamb.txt');
$description = \Xmf\Metagen::generateDescription($data, 40);
echo $description;

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.

$data = file_get_contents('mary-had-a-little-lamb.txt');
$summary = \Xmf\Metagen::getSearchSummary($data, 'school', 40);
echo $summary;

The output:

...He followed her to school one day...

Mary Had a Little Lamb