Skip to content

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gulaandrij committed Feb 12, 2013
1 parent 8dceb92 commit 3efe089
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 140 deletions.
108 changes: 94 additions & 14 deletions application/modules/comments/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function init_settings() {
}

public function renderPosts() {
// var_dump($_SERVER['HTTP_REFERER']);
// var_dump($_POST);
$comments = array();
($hook = get_hook('comments_on_build_comments')) ? eval($hook) : NULL;

Expand Down Expand Up @@ -100,33 +100,49 @@ public function renderPosts() {
echo json_encode(array('comments' => $comments));
}

/**
* Determinate commented page.
*
* if product - return id
*/
public function parsUrl($url) {
if (strstr($url, 'product')) {
$url = parse_url($url);
$search = array('shop', 'product', '/');
$replace = array('', '', '');
$url = str_replace($search, $replace, $url['path']);
$id = $this->db->select('id')->where('url', $url)->get('shop_products')->row();
return $id->id;
}
}

public function newPost() {
if ($this->input->post('action') == 'newPost') {
$this->load->library('user_agent');

if ($this->input->post('action') == 'newPost') {
$email = $this->db->select('email')->get_where('users', array('username' => $this->dx_auth->get_username()), 1)->row();

if ($this->dx_auth->is_logged_in())
$comment_data = array(
'module' => $this->module,
'module' => 'shop',//$this->module,
'user_id' => $this->dx_auth->get_user_id(), // 0 if unregistered
'user_name' => $this->dx_auth->get_username(),
'user_mail' => $email->email,
'user_site' => htmlspecialchars($this->input->post(comment_site)),
'text' => $this->input->post('comment'),
'text_plus' => '$comment_text_plus',
'text_minus' => '$comment_text_minus',
'item_id' => '$item_id',
'status' => '$this->_comment_status()',
'agent' => '$this->agent->agent_string()',
'user_ip' => '$this->input->ip_address()',
'text' => $this->input->post('comment_text'),
'text_plus' => $this->input->post('comment_text_plus'),
'text_minus' => $this->input->post('comment_text_minus'),
'item_id' => $this->parsUrl($_SERVER['HTTP_REFERER']),
'status' => $this->_comment_status(),
'agent' => $this->agent->agent_string(),
'user_ip' => $this->input->ip_address(),
'date' => time(),
'rate' => '$rate',
'parent' => '$parent'
'rate' => $this->input->post('ratec'),
'parent' => $this->input->post('parent')
);
// else


$this->db->insert('comments_api', $comment_data);
$this->db->insert('comments', $comment_data);
//return JSON
echo json_encode(array('answer' => 'sucesfull'));

Expand All @@ -136,5 +152,69 @@ public function newPost() {
parent::test();
}

/**
* Determinate comment status.
*
* Comment statuses
* 0 - Normal(approved) comment.
* 1 - Waiting for moderation(pending).
* 2 - Spam.
*/
private function _comment_status() {
($hook = get_hook('comments_on_get_status')) ? eval($hook) : NULL;

$status = 0;

if ($this->dx_auth->is_admin() == TRUE) {
return 0;
}

if ($this->use_moderation == TRUE) {
$status = 1;
} elseif ($this->use_moderation == FALSE) {
$status = 0;
}

return $status;
}

public function setyes() {
$comid = $this->input->post('comid');
if ($this->session->userdata('commentl' . $comid) != 1) {
$row = $this->db->where('id', $comid)->get('comments')->row();
$like = $row->like;
$like = $like + 1;
$data = array('like' => $like);
$this->db->where('id', $comid);
$this->db->update('comments', $data);
$this->session->set_userdata('commentl' . $comid, 1);
if ($this->input->is_ajax_request()) {
return json_encode(array("y_count" => "$like"));
} else {
$like--;
return json_encode(array("y_count" => "$like"));
}
}
}

public function setno() {
$comid = $this->input->post('comid');
if ($this->session->userdata('commentl' . $comid) != 1) {
$row = $this->db->where('id', $comid)->get('comments')->row();
$disslike = $row->disslike;
$disslike = $disslike + 1;
$data = array('disslike' => $disslike);
$this->db->where('id', $comid);
$this->db->update('comments', $data);
$this->session->set_userdata('commentl' . $comid, 1);
if ($this->input->is_ajax_request()) {
return json_encode(array("n_count" => "$disslike"));
} else {
$disslike--;
return json_encode(array("n_count" => "$disslike"));
}
}
}

}

2 changes: 1 addition & 1 deletion application/modules/shop
Submodule shop updated from 32daa1 to 306763
122 changes: 105 additions & 17 deletions templates/commerce/comments_api.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{# Comments form for product}

{if $can_comment == 1 AND !$is_logged_in}
<p class="m-l_10">{sprintf(lang('login_for_comments'), site_url($modules.auth))}</p>
<p class="m-l_10">
{sprintf(lang('login_for_comments'), site_url($modules.auth))}
</p>
{/if}

{if $can_comment == 0 OR $is_logged_in}
<div class="di_b">
<span class="comment_ajax_refer b-r_4 visible">

<a href="#" class="t-d_n"><span class="js">{lang('s_leave_comment')}</span><span class="blue_arrow"></span></a>
<a href="#" class="t-d_n">
<span class="js">
{lang('s_leave_comment')}
</span>
<span class="blue_arrow">
</span>
</a>

{if $is_logged_in}
{lang('s_lang_logged')} {$username}
Expand All @@ -24,17 +32,30 @@
<input type="hidden" name="comment_item_id" value="{$item_id}" />
<input type="hidden" name="redirect" value="{uri_string()}" />
{if $comment_errors}
<span class="red"> {$comment_errors}</span>
<span class="red">
{$comment_errors}
</span>
{/if}

{if !$is_logged_in}

<label>{lang('lang_comment_author')} <span style="color:red;">*</span>
<input type="text" name="comment_author" id="comment_author" value="{get_cookie('comment_author')}"/></label>
<label>{lang('lang_comment_email')} <span style="color:red;">*</span>
<input type="text" name="comment_email" id="comment_email" value="{get_cookie('comment_email')}"/></label>
<label>
{lang('lang_comment_author')}
<span style="color:red;">
*
</span>
<input type="text" name="comment_author" id="comment_author" value="{get_cookie('comment_author')}"/>
</label>
<label>
{lang('lang_comment_email')}
<span style="color:red;">
*
</span>
<input type="text" name="comment_email" id="comment_email" value="{get_cookie('comment_email')}"/>
</label>
<label>{lang('lang_comment_site')}
<input type="text" name="comment_site" id="comment_site" value="{get_cookie('comment_site')}"/></label>
<input type="text" name="comment_site" id="comment_site" value="{get_cookie('comment_site')}"/>
</label>

{/if}
<label>
Expand Down Expand Up @@ -86,7 +107,7 @@
</div>
{/if}
<label class="buttons button_middle_blue f_l">
<input name="submit" type="button" class="submit" value="Пуск" id="button" onclick="json()">
<input name="submit" type="button" class="submit" value="Пуск" id="button" onclick="post(this)">
</label>

{form_csrf()}
Expand All @@ -96,7 +117,7 @@

{if $comments_arr}
<ul class="comments" style="width:100%">
{foreach $comments_arr as $comment}
{foreach $comments_arr as $key => $comment}
<li>
{if $comment.rate != 0}
<div class="star_rating">
Expand Down Expand Up @@ -150,7 +171,7 @@
</div>

{if $can_comment == 0 OR $is_logged_in}
<form action="" method="post" class="comment_form">
<form id="s{$key}" name="{$key}" action="" method="post" class="comment_form">
<input type="hidden" name="comment_item_id" value="{$item_id}"/>
<input type="hidden" name="redirect" value="{uri_string()}"/>
{if !$is_logged_in}
Expand All @@ -164,9 +185,9 @@
<label>{lang('s_text_comment_one')} <span style="color:red;">*</span>
<textarea name="comment_text" id="comment_text" rows="10" cols="50">{$_POST.comment_text}</textarea>
</label>
<input type="hidden" name="parent" value="{echo $comment.id}">
<input type="hidden" id="parent" name="parent" value="{echo $comment.id}">
<label class="buttons button_middle_blue f_l">
<input name="submit" type="button button_middle_blue f_l" class="submit" value="Пуск" id="button" onclick="json()">
<input name="submit" type="button" class="submit" value="Пуск child" id="button" onclick="post(this)">
</label>

{form_csrf()}
Expand All @@ -175,14 +196,81 @@
{foreach $comment_ch as $com_ch}
{if $com_ch.parent == $comment.id}
<li style="padding-left: 50px">
<b>{$com_ch.user_name}</b>
<div class="c_9 f-s_11">{lang('s_on_comment')} {date('d-m-Y H:i', $com_ch.date)}</div>
<p>{$com_ch.text}</p>
<b>
{$com_ch.user_name}
</b>
<div class="c_9 f-s_11">
{lang('s_on_comment')} {date('d-m-Y H:i', $com_ch.date)}
</div>
<p>
{$com_ch.text}
</p>
</li>
{/if}
{/foreach}
</li>

{/foreach}
<ul>
{/if}
{/if}
{literal}
<script>
$('form').submit(function() {
alert($(this).serialize());
return false;
});
$('span.clickrate').on('click', function() {
var val = $(this).attr('title');
$.ajax({
type: "POST",
data: "pid=" + currentProductId + "&val=" + val,
dataType: "json",
url: '/shop/ajax/rate',
success: function(obj) {
if (obj.classrate != null)
$('#' + 'star_rating_' + currentProductId).removeClass().addClass('rating ' + obj.classrate + ' star_rait');
}
});
});
$('span.clicktemprate').on('click', function() {
var rate = $(this).attr('title');
var ratec;
if (rate == 1)
ratec = "onestar";
if (rate == 2)
ratec = "twostar";
if (rate == 3)
ratec = "threestar";
if (rate == 4)
ratec = "fourstar";
if (rate == 5)
ratec = "fivestar";
$('#comment_block').removeClass().addClass('rating ' + ratec + ' star_rait');
$('#ratec').attr('value', rate);
});
$('.usefullyes').on('click', function() {
var comid = $(this).attr('data-comid');
$.ajax({
type: "POST",
data: "comid=" + comid,
dataType: "json",
url: '/comments/api/setyes',
success: function(obj) {
$('#yesholder' + comid).html("(" + obj.y_count + ")");
}
});
});
$('.usefullno').on('click', function() {
var comid = $(this).attr('data-comid');
$.ajax({
type: "POST",
data: "comid=" + comid,
dataType: "json",
url: '/comments/api/setno',
success: function(obj) {
$('#noholder' + comid).html("(" + obj.n_count + ")");
}
});
});
</script>
{/literal}
Loading

0 comments on commit 3efe089

Please sign in to comment.