Exemplo n.º 1
0
 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);
             }
         }
     }
 }
Exemplo n.º 2
0
 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);
         }
     }
 }
Exemplo n.º 3
0
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2012 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */
defined('_JEXEC') or die;
error_reporting(0);
if (file_exists(JPATH_ROOT . '/components/com_osmembership/osmembership.php')) {
    require_once JPATH_ROOT . '/components/com_osmembership/libraries/rad/bootstrap.php';
    //OS Framework
    require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/defines.php';
    require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/inflector.php';
    require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/autoload.php';
    $document = JFactory::getDocument();
    $user = JFactory::getUser();
    $db =& JFactory::getDBO();
    OSMembershipHelper::loadLanguage();
    $styleUrl = JURI::base(true) . '/components/com_osmembership/assets/css/style.css';
    $document->addStylesheet($styleUrl, 'text/css', null, null);
    $config = OSMembershipHelper::getConfig();
    if (@$config->load_jquery !== '0') {
        OSMembershipHelper::loadJQuery();
    }
    OSMembershipHelper::loadBootstrap(true);
    JHtml::_('script', OSMembershipHelper::getSiteUrl() . 'components/com_osmembership/assets/js/jquery-noconflict.js', false, false);
    $Itemid = JRequest::getInt('Itemid');
    $planIds = $params->get('plan_ids', '*');
    $layout = $params->get('layout_type', 'default');
    $fieldSuffix = OSMembershipHelper::getFieldSuffix();
    if (!$planIds) {
        $planIds = '*';
    }
Exemplo n.º 4
0
 /**
  * Replace callback function
  *
  * @param array $matches
  */
 function displayPlans($matches)
 {
     require_once JPATH_ROOT . '/components/com_osmembership/libraries/rad/bootstrap.php';
     //OS Framework
     require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/defines.php';
     require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/inflector.php';
     require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/autoload.php';
     $document = JFactory::getDocument();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $config = OSMembershipHelper::getConfig();
     if (@$config->load_jquery !== '0') {
         OSMembershipHelper::loadJQuery();
     }
     OSMembershipHelper::loadBootstrap(true);
     JHtml::_('script', OSMembershipHelper::getSiteUrl() . 'components/com_osmembership/assets/js/jquery-noconflict.js', false, false);
     OSMembershipHelper::loadLanguage();
     $styleUrl = JURI::base(true) . '/components/com_osmembership/assets/css/style.css';
     $document->addStylesheet($styleUrl, 'text/css', null, null);
     OSMembershipHelper::loadBootstrap(false);
     $Itemid = OSMembershipHelper::getItemid();
     $planIds = $matches[1];
     $fieldSuffix = OSMembershipHelper::getFieldSuffix();
     $layout = $this->params->get('layout_type', 'default');
     if ($planIds == '*') {
         $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description  FROM #__osmembership_plans AS a WHERE a.published = 1 ORDER BY a.ordering';
     } elseif (strpos($planIds, 'cat-') !== false) {
         $catId = (int) substr($planIds, 4);
         $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description  FROM #__osmembership_plans AS a WHERE a.published = 1 AND a.category_id=' . $catId . ' ORDER BY a.ordering';
     } else {
         $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description  FROM #__osmembership_plans AS a WHERE a.published = 1 AND a.id IN (' . $planIds . ') ORDER BY a.ordering';
     }
     $db->setQuery($sql);
     $rows = $db->loadObjectList();
     if ($user->id) {
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             $row = $rows[$i];
             $taxRate = OSMembershipHelper::calculateTaxRate($row->id);
             if ($config->show_price_including_tax && $taxRate > 0) {
                 $row->price = $row->price * (1 + $taxRate / 100);
                 $row->trial_amount = $row->trial_amount * (1 + $taxRate / 100);
             }
             if (!$row->enable_renewal) {
                 $sql = 'SELECT COUNT(*) FROM #__osmembership_subscribers WHERE (email="' . $user->email . '" OR user_id=' . $user->id . ') AND plan_id=' . $row->id . ' AND published != 0 ';
                 $db->setQuery($sql);
                 $total = (int) $db->loadResult();
                 if ($total) {
                     $row->disable_subscribe = 1;
                 }
             }
         }
     } elseif ($config->show_price_including_tax) {
         for ($i = 0, $n = count($rows); $i < $n; $i++) {
             $row = $rows[$i];
             $taxRate = OSMembershipHelper::getPlanTaxRate($row->id);
             if ($taxRate > 0) {
                 $row->price = $row->price * (1 + $taxRate / 100);
                 $row->trial_amount = $row->trial_amount * (1 + $taxRate / 100);
             }
         }
     }
     if ($layout == 'default') {
         return '<div class="osm-container row-fluid clearfix">' . OSMembershipHelperHtml::loadCommonLayout('common/default_plans.php', array('items' => $rows, 'config' => $config, 'Itemid' => $Itemid)) . '</div>';
     } else {
         return '<div class="osm-container row-fluid clearfix">' . OSMembershipHelperHtml::loadCommonLayout('common/columns_plans.php', array('items' => $rows, 'config' => $config, 'Itemid' => $Itemid)) . '</div>';
     }
 }