View source
<?php
function _context_addassets_admin_path() {
if (module_exists('context_ui')) {
$core_context_items = context_ui_menu();
foreach ($core_context_items as $path => $item) {
if (stripos($path, 'context/settings') != false) {
$addassets_admin_path = str_replace('/settings', '', $path) . '/add-assets';
break;
}
}
if (!isset($addassets_admin_path) or !trim($addassets_admin_path)) {
$addassets_admin_path = 'admin/structure/context/add-assets';
}
return $addassets_admin_path;
}
else {
return;
}
}
function context_addassets_menu() {
$items[_context_addassets_admin_path()] = array(
'title' => 'Assets',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'context_addassets_admin',
),
'access arguments' => array(
'access administration pages',
),
'type' => MENU_LOCAL_TASK,
);
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(
'#markup' => 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',
),
);
if (module_exists('less')) {
$plugins['context_reaction_addless'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_addassets') . '/plugins',
'file' => 'context_reaction_addless.inc',
'class' => 'context_reaction_addless',
'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',
),
);
if (module_exists('less')) {
$registry['reactions']['less'] = array(
'plugin' => 'context_reaction_addless',
);
}
return $registry;
}
function context_addassets_context_page_reaction() {
if ($plugin = context_get_plugin('reaction', 'css')) {
$plugin
->execute();
}
if (module_exists('less')) {
if ($plugin = context_get_plugin('reaction', 'less')) {
$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') {
$file_files = FALSE;
if ($filetype[0] == '.') {
$filetype = drupal_substr(1, drupal_strlen($filetype));
}
$include_all = FALSE;
$mask = "/.+\\." . $filetype . '/';
switch ($where) {
case 'modules':
$modules = variable_get('context_addassets_index_modules', array());
foreach ($modules as $path) {
if (!$path) {
continue;
}
$files_raw[$path] = file_scan_directory($path, $mask);
}
break;
case 'paths':
$path_index = 0;
while ($path = variable_get('context_addassets_index_path' . $path_index, NULL)) {
$files_raw[$path] = file_scan_directory($path, $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 = $theme['path'];
$name = $theme['name'];
$mask = "/.+\\." . $filetype . "/";
$files_raw[$name] = file_scan_directory($dir, $mask);
}
break;
}
if (isset($files_raw)) {
if (is_array($files_raw)) {
foreach ($files_raw as $key => $value) {
foreach ($value as $value_key => $file) {
$file_files[$file->uri] = $key . ' -- ' . $file->uri;
}
}
}
}
return $file_files;
}