<?php

/**
 * Plugin CIBLOC
 * @copyright 2018 MTECT
 * @author Christophe IMBERTI (cf. CPI art L121-1)
 * @license GNU/GPLv3
 */

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

include_spip('inc/filtres');

function action_reinitialiser_cibloc_objet($type_et_id = null) {

	if ($type_et_id === null) {
		$securiser_action = charger_fonction('securiser_action', 'inc');
		$type_et_id = $securiser_action();
	}

	if (autoriser('configurer')) {
		if (ctype_alnum(str_replace(['_', '|'], '', $type_et_id))) {
			$pos = strpos($type_et_id, '_');
			$type = substr($type_et_id, 0, $pos);
			$id = substr($type_et_id, $pos + 1);
			if (in_array($type, ['bloc', 'bouton', 'ensemble', 'multi'])) {
				sql_delete('spip_cibloc_objets', "type='" . $type . "' AND id='" . $id . "' AND source='maj'");
				include_spip('inc/cibloc_commun');
				cibloc_purger_definition_cache();
				cibloc_purger_cache_js();
				cibloc_purger_cache_css();
				include_spip('inc/invalideur');
				suivre_invalideur('1');
			}
		}
	} else {
		spip_log("action_reinitialiser_cibloc_objet $type_et_id interdit", _LOG_INFO_IMPORTANTE);
	}
}
