/** * Run when a membership expiried die * @param PlanOsMembership $row */ function onMembershipExpire($row) { if ($row->user_id) { $user = JFactory::getUser($row->user_id); $currentGroups = $user->get('groups'); $plan = JTable::getInstance('Osmembership', 'Plan'); $plan->load($row->plan_id); $params = new JRegistry($plan->params); $groups = explode(',', $params->get('joomla_expried_group_ids')); $subscriptionExpiredGroupIds = explode(',', $params->get('subscription_expired_joomla_group_ids')); $activePlans = OSMembershipHelper::getActiveMembershipPlans($row->user_id, array($row->id)); // Subscribers will be assigned to this group if he has no more active subscription of this plan, haven't renewed yet if (!in_array($row->plan_id, $activePlans)) { $currentGroups = array_merge($currentGroups, $subscriptionExpiredGroupIds); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('params')->from('#__osmembership_plans')->where('id IN (' . implode(',', $activePlans) . ')'); $db->setQuery($query); $rowPlans = $db->loadObjectList(); if (count($rowPlans)) { foreach ($rowPlans as $rowPlan) { $planParams = new JRegistry($rowPlan->params); $planGroups = explode(',', $planParams->get('joomla_group_ids')); $groups = array_diff($groups, $planGroups); } } $currentGroups = array_unique(array_diff($currentGroups, $groups)); $user->set('groups', $currentGroups); $user->save(true); } }
function processRestriction($matches) { $document = JFactory::getDocument(); $styleUrl = JURI::base(true) . '/components/com_osmembership/assets/css/style.css'; $document->addStylesheet($styleUrl, 'text/css', null, null); require_once JPATH_ROOT . '/components/com_osmembership/helper/helper.php'; $message = OSMembershipHelper::getMessages(); $fieldSuffix = OSMembershipHelper::getFieldSuffix(); if (strlen($message->{'content_restricted_message' . $fieldSuffix})) { $restrictedText = $message->{'content_restricted_message' . $fieldSuffix}; } else { $restrictedText = $message->content_restricted_message; } $requiredPlanIds = $matches[1]; $protectedText = $matches[2]; $activePlanIds = OSMembershipHelper::getActiveMembershipPlans(); if (count($activePlanIds) == 1 && $activePlanIds[0] == 0) { return '<div id="restricted_info">' . $restrictedText . '</div>'; } elseif ($requiredPlanIds == '*') { return $protectedText; } else { $requiredPlanIds = explode(',', $requiredPlanIds); if (count(array_intersect($requiredPlanIds, $activePlanIds))) { return $protectedText; } else { return '<div id="restricted_info">' . $restrictedText . '</div>'; } } }
function onAfterInitialise() { $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } if (JPluginHelper::isEnabled('osmembership', 'urls')) { $db = JFactory::getDbo(); $currentUrl = trim(JUri::getInstance()->toString()); //remove www in the url $currentUrl = str_replace('www.', '', $currentUrl); $siteURL = JURI::root(); $siteURL = str_replace('www.', '', $siteURL); if ($siteURL == $currentUrl) { //Dont' prevent access to homepage return; } $sql = 'SELECT DISTINCT plan_id FROM #__osmembership_urls WHERE url = "' . $currentUrl . '"'; $db->setQuery($sql); $planIds = $db->loadColumn(); if (count($planIds)) { //Check to see the current user has an active subscription plans require_once JPATH_ROOT . '/components/com_osmembership/helper/helper.php'; $activePlans = OSMembershipHelper::getActiveMembershipPlans(); if (!count(array_intersect($planIds, $activePlans))) { //Load language file OSMembershipHelper::loadLanguage(); //Get title of these subscription plans $sql = 'SELECT title FROM #__osmembership_plans WHERE id IN (' . implode(',', $planIds) . ') AND published=1 ORDER BY ordering'; $db->setQuery($sql); $planTitles = $db->loadColumn(); $planTitles = implode(' OR ', $planTitles); $msg = JText::_('OS_MEMBERSHIP_URL_ACCESS_RESITRICTED'); $msg = str_replace('[PLAN_TITLES]', $planTitles, $msg); $redirectUrl = $this->params->get('redirect_url', OSMembershipHelper::getViewUrl(array('categories', 'plans', 'plan', 'register'))); if (!$redirectUrl) { $redirectUrl = JUri::root(); } JFactory::getApplication()->redirect($redirectUrl, $msg); } } } }
function onAfterRoute() { $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } $user = JFactory::getUser(); if ($user->authorise('core.admin')) { return true; } $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); if ($option != 'com_content' || $view != 'article') { return true; } require_once JPATH_ROOT . '/components/com_osmembership/helper/helper.php'; OSMembershipHelper::loadLanguage(); $db = JFactory::getDbo(); $articleId = JRequest::getInt('id'); $sql = 'SELECT DISTINCT plan_id FROM #__osmembership_articles WHERE article_id = ' . $articleId; $db->setQuery($sql); $planIds = $db->loadColumn(); if (count($planIds)) { //Check to see the current user has an active subscription plans require_once JPATH_ROOT . '/components/com_osmembership/helper/helper.php'; $activePlans = OSMembershipHelper::getActiveMembershipPlans(); if (!count(array_intersect($planIds, $activePlans))) { //Get title of these subscription plans $sql = 'SELECT title FROM #__osmembership_plans WHERE id IN (' . implode(',', $planIds) . ') AND published=1 ORDER BY ordering'; $db->setQuery($sql); $planTitles = $db->loadColumn(); $planTitles = implode(' OR ', $planTitles); $msg = JText::_('OS_MEMBERSHIP_ARTICLE_ACCESS_RESITRICTED'); $msg = str_replace('[PLAN_TITLES]', $planTitles, $msg); $redirectUrl = $this->params->get('redirect_url', OSMembershipHelper::getViewUrl(array('categories', 'plans', 'plan', 'register'))); if (!$redirectUrl) { $redirectUrl = JUri::root(); } JFactory::getApplication()->redirect($redirectUrl, $msg); } } }
/** * Method to block the CB account when the subscription record is expired * * @param SubscriberOSMembership $row The subscription record */ function onMembershipExpire($row) { if (!$this->canRun) { return; } $blockUser = $this->params->get('block_user_on_membership_expire', 0); if ($row->user_id && $blockUser) { $activePlanIds = OSMembershipHelper::getActiveMembershipPlans($row->user_id); if (count($activePlanIds) == 2 && $activePlanIds[1] == $row->plan_id) { $this->setCBAuth($row->user_id, 0); } } }