View source
<?php
function addtocopy_permission() {
return array(
'bypass addtocopy' => array(
'title' => t('Bypass addtocopy'),
'description' => t('Copy text without additional piece added by addtocopy.'),
),
);
}
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;
}
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;
}
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;
}
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;
}
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;
}
function addtocopy_page_build(&$page) {
if (!user_access('bypass addtocopy')) {
drupal_add_library('addtocopy', 'addtocopy', TRUE);
}
}