Пример #1
1
	function onBeforeDisplayContent( &$article, &$params, $limitstart ){
		//this may fire fron a component other than com_content
		
		if(!file_exists(JPATH_SITE.DS.'plugins'.DS.'system'.DS.'myApiConnectFacebook.php') || ( !array_key_exists('category',$article) && !array_key_exists('showK2Plugins',$params)  )){ return; }
		
		if((@$article->id != '') && (@$_POST['fb_sig_api_key'] == '') && class_exists('plgSystemmyApiOpenGraph')){
			$row = & JTable::getInstance('content');
			$row->load($article->id);
			$attribs = new JParameter($row->attribs);
			if($attribs->get('ogimage','') == ''){
				$attribs->set('ogimage',plgContentmyApiOpenGraphContent::getContentImage($article->text));
				$row->attribs = $attribs->toString();
				$row->bind($row);
				$row->store();
			}
			//Set open graph tags
			if(JRequest::getVar('view','','get') == 'article' || (JRequest::getVar('option','','get') == 'com_k2' && JRequest::getVar('view','','get') == 'item')){
				if(isset($article->slug)){
					require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
					$link = ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid);
				}elseif(method_exists('K2HelperRoute','getItemRoute')){
					$link = K2HelperRoute::getItemRoute($article->id.':'.urlencode($article->alias),$article->catid.':'.urlencode($article->category->alias));
				}else{
					error_log('myApi unable to calculate link for the article id '.$article->id);
					return;
				}
				$u =& JURI::getInstance( JURI::base().$link );
				$port 	= ($u->getPort() == '') ? '' : ":".$u->getPort();
				$articleURL = 'http://'.$u->getHost().$port.$u->getPath().'?'.$u->getQuery();
				$rawText = strip_tags($article->introtext);
				$newTags = array();
				$newTags['og:title'] 		= $article->title;
				$newTags['og:description'] 	= (strlen($rawText) > 247) ? substr($rawText,0,247).'...' : $rawText;
				$newTags['og:type']	= 'article';
				$newTags['og:author']	= (is_object($article->author)) ? $article->author->name : $article->author;
				$newTags['og:url'] 	= $articleURL;
				if($attribs->get('ogimage','0') != '0') $newTags['og:image'] = $attribs->get('ogimage');
				
				plgSystemmyApiOpenGraph::setTags($newTags);
			}
		}
	}
Пример #2
0
	function plgSystemmyApiOpenGraph(&$subject, $config){
		parent::__construct($subject, $config);
		if(!class_exists('plgSystemmyApiConnect')) return;
		
		$cache = & JFactory::getCache('plgSystemmyApiOpenGraph - FB Admins query');
		$cache->setCaching( 1 );
		$config 	=& JFactory::getConfig();
		$connect_plugin 	=& JPluginHelper::getPlugin('system', 'myApiConnect');
		$connect_params 	= new JParameter( $connect_plugin->params );
		
		$plugin =& JPluginHelper::getPlugin('system', 'myApiOpenGraph');
		$plugin_params = new JParameter( $plugin->params );
		
		$db_admins = $cache->call( array( 'plgSystemmyApiOpenGraph', 'getFbAdmins'));
		$param_admins = ($plugin_params->get('fbadmins') != '') ? explode(',',$plugin_params->get('fbadmins')) : array();
		$admins = array_merge($db_admins,$param_admins);
		
		$ogptags_default					= array();
		$ogptags_default['og:title']		= $config->getValue( 'config.sitename' );
		$ogptags_default['og:type'] 		= 'website';
		$ogptags_default['og:url'] 			= JURI::getInstance()->toString();
		$ogptags_default['og:site_name']	= $config->getValue( 'config.sitename' );
		$ogptags_default['fb:app_id'] 		= $connect_params->get('appId');
		$ogptags_default['fb:admins']		= implode(',',$admins);
		if($plugin_params->get('ogimage') != '' && $plugin_params->get('ogimage') != -1) $ogptags_default['og:image'] = JURI::base().'images/'.$plugin_params->get('ogimage');
		if($plugin_params->get('fbpageid') != '') $ogptags_default['fb:page_id'] = $plugin_params->get('fbpageid');
		
		
		plgSystemmyApiOpenGraph::setTags($ogptags_default);
	}