Added Feed loop to retreive feeds using SimplePie
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
<loops>
|
||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||
<loop class="Thelia\Core\Template\Loop\Feed" name="feed"/>
|
||||
</loops>
|
||||
|
||||
|
||||
|
||||
41
core/lib/Thelia/Core/Security/Role/Role.php
Normal file
41
core/lib/Thelia/Core/Security/Role/Role.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace use Thelia\Core\Security\Role;
|
||||
|
||||
/**
|
||||
* Role is a simple implementation of a RoleInterface where the role is a
|
||||
* string.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Role implements RoleInterface
|
||||
{
|
||||
private $role;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $role The role name
|
||||
*/
|
||||
public function __construct($role)
|
||||
{
|
||||
$this->role = (string) $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRole()
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
}
|
||||
35
core/lib/Thelia/Core/Security/Role/RoleInterface.php
Normal file
35
core/lib/Thelia/Core/Security/Role/RoleInterface.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Thelia\Core\Security\Role;
|
||||
|
||||
/**
|
||||
* RoleInterface represents a role granted to a user.
|
||||
*
|
||||
* A role must either have a string representation or it needs to be explicitly
|
||||
* supported by at least one AccessDecisionManager.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface RoleInterface
|
||||
{
|
||||
/**
|
||||
* Returns the role.
|
||||
*
|
||||
* This method returns a string representation whenever possible.
|
||||
*
|
||||
* When the role cannot be represented with sufficient precision by a
|
||||
* string, it should return null.
|
||||
*
|
||||
* @return string|null A string representation of the role, or null
|
||||
*/
|
||||
public function getRole();
|
||||
}
|
||||
@@ -30,6 +30,20 @@ interface UserInterface {
|
||||
*/
|
||||
public function getAlgo();
|
||||
|
||||
/**
|
||||
* Returns the roles granted to the user.
|
||||
*
|
||||
* <code>
|
||||
* public function getRoles()
|
||||
* {
|
||||
* return array('ROLE_USER');
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @return Role[] The user roles
|
||||
*/
|
||||
public function getRoles();
|
||||
|
||||
/**
|
||||
* Removes sensitive data from the user.
|
||||
*
|
||||
|
||||
127
core/lib/Thelia/Core/Template/Loop/Feed.php
Normal file
127
core/lib/Thelia/Core/Template/Loop/Feed.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Core\Template\Loop;
|
||||
|
||||
use Thelia\Core\Template\Element\BaseLoop;
|
||||
use Thelia\Core\Template\Element\LoopResult;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Type\TypeCollection;
|
||||
use Thelia\Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Thelia\Core\Template\Loop
|
||||
*
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class Feed extends BaseLoop
|
||||
{
|
||||
|
||||
public $url;
|
||||
public $limit;
|
||||
public $timeout;
|
||||
|
||||
public function defineArgs()
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
new Argument(
|
||||
'url',
|
||||
new TypeCollection(new Type\AnyType())
|
||||
),
|
||||
new Argument(
|
||||
'limit',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
3
|
||||
),
|
||||
new Argument(
|
||||
'timeout',
|
||||
new TypeCollection(
|
||||
new Type\IntType()
|
||||
),
|
||||
10
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
public function exec()
|
||||
{
|
||||
$cachedir = THELIA_ROOT . 'cache/feeds';
|
||||
|
||||
if (! is_dir($cachedir)) {
|
||||
if (! mkdir($cachedir)) {
|
||||
throw new \Exception(sprintf("Failed to create cache directory '%s'", $cachedir));
|
||||
}
|
||||
}
|
||||
|
||||
$feed = new \SimplePie($this->url, THELIA_ROOT . 'cache/feeds');
|
||||
|
||||
$feed->init();
|
||||
|
||||
$feed->handle_content_type();
|
||||
|
||||
$feed->set_timeout($this->timeout);
|
||||
|
||||
$items = $feed->get_items();
|
||||
|
||||
$limit = min(count($tab), $this->limit);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
for($idx = 0; $idx < $this->limit; $idx++) {
|
||||
|
||||
$item = $items[$idx];
|
||||
|
||||
$link = $item->get_permalink();
|
||||
|
||||
$title = $item->get_title();
|
||||
$author = $item->get_author();
|
||||
$description = $item->get_description();
|
||||
|
||||
$date = $item->get_date('d/m/Y');
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
|
||||
$loopResultRow->set("URL", $item->get_permalink());
|
||||
$loopResultRow->set("TITLE", $item->get_title());
|
||||
$loopResultRow->set("AUTHOR", $item->get_author());
|
||||
$loopResultRow->set("DESCRIPTION", $item->get_description());
|
||||
$loopResultRow->set("DATE", $item->get_date('d/m/Y')); // FIXME - date format should be an intl parameter
|
||||
|
||||
$loopResult->addRow($loopResultRow);
|
||||
}
|
||||
|
||||
return $loopResult;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\om\BaseAdmin;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Thelia\Core\Security\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'admin' table.
|
||||
@@ -36,7 +36,7 @@ class Admin extends BaseAdmin implements UserInterface
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRoles() {
|
||||
return array(new Role('USER_CUSTOMER'));
|
||||
return array(new Role('USER_ADMIN'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
use Thelia\Model\om\BaseCustomer;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Thelia\Core\Security\User\UserInterface;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user