socialmedia.install in Social media 7
Install, update and uninstall functions for the widgets module.
File
socialmedia.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the widgets module.
*/
/**
* Implements hook_uninstall()
*/
function socialmedia_uninstall() {
variable_del('socialmedia_platforms_site');
variable_del('socialmedia_platforms_user');
variable_del('socialmedia_default_color_body_background');
variable_del('socialmedia_default_color_body_linktext');
variable_del('socialmedia_default_color_body_text');
variable_del('socialmedia_default_color_border');
variable_del('socialmedia_default_color_header_background');
variable_del('socialmedia_default_color_header_text');
variable_del('socialmedia_default_height');
variable_del('socialmedia_default_width');
variable_del('socialmedia_icon_default_style');
variable_del('socialmedia_widget_set_default_profile');
variable_del('socialmedia_widget_set_default_share');
}
/**
* Implements hook_schema().
*/
function socialmedia_schema() {
$schema = array();
$schema['socialmedia_profile'] = array(
'description' => 'Stores social media profile data',
'fields' => array(
'smid' => array(
'description' => 'Primary id',
'type' => 'serial',
'not null' => TRUE,
),
'platform' => array(
'description' => 'machine name identifier of the platform of the profile',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
),
'uid' => array(
'description' => 'User id the profile belongs to. Site profiles have a uid of 0',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'data' => array(
'description' => 'Profile data',
'type' => 'text',
//'serialize' => TRUE, // TODO set field to serialize
'not null' => TRUE,
),
),
'primary key' => array(
'smid',
),
'indexes' => array(
'platform' => array(
'platform',
'uid',
),
),
);
return $schema;
}
/**
* Converts AddThis username to pubid & adds userid to profiles
*/
function socialmedia_update_7001() {
// convert addthis username to pubid
$record = db_select('socialmedia_profile', 'p')
->fields('p')
->condition('platform', 'addthis')
->execute()
->fetch();
$record->data = unserialize($record->data);
if (isset($record->data['username'])) {
$record->data['pubid'] = $record->data['username'];
}
$record->data = serialize($record->data);
drupal_write_record('socialmedia_profile', $record, 'smid');
// create userid in standard profiles
$pubs = array(
'facebook',
'flickr',
'googleplus',
'pinterest',
'linkedin',
'pinterest',
'twitter',
'vimeo',
'youtube',
);
foreach ($pubs as $pub) {
$result = db_select('socialmedia_profile', 'p')
->fields('p')
->condition('platform', $pub)
->execute();
while ($record = $result
->fetchObject()) {
$record->data = unserialize($record->data);
if (isset($record->data['username'])) {
$record->data['userid'] = $record->data['username'];
$record->data = serialize($record->data);
drupal_write_record('socialmedia_profile', $record, 'smid');
}
}
}
}
Functions
Name![]() |
Description |
---|---|
socialmedia_schema | Implements hook_schema(). |
socialmedia_uninstall | Implements hook_uninstall() |
socialmedia_update_7001 | Converts AddThis username to pubid & adds userid to profiles |