%k25u25%fgd5n!?%k25u25%fgd5n!%k25u25%fgd5n!?%k25u25%fgd5n!meta.php000066600000005520151454733230006220 0ustar00array(), 'message_erreur'=>array(), 'erreurs'=>array()); /** * version du depot * @var int */ var $version = 2; /** * * @param Array $params */ function cfg_depot_meta($params=array()) { foreach ($params as $o=>$v) { $this->$o = $v; } } /** * recuperer les valeurs. * * unserialize : si la valeur est deserialisable, elle est retournee deserialisee * permet a #CONFIG d'obtenir une valeur non deserialisee... * * @param boolean $unserialize * @return Array */ function lire($unserialize=true) { $val = array(); if ($this->champs) { foreach ($this->champs as $name => $def) { // pour compat cfg, si la meta est deserialisable, la retourner deserialisee if ($unserialize && ($a = @unserialize($GLOBALS['meta'][$name]))) $val[$name] = $a; else { $val[$name] = $GLOBALS['meta'][$name]; } } // si pas d'argument, retourner comme le core serialize($GLOBALS['meta']) } else { $val = serialize($GLOBALS['meta']); } return array(true, $val); } /** * ecrit chaque enregistrement de meta pour chaque champ * * @return Array */ function ecrire() { foreach ($this->champs as $name => $def) { ecrire_meta($name, $this->val[$name]); } if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, $this->val); } /** * supprime chaque enregistrement de meta pour chaque champ * * @return Array */ function effacer(){ foreach ($this->champs as $name => $def) { if (!$this->val[$name]) { effacer_meta($name); } } if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, $this->val); } /** * charger les arguments de lire_config(meta::nom) * * @param string $args # $args = 'nom'; ici * @return boolean */ function charger_args($args){ if ($args) $this->champs = array($args=>true); return true; } } ?> tablepack.php000066600000021652151454733230007224 0ustar00array(), 'message_erreur'=>array(), 'erreurs'=>array()); /** * Arbre * @var Array */ var $_arbre = array(); /** * Le WHERE permettant de retrouver l'Arbre * @var Array */ var $_id = array(); /** * Base de l'arbre * @var Array */ var $_base = null; /** * Où on est dans l'arbre $this->_arbre * @var &Array */ var $_ici = null; /** * version du depot * @var int */ var $version = 2; /** * Dépôt dans les attributs de la classe * * @param Array $params */ function cfg_depot_tablepack($params=array()) { foreach ($params as $o=>$v) { $this->$o = $v; } } /** * charge la base (racine) et le point de l'arbre sur lequel on se trouve (ici) * * @param boolean $lire # inutilisé * @return */ function charger($lire = false){ if (!$this->param['colonne']) $this->param['colonne'] = 'cfg'; // colid : nom de la colonne primary key if ($this->param['table']) { list($this->param['table'], $colid) = $this->get_table_id($this->param['table']); // renseigner les liens id=valeur $id = explode('/',$this->param['cfg_id']); foreach ($colid as $n=>$c) { if (isset($id[$n])) { $this->_id[$c] = $id[$n]; } } } if (!$this->param['cfg_id']) { $this->messages['message_erreur'][] = _T('cfg:id_manquant'); return false; } // verifier que la colonne existe if (!$this->verifier_colonne()) { return false; } else { // recuperer la valeur du champ de la table sql $this->_where = array(); foreach ($this->_id as $nom => $id) { $this->_where[] = $nom . '=' . sql_quote($id); } $this->_base = ($d = sql_getfetsel($this->param['colonne'], $this->param['table'], $this->_where)) ? unserialize($d) : array(); } $this->_arbre = array(); $this->_ici = &$this->_base; $this->_ici = &$this->monte_arbre($this->_ici, $this->param['nom']); $this->_ici = &$this->monte_arbre($this->_ici, $this->param['casier']); return true; } /** * recuperer les valeurs. * * @return Array */ function lire() { // charger if (!$this->charger(true)){ return array(true, null); } $ici = &$this->_ici; // utile ?? if ($this->param['cfg_id']) { $cles = explode('/', $this->param['cfg_id']); foreach ($this->champs_id as $i => $name) { $ici[$name] = $cles[$i]; } } // s'il y a des champs demandes, ne retourner que ceux-ci if (count($this->champs)){ $val = array(); foreach ($this->champs as $name => $def) { $val[$name] = $ici[$name]; } $ici = $val; } return array(true, $ici); } /** * ecrit chaque enregistrement pour chaque champ. * * @return Array */ function ecrire() { // charger if (!$this->charger()){ return array(false, $this->val, $this->messages); } $ici = &$this->_ici; if ($this->champs){ foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; $ici[$name] = $this->val[$name]; } } else { $ici = $this->val; } $ok = sql_updateq($this->param['table'], array($this->param['colonne'] => serialize($this->_base)), $this->_where); return array($ok, $ici); } /** * supprime chaque enregistrement pour chaque champ. * * @return Array */ function effacer(){ // charger if (!$this->charger()){ return array(false, $this->val, $this->messages); } $ici = &$this->_ici; if ($this->champs){ foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; unset($ici[$name]); } } // supprimer les dossiers vides for ($i = count($this->_arbre); $i--; ) { if ($this->_arbre[$i][0][$this->_arbre[$i][1]]) { break; } unset($this->_arbre[$i][0][$this->_arbre[$i][1]]); } $ok = sql_updateq($this->param['table'], array($this->param['colonne'] => serialize($this->_base)), $this->_where); return array($ok, array()); } /** * charger les arguments de * - lire_config(tablepack::table@colonne:id/nom/casier/champ) * - lire_config(tablepack::~id_auteur@colonne/chemin/champ) * - lire_config(tablepack::~@colonne/chemin/champ * * @param $args * @return */ function charger_args($args){ $args = explode('/',$args); // cas ~id_auteur/ if ($args[0][0] == '~'){ $table = 'spip_auteurs'; $colid = array('id_auteur'); list($auteur, $colonne) = explode('@',array_shift($args)); if (count($auteur)>1){ $id = substr($auteur,1); } else { $id = $GLOBALS['auteur_session'] ? $GLOBALS['auteur_session']['id_auteur'] : ''; } // cas table:id/ // peut etre table:id:id/ si la table a 2 cles } else { list($table, $id) = explode(':',array_shift($args),2); list($table, $colonne) = explode('@',$table); list($table, $colid) = $this->get_table_id($table); } $this->param['cfg_id'] = $id; $this->param['colonne'] = $colonne ? $colonne : 'cfg'; $this->param['table'] = $table ? $table : 'spip_auteurs'; if ($champ = array_pop($args)) { $this->champs = array($champ=>true); } $this->param['casier'] = implode('/',$args); // renseigner les liens id=valeur $id = explode(':',$id); foreach ($colid as $n=>$c) { if (isset($id[$n])) { $this->_id[$c] = $id[$n]; } } return true; } /** * se positionner dans le tableau arborescent * * @param $base * @param $chemin * @return */ function & monte_arbre(&$base, $chemin){ if (!$chemin) { return $base; } if (!is_array($chemin)) { $chemin = explode('/', $chemin); } if (!is_array($base)) { $base = array(); } foreach ($chemin as $dossier) { if (!isset($base[$dossier])) { $base[$dossier] = array(); } $this->_arbre[] = array(&$base, $dossier); $base = &$base[$dossier]; } return $base; } /** * * @param $creer * @return */ function verifier_colonne($creer = false) { if (!$this->param['table']) return false; $col = sql_showtable($table = $this->param['table']); if (!is_array($col['field']) OR !array_key_exists($colonne = $this->param['colonne'], $col['field'])) { if ($creer && $colonne && sql_alter('TABLE '.$this->param['table'] . ' ADD ' . $colonne . 'TEXT NOT NULL DEFAULT \'\'')) { return true; } return false; } return true; } /** * Cherche le vrai nom d'une table ainsi que ses cles primaires * * @param $table * @return */ function get_table_id($table) { static $catab = array( 'tables_principales' => 'base/serial', 'tables_auxiliaires' => 'base/auxiliaires', ); $try = array($table, 'spip_' . $table); foreach ($catab as $categ => $catinc) { include_spip($catinc); foreach ($try as $nom) { if (isset($GLOBALS[$categ][$nom])) { return array($nom, preg_split('/\s*,\s*/', $GLOBALS[$categ][$nom]['key']['PRIMARY KEY'])); } } } if ($try = table_objet($table)) { return array('spip_' . $try, array(id_table_objet($table))); } return array(false, false); } } ?> table.php000066600000015127151454733230006365 0ustar00array(), 'message_erreur'=>array(), 'erreurs'=>array()); /** * Arbre * @var Array */ var $_arbre = array(); /** * Le WHERE permettant de retrouver l'Arbre * @var Array */ var $_id = array(); /** * Base de l'arbre * @var Array */ var $_base = null; /** * Où on est dans l'arbre $this->_arbre * @var &Array */ var $_ici = null; /** * version du depot * @var int */ var $version = 2; /** * Dépôt dans les attributs de la classe * * @param Array $params */ function cfg_depot_table($params=array()){ foreach ($params as $o=>$v) { $this->$o = $v; } } /** * charge la base (racine) et le point de l'arbre sur lequel on se trouve (ici) * * @param boolean $creer # inutilisé */ function charger($creer = false){ if (!$this->param['table']) { $this->messages['message_erreur'][] = _T('cfg:nom_table_manquant'); return false; } // colid : nom de la colonne primary key list($this->param['table'], $colid) = $this->get_table_id($this->param['table']); // renseigner les liens id=valeur $id = explode('/',$this->param['cfg_id']); foreach ($colid as $n=>$c) { if (isset($id[$n])) { $this->_id[$c] = $id[$n]; } } if (!$this->param['cfg_id'] AND !($this->param['autoriser_absence_id'] == 'oui')) { $this->messages['message_erreur'][] = _T('cfg:id_manquant'); return false; } // select $this->_select = array(); if ($this->champs){ foreach ($this->champs as $nom => $def) { if (isset($def['id'])) { continue; } $this->_select[] = $nom; } } else { $this->_select[] = '*'; } // where $this->_where = array(); foreach ($this->_id as $nom => $id) { $this->_where[] = $nom . '=' . sql_quote($id); } $this->_base = ($d = sql_fetsel( $this->_select, $this->param['table'], $this->_where)) ? $d : array(); $this->_existe = count($this->_base); $this->_ici = &$this->_base; return true; } /** * recuperer les valeurs. * * @return Array */ function lire() { // charger if (!$this->charger()){ return array(false, $this->val, $this->messages); } // utile ?? if ($this->param['cfg_id']) { $cles = explode('/', $this->param['cfg_id']); foreach ($this->champs_id as $i => $name) { $this->_ici[$name] = $cles[$i]; } } // s'il y a des champs demandes, ne retourner que ceux-ci if (count($this->champs)){ $val = array(); foreach ($this->champs as $name => $def) { $val[$name] = $this->_ici[$name]; } $this->_ici = $val; } return array(true, $this->_ici); } /** * ecrit chaque enregistrement pour chaque champ. * * @return Array */ function ecrire() { // charger if (!$this->charger()){ return array(false, $this->val, $this->messages); } if ($this->champs){ foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; $this->_ici[$name] = $this->val[$name]; } } else { $this->_ici = $this->val; } // update if ($this->_existe) { $ok = sql_updateq($this->param['table'], $this->_ici, $this->_where ); } else { $ok = $id = sql_insertq($this->param['table'], $this->_ici); } // remettre l'id if ($ok && (count($this->champs_id)==1)) { $this->_ici[$nomid = $this->champs_id[0]] = $this->_existe ? $this->val[$nomid] : $ok; } return array($ok, $this->_ici); } /** * supprime chaque enregistrement pour chaque champ. * * @return Array */ function effacer(){ // charger if (!$this->charger()){ return array(false, $this->val, $this->messages); } $ok = !$this->_existe || sql_delete($this->param['table'], $this->_where ); return array($ok, array()); } /** * charger les arguments * - lire_config(table::table@colonne:id * - lire_config(table::table:id * * @param string $args * @return boolean */ function charger_args($args){ list($table, $id) = explode(':',$args,2); list($table, $colonne) = explode('@',$table); list($table, $colid) = $this->get_table_id($table); $this->param['cfg_id'] = $id; $this->param['champs'] = $colonne ? array($colonne=>true) : ''; $this->param['table'] = $table ? $table : 'spip_cfg'; // renseigner les liens id=valeur $id = explode(':',$id); foreach ($colid as $n=>$c) { if (isset($id[$n])) { $this->_id[$c] = $id[$n]; } } return true; } /** * se positionner dans le tableau arborescent * * @param &Array $base * @param string $chemin * @return &Array */ function & monte_arbre(&$base, $chemin){ if (!$chemin) { return $base; } if (!is_array($chemin)) { $chemin = explode('/', $chemin); } if (!is_array($base)) { $base = array(); } foreach ($chemin as $dossier) { if (!isset($base[$dossier])) { $base[$dossier] = array(); } $this->_arbre[] = array(&$base, $dossier); $base = &$base[$dossier]; } return $base; } /** * Cherche le vrai nom d'une table * ainsi que ses cles primaires * * @param string $table * @return Array */ function get_table_id($table) { static $catab = array( 'tables_principales' => 'base/serial', 'tables_auxiliaires' => 'base/auxiliaires', ); $try = array($table, 'spip_' . $table); foreach ($catab as $categ => $catinc) { include_spip($catinc); foreach ($try as $nom) { if (isset($GLOBALS[$categ][$nom])) { return array($nom, preg_split('/\s*,\s*/', $GLOBALS[$categ][$nom]['key']['PRIMARY KEY'])); } } } if ($try = table_objet($table)) { return array('spip_' . $try, array(id_table_objet($table))); } return array(false, false); } } ?> metapack.php000066600000012642151454733230007062 0ustar00array(), 'message_erreur'=>array(), 'erreurs'=>array()); /** * Arbre * @var Array */ var $_arbre = array(); /** * version du depot * @var int */ var $version = 2; /** * Stockage interne dans les attributs de la classe * * @param Array $params */ function cfg_depot_metapack($params=array()) { foreach ($params as $o=>$v) { $this->$o = $v; } } /** * charge la base (racine) et le point de l'arbre sur lequel on se trouve (ici) * * @param boolean $lire * @return boolean */ function charger($lire = false){ if ($lire && !isset($GLOBALS['meta'][$this->param['nom']])) return false; $this->_base = is_array($c = $GLOBALS['meta'][$this->param['nom']]) ? $c : @unserialize($c); $this->_arbre = array(); $this->_ici = &$this->_base; $this->_ici = &$this->monte_arbre($this->_ici, $this->param['casier']); $this->_ici = &$this->monte_arbre($this->_ici, isset($this->param['cfg_id']) ? $this->param['cfg_id'] : ''); return true; } /** * recuperer les valeurs. * * @return Array */ function lire() { if (!$this->charger(true)){ return array(true, null); // pas de chargement = pas de valeur encore enregistrees } $ici = &$this->_ici; // utile ?? if (isset($this->param['cfg_id'])) { $cles = explode('/', $this->param['cfg_id']); foreach ($this->champs_id as $i => $name) { $ici[$name] = $cles[$i]; } } // s'il y a des champs demandes, les retourner... sinon, retourner la base // (cas de lire_config('metapack::nom') tout court) if (count($this->champs)){ $val = array(); foreach ($this->champs as $name => $def) { $val[$name] = $ici[$name]; } $ici = $val; } return array(true, $ici); } /** * ecrit une meta pour tous les champs * * @return Array */ function ecrire() { // si pas de champs : on ecrit directement (ecrire_meta(metapack::nom,$val))... if (!$this->champs){ ecrire_meta($this->param['nom'], serialize($this->val)); if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, $this->val); } if (!$this->charger()){ return array(false, $this->val); } $ici = &$this->_ici; foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; $ici[$name] = $this->val[$name]; } ecrire_meta($this->param['nom'], serialize($this->_base)); if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, $ici); } /** * supprime chaque enregistrement de meta pour chaque champ * * @return Array */ function effacer(){ // si pas de champs : on supprime directement (effacer_meta(metapack::nom))... if (!$this->champs){ effacer_meta($this->param['nom']); if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, array()); } if (!$this->charger()){ return array(false, $this->val); } $ici = &$this->_ici; // supprimer les champs foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; unset($ici[$name]); } // supprimer les dossiers vides for ($i = count($this->_arbre); $i--; ) { if ($this->_arbre[$i][0][$this->_arbre[$i][1]]) { break; } unset($this->_arbre[$i][0][$this->_arbre[$i][1]]); } if (!$this->_base) { effacer_meta($this->param['nom']); } else { ecrire_meta($this->param['nom'], serialize($this->_base)); } if (defined('_COMPAT_CFG_192')) ecrire_metas(); return array(true, array()); } /** * charger les arguments de lire_config(metapack::nom/casier/champ) * il se peut qu'il n'y ait pas de champs si : lire_config(metapack::nom); * * @param string $args # $args = 'nom'; ici * @return boolean */ function charger_args($args){ $args = explode('/',$args); $this->param['nom'] = array_shift($args); if ($champ = array_pop($args)) { $this->champs = array($champ=>true); } $this->param['casier'] = implode('/',$args); return true; } /** * se positionner dans le tableau arborescent * * @param &Array $base * @param string $chemin * @return &Array */ function & monte_arbre(&$base, $chemin){ if (!$chemin) { return $base; } if (!is_array($chemin)) { $chemin = explode('/', $chemin); } if (!is_array($base)) { $base = array(); } foreach ($chemin as $dossier) { if (!isset($base[$dossier])) { $base[$dossier] = array(); } $this->_arbre[] = array(&$base, $dossier); $base = &$base[$dossier]; } return $base; } } ?> php.php000066600000013300151454733230006054 0ustar00array(), 'message_erreur'=>array(), 'erreurs'=>array()); /** * Arbre * @var Array */ var $_arbre = array(); /** * version du depot * @var int */ var $version = 2; /** * Dépôt dans les attributs de la classe * * @param Array $params */ function cfg_depot_php($params=array()) { foreach ($params as $o=>$v) { $this->$o = $v; } } /** * calcule l'emplacement du fichier * * @staticvar Array $fichier * @return string # L'emplacement du fichier */ function get_fichier(){ static $fichier = array(); $cle = $this->param['nom'] . ' - ' . $this->param['fichier']; if (isset($fichier[$cle])) return $fichier[$cle]; if (!$this->param['fichier']) $f = _DIR_VAR . 'cfg/' . $this->param['nom'] . '.php'; else $f = _DIR_RACINE . $this->param['fichier']; include_spip('inc/flock'); return $fichier[$cle] = sous_repertoire(dirname($f)) . basename($f); } /** * charge la base (racine) et le point de l'arbre sur lequel on se trouve (ici) * * @param boolean $lire * @return boolean */ function charger($lire=false){ $fichier = $this->get_fichier(); // inclut une variable $cfg if (!@include $fichier) { if ($lire) return false; $this->_base = array(); } elseif (!$cfg OR !is_array($cfg)) { $this->_base = array(); } else { $this->_base = $cfg; } $this->_ici = &$this->_base; $this->_ici = &$this->monte_arbre($this->_ici, $this->param['nom']); $this->_ici = &$this->monte_arbre($this->_ici, $this->param['casier']); $this->_ici = &$this->monte_arbre($this->_ici, $this->param['cfg_id']); return true; } /** * recuperer les valeurs. * * @return Array */ function lire() { if (!$this->charger(true)){ return array(true, null); // pas de chargement = pas de valeur encore enregistrees } // utile ?? if ($this->param['cfg_id']) { $cles = explode('/', $this->param['cfg_id']); foreach ($this->champs_id as $i => $name) { $this->_ici[$name] = $cles[$i]; } } return array(true, $this->_ici); } /** * ecrit chaque enregistrement pour chaque champ. * * @return Array */ function ecrire() { if (!$this->charger()){ return array(false, $this->val); } foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; $this->_ici[$name] = $this->val[$name]; } if (!$this->ecrire_fichier($this->_base)){ return array(false, $this->val); } return array(true, $this->_ici); } /** * supprime chaque enregistrement pour chaque champ. * * @return Array */ function effacer(){ if (!$this->charger()){ return array(false, $this->val); } // pas de champ, on supprime tout if (!$this->champs) return array($this->ecrire_fichier(), array()); // effacer les champs foreach ($this->champs as $name => $def) { if (isset($def['id'])) continue; unset($this->_ici[$name]); } // supprimer les dossiers vides for ($i = count($this->_arbre); $i--; ) { if ($this->_arbre[$i][0][$this->_arbre[$i][1]]) { break; } unset($this->_arbre[$i][0][$this->_arbre[$i][1]]); } return array($this->ecrire_fichier($this->_base), $this->_ici); } /** * Ecrire un fichier * * @param Array $contenu * @return boolean */ function ecrire_fichier($contenu=array()){ $fichier = $this->get_fichier(); if (!$contenu) { return supprimer_fichier($fichier); } $contenu = ' '; return ecrire_fichier($fichier, $contenu); } /** * charger les arguments de * - lire_config(php::nom/casier/champ) * - lire_config(php::adresse/fichier.php:nom/casier/champ) * * @param string $args * @return boolean */ function charger_args($args){ list($fichier, $args) = explode(':',$args); if (!$args) { $args = $fichier; $fichier = _DIR_VAR . 'cfg/' . $fichier . '.php'; } $this->param['fichier'] = $fichier; $arbre = explode('/',$args); $this->param['nom'] = array_shift($arbre); if ($champ = array_pop($arbre)) $this->champs = array($champ=>true); $this->param['casier'] = implode('/',$arbre); return true; } /** * se positionner dans le tableau arborescent * * @param &Array $base * @param Array $chemin * @return &Array */ function & monte_arbre(&$base, $chemin){ if (!$chemin) { return $base; } if (!is_array($chemin)) { $chemin = explode('/', $chemin); } if (!is_array($base)) { $base = array(); } foreach ($chemin as $dossier) { if (!isset($base[$dossier])) { $base[$dossier] = array(); } $this->_arbre[] = array(&$base, $dossier); $base = &$base[$dossier]; } return $base; } } ?>