웹마스터 팁

XE의 문서읽기 화면에서 추천을 하지 않았을 경우에는 추천버튼이 나타나게 하고,


추천을 한 경우에는 추천취소버튼이 나타나도록 해보겠습니다.


XE 스킨을 간단하게라도 다룰수 있어야 따라하실 수 있습니다.


XE의 기본 게시판 스킨인 default 를 기준으로 설명합니다.



1. 문서 내용 밑에 추천 버튼 만들기


먼저 게시판스킨의 _read.html파일을 엽니다. (default스킨 이라면 modules/board/skins/default/_read.html)


 default스킨 기준으로 {$oDocument->getContent(false)}와 같이 본문내용을 출력해주는 부분을 찾습니다.


또는 각자 사용하고 있는 스킨에서  추천버튼을 자체적으로 출력한다면 추천버튼이 나오는 부분을 찾습니다.


sketchbook 스킨 을 예로 들면

<!--// Vote -->
<div cond="$mi->votes!='N'" class="rd_vote">
	<a class="bg_f_f9 bd_login" href="#" onclick="doCallModuleAction('document','procDocumentVoteUp','{$oDocument->document_srl}');return false"|cond="$is_logged" style="border:2px solid #{$mi->color};color:#{$mi->color};">
		<b>♥ {$oDocument->get('voted_count')}</b>
		<p>{$lang->cmd_vote}</p>
	</a>

이 부분이 추천버튼 입니다.



이제 본문내용을 출력하는 부분(_read.html파일의 44번째줄) 밑에 추천/비추천 버튼을 아래와 같이 만듭니다.


</form>
		<!--@else-->
		{$oDocument->getContent(false)}


		<!--// 추천/추천취소 버튼 만들기 -->
		<!--@if($is_logged)-->
			{@
				// document_voted_log 테이블에서서 현재 로그인한 사용자의 추천 로그 확인
		    	$args->document_srl = $document_srl;
		    	$args->member_srl = $logged_info->member_srl;
		    	$args->point = 1;
		    	$output = executeQuery('document.getDocumentVotedLogInfoWithPoint',$args);
		    }
	    <!--@end-->

		<!--@if($output->data->count)-->
		    <a href="javascript:void(0)" onclick="doCallModuleAction('document','procDocumentVoteUpRemove','{$document_srl}');return false;">추천취소</a>
	    <!--@else-->
		    <a href="javascript:void(0)" onclick="doCallModuleAction('document','procDocumentVoteUp','{$document_srl}');return false;">추천</a>
	    <!--@end-->
	    
	    
		<!--@end-->
	</div>
	<!-- /READ BODY -->
	<!-- READ FOOTER -->

설명


$output = executeQuery('document.getDocumentVotedLogInfoWithPoint',$args); 는 document모듈의 getDocumentVotedLogInfoWithPoint라는 쿼리를 $args라는 인자와 함께 실행시켜주고 결과값을 $output 에 담는 코드입니다. (해당쿼리는 XE에있는 기본 쿼리가 아닌 사용저 정의 쿼리입니다.)


그리고 밑에 $output->data>count를 통해서 쿼리 결과값의 count라는 컬럼값을 불러옵니다.


count의 값이 1이면 현재 로그인한 사용자가 추천한 로그가 document_voted_log 테이블에 1개 있다는 뜻이고


즉 사용자가 추천한 기록이 있으므로 '추천취소' 버튼을 보여줍니다.


추천버튼을 눌렀을때 실행되는 자바스크립트함수 doCallModuleAction()는 xe.js에 정의 되어있는데 XE 모듈의 액션을 xml로 요청하는 역활을 합니다.




2. document 모듈의 쿼리 만들기


추천로그를 검색하는 쿼리와 추천로그를 삭제하는 쿼리 두개를 새로 만듭니다.


modules/document/queris/getDocumentVotedLogInfoWithPoint.xml 파일을 아래와 같이 만듭니다.

파일 다운로드


<query id="getDocumentVotedLogInfo" action="select">
    <tables>
        <table name="document_voted_log" />
    </tables>
    <columns>
        <column name="count(*)" alias="count" />
    </columns>
    <conditions>
        <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
        <group pipe="and">
            <condition operation="equal" column="member_srl" var="member_srl" filter="number" pipe="and" />
            <condition operation="equal" column="ipaddress" var="ipaddress" pipe="and" />
            <condition operation="equal" column="point" var="point" pipe="and" />
        </group>
    </conditions>
</query>



그리고


modules/document/queris/deleteDocumentVotedLogWithMemberSrl.xml 파일을 아래와 같이 만듭니다.

파일 다운로드


<query id="deleteDocumentVotedLogWithMemberSrl" action="delete">
    <tables>
        <table name="document_voted_log" />
    </tables>
    <conditions>
        <condition operation="in" column="document_srl" var="document_srl" filter="number" notnull="notnull" />
		<condition operation="equal" column="member_srl" var="member_srl" filter="number" notnull="notnull" pipe="and" />
		<condition operation="equal" column="point" var="point" filter="number" notnull="notnull" pipe="and" />
    </conditions>
</query>





3. document 모듈의 controller 함수 선언하기


추천취소 기능을 수행할 함수를 modules/document/document.controller.php 파일에 새로 선언합니다.(제일 밑에)


// 추천 취소하기
	function procDocumentVoteUpRemove()
	{
		// 로그인 정보가 없으면 리턴
		$member_srl = $_SESSION['member_srl'];
		if(!$member_srl) return new Object(0, 'No Logged User Information');

		// args
		$args->document_srl = Context::get('target_srl'); // doCallModuleAction의 전달값 받기

		// 추천 점수 삭감
		$oDocumentModel = &getModel('document');
		$oDocument = $oDocumentModel->getDocument($args->document_srl, false, false); // 현재 문서 가져오기
		$args->voted_count = $oDocument->get('voted_count') - 1;
		$output = executeQuery('document.updateVotedCount', $args);
		if(!$output->toBool()) return new Object(0, 'Failed to update vote count');

		// 추천 로그 삭제
		$args->point = 1; // 삭제할 로그의 추천점수(추천 : 1, 비추천 : -1)
		$args->member_srl = $member_srl; // 삭제할 로그의 member_srl 
		$output = executeQuery('document.deleteDocumentVotedLogWithMemberSrl', $args);
		if(!$output->toBool()) return new Object(0, 'Failed to remove log');

		// 세션 삭제
		$_SESSION['voted_document'][$args->document_srl] = false;

return new Object(0, '추천을 취소하였습니다.');
	}




그리고 위 함수를 doCallModuleAction()의 함수에서 사용하기 위해 document 모듈 정보에 등록합니다.


modules/document/conf/module.xml 파일을 열어서 27번째줄 아래에 다음과 같이 한 줄을 추가해 주세요.


    <actions>
        <action name="dispDocumentPrint" type="view" standalone="true" />
        <action name="dispDocumentPreview" type="view" standalone="true" />
        <action name="dispDocumentManageDocument" type="view" standalone="true" />
        <action name="dispTempSavedList" type="view" standalone="true" />

        <action name="getDocumentCategories" type="model" standalone="true" />
        <action name="getDocumentMenu" type="model" standalone="true" />

        <action name="procDocumentVoteUp" type="controller" standalone="true" />
        <action name="procDocumentVoteUpRemove" type="controller" standalone="true" />
        <action name="procDocumentVoteDown" type="controller" standalone="true" />
        <action name="procDocumentDeclare" type="controller" standalone="true" />
        <action name="procDocumentAddCart" type="controller" standalone="true" />
        <action name="procDocumentManageCheckedDocument" type="controller" standalone="true" />
        <action name="procDocumentInsertModuleConfig" type="controller" standalone="true" />





4. 결과 화면


아래처럼 본문내용 밑에 추천/추천취소 버튼이 나타납니다.


추천.png



추천 취소할 때

추천취소.png

태그 연관 글
  1. [2017/08/11] 묻고답하기 글,댓글 추천 log에 member_srl이 있다가 없다가하네요. (버그일까요?) by 헨델8 *1
  2. [2015/05/31] 묻고답하기 추천시에 '몇번째로 추천하였습니다.' 확인창 뜨게하는법. by 파리바께뜨 *4
  3. [2014/05/12] 묻고답하기 관리자에게만 추천 버튼 보이게 하는 방법은 무엇일까요? by DjKiLLeR *3
  4. [2012/04/26] 묻고답하기 송동우님 한번 더 다시 봐주세요~ (추천인 포인트 관련) by 꿀꺽2 *2
  5. [2011/11/18] 웹마스터 팁 비회원도 추천가능하게 하기 (1.5기준설명) by 빽짱구 *3
제목 글쓴이 날짜
리플이나 서명에서 특정 태그 막기 [4] 老姜君 2008.05.05
회원 확장 정보를 레이아웃에서 활용하기 [6] [1] file mooo 2008.05.06
확장변수(textarea)에 html태그 적용 [6] 오엘 2008.05.08
rewrite mod 사용시 404 페이지 에러 해결 방법 이종준 2008.05.09
아고라 서명운동 전용 웹카운터 [2] 살색마수 2008.05.10
일반 html이나 php파일에 모듈을 추가했을시 나타나는 문제점. (최근게시물 모듈. 링크 타겟 지정). [8] 장민수 2008.05.11
오른쪽 상단에 로그인 정보 출력하기 (게시판 만으로) file youngminpark 2008.05.15
게시판→설정→스킨관리→글제목 표시 유무 넣기 [2] 탑심 2008.05.15
New 등의 아이콘 변경하기... [3] file winter548 2008.05.17
게시물목록의 조회수 등의 글씨(폰트), 폰트 크기, 색깔 변경 [1] winter548 2008.05.17
1.0.3 오토링크(autolink) 디자인 수정본 [6] file 위드파트너 2008.05.18
홈페이지에 닉네임 대신 실명으로 뜨게 만들기 [5] file findwind 2008.05.19
본문과 댓글 입력의 기본 폰트. 크기 한번에 변경하기... [3] winter548 2008.05.19
텔넷으로 순간 압축풀기/폴더 삭제/폴더파일 압축하기... [5] Crazyhouse.cn 2008.05.19
회원 관리 리스트에 생일/이메일 추가하기 [4] file 老姜君 2008.05.19
보안로그인 사용시 기본포트가 아닐 경우 [2] bluemind69 2008.05.20
글 쓸 때 자동으로 비밀 글 체크하기(''비고수''님의 팁) [1] 띵야 2008.05.20
버튼 글씨체 바꾸기.... [2] winter548 2008.05.20
''웹진형태의 최근문서 출력''위젯에서 썸네일 생성이 되지 않을때 [2] 아시안느 2008.05.20
태그 위젯으로 생성된 태그 리스트에서 한글태그 검색이 안될때 해결법 [3] 봄대리 2008.05.21