void Media::upload_image_treat() { LOGIN_REQUIRED(); forms::media::UploadImage form; form.load(context()); form.image.load(context()); if (!form.validate()) { if (!form.image.validate()) { add_error(MEDIA_SAVE_INVALID_ERROR_TEXT); } go_back_to_previous_page(); return; } std::string fileURL = uploadsModel->save( form.image.value() ); if (fileURL.empty()) { add_error(MEDIA_SAVE_INTERNAL_ERROR_TEXT); go_back_to_previous_page(); return; } const std::string fileUploaded = (cppcms::locale::format( _("File uploaded successfully. at this address: {1} ") ) % fileURL).str(); add_success(fileUploaded); go_back_to_previous_page(); }
void Pages::change_interface_lang_treat() { forms::InterfaceLang form; form.set_langs(); form.load(context()); if(!form.validate()) { go_back_to_previous_page(); } session()["interfaceLang"] = form.interfaceLang.selected_id(); go_back_to_previous_page(); }
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(); }
void Tokens::external_login_treat() { forms::tokens::ExternalLogin form; form.load(context()); if (!form.validate()) { go_back_to_previous_page(); } }
void Admins::reset_password_treat() { forms::admins::ResetPassword form; form.load(context()); if (!form.validate()) { 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 Words::show_random() { results::Word word = wordModel.get_random_word(); if (word.exists()) { response().set_redirect_header( "/" + get_interface_lang() +"/words/show-in" + "/" + word.text + "/" + word.lang ); } else { // if there's no word in the database // TODO maybe redirect to /words/show // with an error message in session to explain no words exist go_back_to_previous_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::translate(const std::string slug) { LOGIN_REQUIRED(); int articleToTranslateId = articlesModel->get_id_from_lang_and_slug( get_interface_lang(), slug ); if (articleToTranslateId == ARTICLE_DOESNT_EXIST_ERROR) { add_error(_("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::show_conflict(std::string conflictIdStr) { int conflictId = std::stoi(conflictIdStr); contents::articles::ShowConflict c; results::Article article = articlesModel->get_article_from_conflict( conflictId ); if (article.id == 0) { set_message(_( "This conflict does not exists" )); go_back_to_previous_page(); return; } init_content(c); c.markdown = mymarkdown; c.article = article; render("articles_show_conflict", 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(); } }
void Tokens::kick_user() { add_message("kick_user"); go_back_to_previous_page(); }
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(); } }