Browse Source

style: Coding Standard (phpcbf)

master
b_b 2 months ago
parent
commit
8456b0a620
  1. 101
      action/editer_legende.php
  2. 16
      action/supprimer_legende.php
  3. 69
      base/legendes.php
  4. 46
      formulaires/editer_legende.php
  5. 42
      legendes_administrations.php
  6. 54
      legendes_autoriser.php
  7. 50
      legendes_pipelines.php

101
action/editer_legende.php

@ -1,29 +1,32 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function action_editer_legende_dist($arg=null){
function action_editer_legende_dist($arg = null) {
if (is_null($arg)){
if (is_null($arg)) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
}
// si id_legende n'est pas un nombre, c'est une creation
// si id_legende n'est pas un nombre, c'est une creation
if (!$id_legende = intval($arg)) {
$id_document = _request('id_document');
if (!$id_legende = legende_inserer($id_document))
return array(false,_L('echec'));
if (!$id_legende = legende_inserer($id_document)) {
return [false,_L('echec')];
}
}
$err = legende_modifier($id_legende);
return array($id_legende,$err);
return [$id_legende,$err];
}
function legende_modifier($id_legende){
function legende_modifier($id_legende) {
$err = '';
$c = array();
$c = [];
$c['posy'] = _request('top');
$c['posx'] = _request('left');
$c['width'] = _request('width');
@ -33,98 +36,102 @@ function legende_modifier($id_legende){
include_spip('inc/modifier');
$err = objet_modifier_champs('legende', $id_legende, array(
$err = objet_modifier_champs('legende', $id_legende, [
'invalideur' => "id='id_legende/$id_legende'"
), $c);
], $c);
return $err;
}
// creer une nouvelle legende
function legende_inserer($id_document){
function legende_inserer($id_document) {
include_spip('inc/autoriser');
if (!autoriser('creerdans','legende',$id_document))
if (!autoriser('creerdans', 'legende', $id_document)) {
return false;
$champs = array(
}
$champs = [
'id_document' => $id_document,
'id_auteur' => $GLOBALS['visiteur_session']['id_auteur'],
'date' => date('Y-m-d H:i:s'));
'date' => date('Y-m-d H:i:s')
];
// Envoyer aux plugins
$champs = pipeline('pre_insertion',
array(
'args' => array(
$champs = pipeline(
'pre_insertion',
[
'args' => [
'table' => 'spip_legendes',
),
],
'data' => $champs
)
]
);
$id_legende = sql_insertq("spip_legendes", $champs);
$id_legende = sql_insertq('spip_legendes', $champs);
if (!$id_legende){
if (!$id_legende) {
spip_log("legendes action insert legende : impossible d'ajouter une legende");
return false;
}
return $id_legende;
}
return $id_legende;
}
// supprimer une legende
function supprimer_legende($id_legende){
function supprimer_legende($id_legende) {
include_spip('inc/autoriser');
if (!autoriser('supprimer','legende',$id_legende))
if (!autoriser('supprimer', 'legende', $id_legende)) {
return false;
if (intval($id_legende)){
sql_delete("spip_legendes", "id_legende=".intval($id_legende));
}
if (intval($id_legende)) {
sql_delete('spip_legendes', 'id_legende=' . intval($id_legende));
}
$id_legende = 0;
return $id_legende;
}
// tourner une legende
function tourner_legende($id_legende,$angle){
function tourner_legende($id_legende, $angle) {
// recuperer les infos dela note à tourner
$legende = sql_fetsel('*','spip_legendes','id_legende='.intval($id_legende));
$c = array();
foreach($legende as $key=>$val)
$legende = sql_fetsel('*', 'spip_legendes', 'id_legende=' . intval($id_legende));
$c = [];
foreach ($legende as $key => $val) {
$c[$key] = $val;
$n = array();
}
$n = [];
// recuperer les infos de l'image associee
$image = sql_fetsel('*','spip_documents','id_document='.intval($c['id_document']));
$image = sql_fetsel('*', 'spip_documents', 'id_document=' . intval($c['id_document']));
$largeur = $image['largeur'];
$hauteur = $image['hauteur'];
include_spip('inc/modifier');
if($angle==0){
if ($angle == 0) {
return '';
}
if($angle==-90){
if ($angle == -90) {
$n['posx'] = $c['posy'];
$n['posy'] = $hauteur - ($c['posx'] + $c['width']);
$n['width'] = $c['height'];
$n['height'] = $c['width'];
$err .= legende_modifier($id_legende, $n);
}
if($angle==90){
if ($angle == 90) {
$n['posx'] = $largeur - ($c['posy'] + $c['height']);
$n['posy'] = $c['posx'];
$n['width'] = $c['height'];
$n['height'] = $c['width'];
$err .= legende_modifier($id_legende, $n);
}
if($angle==180){
if ($angle == 180) {
$n['posx'] = $largeur - ($c['posx'] + $c['width']);
$n['posy'] = $hauteur - ($c['posy'] + $c['height']);
$n['width'] = $c['width'];
$n['height'] = $c['height'];
$err .= legende_modifier($id_legende, $n);
}
return $err;
return $err;
}

16
action/supprimer_legende.php

@ -1,17 +1,19 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function action_supprimer_legende_dist() {
function action_supprimer_legende_dist(){
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
list($id_legende) = preg_split(',[^0-9],',$arg);
list($id_legende) = preg_split(',[^0-9],', $arg);
include_spip('inc/autoriser');
if (intval($id_legende) and autoriser('supprimer','legende',$id_legende,null,null)){
include_spip("action/editer_legende");
if (intval($id_legende) and autoriser('supprimer', 'legende', $id_legende, null, null)) {
include_spip('action/editer_legende');
supprimer_legende($id_legende);
}
}

69
base/legendes.php

@ -1,34 +1,35 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
function legendes_declarer_tables_interfaces($interface) {
$interface['table_des_tables']['legendes'] = 'legendes';
return $interface;
}
function legendes_declarer_tables_objets_sql($tables) {
$tables['spip_legendes'] = array(
'principale' => 'oui',
'field' => array(
'id_legende' => 'bigint(21) NOT NULL',
'id_document' => "bigint(21) NOT NULL DEFAULT '0'",
'id_auteur' => "bigint(21) NOT NULL DEFAULT '0'",
'posx' => "bigint(21) NOT NULL DEFAULT '0'",
'posy' => "bigint(21) NOT NULL DEFAULT '0'",
'width' => "bigint(21) NOT NULL DEFAULT '0'",
'height' => "bigint(21) NOT NULL DEFAULT '0'",
'texte' => 'text NOT NULL',
'date' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"
),
'key' => array(
'PRIMARY KEY' => 'id_legende',
'KEY id_document' => 'id_document',
'KEY id_auteur' => 'id_auteur'
)
);
return $tables;
}
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function legendes_declarer_tables_interfaces($interface) {
$interface['table_des_tables']['legendes'] = 'legendes';
return $interface;
}
function legendes_declarer_tables_objets_sql($tables) {
$tables['spip_legendes'] = [
'principale' => 'oui',
'field' => [
'id_legende' => 'bigint(21) NOT NULL',
'id_document' => "bigint(21) NOT NULL DEFAULT '0'",
'id_auteur' => "bigint(21) NOT NULL DEFAULT '0'",
'posx' => "bigint(21) NOT NULL DEFAULT '0'",
'posy' => "bigint(21) NOT NULL DEFAULT '0'",
'width' => "bigint(21) NOT NULL DEFAULT '0'",
'height' => "bigint(21) NOT NULL DEFAULT '0'",
'texte' => 'text NOT NULL',
'date' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'"
],
'key' => [
'PRIMARY KEY' => 'id_legende',
'KEY id_document' => 'id_document',
'KEY id_auteur' => 'id_auteur'
]
];
return $tables;
}

46
formulaires/editer_legende.php

@ -1,21 +1,24 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/actions');
include_spip('inc/editer');
include_spip('inc/autoriser');
function formulaires_editer_legende_charger_dist($id_legende='new', $id_document='', $retour=''){
$row = sql_fetsel('*','spip_legendes','id_legende='.intval($id_legende));
$valeurs = formulaires_editer_objet_charger('legende',$id_legende,0,0,$retour,'',$row,$hidden);
function formulaires_editer_legende_charger_dist($id_legende = 'new', $id_document = '', $retour = '') {
$row = sql_fetsel('*', 'spip_legendes', 'id_legende=' . intval($id_legende));
$valeurs = formulaires_editer_objet_charger('legende', $id_legende, 0, 0, $retour, '', $row, $hidden);
if (intval($id_legende)){
foreach($row as $key=>$val)
if (intval($id_legende)) {
foreach ($row as $key => $val) {
$valeurs[$key] = $val;
}else{
}
}else {
$valeurs['id_document'] = $id_document;
}
@ -24,28 +27,28 @@ function formulaires_editer_legende_charger_dist($id_legende='new', $id_document
return $valeurs;
}
function formulaires_editer_legende_verifier_dist($id_legende='new', $id_document='', $retour=''){
$erreurs = array();
function formulaires_editer_legende_verifier_dist($id_legende = 'new', $id_document = '', $retour = '') {
$erreurs = [];
return $erreurs;
}
function formulaires_editer_legende_traiter_dist($id_legende='new', $id_document='', $retour=''){
$message = array('editable'=>true, 'message_ok'=>'');
function formulaires_editer_legende_traiter_dist($id_legende = 'new', $id_document = '', $retour = '') {
$message = ['editable' => true, 'message_ok' => ''];
if (_request('effacer')) {
include_spip("action/editer_legende");
include_spip('action/editer_legende');
supprimer_legende($id_legende);
$message['message_ok'] = _T("legendes:legende_supprimer_ok");
$message['message_ok'] = _T('legendes:legende_supprimer_ok');
}
if (_request('valider')) {
$action_editer = charger_fonction("editer_legende",'action');
$action_editer = charger_fonction('editer_legende', 'action');
list($id,$err) = $action_editer($id_legende);
$message['message_ok'] = _T("legendes:legende_enregistrer_ok");
set_request('id_legende',$id);
if ($err){
$message['message_ok'] = _T('legendes:legende_enregistrer_ok');
set_request('id_legende', $id);
if ($err) {
$message .= $err;
}
elseif ($retour) {
@ -54,7 +57,6 @@ function formulaires_editer_legende_traiter_dist($id_legende='new', $id_document
$message .= redirige_formulaire($retour);
}
}
return $message;
}

42
legendes_administrations.php

@ -1,20 +1,22 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
function legendes_upgrade($nom_meta_base_version, $version_cible) {
$maj = array();
$maj['create'] = array(
array('maj_tables', array('spip_legendes'))
);
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
}
function legendes_vider_tables($nom_meta_base_version) {
sql_drop_table('spip_legendes');
effacer_meta($nom_meta_base_version);
effacer_meta('legendes');
}
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function legendes_upgrade($nom_meta_base_version, $version_cible) {
$maj = [];
$maj['create'] = [
['maj_tables', ['spip_legendes']]
];
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
}
function legendes_vider_tables($nom_meta_base_version) {
sql_drop_table('spip_legendes');
effacer_meta($nom_meta_base_version);
effacer_meta('legendes');
}

54
legendes_autoriser.php

@ -1,9 +1,12 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/* pour que le pipeline ne rale pas ! */
function legendes_autoriser(){}
function legendes_autoriser() {
}
/**
* Autorisation d'ajout d'une legende a un document
@ -15,13 +18,16 @@ function legendes_autoriser(){}
* @param array $options
* @return bool
*/
function autoriser_legende_creerdans_dist($faire,$quoi,$id,$qui,$options){
if (!$id) return false; // interdit de creer une legende sur un document vide !
function autoriser_legende_creerdans_dist($faire, $quoi, $id, $qui, $options) {
if (!$id) {
return false; // interdit de creer une legende sur un document vide !
}
// autorisation personnalisee par config
if(lire_config('legendes/statuts_creerdans') and $qui['statut'])
return ($qui['statut']<=lire_config('legendes/statuts_creerdans','0minirezo'));
if (lire_config('legendes/statuts_creerdans') and $qui['statut']) {
return ($qui['statut'] <= lire_config('legendes/statuts_creerdans', '0minirezo'));
}
// ou autorisation du document associe
return autoriser('modifier','document',$id,$qui);
return autoriser('modifier', 'document', $id, $qui);
}
/**
@ -34,13 +40,16 @@ function autoriser_legende_creerdans_dist($faire,$quoi,$id,$qui,$options){
* @param array $options
* @return bool
*/
function autoriser_legende_modifier_dist($faire,$quoi,$id,$qui,$options){
if (!isset($options['id_document']) or !$id_document=$options['id_document'])
$legende = sql_fetsel('*','spip_legendes','id_legende='.intval($id));
if (!$legende['id_document']) return false;
function autoriser_legende_modifier_dist($faire, $quoi, $id, $qui, $options) {
if (!isset($options['id_document']) or !$id_document = $options['id_document']) {
$legende = sql_fetsel('*', 'spip_legendes', 'id_legende=' . intval($id));
}
if (!$legende['id_document']) {
return false;
}
// autorisation personnalisee par config
if (lire_config('legendes/statuts_modifier') and $qui['statut']){
if ($qui['statut'] <= lire_config('legendes/statuts_modifier','0minirezo')){
if (lire_config('legendes/statuts_modifier') and $qui['statut']) {
if ($qui['statut'] <= lire_config('legendes/statuts_modifier', '0minirezo')) {
if (($qui['statut'] != '0minirezo') and ($qui['id_auteur'] != $legende['id_auteur'])) {
return false;
}
@ -48,7 +57,7 @@ function autoriser_legende_modifier_dist($faire,$quoi,$id,$qui,$options){
}
}
// ou autorisation du document associe
return autoriser('modifier','document',$legende['id_document'],$qui);
return autoriser('modifier', 'document', $legende['id_document'], $qui);
}
@ -62,13 +71,14 @@ function autoriser_legende_modifier_dist($faire,$quoi,$id,$qui,$options){
* @param array $options
* @return bool
*/
function autoriser_legende_supprimer_dist($faire,$quoi,$id,$qui,$options){
if (!isset($options['id_document']) or !$id_document=$options['id_document'])
$id_document = sql_getfetsel('id_document','spip_legendes','id_legende='.intval($id));
function autoriser_legende_supprimer_dist($faire, $quoi, $id, $qui, $options) {
if (!isset($options['id_document']) or !$id_document = $options['id_document']) {
$id_document = sql_getfetsel('id_document', 'spip_legendes', 'id_legende=' . intval($id));
}
// autorisation personnalisee par config
if (lire_config('legendes/statuts_supprimer') and $qui['statut']){
if ($qui['statut'] <= lire_config('legendes/statuts_supprimer','0minirezo')){
$legende = sql_getfetsel('id_auteur','spip_legendes','id_legende='.intval($id));
if (lire_config('legendes/statuts_supprimer') and $qui['statut']) {
if ($qui['statut'] <= lire_config('legendes/statuts_supprimer', '0minirezo')) {
$legende = sql_getfetsel('id_auteur', 'spip_legendes', 'id_legende=' . intval($id));
if (($qui['statut'] != '0minirezo') and ($qui['id_auteur'] != $legende['id_auteur'])) {
return false;
}
@ -76,7 +86,5 @@ function autoriser_legende_supprimer_dist($faire,$quoi,$id,$qui,$options){
}
}
// ou autorisation du document associe
return autoriser('modifier','document',$id_document,$qui);
return autoriser('modifier', 'document', $id_document, $qui);
}
?>

50
legendes_pipelines.php

@ -1,32 +1,34 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function legendes_insert_head($flux){
$flux .='<script src="'._DIR_PLUGIN_LEGENDES.'javascript/jquery.annotate.js" type="text/javascript"></script>';
$flux .= '<link rel="stylesheet" href="'._DIR_PLUGIN_LEGENDES.'legendes.css" type="text/css" media="screen" />';
function legendes_insert_head($flux) {
$flux .= '<script src="' . _DIR_PLUGIN_LEGENDES . 'javascript/jquery.annotate.js" type="text/javascript"></script>';
$flux .= '<link rel="stylesheet" href="' . _DIR_PLUGIN_LEGENDES . 'legendes.css" type="text/css" media="screen" />';
return $flux;
}
function legendes_jqueryui_plugins($plugins){
$plugins[] = "jquery.ui.core";
$plugins[] = "jquery.ui.widget";
$plugins[] = "jquery.ui.mouse";
$plugins[] = "jquery.ui.draggable";
$plugins[] = "jquery.ui.resizable";
function legendes_jqueryui_plugins($plugins) {
$plugins[] = 'jquery.ui.core';
$plugins[] = 'jquery.ui.widget';
$plugins[] = 'jquery.ui.mouse';
$plugins[] = 'jquery.ui.draggable';
$plugins[] = 'jquery.ui.resizable';
return $plugins;
}
function legendes_post_edition($flux){
function legendes_post_edition($flux) {
// si on tourne un document, tourner les legendes associees
if($flux['args']['action']=='tourner'){
if ($flux['args']['action'] == 'tourner') {
$id_document = $flux['args']['id_objet'];
$angle = $flux['args']['champs']['rotation'];
$res = sql_select("id_legende", "spip_legendes", "id_document=".intval($id_document));
while ($row = sql_fetch($res)){
$res = sql_select('id_legende', 'spip_legendes', 'id_document=' . intval($id_document));
while ($row = sql_fetch($res)) {
$id_legende = $row['id_legende'];
include_spip("action/editer_legende");
tourner_legende($id_legende,$angle);
include_spip('action/editer_legende');
tourner_legende($id_legende, $angle);
}
// Invalider les caches
include_spip('inc/invalideur');
@ -35,22 +37,22 @@ function legendes_post_edition($flux){
/**
* On supprime les légendes de documents supprimés
*/
if($flux['args']['operation'] == 'supprimer_document'){
$legendes_documents = sql_select('id_legende','spip_legendes','id_document='.intval($flux['args']['id_objet']));
include_spip("action/editer_legende");
while($legende = sql_fetch($legendes_documents)){
if ($flux['args']['operation'] == 'supprimer_document') {
$legendes_documents = sql_select('id_legende', 'spip_legendes', 'id_document=' . intval($flux['args']['id_objet']));
include_spip('action/editer_legende');
while ($legende = sql_fetch($legendes_documents)) {
supprimer_legende($legende['id_legende']);
}
}
/**
* A la modification d'une légende, on met à jour le champs maj du document
*/
if(($flux['args']['action'] == 'modifier') and ($flux['args']['table'] == 'spip_legendes')){
$id_document = sql_getfetsel('id_document','spip_legendes','id_legende='.intval($flux['args']['id_objet']));
if(intval($id_document)){
if (($flux['args']['action'] == 'modifier') and ($flux['args']['table'] == 'spip_legendes')) {
$id_document = sql_getfetsel('id_document', 'spip_legendes', 'id_legende=' . intval($flux['args']['id_objet']));
if (intval($id_document)) {
include_spip('inc/modifier');
include_spip('action/editer_document');
document_modifier($id_document, $c=array('maj'=>date('Y-m-d H:i:s')));
document_modifier($id_document, $c = ['maj' => date('Y-m-d H:i:s')]);
}
}
return $flux;

Loading…
Cancel
Save