25require_once DOL_DOCUMENT_ROOT.
'/core/class/mastodonhandler.class.php';
56 private $lastFetchDate;
66 $this->platform = $platform;
78 $handlerFile = strtolower((
string) $this->platform);
79 if (in_array($handlerFile, array(
'mastodon',
'diaspora',
'reddit'))) {
80 require_once DOL_DOCUMENT_ROOT.
'/core/class/'.$handlerFile.
'handler.class.php';
83 $handlerClass =
dol_ucfirst($this->platform).
'Handler';
84 if (class_exists($handlerClass)) {
85 $this->handler =
new $handlerClass($authParams);
87 $this->error =
"Handler for $this->platform not found.";
101 public function fetchPosts($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir =
'', $authParams = [])
103 if (!$this->handler) {
108 $result = $this->handler->fetch($urlAPI, $maxNb, $cacheDelay, $cacheDir, $authParams);
110 if (!empty($this->handler->error)) {
111 $this->error = $this->handler->error;
115 $cacheFile = $cacheDir.
'/'.
dol_hash($urlAPI,
'3');
118 } elseif ($result !==
false) {
119 $this->lastFetchDate =
dol_now();
132 $posts = $this->handler ? $this->handler->getPosts() : [];
133 if (is_array($posts)) {
135 foreach ($posts as $key => $post) {
136 if (!empty($post[
'url']) && !preg_match(
'/^https?:\/\//i', $post[
'url'])) {
137 $posts[$key][
'url'] =
'';
151 return $this->lastFetchDate;
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_filemtime($pathoffile)
Return time of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.