Manage Metadata with XMF Metagen

This example shows how the Metagen class can simplify extracting metadata and summaries from your content.

The results of calls and contents of variables is shown using Xmf\Debug::dump();. Click on any item to explore the details.


Title

string(32) "xmf - the XOOPS Module Framework"

Article

string UTF-8(982) "XMF is Copyright © 2011-2016 The XOOPS Project This program is free software; yo…"
XMF is Copyright © 2011-2016 The XOOPS Project

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Some portions of this work are licensed under the GNU Lesser General
Public License Version 2.1 as published by the Free Software Foundation.
Such portions are clearly identified in the source files.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License, and
the GNU Lesser General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.

You may contact the copyright holder through XOOPS Project: <http://xoops.org>

Extract Title Keywords

array(4)
string(3) "xmf"
string(5) "xoops"
string(6) "module"
string(9) "framework"

Extract Keywords

array(10)
string(3) "xmf"
string(6) "module"
string(5) "xoops"
string(9) "framework"
string(7) "license"
string(7) "general"
string(6) "public"
string(7) "version"
string(7) "program"
string(4) "free"

Generate a Teaser

string UTF-8(277) "XMF is Copyright © 2011 2016 The XOOPS Project This program is free software you…"
XMF is Copyright © 2011 2016 The XOOPS Project This program is free software you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or at your option any later...

Create SEO Slug from Title

string(26) "xmf-XOOPS-Module-Framework"

Show Article with Keywords Highlighted

XMF is Copyright © 2011-2016 The XOOPS Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. Some portions of this work are licensed under the GNU Lesser General Public License Version 2.1 as published by the Free Software Foundation. Such portions are clearly identified in the source files. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License, and the GNU Lesser General Public License along with this program. If not, see . You may contact the copyright holder through XOOPS Project:

Show a Search Summary

...portions are clearly identified in the source files. This program is...

Code


<?php

use Xmf\Debug;
use 
Xmf\Highlighter;
use 
Xmf\Metagen;
use 
Xmf\Module\Helper;


// define some dummy content
$title="xmf - the XOOPS Module Framework";
$article =<<<EOT
XMF is Copyright © 2011-2016 The XOOPS Project

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Some portions of this work are licensed under the GNU Lesser General
Public License Version 2.1 as published by the Free Software Foundation.
Such portions are clearly identified in the source files.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License, and
the GNU Lesser General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.

You may contact the copyright holder through XOOPS Project: <http://xoops.org>
EOT;

echo 
'<h4>Title</h4>';
Debug::dump($title);

echo 
'<h4>Article</h4>';
Debug::dump($article);

echo 
'<h4>Extract Title Keywords</h4>';
// get important words from title
$title_keywords Metagen::generateKeywords($title103);
Debug::dump($title_keywords);

echo 
'<h4>Extract Keywords</h4>';
// get top 25 keywords, but always keep keywords from title
$keywords Metagen::generateKeywords($article104$title_keywords);
Debug::dump($keywords);

echo 
'<h4>Generate a Teaser</h4>';
$metadesc Metagen::generateDescription($article50);
Debug::dump($metadesc);

echo 
'<h4>Create SEO Slug from Title</h4>';
Debug::dump(Metagen::generateSeoTitle($title));

echo 
'<h4>Show Article with Keywords Highlighted</h4>';
echo 
Highlighter::apply($keywords$article);

echo 
'<br><br><h4>Show a Search Summary</h4>';
$searchTerms = array('source''files');
$summary = \Xmf\Metagen::getSearchSummary($article$searchTerms80);
echo 
Highlighter::apply($searchTerms$summary'<span style="background-color: yellow;">''</span>');



Back to the XMF Example List
Design by: XOOPS UI/UX Team