Exemple #1
0
    public function replyAction()
    {
        $this->noViewRenderer(true);
        $request = $this->getRequest();
        if (!JO_Session::get('user_id')) {
            JO_Session::set('msg_error', $this->translate('You must be logged to change your profile'));
            $this->redirect(WM_Router::create($request->getBaseUrl() . '?controller=users&action=login'));
        }
        $link = $request->getServer('HTTP_REFERER');
        if ($request->getRequest('c_id')) {
            $item = Model_Comments::get($request->getRequest('c_id'));
            if ($item) {
                $comment = trim($request->getPost('comment_reply'));
                if ($comment) {
                    $data = array('owner_id' => (int) $item['owner_id'], 'item_id' => $item['item_id'], 'item_name' => $item['item_name'], 'user_id' => JO_Session::get('user_id'), 'comment' => $comment, 'notify' => 'false', 'reply_to' => $item['id']);
                    $id = Model_Comments::add($data);
                    JO_Session::set('msg_success', $this->translate('Your reply has been added successfully'));
                    if ($item['notify'] == 'true' && JO_Session::get('user_id') != $item['owner_id']) {
                        $user = Model_Users::getUser($item['owner_id']);
                        if ($user && !empty($user['email'])) {
                            if (JO_Session::get('user_id') != $item['user_id']) {
                                $is_mail_smtp = JO_Registry::forceGet('config_mail_smtp');
                                $not_template = Model_Notification::getNotification('comment_reply_to');
                                $mail = new JO_Mail();
                                if ($is_mail_smtp) {
                                    $mail->setSMTPParams(JO_Registry::forceGet('config_mail_smtp_host'), JO_Registry::forceGet('config_mail_smtp_port'), JO_Registry::forceGet('config_mail_smtp_user'), JO_Registry::forceGet('config_mail_smtp_password'));
                                }
                                $domain = $request->getDomain();
                                $mail->setFrom('no-reply@' . $domain);
                                $mail->setReturnPath('no-reply@' . $domain);
                                $mail->setSubject($this->translate('New comment on your item') . ' - ' . JO_Registry::forceGet('meta_title'));
                                $lnk = '<a href="' . WM_Router::create($request->getBaseUrl() . '?controller=items&action=comments&item_id=' . $data['item_id']) . '">' . $data['name'] . '</a>';
                                if ($not_template) {
                                    $title = $not_template['title'];
                                    $html = html_entity_decode($not_template['template'], ENT_QUOTES, 'utf-8');
                                    $html = str_replace('{URL}', $lnk, $html);
                                    $html = str_replace('{ITEMNAME}', $item['item_name'], $html);
                                } else {
                                    $html = nl2br('Hello,
			    
			    					There is a new comment on your item ' . $item['name'] . '. You can see it on ' . WM_Router::create($lnk . '&filter=' . $id) . '
			        				');
                                }
                                $mail->setHTML($html);
                                $result = (int) $mail->send(array($user['email']), $is_mail_smtp ? 'smtp' : 'mail');
                            }
                        }
                    }
                } else {
                    JO_Session::set('msg_error', $this->translate('Your reply is empty'));
                }
            } else {
                JO_Session::set('msg_error', $this->translate('The item not found'));
            }
        } else {
            JO_Session::set('msg_error', $this->translate('The comment has not been added'));
        }
        $this->redirect($link . ($item['id'] ? '#c_' . $item['id'] : ''));
    }