Explorar o código

Merge pull request #535 from causefx/cero-dev

Refinement of Playlists
causefx %!s(int64=8) %!d(string=hai) anos
pai
achega
c427db3b23
Modificáronse 2 ficheiros con 73 adicións e 103 borrados
  1. 12 8
      functions.php
  2. 61 95
      homepage.php

+ 12 - 8
functions.php

@@ -666,9 +666,10 @@ function resolveEmbyItem($address, $token, $item, $nowPlaying = false, $showName
 }
 
 // Format item from Plex for Carousel
-function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false) {
+function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames = false, $role = false, $playlist = false) {
     // Static Height
-    $height = 444;    
+    $height = 444;  
+	$playlist = ($playlist) ? " playlist-$playlist" : "";  
 
     switch ($item['type']) {
     	case 'season':
@@ -866,7 +867,7 @@ function resolvePlexItem($server, $token, $item, $nowPlaying = false, $showNames
     if($nowPlaying){
         return '<div class="col-sm-6 col-md-3"><div class="thumbnail ultra-widget"><div style="display: none;" np="'.$id.'" class="overlay content-box small-box gray-bg">'.$streamInfo.'</div><span class="w-refresh w-p-icon gray" link="'.$id.'"><span class="fa-stack fa-lg" style="font-size: .5em"><i class="fa fa-square fa-stack-2x"></i><i class="fa fa-info-circle fa-stack-1x fa-inverse"></i></span></span><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img style="width: 500px; display:inherit;" src="'.$image_url.'" alt="'.$item['Name'].'"></a><div class="progress progress-bar-sm zero-m"><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="'.$watched.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$watched.'%"></div><div class="progress-bar palette-Grey-500 bg" style="width: '.$transcoded.'%"></div></div><div class="caption"><i style="float:left" class="fa fa-'.$state.'"></i>'.$topTitle.''.$bottomTitle.'</div></div></div>';
     }else{
-        return '<div class="item-'.$item['type'].'"><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
+        return '<div class="item-'.$item['type'].$playlist.'"><a class="openTab" openTab="'.$openTab.'" href="'.$address.'" target="_blank"><img alt="'.$item['Name'].'" class="'.$image.'" data-lazy="'.$image_url.'"></a><small style="margin-right: 13px" class="elip">'.$title.'</small></div>';
     }
 }
 
@@ -888,7 +889,7 @@ function outputRecentAdded($header, $items, $script = false, $array) {
         return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 class="text-center">'.$header.'</h5><p class="text-center">No Media Found</p></div>';
     }else{
 		$className = str_replace(' ', '', $header);
-        return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><div class="recentItems" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
+        return '<div id="recentMedia" class="content-box box-shadow big-box"><h5 style="margin-bottom: -20px" class="text-center">'.$header.'</h5><div class="recentHeader inbox-pagination '.$className.'">'.$hideMenu.'</div><br/><br/><div class="recentItems-recent" data-name="'.$className.'">'.implode('',$items).'</div></div>'.($script?'<script>'.$script.'</script>':'');
     }
     
 }
@@ -3664,6 +3665,7 @@ function getPlexPlaylists(){
 			// Identify the local machine
 			$gotServer = $getServer['machineIdentifier'];
 			$output = "";
+			$hideMenu = '<div class="pull-right"><div class="btn-group" role="group"><button type="button" id="playlist-Name" class="btn waves btn-default btn-sm dropdown-toggle waves-effect waves-float" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Choose A Playlist<span class="caret"></span></button><ul style="right:0; left: auto" class="dropdown-menu filter-recent-playlist">';
 			foreach($api AS $child) {
 				$items = "";
 				if ($child['playlistType'] == "video" && strpos(strtolower($child['title']) , 'private') === false){
@@ -3671,18 +3673,20 @@ function getPlexPlaylists(){
 					$api = simplexml_load_string($api);
 					if (is_array($api) || is_object($api)){
 						if (!$api->head->title){
+							$className = preg_replace("/(\W)+/", "", $api['title']);
+							$hideMenu .= '<li data-filter="playlist-'.$className.'" data-name="'.$api['title'].'"><a class="js-filter-'.$className.'" href="javascript:void(0)">'.$api['title'].'</a></li>';
 							foreach($api->Video AS $child){
-								$items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false);
+								$items[] = resolvePlexItem($gotServer, PLEXTOKEN, $child, false, false,false,$className);
 							}
 							if (count($items)) {
-								$className = preg_replace("/(\W)+/", "", $api['title']);
-								$output .= '<div id="playlist-'.$className.'" class="content-box box-shadow big-box"><h5 style="margin-bottom: -20px" class="text-center">'.$api['title'].'</h5><div class="recentHeader inbox-pagination '.$className.'"></div><br/><div class="recentItems" data-name="'.$className.'">'.implode('',$items).'</div></div>';
+								$output .= ''.implode('',$items).'';
 							}							
 						}
 					}
 				}
 			}
-			return $output;
+			$hideMenu .= '</ul></div></div>';
+			return '<div id="playlist-all" class="content-box box-shadow big-box"><h5 id="playlist-title" style="margin-bottom: -20px" class="text-center">All Playlists</h5><div class="recentHeader inbox-pagination all">'.$hideMenu.'</div><br/><br/><div class="recentItems-playlists" data-name="all">'.$output.'</div></div>';
 		}else{
 			writeLog("error", "PLEX PLAYLIST ERROR: could not connect - check token - if HTTPS, is cert valid");
 		}

+ 61 - 95
homepage.php

@@ -544,7 +544,7 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
         function localStorageSupport() {
             return (('localStorage' in window) && window['localStorage'] !== null)
         }
-		
+
         $( document ).ready(function() {
             $('#plexSearchForm').on('submit', function () {
                 var refreshBox = $(this).closest('div.content-box');
@@ -575,7 +575,7 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
                 $("div[np^='"+id+"']").toggle();
             });
 
-            $('.recentItems').each(function() {
+            $('div[class*=recentItems-]').each(function() {
                 var name = $(this).attr("data-name");
                 console.log(name);
                 $(this).slick({
@@ -665,103 +665,68 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
                 ]
                 });
             });
-
-            
+            //RECENT ITEMS
             // each filter we click on
             $(".filter-recent-event > li").on("click", function() {
+                    
+                // toggle the filter on/off
+                $(this).data( "filter-on" , !$(this).data("filter-on") );
                 
-            // toggle the filter on/off
-            $(this).data( "filter-on" , !$(this).data("filter-on") );
-            
-            // set all the filter strings to empty
-            var filtersOn = "";
-            var filtersOff = "";
-            var allFilters = "";
-            
-            // loop through each filter
-            $(".filter-recent-event > li").each(function() {
+                // set all the filter strings to empty
+                var filtersOn = "";
+                var filtersOff = "";
+                var allFilters = "";
                 
-                // set a variable to hold the value of the filter class
-                // and also if the filter is on/off
-                var filter = $(this).data("filter");
-                var isOn = $(this).data("filter-on");
+                // loop through each filter
+                $(".filter-recent-event > li").each(function() {
+                    
+                    // set a variable to hold the value of the filter class
+                    // and also if the filter is on/off
+                    var filter = $(this).data("filter");
+                    var isOn = $(this).data("filter-on");
 
-                // add the filter to the filtersOn / filtersOff collection
-                if( isOn ) {
-                    filtersOn += "." + filter + ", ";
-                } else {
-                    filtersOff += "." + filter + ", ";
-                }
+                    // add the filter to the filtersOn / filtersOff collection
+                    if( isOn ) {
+                        filtersOn += "." + filter + ", ";
+                    } else {
+                        filtersOff += "." + filter + ", ";
+                    }
 
-            });
-            
-            // remove the last ", " from each filter collection.
-            filtersOn = filtersOn.replace(/, $/, "");
-            filtersOff = filtersOff.replace(/, $/, "");
-            
-            // remove all filters if none are on.
-            if( filtersOn === "" ) {
-                filtersOn = "*";
-                filtersOff = "";
-            }
-            
-            // combine the filters together ( on + off )
-            allFilters = filtersOn + ":not(" + filtersOff + ")";
-            console.log( allFilters );
-            
-            // now filter the slides.
-            $('.recentItems ')
-                .slick('slickUnfilter')
-                .slick('slickFilter' , allFilters );
+                });
+                
+                // remove the last ", " from each filter collection.
+                filtersOn = filtersOn.replace(/, $/, "");
+                filtersOff = filtersOff.replace(/, $/, "");
+                
+                // remove all filters if none are on.
+                if( filtersOn === "" ) {
+                    filtersOn = "*";
+                    filtersOff = "";
+                }
+                
+                // combine the filters together ( on + off )
+                allFilters = filtersOn + ":not(" + filtersOff + ")";
+                console.log( allFilters );
+                
+                // now filter the slides.
+                $('.recentItems-recent')
+                    .slick('slickUnfilter')
+                    .slick('slickFilter' , allFilters );
 
             });
-            /*
-            var movieFiltered = false;
-            var seasonFiltered = false;
-            var albumFiltered = false;
+            //PLAYLIST SHIT
+             // each filter we click on
+            $(".filter-recent-playlist > li").on("click", function() {
+                var name = $(this).attr('data-name');
+                var filter = $(this).attr('data-filter');
+                $('#playlist-title').text(name);
+                
+                // now filter the slides.
+                $('.recentItems-playlists')
+                    .slick('slickUnfilter')
+                    .slick('slickFilter' , '.'+filter );
 
-            $('.js-filter-movie').on('click', function(){
-              if (movieFiltered === false) {
-                $('.recentItems').slick('slickFilter','.item-season, .item-album, .item-Series, .item-Episode, .item-MusicAlbum');
-                $(this).text('Show Movies');
-                movieFiltered = true;
-              } else {
-                $('.recentItems').slick('slickUnfilter');
-                $(this).text('Hide Movies');
-                movieFiltered = false;
-              }
-            });
-            
-            $('.js-filter-season').on('click', function(){
-              if (seasonFiltered === false) {
-                $('.recentItems').slick('slickFilter','.item-movie, .item-album, .item-Movie, .item-MusicAlbum');
-                $(this).text('Show TV');
-                seasonFiltered = true;
-              } else {
-                $('.recentItems').slick('slickUnfilter');
-                $(this).text('Hide TV');
-                seasonFiltered = false;
-              }
             });
-            
-            $('.js-filter-album').on('click', function(){
-              if (albumFiltered === false) {
-                $('.recentItems').slick('slickFilter','.item-season, .item-movie, .item-Series, .item-Episode, .item-Movie');
-                $(this).text('Show Music');
-                albumFiltered = true;
-              } else {
-                $('.recentItems').slick('slickUnfilter');
-                $(this).text('Hide Music');
-                albumFiltered = false;
-              }
-            });*/
-            
-            /*$('.w-refresh').click(function(e){
-                var moreInfo = $(this).closest('div.overlay').addClass("show");
-                console.log(moreInfo);
-                moreInfo.show();
-                e.preventDefault();
-            });*/
 
             $("body").niceScroll({
                 railpadding: {top:0,right:0,left:0,bottom:0},
@@ -773,11 +738,7 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
                 scrollspeed: 30,
                 mousescrollstep: 60
             });
-            /*$(".carousel-caption").niceScroll({
-                railpadding: {top:0,right:0,left:0,bottom:0},
-                scrollspeed: 30,
-                mousescrollstep: 60
-            });*/
+
             // check if browser support HTML5 local storage
 			
             <?php if((NZBGETURL != "" && qualifyUser(NZBGETHOMEAUTH)) || (SABNZBDURL != "" && qualifyUser(SABNZBDHOMEAUTH))){ ?>
@@ -796,7 +757,7 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
 
             // Initial Loads
             queueLoad();
-			         historyLoad();
+			historyLoad();
 
             // Interval Loads
             var queueInterval = setInterval(queueLoad, queueRefresh);
@@ -809,6 +770,11 @@ $endDate = date('Y-m-d',strtotime("+".CALENDARENDDAY." days"));
             });
             <?php } ?>
         });
+
+        $( window ).on( "load", function() {
+            $( "ul.filter-recent-playlist > li:first" ).trigger("click");
+        });
+
         </script>
         <?php if ((SONARRURL != "" && qualifyUser(SONARRHOMEAUTH)) || (RADARRURL != "" && qualifyUser(RADARRHOMEAUTH)) || (HEADPHONESURL != "" && qualifyUser(HEADPHONESHOMEAUTH)) || (SICKRAGEURL != "" && qualifyUser(SICKRAGEHOMEAUTH))) { ?>
         <script>