'
{$description}
", ); } $form += advagg_validator_admin_form_generator('css', TRUE); $library = advagg_get_library('csslint', 'advagg_validator'); if (!empty($library['installed'])) { $form['#attached']['libraries_load'][] = array('csslint'); } else { $form['#attached']['js'] = $library['variants']['external']['files']['js']; } $form['#attached']['js'][] = array( 'data' => drupal_get_path('module', 'advagg_validator') . '/advagg_validator.js', 'type' => 'file', ); // Comma separated code. // https://github.com/CSSLint/csslint/wiki/Command-line-interface#--ignore $ignore_list = variable_get('advagg_validator_csslint_ignore', ADVAGG_VALIDATOR_CSSLINT_IGNORE); if (is_array($ignore_list)) { $ignore_list = implode(',', $ignore_list); } $form['#attached']['js'][] = array( 'data' => array('csslint' => array('ignore' => $ignore_list)), 'type' => 'setting', ); return $form; } /** * Form builder; CSS validator via jshint. * * @return array * form array. * * @ingroup advagg_forms */ function advagg_validator_admin_js_hint_form() { drupal_set_title(t('AdvAgg: JavaScript Validator using JSHINT')); advagg_display_message_if_requirements_not_met(); // Tell user to update library if a new version is available. $module_name = 'advagg_validator'; $lib_name = 'jshint'; $form = array(); list($description) = advagg_get_version_description($lib_name, $module_name, TRUE); if (!empty($description)) { $form['advagg_version_msg'] = array( '#markup' => "{$description}
", ); } $form = advagg_validator_admin_form_generator('js', TRUE); $library = advagg_get_library('jshint', 'advagg_validator'); if (!empty($library['installed'])) { libraries_load('jshint'); $form['#attached']['libraries_load'][] = array('jshint'); } else { $form['#attached']['js'] = $library['variants']['external']['files']['js']; } $form['#attached']['js'][] = array( 'data' => drupal_get_path('module', 'advagg_validator') . '/advagg_validator.js', 'type' => 'file', ); // Define JSHINT options from https://drupal.org/node/1955232 $settings = array( 'browser' => TRUE, 'curly' => TRUE, 'eqeqeq' => TRUE, 'forin' => TRUE, 'latedef' => TRUE, 'newcap' => TRUE, 'noarg' => TRUE, 'strict' => TRUE, 'trailing' => TRUE, 'undef' => TRUE, 'unused' => TRUE, 'predef' => array( 'Drupal' => FALSE, 'drupalSettings' => FALSE, 'domready' => FALSE, 'jQuery' => FALSE, '_' => FALSE, 'matchMedia' => FALSE, 'Backbone' => FALSE, 'Modernizr' => FALSE, 'VIE' => FALSE, 'CKEDITOR' => FALSE, ), ); // Comma separated code. // https://jslinterrors.com/ $ignore_list = variable_get('advagg_validator_jshint_ignore', ADVAGG_VALIDATOR_JSHINT_IGNORE); if (is_array($ignore_list)) { $ignore_list = implode(',', $ignore_list); } $settings['ignore'] = $ignore_list; $form['#attached']['js'][] = array( 'data' => array('jshint' => $settings), 'type' => 'setting', ); return $form; } /** * Scan the file system and build a form tree from it. * * @param string $type * String: css or js. * @param bool $run_client_side * Set to TRUE to run the checking code client side. * * @return array * form array. */ function advagg_validator_admin_form_generator($type, $run_client_side) { $form = array(); module_load_include('inc', 'advagg_validator', 'advagg_validator'); $files = advagg_validator_scan_all_dirs($type); rsort($files); foreach ($files as $file) { $dir = dirname($file); // Build the direcotry structure. $levels = explode('/', $dir === '.' ? '{ROOT}' : $dir); $point = &$form; $built = array(); foreach ($levels as $key => $value) { // Build direcotry structure. $built[] = $value; $point = &$point[$value]; if (!is_array($point)) { $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir); $wrapper = 'advagg-validator-' . $type . '-validator-ajax' . $form_api_dirname; $point = array( '#type' => 'fieldset', '#title' => check_plain($value), '#description' => '' . t('Directory:') . ' ' . check_plain(implode('/', $built)), '#collapsible' => TRUE, '#collapsed' => TRUE, '#weight' => 100, ); if (!isset($point['check_all_levels']) && $value !== '{ROOT}') { $point['check_all_levels'] = array( '#type' => 'submit', '#value' => t('Check this Directory and all Subdirectories: @dirname', array('@dirname' => implode('/', $built))), ); if (!$run_client_side) { $point['check_all_levels'] += array( '#submit' => array('advagg_validator_admin_test_advagg_' . $type . '_subdirectory_submit'), '#ajax' => array( 'callback' => 'advagg_validator_admin_test_advagg_' . $type . '_subdirectory_callback', 'wrapper' => $wrapper, ), ); } else { $point['check_all_levels'] += array( '#attributes' => array( 'class' => array('advagg_validator_recursive_' . $type), ), ); } } $point['break'] = array( '#markup' => '', ); $point['wrapper'] = array( '#markup' => "", '#weight' => 90, ); } // Drop in button and info if we reached the point where a file lives. if (count($levels) == $key + 1) { $form_api_filename = str_replace(array('/', '.'), array('__', '--'), $file); if (!isset($point['check_this_level'])) { $point['check_this_level'] = array( '#type' => 'submit', '#value' => t('Check this Directory: @dirname', array('@dirname' => $dir)), ); if (!$run_client_side) { $point['check_this_level'] += array( '#submit' => array('advagg_validator_admin_test_advagg_' . $type . '_directory_submit'), '#ajax' => array( 'callback' => 'advagg_validator_admin_test_advagg_' . $type . '_directory_callback', 'wrapper' => $wrapper, ), ); } else { $point['check_this_level'] += array( '#attributes' => array( 'class' => array('advagg_validator_' . $type), ), ); } } if (!isset($point['start'])) { $point['start'] = array( '#markup' => '' . check_plain(print_r($info, TRUE)) . ''; } // @ignore security_dsm drupal_set_message($output); } /** * Display file info via ajax callback. */ function advagg_validator_admin_test_advagg_css_callback($form, &$form_state) { module_load_include('inc', 'advagg_validator', 'advagg_validator'); if (!empty($form_state['values']['error'])) { return ''; } $info = advagg_validator_test_advagg_css(); if (empty($info)) { return ''; } $info = advagg_validator_admin_hide_good_files($info); if (module_exists('httprl')) { $output = httprl_pr($info); } else { $output = '
' . print_r($info, TRUE) . ''; } return '
' . check_plain(print_r($info, TRUE)) . ''; } // @ignore security_dsm drupal_set_message($output); } /** * Display file info via ajax callback. */ function advagg_validator_admin_test_advagg_css_directory_callback($form, &$form_state) { if (empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory:')) !== 0) { return ''; } module_load_include('inc', 'advagg_validator', 'advagg_validator'); $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1)); $slash_count = substr_count('/' . $dir, '/'); // Get list of files. $files = array(); foreach ($form_state['values'] as $key => $value) { if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || substr_count($value, '/') > $slash_count || ($dir === '.' && substr_count($value, '/') > 0)) { continue; } $files[] = $value; } // Check list. $info = advagg_validator_test_css_files($files); $wrapper = ''; if (empty($info)) { return ''; } $info = advagg_validator_admin_hide_good_files($info); if (module_exists('httprl')) { $output = httprl_pr($info); } else { $output = '
' . print_r($info, TRUE) . ''; } $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir); $wrapper = 'advagg-validator-css-validator-ajax' . $form_api_dirname; return '
' . check_plain(print_r($info, TRUE)) . ''; } // @ignore security_dsm drupal_set_message($output); } /** * Display file info via ajax callback. */ function advagg_validator_admin_test_advagg_css_subdirectory_callback($form, &$form_state) { if (empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory and all Subdirectories:')) !== 0) { return ''; } module_load_include('inc', 'advagg_validator', 'advagg_validator'); $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1)); // Get list of files. $files = array(); foreach ($form_state['values'] as $key => $value) { if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || ($dir === '.' && substr_count($value, '/') > 0)) { continue; } $files[] = $value; } // Check list. $info = advagg_validator_test_css_files($files); $wrapper = ''; if (empty($info)) { return ''; } $info = advagg_validator_admin_hide_good_files($info); if (module_exists('httprl')) { $output = httprl_pr($info); } else { $output = '
' . print_r($info, TRUE) . ''; } $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir); $wrapper = 'advagg-validator-css-validator-ajax' . $form_api_dirname; return '
' . check_plain(print_r($info, TRUE)) . ''; } // @ignore security_dsm drupal_set_message($output); } /** * Display file info via ajax callback. */ function advagg_validator_admin_test_all_css_callback($form, &$form_state) { module_load_include('inc', 'advagg_validator', 'advagg_validator'); if (!empty($form_state['values']['error'])) { return ''; } $info = advagg_validator_test_all_css(); if (empty($info)) { return ''; } $info = advagg_validator_admin_hide_good_files($info); if (module_exists('httprl')) { $output = httprl_pr($info); } else { $output = '
' . print_r($info, TRUE) . ''; } return '