Example #1
0
 /**
  * @return array
  */
 public function domainWorker()
 {
     $domainsFile = __DIR__ . "/domains.txt";
     $handle = fopen($domainsFile, "r");
     if (!$handle) {
         throw new \RuntimeException('Error opening file ' . $domainsFile);
     }
     $lines = array();
     while (($line = fgets($handle)) !== false) {
         $line = trim(preg_replace('/\\s\\s+/', ' ', $line));
         // convert russian domains
         if (preg_match('/[А-Яа-яЁё]/u', $line)) {
             $IDN = new IdnaConvert();
             $line = $IDN->encode($line);
         }
         if (empty($line)) {
             continue;
         }
         $lines[] = $line;
     }
     fclose($handle);
     $uniqueLines = array_unique($lines, SORT_STRING);
     sort($uniqueLines, SORT_STRING);
     if (is_writable($domainsFile)) {
         file_put_contents($domainsFile, implode("\n", $uniqueLines));
     } else {
         trigger_error("Permission denied");
     }
     return $lines;
 }
Example #2
0
 public function actionView($id = 0, $url = '')
 {
     if ($url && issetModule('seo')) {
         $seo = SeoFriendlyUrl::getForView($url, $this->modelName);
         if (!$seo) {
             throw404();
         }
         $this->setSeo($seo);
         $id = $seo->model_id;
     }
     $model = $this->loadModel($id, 1);
     if (!$model->active) {
         throw404();
     }
     if ($model->id == 4) {
         //User Agreement
         $field = 'body_' . Yii::app()->language;
         $model->{$field} = str_replace('{site_domain}', IdnaConvert::checkDecode(Yii::app()->getBaseUrl(true)), $model->{$field});
         $model->{$field} = str_replace('{site_title}', CHtml::encode(Yii::app()->name), $model->{$field});
     }
     $this->showSearchForm = $model->widget && $model->widget == 'apartments' ? true : false;
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('view', array('model' => $model));
     } else {
         $this->render('view', array('model' => $model));
     }
 }
Example #3
0
 /**
  * Attempts to return a concrete IDNA instance.
  *
  * @param array $params Set of paramaters
  * @return idna_convert
  * @access public
  */
 public static function getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #4
0
 private function _processEvent($rule, $model, $to, $toModerators = false)
 {
     $user = $this->getFromParam('user');
     if ($this->sendToAdmin) {
         $lang = 'admin';
     } else {
         $lang = Yii::app()->user->checkAccess('backend_access') ? 'default' : 'current';
     }
     $body = '';
     if (isset($rule['body'])) {
         $body = $rule['body'];
         $body = str_replace('{host}', IdnaConvert::checkDecode(Yii::app()->request->hostInfo), $body);
         $body = str_replace('{fullhost}', IdnaConvert::checkDecode(Yii::app()->getBaseUrl(true)), $body);
         if ($user && !isset($model->username) && !isset($model->ownerName)) {
             $body = str_replace('{username}', $user->username, $body);
         }
         if (isset($rule['url']) && $model) {
             $params = array();
             if (isset($rule['url'][1])) {
                 foreach ($rule['url'][1] as $param) {
                     $params[$param] = $model->{$param};
                 }
                 $params['lang'] = $lang;
             }
             $url = Yii::app()->controller->createAbsoluteUrl($rule['url'][0], $params);
             $body = str_replace('{url}', IdnaConvert::checkDecode($url), $body);
         }
         if (isset($rule['fields']) && $model) {
             foreach ($rule['fields'] as $field) {
                 $val = isset($model->{$field}) ? $model->{$field} : tc('No information');
                 $body = str_replace('{' . $field . '}', IdnaConvert::checkDecode($val), $body);
             }
         }
         if (isset($rule['i18nFields']) && $model) {
             foreach ($rule['i18nFields'] as $field) {
                 $field_val = $model->{$field};
                 $body = str_replace('{' . $field . '}', isset($field_val[$lang]) ? CHtml::encode($field_val[$lang]) : tc('No information'), $body);
             }
         }
         $body = str_replace("\n.", "\n..", $body);
     }
     if ($body) {
         Yii::import('application.extensions.mailer.EMailer');
         $mailer = new EMailer();
         if (param('mailUseSMTP', 0)) {
             $mailer->IsSMTP();
             $mailer->SMTPAuth = true;
             $mailer->Host = param('mailSMTPHost', 'localhost');
             $mailer->Port = param('mailSMTPPort', 25);
             $mailer->Username = param('mailSMTPLogin');
             // SMTP login
             $mailer->Password = param('mailSMTPPass');
             // SMTP password
             $mailer->SMTPSecure = param('mailSMTPSecure');
         }
         $mailer->From = param('adminEmail');
         $mailer->FromName = param('mail_fromName', User::getAdminName());
         $mailer->AddAddress($to);
         if ($toModerators && issetModule('rbac')) {
             $moderators = User::model()->findAllByAttributes(array('role' => User::ROLE_MODERATOR));
             if ($moderators && is_array($moderators)) {
                 foreach ($moderators as $moderator) {
                     if (isset($moderator->email) && $moderator->email) {
                         $mailer->AddAddress($moderator->email);
                     }
                 }
             }
         }
         if (isset($rule['subject'])) {
             $mailer->Subject = $rule['subject'];
         }
         $mailer->Body = $body;
         $mailer->CharSet = 'UTF-8';
         $mailer->IsHTML(true);
         if (!$mailer->Send()) {
             throw new CHttpException(503, tt('message_not_send', 'notifier') . ' ErrorInfo: ' . $mailer->ErrorInfo);
             //showMessage(tc('Error'), tt('message_not_send', 'notifier'));
         }
     }
 }