public function comment() { $this->data['mycomments'] = array(); $this->language->load('record/record'); $this->load->model('catalog/comment'); $this->data['entry_sorting'] = $this->language->get('entry_sorting'); $this->data['text_sorting_desc'] = $this->language->get('text_sorting_desc'); $this->data['text_sorting_asc'] = $this->language->get('text_sorting_asc'); $this->data['text_rollup'] = $this->language->get('text_rollup'); $this->data['text_rollup_down'] = $this->language->get('text_rollup_down'); $this->data['text_no_comments'] = $this->language->get('text_no_comments'); $this->data['text_reply_button'] = $this->language->get('text_reply_button'); $this->data['text_edit_button'] = $this->language->get('text_edit_button'); $this->data['text_delete_button'] = $this->language->get('text_delete_button'); $this->load->model('catalog/record'); $record_info = $this->model_catalog_record->getRecord($this->request->get['record_id']); $this->load->model('catalog/blog'); $b_path = $this->model_catalog_blog->getPathByrecord($this->request->get['record_id']); $blog_path = $b_path['path']; if (isset($blog_path)) { if (strpos($blog_path, '_') !== false) { $abid = explode('_', $blog_path); $blog_id = $abid[count($abid) - 1]; } else { $blog_id = (int) $blog_path; } $blog_id = (int) $blog_id; } //isset($blog_path) if (!isset($blog_id)) { $blog_id = ''; } $blog_info = $this->model_catalog_blog->getBlog($blog_id); if (isset($blog_info['design']) && $blog_info['design'] != '') { $this->data['blog_design'] = unserialize($blog_info['design']); } else { $this->data['blog_design'] = array(); } $record_comment = unserialize($record_info['comment']); $this->data['record_comment'] = $record_comment; if (isset($this->data['blog_design']['visual_editor']) && $this->data['blog_design']['visual_editor'] || !isset($this->data['blog_design']['visual_editor'])) { $this->data['visual_editor'] = true; $this->document->addScript('catalog/view/javascript/wysibb/jquery.wysibb.min.js'); $this->document->addStyle('catalog/view/javascript/wysibb/theme/default/wbbtheme.css'); $this->document->addScript('catalog/view/javascript/blog/blog.bbimage.js'); require_once DIR_SYSTEM . 'library/bbcode.class.php'; $this->document->addScript('catalog/view/javascript/blog/rating/jquery.MetaData.js'); $this->document->addScript('catalog/view/javascript/blog/rating/jquery.rating.js'); $this->document->addStyle('catalog/view/javascript/blog/rating/jquery.rating.css'); } else { $this->data['visual_editor'] = false; } if (isset($this->request->get['tracking'])) { $tracking = $this->request->get['tracking']; } else { $tracking = ''; } if ($tracking != '') { $parts = explode('_', trim(utf8_strtolower($tracking))); foreach ($parts as $num => $val) { list($getquery, $getpar) = explode("-", $val); $this->request->get[$getquery] = $getpar; } //$parts as $num => $val } //$tracking != '' if (isset($this->request->get['page'])) { $page = $this->request->get['page']; } else { $page = 1; } $this->data['page'] = $page; $comments_order = 'comment_id'; $this->data['sorting'] = 'desc'; if (isset($record_comment['order_ad']) && $record_comment['order_ad'] != '') { $this->data['sorting'] = strtolower($record_comment['order_ad']); } //isset($record_comment['order_ad']) && $record_comment['order_ad'] != '' if (isset($record_comment['order']) && $record_comment['order'] != '') { $this->data['order'] = strtolower($record_comment['order']); } //isset($record_comment['order']) && $record_comment['order'] != '' if (isset($this->data['order']) && $this->data['order'] == 'sort') { $comments_order = 'comment_id'; } //isset($this->data['order']) && $this->data['order'] == 'sort' if (isset($this->data['order']) && $this->data['order'] == 'date') { $comments_order = 'date_available'; } //isset($this->data['order']) && $this->data['order'] == 'date' if (isset($this->data['order']) && $this->data['order'] == 'rating') { $comments_order = 'rating'; } //isset($this->data['order']) && $this->data['order'] == 'rating' if (isset($this->data['order']) && $this->data['order'] == 'rate') { $comments_order = 'delta'; } //isset($this->data['order']) && $this->data['order'] == 'rate' if (isset($this->request->get['sorting'])) { if ($this->request->get['sorting'] == 'none') { $this->data['sorting'] = $this->data['sorting']; } else { $this->data['sorting'] = $this->request->get['sorting']; } } //isset($this->request->get['sorting']) $this->data['comments'] = array(); $comment_total = $this->model_catalog_comment->getTotalCommentsByRecordId($this->request->get['record_id']); $this->data['blog_num_comments'] = $this->config->get('blog_num_comments'); if ($this->data['blog_num_comments'] == '') { $this->data['blog_num_comments'] = 10; } if (isset($this->data['blog_design']['blog_num_comments']) && $this->data['blog_design']['blog_num_comments'] != '') { $this->data['blog_num_comments'] = $this->data['blog_design']['blog_num_comments']; } //isset($this->data['blog_design']['blog_num_comments']) && $this->data['blog_design']['blog_num_comments'] != '' $results = $this->model_catalog_comment->getCommentsByRecordId($this->request->get['record_id'], ($page - 1) * $this->data['blog_num_comments'], $this->data['blog_num_comments']); if ($this->customer->isLogged()) { $customer_id = $this->customer->getId(); } else { $customer_id = -1; } $results_rates = $this->model_catalog_comment->getRatesByRecordId($this->request->get['record_id'], $customer_id); if ($customer_id == -1) { $customer_id = false; } if (count($results) > 0) { if (!function_exists('sdesc')) { function sdesc($a, $b) { return strcmp($a['sorthex'], $b['sorthex']); } } //!function_exists('sdesc') $resa = NULL; foreach ($results as $num => $res1) { $resa[$num] = $res1; if (isset($results_rates[$res1['comment_id']])) { $resa[$num]['delta'] = $results_rates[$res1['comment_id']]['rate_delta']; $resa[$num]['rate_count'] = $results_rates[$res1['comment_id']]['rate_count']; $resa[$num]['rate_count_plus'] = $results_rates[$res1['comment_id']]['rate_delta_plus']; $resa[$num]['rate_count_minus'] = $results_rates[$res1['comment_id']]['rate_delta_minus']; $resa[$num]['customer_delta'] = $results_rates[$res1['comment_id']]['customer_delta']; } else { $resa[$num]['customer_delta'] = 0; $resa[$num]['delta'] = 0; $resa[$num]['rate_count'] = 0; $resa[$num]['rate_count_plus'] = 0; $resa[$num]['rate_count_minus'] = 0; } $resa[$num]['hsort'] = ''; $mmm = NULL; $kkk = ''; $wh = strlen($res1['sorthex']) / 4; for ($i = 0; $i < $wh; $i++) { $mmm[$i] = str_pad(dechex(65535 - hexdec(substr($res1['sorthex'], $i * 4, 4))), 4, "F", STR_PAD_LEFT); $sortmy = substr($res1['sorthex'], $i * 4, 4); $kkk = $kkk . $sortmy; } //$i = 0; $i < $wh; $i++ $ssorthex = ''; if (is_array($mmm)) { foreach ($mmm as $num1 => $val) { $ssorthex = $ssorthex . $val; } //$mmm as $num1 => $val } //is_array($mmm) if ($this->data['sorting'] != 'asc') { $resa[$num]['sorthex'] = $ssorthex; } else { $resa[$num]['sorthex'] = $kkk; } $resa[$num]['hsort'] = $kkk; } //$results as $num => $res1 $results = NULL; $results = $resa; uasort($results, 'sdesc'); $i = 0; foreach ($results as $num => $result) { if (!isset($result['date_available'])) { $result['date_available'] = $result['date_added']; } if ($this->rdate($this->language->get('text_date')) == $this->rdate($this->language->get('text_date'), strtotime($result['date_available']))) { $date_str = $this->language->get('text_today'); } else { $date_str = $this->language->get('text_date'); } $date_added = $this->rdate($date_str . $this->language->get('text_hours'), strtotime($result['date_added'])); $text = strip_tags($result['text']); if ($this->data['visual_editor']) { if (isset($this->data['blog_design']['bbwidth']) && $this->data['blog_design']['bbwidth'] != '') { BBCode::$width = $this->data['blog_design']['bbwidth']; } //isset($this->data['blog_design']['bbwidth']) && $this->data['blog_design']['bbwidth'] != '' $text = BBCode::parse($text); } //$this->data['visual_editor'] $this->data['comments'][] = array('comment_id' => $result['comment_id'], 'sorthex' => $result['sorthex'], 'customer_id' => $result['customer_id'], 'customer' => $customer_id, 'customer_delta' => $result['customer_delta'], 'level' => strlen($result['sorthex']) / 4 - 1, 'parent_id' => $result['parent_id'], 'author' => $result['author'], 'text' => $text, 'rating' => (int) $result['rating'], 'hsort' => $result['hsort'], 'myarray' => $mmm, 'delta' => $result['delta'], 'rate_count' => $result['rate_count'], 'rate_count_plus' => $result['rate_count_plus'], 'rate_count_minus' => $result['rate_count_minus'], 'settings_blog' => $this->data['blog_design'], 'comments' => sprintf($this->language->get('text_comments'), (int) $comment_total), 'date_added' => $date_added, 'date_available' => $result['date_available']); $i++; } //$results as $num => $result } //count($results) > 0 if (!function_exists('compare')) { function compare($a, $b) { if ($a['comment_id'] > $b['comment_id']) { return 1; } if ($b['comment_id'] > $a['comment_id']) { return -1; } return 0; } } //!function_exists('compare') if (!function_exists('compared')) { function compared($a, $b) { if ($a['comment_id'] > $b['comment_id']) { return -1; } if ($b['comment_id'] > $a['comment_id']) { return 1; } return 0; } } //!function_exists('compared') if (!function_exists('my_sort_div')) { function my_sort_div($data, $parent = 0, $sorting, $field, $lev = -1) { $arr = $data[$parent]; usort($arr, array(new cmp_my_comment($field, $sorting), "my_cmp")); $lev = $lev + 1; for ($i = 0; $i < count($arr); $i++) { $arr[$i]['level'] = $lev; $z[] = $arr[$i]; $z[count($z) - 1]['flag_start'] = 1; $z[count($z) - 1]['flag_end'] = 0; if (isset($data[$arr[$i]['comment_id']])) { $m = my_sort_div($data, $arr[$i]['comment_id'], $sorting, $field, $lev); $z = array_merge($z, $m); } //isset($data[$arr[$i]['comment_id']]) if (isset($z[count($z) - 1]['flag_end'])) { $z[count($z) - 1]['flag_end']++; } else { $z[count($z) - 1]['flag_end'] = 1; } } //$i = 0; $i < count($arr); $i++ return $z; } } //!function_exists('my_sort_div') if (count($this->data['comments']) > 0) { for ($i = 0, $c = count($this->data['comments']); $i < $c; $i++) { $new_arr[$this->data['comments'][$i]['parent_id']][] = $this->data['comments'][$i]; } //$i = 0, $c = count($this->data['comments']); $i < $c; $i++ $mycomments = my_sort_div($new_arr, 0, $this->data['sorting'], $comments_order); $i = 0; foreach ($mycomments as $num => $result) { if ($i >= ($page - 1) * $this->data['blog_num_comments'] && $i < ($page - 1) * $this->data['blog_num_comments'] + $this->data['blog_num_comments']) { $this->data['mycomments'][$i] = $result; } //($i >= (($page - 1) * $this->data['blog_num_comments'])) && ($i < ((($page - 1) * $this->data['blog_num_comments']) + $this->data['blog_num_comments'])) $i++; } //$mycomments as $num => $result } else { $this->data['mycomments'] = array(); } $this->getChild('common/seoblog'); $this->data['comments'] = $this->data['mycomments']; $pagination = new Pagination(); $pagination->total = $comment_total; $pagination->page = $page; $pagination->limit = $this->data['blog_num_comments']; $pagination->text = $this->language->get('text_pagination'); $pagination->url = $this->url->link('record/record', 'record_id=' . $this->request->get['record_id'] . '&tracking=sorting-' . $this->data['sorting'] . '_page-{page}'); $this->data['pagination'] = $pagination->render(); if (isset($this->data['blog_design']['blog_template_comment']) && $this->data['blog_design']['blog_template_comment'] != '') { $template = $this->data['blog_design']['blog_template_comment']; } else { $template = 'comment.tpl'; } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/record/' . $template)) { $this->template = $this->config->get('config_template') . '/template/record/' . $template; } else { if (file_exists(DIR_TEMPLATE . 'default/template/record/' . $template)) { $this->template = 'default/template/record/' . $template; } else { $this->template = 'default/template/record/comment.tpl'; } } $this->data['theme'] = $this->config->get('config_template'); $html = $this->render(); if (isset($this->request->get['ajax']) && $this->request->get['ajax'] == 1) { $this->response->setOutput($html); } else { return $html; } }