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 notifyAdmin() { $tos = array(); if ($this->getToId()) { $email = $this->getTo()->getSwiftEmail(); if ($email) { $tos[] = $email; } } if (!$tos && $this->getPetitionId()) { $prs = PetitionRightsTable::getInstance()->queryByPetitionAndAdmin($this->getPetition())->execute(); foreach ($prs as $pr) { /* @var $pr PetitionRights */ if ($pr->getUser()->isCampaignMember($this->getPetition()->getCampaign())) { $email = $pr->getUser()->getSwiftEmail(); if ($email) { $tos[] = $email; } } } } if (!$tos && $this->getCampaignId()) { $crs = CampaignRightsTable::getInstance()->queryByCampaignAndAdmin($this->getCampaign())->execute(); foreach ($crs as $cr) { /* @var $cr CampaignRights */ $email = $cr->getUser()->getSwiftEmail(); if ($email) { $tos[] = $email; } } } if ($tos) { $subject = 'Ticket-Notification'; $body = "A new ticket about the following subject has been created:\n\n"; $body .= " Topic: " . $this->getKindName() . "\n"; if ($this->getCampaignId()) { $body .= "Campaign: " . $this->getCampaign()->getName() . "\n"; } if ($this->getPetitionId()) { $body .= " Action: " . $this->getPetition()->getName() . "\n"; } if ($this->getWidgetId()) { $body .= " Widget: " . $this->getWidgetId() . "\n"; } if ($this->getFromId()) { $body .= " User: "******"\n"; } $body .= "\n\n" . sfContext::getInstance()->getRouting()->generate('dashboard', array(), true); foreach ($tos as $to) { UtilMail::send(null, null, $to, $subject, $body); } } }
public function executeTestmail(sfWebRequest $request) { $form = new TestmailForm(); if ($request->isMethod('post')) { $form->bind($request->getPostParameter($form->getName())); if ($form->isValid()) { UtilMail::send(null, $form->getValue('from'), $form->getValue('to'), $form->getValue('subject'), $form->getValue('body')); return $this->ajax()->form($form)->alert('Mail sent.', '', '#testmail', 'after')->render(); } return $this->ajax()->form($form)->render(); } $this->form = $form; }
/** * Displays the contact page */ public function actionContact() { $this->layout = '//layouts/site'; $model = new ContactForm(); if (isset($_POST['ContactForm'])) { $model->attributes = $_POST['ContactForm']; if ($model->validate()) { UtilHelper::writeToFile($model, 'a+'); UtilMail::sendMail($model->email, $model->subject, $model->body); // $headers="From: {$model->email}\r\nReply-To: {$model->email}"; // mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers); Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.'); $this->refresh(); } } $this->render('contact', array('model' => $model)); }
protected function doSave($con = null) { $stats = $this->getValue('stats'); if (is_array($stats)) { foreach ($this->getObject()->getWidgetOwner() as $widget_owner) { /* @var $widget_owner WidgetOwner */ if (array_key_exists($widget_owner->getId(), $stats)) { $new_stat = $stats[$widget_owner->getId()]; if (array_key_exists($new_stat, Owner::$STATUS_SHOW) && $new_stat != $widget_owner->getStatus()) { $widget_owner->setStatus($new_stat); } } } } parent::doSave($con); if ($this->getValue('send_email')) { list($subject, $body) = DefaultText::fetchText(DefaultText::TEXT_AGREEMENT_REPLY); $body = UtilMarkdown::transform($body); $owner = $this->getObject(); UtilMail::send(null, null, array($owner->getEmail() => $owner->getFirstname() . ' ' . $owner->getLastname()), $subject, $body, 'text/html'); } }
public function executeValidate(sfWebRequest $request) { if ($request->hasParameter('code')) { $idcode = $request->getParameter('code'); if (is_string($idcode)) { $idcode = explode('-', trim($idcode)); } if (is_array($idcode) && count($idcode) === 2) { list($this->id, $code) = $idcode; $this->id = ltrim($this->id, '0 '); $petition_signing = PetitionSigningTable::getInstance()->fetch($this->id); if (!empty($petition_signing)) { $petition = $petition_signing->getPetition(); $widget = $petition_signing->getWidget(); $this->lang = $widget->getPetitionText()->getLanguageId(); $this->getContext()->getI18N()->setCulture($this->lang); $this->getUser()->setCulture($this->lang); /* @var $petition_signing PetitionSigning */ /* @var $petition Petition */ $wave = null; if ($petition->isGeoKind()) { foreach ($petition_signing['PetitionSigningWave'] as $psw) { if ($psw['validation_data'] === $code) { $wave = $psw; break; } } } if ($code === $petition_signing->getValidationData() && !$petition->isGeoKind() || $wave) { if ($petition_signing->getStatus() == PetitionSigning::STATUS_PENDING || $wave && $wave->getStatus() == PetitionSigning::STATUS_PENDING) { if ($petition->isEmailKind()) { if ($petition->isGeoKind()) { $petition_signing->setWaveCron($petition_signing->getWavePending()); $wave->setStatus(PetitionSigning::STATUS_VERIFIED); } else { // regular email action, send mail now $subject = $petition_signing->getField(Petition::FIELD_EMAIL_SUBJECT); $body = $petition_signing->getField(Petition::FIELD_EMAIL_BODY); $email_targets = $petition->getEmailTargets(); if (is_string($email_targets)) { $email_targets = json_decode($email_targets, true); } if (is_array($email_targets) && count($email_targets)) { $petition_text = $widget->getPetitionText()->getEmailBody(); if ($petition_text) { UtilMail::appendMissingKeywords($body, $petition_text, PetitionSigningTable::$KEYWORDS); } /* Email to target */ UtilMail::send(null, $petition_signing->getEmailContact($petition->getFromEmail(), true), $email_targets, $subject, $body, null, $petition_signing->getSubst($this->lang), null, $petition_signing->getEmailContact()); } } } $petition_signing->setStatus(PetitionSigning::STATUS_VERIFIED); $petition_signing->setEmailHash($petition_signing->getEmailHashAuto()); $petition_signing->save(); } $this->ref = $petition_signing->getField(Petition::FIELD_REF); $this->wid = $petition_signing->getWidgetId(); $this->landing_url = $widget->findLandingUrl($petition); if ($this->landing_url) { $this->setLayout(false); $this->setTemplate('landing'); } return; } } } $this->setLayout(false); $this->setTemplate('fail'); } }
echo image_path('facebook-32.png'); ?> " /></a> <a href="https://twitter.com/share?text=<?php echo urlencode($title); ?> &url=" class="newwin sicon twitter" title="Twitter"><img class="no_load" alt="Twitter" src="<?php echo image_path('twitter-32.png'); ?> " /></a> <a href="https://plus.google.com/share?url=" class="newwin sicon gplus" title="Google+"><img class="no_load" alt="Google+" src="<?php echo image_path('googleplus-32.png'); ?> " /></a> <?php list($mail_subject, $mail_body) = UtilMail::tellyourmail($widget, $petition, $petition_text, 'UURRLLRREEFF', 'UURRLLMMOORREE'); ?> <a href="mailto:?subject=<?php echo $mail_subject; ?> &body=<?php echo $mail_body; ?> " class="sicon mailto" title="Email" target="_top"><img class="no_load" alt="Email" src="<?php echo image_path('email-32.png'); ?> " /></a> <a id="a_embed_this" class="button_color button_btn"><?php echo __('Embed this'); ?> </a>
protected function execute($arguments = array(), $options = array()) { $context = sfContext::createInstance($this->configuration); $i18n = $context->getI18N(); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $petition_text_by_lang = array(); $table = PetitionSigningTable::getInstance(); $con = $table->getConnection(); $con->beginTransaction(); try { $petition_signing = $table->createQuery('ps')->addFrom('ps.PetitionSigningWave psw')->where('ps.wave_cron > 0')->andWhere('DATE_SUB(NOW(),INTERVAL 2 MINUTE) > ps.updated_at')->andWhere('psw.status = ?', PetitionSigning::STATUS_VERIFIED)->orderBy('ps.created_at DESC')->fetchOne(); if (empty($petition_signing)) { echo "nothing pending. (stop)"; $connection->rollback(); return; } /* @var $petition_signing PetitionSigning */ $petition = $petition_signing->getPetition(); /* @var $petition Petition */ $is_pledge = $petition->getKind() == Petition::KIND_PLEDGE; $waves_verified = array(); foreach ($petition_signing->getPetitionSigningWave() as $wave) { if ($wave->getStatus() == PetitionSigning::STATUS_VERIFIED) { $waves_verified[] = $wave->getWave(); $wave->setStatus(PetitionSigning::STATUS_SENT); } } $contacts = ContactTable::getInstance()->createQuery('c')->addFrom('c.PetitionSigningContact psc')->where('psc.petition_signing_id = ?', $petition_signing->getId())->andWhereIn('psc.wave', $waves_verified)->addFrom('c.ContactMeta cm')->addFrom('cm.MailingListMetaChoice mlmc')->fetchArray(); $subst_fields = $petition_signing->getPetition()->getGeoSubstFields(); $i = 0; foreach ($contacts as $contact) { $subst = $petition_signing->getSubst(); foreach ($subst_fields as $pattern => $subst_field) { switch ($subst_field['type']) { case 'fix': $subst[$pattern] = $contact[$subst_field['id']]; break; case 'free': $subst[$pattern] = ''; foreach ($contact['ContactMeta'] as $cm) { if ($cm['mailing_list_meta_id'] == $subst_field['id']) { $subst[$pattern] = $cm['value']; } } break; case 'choice': $subst[$pattern] = ''; foreach ($contact['ContactMeta'] as $cm) { if ($cm['mailing_list_meta_id'] == $subst_field['id']) { $subst[$pattern] = $cm['MailingListMetaChoice']['choice']; } } break; } } $wave = $petition_signing->getWave($contact['PetitionSigningContact'][0]['wave']); $wave_lang_id = $wave->getLanguageId(); if ($wave_lang_id) { $i18n->setCulture($wave_lang_id); } if ($contact['gender'] == Contact::GENDER_FEMALE) { $personal_salutation = $i18n->__('Dear Madam %F %L,', array('%F' => $contact['firstname'], '%L' => $contact['lastname'])); } elseif ($contact['gender'] == Contact::GENDER_MALE) { $personal_salutation = $i18n->__('Dear Sir %F %L,', array('%F' => $contact['firstname'], '%L' => $contact['lastname'])); } else { $personal_salutation = $i18n->__('Dear Sir/Madam %F %L,', array('%F' => $contact['firstname'], '%L' => $contact['lastname'])); } $personal_salutation .= "\n\n"; $subst[PetitionTable::KEYWORD_PERSONAL_SALUTATION] = $personal_salutation; if ($wave) { if ($is_pledge) { $petition_contact = PetitionContactTable::getInstance()->findOneByPetitionIdAndContactId($petition->getId(), $contact['id']); if (!$petition_contact) { $petition_contact = new PetitionContact(); $petition_contact->setPetitionId($petition->getId()); $petition_contact->setContactId($contact['id']); $new_secret = ''; while (strlen($new_secret) < 15) { $new_secret .= strtoupper(strtr(base_convert(mt_rand(), 10, 36), array('0' => '', 'o' => ''))); } $petition_contact->setSecret(substr($new_secret, 0, 15)); $petition_contact->save(); } $secret = $petition_contact->getSecret(); $subst['#PLEDGE-URL#'] = $this->getRouting()->generate('pledge_contact', array('petition_id' => $petition->getId(), 'contact_id' => $contact['id'], 'secret' => $secret), true); } if (array_key_exists($contact['language_id'], $petition_text_by_lang)) { $petition_text = $petition_text_by_lang[$contact['language_id']]; } else { $petition_text = PetitionTextTable::getInstance()->fetchByPetitionAndPrefLang($petition, $contact['language_id'], Doctrine_Core::HYDRATE_ARRAY); $petition_text_by_lang[$contact['language_id']] = $petition_text; } if ($petition->getKind() == Petition::KIND_PLEDGE) { if ($petition_text) { $subject = $petition_text['email_subject']; $body = $petition_text['email_body']; } else { $subject = $body = ''; } } else { $subject = $wave->getField(Petition::FIELD_EMAIL_SUBJECT); $body = $wave->getField(Petition::FIELD_EMAIL_BODY); } if ($petition_text) { UtilMail::appendMissingKeywords($body, $petition_text['email_body'], PetitionSigningTable::$KEYWORDS); } $i++; try { /* Email to target */ UtilMail::send(null, $wave->getEmailContact($petition->getFromEmail(), true), array($contact['email'] => $contact['firstname'] . ' ' . $contact['lastname']), $subject, $body, null, $subst, null, $wave->getEmailContact()); /* email problem */ } catch (Swift_RfcComplianceException $e) { // ignore invalid emails } } } $id = $petition_signing->getId(); $waves_sent = implode(',', $waves_verified); $petition_signing->setWaveSent($petition_signing->getWaveCron()); $petition_signing->setWaveCron(0); $petition_signing->save(); echo "{$i} mails sent. [{$id}:{$waves_sent}] (continue)"; $con->commit(); } catch (Exception $e) { $con->rollback(); print $e; echo 'exception in transaction. (stop)'; } }
public function executeForgotten($request) { /* @var $request sfWebRequest */ if (!$request->isXmlHttpRequest()) { $this->redirect404(); } $user = $this->getUser(); if ($user->isAuthenticated()) { return $this->redirect('@homepage'); } $form = new sfGuardRequestForgotPasswordForm(); if ($request->isMethod('post')) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { // $this->user = $form->user; $this->_deleteOldUserForgotPasswordRecords($form->user->id); $salt = ''; while (strlen($salt) < 16) { $salt .= base_convert(mt_rand(), 10, 36); } $salt = substr($salt, 0, 16); $code = base_convert(sha1('policat' . mt_rand() . microtime() . mt_rand() . mt_rand()), 16, 36); $forgotPassword = new sfGuardForgotPassword(); $forgotPassword->user_id = $form->user->id; $forgotPassword->unique_key = crypt($code, '$6$' . $salt); $forgotPassword->expires_at = new Doctrine_Expression('NOW()'); $forgotPassword->save(); // $message = Swift_Message::newInstance() // ->setFrom(sfConfig::get('app_sf_guard_plugin_default_from_email', '*****@*****.**')) // ->setTo($this->form->user->email_address) // ->setSubject('Forgot Password Request for ' . $this->form->user->username) // ->setBody($this->getPartial('sfGuardForgotPassword/send_request', array('user' => $this->form->user, 'forgot_password' => $forgotPassword))) // ->setContentType('text/html') // ; // // $this->getMailer()->send($message); $subject = 'password forgotten'; $body = "#VALIDATION-URL#"; $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::PASSWORD_FORGOTTEN_MAIL, $form->user->getLanguageId()); if ($store) { $subject = $store->getField('subject'); $body = $store->getField('body'); } $subst = array('#VALIDATION-URL#' => $this->generateUrl('password_reset', array('id' => $form->user->getId(), 'code' => $code), true), '#USER-NAME#' => $form->user->getFullName()); UtilMail::send(null, null, $form->user->getEmailAddress(), $subject, $body, null, $subst); return $this->ajax()->remove('#forgotten_modal .alert')->attr('#forgotten_modal input, #forgotten_modal button', 'disabled', 'disabled')->alert('Request accepted. Check your mail now.', '', '#forgotten_modal .modal-body', 'append')->render(); } else { return $this->ajax()->remove('#forgotten_modal .alert')->alert('Wrong email address.', 'Error', '#forgotten_modal .modal-body', 'append')->render(); } } else { return $this->ajax()->remove('#forgotten_modal')->appendPartial('body', 'forgotten', array('form' => $form))->modal('#login_modal', 'hide')->modal('#forgotten_modal')->render(); } }
public function executeEdit(sfWebRequest $request) { $id = $request->getParameter('id'); if (is_numeric($id)) { $user = sfGuardUserTable::getInstance()->find($id); /* @var $user sfGuardUser */ if (!$user) { return $this->notFound(); } } else { $user = new sfGuardUser(); $user->setIsActive(false); } if (!$this->getGuardUser()->getIsSuperAdmin() && $user->getIsSuperAdmin()) { $this->noAccess(); } if ($user->isNew()) { $this->form = new UserNewForm($user); } else { $this->form = new UserForm($user); } if ($request->isMethod('post')) { $this->form->bind($request->getPostParameter($this->form->getName())); if ($this->form->isValid()) { $con = sfGuardUserTable::getInstance()->getConnection(); $con->beginTransaction(); try { $this->form->updateGroupsList($this->form->getValues()); $user = $this->form->updateObject(); $user->setUsername($user->getEmailAddress()); if ($user->isNew()) { $user->setValidationKind(sfGuardUserTable::VALIDATION_KIND_BACKEND_LINK); $user->randomValidationCode(); $user->save(); $subject = 'validate activation'; $body = "#VALIDATION-URL#"; $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::NEW_USER_ADMIN_MAIL, $user->getLanguageId()); if ($store) { $subject = $store->getField('subject'); $body = $store->getField('body'); } $subst = array('#VALIDATION-URL#' => $this->generateUrl('user_validation', array('id' => $user->getId(), 'code' => $user->getValidationCode()), true), '#USER-NAME#' => $user->getFullName()); UtilMail::send(null, null, $user->getEmailAddress(), $subject, $body, null, $subst); } else { $user->save(); } $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } return $this->ajax()->redirectRotue('user_idx')->render(); } else { return $this->ajax()->form($this->form)->render(); } } if (!$user->isNew()) { $this->campaign_rights_list = CampaignRightsTable::getInstance()->queryByUser($user)->execute(); $this->petition_rights_list = PetitionRightsTable::getInstance()->queryByUser($user)->execute(); } }
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); } }