View source
<?php
function _context_addassets_admin_url() {
return 'admin/build/context/add-assets';
}
function context_addassets_menu() {
$items[_context_addassets_admin_url()] = array(
'title' => 'Configure Add Assets',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'context_addassets_admin',
),
'access arguments' => array(
'access administration pages',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function context_addassets_uninstall() {
}
function context_addassets_admin() {
$css = drupal_get_path('module', 'context_addassets') . "/css/context_addassets-admin.css";
drupal_add_css($css, 'theme', 'all', TRUE);
$modules = module_list();
asort($modules);
foreach ($modules as $key => $value) {
$index = drupal_get_path('module', $value);
$modules[$index] = $value;
unset($modules[$key], $index);
}
$form['description'] = array(
'#value' => t('By default Context Add Assets indexes your active themes, you can increase the locations that are indexed below.'),
);
$form['modules'] = array(
'#type' => 'fieldset',
'#title' => 'Index Module Assets',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['modules']['context_addassets_index_modules'] = array(
'#type' => 'checkboxes',
'#title' => 'Include Selected Module Assets',
'#options' => $modules,
'#default_value' => variable_get('context_addassets_index_modules', array()),
);
$form['paths'] = array(
'#type' => 'fieldset',
'#title' => 'Index Path Assets',
'#description' => t('Add file paths below to have them indexed by Add Assets. Note that paths should be relative to root of Drupal installation and <em>not include a leading/trailing slash</em>.<p><strong>Example:</strong> sites/all/libraries/my-custom-libraries</p>'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$path_index = 0;
while ($path = variable_get('context_addassets_index_path' . $path_index, NULL)) {
$form['paths']['context_addassets_index_path' . $path_index] = array(
'#type' => 'textfield',
'#title' => 'Path',
'#default_value' => $path,
);
$path_index += 1;
}
$path_add_at_time = 1;
$end = $path_index + $path_add_at_time - 1;
while ($path_index <= $end) {
$form['paths']['context_addassets_index_path' . $path_index] = array(
'#type' => 'textfield',
'#title' => 'Path',
);
$path_index += 1;
}
return system_settings_form($form);
}
function context_addassets_ctools_plugin_api($module, $api) {
if ($module == 'context' && $api == 'plugins') {
return array(
'version' => 3,
);
}
}
function context_addassets_context_plugins() {
$plugins = array();
$plugins['context_reaction_addcss'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addcss.inc',
'class' => 'context_reaction_addcss',
'parent' => 'context_reaction',
),
);
$plugins['context_reaction_addjs'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addjs.inc',
'class' => 'context_reaction_addjs',
'parent' => 'context_reaction',
),
);
$plugins['context_reaction_addcss_module'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addcss_module.inc',
'class' => 'context_reaction_addcss_module',
'parent' => 'context_reaction',
),
);
$plugins['context_reaction_addjs_module'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addjs_module.inc',
'class' => 'context_reaction_addjs_module',
'parent' => 'context_reaction',
),
);
$plugins['context_reaction_addcss_path'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addcss_path.inc',
'class' => 'context_reaction_addcss_path',
'parent' => 'context_reaction',
),
);
$plugins['context_reaction_addjs_path'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addjs_path.inc',
'class' => 'context_reaction_addjs_path',
'parent' => 'context_reaction',
),
);
return $plugins;
}
function context_addassets_context_registry() {
$registry = array();
$registry['reactions'] = array(
'css' => array(
'plugin' => 'context_reaction_addcss',
),
'js' => array(
'plugin' => 'context_reaction_addjs',
),
'css_module' => array(
'plugin' => 'context_reaction_addcss_module',
),
'js_module' => array(
'plugin' => 'context_reaction_addjs_module',
),
'css_path' => array(
'plugin' => 'context_reaction_addcss_path',
),
'js_path' => array(
'plugin' => 'context_reaction_addjs_path',
),
);
return $registry;
}
function context_addassets_context_page_reaction() {
if ($plugin = context_get_plugin('reaction', 'css')) {
$plugin
->execute();
}
if ($plugin = context_get_plugin('reaction', 'js')) {
$plugin
->execute();
}
if ($plugin = context_get_plugin('reaction', 'css_module')) {
$plugin
->execute();
}
if ($plugin = context_get_plugin('reaction', 'js_module')) {
$plugin
->execute();
}
if ($plugin = context_get_plugin('reaction', 'css_path')) {
$plugin
->execute();
}
if ($plugin = context_get_plugin('reaction', 'js_path')) {
$plugin
->execute();
}
}
function _context_addassets_scandir($filetype = NULL, $where = 'themes') {
if ($filetype[0] == '.') {
$filetype = drupal_substr(1, drupal_strlen($filetype));
}
$include_all = FALSE;
switch ($where) {
case 'modules':
$modules = variable_get('context_addassets_index_modules', array());
foreach ($modules as $path) {
if (!$path) {
continue;
}
$dir = realpath('.') . base_path() . $path;
$mask = ".+\\." . $filetype;
$files_raw[$path] = file_scan_directory($dir, $mask);
}
break;
case 'paths':
$path_index = 0;
while ($path = variable_get('context_addassets_index_path' . $path_index, NULL)) {
$dir = realpath('.') . base_path() . $path;
$mask = ".+\\." . $filetype;
$files_raw[$path] = file_scan_directory($dir, $mask);
$path_index += 1;
}
break;
case 'themes':
default:
$selected_themes = array();
$files_raw = array();
$themes = list_themes();
foreach ($themes as $item) {
$list = get_object_vars($item);
if ($include_all == FALSE and $list['status'] or $include_all == TRUE) {
$list = get_object_vars($item);
$path = explode('/', $list['filename']);
unset($path[count($path) - 1]);
$path = implode('/', $path);
$selected_themes[] = array(
'name' => $list['info']['name'],
'path' => $path,
);
}
}
foreach ($selected_themes as $theme) {
$dir = realpath('.') . base_path() . $theme['path'];
$name = $theme['name'];
$mask = ".+\\." . $filetype;
$files_raw[$name] = file_scan_directory($dir, $mask);
}
break;
}
if (!is_array($files_raw)) {
return;
}
foreach ($files_raw as $key => $value) {
foreach ($value as $value_key => $file) {
$theme_path = drupal_get_path('theme', $key);
$dir = realpath('.') . base_path() . ($theme_path ? $theme_path . "/" : $theme_path);
$file_name = str_replace($dir, '', $file->filename);
$file_path = str_replace(realpath('.') . '/', '', $file->filename);
if (!is_array($key)) {
$key = explode('/', $key);
$key = $key[count($key) - 1];
}
$file_name = explode("/{$key}/", $file_name);
$file_name = $file_name[1] ? $file_name[1] : $file_name[0];
$file_files[$file_path] = $key . ' -- ' . $file_name;
}
}
return $file_files;
}