From 320c3b63e842a480b448a8a614be28442e44412d Mon Sep 17 00:00:00 2001 From: tofulm Date: Tue, 20 Aug 2019 17:45:22 +0200 Subject: [PATCH] ajout autorisation dans les actions --- UltiSnips/html.snippets | 3 + UltiSnips/php.snippets | 13 +- php.json | 302 ++++++++++++++++++++-------------------- 3 files changed, 166 insertions(+), 152 deletions(-) diff --git a/UltiSnips/html.snippets b/UltiSnips/html.snippets index 84fd1df..7bd770d 100755 --- a/UltiSnips/html.snippets +++ b/UltiSnips/html.snippets @@ -307,3 +307,6 @@ var url_${1:nom} = "[(#VAL{$1}|generer_url_action{"", 1})]"; ${0} endsnippet +snippet ifa "" w +$0 +endsnippet diff --git a/UltiSnips/php.snippets b/UltiSnips/php.snippets index 80b81e2..64834a3 100755 --- a/UltiSnips/php.snippets +++ b/UltiSnips/php.snippets @@ -5,6 +5,12 @@ snippet action "SPIP action declenchee dans un lien" if (!defined('_ECRIRE_INC_VERSION')) return; function action_`!v vim_snippets#Filename()`_dist(){ + + include_spip('inc/autoriser'); + if (! autoriser("etre","connecte")) { + return false; + } + $securiser_action = charger_fonction('securiser_action', 'inc'); $arg = $securiser_action(); $$1 = $arg; @@ -29,6 +35,11 @@ if (!defined('_ECRIRE_INC_VERSION')) return; function action_`!v vim_snippets#Filename()`_dist($arg=null){ + include_spip('inc/autoriser'); + if (! autoriser("etre","connecte")) { + return false; + } + if (is_null($arg)) { // DEMI sécurité : s'il y a un hash, on teste la sécurité if (_request('hash')) { @@ -194,7 +205,7 @@ suivre_invalideur("id='${1:id_objet}/1'"); ${0} endsnippet -snippet req "SPIP _request()" +snippet req "SPIP _request()" w _request('${1}')${0} endsnippet diff --git a/php.json b/php.json index 5fe8486..4467f75 100644 --- a/php.json +++ b/php.json @@ -1,153 +1,153 @@ { - "action": { - "prefix": "action", - "body": " ${3:\"\"},\n\t);\n\t${0}\n\treturn $valeurs;\n}\n\nfunction formulaires_${TM_FILENAME_BASE}_verifier_dist($$1){\n\t$$2 = _request('$2');\n\n\t$erreurs = array();\n\t//champs obligatoire\n\tforeach (array ('$2') as $obligatoire) {\n\t\tif (!_request($obligatoire)) $erreurs[$obligatoire] = 'Ce champs est obligatoire';\n\t}\n\n\t//autres erreurs\n\t$erreurs['$2'] = \"Ce champ ne convient pas.\";\n\n\t//Il y a des erreurs\n\tif (count($erreurs)) {\n\t\t$erreurs['message_erreur'] = 'Votre saisie contient des erreurs !';\n\t}\n\n\treturn $erreurs;\n}\n\nfunction formulaires_${TM_FILENAME_BASE}_traiter_dist($$1){\n\t$$2 = _request('$2');\n\n\t$retour = array();\n\t$retour['message_ok'] = \"bravo\";\n\t$retour['redirect'] = \"spip.php?page=perdu\";\n\t$retour['editable'] = true;\n\n\treturn $retour;\n}", - "description": "SPIP" - }, - "bigint": { - "prefix": "bigint", - "body": "'bigint(${1:21}) NOT NULL',${0}", - "description": "SQL bigint(21)" - }, - "float": { - "prefix": "float", - "body": "'float NOT NULL',${0}", - "description": "SQL float" - }, - "tinyint": { - "prefix": "tinyint", - "body": "'tinyint(4) NOT NULL',${0}", - "description": "SQL tinyint(4)" - }, - "decimal": { - "prefix": "decimal", - "body": "'decimal(10,2) DEFAULT \"0\" NOT NULL',${0}", - "description": "SQL decimal(10,2)" - }, - "text": { - "prefix": "text", - "body": "'text NOT NULL DEFAULT \"\"',${0}", - "description": "SQL text NOT NULL" - }, - "varchar": { - "prefix": "varchar", - "body": "'varchar(${1:255}) NOT NULL DEFAULT \"\"',${0}", - "description": "SQL varchar(25)" - }, - "datetime": { - "prefix": "datetime", - "body": "'datetime NOT NULL DEFAULT \"0000-00-00 00:00:00\"',${0}", - "description": "SQL datetime" - }, - "php": { - "prefix": "php", - "body": " $${2:valeur_champs1},\n\t'${3:champs2}' => $${4:valeur_champs2},\n);\n$id_objet = objet_inserer($objet, $id_parent);\n//ou $id_objet=$ma_variable;\n\nobjet_modifier($objet, $id_objet, $set);", - "description": "SPIP API Objet" - }, - "api_lien": { - "prefix": "api_lien", - "body": "// utilisation API editier_liens\n// http://www.spip.net/fr_article5477.html\ninclude_spip('action/editer_liens');\n\n$objets_source = array(\"${1:auteur}\"=>${2:id_auteur ou array});\n$objets_lies = array(\"${3:article}\"=>${:id_article ou array});\n${0}\n\nobjet_associer($objets_source, $objets_lies);", - "description": "SPIP API Lien" - }, - "cache": { - "prefix": "cache", - "body": "include_spip('inc/invalideur');\nsuivre_invalideur(\"id='${1:id_objet}/1'\");\n${0}", - "description": "SPIP invalide cache" - }, - "req": { - "prefix": "req", - "body": "_request('${1}')${0}", - "description": "SPIP _request()" - }, - "array": { - "prefix": "array", - "body": "array(\n\t'${1}' => ${2},${0}\n\t);", - "description": "SPIP Array( X lignes)" - }, - "array_ligne": { - "prefix": "array_ligne", - "body": "'${1:var}' => $$1,${0}", - "description": "SPIP Une ligne d'array" - }, - "vd": { - "prefix": "vd", - "body": "var_dump($${1:var});\n${0}", - "description": "var_dump()" - }, - "ec": { - "prefix": "ec", - "body": "echo ${1};\n${0}", - "description": "Echo" - }, - "pre": { - "prefix": "pre", - "body": "echo \"
\";\n\tprint_r($${1});\necho \"
\";\n${0}", - "description": "
 print_r"
-  },
-  "include": {
-    "prefix": "include",
-    "body": "include_spip('${1:fichier}');\n${0}",
-    "description": "SPIP include_spip"
-  },
-  "pipeline": {
-    "prefix": "pipeline",
-    "body": "/**\n * Charger des styles CSS\n *\n * @pipeline insert_head_css\n * @param string $flux Code html des styles CSS à charger\n * @return string Code html complété\n **/\nfunction ${1:prefix}_insert_head_css($flux){\n\t$flux .= '' . \"\\n\";\n\t$flux .= '' . \"\\n\";\n\treturn $flux;\n}\n${0}\n/**\n * Charger des scripts jquery\n *\n * @pipeline jqueryui_plugins\n * @param array $scripts Liste à charger\n * @return array Liste complétée\n **/\nfunction $1_jquery_plugins($scripts){\n\t$scripts[] = \"aa\";\n\t$scripts[] = produire_fond_statique('javascript/bigup.js');\n\treturn $scripts;\n}\n\n/**\n * Charger des scripts jquery ui\n *\n * @pipeline jqueryui_plugins\n * @param array $scripts Liste à charger\n * @return array Liste complétée\n **/\nfunction $1_jqueryui_plugins($scripts){\n\t$scripts[] = \"aa\";\n\treturn $scripts;\n}",
-    "description": "SPIP Les pipelines de base"
-  },
-  "debugspip": {
-    "prefix": "debugspip",
-    "body": "function debug_spip(){\n\tdefine('_DEBUG_SLOW_QUERIES', true);\n\tdefine('_BOUCLE_PROFILER', 5000);\n\tdefine('_LOG_FILTRE_GRAVITE', 8);\n\tdefine('_LOG_FILELINE',true);\n\tdefine('_DEBUG_AUTORISER', true);\n\tdefine('_MAX_LOG', 500000);\n\n\terror_reporting(E_ALL^E_NOTICE);\n\tini_set (\"display_errors\", \"On\");\n\tini_set(\"html_errors\", \"On\");\n\tini_set(\"allow_url_fopen\", \"On\");\n\tdefine('SPIP_ERREUR_REPORT',E_ALL^E_NOTICE);\n\tdefine('SPIP_ERREUR_REPORT_INCLUDE_PLUGINS',E_ALL^E_NOTICE);\n\n\n\tdefine('_NO_CACHE', -1);\n\tdefine('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);\n}\n\nif ( $_SERVER['SERVER_ADDR'] === \"127.0.0.1\") {\n\tdebug_spip();\n}\n\nif ( substr($_SERVER['SERVER_ADDR'],0,7) === \"192.168\") {\n\tdebug_spip();\n}",
-    "description": "SPIP define de debug"
-  },
-  "/*": {
-    "prefix": "/*",
-    "body": "/**\n * ${0}\n **/"
-  },
-  "doc": {
-    "prefix": "doc",
-    "body": "/**\n * ${1:function non documente}\n *\n * @param ${2}\n * @return ${0}\n * @author tofulm\n **/"
-  },
-  "fdoc": {
-    "prefix": "fdoc",
-    "body": "/**\n * ${4:fonction non documente}\n *\n * @param ${5}\n * @return ${3}\n * @author tofulm\n **/\nfunction ${1}(${2}){\n\t${6}\n }"
-  },
-  "spip_log": {
-    "prefix": "spip_log",
-    "body": "spip_log(${1},${2:\"gamuza\"});\n${0}",
-    "description": "SPIP fctn spip_log()"
-  }
+	"action": {
+		"prefix": "action",
+		"body": " ${3:\"\"},\n\t);\n\t${0}\n\treturn $valeurs;\n}\n\nfunction formulaires_${TM_FILENAME_BASE}_verifier_dist($$1){\n\t$$2   = _request('$2');\n\n\t$erreurs = array();\n\t//champs obligatoire\n\tforeach (array ('$2') as $obligatoire) {\n\t\tif (!_request($obligatoire)) $erreurs[$obligatoire] = 'Ce champs est obligatoire';\n\t}\n\n\t//autres erreurs\n\t$erreurs['$2'] = \"Ce champ ne convient pas.\";\n\n\t//Il y a des erreurs\n\tif (count($erreurs)) {\n\t\t$erreurs['message_erreur'] = 'Votre saisie contient des erreurs !';\n\t}\n\n\treturn $erreurs;\n}\n\nfunction formulaires_${TM_FILENAME_BASE}_traiter_dist($$1){\n\t$$2   = _request('$2');\n\n\t$retour = array();\n\t$retour['message_ok'] = \"bravo\";\n\t$retour['redirect'] = \"spip.php?page=perdu\";\n\t$retour['editable'] = true;\n\n\treturn $retour;\n}",
+		"description": "SPIP"
+	},
+	"bigint": {
+		"prefix": "bigint",
+		"body": "'bigint(${1:21}) NOT NULL',${0}",
+		"description": "SQL bigint(21)"
+	},
+	"float": {
+		"prefix": "float",
+		"body": "'float NOT NULL',${0}",
+		"description": "SQL float"
+	},
+	"tinyint": {
+		"prefix": "tinyint",
+		"body": "'tinyint(4) NOT NULL',${0}",
+		"description": "SQL tinyint(4)"
+	},
+	"decimal": {
+		"prefix": "decimal",
+		"body": "'decimal(10,2) DEFAULT \"0\" NOT NULL',${0}",
+		"description": "SQL decimal(10,2)"
+	},
+	"text": {
+		"prefix": "text",
+		"body": "'text NOT NULL DEFAULT \"\"',${0}",
+		"description": "SQL text NOT NULL"
+	},
+	"varchar": {
+		"prefix": "varchar",
+		"body": "'varchar(${1:255}) NOT NULL DEFAULT \"\"',${0}",
+		"description": "SQL varchar(25)"
+	},
+	"datetime": {
+		"prefix": "datetime",
+		"body": "'datetime NOT NULL DEFAULT \"0000-00-00 00:00:00\"',${0}",
+		"description": "SQL datetime"
+	},
+	"php": {
+		"prefix": "php",
+		"body": " $${2:valeur_champs1},\n\t'${3:champs2}'    => $${4:valeur_champs2},\n);\n$id_objet = objet_inserer($objet, $id_parent);\n//ou $id_objet=$ma_variable;\n\nobjet_modifier($objet, $id_objet, $set);",
+		"description": "SPIP API Objet"
+	},
+	"api_lien": {
+		"prefix": "api_lien",
+		"body": "// utilisation API editier_liens\n// http://www.spip.net/fr_article5477.html\ninclude_spip('action/editer_liens');\n\n$objets_source = array(\"${1:auteur}\"=>${2:id_auteur ou array});\n$objets_lies = array(\"${3:article}\"=>${:id_article ou array});\n${0}\n\nobjet_associer($objets_source, $objets_lies);",
+		"description": "SPIP API Lien"
+	},
+	"cache": {
+		"prefix": "cache",
+		"body": "include_spip('inc/invalideur');\nsuivre_invalideur(\"id='${1:id_objet}/1'\");\n${0}",
+		"description": "SPIP invalide cache"
+	},
+	"req": {
+		"prefix": "req",
+		"body": "_request('${1}')${0}",
+		"description": "SPIP _request()"
+	},
+	"array": {
+		"prefix": "array",
+		"body": "array(\n\t'${1}' => ${2},${0}\n\t);",
+		"description": "SPIP Array( X lignes)"
+	},
+	"array_ligne": {
+		"prefix": "array_ligne",
+		"body": "'${1:var}' => $$1,${0}",
+		"description": "SPIP Une ligne d'array"
+	},
+	"vd": {
+		"prefix": "vd",
+		"body": "var_dump($${1:var});\n${0}",
+		"description": "var_dump()"
+	},
+	"ec": {
+		"prefix": "ec",
+		"body": "echo ${1};\n${0}",
+		"description": "Echo"
+	},
+	"pre": {
+		"prefix": "pre",
+		"body": "echo \"
\";\n\tprint_r($${1});\necho \"
\";\n${0}", + "description": "
 print_r"
+	},
+	"include": {
+		"prefix": "include",
+		"body": "include_spip('${1:fichier}');\n${0}",
+		"description": "SPIP include_spip"
+	},
+	"pipeline": {
+		"prefix": "pipeline",
+		"body": "/**\n * Charger des styles CSS\n *\n * @pipeline insert_head_css\n * @param string $flux Code html des styles CSS à charger\n * @return string Code html complété\n **/\nfunction ${1:prefix}_insert_head_css($flux){\n\t$flux .= '' . \"\\n\";\n\t$flux .= '' . \"\\n\";\n\treturn $flux;\n}\n${0}\n/**\n * Charger des scripts jquery\n *\n * @pipeline jqueryui_plugins\n * @param array $scripts Liste à charger\n * @return array Liste complétée\n **/\nfunction $1_jquery_plugins($scripts){\n\t$scripts[] = \"aa\";\n\t$scripts[] = produire_fond_statique('javascript/bigup.js');\n\treturn $scripts;\n}\n\n/**\n * Charger des scripts jquery ui\n *\n * @pipeline jqueryui_plugins\n * @param array $scripts Liste à charger\n * @return array Liste complétée\n **/\nfunction $1_jqueryui_plugins($scripts){\n\t$scripts[] = \"aa\";\n\treturn $scripts;\n}",
+		"description": "SPIP Les pipelines de base"
+	},
+	"debugspip": {
+		"prefix": "debugspip",
+		"body": "function debug_spip(){\n\tdefine('_DEBUG_SLOW_QUERIES', true);\n\tdefine('_BOUCLE_PROFILER', 5000);\n\tdefine('_LOG_FILTRE_GRAVITE', 8);\n\tdefine('_LOG_FILELINE',true);\n\tdefine('_DEBUG_AUTORISER', true);\n\tdefine('_MAX_LOG', 500000);\n\n\terror_reporting(E_ALL^E_NOTICE);\n\tini_set (\"display_errors\", \"On\");\n\tini_set(\"html_errors\", \"On\");\n\tini_set(\"allow_url_fopen\", \"On\");\n\tdefine('SPIP_ERREUR_REPORT',E_ALL^E_NOTICE);\n\tdefine('SPIP_ERREUR_REPORT_INCLUDE_PLUGINS',E_ALL^E_NOTICE);\n\n\n\tdefine('_NO_CACHE', -1);\n\tdefine('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);\n}\n\nif ( $_SERVER['SERVER_ADDR'] === \"127.0.0.1\") {\n\tdebug_spip();\n}\n\nif ( substr($_SERVER['SERVER_ADDR'],0,7) === \"192.168\") {\n\tdebug_spip();\n}",
+		"description": "SPIP define de debug"
+	},
+	"/*": {
+		"prefix": "/*",
+		"body": "/**\n * ${0}\n **/"
+	},
+	"doc": {
+		"prefix": "doc",
+		"body": "/**\n * ${1:function non documente}\n *\n * @param ${2}\n * @return ${0}\n * @author tofulm\n **/"
+	},
+	"fdoc": {
+		"prefix": "fdoc",
+		"body": "/**\n * ${4:fonction non documente}\n *\n * @param ${5}\n * @return ${3}\n * @author tofulm\n **/\nfunction ${1}(${2}){\n\t${6}\n }"
+	},
+	"spip_log": {
+		"prefix": "spip_log",
+		"body": "spip_log(${1},${2:\"gamuza\"});\n${0}",
+		"description": "SPIP fctn spip_log()"
+	}
 }