Skip to content

Commit

Permalink
Added Structured Data to Articles
Browse files Browse the repository at this point in the history
For feature #902
Also updated docs on how to use the structureddata autotag.  (which still doesn't work when caching enabled)
Bug Fix #919 Increased speed for articles when cached
  • Loading branch information
eSilverStrike committed Feb 4, 2019
1 parent d155f29 commit 8458f3f
Show file tree
Hide file tree
Showing 29 changed files with 282 additions and 93 deletions.
3 changes: 2 additions & 1 deletion language/english.php
Expand Up @@ -2113,7 +2113,7 @@

$LANG_STRUCT_DATA = array(
'lang_structured_data_type' => 'Structured Data Type',
'autotag_desc_structureddata' => '[structureddata:parameter:schema_parameter]Parameter Value[/structureddata] - Adds a parameter to the structured data of the content that the autotag is embedded in.'
'autotag_desc_structureddata' => '[structureddata:schema_property]Property Value[/structureddata] - Adds a property to the structured data of the content that the autotag is embedded in.'
);

###############################################################################
Expand Down Expand Up @@ -2305,6 +2305,7 @@
'page_break_comments' => 'Comments on Multi-Page Articles',
'article_image_align' => 'Topic Icon Alignment',
'show_topic_icon' => 'Show Topic Icon?',
'structured_data_type_default' => 'Structured Data Type Default',
'draft_flag' => 'Draft Flag Default',
'frontpage' => 'Frontpage Default',
'hide_no_news_msg' => 'Hide "No News" Message?',
Expand Down
3 changes: 2 additions & 1 deletion language/english_utf-8.php
Expand Up @@ -2114,7 +2114,7 @@

$LANG_STRUCT_DATA = array(
'lang_structured_data_type' => 'Structured Data Type',
'autotag_desc_structureddata' => '[structureddata:parameter:schema_parameter]Parameter Value[/structureddata] - Adds a parameter to the structured data of the content that the autotag is embedded in.'
'autotag_desc_structureddata' => '[structureddata:schema_property]Property Value[/structureddata] - Adds a property to the structured data of the content that the autotag is embedded in.'
);

###############################################################################
Expand Down Expand Up @@ -2306,6 +2306,7 @@
'page_break_comments' => 'Comments on Multi-Page Articles',
'article_image_align' => 'Topic Icon Alignment',
'show_topic_icon' => 'Show Topic Icon?',
'structured_data_type_default' => 'Structured Data Type Default',
'draft_flag' => 'Draft Flag Default',
'frontpage' => 'Frontpage Default',
'hide_no_news_msg' => 'Hide "No News" Message?',
Expand Down
3 changes: 2 additions & 1 deletion language/japanese_utf-8.php
Expand Up @@ -2113,7 +2113,7 @@

$LANG_STRUCT_DATA = array(
'lang_structured_data_type' => 'Structured Data Type',
'autotag_desc_structureddata' => '[structureddata:parameter:schema_parameter]Parameter Value[/structureddata] - Adds a parameter to the structured data of the content that the autotag is embedded in.'
'autotag_desc_structureddata' => '[structureddata:schema_property]Property Value[/structureddata] - Adds a property to the structured data of the content that the autotag is embedded in.'
);

###############################################################################
Expand Down Expand Up @@ -2304,6 +2304,7 @@
'page_break_comments' => '改ページ時のコメント表示位置',
'article_image_align' => '話題アイコンの表示位置',
'show_topic_icon' => '話題アイコン表示のデフォルト',
'structured_data_type_default' => 'Structured Data Type Default',
'draft_flag' => 'ドラフトモードをデフォルトにする',
'frontpage' => 'トップページ配置をデフォルトにする',
'hide_no_news_msg' => '記事がない場合のメッセージを表示しない',
Expand Down
2 changes: 1 addition & 1 deletion plugins/staticpages/functions.inc
Expand Up @@ -426,7 +426,7 @@ function SP_displayPage($page, $A, $comment_order = 'ASC', $comment_mode = 'nest
$breadcrumb_trail = TOPIC_breadcrumbs('staticpages', $page);
}
}
$spage->set_var('breadcrumb_trail', $breadcrumb_trail); // Still need to keep this template variable incase main theme does not support 2.0.0 theme engine. Once we drop support of theme engine 1.9.1 then remove
$spage->set_var('breadcrumb_trail', $breadcrumb_trail); // Still need to keep this template variable in case main theme does not support 2.0.0 theme engine. Once we drop support of theme engine 1.9.1 then remove

$author_name = COM_getDisplayName($A['owner_id']);
$author_username = DB_getItem($_TABLES['users'], 'username',
Expand Down
2 changes: 1 addition & 1 deletion plugins/staticpages/install_defaults.php
Expand Up @@ -119,7 +119,7 @@
$_SP_DEFAULT['comment_code'] = -1;

// Default to set Structured Data type for new staticpages. See $LANG_structureddatatypes
$_SP_DEFAULT['structured_data_type_default'] = 0;
$_SP_DEFAULT['structured_data_type_default'] = 1; // Setting WebPage as the default

// Whether to set the draft flag by default for new pages
$_SP_DEFAULT['draft_flag'] = 0;
Expand Down
10 changes: 9 additions & 1 deletion public_html/admin/article.php
Expand Up @@ -250,7 +250,8 @@ function liststories($current_topic = '')
function storyeditor($sid = '', $mode = '', $errormsg = '')
{
global $_CONF, $_TABLES, $_USER, $LANG24, $LANG_ACCESS, $LANG_ADMIN,
$MESSAGE, $_SCRIPTS, $LANG_DIRECTION, $LANG_MONTH, $LANG_WEEK;
$MESSAGE, $_SCRIPTS, $LANG_DIRECTION, $LANG_MONTH, $LANG_WEEK,
$LANG_STRUCT_DATA;

$display = '';

Expand Down Expand Up @@ -577,6 +578,13 @@ function storyeditor($sid = '', $mode = '', $errormsg = '')
} else {
$story_templates->set_var('show_topic_icon_checked', '');
}

$story_templates->set_var('lang_structured_data_type', $LANG_STRUCT_DATA['lang_structured_data_type']);
$story_templates->set_var(
'structured_data_options',
COM_optionListFromLangVariables('LANG_structureddatatypes', $story->EditElements('structured_data_type'))
);

$story_templates->set_var('lang_cachetime', $LANG24['cache_time']);
$story_templates->set_var('lang_cachetime_desc', $LANG24['cache_time_desc']);
$story_templates->set_var('cache_time', $story->EditElements('cache_time'));
Expand Down
3 changes: 3 additions & 0 deletions public_html/admin/configuration_validation.php
Expand Up @@ -205,6 +205,9 @@
'rule' => array('inList', array('left', 'right'), true)
);
$_CONF_VALIDATE['Core']['show_topic_icon'] = array('rule' => 'boolean');
$_CONF_VALIDATE['Core']['structured_data_type_default'] = array(
'rule' => array('inList', array('0', '1', '2', '3', '4'), true)
);
$_CONF_VALIDATE['Core']['draft_flag'] = array('rule' => 'boolean');
$_CONF_VALIDATE['Core']['frontpage'] = array('rule' => 'boolean');
$_CONF_VALIDATE['Core']['hide_no_news_msg'] = array('rule' => 'boolean');
Expand Down
1 change: 1 addition & 0 deletions public_html/admin/install/config-install.php
Expand Up @@ -133,6 +133,7 @@ function install_config()
$c->add('page_break_comments','last','select',1,7,7,1250,TRUE, $me, 7);
$c->add('article_image_align','right','select',1,7,8,1260,TRUE, $me, 7);
$c->add('show_topic_icon',1,'select',1,7,0,1270,TRUE, $me, 7);
$c->add('structured_data_type_default',2,'select',1,7,39,1275,TRUE, $me, 7); // Setting article as the default
$c->add('draft_flag',0,'select',1,7,0,1280,TRUE, $me, 7);
$c->add('frontpage',1,'select',1,7,0,1290,TRUE, $me, 7);
$c->add('hide_no_news_msg',0,'select',1,7,0,1300,TRUE, $me, 7);
Expand Down
4 changes: 4 additions & 0 deletions public_html/admin/install/devel-db-update.php
Expand Up @@ -83,6 +83,10 @@ function update_DatabaseFor221()

// Remove unused Vars table record (originally inserted by devel-db-update script on previous version upgrades)
$_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = 'geeklog'";

// Add structured data type to article table and modified date
$_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD `structured_data_type` tinyint(4) NOT NULL DEFAULT 0 AFTER `commentcode`";
$_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD `modified` DATETIME NULL DEFAULT NULL AFTER `date`";

// ***************************************
// Core Plugin Updates Here (including version update)
Expand Down
14 changes: 14 additions & 0 deletions public_html/article.php
Expand Up @@ -193,6 +193,7 @@ function extractExternalLinks($text) {
}

$articleTemplate->set_var('story_date', $article->displayElements('date'));
$articleTemplate->set_var('story_modified', $article->displayElements('modified'));

if ($_CONF['contributedbyline'] == 1) {
$articleTemplate->set_var('lang_contributedby', $LANG01[1]);
Expand Down Expand Up @@ -514,6 +515,19 @@ function extractExternalLinks($text) {
$display .= $articleTemplate->finish($articleTemplate->parse('output', 'article'));

$breadcrumbs = TOPIC_breadcrumbs('article', $article->getSid());

$properties['headline'] = $article->displayElements('title');
$properties['url'] = $permalink;
$properties['datePublished'] = $article->displayElements('date');

// Don't include modified if empty or date is less than published
if (!empty($article->displayElements('unixmodified')) && ($article->displayElements('unixmodified') > $article->displayElements('unixdate'))) {
$properties['dateModified'] = $article->displayElements('modified');
}
$properties['description'] = $article->DisplayElements('meta_description');
$properties['commentCount'] = CMT_commentCount($article->getSid(), 'article');
$_STRUCT_DATA->add_type('article', $article->getSid(), $article->displayElements('structured_data_type'), $properties);
$_STRUCT_DATA->set_author_item('article', $article->getSid(), $article->DisplayElements('username'));

$display = COM_createHTMLDocument(
$display,
Expand Down
32 changes: 31 additions & 1 deletion public_html/docs/english/config.html
Expand Up @@ -84,7 +84,7 @@ <h3><a name="site_site">Site: Site</a></h3>
<tr>
<td valign="top"><a name="desc_owner_name">owner_name</a></td>
<td valign="top"><span class="tt">''</span> <em>(empty)</em></td>
<td valign="top">The name of the owner of the site. This is used in the copyright notice if set, else the site name is used.</td></tr>
<td valign="top">The name of the owner of the site. This is used in the copyright notice and Structured Data Organization if set, else the site name is used.</td></tr>
<tr>
<td valign="top"><a name="desc_copyrightyear">copyrightyear</a></td>
<td valign="top"><em>(disabled)</em></td>
Expand Down Expand Up @@ -403,6 +403,36 @@ <h3><a name="stories_story">Articles and Trackback: Article</a></h3>
<td valign="top"><a name="desc_show_topic_icon">show_topic_icon</a></td>
<td valign="top">1</td>
<td valign="top">Default setting for new articles and article submissions: Whether to show the topic icon (1) or not (0).</td></tr>
<tr>
<td valign="top"><a name="desc_structured_data_type_default">structured_data_type_default</a></td>
<td valign="top">2</td>
<td valign="top">Default Structured Data Type for new articles. Structured Data markup will only be included when viewing the full article. Some plugins may also use this as the default. Supported types include:<br /><br />
<ul>
<li>0 => None</li>
<li>1 => WebPage</li>
<li>2 => Article</li>
<li>3 => NewsArticle</li>
<li>4 => BlogPosting</li>
</ul>
<br />
Geeklog will add Structured Data markup (JSON-LD code) to your pages (either in the head of the page or near the actual content as it depends on caching) which increases the understanding of the page by search engines and can enhance your appearance in search results. This does not require any additional changes to your theme (unless your theme contains hard coded conflicting structured data markup). Currently Geeklog supports Structured Data for Breadcrumbs, Articles, and Staticpages. Based on the page (i.e. Article or Staticpage) and structured data type selected, Geeklog will map the data fields to the appropriate Structured Data properties.<br /><br />

Additional Structured Data properties can be added (or some current ones changed) by using the [structureddata: ] autotag in the actual article, static page, and other supported plugins items. For example:<br /><br />

<code>[structureddata:image height:60 width:200]{site_url}/images/example.jpg[/structureddata]</code><br /><br />

would add the image property to the sturctured data of the page. You could do this multiple times to add more than one image to the Structured Data. Alternately you could also include the id of the page and the type of item it is (plugin name) as well in the autotag. This has been added since some plugins which support Structured Data may not support the ability of the autotag to know what object it is embedded in.<br /><br />

<code>[structureddata:image type:staticpages id:page_id height:60 width:200]{site_url}/images/example.jpg[/structureddata]</code><br /><br />

For articles and static pages, the meta description is used for the structured data description property. If you wanted to change this without changing the meta description you could include an autotag like so within your content:<br /><br />

<code>[structureddata:description]This is my new example description.[/structureddata]</code><br /><br />

For more on Structured Data itself, see <a href="https://schema.org/" target="_blank">Schema.org</a> and <a href="https://developers.google.com/search/docs/data-types/article" target="_blank">Google Search Reference</a>.<br /><br />

To test your pages for Structured Data and see if it is setup correctly you can use the <a href="https://search.google.com/structured-data/testing-tool" target="_blank">Google Structured Data Testing Tool</a>. Please note this tool test includes checking that the Structured Data supports the AMP specification so if some errors are reported they may only deal with AMP specific issues and may be fine for normal web pages. For more on the tool itself you can read Google's <a href="https://developers.google.com/search/docs/guides/prototype" target="_blank">guide</a>.
</td></tr>
<tr>
<td valign="top"><a name="desc_draft_flag">draft_flag</a></td>
<td valign="top">0</td>
Expand Down
4 changes: 2 additions & 2 deletions public_html/docs/english/staticpages.html
Expand Up @@ -255,8 +255,8 @@ <h3><a name="main">Static Pages Main Settings</a></h3>
</tr>
<tr>
<td><a name="desc_structured_data_type_default">structured_data_type_default</a></td>
<td>0</td>
<td>Default Structured Data Type for new pages.Find out more see Structured data integration into Geeklog.<br /><br />For more on Structured Data itself, see <a href="https://schema.org/" target="_blank">Schema.org</a> and <a href="https://developers.google.com/search/docs/data-types/article" target="_blank">Google Search Reference</a>.</td>
<td>1</td>
<td>Default Structured Data Type for new pages. To find out more about Structured Data and its integration into Geeklog see <a href="config.html#desc_structured_data_type_default">this page</a>.
</tr>
<tr>
<td><a name="desc_draft_flag">draft_flag</a></td>
Expand Down
30 changes: 30 additions & 0 deletions public_html/docs/japanese/config.html
Expand Up @@ -368,6 +368,36 @@ <h3><a name="stories_story">記事とトラックバック: 記事</a></h3>
<td valign="top"><a name="desc_show_topic_icon">話題アイコン表示のデフォルト(show_topic_icon)</a></td>
<td valign="top">はい</td>
<td valign="top">「はい」にすると、新規記事とユーザーによる投稿の際にデフォルトで話題アイコンを表示するようになります。</td></tr>
<tr>
<td valign="top"><a name="desc_structured_data_type_default">structured_data_type_default</a></td>
<td valign="top">2</td>
<td valign="top">Default Structured Data Type for new articles. Structured Data markup will only be included when viewing the full article. Some plugins may also use this as the default. Supported types include:<br /><br />
<ul>
<li>0 => None</li>
<li>1 => WebPage</li>
<li>2 => Article</li>
<li>3 => NewsArticle</li>
<li>4 => BlogPosting</li>
</ul>
<br />
Geeklog will add Structured Data markup (JSON-LD code) to your pages (either in the head of the page or near the actual content as it depends on caching) which increases the understanding of the page by search engines and can enhance your appearance in search results. This does not require any additional changes to your theme (unless your theme contains hard coded conflicting structured data markup). Currently Geeklog supports Structured Data for Breadcrumbs, Articles, and Staticpages. Based on the page (i.e. Article or Staticpage) and structured data type selected, Geeklog will map the data fields to the appropriate Structured Data properties.<br /><br />

Additional Structured Data properties can be added (or some current ones changed) by using the [structureddata: ] autotag in the actual article, static page, and other supported plugins items. For example:<br /><br />

<code>[structureddata:image height:60 width:200]{site_url}/images/example.jpg[/structureddata]</code><br /><br />

would add the image property to the sturctured data of the page. You could do this multiple times to add more than one image to the Structured Data. Alternately you could also include the id of the page and the type of item it is (plugin name) as well in the autotag. This has been added since some plugins which support Structured Data may not support the ability of the autotag to know what object it is embedded in.<br /><br />

<code>[structureddata:image type:staticpages id:page_id height:60 width:200]{site_url}/images/example.jpg[/structureddata]</code><br /><br />

For articles and static pages, the meta description is used for the structured data description property. If you wanted to change this without changing the meta description you could include an autotag like so within your content:<br /><br />

<code>[structureddata:description]This is my new example description.[/structureddata]</code><br /><br />

For more on Structured Data itself, see <a href="https://schema.org/" target="_blank">Schema.org</a> and <a href="https://developers.google.com/search/docs/data-types/article" target="_blank">Google Search Reference</a>.<br /><br />

To test your pages for Structured Data and see if it is setup correctly you can use the <a href="https://search.google.com/structured-data/testing-tool" target="_blank">Google Structured Data Testing Tool</a>. Please note this tool test includes checking that the Structured Data supports the AMP specification so if some errors are reported they may only deal with AMP specific issues and may be fine for normal web pages. For more on the tool itself you can read Google's <a href="https://developers.google.com/search/docs/guides/prototype" target="_blank">guide</a>.
</td></tr>
<tr>
<td valign="top"><a name="desc_draft_flag">ドラフトモードをデフォルトにする(draft_flag)</a></td>
<td valign="top">いいえ</td>
Expand Down
4 changes: 2 additions & 2 deletions public_html/docs/japanese/staticpages.html
Expand Up @@ -235,8 +235,8 @@ <h3><a name="main">静的ページの主な設定</a></h3>
</tr>
<tr>
<td><a name="desc_structured_data_type_default">structured_data_type_default</a></td>
<td>0</td>
<td>Default Structured Data Type for new pages.Find out more see Structured data integration into Geeklog.<br /><br />For more on Structured Data itself, see <a href="https://schema.org/" target="_blank">Schema.org</a> and <a href="https://developers.google.com/search/docs/data-types/article" target="_blank">Google Search Reference</a>.</td>
<td>1</td>
<td>Default Structured Data Type for new pages. To find out more about Structured Data and its integration into Geeklog see <a href="config.html#desc_structured_data_type_default">this page</a>.
</tr>
<tr>
<td><a name="desc_draft_flag">ドラフトモードをデフォルトにする(draft_flag)</a></td>
Expand Down
6 changes: 6 additions & 0 deletions public_html/layout/denim/admin/article/articleeditor.thtml
Expand Up @@ -44,6 +44,12 @@

<dt><label for="admin-storyeditor-show_topic_icon">{lang_show_topic_icon}</label></dt>
<dd class="controls_text"><input type="checkbox" {show_topic_icon_checked} name="show_topic_icon" id="admin-storyeditor-show_topic_icon"{xhtml}></dd>

<dt><label for="admin-storyeditor-structureddata">{lang_structured_data_type}</label></dt>
<dd><select name="structured_data_type" id="admin-storyeditor-structureddata">
{structured_data_options}
</select>
</dd>

<dt><label for="admin-storyeditor-cachetime">{lang_cachetime}</label></dt>
<dd><input type="text" size="8" value="{cache_time}" name="cache_time" id="admin-storyeditor-cachetime" class="text" aria-describedby="desc-admin-storyeditor-cachetime"{xhtml}></dd>
Expand Down

0 comments on commit 8458f3f

Please sign in to comment.