$items_per_page = $sets[$discussion_object_types[$data['object_type']] . '_posts_per_page']; $page = ceil($post_pos / $items_per_page); if (empty($_REQUEST['page']) && $page != 1 || !empty($_REQUEST['page']) && $page != $_REQUEST['page']) { $_REQUEST['page'] = $page; } $_SESSION['discussion_post_id'] = $_REQUEST['post_id']; return array(CONTROLLER_STATUS_REDIRECT, fn_query_remove(Registry::get('config.current_url'), 'page', 'post_id')); } } } $show_discussion_crumb = true; if ($data['object_type'] == 'E') { // testimonials $show_discussion_crumb = false; } $discussion_object_data = fn_get_discussion_object_data($data['object_id'], $data['object_type']); fn_add_breadcrumb($discussion_object_data['description'], $discussion_object_data['url']); if ($show_discussion_crumb && AREA != 'A') { fn_add_breadcrumb(fn_get_lang_var('discussion')); } if (!empty($_SESSION['discussion_post_id'])) { $view->assign('current_post_id', $_SESSION['discussion_post_id']); unset($_SESSION['discussion_post_id']); } $view->assign('object_id', $data['object_id']); $view->assign('title', $discussion_object_data['description']); $view->assign('object_type', $data['object_type']); } function fn_discussion_get_object_by_thread($thread_id) { static $cache = array();
$_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')); if (!empty($posts)) { foreach ($posts as $k => $v) { $posts[$k]['object_data'] = fn_get_discussion_object_data($v['object_id'], $v['object_type'], DESCR_SL); } } Tygh::$app['view']->assign('posts', $posts); Tygh::$app['view']->assign('search', $search); Tygh::$app['view']->assign('discussion_object_type', $_REQUEST['object_type']); Tygh::$app['view']->assign('discussion_object_types', $discussion_object_types); } function fn_get_discussions($params, $items_per_page) { // Init filter $params = LastView::instance()->update('discussion', $params); // Set default values to input params $default_params = array('page' => 1, 'items_per_page' => $items_per_page); $params = array_merge($default_params, $params); // Define fields that should be retrieved
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']; }