public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'index-index';
     $viewContext->layoutName = 'layout-headerless';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['myanimelist', 'mal', 'rating', 'favorites', 'score']);
     WebMediaHelper::addCustom($viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     try {
         if (empty($_POST['action'])) {
             throw new Exception('No action specified');
         }
         $action = $_POST['action'];
         if ($action == 'wipe-cache') {
             $deleted = 0;
             foreach ($controllerContext->cache->getAllFiles() as $path) {
                 $deleted++;
                 unlink($path);
             }
             $viewContext->messageType = 'info';
             $viewContext->message = 'Deleted ' . $deleted . ' files';
         } else {
             throw new Exception('Unknown action: ' . $action);
         }
     } catch (Exception $e) {
         $viewContext->messageType = 'error';
         $viewContext->message = $e->getMessage();
     }
     $viewContext->viewName = 'admin-index';
     $viewContext->meta->title = 'Admin — ' . Config::$title;
     WebMediaHelper::addCustom($viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-list';
     $viewContext->meta->title = $viewContext->user->name . ' — List (' . Media::toString($viewContext->media) . ') — ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' list.';
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
示例#4
0
 public function __construct()
 {
     $this->layoutName = 'layout';
     $this->viewName = null;
     $this->renderStart = microtime(true);
     $this->meta = new StdClass();
     $this->meta->description = Config::$title . ' (MALgraph) is an extension of your myanimelist.net profile, showing you various information about your anime and manga.';
     $this->meta->styles = [];
     $this->meta->scripts = [];
     WebMediaHelper::addBasic($this);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-list';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - list (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' list on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-profile';
     $viewContext->meta->title = $viewContext->user->name . '\'s profile — ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s profile.';
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->yearsOnMal = null;
     if (intval($viewContext->user->join_date)) {
         list($year, $month, $day) = explode('-', $viewContext->user->join_date);
         $time = mktime(0, 0, 0, $month, $day, $year);
         $diff = time() - $time;
         $diff /= 3600 * 24;
         $viewContext->yearsOnMal = $diff / 361.25;
     }
     $viewContext->friends = $viewContext->user->getFriends();
     $viewContext->finished = [];
     $viewContext->meanUserScore = [];
     $viewContext->meanGlobalScore = [];
     $viewContext->franchiseCount = [];
     $viewContext->mismatchedCount = [];
     foreach (Media::getConstList() as $media) {
         $list = $viewContext->user->getMixedUserMedia($media);
         $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
         $viewContext->finished[$media] = count($listFinished);
         unset($listFinished);
         $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
         $viewContext->meanUserScore[$media] = RatingDistribution::fromEntries($listNonPlanned)->getMeanScore();
         $franchises = Model_MixedUserMedia::getFranchises($listNonPlanned);
         $viewContext->franchiseCount[$media] = count(array_filter($franchises, function ($franchise) {
             return count($franchise->ownEntries) > 1;
         }));
         unset($franchises);
         unset($listNonPlanned);
         if ($media == Media::Anime) {
             $viewContext->episodes = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_episodes;
             }, $list));
         } else {
             $viewContext->chapters = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_chapters;
             }, $list));
         }
         $mismatched = $viewContext->user->getMismatchedUserMedia($list);
         $viewContext->mismatchedCount[$media] = count($mismatched);
         unset($mismatched);
         unset($list);
         $globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
         $viewContext->meanGlobalScore[$media] = array_map(function ($v) {
             return RatingDistribution::fromArray($v);
         }, $globalsCache['rating-dist'])[$media]->getMeanScore();
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-profile';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . '’s profile';
     $viewContext->meta->description = $viewContext->user->name . '’s profile on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $viewContext->yearsOnMal = null;
     if (intval($viewContext->user->join_date)) {
         list($year, $month, $day) = explode('-', $viewContext->user->join_date);
         $time = mktime(0, 0, 0, $month, $day, $year);
         $diff = time() - $time;
         $diff /= 3600 * 24;
         $viewContext->yearsOnMal = $diff / 361.25;
     }
     $viewContext->friends = $viewContext->user->getFriends();
     $viewContext->clubs = $viewContext->user->getClubs();
     $viewContext->finished = [];
     $viewContext->meanUserScore = [];
     $viewContext->meanGlobalScore = [];
     $viewContext->franchiseCount = [];
     $viewContext->mismatchedCount = [];
     foreach (Media::getConstList() as $media) {
         $list = $viewContext->user->getMixedUserMedia($media);
         $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
         $viewContext->finished[$media] = count($listFinished);
         unset($listFinished);
         $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
         $viewContext->meanUserScore[$media] = RatingDistribution::fromEntries($listNonPlanned)->getMeanScore();
         $viewContext->meanGlobalScore[$media] = Model_MixedUserMedia::getRatingDistribution($media)->getMeanScore();
         $franchises = Model_MixedUserMedia::getFranchises($listNonPlanned);
         $viewContext->franchiseCount[$media] = count(array_filter($franchises, function ($franchise) {
             return count($franchise->ownEntries) > 1;
         }));
         unset($franchises);
         unset($listNonPlanned);
         if ($media == Media::Anime) {
             $viewContext->episodes = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_episodes;
             }, $list));
         } else {
             $viewContext->chapters = array_sum(array_map(function ($mixedMediaEntry) {
                 return $mixedMediaEntry->finished_chapters;
             }, $list));
         }
         $mismatched = $viewContext->user->getMismatchedUserMedia($list);
         $viewContext->mismatchedCount[$media] = count($mismatched);
         unset($mismatched);
         unset($list);
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-favorites';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - favorites (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' favorites on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned);
     $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned);
     $favYears = MediaYearDistribution::fromEntries($listNonPlanned);
     $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned);
     $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned);
     $viewContext->favCreators = $favCreators;
     $viewContext->favGenres = $favGenres;
     $viewContext->favYears = $favYears;
     $viewContext->favDecades = $favDecades;
     $viewContext->favTypes = $favTypes;
     $distMeanScore = [];
     $distTimeSpent = [];
     foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) {
         $meanScore = [];
         $timeSpent = [];
         foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) {
             $meanScore[$safeKey] = 0;
             $timeSpent[$safeKey] = 0;
             $subEntries = $dist->getGroupEntries($key);
             $scoreCount = 0;
             foreach ($subEntries as $entry) {
                 $timeSpent[$safeKey] += $entry->finished_duration;
                 $meanScore[$safeKey] += $entry->score;
                 $scoreCount += $entry->score > 0;
             }
             $meanScore[$safeKey] /= max(1, $scoreCount);
         }
         $distMeanScore[get_class($dist)] = $meanScore;
         $distTimeSpent[get_class($dist)] = $timeSpent;
     }
     $viewContext->creatorScores = $distMeanScore[get_class($favCreators)];
     $viewContext->genreScores = $distMeanScore[get_class($favGenres)];
     $viewContext->yearScores = $distMeanScore[get_class($favYears)];
     $viewContext->decadeScores = $distMeanScore[get_class($favDecades)];
     $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)];
     $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)];
     $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes());
     $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres);
     $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators);
 }
示例#9
0
 public function __construct()
 {
     $this->layoutName = 'layout';
     $this->viewName = null;
     $this->renderStart = microtime(true);
     $this->meta = new StdClass();
     $this->meta->keywords = ['malgraph', 'anime', 'manga', 'statistics', 'stats'];
     $this->meta->description = 'MALgraph - an extension of your MyAnimeList profile. Check your rating distribution, get anime or manga recommendations, and compare numerous stats with other kawaii Japanese otaku.';
     $this->meta->styles = [];
     $this->meta->scripts = [];
     WebMediaHelper::addBasic($this);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-favorites';
     $viewContext->meta->title = $viewContext->user->name . ' — Favorites (' . Media::toString($viewContext->media) . ') — ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' favorites.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned);
     $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned);
     $favYears = MediaYearDistribution::fromEntries($listNonPlanned);
     $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned);
     $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned);
     $viewContext->favCreators = $favCreators;
     $viewContext->favGenres = $favGenres;
     $viewContext->favYears = $favYears;
     $viewContext->favDecades = $favDecades;
     $viewContext->favTypes = $favTypes;
     $distMeanScore = [];
     $distTimeSpent = [];
     foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) {
         $meanScore = [];
         $timeSpent = [];
         foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) {
             $meanScore[$safeKey] = 0;
             $timeSpent[$safeKey] = 0;
             $subEntries = $dist->getGroupEntries($key);
             $scoreCount = 0;
             foreach ($subEntries as $entry) {
                 $timeSpent[$safeKey] += $entry->finished_duration;
                 $meanScore[$safeKey] += $entry->score;
                 $scoreCount += $entry->score > 0;
             }
             $meanScore[$safeKey] /= max(1, $scoreCount);
         }
         $distMeanScore[get_class($dist)] = $meanScore;
         $distTimeSpent[get_class($dist)] = $timeSpent;
     }
     $viewContext->creatorScores = $distMeanScore[get_class($favCreators)];
     $viewContext->genreScores = $distMeanScore[get_class($favGenres)];
     $viewContext->yearScores = $distMeanScore[get_class($favYears)];
     $viewContext->decadeScores = $distMeanScore[get_class($favDecades)];
     $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)];
     $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)];
     $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes());
     $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres);
     $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-history';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - history (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' activity history on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
     $monthlyHistoryGroups = [];
     $unknownEntries = [];
     $max = 0;
     foreach ($listFinished as $entry) {
         $key = $entry->end_date;
         list($year, $month, $day) = array_map('intval', explode('-', $key));
         if (!$year or !$month) {
             $unknownEntries[] = $entry;
             continue;
         }
         if (!isset($monthlyHistoryGroups[$year])) {
             $monthlyHistoryGroups[$year] = [];
         }
         if (!isset($monthlyHistoryGroups[$year][$month])) {
             $monthlyHistoryGroups[$year][$month] = [];
         }
         $monthlyHistoryGroups[$year][$month][] = $entry;
         $max = max($max, count($monthlyHistoryGroups[$year][$month]));
     }
     krsort($monthlyHistoryGroups, SORT_NUMERIC);
     foreach ($monthlyHistoryGroups as &$group) {
         ksort($group, SORT_NUMERIC);
     }
     unset($group);
     $viewContext->monthlyHistoryMax = $max;
     $viewContext->monthlyHistoryGroups = $monthlyHistoryGroups;
     $viewContext->monthlyHistoryUnknownEntries = $unknownEntries;
     $dailyHistory = $viewContext->user->getHistory($viewContext->media);
     $dailyHistoryGroups = [];
     foreach ($dailyHistory as $historyEntry) {
         $key = date('Y-m-d', strtotime($historyEntry->timestamp));
         if (!isset($dailyHistoryGroups[$key])) {
             $dailyHistoryGroups[$key] = [];
         }
         $dailyHistoryGroups[$key][] = $historyEntry;
     }
     krsort($dailyHistoryGroups);
     $viewContext->dailyHistoryGroups = $dailyHistoryGroups;
     $viewContext->isPrivate = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-history';
     $viewContext->meta->title = $viewContext->user->name . ' — History (' . Media::toString($viewContext->media) . ') — ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' history.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
     $monthlyHistoryGroups = [];
     $unknownEntries = [];
     $max = 0;
     foreach ($listFinished as $entry) {
         $key = $entry->end_date;
         list($year, $month, $day) = array_map('intval', explode('-', $key));
         if (!$year or !$month) {
             $unknownEntries[] = $entry;
             continue;
         }
         if (!isset($monthlyHistoryGroups[$year])) {
             $monthlyHistoryGroups[$year] = [];
         }
         if (!isset($monthlyHistoryGroups[$year][$month])) {
             $monthlyHistoryGroups[$year][$month] = [];
         }
         $monthlyHistoryGroups[$year][$month][] = $entry;
         $max = max($max, count($monthlyHistoryGroups[$year][$month]));
     }
     krsort($monthlyHistoryGroups, SORT_NUMERIC);
     foreach ($monthlyHistoryGroups as &$group) {
         ksort($group, SORT_NUMERIC);
     }
     unset($group);
     $viewContext->monthlyHistoryMax = $max;
     $viewContext->monthlyHistoryGroups = $monthlyHistoryGroups;
     $viewContext->monthlyHistoryUnknownEntries = $unknownEntries;
     $dailyHistory = $viewContext->user->getHistory($viewContext->media);
     $dailyHistoryGroups = [];
     foreach ($dailyHistory as $historyEntry) {
         $key = date('Y-m-d', strtotime($historyEntry->timestamp));
         if (!isset($dailyHistoryGroups[$key])) {
             $dailyHistoryGroups[$key] = [];
         }
         $dailyHistoryGroups[$key][] = $historyEntry;
     }
     krsort($dailyHistoryGroups);
     $viewContext->dailyHistoryGroups = $dailyHistoryGroups;
     $viewContext->isPrivate = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'admin-login';
     $viewContext->meta->title = 'MALgraph - admin';
     WebMediaHelper::addCustom($viewContext);
     if (isset($_POST['password'])) {
         $viewContext->entered = $_POST['password'];
         $_SESSION['logged-in'] = $_POST['password'] == Config::$adminPassword;
         if ($_SESSION['logged-in']) {
             $url = AdminControllerIndexModule::url();
             $viewContext->viewName = null;
             HttpHeadersHelper::setCurrentHeader('Location', $url);
         }
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-ratings';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - rating statistics (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '’s ' . Media::toString($viewContext->media) . ' rating statistics on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'suggestions', 'recommendations']);
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addFarbtastic($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $list = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $viewContext->ratingDistribution = RatingDistribution::fromEntries($list);
     $viewContext->ratingTimeDistribution = RatingTimeDistribution::fromEntries($list);
     $listNoMovies = UserMediaFilter::doFilter($list, UserMediaFilter::nonMovie());
     $viewContext->lengthDistribution = MediaLengthDistribution::fromEntries($listNoMovies);
     $f = explode('-', $viewContext->user->join_date);
     if (count($f) != 3) {
         $viewContext->earliestTimeKnown = null;
         $viewContext->meanTime = null;
     } else {
         list($year, $month, $day) = $f;
         $earliest = mktime(0, 0, 0, $month, $day, $year);
         $totalTime = 0;
         foreach ($list as $mixedUserMedia) {
             $totalTime += $mixedUserMedia->finished_duration;
             foreach ([$mixedUserMedia->start_date, $mixedUserMedia->end_date] as $k) {
                 $f = explode('-', $k);
                 if (count($f) != 3) {
                     continue;
                 }
                 $year = intval($f[0]);
                 $month = intval($f[1]);
                 $day = intval($f[2]);
                 if (!$year or !$month or !$day) {
                     continue;
                 }
                 $time = mktime(0, 0, 0, $month, $day, $year);
                 if ($time < $earliest) {
                     $earliest = $time;
                 }
             }
         }
         $viewContext->earliestTimeKnown = $earliest;
         $viewContext->meanTime = $totalTime / max(1, (time() - $earliest) / (24.0 * 3600.0));
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-ratings';
     $viewContext->meta->title = $viewContext->user->name . ' &#8212; Ratings (' . Media::toString($viewContext->media) . ') &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' ratings.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addFarbtastic($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $list = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $viewContext->ratingDistribution = RatingDistribution::fromEntries($list);
     $viewContext->ratingTimeDistribution = RatingTimeDistribution::fromEntries($list);
     $listNoMovies = UserMediaFilter::doFilter($list, UserMediaFilter::nonMovie());
     $viewContext->lengthDistribution = MediaLengthDistribution::fromEntries($listNoMovies);
     $f = explode('-', $viewContext->user->join_date);
     if (count($f) != 3) {
         $viewContext->earliestTimeKnown = null;
         $viewContext->meanTime = null;
     } else {
         list($year, $month, $day) = $f;
         $earliest = mktime(0, 0, 0, $month, $day, $year);
         $totalTime = 0;
         foreach ($list as $mixedUserMedia) {
             $totalTime += $mixedUserMedia->finished_duration;
             foreach ([$mixedUserMedia->start_date, $mixedUserMedia->end_date] as $k) {
                 $f = explode('-', $k);
                 if (count($f) != 3) {
                     continue;
                 }
                 $year = intval($f[0]);
                 $month = intval($f[1]);
                 $day = intval($f[2]);
                 if (!$year or !$month or !$day) {
                     continue;
                 }
                 $time = mktime(0, 0, 0, $month, $day, $year);
                 if ($time < $earliest) {
                     $earliest = $time;
                 }
             }
         }
         $viewContext->earliestTimeKnown = $earliest;
         $viewContext->meanTime = $totalTime / max(1, (time() - $earliest) / (24.0 * 3600.0));
     }
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'index-globals';
     $viewContext->meta->title = 'MALgraph - global statistics';
     $viewContext->meta->description = 'Global community statistics on MALgraph, an online tool that extends your MyAnimeList profile.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addMiniSections($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $globalsCache = file_exists(Config::$globalsCachePath) ? TextHelper::loadJson(Config::$globalsCachePath, true) : [];
     $viewContext->userCount = $globalsCache['user-count'];
     $viewContext->mediaCount = $globalsCache['media-count'];
     $viewContext->ratingDistribution = array_map(function ($v) {
         return RatingDistribution::fromArray($v);
     }, $globalsCache['rating-dist']);
     $viewContext->queuedUserCount = (new Queue(Config::$userQueuePath))->size();
     $viewContext->queueSizes = TextHelper::loadJson(Config::$userQueueSizesPath, true);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-recommendations';
     $viewContext->meta->title = 'MALgraph - ' . $viewContext->user->name . ' - recommendations (' . Media::toString($viewContext->media) . ')';
     $viewContext->meta->description = $viewContext->user->name . '&rsquo;s ' . Media::toString($viewContext->media) . ' recommendations on MALgraph, an online tool that extends your MyAnimeList profile.';
     $viewContext->meta->keywords = array_merge($viewContext->meta->keywords, ['profile', 'list', 'achievements', 'ratings', 'history', 'favorites', 'recommendations']);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $recsEngine = new RecommendationsEngine($viewContext->media, $list);
     $goal = 10;
     $viewContext->newRecommendations = $recsEngine->getNewRecommendations($goal);
     $viewContext->franchises = $recsEngine->getMissingTitles();
     $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'index-index';
     $viewContext->layoutName = 'layout-headerless';
     WebMediaHelper::addCustom($viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'admin-index';
     $viewContext->meta->title = 'Admin &#8212; ' . Config::$title;
     WebMediaHelper::addCustom($viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-achievements';
     $viewContext->meta->title = $viewContext->user->name . ' &#8212; Achievements (' . Media::toString($viewContext->media) . ') &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' achievements.';
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $achList = self::getAchievementsDefinitions();
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listFinished = UserMediaFilter::doFilter($list, UserMediaFilter::finished());
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $listDropped = UserMediaFilter::doFilter($list, UserMediaFilter::dropped());
     $distribution = RatingDistribution::fromEntries($listNonPlanned);
     $evaluators = ['given-titles' => function ($groupData) use($listFinished) {
         $entriesOwned = UserMediaFilter::doFilter($listFinished, UserMediaFilter::givenMedia($groupData->requirement->titles));
         return [count($entriesOwned), $entriesOwned];
     }, 'genre-titles' => function ($groupData) use($viewContext, $listFinished) {
         $entriesOwned1 = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre($groupData->requirement->genre, $listFinished));
         $entriesOwned2 = !empty($groupData->requirement->titles) ? UserMediaFilter::doFilter($listFinished, UserMediaFilter::givenMedia($groupData->requirement->titles)) : [];
         $entriesOwned = array_merge($entriesOwned1, $entriesOwned2);
         #array unique w/ callback
         $entriesOwned = array_intersect_key($entriesOwned, array_unique(array_map(function ($e) {
             return $e->media . $e->mal_id;
         }, $entriesOwned)));
         return [count($entriesOwned), $entriesOwned];
     }, 'pervert' => function ($groupData) use($viewContext, $listFinished) {
         $entriesTotalCount = count($listFinished);
         if ($entriesTotalCount > 0) {
             $entriesEcchi = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre(9, $listFinished));
             $entriesHentai = UserMediaFilter::doFilter($listFinished, UserMediaFilter::genre(12, $listFinished));
             $score = 100 / $entriesTotalCount * (count($entriesEcchi) * 2 + count($entriesHentai) * 4);
             if ($score > 100) {
                 $score = 100;
             }
             $entries = array_merge($entriesEcchi, $entriesHentai);
             $entries = array_intersect_key($entries, array_unique(array_map(function ($e) {
                 return $e->media . $e->mal_id;
             }, $entries)));
             return [$score, $entries];
         }
         return [0, null];
     }, 'finished-titles' => function ($groupData) use($listFinished) {
         return [count($listFinished), null];
     }, 'mean-score' => function ($groupData) use($listNonPlanned, $distribution) {
         if ($distribution->getRatedCount() > 0) {
             return [$distribution->getMeanScore(), null];
         }
         return [null, null];
     }, 'no-drop' => function ($groupData) use($listFinished, $listDropped) {
         if (count($listDropped) > 0) {
             return [0, null];
         }
         return [count($listFinished), null];
     }, 'old-titles' => function ($groupData) use($listFinished) {
         $entriesOwned = UserMediaFilter::doFilter($listFinished, function ($row) {
             $year = substr($row->published_to, 0, 4);
             return $year != '0000' and intval($year) <= 1980;
         });
         return [count($entriesOwned), $entriesOwned];
     }];
     $viewContext->rito = "";
     $achievements = [];
     $hiddenCount = 0;
     foreach ($achList[$viewContext->media] as $group => $groupData) {
         //get subject and entries basing on requirement type
         $evaluator = $evaluators[$groupData->requirement->type];
         list($subject, $entriesOwned) = $evaluator($groupData);
         $groupData->achievements = array_reverse($groupData->achievements);
         if ($subject === null) {
             continue;
         }
         //give first achievement for which the subject fits into its threshold
         $localAchievements = [];
         foreach ($groupData->achievements as &$ach) {
             list($a, $b) = self::getThreshold($ach);
             $ach->thresholdLeft = $a;
             $ach->thresholdRight = $b;
             $ach->earned = (($subject >= $a or $a === null) and ($subject <= $b or $b === null));
             if ($ach->next and $ach->next->earned) {
                 $ach->earned = true;
                 $ach->hidden = true;
                 $hiddenCount++;
             } else {
                 $ach->hidden = false;
             }
             if ($ach->earned) {
                 //put additional info
                 if (!empty($entriesOwned)) {
                     DataSorter::sort($entriesOwned, DataSorter::Title);
                     $ach->entries = $entriesOwned;
                 }
                 $ach->progress = 100;
                 $ach->subject = round($subject, 2);
                 if ($ach->next) {
                     $ach->progress = ($subject - $a) * 100.0 / ($ach->next->thresholdLeft - $a);
                 }
                 $localAchievements[] = $ach;
             }
         }
         $achievements = array_merge($achievements, array_reverse($localAchievements));
     }
     $viewContext->achievements = $achievements;
     $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media);
     $viewContext->hiddenCount = $hiddenCount;
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-recommendations';
     $viewContext->meta->title = $viewContext->user->name . ' &#8212; Recommendations (' . Media::toString($viewContext->media) . ') &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' recommendations.';
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $recsEngine = new RecommendationsEngine($viewContext->media, $list);
     $goal = 20;
     $viewContext->newRecommendations = $recsEngine->getNewRecommendations($goal);
     $viewContext->franchises = $recsEngine->getMissingTitles();
     $viewContext->missingTitlesCount = $recsEngine->getMissingTitlesCount($viewContext->franchises);
     $viewContext->private = $viewContext->user->isUserMediaPrivate($viewContext->media);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'index-about';
     $viewContext->meta->title = 'MALgraph - about';
     WebMediaHelper::addCustom($viewContext);
 }
 public static function work(&$controllerContext, &$viewContext)
 {
     $viewContext->viewName = 'user-favorites';
     $viewContext->meta->title = $viewContext->user->name . ' &#8212; Favorites (' . Media::toString($viewContext->media) . ') &#8212; ' . Config::$title;
     $viewContext->meta->description = $viewContext->user->name . '\'s ' . Media::toString($viewContext->media) . ' favorites.';
     WebMediaHelper::addHighcharts($viewContext);
     WebMediaHelper::addTablesorter($viewContext);
     WebMediaHelper::addInfobox($viewContext);
     WebMediaHelper::addEntries($viewContext);
     WebMediaHelper::addCustom($viewContext);
     $list = $viewContext->user->getMixedUserMedia($viewContext->media);
     $listNonPlanned = UserMediaFilter::doFilter($list, UserMediaFilter::nonPlanned());
     $favCreators = MediaCreatorDistribution::fromEntries($listNonPlanned);
     $favGenres = MediaGenreDistribution::fromEntries($listNonPlanned);
     $favYears = MediaYearDistribution::fromEntries($listNonPlanned);
     $favDecades = MediaDecadeDistribution::fromEntries($listNonPlanned);
     $favTypes = MediaTypeDistribution::fromEntries($listNonPlanned);
     $viewContext->yearName = ["", MediaType::toString(1, $viewContext->media), '', 'Dropped/On-Hold'];
     $favWatchedYears = [];
     foreach ($favTypes->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY | AbstractDistribution::IGNORE_EMPTY_GROUPS) as $type) {
         if ($type != 1) {
             $viewContext->yearName[2] .= ucfirst(MediaType::toString($type, $viewContext->media) . '/');
         }
         foreach ($favTypes->getGroupEntries($type) as $entry) {
             $category = 2;
             if ($entry->sub_type == 1) {
                 $category = 1;
             }
             if ($entry->status == UserListStatus::Dropped || $entry->status == UserListStatus::OnHold) {
                 $category = 3;
             }
             $favWatchedYears[$category][MediaYearDistribution::getPublishedYear($entry)][] = $entry;
         }
     }
     $viewContext->yearName[2] = trim($viewContext->yearName[2], '/');
     $favWatchedDecades = [];
     foreach ($favTypes->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY | AbstractDistribution::IGNORE_EMPTY_GROUPS) as $type) {
         foreach ($favTypes->getGroupEntries($type) as $entry) {
             $category = 2;
             if ($entry->sub_type == 1) {
                 $category = 1;
             }
             if ($entry->status == UserListStatus::Dropped || $entry->status == UserListStatus::OnHold) {
                 $category = 3;
             }
             $favWatchedDecades[$category][MediaDecadeDistribution::getPublishedDecade($entry)][] = $entry;
         }
     }
     $maxYear = max(array_keys($favYears->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY)));
     $maxDecade = max(array_keys($favDecades->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY)));
     for ($i = 1; $i < 4; $i++) {
         if (!isset($favWatchedYears[$i])) {
             $favWatchedYears[$i][$maxYear] = [];
         }
         if (!isset($favWatchedDecades[$i])) {
             $favWatchedDecades[$i][$maxDecade] = [];
         }
     }
     $viewContext->favCreators = $favCreators;
     $viewContext->favGenres = $favGenres;
     $viewContext->favYears = $favYears;
     $viewContext->favDecades = $favDecades;
     $viewContext->favTypes = $favTypes;
     $viewContext->favWatchedYears = $favWatchedYears;
     $viewContext->favWatchedDecades = $favWatchedDecades;
     $distMeanScore = [];
     $distTimeSpent = [];
     foreach ([$favCreators, $favGenres, $favDecades, $favYears] as $dist) {
         $meanScore = [];
         $timeSpent = [];
         foreach ($dist->getGroupsKeys(AbstractDistribution::IGNORE_NULL_KEY) as $safeKey => $key) {
             $meanScore[$safeKey] = 0;
             $timeSpent[$safeKey] = 0;
             $subEntries = $dist->getGroupEntries($key);
             $scoreCount = 0;
             foreach ($subEntries as $entry) {
                 $timeSpent[$safeKey] += $entry->finished_duration;
                 $meanScore[$safeKey] += $entry->score;
                 $scoreCount += $entry->score > 0;
             }
             $meanScore[$safeKey] /= max(1, $scoreCount);
         }
         $distMeanScore[get_class($dist)] = $meanScore;
         $distTimeSpent[get_class($dist)] = $timeSpent;
     }
     $viewContext->creatorScores = $distMeanScore[get_class($favCreators)];
     $viewContext->genreScores = $distMeanScore[get_class($favGenres)];
     $viewContext->yearScores = $distMeanScore[get_class($favYears)];
     $viewContext->decadeScores = $distMeanScore[get_class($favDecades)];
     $viewContext->creatorTimeSpent = $distTimeSpent[get_class($favCreators)];
     $viewContext->genreTimeSpent = $distTimeSpent[get_class($favGenres)];
     $viewContext->typePercentages = TextHelper::roundPercentages($favTypes->getGroupsSizes());
     $viewContext->genreValues = DistributionEvaluator::evaluate($favGenres);
     $viewContext->creatorValues = DistributionEvaluator::evaluate($favCreators);
 }
示例#24
0
<?php

require_once __DIR__ . '/../src/core.php';
touch(Config::$userQueuePath);
touch(Config::$userQueueSizesPath);
touch(Config::$mediaQueuePath);
touch(Config::$bannedUsersListPath);
WebMediaHelper::download();
 public static function work(&$controllerContext, &$viewContext)
 {
     try {
         if (empty($_POST['sender'])) {
             throw new Exception('No sender specified');
         }
         $sender = $_POST['sender'];
         if (empty($_POST['action'])) {
             throw new Exception('No action specified');
         }
         $action = $_POST['action'];
         if (empty($_POST['model-ids'])) {
             throw new Exception('No model ids specified');
         }
         $modelIds = array_map('trim', preg_split('/[,;]/', $_POST['model-ids']));
         $chosenMedia = [];
         $chosenUsers = [];
         switch ($sender) {
             case 'media':
                 $chosenMedia = self::getChosenMedia($modelIds);
                 break;
             case 'user':
                 $chosenUsers = self::getChosenUsers($modelIds);
                 break;
             default:
                 throw new Exception('Unknown sender: ' . $sender);
         }
         if ($action == 'refresh') {
             $num = 0;
             $startTime = microtime(true);
             $mediaProcessors = [Media::Anime => new AnimeProcessor(), Media::Manga => new MangaProcessor()];
             $userProcessor = new UserProcessor();
             foreach ($chosenMedia as $media => $ids) {
                 foreach ($ids as $id) {
                     $mediaProcessors[$media]->process($id);
                     ++$num;
                 }
             }
             foreach ($chosenUsers as $user) {
                 $userProcessor->process($user);
                 ++$num;
             }
             $viewContext->messageType = 'info';
             $viewContext->message = sprintf('Successfully processed %d entities in %.02fs', $num, microtime(true) - $startTime);
         } elseif ($action == 'wipe-cache') {
             $deleted = 0;
             foreach ($chosenUsers as $userName) {
                 $cache = new Cache();
                 $cache->setPrefix($userName);
                 foreach ($cache->getAllFiles() as $path) {
                     $deleted++;
                     unlink($path);
                 }
             }
             $viewContext->messageType = 'info';
             $viewContext->message = 'Deleted ' . $deleted . ' files';
         } elseif ($action == 'unban' or $action == 'soft-ban' or $action == 'hard-ban') {
             switch ($action) {
                 case 'unban':
                     $banState = BanHelper::USER_BAN_NONE;
                     break;
                 case 'soft-ban':
                     $banState = BanHelper::USER_BAN_QUEUE_ONLY;
                     break;
                 case 'hard-ban':
                     $banState = BanHelper::USER_BAN_TOTAL;
                     break;
                 default:
                     throw new Exception('Wrong ban state');
             }
             $changed = 0;
             foreach ($chosenUsers as $userName) {
                 BanHelper::setUserBanState($userName, $banState);
                 ++$changed;
             }
             $viewContext->messageType = 'info';
             $viewContext->message = sprintf('Successfully updated %d users', $changed);
         } elseif ($action == 'reset-franchise') {
             $num = 0;
             foreach ($chosenMedia as $media => $ids) {
                 $query = 'UPDATE media SET franchise = NULL WHERE media = ? AND mal_id IN (' . R::genSlots($ids) . ')';
                 R::exec($query, array_merge([$media], $ids));
                 $num += count($ids);
             }
             $viewContext->messageType = 'info';
             $viewContext->message = sprintf('Successfully reset franchise for %d entities. Don\'t forget to refresh them now!', $num);
         } elseif ($action == 'remove') {
             $num = 0;
             foreach ($chosenMedia as $media => $ids) {
                 $query = 'DELETE FROM media WHERE media = ? AND mal_id IN (' . R::genSlots($ids) . ')';
                 R::exec($query, array_merge([$media], $ids));
                 $num += count($ids);
             }
             $viewContext->messageType = 'info';
             $viewContext->message = sprintf('Successfully removed %d entities.', $num);
         } else {
             throw new Exception('Unknown action: ' . $action);
         }
     } catch (Exception $e) {
         $viewContext->messageType = 'error';
         $viewContext->message = $e->getMessage();
     }
     $viewContext->viewName = 'admin-index';
     $viewContext->meta->title = 'Admin &#8212; ' . Config::$title;
     WebMediaHelper::addCustom($viewContext);
 }