public function getAdminEmails(&$emails = array()) { $db = EasyBlogHelper::db(); $query = 'SELECT ' . $db->nameQuote('name') . ', ' . $db->nameQuote('email'); $query .= ' FROM ' . $db->nameQuote('#__users'); $emptyUserId = false; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $saUsersIds = EasyBlogHelper::getSAUsersIds(); if (!$saUsersIds) { $emptyUserId = true; } $query .= ' WHERE id IN (' . implode(',', $saUsersIds) . ')'; } else { $query .= ' WHERE LOWER( ' . $db->nameQuote('usertype') . ' ) = ' . $db->Quote('super administrator'); } $query .= ' AND `sendEmail` = ' . $db->Quote('1'); if (!$emptyUserId) { $db->setQuery($query); $result = $db->loadObjectList(); } else { $result = ""; } if (!$result) { return; } foreach ($result as $row) { $obj = new StdClass(); $obj->unsubscribe = false; $obj->email = $row->email; $emails[$row->email] = $obj; } }
function getMembersAndSubscribers() { $db = EasyBlogHelper::db(); // do not get superadmin users. $query = "(select `id`, `id` as `user_id`, `name` as `fullname`, `email`, now() as `created`, 'member' as `type` from `#__users`"; $query .= " where `block` = 0"; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $saUsersIds = EasyBlogHelper::getSAUsersIds(); $query .= " and `id` NOT IN (" . implode(',', $saUsersIds) . ")"; } else { $query .= " and LOWER( `usertype` ) != " . $db->Quote('super administrator'); } $query .= ")"; $query .= " union "; $query .= "(select `id`, `user_id`, `fullname`, `email`, `created` , 'bloggersubscription' as `type` from `#__easyblog_blogger_subscription` where `user_id` = 0)"; $query .= " union "; $query .= "(select `id`, `user_id`, `fullname`, `email`, `created` , 'categorysubscription' as `type` from `#__easyblog_category_subscription` where `user_id` = 0)"; $query .= " union "; $query .= "(select `id`, `user_id`, `fullname`, `email`, `created` , 'teamsubscription' as `type` from `#__easyblog_team_subscription` where `user_id` = 0)"; $query .= " union "; $query .= "(select `id`, `user_id`, `fullname`, `email`, `created` , 'sitesubscription' as `type` from `#__easyblog_site_subscription` where `user_id` = 0)"; $db->setQuery($query); $result = $db->loadObjectList(); return $result; }
public static function getDefaultSAIds() { $saUserId = '62'; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $saUsers = EasyBlogHelper::getSAUsersIds(); $saUserId = $saUsers[0]; } return $saUserId; }
function getMembersAndSubscribers() { $db = EB::db(); $saUsersIds = EasyBlogHelper::getSAUsersIds(); $query = "(select `id`, `id` as `user_id`, `name` as `fullname`, `email`, now() as `created`, 'member' as `type` from `#__users`"; $query .= " where `block` = 0"; // do not get superadmin users. if ($saUsersIds) { $query .= " and `id` NOT IN (" . implode(',', $saUsersIds) . ")"; } $query .= ")"; $query .= " union "; $query .= '(select `id`, `user_id`, `fullname`, `email`, `created`,'; $query .= ' (case'; $query .= ' when `utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_SITE) . ' then ' . $db->Quote('sitesubscription'); $query .= ' when `utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_BLOGGER) . ' then ' . $db->Quote('bloggersubscription'); $query .= ' when `utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_CATEGORY) . ' then ' . $db->Quote('categorysubscription'); $query .= ' when `utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_TEAMBLOG) . ' then ' . $db->Quote('teamsubscription'); $query .= ' when `utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_ENTRY) . ' then ' . $db->Quote('subscription'); $query .= ' end) as `type` from ' . $db->qn('#__easyblog_subscriptions'); $query .= ' where `user_id` = 0)'; $db->setQuery($query); $result = $db->loadObjectList(); return $result; }
function _getSAUserId() { $saUserId = '62'; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $saUsers = EasyBlogHelper::getSAUsersIds(); $saUserId = '42'; if (count($saUsers) > 0) { $saUserId = $saUsers['0']; } } return $saUserId; }
function _verifyOnwerShip($newOwnerShip) { $db = JFactory::getDBO(); $query = 'SELECT `id` FROM `#__users` WHERE `id` = ' . $db->Quote($newOwnerShip); $db->setQuery($query); $result = $db->loadResult(); if (empty($result)) { if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $saUsersId = EasyBlogHelper::getSAUsersIds(); $result = $saUsersId[0]; } else { $result = $this->_getSuperAdminId(); } } return $result; }
function _removeUser16($id) { // @task: Check for acl rules. $this->checkAccess('user'); $db = EasyBlogHelper::db(); $currentUser = JFactory::getUser(); $user = JFactory::getUser($id); $isUserSA = $user->authorise('core.admin'); if ($isUserSA) { $msg = JText::_('You cannot delete a Super Administrator'); } else { if ($id == $currentUser->get('id')) { $msg = JText::_('You cannot delete Yourself!'); } else { $count = 2; if ($isUserSA) { $saUsers = EasyBlogHelper::getSAUsersIds(); $count = count($saUsers); } if ($count <= 1 && $isUserSA) { // cannot delete Super Admin where it is the only one that exists $msg = "You cannot delete this Super Administrator as it is the only active Super Administrator for your site"; } else { // delete user $user->delete(); $msg = JText::_('User Deleted.'); JRequest::setVar('task', 'remove'); JRequest::setVar('cid', $id); // delete user acounts active sessions $this->logout(); $success = true; } } } $result['success'] = $success; $result['msg'] = $msg; return $result; }
/** * Send to a list of subscribers on the site * * @since 5.0 * @access public * @param string * @return */ public function sendSubscribers($emailTitle, $template, $data, EasyBlogPost $post, $ignoreEmails = array()) { $db = EB::db(); $config = EB::config(); $app = JFactory::getApplication(); $jConfig = EB::getJConfig(); $defaultEmailFrom = $jConfig->get('mailfrom'); $defaultFromName = $jConfig->get('fromname'); $fromEmail = $config->get('notification_from_email', $defaultEmailFrom); $fromName = $config->get('notification_from_name', $defaultFromName); // Override the from email address if necessary if (empty($fromEmail)) { $fromEmail = $defaultEmailFrom; } // Override the from name if necessary if (empty($fromName)) { $fromName = $defaultFromName; } // Check if this is to notify team subscribers $model = EB::model('TeamBlogs'); $contribution = $model->getBlogContributed($post->id); if ($contribution) { $team = EB::table('TeamBlog'); $team->load($contribution->team_id); $contribution->access = $team->access; } else { $contribution = new stdClass(); $contribution->access = EBLOG_TEAMBLOG_ACCESS_EVERYONE; } $jsonData = json_encode($data); $insertQuery = array(); $insertDate = EB::date()->toMySQL(); $mainQuery = ''; $queryHeader = 'insert into `#__easyblog_mailq` (`mailfrom`,`fromname`,`recipient`,`subject`,`created`,`status`,`template`,`data`,`param`) '; if (!$post->send_notification_emails) { return; } $query = ''; // When the post is posted into a team, send it to the team if ($contribution && $config->get('notification_teamsubscriber') && isset($contribution->team_id)) { // teamblog subscribers $query .= 'select a.`email`'; $query .= ' FROM `#__easyblog_subscriptions` as a'; $query .= ' WHERE a.`uid` = ' . $db->Quote($contribution->team_id); $query .= ' AND a.`utype` = ' . $db->Quote(EBLOG_SUBSCRIPTION_TEAMBLOG); // teamblog members $query .= ' UNION '; $query .= 'select a1.`email`'; $query .= ' from `#__users` as a1 inner join `#__easyblog_team_users` as b1 on a1.`id` = b1.`user_id`'; $query .= ' where b1.`team_id` = ' . $db->Quote($contribution->team_id); } // @task: Only send emails to these group of users provided that, it is not a team posting or private team posting. if (!$contribution || $contribution->access != EBLOG_TEAMBLOG_ACCESS_MEMBER) { // @rule: Get all email addresses for the whole site. if ($config->get('notification_allmembers')) { // all superadmins user id $saUsersIds = EasyBlogHelper::getSAUsersIds(); $query .= 'select a.`email` from `#__users` as a'; $query .= ' where a.`block` = 0'; $query .= ' and a.`id` NOT IN (' . implode(',', $saUsersIds) . ')'; // guest subscribers $query .= ' UNION '; $query .= 'select a1.`email` FROM `#__easyblog_subscriptions` as a1'; $query .= ' WHERE a1.`user_id` = ' . $db->Quote('0'); } else { if ($config->get('notification_blogsubscriber') || $config->get('notification_categorysubscriber') || $config->get('notification_sitesubscriber')) { $command = array(); if ($config->get('notification_blogsubscriber')) { $command[] = '(' . $db->qn('a.uid') . ' = ' . $db->Quote($post->created_by) . ' and ' . $db->qn('a.utype') . ' = ' . $db->Quote(EBLOG_SUBSCRIPTION_BLOGGER) . ')'; } if ($config->get('notification_categorysubscriber')) { $command[] = '(' . $db->qn('a.uid') . ' IN (select ' . $db->qn('pc.category_id') . ' from ' . $db->qn('#__easyblog_post_category') . ' as pc where ' . $db->qn('pc.post_id') . ' = ' . $db->Quote($post->id) . ') and ' . $db->qn('a.utype') . ' = ' . $db->Quote(EBLOG_SUBSCRIPTION_CATEGORY) . ')'; } if ($config->get('notification_sitesubscriber')) { $command[] = '(' . $db->qn('a.uid') . ' = ' . $db->Quote('0') . ' and ' . $db->qn('a.utype') . ' = ' . $db->Quote(EBLOG_SUBSCRIPTION_SITE) . ')'; } $query = 'select ' . $db->qn('a.email'); $query .= ' from ' . $db->qn('#__easyblog_subscriptions') . ' as a'; $query .= ' where 1 = 1'; $query .= ' and ('; $query .= implode(' OR ', $command); $query .= ')'; } } } if ($query) { $mainQuery = $queryHeader; $mainQuery .= 'SELECT ' . $db->Quote($fromEmail) . ' as `mailfrom`,' . $db->Quote($fromName) . ' as `fromname`, x.`email` as `recipient`,'; $mainQuery .= $db->Quote($emailTitle) . ' as `subject`,' . $db->Quote($insertDate) . ' as `created`, 0 as `status`, ' . $db->Quote($template) . ' as `template`'; $mainQuery .= ', ' . $db->Quote($jsonData) . ' as `data`'; $mainQuery .= ', concat(\'{"email":"\', x.email, \'","unsubscribe":"1"}\') as `param`'; $mainQuery .= ' FROM (' . $query . ') as x'; // exclude these emails if there are any if ($ignoreEmails) { $tmpQuery = ''; if (count($ignoreEmails) == 1) { $tmpQuery = ' where x.email != ' . $db->Quote($ignoreEmails[0]); } else { $emails = ''; foreach ($ignoreEmails as $ignore) { $emails .= $emails ? $db->Quote($ignore) : ',' . $db->Quote($ignore); } $tmpQuery = ' where x.email NOT IN (' . $emails . ')'; } $mainQuery .= $tmpQuery; } // insert records into mailq here. $db->setQuery($mainQuery); $db->query(); } return true; }
private function sendMail(&$user, $password) { $mainframe = JFactory::getApplication(); $db = EasyBlogHelper::db(); $name = $user->get('name'); $email = $user->get('email'); $username = $user->get('username'); $usersConfig = JComponentHelper::getParams('com_users'); $sitename = $mainframe->getCfg('sitename'); $useractivation = $usersConfig->get('useractivation'); $mailfrom = $mainframe->getCfg('mailfrom'); $fromname = $mainframe->getCfg('fromname'); $siteURL = JURI::base(); $subject = JText::sprintf('COM_EASYBLOG_REGISTER_MAIL_ACCOUNT_DETAILS', $name, $sitename); $subject = html_entity_decode($subject, ENT_QUOTES); if ($useractivation == 1) { $task = ''; $key = ''; if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $task = 'registration.activate'; $key = 'token'; } else { $task = 'activate'; $key = 'activation'; } $message = sprintf(JText::_('COM_EASYBLOG_REGISTER_MAIL_ACTIVATE'), $name, $sitename, $siteURL . "index.php?option=com_users&task=" . $task . "&" . $key . "=" . $user->get('activation'), $siteURL, $username, $password); } else { $message = sprintf(JText::_('COM_EASYBLOG_REGISTER_MAIL'), $name, $sitename, $siteURL, $username, $password); } $message = html_entity_decode($message, ENT_QUOTES); $ids = EasyBlogHelper::getSAUsersIds(); $rows = array(); foreach ($ids as $id) { $row = new stdClass(); $user = JFactory::getUser($id); $row->name = $user->name; $row->email = $user->email; $row->sendEmail = $user->sendEmail; $rows[] = $row; } // Send email to user if (!$mailfrom || !$fromname) { $fromname = $rows[0]->name; $mailfrom = $rows[0]->email; } if (EasyBlogHelper::getJoomlaVersion() >= '3.0') { $mail = JMail::getInstance(); $mail->sendMail($mailfrom, $fromname, $email, $subject, $message, true); } else { JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message); } // Send notification to all administrators $subject2 = sprintf(JText::_('Account details for'), $name, $sitename); $subject2 = html_entity_decode($subject2, ENT_QUOTES); // get superadministrators id foreach ($rows as $row) { if ($row->sendEmail) { $message2 = sprintf(JText::_('COM_EASYBLOG_REGISTER_MAIL_ADMIN'), $row->name, $sitename, $name, $email, $username); $message2 = html_entity_decode($message2, ENT_QUOTES); if (EasyBlogHelper::getJoomlaVersion() >= '3.0') { $mail = JMail::getInstance(); $mail->sendMail($mailfrom, $fromname, $row->email, $subject2, $message2, true); } else { JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2); } } } }