username = iro_opt('my_anime_list_username'); $this->sort = iro_opt('my_anime_list_sort'); } /** * Get anime list with username from https://myanimelist.net/ * @author siroi * @author KotoriK * @author cocdeshijie */ function get_data() { $username = $this->username; $sort = $this->sort; switch ($sort) { case 1: // Status and Last Updated $sort = 'order=16&order2=5&status=7'; break; case 2: // Last Updated $sort = 'order=5&status=7'; break; case 3: // Status $sort = 'order=16&status=7'; break; } $url = "https://myanimelist.net/animelist/$username/load.json?$sort"; $args = array( 'headers' => array( 'Host' => 'myanimelist.net', 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97' ) ); $response = wp_remote_get($url, $args); if(is_array($response)){ return json_decode($response["body"], true); }else{ return false; } } public function get_all_items() { $resp = $this->get_data(); if ($resp === false) { return "
" . __('Backend error', 'sakurairo') . "
"; } else { $item_count = count($resp); $total_episodes = 0; foreach ((array)$resp as $item) { $html .= MyAnimeList::get_item_details($item); $total_episodes += $item['num_watched_episodes']; } $top_info = '
' . __('Following ', 'sakurairo') . $item_count . __(' anime.', 'sakurairo') . __(' Watched ', 'sakurairo') . $total_episodes . __(' episodes.', 'sakurairo') . '
'; $html = $top_info . $html . ''; return $html; } } private static function get_item_details(array $item) { return ''; } private static function get_image(string $image_path) { preg_match('/\/anime(.*?)\./', $image_path, $output); return "https://cdn.myanimelist.net/images/anime/$output[1].jpg"; } private static function bangumi_status(array $item) { switch($item['status']) { case 2: // Completed { return '
' . '

' . __('Finished ', 'sakurairo') . $item['num_watched_episodes'] . '/' . $item['anime_num_episodes'] . '

'; } case 1: // Watching { return '
' . '

' . __('Watching ', 'sakurairo') . $item['num_watched_episodes'] . '/' . $item['anime_num_episodes'] . '

'; } case 6: // Plan to watch { return '
' . '

' . __('Planning to Watch ', 'sakurairo') . '

'; } case 4: // Dropped { return '
' . '

' . __('Dropped ', 'sakurairo') . $item['num_watched_episodes'] . '/' . $item['anime_num_episodes'] . '

'; } case 3: // On Hold { return '
' . '

' . __('Paused ', 'sakurairo') . $item['num_watched_episodes'] . '/' . $item['anime_num_episodes'] . '

'; } default: // TODO: other possible status code { return ''; } } } private static function status_percent(array $item) { if ($item['anime_num_episodes'] == 0) { return 0; } else { return ($item['num_watched_episodes']/$item['anime_num_episodes']) * 100; } } }