View source
<?php
function live_css_menu() {
$items = array();
$items['css/save'] = array(
'page callback' => 'live_css_save',
'access arguments' => array(
'edit css',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function live_css_perm() {
return array(
'edit css',
);
}
function live_css_init() {
if (user_access('edit css')) {
drupal_add_link(array(
'id' => 'bespin_base',
'href' => '/' . drupal_get_path('module', 'live_css') . '/bespin/prebuilt/',
'rel' => '',
));
drupal_add_css(drupal_get_path('module', 'live_css') . '/bespin/prebuilt/BespinEmbedded.css', 'module', 'all', FALSE);
drupal_add_js(drupal_get_path('module', 'live_css') . '/bespin/prebuilt/BespinEmbedded.js');
drupal_add_js(drupal_get_path('module', 'live_css') . '/plugins.js');
drupal_add_css(drupal_get_path('module', 'live_css') . '/css.css', 'module', 'all', FALSE);
drupal_add_js(drupal_get_path('module', 'live_css') . '/css.js?1');
}
}
function live_css_save() {
$css = $_POST['css'];
$href = $_POST['href'];
$parts = split('/', $href);
$path = '';
for ($i = 3; $i < count($parts); $i++) {
$path .= $parts[$i] . '/';
}
$path = substr($path, 0, strpos($path, '?'));
$fh = fopen($path, 'w') or die("can't open file");
fwrite($fh, $css);
fclose($fh);
echo json_encode(array(
'result' => 'success',
'filename' => $path,
));
}