You are here

function live_css_save in Live CSS 6

Same name and namespace in other branches
  1. 6.2 live_css.module \live_css_save()
  2. 7.2 live_css.module \live_css_save()
  3. 7 live_css.module \live_css_save()
1 string reference to 'live_css_save'
live_css_menu in ./live_css.module
Implements hook_menu().

File

./live_css.module, line 47

Code

function live_css_save() {
  $css = $_POST['css'];
  $href = $_POST['href'];

  //calculate the file path relative to the base drupal folder
  $parts = split('/', $href);
  $path = '';
  for ($i = 3; $i < count($parts); $i++) {
    $path .= $parts[$i] . '/';
  }
  $path = substr($path, 0, strpos($path, '?'));

  //save file back
  $fh = fopen($path, 'w') or die("can't open file");
  fwrite($fh, $css);
  fclose($fh);
  echo json_encode(array(
    'result' => 'success',
    'filename' => $path,
  ));
}