<?php
+/**
+ * Crayons
+ * plugin for spip
+ * (c) Fil, toggg 2006-2013
+ * licence GPL
+ */
if (!defined("_ECRIRE_INC_VERSION")) return;
function verif_secu($w, $secu) {
- return (
- $secu == md5($GLOBALS['meta']['alea_ephemere'].'='.$w)
- OR
- $secu == md5($GLOBALS['meta']['alea_ephemere_ancien'].'='.$w)
- );
+ return (
+ $secu == md5($GLOBALS['meta']['alea_ephemere'].'='.$w)
+ OR
+ $secu == md5($GLOBALS['meta']['alea_ephemere_ancien'].'='.$w)
+ );
}
function post_crayons() {
- $results = array();
-
- if (isset($_POST['crayons']) AND is_array($_POST['crayons']))
- foreach ($_POST['crayons'] as $crayon) {
-
- $name = $_POST['name_'.$crayon];
- $content = array();
- if ($_POST['fields_'.$crayon]) {
- foreach (explode(',', $_POST['fields_'.$crayon]) as $field) {
- // cas particulier d'un envoi de fichier
- if (isset($_FILES['content_'.$crayon.'_'.$field])) {
- if ($_FILES['content_'.$crayon.'_'.$field]['size']>0)
- $content[$field] = $_FILES['content_'.$crayon.'_'.$field];
- else
- $content[$field] = false;
- # cf. valeur passee dans crayon->md5() : false ou filemtime() du logo
- } else {
- /*
- le changement de charset n'est plus necessaire
- depuis jquery 1.5 (feature non documentee de jquery!)
- */
- $content[$field] = is_array($_POST['content_'.$crayon.'_'.$field])?implode(',',$_POST['content_'.$crayon.'_'.$field]):$_POST['content_'.$crayon.'_'.$field];
- }
- }
- }
-
- // Si les donnees POSTees ne correspondent pas a leur md5,
- // il faut les traiter
- if (isset($name)
- AND md5(serialize($content)) != $_POST['md5_'.$crayon]) {
- if (!isset($_POST['secu_'.$crayon])
- OR verif_secu($name, $_POST['secu_'.$crayon])) {
- $results[] = array($name, $content, $_POST['md5_'.$crayon], $crayon);
- }
- else {
- return false; // erreur secu
- }
- }
- // cas inchange
- else
- $results[] = array($name, $content, false, $crayon);
- }
-
- return $results;
+ $results = array();
+
+ if (isset($_POST['crayons']) AND is_array($_POST['crayons']))
+ foreach ($_POST['crayons'] as $crayon) {
+ $name = $_POST['name_'.$crayon];
+ $content = array();
+ if ($_POST['fields_'.$crayon]) {
+ foreach (explode(',', $_POST['fields_'.$crayon]) as $field) {
+ // cas particulier d'un envoi de fichier
+ if (isset($_FILES['content_'.$crayon.'_'.$field])) {
+ if ($_FILES['content_'.$crayon.'_'.$field]['size']>0)
+ $content[$field] = $_FILES['content_'.$crayon.'_'.$field];
+ else
+ $content[$field] = false;
+ // cf. valeur passee dans crayon->md5() : false ou filemtime() du logo
+ } else {
+ /**
+ * le changement de charset n'est plus necessaire
+ * depuis jquery 1.5 (feature non documentee de jquery!)
+ */
+ if (isset($_POST['content_'.$crayon.'_'.$field])) {
+ $content[$field] = is_array($_POST['content_'.$crayon.'_'.$field])
+ ?implode(',',$_POST['content_'.$crayon.'_'.$field])
+ :$_POST['content_'.$crayon.'_'.$field];
+ } else {
+ $content[$field] = null;
+ }
+ }
+ }
+ }
+
+ // Si les donnees POSTees ne correspondent pas a leur md5,
+ // il faut les traiter
+ if (isset($name)
+ AND md5(serialize($content)) != $_POST['md5_'.$crayon]) {
+ if (!isset($_POST['secu_'.$crayon])
+ OR verif_secu($name, $_POST['secu_'.$crayon])) {
+ $results[] = array($name, $content, $_POST['md5_'.$crayon], $crayon);
+ }
+ else
+ return false; // erreur secu
+ }
+ // cas inchange
+ else
+ $results[] = array($name, $content, false, $crayon);
+ }
+
+ return $results;
}
foreach ($modifs as $modif) {
list($type, $modele, $id, $content, $wid) = $modif;
- // MODELE
$fun = '';
+ // si le crayon est un MODELE avec une fonction xxx_revision associee
+ // cas ou une fonction xxx_revision existe
if (function_exists($f = $type.'_'. $modele . "_revision")
OR function_exists($f = $modele . "_revision")
OR function_exists($f = $type . "_revision"))
$fun = $f;
+
+ // si on est en SPIP 3+ et qu'on edite un objet editorial bien declare
+ // passer par l'API objet_modifier
+ elseif (function_exists('lister_tables_objets_sql')
+ AND $tables_objet = lister_tables_objets_sql()
+ AND isset($tables_objet[table_objet_sql($type)])) {
+ $fun = 'crayons_objet_modifier';
+ }
+
+ // sinon spip < 3 (ou pas un objet edito)
+ // on teste les objets connus et on route sur les fonctions correspondantes
else switch($type) {
case 'article':
$fun = 'crayons_update_article';
include_spip('action/editer_site');
$fun = 'revisions_sites';
break;
+ case 'document':
+ include_spip('plugins/installer');
+ include_spip('inc/plugin');
+ if (spip_version_compare($GLOBALS['spip_version_branche'], '3.0.0alpha', '>=')) {
+ include_spip('action/editer_document');
+ $fun = 'document_modifier';
+ } else {
+ include_spip('inc/modifier');
+ $fun = 'revision_document';
+ }
+ break;
// cas geres de la maniere la plus standard
case 'auteur':
- case 'document':
case 'mot':
case 'signature':
case 'petition':
$fun = 'revision_'.$type;
break;
}
+
+ // si on a pas reussi on passe par crayons_update() qui fera un update sql brutal
if (!$fun or !function_exists($fun)) {
- $fun = 'crayons_update';
-// $return['$erreur'] = "$type: " . _U('crayons:non_implemente');
-// break;
+ $fun = 'crayons_update';
+ // $return['$erreur'] = "$type: " . _U('crayons:non_implemente');
+ // break;
}
if (!isset($updates[$type][$fun])) {
// il manque une fonction de mise a jour ==> on ne fait rien !
if ($return['$erreur'])
- return $return;
+ return $return;
// hop ! mises a jour table par table et id par id
foreach ($updates as $type => $idschamps)
- foreach ($idschamps as $fun => $ids) {
- foreach ($ids as $id => $champsvaleurs) {
- /* cas particulier du logo dans un crayon complexe :
- ce n'est pas un champ de la table */
- if (isset($champsvaleurs['chval']['logo'])) {
- spip_log('revision logo', 'crayons');
- logo_revision($id, $champsvaleurs['chval'], $type, $champsvaleurs['wdg']);
- unset($champsvaleurs['chval']['logo']);
- }
- if (count($champsvaleurs['chval'])) {
- // -- revisions_articles($id_article, $c) --
- spip_log("$fun($id ...)", 'crayons');
- $updok = $fun($id, $champsvaleurs['chval'], $type, $champsvaleurs['wdg']);
- // Renvoyer erreur si update base distante echoue, on ne regarde pas les updates base local car ils ne renvoient rien
- list($distant,$table) = distant_table($type);
- if ($distant AND !$updok)
- $return['$erreur'] = "$type: " . _U('crayons:update_impossible');
+ foreach ($idschamps as $fun => $ids) {
+ foreach ($ids as $id => $champsvaleurs) {
+ /* cas particulier du logo dans un crayon complexe :
+ ce n'est pas un champ de la table */
+ if (isset($champsvaleurs['chval']['logo'])) {
+ spip_log('revision logo', 'crayons');
+ logo_revision($id, $champsvaleurs['chval'], $type, $champsvaleurs['wdg']);
+ unset($champsvaleurs['chval']['logo']);
+ }
+ if (count($champsvaleurs['chval'])) {
+ // -- revisions_articles($id_article, $c) --
+ spip_log("$fun($id ...)", 'crayons');
+ $updok = $fun($id, $champsvaleurs['chval'], $type, $champsvaleurs['wdg']);
+ // Renvoyer erreur si update base distante echoue, on ne regarde pas les updates base local car ils ne renvoient rien
+ list($distant,$table) = distant_table($type);
+ if ($distant AND !$updok)
+ $return['$erreur'] = "$type: " . _U('crayons:update_impossible');
+ }
}
- }
- }
+ }
return $return;
}
lang_select($a = $GLOBALS['meta']['langue_site']);
}
- // chercher vues/article_toto.html
- // sinon vues/toto.html
- if (find_in_path( ($fond = 'vues/' . $type . '_' . $modele) . '.html')
- OR find_in_path( ($fond = 'vues/' . $modele) .'.html')
- OR find_in_path( ($fond = 'vues/' . $type) .'.html')) {
+ // chercher vues/article_toto.html
+ // sinon vues/toto.html
+ if (find_in_path( ($fond = 'vues/' . $type . '_' . $modele) . '.html')
+ OR find_in_path( ($fond = 'vues/' . $modele) .'.html')
+ OR find_in_path( ($fond = 'vues/' . $type) .'.html')) {
$contexte = array(
- 'id_' . $table => $id,
- 'crayon_type' => $type,
+ 'id_' . $table => $id,
+ 'crayon_type' => $type,
'crayon_modele' => $modele,
- 'champ' => $modele,
- 'class' => _request('class_'.$wid),
- 'self' => _request('self'),
- 'lang' => $GLOBALS['spip_lang']
+ 'champ' => $modele,
+ 'class' => _request('class_'.$wid),
+ 'self' => _request('self'),
+ 'lang' => $GLOBALS['spip_lang']
);
$contexte = array_merge($contexte, $content);
include_spip('public/assembler');
return recuperer_fond($fond, $contexte);
- }
+ }
// vue par defaut
else {
// Par precaution on va rechercher la valeur
// seul spip core sait rendre les donnees
if (in_array($modele,
- array('chapo', 'texte', 'descriptif', 'ps', 'bio'))) {
+ array('chapo', 'texte', 'descriptif', 'ps', 'bio'))) {
return propre($valeur);
} else {
return typo($valeur);
}
}
+
+/**
+ * Fonction de mise a jour par API editer_objet
+ * @param $id
+ * @param $data
+ * @param $type
+ * @param $ref
+ * @return bool|mixed|string
+ */
+function crayons_objet_modifier($id, $data, $type, $ref) {
+ if (include_spip('action/editer_objet')
+ AND function_exists('objet_modifier')) {
+ return objet_modifier(objet_type($type),$id,$data);
+ }
+ // fallback
+ return crayons_update($id, $data, $type);
+}
+
//
// Fonctions de mise a jour generique
//
-function crayons_update($id, $colval = array(), $type = '')
-{
+function crayons_update($id, $colval = array(), $type = ''){
if (!$colval OR !count($colval))
return false;
list($distant,$table) = distant_table($type);