PageRenderTime 55ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/sampleapps/vidislide/slide_list.php

https://github.com/zeitin/vidipublic
PHP | 271 lines | 264 code | 3 blank | 4 comment | 2 complexity | 9769bbabbdfdd26537bed4149504cf72 MD5 | raw file
  1. <?php
  2. require "config.php";
  3. require "log.php";
  4. require "vidi.php";
  5. /*
  6. * This function gets room for given room name,
  7. * if there is no room creates newone.
  8. */
  9. function getRoom($room_name) {
  10. global $vidi, $apikey;
  11. debug_log("getRoom called");
  12. try {
  13. $roomid = $vidi->getProperty($apikey, 'apikey', $apikey, $room_name);
  14. } catch (Exception $e) {
  15. debug_log("roomid for room '$room_name' cannot be retrieved from apikey");
  16. }
  17. if (!in_array($roomid, $vidi->listRooms($apikey))) {
  18. debug_log("roomid '$roomid' exists in apikey propertires but it possibly expired, i'll get a new roomid for room-'$room_name'");
  19. $roomid="";
  20. }
  21. if (!$roomid) {
  22. $roomid = $vidi->createRoom($apikey);
  23. $vidi->setProperty($apikey, 'apikey', $apikey, $room_name, $roomid);
  24. $vidi->setProperty($apikey, 'roomid', $roomid, "room", $room_name); # only for monitoring page, not functional
  25. debug_log("created room-'$room_name' roomid-'$roomid'");
  26. }
  27. debug_log("using '$roomid' for room '$room_name'");
  28. return array($room_name, $roomid);
  29. }
  30. /*
  31. * This function gets client from given room for given client name,
  32. * if there is no client in that room creates newone.
  33. */
  34. function getClient($client_name, $roomid) {
  35. global $vidi, $apikey;
  36. debug_log("getClient called");
  37. $clientid = "";
  38. if (!$clientid) {
  39. $clientid = $vidi->createClientInRoom($apikey, $roomid);
  40. $vidi->setProperty($apikey, 'clientid', $clientid, "name", $client_name);
  41. $vidi->setProperty($apikey, 'roomid', $roomid, $client_name, $clientid);
  42. }
  43. debug_log("using '$clientid' for client '$client_name'");
  44. return array($client_name,$clientid);
  45. }
  46. function getClientsInRoom($roomid) {
  47. global $vidi, $apikey;
  48. $clients = $vidi->listClientsInRoom($apikey, $roomid);
  49. $client_names = array();
  50. foreach ($clients as $clientid) {
  51. $name = $vidi->getProperty($apikey, 'clientid', $clientid, "name");
  52. array_push($client_names, array($clientid,$name));
  53. }
  54. if (count($client_names) == 0) return false;
  55. else return $client_names;
  56. }
  57. function getSlidePages($slide_path, $slide_name) {
  58. $path = "$slide_path/$slide_name";
  59. if (!file_exists($path)) {
  60. mkdir($path,0755);
  61. }
  62. $page_list = scandir("$slide_path/$slide_name");
  63. sort($page_list);
  64. $page_list = array_slice($page_list,2);
  65. return $page_list;
  66. }
  67. // check request variables, if room requested get room info else stop script
  68. $room_info = (isset($_REQUEST["slidename"])) ? getRoom($_REQUEST["slidename"]) : die("Bir slayt ismi belirlemelisiniz.");
  69. $room_name = $room_info[0];
  70. $roomid = $room_info[1];
  71. // check request variables, if client requested get client info else stop script
  72. $client_info = (isset($_REQUEST["clientname"])) ? getClient($_REQUEST["clientname"],$roomid) : die("Bir isim seƧmelisiniz.");
  73. $client_name = $client_info[0];
  74. $slide_name = $room_name;
  75. $clientid = $client_info[1];
  76. $show_client_list = (isset($_REQUEST["showclientlist"]) && ($_REQUEST["showclientlist"] == "false")) ? "none" : "inline";
  77. // get client list
  78. $client_list = getClientsInRoom($roomid);
  79. for ($i=0; $i<count($client_list); $i++) {
  80. if ($client_list[$i][1] == $client_name) unset($client_list[$i]);
  81. }
  82. // ugly hack to calculate size
  83. $width = 600;
  84. $height = 500;
  85. /*
  86. $width = (isset($_REQUEST["width"])) ? $_REQUEST["width"] : 320;
  87. $height = (isset($_REQUEST["height"])) ? $_REQUEST["height"] : 240;
  88. $chatbox_width = $width - 15;
  89. $chatbox_height = $height - 75;
  90. $controls_width = $width - 15;
  91. $controls_height = 50;
  92. $chat_message_width = $width - 90;
  93. */
  94. $page_list = getSlidePages($slide_path, $slide_name);
  95. ?>
  96. <html>
  97. <head>
  98. <title>Vidi Slide</title>
  99. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  100. <link rel="stylesheet" type="text/css" media="all" href="style.css" />
  101. <script type="text/javascript" src="<?=$vidi_js_path?>"></script>
  102. <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
  103. <script type="text/javascript">
  104. var globals = {
  105. client_name: "<?=$client_name?>",
  106. client_id: "<?=$clientid?>",
  107. debug: <?=$debug?>,
  108. screen: "",
  109. screen_settings: {
  110. divid: "screen_container",
  111. camera: false,
  112. screen: false,
  113. mic: false,
  114. speaker: false,
  115. screen_width: 1,
  116. screen_height: 1,
  117. localecho: false
  118. }
  119. };
  120. function log(message) {
  121. if (globals.debug && window.console) {
  122. console.log(message);
  123. }
  124. }
  125. function createScreen(settings) {
  126. return vidi.createVidi(settings);
  127. }
  128. function onVidiCallback(cmd, obj) {
  129. var action_info;
  130. var action;
  131. var data;
  132. var stranger_info;
  133. var stranger_id;
  134. var stranger_name;
  135. var temp;
  136. if (cmd == "callback_test") {
  137. return "ok";
  138. } else if (cmd == "server_says") {
  139. action_info = obj.message.split("::");
  140. action = action_info[0];
  141. data = action_info[1];
  142. if (action == "client_joined_room") {
  143. stranger_info = data.split("|");
  144. stranger_id = stranger_info[0];
  145. stranger_name = stranger_info[1];
  146. if (globals.client_id != stranger_id) {
  147. if ($("#"+stranger_id).length == 0) {
  148. temp = "<li id='"+stranger_id+"'><input type='checkbox' checked class='client' id='"+stranger_id+"' />&nbsp;&nbsp;"+stranger_name+"</li>";
  149. $("#client_list").append(temp);
  150. }
  151. }
  152. } else
  153. if (action == "client_left_room") {
  154. stranger_info = data.split("|");
  155. stranger_id = stranger_info[0];
  156. stranger_name = stranger_info[1];
  157. if (globals.client_id != stranger_id) {
  158. $("#"+stranger_id).remove();
  159. }
  160. }
  161. } else {
  162. log("undefined callback: "+cmd);
  163. }
  164. }
  165. function getSelectedClients() {
  166. log("getSelectedClients called");
  167. var client_list = "";
  168. $(".client").each(function() {
  169. if (this.checked = true) {
  170. client_list += this.id+"|";
  171. }
  172. });
  173. client_list = client_list.slice(0,-1);
  174. log("client list: "+client_list);
  175. return client_list;
  176. }
  177. function publishPage(screen, slide_name, page) {
  178. log("publishPage called");
  179. client_list = getSelectedClients();
  180. var msg = {message:'publish_page::'+slide_name+'|'+page+';;'+client_list}
  181. screen.tellServer(msg);
  182. }
  183. $(function() {
  184. vidi.initialize({
  185. clientid: "<?=$clientid?>",
  186. roomid: "<?=$roomid?>",
  187. debug: <?=$debug?>,
  188. callback: onVidiCallback
  189. });
  190. globals.screen = createScreen(globals.screen_settings);
  191. $(".publish").click(function(){
  192. var slide_name="<?=$slide_name?>";
  193. var page = $(this).attr("id");
  194. publishPage(globals.screen, slide_name, page);
  195. });
  196. });
  197. </script>
  198. </head>
  199. <body>
  200. <div>
  201. <div id="screen_container"></div>
  202. <div id="slide_list_container" style="width: <?=$width?>px; height: <?=$height?>px;">
  203. <h3>&nbsp;Pages of slide "<?=$slide_name?>"</h3>
  204. <hr />
  205. <center>
  206. <a href="new_slide.php?slidename=<?=$slide_name?>&clientname=<?=$client_name?>">Add Page</a>&nbsp;
  207. <a href="#">Delete Selected</a>
  208. <table id="slide_list" border="1" width="100%">
  209. <tr>
  210. <th>&nbsp;</th>
  211. <th>Slide Name</th>
  212. <th>Page #</th>
  213. <th>&nbsp;</th>
  214. <th>&nbsp;</th>
  215. <th>&nbsp;</th>
  216. </tr>
  217. <? foreach($page_list as $value): ?>
  218. <tr>
  219. <td><input type="checkbox" /></td>
  220. <td><?=$slide_name?></td>
  221. <td><?=$value?></td>
  222. <td><a href="new_slide.php?slidename=<?=$slide_name?>&clientname=<?=$client_name?>&page=<?=$value?>">edit</a></td>
  223. <td><a href="<?=$slide_path."/".$slide_name."/".$value?>/index.html">show</a></td>
  224. <td><a href="#" id="<?=$value?>" class="publish" />publish</a></td>
  225. </tr>
  226. <? endforeach; ?>
  227. </table>
  228. </center>
  229. </div>
  230. <div id="client_list_container" style="height: <?=$height?>px; display: <?=$show_client_list?>">
  231. <h3>&nbsp;&nbsp;Publish List</h3>
  232. <hr />
  233. <ul id="client_list">
  234. <? foreach($client_list as $value): ?>
  235. <li id="<?=$value[0]?>">
  236. <input type="checkbox" checked class="client" id="<?=$value[0]?>" />&nbsp;&nbsp;<?=$value[1]?>
  237. </li>
  238. <? endforeach; ?>
  239. </ul>
  240. </div>
  241. </div>
  242. </body>
  243. </html>