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

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

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

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

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

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

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

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

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

Powered by Kunena Forum

Last from the forum

    • psyllium fiber capsule manufacturing
    • Our process combines cutting-edge encapsulation technology and meticulous quality assurance, ensuring every capsule delivers optimal fiber content and efficacy. Rigorously tested for contaminants and uniformity, our capsules are trusted by leading wellness brands who value transparency, consumer safety, and nutritional performance.  
    • In English Forum / Component
    • Is Kamagra Oral Jelly Safe for Long-Term ED Treatm...
    • can be effective for treating erectile dysfunction, but its safety for long-term use depends on individual health factors and medical guidance. The active ingredient, sildenafil citrate, is generally well-tolerated when taken as prescribed. However, regular or prolonged use without a doctor’s supervision can increase the risk of side effects such as headaches, dizziness, indigestion, nasal congestion, and visual disturbances. For long-term treatment, it's important to consider the underlying cause of ED, such as cardiovascular issues, diabetes, or stress, and address it alongside medication. Using Kamagra Oral Jelly and occasionally and under medical advice may be safe for many men, but it should not be used as a permanent solution without medical oversight.
    • In Component / Afisha Joomla
    • greensocialteam
    • Su Hailin entered the Japanese AV industry under the stage name "Erina". After her debut, she attracted many haters who kept scolding her online. She held a "Face-to-face meeting with haters" in Mong Kok yesterday (May 10). Beforehand, she publicly named 9 black fans who often attacked her, hoping to meet and talk in person. However, the night before the event, Su Hailin stated on social media that the police opposed her holding the event on the street and that it would eventually have to be held in a party room. However, all the haters disappeared, and instead a large number of fans showed up to support her. Su Hailin also announced that a photo exhibition will be held next month, and haters are also welcome to visit.  
    • In Component / JL Mail
© 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.