less.watch.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Contains page callback for LESS watch functionality.
  5. */
  6. /**
  7. * Page callback for 'ajax/less/watch'.
  8. *
  9. * Handles AJAX requests to check for changes to files while in developer mode.
  10. */
  11. function _less_watch() {
  12. global $theme;
  13. drupal_page_is_cacheable(FALSE);
  14. $changed_files = array();
  15. if (variable_get(LESS_WATCH, FALSE)) {
  16. $files = (isset($_POST['less_files']) && is_array($_POST['less_files'])) ? $_POST['less_files'] : array();
  17. foreach ($files as $file) {
  18. $file_url_parts = drupal_parse_url($file);
  19. if ($cache = cache_get('less:watch:' . drupal_hash_base64($file_url_parts['path']))) {
  20. $cached_data = $cache->data;
  21. $input_file = $cached_data['less']['input_file'];
  22. $output_file = $cached_data['less']['output_file'];
  23. $current_mtime = filemtime($output_file);
  24. $theme = $cached_data['less']['theme'];
  25. $styles = array(
  26. '#items' => array(
  27. $input_file => $cached_data,
  28. ),
  29. );
  30. $styles = _less_pre_render($styles);
  31. if (filemtime($styles['#items'][$input_file]['data']) > $current_mtime) {
  32. $changed_files[] = array(
  33. 'old_file' => $file_url_parts['path'],
  34. 'new_file' => file_create_url($styles['#items'][$input_file]['data']),
  35. );
  36. }
  37. }
  38. }
  39. }
  40. return $changed_files;
  41. }