Example #1
0
function save($root, $path, $data)
{
    $playlist_file_info = get_file_info($path);
    // Reference: http://stackoverflow.com/questions/689185/json-decode-returns-null-php
    if (get_magic_quotes_gpc()) {
        // Remove PHP magic quotes
        $data = stripslashes($data);
    }
    $data = json_decode($data, true);
    if ($data == null) {
        die('Playlist could not be saved: Could not parse json data');
    }
    $handle = @fopen($playlist_file_info['path'], 'w') or die('Playlist could not be saved: Could not open file for writing');
    fwrite($handle, playlist_header() . LINE_BREAK);
    fwrite($handle, implode("\n", playlist_contents($playlist_file_info['path'], $data)));
    fclose($handle);
    echo 'Playlist saved successfully';
}
Example #2
0
File: data.php Project: RiJo/m3uer
define('KEY_CONTENTS', 'contents');
define('KEY_VALID', 'valid');
define('KEY_INVALID', 'invalid');
define('KEY_COMMENT', 'comment');
if (!isset($_GET['q'])) {
    die("No valid query given");
}
switch ($_GET['q']) {
    case 'playlist-tree':
        assure_keys($_GET, array('root', 'path'));
        assure_keys($_SESSION, SESSION_MEDIA);
        echo playlist_valid_tree($_GET['root'], $_GET['path'], unserialize($_SESSION[SESSION_MEDIA]));
        break;
    case 'playlist-contents':
        assure_keys($_GET, array('root', 'path'));
        echo playlist_contents($_GET['root'], $_GET['path']);
        break;
    case 'playlist-invalid-count':
        assure_keys($_GET, array('root', 'path'), '-1');
        echo playlist_invalid_count($_GET['root'], $_GET['path']);
        break;
    case 'playlists':
        assure_keys($_GET, array('root'));
        assure_keys($_SESSION, SESSION_PLAYLISTS);
        echo playlists($_GET['root'], unserialize($_SESSION[SESSION_PLAYLISTS]));
        break;
    default:
        die("Unrecognized query {$_GET['q']}");
}
function assure_keys($array, $keys, $error_message = '')
{