return response('Required argument "css" missing', 400); } if ($args['page'] === false) { // TODO (later): drop_cache() if (empty($args['css'])) { // empty stylesheet @unlink(CONTENT_DIR . '/usercss'); return response(true); } else { $m = umask(0111); if (!@file_put_contents(CONTENT_DIR . '/usercss', $args['css'])) { umask($m); return response('Error saving stylesheet', 500); } else { umask($m); return response(true); } } } else { drop_cache('page', $args['page']); load_modules('glue'); if (empty($args['css'])) { delete_object(array('name' => $args['page'] . '.usercss')); return response(true); } else { return update_object(array('name' => $args['page'] . '.usercss', 'type' => 'usercss', 'module' => 'user_css', 'content' => $args['css'])); } } } register_service('user_css.set_css', 'user_css_set_css', array('auth' => true));
if ($args['page'] === false) { drop_cache('page'); foreach (array('head', 'body') as $x) { if (empty($args[$x])) { @unlink(CONTENT_DIR . '/user' . $x); } else { $m = umask(0111); if (!@file_put_contents(CONTENT_DIR . '/user' . $x, $args[$x])) { umask($m); return response('Error saving user ' . $x, 500); } else { umask($m); } } } return response(true); } else { drop_cache('page', $args['page']); load_modules('glue'); foreach (array('head', 'body') as $x) { if (empty($args[$x])) { delete_object(array('name' => $args['page'] . '.user' . $x)); } else { update_object(array('name' => $args['page'] . '.user' . $x, 'type' => 'user' . $x, 'module' => 'user_code', 'content' => $args[$x])); } } return response(true); } } register_service('user_code.set_code', 'user_code_set_code', array('auth' => true));
log_msg('info', 'image_resize: created a resized image of ' . quot($obj['name']) . ' -> ' . quot(basename($fn))); } // the code above can take a while, so read in the object anew via // update_object() $update = array(); $update['name'] = $obj['name']; $update['image-resized-file'] = basename($fn); $update['image-resized-width'] = $width; $update['image-resized-height'] = $height; // we change width and height here as well since we are racing with the // save_object from the frontend after resize $update['object-width'] = $width . 'px'; $update['object-height'] = $height . 'px'; return update_object($update); } register_service('image.resize', 'image_resize', array('auth' => true)); /** * implements save_state */ function image_save_state($args) { $elem = $args['elem']; $obj = $args['obj']; // only take responsibility for the element when we are its main class if (array_shift(elem_classes($elem)) != 'image') { return false; } // make sure the type is set $obj['type'] = 'image'; $obj['module'] = 'image'; // by convention the main retrieving of the elements properties takes
if (($x = @intval($args['x'])) == 0) { return response('Required argument "x" missing or invalid', 400); } if (($y = @intval($args['y'])) == 0) { return response('Required argument "y" missing or invalid', 400); } $m = umask(0111); if (!@file_put_contents(CONTENT_DIR . '/grid', $x . ' ' . $y)) { umask($m); return response('Error saving to global grid file', 500); } else { umask($m); return response(true); } } register_service('page.set_grid', 'page_set_grid', array('auth' => true)); function page_upload($args) { // only handle the file if the frontend wants us to if (empty($args['preferred_module']) || $args['preferred_module'] != 'page') { return false; } // check if supported file if (!in_array($args['mime'], array('image/jpeg', 'image/png', 'image/gif')) || $args['mime'] == '' && !in_array(filext($args['file']), array('jpg', 'jpeg', 'png', 'gif'))) { return false; } // check if there is already a background-image and delete it $obj = load_object(array('name' => $args['page'] . '.page')); if (!$obj['#error']) { $obj = $obj['#data']; if (!empty($obj['page-background-file'])) {
$ret = array(); // for each revision foreach ($revs as $rev) { // load all objects $files = @scandir(CONTENT_DIR . '/' . $args['pagename'] . '/' . $rev); foreach ($files as $f) { if ($f == '.' || $f == '..') { continue; } $obj = load_object(array('name' => $args['pagename'] . '.' . $rev . '.' . $f)); if ($obj['#error']) { continue; } else { $obj = $obj['#data']; } // and handle the object to our modules log_msg('debug', 'upload_references: checking ' . quot($obj['name'])); $revs = invoke_hook_while('has_reference', false, array('file' => $args['file'], 'obj' => $obj)); if (count($revs)) { $ret[] = $args['pagename'] . '.' . $rev . '.' . $f; if (count($ret) == $stop_after) { // return prematurely return response($ret); } } } } return response($ret); } register_service('glue.upload_references', 'upload_references', array('auth' => true)); register_hook('has_reference', 'check if an object references an uploaded file');