index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * LiveEdu.tv Badges Embed Code Generator
  4. *
  5. * @package LctvBadges\Demos
  6. * @version 0.0.9
  7. * @since 0.0.8
  8. */
  9. require_once('../api/LctvApiHelpers.inc') ;
  10. require_once('../badges/LctvBadgeConstants.inc') ;
  11. $DEMO_TITLE = LctvApiHelpers::SanitizeGetParam('title' , '') ;
  12. $BADGE_STYLE = LctvApiHelpers::SanitizeGetParam('badge-style' , '') ;
  13. $BADGE_IMG_ID = $BADGE_IMG_IDS["$BADGE_STYLE"] ;
  14. $CHANNEL_INPUT_ID = 'channel-name-input' ;
  15. $SUBMIT_INPUT_ID = 'submit-input' ;
  16. $OPTIONS_TABLE_ID = 'options-table' ;
  17. $ONLINE_INPUT_ID = 'online-text-input' ;
  18. $OFFLINE_INPUT_ID = 'offline-text-input' ;
  19. $TITLE_INPUT_ID = 'use-title-input' ;
  20. $LINK_INPUT_ID = 'wrap-link-input' ;
  21. $CODE_DIV_ID = 'code-div' ;
  22. $IMG_CODE_ID = 'img-pre' ;
  23. $NOTES_TABLE_ID = 'notes-table' ;
  24. $IS_V1_STYLE = in_array($BADGE_STYLE , $BADGE_V1_STYLES ) ;
  25. $IS_V2_STYLE = in_array($BADGE_STYLE , $BADGE_V2_STYLES ) ;
  26. $IS_FLIP_STYLE = in_array($BADGE_STYLE , $BADGE_FLIP_STYLES) ;
  27. $IMG_DIMS_PARAMS = 'width="100" height="24"' ;
  28. $IMG_FLIP_PARAMS = "data-channel=\"pending\"" ;
  29. $DEMO_IMG_PARAMS = (($IS_V1_STYLE ) ? '' : $IMG_DIMS_PARAMS) .
  30. ((!$IS_FLIP_STYLE) ? '' : $IMG_FLIP_PARAMS) ;
  31. $CHANNEL_INPUT_HTML = "<input id=\"$CHANNEL_INPUT_ID\" type=\"text\" />" ;
  32. $SUBMIT_INPUT_HTML = "<input id=\"$SUBMIT_INPUT_ID\" type=\"button\" value=\"Demo\" />" ;
  33. $BADGE_IMG_HTML = "<img id=\"$BADGE_IMG_ID\" $DEMO_IMG_PARAMS style=\"visibility: hidden ;\" />" ;
  34. $STYLE_INPUT_HTML = "<input id=\"style-id-unused\" type=\"text\" value=\"$BADGE_STYLE\" readonly />" ;
  35. $LINK_INPUT_HTML = "<input id=\"$LINK_INPUT_ID\" type=\"checkbox\" checked />" ;
  36. $TITLE_INPUT_HTML = "<input id=\"$TITLE_INPUT_ID\" type=\"checkbox\" />" ;
  37. $ONLINE_INPUT_HTML = "<input id=\"$ONLINE_INPUT_ID\" type=\"text\" />" ;
  38. $OFFLINE_INPUT_HTML = "<input id=\"$OFFLINE_INPUT_ID\" type=\"text\" />" ;
  39. $CHANNEL_PARAM_DESC = "(Required) Name of channel for which to fetch data." ;
  40. $STYLE_PARAM_DESC = "(Optional) Name of badge style. ($BADGE_STYLE for this badge)" ;
  41. $LINK_PARAM_DESC = "(Optional) true/false to wrap image in hyperlink to channel." ;
  42. $TITLE_PARAM_DESC = "(Optional) true/false to show streaming title when live. (Overrides online message)" ;
  43. $ONLINE_PARAM_DESC = "(Optional) Badge message if status is streaming." ;
  44. $OFFLINE_PARAM_DESC = "(Optional) Badge message if status is not streaming." ;
  45. $CODE_SPAN_TEXT = (($IS_V1_STYLE ) ? 'Add this IMG tag to your HTML:' :
  46. (($IS_V2_STYLE ) ? 'Add this A and IMG tag to your HTML (A tag is optional):' :
  47. (($IS_FLIP_STYLE) ? 'Add this IMG and SCRIPT tag to your HTML:' : ''))) ;
  48. ?>
  49. <!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title></title></head>
  50. <body><link rel="stylesheet" type="text/css" href="lctv-badges.css" />
  51. <?php if (empty($DEMO_TITLE) || empty($BADGE_STYLE)) die('</body></html>') ; ?>
  52. <h3><?php echo $DEMO_TITLE ; ?></h3>
  53. <table id="<?php echo $OPTIONS_TABLE_ID ; ?>">
  54. <tr><td colspan="2">Type an LCTV channel name here --> </td>
  55. <td><?php echo $CHANNEL_INPUT_HTML ; ?></td>
  56. <td>then press "Demo" --> </td>
  57. <td><?php echo $SUBMIT_INPUT_HTML . ' --> ' ; ?></td>
  58. <td><?php echo $BADGE_IMG_HTML ; ?></td></tr>
  59. <tr><td>Additional Options --></td><td>Badge Style: </td>
  60. <td><?php echo $STYLE_INPUT_HTML ; ?></td>
  61. <td colspan="3"> </td></tr>
  62. <tr><td> </td><td>Make Link: </td>
  63. <td><?php echo $LINK_INPUT_HTML ; ?></td>
  64. <td colspan="3"> </td></tr>
  65. <tr><td> </td><td>Use Stream Title:</td>
  66. <td><?php echo $TITLE_INPUT_HTML ; ?></td>
  67. <td colspan="3"> </td></tr>
  68. <tr><td> </td><td>Online Text: </td>
  69. <td><?php echo $ONLINE_INPUT_HTML ; ?></td>
  70. <td colspan="3"> </td></tr>
  71. <tr><td> </td><td>Offline Text: </td>
  72. <td><?php echo $OFFLINE_INPUT_HTML ; ?></td>
  73. <td colspan="3"> </td></tr>
  74. </table>
  75. <h3>To use this badge on your website:</h3>
  76. <div id="<?php echo $CODE_DIV_ID ; ?>">
  77. <span><?php echo $CODE_SPAN_TEXT ; ?></span>
  78. <pre id="<?php echo $IMG_CODE_ID ; ?>"></pre>
  79. <span>Options</span>
  80. <table id="<?php echo $NOTES_TABLE_ID ; ?>">
  81. <tr><td><em><?php echo CHANNEL_KEY ; ?>:</em></td><td><?php echo $CHANNEL_PARAM_DESC ; ?></td></tr>
  82. <tr><td><em><?php echo STYLE_KEY ; ?>:</em></td><td><?php echo $STYLE_PARAM_DESC ; ?></td></tr>
  83. <tr><td><em><?php echo LINK_KEY ; ?>:</em></td><td><?php echo $LINK_PARAM_DESC ; ?></td></tr>
  84. <tr><td><em><?php echo TITLE_KEY ; ?>:</em></td><td><?php echo $TITLE_PARAM_DESC ; ?></td></tr>
  85. <tr><td><em><?php echo ONLINE_KEY ; ?>:</em></td><td><?php echo $ONLINE_PARAM_DESC ; ?></td></tr>
  86. <tr><td><em><?php echo OFFLINE_KEY ; ?>:</em></td><td><?php echo $OFFLINE_PARAM_DESC ; ?></td></tr>
  87. </table>
  88. </div>
  89. <?php if ($IS_FLIP_STYLE) { ?>
  90. <script type="text/javascript" src="<?php echo BADGES_JS_URL ; ?>"></script>
  91. <?php } ?>
  92. <script type="text/javascript">
  93. var CHANNEL_INPUT_ID = '<?php echo $CHANNEL_INPUT_ID ; ?>' ;
  94. var SUBMIT_INPUT_ID = '<?php echo $SUBMIT_INPUT_ID ; ?>' ;
  95. var OPTIONS_TABLE_ID = '<?php echo $OPTIONS_TABLE_ID ; ?>' ;
  96. var ONLINE_INPUT_ID = '<?php echo $ONLINE_INPUT_ID ; ?>' ;
  97. var OFFLINE_INPUT_ID = '<?php echo $OFFLINE_INPUT_ID ; ?>' ;
  98. var TITLE_INPUT_ID = '<?php echo $TITLE_INPUT_ID ; ?>' ;
  99. var LINK_INPUT_ID = '<?php echo $LINK_INPUT_ID ; ?>' ;
  100. var BADGE_IMG_ID = '<?php echo $BADGE_IMG_ID ; ?>' ;
  101. var IMG_CODE_ID = '<?php echo $IMG_CODE_ID ; ?>' ;
  102. var NOTES_TABLE_ID = '<?php echo $NOTES_TABLE_ID ; ?>' ;
  103. var DEMO_TITLE = '<?php echo $DEMO_TITLE ; ?>' ;
  104. var IMG_DIMS_PARAMS = '<?php echo $IMG_DIMS_PARAMS ; ?>' ;
  105. var BADGES_PHP_URL = '<?php echo BADGES_PHP_URL ; ?>' ;
  106. var BADGES_JS_URL = '<?php echo BADGES_JS_URL ; ?>' ;
  107. var LCTV_URL = '<?php echo LCTV_URL ; ?>' ;
  108. var CHANNEL_KEY = '<?php echo CHANNEL_KEY ; ?>' ;
  109. var STYLE_KEY = '<?php echo STYLE_KEY ; ?>' ;
  110. var LINK_KEY = '<?php echo LINK_KEY ; ?>' ;
  111. var TITLE_KEY = '<?php echo TITLE_KEY ; ?>' ;
  112. var ONLINE_KEY = '<?php echo ONLINE_KEY ; ?>' ;
  113. var OFFLINE_KEY = '<?php echo OFFLINE_KEY ; ?>' ;
  114. var STATUS_V1_STYLE = '<?php echo STATUS_V1_STYLE ; ?>' ;
  115. var STATUS_V2_STYLE = '<?php echo STATUS_V2_STYLE ; ?>' ;
  116. var VIEWERS_V1_STYLE = '<?php echo VIEWERS_V1_STYLE ; ?>' ;
  117. var FOLLOWERS_V1_STYLE = '<?php echo FOLLOWERS_V1_STYLE ; ?>' ;
  118. var LASTSTREAM_V1_STYLE = '<?php echo LASTSTREAM_V1_STYLE ; ?>' ;
  119. var NEXTSTREAM_V1_STYLE = '<?php echo NEXTSTREAM_V1_STYLE ; ?>' ;
  120. var BADGE_STYLE = '<?php echo $BADGE_STYLE ; ?>' ;
  121. var IS_V1_STYLE = <?php echo ($IS_V1_STYLE ) ? 'true' : 'false' ; ?> ;
  122. var IS_V2_STYLE = <?php echo ($IS_V2_STYLE ) ? 'true' : 'false' ; ?> ;
  123. var IS_FLIP_STYLE = <?php echo ($IS_FLIP_STYLE) ? 'true' : 'false' ; ?> ;
  124. var N_STATIC_OPTIONS = 2 ; // CHANNEL_KEY, STYLE_KEY
  125. var N_FLIP_OPTIONS = 3 ; // CHANNEL_KEY, STYLE_KEY, LINK_KEY, TITLE_KEY, ONLINE_KEY, OFFLINE_KEY
  126. var N_CUSTOM_OPTIONS = 6 ; // CHANNEL_KEY, STYLE_KEY, LINK_KEY, TITLE_KEY, ONLINE_KEY, OFFLINE_KEY
  127. var ChannelInput ;
  128. var SubmitInput ;
  129. var OptionsTable ;
  130. var OnlineInput ;
  131. var OfflineInput ;
  132. var TitleInput ;
  133. var LinkInput ;
  134. var BadgeImg ;
  135. var ImgPre ;
  136. var NotesTable ;
  137. function init()
  138. {
  139. ChannelInput = document.getElementById(CHANNEL_INPUT_ID) ;
  140. SubmitInput = document.getElementById(SUBMIT_INPUT_ID ) ;
  141. OptionsTable = document.getElementById(OPTIONS_TABLE_ID) ;
  142. OnlineInput = document.getElementById(ONLINE_INPUT_ID ) ;
  143. OfflineInput = document.getElementById(OFFLINE_INPUT_ID) ;
  144. TitleInput = document.getElementById(TITLE_INPUT_ID ) ;
  145. LinkInput = document.getElementById(LINK_INPUT_ID ) ;
  146. BadgeImg = document.getElementById(BADGE_IMG_ID ) ;
  147. ImgPre = document.getElementById(IMG_CODE_ID ) ;
  148. NotesTable = document.getElementById(NOTES_TABLE_ID ) ;
  149. ChannelInput.onkeyup = setEmbedCode ;
  150. OnlineInput .onkeyup = setEmbedCode ;
  151. OfflineInput.onkeyup = setEmbedCode ;
  152. TitleInput .onclick = setEmbedCode ;
  153. LinkInput .onclick = setEmbedCode ;
  154. SubmitInput .onclick = loadImage ;
  155. hideUnusedOptions() ;
  156. document.title = DEMO_TITLE ;
  157. setEmbedCode() ;
  158. }
  159. function hideUnusedOptions()
  160. {
  161. if (N_CUSTOM_OPTIONS != OptionsTable.rows.length ||
  162. N_CUSTOM_OPTIONS != NotesTable .rows.length ) return ;
  163. var option_n = N_CUSTOM_OPTIONS ;
  164. var n_keep_options = (IS_V1_STYLE) ? N_CUSTOM_OPTIONS :
  165. (IS_V2_STYLE) ? N_STATIC_OPTIONS : N_FLIP_OPTIONS ;
  166. while (option_n-- > n_keep_options)
  167. {
  168. OptionsTable.deleteRow(option_n) ;
  169. NotesTable .deleteRow(option_n) ;
  170. }
  171. }
  172. function loadImage()
  173. {
  174. if (!ChannelInput.value) return ;
  175. // remove badge img from anchor if present
  176. var wrap_link = LinkInput.checked ;
  177. var badge_id = BadgeImg.id ;
  178. var badge_parent = BadgeImg.parentNode ;
  179. var badge_parent_id = badge_parent.id ;
  180. var badge_a_id = badge_id.substring(0 , badge_id.length - 3) + 'a'
  181. if (!wrap_link && badge_parent_id === badge_a_id)
  182. badge_parent.parentNode.replaceChild(BadgeImg , badge_parent) ;
  183. // load badge image
  184. if (IS_FLIP_STYLE) loadImages() ; // in BADGES_JS_URL
  185. else BadgeImg.src = makeBadgeUrl() ;
  186. BadgeImg.style.visibility = 'visible' ;
  187. }
  188. function getChannelName()
  189. {
  190. return ((ChannelInput.value) ? ChannelInput.value : 'YOUR_LCTV_CHANNEL_NAME') ;
  191. }
  192. function makeBadgeUrl()
  193. {
  194. var channel_name = getChannelName() ;
  195. var wrap_link = LinkInput.checked ;
  196. var use_title = TitleInput.checked ;
  197. var online_text = escape(OnlineInput.value) ;
  198. var offline_text = escape(OfflineInput.value) ;
  199. OnlineInput.style.disabled = use_title ;
  200. var style_param = '?' + STYLE_KEY + '=' + BADGE_STYLE ;
  201. var channel_param = '&' + CHANNEL_KEY + '=' + channel_name ;
  202. var link_param = (! wrap_link ) ? '&' + LINK_KEY + '=' + wrap_link : '' ;
  203. var title_param = (!!use_title ) ? '&' + TITLE_KEY + '=' + use_title : '' ;
  204. var online_param = (!!online_text ) ? '&' + ONLINE_KEY + '=' + online_text : '' ;
  205. var offline_param = (!!offline_text) ? '&' + OFFLINE_KEY + '=' + offline_text : '' ;
  206. var badge_url = BADGES_PHP_URL + style_param + channel_param + link_param +
  207. title_param + online_param + offline_param ;
  208. return badge_url ;
  209. }
  210. function setEmbedCode()
  211. {
  212. var badge_url = makeBadgeUrl() ;
  213. var channel_name = getChannelName() ;
  214. var wrap_link = LinkInput.checked ;
  215. var channel_url = LCTV_URL + channel_name ;
  216. var link_param = (!wrap_link) ? ' data-link="false"' : '' ;
  217. BadgeImg.dataset.channel = channel_name ;
  218. BadgeImg.dataset.link = wrap_link ;
  219. var img_custom_code = '&lt;img src="' + badge_url + '" /&gt;' ;
  220. var img_static_code = '&lt;a href="' + channel_url + '"&gt;\n' +
  221. ' &lt;img ' + IMG_DIMS_PARAMS + '\n' +
  222. ' src="' + badge_url + '" /&gt;\n' +
  223. '&lt;/a&gt;' ;
  224. var img_flip_code = '&lt;img id="' + BADGE_IMG_ID +
  225. '" ' + IMG_DIMS_PARAMS +
  226. ' data-channel="' + channel_name + '"' +
  227. link_param + ' /&gt;' ;
  228. var script_code = '\n\n&lt;script type="text/javascript"' +
  229. ' src="' + BADGES_JS_URL + '"&gt;&lt;/script&gt;' ;
  230. ImgPre.innerHTML = (IS_V1_STYLE ) ? img_custom_code :
  231. (IS_V2_STYLE ) ? img_static_code :
  232. (IS_FLIP_STYLE) ? img_flip_code + script_code :
  233. "unknown 'badge-style'" ;
  234. }
  235. init() ;
  236. </script>
  237. </body></html>