Example #1
0
func (db Database) CCKFields() (map[string][]*CCKFieldType, error) {
	var err error = nil
	_sql := `select cnf.field_name, type, global_settings, required, multiple, 
	  db_storage, module, db_columns, locked, cnfi.type_name as type_name
	  from %scontent_node_field cnf, %scontent_node_field_instance cnfi 
	  where cnf.field_name = cnfi.field_name and cnf.active = 1 and cnfi.widget_active = 1`
	query := fmt.Sprintf(_sql, db.Prefix, db.Prefix)
	var fields []*CCKFieldType
	_, err = db.DbMap.Select(&fields, query)
	if err != nil {
		util.LogError(err, "Error executing CCKFields select.")
		return nil, err
	}
	fieldsByType := make(map[string][]*CCKFieldType)
	for _, cft := range fields {
		decoded, err := php.Decode(cft.Gs)
		cft.GlobalSettings = decoded.(map[interface{}]interface{})
		if err != nil {
			util.LogError(err, "Unable to parse global settings for "+cft.Name)
		}
		decoded, err = php.Decode(cft.Dbc)
		cft.DBColumns = decoded.(map[interface{}]interface{})
		if err != nil {
			util.LogError(err, "Unable to parse db columns for "+cft.Name)
		}
		typeFields, ok := fieldsByType[cft.ContentType]
		if !ok {
			typeFields = make([]*CCKFieldType, 0, 100)
		}
		fieldsByType[cft.ContentType] = append(typeFields, cft)
		err = nil
	}
	return fieldsByType, err
}
Example #2
0
func main() {
	data3 := make(map[interface{}]interface{})
	data3["test"] = true
	data3[int64(0)] = int64(5)
	data3["flt32"] = float32(2.3)

	data2 := make(map[interface{}]interface{})
	data2["test"] = true
	data2[int64(0)] = int64(5)
	data2["flt32"] = float32(2.3)
	data2["int64"] = int64(45)
	data2["data3"] = data3

	data := make(map[interface{}]interface{})
	data["arr"] = data2
	data["3"] = "s\"tr'}e"
	data["g"] = nil

	var (
		result    string
		decodeRes interface{}
		err       error
	)

	if result, err = phpserialize.Encode(data); err != nil {
		fmt.Errorf("encode data fail %v, %v", err, data)
		return
	}
	fmt.Println(result) //a:3:{s:3:"arr";a:4:{s:4:"test";b:1;i:0;i:5;s:5:"flt32";d:2.299999952316284;s:5:"int64";i:45;}i:3;s:7:"s"tr'}e";s:1:"g";N;}

	php_s_str := `a:2:{s:3:"sub";a:2:{s:1:"c";i:3;i:99;s:1:"b";}s:2:"aa";i:88;}`
	if decodeRes, err = phpserialize.Decode(php_s_str); err != nil {
		fmt.Errorf("decode data fail %v, %v", err, result)
		return
	}
	fmt.Println(decodeRes) //map[sub:map[c:3 99:b] aa:88]

}