-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.1] [RFC] Use schema.org for metadata #25117
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
05548fb
Mucking around with JSON+LD schemas
wilsonge 8205436
WIP on JSON LD implementation
wilsonge 1c59e87
Fix things
wilsonge 5a2395c
com_contact work
wilsonge 6da6fd3
Remove tests
wilsonge 1c491f5
Update components/com_contact/View/Contact/HtmlView.php
wilsonge a3f15bb
Use document in the view
wilsonge 3133be5
Merge branch '4.0-dev' into feature/jsonld
wilsonge 7d4f7c9
Add global metadata for publisher feeds
wilsonge 3cb789f
Add a todo
wilsonge f0fc72f
Update schema library to latest and greatest
wilsonge 6c21fe4
Codestyle
wilsonge e463aac
Last codestyle fix
wilsonge e5d5c9d
Merge branch '4.0-dev' into feature/jsonld
wilsonge File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
administrator/components/com_config/tmpl/application/default_seo_metadata.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_config | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
use Joomla\CMS\Language\Text; | ||
use Joomla\CMS\Layout\LayoutHelper; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
$this->name = Text::_('COM_CONFIG_SEO_METADATA_SETTINGS'); | ||
$this->fieldsname = 'seo_metadata'; | ||
$this->formclass = 'options-grid-form options-grid-form-full'; | ||
$this->description = Text::_('COM_CONFIG_SEO_METADATA_SETTINGS_DESCRIPTION'); | ||
|
||
echo LayoutHelper::render('joomla.content.options_default', $this); | ||
|
||
// We don't use the description in any other options groups - remove it so the remaining groups don't use it | ||
unset($this->description); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\Application\CMSApplicationInterface; | ||
use Joomla\CMS\Categories\Categories; | ||
use Joomla\CMS\Factory; | ||
use Joomla\CMS\Helper\TagsHelper; | ||
|
@@ -20,7 +21,12 @@ | |
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; | ||
use Joomla\CMS\Plugin\PluginHelper; | ||
use Joomla\CMS\Router\Route; | ||
use Joomla\CMS\Uri\Uri; | ||
use Joomla\CMS\User\User; | ||
use Joomla\Component\Contact\Site\Helper\Route as ContactHelperRoute; | ||
use Spatie\SchemaOrg\Person; | ||
use Spatie\SchemaOrg\PostalAddress; | ||
use Spatie\SchemaOrg\Schema; | ||
|
||
/** | ||
* HTML Contact View class for the Contact component | ||
|
@@ -107,12 +113,13 @@ class HtmlView extends BaseHtmlView | |
* | ||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths. | ||
* | ||
* @return mixed A string if successful, otherwise an Error object. | ||
* @return void | ||
* @throws \Exception | ||
*/ | ||
public function display($tpl = null) | ||
{ | ||
$app = Factory::getApplication(); | ||
$user = Factory::getUser(); | ||
$user = $app->getIdentity(); | ||
$state = $this->get('State'); | ||
$item = $this->get('Item'); | ||
$this->form = $this->get('Form'); | ||
|
@@ -181,7 +188,7 @@ public function display($tpl = null) | |
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); | ||
$app->setHeader('status', 403, true); | ||
|
||
return false; | ||
return; | ||
} | ||
|
||
$options['category_id'] = $item->catid; | ||
|
@@ -383,7 +390,7 @@ public function display($tpl = null) | |
$item->text = $item->misc; | ||
} | ||
|
||
$app->triggerEvent('onContentPrepare', array ('com_contact.contact', &$item, &$this->params, $offset)); | ||
$app->triggerEvent('onContentPrepare', array('com_contact.contact', &$item, &$this->params, $offset)); | ||
|
||
// Store the events for later | ||
$item->event = new \stdClass; | ||
|
@@ -406,7 +413,7 @@ public function display($tpl = null) | |
if ($item->params->get('show_user_custom_fields') && $item->user_id && $contactUser = Factory::getUser($item->user_id)) | ||
{ | ||
$contactUser->text = ''; | ||
$app->triggerEvent('onContentPrepare', array ('com_users.user', &$contactUser, &$item->params, 0)); | ||
$app->triggerEvent('onContentPrepare', array('com_users.user', &$contactUser, &$item->params, 0)); | ||
|
||
if (!isset($contactUser->jcfields)) | ||
{ | ||
|
@@ -457,8 +464,9 @@ public function display($tpl = null) | |
} | ||
|
||
$this->_prepareDocument(); | ||
$this->addJsonSchema(); | ||
|
||
return parent::display($tpl); | ||
parent::display($tpl); | ||
} | ||
|
||
/** | ||
|
@@ -574,4 +582,104 @@ protected function _prepareDocument() | |
} | ||
} | ||
} | ||
|
||
/** | ||
* Prepares the document. | ||
* | ||
This comment was marked as abuse.
Sorry, something went wrong. |
||
* @return void | ||
*/ | ||
private function addJsonSchema() | ||
{ | ||
// Note we don't display tags here as the keywords property isn't valid for a person | ||
$schema = Schema::person() | ||
->if( | ||
$this->item->params->get('show_name'), | ||
function (Person $schema) { | ||
$schema->name($this->item->name); | ||
} | ||
) | ||
->if( | ||
$this->item->image && $this->item->params->get('show_image'), | ||
function (Person $schema) { | ||
$schema->image(Uri::root() . $this->item->image); | ||
} | ||
) | ||
->if( | ||
$this->item->params->get('show_position'), | ||
function (Person $schema) { | ||
$schema->jobTitle($this->item->con_position); | ||
} | ||
) | ||
->if( | ||
$this->item->params->get('address_check') > 0, | ||
function (Person $schema) { | ||
$schema->address( | ||
Schema::postalAddress() | ||
->if( | ||
$this->item->address && $this->params->get('show_street_address'), | ||
function (PostalAddress $schema) { | ||
$schema->streetAddress($this->item->address); | ||
} | ||
) | ||
->if( | ||
$this->item->suburb && $this->params->get('show_suburb'), | ||
function (PostalAddress $schema) { | ||
$schema->addressLocality($this->item->suburb); | ||
} | ||
) | ||
->if( | ||
$this->item->state && $this->params->get('show_state'), | ||
function (PostalAddress $schema) { | ||
$schema->addressRegion($this->item->state); | ||
} | ||
) | ||
->if( | ||
$this->item->postcode && $this->params->get('show_postcode'), | ||
function (PostalAddress $schema) { | ||
$schema->postalCode($this->item->postcode); | ||
} | ||
) | ||
->if( | ||
$this->item->country && $this->params->get('show_country'), | ||
function (PostalAddress $schema) { | ||
$schema->addressCountry($this->item->country); | ||
} | ||
) | ||
); | ||
} | ||
) | ||
// TODO: Should we expose the raw email like this? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do in the vcard download |
||
->if( | ||
$this->item->params->get('show_email') === '1', | ||
function (Person $schema) { | ||
$schema->email($this->item->email_raw); | ||
} | ||
) | ||
->if( | ||
$this->item->telephone && $this->params->get('show_telephone'), | ||
function (Person $schema) { | ||
$schema->telephone($this->item->telephone); | ||
} | ||
) | ||
->if( | ||
$this->item->fax && $this->params->get('show_fax'), | ||
function (Person $schema) { | ||
$schema->faxNumber($this->item->fax); | ||
} | ||
) | ||
->if( | ||
$this->item->mobile && $this->params->get('show_mobile'), | ||
function (Person $schema) { | ||
$schema->telephone($this->item->mobile); | ||
} | ||
) | ||
->if( | ||
$this->item->webpage && $this->params->get('show_webpage'), | ||
function (Person $schema) { | ||
$schema->url($this->item->webpage); | ||
} | ||
); | ||
|
||
$this->document->addScriptDeclaration(json_encode($schema, JDEBUG ? JSON_PRETTY_PRINT : 0), 'application/ld+json'); | ||
wilsonge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as abuse.
Sorry, something went wrong.