<repo_name>kamaroly/umuzika<file_sep>/app/Http/routes.php
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', function () {
    return view('layouts.default');
});

$router->get('explore', function() {
	return view('tracks.item');
});

$router->get('/search',function(){
	return view('tracks.search');
});

$router->get('/upload',function(){
	return view('files.upload');
});

$router->get('/home',function(){
	$songs = App\Models\File::all();
	return view('layouts.default3',compact('songs'));
});

Route::get('files/get/{filename?}', [
	'as' => 'files.get', 'uses' => 'UploadController@get']);
	
Route::post('upload/music', ['as' => 'upload.music', 'uses' => 'UploadController@upload']);
<file_sep>/app/Http/Controllers/UploadController.php
<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Models\File as FileModel;
use Illuminate\Contracts\Filesystem\Factory as Storage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Response;

class UploadController extends Controller
{
    public $file;
  public $storage;
  function __construct(FileModel $file, Storage $storage) {
    $this->file = $file;
    $this->storage = $storage;
  }

	/**
	 * Upload a file to the server
	 * @param  Request $request input
	 * @return json           
	 */
    public function upload() {

    if(Input::hasFile('file')) {

      //upload an image to the /img/tmp directory and return the filepath.
      $file = Input::file('file');

      $extension = $file->getClientOriginalExtension();

      $filename = time() . $file->getFilename();
      
      $this->storage->disk('local')->put($filename . '.' . $extension, File::get($file));

      $entry = $this->file;

      $entry->mime = $file->getClientMimeType();

      $entry->original_filename = $filename;

      $entry->filename = $filename . '.' . $extension;

      $entry->save();

      return response()->json(array('path'=> route('files.get',['filename' => $entry->filename])), 200);
    } 
    else 
    {
      return response()->json(false, 200);
    }
  }

  /**
   * Get file from the diesk
   * @param  string $filename 
   * @return file           
   */
  public function get($filename=null) {

    $entry = $this->file->where('filename', '=', $filename)->first();
    // If we don't have a file, return this dumy path
    if (is_null($entry)) {
      return redirect(url('assets/dist/img/no-image.png'));
    }

    $file = $this->storage->disk('local')->get($entry->filename);

    return (new Response($file))
      ->header('Content-Type', $entry->mime);
  }
}
<file_sep>/public/assets/js/umuzika.page.js
$(function() {
	$("body").on("click", "a[rel='loadpage']", function(e) {
		// Get the link location that was clicked
		
		startLoadingBar();
		pageurl = $(this).attr('href');
		
		// Replace the path of the url from index to the path with raw content
		var custom = pageurl;
		var custom = custom.replace('index', 'page');
		
		// Request the page
		$.ajax({url:custom,success: function(data) {
			// Show the content
			$('#content').html(data);
			// Stop the loading bar
			stopLoadingBar();
			// Set the new title tag
			document.title = $('#page-title').html();
			// Scroll the document at the top of the page
			$(document).scrollTop(0);
			// Reload functions
			reload();
		}});
		
		// Store the url to the last page accessed
		if(pageurl != window.location){
			window.history.pushState({path:pageurl}, '', pageurl);	
		}
		return false;
	});
});

// Override the back button to get the ajax content via the back content */
$(window).bind('popstate', function(ev) {
	if (navigator.userAgent.match(/(iPad|iPhone|iPod|Android)/g) && !window.history.ready && !ev.originalEvent.state) {
		return; // Work around for WebKit devices [prevent executing a popstate upon page load (The bug was fixed in Chrome 35+, but not on the mobile browser)]
	}
	if (navigator.userAgent.match(/AppleWebKit/) && !navigator.userAgent.match(/Chrome/) && !window.history.ready && !ev.originalEvent.state) {
		return; // Work around for WebKit devices [prevent executing a popstate upon page load (The bug was fixed in Chrome 35+, but not on the mobile browser)]
	}
	
	startLoadingBar();
	// Replace the path of the url from index to the path with raw content
	var custom = location.href;
	
	// Check whether the page contains index.php or not, if it doens't then add one (prevent breaking when loading website without index.php
	if(custom.indexOf("index.php") == -1) {
		var custom = location.href + '/index.php';
	}
	var custom = custom.replace('index', 'page');
	
	// Request the page
	$.ajax({url:custom,success: function(data){
		// Show the content
		$('#content').html(data);
		// Stop the loading bar
		stopLoadingBar();
		// Set the new title tag
		document.title = $('#page-title').html();
		// Scroll the document at the top of the page
		$(document).scrollTop(0);
		// Reload functions
		reload();
	}});
});

$(document).ready(function() {
	// Set the player volume
	if(getCookie("volume") == "") {
		player_volume = 0.80;
		setCookie("volume", 0.80, "365");
	} else {
		player_volume = getCookie("volume");
	}
	$("#sound-player").jPlayer({
		ready: function (event) {
			$(this).jPlayer("setMedia", {
				
			});
		},
		cssSelectorAncestor: '#sound-container',
		swfPath: "http://dev.umuzika.com/themes/sound/js",
		supplied: "mp3",
		wmode: "window",
		volume: player_volume,
		smoothPlayBar: true,
		keyEnabled: true
	});
});

function playSong(song, id) {
	// If the user is on a mobile device, open the track in a new tab rather than playing it on the page
	/*if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
		window.location = 'http://dev.umuzika.com/uploads/tracks/'+song;
		return false;
	}*/
	
	// Remove the current-song class (if any)
	$('.current-song').removeClass('current-song');
	
	// Show the previously hidden Play button (if any)
	$('.current-play').show();
	$('.current-play').removeClass('current-play');
	
	// Remove the active player if exist and set the ghost player
	$('.current-seek').html($('#sound_ghost_player').html());
	
	// Remove the active player class
	$('.current-seek').removeClass('current-seek');
	
	// Escape the ID (contains dots) http://api.jquery.com/category/selectors/
	var parsedId = song.replace('.', '\\.');
	
	// Add the current song class
	$('#track'+id).addClass('current-song');
	// Add current play class to the Play button and hide it
	$('#play'+id).addClass('current-play');
	$('.current-play').hide();
	
	// Get the current song name and url
	var trackUrl = $('#song-url'+id).attr('href');
	var songName, shortSongName = songName = $('#song-name'+id).html();
	
	if (songName.length > 30) {
		var shortSongName = $('#song-name'+id).html().substr(0, 30)+'...';
	}
	
	$('#sw-song-name').html($('<a>', {text: shortSongName, href: trackUrl, title: songName, rel: 'loadpage'}));
	
	// Show the time holder when a song starts playing
	$('.jp-audio .jp-time-holder').show();
	
	// Destroy the player if any is active
	$("#sound-player").jPlayer("destroy");
	
	// Add the active player to the current song
	$("#song-controls"+id).html($("#seek-bar-song").html());
	
	// Add the active player class to the current song
	$("#song-controls"+id).addClass('current-seek');
	
	// Set the play/pause button position (this is needed for mobile view in order for the play/pause button to be at the same height with the initial play button)
	$('#track'+id+' .jp-play , #track'+id+' .jp-pause').css({ 'margin-top' : '-' + $('.song-top', '#track'+id).outerHeight() + 'px' });
	
	// Get the track extension
	var ext = getExtension(song);
	
	// Determine prev next buttons
	prevnext();
	$("#sound-player").jPlayer({
		ready: function (event) {
			if(ext == 'mp3') {
				$(this).jPlayer("setMedia", {
					mp3: 'http://dev.umuzika.com/uploads/tracks/'+song
				}).jPlayer("play");
			} else if(ext == 'm4a') {
				$(this).jPlayer("setMedia", {
					m4a: 'http://dev.umuzika.com/uploads/tracks/'+song				
				}).jPlayer("play");
			}
		},
		cssSelectorAncestor: '#sound-container',
		ended: function () {
			$.ajax({
				type: "POST",
				url: "http://dev.umuzika.com/requests/add_view.php",
				data: "id="+id, 
				cache: false,
				success: function(html) {
				
				}
			});
			
			// If repeat is not turned on, move to the next song
			if($('#repeat-song').html() == 0) {
				$('.current-seek').html($('#sound_ghost_player').html());
				$('.current-play').show();
				nextSong(id);
			}
		},
		/*error: function() {
			// If the track fails to play for whatever reasons, hide it
			$('#track'+id).fadeOut();
			nextSong(id);
		},*/
		errorAlerts: true,
		swfPath: "http://dev.umuzika.com/themes/sound/js",
		supplied: ext,
		wmode: "window",
		volume: getCookie("volume"),
		smoothPlayBar: true,
		solution: "html, flash",
		keyEnabled: true
	});
};
