/**
 * Creates a matrix with 7 columns, one per day of week, and as many rows (weeks) as necessary.
 * Every cell contains a dictionary with the wotd, the definition and other info.
 */
function createCalendar($year, $month)
{
    $days = listDaysOfMonth($year, $month);
    $today = date('Y-m-d');
    $calendar = array();
    // Pad beginning
    $startDow = date('N', strtotime("{$year}-{$month}-01"));
    for ($i = 1; $i < $startDow; $i++) {
        $calendar[] = array();
    }
    // Create a record per day
    foreach ($days as $i => $date) {
        $wotd = WordOfTheDay::get_by_displayDate($date);
        $wotdr = $wotd ? WordOfTheDayRel::get_by_wotdId($wotd->id) : null;
        $def = $wotdr ? Definition::get_by_id($wotdr->refId) : null;
        $visible = $def && ($date <= $today || util_isModerator(PRIV_WOTD));
        $calendar[] = array('wotd' => $wotd, 'def' => $def, 'visible' => $visible, 'dayOfMonth' => $i + 1);
    }
    // Pad end
    while (count($calendar) % 7 != 0) {
        $calendar[] = array();
    }
    // Wrap 7 records per line
    $weeks = array();
    while (count($calendar)) {
        $weeks[] = array_splice($calendar, 0, 7);
    }
    return $weeks;
}
Exemple #2
0
 public static function get_by_id($id)
 {
     if (util_isModerator(PRIV_ADMIN)) {
         return parent::get_by_id($id);
     } else {
         return Model::factory('Definition')->where('id', $id)->where_not_equal('status', self::ST_HIDDEN)->find_one();
     }
 }
Exemple #3
0
 private static function getUnsortedTopData($manual)
 {
     $allowHidden = util_isModerator(PRIV_VIEW_HIDDEN);
     $data = FileCache::getTop($manual, $allowHidden);
     if (!$data) {
         $data = TopEntry::loadUnsortedTopData($manual);
         FileCache::putTop($data, $manual, $allowHidden);
     }
     return $data;
 }
 public static function filterHidden(&$searchResults, &$sources)
 {
     if (!util_isModerator(PRIV_VIEW_HIDDEN)) {
         foreach ($searchResults as $i => &$sr) {
             if ($sr->source->isOfficial == SOURCE_TYPE_HIDDEN || $sr->definition->status == ST_HIDDEN) {
                 $sources[$sr->source->id] = $sr->source;
                 unset($searchResults[$i]);
             }
         }
     }
 }
<?php

require_once "../phplib/util.php";
$submitButton = util_getRequestParameter('submitButton');
if ($submitButton) {
    util_assertModerator(PRIV_ADMIN);
    $order = 1;
    $ids = util_getRequestParameter("ids");
    foreach ($ids as $id) {
        $src = Source::get_by_id($id);
        $src->displayOrder = $order++;
        $src->save();
    }
    FlashMessage::add('Ordinea a fost salvată.', 'info');
    util_redirect('surse');
}
$sources = util_isModerator(PRIV_VIEW_HIDDEN) ? Model::factory('Source')->order_by_asc('displayOrder')->find_many() : Model::factory('Source')->where_not_equal('isOfficial', SOURCE_TYPE_HIDDEN)->order_by_asc('displayOrder')->find_many();
smarty_assign('sources', $sources);
smarty_assign('page_title', 'Surse');
smarty_displayCommonPageWithSkin('surse.ihtml');
Exemple #6
0
<?php

require_once "../phplib/util.php";
$form = util_getRequestParameter('form');
$locVersion = util_getRequestParameter('locVersion');
$locVersions = Config::getLocVersions();
if (!util_isModerator(PRIV_LOC)) {
    $locVersions = array_slice($locVersions, 1);
    // remove the version in progress
}
if ($locVersion && $form) {
    LocVersion::changeDatabase($locVersion);
    $form = StringUtil::cleanupQuery($form);
    $field = StringUtil::hasDiacritics($form) ? 'formNoAccent' : 'formUtf8General';
    $data = Model::factory('InflectedForm')->table_alias('I')->select('I.form', 'inflectedForm')->select('L.formNoAccent', 'lexemFormNoAccent')->select('L.form', 'lexemForm')->select('LM.modelType', 'modelType')->select('LM.modelNumber', 'modelNumber')->select('LM.restriction', 'restriction')->select('Infl.description', 'inflection')->join('LexemModel', 'I.lexemModelId = LM.id', 'LM')->join('Lexem', 'LM.lexemId = L.id', 'L')->join('ModelType', 'LM.modelType = MT.code', 'MT')->join('Model', 'MT.canonical = M.modelType and LM.modelNumber = M.number', 'M')->join('ModelDescription', 'M.id = MD.modelId and I.variant = MD.variant and I.inflectionId = MD.inflectionId', 'MD')->join('Inflection', 'I.inflectionId = Infl.id', 'Infl')->where('MD.applOrder', 0)->where("I.{$field}", $form)->where('LM.isLoc', 1)->where('MD.isLoc', 1)->order_by_asc('LM.lexemId')->find_array();
    SmartyWrap::assign('page_title', 'Verificare LOC: ' . $form);
    SmartyWrap::assign('form', $form);
    SmartyWrap::assign('selectedLocVersion', $locVersion);
    SmartyWrap::assign('data', $data);
} else {
    SmartyWrap::assign('selectedLocVersion', $locVersions[0]->name);
    SmartyWrap::assign('page_title', 'Căutare formă flexionară în LOC ' . $form);
}
SmartyWrap::addJs('modelDropdown');
SmartyWrap::assign('suggestHiddenSearchForm', true);
SmartyWrap::assign('page_title', 'Scrabble');
SmartyWrap::assign('locVersions', $locVersions);
SmartyWrap::display('scrabble.ihtml');
Exemple #7
0
$userData = array();
$user->email = StringUtil::scrambleEmail($user->email);
// Find the rank of this user by number of words and number of characters
$topWords = TopEntry::getTopData(CRIT_WORDS, SORT_DESC, true);
$numUsers = count($topWords);
$rankWords = 0;
while ($rankWords < $numUsers && $topWords[$rankWords]->userNick != $nick) {
    $rankWords++;
}
$userData['rank_words'] = $rankWords + 1;
if ($rankWords < $numUsers) {
    $topEntry = $topWords[$rankWords];
    $userData['last_submission'] = $topEntry->timestamp;
    $userData['num_words'] = $topEntry->numDefinitions;
    $userData['num_chars'] = $topEntry->numChars;
}
$topChars = TopEntry::getTopData(CRIT_CHARS, SORT_DESC, true);
$numUsers = count($topChars);
$rankChars = 0;
while ($rankChars < $numUsers && $topChars[$rankChars]->userNick != $nick) {
    $rankChars++;
}
$userData['rank_chars'] = $rankChars + 1;
SmartyWrap::assign('medals', Medal::loadForUser($user));
if (util_isModerator(PRIV_ADMIN)) {
    // Admins can grant/revoke medals
    SmartyWrap::assign('allMedals', Medal::$DATA);
}
SmartyWrap::assign('user', $user);
SmartyWrap::assign('userData', $userData);
SmartyWrap::display('user.tpl');
Exemple #8
0
$today = date('Y-m-01', time());
// Always use the first of the month
$timestamp = $date ? strtotime($date) : time();
$mysqlDate = date("Y-m-01", $timestamp);
if ($mysqlDate < WOTM_BIG_BANG || $mysqlDate > $today && !util_isModerator(PRIV_ADMIN)) {
    util_redirect(util_getWwwRoot() . 'cuvantul-lunii');
}
$wotm = WordOfTheMonth::getWotM($mysqlDate);
$def = Definition::get_by_id($wotm->definitionId);
if ($type == 'url') {
    SmartyWrap::assign('today', $today);
    SmartyWrap::assign('title', $def->lexicon);
    SmartyWrap::displayWithoutSkin('bits/wotmurl.tpl');
    exit;
}
$searchResults = SearchResult::mapDefinitionArray(array($def));
$cYear = date('Y', $timestamp);
$cMonth = date('n', $timestamp);
$nextTS = mktime(0, 0, 0, $cMonth + 1, 1, $cYear);
$prevTS = mktime(0, 0, 0, $cMonth - 1, 1, $cYear);
if ($mysqlDate > WOTM_BIG_BANG) {
    SmartyWrap::assign('prevmon', date('Y/m', $prevTS));
}
if ($mysqlDate < $today || util_isModerator(PRIV_ADMIN)) {
    SmartyWrap::assign('nextmon', date('Y/m', $nextTS));
}
SmartyWrap::assign('imageUrl', $wotm->getImageUrl());
SmartyWrap::assign('artist', $wotm->getArtist());
SmartyWrap::assign('timestamp', $timestamp);
SmartyWrap::assign('searchResult', array_pop($searchResults));
SmartyWrap::display('wotm.tpl');
// Regular expressions
if ($hasRegexp) {
    $searchType = SEARCH_REGEXP;
    $numResults = Lexem::countRegexpMatches($cuv, $hasDiacritics, $sourceId, true);
    $lexems = Lexem::searchRegexp($cuv, $hasDiacritics, $sourceId, true);
    smarty_assign('numResults', $numResults);
    smarty_assign('lexems', $lexems);
    if (!$numResults) {
        FlashMessage::add("Niciun rezultat pentru {$cuv}.");
    }
}
// Definition.id search
if ($defId) {
    smarty_assign('defId', $defId);
    $searchType = SEARCH_DEF_ID;
    if (util_isModerator(PRIV_VIEW_HIDDEN)) {
        $def = Model::factory('Definition')->where('id', $defId)->where_in('status', array(ST_ACTIVE, ST_HIDDEN))->find_one();
    } else {
        $def = Model::factory('Definition')->where('id', $defId)->where('status', ST_ACTIVE)->find_one();
    }
    $definitions = array();
    if ($def) {
        $definitions[] = $def;
    } else {
        FlashMessage::add("Nu există nicio definiție cu ID-ul {$defId}.");
    }
    $searchResults = SearchResult::mapDefinitionArray($definitions);
    smarty_assign('results', $searchResults);
}
// Normal search
if ($searchType == SEARCH_INFLECTED) {
Exemple #10
0
function util_assertModerator($type)
{
    if (!util_isModerator($type)) {
        FlashMessage::add('Nu aveți privilegii suficiente pentru a accesa această pagină.');
        util_redirect(util_getWwwRoot());
    }
}
 public static function searchLexemId($lexemId, $exclude_unofficial = false)
 {
     $excludeClause = $exclude_unofficial ? "and S.isOfficial <> 0 " : '';
     $statusClause = util_isModerator(PRIV_VIEW_HIDDEN) ? sprintf("and D.status in (%d,%d)", ST_ACTIVE, ST_HIDDEN) : sprintf("and D.status = %d", ST_ACTIVE);
     return Model::factory('Definition')->raw_query("select D.* from Definition D, LexemDefinitionMap L, Source S where D.id = L.definitionId " . "and D.sourceId = S.id and L.lexemId = '{$lexemId}' {$excludeClause} {$statusClause} " . "order by S.isOfficial desc, S.displayOrder, D.lexicon", null)->find_many();
 }
Exemple #12
0
<?php

require_once "../../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$models = FlexModel::loadByType('A');
smarty_assign('recentLinks', RecentLink::loadForUser());
smarty_assign('canEditWotd', util_isModerator(PRIV_WOTD));
smarty_assign("allStatuses", util_getAllStatuses());
smarty_assign("allModeratorSources", Model::factory('Source')->where('canModerate', true)->order_by_asc('displayOrder')->find_many());
smarty_assign('modelTypes', ModelType::loadCanonical());
smarty_assign('models', $models);
smarty_displayWithoutSkin('admin/index.ihtml');
Exemple #13
0
function validate($lexem, $original, $variantIds, $meanings)
{
    if (!$lexem->form) {
        FlashMessage::add('Forma nu poate fi vidă.');
    }
    $numAccents = mb_substr_count($lexem->form, "'");
    // Note: we allow multiple accents for lexems like hárcea-párcea
    if ($numAccents && $lexem->noAccent) {
        FlashMessage::add('Ați indicat că lexemul nu necesită accent, dar forma conține un accent.');
    } else {
        if (!$numAccents && !$lexem->noAccent) {
            FlashMessage::add('Adăugați un accent sau debifați câmpul "Necesită accent".');
        }
    }
    foreach ($lexem->getLexemModels() as $lm) {
        $hasS = false;
        $hasP = false;
        for ($i = 0; $i < mb_strlen($lm->restriction); $i++) {
            $c = StringUtil::getCharAt($lm->restriction, $i);
            if ($c == 'T' || $c == 'U' || $c == 'I') {
                if ($lm->modelType != 'V' && $lm->modelType != 'VT') {
                    FlashMessage::add("Restricția <b>{$c}</b> se aplică numai verbelor");
                }
            } else {
                if ($c == 'S') {
                    if ($lm->modelType == 'I' || $lm->modelType == 'T') {
                        FlashMessage::add("Restricția <b>S</b> nu se aplică modelului {$lm->modelType}");
                    }
                    $hasS = true;
                } else {
                    if ($c == 'P') {
                        if ($lm->modelType == 'I' || $lm->modelType == 'T') {
                            FlashMessage::add("Restricția <b>P</b> nu se aplică modelului {$lm->modelType}");
                        }
                        $hasP = true;
                    } else {
                        FlashMessage::add("Restricția <b>{$c}</b> este incorectă.");
                    }
                }
            }
        }
        if ($hasS && $hasP) {
            FlashMessage::add("Restricțiile <b>S</b> și <b>P</b> nu pot coexista.");
        }
        $ifs = $lm->generateInflectedForms();
        if (!is_array($ifs)) {
            $infl = Inflection::get_by_id($ifs);
            FlashMessage::add(sprintf("Nu pot genera flexiunea '%s' conform modelului %s%s", htmlentities($infl->description), $lm->modelType, $lm->modelNumber));
        }
    }
    $variantOf = Lexem::get_by_id($lexem->variantOfId);
    if ($variantOf && !goodForVariantJson($meanings)) {
        FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși sensuri. " . "Este permis doar un sens, fără conținut, pentru indicarea surselor și a registrelor de folosire.");
    }
    if ($variantOf && !empty($variantIds)) {
        FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși variante.");
    }
    if ($variantOf && $variantOf->id == $lexem->id) {
        FlashMessage::add("Lexemul nu poate fi variantă a lui însuși.");
    }
    foreach ($variantIds as $variantId) {
        $variant = Lexem::get_by_id($variantId);
        if ($variant->id == $lexem->id) {
            FlashMessage::add('Lexemul nu poate fi variantă a lui însuși.');
        }
        if ($variant->variantOfId && $variant->variantOfId != $lexem->id) {
            $other = Lexem::get_by_id($variant->variantOfId);
            FlashMessage::add("\"{$variant}\" este deja marcat ca variantă a lui \"{$other}\".");
        }
        $variantVariantCount = Model::factory('Lexem')->where('variantOfId', $variant->id)->count();
        if ($variantVariantCount) {
            FlashMessage::add("\"{$variant}\" are deja propriile lui variante.");
        }
        $variantMeanings = Model::factory('Meaning')->where('lexemId', $variant->id)->find_many();
        if (!goodForVariant($variantMeanings)) {
            FlashMessage::add("\"{$variant}\" are deja propriile lui sensuri.");
        }
    }
    if ($lexem->structStatus == Lexem::STRUCT_STATUS_DONE && $original->structStatus != Lexem::STRUCT_STATUS_DONE && !util_isModerator(PRIV_EDIT)) {
        FlashMessage::add("Doar moderatorii pot marca structurarea drept terminată. Vă rugăm să folosiți valoarea „așteaptă moderarea”.");
    }
    return FlashMessage::getMessage() == null;
}
// 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);
    smarty_assign('searchResults', $searchResults);
}
$models = FlexModel::loadByType($lexem->modelType);
$sources = LexemSources::getSourceArrayChecked($lexem->source);
$sourceNames = LexemSources::getNamesOfSources($lexem->source);
$canEditForm = !$lexem->isLoc || util_isModerator(PRIV_LOC);
smarty_assign('lexem', $lexem);
smarty_assign('sources', $sources);
smarty_assign('sourceNames', $sourceNames);
smarty_assign('searchResults', $searchResults);
smarty_assign('definitionLexem', $definitionLexem);
smarty_assign('homonyms', Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many());
smarty_assign('suggestedLexems', loadSuggestions($lexem, 5));
smarty_assign('restrS', FlexStringUtil::contains($lexem->restriction, 'S'));
smarty_assign('restrP', FlexStringUtil::contains($lexem->restriction, 'P'));
smarty_assign('restrU', FlexStringUtil::contains($lexem->restriction, 'U'));
smarty_assign('restrI', FlexStringUtil::contains($lexem->restriction, 'I'));
smarty_assign('restrT', FlexStringUtil::contains($lexem->restriction, 'T'));
smarty_assign('modelTypes', Model::factory('ModelType')->order_by_asc('code')->find_many());
smarty_assign('models', $models);
smarty_assign('canEditForm', $canEditForm);
/**
 * Logic that tells us whether it's ok to use the memcached server.
 * We don't want it for moderators because they are the ones who can alter the results and we want them to see the changes right away.
 */
function mc_shouldUse()
{
    return pref_getServerPreference('memcache') && !util_isModerator(PRIV_EDIT);
}
Exemple #16
0
/**
 * Logic that tells us whether it's ok to use the memcached server.
 * We don't want it for moderators because they are the ones who can alter the results and we want them to see the changes right away.
 */
function mc_shouldUse()
{
    return Config::get('global.memcache') && !util_isModerator(PRIV_EDIT);
}