Exemplo n.º 1
0
/**
 * Update a language code, in such a way that new attachments are created if they were specified.
 *
 * @param  integer		The language id
 * @param  LONG_TEXT		The new text
 * @param  ID_TEXT		The arbitrary type that the attached is for (e.g. download)
 * @param  ID_TEXT		The id in the set of the arbitrary types that the attached is for
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether to backup the language string before changing it
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return integer		The language id
 */
function update_lang_comcode_attachments($lang_id, $text, $type, $id, $connection = NULL, $backup_string = false, $for_member = NULL)
{
    if ($lang_id == 0) {
        return insert_lang_comcode_attachments(3, $text, $type, $id, $connection, false, $for_member);
    }
    if ($text === STRING_MAGIC_NULL) {
        return $lang_id;
    }
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    require_lang('comcode');
    _check_attachment_count();
    $test = $connection->query_value_null_ok('translate', 'text_original', array('id' => $id, 'language' => user_lang()));
    if ($backup_string) {
        $current = $connection->query_select('translate', array('*'), array('id' => $lang_id, 'language' => user_lang()));
        if (!array_key_exists(0, $current)) {
            $current = $connection->query_select('translate', array('*'), array('id' => $lang_id));
        }
        $connection->query_insert('translate_history', array('lang_id' => $lang_id, 'language' => $current[0]['language'], 'text_original' => $current[0]['text_original'], 'broken' => $current[0]['broken'], 'action_member' => get_member(), 'action_time' => time()));
    }
    $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    $_info = do_comcode_attachments($text, $type, $id, false, $connection, NULL, $for_member);
    $text2 = '';
    //Actually we'll let it regenerate with the correct permissions ($member, not $for_member) $_info['tempcode']->to_assembly();
    $remap = array('text_original' => $_info['comcode'], 'text_parsed' => $text2);
    if (ocp_admirecookie('use_wysiwyg', '1') == '0' && get_value('edit_with_my_comcode_perms') === '1' || !has_specific_permission($member, 'allow_html') || !has_specific_permission($member, 'use_very_dangerous_comcode')) {
        $remap['source_user'] = $member;
    }
    if (!is_null($test)) {
        $connection->query_update('translate', $remap, array('id' => $lang_id, 'language' => user_lang()));
    } else {
        $connection->query_update('translate', $remap, array('id' => $lang_id));
    }
    return $lang_id;
}
Exemplo n.º 2
0
/**
 * Insert some comcode content that may contain attachments, and return the language id.
 *
 * @param  integer		The level of importance this language string holds
 * @set    1 2 3 4
 * @param  LONG_TEXT		The comcode content
 * @param  ID_TEXT		The arbitrary type that the attached is for (e.g. download)
 * @param  ID_TEXT		The id in the set of the arbitrary types that the attached is for
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether to insert it as an admin (any comcode parsing will be carried out with admin privileges)
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return integer		The language id
 */
function insert_lang_comcode_attachments($level, $text, $type, $id, $connection = NULL, $insert_as_admin = false, $for_member = NULL)
{
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    require_lang('comcode');
    _check_attachment_count();
    $_info = do_comcode_attachments($text, $type, $id, false, $connection, $insert_as_admin, $for_member);
    $text2 = $_info['tempcode']->to_assembly();
    $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    $lang_id = NULL;
    if (user_lang() == 'Gibb') {
        $lang_id = $connection->query_insert('translate', array('source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => 'EnglishEnglishWarningWrongLanguageWantGibberishLang', 'text_parsed' => '', 'language' => 'EN'), true);
    }
    if (is_null($lang_id)) {
        $lang_id = $connection->query_insert('translate', array('source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $_info['comcode'], 'text_parsed' => $text2, 'language' => user_lang()), true);
    } else {
        $connection->query_insert('translate', array('id' => $lang_id, 'source_user' => $member, 'broken' => 0, 'importance_level' => $level, 'text_original' => $_info['comcode'], 'text_parsed' => $text2, 'language' => user_lang()));
    }
    final_attachments_from_preview($id, $connection);
    return $lang_id;
}