Файловый менеджер - Редактировать - /var/www/html/osmembershipk2.zip
Ðазад
PK ! �^���A �A osmembershipk2.phpnu �[��� <?php /** * @package Joomla * @subpackage Membership Pro * @author Tuan Pham Ngoc * @copyright Copyright (C) 2012 - 2025 Ossolution Team * @license GNU/GPL, see LICENSE.php */ defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Uri\Uri; use Joomla\Event\Event; use Joomla\Event\SubscriberInterface; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; if (!file_exists(JPATH_ADMINISTRATOR . '/components/com_osmembership/loader.php')) { return; } // Require library + register autoloader require_once JPATH_ADMINISTRATOR . '/components/com_osmembership/loader.php'; class plgSystemOSMembershipk2 extends CMSPlugin implements SubscriberInterface { use MPFEventResult; /** * Application object. * * @var \Joomla\CMS\Application\CMSApplication */ protected $app; /** * Database object * * @var \Joomla\Database\DatabaseDriver */ protected $db; public static function getSubscribedEvents(): array { return [ 'onAfterRoute' => 'onAfterRoute', 'onEditSubscriptionPlan' => 'onEditSubscriptionPlan', 'onAfterSaveSubscriptionPlan' => 'onAfterSaveSubscriptionPlan', 'onContentPrepare' => 'onContentPrepare', 'onProfileDisplay' => 'onProfileDisplay', ]; } /** * Register listeners * * @return void */ public function registerListeners() { if (!ComponentHelper::isEnabled('com_osmembership')) { return; } if (!ComponentHelper::isEnabled('com_k2')) { return; } parent::registerListeners(); } /** * Render settings form * * @param Event $event * * @return void */ public function onEditSubscriptionPlan(Event $event): void { /* @var OSMembershipTablePlan $row */ [$row] = array_values($event->getArguments()); if (!$this->isExecutable()) { return; } ob_start(); $this->loadLanguage(); $this->drawSettingForm($row); $form = ob_get_clean(); $result = [ 'title' => Text::_('PLG_OSMEMBERSHIP_K2_ITEMS_RESTRICTION_SETTINGS'), 'form' => $form, ]; $this->addResult($event, $result); } /** * Store setting into database * * @param Event $event * * @return void */ public function onAfterSaveSubscriptionPlan(Event $event): void { /** * @var string $context * @var OSMembershipTablePlan $row * @var array $data * @var $isNew */ [$context, $row, $data, $isNew] = array_values($event->getArguments()); if (!$this->isExecutable()) { return; } $db = $this->db; $query = $db->getQuery(true); $planId = $row->id; $articleIds = $data['k2_item_ids']; if (!$isNew) { $query->delete('#__osmembership_k2items') ->where('plan_id = ' . (int) $planId); $db->setQuery($query) ->execute(); } if (!empty($articleIds)) { $articleIds = explode(',', $articleIds); $articleIds = array_filter(ArrayHelper::toInteger($articleIds)); foreach ($articleIds as $articleId) { $query->clear() ->insert('#__osmembership_k2items') ->columns('plan_id, article_id') ->values("$row->id,$articleId"); $db->setQuery($query); $db->execute(); } } if ($this->params->get('setup_method', '0')) { $selectedCategories = explode(',', $data['k2_item_categories']); } else { $selectedCategories = $data['k2_item_categories'] ?? []; } $params = new Registry($row->params); $params->set('k2_item_categories', implode(',', $selectedCategories)); $row->params = $params->toString(); $row->store(); } /** * Display form allows users to change setting for this subscription plan * * @param object $row */ private function drawSettingForm($row) { if ($this->params->get('setup_method', '0')) { $layout = 'simple'; } else { $layout = 'form'; } $params = new Registry($row->params); $db = $this->db; $query = $db->getQuery(true); if ($layout === 'form') { //Get categories $query->select('id, name') ->from('#__k2_categories') ->where('published = 1') ->order('ordering'); $db->setQuery($query); $categories = $db->loadObjectList('id'); if (!count($categories)) { return; } $categoryIds = array_keys($categories); $query->clear() ->select('id, title, catid') ->from('#__k2_items') ->where('`published` = 1') ->whereIn('catid', $categoryIds) ->order('ordering'); $db->setQuery($query); $rowArticles = $db->loadObjectList(); if (!count($rowArticles)) { return; } $articles = []; foreach ($rowArticles as $rowArticle) { $articles[$rowArticle->catid][] = $rowArticle; } $categories = array_values($categories); if (!$this->params->get('display_empty_categories')) { for ($i = 0, $n = count($categories); $i < $n; $i++) { $category = $categories[$i]; if (!isset($articles[$category->id])) { unset($categories[$i]); } } reset($categories); } $selectedCategories = explode(',', $params->get('k2_item_categories', '')); } //Get plans articles $query->clear() ->select('article_id') ->from('#__osmembership_k2items') ->where('plan_id=' . (int) $row->id); $db->setQuery($query); $planArticles = $db->loadColumn(); require PluginHelper::getLayoutPath($this->_type, $this->_name, $layout); } public function onAfterRoute(Event $event): void { if (!$this->app->isClient('site')) { return; } $user = $this->app->getIdentity(); if ($user->authorise('core.admin')) { return; } if ($this->params->get('protection_method', 0) == 1) { return; } if ($this->params->get('allow_search_engine', 0) == 1 && $this->app->client->robot) { return; } $option = $this->app->getInput()->getCmd('option'); $view = $this->app->getInput()->getCmd('view'); $task = $this->app->getInput()->getCmd('task'); $articleId = $this->app->getInput()->getInt('id', 0); if ($option != 'com_k2' || ($view != 'item' && $task != 'download') || !$articleId) { return; } if ($this->isItemReleased($articleId)) { return; } $planIds = $this->getRequiredPlanIds($articleId); if (count($planIds)) { //Check to see the current user has an active subscription plans $activePlans = OSMembershipHelperSubscription::getActiveMembershipPlans(); if (!count(array_intersect($planIds, $activePlans))) { OSMembershipHelper::loadLanguage(); $msg = Text::_('OS_MEMBERSHIP_K2_ARTICLE_ACCESS_RESITRICTED'); $msg = str_replace('[PLAN_TITLES]', $this->getPlanTitles($planIds), $msg); $msg = HTMLHelper::_('content.prepare', $msg); // Try to find the best redirect URL $redirectUrl = OSMembershipHelper::callOverridableHelperMethod( 'Helper', 'getPluginRestrictionRedirectUrl', [$this->params, $planIds] ); // Store URL of this page to redirect user back after user logged in if they have active subscription of this plan $session = $this->app->getSession(); $session->set('osm_return_url', Uri::getInstance()->toString()); $session->set('required_plan_ids', $planIds); $this->app->enqueueMessage($msg); $this->app->redirect($redirectUrl); } } } /** * Hide fulltext of article to none-subscribers * * @param Event $event * * @return void */ public function onContentPrepare(Event $event): void { [$context, $row, $params, $page] = array_values($event->getArguments()); if ($this->params->get('protection_method', 0) == 0) { return; } if ($this->params->get('allow_search_engine', 0) == 1 & $this->app->client->robot) { return; } if (!is_object($row)) { return; } if ($context != 'com_k2.item') { return; } if ($this->isItemReleased($row->id)) { return; } $planIds = $this->getRequiredPlanIds($row->id); if (count($planIds)) { //Check to see the current user has an active subscription plans $activePlans = OSMembershipHelperSubscription::getActiveMembershipPlans(); if (!count(array_intersect($planIds, $activePlans))) { OSMembershipHelper::loadLanguage(); $msg = OSMembershipHelper::callOverridableHelperMethod('Helper', 'getContentRestrictedMessages', [$planIds]); // Try to find the best redirect URL $redirectUrl = OSMembershipHelper::callOverridableHelperMethod( 'Helper', 'getPluginRestrictionRedirectUrl', [$this->params, $planIds] ); // Store URL of this page to redirect user back after user logged in if they have active subscription of this plan $session = $this->app->getSession(); $session->set('osm_return_url', Uri::getInstance()->toString()); $session->set('required_plan_ids', $planIds); $msg = str_replace('[SUBSCRIPTION_URL]', $redirectUrl, $msg); $msg = str_replace('[PLAN_IDS]', implode(',', $planIds), $msg); $msg = HTMLHelper::_('content.prepare', $msg); $layoutData = [ 'row' => $row, 'introText' => $row->introtext, 'msg' => $msg, 'context' => 'plgSystemOSMembershipK2.onContentPrepare', ]; $row->text = OSMembershipHelperHtml::loadCommonLayout('common/tmpl/restrictionmsg.php', $layoutData); } } } /** * Check if the K2 items released * * @param int $id * * @return bool */ private function isItemReleased($id) { if (!$this->params->get('release_article_older_than_x_days', 0) && !$this->params->get('make_new_item_free_for_x_days', 0)) { return false; } $db = $this->db; $query = $db->getQuery(true) ->select('*') ->from('#__k2_items') ->where('id = ' . (int) $id); $db->setQuery($query); $item = $db->loadObject(); if ($item->publish_up && $item->publish_up != $db->getNullDate()) { $publishedDate = $item->publish_up; } else { $publishedDate = $item->created; } $today = Factory::getDate(); $publishedDate = Factory::getDate($publishedDate); $numberDays = $publishedDate->diff($today)->days; // This article is older than configured number of days, it can be accessed for free if ($today >= $publishedDate && $this->params->get('release_item_older_than_x_days') > 0 && $numberDays >= $this->params->get('release_item_older_than_x_days')) { return true; } // This article is just published and it's still free for access for the first X-days if ($today >= $publishedDate && $this->params->get('make_new_item_free_for_x_days') > 0 && $numberDays <= $this->params->get('make_new_item_free_for_x_days')) { return true; } return false; } /** * The the Ids of the plans which users can subscribe for to access to the given article * * @param int $articleId * * @return array */ private function getRequiredPlanIds($articleId) { $db = $this->db; $query = $db->getQuery(true); $query->select('DISTINCT plan_id') ->from('#__osmembership_k2items') ->where('article_id = ' . $articleId) ->where('plan_id IN (SELECT id FROM #__osmembership_plans WHERE published = 1)'); $db->setQuery($query); try { $planIds = $db->loadColumn(); } catch (Exception $e) { $planIds = []; } // Check categories $query->clear() ->select('catid') ->from('#__k2_items') ->where('id = ' . (int) $articleId); $db->setQuery($query); $catId = $db->loadResult(); $query->clear() ->select('id, params') ->from('#__osmembership_plans') ->where('published = 1'); $db->setQuery($query); $plans = $db->loadObjectList(); foreach ($plans as $plan) { $params = new Registry($plan->params); if ($articleCategories = $params->get('k2_item_categories')) { $articleCategories = ArrayHelper::toInteger(explode(',', $articleCategories)); if ($this->params->get('restrict_children_categories')) { $articleCategories = $this->getAllChildrenCategories($articleCategories); } if (in_array($catId, $articleCategories)) { $planIds[] = $plan->id; } } } return $planIds; } /** * Get imploded titles of the given plans * * @param array $planIds * * @return string */ private function getPlanTitles($planIds) { $db = $this->db; $query = $db->getQuery(true); $query->select('title') ->from('#__osmembership_plans') ->whereIn('id', $planIds) ->where('published = 1') ->order('ordering'); $db->setQuery($query); return implode(' ' . Text::_('OSM_OR') . ' ', $db->loadColumn()); } /** * Get all childrent categories of the given categories * * @param array $catIds * * @return array */ private function getAllChildrenCategories($catIds) { $db = $this->db; $query = $db->getQuery(true); $queue = $catIds; $categoryIds = $catIds; while (count($queue)) { $categoryId = array_pop($queue); //Get list of children categories of the current category $query->clear() ->select('id') ->from('#__k2_categories') ->where('parent = ' . $categoryId) ->where('published = 1'); $db->setQuery($query); $db->setQuery($query); $children = $db->loadColumn(); if (count($children)) { $queue = array_merge($queue, $children); $categoryIds = array_merge($categoryIds, $children); } } return $categoryIds; } /** * Display k2 items which subscriber can access to in his profile * * @param Event $event * * @return void */ public function onProfileDisplay(Event $event): void { /* @var OSMembershipTableSubscriber $row */ [$row] = array_values($event->getArguments()); if (!$this->params->get('display_k2_items_in_profile')) { return; } ob_start(); $this->loadLanguage(); $this->displayK2Items(); $form = ob_get_clean(); $result = [ 'title' => Text::_('OSM_MY_K2_ITMES'), 'form' => $form, ]; $this->addResult($event, $result); } /** * Display list of accessible k2 items */ private function displayK2Items() { $db = $this->db; $query = $db->getQuery(true); $items = []; $activePlanIds = OSMembershipHelperSubscription::getActiveMembershipPlans(); // Get categories $query->select('id, params') ->from('#__osmembership_plans') ->whereIn('id', $activePlanIds); $db->setQuery($query); $plans = $db->loadObjectList(); $catIds = []; foreach ($plans as $plan) { $params = new Registry($plan->params); if ($articleCategories = $params->get('k2_item_categories')) { $catIds = array_merge($catIds, explode(',', $articleCategories)); } } if (count($activePlanIds) > 1) { $query->clear() ->select('a.id, a.catid, a.title, a.alias, a.hits, c.name AS category_name') ->from('#__k2_items AS a') ->innerJoin('#__k2_categories AS c ON a.catid = c.id') ->innerJoin('#__osmembership_k2items AS b ON a.id = b.article_id') ->whereIn('b.plan_id', $activePlanIds) ->where('a.published = 1') ->order('plan_id') ->order('a.ordering'); $db->setQuery($query); $items = array_merge($items, $db->loadObjectList()); } if (count($catIds)) { $query->clear() ->select('a.id, a.catid, a.title, a.alias, a.hits, c.name AS category_name') ->from('#__k2_items AS a') ->innerJoin('#__k2_categories AS c ON a.catid = c.id') ->whereIn('a.catid', $catIds) ->where('a.published = 1') ->order('a.ordering'); $db->setQuery($query); $items = array_merge($items, $db->loadObjectList()); } if (empty($items)) { return; } echo OSMembershipHelperHtml::loadCommonLayout('plugins/tmpl/osmembershipk2.php', ['items' => $items]); } /** * Method to check if the plugin is executable * * @return bool */ private function isExecutable() { if ($this->app->isClient('site') && !$this->params->get('show_on_frontend')) { return false; } return true; } } PK ! Պ��� � osmembershipk2.xmlnu �[��� <?xml version="1.0" encoding="utf-8"?> <extension version="4.2.0" type="plugin" group="system" method="upgrade"> <name>System - Membership Pro K2 items Restriction</name> <author>Tuan Pham Ngoc</author> <authorEmail>tuanpn@joomdonation.com</authorEmail> <authorUrl>https://joomdonation.com</authorUrl> <copyright>Copyright (C) 2012 - 2025 Ossolution Team</copyright> <license>GNU General Public License version 3, or later</license> <creationDate>Nov 2012</creationDate> <version>4.3.1</version> <description>This plugin check to see whether users can access to a k2 item. Only publish it if you use Membership Pro K2 Restriction Settings plugin to restrict access for subscribers </description> <files> <filename plugin="osmembershipk2">osmembershipk2.php</filename> <folder>tmpl</folder> </files> <languages folder="language"> <language tag="en-GB">en-GB/en-GB.plg_system_osmembershipk2.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="redirect_url" label="Redirect URL" type="text" size="70" default="" description="URL of the page users will be redirected to when they are not allowed to access to the k2 item. You should put the url of the subscription plans page on your site into this param"/> <field name="protection_method" type="radio" label="Protection Method" default="0" description="Select the method you want to use to protect the article"> <option value="0">Prevent Access to Item K2 Detail Page</option> <option value="1">Hide fulltext from none subscribers</option> </field> <field name="display_k2_items_in_profile" type="radio" label="Display K2 Items In Profile" default="0" description="If set to Yes, the list of k2 items which subscriber can access to will be displayed in his profile"> <option value="0">No</option> <option value="1">Yes</option> </field> <field name="allow_search_engine" type="radio" label="Allow Search Engine" default="0" description="Select to Yes to allow search engine bots to see and index the protected content"> <option value="0">No</option> <option value="1">Yes</option> </field> <field name="make_new_item_free_for_x_days" type="text" size="60" default="0" label="Make New Items Free For X Days" description="If enter a number here, K2 items will be free for everyone for the first X days from the time it's published"/> <field name="release_item_older_than_x_days" type="text" size="60" default="0" label="Release K2 Items Older Than X Days" description="If enter a number here, K2 items older than this entered number days will be free to access to everyone"/> <field name="display_empty_categories" type="radio" label="Display Empty Categories" default="0" description="Set this to Yes if you want to display categories without any items added to it yet."> <option value="0">No</option> <option value="1">Yes</option> </field> <field name="restrict_children_categories" type="radio" label="Restrict Children Categories" default="0" description="Set this to Yes if you restrict access to a category, it's children categories will be restricted, too"> <option value="0">No</option> <option value="1">Yes</option> </field> <field name="setup_method" type="list" label="Setup Method" default="0" description="Select the method you want to use to setup restriction"> <option value="0">Default</option> <option value="1">Simple</option> </field> <field name="show_on_frontend" type="radio" label="Show On Frontend" description="If set to Yes, this plugin will be available on frontend add/edit plan form" class="btn-group btn-group-yesno" default="0" > <option value="1">JYES</option> <option value="0">JNO</option> </field> </fieldset> </fields> </config> </extension> PK ! 9Ho� tmpl/form.phpnu �[��� <?php /** * @package Joomla * @subpackage Membership Pro * @author Tuan Pham Ngoc * @copyright Copyright (C) 2012 - 2025 Ossolution Team * @license GNU/GPL, see LICENSE.php */ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; Factory::getApplication() ->getDocument() ->getWebAssetManager() ->registerAndUseScript('plug-system-osmembershipk2', 'media/com_osmembership/js/plug-system-osmembershipk2.min.js'); /** * Layout variables * ----------------- * @var array $categories * @var array $selectedCategories * @var array $articles * @var array $planArticles * @var stdClass $row */ $activeCategoryId = 0; ?> <h2><?php echo Text::_('OSM_K2_CATEGORIES'); ?></h2> <p class="text-info"><?php echo Text::_('OSM_K2_CATEGORIES_EXPLAIN'); ?></p> <table class="admintable adminform" style="width: 100%;"> <?php foreach ($categories as $category) { if ($activeCategoryId == 0 && isset($articles[$category->id])) { $activeCategoryId = $category->id; } ?> <tr> <td> <label class="checkbox"> <input type="checkbox" class="form-check-input" value="<?php echo $category->id ?>" <?php if (in_array($category->id, $selectedCategories)) { echo ' checked="checked"'; } ?> name="k2_item_categories[]"/> <strong><?php echo $category->name; ?></strong> </label> </td> </tr> <?php } ?> </table> <h2><?php echo Text::_('OSM_K2_ITEMS'); ?></h2> <p class="text-info"><?php echo Text::_('OSM_K2_ITEMS_EXPLAIN'); ?></p> <?php echo HTMLHelper::_( 'bootstrap.startAccordion', 'k2-categories-accordion', ['active' => 'k2-category-' . $activeCategoryId, 'parent' => 'k2-categories-accordion'] ); foreach ($categories as $category) { if (!isset($articles[$category->id])) { continue; } echo HTMLHelper::_( 'bootstrap.addSlide', 'k2-categories-accordion', $category->name, 'k2-category-' . $category->id ); ?> <label class="checkbox"> <input type="checkbox" value="<?php echo $category->id ?>" class="form-check-input k2-category-check-all"> <strong>Check All</strong> </label> <?php $categoryArticles = $articles[$category->id]; foreach ($categoryArticles as $article) { ?> <label class="checkbox" style="display: block;"> <input type="checkbox" value="<?php echo $article->id; ?>" class="form-check-input k2-category-<?php echo $category->id ?> k2-item-checkbox" <?php if (in_array($article->id, $planArticles)) { echo ' checked="checked" '; } ?> /> <?php echo $article->title; ?> </label> <?php } echo HTMLHelper::_('bootstrap.endSlide'); } echo HTMLHelper::_('bootstrap.endAccordion'); ?> <input type="hidden" value="<?php echo implode(',', $planArticles) ?>" name="k2_item_ids" id="k2_item_ids"/> PK ! ڙ�� � tmpl/simple.phpnu �[��� <?php /** * @package Joomla * @subpackage Membership Pro * @author Tuan Pham Ngoc * @copyright Copyright (C) 2012 - 2025 Ossolution Team * @license GNU/GPL, see LICENSE.php */ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; /** * Layout variables * ----------------- * @var \Joomla\Registry\Registry $params * @var array $planArticles */ ?> <div class="control-group"> <div class="control-label"> <?php echo OSMembershipHelperHtml::getFieldLabel('k2_item_categories', Text::_('OSM_K2_CATEGORIES'), Text::_('OSM_K2_CATEGORIES_SIMPLE_EXPLAIN')); ?> </div> <div class="controls"> <input type="text" class="form-control" name="k2_item_categories" value="<?php echo $params->get('k2_item_categories', ''); ?>"/> </div> </div> <div class="control-group"> <div class="control-label"> <?php echo OSMembershipHelperHtml::getFieldLabel('k2_item_ids', Text::_('OSM_K2_ITEMS'), Text::_('OSM_K2_ITEMS_SIMPLE_EXPLAIN')); ?> </div> <div class="controls"> <input type="text" class="form-control" name="k2_item_ids" value="<?php echo implode(',', $planArticles); ?>"/> </div> </div>PK ! �^���A �A osmembershipk2.phpnu �[��� PK ! Պ��� � �A osmembershipk2.xmlnu �[��� PK ! 9Ho� �T tmpl/form.phpnu �[��� PK ! ڙ�� � 3b tmpl/simple.phpnu �[��� PK @ g
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка