<?
	/*
	 * ==============================================================================
	 * SVT Play by Sveriges Television for Xtreamer Media Player & Streamer
	 * ==============================================================================
	 *
	 * This project allows to watch content brom SVT Play is the brand used for the
	 * video on demand service offered by Sveriges Television.
	 *
	 * Scraper based on SVT Play plugin for XBMC, xbmc-svtplay, code.google.com/p/xbmc-svtplay/
	 *
	 * Licence: GNU General Public License v2
	 * http://www.gnu.org/licenses/gpl.html
	 *
	 * Do not remove or change any header comments! Respect our work!
	 *
	 * If you are satisfied with my work you can support it with small donation
	 *   https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SB8WDDAWY5YZE&lc=SI&item_name=xJukebox&item_number=ak5349jgdr&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted	 *
	 *
	 * Author: vpeter
	 *  http://forum.xtreamer.net/user/34082-vpeter/
	 *
	 * ==============================================================================
	 */

	header('Content-type: text/plain');

	require_once 'KLogger.php';		// include the logger

  $fav = @$_GET['fav'];
  if (is_null($fav) || $fav == '')
    die();

	$favoritesFile = 'favorites.dat';

	if ($fav == 'delete') {
		$arr = unserialize(file_get_contents($favoritesFile));

		foreach ($arr as $key => $data) {
			if ($data['mode'] == $_GET['mode'] && $data['url'] == $_GET['url']) {
				// saved
				array_splice($arr, $key, 1);		// remove this element
				file_put_contents($favoritesFile, serialize($arr));
				die();
			}
		}
	} else if ($fav == 'write') {
		$arr = unserialize(file_get_contents($favoritesFile));

		foreach ($arr as $data) {
			if ($data[5] == $_GET['mode'] && $data[6] == $_GET['url'])
				die();		// already saved
		}
		// save
		$arrAdd = array('name'				=> $_GET['title'],
							 			'desc'				=> $_GET['title2'],
							 			'extra'				=> $_GET['title3'],
							 			'mode'				=> $_GET['mode'],
							 			'url'					=> $_GET['url'],
							 			'iconimage'		=> $_GET['iconimage'],
							 			'folder'			=> 0);

		$arr[] = $arrAdd;
		file_put_contents($favoritesFile, serialize($arr));
	}

?>