File manager - Edit - /home/jardides/www/Jardi-design/plugins/content/socialmeta/socialmeta.php
Back
<?php /** * Social Meta : Plugin for Joomla Content for more efficient sharing results in Social Media. * @version $Id: socialmeta.php 1.0.0 * @site http://www.templateplazza.com * @package Joomla 3.6.x * @copyright Copyright (C) 2016 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; jimport( 'joomla.event.plugin' ); //require_once JPATH_SITE.'/components/com_content/helpers/route.php'; class plgContentsocialmeta extends JPlugin { function __construct(&$subject, $params){ parent::__construct( $subject, $params ); } function onContentPrepare( $context, &$row, &$params, $limitstart=0 ) { $pluginbase = ''.JURI::base(true).'/plugins/content/socialmeta/'; $doc = JFactory::getDocument(); //processing variables $input = JFactory::getApplication()->input; $option = $input->getCmd('option'); // This gets the component $view = $input->getCmd('view'); // This gets the view, article, category, featured $layout = $input->getCmd('layout'); // This gets the view's layout, blog /** COM CONTENT START **/ /* article page */ if ($option == 'com_content' && $view == 'article') { $id = $input->getInt('id'); //get the article ID $article = JTable::getInstance('content'); $article->load($id); $title = $article->get('title'); $type = "article"; //date $date = new JDate($article->get('created')); $published_time = $date->toISO8601(false); $mdate = new JDate($article->get('modified')); $modified_time = $mdate->toISO8601(); //author $authorId = $article->get('created_by'); $user = JFactory::getUser($authorId); $author = $user->name; //category title $catid = $article->get('catid'); $db = JFactory::getDbo(); $db->setQuery("SELECT cat.title FROM #__categories cat WHERE cat.id='$catid'"); $categoryname = $db->loadResult(); //image $image =""; $images = json_decode($article->get('images')); //get introtext $introtext = $article->get('introtext'); //get image from intro image if(!empty($images->image_intro) ) { $image = JURI::root().htmlspecialchars($images->image_intro); } // if no intro image then find full image elseif ( empty($images->image_intro) && !empty($images->image_fulltext) ) { $image = JURI::root().htmlspecialchars($images->image_fulltext); } // if no intro image and full image then find image on article elseif ( empty($images->image_intro) && empty($images->image_fulltext) ) { preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $introtext, $src); if (isset($src[1]) && $src[1] != '') { $absU = 0; // Test if this link is absolute http:// then do not change it $pos1 = strpos($src[1], 'http://'); if ($pos1 === false) { } else { $absU = 1; } // Test if this link is absolute https:// then do not change it $pos2 = strpos($src[1], 'https://'); if ($pos2 === false) { } else { $absU = 1; } if ($absU == 1) { $image = $src[1]; } else { $image = JURI::base(false).$src[1]; } } } // short description, removed the html tags and limit the characters to 250 max if($article->metadesc){ $shortdesc = $article->metadesc; } else { $shortdesc = substr(strip_tags($introtext), 0, 250); $shortdesc = str_replace("\n", "", $shortdesc); } } // category page elseif($option == 'com_content' && $view == 'category') { $id = $input->getInt('id'); //get the category ID $cat = JTable::getInstance('category'); $cat->load($id); $title = $doc->getTitle(); $type = "website"; $published_time = ""; $modified_time = ""; $author = ""; $categoryname = ""; $catimage = json_decode($cat->params); if(!empty($catimage->image)){ $image = JURI::root().$catimage->image; } else { $image = ""; } $shortdesc = $doc->getMetaData("description"); } else { $title = $doc->getTitle(); $type = "website"; $published_time = ""; $modified_time = ""; $author = ""; $categoryname = ""; $image = ""; $shortdesc = $doc->getMetaData("description"); } /** COM CONTENT END **/ $url = JUri::getInstance(); $config = JFactory::getConfig(); $lang = JFactory::getLanguage(); $language = str_replace("-","_",$lang->getTag()); /** START of FB metadata **/ $doc->setMetaData( 'og:locale', $language, 'property'); $doc->setMetaData( 'og:site_name', $config->get('sitename'), 'property'); $doc->setMetaData( 'og:title', htmlspecialchars($title), 'property'); $doc->setMetaData( 'og:type', $type, 'property'); if ($option == 'com_content' && $view == 'article') { $doc->setMetaData( 'article:published_time', $published_time, 'property' ); $doc->setMetaData( 'article:modified_time', $modified_time, 'property'); $doc->setMetaData( 'article:author', $this->params->get('fbprofileurl'), 'property'); $doc->setMetaData( 'article:section', htmlspecialchars($categoryname), 'property'); } $doc->setMetaData( 'og:url', $url, 'property' ); $doc->setMetaData( 'og:description', htmlspecialchars($shortdesc), 'property'); $doc->setMetaData( 'og:image', $image, 'property'); /** END of FB Metadata **/ /** START of Twitter metadata **/ $doc->setMetaData( 'twitter:card', 'summary_large_image' ); $doc->setMetaData( 'twitter:site', $this->params->get('twittername') ); $doc->setMetaData( 'twitter:creator', $this->params->get('twittername') ); $doc->setMetaData( 'twitter:title', $title ); $doc->setMetaData( 'twitter:description', htmlspecialchars($shortdesc)); $doc->setMetaData( 'twitter:image', $image ); /** END of Twitter Metadata **/ /** START of Google+ metadata (schema.org) **/ $doc->setMetaData( 'name', htmlspecialchars($title) ); if ($option == 'com_content' && $view == 'article') { $doc->setMetaData( 'author', $this->params->get('gplusprofileurl') ); } $doc->setMetaData( 'description', htmlspecialchars($shortdesc)); $doc->setMetaData( 'image', $image ); /** END of Google+ metadata **/ } } ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings