Skip to content

Commit 8c06dfd

Browse files
committed
create new Community module
1 parent 5d1712d commit 8c06dfd

File tree

8 files changed

+818
-0
lines changed

8 files changed

+818
-0
lines changed

Controller/Adminhtml/Actions.php

Lines changed: 525 additions & 0 deletions
Large diffs are not rendered by default.

Model/AdminNotificationFeed.php

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
/** Copyright © Magefan (support@magefan.com).
4+
* All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*/
7+
8+
namespace Magefan\Community\Model;
9+
10+
use Magento\Framework\Config\ConfigOptionsListConstants;
11+
12+
/**
13+
* Class AdminNotificationFeedextends
14+
* @package Magefan\Community\Model
15+
*/
16+
class AdminNotificationFeedextends extends \Magento\AdminNotification\Model\Feed
17+
{
18+
/**
19+
* @var \Magento\Backend\Model\Auth\Session
20+
*/
21+
protected $_backendAuthSession;
22+
/**
23+
* @var \Magento\Framework\Module\ModuleListInterface
24+
*/
25+
protected $_moduleList;
26+
/**
27+
* @var \Magento\Framework\Module\Manager
28+
*/
29+
protected $_moduleManager;
30+
/**
31+
* @param \Magento\Framework\Model\Context $context
32+
* @param \Magento\Framework\Registry $registry
33+
* @param \Magento\Backend\App\ConfigInterface $backendConfig
34+
* @param InboxFactory $inboxFactory
35+
* @param \Magento\Backend\Model\Auth\Session $backendAuthSession
36+
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
37+
* @param \Magento\Framework\Module\Manager $moduleManager,
38+
* @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory
39+
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
40+
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
41+
* @param \Magento\Framework\UrlInterface $urlBuilder
42+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
43+
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
44+
* @param array $data
45+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
46+
*/
47+
public function __construct(
48+
\Magento\Framework\Model\Context $context,
49+
\Magento\Framework\Registry $registry,
50+
\Magento\Backend\App\ConfigInterface $backendConfig,
51+
\Magento\AdminNotification\Model\InboxFactory $inboxFactory,
52+
\Magento\Backend\Model\Auth\Session $backendAuthSession,
53+
\Magento\Framework\Module\ModuleListInterface $moduleList,
54+
\Magento\Framework\Module\Manager $moduleManager,
55+
\Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory,
56+
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
57+
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
58+
\Magento\Framework\UrlInterface $urlBuilder,
59+
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
60+
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
61+
array $data = []
62+
) {
63+
parent::__construct($context, $registry, $backendConfig, $inboxFactory, $curlFactory, $deploymentConfig, $productMetadata, $urlBuilder, $resource, $resourceCollection, $data);
64+
$this->_backendAuthSession = $backendAuthSession;
65+
$this->_moduleList = $moduleList;
66+
$this->_moduleManager = $moduleManager;
67+
}
68+
69+
/**
70+
* Retrieve feed url
71+
*
72+
* @return string
73+
*/
74+
public function getFeedUrl()
75+
{
76+
if (is_null($this->_feedUrl)) {
77+
$this->_feedUrl = 'http://mage'.'fan'
78+
.'.c'.'om/community/notifications'.'/'.'feed/';
79+
}
80+
$urlInfo = parse_url($this->urlBuilder->getBaseUrl());
81+
$domain = isset($urlInfo['host']) ? $urlInfo['host'] : '';
82+
$url = $this->_feedUrl . 'domain/' . urlencode($domain);
83+
$modulesParams = [];
84+
foreach ($this->getMagefanModules() as $key => $module) {
85+
$key = str_replace('Magefan_', '', $key);
86+
$modulesParams[] = $key . ',' . $module['setup_version'];
87+
}
88+
if (count($modulesParams)) {
89+
$url .= '/modules/'.base64_encode(implode(';', $modulesParams));
90+
}
91+
return $url;
92+
}
93+
94+
/**
95+
* Get Magefan Modules Info
96+
*
97+
* @return $this
98+
*/
99+
protected function getMagefanModules()
100+
{
101+
$modules = [];
102+
foreach ($this->_moduleList->getAll() as $moduleName => $module) {
103+
if (strpos($moduleName, 'Magefan_') !== false && $this->_moduleManager->isEnabled($moduleName)) {
104+
$modules[$moduleName] = $module;
105+
}
106+
}
107+
return $modules;
108+
}
109+
110+
/**
111+
* Check feed for modification
112+
*
113+
* @return $this
114+
*/
115+
public function checkUpdate()
116+
{
117+
$session = $this->_backendAuthSession;
118+
$time = time();
119+
$frequency = $this->getFrequency();
120+
if (($frequency + $session->getMfNoticeLastUpdate() > $time)
121+
|| ($frequency + $this->getLastUpdate() > $time)
122+
) {
123+
return $this;
124+
}
125+
$session->setMfNoticeLastUpdate($time);
126+
return parent::checkUpdate();
127+
}
128+
129+
/**
130+
* Retrieve Update Frequency
131+
*
132+
* @return int
133+
*/
134+
public function getFrequency()
135+
{
136+
return 86400;
137+
}
138+
139+
/**
140+
* Retrieve Last update time
141+
*
142+
* @return int
143+
*/
144+
public function getLastUpdate()
145+
{
146+
return $this->_cacheManager->load('magefan_admin_notifications_lastcheck');
147+
}
148+
149+
/**
150+
* Set last update time (now)
151+
*
152+
* @return $this
153+
*/
154+
public function setLastUpdate()
155+
{
156+
$this->_cacheManager->save(time(), 'magefan_admin_notifications_lastcheck');
157+
return $this;
158+
}
159+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/** Copyright © Magefan (support@magefan.com).
4+
* All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*/
7+
8+
namespace Magefan\Community\Observer;
9+
10+
use Magento\Framework\Event\ObserverInterface;
11+
12+
/**
13+
* community observer
14+
*/
15+
class PredispathAdminActionControllerObserver implements ObserverInterface
16+
{
17+
/**
18+
* @var \Magefan\Blog\Model\AdminNotificationFeedFactory
19+
*/
20+
protected $_feedFactory;
21+
22+
/**
23+
* @var \Magento\Backend\Model\Auth\Session
24+
*/
25+
protected $_backendAuthSession;
26+
27+
/**
28+
* @var \Magefan\Blog\Model\Comment\Notification
29+
*/
30+
protected $commentNotification;
31+
32+
/**
33+
* @param \Magefan\Blog\Model\AdminNotificationFeedFactory $feedFactory
34+
* @param \Magento\Backend\Model\Auth\Session $backendAuthSession
35+
* @param \Magefan\Blog\Model\Comment\Notification $commentNotification,
36+
*/
37+
public function __construct(
38+
\Magefan\Blog\Model\AdminNotificationFeedFactory $feedFactory,
39+
\Magento\Backend\Model\Auth\Session $backendAuthSession,
40+
\Magefan\Blog\Model\Comment\Notification $commentNotification
41+
) {
42+
$this->_feedFactory = $feedFactory;
43+
$this->_backendAuthSession = $backendAuthSession;
44+
$this->commentNotification = $commentNotification;
45+
}
46+
47+
/**
48+
* Predispath admin action controller
49+
*
50+
* @param \Magento\Framework\Event\Observer $observer
51+
* @return void
52+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
53+
*/
54+
public function execute(\Magento\Framework\Event\Observer $observer)
55+
{
56+
if ($this->_backendAuthSession->isLoggedIn()) {
57+
$feedModel = $this->_feedFactory->create();
58+
/* @var $feedModel \Magefan\Blog\Model\AdminNotificationFeed */
59+
$feedModel->checkUpdate();
60+
61+
/** Check pending blog comments */
62+
$this->commentNotification->checkComments();
63+
}
64+
}
65+
}

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "magefan/module-community",
3+
"description": "",
4+
"license": "proprietary",
5+
"authors": [
6+
{
7+
"email": "info@mage2gen.com",
8+
"name": "Mage2Gen"
9+
}
10+
],
11+
"minimum-stability": "dev",
12+
"require": {},
13+
"autoload": {
14+
"files": [
15+
"registration.php"
16+
],
17+
"psr-4": {
18+
"Magefan\\Community\\": ""
19+
}
20+
}
21+
}

etc/adminhtml/events.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/** Copyright © Magefan (support@magefan.com).
4+
* All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
9+
<event name="controller_action_predispatch">
10+
<observer name="magefan_blog_controller_action_predispatch" instance="Magefan\Blog\Observer\PredispathAdminActionControllerObserver" />
11+
</event>
12+
<event name="controller_action_postdispatch_blog_post_save">
13+
<observer name="magefan_blog_invalidate_cache" instance="Magefan\Blog\Observer\InvalidateCache" />
14+
</event>
15+
<event name="controller_action_postdispatch_blog_category_save">
16+
<observer name="magefan_blog_invalidate_cache" instance="Magefan\Blog\Observer\InvalidateCache" />
17+
</event>
18+
</config>

etc/module.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" ?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="Magefan_Community" setup_version="1.0.0"/>
4+
</config>

etc/routes.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/** Copyright © Magefan (support@magefan.com).
4+
* All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
9+
<router id="standard">
10+
<route id="community" frontName="community">
11+
<module name="Magefan_Community" />
12+
</route>
13+
</router>
14+
</config>

registration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/** Copyright © Magefan (support@magefan.com).
4+
* All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*/
7+
8+
\Magento\Framework\Component\ComponentRegistrar::register(
9+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
10+
'Magefan_Community',
11+
__DIR__
12+
);

0 commit comments

Comments
 (0)