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