You are here

ocupload.install in One Click Upload 7

Same filename and directory in other branches
  1. 7.2 ocupload.install

Install/Uninstall functions

File

ocupload.install
View source
<?php

/**
 * @file
 * Install/Uninstall functions
 */

/**
 * Implements hook_schema().
 */
function ocupload_schema() {
  $shema['ocupload_templates'] = array(
    'fields' => array(
      'tid' => array(
        'description' => 'Template ID',
        'type' => 'serial',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'mask' => array(
        'description' => 'File mask',
        'type' => 'varchar',
        'length' => 200,
        'not null' => TRUE,
        'default' => '',
      ),
      'path' => array(
        'description' => 'Upload path',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'max_filesize' => array(
        'description' => 'Max filesize in bytes',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'template' => array(
        'description' => 'Template',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '<a href="!filepath">!filename</a>',
      ),
      'template_select' => array(
        'description' => 'Template for replace selected text',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '<a href="!filepath">!text</a>',
      ),
      'image_style' => array(
        'description' => 'Image style',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'image_style_original' => array(
        'description' => 'Image style for original image',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'link_to_original' => array(
        'description' => 'Wrap template link to original image',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'link_template' => array(
        'description' => 'Link template',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '<a href="!filepath" target="_blank">!image</a>',
      ),
      'link_only_big' => array(
        'description' => '1 - wrap template only big images, 0 - wrap all images',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_dimensions' => array(
        'description' => 'Maximum image resolution',
        'type' => 'varchar',
        'length' => 20,
        'not null' => TRUE,
        'default' => '',
      ),
      'rename_file' => array(
        'description' => '1 - change filename to unique number (datetime), 0 - not change',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'tid',
    ),
    'description' => 'Module templates',
  );
  return $shema;
}

/**
 * Implements hook_install().
 */
function ocupload_install() {
  module_load_include('inc', 'ocupload');
  $templates = array(
    array(
      'mask' => 'jpg,jpeg,gif,png',
      'path' => 'images',
      'template' => '<img src="!filepath" alt="" />',
      'template_select' => module_exists('colorbox') ? '<a href="!filepath" class="colorbox" target="_blank">!text</a>' : '<a href="!filepath" target="_blank">!text</a>',
      'image_style' => 'large',
      'link_to_original' => 1,
      'link_only_big' => 1,
      'rename_file' => 0,
    ),
    array(
      'mask' => 'rar,zip,doc,xls',
      'path' => 'files',
      'template' => '<a href="!filepath">!filename</a>',
      'template_select' => '<a href="!filepath">!text</a>',
      'rename_file' => 0,
    ),
    array(
      'mask' => 'webm,mp4,ogv',
      'path' => 'video',
      'template' => '<video src="!filepath" width="480" height="390" controls></video>',
      'template_select' => '<a href="!filepath">!text</a>',
      'rename_file' => 0,
    ),
  );
  foreach ($templates as $template) {
    $directory = 'public://' . $template['path'];
    file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
  }
  ocupload_template_save($templates, TRUE);
}

/**
 * Implements hook_uninstall().
 */
function ocupload_uninstall() {
  foreach (array(
    'ocupload_delete_unused_files',
  ) as $name) {
    variable_del($name);
  }
}

/**
 * Add new col {ocupload_templates}.show_in_colorbox
 */
function ocupload_update_7100() {
  db_add_field('ocupload_templates', 'show_in_colorbox', array(
    'description' => '1 - show original image in colorbox, 0 - open in new page',
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
}

/**
 * Change col length {ocupload_templates}.path
 */
function ocupload_update_7101() {
  db_change_field('ocupload_templates', 'path', 'path', array(
    'description' => 'Upload path',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));
}

/**
 * Add new col {ocupload_templates}.image_style_original
 */
function ocupload_update_7102() {
  db_add_field('ocupload_templates', 'image_style_original', array(
    'description' => 'Image style for original image',
    'type' => 'varchar',
    'length' => 50,
    'not null' => TRUE,
    'default' => '',
  ));
}

/**
 * Add new col {ocupload_templates}.max_filesize
 */
function ocupload_update_7103() {
  db_add_field('ocupload_templates', 'max_filesize', array(
    'description' => 'Max filesize in bytes',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
}

/**
 * Add new col {ocupload_templates}.max_dimensions
 */
function ocupload_update_7104() {
  db_add_field('ocupload_templates', 'max_dimensions', array(
    'description' => 'Maximum image resolution',
    'type' => 'varchar',
    'length' => 20,
    'not null' => TRUE,
    'default' => '',
  ));
}

/**
 * Add new col {ocupload_templates}.link_template
 * Update colorbox integration
 * Delete col {ocupload_templates}.show_in_colorbox
 */
function ocupload_update_7105() {

  // Add field
  db_add_field('ocupload_templates', 'link_template', array(
    'description' => 'Link template',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '<a href="!filepath" target="_blank">!image</a>',
  ));

  // Update Colorbox integration
  module_load_include('module', 'ocupload');
  module_load_include('inc', 'ocupload');
  foreach (ocupload_templates() as $template) {
    if ($template->show_in_colorbox) {
      $template->link_template = '<a href="!filepath" class="colorbox" target="_blank">!image</a>';
      ocupload_template_save($template);
    }
  }

  // Delete field
  db_drop_field('ocupload_templates', 'show_in_colorbox');
}

Functions

Namesort descending Description
ocupload_install Implements hook_install().
ocupload_schema Implements hook_schema().
ocupload_uninstall Implements hook_uninstall().
ocupload_update_7100 Add new col {ocupload_templates}.show_in_colorbox
ocupload_update_7101 Change col length {ocupload_templates}.path
ocupload_update_7102 Add new col {ocupload_templates}.image_style_original
ocupload_update_7103 Add new col {ocupload_templates}.max_filesize
ocupload_update_7104 Add new col {ocupload_templates}.max_dimensions
ocupload_update_7105 Add new col {ocupload_templates}.link_template Update colorbox integration Delete col {ocupload_templates}.show_in_colorbox