public static function sendNotificationToAdmin($args) { list($idsite, $idvisitor, $message) = $args; $visitorInfo = ChatPersonnalInformation::get($idvisitor); $subject = "New message on " . ChatSite::getSiteName($idsite); $mail = new Mail(); $mail->setFrom(Config::getInstance()->General['noreply_email_address'], "Piwik Chat"); $mail->setSubject($subject); $mail->setBodyHtml("Name : " . $visitorInfo['name'] . "<br />\n Email : " . $visitorInfo['email'] . "<br />\n Phone : " . $visitorInfo['phone'] . "<br />\n Comments : " . $visitorInfo['comments'] . "<br />\n <br /><br />\n Message:<br />{$message}"); foreach (ChatCommon::getUsersBySite($idsite) as $user) { if (empty($user['email'])) { continue; } if (ChatPiwikUser::isStaffOnline($user['login'])) { continue; } $mail->addTo($user['email']); try { $mail->send(); } catch (Exception $e) { throw new Exception("An error occured while sending '{$subject}' " . " to " . implode(', ', $mail->getRecipients()) . ". Error was '" . $e->getMessage() . "'"); } $mail->clearRecipients(); } }
public function poll($microtime = false, $admin = false) { session_write_close(); $pollMs = 500000; $timeout = $counter = 30; $timeoutBuffer = 5; set_time_limit($timeout + $timeoutBuffer); if (microtime(true) > $microtime + 10) { $microtime = microtime(true); } ChatPiwikUser::setLastPoll($microtime, $admin); while ($counter > 0) { $data = $this->getNewMessages($microtime, $admin); if (count($data) > 0) { break; } else { usleep($pollMs); $counter -= $pollMs / 1000000; } } if (count($data) > 0) { return $data; } return false; }
public function isStaffOnline($idSite) { return ChatPiwikUser::isStaffOnline(); }
public function popout() { header("Access-Control-Allow-Origin: *"); $params = UrlHelper::getArrayFromQueryString($_SERVER['QUERY_STRING']); $request = new Tracker\Request($params); // the IP is needed by isExcluded() and GoalManager->recordGoals() $ip = $request->getIp(); $visitorInfo['location_ip'] = $ip; /** * Triggered after visits are tested for exclusion so plugins can modify the IP address * persisted with a visit. * * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses. * * @param string &$ip The visitor's IP address. */ Piwik::postEvent('Tracker.setVisitorIp', array(&$visitorInfo['location_ip'])); /*** * Visitor recognition */ $settings = new Tracker\Settings($request, $visitorInfo['location_ip']); $visitor = new Visitor($request, $settings->getConfigId(), $visitorInfo); $visitor->recognize(); $visitorInfo = $visitor->getVisitorInfo(); if (!isset($visitorInfo['location_browser_lang'])) { return "Who are you ?"; } $idSite = Common::getRequestVar('idsite', null, 'int'); $conversation = new ChatConversation($idSite, bin2hex($visitorInfo['idvisitor'])); /*** * Segment recognition */ foreach (ChatAutomaticMessage::getAll($idSite) as $autoMsg) { $segment = ChatSegment::get($autoMsg['segmentID']); $fetchSegment = new Segment($segment['definition'], array($idSite)); $query = $fetchSegment->getSelectQuery("idvisitor", "log_visit", "log_visit.idvisitor = ?", array($visitorInfo['idvisitor'])); $rows = Db::fetchAll($query['sql'], $query['bind']); if (count($rows) == 0) { continue; } if ($autoMsg['segmentID'] != $segment['idsegment']) { continue; } $getAlreadyReceivedMsg = $conversation->getAutomaticMessageReceivedById($autoMsg['id']); if (count($getAlreadyReceivedMsg) > 0) { // If the AutoMsg is a "one shot" if ($autoMsg['frequency'] == 0) { continue; } if ($autoMsg['frequency'] != 0) { // Now, we gonna try to define when the last AutoMsg received has been sent list($freqTime, $freqScale) = explode('|', $autoMsg['frequency']); if ($freqScale == "w") { $dayMultiplier = 7; } elseif ($freqScale == "m") { $dayMultiplier = 30; } else { $dayMultiplier = 1; } $secToWait = 3600 * 24 * $freqTime * $dayMultiplier; // Is it older than the time range needed to wait ? if ($getAlreadyReceivedMsg[0]['microtime'] + $secToWait > microtime(true)) { continue; } } } $conversation->sendMessage($autoMsg['message'], $autoMsg['transmitter'], $autoMsg['id']); } $view = new View('@Chat/popout.twig'); $view->idvisitor = bin2hex($visitorInfo['idvisitor']); $view->idsite = $idSite; $view->timeLimit = time() - 2 * 60 * 60; $view->isStaffOnline = ChatPiwikUser::isStaffOnline(); $view->siteUrl = ChatSite::getMainUrl($idSite); $view->lang = $visitorInfo['location_browser_lang']; return $view->render(); }