Доработка приведение кода в нормальный вид

More
8 years 1 month ago - 8 years 1 month ago #5926 by Aoki Daisuke
Долго объяснять, проще показать все изменения в файле:
jlcomments.php
<?php
/**
 * JLcomments
 *
 * @version 2.6
 * @author Kunitsyn Vadim (vadim@joomline.ru), Artem Jukov (artem@joomline.ru)
 * @copyright (C) 2011 by Kunitsyn Vadim(http://www.joomline.ru)
 * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
 **/
 
// no direct access
defined('_JEXEC') or die;
 
jimport('joomla.plugin.plugin');
 
class plgContentJlcomments extends JPlugin
{
 
	public function onContentPrepare($context, &$article, &$params, $page = 0){
		if($context == 'com_content.article'){
		if (strpos($article->text, '{jlcomments-off}') !== false) {
			$article->text = str_replace("{jlcomments-off}","",$article->text);
			return true;
		}
 
		if (strpos($article->text, '{jlcomments}') === false && !$this->params->def('autoAdd')) {
			return true;
		}
 
		$exceptcat = is_array($this->params->def('categories')) ? $this->params->def('categories') : array($this->params->def('categories'));
		if (!in_array($article->catid,$exceptcat)) {
			$view = JRequest::getCmd('view');
			if ($view == 'article') {
				$doc = JFactory::getDocument();
				$uri = JURI::getInstance();
				$base = $uri->toString(array('scheme', 'host', 'port'));
				$article_url = $base.JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->catslug));
 
 
				$apiId 			= $this->params->def('apiId');
				$widthvk 		= $this->params->def('widthvk');
				$widthfb 		= $this->params->def('widthfb');
				$widthgoogle 	= $this->params->def('widthgoogle');
				$comLimit 		= $this->params->def('comLimit');
				$attach 		= $this->params->def('attach');
				$autoPublish	= $this->params->def('autoPublish');
				$norealtime 	= $this->params->def('norealtime');
				$fbId 			= $this->params->def('fbId');
				$fbadmin 		= $this->params->def('fbadmin');
				$fb_lang 		= $this->params->def('fb_lang');
				$typeviewerjq 	= $this->params->def('typeviewerjq');
				$typeviewerbs 	= $this->params->def('typeviewerbs');
				$typeviewernojq = $this->params->def('typeviewernojq');
				$typeviewercss	= $this->params->def('typeviewercss');
				$link 			= $this->params->def('link');
				$colorscheme 	= $this->params->def('colorscheme');
				$order_by_fb	= $this->params->def('orderbyfb');
				$linknone		= '';
				$lang = JFactory::getLanguage();
				$lang->load('plg_content_jlcomments', JPATH_ADMINISTRATOR);
				$jlcomments_comments = JText::_('PLG_JLCOMMENTS_COMMENTS');
				$jlcomments_vk = JText::_('PLG_JLCOMMENTS_VK');
				$jlcomments_fb = JText::_('PLG_JLCOMMENTS_FB');
				$jlcomments_google = JText::_('PLG_JLCOMMENTS_GOOGLE');
 
				$script = "VK.init({apiId: $apiId, onlyWidgets: true});";
				$doc->addCustomTag('<meta property="fb:admins" content="'.$fbadmin.'"/>');
				$doc->addCustomTag('<meta property="fb:app_id" content="'.$fbId.'"/>');
				$doc->addScript("//vk.com/js/api/openapi.js?95");
				$doc->addCustomTag('<script src="https://apis.google.com/js/plusone.js" type="text/javascript">/* {lang: "'.$fb_lang.'"} */</script>');
				$doc->addScriptDeclaration($script);
				$pagehash = $article->id;
				$orders = explode(",",$this->params->def('orders'));
				if (($this->params->def('googleid')!='')&&($this->params->def('googleplus'))){
					$doc->addCustomTag('<link rel="author" href="https://plus.google.com/'. $this->params->def('googleid') .'/">');
				}
				else {}
 
				if ($link==0){
					$linknone = 'display:none;';
					}
				else {}
 
				If ($typeviewerjq==1) {
					$doc->addCustomTag('<script src="http://yandex.st/jquery/1.9.1/jquery.min.js"></script>');
					}
				If ($typeviewercss==1) {
					$doc->addStyleSheet("/plugins/content/jlcomments/css/jlcomtabs.css");
					}
				If ($typeviewerbs==1) {
					$doc->addCustomTag('<script src="http://yandex.st/bootstrap/2.3.0/js/bootstrap.min.js"></script>');
					}
				If ($typeviewernojq==1) {
					$doc->addCustomTag ('<script type="text/javascript">var jqjlcomm = jQuery.noConflict();</script>');
					}
				else {}
 
                $comments = JPATH_SITE . '/components/com_jcomments/jcomments.php';
                  if (file_exists($comments)) {
                    require_once($comments);
                    $options['object_id'] = $pagehash;
                    $options['object_group'] = 'com_content';
                    $options['published'] = 1;
                    $count = JCommentsModel::getCommentsCount($options);
                  }
 
	$scriptPage = <<<HTML
		<div style="clear:both">&nbsp;</div><div id="jlcomments_container"><ul class="nav nav-tabs" id="plgjlcomments1">
HTML;
 
 
 
	foreach ($orders as $order) {
		switch($order) {
			case 1:	if ($this->params->def('showjcomments')) { $scriptPage .= <<<HTML
				<li style="list-style-type: none;" class="active"><a href="#jcommentscomm" data-toggle="tab"><i class="jlico-comments"></i> $jlcomments_comments ($count)</a></li>
HTML;
			} else {$scriptPage .='';$showjcomments='-1';} break;
			case 2:	if ($this->params->def('showvkontakte')) { $scriptPage .= <<<HTML
				<script type="text/javascript">
					/* <![CDATA[ */
					jQuery(document).ready(function(){
					jQuery.ajax({
					url: "https://api.vk.com/method/widgets.getComments.json?widget_api_id=$apiId&page_id=$pagehash",
					dataType: 'jsonp',
					success: function(data){
					jQuery('#vk_count').text(data.response.count); 
					},
					error: function(data){
					console.log(data);
					}
					}); 
					});
					/* ]]> */
				</script>
				<li style="list-style-type: none;"><a href="#vkcomm" data-toggle="tab"><i class="jlico-vk"></i> $jlcomments_vk (<span id="vk_count"></span>)</a></li>
HTML;
			} else {$scriptPage .='';} break;
			case 3:	if ($this->params->def('googleplus')) {
				$width_ = $widthgoogle.'px';
				$doc = JFactory::getDocument();
				$style1 = '#googlecomm * {width:$width_ !important;min-height:600px !important;}';
				$doc->addStyleDeclaration( $style1 );
				$scriptPage .= <<<HTML
					<li style="list-style-type: none;"><a href="#googlecomm" data-toggle="tab"><i class="jlico-google"></i> $jlcomments_google</a></li>
HTML;
			} else {$scriptPage .='';} break;
			case 4:	if ($this->params->def('showfacebook')) {$doc = JFactory::getDocument();
				$style2 = '.fb-comments,.fb-comments span,.fb-comments iframe {min-height: 300px!important; width:100%!important;} .fb_hide_iframes iframe {left:0px !important;}';
				$doc->addStyleDeclaration( $style2 );
			$scriptPage .= <<<HTML
 
				<li style="list-style-type: none;"><a href="#fbcomm" data-toggle="tab"><div><i class="jlico-facebook"></i> $jlcomments_fb (<span class="fb-comments-count" data-href="$article_url"></span>)</div></a></li>
HTML;
			} else {$scriptPage .='';} break;
			}			
			}
 
		$scriptPage .= <<<HTML
			</ul>
			<div class="tab-content">
HTML;
	foreach ($orders as $order) {		
		switch($order) {		
			case 1: if ($this->params->def('showjcomments')) { $scriptPage .= <<<HTML
				<div class="tab-pane active" id="jcommentscomm">
					{jcomments}
				</div>
HTML;
			} else {$scriptPage .='';$showjcomments='-1';} break;
			case 2: if ($this->params->def('showvkontakte')) { $scriptPage .= <<<HTML
				<div class="tab-pane" id="vkcomm">
					<div id='jlcomments'></div>
						<script type='text/javascript'>
						/* <![CDATA[ */
							VK.Widgets.Comments('jlcomments', {limit: $comLimit, width: '$widthvk', attach: '$attach', autoPublish: $autoPublish, norealtime: $norealtime},$pagehash);
						/* ]]> */
						</script>
				</div>
 
HTML;
			} else {$scriptPage .='';} break;	
			case 3: if ($this->params->def('googleplus')) { 
 
				$scriptPage .= <<<HTML
 
 
 
					<div class="tab-pane" id="googlecomm">		
 
						<div class="g-comments"
							data-href="$article_url"
							data-width="$widthgoogle"
							data-first_party_property="BLOGGER"
							data-view_type="FILTERED_POSTMOD">
						</div>
					</div>
HTML;
			} else {$scriptPage .='';} break;						
			case 4: if ($this->params->def('showfacebook')) { $scriptPage .= <<<HTML
                <div class="tab-pane" id="fbcomm">
						<script type="text/javascript">/* <![CDATA[ */(function(d, s, id) {
						var js, fjs = d.getElementsByTagName(s)[0];
						if (d.getElementById(id)) return;
						js = d.createElement(s); js.id = id;
						js.src = "//connect.facebook.net/$fb_lang/all.js#xfbml=1&version=v2.0";
						fjs.parentNode.insertBefore(js, fjs);
						}(document, 'script', 'facebook-jssdk'));/* ]]> */</script>
					<div class="fb-comments" data-href="$article_url" data-num-posts="$comLimit" data-width="$widthfb" data-colorscheme="$colorscheme" data-order-by="$order_by_fb"></div>
				</div>				
 
 
HTML;
			} else {$scriptPage .='';} break;
		}
	}
	$scriptPage .= <<<HTML
		 </div>	
	</div>
		<script type="text/javascript">
			/* <![CDATA[ */
			jQuery(document).ready(function(){
			jQuery('#plgjlcomments1 a:first').tab('show');
			});
			/* ]]> */
		</script>
	<div style="text-align: right; $linknone;">
		<a style="text-decoration:none; color: #c0c0c0; font-family: arial,helvetica,sans-serif; font-size: 5pt; " target="_blank" href="http://www.38i.ru">www.38i.ru</a>
	</div>
HTML;
 
		if ($this->params->def('autoAdd') == 1) {
			$article->text .= $scriptPage;
			} else {
				$article->text = str_replace("{jlcomments}",$scriptPage,$article->text);
				}
 
			}
		} else {
				$article->text = str_replace("{jlcomments}","",$article->text);
			}
 
		}
	}
}
данный код рабочий и проходит по валидации
Last edit: 8 years 1 month ago by Aoki Daisuke.

Please Log in or Create an account to join the conversation.

More
8 years 1 month ago #5927 by JoomLine
А чем отличается от оригинала, кроме того, что вы вынесли в хидер некоторые стлили?

Please Log in or Create an account to join the conversation.

More
8 years 1 month ago - 8 years 1 month ago #5928 by Aoki Daisuke
Для начало неплохо было бы залить скрипт на github.com, как у JoomlaWorks сделано:
github.com/joomlaworks/allvideos

Эту модификацию я делал:
github.com/lev99/mod_amoney

социальные кнопки тоже делал, но так и не пригодилось не для одного проекта :evil:

GitHub — крупнейший веб-сервис для хостинга IT-проектов и их совместной разработки. Основан на системе контроля версий Git и разработан на Ruby on Rails и Erlang компанией GitHub, Inc (ранее Logical Awesome).


Так было бы заметней когда я правлю и ссылки на изменение проще писать.
а так по изменениям
$doc->addCustomTag('<script src="https://apis.google.com/js/plusone.js" type="text/javascript">/* {lang: "'.$fb_lang.'"} */</script>');
$scriptPage = <<<HTML
		<div style="clear:both">&nbsp;</div><div id="jlcomments_container"><ul class="nav nav-tabs" id="plgjlcomments1">
HTML;
<li style="list-style-type: none;"><a href="#fbcomm" data-toggle="tab"><div><i class="jlico-facebook"></i> $jlcomments_fb (<span class="fb-comments-count" data-href="$article_url"></span>)</div></a></li>

HTML;
				<script type="text/javascript">
					/* <![CDATA[ */
					jQuery(document).ready(function(){
					jQuery.ajax({
					url: "https://api.vk.com/method/widgets.getComments.json?widget_api_id=$apiId&page_id=$pagehash",
					dataType: 'jsonp',
					success: function(data){
					jQuery('#vk_count').text(data.response.count); 
					},
					error: function(data){
					console.log(data);
					}
					}); 
					});
					/* ]]> */
				</script>
						<script type='text/javascript'>
						/* <![CDATA[ */
							VK.Widgets.Comments('jlcomments', {limit: $comLimit, width: '$widthvk', attach: '$attach', autoPublish: $autoPublish, norealtime: $norealtime},$pagehash);
						/* ]]> */
						</script>
              <div class="tab-pane" id="fbcomm">
						<script type="text/javascript">/* <![CDATA[ */(function(d, s, id) {
						var js, fjs = d.getElementsByTagName(s)[0];
						if (d.getElementById(id)) return;
						js = d.createElement(s); js.id = id;
						js.src = "//connect.facebook.net/$fb_lang/all.js#xfbml=1&version=v2.0";
						fjs.parentNode.insertBefore(js, fjs);
						}(document, 'script', 'facebook-jssdk'));/* ]]> */</script>
					<div class="fb-comments" data-href="$article_url" data-num-posts="$comLimit" data-width="$widthfb" data-colorscheme="$colorscheme" data-order-by="$order_by_fb"></div>
				</div>
		<script type="text/javascript">
			/* <![CDATA[ */
			jQuery(document).ready(function(){
			jQuery('#plgjlcomments1 a:first').tab('show');
			});
			/* ]]> */
		</script>
		} else {$scriptPage .='';} break;
			case 3:	if ($this->params->def('googleplus')) {
				$width_ = $widthgoogle.'px';
				$doc = JFactory::getDocument();
				$style1 = '#googlecomm * {width:$width_ !important;min-height:600px !important;}';
				$doc->addStyleDeclaration( $style1 );
				$scriptPage .= <<<HTML
					<li style="list-style-type: none;"><a href="#googlecomm" data-toggle="tab"><i class="jlico-google"></i> $jlcomments_google</a></li>
HTML;
case 4:	if ($this->params->def('showfacebook')) {$doc = JFactory::getDocument();
				$style2 = '.fb-comments,.fb-comments span,.fb-comments iframe {min-height: 300px!important; width:100%!important;} .fb_hide_iframes iframe {left:0px !important;}';
				$doc->addStyleDeclaration( $style2 );

приблизительно всё
ваш
jsfiddle.net/buxwfs5b/
мой
jsfiddle.net/53k4qkts/

забыл добавить, результат данных изменений, скрипт стал подгружаться быстрее, а значит лучше работать!
Last edit: 8 years 1 month ago by Aoki Daisuke.

Please Log in or Create an account to join the conversation.

More
8 years 4 days ago - 8 years 4 days ago #6032 by Aoki Daisuke
не могу там править, доступа может нет
bitbucket.org/joomline/jl-comments/

Ещё пару изменений пока не забыл
$doc->addCustomTag('<script src="https://apis.google.com/js/plusone.js" type="text/javascript" async="async">/* {lang: "'.$fb_lang.'"} */</script>');
$doc->addCustomTag('<script src="//yandex.st/bootstrap/2.3.0/js/bootstrap.min.js" async="async"></script>');

Есть конфликт вк и фб, как это можно увидеть, поменяйте строку:
$doc->addScript("//vk.com/js/api/openapi.js?95");
на эту
$doc->addCustomTag('<script src="//vk.com/js/api/openapi.js?95" async="async"></script>');
похоже Обычная инициализация - не подходит, должна быть Асинхронная инициализация
vk.com/dev/openapi

Кстати у них уже изменения
<!-- Put this script tag to the <head> of your page -->
<script type="text/javascript" src="//vk.com/js/api/openapi.js?127"></script>
vk.com/dev/Comments
То есть должно быть:
$doc->addScript("//vk.com/js/api/openapi.js?127");
Last edit: 8 years 4 days ago by Aoki Daisuke.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum

Last from the forum

    • e house with his family. As he explored the proper...
    • In a small, sleepy town, there was an old house with a garden that had been locked up for decades. The garden was surrounded by a tall, ivy-covered wall, and no one had seen inside for as long as anyone could remember. One day, a curious boy named Sam moved into the house with his family. As he explored the property, he noticed a rusty, old key lying under a bush. Sam picked it up, wondering what it might unlock. After searching the house and finding nothing, Sam decided to try the key on the garden gate. To his surprise, the key fit perfectly. With a turn of the key and a creak of the hinges, the gate slowly swung open. Inside the garden, Sam was greeted by a sight of wonder. The garden was overgrown but full of vibrant flowers, exotic plants, and a small, sparkling pond. In the middle of the garden stood a beautiful stone statue of a unicorn. As Sam explored further, he discovered a small plaque next to the statue. It read: "To whoever finds this garden, may you always find joy in the beauty of nature and the magic of discovery." Sam spent hours in the garden, exploring every corner and marveling at the hidden beauty. The garden seemed to have a magical quality that made Sam feel at peace and incredibly happy. From that day on, Sam made it a habit to visit the garden every day, taking care of it and sharing its beauty with his friends and family. The once-forgotten garden became a place of joy and wonder for everyone who visited. And so, Sam learned that sometimes, the greatest treasures are not just the secrets we uncover but the beauty and joy we find in them.
    • In Component / JL TV
    • Emeriosoft UAE
    • Do you want to turn your digital ambitions into reality? Emeriosoft UAE is the premier <!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--> that can make it happen. We are providing email marketing services in UAE  ,SEO, social media marketing, content creation, and PPC campaigns, offering tailored solutions that elevate your brand's online presence. Our team of experts uses the latest technology and data-driven strategies to drive engagement, increase conversions, and boost visibility. With Emeriosoft UAE, transform your digital marketing efforts into a powerful engine for growth and success.
    • In WordPress / Plugins WordPress
© 2010- JoomLine
The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. joomline.net is not affiliated with or endorsed by Open Source Matters or the Joomla! Project.

email: This email address is being protected from spambots. You need JavaScript enabled to view it.