Example #1
0
	function Crayon($name, $texts = array(), $options = array(), $c=null) {
		$this->name = $name;
		list($this->type, $this->modele, $this->id) = explode('-', $this->name, 3);
		list($this->distant,$this->table) = distant_table($this->type);
		if (is_scalar($texts) || is_null($texts)) {
			$texts = array($this->modele => $texts);
		}
		$this->texts = $texts;
		$this->key = strtr(uniqid('wid', true), '.', '_');
		$this->md5 = $this->md5();
		foreach ($options as $opt=>$val) {
			$this->$opt = $val;
		}
		$this->dimension($c);
		$this->css();
	}
function crayons_update($id, $colval = array(), $type = '')
{
    if (!$colval or !count($colval)) {
        return false;
    }
    list($distant, $table) = distant_table($type);
    if ($distant) {
        list($nom_table, $where) = table_where($type, $id);
        if (!$nom_table) {
            return false;
        }
        $update = $sep = '';
        foreach ($colval as $col => $val) {
            $update .= $sep . '`' . $col . '`=' . _q($val);
            $sep = ', ';
        }
        $a = spip_query($q = 'UPDATE `' . $nom_table . '` SET ' . $update . ' WHERE ' . $where, $distant);
        #spip_log($q);
        include_spip('inc/invalideur');
        suivre_invalideur($cond, $modif = true);
    } else {
        // cle primaire composee : 3-4-rubrique
        // calculer un where approprie
        // et modifier sans passer par la fonction destinee aux tables principales
        // on limite a SPIP 2 mini car sql_updateq n'est pas mappe dans les crayons_compat
        if (is_scalar($id) and $GLOBALS['spip_version_code'] >= '1.93') {
            list($nom_table, $where) = table_where($type, $id, true);
            // where sous forme de tableau
            $a = sql_updateq($nom_table, $colval, $where);
        } else {
            // modification d'une table principale
            include_spip('inc/modifier');
            $a = modifier_contenu($type, $id, array(), $colval);
        }
    }
    return $a;
}
Example #3
0
function &crayons_get_table($type, &$nom_table)
{
    list($distant, $table) = distant_table($type);
    static $return = array();
    static $noms = array();
    if (!isset($return[$table])) {
        $try = array(table_objet_sql($table), 'spip_' . table_objet($table), 'spip_' . $table . 's', $table . 's', 'spip_' . $table, $table);
        // premiere possibilite (à partir de 1.9.3) : regarder directement la base
        if (function_exists('sql_showtable')) {
            foreach ($try as $nom) {
                if ($q = sql_showtable($nom, !$distant, $distant)) {
                    $noms[$table] = $nom;
                    $return[$table] = $q;
                    break;
                }
            }
        }
        // seconde, une heuristique 1.9.2
        if (!isset($return[$table])) {
            include_spip('base/serial');
            include_spip('base/auxiliaires');
            include_spip('public/parametrer');
            foreach (array('tables_principales', 'tables_auxiliaires') as $categ) {
                foreach ($try as $nom) {
                    if (isset($GLOBALS[$categ][$nom])) {
                        $noms[$table] = $nom;
                        $return[$table] =& $GLOBALS[$categ][$nom];
                        break 2;
                    }
                }
            }
        }
    }
    $nom_table = $noms[$table];
    return $return[$table];
}