function GetDirArrayRecursive($dir, $filter = false)
{
    global $Amedia_types, $Ahide_files, $Ahide_folders, $Akeywords;
    if ($filter) {
        $Afilter = $filter;
    } else {
        $Afilter = $Amedia_types;
    }
    $Afiles = array();
    if (!$dir || $dir == "") {
        $dir = ".";
    }
    $handle = @opendir($dir);
    if ($dir) {
        if (is_dir($dir)) {
            while (false !== ($entry = @readdir($handle))) {
                if ($entry != '.' && $entry != '..') {
                    $entry = $dir . '/' . str_replace("\\", "/", $entry);
                    $pathinfo = path_parts($entry);
                    if (is_dir($entry)) {
                        if (!checkKeyWords($Ahide_folders, $pathinfo['filename']) && !checkKeyWords($Akeywords, $pathinfo['filename'])) {
                            $Afiles = array_merge($Afiles, GetDirArrayRecursive($entry, $Afilter));
                        }
                    } else {
                        if (in_array(strtolower($pathinfo['ext']), $Afilter)) {
                            if (!checkKeyWords($Ahide_files, $pathinfo['filename']) && !checkKeyWords($Akeywords, $pathinfo['filename'])) {
                                $Afiles[] = $entry;
                            }
                        }
                    }
                }
            }
        }
    }
    @closedir($handle);
    return $Afiles;
}
Esempio n. 2
0
function makeXMLplaylist($theDir, $recursive = false)
{
    global $WIMPY_PATH, $wimpyApp, $defaultVisualBaseName, $defaultVisualExt;
    $sPath = utf8_decode(rawurldecode($theDir));
    if ($recursive) {
        $AdirList['files'] = GetDirArrayRecursive($sPath);
        $AdirList['dirs'] = array();
    } else {
        $AdirList = GetDirArray($sPath);
    }
    $playlistCoverart = cleanForFlash(lookForVisual($sPath . slash . $defaultVisualBaseName . "." . $defaultVisualExt));
    $retval = '<playlist image="' . $playlistCoverart . '">' . newline;
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    // Directory
    $Adirs = array();
    if (sizeof($AdirList['dirs']) > 0) {
        for ($i = 0; $i < sizeof($AdirList['dirs']); $i++) {
            $tempName = $AdirList['dirs'][$i];
            $path_info = path_parts($tempName);
            $Aitem = array();
            $Aitem['filename'] = filepath2url($tempName);
            $Aitem['date'] = date("Y-m-d H:i:s", filemtime($tempName));
            // Image:
            $visualfilenameA = $tempName . slash . $defaultVisualBaseName . "." . $defaultVisualExt;
            if (@is_file($visualfilenameA)) {
                $visualFound = filepath2url($visualfilenameA);
            } else {
                $visualFound = "";
            }
            $Aitem['image'] = $visualFound;
            $infoFound = lookForInfo($tempName . slash . "folder.info");
            if ($infoFound != false) {
                $retval .= '<item>' . newline;
                $retval .= '<filename>' . $Aitem['filename'] . '</filename>' . newline;
                $retval .= $infoFound;
                $retval .= '<image>' . $Aitem['image'] . '</image>' . newline;
                $retval .= '<date>' . $Aitem['date'] . '</date>' . newline;
                $retval .= '<filekind>dir</filekind>' . newline;
                $retval .= "</item>" . newline;
            } else {
                $Aitem['artist'] = "";
                $Aitem['title'] = $path_info['filename'];
                $Aitem['album'] = "";
                $Aitem['seconds'] = "";
                $Aitem['link'] = "";
                $Aitem['description'] = "";
                // Write item XML
                $retval .= '<item>' . newline;
                $retval .= returnXMLkeys($Aitem);
                $retval .= "<filekind>dir</filekind>" . newline;
                $retval .= "</item>" . newline;
            }
        }
    }
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////
    // Files
    $Afiles = array();
    if (sizeof($AdirList['files']) > 0) {
        for ($i = 0; $i < sizeof($AdirList['files']); $i++) {
            $tempName = $AdirList['files'][$i];
            $path_info = path_parts($tempName);
            $Aitem = array();
            // Filename
            //
            $Aitem['filename'] = filepath2url($tempName);
            $Aitem['date'] = date("Y-m-d H:i:s", filemtime($tempName));
            $Aitem['image'] = lookForVisual($path_info['basepath'] . slash . $path_info['basename'] . "." . $defaultVisualExt);
            $infoFound = lookForInfo($path_info['basepath'] . slash . $path_info['basename'] . ".info");
            if ($infoFound != false) {
                $retval .= '<item>' . newline;
                $retval .= '<filename>' . $Aitem['filename'] . '</filename>' . newline;
                $retval .= $infoFound;
                $retval .= '<date>' . $Aitem['date'] . '</date>' . newline;
                $retval .= '<image>' . $Aitem['image'] . '</image>' . newline;
                $retval .= '<filekind>' . strtolower($path_info['ext']) . '</filekind>' . newline;
                $retval .= "</item>" . newline;
            } else {
                if (strtolower($path_info['ext']) == "mp3") {
                    $Aid3 = getID3info4me($tempName);
                } else {
                    $Aid3 = array();
                }
                // Basic ID3 info:
                $Aitem['artist'] = @$Aid3['artist'];
                $Aitem['title'] = @$Aid3['title'] ? @$Aid3['title'] : $path_info['basename'];
                $Aitem['album'] = @$Aid3['album'];
                $Aitem['seconds'] = @$Aid3['seconds'];
                // URL Link
                //
                // [comment] = id3v1
                // [commentS] = id3v2
                //
                // See if comments contain a URL:
                if (@substr($Aid3['comment'], 0, 4) == "http") {
                    $Aitem['link'] = @$Aid3['comment'];
                }
                // Replace ID3v1 with ID3v2
                if (@substr($Aid3['comments'], 0, 4) == "http") {
                    $Aitem['link'] = @$Aid3['comments'];
                }
                // Comments and URL link
                //
                // [comment] = id3v1
                // [commentS] = id3v2
                //
                if (@substr(@$Aid3['comment'], 0, 4) != "http" && strlen(@$Aid3['comment']) > 0) {
                    $Aitem['description'] = @$Aid3['comment'];
                }
                // Replace ID3v1 with ID3v2
                if (@substr(@$Aid3['comments'], 0, 4) == "http" && strlen(@$Aid3['comments']) > 0) {
                    $Aitem['description'] = @$Aid3['comments'];
                }
                // Image
                //
                $retval .= '<item>' . newline;
                $retval .= returnXMLkeys($Aitem);
                $retval .= '<filekind>' . strtolower($path_info['ext']) . '</filekind>' . newline;
                $retval .= "</item>" . newline;
            }
        }
    }
    $retval .= "</playlist>" . newline;
    @clearstatcache();
    return $retval;
}