Esempio n. 1
0
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);
}
Esempio n. 2
0
/**
 * 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"
    );
}
Esempio n. 3
0
void Pages::homepage() {
    contents::pages::Homepage c;
    init_content(c);


    render("homepage", c);
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
/**
 * 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);
}
Esempio n. 6
0
/**
 * 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);
}
Esempio n. 7
0
void Tokens::check_token() {

    contents::tokens::CheckToken c;
    init_content(c);


    render("tokens_check_token", c);
}
Esempio n. 8
0
void Admins::reset_password() {

    contents::admins::ResetPassword c;
    init_content(c);


    render("admins_reset_password", c);
}
Esempio n. 9
0
void Tokens::external_login() {

    contents::tokens::ExternalLogin c;
    init_content(c);


    render("tokens_external_login", c);
}
Esempio n. 10
0
void Media::list_all() {

    contents::media::ListAll c(
        uploadsModel->list(MEDIA_FILES_BY_PAGE)
    );
    init_content(c);

    render("media_list_all", c);
}
Esempio n. 11
0
void Media::upload_image() {

    LOGIN_REQUIRED();

    contents::media::UploadImage c;
    init_content(c);


    render("media_upload_image", c);
}
Esempio n. 12
0
void Pages::homepage() {
    contents::pages::Homepage c;
    init_content(c);

    models::Posts postsModel;

    c.markdown = mymarkdown;
    c.posts = postsModel.get_all();

    render("homepage", c);
}
Esempio n. 13
0
void Words::show(std::string str) {

	contents::WordsShow c;
	contents::WordsHelper whc;
    init_content(c);
    c.wordStr = str;
    whc.lang = c.lang;

    whc.words = wordModel.get_words_with_str(str);
    c.whc = whc;
    render ("words_show", c);
}
Esempio n. 14
0
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);
}
Esempio n. 15
0
void Articles::show_all() {
    //TODO in the future would be better if paginated
    
    if(tatowiki::Config::isPrivate()) {
        LOGIN_REQUIRED();
    }


    contents::articles::ShowAll c;
    init_content(c);

    c.articles = articlesModel->get_all();

    render("articles_show_all", c);
}
Esempio n. 16
0
void Words::show_in(std::string wordStr, std::string wordLang) {

	contents::WordsShow c;
    init_content(c);
    c.wordStr = wordStr;
    c.wordLang = wordLang;

	contents::WordsHelper whc(
        wordModel.get_word_with_lang_str(wordLang, wordStr)
    );
    whc.lang = c.lang;

    c.whc = whc;
    render ("words_show", c);
}
Esempio n. 17
0
void Words::show_all(std::string offsetStr, std::string sizeStr) {
    unsigned int size = atoi(sizeStr.c_str());
    unsigned int offset = atoi(offsetStr.c_str()) - 1;

	contents::Words c;
	contents::WordsHelper whc;
    init_content(c);

    whc.baseUrl = "/words/show-all";
    whc.lang = c.lang;
    whc.words = wordModel.get_all_words(offset, size);

    c.whc = whc;
    c.paginationSize = size;
    render ("words_show_all", c);
}
Esempio n. 18
0
void Words::show_all_in(std::string filterLang, std::string offsetStr, std::string sizeStr) {
    unsigned int size = atoi(sizeStr.c_str());
    unsigned int offset = atoi(offsetStr.c_str()) - 1;

	contents::WordsAllIn c;
	contents::WordsHelper whc;
    init_content(c);
    c.filterLang = filterLang;

    whc.baseUrl = "/words/show-all-in/" + filterLang;
    whc.lang = c.lang;
    whc.words = wordModel.get_all_words_in_lang(filterLang, offset, size);

    c.whc = whc;
    c.paginationSize = size;
    render ("words_show_all_in", c);
}
Esempio n. 19
0
void Searches::simple () {
    std::string fromLang = "und";
    std::string toLang = "und";
    std::string query = "";

    unsigned int page = 0;//atoi(sizeStr.c_str());
    if (request().request_method() == "GET") {
        cppcms::http::request::form_type getData = request().get();
        cppcms::http::request::form_type::const_iterator it;
        
        GET_FIELD(fromLang, "from");
        GET_FIELD(toLang, "to");
        GET_FIELD(query, "query");

        GET_INT_FIELD(page, "page");
    }

    

	contents::SearchesShowResult c;
	contents::helpers::Sentences shc;

    init_content(c);

    c.queryStr = query;
    c.queryLang = fromLang;
    c.paginationSize = 10; //TODO MAGIC NUMBER
    shc.currentUserHelper = c.usersHelper;

    std::cout << "[DEBUG]" <<  query <<
        " in " << fromLang <<
        " to " << toLang << std::endl; 

    shc.sentences = searchesModel->advance(
        query,
        fromLang,
        toLang,
        page
    );
    
    c.shc = shc;

    render ("searches_simple_api", c);
}
Esempio n. 20
0
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);
}
Esempio n. 21
0
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);
}
Esempio n. 22
0
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);
}
Esempio n. 23
0
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);
}