Commit fff2f548 authored by Dries's avatar Dries
Browse files

- Improved form items: added <label> tags to improve accessibility and added
  theme_form_element() function to improve themeability.  I left form_item()
  and the calls to form_item() intact for now.
parent e27df450
......@@ -813,34 +813,35 @@ function form($form, $method = "post", $action = 0, $options = 0) {
}
function form_item($title, $value, $description = 0) {
return "<div class=\"form-item\">". ($title ? "<div class=\"title\">$title:</div>" : "") . $value . ($description ? "<div class=\"description\">$description</div>" : "") ."</div>\n";
return theme("form_element", $title, $value, $description);
}
function form_group($legend, $group, $description = 0) {
return "<fieldset>" . ($legend ? "<legend>$legend</legend>" : "") . $group . ($description ? "<div class=\"description\">$description</div>" : "") . "</fieldset>\n";
}
function form_radio($title, $name, $value = 1, $checked = 0, $description = 0, $attributes = 0) {
return form_item(0, "<input type=\"radio\" class=\"form-radio\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
return theme("form_element", 0, "<input type=\"radio\" class=\"form-radio\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
}
function form_checkbox($title, $name, $value = 1, $checked = 0, $description = 0, $attributes = 0) {
return form_hidden($name, 0) . form_item(0, "<input type=\"checkbox\" class=\"form-checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
return form_hidden($name, 0) . theme("form_element", 0, "<input type=\"checkbox\" class=\"form-checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") . drupal_attributes($attributes) ." /> $title", $description);
}
function form_textfield($title, $name, $value, $size, $maxlength, $description = 0, $attributes = 0) {
$size = $size ? " size=\"$size\"" : "";
return form_item($title, "<input type=\"text\" maxlength=\"$maxlength\" class=\"form-text\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
return theme("form_element", $title, "<input type=\"text\" maxlength=\"$maxlength\" class=\"form-text\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
}
function form_password($title, $name, $value, $size, $maxlength, $description = 0, $attributes = 0) {
$size = $size ? " size=\"$size\"" : "";
return form_item($title, "<input type=\"password\" class=\"form-password\" maxlength=\"$maxlength\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
return theme("form_element", $title, "<input type=\"password\" class=\"form-password\" maxlength=\"$maxlength\" name=\"edit[$name]\"$size value=\"". check_form($value) ."\"". drupal_attributes($attributes) ." />", $description);
}
function form_textarea($title, $name, $value, $cols, $rows, $description = 0, $attributes = 0) {
$cols = $cols ? " cols=\"$cols\"" : "";
module_invoke_all("textarea", $name); // eg. optionally plug in a WYSIWYG editor
return form_item($title, "<textarea wrap=\"virtual\"$cols rows=\"$rows\" name=\"edit[$name]\" id=\"edit[$name]\"". drupal_attributes($attributes) .">". check_form($value) ."</textarea>", $description);
return theme("form_element", $title, "<textarea wrap=\"virtual\"$cols rows=\"$rows\" name=\"edit[$name]\" id=\"edit[$name]\"". drupal_attributes($attributes) .">". check_form($value) ."</textarea>", $description);
}
function form_select($title, $name, $value, $options, $description = 0, $extra = 0, $multiple = 0) {
......@@ -848,7 +849,7 @@ function form_select($title, $name, $value, $options, $description = 0, $extra =
foreach ($options as $key=>$choice) {
$select .= "<option value=\"$key\"". (is_array($value) ? (in_array($key, $value) ? " selected=\"selected\"" : "") : ($value == $key ? " selected=\"selected\"" : "")) .">". check_form($choice) ."</option>";
}
return form_item($title, "<select name=\"edit[$name]". ($multiple ? "[]" : "") ."\"". ($multiple ? " multiple " : "") . ($extra ? " $extra" : "") .">$select</select>", $description);
return theme("form_element", $title, "<select name=\"edit[$name]". ($multiple ? "[]" : "") ."\"". ($multiple ? " multiple " : "") . ($extra ? " $extra" : "") .">$select</select>", $description);
}
}
......@@ -857,12 +858,12 @@ function form_radios($title, $name, $value, $options, $description = 0) {
foreach ($options as $key=>$choice) {
$output .= form_radio($choice, $name, $key, ($key == $value));
}
return form_item($title, $output, $description);
return theme("form_element", $title, $output, $description);
}
}
function form_file($title, $name, $size, $description = 0) {
return form_item($title, "<input type=\"file\" class=\"form-file\" name=\"edit[$name]\" size=\"$size\" />\n", $description);
return theme("form_element", $title, "<input type=\"file\" class=\"form-file\" name=\"edit[$name]\" size=\"$size\" />\n", $description);
}
function form_hidden($name, $value) {
......
......@@ -145,6 +145,19 @@ function _theme_table_cell($cell, $header = 0) {
return $output;
}
/**
Returns themed table.
@param $title the form element's title
@param $value the form element's data
@param $description the form element's description or explanation
@return a string contraining the \a node output.
**/
function theme_form_element($title, $value, $description = 0) {
return "<div class=\"form-item\">". ($title ? "<label>$title:</label>" : "") . $value . ($description ? "<div class=\"description\">$description</div>" : "") ."</div>\n";
}
/**
Returns themed table.
......
......@@ -113,7 +113,7 @@ fieldset {
.form-item .description {
font-size: 0.85em;
}
.form-item .title {
.form-item label {
font-weight: bold;
margin-top: 1.1em;
margin-bottom: 1px;
......
......@@ -17,10 +17,10 @@ function blogapi_help($section) {
function blogapi_xmlrpc() {
$methods = array('blogger.getUsersBlogs' => array('function' => 'blogapi_get_users_blogs'),
'blogger.newPost' => array('function' => 'blogapi_new_post'),
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
'blogger.newPost' => array('function' => 'blogapi_new_post'),
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
'blogger.deletePost' => array('function' => 'blogapi_delete_post'),
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
'metaWeblog.newPost' => array('function' => 'blogapi_new_post'),
'metaWeblog.editPost' => array('function' => 'blogapi_edit_post'),
'metaWeblog.getPost' => array('function' => 'blogapi_get_post'),
......@@ -31,7 +31,7 @@ function blogapi_xmlrpc() {
'mt.getPostCategories' => array('function' => 'blogapi_get_post_categories'),
'mt.setPostCategories' => array('function' => 'blogapi_set_post_categories')
);
return $methods;
}
......@@ -62,7 +62,7 @@ function blogapi_get_user_info($req_params) {
'firstname' => new xmlrpcval(substr($user->name, 0, strrpos($user->name, " ")), 'string'),
'nickname' => new xmlrpcval($user->name, 'string'),
'email' => new xmlrpcval($user->mail, 'string'),
'url' => new xmlrpcval(url('blog/view/' . $user->uid), 'string')),
'url' => new xmlrpcval(url('blog/view/' . $user->uid), 'string')),
'struct');
return new xmlrpcresp($struct);
}
......@@ -73,11 +73,11 @@ function blogapi_get_user_info($req_params) {
function blogapi_new_post($req_params) {
global $user;
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$promote = variable_get("node_promote_blog", 0);
......@@ -94,7 +94,7 @@ function blogapi_new_post($req_params) {
$title = blogapi_blogger_title($params[3]);
$body = $params[3];
}
$node = node_validate(array('type' => 'blog',
'uid' => $user->uid,
'name' => $user->name,
......@@ -106,7 +106,7 @@ function blogapi_new_post($req_params) {
'moderate' => $moderate,
'revision' => $revision
), $error);
if (count($error) > 0) {
return blogapi_error($error);
}
......@@ -130,7 +130,7 @@ function blogapi_edit_post($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$node = node_load(array('nid' => $params[0]));
......@@ -151,12 +151,12 @@ function blogapi_edit_post($req_params) {
$title = blogapi_blogger_title($params[3]);
$body = $params[3];
}
$node->title = $title;
$node->body = $body;
$node->status = $params[4];
$node = node_validate($node, $error);
if (count($error) > 0) {
return blogapi_error($error);
}
......@@ -176,10 +176,10 @@ function blogapi_get_post($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$node = node_load(array('nid' => $params[0]));
$node = node_load(array('nid' => $params[0]));
$blog = new xmlrpcval(array('userid' => new xmlrpcval($node->name, 'string'),
'dateCreated' => new xmlrpcval(iso8601_encode($node->created), "dateTime.iso8601"),
'title' => new xmlrpcval($node->title, 'string'),
......@@ -194,10 +194,10 @@ function blogapi_delete_post($req_params) {
global $user;
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[2], $params[3]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$ret = node_delete(array('nid' => $params[1], 'confirm' => 1));
......@@ -234,7 +234,7 @@ function blogapi_get_post_categories($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$terms = taxonomy_node_get_terms($params[0]);
......@@ -256,7 +256,7 @@ function blogapi_set_post_categories($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$nid = $params[0];
......@@ -272,7 +272,7 @@ function blogapi_get_recent_posts($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$res = db_query_range("SELECT n.nid, n.title, n.body, n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = 'blog' AND n.uid = %d ORDER BY n.created DESC", $user->uid, 0, $params[3]);
......@@ -303,13 +303,13 @@ function blogapi_convert($params) {
function blogapi_error($message) {
global $xmlrpcusererr;
return new xmlrpcresp(0, $xmlrpcusererr + 1, $message);
}
function blogapi_validate_user($username, $password) {
global $user;
$user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1));
if (!user_access('access blog API')) {
......
......@@ -17,10 +17,10 @@ function blogapi_help($section) {
function blogapi_xmlrpc() {
$methods = array('blogger.getUsersBlogs' => array('function' => 'blogapi_get_users_blogs'),
'blogger.newPost' => array('function' => 'blogapi_new_post'),
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
'blogger.newPost' => array('function' => 'blogapi_new_post'),
'blogger.editPost' => array('function' => 'blogapi_edit_post'),
'blogger.deletePost' => array('function' => 'blogapi_delete_post'),
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
'blogger.getRecentPosts' => array('function' => 'blogapi_get_recent_posts'),
'metaWeblog.newPost' => array('function' => 'blogapi_new_post'),
'metaWeblog.editPost' => array('function' => 'blogapi_edit_post'),
'metaWeblog.getPost' => array('function' => 'blogapi_get_post'),
......@@ -31,7 +31,7 @@ function blogapi_xmlrpc() {
'mt.getPostCategories' => array('function' => 'blogapi_get_post_categories'),
'mt.setPostCategories' => array('function' => 'blogapi_set_post_categories')
);
return $methods;
}
......@@ -62,7 +62,7 @@ function blogapi_get_user_info($req_params) {
'firstname' => new xmlrpcval(substr($user->name, 0, strrpos($user->name, " ")), 'string'),
'nickname' => new xmlrpcval($user->name, 'string'),
'email' => new xmlrpcval($user->mail, 'string'),
'url' => new xmlrpcval(url('blog/view/' . $user->uid), 'string')),
'url' => new xmlrpcval(url('blog/view/' . $user->uid), 'string')),
'struct');
return new xmlrpcresp($struct);
}
......@@ -73,11 +73,11 @@ function blogapi_get_user_info($req_params) {
function blogapi_new_post($req_params) {
global $user;
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$promote = variable_get("node_promote_blog", 0);
......@@ -94,7 +94,7 @@ function blogapi_new_post($req_params) {
$title = blogapi_blogger_title($params[3]);
$body = $params[3];
}
$node = node_validate(array('type' => 'blog',
'uid' => $user->uid,
'name' => $user->name,
......@@ -106,7 +106,7 @@ function blogapi_new_post($req_params) {
'moderate' => $moderate,
'revision' => $revision
), $error);
if (count($error) > 0) {
return blogapi_error($error);
}
......@@ -130,7 +130,7 @@ function blogapi_edit_post($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$node = node_load(array('nid' => $params[0]));
......@@ -151,12 +151,12 @@ function blogapi_edit_post($req_params) {
$title = blogapi_blogger_title($params[3]);
$body = $params[3];
}
$node->title = $title;
$node->body = $body;
$node->status = $params[4];
$node = node_validate($node, $error);
if (count($error) > 0) {
return blogapi_error($error);
}
......@@ -176,10 +176,10 @@ function blogapi_get_post($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$node = node_load(array('nid' => $params[0]));
$node = node_load(array('nid' => $params[0]));
$blog = new xmlrpcval(array('userid' => new xmlrpcval($node->name, 'string'),
'dateCreated' => new xmlrpcval(iso8601_encode($node->created), "dateTime.iso8601"),
'title' => new xmlrpcval($node->title, 'string'),
......@@ -194,10 +194,10 @@ function blogapi_delete_post($req_params) {
global $user;
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[2], $params[3]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$ret = node_delete(array('nid' => $params[1], 'confirm' => 1));
......@@ -234,7 +234,7 @@ function blogapi_get_post_categories($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$terms = taxonomy_node_get_terms($params[0]);
......@@ -256,7 +256,7 @@ function blogapi_set_post_categories($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$nid = $params[0];
......@@ -272,7 +272,7 @@ function blogapi_get_recent_posts($req_params) {
$params = blogapi_convert($req_params);
$user = blogapi_validate_user($params[1], $params[2]);
if (!$user->uid) {
return blogapi_error(t('error validating user'));
return blogapi_error(t('error validating user'));
}
$res = db_query_range("SELECT n.nid, n.title, n.body, n.created, u.name FROM {node} n, {users} u WHERE n.uid=u.uid AND n.type = 'blog' AND n.uid = %d ORDER BY n.created DESC", $user->uid, 0, $params[3]);
......@@ -303,13 +303,13 @@ function blogapi_convert($params) {
function blogapi_error($message) {
global $xmlrpcusererr;
return new xmlrpcresp(0, $xmlrpcusererr + 1, $message);
}
function blogapi_validate_user($username, $password) {
global $user;
$user = user_load(array('name' => $username, 'pass' => $password, 'status' => 1));
if (!user_access('access blog API')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment