Exemplo n.º 1
0
/**
 * Validates article data.
 *
 * @param  array        $rs  Article data
 * @param  string|array $msg Initial message
 * @return string HTML
 */
function article_validate($rs, &$msg)
{
    global $prefs, $step, $statuses;
    if (!empty($msg)) {
        return false;
    }
    $constraints = array('Status' => new ChoiceConstraint($rs['Status'], array('choices' => array_keys($statuses), 'message' => 'invalid_status')), 'Section' => new SectionConstraint($rs['Section']), 'Category1' => new CategoryConstraint($rs['Category1'], array('type' => 'article')), 'Category2' => new CategoryConstraint($rs['Category2'], array('type' => 'article')), 'textile_body' => new \Textpattern\Textfilter\Constraint($rs['textile_body'], array('message' => 'invalid_textfilter_body')), 'textile_excerpt' => new \Textpattern\Textfilter\Constraint($rs['textile_excerpt'], array('message' => 'invalid_textfilter_excerpt')));
    if (!$prefs['articles_use_excerpts']) {
        $constraints['excerpt_blank'] = new BlankConstraint($rs['Excerpt'], array('message' => 'excerpt_not_blank'));
    }
    if (!$prefs['use_comments']) {
        $constraints['annotate_invite_blank'] = new BlankConstraint($rs['AnnotateInvite'], array('message' => 'invite_not_blank'));
        $constraints['annotate_false'] = new FalseConstraint($rs['Annotate'], array('message' => 'comments_are_on'));
    }
    if ($prefs['allow_form_override']) {
        $constraints['override_form'] = new FormConstraint($rs['override_form'], array('type' => 'article'));
    } else {
        $constraints['override_form'] = new BlankConstraint($rs['override_form'], array('message' => 'override_form_not_blank'));
    }
    callback_event_ref('article_ui', "validate_{$step}", 0, $rs, $constraints);
    $validator = new Validator($constraints);
    if ($validator->validate()) {
        $msg = '';
        return true;
    } else {
        $msg = doArray($validator->getMessages(), 'gTxt');
        $msg = array(join(', ', $msg), E_ERROR);
        return false;
    }
}