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

version 2.0.0, compat SPIP 4.1 mini #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/vendor/
/composer.lock
/.phpunit.cache
/phpunit.xml
/.php-cs-fixer.cache
/.php-cs-fixer.php
/phpstan.neon
/bin/
/.php_cs.cache
/.php_cs.txt
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.

11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
seenthis_opencalais
===================
# seenthis/opencalais

recuperer les tags automatiques sur OpenCalais
Récupérer les tags automatiques sur OpenCalais


## Usage :
## Usage

Le service OpenCalais n'est pas libre.

Pour utiliser leur API il faut au préalable demander une clé d'autorisation.

Une fois l'autorisation obtenue, vous devrez ajouter dans le fichier `mes_options.php` la ligne suivante :
```

```php
define('_OPENCALAIS_APIKEY', "3cve82h1b7n2fg637cr2vxc1");
```
66 changes: 31 additions & 35 deletions action/lien_mot.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?php


function action_lien_mot() {


$auteur_session = $GLOBALS["auteur_session"]["id_auteur"];
$relation = _request("relation");
$statut = _request("statut");

if ($statut == "desactiver") $statut = "oui";
else if ($statut == "activer") $statut = "non";
$auteur_session = $GLOBALS['auteur_session']['id_auteur'];
$relation = _request('relation');
$statut = _request('statut');

if ($auteur_session < 1) exit;
$autoriser = false;
if ($statut == 'desactiver') {
$statut = 'oui';
} elseif ($statut == 'activer') {
$statut = 'non';
}

if (preg_match(",mot([0-9]+|.*:.*)\-me([0-9]+)(\-syndic([0-9]+))?,", $relation, $regs)) {
if ($auteur_session < 1) {
exit;
}
$autoriser = false;

if (preg_match(',mot([0-9]+|.*:.*)\-me([0-9]+)(\-syndic([0-9]+))?,', $relation, $regs)) {
# old style, id_mot
if (preg_match(',^\d+$,', $regs[1])) {
$s = sql_query('SELECT m.titre, g.titre as groupe FROM spip_mots AS m LEFT JOIN spip_groupes_mots AS g ON m.id_groupe=g.id_groupe WHERE id_mot='.sql_quote($regs[1]));
$s = sql_query('SELECT m.titre, g.titre as groupe FROM spip_mots AS m LEFT JOIN spip_groupes_mots AS g ON m.id_groupe=g.id_groupe WHERE id_mot=' . sql_quote($regs[1]));
if ($t = sql_fetch($s)) {
$tag = $t['groupe'].':'.$t['titre'];
$tag = $t['groupe'] . ':' . $t['titre'];
var_dump($tag);
} else
} else {
return;
}
}
else {
$tag = $regs[1];
Expand All @@ -33,48 +37,40 @@ function action_lien_mot() {
$id_syndic = intval($regs[4]);

if ($id_me > 0) {
#var_dump("ME", $id_me, $tag, $statut);

$query = sql_select("id_auteur", "spip_me", "id_me=$id_me AND id_auteur=$auteur_session");
$query = sql_select('id_auteur', 'spip_me', "id_me=$id_me AND id_auteur=$auteur_session");
if ($row = sql_fetch($query)) {
$autoriser = true;

sql_updateq(
"spip_me_tags",
array("off"=> $statut),
"id_me=$id_me AND tag=".sql_quote($tag)
'spip_me_tags',
['off' => $statut],
"id_me=$id_me AND tag=" . sql_quote($tag)
);

# old style
if ($id_mot > 0) {
sql_updateq(
"spip_me_mot",
array("off"=> $statut),
"id_me=$id_me AND id_mot=$id_mot"
sql_updateq(
'spip_me_mot',
['off' => $statut],
"id_me=$id_me AND id_mot=$id_mot"
);
}
}
}

# OLD STYLE -
if ($id_syndic > 0 && $autoriser) {
#echo "SYNDIC";
sql_updateq(
"spip_syndic_oc",
array("off"=> $statut),
"id_syndic=$id_syndic AND id_mot=$id_mot"
);
sql_updateq(
'spip_syndic_oc',
['off' => $statut],
"id_syndic=$id_syndic AND id_mot=$id_mot"
);
}

if ($id_me > 0 && $autoriser) {
cache_message($id_me);
include_spip('inc/headers');
redirige_par_entete(generer_url_entite($id_me, 'me'));
}
}

}



?>
122 changes: 40 additions & 82 deletions base/seenthisoc.php
Original file line number Diff line number Diff line change
@@ -1,137 +1,98 @@
<?php
/*

/**
* Plugin Seenthis_OpenCalais
*
*/

if (!defined("_ECRIRE_INC_VERSION")) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}

// lire directement une declaration SQL SHOW CREATE TABLE => SPIP
function seenthisoc_lire_create_table($x) {
$m = array('field' => array(), 'key' => array());
$m = ['field' => [], 'key' => []];

foreach(explode("\n", $x) as $line) {
foreach (explode("\n", $x) as $line) {
$line = trim(preg_replace('/,$/', '', $line));
if (preg_match("/^(PRIMARY KEY) \(`(.*?)`\)/", $line, $c)) {
if (preg_match('/^(PRIMARY KEY) \(`(.*?)`\)/', $line, $c)) {
$m['key'][$c[1]] = $c[2];
}
elseif (preg_match("/^(KEY) `(.*?)`\s+\((.*?)\)/", $line, $c)) {
$m['key'][$c[1]." ".$c[2]] = $c[3];
elseif (preg_match('/^(KEY) `(.*?)`\s+\((.*?)\)/', $line, $c)) {
$m['key'][$c[1] . ' ' . $c[2]] = $c[3];
}
elseif (preg_match("/^`(.*?)`\s+(.*?)$/", $line, $c)) {
elseif (preg_match('/^`(.*?)`\s+(.*?)$/', $line, $c)) {
$m['field'][$c[1]] = str_replace('`', '', $c[2]);
}
}

return $m;
}

/*
function seenthisoc_declarer_tables_interfaces($interface){
return $interface;
}
function seenthisoc_declarer_tables_objets_surnoms($interface){
return $interface;
}
function seenthisoc_declarer_tables_principales($tables_principales){
return $tables_principales;
}
*/

function seenthisoc_declarer_tables_auxiliaires($tables_auxiliaires){
/*
$tables_auxiliaires['spip_syndic_oc'] = seenthis_lire_create_table(
"
`id_syndic` bigint(21) NOT NULL,
`id_mot` bigint(21) NOT NULL,
`relevance` int(11) NOT NULL,
`off` varchar(3) NOT NULL DEFAULT 'non',
KEY `id_syndic` (`id_syndic`),
KEY `id_mot` (`id_mot`)
"
);
*/

## table cree a l'upgrade, par injection des donnees�
/*
$tables_auxiliaires['spip_oc_uri'] = seenthis_lire_create_table(
"
`uri` text NOT NULL,
`relevance` int(11) NOT NULL,
`off` varchar(3) NOT NULL DEFAULT 'non',
`tag` longtext NOT NULL
"
## SPIP 2.1 n'accepte pas les KEY avec (60)
## on l'ajoute a la main plus bas
# KEY `tag` (`tag`(60)),
# KEY `uri` (`uri`(60)),
);
*/

function seenthisoc_declarer_tables_auxiliaires($tables_auxiliaires) {
return $tables_auxiliaires;

}

function seenthisoc_upgrade($nom_meta_base_version,$version_cible){
function seenthisoc_upgrade($nom_meta_base_version, $version_cible) {
$current_version = 0.0;


if ((!isset($GLOBALS['meta'][$nom_meta_base_version]) )
|| (($current_version = $GLOBALS['meta'][$nom_meta_base_version])!=$version_cible)){
if (
(!isset($GLOBALS['meta'][$nom_meta_base_version]) )
|| (($current_version = $GLOBALS['meta'][$nom_meta_base_version]) != $version_cible)
) {
include_spip('base/abstract_sql');
if (version_compare($current_version,"1.0.2",'<')){
if (version_compare($current_version, '1.0.2', '<')) {
include_spip('base/serial');
include_spip('base/auxiliaires');
include_spip('base/create');
creer_base();

maj_tables(array(
maj_tables([
'spip_syndic_oc',
));
if (version_compare($current_version,"1.0.2",'<')) {
]);

if (version_compare($current_version, '1.0.2', '<')) {
seenthisoc_recuperer_tags_102();
sql_query("ALTER TABLE spip_oc_uri ADD INDEX `tag` (`tag`(60))");
sql_query("ALTER TABLE spip_oc_uri ADD INDEX `uri` (`uri`(60))");
sql_query('ALTER TABLE spip_oc_uri ADD INDEX `tag` (`tag`(60))');
sql_query('ALTER TABLE spip_oc_uri ADD INDEX `uri` (`uri`(60))');
}

/* pour la version suivante
if (version_compare($current_version,"1.0.3",'<')) {
sql_drop_table("spip_syndic_oc");
}
*/
/**
* pour la version suivante
* if (version_compare($current_version,"1.0.3",'<')) {
* sql_drop_table("spip_syndic_oc");
* }
*/

ecrire_meta($nom_meta_base_version,$current_version=$version_cible,'non');
ecrire_meta($nom_meta_base_version, $current_version = $version_cible, 'non');
}

}
}

function seenthisoc_vider_tables($nom_meta_base_version) {
effacer_meta($nom_meta_base_version);
sql_drop_table("spip_syndic_oc");
sql_drop_table('spip_syndic_oc');
}


function seenthisoc_install($action,$prefix,$version_cible){
$version_base = $GLOBALS[$prefix."_base_version"];
switch ($action){
function seenthisoc_install($action, $prefix, $version_cible) {
$version_base = $GLOBALS[$prefix . '_base_version'];
switch ($action) {
case 'test':
$ok = (isset($GLOBALS['meta'][$prefix."_base_version"])
AND version_compare($GLOBALS['meta'][$prefix."_base_version"],$version_cible,">="));
$ok = (isset($GLOBALS['meta'][$prefix . '_base_version'])
and version_compare($GLOBALS['meta'][$prefix . '_base_version'], $version_cible, '>='));

if (!function_exists('curl_init')) {
$ok = false;
echo "<p class='error'>"._L("n&#xE9;cessite @module@", array('module' => 'php-curl'))."</p>";
echo "<p class='error'>" . _L('n&#xE9;cessite @module@', ['module' => 'php-curl']) . '</p>';
}

return $ok;
break;
case 'install':
seenthisoc_upgrade($prefix."_base_version",$version_cible);
seenthisoc_upgrade($prefix . '_base_version', $version_cible);
break;
case 'uninstall':
seenthisoc_vider_tables($prefix."_base_version");
seenthisoc_vider_tables($prefix . '_base_version');
break;
}
}
Expand All @@ -146,7 +107,4 @@ function seenthisoc_recuperer_tags_102() {
LEFT JOIN spip_groupes_mots AS g ON m.id_groupe=g.id_groupe
LEFT JOIN spip_syndic AS u ON u.id_syndic=a.id_syndic
");

}

?>
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "seenthis/opencalais",
"description": "Sphinx pour Seenthis",
"license": "GPL-3.0-or-later",
"type": "spip-plugin",
"authors": [
{
"name": "Arno*",
"email": "[email protected]"
}
],
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/php-compatibility": "10.x-dev",
"spip/coding-standards": "^1.3"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}
Loading