<?php
  /*
   * ==============================================================================
   * 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/
   *
   * ==============================================================================
   */
   
/* get string width to use it in menus */
$fontWidth_arialbd_9 = array(
  ' '=>6  ,'!'=>5  ,'"'=>7  ,'#'=>9  ,'$'=>9  ,'%'=>13  ,'&'=>11  ,'\''=>4  ,'('=>5  ,')'=>5  ,'*'=>7  ,'+'=>9  ,','=>5  ,'-'=>5  ,'.'=>5  ,'/'=>6  ,'0'=>9
  ,'1'=>8  ,'2'=>9  ,'3'=>9  ,'4'=>9  ,'5'=>9  ,'6'=>9  ,'7'=>9  ,'8'=>9  ,'9'=>9  ,':'=>5  ,';'=>5  ,'<'=>9  ,'='=>9  ,'>'=>9  ,'?'=>8  ,'@'=>14
  ,'A'=>11  ,'B'=>10  ,'C'=>10  ,'D'=>10  ,'E'=>9  ,'F'=>8  ,'G'=>11  ,'H'=>10  ,'I'=>5  ,'J'=>9  ,'K'=>10  ,'L'=>8  ,'M'=>12  ,'N'=>10  ,'O'=>11  ,'P'=>9
  ,'Q'=>11  ,'R'=>10  ,'S'=>10  ,'T'=>9  ,'U'=>10  ,'V'=>10  ,'W'=>13  ,'X'=>10  ,'Y'=>10  ,'Z'=>9  ,'['=>5  ,'\\'=>6  ,']'=>6  ,'^'=>8  ,'_'=>9  ,'`'=>6
  ,'a'=>8  ,'b'=>8  ,'c'=>8  ,'d'=>8  ,'e'=>9  ,'f'=>6  ,'g'=>8  ,'h'=>8  ,'i'=>5  ,'j'=>6  ,'k'=>8  ,'l'=>5  ,'m'=>12  ,'n'=>8  ,'o'=>8  ,'p'=>8
  ,'q'=>8  ,'r'=>6  ,'s'=>9  ,'t'=>6  ,'u'=>8  ,'v'=>9  ,'w'=>11  ,'x'=>9  ,'y'=>8  ,'z'=>8  ,'{'=>7  ,'|'=>5  ,'}'=>7  ,'~'=>9
);

/*	http://danielfamily.com/techblog/?p=29	*/
function strPixels($string, $strPixelWidths) {
  $weight = 0;
  if (!empty($string)) {
    for ($i = 0; $i < strlen($string); $i++) {
      $w = $strPixelWidths[substr($string, $i, 1)];
      if ($w)
      	$weight += $w + 1;
      else {
      	$w = $strPixelWidths['o'];
      	if ($w)
      		$weight += $w + 1;
      	else
      		$weight += 10;
      }
    }
  }
  return $weight;
}

function strWidthPC($string, $strPixelWidths) {
  $weight = strPixels($string, $strPixelWidths);
  $weight += 8;
	$roundNum = 2;
	$xFactor = 1.0565079;		// don't know why this pixels are not correct
	$weight = round((float) ($weight/1280*100*$xFactor), $roundNum);
  return $weight;
}

/* rtmpgw start/stop functions */
function stop_rtmpgwd() {
	$cmd = 'killall -9 rtmpgw';
	system($cmd);
}

function start_rtmpgw() {
	$cmd = "killall -0 rtmpgw 2>/dev/null || ./rtmpgw -q >/dev/null 2>&1 &";
	exec($cmd);
}

function check_rtmpgw() {
	$cmd = "killall -0 rtmpgw";
	exec($cmd, $output, $result);
  if ($result == 0) {
    return true;	// the process is alive
	}
 
  return false;	// the process is dead
}

?>
