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

More
8 years 6 months ago - 8 years 6 months 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 6 months ago by Aoki Daisuke.

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

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

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

More
8 years 6 months ago - 8 years 6 months 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 6 months ago by Aoki Daisuke.

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

More
8 years 4 months ago - 8 years 4 months 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 months ago by Aoki Daisuke.

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

Powered by Kunena Forum

Last from the forum

    • web design inspiration
    •   In it for the long run, during 2024 Nexon has taken the web3 extension of its MapleStory IP not just wider, but also deeper. Garnering 400,000 users during a single day in its latest MapleStory N playtest showcases Nexon’s growing understanding on sustainable ecosystem building. The release of its NXPC token model makes MapleStory Universe users even more excited about where the project is heading as we’re on the verge of a new year.
    • In Component / JL TV
    • luxury timepieces
    • One day, a monkey drove his car near a lake. Sudden, he saw a tiger under a tree. The tiger saw him, too. The tiger ran very fast at the monkey. The monkey was very afraid and he and his car fell into the lake. The monkey couldn't swim and he shouted. A rabbit came and he jumped into the lake. The abbit swam to the monkey but did not help him. Both of them shouted forhelp. Luckily, a giraffe came along. He was very tall. He helped the rabbit and the monkey.  
    • In Component / Afisha Joomla
    • E-Commerce Point of sales system
    • One day, a monkey drove his car near a lake. Sudden, he saw a tiger under a tree. The tiger saw him, too. The tiger ran very fast at the monkey. The monkey was very afraid and he and his car fell into the lake. The monkey couldn't swim and he shouted. A rabbit came and he jumped into the lake. The abbit swam to the monkey but did not help him. Both of them shouted forhelp. Luckily, a giraffe came along. He was very tall. He helped the rabbit and the monkey.  
    • In Component / Afisha Joomla
© 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.