year;
$month = $this->month;
if (($year < 2014) && ($year > date("Y"))) {
$year = date("Y");
}
if (($this->month < 1) && ($this->month > 12)) {
$month = date("n");
} else if (mktime(0, 0, 0, $month, 1, $year) > $time) {
$month = date("n");
}
$this->year = array();
$this->month = array();
for ($i = 2014; $i <= date("Y"); $i++) {
if ($i == $year) {
$this->year_list[] = $i . "年";
} else {
$this->year_list[] = '' . $i . '年';
}
}
$max_month = 1;
for ($i = 1; $i <= 12; $i++) {
if (mktime(0, 0, 0, $i, 1, $year) > $time) {
break;
}
$_check = $this->_get_gallery($year, $i);
if (count($_check) > 0) {
$max_month = $i;
if ($i == $month) {
$this->month_list[] = $i . "月";
} else {
$this->month_list[] = '' . $i . '月';
}
}
}
//if ($month == date("n") && $max_month != $month) {
// // 当月のギャラリーがない場合、最大月のギャラリー表示
// $month = $max_month;
//}
$this->gallery = $this->_get_gallery($year, $month);
$this->year = $year;
$this->month = $month;
return $this->render('gallery/option');
}
// ---------------------------------------------
// ギャラリー取得
// ---------------------------------------------
function _get_gallery($year, $month) {
$start = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
$end = date('Y-m-d', mktime(0, 0, 0, $month + 1, 1, $year));
$param = array($start, $end);
$sql = "SELECT * FROM main_gallery WHERE ";
$sql .= "switch IS TRUE AND publish_date >= ? AND publish_date < ? AND publish_date <= NOW() AND type in (4,5,6) ORDER BY publish_date DESC;";
$gallery = $this->db->getAll($sql, $param);
foreach ($gallery as $key => $val) {
$gallery[$key]['main'] = 0;
$gallery[$key]['sub1'] = 0;
$gallery[$key]['sub2'] = 0;
$gallery[$key]['message'] = 0;
if ($this->_rk_file_exists(RK_SSL . MAIN_GALLERY_IMAGE_PATH . $val['photo'], MAIN_GALLERY_IMAGE_FULL_PATH . $val['photo'])) {
$gallery[$key]['main'] = 1;
}
//if ($this->_rk_file_exists(RK_SSL . MAIN_GALLERY_IMAGE_PATH . 'sub1_' . $val['photo'], MAIN_GALLERY_IMAGE_FULL_PATH . 'sub1_' . $val['photo'])) {
// $gallery[$key]['sub1'] = 1;
//}
//if ($this->_rk_file_exists(RK_SSL . MAIN_GALLERY_IMAGE_PATH . 'sub2_' . $val['photo'], MAIN_GALLERY_IMAGE_FULL_PATH . 'sub2_' . $val['photo'])) {
// $gallery[$key]['sub2'] = 1;
//}
if ($this->_rk_file_exists(RK_SSL . MAIN_GALLERY_IMAGE_PATH . 'message_' . $val['photo'], MAIN_GALLERY_IMAGE_FULL_PATH . 'message_' . $val['photo'])) {
$gallery[$key]['message'] = 1;
}
}
return $gallery;
}
function _rk_file_exists($image_url, $local_path) {
if (file_exists($local_path)) {
return true;
} else {
$file_headers = @$this->_get_headers_curl($image_url);
if (strpos($file_headers[0], '200')) {
$img = file_get_contents($image_url, FILE_BINARY);
if (file_put_contents($local_path, $img) !== false) {
return true;
}
}
}
return false;
}
function _get_headers_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
$r = curl_exec($ch);
$r = explode("\n", $r);
return $r;
}
// ---------------------------------------------
// 最新ギャラリー取得
// ---------------------------------------------
function _get_new_gallery() {
$param = array();
$sql = "SELECT max(publish_date) FROM main_gallery WHERE ";
$sql .= "switch IS TRUE AND publish_date <= NOW() AND type in (4,5,6);";
$gallery = $this->db->getRow($sql, $param);
$new_publish_date = date('Y-n-d');
if (!empty($gallery)) {
$new_publish_date = $gallery['max'];
}
return $new_publish_date;
}
/*----------------------------------------------------------
設定フィルター
----------------------------------------------------------*/
function defaultSetBeforeFilter () {
parent::defaultSetBeforeFilter();
if (empty($this->year) && empty($this->month)) {
$new_publish_date = $this->_get_new_gallery();
$this->year = date("Y", strtotime($new_publish_date));
$this->month = date("n", strtotime($new_publish_date));
} else {
if (empty($this->year)) {
$this->year = date("Y");
}
if (empty($this->month)) {
$this->month = date("n");
}
}
}
}
$controller = new GalleryController();
$controller->process();
exit;