getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } getRequestUri())); } /** 旧 appLoginBlock → redirectMyPage → Friend 取得 → 足あと。戻り値は Friend か、リダイレクト */ private function entry(Request $request, string $pu, bool $login = false) { if ($login && ! S::me()) { return $this->loginRedirect($request); } $pk = S::dec($pu); $me = S::me(); if ($me && $pk === (int) $me->pk_user) { $uri = $request->getRequestUri(); if (preg_match('~/record/day/(\d{8})_[^/]*\.html~', $uri, $dm)) { return redirect('/note/my/record/day/' . $dm[1] . '.html'); } if (preg_match('~/top_[^/]*\.html~', $uri)) { return redirect('/note/my/index.html'); } return redirect(preg_replace('~/note/some/~', '/note/my/', $uri, 1)); } $friend = S::friend($pk); if (! $friend) { return redirect('/note/some/error.html'); } S::footprint($request, $friend); return $friend; } /** 左カラム (旧 my-left.inc.php) のデータ */ private function base(object $friend, string $pu): array { return [ 'friend' => $friend, 'pu' => $pu, 'images' => S::images((int) $friend->pk_user), 'circles' => S::circles((int) $friend->pk_user, 4), 'circleTotal' => S::circleCount((int) $friend->pk_user), ]; } private function viewFor(string $view, object $friend, string $pu, array $data = []) { return view($view, $this->base($friend, $pu) + $data); } private function offset(Request $request): int { return max(0, (int) $request->query('n', 0)); } // ---------------------------------------------------------------- top public function top(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor('note.some.top', $f, $pu, [ 'ni' => S::kirokuOpen($pk), 'diaries' => S::recentDiaries($f), 'imgDiaries' => S::imageDiaries($f), 'reviews' => S::reviews($pk), 'reviewCount' => S::reviewCount($pk), ]); } // ---------------------------------------------------------------- record/day (日記の個別ページ) public function day(Request $request, string $ymd, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $ni = D::diary($f, $ymd); if (! $ni) { return redirect('/note/some/diary/error.html'); } $mealOpen = D::mealOpen($pk); $f->meal_open = $mealOpen; return $this->viewFor('note.some.day', $f, $pu, [ 'ni' => $ni, 'kiroku' => D::kiroku($pk, $ni->date), 'meal' => ['open' => $mealOpen], 'meals' => ($mealOpen !== '1' && (string) $ni->menu_obj === '1') ? D::meals($pk, $ni->date, (int) $ni->nid) : [], 'comments' => D::comments($pk, $ni->date), 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/list (記録ノート一覧) /** record/list/{pu}.html (直近 1 か月) と record/list/{ym}_{pu}.html (その月) */ public function recordList(Request $request, string $pu) { return $this->recordListPage($request, $pu, null); } public function recordListMonth(Request $request, string $ym, string $pu) { return $this->recordListPage($request, $pu, $ym); } private function recordListPage(Request $request, string $pu, ?string $ym) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $y = null; $m = null; if ($ym !== null) { $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { $y = $m = null; } } $pk = (int) $f->pk_user; return $this->viewFor('note.some.record_list', $f, $pu, [ 'list' => D::listDiaries($f, $y, $m), 'y' => $y, 'm' => $m, 'mm' => $ym !== null && $m ? substr($ym, 4, 2) : null, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk), ]); } // ---------------------------------------------------------------- record/new, tag, month, category /** 記録ノート系ページ共通: 会員の確認と左カラムのデータ */ private function recordBase(Request $request, string $pu, string $view, \Closure $data) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; return $this->viewFor($view, $f, $pu, $data($f, $pk) + ['newDiaries' => D::newDiaries($f), 'tags' => D::tags($pk)]); } public function recordNew(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_new', fn ($f, $pk) => ['list' => D::newestDiaries($f)]); } public function recordTag(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_tag', fn ($f, $pk) => ['tagList' => D::tagList($pk)]); } public function recordMonth(Request $request, string $pu) { return $this->recordBase($request, $pu, 'note.some.record_month', fn ($f, $pk) => ['months' => D::monthCounts($f)]); } public function recordCategory(Request $request, string $tag, string $pu) { $n = $this->offset($request); return $this->recordBase($request, $pu, 'note.some.record_category', function ($f, $pk) use ($tag, $n) { [$rows, $count] = D::tagDiaries($f, $tag, $n); return ['tag' => $tag, 'rows' => $rows, 'count' => $count, 'n' => $n]; }); } /** record/gallery/{pu}/index.html: 記録ノートの写真ギャラリー */ public function recordGallery(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); [$rows, $count] = D::gallery($f, $n); return $this->viewFor('note.some.record_gallery', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- kiroku (記録グラフの人気ランキング・記録項目の紹介) /** kiroku/index.html */ public function kirokuIndex(Request $request) { $q = trim((string) $request->query('q', '')); $o = (string) $request->query('o', '1') === '2' ? 2 : 1; $n = $this->offset($request); $me = S::me(); [$rows, $count] = K::ranking($q, $o, $n, $me ? (int) $me->pk_user : null); return view('note.some.kiroku_index', [ 'rows' => $rows, 'count' => $count, 'q' => $q, 'o' => $o, 'n' => $n, 'me' => $me, 'pager' => S::pages($count, $n, K::PER_PAGE, S::qs($request)), ]); } /** kiroku/{kid}.html (と taiju.html など) */ public function kirokuFormat(Request $request, string $kid) { $kid = (int) (['taiju' => 1, 'walk' => 202, 'fukin' => 204, 'ketuatu' => 207, 'sleep' => 211, 'cal' => 213][$kid] ?? $kid); $kiroku = K::master($kid); if (! $kiroku) { return redirect('/note/some/error.html'); } $n = $this->offset($request); [$mem, $count] = K::members($kid, $n); $me = S::me(); return view('note.some.kiroku_format', [ 'kiroku' => $kiroku, 'kid' => $kid, 'mem' => $mem, 'count' => $count, 'me' => $me, 'isSet' => K::isSet($me ? (int) $me->pk_user : null, $kid), 'pager' => S::pages($count, $n, K::MEMBERS_PER_PAGE, S::qs($request)), ]); } // ---------------------------------------------------------------- log/trace (足あと) /** log/trace_{pu}.html */ public function logTrace(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } return $this->viewFor('note.some.log_trace', $f, $pu, ['list' => S::footprints((int) $f->pk_user)]); } /** log/del_{pu}_{aid}.html (POST): 自分が付けた足あとを消す */ public function logDel(Request $request, string $pu, string $aid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } if ($request->isMethod('post')) { S::deleteFootprint(S::dec($pu), (int) $aid, (string) $request->input('ymd', ''), (int) $me->pk_user); } return redirect('/note/some/log/trace_' . $pu . '.html'); } // ---------------------------------------------------------------- start (記録の始め方) /** start/{name}.html: その記録項目を始めよう */ public function startBase(Request $request, string $name) { $map = ['taiju' => 1, 'hone' => 2, 'taisibo' => 199, 'run' => 200, 'tabako' => 201, 'walk' => 202, 'kiso' => 203, 'fukin' => 204, 'skwat' => 205, 'taion' => 206, 'ketuatu' => 207, 'kettoti' => 208, 'manpokei' => 209, 'sleep' => 211, 'syohi' => 212, 'calory' => 213]; if (! isset($map[$name])) { return redirect('/note/some/error.html'); } $r = K::startPage($map[$name]); if (! $r) { return redirect('/note/some/error.html'); } [$kiroku, $mem, $count, $cir] = $r; $me = S::me(); return view('note.some.start_base', [ 'kiroku' => $kiroku, 'kid' => $map[$name], 'mem' => $mem, 'count' => $count, 'cir' => $cir, 'me' => $me, 'goUrl' => ! $me ? '/toroku/toroku.html' : ((string) $me->note_flg === '1' ? '/note/my/index.html' : '/note/first.html'), ]); } // ---------------------------------------------------------------- review (レシピ・レビュー一覧) /** review/{pu}/index.html */ public function reviewIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $rk = (int) $request->query('rk', 0); [$rows, $count] = S::reviewPage((int) $f->pk_user, $rk, $n); return $this->viewFor('note.some.review_index', $f, $pu, [ 'rows' => $rows, 'count' => $count, 'rk' => $rk, 'pager' => S::pages($count, $n, 20, S::qs($request)), ]); } // ---------------------------------------------------------------- record/keyword (人気タグランキング) /** record/keyword.html */ public function recordKeyword(Request $request) { $me = S::me(); $n = $this->offset($request); [$rows, $count] = D::popularTags($me ? $me->user_id : null, $n, 100); [$top] = D::popularTags($me ? $me->user_id : null, 0, 20); return view('note.some.record_keyword', [ 'rows' => $rows, 'count' => $count, 'n' => $n, 'top' => $top, ]); } // ---------------------------------------------------------------- meal/cal/{pu}/{ym}.html (食事レポート: カロリー推移) /** meal/cal と meal/balance の共通部分。戻り値は配列かリダイレクト */ private function mealBase(Request $request, string $pu, ?string $ym, string $page) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; if ($ym === null) { return redirect('/note/some/meal/cal/' . $pu . '/' . (M::latestYm($pk) ?: S::now()->format('Ym')) . '.html'); } $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); if ($m < 1 || $m > 12 || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $month = M::month($pk, $y, $m); $ana = []; foreach ($eiyou as $c => $e) { $ana[$c] = M::analyzeOne($set, $c, $month['avg'][$c]); } $advice = null; if ($month['cnt'] > 0) { $advice = [ 'avg' => $month['avg'][$col], 'min' => $set->{$col . '_min'}, 'max' => $set->{$col . '_max'}, 'text' => MealReportData::ADVICE[$col . '_' . $ana[$col]['jud']] ?? '', ]; } return [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'month' => $month, 'ana' => $ana, 'advice' => $advice, 'page' => $page, ]; } public function mealCal(Request $request, string $pu, ?string $ym = null) { $b = $this->mealBase($request, $pu, $ym, 'cal'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($d = 1; $d <= $b['month']['last']; $d++) { $labels[] = $d; $data[] = isset($b['month']['days'][$d]) ? (float) $b['month']['days'][$d]->sum[$col] : null; } $set = $b['set']; $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => is_numeric($set->{$col . '_min'}) ? (float) $set->{$col . '_min'} : null, 'max' => is_numeric($set->{$col . '_max'}) ? (float) $set->{$col . '_max'} : null, ]; return view('note.some.meal_cal', $b); } // ---------------------------------------------------------------- meal/daily/{pu}/{ymd}.html (日別の食事レポート) public function mealDaily(Request $request, string $pu, string $ymd) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $y = (int) substr($ymd, 0, 4); $m = (int) substr($ymd, 4, 2); $d = (int) substr($ymd, 6, 2); if (! checkdate($m, $d, $y) || $y < 1990 || $y > 2100) { return redirect('/note/some/error.html'); } $set = M::setting($pk, $y, $m, $d); if (! $set) { return redirect('/error404.html'); } $eiyou = M::eiyou(); $col = (string) $request->query('col', 'kcal'); if (! isset($eiyou[$col])) { $col = 'kcal'; } $day = M::day($pk, $y, $m, $d); $ana = []; $radar = []; $i = 0; foreach ($eiyou as $c => $e) { $i++; $ana[$c] = M::analyzeOne($set, $c, $day['avg'][$c]); $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $ana[$c]['pers']]; } return view('note.some.meal_daily', [ 'friend' => $f, 'pu' => $pu, 'y' => $y, 'm' => $m, 'd' => $d, 'col' => $col, 'coldic' => $eiyou[$col], 'eiyou' => $eiyou, 'set' => $set, 'day' => $day, 'ana' => $ana, 'radar' => $radar, ]); } // ---------------------------------------------------------------- meal/detail/{pu}/{pkey}.html (食事の詳細) public function mealDetail(Request $request, string $pu, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); if (! $set) { return redirect('/error404.html'); } $meal = M::detail($pk, (int) $pkey); if (! $meal) { return redirect('/error404.html'); } return view('note.some.meal_detail', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'meal' => $meal, 'eiyou' => M::eiyou(), 'par' => M::percent($set, $meal), 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/analyze/{pu}/{col}/{pkey}.html (栄養素の内訳) public function mealAnalyze(Request $request, string $pu, string $col, string $pkey) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $set = M::setting($pk, 0, 0); $eiyou = M::eiyou(); if (! $set || ! isset($eiyou[$col])) { return redirect('/error404.html'); } $alz = M::analyze($pk, (int) $pkey, $col); if (! $alz) { return redirect('/error404.html'); } $parc = []; $other = 0; foreach ($alz['foods'] as $i => $v) { if ($i <= 4) { $parc[$i] = (float) $v['par']; } else { $other += $v['par']; } } if ($other > 0) { $parc[5] = (float) $other; } return view('note.some.meal_analyze', [ 'friend' => $f, 'pu' => $pu, 'pkey' => (int) $pkey, 'col' => $eiyou[$col], 'alz' => $alz, 'parc' => $parc, 'other' => $other, 'msg' => MealReportData::MSG[$col] ?? '', 'back' => (string) $request->headers->get('referer', ''), ]); } // ---------------------------------------------------------------- meal/time/{pu}/{ym}.html (時間別) public function mealTime(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'time'); if (! is_array($b)) { return $b; } $col = $b['col']; $labels = []; $data = []; for ($h = 0; $h <= 23; $h++) { $labels[] = $h; $data[] = (float) ($b['month']['hours'][$col][$h] ?? 0); } $b['chart'] = [ 'name' => $b['coldic']->name, 'unit' => S::d($b['coldic']->unit), 'labels' => $labels, 'data' => $data, 'min' => null, 'max' => null, 'xunit' => '時', ]; return view('note.some.meal_time', $b); } // ---------------------------------------------------------------- meal/balance/{pu}/{ym}.html (栄養バランス) public function mealBalance(Request $request, string $pu, string $ym) { $b = $this->mealBase($request, $pu, $ym, 'balance'); if (! is_array($b)) { return $b; } $radar = []; $i = 0; foreach ($b['eiyou'] as $c => $e) { $i++; $radar[] = ['i' => $i, 'name' => $e->name, 'pers' => $b['ana'][$c]['pers']]; } $b['radar'] = $radar; return view('note.some.meal_balance', $b); } /** 記録グラフ詳細 kid=5 (摂取カロリー比較)。旧 graph/view.php */ private function graphCalorie(Request $request, object $f, string $pu, object $km, object $set, int $y, int $m) { $pk = (int) $f->pk_user; $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12], true)) { $range = 1; } $chart = Cal::series($pk, $y, $m, $range); if ($chart === null) { // 非公開の記録 return redirect('/note/some/error.html'); } return view('note.some.graph_view', [ 'friend' => $f, 'pu' => $pu, 'kid' => 5, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $chart['any'], 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'tb' => Cal::table($f, $y, $m), ]); } // ---------------------------------------------------------------- graph/{pu}/index.html (記録グラフ一覧) public function graphIndex(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $pk = (int) $f->pk_user; $sets = DB::select( "select t120.kid, t120.graph, t120.mset, t120.mokuhyou, t120.first_val, date_format(t120.lastdate, '%Y%m%d%H%i%s') as ver, t120.last_val as kdata, date_format(t120.last_date, '%Y') as y, date_format(t120.last_date, '%m') as m, date_format(t120.last_date, '%d') as d from t120_kiroku as t120 where t120.open = 0 and t120.del = 0 and t120.pk_user = ? order by lastdate desc", [$pk] ); $items = []; if ($sets) { $kids = array_values(array_unique(array_map(fn ($r) => (int) $r->kid, $sets))); $info = []; foreach (DB::select( 'select t250.kid, t250.title, t270.unit from t250_kiroku as t250 join t270_unit as t270 using (unid) where t250.del = 0 and t250.kid in (' . implode(',', array_fill(0, count($kids), '?')) . ')', $kids ) as $r) { $info[(int) $r->kid] = $r; } $seen = []; foreach ($sets as $r) { if (isset($info[(int) $r->kid]) && ! isset($seen[(int) $r->kid])) { $seen[(int) $r->kid] = true; $r->title = $info[(int) $r->kid]->title; $r->unit = $info[(int) $r->kid]->unit; $items[] = $r; } } D::attachCharts($pk, $items); } return view('note.some.graph_index', ['fr' => $f, 'pu' => $pu, 'items' => $items]); } // ---------------------------------------------------------------- graph/{kid}/{pu}/{ym}/det.html public function graphDet(Request $request, string $kid, string $pu, ?string $ym = null) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } if ($ym === null) { return redirect('/note/some/graph/' . (int) $kid . '/' . $pu . '/' . S::now()->format('Ym') . '/det.html'); } $pk = (int) $f->pk_user; $kid = (int) $kid; $y = (int) substr($ym, 0, 4); $m = (int) substr($ym, 4, 2); $km = G::master($kid); $set = G::set($pk, $kid); if ($kid === 5 && $km && $set && $m >= 1 && $m <= 12 && $y >= 1990 && $y <= 2100) { return $this->graphCalorie($request, $f, $pu, $km, $set, $y, $m); } if (! $km || ! $set || $m < 1 || $m > 12 || $y < 1990 || $y > 2100 || ! in_array((string) $set->graph, ['1', '2', '5'], true)) { return redirect('/note/some/error.html'); } $range = (int) $request->query('range', 1); if (! in_array($range, [1, 3, 6, 12, 24, 36, 48, 60, 120], true)) { $range = 1; } $chart = G::series($pk, $kid, $y, $m, $range, $set, $km); $hasData = count(array_filter($chart['data'], fn ($v) => $v !== null)) > 0; return view('note.some.graph_det', [ 'friend' => $f, 'pu' => $pu, 'kid' => $kid, 'y' => $y, 'm' => $m, 'range' => $range, 'km' => $km, 'set' => $set, 'chart' => $chart, 'hasData' => $hasData, 'pre' => date('Ym', mktime(0, 0, 0, $m - 1, 1, $y)), 'nxt' => date('Ym', mktime(0, 0, 0, $m + 1, 1, $y)), 'daily' => G::daily($f, $kid, $y, $m, $set), 'sum' => G::summary($pk, $kid, $y, $m, $km, $set), ]); } // ---------------------------------------------------------------- friend / circle list public function friendList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $from = " from t450_friend as t450 join t100_user as t100 on (t450.memid = t100.user_id) left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t450.my_pk_user = ? and t450.del = 0 and t100.del = 0 "; $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, [(int) $f->pk_user])->c ?? 0); $rows = DB::select( "select t450.fid, t100.pk_user, t100.name, t100.f_count, if(t101.main_img != '' and t101.main_img is not null, 1, 0) as main_img, date_format(t101.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, [(int) $f->pk_user] ); return $this->viewFor('note.some.friend_list', $f, $pu, [ 'rows' => $rows, 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function circleList(Request $request, string $pu) { $f = $this->entry($request, $pu); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $n = $this->offset($request); $m = S::PAGE_FRIEND; $count = S::circleCount((int) $f->pk_user); return $this->viewFor('note.some.circle_list', $f, $pu, [ 'rows' => S::circles((int) $f->pk_user, $m, $n), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } // ---------------------------------------------------------------- コメントの書き込み・修正・削除 private function dayUrl(object $d, string $suffix = ''): string { return '/note/some/record/day/' . str_replace('-', '', $d->ndate) . '_' . S::enc((int) $d->npk_user) . '.html' . $suffix; } /** コメントを書く処理の共通チェック: [日記, 会員] か、リダイレクト */ private function commentGate(Request $request, int $nid) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $d = D::commentTarget($nid); if (! $d) { return redirect('/note/some/diary/error.html'); } if ((string) $me->note_flg !== '1') { return redirect($this->dayUrl($d)); } return [$d, $me]; } /** record/cinput_cnf.html (POST): コメントの確認 */ public function commentCnf(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', $request->query('nid', 0))); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $f = S::friend((int) $d->npk_user); if (! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_cnf', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'doc' => $doc, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cinput_bak.html (POST): 確認から戻って編集 */ public function commentBak(Request $request) { $d = D::commentTarget((int) $request->input('nid', 0)); if (! $d) { return redirect('/note/some/diary/error.html'); } return redirect($this->dayUrl($d, '#comfrm'))->withInput(); } /** record/cinput_fin.html (POST): コメントを書き込む */ public function commentFin(Request $request) { $g = $this->commentGate($request, (int) $request->input('nid', 0)); if (! is_array($g)) { return $g; } [$d, $me] = $g; $doc = (string) $request->input('doc', ''); if (trim($doc) === '') { return redirect($this->dayUrl($d, '#comfrm'))->with('com_errs', ['コメントを、入力してください。']); } $cid = D::addComment($me, $d, $doc); return redirect($this->dayUrl($d, '?nocache=1#reply' . $cid)); } /** record/cinput_fin2.html (POST): 自分のコメントを修正する */ public function commentFin2(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } $doc = (string) $request->input('doc', ''); if (trim($doc) !== '') { D::editComment((int) $com->cid, (int) $me->pk_user, $doc); } return redirect($this->dayUrl($com, '?nocache=1#reply' . $com->cid)); } /** record/cdel_dcnf.html (GET): コメント削除の確認 */ public function commentDcnf(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->query('cid', 0), (int) $me->pk_user); $d = $com ? D::commentTarget((int) $com->nid) : null; $f = $d ? S::friend((int) $d->npk_user) : null; if (! $d || ! $f) { return redirect('/note/some/diary/error.html'); } return $this->viewFor('note.some.comment_del', $f, S::enc((int) $d->npk_user), [ 'd' => $d, 'com' => $com, 'newDiaries' => D::newDiaries($f), 'tags' => D::tags((int) $f->pk_user), ]); } /** record/cdel_dfin.html (POST): コメントを削除する */ public function commentDfin(Request $request) { $me = S::me(); if (! $me) { return $this->loginRedirect($request); } $com = D::ownComment((int) $request->input('cid', 0), (int) $me->pk_user); if (! $com) { return redirect('/note/some/diary/error.html'); } D::deleteComment($com); return redirect($this->dayUrl($com)); } // ---------------------------------------------------------------- gallery / keyword / index / error public function gallery(Request $request) { $n = $this->offset($request); $m = 20; $from = " from t201_nikki_img as t201 join t200_nikki as t200 on (t200.nid = t201.nid and t200.del = 0 and t200.open = '1') join t100_user as t100 on (t100.pk_user = t201.pk_user and t100.del = 0 and t100.note_flg = 1) where (t201.img1 is not null and t201.img1 != '') or (t201.img2 is not null and t201.img2 != '') or (t201.img3 is not null and t201.img3 != '') "; // 全会員の写真の件数・並びは重い (数十万行の走査) ので少しの間キャッシュする $count = (int) \Illuminate\Support\Facades\Cache::remember('note_some_gallery_count', 21600, fn () => (int) (DB::selectOne('select count(t201.nid) as c' . $from)->c ?? 0)); $rows = \Illuminate\Support\Facades\Cache::remember('note_some_gallery_rows_' . $n, 600, fn () => array_map(fn ($r) => (array) $r, DB::select( "select t201.nid, t201.pk_user, t200.title, t100.name, date_format(t201.date, '%Y') as y, date_format(t201.date, '%m') as m, date_format(t201.date, '%d') as d, if(t201.img1 is not null and t201.img1 != '', 1, 0) as img1, if(t201.img2 is not null and t201.img2 != '', 1, 0) as img2, if(t201.img3 is not null and t201.img3 != '', 1, 0) as img3, date_format(t201.`update`, '%Y%m%d%H%i%s') as ver" . $from . ' order by t201.date desc, t201.nimg_id asc limit ' . $m . ' offset ' . $n ))); $rows = array_map(fn ($r) => (object) $r, $rows); foreach ($rows as $r) { $r->num = $r->img1 ? 1 : ($r->img2 ? 2 : 3); $r->pu = S::enc($r->pk_user); } return view('note.some.gallery', ['rows' => $rows, 'pager' => S::pages($count, $n, $m, S::qs($request))]); } public function keyword(Request $request) { $n = $this->offset($request); $m = 100; $me = S::me(); $w = ''; $wb = []; $parts = ['select tag, sum(cnt_1) as cnt from t110_user_tag where true %W% group by tag']; $binds = []; if ($me) { $w = ' and user_id != ? '; $wb = [$me->user_id]; $parts[] = 'select tag, sum(cnt_2) as cnt from t110_user_tag where true %W% group by tag'; $parts[] = "select tag, sum(cnt_3) as cnt from t110_user_tag where user_id in (select user_id from t450_friend where memid = ? and del = '0') %W% group by tag"; } foreach ($parts as $i => $p) { $parts[$i] = str_replace('%W%', $w, $p); if ($i === 2) { $binds[] = $me->user_id; } $binds = array_merge($binds, $wb); } $union = implode(' union all ', $parts); $count = (int) (DB::selectOne("select count(*) as c from (select tag from ($union) as t group by tag having sum(cnt) > 0) as t", $binds)->c ?? 0); $rows = DB::select("select tag, sum(cnt) as cnt from ($union) as t group by tag having sum(cnt) > 0 order by cnt desc limit $m offset $n", $binds); return view('note.some.keyword', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'pager' => S::pageLink($count, $n, $m, S::qs($request)), ]); } public function index(Request $request) { $n = $this->offset($request); $m = 50; $me = S::me(); $meId = $me ? (int) $me->pk_user : 0; $free = trim((string) $request->query('freeword', '')); $tag = trim((string) $request->query('tag', '')); $search = false; foreach (['freeword', 'name', 'sex', 'nendai_from', 'nendai_to', 'month', 'day', 'todofuken', 'blood', 'rec', 'tag'] as $k) { if (S::isVal($request->query($k))) { $search = true; } } $cols = "t100.pk_user, t100.name, t100.doc, t100.sex, t100.sex_set, t100.nendai, t100.nendai_set, t100.todofuken, t100.todofuken_set, date_format(t100.`update`, '%Y%m%d%H%i%s') as ver, if(t101.main_img is not null and t101.main_img != '', 1, 0) as main_img"; $from = ' from t100_user as t100 left outer join t101_user_img as t101 on (t100.user_id = t101.user_id) where t100.del = 0 and t100.note_flg = 1 and t100.pk_user != ? '; $bind = [$meId]; if ($search) { $from .= ' and t100.name like ? '; $bind[] = addcslashes($free, '\\%_') . '%'; if ($tag !== '') { $lv = $me ? '<= 2' : '= 1'; $t = S::stored($tag); $from .= " and ((find_in_set(?, t100.tag) > 0 and t100.tag_set $lv) or (find_in_set(?, t100.sports) > 0 and t100.sports_set $lv) or (find_in_set(?, t100.disease) > 0 and t100.disease_set $lv)) "; array_push($bind, $t, $t, $t); } $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $from, $bind)->c ?? 0); $rows = DB::select('select ' . $cols . $from . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $bind); } else { $week = 1; do { $b = array_merge($bind, [S::now()->subWeeks($week)->format('Y-m-d')]); $w = $from . ' and t100.lastlogin > ? '; $rows = DB::select('select ' . $cols . $w . ' order by t100.lastlogin desc limit ' . $m . ' offset ' . $n, $b); $again = $m >= count($rows) && $week < 2; $week++; } while ($again); $count = (int) (DB::selectOne('select count(t100.pk_user) as c' . $w, $b)->c ?? 0); } foreach ($rows as $r) { $r->pu = S::enc($r->pk_user); $r->prof = S::profLine($r); } return view('note.some.index', [ 'rows' => $rows, 'rank' => S::tagRanking(), 'freeword' => (string) $request->query('freeword', ''), 'pager' => S::pageLinksSimple($count, $n, $m, S::qs($request)), ]); } public function error() { return view('note.some.error'); } // ---------------------------------------------------------------- watch private function watching(int $me, int $pk): bool { $r = DB::selectOne("select count(my_pk_user) as c from t455_watchlist where my_pk_user = ? and w_pk_user = ? and del = '0'", [$me, $pk]); return ($r->c ?? 0) > 0; } private function updateWatchCount(int $pk): void { DB::update( "update t100_user set w_count = (select count(wlid) from t455_watchlist where w_pk_user = ? and del = '0') where pk_user = ?", [$pk, $pk] ); } public function watch(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = (int) S::me()->pk_user; $pk = (int) $f->pk_user; $double = false; $view = 'frm'; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/watch/frm_' . $pu . '.html'); } if ($this->watching($me, $pk)) { $double = true; } else { DB::insert('insert into t455_watchlist (my_pk_user, w_pk_user, `date`, `update`) values (?, ?, now(), now())', [$me, $pk]); $this->updateWatchCount($pk); $view = 'fin'; } } elseif ($action === 'del') { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } DB::update("update t455_watchlist set del = '1', `update` = now() where my_pk_user = ? and w_pk_user = ?", [$me, $pk]); $this->updateWatchCount($pk); return redirect('/note/my/watch/list.html'); } else { $double = $this->watching($me, $pk); } return $this->viewFor('note.some.watch', $f, $pu, ['mode' => $view, 'double' => $double]); } // ---------------------------------------------------------------- message /** 旧 checkCnf (件名・本文) */ private function checkMessage(string $title, string $doc): array { $err = []; if (trim($title) === '') { $err[] = '件名を、入力してください。'; } if (trim($doc) === '') { $err[] = '本文を、入力してください。'; } if (mb_strlen($doc, 'UTF-8') > 1500) { $err[] = '本文は、1500文字以下で入力してください。'; } if (mb_strlen($title, 'UTF-8') > 50) { $err[] = '件名は、50文字以下で入力してください。'; } return $err; } public function message(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $title = (string) $request->input('title', ''); $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { $mode = 'fin'; } elseif ($action === 'cnf' || $action === 'ent') { $errors = $this->checkMessage($title, $doc); if ($action === 'ent') { if (! $request->isMethod('post')) { return redirect('/note/some/message/frm_' . $pu . '.html'); } if (! $errors) { $this->sendMessage($me, $f, $title, $doc); return redirect('/note/some/message/fin_' . $pu . '.html'); } } else { $mode = $errors ? 'frm' : 'cnf'; } } return $this->viewFor('note.some.message', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'title' => $title, 'doc' => $doc]); } /** 旧 InsertMail: 送信者の送信済みと受信者の受信箱に 1 通ずつ (t400_msg) + 通知メール */ private function sendMessage(object $me, object $f, string $title, string $doc): void { $t = S::stored($title); $d = S::stored($doc); $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, `date`, `update`, sflg, from_open, to_open, type)'; $mid = 0; DB::transaction(function () use ($me, $f, $t, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, 1], [(int) $f->pk_user, 0]] as [$owner, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now(), now(), ?, 1, 1, 1)", [$t, $d, $owner, $owner === (int) $me->pk_user ? $me->user_id : $f->user_id, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg] ); } $mid = (int) DB::getPdo()->lastInsertId(); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail !== '2') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからメッセージが届いています", <<c ?? 0) > 0; } private function reqIsSent(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$pk, $me, self::M_FRIEND])->c ?? 0) > 0; } private function reqIsExist(int $me, int $pk): bool { return (DB::selectOne('select count(mid) as c from t400_msg where pk_user = ? and from_pk = ? and tmp1 is null and type = ? and del = 0', [$me, $pk, self::M_FRIEND])->c ?? 0) > 0; } public function request(Request $request, string $action, string $pu) { $f = $this->entry($request, $pu, true); if (! is_object($f) || ! isset($f->pk_user)) { return $f; } $me = S::me(); $meId = (int) $me->pk_user; $pk = (int) $f->pk_user; $doc = (string) $request->input('doc', ''); $mode = 'frm'; $errors = []; if ($action === 'fin') { if (! $request->isMethod('post')) { return redirect('/note/some/request/frm_' . $pu . '.html'); } if (! $this->reqIsExist($meId, $pk) && ! $this->reqIsMember($meId, $pk) && ! $this->reqIsSent($meId, $pk)) { if (trim($doc) === '') { $errors[] = 'メッセージを、入力してください。'; } else { $this->sendRequest($me, $f, $doc); } } $mode = $errors ? 'frm' : 'fin'; } elseif ($action === 'cnf') { if (trim($doc) === '') { $errors[] = '本文を、入力してください。'; } $mode = $errors ? 'frm' : 'cnf'; } elseif ($action === 'back') { $mode = 'frm'; } else { if ($this->reqIsMember($meId, $pk)) { $mode = 'r_err'; } elseif ($this->reqIsSent($meId, $pk)) { $mode = 's_err'; } elseif ($this->reqIsExist($meId, $pk)) { $mode = 'e_err'; } } return $this->viewFor('note.some.request', $f, $pu, ['mode' => $mode, 'errs' => $errors, 'doc' => $doc]); } /** 旧 insertMail (仲間追加依頼メッセージ) */ private function sendRequest(object $me, object $f, string $doc): void { $cols = '(title, doc, pk_user, user_id, to_pk, `to`, to_name, from_pk, `from`, from_name, vflg, `date`, `update`, sflg, from_open, to_open, type)'; $title = 'メンバー追加の依頼'; $d = S::stored($doc); $mid = 0; DB::transaction(function () use ($me, $f, $doc, $title, $d, $cols, &$mid) { foreach ([[(int) $me->pk_user, $me->user_id, 1], [(int) $f->pk_user, $f->user_id, 0]] as [$owner, $ownerId, $sflg]) { DB::insert( "insert into t400_msg $cols values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, now(), now(), ?, 1, 1, ?)", [$title, $d, $owner, $ownerId, (int) $f->pk_user, $f->user_id, $f->name, (int) $me->pk_user, $me->user_id, S::stored($me->name), $sflg, self::M_FRIEND] ); } $mid = (int) DB::getPdo()->lastInsertId(); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); $text = $doc . "\n■以下のページよりマイメンバーへ追加するか断ってください\n" . $base . '/note/my/friend/frm_' . $mid . ".html\n■" . S::d($me->name) . "さんのページ\n" . $base . '/note/some/top_' . S::enc($me->pk_user) . '.html'; DB::update('update t400_msg set doc = ? where mid = ?', [S::stored($text), $mid]); }); $u = DB::selectOne('select mail, msg_mail from t100_user where pk_user = ? limit 1', [(int) $f->pk_user]); if ($u && (string) $u->msg_mail === '1') { $from = S::d($me->name); $to = S::d($f->name); $base = rtrim((string) config('qa.base_url', self::BASE), '/'); S::mail($u->mail, "【カラダカラ】{$from}さんからのマイメンバー追加依頼", <<pk_user] ); $clean = fn ($s) => strip_tags(S::d((string) $s)); $link = fn ($r) => self::BASE . '/note/some/record/day/' . $r->sdate . '_' . $pu . '.html'; $x = fn ($s) => htmlspecialchars((string) $s, ENT_XML1 | ENT_QUOTES, 'UTF-8'); $title = $clean('健康診断チェックのポータルサイト【カラダカラ:健康診断】'); $desc = $clean('健康診断チェックのポータルサイト。手軽にあなたのカラダが診断チェックできるサイトです。まずは気軽に健康診断チェックしてみよう!診断チェックをすると、健康の全国ランキングを表示!あなたのカラダは全国ランキングで何位?'); $out = '' . "\n" . '' . "\n" . '' . "\n" . '' . $x($title) . '' . "\n" . '' . $x(self::BASE . '/') . '' . "\n" . '' . $x($desc) . '' . "\n" . '' . date('c') . '' . "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n"; } $out .= "\n\n\n"; foreach ($rows as $r) { $out .= '' . "\n" . '' . $x($clean($r->title)) . '' . "\n" . '' . $x($link($r)) . '' . "\n" . '' . $r->d . '' . "\n" . '' . $x($clean($r->doc)) . '' . "\n" . '' . $r->d . '' . "\n\n"; } $out .= "\n"; return response($out, 200, ['Content-Type' => 'text/xml; charset=UTF-8']); } /** 旧 trac.php (トラックバック受信) は先頭で exit しており何もしない。スパム対策のため受け付けない */ public function trac() { return response('', 200); } /** 旧 vote.php?action=fin: 日記への投票 (t430_vote) */ public function vote(Request $request) { if ($request->headers->get('Sec-Fetch-Site') === 'cross-site') { abort(403); } $me = S::me(); $nid = (int) $request->input('nid', 0); if ($request->input('action') === 'fin' && $me && $nid > 0) { try { DB::insert( 'insert ignore into t430_vote (pk_user, nid, entdate, uniq) values (?, ?, ?, ?)', [(int) $me->pk_user, $nid, S::now()->format('Y-m-d H:i:s'), (int) $me->pk_user . '_' . $nid] ); } catch (\Throwable $e) { // 旧と同じく t430_vote が無い環境では何もしない } } return response('', 200); } /** 旧 /note/youtube.html / note/youtube.php: みんなの動画 */ public function youtube(Request $request) { $n = $this->offset($request); $m = 20; $count = (int) \Illuminate\Support\Facades\Cache::remember('note_youtube_count', 3600, function () { return (int) (DB::selectOne("SELECT COUNT(*) as c FROM karadakara_yt.yt100_url")->c ?? 0); }); $items = DB::select(" SELECT y.pkey, y.pk_user, y.nid, y.ndate, y.url, y.vid, y.ytitle, t.title as nikki_title, u.name as user_name FROM karadakara_yt.yt100_url y LEFT JOIN karadakara_db.t200_nikki t ON y.nid = t.nid LEFT JOIN karadakara_user.us100_user u ON y.pk_user = u.pk_user ORDER BY y.pkey DESC LIMIT ? OFFSET ? ", [$m, $n]); $rows = []; foreach ($items as $item) { $ndate = $item->ndate ? str_replace('-', '', substr((string)$item->ndate, 0, 10)) : ''; $rows[] = (object) [ 'pkey' => $item->pkey, 'pk_user' => $item->pk_user, 'pu' => S::enc($item->pk_user), 'nid' => $item->nid, 'ymd' => $ndate, 'vid' => $item->vid, 'url' => $item->url, 'title' => $item->nikki_title ?: ($item->ytitle ?: '動画'), 'name' => $item->user_name ?: 'ゲスト', ]; } $pager = S::pages($count, $n, $m, S::qs($request)); return view('note.youtube', [ 'rows' => $rows, 'pager' => $pager, ]); } } ℼ佄呃偙⁅瑨汭ਾ格浴慬杮∽湥㸢 †㰠敨摡ਾ††††洼瑥⁡档牡敳㵴產晴㠭㸢 †††㰠敭慴渠浡㵥瘢敩灷牯≴挠湯整瑮∽楷瑤㵨敤楶散眭摩桴‬湩瑩慩⵬捳污㵥∱ਾ †††㰠楴汴㹥敓癲牥䔠牲牯⼼楴汴㹥ਊ††††猼祴敬ਾ††††††⨯‡潮浲污穩⹥獣⁳㡶〮ㄮ簠䴠呉䰠捩湥敳簠朠瑩畨⹢潣⽭敮潣慬⽳潮浲污穩⹥獣⁳⼪瑨汭汻湩ⵥ敨杩瑨ㄺㄮ㬵眭扥楫⵴整瑸猭穩ⵥ摡番瑳ㄺ〰紥潢祤浻牡楧㩮細筡慢正牧畯摮挭汯牯琺慲獮慰敲瑮捽摯筥潦瑮昭浡汩㩹潭潮灳捡ⱥ潭潮灳捡㭥潦瑮猭穩㩥攱絭桛摩敤嵮摻獩汰祡渺湯絥瑨汭晻湯⵴慦業祬猺獹整⵭極⴬灡汰ⵥ祳瑳浥䈬楬歮慍卣獹整䙭湯ⱴ敓潧⁥䥕刬扯瑯Ɐ效癬瑥捩⁡敎敵䄬楲污丬瑯慓獮猬湡⵳敳楲ⱦ灁汰⁥潃潬⁲浅橯Ⱪ敓潧⁥䥕䔠潭楪匬来敯唠⁉祓扭汯丬瑯潃潬⁲浅橯㭩楬敮栭楥桧㩴⸱紵Ⱚ愺瑦牥㨬敢潦敲扻硯猭穩湩㩧潢摲牥戭硯戻牯敤㩲‰潳楬⁤攣攲昸細筡潣潬㩲湩敨楲㭴整瑸搭捥牯瑡潩㩮湩敨楲絴潣敤晻湯⵴慦業祬䴺湥潬䴬湯捡Ɐ潃獮汯獡䰬扩牥瑡潩潍潮䌬畯楲牥丠睥洬湯獯慰散獽杶瘬摩潥摻獩汰祡戺潬正瘻牥楴慣⵬污杩㩮業摤敬白摩潥浻硡眭摩桴ㄺ〰㬥敨杩瑨愺瑵絯戮ⵧ桷瑩筥ⴭ杢漭慰楣祴ㄺ戻捡杫潲湵ⵤ潣潬㩲昣晦戻捡杫潲湵ⵤ潣潬㩲杲慢㈨㔵㈬㔵㈬㔵瘬牡⴨戭ⵧ灯捡瑩⥹紩戮ⵧ牧祡ㄭ〰⵻戭ⵧ灯捡瑩㩹㬱慢正牧畯摮挭汯牯⌺㝦慦捦戻捡杫潲湵ⵤ潣潬㩲杲慢㈨㜴㈬〵㈬㈵瘬牡⴨戭ⵧ灯捡瑩⥹紩戮牯敤⵲牧祡㈭〰⵻戭牯敤⵲灯捡瑩㩹㬱潢摲牥挭汯牯⌺摥㉦㝦戻牯敤⵲潣潬㩲杲慢㈨㜳㈬㈴㈬㜴瘬牡⴨戭牯敤⵲灯捡瑩⥹紩戮牯敤⵲牧祡㐭〰⵻戭牯敤⵲灯捡瑩㩹㬱潢摲牥挭汯牯⌺扣㕤づ戻牯敤⵲潣潬㩲杲慢㈨㌰㈬㌱㈬㐲瘬牡⴨戭牯敤⵲灯捡瑩⥹紩戮牯敤⵲筴潢摲牥琭灯眭摩桴ㄺ硰⹽潢摲牥爭扻牯敤⵲楲桧⵴楷瑤㩨瀱絸昮敬筸楤灳慬㩹汦硥⹽牧摩摻獩汰祡机楲絤栮摩敤筮楤灳慬㩹潮敮⹽瑩浥⵳散瑮牥慻楬湧椭整獭挺湥整絲樮獵楴祦挭湥整筲番瑳晩⵹潣瑮湥㩴散瑮牥⹽潦瑮猭浥扩汯筤潦瑮眭楥桧㩴〶細栮㔭桻楥桧㩴⸱㔲敲絭栮㠭桻楥桧㩴爲浥⹽⵨㘱桻楥桧㩴爴浥⹽整瑸猭筭潦瑮猭穩㩥㠮㔷敲絭琮硥⵴杬晻湯⵴楳敺ㄺㄮ㔲敲絭氮慥楤杮㜭汻湩ⵥ敨杩瑨ㄺ㜮爵浥⹽硭愭瑵筯慭杲湩氭晥㩴畡潴活牡楧⵮楲桧㩴畡潴⹽汭ㄭ浻牡楧⵮敬瑦⸺㔲敲絭洮⵴笲慭杲湩琭灯⸺爵浥⹽牭㈭浻牡楧⵮楲桧㩴㔮敲絭洮⵬笲慭杲湩氭晥㩴㔮敲絭洮⵴笴慭杲湩琭灯ㄺ敲絭洮⵬笴慭杲湩氭晥㩴爱浥⹽瑭㠭浻牡楧⵮潴㩰爲浥⹽汭ㄭ笲慭杲湩氭晥㩴爳浥⹽洭⵴硰浻牡楧⵮潴㩰ㄭ硰⹽慭⵸⵷汸浻硡眭摩桴㌺父浥⹽慭⵸⵷砶筬慭⵸楷瑤㩨㈷敲絭洮湩栭猭牣敥筮業⵮敨杩瑨ㄺ〰桶⹽癯牥汦睯栭摩敤筮癯牥汦睯栺摩敤絮瀮㘭灻摡楤杮ㄺ㔮敲絭瀮⵹笴慰摤湩ⵧ潴㩰爱浥瀻摡楤杮戭瑯潴㩭爱浥⹽硰㐭灻摡楤杮氭晥㩴爱浥瀻摡楤杮爭杩瑨ㄺ敲絭瀮⵸笶慰摤湩ⵧ敬瑦ㄺ㔮敲㭭慰摤湩ⵧ楲桧㩴⸱爵浥⹽瑰㠭灻摡楤杮琭灯㈺敲絭昮硩摥灻獯瑩潩㩮楦數絤爮汥瑡癩筥潰楳楴湯爺汥瑡癩絥琮灯〭瑻灯〺⹽楲桧⵴笰楲桧㩴細献慨潤筷潢⵸桳摡睯〺ㄠ硰㌠硰〠爠执⡡ⰰⰰⰰㄮⰩ‰瀱⁸瀲⁸‰杲慢〨〬〬⸬㘰紩琮硥⵴散瑮牥瑻硥⵴污杩㩮散瑮牥⹽整瑸札慲⵹〲笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺摥㉦㝦挻汯牯爺执⡡㌲ⰷ㐲ⰲ㐲ⰷ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〳笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺㉥㡥て挻汯牯爺执⡡㈲ⰶ㌲ⰲ㐲ⰰ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〴笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺扣㕤づ挻汯牯爺执⡡〲ⰳㄲⰳ㈲ⰴ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〵笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺ち敡っ挻汯牯爺执⡡㘱ⰰ㜱ⰴ㤱ⰲ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〶笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺ㄷ〸㘹挻汯牯爺执⡡ㄱⰳ㈱ⰸ㔱ⰰ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〷笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺愴㔵㠶挻汯牯爺执⡡㐷㠬ⰵ〱ⰴ慶⡲ⴭ整瑸漭慰楣祴⤩⹽整瑸札慲⵹〹笰ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺愱〲挲挻汯牯爺执⡡㘲㌬ⰲ㐴瘬牡⴨琭硥⵴灯捡瑩⥹紩甮灰牥慣敳瑻硥⵴牴湡晳牯㩭灵数捲獡絥甮摮牥楬敮瑻硥⵴敤潣慲楴湯町摮牥楬敮⹽湡楴污慩敳筤眭扥楫⵴潦瑮猭潭瑯楨杮愺瑮慩楬獡摥ⴻ潭⵺獯⵸潦瑮猭潭瑯楨杮机慲獹慣敬⹽牴捡楫杮眭摩牥汻瑥整⵲灳捡湩㩧〮攵絭眮㔭睻摩桴ㄺ㈮爵浥⹽⵷笸楷瑤㩨爲浥⹽⵷畡潴睻摩桴愺瑵絯朮楲ⵤ潣獬ㄭ杻楲ⵤ整灭慬整挭汯浵獮爺灥慥⡴ⰱ業浮硡〨ㄬ牦⤩䁽眭扥楫⵴敫晹慲敭⁳灳湩ほ笥牴湡晳牯㩭潲慴整〨敤⥧瑽筯牴湡晳牯㩭潲慴整ㄨ畴湲紩䁽敫晹慲敭⁳灳湩ほ笥牴湡晳牯㩭潲慴整〨敤⥧瑽筯牴湡晳牯㩭潲慴整ㄨ畴湲紩䁽眭扥楫⵴敫晹慲敭⁳楰杮ほ笥牴湡晳牯㩭捳污⡥⤱漻慰楣祴ㄺ㝽┵琬筯牴湡晳牯㩭捳污⡥⤲漻慰楣祴〺絽歀祥牦浡獥瀠湩筧┰瑻慲獮潦浲猺慣敬ㄨ㬩灯捡瑩㩹紱㔷Ⱕ潴瑻慲獮潦浲猺慣敬㈨㬩灯捡瑩㩹細䁽眭扥楫⵴敫晹慲敭⁳異獬筥┰琬筯灯捡瑩㩹紱〵笥灯捡瑩㩹㔮絽歀祥牦浡獥瀠汵敳ほⰥ潴潻慰楣祴ㄺ㕽┰潻慰楣祴⸺紵䁽眭扥楫⵴敫晹慲敭⁳潢湵散ほⰥ潴瑻慲獮潦浲琺慲獮慬整⡙㈭┵㬩眭扥楫⵴湡浩瑡潩⵮楴業杮昭湵瑣潩㩮畣楢ⵣ敢楺牥⸨ⰸⰰⰱ⤱愻楮慭楴湯琭浩湩ⵧ畦据楴湯挺扵捩戭穥敩⡲㠮〬ㄬㄬ紩〵笥牴湡晳牯㩭牴湡汳瑡奥〨㬩眭扥楫⵴湡浩瑡潩⵮楴業杮昭湵瑣潩㩮畣楢ⵣ敢楺牥〨〬⸬ⰲ⤱愻楮慭楴湯琭浩湩ⵧ畦据楴湯挺扵捩戭穥敩⡲ⰰⰰ㈮ㄬ紩䁽敫晹慲敭⁳潢湵散ほⰥ潴瑻慲獮潦浲琺慲獮慬整⡙㈭┵㬩眭扥楫⵴湡浩瑡潩⵮楴業杮昭湵瑣潩㩮畣楢ⵣ敢楺牥⸨ⰸⰰⰱ⤱愻楮慭楴湯琭浩湩ⵧ畦据楴湯挺扵捩戭穥敩⡲㠮〬ㄬㄬ紩〵笥牴湡晳牯㩭牴湡汳瑡奥〨㬩眭扥楫⵴湡浩瑡潩⵮楴業杮昭湵瑣潩㩮畣楢ⵣ敢楺牥〨〬⸬ⰲ⤱愻楮慭楴湯琭浩湩ⵧ畦据楴湯挺扵捩戭穥敩⡲ⰰⰰ㈮ㄬ紩䁽敭楤⁡洨湩眭摩桴㘺〴硰笩献屭爺畯摮摥氭筧潢摲牥爭摡畩㩳㔮敲絭献屭戺潬正摻獩汰祡戺潬正⹽浳㩜瑩浥⵳散瑮牥慻楬湧椭整獭挺湥整絲献屭樺獵楴祦猭慴瑲橻獵楴祦挭湯整瑮昺敬⵸瑳牡絴献屭樺獵楴祦戭瑥敷湥橻獵楴祦挭湯整瑮猺慰散戭瑥敷湥⹽浳㩜⵨〲桻楥桧㩴爵浥⹽浳㩜汭〭浻牡楧⵮敬瑦〺⹽浳㩜硰㘭灻摡楤杮氭晥㩴⸱爵浥瀻摡楤杮爭杩瑨ㄺ㔮敲絭献屭瀺⵴笰慰摤湩ⵧ潴㩰細献屭琺硥⵴敬瑦瑻硥⵴污杩㩮敬瑦⹽浳㩜整瑸爭杩瑨瑻硥⵴污杩㩮楲桧絴䁽敭楤⁡洨湩眭摩桴㜺㠶硰笩洮層戺牯敤⵲⵴笰潢摲牥琭灯眭摩桴〺⹽摭㩜潢摲牥氭扻牯敤⵲敬瑦眭摩桴ㄺ硰⹽摭㩜牧摩挭汯⵳笲牧摩琭浥汰瑡ⵥ潣畬湭㩳敲数瑡㈨洬湩慭⡸ⰰ昱⥲紩䁽敭楤⁡洨湩眭摩桴ㄺ㈰瀴⥸⹻杬㩜硰㠭灻摡楤杮氭晥㩴爲浥瀻摡楤杮爭杩瑨㈺敲絭䁽敭楤⁡瀨敲敦獲挭汯牯猭档浥㩥慤歲笩搮牡屫戺ⵧ牧祡㠭〰⵻戭ⵧ灯捡瑩㩹㬱慢正牧畯摮挭汯牯⌺搲㜳㠴戻捡杫潲湵ⵤ潣潬㩲杲慢㐨ⰵ㔵㜬ⰲ慶⡲ⴭ杢漭慰楣祴⤩⹽慤歲㩜杢札慲⵹〹笰ⴭ杢漭慰楣祴ㄺ戻捡杫潲湵ⵤ潣潬㩲ㄣ㉡㈰㭣慢正牧畯摮挭汯牯爺执⡡㘲㌬ⰲ㐴瘬牡⴨戭ⵧ灯捡瑩⥹紩搮牡屫戺牯敤⵲牧祡㜭〰⵻戭牯敤⵲灯捡瑩㩹㬱潢摲牥挭汯牯⌺愴㔵㠶戻牯敤⵲潣潬㩲杲慢㜨ⰴ㔸ㄬ㐰瘬牡⴨戭牯敤⵲灯捡瑩⥹紩搮牡屫琺硥⵴桷瑩筥ⴭ整瑸漭慰楣祴ㄺ挻汯牯⌺晦㭦潣潬㩲杲慢㈨㔵㈬㔵㈬㔵瘬牡⴨琭硥⵴灯捡瑩⥹紩搮牡屫琺硥⵴牧祡㌭〰笠ⴠ琭硥⵴灯捡瑩㩹ㄠ※潣潬㩲⌠㉥㡥て※潣潬㩲爠执⡡㈲ⰶ㌲ⰲ㐲ⰰ慶⡲ⴭ整瑸漭慰楣祴⤩素੽††††⼼瑳汹㹥ਊ††††猼祴敬ਾ††††††潢祤笠 †††††††映湯⵴慦業祬›極猭湡⵳敳楲ⱦ猠獹整⵭極‬愭灰敬猭獹整Ɑ䈠楬歮慍卣獹整䙭湯ⱴ∠敓潧⁥䥕Ⱒ删扯瑯Ɐ∠效癬瑥捩⁡敎敵Ⱒ䄠楲污‬丢瑯慓獮Ⱒ猠湡⵳敳楲ⱦ∠灁汰⁥潃潬⁲浅橯≩‬匢来敯唠⁉浅橯≩‬匢来敯唠⁉祓扭汯Ⱒ∠潎潴䌠汯牯䔠潭楪㬢 †††††素 †††㰠猯祴敬ਾ††⼼敨摡ਾ††戼摯⁹汣獡㵳愢瑮慩楬獡摥戠ⵧ桷瑩⁥整瑸戭慬正㸢 †††㰠楤⁶汣獡㵳爢汥瑡癩⁥汦硥椠整獭琭灯樠獵楴祦挭湥整⁲業⵮⵨捳敲湥戠ⵧ桷瑩⁥整瑸戭慬正猠㩭瑩浥⵳散瑮牥猠㩭瑰〭•潲敬∽慭湩㸢 †††††㰠楤⁶汣獡㵳洢硡眭砭硭愭瑵浳瀺⵸‶杬瀺⵸∸ਾ††††††††搼癩挠慬獳∽汦硥椠整獭挭湥整⁲瑰㠭猠㩭番瑳晩⵹瑳牡⁴浳瀺⵴∰ਾ††††††††††格‱汣獡㵳瀢⵸‴整瑸氭⁧整瑸戭慬正戠牯敤⵲⁲潢摲牥札慲⵹〴∰ਾ††††††††††††〵‰†††††††††㰠栯㸱ਊ††††††††††搼癩挠慬獳∽汭㐭琠硥⵴杬琠硥⵴汢捡≫ਾ††††††††††††敓癲牥䔠牲牯††††††††††⼼楤㹶 †††††††㰠搯癩ਾ††††††⼼楤㹶 †††㰠搯癩ਾ††⼼潢祤ਾ⼼瑨汭ਾ