public static function send(PetitionSigning $signing, $subject_prefix = null) { if ($signing->getValidationKind() != PetitionSigning::VALIDATION_KIND_EMAIL) { return; } $widget = $signing->getWidget(); $petition = $widget->getPetition(); $petition_text = $widget->getPetitionText(); $subject = $petition_text->getEmailValidationSubject(); $body = $petition_text->getEmailValidationBody(); $validation = UtilLink::signValidation($signing->getId(), $signing->getValidationData()); $url_ref_ = $signing->getField(Petition::FIELD_REF); // $this->getValue('ref'); $url_readmore_ = $petition->getReadMoreUrl(); $url_ref = UtilPolicat::firstString(array($url_ref_, $url_readmore_)); $url_readmore = UtilPolicat::firstString(array($url_readmore_, $url_ref_)); $from = $petition->getFrom(); $to = $signing->getEmail(); $additional_subst = array('URL-REFERER' => $url_ref, 'URL-READMORE' => $url_readmore, 'VALIDATION' => $validation, '#REFERER-URL#' => $url_ref, '#READMORE-URL#' => $url_readmore, '#VALIDATION-URL#' => $validation); if ($subject_prefix) { $i18n = sfContext::getInstance()->getI18N(); $i18n->setCulture($signing->getWidget()->getPetitionText()->getLanguageId()); $translated = $i18n->__($subject_prefix); $subject = $translated . ' ' . $subject; } UtilMail::sendWithSubst(null, $from, $to, $subject, $body, $petition_text, $widget, $additional_subst, $signing->getSubst()); }
public function executeSign(sfWebRequest $request) { // hash check $id = $request->getParameter('id'); $hash = $request->getParameter('hash'); if (!is_numeric($id) || !is_string($hash)) { $this->forward404(); } $id = ltrim($id, ' 0'); if (!Widget::isValidLastHash($id, $hash)) { $this->forward404(); } $this->setLayout(false); $this->fetchWidget(); $this->petition = $this->widget['Petition']; $this->petition_text = $this->widget['PetitionText']; $this->lang = $this->petition_text['language_id']; $this->getUser()->setCulture($this->lang); $widget_texts = $this->petition->getWidgetIndividualiseText(); $this->title = $widget_texts && !empty($this->widget['title']) ? $this->widget['title'] : $this->petition_text['title']; $this->target = $widget_texts ? $this->widget['target'] : $this->petition_text['target']; $this->background = $widget_texts ? $this->widget['background'] : $this->petition_text['background']; $this->paypal_email = StoreTable::value(StoreTable::DONATIONS_PAYPAL) ? $this->widget->getFinalPaypalEmail() : ''; $this->paypal_ref = sprintf("%s%s%s", $this->petition['id'], $this->petition_text['language_id'], $this->widget['id']); $this->read_more_url = $this->petition['read_more_url']; $this->width = $this->widget->getStyling('width'); $this->font_family = $this->petition->getStyleFontFamily(); $widget_colors = $this->petition->getWidgetIndividualiseDesign(); foreach (array('title_color', 'body_color', 'button_color', 'bg_left_color', 'bg_right_color', 'form_title_color') as $style) { if ($widget_colors) { $this->{$style} = $this->widget->getStyling($style, $this->petition['style_' . $style]); } else { $this->{$style} = $this->petition['style_' . $style]; } } $sign = new PetitionSigning(); $sign['Petition'] = $this->widget['Petition']; $sign['Widget'] = $this->widget; if ($request->isMethod('post') && $request->hasParameter('widget')) { $form_param = $request->getParameter('widget'); if (is_scalar($form_param['edit_code']) && !empty($form_param['edit_code'])) { $new_widget = Doctrine_Core::getTable('Widget')->createQuery('w')->where('w.id = ?', $id)->andWhere('w.edit_code = ?', $form_param['edit_code'])->addFrom('w.Campaign, w.Petition, w.PetitionText')->fetchOne(); } } if (!isset($new_widget)) { $new_widget = new Widget(); $new_widget['Parent'] = $this->widget; $new_widget['Campaign'] = $this->widget['Campaign']; $new_widget['Petition'] = $this->widget['Petition']; $new_widget['PetitionText'] = $this->widget['PetitionText']; } $this->form = new PetitionSigningForm($sign, array('validation_kind' => PetitionSigning::VALIDATION_KIND_EMAIL)); $this->form_embed = new WidgetPublicForm($new_widget); $extra = array(); if ($this->getRequest()->isMethod('post')) { $this->getResponse()->setContentType('text/javascript'); $ajax_response_form = null; // It is a signing form if ($request->hasParameter($this->form->getName())) { if ($this->petition->isBefore() || $this->petition->isAfter()) { return $this->renderText(json_encode(array('over' => true))); } $ajax_response_form = $this->form; $this->form->bind($request->getPostParameter($this->form->getName())); if ($this->form->isValid()) { $this->form->save(); if (sfConfig::get('sf_environment') === 'stress') { // ONLY FOR STRESS TEST !!! $extra['code'] = $this->form->getObject()->getId() . '-' . $this->form->getObject()->getValidationData(); } $search_table = PetitionSigningSearchTable::getInstance(); $search_table->savePetitionSigning($sign, false); $con = $search_table->getConnection(); $ref = $this->form->getValue(Petition::FIELD_REF); if (!(strpos($ref, 'http://') === 0 || strpos($ref, 'http://') === 0)) { $ref = null; } $sql_time = gmdate('Y-m-d H:i:s'); // DQL query would invalidate petition cache so let's use SQL $con->exec('update petition set activity_at = ? where id = ?', array($sql_time, $this->petition->getId())); if ($ref) { $con->exec('update widget set activity_at = ?, last_ref = ? where id = ?', array($sql_time, $ref, $this->widget->getId())); } else { $con->exec('update widget set activity_at = ? where id = ?', array($sql_time, $this->widget->getId())); } } } else { if ($request->hasParameter($this->form_embed->getName())) { $ajax_response_form = $this->form_embed; $this->form_embed->bind($request->getPostParameter($this->form_embed->getName())); if ($this->form_embed->isValid()) { $this->form_embed->save(); $extra['id'] = $this->form_embed->getObject()->getId(); $extra['edit_code'] = $this->form_embed->getObject()->getEditCode(); $extra['markup'] = UtilLink::widgetMarkup($extra['id']); } else { } } else { if ($request->hasParameter('target_selector')) { $target_selector = $request->getParameter('target_selector'); if (is_scalar($target_selector)) { return $this->renderText(json_encode($this->petition->getTargetSelectorChoices($target_selector))); } } else { if ($request->hasParameter('target_selector1') && $request->hasParameter('target_selector2')) { $target_selector1 = $request->getParameter('target_selector1'); $target_selector2 = $request->getParameter('target_selector2'); if (is_scalar($target_selector1) && is_scalar($target_selector2)) { return $this->renderText(json_encode($this->petition->getTargetSelectorChoices2($target_selector1, $target_selector2))); } } } } } return $this->renderPartial('json_form', array('form' => $ajax_response_form, 'extra' => $extra)); } }
protected function doSave($con = null) { $wasNew = $this->getObject()->isNew(); parent::doSave($con); if ($wasNew) { $widget = $this->getObject(); $petition = $widget->getPetition(); $petition_text = $widget->getPetitionText(); $subject = 'Validate your widget'; $body = "Validate: VALIDATION\nEdit: EDITCODE"; $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::EMBED_WIDGET_MAIL, $petition_text->getLanguageId()); if ($store) { $subject = $store->getField('subject'); $body = $store->getField('body'); } $validation = UtilLink::widgetValidation($this->getObject()->getId(), $this->getObject()->getValidationData()); $edit_code = UtilLink::widgetEdit($this->getObject()->getId(), $this->getObject()->getEditCode()); $from = $petition->getFrom(); $to = $this->getObject()->getEmail(); $additional_subst = array('VALIDATION' => $validation, 'EDITCODE' => $edit_code, '#VALIDATION-URL#' => $validation, '#EDIT-URL#' => $edit_code); UtilMail::sendWithSubst(null, $from, $to, $subject, $body, $petition_text, $widget, $additional_subst); } }