Example #1
0
            //include("$absoluteurl"."core/archive_nocat.php");
            $PG_mainbody .= showPodcastEpisodes(1, NULL);
        }
    } elseif ($_GET['p'] == "ftpfeature") {
        //To place in admin
        include "{$absoluteurl}" . "core/ftpfeature.php";
    } else {
        //show recent episodes (don't show all episodes) - no categories distinction
        $PG_mainbody .= showPodcastEpisodes(0, 0);
        //parameter, is bool yes or not (all episodes?), the second parameter is the category
        $PG_mainbody .= '<div style="clear:both;"><p><a href="' . $url . '?p=archive&amp;cat=all"><i class="fa fa-archive"></i> ' . _("Go to episodes archive") . '</a></p></div>';
    }
} elseif (isset($_GET['name'])) {
    //include("$absoluteurl"."core/episode.php");
    $PG_mainbody .= showSingleEpisode(avoidXSS($_GET['name']), NULL);
} else {
    // if no p= specifies, e.g. just index.php with no GET
    //show recent episodes (don't show all episodes) - no categories distinction
    $PG_mainbody .= showPodcastEpisodes(0, 0);
    //parameter, is bool yes or not (all episodes?), the second parameter is the category
    $PG_mainbody .= '<div style="clear:both;"><p><a href="' . $url . '?p=archive&amp;cat=all"><i class="fa fa-archive"></i> ' . _("Go to episodes archive") . '</a></p></div>';
}
//If the theme folder contains theme.xml then it's a theme for PG 2.0+ with new features and we use the new template engine templates.php
if (useNewThemeEngine($theme_path)) {
    //if function is TRUE
    include "{$absoluteurl}" . "core/templates.php";
} else {
    //otherwise use the old theme engine (themes.php) for retrocompatibility
    include "{$absoluteurl}" . "core/themes.php";
}
echo $theme_file_contents;
function showPodcastEpisodes($all, $category)
{
    include "core/includes.php";
    $finalOutputEpisodes = NULL;
    // declare final output to return
    if ($all == TRUE) {
        $max_recent = NULL;
        //reset limitation for recent episodes set in config.php
        $categoryURLforPagination = "&cat=all";
        //preserve category in links in number of pages at the button
        //don't show social networks when noextras is appended to the URL
        if (isset($_GET['noextras'])) {
            $disableextras = TRUE;
            $categoryURLforPagination .= "&noextras";
            //preserve category in links in number of pages at the button
        }
    } else {
        // in home page, do not paginate but use $max_recent
        $episodeperpage = 999999;
        //do not use pagination (workaround - could be more elegant)
    }
    /// Header for Category (RSS and Title)
    if (isset($category) and $category != NULL) {
        $CounterEpisodesInCategory = 0;
        // set counter to 0
        $category = avoidXSS($category);
        //URL depuration
        $categoryURLforPagination = "&cat=" . $category;
        //retrieve existing categories (description/long name)
        //NB $existingCategories[$category] is category full name (not just ID)
        $existingCategories = readPodcastCategories($absoluteurl);
        $category_header = '<div>';
        if (isset($existingCategories[$category])) {
            $category_header .= '<h3 class="sectionTitle"><a href="' . $url . 'feed.php?cat=' . $category . '"><i class="fa fa-rss "></i> ' . $existingCategories[$category] . '</a></h3>';
        }
        $category_header .= '</div>';
    }
    // Open podcast directory and read all the files contained
    $fileNamesList = readMediaDir($absoluteurl, $upload_dir);
    if (empty($fileNamesList)) {
        // If media directory is empty
        $finalOutputEpisodes .= '<div class="topseparator"><p>' . _("No episodes here yet...") . '</p></div>';
    } else {
        // If media directory contains files
        $episodesCounter = 0;
        //set counter to zero
        //if isset pagination variable in GET
        if (isset($_GET["pgn"]) and is_numeric($_GET["pgn"])) {
            $maxC = $episodeperpage * $_GET["pgn"];
            $minC = $episodeperpage * $_GET["pgn"] - $episodeperpage;
        } else {
            $maxC = $episodeperpage;
            $minC = 0;
        }
        // Loop through each file in the media directory
        foreach ($fileNamesList as $singleFileName) {
            $resulting_episodes = NULL;
            //declare the 1st time and then reset
            //If current episode won't be displayed in this page, skip it and break the loop
            if ($episodesCounter > $maxC) {
                //NB. count($fileNamesList)/2 is the total number of episodes
                $episodesCounter = count($fileNamesList) / 2;
                break;
            } else {
                if ($episodesCounter < $max_recent or $max_recent == NULL) {
                    ////Validate the current episode
                    //NB. validateSingleEpisode returns [0] episode is supported (bool), [1] Episode Absolute path, [2] Episode XML DB absolute path,[3] File Extension (Type), [4] File MimeType, [5] File name without extension, [6] episode file supported but to XML present
                    $thisPodcastEpisode = validateSingleEpisode($singleFileName);
                    ////If episode is supported and has a related xml db, and if it's not set to a future date OR if it's set for a future date but you are logged in as admin
                    if ($thisPodcastEpisode[0] == TRUE and !publishInFuture($thisPodcastEpisode[1]) or $thisPodcastEpisode[0] == TRUE and publishInFuture($thisPodcastEpisode[1]) and isUserLogged()) {
                        ////Parse XML data related to the episode
                        // NB. Function parseXMLepisodeData returns: [0] episode title, [1] short description, [2] long description, [3] image associated, [4] iTunes keywords, [5] Explicit language,[6] Author's name,[7] Author's email,[8] PG category 1, [9] PG category 2, [10] PG category 3, [11] file_info_size, [12] file_info_duration, [13] file_info_bitrate, [14] file_info_frequency, [15] embedded image in mp3
                        $thisPodcastEpisodeData = parseXMLepisodeData($thisPodcastEpisode[2]);
                        ////if category is specified as a parameter of this function
                        if (isset($category) and $category != NULL) {
                            //if category is not associated to the current episode
                            if ($category != $thisPodcastEpisodeData[8] and $category != $thisPodcastEpisodeData[9] and $category != $thisPodcastEpisodeData[10]) {
                                continue;
                                //STOP this cycle and start a new one
                            } else {
                                $CounterEpisodesInCategory++;
                                // Incremente episodes counter
                            }
                        }
                        //// Start constructing episode HTML output
                        //Theme engine PG version >= 2.0
                        if (useNewThemeEngine($theme_path)) {
                            //episodes per line in some themes (e.g. bootstrap)
                            $numberOfEpisodesPerLine = 2;
                            //If the current episode number is multiple of $numberOfEpisodesPerLine
                            if ($episodesCounter % $numberOfEpisodesPerLine != 0 or $episodesCounter == count($fileNamesList)) {
                                //open div with class row-fluid (theme based on bootstrap)
                                //N.B. row-fluid is a CSS class for a div containing 1 or more episodes
                                //$resulting_episodes .= '<div class="row-fluid">';
                                $resulting_episodes .= '<div class="episode">';
                            }
                            $resulting_episodes .= '<div class="span6 col-md-6 6u episodebox">';
                            //open the single episode DIV
                        } else {
                            $resulting_episodes .= '<div class="episode">';
                            //open the single episode DIV
                        }
                        ////Title
                        $resulting_episodes .= '<h3 class="episode_title"><a href="?name=' . $thisPodcastEpisode[5] . '.' . $thisPodcastEpisode[3] . '">' . $thisPodcastEpisodeData[0];
                        if (isItAvideo($thisPodcastEpisode[3])) {
                            $resulting_episodes .= '&nbsp;<i class="fa fa-youtube-play"></i>';
                        }
                        //add video icon
                        $resulting_episodes .= '</a></h3>';
                        ////Date
                        $resulting_episodes .= '<p class="episode_date">';
                        $thisEpisodeDate = filemtime($thisPodcastEpisode[1]);
                        if ($thisEpisodeDate > time()) {
                            //if future date
                            $resulting_episodes .= '<i class="fa fa-clock-o fa-2x"></i>  ';
                            //show watch icon
                        }
                        $episodeDate = date($dateformat, $thisEpisodeDate);
                        $resulting_episodes .= $episodeDate . '</p>';
                        //// Edit/Delete button for logged user (i.e. admin)
                        if (isUserLogged()) {
                            $resulting_episodes .= '<p><a class="btn btn-inverse btn-xs btn-mini" href="?p=admin&amp;do=edit&amp;=episode&amp;name=' . urlencode($thisPodcastEpisode[5]) . '.' . $thisPodcastEpisode[3] . '">' . _("Edit / Delete") . '</a></p>';
                        }
                        //Show Image embedded in the mp3 file or image associated in the images/ folder from previous versions of PG (i.e. 1.4-) - Just jpg and png extension supported
                        if (file_exists($absoluteurl . $img_dir . $thisPodcastEpisode[5] . '.jpg')) {
                            $resulting_episodes .= '<img class="episode_image" src="' . $url . $img_dir . $thisPodcastEpisode[5] . '.jpg" alt="' . $thisPodcastEpisodeData[0] . '" />';
                        } else {
                            if (file_exists($absoluteurl . $img_dir . $thisPodcastEpisode[5] . '.png')) {
                                $resulting_episodes .= '<img class="episode_image" src="' . $url . $img_dir . $thisPodcastEpisode[5] . '.png" alt="' . $thisPodcastEpisodeData[0] . '" />';
                            }
                        }
                        //// Short Description
                        $resulting_episodes .= '<p>' . $thisPodcastEpisodeData[1] . '</p>';
                        ////Buttons (More, Download, Watch)
                        $resulting_episodes .= showButtons($thisPodcastEpisode[5], $thisPodcastEpisode[3], $url, $upload_dir, $episodesCounter, $thisPodcastEpisode[1], $enablestreaming);
                        ////Other details (file type, duration, bitrate, frequency)
                        //NB. read from XML DB (except file extension = $thisPodcastEpisode[3]).
                        $episodeDetails = _('Filetype:') . " " . strtoupper($thisPodcastEpisode[3]);
                        if ($thisPodcastEpisodeData[11] != NULL) {
                            $episodeDetails .= ' - ' . _('Size:') . " " . $thisPodcastEpisodeData[11] . _("MB");
                        }
                        if ($thisPodcastEpisodeData[12] != NULL) {
                            // display file duration
                            $episodeDetails .= " - " . _("Duration:") . " " . $thisPodcastEpisodeData[12] . " " . _("m");
                        }
                        if ($thisPodcastEpisode[3] == "mp3" and $thisPodcastEpisodeData[13] != NULL and $thisPodcastEpisodeData[14] != NULL) {
                            //if mp3 show bitrate and frequency
                            $episodeDetails .= " (" . $thisPodcastEpisodeData[13] . " " . _("kbps") . " " . $thisPodcastEpisodeData[14] . " " . _("Hz") . ")";
                        }
                        $resulting_episodes .= '<p class="episode_info">' . $episodeDetails . '</p>';
                        ////Playes: audio (flash/html5) and video (html5), for supported files and browsers
                        //if audio and video streaming is enabled in PG options
                        if ($enablestreaming == "yes" and !detectMobileDevice()) {
                            $resulting_episodes .= showStreamingPlayers($thisPodcastEpisode[5], $thisPodcastEpisode[3], $url, $upload_dir, $episodesCounter);
                        }
                        $isvideo = FALSE;
                        //RESET isvideo for next episode
                        ////Social networks and (eventual) embedded code
                        $resulting_episodes .= attachToEpisode($thisPodcastEpisode[5], $thisPodcastEpisode[3], $thisPodcastEpisodeData[0]);
                        //Blank space as bottom margin (to be replaced with CSS style!)
                        $resulting_episodes .= "<br />";
                        //Close the single episode DIV
                        $resulting_episodes .= "</div>";
                        //Close div with class row-fluid (theme based on bootstrap). Theme engine >= 2.0
                        if (useNewThemeEngine($theme_path) and $episodesCounter % $numberOfEpisodesPerLine != 0 or $episodesCounter == count($fileNamesList)) {
                            $resulting_episodes .= "</div>";
                            //close class row-fluid (bootstrap)
                        }
                        $episodesCounter++;
                        //increment counter
                    }
                    // END - If episode is supported and has a related xml db
                    if ($episodesCounter <= $maxC and $episodesCounter > $minC) {
                        //Append this episode to the final output to return
                        $finalOutputEpisodes .= $resulting_episodes;
                    }
                }
            }
            //END - Else if this episode is shown in this page, or no limitation in $max_recent
        }
        // END - Loop through each file in the media directory
    }
    // END - If media directory contains files
    //IF a category is requested add category header and message when empty
    if (isset($category) and $category != NULL) {
        //If a category is requested and doesn't contain any episode
        if ($CounterEpisodesInCategory < 1 and !empty($fileNamesList)) {
            $finalOutputEpisodes .= '<p>' . "No episodes here yet..." . '</p>';
        }
        $finalOutputEpisodes = $category_header . $finalOutputEpisodes;
        //category header at the top
    }
    ////Pagination (and links to pages)
    //Calculate total number of pages
    if (isset($episodesCounter)) {
        $numberOfPages = $episodesCounter / $episodeperpage;
    }
    if (isset($numberOfPages) and $numberOfPages > 1) {
        $numberOfPages = ceil($numberOfPages);
    }
    //round to the next integer
    //echo $numberOfPages; // Debug
    if (isset($_GET['p'])) {
        $pageURLforPagination = avoidXSS($_GET['p']);
    } else {
        $pageURLforPagination = "home";
    }
    if (isset($_GET["pgn"])) {
        $thisCurrentPage = $_GET["pgn"];
    } else {
        $thisCurrentPage = 1;
    }
    if (isset($episodesCounter) and $episodesCounter > $episodeperpage) {
        $finalOutputEpisodes .= '<div style="clear:both;"><p>';
        //Print page index and links
        for ($onePage = 1; $onePage <= $numberOfPages; $onePage++) {
            if ($thisCurrentPage == $onePage) {
                $finalOutputEpisodes .= $onePage . ' | ';
            } else {
                $finalOutputEpisodes .= '<a href="?p=' . $pageURLforPagination . $categoryURLforPagination . '&amp;pgn=' . $onePage . '">' . $onePage . '</a> | ';
            }
        }
        $finalOutputEpisodes .= '</p></div>';
    }
    //Finally, return all the episodes to output on the web page
    return $finalOutputEpisodes;
}