[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / medias / action / changer_mode_document.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2019 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13 if (!defined('_ECRIRE_INC_VERSION')) {
14 return;
15 }
16
17
18 /**
19 * Cette action permet de basculer du mode image au mode document et vice versa
20 *
21 * https://code.spip.net/@action_changer_mode_document_dist
22 *
23 * @param int $id_document
24 * @param string $mode
25 * @return void
26 */
27 function action_changer_mode_document_dist($id_document = null, $mode = null) {
28 if (is_null($id_document) or is_null($mode)) {
29 $securiser_action = charger_fonction('securiser_action', 'inc');
30 $arg = $securiser_action();
31
32 if (!preg_match(',^(\d+)\W(\w+)$,', $arg, $r)) {
33 spip_log("action_changer_mode_document $arg pas compris");
34 } else {
35 array_shift($r);
36 list($id_document, $mode) = $r;
37 }
38 }
39
40 if ($id_document
41 and include_spip('inc/autoriser')
42 and autoriser('modifier', 'document', $id_document)
43 ) {
44 action_changer_mode_document_post($id_document, $mode);
45 }
46 }
47
48 // https://code.spip.net/@action_changer_mode_document_post
49 function action_changer_mode_document_post($id_document, $mode) {
50 // - id_document le doc a modifier
51 // - mode le mode a lui donner
52 if ($id_document = intval($id_document)
53 and in_array($mode, array('vignette', 'image', 'document'))
54 ) {
55 include_spip('action/editer_document');
56 document_modifier($id_document, array('mode' => $mode));
57 }
58 }