mirror of
https://github.com/moparisthebest/wallabag
synced 2024-10-31 15:35:05 -04:00
Symfony + MongoDB refactoring
This commit is contained in:
parent
6405fdea2a
commit
44dd68762a
@ -15,12 +15,16 @@ class AppKernel extends Kernel
|
||||
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
|
||||
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
|
||||
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
|
||||
new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(),
|
||||
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
|
||||
new FOS\UserBundle\FOSUserBundle(),
|
||||
new FOS\RestBundle\FOSRestBundle(),
|
||||
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
|
||||
new JMS\AopBundle\JMSAopBundle(),
|
||||
new JMS\SerializerBundle\JMSSerializerBundle(),
|
||||
new Wallabag\Bundle\CoreBundle\WallabagCoreBundle(),
|
||||
new Wallabag\Bundle\ApiBundle\WallabagApiBundle(),
|
||||
new Wallabag\Bundle\CliBundle\WallabagCliBundle(),
|
||||
new Wallabag\Bundle\ReadabilityBundle\WallabagReadabilityBundle(),
|
||||
);
|
||||
|
||||
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
|
||||
|
@ -9,5 +9,6 @@ use Composer\Autoload\ClassLoader;
|
||||
$loader = require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
|
||||
\Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::registerAnnotationClasses();
|
||||
|
||||
return $loader;
|
||||
|
148
app/check.php
148
app/check.php
@ -2,61 +2,141 @@
|
||||
|
||||
require_once dirname(__FILE__).'/SymfonyRequirements.php';
|
||||
|
||||
$lineSize = 70;
|
||||
$symfonyRequirements = new SymfonyRequirements();
|
||||
|
||||
$iniPath = $symfonyRequirements->getPhpIniConfigPath();
|
||||
|
||||
echo "********************************\n";
|
||||
echo "* *\n";
|
||||
echo "* Symfony requirements check *\n";
|
||||
echo "* *\n";
|
||||
echo "********************************\n\n";
|
||||
echo_title('Symfony2 Requirements Checker');
|
||||
|
||||
echo $iniPath ? sprintf("* Configuration file used by PHP: %s\n\n", $iniPath) : "* WARNING: No configuration file (php.ini) used by PHP!\n\n";
|
||||
|
||||
echo "** ATTENTION **\n";
|
||||
echo "* The PHP CLI can use a different php.ini file\n";
|
||||
echo "* than the one used with your web server.\n";
|
||||
if ('\\' == DIRECTORY_SEPARATOR) {
|
||||
echo "* (especially on the Windows platform)\n";
|
||||
echo '> PHP is using the following php.ini file:'.PHP_EOL;
|
||||
if ($iniPath) {
|
||||
echo_style('green', ' '.$iniPath);
|
||||
} else {
|
||||
echo_style('warning', ' WARNING: No configuration file (php.ini) used by PHP!');
|
||||
}
|
||||
echo "* To be on the safe side, please also launch the requirements check\n";
|
||||
echo "* from your web server using the web/config.php script.\n";
|
||||
|
||||
echo_title('Mandatory requirements');
|
||||
echo PHP_EOL.PHP_EOL;
|
||||
|
||||
$checkPassed = true;
|
||||
echo '> Checking Symfony requirements:'.PHP_EOL.' ';
|
||||
|
||||
$messages = array();
|
||||
foreach ($symfonyRequirements->getRequirements() as $req) {
|
||||
/** @var $req Requirement */
|
||||
echo_requirement($req);
|
||||
if (!$req->isFulfilled()) {
|
||||
$checkPassed = false;
|
||||
if ($helpText = get_error_message($req, $lineSize)) {
|
||||
echo_style('red', 'E');
|
||||
$messages['error'][] = $helpText;
|
||||
} else {
|
||||
echo_style('green', '.');
|
||||
}
|
||||
}
|
||||
|
||||
echo_title('Optional recommendations');
|
||||
$checkPassed = empty($messages['error']);
|
||||
|
||||
foreach ($symfonyRequirements->getRecommendations() as $req) {
|
||||
echo_requirement($req);
|
||||
if ($helpText = get_error_message($req, $lineSize)) {
|
||||
echo_style('yellow', 'W');
|
||||
$messages['warning'][] = $helpText;
|
||||
} else {
|
||||
echo_style('green', '.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($checkPassed) {
|
||||
echo_block('success', 'OK', 'Your system is ready to run Symfony2 projects', true);
|
||||
} else {
|
||||
echo_block('error', 'ERROR', 'Your system is not ready to run Symfony2 projects', true);
|
||||
|
||||
echo_title('Fix the following mandatory requirements', 'red');
|
||||
|
||||
foreach ($messages['error'] as $helpText) {
|
||||
echo ' * '.$helpText.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($messages['warning'])) {
|
||||
echo_title('Optional recommendations to improve your setup', 'yellow');
|
||||
|
||||
foreach ($messages['warning'] as $helpText) {
|
||||
echo ' * '.$helpText.PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
echo_style('title', 'Note');
|
||||
echo ' The command console could use a different php.ini file'.PHP_EOL;
|
||||
echo_style('title', '~~~~');
|
||||
echo ' than the one used with your web server. To be on the'.PHP_EOL;
|
||||
echo ' safe side, please check the requirements from your web'.PHP_EOL;
|
||||
echo ' server using the ';
|
||||
echo_style('yellow', 'web/config.php');
|
||||
echo ' script.'.PHP_EOL;
|
||||
echo PHP_EOL;
|
||||
|
||||
exit($checkPassed ? 0 : 1);
|
||||
|
||||
/**
|
||||
* Prints a Requirement instance
|
||||
*/
|
||||
function echo_requirement(Requirement $requirement)
|
||||
function get_error_message(Requirement $requirement, $lineSize)
|
||||
{
|
||||
$result = $requirement->isFulfilled() ? 'OK' : ($requirement->isOptional() ? 'WARNING' : 'ERROR');
|
||||
echo ' ' . str_pad($result, 9);
|
||||
echo $requirement->getTestMessage() . "\n";
|
||||
|
||||
if (!$requirement->isFulfilled()) {
|
||||
echo sprintf(" %s\n\n", $requirement->getHelpText());
|
||||
if ($requirement->isFulfilled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
|
||||
$errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
|
||||
|
||||
return $errorMessage;
|
||||
}
|
||||
|
||||
function echo_title($title)
|
||||
function echo_title($title, $style = null)
|
||||
{
|
||||
echo "\n** $title **\n\n";
|
||||
$style = $style ?: 'title';
|
||||
|
||||
echo PHP_EOL;
|
||||
echo_style($style, $title.PHP_EOL);
|
||||
echo_style($style, str_repeat('~', strlen($title)).PHP_EOL);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
|
||||
function echo_style($style, $message)
|
||||
{
|
||||
// ANSI color codes
|
||||
$styles = array(
|
||||
'reset' => "\033[0m",
|
||||
'red' => "\033[31m",
|
||||
'green' => "\033[32m",
|
||||
'yellow' => "\033[33m",
|
||||
'error' => "\033[37;41m",
|
||||
'success' => "\033[37;42m",
|
||||
'title' => "\033[34m",
|
||||
);
|
||||
$supports = has_color_support();
|
||||
|
||||
echo ($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
|
||||
}
|
||||
|
||||
function echo_block($style, $title, $message)
|
||||
{
|
||||
$message = ' '.trim($message).' ';
|
||||
$width = strlen($message);
|
||||
|
||||
echo PHP_EOL.PHP_EOL;
|
||||
|
||||
echo_style($style, str_repeat(' ', $width).PHP_EOL);
|
||||
echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT).PHP_EOL);
|
||||
echo_style($style, str_pad($message, $width, ' ', STR_PAD_RIGHT).PHP_EOL);
|
||||
echo_style($style, str_repeat(' ', $width).PHP_EOL);
|
||||
}
|
||||
|
||||
function has_color_support()
|
||||
{
|
||||
static $support;
|
||||
|
||||
if (null === $support) {
|
||||
if (DIRECTORY_SEPARATOR == '\\') {
|
||||
$support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
|
||||
} else {
|
||||
$support = function_exists('posix_isatty') && @posix_isatty(STDOUT);
|
||||
}
|
||||
}
|
||||
|
||||
return $support;
|
||||
}
|
||||
|
@ -60,6 +60,17 @@ doctrine:
|
||||
auto_generate_proxy_classes: "%kernel.debug%"
|
||||
auto_mapping: true
|
||||
|
||||
# app/config/config.yml
|
||||
doctrine_mongodb:
|
||||
connections:
|
||||
default:
|
||||
server: mongodb://localhost:27017
|
||||
options: {}
|
||||
default_database: wallabag
|
||||
document_managers:
|
||||
default:
|
||||
auto_mapping: true
|
||||
|
||||
# Swiftmailer Configuration
|
||||
swiftmailer:
|
||||
transport: "%mailer_transport%"
|
||||
@ -68,8 +79,28 @@ swiftmailer:
|
||||
password: "%mailer_password%"
|
||||
spool: { type: memory }
|
||||
|
||||
fos_rest:
|
||||
body_converter:
|
||||
enabled: false
|
||||
view:
|
||||
view_response_listener: true
|
||||
format_listener:
|
||||
rules:
|
||||
# setting fallback_format to json means that instead of considering the next rule in case of a priority mismatch, json will be used
|
||||
- { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: false }
|
||||
|
||||
|
||||
# FOS User Configuration
|
||||
fos_user:
|
||||
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
|
||||
db_driver: mongodb # other valid values are 'mongodb', 'couchdb' and 'propel'
|
||||
firewall_name: main
|
||||
user_class: Wallabag\CoreBundle\Entity\User
|
||||
user_class: Wallabag\CoreBundle\Document\User
|
||||
|
||||
jms_di_extra:
|
||||
locations:
|
||||
all_bundles: false
|
||||
bundles: [WallabagCoreBundle]
|
||||
directories: ["%kernel.root_dir%/../src"]
|
||||
|
||||
sensio_framework_extra:
|
||||
view: { annotations: false }
|
@ -11,7 +11,7 @@ wallabag_cli:
|
||||
wallabag_api:
|
||||
resource: "@WallabagApiBundle/Controller/"
|
||||
type: annotation
|
||||
prefix: /
|
||||
prefix: /api
|
||||
|
||||
wallabag_core:
|
||||
resource: "@WallabagCoreBundle/Controller/"
|
||||
|
@ -6,6 +6,20 @@
|
||||
"autoload": {
|
||||
"psr-0": { "": "src/", "SymfonyStandard": "app/" }
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "package",
|
||||
"package": {
|
||||
"name": "fivefilters/full-text-rss",
|
||||
"version": "dev-master",
|
||||
"source": {
|
||||
"url": "https://bitbucket.org/fivefilters/full-text-rss.git",
|
||||
"type": "git",
|
||||
"reference": "origin/master"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"symfony/symfony": "2.5.*",
|
||||
@ -20,7 +34,16 @@
|
||||
"incenteev/composer-parameter-handler": "~2.0",
|
||||
"fivefilters/php-readability": "v1.0",
|
||||
"friendsofsymfony/user-bundle": "2.0.x-dev",
|
||||
"simplepie/simplepie": "1.3.1"
|
||||
"friendsofsymfony/rest-bundle": "1.5.*@dev",
|
||||
"simplepie/simplepie": "1.3.1",
|
||||
"ezyang/htmlpurifier": "v4.6.0",
|
||||
"exercise/htmlpurifier-bundle": "1.0.x-dev",
|
||||
"mibe/feedwriter": "dev-master",
|
||||
"doctrine/mongodb-odm-bundle": "3.0.*@dev",
|
||||
"doctrine/mongodb-odm": "1.0.*@dev",
|
||||
"jms/di-extra-bundle": "1.4.*@dev",
|
||||
"jms/serializer-bundle": "0.13.*@dev",
|
||||
"fivefilters/full-text-rss": "dev-master"
|
||||
},
|
||||
"require-dev": {
|
||||
"sensio/generator-bundle": "~2.3"
|
||||
|
1170
composer.lock
generated
1170
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ApiBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/hello/{name}")
|
||||
* @Template()
|
||||
*/
|
||||
public function indexAction($name)
|
||||
{
|
||||
return array('name' => $name);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ApiBundle\Controller;
|
||||
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\View;
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Routing\Router;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Wallabag\Bundle\CoreBundle\Document\User;
|
||||
use Wallabag\Bundle\CoreBundle\Service\EntryService;
|
||||
|
||||
class EntriesController
|
||||
{
|
||||
/**
|
||||
* @var EntryService
|
||||
* @Inject("wallabag_core.entry")
|
||||
*/
|
||||
private $entryService;
|
||||
|
||||
/**
|
||||
* @var Router
|
||||
* @Inject("router")
|
||||
*/
|
||||
private $router;
|
||||
|
||||
/**
|
||||
* @Post("/u/{user}/entries")
|
||||
* @ParamConverter("user",options={"mapping": {"user": "username"}})
|
||||
* @View(statusCode=201)
|
||||
*/
|
||||
public function postAction(Request $request, User $user)
|
||||
{
|
||||
$url = $request->request->get("url");
|
||||
$tags = $request->request->get("tags");
|
||||
$entry = $this->entryService->save($user, $url, $tags);
|
||||
$view = \FOS\RestBundle\View\View::create();
|
||||
$view->setData($entry);
|
||||
$view->setStatusCode(Response::HTTP_CREATED);
|
||||
$view->setLocation($this->router->generate("wallabag_api_entry_get", array(
|
||||
"user" => $user->getUsername(),
|
||||
"entry" => $entry->getId()
|
||||
)));
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/u/{user}/entries", methods={"GET"})
|
||||
* @Get("/u/{user}", methods={"GET"})
|
||||
* @ParamConverter("user", options={"mapping": {"user": "username"}})
|
||||
* @View(statusCode=200, serializerGroups={"entries"})
|
||||
*/
|
||||
public function getAction(User $user) {
|
||||
return array_values($this->entryService->listForUser($user));
|
||||
}
|
||||
}
|
31
src/Wallabag/Bundle/ApiBundle/Controller/EntryController.php
Normal file
31
src/Wallabag/Bundle/ApiBundle/Controller/EntryController.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Wallabag\Bundle\ApiBundle\Controller;
|
||||
|
||||
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\View;
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Wallabag\Bundle\CoreBundle\Document\Entry;
|
||||
use Wallabag\Bundle\CoreBundle\Document\User;
|
||||
use Wallabag\Bundle\CoreBundle\Service\EntryService;
|
||||
|
||||
class EntryController {
|
||||
/**
|
||||
* @var EntryService
|
||||
* @Inject("wallabag_core.entry")
|
||||
*/
|
||||
private $entryService;
|
||||
|
||||
/**
|
||||
* @Get("/u/{user}/entry/{entry}", methods={"GET"})
|
||||
* @ParamConverter("user", options={"mapping": {"user": "username"}})
|
||||
* @ParamConverter("entry", options={"id"="entry"})
|
||||
* @View(statusCode=200, serializerGroups={"entries"})
|
||||
*/
|
||||
public function getAction(User $user, Entry $entry) {
|
||||
return $entry;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ApiBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Controller;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Wallabag\Bundle\CoreBundle\Document\User;
|
||||
use Wallabag\Bundle\CoreBundle\Service\EntryService;
|
||||
|
||||
class BookmarkController
|
||||
{
|
||||
/**
|
||||
* @var EntryService
|
||||
* @Inject("wallabag_core.bookmark")
|
||||
*/
|
||||
private $bookmarkService;
|
||||
|
||||
/**
|
||||
* @Route("/u/{user}/bookmarks", methods={"GET"})
|
||||
* @ParamConverter("user",options={"mapping": {"user": "username"}})
|
||||
* @Template(template="WallabagCoreBundle:Default:index.html.twig")
|
||||
*/
|
||||
public function saveAction(Request $request, User $user)
|
||||
{
|
||||
$url = $request->get("url");
|
||||
$this->bookmarkService->save($user, $url);
|
||||
return array('name' => 'Fabien');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/u/{user}", methods={"GET"})
|
||||
* @ParamConverter("user", options={"mapping": {"user": "username"}})
|
||||
* @Template(template="WallabagCoreBundle:Default:index.html.twig")
|
||||
*/
|
||||
public function listAction(Request $request, User $user) {
|
||||
$list = $this->bookmarkService->listForUser($user);
|
||||
foreach($list as $item) {
|
||||
var_dump($item);
|
||||
}
|
||||
die;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/hello/{name}")
|
||||
* @Template()
|
||||
*/
|
||||
public function indexAction($name)
|
||||
{
|
||||
return array('name' => $name);
|
||||
}
|
||||
}
|
316
src/Wallabag/Bundle/CoreBundle/Document/Entry.php
Normal file
316
src/Wallabag/Bundle/CoreBundle/Document/Entry.php
Normal file
@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Document;
|
||||
|
||||
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
|
||||
use JMS\Serializer\Annotation\Expose;
|
||||
use JMS\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* Entry
|
||||
*
|
||||
* @MongoDB\Document(repositoryClass="Wallabag\Bundle\CoreBundle\Repository\EntryRepository")
|
||||
*/
|
||||
class Entry
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @MongoDB\Id(strategy="auto")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @MongoDB\ReferenceOne(targetDocument="Wallabag\Bundle\CoreBundle\Document\User")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @MongoDB\Date
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @var Tag[]
|
||||
* @MongoDB\EmbedMany(targetDocument="Wallabag\Bundle\CoreBundle\Document\Tag")
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $tags;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @MongoDB\Boolean
|
||||
*/
|
||||
private $archived;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @MongoDB\Boolean
|
||||
*/
|
||||
private $deleted;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
* @MongoDB\Boolean
|
||||
*/
|
||||
private $starred;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->tags = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set url
|
||||
*
|
||||
* @param string $url
|
||||
* @return Entry
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title
|
||||
*
|
||||
* @param string $title
|
||||
* @return Entry
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content
|
||||
*
|
||||
* @param string $content
|
||||
* @return Entry
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set createdAt
|
||||
*
|
||||
* @param \DateTime $createdAt
|
||||
* @return self
|
||||
*/
|
||||
public function setCreatedAt($createdAt)
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Get createdAt
|
||||
*
|
||||
* @return \DateTime $createdAt
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag
|
||||
*
|
||||
* @param \Wallabag\Bundle\CoreBundle\Document\Tag $tag
|
||||
*/
|
||||
public function addTag(\Wallabag\Bundle\CoreBundle\Document\Tag $tag)
|
||||
{
|
||||
$this->tags[] = $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tag
|
||||
*
|
||||
* @param \Wallabag\Bundle\CoreBundle\Document\Tag $tag
|
||||
*/
|
||||
public function removeTag(\Wallabag\Bundle\CoreBundle\Document\Tag $tag)
|
||||
{
|
||||
$this->tags->removeElement($tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tags
|
||||
*
|
||||
* @return Tag[] $tags
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set archived
|
||||
*
|
||||
* @param boolean $archived
|
||||
* @return self
|
||||
*/
|
||||
public function setArchived($archived)
|
||||
{
|
||||
$this->archived = $archived;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get archived
|
||||
*
|
||||
* @return boolean $archived
|
||||
*/
|
||||
public function getArchived()
|
||||
{
|
||||
return $this->archived;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set deleted
|
||||
*
|
||||
* @param boolean $deleted
|
||||
* @return self
|
||||
*/
|
||||
public function setDeleted($deleted)
|
||||
{
|
||||
$this->deleted = $deleted;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get deleted
|
||||
*
|
||||
* @return boolean $deleted
|
||||
*/
|
||||
public function getDeleted()
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set starred
|
||||
*
|
||||
* @param boolean $starred
|
||||
* @return self
|
||||
*/
|
||||
public function setStarred($starred)
|
||||
{
|
||||
$this->starred = $starred;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get starred
|
||||
*
|
||||
* @return boolean $starred
|
||||
*/
|
||||
public function getStarred()
|
||||
{
|
||||
return $this->starred;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user
|
||||
*
|
||||
* @param User $user
|
||||
* @return self
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user
|
||||
*
|
||||
* @return User $user
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
}
|
125
src/Wallabag/Bundle/CoreBundle/Document/Preference.php
Normal file
125
src/Wallabag/Bundle/CoreBundle/Document/Preference.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Document;
|
||||
|
||||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
|
||||
|
||||
/**
|
||||
* Class Preference
|
||||
* @package Wallabag\Bundle\CoreBundle\Document
|
||||
* @MongoDB\EmbeddedDocument
|
||||
*/
|
||||
class Preference {
|
||||
/**
|
||||
* @var string
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $locale;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @MongoDB\Int
|
||||
*/
|
||||
private $pageSize;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $sortDirection = 'asc';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $theme = 'original';
|
||||
|
||||
/**
|
||||
* Set locale
|
||||
*
|
||||
* @param string $locale
|
||||
* @return self
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get locale
|
||||
*
|
||||
* @return string $locale
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set pageSize
|
||||
*
|
||||
* @param int $pageSize
|
||||
* @return self
|
||||
*/
|
||||
public function setPageSize($pageSize)
|
||||
{
|
||||
$this->pageSize = $pageSize;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pageSize
|
||||
*
|
||||
* @return int $pageSize
|
||||
*/
|
||||
public function getPageSize()
|
||||
{
|
||||
return $this->pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sortDirection
|
||||
*
|
||||
* @param string $sortDirection
|
||||
* @return self
|
||||
*/
|
||||
public function setSortDirection($sortDirection)
|
||||
{
|
||||
$this->sortDirection = $sortDirection;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sortDirection
|
||||
*
|
||||
* @return string $sortDirection
|
||||
*/
|
||||
public function getSortDirection()
|
||||
{
|
||||
return $this->sortDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set theme
|
||||
*
|
||||
* @param string $theme
|
||||
* @return self
|
||||
*/
|
||||
public function setTheme($theme)
|
||||
{
|
||||
$this->theme = $theme;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme
|
||||
*
|
||||
* @return string $theme
|
||||
*/
|
||||
public function getTheme()
|
||||
{
|
||||
return $this->theme;
|
||||
}
|
||||
}
|
53
src/Wallabag/Bundle/CoreBundle/Document/Tag.php
Normal file
53
src/Wallabag/Bundle/CoreBundle/Document/Tag.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Document;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
|
||||
use JMS\Serializer\Annotation\Expose;
|
||||
use JMS\Serializer\Annotation\Groups;
|
||||
|
||||
/**
|
||||
* Tag
|
||||
*
|
||||
* @MongoDB\EmbeddedDocument
|
||||
*/
|
||||
class Tag
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
* @Expose
|
||||
* @Groups({"entries"})
|
||||
*/
|
||||
private $value;
|
||||
|
||||
function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param string $value
|
||||
* @return Tag
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
157
src/Wallabag/Bundle/CoreBundle/Document/User.php
Normal file
157
src/Wallabag/Bundle/CoreBundle/Document/User.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Document;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
|
||||
use FOS\UserBundle\Model\User as BaseUser;
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @MongoDB\Document
|
||||
*/
|
||||
class User extends BaseUser
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @MongoDB\Id(strategy="auto")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $apiToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $feedToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $authGoogleToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @MongoDB\String
|
||||
*/
|
||||
private $authMozillaToken;
|
||||
|
||||
/**
|
||||
* @var Preference
|
||||
*
|
||||
* @MongoDB\EmbedOne(targetDocument="\Wallabag\Bundle\CoreBundle\Document\Preference")
|
||||
*/
|
||||
private $preferences;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiToken()
|
||||
{
|
||||
return $this->apiToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $apiToken
|
||||
*/
|
||||
public function setApiToken($apiToken)
|
||||
{
|
||||
$this->apiToken = $apiToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthGoogleToken()
|
||||
{
|
||||
return $this->authGoogleToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $authGoogleToken
|
||||
*/
|
||||
public function setAuthGoogleToken($authGoogleToken)
|
||||
{
|
||||
$this->authGoogleToken = $authGoogleToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthMozillaToken()
|
||||
{
|
||||
return $this->authMozillaToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $authMozillaToken
|
||||
*/
|
||||
public function setAuthMozillaToken($authMozillaToken)
|
||||
{
|
||||
$this->authMozillaToken = $authMozillaToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFeedToken()
|
||||
{
|
||||
return $this->feedToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $feedToken
|
||||
*/
|
||||
public function setFeedToken($feedToken)
|
||||
{
|
||||
$this->feedToken = $feedToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set preferences
|
||||
*
|
||||
* @param \Wallabag\Bundle\CoreBundle\Document\Preference $preferences
|
||||
* @return self
|
||||
*/
|
||||
public function setPreferences(Preference $preferences)
|
||||
{
|
||||
$this->preferences = $preferences;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get preferences
|
||||
*
|
||||
* @return \Wallabag\Bundle\CoreBundle\Document\Preference $preferences
|
||||
*/
|
||||
public function getPreferences()
|
||||
{
|
||||
return $this->preferences;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Config
|
||||
*
|
||||
* @ORM\Table()
|
||||
* @ORM\Entity(repositoryClass="Wallabag\Bundle\CoreBundle\Repository\ConfigRepository")
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=255)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="value", type="text")
|
||||
*/
|
||||
private $value;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
* @return Config
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param string $value
|
||||
* @return Config
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -1,294 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Entry
|
||||
*
|
||||
* @ORM\Table(indexes={@ORM\Index(name="idx_status", columns={"status"})})
|
||||
* @ORM\Entity(repositoryClass="Wallabag\Bundle\CoreBundle\Repository\EntryRepository")
|
||||
*/
|
||||
class Entry
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="url", type="text")
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="title", type="text")
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="content", type="text")
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="updated", type="boolean")
|
||||
*/
|
||||
private $updated;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="status", type="string", length=255)
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="bookmark", type="boolean")
|
||||
*/
|
||||
private $bookmark;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*
|
||||
* @ORM\Column(name="fetched", type="boolean")
|
||||
*/
|
||||
private $fetched;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Wallabag\Bundle\CoreBundle\Entity\User")
|
||||
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\ManyToMany(targetEntity="Wallabag\Bundle\CoreBundle\Entity\Tag")
|
||||
* @ORM\JoinTable(name="tags_entries",
|
||||
* joinColumns={@ORM\JoinColumn(name="entry_id", referencedColumnName="id")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")})
|
||||
*/
|
||||
private $tags;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set url
|
||||
*
|
||||
* @param string $url
|
||||
* @return Entry
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title
|
||||
*
|
||||
* @param string $title
|
||||
* @return Entry
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set content
|
||||
*
|
||||
* @param string $content
|
||||
* @return Entry
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set updated
|
||||
*
|
||||
* @param boolean $updated
|
||||
* @return Entry
|
||||
*/
|
||||
public function setUpdated($updated)
|
||||
{
|
||||
$this->updated = $updated;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updated
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getUpdated()
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set status
|
||||
*
|
||||
* @param string $status
|
||||
* @return Entry
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bookmark
|
||||
*
|
||||
* @param boolean $bookmark
|
||||
* @return Entry
|
||||
*/
|
||||
public function setBookmark($bookmark)
|
||||
{
|
||||
$this->bookmark = $bookmark;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bookmark
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getBookmark()
|
||||
{
|
||||
return $this->bookmark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set fetched
|
||||
*
|
||||
* @param boolean $fetched
|
||||
* @return Entry
|
||||
*/
|
||||
public function setFetched($fetched)
|
||||
{
|
||||
$this->fetched = $fetched;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fetched
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getFetched()
|
||||
{
|
||||
return $this->fetched;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $tags
|
||||
*/
|
||||
public function setTags($tags)
|
||||
{
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* PluginOption
|
||||
*
|
||||
* @ORM\Table()
|
||||
* @ORM\Entity(repositoryClass="Wallabag\Bundle\CoreBundle\Entity\PluginOptionRepository")
|
||||
*/
|
||||
class PluginOption
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="name", type="string", length=255)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="value", type="text")
|
||||
*/
|
||||
private $value;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string $name
|
||||
* @return PluginOption
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param string $value
|
||||
* @return PluginOption
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Tag
|
||||
*
|
||||
* @ORM\Table()
|
||||
* @ORM\Entity(repositoryClass="Wallabag\Bundle\CoreBundle\Repository\TagRepository")
|
||||
*/
|
||||
class Tag
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="value", type="string", length=255)
|
||||
*/
|
||||
private $value;
|
||||
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param string $value
|
||||
* @return Tag
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -1,223 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use FOS\UserBundle\Model\User as BaseUser;
|
||||
|
||||
/**
|
||||
* User
|
||||
*
|
||||
* @ORM\Table()
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class User extends BaseUser
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="preferred_locale", type="string", length=5)
|
||||
*/
|
||||
private $preferredLocale;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Column(name="items_per_page", type="integer")
|
||||
*/
|
||||
private $itemsPerPage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="theme", type="string")
|
||||
*/
|
||||
private $theme = 'original';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="items_sorting_direction", type="string")
|
||||
*/
|
||||
private $itemsSortingDirection = 'asc';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="api_token", type="string")
|
||||
*/
|
||||
private $apiToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="feed_token", type="string")
|
||||
*/
|
||||
private $feedToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="auth_google_token", type="string")
|
||||
*/
|
||||
private $authGoogleToken;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(name="auth_mozilla_token", type="string")
|
||||
*/
|
||||
private $authMozillaToken;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPreferredLocale()
|
||||
{
|
||||
return $this->preferredLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $preferredLocale
|
||||
*/
|
||||
public function setPreferredLocale($preferredLocale)
|
||||
{
|
||||
$this->preferredLocale = $preferredLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiToken()
|
||||
{
|
||||
return $this->apiToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $apiToken
|
||||
*/
|
||||
public function setApiToken($apiToken)
|
||||
{
|
||||
$this->apiToken = $apiToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthGoogleToken()
|
||||
{
|
||||
return $this->authGoogleToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $authGoogleToken
|
||||
*/
|
||||
public function setAuthGoogleToken($authGoogleToken)
|
||||
{
|
||||
$this->authGoogleToken = $authGoogleToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthMozillaToken()
|
||||
{
|
||||
return $this->authMozillaToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $authMozillaToken
|
||||
*/
|
||||
public function setAuthMozillaToken($authMozillaToken)
|
||||
{
|
||||
$this->authMozillaToken = $authMozillaToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFeedToken()
|
||||
{
|
||||
return $this->feedToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $feedToken
|
||||
*/
|
||||
public function setFeedToken($feedToken)
|
||||
{
|
||||
$this->feedToken = $feedToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getItemsPerPage()
|
||||
{
|
||||
return $this->itemsPerPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $itemsPerPage
|
||||
*/
|
||||
public function setItemsPerPage($itemsPerPage)
|
||||
{
|
||||
$this->itemsPerPage = $itemsPerPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getItemsSortingDirection()
|
||||
{
|
||||
return $this->itemsSortingDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $itemsSortingDirection
|
||||
*/
|
||||
public function setItemsSortingDirection($itemsSortingDirection)
|
||||
{
|
||||
$this->itemsSortingDirection = $itemsSortingDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTheme()
|
||||
{
|
||||
return $this->theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $theme
|
||||
*/
|
||||
public function setTheme($theme)
|
||||
{
|
||||
$this->theme = $theme;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* ConfigRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class ConfigRepository extends EntityRepository
|
||||
{
|
||||
}
|
@ -2,14 +2,45 @@
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ODM\MongoDB\DocumentRepository;
|
||||
use Wallabag\Bundle\CoreBundle\Document\Entry;
|
||||
|
||||
/**
|
||||
* EntryRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class EntryRepository extends EntityRepository
|
||||
class EntryRepository extends DocumentRepository
|
||||
{
|
||||
/**
|
||||
* Find all unread bookmarks for a given user
|
||||
*
|
||||
* @param string $userId the user ID
|
||||
* @return Bookmark[]
|
||||
*/
|
||||
public function findUnreadByUser($userId) {
|
||||
return $this->createQueryBuilder('Wallabag\Bundle\CoreBundle\Document\Entry')
|
||||
->field('user.$id')
|
||||
->equals(new \MongoId($userId))
|
||||
->field('archived')
|
||||
->equals(false)
|
||||
->sort('createdAt', 'desc')
|
||||
->eagerCursor()
|
||||
->getQuery()
|
||||
->execute()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* @param $url
|
||||
* @return Entry
|
||||
*/
|
||||
public function findOneByUserAndUrl($userId, $url) {
|
||||
return $this->createQueryBuilder('Wallabag\Bundle\CoreBundle\Document\Entry')
|
||||
->field('user.$id')
|
||||
->equals(new \MongoId($userId))
|
||||
->field('url')
|
||||
->equals($url)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* PluginOptionRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class PluginOptionRepository extends EntityRepository
|
||||
{
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Repository;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* TagRepository
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class TagRepository extends EntityRepository
|
||||
{
|
||||
}
|
@ -4,17 +4,10 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<!--
|
||||
<parameters>
|
||||
<parameter key="wallabag_core.example.class">Wallabag\Bundle\CoreBundle\Example</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="wallabag_core.example" class="%wallabag_core.example.class%">
|
||||
<argument type="service" id="service_id" />
|
||||
<argument>plain_value</argument>
|
||||
<argument>%parameter_name%</argument>
|
||||
<service id="doctrine_mongo_db_param_converter" class="Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter">
|
||||
<argument type="service" id="doctrine_mongodb" />
|
||||
<tag name="request.param_converter" converter="doctrine.odm" />
|
||||
</service>
|
||||
</services>
|
||||
-->
|
||||
</container>
|
||||
|
67
src/Wallabag/Bundle/CoreBundle/Service/EntryService.php
Normal file
67
src/Wallabag/Bundle/CoreBundle/Service/EntryService.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Service;
|
||||
|
||||
use Doctrine\ODM\MongoDB\DocumentManager;
|
||||
use JMS\DiExtraBundle\Annotation\InjectParams;
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
use JMS\DiExtraBundle\Annotation\Service;
|
||||
use Wallabag\Bundle\CoreBundle\Document\Bookmark;
|
||||
use Wallabag\Bundle\CoreBundle\Document\Entry;
|
||||
use Wallabag\Bundle\CoreBundle\Document\Tag;
|
||||
use Wallabag\Bundle\CoreBundle\Document\User;
|
||||
|
||||
/**
|
||||
* Class BookmarkService
|
||||
* @package Wallabag\Bundle\CoreBundle\Service
|
||||
* @Service(id="wallabag_core.entry")
|
||||
*/
|
||||
class EntryService {
|
||||
/**
|
||||
* @var DocumentManager
|
||||
*/
|
||||
private $dm;
|
||||
|
||||
/**
|
||||
* @InjectParams({
|
||||
* "dm" = @Inject("doctrine_mongodb.odm.document_manager")
|
||||
* })
|
||||
* @param DocumentManager $dm
|
||||
*/
|
||||
public function __construct(DocumentManager $dm) {
|
||||
$this->dm = $dm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $url
|
||||
* @param string[] $tags
|
||||
* @return Entry the created entry
|
||||
*/
|
||||
public function save(User $user, $url, $tags = array()) {
|
||||
$entry = new Entry();
|
||||
$entry->setUser($user);
|
||||
$entry->setUrl($url);
|
||||
$entry->setCreatedAt(new \DateTime());
|
||||
$entry->setContent("Fixture content");
|
||||
$entry->setTitle("Fixture title");
|
||||
$entry->setArchived(false);
|
||||
$entry->setDeleted(false);
|
||||
$entry->setStarred(false);
|
||||
|
||||
foreach($tags as $tag) {
|
||||
$entry->addTag(new Tag($tag));
|
||||
}
|
||||
|
||||
$this->dm->persist($entry);
|
||||
$this->dm->flush();
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public function listForUser(User $user) {
|
||||
$bookmarkRepository = $this->dm->getRepository('\Wallabag\Bundle\CoreBundle\Document\Entry');
|
||||
return $bookmarkRepository->findUnreadByUser($user->getId());
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
|
||||
}
|
||||
}
|
9
src/Wallabag/Bundle/CoreBundle/Url/UrlFetcher.php
Normal file
9
src/Wallabag/Bundle/CoreBundle/Url/UrlFetcher.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Wallabag\Bundle\CoreBundle\Url;
|
||||
|
||||
|
||||
interface UrlFetcher {
|
||||
public function fetch($url, $max, $links);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/hello/{name}")
|
||||
* @Template()
|
||||
*/
|
||||
public function indexAction($name)
|
||||
{
|
||||
return array('name' => $name);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This is the class that validates and merges configuration from your app/config files
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('wallabag_readability');
|
||||
|
||||
// Here you should define the parameters that are allowed to
|
||||
// configure your bundle. See the documentation linked above for
|
||||
// more information on that topic.
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration
|
||||
*
|
||||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
|
||||
*/
|
||||
class WallabagReadabilityExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.xml');
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Readability;
|
||||
|
||||
class WallabagReadability extends \Readability
|
||||
{
|
||||
/**
|
||||
* Get the article title as an H1.
|
||||
*
|
||||
* @return DOMElement
|
||||
*/
|
||||
protected function getArticleTitle() {
|
||||
$curTitle = '';
|
||||
$origTitle = '';
|
||||
|
||||
try {
|
||||
$curTitle = $origTitle = $this->getInnerText($this->dom->getElementsByTagName('title')->item(0));
|
||||
} catch(Exception $e) {}
|
||||
|
||||
if (preg_match('/ [\|\-] /', $curTitle))
|
||||
{
|
||||
$curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle);
|
||||
|
||||
if (count(explode(' ', $curTitle)) < 3) {
|
||||
$curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle);
|
||||
}
|
||||
}
|
||||
else if(strlen($curTitle) > 150 || strlen($curTitle) < 15)
|
||||
{
|
||||
$hOnes = $this->dom->getElementsByTagName('h1');
|
||||
if($hOnes->length == 1)
|
||||
{
|
||||
$curTitle = $this->getInnerText($hOnes->item(0));
|
||||
}
|
||||
}
|
||||
|
||||
$curTitle = trim($curTitle);
|
||||
|
||||
if (count(explode(' ', $curTitle)) <= 4) {
|
||||
$curTitle = $origTitle;
|
||||
}
|
||||
|
||||
$articleTitle = $this->dom->createElement('h1');
|
||||
$articleTitle->innerHTML = $curTitle;
|
||||
|
||||
return $articleTitle;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="wallabag_readability.url_extractor.class">Wallabag\Bundle\ReadabilityBundle\Url\UrlExtractor</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="wallabag_readability.url_extractor" class="%wallabag_readability.url_extractor.class%"/>
|
||||
</services>
|
||||
</container>
|
@ -1 +0,0 @@
|
||||
Hello {{ name }}!
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class DefaultControllerTest extends WebTestCase
|
||||
{
|
||||
public function testIndex()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Url;
|
||||
|
||||
class DummySingleItem {
|
||||
public $url;
|
||||
function __construct($url) { $this->url = $url; }
|
||||
public function get_permalink() { return $this->url; }
|
||||
public function get_title() { return null; }
|
||||
public function get_date($format='') { return false; }
|
||||
public function get_author($key=0) { return null; }
|
||||
public function get_authors() { return null; }
|
||||
public function get_description() { return ''; }
|
||||
public function get_enclosure($key=0, $prefer=null) { return null; }
|
||||
public function get_enclosures() { return null; }
|
||||
public function get_categories() { return null; }
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Url;
|
||||
|
||||
class DummySingleItemFeed {
|
||||
public $item;
|
||||
function __construct($url) { $this->item = new DummySingleItem($url); }
|
||||
public function get_title() { return ''; }
|
||||
public function get_description() { return 'Content extracted from '.$this->item->url; }
|
||||
public function get_link() { return $this->item->url; }
|
||||
public function get_language() { return false; }
|
||||
public function get_image_url() { return false; }
|
||||
public function get_items($start=0, $max=1) { return array(0=>$this->item); }
|
||||
}
|
@ -1,392 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* wallabag, a read it later open source system
|
||||
*
|
||||
* @category wallabag
|
||||
* @author Nicolas Lœuillet <hello@wallabag.org>
|
||||
* @copyright 2013
|
||||
* @license http://www.wtfpl.net/ see COPYING file
|
||||
*/
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle\Url;
|
||||
|
||||
use Wallabag\Bundle\ReadabilityBundle\Readability\WallabagReadability;
|
||||
|
||||
class UrlExtractor
|
||||
{
|
||||
public $url;
|
||||
|
||||
private $fingerprints = array(
|
||||
// Posterous
|
||||
'<meta name="generator" content="Posterous"' => array('hostname'=>'fingerprint.posterous.com', 'head'=>true),
|
||||
// Blogger
|
||||
'<meta content=\'blogger\' name=\'generator\'' => array('hostname'=>'fingerprint.blogspot.com', 'head'=>true),
|
||||
'<meta name="generator" content="Blogger"' => array('hostname'=>'fingerprint.blogspot.com', 'head'=>true),
|
||||
// WordPress (self-hosted and hosted)
|
||||
'<meta name="generator" content="WordPress' => array('hostname'=>'fingerprint.wordpress.com', 'head'=>true)
|
||||
);
|
||||
|
||||
private $user_agents = array( 'lifehacker.com' => 'PHP/5.2',
|
||||
'gawker.com' => 'PHP/5.2',
|
||||
'deadspin.com' => 'PHP/5.2',
|
||||
'kotaku.com' => 'PHP/5.2',
|
||||
'jezebel.com' => 'PHP/5.2',
|
||||
'io9.com' => 'PHP/5.2',
|
||||
'jalopnik.com' => 'PHP/5.2',
|
||||
'gizmodo.com' => 'PHP/5.2',
|
||||
'.wikipedia.org' => 'Mozilla/5.2'
|
||||
);
|
||||
|
||||
private $content_type_exc = array(
|
||||
'application/pdf' => array('action'=>'link', 'name'=>'PDF'),
|
||||
'image' => array('action'=>'link', 'name'=>'Image'),
|
||||
'audio' => array('action'=>'link', 'name'=>'Audio'),
|
||||
'video' => array('action'=>'link', 'name'=>'Video')
|
||||
);
|
||||
|
||||
private $rewrite_url = array(
|
||||
// Rewrite public Google Docs URLs to point to HTML view:
|
||||
// if a URL contains docs.google.com, replace /Doc? with /View?
|
||||
'docs.google.com' => array('/Doc?' => '/View?'),
|
||||
'tnr.com' => array('tnr.com/article/' => 'tnr.com/print/article/'),
|
||||
'.m.wikipedia.org' => array('.m.wikipedia.org' => '.wikipedia.org')
|
||||
);
|
||||
|
||||
private $rewrite_relative_urls = true;
|
||||
private $error_message = '[unable to retrieve full-text content]';
|
||||
|
||||
function __construct($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function isCorrect($url) {
|
||||
return filter_var($url, FILTER_VALIDATE_URL) !== FALSE;
|
||||
}
|
||||
|
||||
public function extract($url) {
|
||||
global $http, $extractor;
|
||||
$extractor = new \ContentExtractor(dirname(__FILE__).'/../3rdparty/site_config/custom', dirname(__FILE__).'/../3rdparty/site_config/standard');
|
||||
$extractor->fingerprints = $this->fingerprints;
|
||||
|
||||
$http = new \HumbleHttpAgent();
|
||||
$http->userAgentMap = $this->user_agents;
|
||||
$http->headerOnlyTypes = array_keys($this->content_type_exc);
|
||||
$http->rewriteUrls = $this->rewrite_url;
|
||||
$http->userAgentDefault = \HumbleHttpAgent::UA_PHP;
|
||||
// configure SimplePie HTTP extension class to use our HumbleHttpAgent instance
|
||||
\SimplePie_HumbleHttpAgent::set_agent($http);
|
||||
$feed = new \SimplePie();
|
||||
// some feeds use the text/html content type - force_feed tells SimplePie to process anyway
|
||||
$feed->force_feed(true);
|
||||
$feed->set_file_class('SimplePie_HumbleHttpAgent');
|
||||
$feed->feed_url = $url;
|
||||
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
|
||||
$feed->set_timeout(20);
|
||||
$feed->enable_cache(false);
|
||||
$feed->set_stupidly_fast(true);
|
||||
$feed->enable_order_by_date(false); // we don't want to do anything to the feed
|
||||
$feed->set_url_replacements(array());
|
||||
// initialise the feed
|
||||
// the @ suppresses notices which on some servers causes a 500 internal server error
|
||||
$result = @$feed->init();
|
||||
if ($result && (!is_array($feed->data) || count($feed->data) == 0)) {
|
||||
die('Sorry, no feed items found');
|
||||
}
|
||||
// from now on, we'll identify ourselves as a browser
|
||||
$http->userAgentDefault = \HumbleHttpAgent::UA_BROWSER;
|
||||
unset($feed, $result);
|
||||
|
||||
$feed = new DummySingleItemFeed($url);
|
||||
|
||||
$items = $feed->get_items(0, 1);
|
||||
// Request all feed items in parallel (if supported)
|
||||
$urls_sanitized = array();
|
||||
$urls = array();
|
||||
foreach ($items as $key => $item) {
|
||||
$permalink = htmlspecialchars_decode($item->get_permalink());
|
||||
// Colons in URL path segments get encoded by SimplePie, yet some sites expect them unencoded
|
||||
$permalink = str_replace('%3A', ':', $permalink);
|
||||
if ($permalink) {
|
||||
$urls_sanitized[] = $permalink;
|
||||
}
|
||||
$urls[$key] = $permalink;
|
||||
}
|
||||
$http->fetchAll($urls_sanitized);
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
$do_content_extraction = true;
|
||||
$extract_result = false;
|
||||
$permalink = $urls[$key];
|
||||
|
||||
// TODO: Allow error codes - some sites return correct content with error status
|
||||
// e.g. prospectmagazine.co.uk returns 403
|
||||
|
||||
if ($permalink && ($response = $http->get($permalink, true)) && ($response['status_code'] < 300 || $response['status_code'] > 400)) {
|
||||
$effective_url = $response['effective_url'];
|
||||
// check if action defined for returned Content-Type
|
||||
$type = null;
|
||||
if (preg_match('!^Content-Type:\s*(([-\w]+)/([-\w\+]+))!im', $response['headers'], $match)) {
|
||||
// look for full mime type (e.g. image/jpeg) or just type (e.g. image)
|
||||
$match[1] = strtolower(trim($match[1]));
|
||||
$match[2] = strtolower(trim($match[2]));
|
||||
|
||||
foreach (array($match[1], $match[2]) as $_mime) {
|
||||
if (isset($this->content_type_exc[$_mime])) {
|
||||
$type = $match[1];
|
||||
$_act = $this->content_type_exc[$_mime]['action'];
|
||||
$_name = $this->content_type_exc[$_mime]['name'];
|
||||
if ($_act == 'exclude') {
|
||||
continue 2; // skip this feed item entry
|
||||
} elseif ($_act == 'link') {
|
||||
if ($match[2] == 'image') {
|
||||
$html = "<a href=\"$effective_url\"><img src=\"$effective_url\" alt=\"$_name\" /></a>";
|
||||
} else {
|
||||
$html = "<a href=\"$effective_url\">Download $_name</a>";
|
||||
}
|
||||
$title = $_name;
|
||||
$do_content_extraction = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($_mime, $_act, $_name, $match);
|
||||
}
|
||||
if ($do_content_extraction) {
|
||||
$html = $response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = $this->convert_to_utf8($html, $response['headers']);
|
||||
|
||||
// check site config for single page URL - fetch it if found
|
||||
if ($single_page_response = $this->getSinglePage($item, $html, $effective_url)) {
|
||||
$html = $single_page_response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = $this->convert_to_utf8($html, $single_page_response['headers']);
|
||||
$effective_url = $single_page_response['effective_url'];
|
||||
unset($single_page_response);
|
||||
}
|
||||
$extract_result = $extractor->process($html, $effective_url);
|
||||
$readability = $extractor->readability;
|
||||
$content_block = ($extract_result) ? $extractor->getContent() : null;
|
||||
}
|
||||
}
|
||||
if ($do_content_extraction) {
|
||||
// if we failed to extract content...
|
||||
if (!$extract_result) {
|
||||
$html = $this->error_message;
|
||||
// keep the original item description
|
||||
$html .= $item->get_description();
|
||||
} else {
|
||||
$readability->clean($content_block, 'select');
|
||||
if ($this->rewrite_relative_urls) $this->makeAbsolute($effective_url, $content_block);
|
||||
if ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) {
|
||||
$html = $content_block->firstChild->innerHTML;
|
||||
} else {
|
||||
$html = $content_block->innerHTML;
|
||||
}
|
||||
// post-processing cleanup
|
||||
$html = preg_replace('!<p>[\s\h\v]*</p>!u', '', $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$title = ($extractor->getTitle() != '' ? $extractor->getTitle() : _('Untitled'));
|
||||
$content = array ('title' => $title, 'body' => $html);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function convert_to_utf8($html, $header=null)
|
||||
{
|
||||
$encoding = null;
|
||||
if ($html || $header) {
|
||||
if (is_array($header)) $header = implode("\n", $header);
|
||||
if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=["\']?([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) {
|
||||
// error parsing the response
|
||||
} else {
|
||||
$match = end($match); // get last matched element (in case of redirects)
|
||||
if (isset($match[2])) $encoding = trim($match[2], "\"' \r\n\0\x0B\t");
|
||||
}
|
||||
// TODO: check to see if encoding is supported (can we convert it?)
|
||||
// If it's not, result will be empty string.
|
||||
// For now we'll check for invalid encoding types returned by some sites, e.g. 'none'
|
||||
// Problem URL: http://facta.co.jp/blog/archives/20111026001026.html
|
||||
if (!$encoding || $encoding == 'none') {
|
||||
// search for encoding in HTML - only look at the first 35000 characters
|
||||
$html_head = substr($html, 0, 40000);
|
||||
if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) {
|
||||
$encoding = trim($match[1], '"\'');
|
||||
} elseif (preg_match('/<meta\s+http-equiv=["\']?Content-Type["\']? content=["\'][^;]+;\s*charset=["\']?([^;"\'>]+)/i', $html_head, $match)) {
|
||||
$encoding = trim($match[1]);
|
||||
} elseif (preg_match_all('/<meta\s+([^>]+)>/i', $html_head, $match)) {
|
||||
foreach ($match[1] as $_test) {
|
||||
if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) {
|
||||
$encoding = trim($_m[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($encoding)) $encoding = trim($encoding);
|
||||
// trim is important here!
|
||||
if (!$encoding || (strtolower($encoding) == 'iso-8859-1')) {
|
||||
// replace MS Word smart qutoes
|
||||
$trans = array();
|
||||
$trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark
|
||||
$trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook
|
||||
$trans[chr(132)] = '„'; // Double Low-9 Quotation Mark
|
||||
$trans[chr(133)] = '…'; // Horizontal Ellipsis
|
||||
$trans[chr(134)] = '†'; // Dagger
|
||||
$trans[chr(135)] = '‡'; // Double Dagger
|
||||
$trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent
|
||||
$trans[chr(137)] = '‰'; // Per Mille Sign
|
||||
$trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron
|
||||
$trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark
|
||||
$trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE
|
||||
$trans[chr(145)] = '‘'; // Left Single Quotation Mark
|
||||
$trans[chr(146)] = '’'; // Right Single Quotation Mark
|
||||
$trans[chr(147)] = '“'; // Left Double Quotation Mark
|
||||
$trans[chr(148)] = '”'; // Right Double Quotation Mark
|
||||
$trans[chr(149)] = '•'; // Bullet
|
||||
$trans[chr(150)] = '–'; // En Dash
|
||||
$trans[chr(151)] = '—'; // Em Dash
|
||||
$trans[chr(152)] = '˜'; // Small Tilde
|
||||
$trans[chr(153)] = '™'; // Trade Mark Sign
|
||||
$trans[chr(154)] = 'š'; // Latin Small Letter S With Caron
|
||||
$trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark
|
||||
$trans[chr(156)] = 'œ'; // Latin Small Ligature OE
|
||||
$trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis
|
||||
$html = strtr($html, $trans);
|
||||
}
|
||||
if (!$encoding) {
|
||||
$encoding = 'utf-8';
|
||||
} else {
|
||||
if (strtolower($encoding) != 'utf-8') {
|
||||
$html = \SimplePie_Misc::change_encoding($html, $encoding, 'utf-8');
|
||||
/*
|
||||
if (function_exists('iconv')) {
|
||||
// iconv appears to handle certain character encodings better than mb_convert_encoding
|
||||
$html = iconv($encoding, 'utf-8', $html);
|
||||
} else {
|
||||
$html = mb_convert_encoding($html, 'utf-8', $encoding);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function makeAbsolute($base, $elem) {
|
||||
$base = new \SimplePie_IRI($base);
|
||||
// remove '//' in URL path (used to prevent URLs from resolving properly)
|
||||
// TODO: check if this is still the case
|
||||
if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path);
|
||||
foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) {
|
||||
$elems = $elem->getElementsByTagName($tag);
|
||||
for ($i = $elems->length-1; $i >= 0; $i--) {
|
||||
$e = $elems->item($i);
|
||||
//$e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e);
|
||||
$this->makeAbsoluteAttr($base, $e, $attr);
|
||||
}
|
||||
if (strtolower($elem->tagName) == $tag) $this->makeAbsoluteAttr($base, $elem, $attr);
|
||||
}
|
||||
}
|
||||
|
||||
private function makeAbsoluteAttr($base, $e, $attr) {
|
||||
if ($e->hasAttribute($attr)) {
|
||||
// Trim leading and trailing white space. I don't really like this but
|
||||
// unfortunately it does appear on some sites. e.g. <img src=" /path/to/image.jpg" />
|
||||
$url = trim(str_replace('%20', ' ', $e->getAttribute($attr)));
|
||||
$url = str_replace(' ', '%20', $url);
|
||||
if (!preg_match('!https?://!i', $url)) {
|
||||
if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
|
||||
$e->setAttribute($attr, $absolute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function makeAbsoluteStr($base, $url) {
|
||||
$base = new \SimplePie_IRI($base);
|
||||
// remove '//' in URL path (causes URLs not to resolve properly)
|
||||
if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path);
|
||||
if (preg_match('!^https?://!i', $url)) {
|
||||
// already absolute
|
||||
return $url;
|
||||
} else {
|
||||
if ($absolute = \SimplePie_IRI::absolutize($base, $url)) {
|
||||
return $absolute;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// returns single page response, or false if not found
|
||||
private function getSinglePage($item, $html, $url) {
|
||||
global $http, $extractor;
|
||||
$host = @parse_url($url, PHP_URL_HOST);
|
||||
$site_config = \SiteConfig::build($host);
|
||||
if ($site_config === false) {
|
||||
// check for fingerprints
|
||||
if (!empty($extractor->fingerprints) && ($_fphost = $extractor->findHostUsingFingerprints($html))) {
|
||||
$site_config = \SiteConfig::build($_fphost);
|
||||
}
|
||||
if ($site_config === false) $site_config = new \SiteConfig();
|
||||
\SiteConfig::add_to_cache($host, $site_config);
|
||||
return false;
|
||||
} else {
|
||||
\SiteConfig::add_to_cache($host, $site_config);
|
||||
}
|
||||
$splink = null;
|
||||
if (!empty($site_config->single_page_link)) {
|
||||
$splink = $site_config->single_page_link;
|
||||
} elseif (!empty($site_config->single_page_link_in_feed)) {
|
||||
// single page link xpath is targeted at feed
|
||||
$splink = $site_config->single_page_link_in_feed;
|
||||
// so let's replace HTML with feed item description
|
||||
$html = $item->get_description();
|
||||
}
|
||||
if (isset($splink)) {
|
||||
// Build DOM tree from HTML
|
||||
$readability = new WallabagReadability($html, $url);
|
||||
$xpath = new DOMXPath($readability->dom);
|
||||
// Loop through single_page_link xpath expressions
|
||||
$single_page_url = null;
|
||||
foreach ($splink as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $readability->dom);
|
||||
if (is_string($elems)) {
|
||||
$single_page_url = trim($elems);
|
||||
break;
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
foreach ($elems as $item) {
|
||||
if ($item instanceof DOMElement && $item->hasAttribute('href')) {
|
||||
$single_page_url = $item->getAttribute('href');
|
||||
break;
|
||||
} elseif ($item instanceof DOMAttr && $item->value) {
|
||||
$single_page_url = $item->value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If we've got URL, resolve against $url
|
||||
if (isset($single_page_url) && ($single_page_url = $this->makeAbsoluteStr($url, $single_page_url))) {
|
||||
// check it's not what we have already!
|
||||
if ($single_page_url != $url) {
|
||||
// it's not, so let's try to fetch it...
|
||||
$_prev_ref = $http->referer;
|
||||
$http->referer = $single_page_url;
|
||||
if (($response = $http->get($single_page_url, true)) && $response['status_code'] < 300) {
|
||||
$http->referer = $_prev_ref;
|
||||
return $response;
|
||||
}
|
||||
$http->referer = $_prev_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\Bundle\ReadabilityBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class WallabagReadabilityBundle extends Bundle
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user