From 6b7b4e04fac46aeacd6cf717a63c57e7b708999d Mon Sep 17 00:00:00 2001 From: Alisha Date: Tue, 19 Jul 2022 19:06:52 +0530 Subject: [PATCH 1/3] Create 'Open Graph' tab & add fields --- .../components/com_content/forms/article.xml | 81 +++++++++++++++++++ .../com_content/tmpl/article/edit.php | 10 +++ administrator/language/en-GB/com_content.ini | 22 +++++ layouts/joomla/edit/opengraph.php | 31 +++++++ 4 files changed, 144 insertions(+) create mode 100644 layouts/joomla/edit/opengraph.php diff --git a/administrator/components/com_content/forms/article.xml b/administrator/components/com_content/forms/article.xml index acf8372d83..65b670f180 100644 --- a/administrator/components/com_content/forms/article.xml +++ b/administrator/components/com_content/forms/article.xml @@ -546,6 +546,87 @@ /> +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index 29ce01e10f..ccaf20c10b 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -171,6 +171,16 @@ + +
+ +
+ +
+
+ + + diff --git a/administrator/language/en-GB/com_content.ini b/administrator/language/en-GB/com_content.ini index e7186424ee..7c31d27232 100644 --- a/administrator/language/en-GB/com_content.ini +++ b/administrator/language/en-GB/com_content.ini @@ -50,6 +50,14 @@ 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="Open Graph" +COM_CONTENT_FIELD_ARTICLE_OG_AUTHOR="Author" +COM_CONTENT_FIELD_ARTICLE_OG_DESC="Description" +COM_CONTENT_FIELD_ARTICLE_OG_HIDE_MESSAGES="Disable Messages" +COM_CONTENT_FIELD_ARTICLE_OG_IMG="Image" +COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME="Published Date" +COM_CONTENT_FIELD_ARTICLE_OG_TITLE="Title" +COM_CONTENT_FIELD_ARTICLE_OG_TYPE="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" @@ -94,6 +102,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" @@ -141,6 +150,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" diff --git a/layouts/joomla/edit/opengraph.php b/layouts/joomla/edit/opengraph.php new file mode 100644 index 0000000000..d67364f67b --- /dev/null +++ b/layouts/joomla/edit/opengraph.php @@ -0,0 +1,31 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Factory; + +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Associations; +use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\Router\Route; +use Joomla\Registry\Registry; + +$form = $displayData->getForm(); + +foreach($form->getFieldset('opengraph') as $field) : + echo $field->renderField(); +endforeach; + +//echo $form->renderFieldset('opengraph'); + +?> \ No newline at end of file From 552a588894c445b979fb2ddca6526c2763ae65a2 Mon Sep 17 00:00:00 2001 From: Alisha Date: Thu, 21 Jul 2022 14:50:55 +0530 Subject: [PATCH 2/3] Add complete OG functionality --- .../components/com_content/forms/article.xml | 6 ++ .../com_content/tmpl/article/edit.php | 4 +- administrator/language/en-GB/com_content.ini | 6 ++ .../com_content/src/View/Article/HtmlView.php | 87 +++++++++++++++++++ layouts/joomla/edit/opengraph.php | 31 ------- 5 files changed, 101 insertions(+), 33 deletions(-) delete mode 100644 layouts/joomla/edit/opengraph.php diff --git a/administrator/components/com_content/forms/article.xml b/administrator/components/com_content/forms/article.xml index 65b670f180..1518d0dc54 100644 --- a/administrator/components/com_content/forms/article.xml +++ b/administrator/components/com_content/forms/article.xml @@ -568,6 +568,7 @@ type="list" default="article" label="COM_CONTENT_FIELD_ARTICLE_OG_TYPE" + description="COM_CONTENT_FIELD_ARTICLE_OG_TYPE_DESC" > @@ -589,6 +590,7 @@ type="calendar" default="" label="COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME" + description="COM_CONTENT_FIELD_ARTICLE_OG_PUBLISHED_TIME_DESC" showon="og_type:article" /> @@ -596,6 +598,7 @@ 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" /> @@ -603,6 +606,7 @@ name="og_title" type="text" label="COM_CONTENT_FIELD_ARTICLE_OG_TITLE" + description="COM_CONTENT_FIELD_ARTICLE_OG_TITLE_DESC" />
diff --git a/administrator/components/com_content/tmpl/article/edit.php b/administrator/components/com_content/tmpl/article/edit.php index ccaf20c10b..58fb0dcd9e 100644 --- a/administrator/components/com_content/tmpl/article/edit.php +++ b/administrator/components/com_content/tmpl/article/edit.php @@ -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); @@ -175,7 +175,7 @@
- + form->renderFieldset('opengraph'); ?>
diff --git a/administrator/language/en-GB/com_content.ini b/administrator/language/en-GB/com_content.ini index 7c31d27232..f31f1eebc7 100644 --- a/administrator/language/en-GB/com_content.ini +++ b/administrator/language/en-GB/com_content.ini @@ -52,12 +52,18 @@ COM_CONTENT_FEATURED_TABLE_CAPTION="Table of Featured Articles" COM_CONTENT_FEATURED_TITLE="Articles: Featured" COM_CONTENT_FIELD_ARTICLE_OG="Open Graph" 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_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" diff --git a/components/com_content/src/View/Article/HtmlView.php b/components/com_content/src/View/Article/HtmlView.php index 1678dd3d61..5185626692 100644 --- a/components/com_content/src/View/Article/HtmlView.php +++ b/components/com_content/src/View/Article/HtmlView.php @@ -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')); diff --git a/layouts/joomla/edit/opengraph.php b/layouts/joomla/edit/opengraph.php deleted file mode 100644 index d67364f67b..0000000000 --- a/layouts/joomla/edit/opengraph.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Component\ComponentHelper; -use Joomla\CMS\Language\Text; -use Joomla\CMS\Uri\Uri; -use Joomla\CMS\Factory; - -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Associations; -use Joomla\CMS\Layout\LayoutHelper; -use Joomla\CMS\Router\Route; -use Joomla\Registry\Registry; - -$form = $displayData->getForm(); - -foreach($form->getFieldset('opengraph') as $field) : - echo $field->renderField(); -endforeach; - -//echo $form->renderFieldset('opengraph'); - -?> \ No newline at end of file From dec0719be31fa3795c235ea3f6e5b884a25d2fd0 Mon Sep 17 00:00:00 2001 From: Alisha Date: Thu, 21 Jul 2022 16:30:57 +0530 Subject: [PATCH 3/3] Update language file --- administrator/language/en-GB/com_content.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/administrator/language/en-GB/com_content.ini b/administrator/language/en-GB/com_content.ini index f31f1eebc7..99bbad6f8f 100644 --- a/administrator/language/en-GB/com_content.ini +++ b/administrator/language/en-GB/com_content.ini @@ -55,6 +55,7 @@ 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="
If you don't define any of the OG images, it will first look for an intro image and then for an article image
" 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"