bot_plus/utils/bot_plus_funcions.php

203 líneas
6 KiB
PHP
Original Vista normal Històric

2023-05-24 10:40:54 +02:00
<?php
function HoraGmt() {
$data_gmt = date("r",(time()));
$data_mat = explode(" ",$data_gmt);
$dif_gmt = ($data_mat[5]/100);
$str_gmt_dif = ($dif_gmt*3600);
//echo $str_gmt_dif;
return $str_gmt_dif;
}
function convData($data) {
$argument = $data;
$conversió = strtotime($argument);
//echo $conversió." ".$argument."\n";
$convdata = $conversio." ".$argument."\n";
return $convdata;
}
// per fer cerca a matrius multidimensionals
function cercaID($id, $array) {
foreach ($array as $key => $val) {
if ($val['id'] == $id) {
return $key;
}
}
return null;
}
function errorExec($resposta) {
if ($resposta !=0) {
$missatge = "!ERRADA!";
} else {
$missatge = "Correcte";
}
return $missatge;
}
function TriaOpcio($num) {
if (is_int($num/23)) { $trie = 1; }
elseif (is_int($num/19)) { $trie = 2; }
elseif (is_int($num/17)) { $trie = 3; }
elseif (is_int($num/13)) { $trie = 4; }
elseif (is_int($num/11)) { $trie = 5; }
elseif (is_int($num/7 )) { $trie = 6; }
elseif (is_int($num/5 )) { $trie = 7; }
elseif (is_int($num/3 )) { $trie = 8; }
elseif (is_int($num/2 )) { $trie = 9; }
else { $trie = 10; }
return $trie;
}
function enviaCorreu($elmeucompte,$titol,$contingut,$elremitent) {
$per = $elmeucompte;
$assumpte = $titol;
$missatge = $contingut;
$de = $elremitent;
$caps = "From:" . $de . "";
mail($per,$assumpte,$missatge,$caps);
}
function canviaVariableFitxer($path, $oldContent, $newContent)
{
$str = file_get_contents($path);
$str = str_replace($oldContent, $newContent, $str);
file_put_contents($path, $str);
}
// utilitzacio
// canviaVariableFiter('your file path','string you want to change', 'new string')
// connexió mencions
function ConsultaNotificacions($token,$base_url,$limit_m,$headers) {
$bot_status = curl_init();
curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?limit=".$limit_m."");
curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true);
curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers);
$resposta = (curl_exec($bot_status));
$resposta_json = json_decode(curl_exec($bot_status),true);
curl_close ($bot_status);
$resposta = json_decode($resposta,true);
// echo "\n\nresposta json_decode\n";
// print_r($resposta);
// $nr = count($resposta);
// echo $nr."\n";
return $resposta;
}
function ConsultaMencions($token,$base_url,$limit_m,$headers) {
//Link: <https://mastodon.example/api/v1/notifications?max_id=34975535>; rel="next", <https://mastodon.example/api/v1/notifications?min_id=34975861>;
$bot_status = curl_init();
curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?limit=".$limit_m."");
// curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?types[]=mention");
curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true);
curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers);
$resposta = (curl_exec($bot_status));
$resposta_json = json_decode(curl_exec($bot_status),true);
curl_close ($bot_status);
$resposta = json_decode($resposta,true);
// echo "\n\nresposta json_decode\n";
// print_r($resposta);
// $nr = count($resposta);
// echo $nr."\n";
return $resposta;
}
function ConsultaSeguidors($base_url,$id_cmpt,$headers) {
$bot_perf = curl_init();
curl_setopt($bot_perf, CURLOPT_URL, $base_url . "/api/v1/accounts/".$id_cmpt."");
curl_setopt($bot_perf, CURLOPT_RETURNTRANSFER, true);
curl_setopt($bot_perf, CURLOPT_HTTPHEADER, $headers);
$bot_dad = (curl_exec($bot_perf));
$bot_dad_json = json_decode(curl_exec($bot_perf));
curl_close ($bot_perf);
$bot_dad = json_decode($bot_dad,true);
$seg_bot = $bot_dad['followers_count'];
//return $bot_dad;
return $seg_bot;
}
// PROVES
// connexió imatges
function PujaImatges($base_url,$imat_mst,$headers) {
}
function RecuperaImatge($base_url,$imat_mst,$headers) {
$bot_imtg = curl_init();
curl_setopt($bot_imtg, CURLOPT_URL, $base_url . "/api/v1/media/".$imat_mst."");
curl_setopt($bot_imtg, CURLOPT_RETURNTRANSFER, true);
curl_setopt($bot_imtg, CURLOPT_HTTPHEADER, $headers);
$resposta = (curl_exec($bot_imtg));
$resposta_json = json_decode(curl_exec($bot_imtg));
$resposta_imtg = json_decode($resposta,true);
curl_close ($bot_imtg);
return $resposta_imtg;
}
// connexio statuses
// per publicar
function PublicaMissatge($base_url,$headers,$publicacio) {
$bot_conn = curl_init();
curl_setopt($bot_conn, CURLOPT_URL, $base_url . "/api/v1/statuses");
curl_setopt($bot_conn, CURLOPT_POST, 1);
curl_setopt($bot_conn, CURLOPT_POSTFIELDS, $publicacio);
curl_setopt($bot_conn, CURLOPT_RETURNTRANSFER, true);
curl_setopt($bot_conn, CURLOPT_HTTPHEADER, $headers);
$resposta_conn = json_decode(curl_exec($bot_conn),true);
curl_close ($bot_conn);
return $resposta_conn;
}
function FesFavorit($base_url,$en_resposta,$headers) {
$fav_status = curl_init();
curl_setopt($fav_status, CURLOPT_URL, $base_url . "/api/v1/statuses/".$en_resposta."/favourite");
curl_setopt($fav_status, CURLOPT_POST, 1);
curl_setopt($fav_status, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fav_status, CURLOPT_HTTPHEADER, $headers);
$fav_eixida = json_decode(curl_exec($fav_status),true);
curl_close ($fav_status);
return $fav_eixida;
}
function FesRebloc($base_url,$en_resposta,$headers) {
$reb_status = curl_init();
curl_setopt($reb_status, CURLOPT_URL, $base_url . "/api/v1/statuses/".$en_resposta."/reblog");
curl_setopt($reb_status, CURLOPT_POST, 1);
curl_setopt($reb_status, CURLOPT_RETURNTRANSFER, true);
curl_setopt($reb_status, CURLOPT_HTTPHEADER, $headers);
$reb_eixida = json_decode(curl_exec($reb_status),true);
curl_close ($reb_status);
return $reb_eixida;
}
/**
// NO FUNCIONA ENCARA
function FesFinal() {
$neteja = shell_exec("tail -".$max_linies." ".$lloc."/fitxers/dates.txt | sort | uniq | tee ".$lloc."/fitxers/dates.txt");
$net_url = shell_exec("tail -".($max_linies*2)." ".$lloc."/fitxers/urls_pub.txt | sort | uniq | tee ".$lloc."/fitxers/urls_pub.txt");
$log -> lwrite("Temps total: ".date("i:s",$durada)." minuts | ".round($durada,4)." segons ");
$log -> lwrite ("FINAL!! ".$bot_nom." ".$bot_versio."");
exit;
}
**/
?>