Skip to content

Commit

Permalink
Optimizations for Reader implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sippsolutions committed May 6, 2019
1 parent ae5451e commit 73c1e62
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 300 deletions.
75 changes: 50 additions & 25 deletions Block/Adminhtml/Dashboard.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
Expand All @@ -12,10 +12,11 @@

namespace Magenerds\Dashboard\Block\Adminhtml;

use Exception;
use Magento\Backend\Block\Template;

/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
Expand All @@ -41,26 +42,44 @@ class Dashboard extends Template
*/
const NUMBER_NEWS_FEEDS = 5;

/**
* @return object
*/
protected function getReader()
{
if (class_exists('\Zend_Feed_Reader')) {
return new \Zend_Feed_Reader();
}
/** @noinspection PhpFullyQualifiedNameUsageInspection PhpUndefinedNamespaceInspection */
return new \Zend\Feed\Reader\Reader();
}

/**
* Returns the blog feeds
*
* @return []
* @return array
*/
public function getBlogFeeds()
{
$feeds = [];
$reader = new \Zend_Feed_Reader();
$reader = $this->getReader();

$ctr = 1;
foreach ($reader->import(self::BLOG_FEED_URL) as $feed) {
$feeds[] = [
'link' => $feed->getLink(),
'title' => $feed->getTitle(),
'date' => substr($feed->getDateCreated(), 0, 10),
'description' => $feed->getDescription()
];
if ($ctr == self::NUMBER_BLOG_FEEDS) break;
$ctr++;
try {
foreach ($reader->import(self::BLOG_FEED_URL) as $feed) {
$feeds[] = [
'link' => $feed->getLink(),
'title' => $feed->getTitle(),
'date' => substr($feed->getDateCreated(), 0, 10),
'description' => $feed->getDescription()
];
if ($ctr == self::NUMBER_BLOG_FEEDS) {
break;
}
$ctr++;
}
} catch (Exception $e) {
// do nothing
}

return $feeds;
Expand All @@ -69,25 +88,31 @@ public function getBlogFeeds()
/**
* Returns the news feeds
*
* @return []
* @return array
*/
public function getNewsFeeds()
{
$feeds = [];
$reader = new \Zend_Feed_Reader();
$reader = $this->getReader();

$ctr = 1;
foreach ($reader->import(self::NEWS_FEED_URL) as $feed) {
$feeds[] = [
'link' => $feed->getLink(),
'title' => $feed->getTitle(),
'date' => substr($feed->getDateCreated(), 0, 10),
'content' => $feed->getContent()
];
if ($ctr == self::NUMBER_NEWS_FEEDS) break;
$ctr++;
try {
foreach ($reader->import(self::NEWS_FEED_URL) as $feed) {
$feeds[] = [
'link' => $feed->getLink(),
'title' => $feed->getTitle(),
'date' => substr($feed->getDateCreated(), 0, 10),
'content' => $feed->getContent()
];
if ($ctr == self::NUMBER_NEWS_FEEDS) {
break;
}
$ctr++;
}
} catch (Exception $e) {
// do nothing
}

return $feeds;
}
}
}
16 changes: 9 additions & 7 deletions Controller/Adminhtml/Dashboard/Index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
Expand All @@ -13,18 +13,19 @@
namespace Magenerds\Dashboard\Controller\Adminhtml\Dashboard;

use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\App\Action;

/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
class Index extends Action
{
/**
* @var \Magento\Framework\View\Result\PageFactory
* @var PageFactory
*/
protected $_resultPageFactory;

Expand All @@ -35,19 +36,20 @@ class Index extends Action
public function __construct(
Context $context,
PageFactory $resultPageFactory
) {
)
{
parent::__construct($context);
$this->_resultPageFactory = $resultPageFactory;
}

/**
* Index action
*
* @return \Magento\Backend\Model\View\Result\Page
* @return Page
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
/** @var Page $resultPage */
$resultPage = $this->_resultPageFactory->create();
$resultPage->setActiveMenu('Magenerds_Dashboard::dashboard');
$resultPage->addBreadcrumb(__('Magenerds'), __('Magenerds'));
Expand All @@ -66,4 +68,4 @@ protected function _isAllowed()
{
return $this->_authorization->isAllowed('Magenerds_Dashboard::index');
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Magenerds_Dashboard
# Magenerds Dashboard

This module will serve information about Magenerds.
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "magenerds/dashboard",
"description": "The Magenerds dashboard provides useful information about Magenerds",
"require": {
"magento/framework": "^100.0.0|^101.0.0|^102.0.0"
},
"type": "magento2-module",
"license": [
"OSL-3.0"
],
"autoload": {
"files": [
"registration.php"
"name": "magenerds/dashboard",
"description": "The Magenerds dashboard provides useful information about Magenerds",
"require": {
"magento/framework": "^100.0.0|^101.0.0|^102.0.0"
},
"type": "magento2-module",
"license": [
"OSL-3.0"
],
"psr-4": {
"Magenerds\\Dashboard\\": ""
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Magenerds\\Dashboard\\": ""
}
}
}
}
12 changes: 6 additions & 6 deletions etc/acl.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
* For more information see http://www.mageneds.com/
* For more information see http://www.magenerds.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
Expand All @@ -22,10 +22,10 @@
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magenerds_Dashboard::dashboard" title="Magenerds" sortOrder="10" >
<resource id="Magenerds_Dashboard::index" title="Magenerds" sortOrder="10" />
<resource id="Magenerds_Dashboard::dashboard" title="Magenerds" sortOrder="10">
<resource id="Magenerds_Dashboard::index" title="Magenerds" sortOrder="10"/>
</resource>
</resource>
</resources>
</acl>
</config>
</config>
8 changes: 4 additions & 4 deletions etc/adminhtml/menu.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
* For more information see http://www.mageneds.com/
* For more information see http://www.magenerds.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
Expand All @@ -27,4 +27,4 @@
action="magenerds/dashboard"
/>
</menu>
</config>
</config>
6 changes: 3 additions & 3 deletions etc/adminhtml/routes.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
* For more information see http://www.mageneds.com/
* For more information see http://www.magenerds.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
Expand Down
10 changes: 5 additions & 5 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
* For more information see http://www.mageneds.com/
* For more information see http://www.magenerds.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magenerds_Dashboard" setup_version="0.0.1" />
</config>
<module name="Magenerds_Dashboard" setup_version="0.0.1"/>
</config>
6 changes: 3 additions & 3 deletions registration.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2017 Magenerds
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
Expand All @@ -11,12 +11,12 @@
*/

/**
* @copyright Copyright (c) 2017 Magenerds (http://www.magenerds.com)
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Magenerds_Dashboard',
__DIR__
);
);
18 changes: 18 additions & 0 deletions view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2019 Magenerds
* All rights reserved
*
* This product includes proprietary software developed at Magenerds, Germany
* For more information see http://www.magenerds.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
/**
* @copyright Copyright (c) 2019 Magenerds (http://www.magenerds.com)
* @link http://www.magenerds.com/
* @author Florian Sydekum <[email protected]>
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Magenerds_Dashboard::css/menu.css"/>
Expand Down
Loading

0 comments on commit 73c1e62

Please sign in to comment.