dolibarr 21.0.0-beta
fediverseparser.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
26require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/socialnetworkmanager.class.php';
32{
36 public $db;
37
41 public $error = '';
42
46 private $manager;
47
53 public function __construct($platform)
54 {
55 $this->manager = new SocialNetworkManager($platform);
56 if (!empty($this->manager->error)) {
57 $this->error = $this->manager->error;
58 }
59 }
60
70 public function parser($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '')
71 {
72 if (!$this->manager) {
73 return -1;
74 }
75
76 $result = $this->manager->fetchPosts($urlAPI, $maxNb, $cacheDelay, $cacheDir);
77 if ($result === false) {
78 $this->error = $this->manager->error;
79 return -1;
80 }
81 return 1;
82 }
83
84
90 public function getPosts()
91 {
92 return $this->manager ? $this->manager->getPosts() : [];
93 }
94
100 public function getLastFetchDate()
101 {
102 return $this->manager ? $this->manager->getLastFetchDate() : '';
103 }
104}
Class to parse Fediverse files.
parser($urlAPI, $maxNb=5, $cacheDelay=60, $cacheDir='')
Parse Fediverse API to retrieve posts.
__construct($platform)
Constructor.
getPosts()
Get the list of retrieved posts.
getLastFetchDate()
Get the last fetch date.
Class to manage Social network posts.