コード例 #1
0
ファイル: func.php プロジェクト: ambient-lounge/site
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'];
}
コード例 #2
0
ファイル: discussion.php プロジェクト: ambient-lounge/site
        }
        fn_add_discussion_post($_REQUEST['post_data']);
    }
    if ($mode == 'update') {
        if (!empty($_REQUEST['posts'])) {
            fn_update_discussion_posts($_REQUEST['posts']);
        }
    }
    $redirect_url = "discussion_manager.manage";
    if (!empty($_REQUEST['redirect_url'])) {
        $redirect_url = $_REQUEST['redirect_url'] . $suffix;
    }
    return array(CONTROLLER_STATUS_OK, $redirect_url);
}
if ($mode == 'view') {
    $data = fn_discussion_get_object(array('thread_id' => $_REQUEST['thread_id']));
    if (empty($data)) {
        return array(CONTROLLER_STATUS_NO_PAGE);
    }
    if (AREA != 'A') {
        // Check if user has an access for this thread
        if (fn_is_accessible_discussion($data, $auth) == false) {
            return array(CONTROLLER_STATUS_DENIED);
        }
        if ($data['object_type'] == 'E' && !empty($_REQUEST['post_id'])) {
            $post_pos = db_get_field("SELECT COUNT(*) FROM ?:discussion_posts WHERE thread_id = ?i AND post_id >= ?i AND status = 'A' ORDER BY timestamp DESC", $_REQUEST['thread_id'], $_REQUEST['post_id']);
            if (!empty($post_pos)) {
                $sets = Registry::get('addons.discussion');
                $discussion_object_types = fn_get_discussion_objects();
                $items_per_page = $sets[$discussion_object_types[$data['object_type']] . '_posts_per_page'];
                $page = ceil($post_pos / $items_per_page);