You are here

smileys.install in Smileys 5

Same filename and directory in other branches
  1. 6 smileys.install

File

smileys.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function smileys_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $result = db_query("CREATE TABLE IF NOT EXISTS {smileys} (\n        id int(11) auto_increment,\n        acronyms varchar(255) DEFAULT '' NOT NULL,\n        image varchar(255) DEFAULT '' NOT NULL,\n        description varchar(64) DEFAULT '' NOT NULL,\n        standalone tinyint(1) DEFAULT '0' NOT NULL,\n        promote_to_box tinyint(1) DEFAULT '1' NOT NULL,\n        package varchar(64) DEFAULT 'Uncategorized' NOT NULL,\n        PRIMARY KEY (id)\n      ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $result = db_query("CREATE TABLE {smileys} (\n        id SERIAL,\n        acronyms varchar(255) DEFAULT '' NOT NULL,\n        image varchar(255) DEFAULT '' NOT NULL,\n        description varchar(64) DEFAULT '' NOT NULL,\n        standalone INT2 NOT NULL DEFAULT '0',\n        promote_to_box INT2 NOT NULL DEFAULT '1',\n        package varchar(64) DEFAULT 'Uncategorized' NOT NULL,\n        PRIMARY KEY (id)\n      )");
      break;
  }
  if ($result) {
    $dir = drupal_get_path('module', 'smileys') . '/packs/example/';
    $examples = array(
      array(
        ':) :-) :smile:',
        'smile.png',
        'Smiling',
      ),
      array(
        ';) ;-) :wink:',
        'wink.png',
        'Eye-wink',
      ),
      array(
        ':( :-( :sad:',
        'sad.png',
        'Sad',
      ),
      array(
        ':D :-D :lol:',
        'lol.png',
        'Laughing out loud',
      ),
      array(
        '}:) }:-) :evil:',
        'evil.png',
        'Evil',
      ),
      array(
        ':P :-P :tongue:',
        'tongue.png',
        'Sticking out tongue',
      ),
      array(
        ':O :-O :shocked:',
        'shock.png',
        'Shocked',
      ),
      array(
        ':? :-? :puzzled:',
        'puzzled.png',
        'Puzzled',
      ),
      array(
        '8) 8-) :cool:',
        'cool.png',
        'Cool',
      ),
      array(
        ':jawdrop:',
        'jawdrop.gif',
        'Jawdropping!',
      ),
      array(
        ':sick: :barf:',
        'barf.gif',
        'Barf!',
      ),
    );
    foreach ($examples as $data) {
      db_query("INSERT INTO {smileys} (acronyms, image, description, standalone, package) VALUES ('%s', '%s', '%s', 1, '%s');", $data[0], $dir . $data[1], $data[2], 'example');
    }
  }
}

/**
 * Implementation of hook_uninstall().
 */
function smileys_uninstall() {
  db_query('DROP TABLE {smileys}');
  variable_del('smileys_enable_for_comments');
  variable_del('smileys_enable_for_nodes');
}

/**
 * Updates
 */
function smileys_update_1() {
  return _system_update_utf8(array(
    'smileys',
  ));
}
function smileys_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_add_column($ret, 'smileys', 'promote_to_box', 'INT2', array(
        'default' => '1',
        'not null' => TRUE,
        'after' => 'standalone',
      ));
      break;
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {smileys} ADD COLUMN promote_to_box tinyint(1) NOT NULL DEFAULT 1 AFTER standalone");
  }
  return $ret;
}

Functions

Namesort descending Description
smileys_install Implementation of hook_install().
smileys_uninstall Implementation of hook_uninstall().
smileys_update_1 Updates
smileys_update_2