function makeNowPlaying()
{
    global $plex_instances;
    foreach ($plex_instances as $instance) {
        $plex_port = $instance[1];
        $network = getNetwork($instance[3]);
        $clientIP = get_client_ip();
        $plexSessionXML = simplexml_load_file($network . ':' . $plex_port . '/status/sessions');
        if (!$plexSessionXML) {
            makeRecenlyViewed();
        } elseif (count($plexSessionXML->Video) == 0) {
            makeRecenlyReleased();
        } else {
            $i = 0;
            // Initiate and assign a value to i & t
            $t = 0;
            // T is the total amount of sessions
            echo '<div class="col-md-10 col-sm-offset-1">';
            //echo '<div class="col-md-12">';
            foreach ($plexSessionXML->Video as $sessionInfo) {
                $t++;
            }
            foreach ($plexSessionXML->Video as $sessionInfo) {
                $mediaKey = $sessionInfo['key'];
                $playerTitle = $sessionInfo->Player['title'];
                $mediaXML = simplexml_load_file($network . ':' . $plex_port . $mediaKey);
                $type = $mediaXML->Video['type'];
                echo '<div class="thumbnail">';
                $i++;
                // Increment i every pass through the array
                if ($type == "movie") {
                    // Build information for a movie
                    $movieArt = $mediaXML->Video['thumb'];
                    $movieTitle = $mediaXML->Video['title'];
                    $duration = $plexSessionXML->Video[$i - 1]['duration'];
                    $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset'];
                    $progress = sprintf('%.0f', $viewOffset / $duration * 100);
                    $user = $plexSessionXML->Video[$i - 1]->User['title'];
                    $device = $plexSessionXML->Video[$i - 1]->Player['title'];
                    $state = $plexSessionXML->Video[$i - 1]->Player['state'];
                    // Truncate movie summary if it's more than 50 words
                    if (countWords($mediaXML->Video['summary']) < 51) {
                        $movieSummary = $mediaXML->Video['summary'];
                    } else {
                        $movieSummary = limitWords($mediaXML->Video['summary'], 50);
                        // Limit to 50 words
                        $movieSummary .= "...";
                        // Add ellipsis
                    }
                    echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $movieArt) . '" alt="' . $movieTitle . '">';
                    // Make now playing progress bar
                    //echo 'div id="now-playing-progress-bar">';
                    echo '<div class="progress now-playing-progress-bar">';
                    echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">';
                    echo '</div>';
                    echo '</div>';
                    echo '<div class="caption">';
                    //echo '<h2 class="exoextralight">'.$movieTitle.'</h2>';
                    echo '<p class="exolight" style="margin-top:5px;">' . $movieSummary . '</p>';
                    if ($state == "playing") {
                        // Show the playing icon
                        echo '<span class="glyphicon glyphicon-play"></span>';
                    } else {
                        echo '<span class="glyphicon glyphicon-pause"></span>';
                    }
                    if ($user == "") {
                        echo '<p class="exolight">' . $device . '</p>';
                    } else {
                        echo '<p class="exolight">' . $user . '</p>';
                    }
                } else {
                    // Build information for a tv show
                    $tvArt = $mediaXML->Video['grandparentThumb'];
                    $showTitle = $mediaXML->Video['grandparentTitle'];
                    $episodeTitle = $mediaXML->Video['title'];
                    $episodeSummary = $mediaXML->Video['summary'];
                    $episodeSeason = $mediaXML->Video['parentIndex'];
                    $episodeNumber = $mediaXML->Video['index'];
                    $duration = $plexSessionXML->Video[$i - 1]['duration'];
                    $viewOffset = $plexSessionXML->Video[$i - 1]['viewOffset'];
                    $progress = sprintf('%.0f', $viewOffset / $duration * 100);
                    $user = $plexSessionXML->Video[$i - 1]->User['title'];
                    $device = $plexSessionXML->Video[$i - 1]->Player['title'];
                    $state = $plexSessionXML->Video[$i - 1]->Player['state'];
                    //echo '<div class="img-overlay">';
                    echo '<img src="plex.php?img=' . urlencode($network . ':' . $plex_port . $tvArt) . '" alt="' . $showTitle . '">';
                    // Make now playing progress bar
                    //echo 'div id="now-playing-progress-bar">';
                    echo '<div class="progress now-playing-progress-bar">';
                    echo '<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="' . $progress . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $progress . '%">';
                    echo '</div>';
                    echo '</div>';
                    //echo '</div>';
                    // Make description below thumbnail
                    echo '<div class="caption">';
                    //echo '<h2 class="exoextralight">'.$showTitle.'</h2>';
                    echo '<h3 class="exoextralight" style="margin-top:5px;">Season ' . $episodeSeason . '</h3>';
                    echo '<h4 class="exoextralight" style="margin-top:5px;">E' . $episodeNumber . ' - ' . $episodeTitle . '</h4>';
                    // Truncate episode summary if it's more than 50 words
                    if (countWords($mediaXML->Video['summary']) < 51) {
                        $episodeSummary = $mediaXML->Video['summary'];
                    } else {
                        $episodeSummary = limitWords($mediaXML->Video['summary'], 50);
                        // Limit to 50 words
                        $episodeSummary .= "...";
                        // Add ellipsis
                    }
                    echo '<p class="exolight">' . $episodeSummary . '</p>';
                    if ($state == "playing") {
                        // Show the playing icon
                        echo '<span class="glyphicon glyphicon-play"></span>';
                    } else {
                        echo '<span class="glyphicon glyphicon-pause"></span>';
                    }
                    if ($user == "") {
                        echo '<p class="exolight">' . $device . '</p>';
                    } else {
                        echo '<p class="exolight">' . $user . '</p>';
                    }
                }
                // Action buttons if we ever want to do something with them.
                //echo '<p><a href="#" class="btn btn-primary">Action</a> <a href="#" class="btn btn-default">Action</a></p>';
                echo "</div>";
                echo "</div>";
                // Should we make <hr>? Only if there is more than one video and it's not the last thumbnail created.
                if ($i > 0 && $i < $t) {
                    echo '<hr>';
                } else {
                    // Do nothing
                }
            }
            echo '</div>';
        }
    }
}
Beispiel #2
0
 /**
  * Get the excerpt
  *
  * @filter the_excerpt
  * @filter get_the_excerpt
  * @filter fire/model/post/excerpt
  * @param  integer  $limit          Number of words/characters to limit to
  * @param  string   $append         String to append to trimmed excerpt
  * @param  boolean  $words          Whether to limit to words (true) or characters (false)
  * @param  boolean  $preserveWords  Limit to character number, but preserve full words
  * @param  boolean  $force          Use excerpt without stripping tags
  */
 public function excerpt($limit = null, $append = null, $words = true, $preserveWords = null, $force = false)
 {
     if ($this->excerpt and !$force) {
         $excerpt = $this->excerpt;
     } else {
         $excerpt = $this->excerpt ? $this->excerpt : $this->content;
         $excerpt = apply_filters('the_excerpt', apply_filters('get_the_excerpt', $excerpt));
         $excerpt = strip_tags(wp_kses_no_null(trim(strip_shortcodes($excerpt))));
     }
     if ($limit and strlen($excerpt) > $limit) {
         $excerpt = $words ? limitWords($excerpt, $limit, $append) : limitChars($excerpt, $limit, $append, $preserveWords);
     }
     return apply_filters('fire/model/post/excerpt', $excerpt, $this);
 }