6

we have construct the one secret URL for my application.i have PHP script how to change java script any one help me to solve the issue

Below mentioned script how to change java script in c# application i have php script this to change javascript

<html>
<title>Live</title>
<head>
<script src="http://content.jwplatform.com/libraries/Y09dkRGs.js"></script>
<script>jwplayer.key = "ti8UU55KNdJCPX+oWrJhLJNjkZYGiX13KS7yhlM7Ok/wmU3R";</script>

</head>
<body>
<?php

function bg_gen_secure_uri($file, $directory, $secret, $expiry=0, $allowed_countries='',
$disallowed_countries='', $allowed_ip='', $allowed_useragent='',
$allowed_metros='', $disallowed_metros='',
$progressive_start='', $progressive_end='',
$extra_params='') {

    if ($file==''||$secret=='') {
        return false;
    }

    // Construct the values for the MD5 salt ...
    if (substr($expiry,0,1)=='=') {
        $timestamp=substr($expiry,1);
    } else if ($expiry > 0) {
        $now=time(); // use UTC time since the server does
        $timestamp=$now+$expiry;
    } else {
        $timestamp=0;
    }

    if ($allowed_countries) {
        $allowed_countries='&a='.$allowed_countries;
    }

    if ($disallowed_countries) {
        $disallowed_countries='&d='.$disallowed_countries;
    }

    if ($allowed_ip) {
        $allowed_ip='&i='.$allowed_ip;
    }

    if ($allowed_useragent) {
        $allowed_useragent='&u='.$allowed_useragent;
    }

    if ($progressive_start!='') {
        $progressive_start='&start='.$progressive_start;
    }

    if ($progressive_end) {
        $progressive_end='&end='.$progressive_end;
    }

    if ($allowed_metros) {
        $allowed_metros='&am='.$allowed_metros;
    }

    if ($disallowed_metros) {
        $disallowed_metros='&dm='.$disallowed_metros;
    }

    if ($extra_params) {
        $extra_params=urldecode($extra_params);
    }

    // Generate the MD5 salt ...
    if ($directory == '') {
        $salt = $secret . $file . '?e=' . $timestamp . $allowed_countries .
        $disallowed_countries . $allowed_metros . $disallowed_metros . $allowed_ip .
        $allowed_useragent . $progressive_start . $progressive_end;
    } else {
        $salt = $secret . $directory . '?e=' . $timestamp . $allowed_countries .
        $disallowed_countries . $allowed_metros . $disallowed_metros . $allowed_ip .
        $allowed_useragent . $progressive_start . $progressive_end;
    }
    // Generate the MD5 hash ...
    $hash_code = md5($salt);

    // Generate the link ...
    $url = $file . '?e=' . $timestamp . $allowed_countries . $disallowed_countries .
    $allowed_metros . $disallowed_metros . $allowed_ip . $allowed_useragent .
    $progressive_start . $progressive_end . '&h=' . $hash_code . $extra_params;

    return $url;
}

function get_secure_url($file,$directory,$secret) {
    $expiry=3600;
    $allowed_countries='';
    $disallowed_countries='';
    $allowed_ip='';
    $allowed_useragent='';
    $allowed_metros='';
    $disallowed_metros='';
    $progressive_start='';
    $progressive_end='';
    $extra_params='&bgsecuredir=1';
    return bg_gen_secure_uri($file, $directory, $secret, $expiry, $allowed_countries, $disallowed_countries, $allowed_ip, $allowed_useragent, $allowed_metros, $disallowed_metros, $progressive_start, $progressive_end, $extra_params);
}
$url = 'http://tv.live-s.cdn.bitgravity.com/cdn-live/_definst_/tv'.get_secure_url('/secure/live/tv/playlist.m3u8','/tv/secure/','kkkfdashfsdiads');
?>
<div>
<div id="player">
<div id="myElement"> </div>
<script type="text/javascript">
jwplayer("myElement").setup({
file: '<?=$url?>',

width: '100%',

aspectratio: '16:9',
stretching:'exactfit',
autostart: false,
androidhls: true,
skin: 'vapor',
primary: 'html5'
});
</script>

</div>          
</div>
naren kumaresan
  • 91
  • 1
  • 1
  • 5
  • 1
    Possible duplicate of [PHP code to convert PHP to JS](http://stackoverflow.com/questions/3235973/php-code-to-convert-php-to-js) – Harsha W Mar 23 '17 at 05:15
  • For get alternative of php functions in javascript, you can check this http://locutus.io – HarisH Sharma Mar 23 '17 at 05:26
  • @HarshaW - That other question was asking how to implement a utility program that could convert a subset of PHP to JS (where the utility itself was to be written in standard PHP). This question is just about a one-off conversion of a specific block of code. (Although perhaps running the code from this question through the answer from the other question would get the desired result). – nnnnnn Mar 23 '17 at 05:32
  • 1
    Naren - StackOverflow isn't intended as a free code-writing service. I'm not a PHP guy, but even I can see that the above PHP code is mostly just a bunch of variable declarations, simple `if/else` blocks, and string concatenation, so any beginner JS programmer could do 70% of it. Why don't you try to do it yourself, and then come back to ask about whichever parts you get stuck on? – nnnnnn Mar 23 '17 at 05:40

2 Answers2

4
  • Install Composer from http://getcomposer.org/
  • Add the "base-reality/php-to-javascript": ">=0.0.3" to your project's composer.json file:

    "require":{ "base-reality/php-to-javascript": "0.1.16" }

    Or the latest tagged version. The dev master should only be used for development, not production.\

  • Include the Composer SPL autoload file in your project: require_once('../vendor/autoload.php');

    Call the converter:

     $phpToJavascript = new PHPToJavascript\PHPToJavascript();
       $phpToJavascript->addFromFile($inputFilename); $jsOutput =
       $phpToJavascript->toJavascript();
    

    $jsOutput will now contain an auto-generated Javascript version of the PHP source file.

Hope this helps!

Thanks

Harsheet
  • 728
  • 9
  • 23
  • Unfortunately stack overflow scope doesn't allow posting links as an answer. Please provide a code or consider posting your answer as a comment. Refer [How do I write a good answer?](http://stackoverflow.com/help/how-to-answer) – CodeMonkey Mar 23 '17 at 05:24
  • You should not answer a duplicate. Second any reference to other tool is out of SO's scope. Here we do not recommend. We are here to solve programmatic problems. – Rajesh Mar 23 '17 at 05:25
  • 1
    I have edited this and I guess now you can vote me up – Harsheet Mar 23 '17 at 05:32
4

You can convert PHP syntax to JS with https://gitlab.com/kornelski/babel-preset-php

Kornel
  • 97,764
  • 37
  • 219
  • 309