function wikitools_node_validate in Wikitools 7
Same name and namespace in other branches
- 5 wikitools.module \wikitools_node_validate()
- 6.2 wikitools.module \wikitools_node_validate()
- 6 wikitools.module \wikitools_node_validate()
Validate check of node edit form.
File
- ./
wikitools.module, line 358 - A non-intrusive module to have some wiki-like behaviour.
Code
function wikitools_node_validate($node) {
if (wikitools_type_affected($node->type)) {
// Check for unique titles.
if (wikitools_enforce_unique_titles()) {
// Build node type condition.
$nid = db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title) AND type IN (:types)", array(
':title' => $node->title,
':types' => wikitools_node_types(),
))
->fetchField();
if (!$nid && wikitools_treat_underscore_as_space()) {
$nid = db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '_', ' ')) = LOWER(REPLACE(:title, '_', ' ')) AND type IN (:types)", array(
':title' => $node->title,
':types' => wikitools_node_types(),
))
->fetchField();
}
if (!$nid && wikitools_treat_dash_as_space()) {
$nid = db_query("SELECT nid FROM {node} WHERE LOWER(REPLACE(title, '-', ' ')) = LOWER(REPLACE(:title, '-', ' ')) AND type IN (:types)", array(
':title' => $node->title,
':types' => wikitools_node_types(),
))
->fetchField();
}
// It is only an error if the node which already exists is not the currently edited node.
if ($nid && $nid != $node->nid) {
form_set_error('title', t('A <a href="@page_url">page</a> with this name already exists.', array(
'@page_url' => url("node/{$nid}"),
)));
}
}
// Check for disallowed characters in title.
if ($disallowed_characters = wikitools_disallowed_characters()) {
for ($i = 0; $i < strlen($node->title); $i++) {
if (strpos($disallowed_characters, $node->title[$i]) !== FALSE) {
form_set_error('title', t('The character %c is not allowed in a title', array(
'%c' => $node->title[$i],
)));
break;
}
}
}
// Check for invalid title names if url subpages are enabled and "/" is allowed in titles.
if (wikitools_subpages_handling() == 'url' && strpos("/", $disallowed_characters) === FALSE) {
$title_parts = explode('/', $node->title);
if (count($title_parts) > 1 && in_array(end($title_parts), wikitools_subpages())) {
form_set_error('title', t('The title is not allowed to end in: %string', array(
'%string' => '/' . implode(', /', wikitools_subpages()),
)));
}
}
}
}