static function getByDate($displayDate, $wotm = false) { $creditsFile = $wotm ? self::CREDITS_FILE_WOTM : self::CREDITS_FILE_WOTD; $lines = @file(util_getRootPath() . $creditsFile); if (!$lines) { return null; } foreach ($lines as $line) { $commentStart = strpos($line, '#'); if ($commentStart !== false) { $line = substr($line, 0, $commentStart); } $line = trim($line); if ($line) { $parts = explode('::', trim($line)); if (preg_match("/{$parts[0]}/", $displayDate)) { return WotdArtist::get_by_label($parts[1]); } } } return null; }
public function getArtist() { return $this->image ? WotdArtist::getByDate($this->displayDate) : null; }
addError($date, sprintf("Definiția cu id-ul %s nu există", $rels[0]->refId)); continue; } // Check that we haven't had the same word or a similar one in the past. // Currently we look for words that contain, or are contained by, the proposed word. $query = sprintf("select d.lexicon, w.displayDate " . "from WordOfTheDay w, WordOfTheDayRel r, Definition d " . "where w.id = r.wotdId " . "and r.refId = d.id " . "and r.refType = 'Definition' " . "and w.displayDate < '%s' " . "and char_length(lexicon) >= 4 " . "and ((instr('%s', lexicon) > 0) or (lexicon like '%%%s%%'))", $date, $def->lexicon, $def->lexicon); $dups = db_getArrayOfRows($query); if (count($dups)) { $msg = "Cuvântul {$def->lexicon} seamnănă cu următoarele cuvinte deja propuse:"; foreach ($dups as $dup) { $msg .= " {$dup[0]} ({$dup[1]})"; } addInfo($date, $msg); } // Check that there is an artist $artist = WotdArtist::getByDate($date); if (!$artist) { addError($date, 'Niciun artist nu este asignat; verificați conținutul fișierului docs/imageCredits/wotd.desc'); } // Check that there is an image if (!$wotd->image) { $assignedImage = assignImageByName($wotd, $def); if ($assignedImage) { $wotd->image = $assignedImage; $wotd->save(); addInfo($date, "Am asociat definiția '{$def->lexicon}' cu imaginea {$assignedImage}"); } else { addError($date, sprintf("Definiția '%s' nu are o imagine asociată (motivul alegerii: %s)", $def->lexicon, $wotd->description)); if ($artist && !in_array($artist->email, $rcptError)) { $rcptError[] = $artist->email; }
if ($height != $validHeight || $width != $validWidth) { throw new Exception("Imaginea trebuie să aibă dimensiuni {$validWidth} x {$validHeight}."); } $dateMin = date('Y-m-d', strtotime("-{$daysInterval} day")); $dateMax = date('Y-m-d', strtotime("+{$daysInterval} day")); $wotds = Model::factory('WordOfTheDay')->table_alias('wotd')->select('wotd.*')->distinct()->join('WordOfTheDayRel', 'wotd.id = rel.wotdId', 'rel')->join('LexemDefinitionMap', 'rel.refId = ldm.definitionId', 'ldm')->join('Lexem', 'ldm.lexemId = l.id', 'l')->join('LexemModel', 'lm.lexemId = l.id', 'lm')->join('InflectedForm', 'i.lexemModelId = lm.id', 'i')->where('i.formUtf8General', $word)->where_gte('wotd.displayDate', $dateMin)->where_lte('wotd.displayDate', $dateMax)->find_many(); if (!count($wotds)) { throw new Exception(sprintf("Cuvântul '%s' nu apare în intervalul %s - %s.", $word, $dateMin, $dateMax)); } else { if (count($wotds) > 1) { throw new Exception(sprintf("Cuvântul '%s' apare de %d ori în intervalul %s - %s.", $word, count($wotds), $dateMin, $dateMax)); } } $wotd = $wotds[0]; // No exception if no artist is assigned -- that's probably simply an ommission. $artist = WotdArtist::getByDate($wotd->displayDate); if ($artist && $artist->email != $from) { throw new Exception("Cuvântul '{$word}' îi este alocat altui artist."); } $today = date('Y-m-d'); if ($wotd->image && $wotd->displayDate < $today) { throw new Exception("Cuvântul zilei '{$word}' are deja o imagine ataşată. Nu puteți modifica imaginile cuvintelor din trecut."); } $wotdDisplayDate = new DateTime($wotd->displayDate); $wotd->image = sprintf("%s/%s.%s", $wotdDisplayDate->format('Y-m'), $word, $imageExtension); $wotd->save(); $wotdImagePath = '/img/wotd/' . $wotd->image; $f = new FtpUtil(); $f->staticServerPut($tmpFilePath, $wotdImagePath); unlink($tmpFilePath); ReplyToEmail($sender, $subject, "Am adăugat imaginea pentru '{$word}'.");