Пример #1
0
function addPeriod($period, $inc = 1)
{
    if (checkPeriod($period) !== false) {
        switch (strlen($period)) {
            case 4:
                return strftime('%Y', mktime(0, 0, 0, 1, 1, $period + $inc));
            case 6:
                return strftime('%Y%m', mktime(0, 0, 0, substr($period, 4) + $inc, 1, substr($period, 0, 4)));
            case 8:
                return strftime('%Y%m%d', mktime(0, 0, 0, substr($period, 4, 2), substr($period, 6, 2) + $inc, substr($period, 0, 4)));
        }
    }
    return false;
}
Пример #2
0
function getCalendar($blogid, $period)
{
    global $database;
    $calendar = array('days' => array());
    if ($period === true || !checkPeriod($period)) {
        $period = Timestamp::getYearMonth();
    }
    $calendar['period'] = $period;
    $calendar['year'] = substr($period, 0, 4);
    $calendar['month'] = substr($period, 4, 2);
    $visibility = doesHaveOwnership() ? '' : 'AND e.visibility > 0' . getPrivateCategoryExclusionQuery($blogid);
    switch (POD::dbms()) {
        case 'Cubrid':
            $result = POD::queryAllWithDBCache("SELECT DISTINCT TO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'DD')\n\t\t\t\tFROM {$database['prefix']}Entries e\n\t\t\t\tWHERE e.blogid = {$blogid} AND e.draft = 0 {$visibility} AND e.category >= 0 AND\n\t\t\t\t\tTO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'YYYY') = '{$calendar['year']}' AND\n\t\t\t\t\tTO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'MM') = '{$calendar['month']}'", 'entry');
            break;
        case 'MySQL':
        case 'MySQLi':
        case 'PostgreSQL':
        default:
            $result = POD::queryAllWithDBCache("SELECT DISTINCT DAYOFMONTH(FROM_UNIXTIME(e.published)) \n\t\t\t\tFROM {$database['prefix']}Entries e\n\t\t\t\tWHERE e.blogid = {$blogid} AND e.draft = 0 {$visibility} AND e.category >= 0 AND YEAR(FROM_UNIXTIME(e.published)) = {$calendar['year']} AND MONTH(FROM_UNIXTIME(e.published)) = {$calendar['month']}", 'entry');
            break;
    }
    if ($result) {
        foreach ($result as $dayArray) {
            list($day) = $dayArray;
            array_push($calendar['days'], $day);
        }
    }
    $calendar['days'] = array_flip($calendar['days']);
    return $calendar;
}
Пример #3
0
function getCalendar($blogid, $period)
{
    global $database;
    $skinSetting = Setting::getSkinSettings($blogid);
    $pool = DBModel::getInstance();
    $pool->init("Entries");
    $pool->setAlias("Entries", "e");
    $pool->setQualifier("e.blogid", "eq", $blogid);
    $pool->setQualifier("e.draft", "eq", 0);
    $pool->setQualifier("e.category", ">=", 0);
    if (!doesHaveOwnership()) {
        $pool->setQualifier("e.visibility", ">", 0);
        $pool = getPrivateCategoryExclusionQualifier($pool, $blogid);
    }
    $calendar = array('days' => array());
    if ($period === true || !checkPeriod($period)) {
        $period = Timestamp::getYearMonth();
    }
    $calendar['period'] = $period;
    $calendar['year'] = substr($period, 0, 4);
    $calendar['month'] = substr($period, 4, 2);
    switch (POD::dbms()) {
        case 'Cubrid':
            $pool->setQualifier("TO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'YYYY')", "eq", $calendar['year'], true);
            $pool->setQualifier("TO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'MM')", "eq", $calendar['month'], true);
            $result = $pool->getAll("TO_CHAR(to_timestamp('09:00:00 AM 01/01/1970')+e.published, 'DD')", array('filter' => 'distinct', 'usedbcache' => true, 'cacheprefix' => 'entry'));
            break;
        case 'SQLite3':
            $pool->setQualifier("strftime('%Y',e.published,'unixepoch')", "eq", $calendar['year'], true);
            $pool->setQualifier("strftime('%m',e.published,'unixepoch')", "eq", $calendar['month'], true);
            $result = $pool->getAll("strftime('%d',e.published,'unixepoch')", array('filter' => 'distinct', 'usedbcache' => true, 'cacheprefix' => 'entry'));
            break;
        case 'MySQL':
        case 'MySQLi':
        case 'PostgreSQL':
        default:
            $pool->setQualifier("YEAR(FROM_UNIXTIME(e.published))", "eq", $calendar['year'], true);
            $pool->setQualifier("MONTH(FROM_UNIXTIME(e.published))", "eq", $calendar['month'], true);
            $result = $pool->getAll("DAYOFMONTH(FROM_UNIXTIME(e.published))", array('filter' => 'distinct', 'usedbcache' => true, 'cacheprefix' => 'entry'));
            break;
    }
    if ($result) {
        foreach ($result as $dayArray) {
            list($day) = $dayArray;
            array_push($calendar['days'], $day);
        }
    }
    $calendar['days'] = array_flip($calendar['days']);
    return $calendar;
}