Example #1
0
/**
 * 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;
}
 public static function associate($lexemId, $definitionId)
 {
     // The definition and the lexem should exist
     $definition = Definition::get_by_id($definitionId);
     $lexem = Lexem::get_by_id($lexemId);
     if (!$definition || !$lexem) {
         return;
     }
     // The association itself should not exist.
     $ldm = Model::factory('LexemDefinitionMap')->where('lexemId', $lexemId)->where('definitionId', $definitionId)->find_one();
     if (!$ldm) {
         $ldm = LexemDefinitionMap::create($lexemId, $definitionId);
         $ldm->save();
     }
 }
Example #3
0
 public static function searchMultipleWords($words, $hasDiacritics, $sourceId, $exclude_unofficial)
 {
     $defCounts = array();
     foreach ($words as $word) {
         $lexems = Lexem::searchInflectedForms($word, $hasDiacritics);
         if (count($lexems)) {
             $definitions = self::loadForLexems($lexems, $sourceId, $word, $exclude_unofficial);
             foreach ($definitions as $def) {
                 $defCounts[$def->id] = array_key_exists($def->id, $defCounts) ? $defCounts[$def->id] + 1 : 1;
             }
         }
     }
     arsort($defCounts);
     $result = array();
     foreach ($defCounts as $defId => $cnt) {
         if ($cnt >= 2) {
             $d = Definition::get_by_id($defId);
             if ($d) {
                 // Hidden definitions might return null
                 $result[] = $d;
             }
         }
     }
     return $result;
 }
<?php

require_once "../phplib/util.php";
$dbResult = db_execute("select id from Definition where sourceId = 33 and status = 0 order by id", PDO::FETCH_ASSOC);
$i = 0;
$modified = 0;
$ambiguousDefinitions = 0;
$ambiguities = 0;
foreach ($dbResult as $row) {
    $def = Definition::get_by_id($row['id']);
    $ambiguousMatches = array();
    // Remove existing hash signs
    $newRep = str_replace('#', '', $def->internalRep);
    $newRep = AdminStringUtil::internalizeDefinition($newRep, $def->sourceId, $ambiguousMatches);
    if (count($ambiguousMatches) || $newRep !== $def->internalRep) {
        print "{$def->id} {$newRep}\n";
    }
    if ($newRep !== $def->internalRep) {
        $modified++;
        $def->internalRep = $newRep;
        $def->htmlRep = AdminStringUtil::htmlize($newRep, $def->sourceId);
    }
    if (count($ambiguousMatches)) {
        $def->abbrevReview = ABBREV_AMBIGUOUS;
        $ambiguousDefinitions++;
        $ambiguities += count($ambiguousMatches);
        print "  AMBIGUOUS:";
        foreach ($ambiguousMatches as $match) {
            print " [{$match['abbrev']}]@{$match['position']}";
        }
        print "\n";
Example #5
0
<?php

require_once "../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$id = util_getRequestIntParameter('id');
$def = Definition::get_by_id($id);
$recordSet = db_execute("SELECT old.Version AS OldVersion, new.Version AS NewVersion, old.ModDate AS OldDate, new.ModDate AS NewDate, old.UserId AS OldUserId, new.UserId AS NewUserId, oldUser.nick AS OldUserNick, newUser.nick AS NewUserNick, old.Status AS OldStatus, new.Status AS NewStatus, old.SourceId AS OldSourceId, new.SourceId AS NewSourceId, oldSource.shortName AS OldSourceName, newSource.shortName AS NewSourceName, old.Lexicon AS OldLexicon, new.Lexicon as NewLexicon, old.ModUserId AS OldModUserId, new.ModUserId AS NewModUserId, oldModUser.nick AS OldModUserNick, newModUser.nick AS NewModUserNick, old.InternalRep AS OldInternalRep, new.InternalRep AS NewInternalRep FROM history_Definition AS old LEFT JOIN User AS oldUser ON old.UserId = oldUser.id LEFT JOIN User AS oldModUser ON old.ModUserId = oldModUser.id LEFT JOIN Source AS oldSource ON old.SourceId = oldSource.id, history_Definition AS new LEFT JOIN User AS newUser ON new.UserId = newUser.id LEFT JOIN User AS newModUser ON new.ModUserId = newModUser.id LEFT JOIN Source AS newSource ON new.SourceId = newSource.id WHERE old.Id = new.Id AND old.Action = new.Action AND new.Version = old.Version + 1 AND old.NewDate = new.ModDate AND old.Action = 'UPDATE' AND old.Id = '{$id}' ORDER BY old.Version DESC");
$changeSets = array();
$diffs = array();
$statuses = Definition::$STATUS_NAMES;
foreach ($recordSet as $row) {
    $changeSet = $row;
    $changeSet['changesCount'] = 0;
    if ($row['OldUserId'] !== $row['NewUserId']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldSourceId'] !== $row['NewSourceId']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldStatus'] !== $row['NewStatus']) {
        $changeSet['OldStatusName'] = $statuses[$row['OldStatus']];
        $changeSet['NewStatusName'] = $statuses[$row['NewStatus']];
        $changeSet['changesCount']++;
    }
    if ($row['OldLexicon'] !== $row['NewLexicon']) {
        $changeSet['changesCount']++;
    }
    if ($row['OldModUserId'] !== $row['NewModUserId']) {
        $changeSet['changesCount']++;
    }
for ($d = 0; $d <= NUM_DAYS; $d++) {
    $date = date("Y-m-d", strtotime("+{$d} days"));
    // Check that exactly one WotD exists
    $wotds = WordOfTheDay::get_all_by_displayDate($date);
    if (count($wotds) != 1) {
        $messages[$date] = count($wotds) ? sprintf("Există %s cuvinte", count($wotds)) : "Nu există niciun cuvânt";
        continue;
    }
    // Check that it has exactly one WotD rel
    $rels = WordOfTheDayRel::get_all_by_wotdId($wotds[0]->id);
    if (count($rels) != 1) {
        $messages[$date] = count($rels) ? sprintf("Există %s definiții asociate", count($rels)) : "Nu există nicio definiție asociată";
        continue;
    }
    // Check that the definition exists
    $def = Definition::get_by_id($rels[0]->refId);
    if (!$def) {
        $messages[$date] = sprintf("Definiția cu id-ul %s nu există", $rels[0]->refId);
        continue;
    }
    // Check that there is an image
    if (!$wotds[0]->image) {
        $messages[$date] = sprintf("Definiția '%s' nu are o imagine asociată", $def->lexicon);
        continue;
    }
    // Check that the image file exists
    if (!$wotds[0]->imageFileExists()) {
        $messages[$date] = sprintf("Definiția '%s' are imaginea asociată '%s', dar fișierul nu există", $def->lexicon, $wotds[0]->image);
        continue;
    }
    if ($firstProblem == $d) {
            $replacement = StringUtil::isUppercase(StringUtil::getCharAt($orig, 0)) ? AdminStringUtil::capitalize($m['abbrev']) : $m['abbrev'];
            $s = substr_replace($s, "#{$replacement}#", $m['position'], $m['length']);
        }
    }
    $def->internalRep = $s;
    $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId);
    $def->abbrevReview = ABBREV_REVIEW_COMPLETE;
    $def->save();
}
$MARKER = 'DEADBEEF';
// any string that won't occur naturally in a definition
$def = null;
$ids = db_getArray(sprintf('select id from Definition where status != %d and abbrevReview = %d', ST_DELETED, ABBREV_AMBIGUOUS));
if (count($ids)) {
    $defId = $ids[array_rand($ids, 1)];
    $def = Definition::get_by_id($defId);
    // Collect the positions of ambiguous abbreviations
    $matches = array();
    AdminStringUtil::markAbbreviations($def->internalRep, $def->sourceId, $matches);
    usort($matches, 'positionCmp');
    // Inject our marker around each ambiguity and htmlize the definition
    $s = $def->internalRep;
    foreach ($matches as $m) {
        $s = substr($s, 0, $m['position']) . " {$MARKER} " . substr($s, $m['position'], $m['length']) . " {$MARKER} " . substr($s, $m['position'] + $m['length']);
    }
    $s = AdminStringUtil::htmlize($s, $def->sourceId);
    // Split the definition into n ambiguities and n+1 bits of text between the ambiguities
    $text = array();
    $ambiguities = array();
    while (($p = strpos($s, $MARKER)) !== false) {
        $chunk = trim(substr($s, 0, $p));
Example #8
0
<?php

define('WOTM_BIG_BANG', '2012-04-01');
require_once "../phplib/util.php";
$date = util_getRequestParameter('d');
$type = util_getRequestParameter('t');
$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));
Example #9
0
    $searchType = SEARCH_FULL_TEXT;
    if (Lock::exists(LOCK_FULL_TEXT_INDEX)) {
        smarty_assign('lockExists', true);
        $definitions = array();
    } else {
        $words = preg_split('/ +/', $cuv);
        list($properWords, $stopWords) = StringUtil::separateStopWords($words, $hasDiacritics);
        smarty_assign('stopWords', $stopWords);
        $defIds = Definition::searchFullText($properWords, $hasDiacritics);
        smarty_assign('numResults', count($defIds));
        // Show at most 50 definitions;
        $defIds = array_slice($defIds, 0, 500);
        // Load definitions in the given order
        $definitions = array();
        foreach ($defIds as $id) {
            if ($res = Definition::get_by_id($id)) {
                $definitions[] = $res;
            }
        }
        if (!count($defIds)) {
            FlashMessage::add('Nicio definiție nu conține toate cuvintele căutate.');
        }
    }
    $searchResults = SearchResult::mapDefinitionArray($definitions);
}
// LexemId search
if ($lexemId) {
    // We don't really use $cuv here
    $searchType = SEARCH_LEXEM_ID;
    smarty_assign('lexemId', $lexemId);
    if (!StringUtil::validateAlphabet($lexemId, '0123456789')) {
Example #10
0
<?php

require_once "../../phplib/util.php";
util_assertModerator(PRIV_WOTD);
$month = util_getRequestParameter('month');
$year = util_getRequestParameter('year');
$month = sprintf("%02d", $month);
$wotds = Model::factory('WordOfTheDay')->where_like('displayDate', "{$year}-{$month}-%")->order_by_asc('displayDate')->find_many();
$wotdSet = array();
foreach ($wotds as $wotd) {
    $wotdr = WordOfTheDayRel::get_by_wotdId($wotd->id);
    $def = Definition::get_by_id($wotdr->refId);
    $wotdSet[] = array('wotd' => $wotd, 'def' => $def);
}
SmartyWrap::assign('month', $month);
SmartyWrap::assign('year', $year);
SmartyWrap::assign('recentLinks', RecentLink::loadForUser());
SmartyWrap::assign('wotdSet', $wotdSet);
SmartyWrap::displayAdminPage('admin/wotdExport.tpl');
<?php

require_once "../../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$defId = util_getRequestParameter('defId');
$similarId = util_getRequestParameter('similarId');
$dstart = util_getRequestParameter('dstart');
$dlen = util_getRequestParameter('dlen');
$sstart = util_getRequestParameter('sstart');
$slen = util_getRequestParameter('slen');
$ins = util_getRequestParameter('ins');
$def = Definition::get_by_id($defId);
$similar = Definition::get_by_id($similarId);
if ($ins) {
    $from = $def;
    $to = $similar;
    $fstart = $dstart;
    $flen = $dlen;
    $tstart = $sstart;
    $tlen = $slen;
} else {
    $from = $similar;
    $to = $def;
    $fstart = $sstart;
    $flen = $slen;
    $tstart = $dstart;
    $tlen = $dlen;
}
// copy text from $from to $to
$mid = substr($from->internalRep, $fstart, $flen);
Example #12
0
<?php

/* Htmlizes the definition and comment, then builds the SimilarRecord */
require_once "../../phplib/util.php";
util_assertModerator(PRIV_EDIT);
util_assertNotMirror();
$definitionId = util_getRequestParameter('definitionId');
$definitionInternalRep = util_getRequestParameter('definitionInternalRep');
$commentInternalRep = util_getRequestParameter('commentInternalRep');
$sourceId = util_getRequestParameter('sourceId');
$lexemIds = util_getRequestCsv('lexemIds');
$d = Definition::get_by_id($definitionId);
$d->internalRep = AdminStringUtil::internalizeDefinition($definitionInternalRep, $sourceId);
$d->htmlRep = AdminStringUtil::htmlize($d->internalRep, $sourceId);
$d->sourceId = $sourceId;
$commentInternalRep = AdminStringUtil::internalizeDefinition($commentInternalRep, $sourceId);
$commentHtmlRep = AdminStringUtil::htmlize($commentInternalRep, $sourceId);
$sim = SimilarRecord::create($d, $lexemIds);
$data = $sim->getJsonFriendly();
$data['htmlRep'] = $d->htmlRep;
$data['commentHtmlRep'] = $commentHtmlRep;
print json_encode($data);
$definitionId = util_getRequestIntParameter('definitionId');
$lexemNames = util_getRequestParameter('lexemName');
$associateLexemId = util_getRequestParameter('associateLexemId');
$sourceId = util_getRequestIntParameter('source');
$internalRep = util_getRequestParameter('internalRep');
$status = util_getRequestIntParameterWithDefault('status', null);
$commentContents = util_getRequestParameter('commentContents');
$preserveCommentUser = util_getRequestParameter('preserveCommentUser');
$refreshButton = util_getRequestParameter('but_refresh');
$acceptButton = util_getRequestParameter('but_accept');
$moveButton = util_getRequestParameter('but_move');
$hasErrors = false;
if (!$definitionId) {
    return;
}
if (!($definition = Definition::get_by_id($definitionId))) {
    return;
}
$comment = Model::factory('Comment')->where('definitionId', $definitionId)->where('status', ST_ACTIVE)->find_one();
$commentUser = $comment ? User::get_by_id($comment->userId) : null;
$oldInternalRep = $definition->internalRep;
if ($associateLexemId) {
    LexemDefinitionMap::associate($associateLexemId, $definitionId);
    util_redirect("definitionEdit.php?definitionId={$definitionId}");
}
if ($internalRep) {
    $errors = array();
    $definition->internalRep = AdminStringUtil::internalizeDefinition($internalRep, $sourceId);
    $definition->htmlRep = AdminStringUtil::htmlize($definition->internalRep, $sourceId, $errors);
    if (!empty($errors)) {
        $hasErrors = true;