Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Compat SPIP 4.1 #293

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f94e170
build: version 3.0.0, compat SPIP 4.1 mini
brunob Feb 28, 2024
19b5aa3
style: Coding Standard (phpcbf)
brunob Feb 28, 2024
70a6354
chore: une passe de rector UP_TO_PHP_74
brunob Feb 28, 2024
fdd950b
fix: pagination legacy reprise de zpip-dist
brunob Feb 28, 2024
3f3c4c6
fix: affichage du bouton play/pause pour les players audio
brunob Feb 29, 2024
2a58564
fix: le bon include pour `copie_locale_safe()`
brunob Feb 29, 2024
ad9a6a3
chore: fichier de conf et baseline phpstan + git attributes pour ne p…
brunob Mar 2, 2024
fe69a0f
fix: deprecated `generer_url_entite()` => `generer_objet_url()`
brunob Mar 4, 2024
2995072
fix: deprecated --
brunob Mar 4, 2024
92bc463
fix: warnings --
brunob Mar 4, 2024
85baa18
fix: warning -- sur `Undefined variable $ret`
brunob Mar 4, 2024
b00e1c9
fix: warnings -- sur `Undefined array key`
brunob Mar 4, 2024
f9c6355
fix: `$id_auteur` n'est pas défini ici, ce code est donc inutile
brunob Mar 4, 2024
5caab57
fix: utiliser la bonne variable dans `action_bouton_follow_mot()`, $t…
brunob Mar 4, 2024
80a4f3f
fix: warning -- sur `Undefined variable: $HTTP_ACCEPT_LANGUAGE`
brunob Mar 4, 2024
9a602ae
chore: update phpstan baseline
brunob Mar 4, 2024
4a8bb6d
chore: phpstan level 1
brunob Mar 4, 2024
260ff6d
fix: phpstan, variable might not be defined
brunob Mar 4, 2024
1f004a2
fix: phpstan, variable might not be defined
brunob Mar 4, 2024
ef0af84
fix: phpstan, variable might not be defined
brunob Mar 4, 2024
d62772d
fix: phpstan, variable might not be defined
brunob Mar 4, 2024
47a2592
fix: deprecated -- `_nano_sha256()` => `spip_sha256()`
brunob Mar 4, 2024
e9d006e
chore: standard files
JamesRezo Jul 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/phpstan.neon.dist export-ignore
/phpstan-baseline.neon export-ignore
/phpstan-constants.php export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
/tests/ export-ignore
/phpunit.xml.dist export-ignore
/.php-cs-fixer.dist.php export-ignore
/.editorconfig export-ignore
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/vendor/
/composer.lock
/.phpunit.cache
/phpunit.xml
/.php-cs-fixer.cache
/.php-cs-fixer.php
/phpstan.neon
/bin/
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

132 changes: 68 additions & 64 deletions action/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,119 +3,123 @@
function action_api_dist() {

$xml = false;
$id_me = 0;

// forcer le https sauf si on a define('_API_HTTPS', false)
if (!defined('_API_HTTPS')
OR _API_HTTPS) {
if ($_SERVER['SERVER_PORT'] != 443)
erreur_405("Please use https");
if (
!defined('_API_HTTPS')
or _API_HTTPS
) {
if ($_SERVER['SERVER_PORT'] != 443) {
erreur_405('Please use https');
}
}

include_spip('inc/session');
$id_auteur = session_get('id_auteur');
if ($id_auteur < 1) erreur_405("The username and/or password used for authentication are invalid", 401);
if ($id_auteur < 1) {
erreur_405('The username and/or password used for authentication are invalid', 401);
}

$method = $_SERVER['REQUEST_METHOD'];


$method = $_SERVER["REQUEST_METHOD"];


if ($method == "PUT") {
if ($method == 'PUT') {
// UPDATE
$putdata = fopen("php://input", "r");

$putdata = fopen('php://input', 'r');

/* Open a file for writing */
/* Read the data 1 KB at a time
and write to the file */
while ($data = fread($putdata, 1024))
while ($data = fread($putdata, 1024)) {
$xml .= $data;
}
fclose($putdata);
$xml = trim($xml);
}
else if ($method == "POST") {
$xml = trim(isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? isset($GLOBALS["HTTP_RAW_POST_DATA"]) : file_get_contents('php://input'));
elseif ($method == 'POST') {
$xml = trim(isset($GLOBALS['HTTP_RAW_POST_DATA']) ?: file_get_contents('php://input'));

$contenttype = $_SERVER["CONTENT_TYPE"];
if (!preg_match(",application\/(atom\+)?xml,", $contenttype)) {
erreur_405("Wrong content-type");
$contenttype = $_SERVER['CONTENT_TYPE'];
if (!preg_match(',application\/(atom\+)?xml,', $contenttype)) {
erreur_405('Wrong content-type');
}


} else if ($method == "DELETE") {
$url = $_SERVER["REQUEST_URI"];
if (preg_match("/messages\/([0-9]+)$/", $url, $regs)) {
} elseif ($method == 'DELETE') {
$url = $_SERVER['REQUEST_URI'];
if (preg_match('/messages\/([0-9]+)$/', $url, $regs)) {
$id_me = $regs[1];
echo "Supprimer: $id_me";
}
} else if ($method == "GET") {
$url = $_SERVER["REQUEST_URI"];
if (preg_match("/messages\/([0-9]+)$/", $url, $regs)) {
} elseif ($method == 'GET') {
$url = $_SERVER['REQUEST_URI'];
if (preg_match('/messages\/([0-9]+)$/', $url, $regs)) {
$id_me = $regs[1];
} else {
erreur_405("No message found");
erreur_405('No message found');
}
}

if ($xml) {


$xml = preg_replace("/<entry[^>]*>/msU", "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:thr='http://purl.org/syndication/thread/1.0'>", $xml);

$xml = preg_replace('/<entry[^>]*>/msU', "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:thr='http://purl.org/syndication/thread/1.0'>", $xml);

$res = new SimpleXMLElement($xml);
$id = $res->id;

$id_parent = 0;
$summary = trim($res->summary);
$content = trim($res->content);

if (strlen($summary) > 0) $texte_message = $summary;
else $texte_message = $content;


if (strlen($texte_message) < 1) die ("No text");

$reply = $res->xpath("thr:in-reply-to/@ref");

if (strlen($summary) > 0) {
$texte_message = $summary;
} else {
$texte_message = $content;
}


if (strlen($texte_message) < 1) {
die('No text');
}

$reply = $res->xpath('thr:in-reply-to/@ref');
if ($reply) {
$reply = $reply[0];
if (preg_match("/message\:([0-9]+)/", $reply, $regs)) {
if (preg_match('/message\:([0-9]+)/', $reply, $regs)) {
$id_parent = $regs[1];
}
}

// creer ou modifier un message ?
// si on passe id = message:1234 remplacer ce message
// si on passe id = "uuid:azertyu" pour creer OU remplacer
$id_me = 0;
if (preg_match("/^message\:(\d+)/", $id, $regs)) {
$uuid = null;
if (preg_match('/^message\:(\d+)/', $id, $regs)) {
$id_me = $regs[1];
$uuid = null;
} else if (preg_match("/^uuid\:(.+)/", $id, $regs)) {
} elseif (preg_match('/^uuid\:(.+)/', $id, $regs)) {
include_spip('inc/uuid');
$uuid = $regs[1];
if (!UUID::Valid($uuid))
erreur_405("Error - invalid UUID format");
} else if (strlen($id)>0) {
erreur_405("Error - your ID does not match an acceptable format");
if (!UUID::Valid($uuid)) {
erreur_405('Error - invalid UUID format');
}
} elseif (strlen($id) > 0) {
erreur_405('Error - your ID does not match an acceptable format');
}

$ret = instance_me ($id_auteur, $texte_message, $id_me, $id_parent, $time="NOW()", $uuid);
$ret = instance_me($id_auteur, $texte_message, $id_me, $id_parent, $time = 'NOW()', $uuid);

$id_me = $ret["id_me"];

if (!$id_me) erreur_405("Unexpected error - not saved in base");
$id_me = $ret['id_me'];

cache_message($id_me);
if (!$id_me) {
erreur_405('Unexpected error - not saved in base');
}

cache_message($id_me);
}

header("Content-type: application/atom+xml; charset=utf-8");

echo "<"."?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo microcache($id_me, "noisettes/atom_me");

exit();

}

header('Content-type: application/atom+xml; charset=utf-8');

echo '<' . "?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo microcache($id_me, 'noisettes/atom_me');

?>
exit();
}
77 changes: 36 additions & 41 deletions action/api_auteur.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,62 @@
<?php



function action_api_auteur() {

$xml = false;

if (!defined('_API_HTTPS')
OR _API_HTTPS) {
if ($_SERVER['SERVER_PORT'] != 443)
erreur_405("Please use https");
if (
!defined('_API_HTTPS')
or _API_HTTPS
) {
if ($_SERVER['SERVER_PORT'] != 443) {
erreur_405('Please use https');
}
}

$id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
if ($id_auteur < 1) erreur_405("Unknown user", 401);
$method = $_SERVER["REQUEST_METHOD"];


if ($method == "GET") {
$url = $_SERVER["REQUEST_URI"];

if (preg_match(",/api/people/(.*)?/messages\/?([0-9]+)?,", $url, $regs)) {
if ($id_auteur < 1) {
erreur_405('Unknown user', 401);
}
$method = $_SERVER['REQUEST_METHOD'];


if ($method == 'GET') {
$url = $_SERVER['REQUEST_URI'];

if (preg_match(',/api/people/(.*)?/messages\/?([0-9]+)?,', $url, $regs)) {
$login = $regs[1];
$debut = $regs[2];
$ret = "";
$query = sql_select("id_auteur", "spip_auteurs", "login='$login' && statut!='nouveau' && statut != 'poubelle'");

$ret = '';

$query = sql_select('id_auteur', 'spip_auteurs', "login='$login' && statut!='nouveau' && statut != 'poubelle'");
if ($row = sql_fetch($query)) {
$id_auteur = $row["id_auteur"];

$id_auteur = $row['id_auteur'];

header("Content-type: application/atom+xml; charset=utf-8");
if ($debut < 0) echo microcache($id_auteur, "noisettes/atom_messages_auteur");
else {
$contenu = recuperer_fond("noisettes/atom_messages_auteur",
array(

header('Content-type: application/atom+xml; charset=utf-8');
if ($debut < 0) {
echo microcache($id_auteur, 'noisettes/atom_messages_auteur');
} else {
$contenu = recuperer_fond(
'noisettes/atom_messages_auteur',
[
'id' => $id_auteur,
"debut_messages" => $debut
));
'debut_messages' => $debut
]
);
echo $contenu;
}


} else {
erreur_405("$login not found");
}

} else {
erreur_405("Wrong URL");
erreur_405('Wrong URL');
}



} else {
erreur_405("Unknow method - use GET to retrieve data");
erreur_405('Unknow method - use GET to retrieve data');
}


exit();

}



?>
18 changes: 8 additions & 10 deletions action/api_url.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
function action_api_url() {
$code = _request('code');

$site = array();
$messages = array();
$site = [];
$messages = [];
$url = '';

// md5 ?
Expand All @@ -22,27 +22,25 @@ function action_api_url() {

foreach ($site as $s) {
$url = $s['url_site'];
foreach (sql_allfetsel('*', 'spip_me_syndic', 'id_syndic='.$s['id_syndic']) as $m) {
foreach (sql_allfetsel('*', 'spip_me_syndic', 'id_syndic=' . $s['id_syndic']) as $m) {
$messages[] = intval($m['id_me']);
}
}

$rep = array(
'status' => (($site AND $messages) ? 'success' : 'fail'),
$rep = [
'status' => (($site and $messages) ? 'success' : 'fail'),
'url' => $url,
'messages' => $messages,
);
];

@header('Content-Type: text/plain; charset=utf-8');
echo json_encode($rep);


}


function recherche_site_par_md5($code) {
// attention seenthis bouffe le / final d'une URL,
// on a donc deux md5 possibles
$f = sql_allfetsel('id_syndic, url_site', 'spip_syndic', '(MD5(url_site)='._q($code).' OR MD5(CONCAT(url_site,"/"))='._q($code).')');
$f = sql_allfetsel('id_syndic, url_site', 'spip_syndic', '(MD5(url_site)=' . _q($code) . ' OR MD5(CONCAT(url_site,"/"))=' . _q($code) . ')');
return $f;
}
Loading