You are here

addtocopy.module in Add link to copied text 7

Same filename and directory in other branches
  1. 8 addtocopy.module
  2. 6 addtocopy.module

File

addtocopy.module
View source
<?php

/**
 * Implements hook_permission().
 */
function addtocopy_permission() {
  return array(
    'bypass addtocopy' => array(
      'title' => t('Bypass addtocopy'),
      'description' => t('Copy text without additional piece added by addtocopy.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function addtocopy_menu() {
  $items = array(
    'admin/config/user-interface/addtocopy' => array(
      'title' => 'Add to Copy',
      'description' => 'Configure Add to Copy settings.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'addtocopy_settings_form',
      ),
      'access callback' => 'user_access',
      'access arguments' => array(
        'administer site configuration',
      ),
      'file' => 'addtocopy.admin.inc',
      'type' => MENU_NORMAL_ITEM,
    ),
  );
  return $items;
}

/**
 * Implements hook_library().
 */
function addtocopy_library() {
  $libraries['addtocopy'] = array(
    'title' => 'Add to Copy',
    'website' => 'http://tops.net.ua/jquery_addtocopy/',
    'version' => _addtocopy_library_version(),
    'js' => array(
      drupal_get_path('module', 'addtocopy') . '/addtocopy.js' => array(),
      array(
        'type' => 'setting',
        'data' => array(
          'addtocopy' => array(
            'selector' => variable_get('addtocopy_selector', '#content'),
            'minlen' => variable_get('addtocopy_minlen', 25),
            'htmlcopytxt' => variable_get('addtocopy_htmlcopytxt', '<br>More: <a href="[link]">[link]</a><br>'),
            'addcopyfirst' => variable_get('addtocopy_addcopyfirst', 0),
          ),
        ),
      ),
    ),
    'css' => array(
      drupal_get_path('module', 'addtocopy') . '/addtocopy.css' => array(
        'type' => 'file',
      ),
    ),
  );
  if (module_exists('libraries')) {
    $libraries['addtocopy']['js'][libraries_get_path('addtocopy') . '/addtocopy.js'] = array();
  }
  else {
    $libraries['addtocopy']['js']['sites/all/libraries/addtocopy' . '/addtocopy.js'] = array();
  }
  return $libraries;
}

/**
 * Returns the path to the Add to Copy library.
 */
function _addtocopy_library_path() {
  $library_path =& drupal_static(__FUNCTION__, NULL);
  if (is_null($library_path)) {
    $library_path = variable_get('addtocopy_library_path', module_exists('libraries') ? libraries_get_path('addtocopy') : 'sites/all/libraries/addtocopy');
    if (!file_exists($library_path . '/addtocopy.js')) {
      watchdog('addtocopy', 'Add to Copy library is missing.', array(), WATCHDOG_ERROR);
      $library_path = FALSE;
    }
  }
  return $library_path;
}

/**
 * Returns the path to the Add to Copy library js file.
 */
function _addtocopy_library_path_js() {
  $library_path_js =& drupal_static(__FUNCTION__, NULL);
  if (is_null($library_path_js) && ($library_path = _addtocopy_library_path())) {
    if (file_exists($library_path . '/addtocopy.js')) {
      $library_path_js = $library_path . '/addtocopy.js';
    }
  }
  return $library_path_js;
}

/**
 * Returns version of the Add to Copy library.
 */
function _addtocopy_library_version() {
  $version =& drupal_static(__FUNCTION__, NULL);
  if (is_null($version) && ($library_path = _addtocopy_library_path())) {
    $pattern = '/@version ([0-9\\.a-z]+)/';
    $addtocopy_js = file_get_contents(_addtocopy_library_path_js(), NULL, NULL, 0, 150);
    if (preg_match($pattern, $addtocopy_js, $matches)) {
      $version = $matches[1];
    }
    else {
      $version = 'Unknown';
    }
  }
  return $version;
}

/**
 * Implements hook_page_build().
 */
function addtocopy_page_build(&$page) {
  if (!user_access('bypass addtocopy')) {
    drupal_add_library('addtocopy', 'addtocopy', TRUE);
  }
}

Functions

Namesort descending Description
addtocopy_library Implements hook_library().
addtocopy_menu Implements hook_menu().
addtocopy_page_build Implements hook_page_build().
addtocopy_permission Implements hook_permission().
_addtocopy_library_path Returns the path to the Add to Copy library.
_addtocopy_library_path_js Returns the path to the Add to Copy library js file.
_addtocopy_library_version Returns version of the Add to Copy library.