adding = $add_form; $form->form = array("title" => (object)array("value" => "", "label" => "Title"), "name" => (object)array("value" => "", "label" => "Name"), "description" => (object)array("value" => "", "label" => "Description"), "slug" => (object)array("value" => "", "label" => "Internet Address")); // @todo add sort column sort order fields $form->errors = array("title" => "", "name" => "", "description" => "", "slug" => ""); if ($type != "album" && $add_form) { $form->form["image"] = (object)array("value" => "", "label" => "Image File"); $form->errors["image"] = ""; } if (empty($path) && !$add_form) { $form->form["name"]->readonly = $form->form["slug"]->readonly = "readonly"; } if ($data) { foreach (array_keys($form->form) as $field) { if (isset($data->$field)) { $form->form[$field]->value = $data->$field; } } } return $form; } static function format_response($type, $path, $form, $result) { $json = (object)array("result" => $result); if ($result != "success") { $json->form = new View("edit.html"); $json->form->title = ($form->adding ? "Add " : "Update ") . ucwords($type); $json->form->url = $form->adding ? "add" : "edit"; $json->form->button_text = $form->adding ? "Add" : "Update"; $json->form->path = $path; $json->form->type = $type; $json->form->form = (object)$form->form; $json->form->errors = (object)$form->errors; $json->form = (string)$json->form; } else { $json->path = $path; $json->type = $type; } return json_encode($json); } /** * Sanitize a filename into something safe * @param string $filename * @return string sanitized filename */ static function sanitize_title($field, $title) { $result = preg_replace("/[^A-Za-z0-9-_]+/", "-", empty($field) ? $title : $field); return trim($result, "-"); } }