コード例 #1
0
ファイル: Words.cpp プロジェクト: Tatoeba/yadict
/**
 * virtual page, used to received the data from the words/add form
 * and treat them
 */
void Words::add_treat() {
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

	contents::WordsAdd c;
    init_content(c);
    c.addWord.load(context());
    
    if (c.addWord.validate()) {
        // TODO : handle if something wrong happen while saving
        results::Word word = wordModel.add_word(
            c.addWord.wordLang.selected_id(),
            c.addWord.wordString.value(),
            get_current_user_id()
        );
        if (word.exists()) {
            
            response().set_redirect_header(
                "/" + c.lang +"/words/show-in"
                "/" + word.text + "/" + word.lang
            );
            return; 
        }
    }

    response().set_redirect_header(
        "/" + c.lang +"/words/show-all"
    );
}
コード例 #2
0
ファイル: Words.cpp プロジェクト: Tatoeba/yadict
/**
 * virtual page, delete the item with the given id
 */
void Words::delete_by_id(std::string wordId) {
    CHECK_PERMISSION_OR_GO_TO_LOGIN();
    
    //TODO test before if we really have an integer inside the string
    //TODO handle return value    
    wordModel.delete_word(
        atoi(wordId.c_str()),
        get_current_user_id()
    );

    go_back_to_previous_page();
}
コード例 #3
0
ファイル: Words.cpp プロジェクト: Tatoeba/yadict
/**
 * virtual page, used to received the data from the words/edit form
 * and treat them
 */
void Words::edit_treat() {
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

	forms::EditWord editWord;
    editWord.load(context());
    
    if (!editWord.validate()) {
        go_back_to_previous_page();
        return;
    }
    // TODO : handle if something wrong happen while saving
    wordModel.edit_word(
        atoi(editWord.wordId.value().c_str()), 
        editWord.wordLang.selected_id(),
        editWord.wordString.value(),
        get_current_user_id()
    );

    response().set_redirect_header(
        "/" + get_interface_lang() +"/words/show-in"
        "/" + editWord.wordString.value() +
        "/" +editWord.wordLang.selected_id()
    );
}
コード例 #4
0
ファイル: Articles.cpp プロジェクト: qdii/tatowiki
void Articles::translate_treat() {
    TREAT_PAGE();
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

    forms::articles::Translate form;
    form.load(context());
    if (!form.validate()) {
        set_message(_("The form you've submitted is not valid"));
        go_back_to_previous_page();
    }

    
    const std::string origLang = get_interface_lang();
    const std::string origSlug = form.slug.value();
    const std::string translationSlug = form.translationSlug.value();
    const std::string translationLang = form.transLang.selected_id();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    std::string summary = form.summary.value();
    
    if (summary.empty()) {
        summary = "translated from " + origLang + ":" + origSlug;
    }

    int resultCode = articlesModel->translate_from_lang_and_slug(
       origLang,
       origSlug,
       translationLang,
       translationSlug,
       title,
       content
    );

    // TODO add something to say that the article
    // as been created (and not simply that a "version"
    // has been added
    // TODO also add something to keep trace of the
    //      translation link in the history 
    if (resultCode <= 0) {
        if (resultCode == ARTICLE_ALREADY_TRANSLATED_ERROR) {
            set_message(_("This article has already a translation in that language."));
        } else if (resultCode == ARTICLE_SAME_TRANSLATION_LANGUAGE_ERROR) {
            set_message(_("You can't translate an article in the same language."));
        } else {
            set_message(_("Error while trying to translate."));
        }
        go_back_to_previous_page();
        return;
    }
    
    // simply here for readability 
    int translationId = resultCode;
    
    results::Article translationArticle(
        translationId,
        translationLang,
        translationSlug,
        title,
        content
    );

    historyModel->add_version(
        translationArticle,
        get_current_user_id(),
        summary
    );
    // we redirect to the article we've just added
    redirect(
        "http://" +
        translationLang +
        "." +
        Config::get_base_host() +
        "/articles/show/" + translationSlug
    );

}
コード例 #5
0
ファイル: Articles.cpp プロジェクト: qdii/tatowiki
void Articles::create_treat() {
    TREAT_PAGE();
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

    forms::articles::Create form;
    form.load(context());

    if (!form.validate()) {
        set_message(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }
    
    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();
    // we save in database the articles
    int articleId = articlesModel->create_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );

    if (articleId <= 0) {
        set_message(_("Error while trying to add the article"));
        go_back_to_previous_page();
        return;
    }
    
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );

    // TODO add something to say that the article
    // as been created (and not simply that a "version"
    // has been added
    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );


    // if save => display newly created articles
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );

    // if save and continue => turn now in edit mode
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }


}
コード例 #6
0
ファイル: Articles.cpp プロジェクト: qdii/tatowiki
void Articles::edit_treat() {
    TREAT_PAGE();
    CHECK_PERMISSION_OR_GO_TO_LOGIN();

    forms::articles::Edit form;
    form.load(context());

    if (!form.validate()) {
        //TODO add a more precise message
        set_message(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }

    //TODO check if the last_version_id the form send us
    // is different from what we have in database
    // if so , error message and redirect 
    const int lastVersionId = std::stoi(form.lastVersion.value());
    
    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();

    // TODO maybe replace this by storing the id in an hidden 
    int articleId = articlesModel->get_id_from_lang_and_slug(
        lang,
        slug
    );
 
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );
 
 
    if (lastVersionId != historyModel->get_last_version_id_of(articleId)) {
        set_message(_(
            "Error, someone has edited the article while you"
            "were also editing it"
        ));
        int conflictId = articlesModel->save_conflict(article);
        redirect(
            "/articles/show-conflict/" + std::to_string(conflictId)
        );
        return;
    }

    articlesModel->edit_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );
       

    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );

    // we invalidate the cache for this article
    cache().rise(lang+slug);

    // we show the edit articles if the user wants to 
    // save it
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );
    // we continue in edit mode if the user wants to save and continue
    // to edit
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }
}
コード例 #7
0
ファイル: Articles.cpp プロジェクト: Tatoeba/tatowiki
void Articles::create_treat() {
    TREAT_PAGE();
    LOGIN_REQUIRED();

    forms::articles::Create form;
    form.load(context());

    // if cancel => go back to main page
    if (form.cancel.value()) {
        // TODO most of the time if we are on a create page
        // its because we've clicked on a link to a non-existing
        // page, so it would be better that "cancel" return us to that page
        // maybe by storing the page url in the create form ?
        redirect(
            tatowiki::Config::main_url_from_lang(get_interface_lang())
        );
        go_back_to_previous_page();
        return;
    }

    if (!form.validate()) {
        add_error(_("The form is not valid."));
        go_back_to_previous_page();
        return;
    }

    const std::string lang = get_interface_lang();
    const std::string slug = form.slug.value();
    const std::string title = form.title.value();
    const std::string content = form.content.value();
    const std::string summary = form.summary.value();
    // we save in database the articles
    int articleId = articlesModel->create_from_lang_and_slug(
        lang,
        slug,
        title,
        content
    );

    if (articleId <= 0) {
        add_error(_("Error while trying to add the article"));
        go_back_to_previous_page();
        return;
    }
    
    results::Article article(
        articleId,
        lang,
        slug,
        title,
        content
    );

    // TODO add something to say that the article
    // as been created (and not simply that a "version"
    // has been added
    historyModel->add_version(
        article,
        get_current_user_id(),
        summary
    );


    // if save => display newly created articles
    if (form.saveAndView.value()) {
        redirect(
            "/articles/show/" + form.slug.value()
        );

    // if save and continue => turn now in edit mode
    } else if (form.saveAndContinue.value()) {
        redirect(
            "/articles/edit/" + form.slug.value()
        );
    } else {
        go_back_to_previous_page();
    }


}