<?php
// piCalのプラグイン管理でのオプションは今のところ意味なしです。
//$options = explode('|', $plugin['options']);

require_once realpath(dirname(__FILE__)) . '/functions.php';
require_once realpath(dirname(__FILE__)) . '/../class/links_Base.class.php';


switch($pluginTerm) {
	case 'daily':
		$range_start = mktime(0, 0, 0, $this->month, $this->date - 1, $this->year);
		$range_end   = mktime(0, 0, 0, $this->month, $this->date + 2, $this->year);
		break;
	case 'weekly':
		$wtop_date = $this->date - ($this->day - $this->week_start + 7) % 7;
		$range_start = mktime(0, 0, 0, $this->month, $wtop_date - 1, $this->year);
		$range_end   = mktime(0, 0, 0, $this->month, $wtop_date + 8, $this->year);
		break;
	case 'monthly':
	default:
		$range_start = mktime(0, 0, 0, $this->month, 0, $this->year);
		$range_end   = mktime(0, 0, 0, $this->month + 1, 1, $this->year);
		break;
}


$links = links_Base::getInstance($mydirname);
$links->clearWhere();
$links->setWhere('l.status', 0, '>');
$links->setWhere('l.date', $range_start, '>=');
$links->setWhere('l.date', $range_end, '<');
$links_data_arr = $links->getDatas();

foreach ($links_data_arr as $data) {
	$user_time = $data['date'] + $tzoffset_s2u;
	if (date('n', $user_time) != $this->month) continue;
	$target_date = date('j', $user_time);

	$tmp_array = array(
			'dotgif'      => $plugin['dotgif'],
			'dirname'     => $plugin['dirname'],
			'link'        => $links->makeUrl('index', 'item', array('lid' => $data['lid'])),
			'id'          => $data['lid'],
			'server_time' => $data['date'],
			'user_time'   => $user_time,
			'name'        => 'lid',
			'title'       => $data['title'],
		);

	if ($just1gif) {
		// Display just 1 gif per a day and per a plugin
		$plugin_returns[$target_date][$plugin['dirname']] = $tmp_array;
	} else {
		// multiple gifs
		$plugin_returns[$target_date][] = $tmp_array;
	}
}

