#!/usr/bin/php <?php include_once 'inc.common.php'; define('LOCK_FILE', '/tmp/cron_lock'); $cron = new Cron(); ini_set('memory_limit', '1024M'); ini_set('time_limit', '1800'); if ($key = key($_GET)) { $cron->process($key); var_dump(memory_get_peak_usage(true)); exit; } if (file_exists(LOCK_FILE) && filemtime(LOCK_FILE) > time() - 3600) { exit; } $time = Database::unix_to_date(); $tasks = Database::order('id', 'asc')->get_vector('cron', array('function', 'period'), 'last_time < ?', $time); if (empty($tasks)) { exit; } touch(LOCK_FILE); foreach ($tasks as $task => $period) { $cron->process($task); $nexttime = Database::unix_to_date(Transform_Time::parse($period) - 15); Database::update('cron', array('last_time' => $nexttime), 'function = ?', $task); } unlink(LOCK_FILE);
function get_data() { if ($this->template != 'slideshow') { global $url; global $error; global $sets; global $def; if (is_numeric($url[2])) { $return['display'] = array('booru_single', 'comments'); $return['art'] = $this->get_art(1, 'id=' . $url[2] . ' and area != "deleted"'); $url['area'] = $return['art'][0]['area']; $return['comments'] = $this->get_comments($url[1], $url[2], is_numeric($url[5]) ? $url[5] : ($url[4] == 'all' ? false : 1)); $return['navi']['curr'] = $url[4] == 'all' ? 'all' : max(1, $url[5]); $return['navi']['all'] = true; $return['navi']['name'] = "Страница комментариев"; $return['navi']['meta'] = $url[2] . '/comments/'; $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $return['navi']['last'] = ceil($return['comments']['number'] / $sets['pp']['comment_in_post']); $this->side_modules['top'] = array(); $return['art'][0]['rating'] = $this->get_rating($url[2]); $return['art'][0]['packs'] = $this->get_packs($url[2]); $return['art'][0]['pool'] = $this->get_pools($url[2]); } elseif ($url[2] != 'pool' && $url[2] != 'cg_packs' && $url[2] != 'download') { $return['display'] = array('booru_page', 'navi'); if ($url[2] == 'page' || !$url[2]) { $area = 'area = "' . $url['area'] . '"'; $return['navi']['curr'] = max(1, $url[3]); if ($sets['art']['sort'] == 'tag-desc') { $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area, 'order by (length(tag) - length(replace(tag,\'|\',\'\'))) desc'); } elseif ($sets['art']['sort'] == 'tag-asc') { $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area, 'order by (length(tag) - length(replace(tag,\'|\',\'\')))'); } else { $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area); } } elseif ($url[2] == 'date') { $parts = explode('-', $url[3]); if (is_numeric($parts[0] . $parts[1] . $parts[2]) && count($parts) == 3) { $area = 'area = "' . $url['area'] . '" and pretty_date ="' . Transform_Time::ru_month($parts[1]) . ' ' . $parts[2] . ', ' . $parts[0] . '"'; $return['navi']['curr'] = max(1, $url[5]); $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area); $return['navi']['meta'] = $url[2] . '/' . $url[3] . '/'; } else { $error = true; } } elseif ($url[2] != 'mixed') { $this->mixed_parse($url[2] . '=' . $url[3]); $area = 'area = "' . $url['area'] . '" and locate("|' . ($url['tag'] ? $url['tag'] : mysql_real_escape_string($url[3])) . '|",art.' . $url[2] . ')'; $return['navi']['curr'] = max(1, $url[5]); $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area); $return['navi']['meta'] = $url[2] . '/' . $url[3] . '/'; $return['rss'] = $this->make_rss($url[1], $url[2], $url[3]); } else { $area = $this->mixed_make_sql($this->mixed_parse($url[3])); $return['navi']['curr'] = max(1, $url[5]); $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], $area); $return['navi']['meta'] = $url[2] . '/' . $url[3] . '/'; } $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $return['navi']['last'] = ceil(obj::db()->sql('select count(id) from art where (' . $area . ')', 2) / $sets['pp']['art']); } else { if ($url[2] == 'pool') { if (is_numeric($url[3])) { if ($url[4] != 'sort') { $return['display'] = array('booru_poolsingle', 'booru_page', 'navi'); } else { $return['display'] = array('booru_poolsingle', 'booru_page'); } $return['pool'] = Database::get_full_row('art_pool', $url[3]); $query = Database::set_counter()->order('order', 'asc'); if ($url[4] != 'sort') { $return['navi']['curr'] = max(1, $url[5]); $return['navi']['meta'] = $url[2] . '/' . $url[3] . '/'; $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $query->limit(sets::pp('art'), ($return['navi']['curr'] - 1) * sets::pp('art')); } $pool = $query->get_vector('art_in_pool', 'art_id', 'pool_id = ?', $url[3]); $return['pool']['count'] = Database::get_counter(); if ($url[4] != 'sort') { $return['navi']['last'] = ceil($return['pool']['count'] / $sets['pp']['art']); } $where = 'id=' . implode(' or id=', $pool); $pool = array_flip($pool); if ($art = $this->get_art(false, $where, '')) { foreach ($art as $one) { $return['art']['thumbs'][$pool[$one['id']]] = $one; } ksort($return['art']['thumbs']); } $return['rss'] = $this->make_rss($url[1], $url[2], $url[3]); } else { $return['display'] = array('booru_poolpage', 'navi'); $return['navi']['curr'] = max(1, $url[4]); $return['navi']['meta'] = $url[2] . '/'; $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $return['navi']['last'] = ceil(obj::db()->sql('select count(id) from art_pool', 2) / $sets['pp']['art_pool']); $return['pools'] = obj::db()->sql(' select p.id as id, p.name as name, count(*) as count from art_pool as p left join art_in_pool as a on p.id = a.pool_id group by p.id order by p.sortdate desc limit ' . ($return['navi']['curr'] - 1) * $sets['pp']['art_pool'] . ', ' . $sets['pp']['art_pool'], 'id'); } } elseif ($url[2] == 'cg_packs') { $this->side_modules['top'] = array(); if (is_numeric($url[3])) { $return['display'] = array('booru_pack_single', 'booru_page', 'navi'); $return['navi']['curr'] = max(1, $url[5]); $return['navi']['meta'] = $url[2] . '/' . $url[3] . '/'; $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $return['navi']['last'] = ceil(obj::db()->sql('select count(*) from art_in_pack where pack_id=' . $url[3], 2) / $sets['pp']['art']); $return['pool'] = obj::db()->sql('select * from art_pack where id=' . $url[3], 1); $return['art']['thumbs'] = $this->get_art(($return['navi']['curr'] - 1) * $sets['pp']['art'] . ', ' . $sets['pp']['art'], 'p.pack_id=' . $url[3], 'order by p.`order`', 'as a left join art_in_pack as p on a.id = p.art_id'); } else { $return['display'] = array('booru_pack_list', 'navi'); $return['navi']['curr'] = max(1, $url[4]); $return['navi']['meta'] = $url[2] . '/'; $return['navi']['start'] = max($return['navi']['curr'] - 5, 2); $return['navi']['last'] = ceil(obj::db()->sql('select count(*) from art_pack where cover != ""', 2) / $sets['pp']['art_cg_pool']); $return['pools'] = obj::db()->sql('select * from art_pack where cover != "" order by `date` desc limit ' . ($return['navi']['curr'] - 1) * $sets['pp']['art_cg_pool'] . ', ' . $sets['pp']['art_cg_pool'], 'id'); } } else { if ($url[3] == 'pack') { if (empty($url[4]) || !is_numeric($url[4])) { $error = true; } else { if (empty($url[5]) || !is_numeric($url[5])) { $pack = obj::db()->sql("select title, weight from art_pack where id = {$url['4']}", 1); if ($pack['weight'] == 0) { $error = true; } else { $this->template = 'download'; $this->side_modules = array(); $name = str_replace(array(' ', ';'), '_', $pack['title']); $file = ROOT_DIR . SL . 'files' . SL . 'pack_cache' . SL . 'pack_' . $url[4] . '.zip'; return array('file' => $file, 'name' => $name . '.zip'); } } else { $this->template = 'download'; $this->side_modules = array(); $art = obj::db()->sql("\n\t\t\t\t\t\t\t\t\tselect a.md5, a.extension, p.filename\n\t\t\t\t\t\t\t\t\tfrom art as a left join art_in_pack as p on a.id = p.art_id\n\t\t\t\t\t\t\t\t\twhere a.id = {$url['5']} and p.pack_id = {$url['4']}", 1); $file = ROOT_DIR . SL . 'images' . SL . 'booru' . SL . 'full' . SL . $art['md5'] . '.' . $art['extension']; if (pathinfo($file, PATHINFO_EXTENSION) == 'jpg') { $type = 'jpeg'; } else { $type = pathinfo($file, PATHINFO_EXTENSION); } return array('file' => $file, 'name' => $art['filename'], 'type' => $type); } } } else { $this->template = 'download'; $this->side_modules = array(); if (pathinfo($url[3], PATHINFO_EXTENSION) == 'jpg') { $type = 'jpeg'; } else { $type = pathinfo($url[3], PATHINFO_EXTENSION); } return array('file' => ROOT_DIR . SL . 'images' . SL . 'booru' . SL . 'full' . SL . $url[3], 'name' => $url[3], 'type' => $type); } } } $return['navi']['base'] = '/art' . ($url['area'] != $def['area'][0] ? '/' . $url['area'] : '') . '/'; return $return; } }
<li> <?php echo $daykey; ?> числа: добавлено <a href="<?php echo $def['site']['dir']; ?> /<?php echo $url[2]; ?> /date/<?php echo $yearkey; ?> -<?php echo Transform_Time::ru_month($monthkey); ?> -<?php echo $daykey; ?> /"> <?php echo $day; ?> артов. </a> </li> <? } ?> </ul>
function get_data() { global $url; if ($url[2] == 'search') { $page = empty($url[5]) ? 1 : $url[5]; return $this->search($url[3], $page); } $return['display'] = array('logs_navi', 'logs_search', 'logs_body', 'logs_arrows'); if (!$this->nocache) { $return['logs'] = base64_decode(obj::db()->sql('select cache from logs where (year=' . $url[2] . ' and month =' . $url[3] . ' and day=' . $url[4] . ' and cache_key =' . static::$cache_key . ')', 2, 'cache')); } if (!$return['logs']) { $today = mktime(0, 0, 0, $url[3], $url[4], $url[2]) * 1000; $rooms = 'roomID = ' . implode(' or roomID = ', static::$room_ids); $return['logs'] = obj::db('chat')->sql('select nickname, logTime, body from ofMucConversationLog where ((' . $rooms . ') and cast(logTime as unsigned) > ' . $today . ' and cast(logTime as unsigned) < ' . ($today + 86400000) . ') order by logTime'); if (is_array($return['logs'])) { foreach ($return['logs'] as $key => &$log) { if (trim($log['body'])) { $log['text'] = $this->format_logs($log['body'], $log['nickname']); } else { unset($return['logs'][$key]); } } } } if (!$return['logs']) { $return['nologs'] = 'За этот день нет ни одного лога.'; } $start = array($this->start_year, $this->start_month, $this->start_day); $end = array(date("Y"), date("n"), date("j")); $current = array($url[2], $url[3], $url[4]); $base = substr(get_called_class(), 8); if (array_diff_assoc($end, $current) && is_array($return['logs'])) { $this->make_logs_cache($return['logs'], $url[2], $url[3], $url[4]); } $rumonth = array('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'); for ($i = $start[0]; $i <= $end[0]; $i++) { $start_month = $i == $start[0] ? $start[1] : 1; $end_month = $i == $end[0] ? $end[1] : 12; for ($j = $start_month; $j <= $end_month; $j++) { $return['month'][$i == $current[0] && $j == $current[1] ? 'current' : '/' . $base . '/' . $i . '/' . $j . '/' . ($j > $start[1] ? 1 : $start[2]) . '/'] = $rumonth[$j - 1] . ' ' . $i; } } $return['log_base'] = $base; $yesterday = mktime(12, 0, 0, $url[3], $url[4] - 1, $url[2]); $tomorrow = mktime(12, 0, 0, $url[3], $url[4] + 1, $url[2]); $start_time = mktime(0, 0, 0, $start[1], $start[2], $start[0]); if ($yesterday > $start_time) { $return['navi']['yesterday'] = array('url' => '/' . $base . '/' . date("Y", $yesterday) . '/' . date("n", $yesterday) . '/' . date("j", $yesterday) . '/', 'name' => $rumonth[date("n", $yesterday) - 1] . ' ' . date("j", $yesterday)); } elseif ($yesterday < mktime(0, 0, 0, $start[1], $start[2] - 1, $start[0])) { $return['nologs'] = "Логов раньше, чем за " . Transform_Time::to_string($start_time) . " попросту нет, комната появилась в тот день."; engine::error_headers(); } $return['navi']['today'] = array('name' => $rumonth[$url[3] - 1] . ' ' . $url[4]); if ($tomorrow < mktime(24, 0, 0, $end[1], $end[2], $end[0])) { $return['navi']['tomorrow'] = array('url' => '/' . $base . '/' . date("Y", $tomorrow) . '/' . date("n", $tomorrow) . '/' . date("j", $tomorrow) . '/', 'name' => $rumonth[date("n", $tomorrow) - 1] . ' ' . date("j", $tomorrow)); } elseif ($tomorrow > mktime(24, 0, 0, $end[1], $end[2] + 1, $end[0])) { $return['nologs'] = "Забегаем в будущее?"; engine::error_headers(); } return $return; }
protected function build_url_array() { $time = strtotime($this->get('lastcheck')); return array('url' => $this->get('url'), 'alias' => $this->get('alias'), 'status' => $this->get('status'), 'check' => Transform_Time::rudate($time, true), 'lastcheck' => $this->get('lastcheck')); }