/**
  * Check template
  */
 private static function checkTemplate($templateName, $text)
 {
     // NOTE: Replace have to do before preg_match_all, then for matching gone new filters
     //
     // 1. Replace twig filters to the allowed mailtank filters
     $text = preg_replace('/\\|raw(\\s|\\||\\)|\\})/', '|safe$1', $text);
     // 2. If anything filters didn't find, then quit
     if (!preg_match_all('/\\|\\w*/', $text, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) {
         return $text;
     }
     $findError = false;
     foreach ($matches[0] as $match) {
         // Skip the allowed mailtank filters
         if (in_array($match[0], ['|safe', '|length', '|capitalize'])) {
             continue;
         }
         $findError = true;
         $start = strrpos($text, "\n", $match[1] - strlen($text));
         if ($start === false) {
             $start = $match[1] > 32 ? $match[1] - 32 : 0;
         }
         $end = strpos($text, "\n", $match[1]);
         if ($end === false) {
             $end = strlen($text) - $match[1] >= 32 ? $match[1] + 32 : strlen($text) - 1;
         }
         if (!self::$useConsoleOut) {
             throw new MailtankException('<' . $templateName . '> find not allowed filter: ' . $match[0]);
         }
         Console::warning('<' . $templateName . '> find not allowed filter: ' . $match[0]);
         Console::annotation(trim(substr($text, $start, $end - $start)));
     }
     if (!$findError) {
         return $text;
     }
     return false;
 }
예제 #2
0
 /**
  * 设置标准响应http状态码
  *
  * @access protected
  * @param int $code 返回的http状态码
  * @return void
  */
 protected function sendHttpCode($code = 200)
 {
     $sender = new SenderHttp();
     if ($extra_headers = Console::serializeHeaders()) {
         $sender->getHeaders()->addHeaderLine('HTTP-CCS-FIREPHP', $extra_headers);
     }
     $sender->setStatus($code);
     $sender->send();
 }
예제 #3
0
 /**
  * Синхронизация подписчиков с мейлтанком
  * @param $isSync boolean false - только сравнить, true - синхронизировать
  */
 public static function syncFromMailtank($isSync = false)
 {
     $subscriberCount = 0;
     try {
         $page = 1;
         $res = self::getPage($page);
         $totalPages = $res['pages_total'];
         while (true) {
             // Обрабатываем подписчиков
             foreach ($res['objects'] as $subscriber) {
                 $subscriberCount++;
                 $mailtankId = $subscriber['id'];
                 $email = $subscriber['email'];
                 $mailtank2email = Mailtank2Email::find()->where(['email' => $email])->asArray()->one();
                 if (!$mailtank2email) {
                     // У нас нет такого email
                     $obj = Mailtank2Email::find()->where(['mailtankId' => $mailtankId])->asArray()->one();
                     if (!$obj) {
                         // Если у нас нет такого mailtankId, то это новый подписчик
                         Console::outputColored("- Subscriber <%y" . $email . "%n> exists only in the mailtank", false);
                         if ($isSync) {
                             if (self::createInnerSubscriber($email, $mailtankId)) {
                                 Console::outputColored("...%g created%n", false);
                             } else {
                                 Console::outputColored("...%r not created%n", false);
                             }
                         }
                         Console::output();
                     } else {
                         // Если у нас есть такой mailtankId, то прописываем ему email с мейлтанка
                         Console::outputColored("- Found inner subscriber mailtankId=<%y" . $mailtankId . "%n> but other email=<%y" . $obj['email'] . "%n>", false);
                         if ($isSync) {
                             $obj['email'] = $email;
                             if ($obj->save()) {
                                 Console::outputColored("...%g changed to <" . $email . ">%n", false);
                             } else {
                                 Console::outputColored("...%r not changed%n", false);
                             }
                         }
                         Console::output();
                     }
                 } else {
                     // У нас есть такой email
                     // Если совпадает mailtankId, то корректный пользователь и ничего делать не надо
                     if ($mailtank2email['mailtankId'] == $mailtankId) {
                         continue;
                     }
                     Console::outputColored("- Same emails <%y" . $email . "%n> belong to different subscribers in the mailtank. Inner id=<%y" . $mailtank2email['mailtankId'] . "%n>, mailtank id=<%y" . $mailtankId . "%n>");
                     if ($isSync) {
                         // Если не совпадает mailtankId, ищем подписчика по mailtankId с мейлтанка
                         $obj = Mailtank2Email::find()->where(['mailtankId' => $mailtankId])->asArray()->one();
                         if ($obj) {
                             // Если нашли, то удаляем его, а предыдущему меняем mailtankId
                             if ($obj->delete()) {
                                 Console::outputColored("  %gInner subscriber mailtankId <" . $mailtankId . "> succesfully delete%n");
                             } else {
                                 Console::outputColored("  %rWrong delete mailtank2email with mailtankId=<" . $mailtankId . ">%n");
                                 die;
                             }
                         }
                         $mailtank2email['mailtankId'] = $mailtankId;
                         if ($mailtank2email->save()) {
                             Console::outputColored("  %gFor email <" . $email . "> changed MailtankId to <" . $mailtankId . ">%n");
                         } else {
                             Console::outputColored("  %rFor email <" . $email . "> didn't change MailtankId to <" . $mailtankId . ">%n");
                         }
                     }
                 }
             }
             if ($page >= $totalPages) {
                 break;
             }
             $page++;
             $res = self::getPage($page);
         }
     } catch (MailtankException $e) {
         if ($e->getCode() == 404) {
             return true;
         }
         throw $e;
     }
 }