Пример #1
0
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     $pathInfo = urlencode($pathInfo);
     if (preg_match('/^[a-zA-Z0-9%()\\-_\\.]+$/', $pathInfo, $matches)) {
         if (!empty($matches)) {
             $objCategory = Category::LoadByRequestUrl($matches[0]);
             if ($objCategory instanceof Category) {
                 $_GET['cat'] = $matches[0];
                 return 'search/browse';
             }
             $objCustomPage = CustomPage::LoadByRequestUrl($matches[0]);
             if ($objCustomPage instanceof CustomPage) {
                 $_GET['id'] = $objCustomPage->request_url;
                 //Reserved keyword for contact us form
                 if ($matches[0] == "contact-us") {
                     return "custompage/contact";
                 } else {
                     return "custompage/index";
                 }
             } else {
                 return false;
             }
         }
     }
     return false;
     // this rule does not apply
 }
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = CustomPage::LoadByRequestUrl('contact-us');
     $this->pageTitle = $model->PageTitle;
     $this->pageDescription = $model->meta_description;
     $this->breadcrumbs = array($model->title => $model->RequestUrl);
     $this->layout = "//layouts/column" . $model->column_template;
     $ContactForm = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $ContactForm->attributes = $_POST['ContactForm'];
         if ($ContactForm->validate()) {
             $objEmail = new EmailQueue();
             if (!Yii::app()->user->isGuest) {
                 $objCustomer = Customer::GetCurrent();
                 $objEmail->customer_id = $objCustomer->id;
                 $ContactForm->fromName = $objCustomer->mainname;
                 $ContactForm->fromEmail = $objCustomer->email;
             }
             $strHtmlBody = $this->renderPartial('/mail/_contactform', array('model' => $ContactForm), true);
             $strSubject = Yii::t('email', 'Contact Us:') . $ContactForm->contactSubject;
             $objEmail->htmlbody = $strHtmlBody;
             $objEmail->subject = $strSubject;
             $orderEmail = _xls_get_conf('ORDER_FROM', '');
             $objEmail->to = empty($orderEmail) ? _xls_get_conf('EMAIL_FROM') : $orderEmail;
             $objHtml = new HtmlToText();
             //If we get back false, it means conversion failed which 99.9% of the time means improper HTML.
             $strPlain = $objHtml->convert_html_to_text($strHtmlBody);
             if ($strPlain !== false) {
                 $objEmail->plainbody = $strPlain;
             }
             if (!$objEmail->save()) {
                 Yii::log("Error creating email " . print_r($objEmail, true) . " " . print_r($objEmail->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
             }
             Yii::app()->user->setFlash('success', Yii::t('email', 'Message sent. Thank you for contacting us. We will respond to you as soon as possible.'));
             //Attempt to use an AJAX call to send the email. If it doesn't work, the Download process will catch it anyway.
             $jsScript = "\$.ajax({url:\"" . CController::createUrl('site/sendemail', array("id" => $objEmail->id)) . "\"});";
             Yii::app()->clientScript->registerScript('sendemail', $jsScript, CClientScript::POS_READY);
         } else {
             Yii::app()->user->setFlash('error', Yii::t('cart', 'Please check your form for errors.'));
             if (YII_DEBUG) {
                 Yii::app()->user->setFlash('error', print_r($ContactForm->getErrors(), true));
             }
         }
     }
     if (!Yii::app()->user->isGuest) {
         $objCustomer = Customer::GetCurrent();
         $ContactForm->fromName = $objCustomer->mainname;
         $ContactForm->fromEmail = $objCustomer->email;
     }
     $this->canonicalUrl = $model->canonicalUrl;
     $this->render('contact', array('ContactForm' => $ContactForm, 'model' => $model));
 }