advagg_validator.admin.inc

  1. cis7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  2. cle7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  3. ecd7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  4. elmsmedia7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  5. harmony7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  6. icor7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  7. meedjum_blog7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
  8. mooc7 sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc

Admin page callbacks for the advagg validator module.

Functions

Namesort ascending Description
advagg_validator_admin_test_all_css_submit Display file info in a drupal message.
advagg_validator_admin_test_all_css_callback Display file info via ajax callback.
advagg_validator_admin_test_advagg_css_submit Display file info in a drupal message.
advagg_validator_admin_test_advagg_css_subdirectory_submit Display file info in a drupal message.
advagg_validator_admin_test_advagg_css_subdirectory_callback Display file info via ajax callback.
advagg_validator_admin_test_advagg_css_directory_submit Display file info in a drupal message.
advagg_validator_admin_test_advagg_css_directory_callback Display file info via ajax callback.
advagg_validator_admin_test_advagg_css_callback Display file info via ajax callback.
advagg_validator_admin_js_hint_form Form builder; CSS validator via jshint.
advagg_validator_admin_hide_good_files Do not display info on a file if it is valid.
advagg_validator_admin_form_generator Scan the file system and build a form tree from it.
advagg_validator_admin_css_w3_form Form builder; CSS validator via w3.
advagg_validator_admin_css_lint_form Form builder; CSS validator via csslint.

File

sites/all/modules/ulmus/advagg/advagg_validator/advagg_validator.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the advagg validator module.
  5. */
  6. /**
  7. * Form builder; CSS validator via w3.
  8. *
  9. * @return array
  10. * form array.
  11. */
  12. function advagg_validator_admin_css_w3_form() {
  13. drupal_set_title(t('AdvAgg: CSS Validator using w3.org'));
  14. $form = advagg_validator_admin_form_generator('css', FALSE);
  15. // Add notice that using this form will submit files to a remote server.
  16. $form['notice'] = array(
  17. '#markup' => '<div>' . t('Notice: The form below will submit files to the <a href="http://jigsaw.w3.org/css-validator/">http://jigsaw.w3.org/css-validator/</a> service if used.') . '</div>',
  18. '#weight' => -1,
  19. );
  20. return $form;
  21. }
  22. /**
  23. * Form builder; CSS validator via csslint.
  24. *
  25. * @return array
  26. * form array.
  27. */
  28. function advagg_validator_admin_css_lint_form() {
  29. drupal_set_title(t('AdvAgg: CSS Validator using CSSLINT'));
  30. $form = advagg_validator_admin_form_generator('css', TRUE);
  31. $form['#attached']['js'][] = array(
  32. 'data' => '//rawgithub.com/stubbornella/csslint/master/release/csslint.js',
  33. 'type' => 'external',
  34. );
  35. $form['#attached']['js'][] = array(
  36. 'data' => drupal_get_path('module', 'advagg_validator') . '/advagg_validator.js',
  37. 'type' => 'file',
  38. );
  39. return $form;
  40. }
  41. /**
  42. * Form builder; CSS validator via jshint.
  43. *
  44. * @return array
  45. * form array.
  46. */
  47. function advagg_validator_admin_js_hint_form() {
  48. drupal_set_title(t('AdvAgg: JavaScript Validator using JSHINT'));
  49. $form = advagg_validator_admin_form_generator('js', TRUE);
  50. $form['#attached']['js'][] = array(
  51. 'data' => '//rawgithub.com/jshint/jshint/master/dist/jshint.js',
  52. 'type' => 'external',
  53. );
  54. $form['#attached']['js'][] = array(
  55. 'data' => drupal_get_path('module', 'advagg_validator') . '/advagg_validator.js',
  56. 'type' => 'file',
  57. );
  58. // Define JSHINT options from https://drupal.org/node/1955232
  59. $settings = array(
  60. 'browser' => TRUE,
  61. 'curly' => TRUE,
  62. 'eqeqeq' => TRUE,
  63. 'forin' => TRUE,
  64. 'latedef' => TRUE,
  65. 'newcap' => TRUE,
  66. 'noarg' => TRUE,
  67. 'strict' => TRUE,
  68. 'trailing' => TRUE,
  69. 'undef' => TRUE,
  70. 'unused' => TRUE,
  71. 'predef' => array(
  72. 'Drupal' => FALSE,
  73. 'drupalSettings' => FALSE,
  74. 'domready' => FALSE,
  75. 'jQuery' => FALSE,
  76. '_' => FALSE,
  77. 'matchMedia' => FALSE,
  78. 'Backbone' => FALSE,
  79. 'Modernizr' => FALSE,
  80. 'VIE' => FALSE,
  81. 'CKEDITOR' => FALSE,
  82. ),
  83. );
  84. $form['#attached']['js'][] = array(
  85. 'data' => array('jshint' => $settings),
  86. 'type' => 'setting',
  87. );
  88. return $form;
  89. }
  90. /**
  91. * Scan the file system and build a form tree from it.
  92. *
  93. * @param string $type
  94. * css or js
  95. * @param bool $run_client_side
  96. * Set to TRUE to run the checking code client side.
  97. *
  98. * @return array
  99. * form array.
  100. */
  101. function advagg_validator_admin_form_generator($type, $run_client_side) {
  102. $form = array();
  103. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  104. $files = advagg_validator_scan_all_dirs($type);
  105. rsort($files);
  106. foreach ($files as $file) {
  107. $dir = dirname($file);
  108. // Build the direcotry structure.
  109. $levels = explode('/', $dir == '.' ? '{ROOT}' : $dir);
  110. $point = &$form;
  111. $built = array();
  112. foreach ($levels as $key => $value) {
  113. // Build direcotry structure,
  114. $built[] = $value;
  115. $point = &$point[$value];
  116. if (!is_array($point)) {
  117. $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir);
  118. $wrapper = 'advagg-validator-' . $type . '-validator-ajax' . $form_api_dirname;
  119. $point = array(
  120. '#type' => 'fieldset',
  121. '#title' => check_plain($value),
  122. '#description' => '<strong>' . t('Directory:') . ' </strong>' . check_plain(implode('/', $built)),
  123. '#collapsible' => TRUE,
  124. '#collapsed' => TRUE,
  125. '#weight' => 100,
  126. );
  127. if (!isset($point['check_all_levels']) && $value != '{ROOT}') {
  128. $point['check_all_levels'] = array(
  129. '#type' => 'submit',
  130. '#value' => t('Check this Directory and all Subdirectories: @dirname', array('@dirname' => implode('/', $built))),
  131. );
  132. if (!$run_client_side) {
  133. $point['check_all_levels'] += array(
  134. '#submit' => array('advagg_validator_admin_test_advagg_' . $type . '_subdirectory_submit'),
  135. '#ajax' => array(
  136. 'callback' => 'advagg_validator_admin_test_advagg_' . $type . '_subdirectory_callback',
  137. 'wrapper' => $wrapper,
  138. ),
  139. );
  140. }
  141. else {
  142. $point['check_all_levels'] += array(
  143. '#attributes' => array(
  144. 'class' => array('advagg_validator_recursive_' . $type),
  145. ),
  146. );
  147. }
  148. }
  149. $point['break'] = array(
  150. '#markup' => '<div></div>',
  151. );
  152. $point['wrapper'] = array(
  153. '#markup' => "<div id='" . $wrapper . "' class='results'></div>",
  154. '#weight' => 90,
  155. );
  156. }
  157. // Drop in button and info if we reached the point where a file lives.
  158. if (count($levels) == $key + 1) {
  159. $form_api_filename = str_replace(array('/', '.'), array('__', '--'), $file);
  160. if (!isset($point['check_this_level'])) {
  161. $point['check_this_level'] = array(
  162. '#type' => 'submit',
  163. '#value' => t('Check this Directory: @dirname', array('@dirname' => $dir)),
  164. );
  165. if (!$run_client_side) {
  166. $point['check_this_level'] += array(
  167. '#submit' => array('advagg_validator_admin_test_advagg_' . $type . '_directory_submit'),
  168. '#ajax' => array(
  169. 'callback' => 'advagg_validator_admin_test_advagg_' . $type . '_directory_callback',
  170. 'wrapper' => $wrapper,
  171. ),
  172. );
  173. }
  174. else {
  175. $point['check_this_level'] += array(
  176. '#attributes' => array(
  177. 'class' => array('advagg_validator_' . $type),
  178. ),
  179. );
  180. }
  181. }
  182. if (!isset($point['start'])) {
  183. $point['start'] = array(
  184. '#markup' => '<br /><strong>' . t('File:') . ' </strong><div class="filenames">',
  185. );
  186. }
  187. else {
  188. $point['start'] = array(
  189. '#markup' => '<br /><strong>' . t('Files:') . ' </strong><div class="filenames">',
  190. );
  191. }
  192. $point[$form_api_filename] = array(
  193. '#markup' => check_plain($file) . ' ',
  194. );
  195. if (!isset($point['end'])) {
  196. $point['end'] = array(
  197. '#markup' => '</div>',
  198. );
  199. }
  200. $point['hidden_' . $form_api_filename] = array(
  201. '#type' => 'hidden',
  202. '#value' => $file,
  203. '#attributes' => array(
  204. 'class' => array('filenames'),
  205. ),
  206. );
  207. }
  208. }
  209. }
  210. return $form;
  211. }
  212. // Submit callbacks.
  213. /**
  214. * Display file info in a drupal message.
  215. */
  216. function advagg_validator_admin_test_advagg_css_submit($form, &$form_state) {
  217. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  218. if (!empty($form_state['input']['ajax_page_state'])) {
  219. return;
  220. }
  221. $info = advagg_validator_test_advagg_css();
  222. $info = advagg_validator_admin_hide_good_files($info);
  223. if (module_exists('httprl')) {
  224. $output = httprl_pr($info);
  225. }
  226. else {
  227. $output = '<pre>' . check_plain(print_r($info, TRUE)) . '</pre>';
  228. }
  229. // @ignore security_dsm
  230. drupal_set_message($output);
  231. }
  232. /**
  233. * Display file info via ajax callback.
  234. */
  235. function advagg_validator_admin_test_advagg_css_callback($form, &$form_state) {
  236. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  237. if (!empty($form_state['values']['error'])) {
  238. return '<div id="advagg-file-info-ajax"></div>';
  239. }
  240. $info = advagg_validator_test_advagg_css();
  241. if (empty($info)) {
  242. return '<div id="advagg-file-info-ajax"></div>';
  243. }
  244. $info = advagg_validator_admin_hide_good_files($info);
  245. if (module_exists('httprl')) {
  246. $output = httprl_pr($info);
  247. }
  248. else {
  249. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  250. }
  251. return '<div id="advagg-validator-css-validator-ajax">' . $output . '</div>';
  252. }
  253. /**
  254. * Display file info in a drupal message.
  255. */
  256. function advagg_validator_admin_test_advagg_css_directory_submit($form, &$form_state) {
  257. if (!empty($form_state['input']['ajax_page_state']) || empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory:')) !== 0) {
  258. return;
  259. }
  260. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  261. $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1));
  262. $slash_count = substr_count('/' . $dir, '/');
  263. // Get list of files.
  264. $files = array();
  265. foreach ($form_state['values'] as $key => $value) {
  266. if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || substr_count($value, '/') > $slash_count || ($dir == '.' && substr_count($value, '/') > 0)) {
  267. continue;
  268. }
  269. $files[] = $value;
  270. }
  271. // Check list.
  272. $info = advagg_validator_test_css_files($files);
  273. $info = advagg_validator_admin_hide_good_files($info);
  274. if (module_exists('httprl')) {
  275. $output = httprl_pr($info);
  276. }
  277. else {
  278. $output = '<pre>' . check_plain(print_r($info, TRUE)) . '</pre>';
  279. }
  280. // @ignore security_dsm
  281. drupal_set_message($output);
  282. }
  283. /**
  284. * Display file info via ajax callback.
  285. */
  286. function advagg_validator_admin_test_advagg_css_directory_callback($form, &$form_state) {
  287. if (empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory:')) !== 0) {
  288. return '<div></div>';
  289. }
  290. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  291. $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1));
  292. $slash_count = substr_count('/' . $dir, '/');
  293. // Get list of files.
  294. $files = array();
  295. foreach ($form_state['values'] as $key => $value) {
  296. if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || substr_count($value, '/') > $slash_count || ($dir == '.' && substr_count($value, '/') > 0)) {
  297. continue;
  298. }
  299. $files[] = $value;
  300. }
  301. // Check list.
  302. $info = advagg_validator_test_css_files($files);
  303. if (empty($info)) {
  304. return '<div id="' . $wrapper . '" class="results"></div>';
  305. }
  306. $info = advagg_validator_admin_hide_good_files($info);
  307. if (module_exists('httprl')) {
  308. $output = httprl_pr($info);
  309. }
  310. else {
  311. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  312. }
  313. $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir);
  314. $wrapper = 'advagg-validator-css-validator-ajax' . $form_api_dirname;
  315. return '<div id="' . $wrapper . '" class="results">' . $output . '</div>';
  316. }
  317. /**
  318. * Display file info in a drupal message.
  319. */
  320. function advagg_validator_admin_test_advagg_css_subdirectory_submit($form, &$form_state) {
  321. if (!empty($form_state['input']['ajax_page_state']) || empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory and all Subdirectories:')) !== 0) {
  322. return;
  323. }
  324. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  325. $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1));
  326. $slash_count = substr_count('/' . $dir, '/');
  327. // Get list of files.
  328. $files = array();
  329. foreach ($form_state['values'] as $key => $value) {
  330. if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || ($dir == '.' && substr_count($value, '/') > 0)) {
  331. continue;
  332. }
  333. $files[] = $value;
  334. }
  335. // Check list.
  336. $info = advagg_validator_test_css_files($files);
  337. $info = advagg_validator_admin_hide_good_files($info);
  338. if (module_exists('httprl')) {
  339. $output = httprl_pr($info);
  340. }
  341. else {
  342. $output = '<pre>' . check_plain(print_r($info, TRUE)) . '</pre>';
  343. }
  344. // @ignore security_dsm
  345. drupal_set_message($output);
  346. }
  347. /**
  348. * Display file info via ajax callback.
  349. */
  350. function advagg_validator_admin_test_advagg_css_subdirectory_callback($form, &$form_state) {
  351. if (empty($form_state['values']['op']) || strpos($form_state['values']['op'], t('Check this Directory and all Subdirectories:')) !== 0) {
  352. return '<div></div>';
  353. }
  354. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  355. $dir = trim(substr($form_state['values']['op'], strpos($form_state['values']['op'], ':') + 1));
  356. $slash_count = substr_count('/' . $dir, '/');
  357. // Get list of files.
  358. $files = array();
  359. foreach ($form_state['values'] as $key => $value) {
  360. if (strpos($key, 'hidden') === FALSE || strpos($value, $dir) === FALSE || ($dir == '.' && substr_count($value, '/') > 0)) {
  361. continue;
  362. }
  363. $files[] = $value;
  364. }
  365. // Check list.
  366. $info = advagg_validator_test_css_files($files);
  367. if (empty($info)) {
  368. return '<div id="' . $wrapper . '" class="results"></div>';
  369. }
  370. $info = advagg_validator_admin_hide_good_files($info);
  371. if (module_exists('httprl')) {
  372. $output = httprl_pr($info);
  373. }
  374. else {
  375. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  376. }
  377. $form_api_dirname = str_replace(array('/', '.'), array('__', '--'), $dir);
  378. $wrapper = 'advagg-validator-css-validator-ajax' . $form_api_dirname;
  379. return '<div id="' . $wrapper . '" class="results">' . $output . '</div>';
  380. }
  381. /**
  382. * Display file info in a drupal message.
  383. */
  384. function advagg_validator_admin_test_all_css_submit($form, &$form_state) {
  385. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  386. if (!empty($form_state['input']['ajax_page_state'])) {
  387. return;
  388. }
  389. $info = advagg_validator_test_all_css();
  390. $info = advagg_validator_admin_hide_good_files($info);
  391. if (module_exists('httprl')) {
  392. $output = httprl_pr($info);
  393. }
  394. else {
  395. $output = '<pre>' . check_plain(print_r($info, TRUE)) . '</pre>';
  396. }
  397. // @ignore security_dsm
  398. drupal_set_message($output);
  399. }
  400. /**
  401. * Display file info via ajax callback.
  402. */
  403. function advagg_validator_admin_test_all_css_callback($form, &$form_state) {
  404. module_load_include('inc', 'advagg_validator', 'advagg_validator');
  405. if (!empty($form_state['values']['error'])) {
  406. return '<div id="advagg-file-info-ajax"></div>';
  407. }
  408. $info = advagg_validator_test_all_css();
  409. if (empty($info)) {
  410. return '<div id="advagg-file-info-ajax"></div>';
  411. }
  412. $info = advagg_validator_admin_hide_good_files($info);
  413. if (module_exists('httprl')) {
  414. $output = httprl_pr($info);
  415. }
  416. else {
  417. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  418. }
  419. return '<div id="advagg-validator-css-validator-ajax">' . $output . '</div>';
  420. }
  421. /**
  422. * Do not display info on a file if it is valid.
  423. *
  424. * @param array $info
  425. * Array containing info about validators and if the file is valid.
  426. *
  427. * @return array
  428. * $info array minus data if that file is valid.
  429. */
  430. function advagg_validator_admin_hide_good_files($info) {
  431. $output = array();
  432. foreach ($info as $filename => $validators) {
  433. foreach ($validators as $v_name => $v_data) {
  434. if (!empty($v_data['validity'])) {
  435. $output[$filename][$v_name] = 'valid';
  436. continue;
  437. }
  438. $output[$filename][$v_name] = $v_data;
  439. }
  440. }
  441. return $output;
  442. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.