/wp-content/plugins/pods/ui/manage_pages.php

https://github.com/alfsaav/belleidea_WP · PHP · 156 lines · 102 code · 6 blank · 48 comment · 13 complexity · 2eebb20f684dcbd7b95465bda6e1f850 MD5 · raw file

  1. <?php
  2. // Get all pages
  3. $result = pod_query("SELECT id, uri FROM @wp_pod_pages ORDER BY uri");
  4. while ($row = mysql_fetch_assoc($result)) {
  5. $pages[$row['id']] = $row['uri'];
  6. }
  7. ?>
  8. <!-- Begin page area -->
  9. <script type="text/javascript">
  10. jQuery(function() {
  11. jQuery(".select-page").change(function() {
  12. page_id = jQuery(this).val();
  13. if ("" == page_id) {
  14. jQuery("#pageArea .stickynote").show();
  15. jQuery("#pageContent").hide();
  16. jQuery("#page_code").val("");
  17. jQuery("#page_precode").val("");
  18. }
  19. else {
  20. jQuery("#pageArea .stickynote").hide();
  21. jQuery("#pageContent").show();
  22. loadPage();
  23. }
  24. });
  25. jQuery(".select-page").change();
  26. jQuery("#pageBox").jqm();
  27. });
  28. function loadPage() {
  29. jQuery.ajax({
  30. type: "post",
  31. url: api_url,
  32. data: "action=load_page&id="+page_id,
  33. success: function(msg) {
  34. if (!is_error(msg)) {
  35. var json = eval('('+msg+')');
  36. var title = (null == json.title) ? "" : json.title;
  37. var code = (null == json.phpcode) ? "" : json.phpcode;
  38. var precode = (null == json.precode) ? "" : json.precode;
  39. var template = (null == json.page_template) ? "" : json.page_template;
  40. jQuery("#page_code").val(code);
  41. jQuery("#page_precode").val(precode);
  42. jQuery("#page_title").val(title);
  43. jQuery("#page_template").val(template);
  44. }
  45. }
  46. });
  47. }
  48. function addPage() {
  49. var uri = jQuery("#new_page").val();
  50. jQuery.ajax({
  51. type: "post",
  52. url: api_url,
  53. data: "action=save_page&uri="+uri,
  54. success: function(msg) {
  55. if (!is_error(msg)) {
  56. var id = msg;
  57. var html = '<option value="'+id+'">'+uri+'</option>';
  58. jQuery(".select-page").append(html);
  59. jQuery("#pageBox #new_page").val("");
  60. jQuery(".select-page > option[value='"+id+"']").attr("selected", "selected");
  61. jQuery(".select-page").change();
  62. jQuery("#pageBox").jqmHide();
  63. }
  64. }
  65. });
  66. }
  67. function editPage() {
  68. var code = jQuery("#page_code").val();
  69. var precode = jQuery("#page_precode").val();
  70. var title = jQuery("#page_title").val();
  71. var template = jQuery("#page_template").val();
  72. jQuery.ajax({
  73. type: "post",
  74. url: api_url,
  75. data: "action=save_page&id="+page_id+"&page_title="+encodeURIComponent(title)+"&page_template="+encodeURIComponent(template)+"&phpcode="+encodeURIComponent(code)+"&precode="+encodeURIComponent(precode),
  76. success: function(msg) {
  77. if (!is_error(msg)) {
  78. alert("Success!");
  79. }
  80. }
  81. });
  82. }
  83. function dropPage() {
  84. if (confirm("Do you really want to drop this page?")) {
  85. jQuery.ajax({
  86. type: "post",
  87. url: api_url,
  88. data: "action=drop_page&id="+page_id,
  89. success: function(msg) {
  90. if (!is_error(msg)) {
  91. jQuery(".select-page > option[value='"+page_id+"']").remove();
  92. jQuery(".select-page").change();
  93. }
  94. }
  95. });
  96. }
  97. }
  98. </script>
  99. <!-- Page popups -->
  100. <div id="pageBox" class="jqmWindow">
  101. <input type="text" id="new_page" style="width:280px" maxlength="128" />
  102. <input type="button" class="button" onclick="addPage()" value="Add Page" />
  103. <div>Ex: <strong>events</strong> or <strong>events/*</strong></div>
  104. </div>
  105. <!-- Page HTML -->
  106. <select class="area-select select-page">
  107. <option value="">-- Choose a Page --</option>
  108. <?php
  109. if (isset($pages)) {
  110. foreach ($pages as $key => $val) {
  111. ?>
  112. <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
  113. <?php
  114. }
  115. }
  116. ?>
  117. </select>
  118. <input type="button" class="button-primary" onclick="jQuery('#pageBox').jqmShow()" value="Add new page" />
  119. <div id="pageContent">
  120. <textarea id="page_code"></textarea><br />
  121. Precode (optional):
  122. <textarea id="page_precode"></textarea><br />
  123. Page Title (optional):<br />
  124. <input id="page_title" type="text" maxlength="128" />
  125. <select id="page_template">
  126. <option value="">-- Page Template --</option>
  127. <?php
  128. $page_templates = get_page_templates();
  129. if (!in_array('page.php',$page_templates) && locate_template(array('page.php',false))) {
  130. $page_templates['Page (WP Default)'] = 'page.php';
  131. ksort($page_templates);
  132. }
  133. foreach ($page_templates as $template => $file) {
  134. ?>
  135. <option value="<?php echo $file; ?>"><?php echo $template; ?></option>
  136. <?php
  137. }
  138. ?>
  139. </select><br />
  140. <input type="button" class="button" onclick="editPage()" value="Save changes" /> or
  141. <a href="javascript:;" onclick="dropPage()">drop page</a>
  142. </div>
  143. <div class="stickynote">
  144. <div><strong>Pod Pages are similar to WordPress pages, but also support PHP and wildcard URLs.</strong></div>
  145. <div style="margin-top:10px">To handle the URL of http://yoursite.com/history, you'd create a Pod Page named <strong>history</strong></div>
  146. <div style="margin-top:10px">A single wildcard Pod Page can handle multiple URLs. For example, the Pod Page <strong>history/*</strong> will be used for any URL beginning with http://yoursite.com/history/</div>
  147. </div>