dolibarr 21.0.0-beta
socialnetworkmanager.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 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/core/class/mastodonhandler.class.php';
26
27
32{
36 public $db;
37
41 private $platform;
42
46 private $handler;
47
51 public $error = '';
52
56 private $lastFetchDate; // @phpstan-ignore-line
57
64 public function __construct($platform, $authParams = [])
65 {
66 $this->platform = $platform;
67 $this->initializeHandler($authParams);
68 }
69
75 private function initializeHandler($authParams)
76 {
77 $handlerClass = dol_ucfirst($this->platform).'Handler';
78 if (class_exists($handlerClass)) {
79 $this->handler = new $handlerClass($authParams);
80 } else {
81 $this->error = "Handler for $this->platform not found.";
82 }
83 }
84
95 public function fetchPosts($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $authParams = [])
96 {
97 if (!$this->handler) {
98 return false;
99 }
100
101 // This fetch URL
102 $result = $this->handler->fetch($urlAPI, $maxNb, $cacheDelay, $cacheDir, $authParams);
103
104 if (!empty($this->handler->error)) {
105 $this->error = $this->handler->error;
106 }
107
108 return $result;
109 }
110
116 public function getPosts()
117 {
118 return $this->handler ? $this->handler->getPosts() : [];
119 }
120
126 public function getLastFetchDate()
127 {
128 return $this->lastFetchDate;
129 }
130}
Class to manage Social network posts.
initializeHandler($authParams)
Initialize the social network needed.
getLastFetchDate()
Get the last fetch date.
fetchPosts($urlAPI, $maxNb=5, $cacheDelay=60, $cacheDir='', $authParams=[])
Fetch Social Network API to retrieve posts.
__construct($platform, $authParams=[])
Constructor.
getPosts()
Get the list of retrieved posts.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.