3개 발견

xe 검색 결과

  1. 미리보기 2015.03.04

    [XE] PHP를 이용해 DB의 내용을 JSON 형식으로 출력하기

  2. 미리보기 2015.03.04

    [XE] 회원가입 항목 관리자만 추가/수정 가능하게 만들기

  3. 미리보기 2015.03.02

    [XE] 대댓글에 'OOO님에게 달린 댓글' 구현하기

2015. 3. 4. 18:35 - Str@wBerry

[XE] PHP를 이용해 DB의 내용을 JSON 형식으로 출력하기



본 게시물은 XE Database에서 문서의 제목내용물을 가져오는 예입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!--?php
$db_host = "호스팅 이름";
$db_user = "DB 사용자 이름";
$db_passwd = "DB 비밀번호";
$db_name = "DB 이름";
  
mysql_connect($db_host,$db_user,$db_passwd);
mysql_select_db($db_name);
 
$result = mysql_query("SELECT * FROM xe_documents;");
$data = mysql_fetch_array($result);
$JSONres = array
(   "title" => $data[title],
    "content" => $data[content]
);
 
print_r((json_encode($JSONres));
?-->

이렇게 작성하게 되면 JSON 형식의 결과물은 나옵니다.

하지만 문제점이 발생됩니다. 


1. 한글이 깨진다.

2. 내용물에 HTML 코드가 같이 나온다.


두가지 문제점을 해결해보도록 하겠습니다.


1. 한글이 깨진다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!--?php
$db_host = "호스팅 이름";
$db_user = "DB 사용자 이름";
$db_passwd = "DB 비밀번호";
$db_name = "DB 이름";
  
mysql_connect($db_host,$db_user,$db_passwd);
mysql_select_db($db_name);
 
mysql_query('set session character_set_connection=utf8;');
mysql_query('set session character_set_results=utf8;');
mysql_query('set session character_set_client=utf8;');
 
$result = mysql_query("SELECT * FROM xe_documents;");
$data = mysql_fetch_array($result);
$JSONres = array
(   "title" => urlencode($data[title]),
    "content" => urlencode($data[content])
);
 
print_r(urldecode(json_encode($JSONres)));
?-->


2. 내용물에 HTML 코드가 같이 나온다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!--?php
$db_host = "호스팅 이름";
$db_user = "DB 사용자 이름";
$db_passwd = "DB 비밀번호";
$db_name = "DB 이름";
 
mysql_connect($db_host,$db_user,$db_passwd);
mysql_select_db($db_name);
 
mysql_query('set session character_set_connection=utf8;');
mysql_query('set session character_set_results=utf8;');
mysql_query('set session character_set_client=utf8;');
 
$result = mysql_query("SELECT * FROM xe_documents;");
$data = mysql_fetch_array($result);
$JSONres = array
(   "title" => urlencode($data[title]),
    "content" => urlencode($data[content])
);
  
print_r(strip_tags(urldecode(json_encode($JSONres))));
?-->


결과물 스크린샷



추가 (2015-03-05)

모든 문서의 제목과 내용을 출력하는 소스입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!--?php
$db_host = "호스팅 이름";
$db_user = "DB 사용자 이름";
$db_passwd = "DB 비밀번호";
$db_name = "DB 이름";
  
mysql_connect($db_host,$db_user,$db_passwd);
mysql_select_db($db_name);
mysql_query('set session character_set_connection=utf8;');
mysql_query('set session character_set_results=utf8;');
mysql_query('set session character_set_client=utf8;');
 
$result = mysql_query("SELECT * FROM xe_documents");
$rows = array();
while ($row = mysql_fetch_assoc($result))
    {
        $JSONres = array
        (  
            "title"     =--> urlencode($row['title']),
            "content"   => urlencode($row['content'])
        );
        array_push($rows, $JSONres);
    }
     
echo (strip_tags(urldecode(json_encode($rows))));
?>





2015. 3. 4. 16:36 - Str@wBerry

[XE] 회원가입 항목 관리자만 추가/수정 가능하게 만들기



본 블로그 게시물은 XE 1.7.10기반으로 작성되었습니다

'이미지 이름'을 관리자만 등록하고 수정할 수 있게하는 예제입니다.


최초 관리자만 관리할 항목을 가입 폼 관리에서 필수가 아닌 '선택'으로 활성화 합니다.




다음으로 회원가입 폼에서 '이미지 이름' 항목을 제거합니다.


modules/member/skins/default/signup_form.html 수정 전

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="control-group">
    <label for="password2" class="control-label"><em style="color:red">*</em> {$lang->password3}</label>
    <div class="controls">
        <input type="password" name="password2" id="password2" value="" required="">
    </div>
</div>
<div class="control-group" loop="$formTags=>$formTag" cond="$formTag->name != 'signature'">
    <label for="{$formTag->name}" class="control-label">{$formTag->title}</label>
    <div class="controls">{$formTag->inputTag}</div>
</div>
<div class="control-group">
    <div class="control-label">{$lang->allow_mailing}</div>
    <div class="controls" style="padding-top:5px">
        <label for="mailingYes"><input type="radio" name="allow_mailing" id="mailingYes" value="Y" checked="checked" |cond="$member_info->allow_mailing == 'Y'"> {$lang->cmd_yes}</label>
        <label for="mailingNo"><input type="radio" name="allow_mailing" id="mailingNo" value="N" checked="checked" |cond="$member_info->allow_mailing != 'Y'"> {$lang->cmd_no}</label>
    </div>
</div>
modules/member/skins/default/signup_form.html 수정 후
38
39
40
41
42
43
44
45
46
47
48
49
50
     
 
        <div class="control-group">
            <label for="password2" class="control-label"><em style="color:red">*</em> {$lang->password3}</label>
            <div class="controls">
                <input type="password" name="password2" id="password2" value="" required="">
            </div>
        </div>
        <div class="control-group" loop="$formTags=>$formTag" cond="$formTag->name != 'signature'&&$formTag->name != 'image_name'">
            <label for="{$formTag->name}" class="control-label">{$formTag->title}</label>
            <div class="controls">{$formTag->inputTag}</div><div class="control-group" loop="$formTags=>$formTag" cond="$formTag->name != 'signature'&&$formTag->name != 'image_name'">
</div>
</div>


두번째, 일반 회원이 수정할 수 있는 폼에서 '이미지 이름' 항목을 제거합니다.

modules/member/skins/default/modify_info.html 수정 전

29
30
31
32
33
34
35
36
37
38
39
40
<div class="control-group" loop="$formTags=>$formTag">
    <label for="" class="control-label">{$formTag->title}</label>
    <div class="controls" cond="$formTag->name != 'signature'">{$formTag->inputTag}</div>
    <div class="controls" cond="$formTag->name =='signature'">
        {$editor}
        <style scoped="">
        .xpress-editor>#smart_content,
        .xpress-editor>#smart_content>.tool{clear:none}
        </style>
    </div>
</div>

modules/member/skins/default/modify_info.html 수정 후

29
30
31
32
33
34
35
36
37
38
39
40
<div class="control-group" loop="$formTags=>$formTag" cond="$formTag->name != 'image_name'">
    <label for="" class="control-label">{$formTag->title}</label>
    <div class="controls" cond="$formTag->name != 'signature'">{$formTag->inputTag}</div>
    <div class="controls" cond="$formTag->name =='signature'">
        {$editor}
        <style scoped="">
        .xpress-editor>#smart_content,
        .xpress-editor>#smart_content>.tool{clear:none}
        </style>
    </div>
</div>



결과물입니다.


일반회원이 수정하려고 하는 경우


관리자가 수정하려는 경우





2015. 3. 2. 21:08 - Str@wBerry

[XE] 대댓글에 'OOO님에게 달린 댓글' 구현하기


본 블로그 게시물은 XE SketchBook5를 기반으로 작성되었습니다


.    


/* 적용 스크린 샷 */





_comment.html 수정 전
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
     
<!--// 댓글 본문 -->
        <!--@if(!$comment->isAccessible())-->
        <form action="./" method="get" onsubmit="return procFilter(this, input_password)">
            <input name="mid" value="{$mid}" type="hidden">
            <input name="page" value="{$page}" type="hidden">
            <input name="document_srl" value="{$comment->get('document_srl')}" type="hidden">
            <input name="comment_srl" value="{$comment->get('comment_srl')}" type="hidden">
            <p>"{$lang->msg_is_secret}"</p>
            <span class="itx_wrp">
                <label for="cpw_{$comment->comment_srl}">{$lang->password}</label>
                <input id="cpw_{$comment->comment_srl}" name="password" class="itx" type="password">
                <input value="{$lang->cmd_input}" class="bd_btn" type="submit">
            </span>
        </form>
        <!--@else-->
        {$comment->getContent(false)}
        <!--@end-->
<!--// 편집 등 -->
        <div class="fdb_nav img_tx">
            <block cond="$mi->cmt_this_btn=='2' && $is_logged">
            <a href="#" onclick="doCallModuleAction('comment','procCommentDeclare','{$comment->comment_srl}');return false"><i class="fa fa-phone"></i>{$lang->cmd_declare}</a>
            <a href="#" onclick="doCallModuleAction('comment','procCommentVoteUp','{$comment->comment_srl}');return false"><i class="fa fa-heart color"></i>{$lang->cmd_vote}</a>
            <a cond="!$mi->cmt_vote_down" href="#" onclick="doCallModuleAction('comment','procCommentVoteDown','{$comment->comment_srl}');return false"><i class="fa fa-heart"></i>{$lang->cmd_vote_down}</a>
            </block>
</div>
_comment.html 수정 후
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
     
<!--// 댓글 본문 -->
        <!--@if(!$comment->isAccessible())-->
        <form action="./" method="get" onsubmit="return procFilter(this, input_password)">
            <input name="mid" value="{$mid}" type="hidden">
            <input name="page" value="{$page}" type="hidden">
            <input name="document_srl" value="{$comment->get('document_srl')}" type="hidden">
            <input name="comment_srl" value="{$comment->get('comment_srl')}" type="hidden">
            <p>"{$lang->msg_is_secret}"</p>
            <span class="itx_wrp">
                <label for="cpw_{$comment->comment_srl}">{$lang->password}</label>
                <input id="cpw_{$comment->comment_srl}" name="password" class="itx" type="password">
                <input value="{$lang->cmd_input}" class="bd_btn" type="submit">
            </span>
        </form>
        <!--@else-->
            <!--@if($comment->parent_srl)-->
            {@
                $oComment = &getModel('comment');
                $comment_parent = $oComment->getComment($comment->parent_srl);
            }
            {$comment_parent->getNickName()} 님에게 달린 댓글 {$comment->getContent(false)}
            <!--@else-->
                {$comment->getContent(false)}
            <!--@end-->
        <!--@end-->
<!--// 편집 등 -->
        <div class="fdb_nav img_tx">
            <block cond="$mi->cmt_this_btn=='2' && $is_logged">
            <a href="#" onclick="doCallModuleAction('comment','procCommentDeclare','{$comment->comment_srl}');return false"><i class="fa fa-phone"></i>{$lang->cmd_declare}</a>
            <a href="#" onclick="doCallModuleAction('comment','procCommentVoteUp','{$comment->comment_srl}');return false"><i class="fa fa-heart color"></i>{$lang->cmd_vote}</a>
            <a cond="!$mi->cmt_vote_down" href="#" onclick="doCallModuleAction('comment','procCommentVoteDown','{$comment->comment_srl}');return false"><i class="fa fa-heart"></i>{$lang->cmd_vote_down}</a>
            </block><font face="돋움"><span style="white-space: normal;">
</span></font></div>

대댓글일 경우에만 'OOO님에게 달린 댓글' 이 먼저 나오게 됩니다.

따로 수정하실 분들은 저 부분만 수정하시면 됩니다.