/** * Log an error * * @param string $errorMessage * @return boolean */ public static function log($errorMessage) { try { $writer = new LogWriterStream(ServiceLocatorService::getServiceLocator()->get('Config')['paths']['error_log']); $logger = new Logger(); $logger->addWriter($writer); $logger->err($errorMessage); // do we need send this error via email? if (null != ($errorEmail = SettingService::getSetting('application_errors_notification_email'))) { ApplicationEmailNotification::sendNotification($errorEmail, SettingService::getSetting('application_error_notification_title', LocalizationService::getDefaultLocalization()['language']), SettingService::getSetting('application_error_notification_message', LocalizationService::getDefaultLocalization()['language']), ['find' => ['ErrorDescription'], 'replace' => [$errorMessage]]); } } catch (Exception $e) { return false; } return true; }
/** * Get widget content * * @return string|boolean */ public function getContent() { if (UserIdentityService::isGuest() && (int) $this->getSetting('user_allow_register')) { // get an user form $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones())->showCaptcha(true); // validate the form if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $userForm->getFormName()) { // make certain to merge the files info! $post = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); // fill the form with received values $userForm->getForm()->setData($post, false); // save data if ($userForm->getForm()->isValid()) { // add a new user with a particular status $status = (int) $this->getSetting('user_auto_confirm') ? true : false; $userInfo = $this->getModel()->addUser($userForm->getForm()->getData(), LocalizationService::getCurrentLocalization()['language'], $status, $this->getRequest()->getFiles()->avatar, true); // the user has been added if (is_array($userInfo)) { // check the user status if (!$status) { // get user activate url if (false !== ($activateUrl = $this->getView()->pageUrl('user-activate', ['user_id' => $userInfo['user_id']]))) { // send an email activate notification EmailNotificationUtility::sendNotification($userInfo['email'], $this->getSetting('user_email_confirmation_title'), $this->getSetting('user_email_confirmation_message'), ['find' => ['RealName', 'SiteName', 'ConfirmationLink', 'ConfCode'], 'replace' => [$userInfo['nick_name'], $this->getSetting('application_site_name'), $this->getView()->url('page', ['page_name' => $activateUrl, 'slug' => $userInfo['slug']], ['force_canonical' => true]), $userInfo['activation_code']]], true); $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('We sent a message with a confirmation code to your registration e-mail')); } else { $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your profile will be activated after checking')); } $this->reloadPage(); } else { // login and redirect the registered user return $this->loginUser($userInfo['user_id'], $userInfo['nick_name'], false); } } else { $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred')); } return $this->reloadPage(); } } return $this->getView()->partial('user/widget/register', ['user_form' => $userForm->getForm()]); } return false; }
/** * Get widget content * * @return string|boolean */ public function getContent() { // get a contact form $contactForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('Page\\Form\\PageContact')->showCaptcha((int) $this->getWidgetSetting('page_contact_form_captcha') && UserIdentityService::isGuest()); if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $contactForm->getFormName()) { // fill form with received values $contactForm->getForm()->setData($this->getRequest()->getPost()); if ($contactForm->getForm()->isValid()) { $formData = $contactForm->getForm()->getData(); $sendResult = EmailNotificationUtility::sendNotification($this->getWidgetSetting('page_contact_form_email'), $this->getWidgetSetting('page_contact_form_title'), $this->getWidgetSetting('page_contact_form_message'), ['find' => ['RealName', 'Email', 'Phone', 'Message'], 'replace' => [$formData['name'], $formData['email'], $formData['phone'], $formData['message']]], true); // send the message if (true === $sendResult) { $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your message has been sent')); } else { $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Message cannot be sent. Please try again later')); } $this->reloadPage(); } } return $this->getView()->partial('page/widget/contact', ['contact_form' => $contactForm->getForm()]); }
/** * Log action * * @param integer $actionId * @param string $description * @param array $params * @return boolean|string */ public function logAction($actionId, $description, array $params = []) { try { $this->adapter->getDriver()->getConnection()->beginTransaction(); $insert = $this->insert()->into('action_tracker_log')->values(['action_id' => $actionId, 'description' => $description, 'description_params' => serialize($params), 'registered' => time()]); $statement = $this->prepareStatementForSqlObject($insert); $statement->execute(); $this->adapter->getDriver()->getConnection()->commit(); } catch (Exception $e) { $this->adapter->getDriver()->getConnection()->rollback(); ApplicationErrorLogger::log($e); return $e->getMessage(); } // send an email notification about add the adding new action if (SettingService::getSetting('action_tracker_send_actions')) { $defaultLocalization = LocalizationService::getDefaultLocalization(); $actionDescription = vsprintf($this->serviceLocator->get('Translator')->translate($description, 'default', $defaultLocalization['locale']), $params); EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('action_tracker_title', $defaultLocalization['language']), SettingService::getSetting('action_tracker_message', $defaultLocalization['language']), ['find' => ['Action', 'Date'], 'replace' => [$actionDescription, $this->serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke(time(), [], $defaultLocalization['language'])]]); } return true; }
/** * Send messages */ public function sendMessagesAction() { $request = $this->getRequest(); $sentMessages = 0; // get a list of messages from a messages queue if (null != ($messagesList = $this->getModel()->getMessages((int) $this->applicationSetting('application_notifications_count')))) { foreach ($messagesList as $messageInfo) { $result = ApplicationEmailNotification::immediatelySendNotification($messageInfo->email, $messageInfo->title, $messageInfo->message); if (true !== $result) { return $result; } // delete the message from the messages queue $sentMessages++; $this->getModel()->deleteMessage($messageInfo->id); } } $verbose = $request->getParam('verbose'); if (!$verbose) { return 'All messages have been sent.' . "\n"; } return $sentMessages . ' messages have been sent.' . "\n"; }
/** * Process action */ public function processAction() { // get the payment's type info if (null == ($payment = $this->getModel()->getPaymentTypeInfo($this->getSlug()))) { return $this->createHttpNotFoundModel($this->getResponse()); } // get the payment type instance $paymentInstance = $this->getServiceLocator()->get('Payment\\Type\\PaymentTypeManager')->getInstance($payment['handler']); // validate the payment if (false !== ($transactionInfo = $paymentInstance->validatePayment())) { if (true === ($result = $this->getModel()->activateTransaction($transactionInfo, $payment['id'], true, true))) { // send an email notification about the paid transaction if ((int) $this->applicationSetting('payment_transaction_paid_users')) { // get the user's info $userInfo = !empty($transactionInfo['user_id']) ? UserIdentityService::getUserInfo($transactionInfo['user_id']) : []; $notificationLanguage = !empty($userInfo['language']) ? $userInfo['language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($transactionInfo['email'], $this->applicationSetting('payment_transaction_paid_users_title', $notificationLanguage), $this->applicationSetting('payment_transaction_paid_users_message', $notificationLanguage), ['find' => ['Id', 'PaymentType'], 'replace' => [$transactionInfo['slug'], $this->getTranslator()->translate($payment['description'], 'default', LocalizationService::getLocalizations()[$notificationLanguage]['locale'])]]); } } } else { return $this->createHttpNotFoundModel($this->getResponse()); } return $this->getResponse(); }
/** * Fire activate payment transaction event * * @param integer $transactionId * @param boolean $isSystemEvent * @param array $transactionInfo * string first_name * string last_name * string email * string id * @return void */ public static function fireActivatePaymentTransactionEvent($transactionId, $isSystemEvent = false, $transactionInfo = []) { // event's description $eventDesc = $isSystemEvent ? 'Event - Payment transaction activated by the system' : (UserIdentityService::isGuest() ? 'Event - Payment transaction activated by guest' : 'Event - Payment transaction activated by user'); $eventDescParams = $isSystemEvent ? [$transactionId] : (UserIdentityService::isGuest() ? [$transactionId] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $transactionId]); self::fireEvent(self::ACTIVATE_PAYMENT_TRANSACTION, $transactionId, self::getUserId($isSystemEvent), $eventDesc, $eventDescParams); // send an email notification about the paid transaction if ($transactionInfo && (int) SettingService::getSetting('payment_transaction_paid')) { EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('payment_transaction_paid_title', LocalizationService::getDefaultLocalization()['language']), SettingService::getSetting('payment_transaction_paid_message', LocalizationService::getDefaultLocalization()['language']), ['find' => ['FirstName', 'LastName', 'Email', 'Id'], 'replace' => [$transactionInfo['first_name'], $transactionInfo['last_name'], $transactionInfo['email'], $transactionInfo['id']]]); } }
/** * Fire edit role event * * @param array $user * string language * string email * string nick_name * integer user_id * @param string $roleName * @param boolean $isSystemEvent * @retun void */ public static function fireEditRoleEvent($user, $roleName, $isSystemEvent = false) { // event's description $eventDesc = $isSystemEvent ? 'Event - User\'s role edited by the system' : (UserIdentityService::isGuest() ? 'Event - User\'s role edited by guest' : 'Event - User\'s role edited by user'); $eventDescParams = $isSystemEvent ? [$user['user_id']] : (UserIdentityService::isGuest() ? [$user['user_id']] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $user['user_id']]); self::fireEvent(self::EDIT_ROLE, $user['user_id'], self::getUserId($isSystemEvent), $eventDesc, $eventDescParams); // send a notification if ((int) SettingService::getSetting('user_role_edited_send')) { $notificationLanguage = $user['language'] ? $user['language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($user['email'], SettingService::getSetting('user_role_edited_title', $notificationLanguage), SettingService::getSetting('user_role_edited_message', $notificationLanguage), ['find' => ['RealName', 'Role'], 'replace' => [$user['nick_name'], ServiceLocatorService::getServiceLocator()->get('Translator')->translate($roleName, 'default', LocalizationService::getLocalizations()[$notificationLanguage]['locale'])]]); } }
/** * Clean expired memberships connections */ public function cleanExpiredMembershipsConnectionsAction() { $request = $this->getRequest(); $deletedConnections = 0; $notifiedConnections = 0; // get a list of expired memberships connections if (null != ($expiredConnections = $this->getModel()->getExpiredMembershipsConnections(self::ITEMS_LIMIT))) { // process expired memberships connections foreach ($expiredConnections as $connectionInfo) { // delete the connection if (false === ($deleteResult = $this->getModel()->deleteMembershipConnection($connectionInfo['id']))) { break; } // get a next membership connection $nextConnection = $this->getModel()->getMembershipConnectionFromQueue($connectionInfo['user_id']); $nextRoleId = $nextConnection ? $nextConnection['role_id'] : AclBaseModel::DEFAULT_ROLE_MEMBER; $nextRoleName = $nextConnection ? $nextConnection['role_name'] : AclBaseModel::DEFAULT_ROLE_MEMBER_NAME; // change the user's role if (true === ($result = $this->getUserModel()->editUserRole($connectionInfo['user_id'], $nextRoleId, $nextRoleName, $connectionInfo, true))) { // activate the next membership connection if ($nextConnection) { $this->getModel()->activateMembershipConnection($nextConnection['id']); } } $deletedConnections++; } } // get list of not notified memberships connections if ((int) $this->applicationSetting('membership_expiring_send')) { if (null != ($notNotifiedConnections = $this->getModel()->getNotNotifiedMembershipsConnections(self::ITEMS_LIMIT))) { // process not notified memberships connections foreach ($notNotifiedConnections as $connectionInfo) { if (false === ($markResult = $this->getModel()->markConnectionAsNotified($connectionInfo['id']))) { break; } // send a notification about membership expiring $notificationLanguage = $connectionInfo['language'] ? $connectionInfo['language'] : LocalizationService::getDefaultLocalization()['language']; $locale = LocalizationService::getLocalizations()[$notificationLanguage]['locale']; ApplicationEmailNotification::sendNotification($connectionInfo['email'], $this->applicationSetting('membership_expiring_send_title', $notificationLanguage), $this->applicationSetting('membership_expiring_send_message', $notificationLanguage), ['find' => ['RealName', 'Role', 'ExpireDate'], 'replace' => [$connectionInfo['nick_name'], ApplicationServiceLocatorService::getServiceLocator()->get('Translator')->translate($connectionInfo['role_name'], 'default', $locale), ApplicationServiceLocatorService::getServiceLocator()->get('viewhelpermanager')->get('applicationDate')->__invoke($connectionInfo['expire_date'], [], $locale)]]); $notifiedConnections++; } } } // delete not active empty connections $this->getModel()->deleteNotActiveEmptyConnections(); $verbose = $request->getParam('verbose'); if (!$verbose) { return 'All expired membership connections have been deleted.' . "\n"; } $result = $deletedConnections . ' membership connections have been deleted.' . "\n"; $result .= $notifiedConnections . ' membership connections have been notified.' . "\n"; return $result; }
/** * Fire add comment event * * @param string $pageUrl * @param array $commentInfo * integer id * string comment * string name * string email * string registered_nickname * string registered_email * string registered_language * integer created * integer active * integer hidden * @param array $parentComment * integer id * string comment * string name * string email * string registered_nickname * string registered_email * string registered_language * integer created * integer active * integer hidden * @return void */ public static function fireAddCommentEvent($pageUrl, array $commentInfo, $parentComment = null) { // event's description $eventDesc = UserIdentityService::isGuest() ? 'Event - Comment added by guest' : 'Event - Comment added by user'; $eventDescParams = UserIdentityService::isGuest() ? [$commentInfo['id']] : [UserIdentityService::getCurrentUserIdentity()['nick_name'], $commentInfo['id']]; self::fireEvent(self::ADD_COMMENT, $commentInfo['id'], UserIdentityService::getCurrentUserIdentity()['user_id'], $eventDesc, $eventDescParams); $serviceLocator = ServiceLocatorService::getServiceLocator(); // send an email notification about add the new comment if (SettingService::getSetting('comment_added_send')) { $defaultLocalization = LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification(SettingService::getSetting('application_site_email'), SettingService::getSetting('comment_added_title', $defaultLocalization), SettingService::getSetting('comment_added_message', $defaultLocalization), ['find' => ['PosterName', 'PosterEmail', 'CommentUrl', 'CommentId', 'Comment', 'Date'], 'replace' => [!empty($commentInfo['registered_nickname']) ? $commentInfo['registered_nickname'] : $commentInfo['name'], !empty($commentInfo['registered_email']) ? $commentInfo['registered_email'] : $commentInfo['email'], $pageUrl, $commentInfo['id'], $commentInfo['comment'], $serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke($commentInfo['created'], [], $defaultLocalization)]]); } // send a email notification about the new reply if ($parentComment && SettingService::getSetting('comment_reply_send')) { // don't send reply notifications if comments owners are equal if ($commentInfo['user_id'] != $parentComment['user_id'] || $commentInfo['email'] != $parentComment['email']) { // get notification language $notificationLanguage = $parentComment['registered_language'] ? $parentComment['registered_language'] : LocalizationService::getDefaultLocalization()['language']; EmailNotificationUtility::sendNotification($parentComment['registered_email'] ? $parentComment['registered_email'] : $parentComment['email'], SettingService::getSetting('comment_reply_title', $notificationLanguage), SettingService::getSetting('comment_reply_message', $notificationLanguage), ['find' => ['PosterName', 'PosterEmail', 'Comment', 'ReplyUrl', 'ReplyId', 'Reply', 'Date'], 'replace' => [!empty($commentInfo['registered_nickname']) ? $commentInfo['registered_nickname'] : $commentInfo['name'], !empty($commentInfo['registered_email']) ? $commentInfo['registered_email'] : $commentInfo['email'], $parentComment['comment'], $pageUrl, $commentInfo['id'], $commentInfo['comment'], $serviceLocator->get('viewHelperManager')->get('applicationDate')->__invoke($commentInfo['created'], [], $notificationLanguage)]]); } } }