Exemple #1
0
 public function __construct()
 {
     parent::__construct();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_rsmembership/tables');
     $document = JFactory::getDocument();
     $config = RSMembershipConfig::getInstance();
     $version = (string) new RSMembershipVersion();
     // Load our CSS
     $document->addStyleSheet(JUri::root(true) . '/components/com_rsmembership/assets/css/rsmembership.css?v=' . $version);
     // Load our JS
     $document->addScript(JUri::root(true) . '/components/com_rsmembership/assets/js/rsmembership.js?v=' . $version);
     if (!RSMembershipHelper::isJ3()) {
         // Load 2.5 CSS
         $document->addStyleSheet(JUri::root(true) . '/components/com_rsmembership/assets/css/j2.css?v=' . $version);
         // Load Bootstrap on 2.5.x
         if ($config->get('load_bootstrap')) {
             $document->addStyleSheet(JUri::root(true) . '/components/com_rsmembership/assets/css/bootstrap.min.css?v=' . $version);
             $document->addScript(JUri::root(true) . '/components/com_rsmembership/assets/js/jquery.min.js?v=' . $version);
             $document->addScript(JUri::root(true) . '/components/com_rsmembership/assets/js/jquery.noconflict.js?v=' . $version);
             $document->addScript(JUri::root(true) . '/components/com_rsmembership/assets/js/bootstrap.min.js?v=' . $version);
         }
     } else {
         // Load 3.x CSS
         $document->addStyleSheet(JUri::root(true) . '/components/com_rsmembership/assets/css/j3.css?v=' . $version);
         // Load Bootstrap on 3.x
         if ($config->get('load_bootstrap')) {
             JHtml::_('bootstrap.framework');
         }
     }
 }
Exemple #2
0
 public static function getConfig($name = null, $default = false)
 {
     $config = RSMembershipConfig::getInstance();
     if (is_null($name)) {
         return $config->getData();
     } else {
         return $config->get($name, $default);
     }
 }
Exemple #3
0
 protected function sendExpirationEmails()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $date = JFactory::getDate();
     $config = RSMembershipConfig::getInstance();
     // Check the last time this has been run
     $now = $date->toUnix();
     if ($now < $config->get('expire_last_run') + $config->get('expire_check_in') * 60) {
         return;
     }
     // update config value for last time the expiration emails were sent
     $config->set('expire_last_run', $now);
     // Get expiration intervals and memberships
     // Performance check - if no emails can be sent, no need to grab the membership
     $query->select('*')->from($db->qn('#__rsmembership_memberships'))->where('(' . $db->qn('user_email_from_addr') . ' != ' . $db->q('') . ' OR ' . $db->qn('user_email_use_global') . ' = ' . $db->q(1) . ')')->where($db->qn('published') . ' = ' . $db->q(1));
     $db->setQuery($query);
     $memberships = $db->loadObjectList();
     if ($memberships) {
         RSMembership::sendNotifications($memberships, null, false);
     }
 }
Exemple #4
0
 public function idevCheckConnection()
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $idev_url = JFactory::getApplication()->input->get('idev_url', '', 'string');
     if (!empty($idev_url)) {
         if (strlen($idev_url) > 5) {
             $idev_url = rtrim($idev_url, '/');
             $idev_url .= '/';
         }
         $config = RSMembershipConfig::getInstance();
         $config->set('idev_url', $idev_url);
     }
     $result = RSMembership::updateIdev(array('idev_saleamt' => 1.0, 'idev_ordernum' => 'test', 'ip_address' => '127.0.0.1'));
     if (!$result['success']) {
         JError::raiseWarning(500, JText::sprintf('COM_RSMEMBERSHIP_IDEV_COULD_NOT_CONNECT', $result['url'], !empty($result['error']) ? $result['error'] : JText::_('COM_RSMEMBERSHIP_UNKNOWN'), $result['code']));
         return false;
     }
     return true;
 }
Exemple #5
0
 public static function sendNotifications($memberships, $cid = null, $resend = false)
 {
     // Get custom fields
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $date = JFactory::getDate();
     $fields = RSMembership::getCustomFields();
     $config = RSMembershipConfig::getInstance();
     $update_ids = array();
     foreach ($memberships as $membership) {
         $date = JFactory::getDate();
         $interval = $membership->expire_notify_interval;
         $date->modify("+{$interval} days");
         // Select all the subscriptions that match (about to expire)
         $query->clear();
         $query->select($db->qn('u.id', 'user_id'))->select($db->qn('u.email', 'user_email'))->select($db->qn('u.name', 'user_name'))->select($db->qn('u.username', 'user_username'))->select($db->qn('mu.id', 'muid'))->select($db->qn('mu.extras'))->select($db->qn('mu.membership_end'))->select($db->qn('mu.from_transaction_id'))->from($db->qn('#__rsmembership_membership_subscribers', 'mu'))->join('left', $db->qn('#__users', 'u') . ' ON ' . $db->qn('mu.user_id') . ' = ' . $db->qn('u.id'))->where($db->qn('mu.status') . ' = ' . $db->q(MEMBERSHIP_STATUS_ACTIVE))->where($db->qn('mu.published') . ' = ' . $db->q(1));
         if (!$resend) {
             $query->where($db->qn('mu.notified') . ' = ' . $db->q($db->getNullDate()));
         }
         $query->where($db->qn('mu.membership_end') . ' != ' . $db->q($db->getNulldate()))->where($db->qn('mu.membership_end') . ' < ' . $db->q($date->toSql()))->where($db->qn('mu.membership_id') . ' = ' . $db->q($membership->id));
         if ($cid != null && is_array($cid) && count($cid) > 0) {
             $ids = implode($db->q(','), $cid);
             $query->where($db->qn('mu.id') . ' IN (' . $ids . ')');
         }
         $db->setQuery($query, 0, $config->get('expire_emails'));
         $results = $db->loadObjectList();
         // No results, next membership
         if (empty($results)) {
             continue;
         }
         $now = JFactory::getDate()->toUnix();
         $sentToUser = false;
         $sentToAdmin = false;
         foreach ($results as $result) {
             $extras = '';
             // Performance check
             if ($result->extras && (strpos($membership->user_email_expire_text . $membership->user_email_expire_subject, '{extras}') !== false || strpos($membership->admin_email_expire_text . $membership->admin_email_expire_subject, '{extras}') !== false)) {
                 $extras = RSMembershipHelper::getExtrasNames($result->extras);
             }
             $expireDate = JFactory::getDate($result->membership_end);
             $expireIn = ceil(($expireDate->toUnix() - $now) / 86400);
             $placeholders = array('{membership}' => $membership->name, '{membership_end}' => RSMembershipHelper::showDate($result->membership_end), '{extras}' => $extras, '{email}' => $result->user_email, '{name}' => $result->user_name, '{username}' => $result->user_username, '{interval}' => $expireIn);
             $replace = array_keys($placeholders);
             $with = array_values($placeholders);
             $query->clear();
             $query->select('*')->from($db->qn('#__rsmembership_subscribers'))->where($db->qn('user_id') . ' = ' . $db->q($result->user_id));
             $db->setQuery($query);
             $user_data_tmp = $db->loadObject();
             $user_data = array();
             foreach ($fields as $field) {
                 $field_id = 'f' . $field->id;
                 $user_data[$field->name] = isset($user_data_tmp->{$field_id}) ? $user_data_tmp->{$field_id} : '';
             }
             unset($user_data_tmp);
             foreach ($fields as $field) {
                 $name = $field->name;
                 $replace[] = '{' . $name . '}';
                 if (isset($user_data[$name])) {
                     $with[] = is_array($user_data[$name]) ? implode("\n", $user_data[$name]) : $user_data[$name];
                 } else {
                     $with[] = '';
                 }
             }
             $membership_fields = RSMembership::getCustomMembershipFields($membership->id);
             $transaction_user_data = RSMembership::getUserData($result->from_transaction_id);
             foreach ($membership_fields as $field) {
                 $name = $field->name;
                 $replace[] = '{' . $name . '}';
                 if (isset($transaction_user_data->membership_fields[$name])) {
                     $with[] = is_array($transaction_user_data->membership_fields[$name]) ? implode("\n", $transaction_user_data->membership_fields[$name]) : $transaction_user_data->membership_fields[$name];
                 } else {
                     $with[] = '';
                 }
             }
             $jconfig = JFactory::getConfig();
             if ($membership->user_email_expire_subject) {
                 $message = str_replace($replace, $with, $membership->user_email_expire_text);
                 // from address
                 $from = $membership->user_email_use_global ? $jconfig->get('mailfrom') : $membership->user_email_from_addr;
                 // from name
                 $fromName = $membership->user_email_use_global ? $jconfig->get('fromname') : $membership->user_email_from;
                 // recipient
                 $recipient = $result->user_email;
                 // user email
                 // subject
                 $subject = str_replace($replace, $with, $membership->user_email_expire_subject);
                 // body
                 $body = $message;
                 // mode
                 $mode = $membership->user_email_mode;
                 // cc
                 $cc = null;
                 // bcc
                 $bcc = null;
                 // attachments
                 $query->clear();
                 $query->select($db->qn('path'))->from($db->qn('#__rsmembership_membership_attachments'))->where($db->qn('membership_id') . ' = ' . $db->q($membership->id))->where($db->qn('email_type') . ' = ' . $db->q('user_email_expire'))->where($db->qn('published') . '=' . $db->q('1'))->order($db->qn('ordering') . ' ASC');
                 $db->setQuery($query);
                 $attachment = $db->loadColumn();
                 // reply to
                 $replyto = $from;
                 // reply to name
                 $replytoname = $fromName;
                 // send to user
                 RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
                 $sentToUser = true;
                 self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Email sent to {$recipient} (Subject: {$subject})");
             }
             // admin emails
             if ($membership->admin_email_expire_subject) {
                 $message = str_replace($replace, $with, $membership->admin_email_expire_text);
                 // from address
                 $from = trim($membership->admin_email_from_addr) != '' ? $membership->admin_email_from_addr : $result->user_email;
                 // from name
                 $fromName = $result->user_name;
                 // recipient
                 $recipient = $membership->admin_email_to_addr;
                 // subject
                 $subject = str_replace($replace, $with, $membership->admin_email_expire_subject);
                 // body
                 $body = $message;
                 // mode
                 $mode = $membership->admin_email_mode;
                 // cc
                 $cc = null;
                 // bcc
                 $bcc = null;
                 // attachments
                 $attachment = null;
                 // reply to
                 $replyto = $from;
                 // reply to name
                 $replytoname = $fromName;
                 // send to admin
                 if ($subject != '') {
                     RSMembershipHelper::sendMail($from, $fromName, $recipient, $subject, $body, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
                     $sentToAdmin = true;
                     self::syslog('expiry-notification', "Membership: " . $membership->name . " (" . $membership->id . ") | Admin email sent to {$recipient} (Subject: {$subject})");
                 }
             }
             if ($sentToUser || $sentToAdmin) {
                 $update_ids[] = $result->muid;
             }
         }
     }
     if (!empty($update_ids)) {
         $query->clear();
         $query->update($db->qn('#__rsmembership_membership_subscribers'))->set($db->qn('notified') . ' = ' . $db->q($date->toSql()))->where($db->qn('id') . ' IN (\'' . implode($db->q(','), $update_ids) . '\')');
         $db->setQuery($query);
         $db->execute();
         return true;
     } else {
         return false;
     }
 }