/* ** Function to Use the Gift search page, when the Property Search is used. */ function custom_tax_page_template( $template ) { //Initiate a Blank New Template $new_template = ''; //For Movies & Music if ( is_singular( 'movie' ) ) $new_template = locate_template( array( 'movies/single.php' ) ); elseif ( is_singular( 'tv' ) ) $new_template = locate_template( array( 'tv/single.php' ) ); //Taxonomies if ( is_tax( 'movie_year' ) ) $new_template = locate_template( array( 'movies/archives/movie_year.php' ) ); elseif ( is_tax( 'movie_genre')) $new_template = locate_template( array( 'movies/archives/movie_genre.php' ) ); elseif ( is_tax( 'movie_actor')) $new_template = locate_template( array( 'movies/archives/movie_actor.php' ) ); elseif ( is_tax( 'movie_director')) $new_template = locate_template( array( 'movies/archives/movie_director.php' ) ); elseif ( is_tax( 'movie_language')) $new_template = locate_template( array( 'movies/archives/movie_language.php' ) ); elseif ( is_tax( 'album')) $new_template = locate_template( array( 'music/archives/album.php' ) ); elseif ( is_tax( 'mtag')) $new_template = locate_template( array( 'music/archives/mtag.php' ) ); elseif ( is_tax( 'music_director')) $new_template = locate_template( array( 'music/archives/music_director.php' ) ); elseif ( is_tax( 'music_genre')) $new_template = locate_template( array( 'music/archives/music_genre.php' ) ); elseif ( is_tax( 'music_language')) $new_template = locate_template( array( 'music/archives/music_language.php' ) ); elseif ( is_tax( 'singer')) $new_template = locate_template( array( 'music/archives/singer.php' ) ); elseif ( is_tax( 'tv_actor')) $new_template = locate_template( array( 'tv/archives/tv_actor.php' ) ); elseif ( is_tax( 'tv_creator')) $new_template = locate_template( array( 'tv/archives/tv_creator.php' ) ); elseif ( is_tax( 'tv_lang')) $new_template = locate_template( array( 'tv/archives/tv_lang.php' ) ); elseif ( is_tax( 'tv_year')) $new_template = locate_template( array( 'tv/archives/tv_year.php' ) ); elseif ( is_tax( 'tv_genre')) $new_template = locate_template( array( 'tv/archives/tv_genre.php' ) ); elseif ( is_tax( 'tv_channel')) $new_template = locate_template( array( 'tv/archives/tv_channel.php' ) ); //For Battle if ( is_singular( 'battle' ) ) $new_template = locate_template( array( 'battles/single.php' ) ); elseif (is_singular( 'top_grossers' )) $new_template = locate_template( array( 'top_grossers/single.php' ) ); elseif (is_singular( 'analytics' )) $new_template = locate_template( array( 'analytics/single.php' ) ); elseif (is_singular( 'singer_battle' )) $new_template = locate_template( array( 'music/singer-battle/single.php' ) ); elseif (is_singular( 'song' )) $new_template = locate_template( array( 'music/song-single/single.php' ) ); if (is_category( 'Box Office' )) $new_template = locate_template( array( 'page-templates/category-box-office-updates.php' ) ); elseif (is_category( 'Trailers' )) $new_template = locate_template( array( 'page-templates/category-trailers.php' ) ); //Return Default stuff is nothing unique is found if ( '' != $new_template ) { return $new_template ; } return $template; } add_filter( 'template_include', 'custom_tax_page_template', 99 ); /* Template Name: BOTY TV API (Year) */ if (!current_user_can( 'edit_posts' )) exit(); // Load the Google API PHP Client Library. require_once __DIR__ . '/../real-time-pop/gc/vendor/autoload.php'; if (!get_transient( 'tv_stats' )) : $analytics = initializeAnalytics(); $response = getReport($analytics); $array_of_tv = printResults($response); set_transient( 'tv_stats', $array_of_tv, 60*60 ); else : $array_of_tv = get_transient( 'tv_stats' ); endif; //var_dump($array_of_tv); $tv_list = array(); foreach ($array_of_tv as $movie) : $m = explode("/", $movie[0]); $tv_list[$m[2]] = $movie[1]; endforeach; /** * Initializes an Analytics Reporting API V4 service object. * * @return An authorized Analytics Reporting API V4 service object. */ function initializeAnalytics() { // Use the developers console and download your service account // credentials in JSON format. Place them in this directory or // change the key file location if necessary. $KEY_FILE_LOCATION = __DIR__ . '/../real-time-pop/service-account-credentials.json'; // Create and configure a new client object. $client = new Google_Client(); $client->setApplicationName("Hello Analytics Reporting"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']); $analytics = new Google_Service_AnalyticsReporting($client); return $analytics; } /** * Queries the Analytics Reporting API V4. * * @param service An authorized Analytics Reporting API V4 service object. * @return The Analytics Reporting API V4 response. */ function getReport($analytics) { // Replace with your view ID, for example XXXX. $VIEW_ID = "118849341"; // Create the DateRange object. $dateRange = new Google_Service_AnalyticsReporting_DateRange(); $dateRange->setStartDate("yesterday"); $dateRange->setEndDate("today"); // Create the Metrics object. $sessions = new Google_Service_AnalyticsReporting_Metric(); $sessions->setExpression("ga:sessions"); $sessions->setAlias("sessions"); $pageviews = new Google_Service_AnalyticsReporting_Metric(); $pageviews->setExpression("ga:pageviews"); $pageviews->setAlias("pageviews"); //Create the Dimensions object. $pagePath = new Google_Service_AnalyticsReporting_Dimension(); $pagePath->setName("ga:pagePath"); $ordering = new Google_Service_AnalyticsReporting_OrderBy(); $ordering->setFieldName("ga:pageviews"); $ordering->setOrderType("VALUE"); $ordering->setSortOrder("DESCENDING"); // Create the ReportRequest object. $request = new Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($VIEW_ID); $request->setDateRanges($dateRange); $request->setDimensions(array($pagePath)); $request->setMetrics(array($sessions, $pageviews)); $request->setOrderBys($ordering); $request->setPageSize(1000); $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests( array( $request) ); //var_dump($body); return $analytics->reports->batchGet( $body ); } /** * Parses and prints the Analytics Reporting API V4 response. * @param An Analytics Reporting API V4 response. */ function printResults($reports) { $pages = $reports->reports[0]->data->rows; $arr = []; foreach ($pages as $page) : $slug = $page->dimensions[0]; $count = $page->metrics[0]->values[1]; if (strpos($slug, '/tv-serial/') !== false ) { //found at start $arr[] = array($slug, $count); } endforeach; return $arr; } // End Google Anlytics $paged = 1; if (isset($_GET['p'])) : $paged = $_GET['p']; endif; $args = array( 'post_type' => 'tv', 'posts_per_page' => 300, 'paged' => $paged, 'post_status' => 'any', ); $q = new WP_Query( $args ); ?>