Skip to content
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

Open Graph #9

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions administrator/components/com_content/forms/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,93 @@
/>
</fieldset>

<fieldset name="opengraph" label="JGLOBAL_FIELDSET_OPENGRAPH_OPTIONS">
<field name="hide_messages"
type="radio"
default="0"
label="COM_CONTENT_FIELD_ARTICLE_OG_HIDE_MESSAGES"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="og"
type="spacer"
default=""
label="COM_CONTENT_FIELD_ARTICLE_OG"
/>

<field
name="og_type"
type="list"
default="article"
label="COM_CONTENT_FIELD_ARTICLE_OG_TYPE"
description="COM_CONTENT_FIELD_ARTICLE_OG_TYPE_DESC"
>
<option value="article">COM_CONTENT_OPENGRAPH_ARTICLE</option>
<option value="product">COM_CONTENT_OPENGRAPH_PRODUCT</option>
<option value="book">COM_CONTENT_OPENGRAPH_BOOK</option>
<option value="profile">COM_CONTENT_OPENGRAPH_PROFILE</option>
<option value="website">COM_CONTENT_OPENGRAPH_WEBSITE</option>
<option value="video.movie">COM_CONTENT_OPENGRAPH_VIDEO_MOVIE</option>
<option value="video.episode">COM_CONTENT_OPENGRAPH_VIDEO_EPISODE</option>
<option value="video.tvshow">COM_CONTENT_OPENGRAPH_VIDEO_TVSHOW</option>
<option value="video.other">COM_CONTENT_OPENGRAPH_VIDEO_OTHER</option>
<option value="music.song">COM_CONTENT_OPENGRAPH_MUSIC_SONG</option>
<option value="music.album">COM_CONTENT_OPENGRAPH_MUSIC_ALBUM</option>
<option value="music.playlist">COM_CONTENT_OPENGRAPH_MUSIC_PLAYLIST</option>
<option value="music.radio_station">COM_CONTENT_OPENGRAPH_MUSIC_RADIOSTATION</option>
</field>

<field
name="og_article_published_time"
type="calendar"
default=""
label="COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME"
description="COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME_DESC"
showon="og_type:article"
/>

<field
name="og_article_author"
type="text"
label="COM_CONTENT_FIELD_ARTICLE_OG_AUTHOR"
description="COM_CONTENT_FIELD_ARTICLE_OG_AUTHOR_DESC"
showon="og_type:article"
/>

<field
name="og_title"
type="text"
label="COM_CONTENT_FIELD_ARTICLE_OG_TITLE"
description="COM_CONTENT_FIELD_ARTICLE_OG_TITLE_DESC"
/>

<field
name="og_description"
type="textarea"
default=""
label="COM_CONTENT_FIELD_ARTICLE_OG_DESC"
description="COM_CONTENT_FIELD_ARTICLE_OG_DESC_DESC"
/>

<field
name="g_help"
type="spacer"
label="COM_CONTENT_FIELD_ARTICLE_OG_G_HELP"
class="text"
showon="hide_messages:0"
/>

<field
name="og_img"
type="media"
label="COM_CONTENT_FIELD_ARTICLE_OG_IMG"
description="COM_CONTENT_FIELD_ARTICLE_OG_IMG_DESC"
/>
</fieldset>

</fieldset>

<fieldset name="editorConfig" label="COM_CONTENT_EDITORCONFIG_FIELDSET_LABEL">
Expand Down
12 changes: 11 additions & 1 deletion administrator/components/com_content/tmpl/article/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
->useScript('com_contenthistory.admin-history-versions');

$this->configFieldsets = array('editorConfig');
$this->hiddenFieldsets = array('basic-limited');
$this->hiddenFieldsets = array('basic-limited', 'opengraph');
$fieldsetsInImages = ['image-intro', 'image-full'];
$fieldsetsInLinks = ['linka', 'linkb', 'linkc'];
$this->ignore_fieldsets = array_merge(array('jmetadata', 'item_associations'), $fieldsetsInImages, $fieldsetsInLinks);
Expand Down Expand Up @@ -171,6 +171,16 @@
<?php echo HTMLHelper::_('uitab.endTab'); ?>
<?php endif; ?>

<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'opengraph', Text::_('COM_CONTENT_FIELDSET_OPENGRAPH')); ?>
<fieldset id="fieldset-opengraph" class="options-form">
<legend><?php echo Text::_('COM_CONTENT_FIELDSET_OPENGRAPH'); ?></legend>
<div>
<?php echo $this->form->renderFieldset('opengraph'); ?>
</div>
</fieldset>

<?php echo HTMLHelper::_('uitab.endTab'); ?>

<?php echo HTMLHelper::_('uitab.endTabSet'); ?>

<?php // Creating 'id' hiddenField to cope with com_associations sidebyside loop ?>
Expand Down
29 changes: 29 additions & 0 deletions administrator/language/en-GB/com_content.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ COM_CONTENT_FEATURED_CATEGORIES_LABEL="Select Categories"
COM_CONTENT_FEATURED_ORDER="Featured Articles Order"
COM_CONTENT_FEATURED_TABLE_CAPTION="Table of Featured Articles"
COM_CONTENT_FEATURED_TITLE="Articles: Featured"
COM_CONTENT_FIELD_ARTICLE_OG="<strong>Open Graph</strong>"
COM_CONTENT_FIELD_ARTICLE_OG_AUTHOR="Author"
COM_CONTENT_FIELD_ARTICLE_OG_AUTHOR_DESC="Mention the Article's Author"
COM_CONTENT_FIELD_ARTICLE_OG_DESC="Description"
COM_CONTENT_FIELD_ARTICLE_OG_DESC_DESC="Write a meaningful text with call to action"
COM_CONTENT_FIELD_ARTICLE_OG_G_HELP="<div class=\"alert alert-info\" style="width:100%">If you don't define any of the OG images, it will first look for an intro image and then for an article image</div>"
COM_CONTENT_FIELD_ARTICLE_OG_HIDE_MESSAGES="Disable Messages"
COM_CONTENT_FIELD_ARTICLE_OG_IMG="Image"
COM_CONTENT_FIELD_ARTICLE_OG_IMG_DESC="Upload an image"
COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME="Published Date"
COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME_DESC="Select Item Published Time. Leave it empty to use the created time of the item."
COM_CONTENT_FIELD_ARTICLE_OG_TITLE="Title"
COM_CONTENT_FIELD_ARTICLE_OG_TITLE_DESC="Define a Meta title."
COM_CONTENT_FIELD_ARTICLE_OG_TYPE="Page type"
COM_CONTENT_FIELD_ARTICLE_OG_TYPE_DESC="Define the page type"
COM_CONTENT_FIELD_ARTICLETEXT_LABEL="Article Text"
COM_CONTENT_FIELD_BROWSER_PAGE_TITLE_LABEL="Browser Page Title"
COM_CONTENT_FIELD_CAPTCHA_LABEL="Allow Captcha on submit"
Expand Down Expand Up @@ -94,6 +109,7 @@ COM_CONTENT_FIELDS_ARTICLE_FIELD_ADD_TITLE="Articles: New Field"
COM_CONTENT_FIELDS_ARTICLE_FIELD_EDIT_TITLE="Articles: Edit Field"
COM_CONTENT_FIELDS_ARTICLE_FIELDS_TITLE="Articles: Fields"
COM_CONTENT_FIELDS_TYPE_MODAL_ARTICLE="Article"
COM_CONTENT_FIELDSET_OPENGRAPH="Open Graph"
COM_CONTENT_FIELDSET_PUBLISHING="Publishing"
COM_CONTENT_FIELDSET_RULES="Permissions"
COM_CONTENT_FIELDSET_URLS_AND_IMAGES="Images and Links"
Expand Down Expand Up @@ -141,6 +157,19 @@ COM_CONTENT_NEW_ARTICLE="New Article"
COM_CONTENT_NO_ARTICLES_LABEL="No Articles Message"
COM_CONTENT_NO_ITEM_SELECTED="Please first make a selection from the list."
COM_CONTENT_NUMBER_CATEGORY_ITEMS_LABEL="# Articles in Category"
COM_CONTENT_OPENGRAPH_ARTICLE="Article"
COM_CONTENT_OPENGRAPH_BOOK="Book"
COM_CONTENT_OPENGRAPH_MUSIC_PLAYLIST="Music - Playlist"
COM_CONTENT_OPENGRAPH_MUSIC_RADIOSTATION="Music - Radio Station"
COM_CONTENT_OPENGRAPH_MUSIC_SONG="Music - Song"
COM_CONTENT_OPENGRAPH_MUSIC_ALBUM="Music - Album"
COM_CONTENT_OPENGRAPH_PRODUCT="Product"
COM_CONTENT_OPENGRAPH_PROFILE="Profile"
COM_CONTENT_OPENGRAPH_VIDEO_EPISODE="Video - Episode"
COM_CONTENT_OPENGRAPH_VIDEO_MOVIE="Video - Movie"
COM_CONTENT_OPENGRAPH_VIDEO_OTHER="Video - Other"
COM_CONTENT_OPENGRAPH_VIDEO_TVSHOW="Video - TV Show"
COM_CONTENT_OPENGRAPH_WEBSITE="Website"
COM_CONTENT_OTHER_OPTIONS="Options"
COM_CONTENT_PAGE_ADD_ARTICLE="Articles: New"
COM_CONTENT_PAGE_EDIT_ARTICLE="Articles: Edit"
Expand Down
87 changes: 87 additions & 0 deletions components/com_content/src/View/Article/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,93 @@ protected function _prepareDocument()
$this->document->setDescription($this->params->get('menu-meta_description'));
}

$url = Uri::root() . RouteHelper::getArticleRoute($this->item->id . ':' . $this->item->alias, $this->item->catid, $this->item->language);
if ($url)
{
$this->document->setMetaData('og:url', $url, 'property');
}

$config = Factory::getConfig();
if ($config->get('sitename'))
{
$this->document->setMetaData('og:site_name', $config->get('sitename'), 'property');
}

if ($this->item->params->get('og_type'))
{
$this->document->setMetaData('og:type', $this->item->params->get('og_type'), 'property');
}

if ($this->item->title)
{
//if (og:title not set)
$this->document->setMetaData('og:title', $this->item->title, 'property');
if ($this->item->params->get('og_title'))
{
$this->document->setMetaData('og:title', $this->item->params->get('og_title'), 'property');
}

}

if ($this->item->metadesc)
{
$this->document->setMetaData('og:description', $this->item->metadesc, 'property');
if ($this->item->params->get('og_description'))
{
$this->document->setMetaData('og:description', $this->item->params->get('og_description'), 'property');
}

}

if ($this->item->publish_up)
{
$this->document->setMetaData('article:published_time', $this->item->publish_up, 'property');
if ($this->item->params->get('og_article_published_time'))
{
$this->document->setMetaData('article:published_time', $this->item->params->get('og_article_published_time'), 'property');
}

}

if ($this->item->author)
{
$this->document->setMetaData('article:author', $this->item->author, 'property');
if ($this->item->params->get('og_article_author'))
{
$this->document->setMetaData('article:author', $this->item->params->get('og_article_author'), 'property');
}

}

$images = json_decode($this->item->images);
$img_url = "";
if ($images->image_intro)
{
$img_url = $images->image_intro;
}
if ($images->image_fulltext)
{
$img_url = $images->image_fulltext;
}
if ($this->item->params->get('og_img'))
{
$img_url = $this->item->params->get('og_img');
}
if ($img_url)
{
$img = substr($img_url, 0, strpos($img_url, '#'));
$img_url = Uri::base() . substr($img_url, 0, strpos($img_url, '#'));
$img_info = getimagesize($img);
$this->document->setMetaData('og:image', $img_url, 'property');
$this->document->setMetaData('og:image:secure_url', $img_url, 'property');
if (\is_array($img_info))
{
$this->document->setMetaData('og:image:type', $img_info['mime'], 'property');
$this->document->setMetaData('og:image:height', $img_info[1]);
$this->document->setMetaData('og:image:width', $img_info[0]);
}
}

if ($this->params->get('robots'))
{
$this->document->setMetaData('robots', $this->params->get('robots'));
Expand Down