Ejemplo n.º 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;
}
Ejemplo n.º 2
0
function createCalendar($year, $month)
{
    $days = listDaysOfMonth($year, $month);
    $today = date('Y-m-d');
    $words = WordOfTheDay::getArchiveWotD($year, $month);
    $inv = array();
    foreach ($words as $k => $v) {
        $inv[$v->displayDate] = $k;
    }
    $new_words = array();
    foreach ($days as $day) {
        if ($day <= $today && array_key_exists($day, $inv)) {
            $new_words[] = $words[$inv[$day]];
        } else {
            $new_words[] = WotDArchive::setOnlyDate($day);
        }
    }
    return $new_words;
}
Ejemplo n.º 3
0
});
$wordCount = Definition::getWordCount();
$wordCountRough = $wordCount - $wordCount % 10000;
SmartyWrap::assign('page_title', 'Dicționar explicativ al limbii române');
SmartyWrap::assign('onHomePage', '1');
SmartyWrap::assign('letters', preg_split('//u', 'aăâbcdefghiîjklmnopqrsștțuvwxyz'));
SmartyWrap::assign('words_total', util_formatNumber($wordCount, 0));
SmartyWrap::assign('words_rough', util_formatNumber($wordCountRough, 0));
SmartyWrap::assign('words_last_month', util_formatNumber(Definition::getWordCountLastMonth(), 0));
SmartyWrap::assign('widgets', $widgets);
SmartyWrap::assign('numEnabledWidgets', $numEnabledWidgets);
/* WotD part */
$wotd = WordOfTheDay::getTodaysWord();
if (!$wotd) {
    WordOfTheDay::updateTodaysWord();
    $wotd = WordOfTheDay::getTodaysWord();
}
$defId = WordOfTheDayRel::getRefId($wotd->id);
$def = Model::factory('Definition')->where('id', $defId)->where('status', ST_ACTIVE)->find_one();
SmartyWrap::assign('thumbUrl', $wotd->getThumbUrl());
SmartyWrap::assign('title', $def->lexicon);
SmartyWrap::assign('today', date('Y/m/d'));
/* WotM part */
$wotm = WordOfTheMonth::getCurrentWotM();
$def = Model::factory('Definition')->where('id', $wotm->definitionId)->where('status', ST_ACTIVE)->find_one();
SmartyWrap::assign('thumbUrlM', $wotm->getThumbUrl());
SmartyWrap::assign('articol', $wotm->article);
SmartyWrap::assign('titleM', $def->lexicon);
SmartyWrap::assign('todayM', date('Y/m'));
$page = Config::get('global.aprilFoolsDay') ? 'index-afd.ihtml' : 'index.ihtml';
SmartyWrap::displayPageWithSkin($page);
Ejemplo n.º 4
0
<?php

require_once '../phplib/util.php';
print "\n\nAcest script nu a fost testat după conversia AdoDB -> Idiorm.\n";
print "El este corect d.p.d.v. sintactic, dar atât.\n";
print "Ștergeți aceste linii și asigurați-vă că scriptul face ceea ce trebuie.\n\n\n";
exit(1);
$list = array_slice($argv, 1);
$userId = 471;
foreach ($list as $defId) {
    $status = WordOfTheDay::getStatus($defId);
    // if defId is not already in the list, add it
    if (is_null($status)) {
        $wotd = Model::factory('WordOfTheDay')->create();
        $wotd->userId = $userId;
        $wotd->priority = 0;
        $wotd->save();
        $wotdr = Model::factory('WordOfTheDayRel')->create();
        $wotdr->refId = $defId;
        $wotdr->refType = 'Definition';
        $wotdr->wotdId = $wotd->id;
        $wotdr->save();
    }
}
Ejemplo n.º 5
0
                break;
            default:
                print "Unknown flag {$arg} -- ignored\n";
                exit;
        }
    }
}
if (!$sendEmail) {
    print "---- DRY RUN ----\n";
}
$messages = array();
$firstProblem = 0;
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;
Ejemplo n.º 6
0
 public static function init()
 {
     self::$DEFAULT_IMAGE = "generic.jpg";
     self::$IMAGE_CREDITS_DIR = util_getRootPath() . 'docs/imageCredits';
 }
Ejemplo n.º 7
0
$today = date('Y-m-d', time());
$timestamp = $date ? strtotime($date) : time();
$mysqlDate = date("Y-m-d", $timestamp);
if ($mysqlDate < WOTD_BIG_BANG || $mysqlDate > $today) {
    util_redirect(util_getWwwRoot() . 'cuvantul-zilei');
}
$wotd = WordOfTheDay::get_by_displayDate($mysqlDate);
if (!$wotd) {
    // We shouldn't have missing words since the Big Bang.
    if ($mysqlDate != $today) {
        util_redirect(util_getWwwRoot() . 'cuvantul-zilei');
    }
    WordOfTheDay::updateTodaysWord();
    $wotd = WordOfTheDay::get_by_displayDate($mysqlDate);
}
$archive = WordOfTheDay::getArchiveWotD(date('Y', $timestamp), date('m', $timestamp));
$defId = WordOfTheDayRel::getRefId($wotd->id);
$def = Definition::get_by_id($defId);
$searchResults = SearchResult::mapDefinitionArray(array($def));
setlocale(LC_ALL, 'ro_RO');
$roDate = strftime("%e %B %Y", $timestamp);
$pageTitle = sprintf("Cuvântul zilei: %s (%s)", $def->lexicon, $roDate);
if ($mysqlDate > WOTD_BIG_BANG) {
    smarty_assign('prevday', date('Y/m/d', $timestamp - 86400));
}
if ($mysqlDate < $today) {
    smarty_assign('nextday', date('Y/m/d', $timestamp + 86400));
}
smarty_assign('imageUrl', $wotd->getImageUrl());
smarty_assign('timestamp', $timestamp);
smarty_assign('archive', $archive);
Ejemplo n.º 8
0
<?php

require_once "../phplib/util.php";
define('NO_OF_WOTD_IN_LIST', 4);
$year = util_getRequestIntParameterWithDefault('y', date('Y'));
$month = util_getRequestIntParameterWithDefault('m', date('m'));
$day = util_getRequestIntParameterWithDefault('d', date('d'));
$timestamp = mktime(0, 0, 0, $month, $day, $year);
$prevWotds = WordOfTheDay::getPreviousYearsWotds($month, $day);
$wotds = [];
foreach ($prevWotds as $w) {
    $currentYear = substr($w->displayDate, 0, 4);
    if (count($wotds) >= NO_OF_WOTD_IN_LIST) {
        break;
    }
    if ($currentYear != $year) {
        $defId = WordOfTheDayRel::getRefId($w->id);
        $def = Model::factory('Definition')->where('id', $defId)->where('status', Definition::ST_ACTIVE)->find_one();
        $entry = [];
        $entry['year'] = $currentYear;
        $entry['href'] = "/cuvantul-zilei/{$currentYear}/{$month}/{$day}";
        $entry['img'] = $w->getThumbUrl();
        $entry['word'] = $def->lexicon;
        $entry['tip'] = $w->description;
        $wotds[] = $entry;
    }
}
SmartyWrap::assign('timestamp', $timestamp);
SmartyWrap::assign('wotds', $wotds);
SmartyWrap::displayWithoutSkin('bits/wotdPreviousYears.tpl');
Ejemplo n.º 9
0
    exit;
}
$today = date('Y-m-d', time());
$timestamp = $date ? strtotime($date) : time();
$mysqlDate = date("Y-m-d", $timestamp);
if ($mysqlDate < WOTD_BIG_BANG || $mysqlDate > $today && !util_isModerator(PRIV_ADMIN)) {
    util_redirect(util_getWwwRoot() . 'cuvantul-zilei');
}
$wotd = WordOfTheDay::get_by_displayDate($mysqlDate);
if (!$wotd) {
    // We shouldn't have missing words since the Big Bang.
    if ($mysqlDate != $today) {
        util_redirect(util_getWwwRoot() . 'cuvantul-zilei');
    }
    WordOfTheDay::updateTodaysWord();
    $wotd = WordOfTheDay::get_by_displayDate($mysqlDate);
}
$reason = '';
if ($wotd) {
    $reason = $wotd->description;
    if (util_isModerator(PRIV_ADMIN) || $mysqlDate >= WOTD_REASON_BIG_BANG && $date && strtotime($date) < time() - WOTD_REASON_DISPLAY_DELAY * ONE_DAY_IN_SECS) {
        SmartyWrap::assign('reason', $reason);
    }
}
$defId = WordOfTheDayRel::getRefId($wotd->id);
$def = Definition::get_by_id($defId);
if ($type == 'url') {
    SmartyWrap::assign('today', $today);
    SmartyWrap::assign('title', $def->lexicon);
    SmartyWrap::displayWithoutSkin('bits/wotdurl.ihtml');
    exit;
Ejemplo n.º 10
0
 /**
  * Deletes a row from the wotd table
  * @access protected
  * @return string
  * */
 protected function doDelete()
 {
     $wotd = WordOfTheDay::get_by_id($this->id);
     $wotd->delete();
     $wotdr = WordOfTheDayRel::get_by_wotdId($this->id);
     $wotdr->delete();
     return '';
 }
Ejemplo n.º 11
0
<?php

WordOfTheDay::$IMAGE_DIR = util_getRootPath() . "wwwbase/img/wotd";
WordOfTheDay::$THUMB_DIR = util_getRootPath() . "wwwbase/img/wotd/thumb";
WordOfTheDay::$THUMB_SIZE = 48;
class WordOfTheDay extends BaseObject
{
    public static $_table = 'WordOfTheDay';
    public static $IMAGE_DIR;
    public static $THUMB_DIR;
    public static $THUMB_SIZE;
    public static function getRSSWotD()
    {
        return Model::factory('WordOfTheDay')->where_gt('displayDate', '2011-01-01')->where_raw('displayDate < NOW()')->order_by_desc('displayDate')->limit(25)->find_many();
    }
    public static function getArchiveWotD($year, $month)
    {
        $query = "SELECT displayDate, lexicon, replace(displayDate, '-', '/') linkDate, DAYOFWEEK(displayDate) dayOfWeek, DAYOFMONTH(displayDate) dayOfMonth \n        FROM WordOfTheDay W\n        JOIN WordOfTheDayRel R ON W.id=R.wotdId\n        JOIN Definition D ON R.refId=D.id AND D.status=0 AND R.refType='Definition'\n        WHERE MONTH(displayDate)={$month} AND YEAR(displayDate)={$year}\n        ORDER BY displayDate";
        //TODO
        $dbRes = db_execute($query);
        $results = array();
        foreach ($dbRes as $row) {
            $wotda = new WotDArchive();
            $wotda->set($row);
            $results[] = $wotda;
        }
        return $results;
    }
    public static function getTodaysWord()
    {
        return Model::factory('WordOfTheDay')->where_raw('displayDate = curdate()')->find_one();
Ejemplo n.º 12
0
 /**
  * Deletes a row from the wotd table
  * @access protected
  * @return error string (empty for success)
  * */
 protected function doDelete()
 {
     $wotd = WordOfTheDay::get_by_id($this->id);
     if ($wotd) {
         $wotd->delete();
         return '';
     } else {
         return "Înregistrarea de șters nu a fost găsită (id={$this->id})";
     }
 }