137 lines
3 KiB
PHP
137 lines
3 KiB
PHP
<?php
|
|
/**
|
|
* Fonctions utiles au plugin GamuTable
|
|
*
|
|
* @plugin GamuTable
|
|
* @copyright 2020
|
|
* @author tofulm
|
|
* @licence GNU/GPL
|
|
* @package SPIP\Gamutable\Fonctions
|
|
*/
|
|
|
|
if (!defined("_ECRIRE_INC_VERSION")) {
|
|
return;
|
|
}
|
|
include_spip("inc/vite");
|
|
|
|
/**
|
|
* fonction pour forcer un hit pour un objet
|
|
* un hit => maj de champ maj
|
|
*
|
|
* @param string $objet
|
|
* @param int $id_objet
|
|
* @param string $table (optional) pour forcer sur une table spécifique ou le test se fait sur la cle primaire de $objet
|
|
* si $table est renseigné : ex :
|
|
* $objet = rubrique
|
|
* $id_objet = 4
|
|
* $table = 'spip_articles'
|
|
* => le hit sur l'id_rubrique 4 de spip_articles
|
|
*
|
|
* @return void [TODO:description]
|
|
*/
|
|
function forcer_hit(string $objet, int $id_objet, string $table = null):void {
|
|
include_spip('inc/invalideur');
|
|
$id = id_table_objet($objet);
|
|
if (!$table) {
|
|
$table = table_objet_sql($objet);
|
|
} else {
|
|
$id_c = id_table_objet($table);
|
|
suivre_invalideur("id='$id_c/1'");
|
|
}
|
|
sql_updateq($table, ['maj' => date("Y-m-d H:i:s")], "$id=".$id_objet);
|
|
suivre_invalideur("id='$id/1'");
|
|
}
|
|
|
|
if (!function_exists('tsEnDate')) {
|
|
/**
|
|
* retour la date d'un timestamp
|
|
*
|
|
* @param $ts
|
|
*
|
|
* @return string
|
|
*/
|
|
function tsEnDate($ts) {
|
|
$ts = intval($ts);
|
|
return date('Y-m-d H:i:s', $ts);
|
|
}
|
|
}
|
|
|
|
function gamutable_fermer_modalbox($id_objet = 9999999999, $num = null) {
|
|
$js = gamutable_generer_js($id_objet, $num);
|
|
$html = <<<EOJS
|
|
<script type="text/javascript">
|
|
$js;
|
|
</script>
|
|
EOJS;
|
|
return $html;
|
|
}
|
|
|
|
function gamutable_generer_js($id_objet, $num){
|
|
if ($num === '_deux' || intval($num) === 2) {
|
|
$num = 2;
|
|
} else {
|
|
$num = null;
|
|
}
|
|
$html = <<<EOJS
|
|
id = "$id_objet";
|
|
if (+id === 9999999999) {
|
|
id = '';
|
|
}
|
|
if (typeof app$num !== 'undefined') {
|
|
app$num.rechargerJson(id);
|
|
}
|
|
$.modalboxclose();
|
|
delete id;
|
|
EOJS;
|
|
return $html;
|
|
|
|
}
|
|
|
|
/**
|
|
* fonction que l'on peut appeler comme filtre dans une vues des crayons
|
|
* ex:
|
|
* [(#ID_APP_HORAIRE|gamutable_recharger_tableau)]
|
|
*
|
|
* @param $id_objet (optional)
|
|
* @param $num (optional) (si on veut recharger qu'un tableau préciséemnt)
|
|
*
|
|
* @return string $html
|
|
*/
|
|
function gamutable_recharger_tableau($id_objet = 9999999999, $num = null):string {
|
|
if ($num === '_deux' || intval($num) === 2) {
|
|
$num = 2;
|
|
} else {
|
|
$num = null;
|
|
}
|
|
|
|
$html = <<<EOJS
|
|
<script type="text/javascript">
|
|
id = "$id_objet";
|
|
if (+id === 9999999999) {
|
|
id = '';
|
|
}
|
|
if (typeof app$num !== 'undefined') {
|
|
app$num.rechargerJson(id);
|
|
}
|
|
delete id;
|
|
</script>
|
|
EOJS;
|
|
return $html;
|
|
}
|
|
|
|
function gamutable_vider_localstorage():int {
|
|
$version_prod = (int) lire_config('gamutable/version_stockage', 1);
|
|
$version_demandee = (int) ($GLOBALS['gamutable_version_stockage'] ?? 1);
|
|
if ($version_demandee > $version_prod) {
|
|
ecrire_config('gamutable/version_stockage', $version_demandee);
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function gamutableGetGlobals(string $name, string $defaut = ''):string {
|
|
if (empty($name)) {
|
|
return '';
|
|
}
|
|
return $GLOBALS[$name] ?? $defaut;
|
|
}
|