View source
<?php
function spaces_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
db_query("CREATE TABLE {spaces} (\n sid int(10) NOT NULL default '0',\n type varchar(64) NOT NULL,\n preset varchar(64) NOT NULL,\n customizer longtext NOT NULL,\n KEY (sid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("CREATE TABLE {spaces_presets} (\n type varchar(64) NOT NULL,\n id varchar(64) NOT NULL,\n name varchar(255) NOT NULL,\n description longtext NOT NULL,\n value longtext NOT NULL,\n KEY (type)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("CREATE TABLE {spaces_settings} (\n sid int(10) NOT NULL default '0',\n type varchar(64) NOT NULL,\n id longtext NOT NULL,\n value longtext NOT NULL,\n KEY (sid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("CREATE TABLE {spaces_features} (\n sid int(10) NOT NULL default '0',\n type varchar(64) NOT NULL,\n id longtext NOT NULL,\n value longtext NOT NULL,\n KEY (sid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
}
}
function spaces_uninstall() {
db_query('DROP TABLE {spaces_settings}');
db_query('DROP TABLE {spaces_features}');
db_query('DROP TABLE {spaces_features_custom}');
$variables = array();
foreach ($variables as $variable) {
variable_del($variable);
}
}
function spaces_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("UPDATE {system} SET weight = 0 WHERE name = 'spaces'");
$ret[] = update_sql("ALTER TABLE {spaces_features} CHANGE COLUMN gid sid int(10) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {spaces_features} ADD KEY(sid)");
$ret[] = update_sql("DROP TABLE {spaces_features_custom}");
db_query("CREATE TABLE {spaces} (\n sid int(10) NOT NULL default '0',\n type varchar(64) NOT NULL,\n preset varchar(64) NOT NULL,\n customizer longtext NOT NULL,\n KEY (sid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("CREATE TABLE {spaces_presets} (\n type varchar(64) NOT NULL,\n id varchar(64) NOT NULL,\n name varchar(255) NOT NULL,\n description longtext NOT NULL,\n value longtext NOT NULL,\n KEY (type)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
db_query("CREATE TABLE {spaces_settings} (\n sid int(10) NOT NULL default '0', \n type varchar(64) NOT NULL,\n id longtext NOT NULL,\n value longtext NOT NULL,\n KEY (sid)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
$result = db_query("SELECT cp.*, og.* FROM {context_prefix} cp JOIN {og} og ON cp.id = og.nid WHERE cp.provider = 'spaces'");
while ($row = db_fetch_object($result)) {
$og = array(
'og_selective' => $row->selective,
'og_directory' => $row->directory,
'og_register' => $row->register,
'og_private' => $row->private,
);
$preset = _spaces_groupmask('check', $og) ? _spaces_groupmask('check', $og) : 'private';
db_query("UPDATE {context_prefix} SET provider = '%s' WHERE provider = 'spaces' AND prefix = '%s'", 'spaces_og', $row->prefix);
db_query("INSERT INTO {spaces} (sid, type, preset, customizer) VALUES(%d, '%s', '%s', '%s')", $row->id, 'og', $preset, '');
}
$result = db_query("SELECT * FROM {spaces_features} WHERE type = %d", 1);
while ($setting = db_fetch_object($result)) {
if ($setting->id == 'spaces_home') {
$values = array(
$setting->sid,
'og',
'home',
serialize($setting->value),
);
db_query("INSERT INTO {spaces_settings} (sid, type, id, value) VALUES(%d, '%s', '%s', '%s')", $values);
db_query("DELETE FROM {spaces_features} WHERE sid = %d AND id = '%s' AND type = %d", $setting->sid, 'spaces_home', 1);
}
else {
if ($setting->id != 'shoutbox') {
$values = array(
$setting->sid,
'og',
$setting->id,
serialize($setting->value),
);
db_query("INSERT INTO {spaces_settings} (sid, type, id, value) VALUES(%d, '%s', '%s', '%s')", $values);
db_query("DELETE FROM {spaces_features} WHERE sid = %d AND id = '%s' AND type = %d", $setting->sid, $setting->id, 1);
}
}
}
$ret[] = update_sql("ALTER TABLE {spaces_features} CHANGE COLUMN type type varchar(64) NOT NULL");
db_query("UPDATE {spaces_features} SET type = '%s'", 'og');
break;
}
return $ret;
}
function _spaces_groupmask($op = 'mask', $og_settings = array()) {
static $spacetype_mask;
if (!$spacetype_mask) {
$spacetype_mask = array(
'private' => array(
'label' => t('Private'),
'limit options' => array(
SPACES_PRIVATE,
),
'mask' => array(
'og_selective' => OG_CLOSED,
'og_directory' => OG_DIRECTORY_NEVER,
'og_register' => OG_REGISTRATION_ALWAYS,
'og_private' => defined(OG_PRIVATE_GROUPS_ALWAYS) ? OG_PRIVATE_GROUPS_ALWAYS : 1,
),
),
'controlled' => array(
'label' => t('Controlled'),
'mask' => array(
'og_selective' => variable_get('spaces_controlled_selective', OG_CLOSED),
'og_directory' => OG_DIRECTORY_ALWAYS,
'og_register' => OG_REGISTRATION_ALWAYS,
'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
),
),
'public' => array(
'label' => t('Public'),
'limit options' => array(
SPACES_PUBLIC,
),
'mask' => array(
'og_selective' => OG_OPEN,
'og_directory' => OG_DIRECTORY_ALWAYS,
'og_register' => OG_REGISTRATION_ALWAYS,
'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
),
),
);
}
switch ($op) {
case 'mask':
return $spacetype_mask;
case 'check':
foreach ($spacetype_mask as $key => $type) {
if ($og_settings == $type['mask']) {
return $key;
}
}
return false;
case 'labels':
$labels = array();
foreach ($spacetype_mask as $key => $type) {
$labels[$key] = $type['label'];
}
return $labels;
}
}