Example #1
0
 public function mailgunValidator($attribute, $params)
 {
     $yg = new Yiigun();
     $result = $yg->validate($this->{$attribute});
     if ($result->is_valid) {
         return false;
     } else {
         $this->addError($attribute, 'There is a problem with your email address ' . $result->address . '. Did you mean ' . $result->did_you_mean . '?');
     }
 }
Example #2
0
 public function actionCreate($id = 0)
 {
     $model = new Message();
     $model->mglist_id = $id;
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Message'])) {
         $model->attributes = $_POST['Message'];
         $model->created_at = new CDbExpression('NOW()');
         $model->modified_at = new CDbExpression('NOW()');
         if ($model->save()) {
             Yii::app()->user->setFlash('messageSubmitted', 'Thank you, your message has been posted.');
             $lookup_item = Mglist::model()->findByPk($model->mglist_id);
             $yg = new Yiigun();
             $yg->send_simple_message($lookup_item['address'], $model->subject, $model->body, Yii::app()->params['superuser']);
             $this->redirect('/mglist/index');
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     $model = new Request();
     $mglist = Mglist::model()->findByPk($id);
     $model->list_id = $id;
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Request'])) {
         $model->mglist_id = $id;
         $model->attributes = $_POST['Request'];
         $model->checksum = 0;
         // unused now - prior rand(100,10000);
         $yg = new Yiigun();
         $model->hash = $yg->generateVerifyHash($model, $mglist);
         $res = $model->save();
         if ($model->save()) {
             $yg->sendVerificationRequest($model, $mglist);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('id' => $id, 'model' => $model, 'mglist' => $mglist));
 }
Example #4
0
 public function syncListMembers($id = 0, $in_batch = false)
 {
     // fetch list members from Mailgun.com
     // don't build membership detail report for batch list sync
     if (is_null($id)) {
         return false;
     }
     $output_str = '';
     $mglist = $this->findByPk($id);
     $yg = new Yiigun();
     // fetch list address based on $id
     $my_members = $yg->fetchListMembers($mglist['address']);
     foreach ($my_members->items as $member) {
         $output_str .= '<p>Upserting member: ' . $member->name . ' &lt;' . $member->address . '&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
         $m = new Member();
         // add to local db
         $temp_str = $m->upsert($member);
         $output_str .= $temp_str;
         // add to join table
         $member = Member::model()->findByAttributes(array('address' => $member->address));
         Member::model()->addToList($member['id'], $id);
         $output_str .= '</p>';
     }
     return $output_str;
 }
Example #5
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionImport($id = 0)
 {
     $model = new Import();
     $model->mglist_id = $id;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Import'])) {
         $temp_email_list = $_POST['Import']['email_list'];
         include 'Mail/RFC822.php';
         $parser = new Mail_RFC822();
         // replace the backslash quotes
         $tolist = str_replace('\\"', '"', $temp_email_list);
         // split the elements by line and by comma
         $to_email_array = preg_split("(\r|\n|,)", $tolist, -1, PREG_SPLIT_NO_EMPTY);
         $num_emails = count($to_email_array);
         $temp = '';
         // construct bulk list of new members for mailgun api call
         $json_upload = '[';
         for ($count = 0; $count < $num_emails && $count <= 500; $count++) {
             $json_upload .= '{';
             $toAddress = trim($to_email_array[$count]);
             if ($toAddress != '') {
                 $addresses = $parser->parseAddressList('my group:' . $toAddress, 'yourdomain.com', false, true);
                 foreach ($addresses as $i) {
                     if ($i->mailbox != '' and $i->host != '') {
                         $temp .= $i->mailbox . '@' . $i->host . ',';
                     }
                     $m = new Member();
                     if ($i->personal != '') {
                         $m->name = $i->personal;
                         $json_upload .= '"name": "' . $m->name . '", ';
                     } else {
                         $m->name = '';
                     }
                     $m->address = $i->mailbox . '@' . $i->host;
                     $json_upload .= '"address": "' . $m->address . '"';
                     $m->status = 1;
                     $m->created_at = new CDbExpression('NOW()');
                     $m->modified_at = new CDbExpression('NOW()');
                     // echo $m->name.' '.$m->address.' ->'.$id.'<br />';
                     $lookup_item = Member::model()->findByAttributes(array('address' => $m->address));
                     if (!is_null($lookup_item)) {
                         // member exists
                         // echo 'exists'.$lookup_item['id'];
                         $m->addToList($lookup_item['id'], $id);
                     } else {
                         // new member
                         $m->save();
                         $last_id = Yii::app()->db->getLastInsertID();
                         // echo 'saved'.$last_id;
                         $m->addToList($last_id, $id);
                     }
                 }
             }
             $json_upload .= '},';
         }
         $temp = trim($temp, ',');
         $model->email_list = $temp;
         $json_upload = trim($json_upload, ',');
         $json_upload .= ']';
         if ($model->save()) {
             Yii::app()->user->setFlash('import_success', 'Thank you! Your messages have been submitted.');
             $yg = new Yiigun();
             // echo $json_upload;
             $list_item = Mglist::model()->findByPk($id);
             // echo $list_item['address'];
             $yg->memberBulkAdd($list_item['address'], $json_upload);
             $this->redirect('/mglist/' . $id);
         }
     }
     $this->render('import', array('model' => $model, 'mglist_id' => $id));
 }
Example #6
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         // delete at Mailgun
         $yg = new Yiigun();
         $yg->listDelete($model->address);
         // delete locally
         $model->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }