function fn_get_discussion_posts($thread_id = 0, $page = 0, $first_limit = '', $random = 'N') { $sets = Registry::get('addons.discussion'); $discussion_object_types = fn_get_discussion_objects(); if (empty($thread_id)) { return false; } $thread_data = db_get_row("SELECT type, object_type FROM ?:discussion WHERE thread_id = ?i", $thread_id); if ($thread_data['type'] == 'D') { return false; } $join = $fields = ''; if ($thread_data['type'] == 'C' || $thread_data['type'] == 'B') { $join .= " LEFT JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id "; $fields .= ", ?:discussion_messages.message"; } if ($thread_data['type'] == 'R' || $thread_data['type'] == 'B') { $join .= " LEFT JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id "; $fields .= ", ?:discussion_rating.rating_value"; } $status_cond = AREA == 'A' ? '' : " AND ?:discussion_posts.status = 'A'"; $total_pages = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts WHERE thread_id = ?i {$status_cond}", $thread_id); if ($first_limit != '') { $limit = "LIMIT {$first_limit}"; } else { $limit = fn_paginate($page, $total_pages, $sets[$discussion_object_types[$thread_data['object_type']] . '_posts_per_page']); } $order_by = $random == 'N' ? '?:discussion_posts.timestamp DESC' : 'RAND()'; return db_get_array("SELECT ?:discussion_posts.* {$fields} FROM ?:discussion_posts {$join} WHERE ?:discussion_posts.thread_id = ?i {$status_cond} ORDER BY ?p {$limit}", $thread_id, $order_by); }
function fn_get_discussion($object_id, $object_type, $get_posts = false, $params = array()) { static $cache = array(); static $customer_companies = null; $_cache_key = $object_id . '_' . $object_type; if (empty($cache[$_cache_key])) { $discussion = db_get_row("SELECT thread_id, type, object_type FROM ?:discussion WHERE object_id = ?i AND object_type = ?s ?p", $object_id, $object_type, fn_get_discussion_company_condition('?:discussion.company_id')); if (empty($discussion) && $object_type == 'M') { $company_discussion_type = Registry::ifGet('addons.discussion.company_discussion_type', 'D'); if ($company_discussion_type != 'D') { $discussion = array('object_type' => 'M', 'object_id' => $object_id, 'type' => $company_discussion_type); if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { $discussion['company_id'] = Registry::get('runtime.company_id'); } $discussion['thread_id'] = db_query('INSERT INTO ?:discussion ?e', $discussion); } } if (!empty($discussion) && AREA == 'C' && $object_type == 'M' && Registry::ifGet('addons.discussion.company_only_buyers', 'Y') == 'Y') { if (empty($_SESSION['auth']['user_id'])) { $discussion['disable_adding'] = true; } else { if ($customer_companies === null) { $customer_companies = db_get_hash_single_array('SELECT company_id FROM ?:orders WHERE user_id = ?i', array('company_id', 'company_id'), $_SESSION['auth']['user_id']); } if (empty($customer_companies[$object_id])) { $discussion['disable_adding'] = true; } } } fn_set_hook('get_discussion', $object_id, $object_type, $discussion); $cache[$_cache_key] = $discussion; } if (!empty($cache[$_cache_key]) && !isset($cache[$_cache_key]['posts']) && $get_posts == true) { $params['thread_id'] = $cache[$_cache_key]['thread_id']; $params['avail_only'] = AREA == 'C'; // FIXME $discussion_object_types = fn_get_discussion_objects(); list($cache[$_cache_key]['posts'], $cache[$_cache_key]['search']) = fn_get_discussion_posts($params, Registry::get('addons.discussion.' . $discussion_object_types[$cache[$_cache_key]['object_type']] . '_posts_per_page')); $cache[$_cache_key]['average_rating'] = fn_get_average_rating($cache[$_cache_key]); } $saved_post_data = fn_restore_post_data('post_data'); if (!empty($saved_post_data)) { $cache[$_cache_key]['post_data'] = $saved_post_data; } return !empty($cache[$_cache_key]) ? $cache[$_cache_key] : false; }
* * * This is commercial software, only users who have purchased a valid * * license and accept to the terms of the License Agreement can install * * and use this program. * * * **************************************************************************** * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE * * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ use Tygh\Registry; use Tygh\Navigation\LastView; if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($mode == 'manage') { $discussion_object_types = fn_get_discussion_objects(); if (empty($_REQUEST['object_type'])) { reset($discussion_object_types); $_REQUEST['object_type'] = key($discussion_object_types); // FIXME: bad style } $_url = fn_query_remove(Registry::get('config.current_url'), 'object_type', 'page'); foreach ($discussion_object_types as $obj_type => $obj) { if ($obj_type == 'E' && Registry::ifGet('addons.discussion.home_page_testimonials', 'D') == 'D') { continue; } $_name = $obj_type != 'E' ? __($obj) . ' ' . __('discussion_title_' . $obj) : __('discussion_title_' . $obj); // FIXME!!! Bad style Registry::set('navigation.tabs.' . $obj, array('title' => $_name, 'href' => $_url . '&object_type=' . $obj_type)); } list($posts, $search) = fn_get_discussions($_REQUEST, Registry::get('settings.Appearance.admin_elements_per_page'));
exit; } return array(CONTROLLER_STATUS_OK, fn_url()); } if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { db_query("DELETE FROM ?:discussion_messages WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_rating WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_posts WHERE post_id = ?i", $_REQUEST['post_id']); return array(CONTROLLER_STATUS_OK, fn_url()); } return; } // No action for vendor at the index if (Registry::get('runtime.company_id') && fn_allowed_for('MULTIVENDOR')) { return; } $latest_posts = db_get_array("SELECT a.post_id, a.ip_address, a.status, a.timestamp, b.object_id, b.object_type as object_type, b.type as type, a.name, c.message, d.rating_value " . "FROM ?:discussion_posts as a INNER JOIN ?:discussion as b ON a.thread_id = b.thread_id ?p " . "LEFT JOIN ?:discussion_messages as c ON a.post_id = c.post_id LEFT JOIN ?:discussion_rating as d ON a.post_id = d.post_id " . "ORDER BY a.timestamp DESC LIMIT 5", fn_get_discussion_company_condition('b.company_id')); if (!empty($latest_posts)) { foreach ($latest_posts as $k => $v) { $latest_posts[$k]['ip_address'] = fn_ip_from_db($v['ip_address']); $latest_posts[$k]['object_data'] = fn_get_discussion_object_data($v['object_id'], $v['object_type'], DESCR_SL); $latest_posts[$k]['rating'] = fn_get_discussion_rating($v['rating_value']); } } Registry::get('view')->assign('discussion_objects', fn_get_discussion_objects()); Registry::get('view')->assign('latest_posts', $latest_posts); if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { // FIXME - bad style Registry::get('view')->display('addons/discussion/views/index/components/dashboard.tpl'); exit; }
if ($mode == 'set_post_status') { $new_status = $_REQUEST['new_status'] === 'A' ? 'A' : 'D'; db_query("UPDATE ?:discussion_posts SET ?u WHERE post_id = ?i", array('status' => $new_status), $_REQUEST['post_id']); $post = db_get_row("SELECT * FROM ?:discussion_posts WHERE post_id = ?i", $_REQUEST['post_id']); $view->assign('post', $post); if (defined('AJAX_REQUEST')) { $view->display('addons/discussion/views/index/components/dashboard_status.tpl'); exit; } return array(CONTROLLER_STATUS_OK, "{$index_script}"); } if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { db_query("DELETE FROM ?:discussion_messages WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_rating WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_posts WHERE post_id = ?i", $_REQUEST['post_id']); return array(CONTROLLER_STATUS_OK, "{$index_script}"); } $latest_posts = db_get_array("SELECT a.post_id, a.ip_address, a.status, a.timestamp, b.object_id, b.object_type, b.type, a.name, c.message, d.rating_value FROM ?:discussion_posts as a LEFT JOIN ?:discussion as b ON a.thread_id = b.thread_id LEFT JOIN ?:discussion_messages as c ON a.post_id = c.post_id LEFT JOIN ?:discussion_rating as d ON a.post_id = d.post_id ORDER BY a.timestamp DESC LIMIT 5"); if (!empty($latest_posts)) { foreach ($latest_posts as $k => $v) { $latest_posts[$k]['object_data'] = fn_get_discussion_object_data($v['object_id'], $v['object_type'], DESCR_SL); $latest_posts[$k]['rating'] = fn_get_discussion_rating($v['rating_value']); } } $view->assign('discussion_objects', fn_get_discussion_objects()); $view->assign('latest_posts', $latest_posts); if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { // FIXME - bad style $view->display('addons/discussion/views/index/components/dashboard.tpl'); exit; }
function fn_get_review_posts_1($thread_id = 0, $page = 0, $first_limit = '', $random = 'N') { $sets = Registry::get('addons.discussion'); $discussion_object_types = fn_get_discussion_objects(); if (empty($thread_id)) { return false; } $thread_data = db_get_row("SELECT type, object_type FROM ?:discussion WHERE thread_id = ?i", $thread_id); if ($thread_data['type'] == 'D') { return false; } $join = $fields = ''; if ($thread_data['type'] == 'C' || $thread_data['type'] == 'B') { $join .= " LEFT JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id "; $fields .= ", ?:discussion_messages.message"; } if ($thread_data['type'] == 'R' || $thread_data['type'] == 'B') { $join .= " LEFT JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id "; $fields .= ", ?:discussion_rating.rating_value"; $fields .= ', ?:discussion_messages.message_title'; } $status_cond = AREA == 'A' ? '' : " AND ?:discussion_posts.status = 'A'"; $total_pages = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts WHERE thread_id = ?i {$status_cond}", $thread_id); if ($first_limit != '') { $limit = "LIMIT {$first_limit}"; } else { $params['total_items'] = $total_pages; $limit = db_paginate($params['page'], $params['items_per_page']); // $limit = fn_paginate($page, $total_pages, $sets[$discussion_object_types[$thread_data['object_type']] . '_posts_per_page']); } $sort = isset($_REQUEST['sort_review']) && $_REQUEST['sort_review'] != 'DF' ? $_REQUEST['sort_review'] : ''; // if discussion type is C do not sort by rating if ($thread_data['type'] == 'C' && ($sort == 'HR' || $sort == 'LR')) { $sort = ''; } switch ($sort) { case 'MH': $fields .= ', SUM(?:review_likes.is_like) as is_l'; $order_by = 'is_l DESC'; $join .= ' JOIN ?:review_likes ON ?:discussion_posts.post_id = ?:review_likes.post_id '; $status_cond .= ' GROUP BY ?:review_likes.post_id '; break; case 'HR': $fields .= ', AVG(?:review_rating.rating) as rating'; $order_by = 'rating DESC'; $join .= ' JOIN ?:review_rating ON ?:discussion_posts.post_id = ?:review_rating.post_id '; $status_cond .= ' GROUP BY ?:review_rating.post_id '; break; case 'LR': $fields .= ', AVG(?:review_rating.rating) as rating'; $order_by = 'rating ASC'; $join .= ' JOIN ?:review_rating ON ?:discussion_posts.post_id = ?:review_rating.post_id '; $status_cond .= ' GROUP BY ?:review_rating.post_id '; break; case 'OD': $order_by = '?:discussion_posts.timestamp ASC'; break; default: $order_by = $random == 'N' ? '?:discussion_posts.timestamp DESC' : 'RAND()'; } $posts = db_get_array("SELECT ?:discussion_posts.* {$fields} FROM ?:discussion_posts {$join} WHERE ?:discussion_posts.thread_id = ?i {$status_cond} ORDER BY ?p {$limit}", $thread_id, $order_by); if (!empty($posts) && is_array($posts)) { foreach ($posts as $k => $post) { $is_like = db_get_field("SELECT COUNT(is_like) FROM ?:review_likes WHERE post_id = ?i AND is_like = '1'", $post['post_id']); $votes = db_get_field('SELECT COUNT(is_like) FROM ?:review_likes WHERE post_id = ?i', $post['post_id']); $posts[$k]['likes']['yes'] = $is_like ? $is_like : 0; $posts[$k]['likes']['votes'] = $votes ? $votes : 0; } } return $posts; }
exit; } return array(CONTROLLER_STATUS_OK, fn_url()); } if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { db_query("DELETE FROM ?:discussion_messages WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_rating WHERE post_id = ?i", $_REQUEST['post_id']); db_query("DELETE FROM ?:discussion_posts WHERE post_id = ?i", $_REQUEST['post_id']); return array(CONTROLLER_STATUS_OK, fn_url()); } return; } // No action for vendor at the index if (Registry::get('runtime.company_id') && fn_allowed_for('MULTIVENDOR')) { return; } $latest_posts = db_get_array("SELECT a.post_id, a.ip_address, a.status, a.timestamp, b.object_id, b.object_type as object_type, b.type as type, a.name, c.message, d.rating_value " . "FROM ?:discussion_posts as a INNER JOIN ?:discussion as b ON a.thread_id = b.thread_id ?p " . "LEFT JOIN ?:discussion_messages as c ON a.post_id = c.post_id LEFT JOIN ?:discussion_rating as d ON a.post_id = d.post_id " . "ORDER BY a.timestamp DESC LIMIT 5", fn_get_discussion_company_condition('b.company_id')); if (!empty($latest_posts)) { foreach ($latest_posts as $k => $v) { $latest_posts[$k]['ip_address'] = fn_ip_from_db($v['ip_address']); $latest_posts[$k]['object_data'] = fn_get_discussion_object_data($v['object_id'], $v['object_type'], DESCR_SL); $latest_posts[$k]['rating'] = fn_get_discussion_rating($v['rating_value']); } } Tygh::$app['view']->assign('discussion_objects', fn_get_discussion_objects()); Tygh::$app['view']->assign('latest_posts', $latest_posts); if ($mode == 'delete_post' && defined('AJAX_REQUEST')) { // FIXME - bad style Tygh::$app['view']->display('addons/discussion/views/index/components/dashboard.tpl'); exit; }
function fn_add_discussion_post($post_data, $send_notifications = true) { $auth =& Tygh::$app['session']['auth']; $discussion_settings = Registry::get('addons.discussion'); $discussion_object_types = fn_get_discussion_objects(); $object = fn_discussion_get_object($post_data); if (empty($object)) { fn_set_notification('E', __('error'), __('cant_find_thread')); return false; } $post_data['thread_id'] = $object['thread_id']; $object_data = fn_get_discussion_object_data($object['object_id'], $object['object_type']); $object_name = $discussion_object_types[$object['object_type']]; $ip = fn_get_ip(); $post_data['ip_address'] = fn_ip_to_db($ip['host']); $post_data['status'] = 'A'; // Check if post is permitted from this IP address if (AREA != 'A' && !empty($discussion_settings[$object_name . '_post_ip_check']) && $discussion_settings[$object_name . '_post_ip_check'] == 'Y') { $is_exists = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts WHERE thread_id = ?i AND ip_address = ?s", $post_data['thread_id'], $post_data['ip_address']); if (!empty($is_exists)) { fn_set_notification('E', __('error'), __('error_already_posted')); return false; } } // Check if post needs to be approved if (AREA != 'A' && !empty($discussion_settings[$object_name . '_post_approval'])) { if ($discussion_settings[$object_name . '_post_approval'] == 'any' || $discussion_settings[$object_name . '_post_approval'] == 'anonymous' && empty($auth['user_id'])) { fn_set_notification('W', __('text_thank_you_for_post'), __('text_post_pended')); $post_data['status'] = 'D'; } } if (!empty($post_data['date'])) { $post_data['timestamp'] = fn_discussion_parse_datetime($post_data['date'] . ' ' . $post_data['time']); } else { $post_data['timestamp'] = TIME; } // Validate rating value if (!empty($post_data['rating_value']) && !in_array($post_data['rating_value'], array_keys(fn_get_discussion_ratings()))) { unset($post_data['rating_value']); } $post_data['user_id'] = $auth['user_id']; $post_data['post_id'] = db_query("INSERT INTO ?:discussion_posts ?e", $post_data); db_query("REPLACE INTO ?:discussion_messages ?e", $post_data); db_query("REPLACE INTO ?:discussion_rating ?e", $post_data); if ($send_notifications) { $fn_prepare_subject = function ($type, $lang_code) { return __('discussion_title_' . $type, '', $lang_code) . ' - ' . __($type, '', $lang_code); }; // For orders - set notification to admin and vendors or customer if ($object['object_type'] == 'O') { $order_info = db_get_row("SELECT email, company_id, lang_code FROM ?:orders WHERE order_id = ?i", $object['object_id']); if (AREA == 'C') { $lang_code = Registry::get('settings.Appearance.backend_default_language'); //Send to admin Mailer::sendMail(array('to' => 'default_company_orders_department', 'from' => array('email' => $order_info['email'], 'name' => $post_data['name']), 'data' => array('url' => fn_url("orders.details?order_id={$object['object_id']}", 'A', 'http', null, true), 'object_data' => $object_data, 'post_data' => $post_data, 'object_name' => $object_name, 'subject' => $fn_prepare_subject($discussion_object_types[$object['object_type']], $lang_code)), 'tpl' => 'addons/discussion/notification.tpl', 'company_id' => $order_info['company_id']), 'A', $lang_code); // Send to vendor if (!empty($order_info['company_id']) && !empty($discussion_settings[$object_name . '_notify_vendor']) && $discussion_settings[$object_name . '_notify_vendor'] == 'Y') { $lang_code = fn_get_company_language($order_info['company_id']); Mailer::sendMail(array('to' => 'company_orders_department', 'from' => array('email' => $order_info['email'], 'name' => $post_data['name']), 'data' => array('url' => fn_url("orders.details?order_id={$object['object_id']}", 'V', 'http', null, true), 'object_data' => $object_data, 'post_data' => $post_data, 'object_name' => $object_name, 'subject' => $fn_prepare_subject($discussion_object_types[$object['object_type']], $lang_code)), 'tpl' => 'addons/discussion/notification.tpl', 'company_id' => $order_info['company_id']), 'A', $lang_code); } } elseif (AREA == 'A') { $lang_code = $order_info['lang_code']; Mailer::sendMail(array('to' => $order_info['email'], 'from' => 'company_orders_department', 'data' => array('url' => fn_url("orders.details?order_id={$object['object_id']}", 'C', 'http', null, true), 'object_data' => $object_data, 'post_data' => $post_data, 'object_name' => $object_name, 'subject' => $fn_prepare_subject($discussion_object_types[$object['object_type']], $lang_code)), 'tpl' => 'addons/discussion/notification.tpl', 'company_id' => $order_info['company_id']), 'C', $lang_code); } } elseif (!empty($discussion_settings[$object_name . '_notification_email']) || !empty($discussion_settings[$object_name . '_notify_vendor']) && $discussion_settings[$object_name . '_notify_vendor'] == 'Y') { $company_id = 0; if (fn_allowed_for('MULTIVENDOR')) { if ($object_name == 'product') { $company_id = db_get_field("SELECT company_id FROM ?:products WHERE product_id = ?i", $object['object_id']); } elseif ($object_name == 'page') { $company_id = db_get_field("SELECT company_id FROM ?:pages WHERE page_id = ?i", $object['object_id']); } elseif ($object_name == 'company') { $company_id = $object['object_id']; } } $url = "discussion_manager.manage?object_type={$object['object_type']}&post_id={$post_data['post_id']}"; if (!empty($discussion_settings[$object_name . '_notification_email'])) { $lang_code = Registry::get('settings.Appearance.backend_default_language'); Mailer::sendMail(array('to' => $discussion_settings[$object_name . '_notification_email'], 'from' => 'company_site_administrator', 'data' => array('url' => fn_url($url, 'A', 'http', null, true), 'object_data' => $object_data, 'post_data' => $post_data, 'object_name' => $object_name, 'subject' => $fn_prepare_subject($discussion_object_types[$object['object_type']], $lang_code)), 'tpl' => 'addons/discussion/notification.tpl', 'company_id' => $company_id), 'A', $lang_code); } // Send to vendor if (!empty($company_id) && !empty($discussion_settings[$object_name . '_notify_vendor']) && $discussion_settings[$object_name . '_notify_vendor'] == 'Y') { $lang_code = fn_get_company_language($company_id); $url = ($object_name == 'company' ? 'companie' : $object_name) . "s.update?" . http_build_query(array($object_name . '_id' => $object['object_id'], 'selected_section' => 'discussion')); Mailer::sendMail(array('to' => 'company_site_administrator', 'from' => 'default_company_site_administrator', 'data' => array('url' => fn_url($url, 'V', 'http', null, true), 'object_data' => $object_data, 'post_data' => $post_data, 'object_name' => $object_name, 'subject' => $fn_prepare_subject($discussion_object_types[$object['object_type']], $lang_code)), 'tpl' => 'addons/discussion/notification.tpl', 'company_id' => $company_id), 'A', $lang_code); } } } return $post_data['post_id']; }