/NDN_embed/options.php

https://bitbucket.org/newsinc/wordpressplugin · PHP · 97 lines · 84 code · 12 blank · 1 comment · 41 complexity · 6b9d85346211f7e5a8c41ab617f25abd MD5 · raw file

  1. <div class="wrap">
  2. <?php screen_icon(); ?>
  3. <h2>NDN embed code conversion</h2>
  4. <?php
  5. if($_POST['submit'] && $_POST['embedcode']){
  6. $error = "<br /><br />This does not appear to be valid embed code, please check your code and try again.<br /><br />";
  7. $str = $_POST['embedcode'];
  8. $class = $_POST['classname'];
  9. $class = preg_replace('/[\s]/',',',$class);
  10. if ($class == "ndn_embed"){unset($class);}
  11. $id = $_POST['idname'];
  12. // determine if it is iframe
  13. if (strpos($str, '<div') === false){
  14. $str = substr($str, ($pos = strpos($str, '<iframe')) !== false ? $pos + 1 : 0);
  15. $str = substr($str,0,strpos($str,">"));
  16. $str = preg_replace('/[^\w-:;=?&\/ ]/', '', $str);
  17. $str = preg_replace('/[&?]/',' ',$str);
  18. preg_match_all("/([^,= ]+)=([^,= ]+)/", $str, $r);
  19. if ($r[1] && $r[2]){
  20. $result = array_combine($r[1], $r[2]);
  21. if (!$result["widgetId"] && !$result["type"] && !$result["trackingGroup"]){
  22. print $error;
  23. }else{
  24. $ndn = '[NDN ';
  25. if ($class){$ndn = $ndn.'class='.$class.' ';}
  26. if ($id){$ndn = $ndn.'id='.$id.' ';}
  27. if ($result["width"] && $result["height"]){
  28. $ndn = $ndn.'style="width:'.$result["width"].'px;height:'.$result["height"].'px;" ';
  29. }else if ($result["width"]){
  30. $ndn = $ndn.'style="width:'.$result["width"].';" ';
  31. }else if ($result["height"]){
  32. $ndn = $ndn.'style="height:'.$result["height"].';" ';
  33. }
  34. if ($result["widgetId"]){$ndn = $ndn.'widgetid='.$result["widgetId"].' ';}
  35. if ($result["type"]){$ndn = $ndn.'type='.$result["type"].' ';}
  36. if ($result["videoId"]){$ndn = $ndn.'videoid='.$result["videoId"].' ';}
  37. if ($result["playlistId"]){$ndn = $ndn.'playlistid='.$result["playlistId"].' ';}
  38. if ($result["siteSection"]){$ndn = $ndn.'sitesection='.$result["siteSection"].' ';}
  39. if ($result["trackingGroup"]){$ndn = $ndn.'trackinggroup='.$result["trackingGroup"].' ';}
  40. $ndn = $ndn.']';
  41. print "<br /><br />Copy the following short code and paste it into your page or post:<br /><br />".$ndn."<br /><br />";
  42. }
  43. }else{
  44. print $error;
  45. }
  46. }else{
  47. $str = substr($str, ($pos = strpos($str, '<div')) !== false ? $pos + 1 : 0);
  48. $str = substr($str,0,strpos($str,">"));
  49. $str = preg_replace('/[^\w-:;=\/ ]/', '', $str);
  50. preg_match_all("/([^,= ]+)=([^,= ]+)/", $str, $r);
  51. if ($r[1] && $r[2]){
  52. $result = array_combine($r[1], $r[2]);
  53. if (!$result["data-config-widget-id"] && !$result["data-config-type"] && !$result["data-config-tracking-group"]){
  54. print $error;
  55. }else{
  56. $ndn = '[NDN ';
  57. if ($result["class"] && $result["class"] != "ndn_embed"){$ndn = $ndn.'class='.$class.' ';}
  58. if ($id){$ndn = $ndn.'id='.$id.' ';}
  59. if ($result["style"]){$ndn = $ndn.'style='.$result["style"].' ';}
  60. if ($result["data-config-widget-id"]){$ndn = $ndn.'widgetid='.$result["data-config-widget-id"].' ';}
  61. if ($result["data-config-type"]){$ndn = $ndn.'type='.$result["data-config-type"].' ';}
  62. if ($result["data-config-video-id"]){$ndn = $ndn.'videoid='.$result["data-config-video-id"].' ';}
  63. if ($result["data-config-playlist-id"]){$ndn = $ndn.'playlistid='.$result["data-config-playlist-id"].' ';}
  64. if ($result["data-config-site-section"]){$ndn = $ndn.'sitesection='.$result["data-config-site-section"].' ';}
  65. if ($result["data-config-tracking-group"]){$ndn = $ndn.'trackinggroup='.$result["data-config-tracking-group"].' ';}
  66. if ($result["data-config-rmm-sound-on"]){$ndn = $ndn.'rmmsoundon='.$result["data-config-rmm-sound-on"].' ';}
  67. if ($result["data-config-auto-play"]){$ndn = $ndn.'autoplay='.$result["data-config-auto-play"].' ';}
  68. if ($result["data-config-continuous-play"]){$ndn = $ndn.'continuousplay='.$result["data-config-continuous-play"].' ';}
  69. $ndn = $ndn.']';
  70. print "<br /><br />Copy the following short code and paste it into your page or post:<br /><br />".$ndn."<br /><br />";
  71. }
  72. }else{
  73. print $error;
  74. }
  75. }
  76. }
  77. ?>
  78. <form id="ndn_convert" action="" method="POST">
  79. <label><h3>Copy your Embed code from the <a href="http://control.newsinc.com/" target="_blank">NDN Control room</a> or Social Share screen on a player here:</h3><textarea form="ndn_convert" cols="40" rows="5" name="embedcode"></textarea></label><br />
  80. <h2>In order to make a single player responsive you need to control it with your own CSS. You can add classes and/or a DIV id below to target in your CSS file.</h2>
  81. <label><h3>Enter your custom CSS Class Name(s) here:<br />(optional - separate by space)</h3><textarea form="ndn_convert" name="classname"></textarea></label><br />
  82. <label><h3>Enter your DIV Id Name here:<br />(optional)</h3><textarea form="ndn_convert" name="idname"></textarea></label><br />
  83. <input name="submit" type="submit" value="Convert" />
  84. </form>
  85. </div>