Ejemplo n.º 1
0
 function __construct()
 {
     parent::__construct('AIzaSyAN2hEVTtDDuQp7qKrB-A8rVNenFf5m4C4');
 }
Ejemplo n.º 2
0
        $update = $mysqli->query("UPDATE companies SET name = '{$name}', last_message_id = '{$lastEventId}' WHERE id = '{$company['id']}' LIMIT 1");
        if (!$update) {
            exit('Что-то не так с первичной обработкой компании: ' . $mysqli->error);
        }
        continue;
    }
    preg_match_all('/href="http:\\/\\/e-disclosure\\.ru\\/portal\\/event\\.aspx\\?EventId=(.*)" s/', $page, $events);
    if ($events[1][0] === $company['last_message_id']) {
        // новых сообщений не добавилось
        continue;
    }
    // @todo: предусмотреть, что за одну минуту могло добавится несколько сообщений одной компании, тогда в хранологическом порядке их рассылать
    preg_match('/href="http:\\/\\/e-disclosure\\.ru\\/portal\\/event\\.aspx\\?EventId=(.*)" style="(.*)" >(.*)<\\/a>/', $page, $lastEvent);
    if (empty($lastEvent[3])) {
        continue;
        // если не удалось получить текст сообщения
    }
    $update = $mysqli->query("UPDATE companies SET last_message_id = '{$lastEvent['1']}' WHERE id = '{$company['id']}' LIMIT 1");
    $longUrl = 'http://e-disclosure.ru/portal/event.aspx?EventId=' . $lastEvent[1];
    $shortener = new GoogleUrlApi(GOOGLE_API_KEY);
    $shortUrl = $shortener->shorten($longUrl);
    $getSubscribers = $mysqli->query("SELECT * FROM subscriptions WHERE company_id = '{$company['id']}'");
    if ($getSubscribers->num_rows) {
        $companyName = empty($company['custom_name']) ? $company['name'] : $company['custom_name'];
        $messageText = $shortText->shorten($lastEvent[3]);
        $text = sprintf('%s: %s %s', $companyName, $messageText, $shortUrl);
        while ($subscriber = $getSubscribers->fetch_assoc()) {
            sendMsgToSubscriber($text, $subscriber['subscriber_id']);
        }
    }
}