/** * Display the page with a form to edit the information about a word */ void Words::edit(std::string wordId) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); int id = atoi(wordId.c_str()); contents::WordsEdit c; init_content(c); contents::WordsHelper whc( wordModel.get_word_with_id(id) ); whc.lang = c.lang; // if no item with this id if (whc.empty()) { response().set_redirect_header( "/" + c.lang +"/words/show-all" ); return; } // Set the value of the form to the current value // So one will know what he is editing c.editWord.wordId.value(wordId); c.editWord.wordLang.selected_id(whc.words[0].lang); c.editWord.wordString.value(whc.words[0].text); c.whc = whc; render("words_edit",c); }
void Articles::show(std::string slug) { if(tatowiki::Config::isPrivate()) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); } contents::articles::Show c; init_content(c); c.markdown = mymarkdown; std::string lang = get_interface_lang(); c.cacheKey = lang + slug; c.article = articlesModel->get_from_lang_and_slug( lang, slug ); // if the article does not exists we redirect to the // page to create one if (!c.article.exists()) { redirect( "/articles/create/" + slug ); return; } c.translatedIn = articlesModel->get_group_of( c.article.id, c.article.groupId ); render("articles_show", c); }
void Articles::edit(const std::string slug) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); results::Article article = articlesModel->get_from_lang_and_slug( get_interface_lang(), slug ); // if the articles does not exist we load the "create" form rather // than "edit" one if (!article.exists()) { redirect( "/articles/create/" + slug ); return; } int lastVersionId = historyModel->get_last_version_id_of( article.id ); contents::articles::Edit c(article,lastVersionId); init_content(c); //TODO get last_version_id of the article and // add it to the content render("articles_edit", c); }
/** * 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" ); }
/** * Display the page with a form to add new words */ void Words::add() { CHECK_PERMISSION_OR_GO_TO_LOGIN(); contents::WordsAdd c; init_content(c); render("words_add",c); }
void Words::startdict_export( std::string src, std::string dest ) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); TatoHyperDB::get_instance("")->startdict_export(src, dest); go_back_to_previous_page(); }
/** * 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(); }
void Articles::show_all() { //TODO in the future would be better if paginated if(tatowiki::Config::isPrivate()) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); } contents::articles::ShowAll c; init_content(c); c.articles = articlesModel->get_all(); render("articles_show_all", c); }
void Articles::remove(const std::string slug) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); const bool success = articlesModel->remove( get_interface_lang(), slug ); if (success) { set_message(_("The article has been removed")); } else { set_message(_("A problem occured while trying to remove")); } go_to_main_page(); }
void Articles::translate(const std::string slug) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); int articleToTranslateId = articlesModel->get_id_from_lang_and_slug( get_interface_lang(), slug ); if (articleToTranslateId == ARTICLE_DOESNT_EXIST_ERROR) { set_message(_("The article you try to translate does not exist.")); go_back_to_previous_page(); return; } contents::articles::Translate c(slug); init_content(c); render("articles_translate", c); }
void Articles::create(std::string slug) { CHECK_PERMISSION_OR_GO_TO_LOGIN(); results::Article article = articlesModel->get_from_lang_and_slug( get_interface_lang(), slug ); // if the article exists there's no need to create it // we display it directly instead if (article.exists()) { //TODO use mapper instead redirect( "/articles/show/" + slug ); return; } contents::articles::Create c(slug); init_content(c); render("articles_create", c); }
/** * 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() ); }
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 ); }
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(); } }
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(); } }