|
|
@ -23,24 +23,29 @@ class Parser
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
$dom = new DOMDocument();
|
|
|
|
$tabArticle = array();
|
|
|
|
$tabArticle = array();
|
|
|
|
|
|
|
|
|
|
|
|
if ($dom->load($flux->getFlux())){
|
|
|
|
if ($dom->load($flux->getFlux())){
|
|
|
|
$items = $dom->getElementsByTagName('item');
|
|
|
|
$items = $dom->getElementsByTagName('item');
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$title = $item->getElementsByTagName('title')[0]->nodeValue;
|
|
|
|
$title = $item->getElementsByTagName('title')[0]->nodeValue;
|
|
|
|
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
|
|
|
|
$date = $item->getElementsByTagName('pubDate')[0]->nodeValue;
|
|
|
|
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
|
|
|
|
$guid = $item->getElementsByTagName('guid')[0]->nodeValue;
|
|
|
|
$link = $item->getElementsByTagName('link')[0]->nodeValue;
|
|
|
|
$link = $item->getElementsByTagName('link')[0]->nodeValue;
|
|
|
|
$description = $item->getElementsByTagName('description')[0]->nodeValue;
|
|
|
|
$description = $item->getElementsByTagName('description')[0]->nodeValue;
|
|
|
|
|
|
|
|
|
|
|
|
$media = $item->getElementsByTagName('media:content');
|
|
|
|
$media = $item->getElementsByTagName('media:content');
|
|
|
|
$mediaUrl = null;
|
|
|
|
$mediaUrl = null;
|
|
|
|
if ($media->length > 0){
|
|
|
|
if ($media->length > 0){
|
|
|
|
$mediaUrl = $media->item(0)->getAttribute('url');
|
|
|
|
$mediaUrl = $media->item(0)->getAttribute('url');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$tabArticle[] = new Article((int)null, $title, $date, $description, $guid, $link, $mediaUrl, $flux->getId());
|
|
|
|
$tabArticle[] = new Article(
|
|
|
|
|
|
|
|
(int)null,
|
|
|
|
|
|
|
|
$title,
|
|
|
|
|
|
|
|
$date,
|
|
|
|
|
|
|
|
$description,
|
|
|
|
|
|
|
|
$guid,
|
|
|
|
|
|
|
|
$link,
|
|
|
|
|
|
|
|
($mediaUrl !== null) ? (string)$mediaUrl : '',
|
|
|
|
|
|
|
|
$flux->getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tabArticle;
|
|
|
|
return $tabArticle;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -54,8 +59,11 @@ class Parser
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function parseAll($fluxes){
|
|
|
|
public function parseAll($fluxes){
|
|
|
|
|
|
|
|
$tabArticles = [];
|
|
|
|
foreach ($fluxes as $flux){
|
|
|
|
foreach ($fluxes as $flux){
|
|
|
|
$tabArticles[] =$this->parseArticles($flux);
|
|
|
|
$fluxx = new Flux($flux[0],$flux[1]);
|
|
|
|
|
|
|
|
$tabArticles[] = $this->parseArticles($fluxx);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tabArticles;
|
|
|
|
return $tabArticles;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -65,20 +73,27 @@ class Parser
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function addAllArticles()
|
|
|
|
public function addAllArticles()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
$tabFluxes = [];
|
|
|
|
$this->articleGateway->removeAllArticleForParser();
|
|
|
|
$this->articleGateway->removeAllArticleForParser();
|
|
|
|
|
|
|
|
|
|
|
|
$allFlux = $this->fluxGateway->findAllFlux();
|
|
|
|
$allItemFlux = $this->fluxGateway->findAllFlux();
|
|
|
|
$allArticles = $this->parseAll($allFlux);
|
|
|
|
foreach ($allItemFlux as $ItemFlux){
|
|
|
|
foreach ($allArticles as $article) {
|
|
|
|
$tabFluxes[] = $ItemFlux[1];
|
|
|
|
$this->articleGateway->addArticle($article);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $allArticles;
|
|
|
|
$allTabArticles = $this->parseAll($allItemFlux);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($allTabArticles as $tabArticle) {
|
|
|
|
|
|
|
|
foreach ($tabArticle as $item) {
|
|
|
|
|
|
|
|
$this->articleGateway->addArticle($item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$gwArt = new ArticleGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
|
|
|
}
|
|
|
|
$gwFl = new FluxGateway(new Connection('mysql:host=londres.uca.local;dbname=dbrorossetto', 'rorossetto', 'tpphp'));
|
|
|
|
|
|
|
|
$pars = new Parser( $gwFl,$gwArt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|