Skip to content

Commit

Permalink
Merge pull request #19 from kdambekalns/master
Browse files Browse the repository at this point in the history
!!! FEATURE: Adjust to Neos 3.0
  • Loading branch information
robertlemke authored Jan 23, 2017
2 parents 49d617e + 8283986 commit 10151e7
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* source code.
*/

use TYPO3\Eel\FlowQuery\FlowQuery;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
use TYPO3\Neos\Domain\Service\ContentContextFactory;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use TYPO3\TYPO3CR\Domain\Model\NodeTemplate;
use TYPO3\TYPO3CR\Domain\Service\NodeTypeManager;
use TYPO3\TYPO3CR\Utility;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Neos\Domain\Service\ContentContextFactory;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\NodeTemplate;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Utility;

/**
* BlogCommand command controller for the RobertLemke.Plugin.Blog package
Expand All @@ -27,7 +27,6 @@
*/
class AtomImportCommandController extends CommandController
{

/**
* @Flow\Inject
* @var NodeTypeManager
Expand All @@ -48,7 +47,7 @@ class AtomImportCommandController extends CommandController
/**
* @var array
*/
protected $tagNodes = array();
protected $tagNodes = [];

/**
* Imports atom data into the blog
Expand Down Expand Up @@ -79,11 +78,11 @@ public function migrateCommand($workspace, $targetNode, $atomFile)

$parser->set_raw_data(file_get_contents($atomFile));
$parser->strip_attributes();
$parser->strip_htmltags(array_merge($parser->strip_htmltags, array('span')));
$parser->strip_htmltags(array_merge($parser->strip_htmltags, ['span']));
$parser->init();
$items = $parser->get_items();

$comments = array();
$comments = [];
/** @var $item \SimplePie_Item */
foreach ($items as $item) {
$categories = $item->get_categories();
Expand All @@ -102,7 +101,7 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
}
}

$textNodeType = $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Text');
$textNodeType = $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text');
$commentNodeType = $this->nodeTypeManager->getNodeType('RobertLemke.Plugin.Blog:Comment');
$counter = 0;
foreach ($parser->get_items() as $item) {
Expand All @@ -111,7 +110,7 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
continue;
}

$tags = array();
$tags = [];
$itemIsPost = false;
foreach ($categories as $category) {
if ($category->get_term() === 'http://schemas.google.com/blogger/2008/kind#post') {
Expand All @@ -134,13 +133,13 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
$nodeTemplate->setProperty('datePublished', $published);
$nodeTemplate->setProperty('tags', $this->getTagNodes($tags));

$slug = strtolower(str_replace(array(' ', ',', ':', 'ü', 'à', 'é', '?', '!', '[', ']', '.', '\''), array('-', '', '', 'u', 'a', 'e', '', '', '', '', '-', ''), $item->get_title()));
$slug = strtolower(str_replace([' ', ',', ':', 'ü', 'à', 'é', '?', '!', '[', ']', '.', '\''], ['-', '', '', 'u', 'a', 'e', '', '', '', '', '-', ''], $item->get_title()));
/** @var NodeInterface $postNode */
$postNode = $this->blogNode->createNodeFromTemplate($nodeTemplate, $slug);
$postNode->getNode('main')->createNode(uniqid('node'), $textNodeType)->setProperty('text', $item->get_content());

$postComments = isset($comments[$item->get_id()]) ? $comments[$item->get_id()] : array();
if ($postComments !== array()) {
$postComments = isset($comments[$item->get_id()]) ? $comments[$item->get_id()] : [];
if ($postComments !== []) {
/** @var NodeInterface $commentsNode */
$commentsNode = $postNode->getNode('comments');
/** @var $postComment \SimplePie_Item */
Expand All @@ -165,15 +164,16 @@ public function migrateCommand($workspace, $targetNode, $atomFile)
$this->outputLine($postNode->getProperty('title') . ' by ' . $postNode->getProperty('author'));
}

$this->outputLine('Imported %s blog posts.', array($counter));
$this->outputLine('Imported %s blog posts.', [$counter]);
}

/**
* @param array $tags
* @return array<NodeInterface>
*/
protected function getTagNodes(array $tags) {
$tagNodes = array();
protected function getTagNodes(array $tags)
{
$tagNodes = [];

foreach ($tags as $tag) {
if (!isset($this->tagNodes[$tag])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
*/

use RobertLemke\Akismet\Service;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\Controller\ActionController;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use TYPO3\TYPO3CR\Domain\Model\NodeTemplate;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Model\NodeTemplate;

/**
* Comments controller for the Blog package
*/
class CommentController extends ActionController
{

/**
* @Flow\Inject
* @var Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use RobertLemke\Rss\Channel;
use RobertLemke\Rss\Feed;
use RobertLemke\Rss\Item;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\I18n\Service;
use TYPO3\Flow\Mvc\Controller\ActionController;
use TYPO3\Flow\Mvc\Routing\UriBuilder;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use TYPO3\TYPO3CR\Domain\Service\NodeTypeManager;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\I18n\Service;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;

/**
* The posts controller for the Blog package
Expand All @@ -29,7 +29,6 @@
*/
class PostController extends ActionController
{

/**
* @Flow\Inject
* @var NodeTypeManager
Expand Down Expand Up @@ -75,7 +74,7 @@ public function rssAction()
$feedUri = $this->request->getInternalArgument('__feedUri');
} else {
$uriBuilder->setFormat('xml');
$feedUri = $uriBuilder->uriFor('show', array('node' => $rssDocumentNode), 'Frontend\Node', 'TYPO3.Neos');
$feedUri = $uriBuilder->uriFor('show', ['node' => $rssDocumentNode], 'Frontend\Node', 'Neos.Neos');
}

$channel = new Channel();
Expand All @@ -89,7 +88,7 @@ public function rssAction()
foreach ($postsNode->getChildNodes('RobertLemke.Plugin.Blog:Post') as $postNode) {

$uriBuilder->setFormat('html');
$postUri = $uriBuilder->uriFor('show', array('node' => $postNode), 'Frontend\Node', 'TYPO3.Neos');
$postUri = $uriBuilder->uriFor('show', ['node' => $postNode], 'Frontend\Node', 'Neos.Neos');

$item = new Item();
$item->setTitle($postNode->getProperty('title'));
Expand All @@ -105,13 +104,13 @@ public function rssAction()
$item->setCreator($author);

if ($postNode->getProperty('categories')) {
$categories = array();
$categories = [];
/** @var NodeInterface $categoryNode */
foreach ($postNode->getProperty('categories') as $categoryNode) {
$categories[] = array(
$categories[] = [
'category' => $categoryNode->getProperty('title'),
'domain' => $categoryNode->getProperty('domain')
);
];
}
$item->setCategories($categories);
}
Expand All @@ -135,5 +134,4 @@ public function rssAction()

return $feed->render();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
* source code.
*/

use TYPO3\Flow\Core\Bootstrap;
use TYPO3\Flow\Package\Package as BasePackage;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;

/**
* The Blog Package
*
*/
class Package extends BasePackage
{

/**
* Invokes custom PHP code directly after the package manager has been initialized.
*
Expand All @@ -32,5 +31,4 @@ public function boot(Bootstrap $bootstrap)
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect('RobertLemke\Plugin\Blog\Controller\CommentController', 'commentCreated', 'RobertLemke\Plugin\Blog\Service\NotificationService', 'sendNewCommentNotification');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* source code.
*/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Aop\JoinPointInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;

/**
* Aspect for hotfixing rendering issues with XML content
Expand All @@ -22,13 +22,12 @@
*/
class RenderingFixingAspect
{

/**
* Makes sure that XML content (such as the RSS feed) is not wrapped with divs.
*
* @param JoinPointInterface $joinPoint
* @return string
* @Flow\Around("method(TYPO3\Neos\Service\ContentElementWrappingService->wrapContentObject())")
* @Flow\Around("method(Neos\Neos\Service\ContentElementWrappingService->wrapContentObject())")
*/
public function preventContentElementWraps(JoinPointInterface $joinPoint)
{
Expand All @@ -39,5 +38,4 @@ public function preventContentElementWraps(JoinPointInterface $joinPoint)

return $joinPoint->getAdviceChain()->proceed($joinPoint);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* source code.
*/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Resource\ResourceManager;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\ContentRepository\Domain\Model\NodeInterface;

/**
* A service which can render specific views of blog related content
Expand All @@ -22,7 +22,6 @@
*/
class ContentService
{

/**
* @Flow\Inject
* @var ResourceManager
Expand All @@ -31,7 +30,7 @@ class ContentService

/**
* Renders a teaser text with up to $maximumLength characters, with an outermost <p> and some more tags removed,
* from the given Node (fetches the first TYPO3.Neos.NodeTypes:Text childNode as a base).
* from the given Node (fetches the first Neos.NodeTypes:Text childNode as a base).
*
* If '<!-- read more -->' is found, the teaser will be the preceding content and $maximumLength is ignored.
*
Expand All @@ -44,7 +43,7 @@ public function renderTeaser(NodeInterface $node, $maximumLength = 500)
$stringToTruncate = '';

/** @var NodeInterface $contentNode */
foreach ($node->getNode('main')->getChildNodes('TYPO3.Neos.NodeTypes:Text') as $contentNode) {
foreach ($node->getNode('main')->getChildNodes('Neos.NodeTypes:Text') as $contentNode) {
foreach ($contentNode->getProperties() as $propertyValue) {
if (!is_object($propertyValue) || method_exists($propertyValue, '__toString')) {
$stringToTruncate .= $propertyValue;
Expand Down Expand Up @@ -79,23 +78,23 @@ public function renderContent(NodeInterface $node)
$content = '';

/** @var NodeInterface $contentNode */
foreach ($node->getNode('main')->getChildNodes('TYPO3.Neos:Content') as $contentNode) {
if ($contentNode->getNodeType()->isOfType('TYPO3.Neos.NodeTypes:TextWithImage')) {
foreach ($node->getNode('main')->getChildNodes('Neos.Neos:Content') as $contentNode) {
if ($contentNode->getNodeType()->isOfType('Neos.NodeTypes:TextWithImage')) {
$propertyValue = $contentNode->getProperty('image');
$attributes = array(
$attributes = [
'width="' . $propertyValue->getWidth() . '"',
'height="' . $propertyValue->getHeight() . '"',
'src="' . $this->resourceManager->getPublicPersistentResourceUri($propertyValue->getResource()) . '"'
);
];
$content .= $contentNode->getProperty('text');
$content .= '<img ' . implode(' ', $attributes) . '/>';
} elseif ($contentNode->getNodeType()->isOfType('TYPO3.Neos.NodeTypes:Image')) {
} elseif ($contentNode->getNodeType()->isOfType('Neos.NodeTypes:Image')) {
$propertyValue = $contentNode->getProperty('image');
$attributes = array(
$attributes = [
'width="' . $propertyValue->getWidth() . '"',
'height="' . $propertyValue->getHeight() . '"',
'src="' . $this->resourceManager->getPublicPersistentResourceUri($propertyValue->getResource()) . '"'
);
];
$content .= '<img ' . implode(' ', $attributes) . '/>';
} else {
foreach ($contentNode->getProperties() as $propertyValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* source code.
*/

use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Log\SystemLoggerInterface;
use TYPO3\SwiftMailer\Message;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\SwiftMailer\Message;
use Neos\ContentRepository\Domain\Model\NodeInterface;

/**
* A notification service
Expand All @@ -23,7 +23,6 @@
*/
class NotificationService
{

/**
* @var array
*/
Expand Down Expand Up @@ -57,23 +56,23 @@ public function sendNewCommentNotification(NodeInterface $commentNode, NodeInter
return;
}

if (!class_exists('TYPO3\SwiftMailer\Message')) {
$this->systemLogger->log('The package "TYPO3.SwiftMailer" is required to send notifications!');
if (!class_exists('Neos\SwiftMailer\Message')) {
$this->systemLogger->log('The package "Neos.SwiftMailer" is required to send notifications!');

return;
}

try {
$mail = new Message();
$mail
->setFrom(array($this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']))
->setReplyTo(array($commentNode->getProperty('emailAddress') => $commentNode->getProperty('author')))
->setTo(array($this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']))
->setFrom([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setReplyTo([$commentNode->getProperty('emailAddress') => $commentNode->getProperty('author')])
->setTo([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setSubject('New comment on blog post "' . $postNode->getProperty('title') . '"' . ($commentNode->getProperty('spam') ? ' (SPAM)' : ''))
->setBody($commentNode->getProperty('text'))
->send();
} catch (\Exception $e) {
$this->systemLogger->logException($e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/

use RobertLemke\Plugin\Blog\Service\ContentService;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\TYPO3CR\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\ContentRepository\Domain\Model\NodeInterface;

/**
* This view helper crops the text of a blog post in a meaningful way.
Expand All @@ -23,7 +23,6 @@
*/
class TeaserViewHelper extends AbstractViewHelper
{

/**
* @var boolean
*/
Expand Down
Loading

0 comments on commit 10151e7

Please sign in to comment.