Exemple #1
0
function session_logout()
{
    log_userLog('Logging out, IP=' . $_SERVER['REMOTE_ADDR']);
    $cookieString = session_getCookieSetting('lll');
    $cookie = Cookie::get_by_cookieString($cookieString);
    if ($cookie) {
        $cookie->delete();
    }
    setcookie("prefs[lll]", NULL, time() - 3600, '/');
    unset($_COOKIE['prefs']['lll']);
    session_kill();
    util_redirect(util_getWwwRoot());
}
        foreach ($lexemNames as $lexemName) {
            $lexemName = addslashes(AdminStringUtil::formatLexem($lexemName));
            if ($lexemName) {
                $matches = Lexem::loadByExtendedName($lexemName);
                if (count($matches) >= 1) {
                    foreach ($matches as $match) {
                        LexemDefinitionMap::associate($match->id, $definition->id);
                        log_userLog("Associating with lexem {$match->id} ({$match->form})");
                    }
                } else {
                    // Create a new lexem.
                    $lexem = Lexem::create($lexemName, 'T', '1', '');
                    $lexem->save();
                    $lexem->regenerateParadigm();
                    LexemDefinitionMap::associate($lexem->id, $definition->id);
                    log_userLog("Created lexem {$lexem->id} ({$lexem->form})");
                }
            }
        }
        FlashMessage::add('Definiția a fost trimisă. Un moderator o va examina în scurt timp. Vă mulțumim!', 'info');
        util_redirect('contribuie');
    }
} else {
    smarty_assign('sourceId', session_getDefaultContribSourceId());
}
smarty_assign('contribSources', Model::factory('Source')->where('canContribute', true)->order_by_asc('displayOrder')->find_many());
smarty_assign('page_title', 'Contribuie cu definiții');
smarty_assign('suggestNoBanner', true);
smarty_displayCommonPageWithSkin('contribuie.ihtml');
/**************************************************************************/
function deleteEmptyElements(&$v)
Exemple #3
0
<?php

require_once "../../phplib/util.php";
$definitionId = util_getRequestParameter('definitionId');
$response = array();
$userId = session_getUserId();
if (!$userId) {
    $response['status'] = 'redirect';
    $response['url'] = 'login';
    echo json_encode($response);
    exit;
}
$bookmarks = UserWordBookmarkDisplayObject::getByUser($userId);
if (count($bookmarks) < Config::get('global.maxBookmarks')) {
    $existing = Model::factory('UserWordBookmark')->where('userId', $userId)->where('definitionId', $definitionId)->find_one();
    if (!$existing) {
        $bookmark = Model::factory('UserWordBookmark')->create();
        $bookmark->userId = $userId;
        $bookmark->definitionId = $definitionId;
        $bookmark->save();
        log_userLog("Added to favorites: {$bookmark->id} - the definition with the id {$bookmark->definitionId} for user {$bookmark->userId}");
    }
    $response['status'] = 'success';
} else {
    $response['status'] = 'error';
    $response['msg'] = 'Ați depășit limita de cuvinte favorite. Limita este ' . Config::get('global.maxBookmarks') . ' cuvinte favorite.';
}
echo json_encode($response);
Exemple #4
0
<?php

require_once "../../phplib/util.php";
$definitionId = util_getRequestParameter('definitionId');
$response = array();
$userId = session_getUserId();
if (!$userId) {
    $response['status'] = 'redirect';
    $response['url'] = 'login';
    echo json_encode($response);
    exit;
}
$bookmark = Model::factory('UserWordBookmark')->where('userId', $userId)->where('definitionId', $definitionId)->find_one();
if ($bookmark) {
    log_userLog("Removed from favorites: {$bookmark->id} - the definition with the id {$bookmark->definitionId} of user: {$bookmark->userId}");
    $bookmark->delete();
}
$response['status'] = 'success';
echo json_encode($response);
        $definition->lexicon = AdminStringUtil::extractLexicon($definition);
        $definition->abbrevReview = count($ambiguousMatches) ? ABBREV_AMBIGUOUS : ABBREV_REVIEW_COMPLETE;
        $definition->save();
        log_userLog("Added definition {$definition->id} ({$definition->lexicon})");
        foreach ($lexemIds as $lexemId) {
            $lexemId = addslashes(AdminStringUtil::formatLexem($lexemId));
            if (StringUtil::startsWith($lexemId, '@')) {
                // create a new lexem
                $lexem = Lexem::deepCreate(substr($lexemId, 1), 'T', '1');
                $lexem->deepSave();
                LexemDefinitionMap::associate($lexem->id, $definition->id);
                log_userLog("Created lexem {$lexem->id} ({$lexem->form})");
            } else {
                $lexem = Lexem::get_by_id($lexemId);
                LexemDefinitionMap::associate($lexem->id, $definition->id);
                log_userLog("Associating with lexem {$lexem->id} ({$lexem->form})");
            }
        }
        FlashMessage::add('Definiția a fost trimisă. Un moderator o va examina în scurt timp. Vă mulțumim!', 'info');
        util_redirect('contribuie');
    }
} else {
    SmartyWrap::assign('sourceId', session_getDefaultContribSourceId());
}
SmartyWrap::assign('lexemIds', $lexemIds);
SmartyWrap::assign('contribSources', Model::factory('Source')->where('canContribute', true)->order_by_asc('displayOrder')->find_many());
SmartyWrap::assign('page_title', 'Contribuie cu definiții');
SmartyWrap::assign('suggestNoBanner', true);
SmartyWrap::addCss('jqueryui', 'select2');
SmartyWrap::addJs('jqueryui', 'select2', 'select2Dev');
SmartyWrap::display('contribuie.ihtml');
Exemple #6
0
function handleLexemActions()
{
    $lexemId = util_getRequestParameter('lexemId');
    $lexem = Lexem::get_by_id($lexemId);
    $associateDefinitionId = util_getRequestParameter('associateDefinitionId');
    if ($associateDefinitionId) {
        LexemDefinitionMap::associate($lexem->id, $associateDefinitionId);
        util_redirect("lexemEdit.php?lexemId={$lexem->id}");
    }
    $dissociateDefinitionId = util_getRequestParameter('dissociateDefinitionId');
    if ($dissociateDefinitionId) {
        LexemDefinitionMap::dissociate($lexem->id, $dissociateDefinitionId);
        util_redirect("lexemEdit.php?lexemId={$lexem->id}");
    }
    $createDefinition = util_getRequestParameter('createDefinition');
    $miniDefTarget = util_getRequestParameter('miniDefTarget');
    if ($createDefinition) {
        $def = Model::factory('Definition')->create();
        $def->userId = session_getUserId();
        $def->sourceId = Source::get_by_shortName('Neoficial')->id;
        $def->lexicon = $lexem->formNoAccent;
        $def->internalRep = '@' . mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)) . '@ v. @' . $miniDefTarget . '.@';
        $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId);
        $def->status = Definition::ST_ACTIVE;
        $def->save();
        LexemDefinitionMap::associate($lexem->id, $def->id);
        util_redirect("lexemEdit.php?lexemId={$lexem->id}");
    }
    $deleteLexem = util_getRequestParameter('deleteLexem');
    if ($deleteLexem) {
        $homonyms = Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many();
        $lexem->delete();
        SmartyWrap::assign('lexem', $lexem);
        SmartyWrap::assign('homonyms', $homonyms);
        SmartyWrap::displayAdminPage('admin/lexemDeleted.tpl');
        exit;
    }
    $cloneLexem = util_getRequestParameter('cloneLexem');
    if ($cloneLexem) {
        $newLexem = $lexem->cloneLexem();
        log_userLog("Cloned lexem {$lexem->id} ({$lexem->form}), new id is {$newLexem->id}");
        util_redirect("lexemEdit.php?lexemId={$newLexem->id}");
    }
    $mergeLexem = util_getRequestParameter('mergeLexem');
    $mergeLexemId = util_getRequestParameter('mergeLexemId');
    if ($mergeLexem) {
        $other = Lexem::get_by_id($mergeLexemId);
        if ($lexem->form != $other->form) {
            FlashMessage::add('Nu pot unifica lexemele deoarece accentele diferă. Rezolvați diferența și încercați din nou.');
            util_redirect("lexemEdit.php?lexemId={$lexem->id}");
        }
        $defs = Definition::loadByLexemId($lexem->id);
        foreach ($defs as $def) {
            LexemDefinitionMap::associate($other->id, $def->id);
        }
        // Add lexem models from $lexem to $other if the form is the same. Exclude T-type models.
        $displayOrder = count($other->getLexemModels());
        foreach ($lexem->getLexemModels() as $lm) {
            if ($lm->modelType != 'T' && !$other->hasModel($lm->modelType, $lm->modelNumber)) {
                $lm->lexemId = $other->id;
                $lm->displayOrder = ++$displayOrder;
                $lm->save();
            }
        }
        // Add meanings from $lexem to $other and renumber their displayOrder and breadcrumb
        // displayOrders are generated sequentially regardless of level.
        // Breadcrumbs follow levels so only their first part changes.
        $counter = Model::factory('Meaning')->where('lexemId', $other->id)->count();
        $numRoots = Model::factory('Meaning')->where('lexemId', $other->id)->where('parentId', 0)->count();
        $meanings = Model::factory('Meaning')->where('lexemId', $lexem->id)->order_by_asc('displayOrder')->find_many();
        foreach ($meanings as $m) {
            $m->lexemId = $other->id;
            $m->displayOrder = ++$counter;
            $parts = explode('.', $m->breadcrumb, 2);
            $parts[0] += $numRoots;
            $m->breadcrumb = implode('.', $parts);
            $m->save();
        }
        // Add images and image tags from $lexem to $other
        $visuals = Visual::get_all_by_lexemeId($lexem->id);
        foreach ($visuals as $v) {
            $v->lexemeId = $other->id;
            $v->save();
        }
        $visualTags = VisualTag::get_all_by_lexemeId($lexem->id);
        foreach ($visualTags as $vt) {
            $vt->lexemeId = $other->id;
            $vt->save();
        }
        $lexem->delete();
        util_redirect("lexemEdit.php?lexemId={$other->id}");
    }
}
}
if (!$errorMessage) {
    $errorMessage = validateRestriction($lexem->modelType, $lexem->restriction);
}
if ($updateLexem && !$errorMessage) {
    if ($oldModelType == 'VT' && $lexem->modelType != 'VT') {
        $lexem->deleteParticiple($oldModelNumber);
    }
    if (($oldModelType == 'VT' || $oldModelType == 'V') && ($lexem->modelType != 'VT' && $lexem->modelType != 'V')) {
        $lexem->deleteLongInfinitive();
    }
    $lexem->save();
    // There are two reasons to regenerate the paradigm: the model has changed
    // or the form has changed. It's easier to do it every time.
    $lexem->regenerateParadigm();
    log_userLog("Edited lexem {$lexem->id} ({$lexem->form})");
    util_redirect("lexemEdit.php?lexemId={$lexem->id}");
}
$definitions = Definition::loadByLexemId($lexem->id);
$searchResults = SearchResult::mapDefinitionArray($definitions);
$definitionLexem = mb_strtoupper(AdminStringUtil::internalize($lexem->form, false));
// Generate new inflected forms, but do not overwrite the old ones.
$ifs = $lexem->generateParadigm();
if (!is_array($ifs)) {
    $infl = Inflection::get_by_id($ifs);
    if (!$errorMessage) {
        $errorMessage = "Nu pot genera flexiunea '" . htmlentities($infl->description) . "' " . "conform modelului {$lexem->modelType}{$lexem->modelNumber}.";
    }
} else {
    $ifMap = InflectedForm::mapByInflectionRank($ifs);
    smarty_assign('ifMap', $ifMap);
        $ldms = LexemDefinitionMap::get_all_by_definitionId($def->id);
        db_execute("delete from LexemDefinitionMap where definitionId = {$definition->id}");
        foreach ($ldms as $ldm) {
            $l = Lexem::get_by_id($ldm->lexemId);
            $otherLdms = LexemDefinitionMap::get_all_by_lexemId($l->id);
            if (!$l->isLoc && !count($otherLdms)) {
                $l->delete();
            }
        }
    } else {
        db_execute("delete from LexemDefinitionMap where definitionId = {$definitionId}");
        foreach ($ldms as $ldm) {
            $ldm->save();
        }
    }
    log_userLog("Edited definition {$definition->id} ({$definition->lexicon})");
    util_redirect('definitionEdit.php?definitionId=' . $definitionId);
}
$source = Source::get_by_id($definition->sourceId);
if (!$refreshButton && !$acceptButton && !$moveButton) {
    // If a button was pressed, then this is a POST request and the URL
    // does not contain the definition ID.
    RecentLink::createOrUpdate(sprintf("Definiție: %s (%s)", $definition->lexicon, $source->shortName));
}
smarty_assign('def', $definition);
smarty_assign('source', $source);
smarty_assign('user', User::get_by_id($definition->userId));
smarty_assign('comment', $comment);
smarty_assign('commentUser', $commentUser);
smarty_assign('lexems', $lexems);
smarty_assign('typos', Typo::get_all_by_definitionId($definition->id));
util_assertNotLoggedIn();
$submitButton = util_getRequestParameter('submitButton');
$identity = util_getRequestParameter('identity');
$email = util_getRequestParameter('email');
SmartyWrap::assign('identity', $identity);
SmartyWrap::assign('email', $email);
SmartyWrap::assign('page_title', 'Parolă uitată');
SmartyWrap::assign('suggestHiddenSearchForm', true);
if ($submitButton) {
    if (!$email) {
        FlashMessage::add('Trebuie să introduceți o adresă de e-mail.');
        SmartyWrap::display('auth/parola-uitata.ihtml');
    } else {
        $user = User::get_by_email($email);
        if ($user) {
            log_userLog("Password recovery requested for {$email} from " . $_SERVER['REMOTE_ADDR']);
            // Create the token
            $pt = Model::factory('PasswordToken')->create();
            $pt->userId = $user->id;
            $pt->token = util_randomCapitalLetterString(20);
            $pt->save();
            // Send email
            SmartyWrap::assign('homePage', util_getFullServerUrl());
            SmartyWrap::assign('token', $pt->token);
            $body = SmartyWrap::fetch('email/resetPassword.ihtml');
            $ourEmail = Config::get('global.contact');
            $headers = array("From: DEX online <{$ourEmail}>", "Reply-To: {$ourEmail}", 'Content-Type: text/plain; charset=UTF-8');
            $result = mail($email, "Schimbarea parolei pentru DEX online", $body, implode("\r\n", $headers));
        }
        // Display a confirmation even for incorrect addresses.
        SmartyWrap::display('auth/passwordRecoveryEmailSent.ihtml');
Exemple #10
0
<?php

require_once "../phplib/util.php";
util_assertModerator(PRIV_WOTD);
util_assertNotMirror();
$defId = util_getRequestParameter('defId');
$status = WordOfTheDay::getStatus($defId);
if (is_null($status)) {
    $wotd = Model::factory('WordOfTheDay')->create();
    $wotd->userId = session_getUserId();
    $wotd->priority = 0;
    $wotd->save();
    $wotdr = Model::factory('WordOfTheDayRel')->create();
    $wotdr->refId = $defId;
    $wotdr->refType = 'Definition';
    $wotdr->wotdId = $wotd->id;
    $wotdr->save();
    log_userLog("Added new word of the day: {$wotd->id} - the definition with the id {$wotdr->refId}");
}
$where_to_go = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/';
header("Location: {$where_to_go}");