Example #1
0
/**
 * Creates a form template.
 *
 * On a successful run, will trigger a 'form.create > done' callback event.
 *
 * @param   string $name The name
 * @param   string $type The type
 * @param   string $Form The template
 * @return  bool   FALSE on error
 * @since   4.6.0
 * @package Template
 */
function create_form($name, $type, $Form)
{
    $types = get_form_types();
    if (form_exists($name) || !is_valid_form($name) || !in_array($type, array_keys($types))) {
        return false;
    }
    if (safe_insert('txp_form', "name = '" . doSlash($name) . "',\n            type = '" . doSlash($type) . "',\n            Form = '" . doSlash($Form) . "'") === false) {
        return false;
    }
    callback_event('form.create', 'done', 0, compact('name', 'type', 'Form'));
    return true;
}
Example #2
0
function addtext_check($array)
{
    global $config;
    check_permission(PERM_ADDER);
    //read file for tokenizer
    $tok_exc = array_map('mb_strtolower', file($config['project']['root'] . '/scripts/tokenizer/tokenizer_exceptions.txt', FILE_IGNORE_NEW_LINES));
    $tok_prefixes = file($config['project']['root'] . '/scripts/tokenizer/tokenizer_prefixes.txt', FILE_IGNORE_NEW_LINES);
    //removing bad symbols
    $clear_text = '';
    for ($i = 0; $i < mb_strlen($array['txt'], 'UTF-8'); ++$i) {
        $char = mb_substr($array['txt'], $i, 1, 'UTF-8');
        $code = uniord($char);
        if ($code != 769 && $code != 173 && ($code < 8192 || $code > 8203) && !in_array($code, array(8206, 8207)) && !in_array($code, array(160, 8237, 8239, 8288, 12288))) {
            $clear_text .= $char;
        }
    }
    $out = array('full' => $clear_text, 'select0' => get_books_for_select(0));
    $pars = split2paragraphs($clear_text);
    foreach ($pars as $par) {
        $par_array = array();
        $sents = split2sentences($par);
        foreach ($sents as $sent) {
            if (!preg_match('/\\S/', $sent)) {
                continue;
            }
            $sent_array = array('src' => $sent);
            $tokens = tokenize_ml($sent, $tok_exc, $tok_prefixes);
            foreach ($tokens as $token) {
                $sent_array['tokens'][] = array('text' => $token[0], 'class' => form_exists($token[0]), 'border' => $token[1], 'vector' => $token[2]);
            }
            $par_array['sentences'][] = $sent_array;
        }
        $out['paragraphs'][] = $par_array;
    }
    //book
    if (isset($array['book_id'])) {
        $book_id = (int) $array['book_id'];
        $r = sql_fetch_array(sql_query("SELECT parent_id FROM books WHERE book_id={$book_id} LIMIT 1"));
        if ($r['parent_id'] > 0) {
            $out['selected0'] = $r['parent_id'];
            $out['select1'] = get_books_for_select($r['parent_id']);
            $out['selected1'] = $book_id;
        } else {
            $out['selected0'] = $book_id;
        }
    }
    return $out;
}