"미디어위키 페이스북 좋아요 버튼 달기"의 두 판 사이의 차이

11번째 줄: 11번째 줄:
$protocol = 'http';
$protocol = 'http';
$port = '80';
$port = '80';
if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol = 'https'; $port = '443'; }
if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol .= 's'; $port = '443'; }
$port = $_SERVER['SERVER_PORT'] == $port ? '' : ':' . $_SERVER['SERVER_PORT'];
$port = $_SERVER['SERVER_PORT'] == $port ? '' : ':' . $_SERVER['SERVER_PORT'];
return $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['SCRIPT_NAME'];
return $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['SCRIPT_NAME'];
18번째 줄: 18번째 줄:
global $wgParser;
global $wgParser;
global $FacebookLikeButtonOnce;
global $FacebookLikeButtonOnce;
$wgParser->setHook( "facelikebutton", "renderFacebookLikeButton" );  
$wgParser->setHook( "fblike", "renderFacebookLikeButton" );  
$FacebookLikeButtonOnce='<div id="fb-root"></div><script src="http://connect.facebook.net/ko_KR/all.js#xfbml=1"></script>';
$FacebookLikeButtonOnce='<div id="fb-root"></div><script src="http://connect.facebook.net/ko_KR/all.js#xfbml=1"></script>';
}  
}  
31번째 줄: 31번째 줄:
$FacebookLikeButtonOnce = '';
$FacebookLikeButtonOnce = '';
$full_url = FacebookLikeButtonUrl().'/'.$wgRequest->getText('title');
$full_url = FacebookLikeButtonUrl().'/'.$wgRequest->getText('title');
return $once.'<div class="fb-like" data-href="'.$full_url.'" data-send="'.$send.'" data-layout="'.$layout.'" data-width="400"></div>';
return $once.'<div>'.$wgRequest->getText('lang').'</div><div class="fb-like" data-href="'.$full_url.'" data-send="'.$send.'" data-layout="'.$layout.'" data-width="400"></div>';
}
}
$wgExtensionCredits['parserhook'][] = array(
$wgExtensionCredits['parserhook'][] = array(

2012년 8월 16일 (목) 22:17 판

How to add like button in Mediawiki
미디어위키 페이스북 좋아요 버튼 달기
미디어위키 좋아요 버튼 추가

1 파일 생성/업로드

  • FacebookLikeButton.php 파일을 아래 내용으로 생성한다.[1]
<?php
$wgExtensionFunctions[] = "facebooklikebuttonExtension";
function FacebookLikeButtonUrl() {
	$protocol = 'http';
	$port = '80';
	if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) { $protocol .=  's'; $port = '443'; }
	$port = $_SERVER['SERVER_PORT'] == $port ? '' : ':' . $_SERVER['SERVER_PORT'];
	return $protocol . '://' . $_SERVER['HTTP_HOST'] . $port . $_SERVER['SCRIPT_NAME'];
}
function facebooklikebuttonExtension() {
	global $wgParser;
	global $FacebookLikeButtonOnce;
	$wgParser->setHook( "fblike", "renderFacebookLikeButton" ); 
	$FacebookLikeButtonOnce='<div id="fb-root"></div><script src="http://connect.facebook.net/ko_KR/all.js#xfbml=1"></script>';
} 
function renderFacebookLikeButton( $input, $argv ) { 
	global $wgRequest;
	global $FacebookLikeButtonOnce;
	$layout = @$argv['layout'];
	$send = @$argv['send'];
	if( $layout != 'standard' && $layout != 'box_count' ) $layout = 'button_count';
	if( $send != 'true' ) $send = 'false';
	$once = $FacebookLikeButtonOnce;
	$FacebookLikeButtonOnce = '';
	$full_url = FacebookLikeButtonUrl().'/'.$wgRequest->getText('title');
	return $once.'<div>'.$wgRequest->getText('lang').'</div><div class="fb-like" data-href="'.$full_url.'" data-send="'.$send.'" data-layout="'.$layout.'" data-width="400"></div>';
}
$wgExtensionCredits['parserhook'][] = array(
	'name' => 'Wiki FacebookLikeButton',
	'version' => '1.0.0',
	'author' => 'Piotr Zuk',
	'url' => 'http://www.mediawiki.org/wiki/Extension:FacebookLikeButton',
	'description' => 'Mediawiki FacebookLikeButton Extension'
);
?>
  • extensions 폴더에 FacebookLikeButton 폴더를 만들고 위 파일을 그곳에 업로드한다.

2 LocalSettings.php 수정

미디어위키 폴더에 있는 LocalSettings.php의 맨아래에 다음 내용을 추가

require_once("$IP/extensions/FacebookLikeButton/FacebookLikeButton.php");

3 테스트

위키에 좋아요 버튼을 달아보자.

  • <fblike/>
<fblike/>
  • <fblike send="true"/>
<fblike send="true"/>
  • <fblike layout="box_count" send="true"/>
<fblike layout="box_count" send="true"/>
  • <fblike layout="standard" send="true"/>
<fblike layout="standard" send="true"/>

4 주석

  1. 이 소스코드는 원본과 조금 다르다. 필자가 한국어판으로 바꾸고 축약했다.

5 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}